root/contributed_modules/modules/noojee/install.php

Revision 13917, 3.1 kB (checked in by bsutton, 1 year ago)

added the obligitory, but completely useless, copyright/license statements.

Line 
1 <?php
2
3 /** Copyright (C) 2012 Noojee IT Pty Ltd
4 *
5 * Author: S. Brett Sutton
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 */
17
18 require_once ("Ini.php");
19 require_once ("NoojeeDatabase.php");
20 require_once ("NJLogging.php");
21 require_once ("NJManager.php");
22 /** Create a Manager Account for each of our products **/
23
24 $noojee_installer = new NoojeeInstaller();
25 $noojee_installer->upgrade();
26
27 class NoojeeInstaller
28 {
29
30     function upgrade()
31     {
32         $noojeeDB = new NoojeeDatabase();
33         $noojeeDB->upgradeDatabase();
34         $noojeeManager = new NJManager();
35
36         if ($noojeeManager->findAccount("NJReception") == null)
37         {
38             $noojeeManager->addAccount("NJReception");
39         }
40         if ($noojeeManager->findAccount("NJFax") == null)
41         {
42             $noojeeManager->addAccount("NJFax", false);
43         }
44         if ($noojeeManager->findAccount("NJClick") == null)
45         {
46             $noojeeManager->addAccount("NJClick");
47         }
48         $this->enableAJAM();
49
50         $this->enableParking();
51
52         needreload();
53     }
54
55     function enableAJAM()
56     {
57
58         $ini = new Ini("/etc/asterisk/http.conf");
59         $ini->read();
60         $general = $ini->getSection("general");
61
62         $general->uncomment("enabled");
63         $general->uncomment( "bindaddr");
64         $general->uncomment( "bindport");
65         $general->uncomment("prefix");
66
67         $general->setKeyValue("enabled", "yes");
68
69         // We try not to change existing settings.
70         if (!$general->keyExists("bindport"))
71         {
72             $general->setKeyValue("bindport", "8088");
73         }
74
75         if (!$general->keyExists("bindaddr") || $general->getKeyValue("bindaddr") == "127.0.0.1" )
76         {
77             $general->setKeyValue("bindaddr", "0.0.0.0");
78         }
79
80         if (!$general->keyExists("prefix"))
81         {
82             $general->setKeyValue("prefix", "asterisk");
83         }
84
85         if ($ini->write() != 1)
86         {
87             echo "<script>javascript:alert('"._("Error writing the http.conf file.")."');</script>";
88         }
89
90         // We also need to make certain that it is enabled in manager.conf
91         $ini = new Ini("/etc/asterisk/manager.conf");
92         $ini->read();
93         $general = $ini->getSection("general");
94
95         $general->uncomment("enabled");
96         $general->uncomment("webenabled");
97         $general->setKeyValue("enabled", "yes");
98         $general->setKeyValue("webenabled", "yes");
99
100         if ($ini->write() != 1)
101         {
102             echo "<script>javascript:alert('"._("Error writing the manager.conf file.")."');</script>";
103         }
104         needreload();
105     }
106
107     function enableParking()
108     {
109         $parkingArray = parking_getconfig();
110
111         error_log("ParkingEnabled ='" . $parkingArray['parkingenabled'] . "'");
112
113         if (!isset($parkingArray['parkingenabled']) || $parkingArray['parkingenabled'] == '')
114         {
115             error_log('Enabling the parking lot');
116             parking_add('s', '700', '8', '45', 'parkedcalls', '', '', '', 'njr-operator,njr-inbound,1');
117         }
118         else
119         {
120             // yes we already have a packing lot so no work to do.
121             error_log('Parking lot already enabled');
122         }
123     }
124
125 }
126
127 ?>
Note: See TracBrowser for help on using the browser.