-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall.php
356 lines (317 loc) · 13.6 KB
/
install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<?php
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
global $db;
$sql[]='CREATE TABLE IF NOT EXISTS `polycom_settings` (
`keyword` varchar(50) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`keyword`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
$sql[]="INSERT IGNORE INTO `polycom_settings` (`keyword`, `value`) VALUES
('apps_push_password', '" . substr(hash('sha512',rand()),0,12) . "'),
('digits', '4'),
('multiple_assignment', '0'),
('httpd_cfg_enabled', '1'),
('device_auth_localUserPassword', '123'),
('device_auth_localAdminPassword', '456'),
('lineKeys', '1'),
('ringType', 'ringer2'),
('missedCallTracking', '1'),
('callBackMode', 'contact'),
('serverFeatureControl_dnd', '0'),
('serverFeatureControl_cf', '0'),
('softkey_feature_basicCallManagement_redundant', '1'),
('call_transfer_blindPreferred', '0'),
('call_callWaiting_ring', 'beep'),
('call_hold_localReminder_enabled', '0'),
('call_rejectBusyOnDnd', '1'),
('call_advancedMissedCalls_addToReceivedList', '0'),
('up_useDirectoryNames', '1'),
('dir_local_readonly', '0'),
('se_pat_misc_messageWaiting_inst', '1'),
('apps_ucdesktop_adminEnabled', '0'),
('attendant_ringType', 'ringer1'),
('feature_callRecording_enabled', '0'),
('feature_directedCallPickup_enabled', '0'),
('attendant_spontaneousCallAppearances_normal', '1'),
('attendant_spontaneousCallAppearances_automata', '0'),
('up_headsetMode', '0'),
('up_analogHeadsetOption', '0'),
('powerSaving_enable', '0'),
('up_backlight_idleIntensity', '1'),
('up_backlight_onIntensity', '3');";
$sql[]="INSERT IGNORE INTO `polycom_settings` (`keyword`, `value`) VALUES
('powerSaving_idleTimeout_officeHours', '480'),
('powerSaving_idleTimeout_offHours', '1'),
('powerSaving_officeHours_startHour_monday', '7'),
('powerSaving_officeHours_startHour_tuesday', '7'),
('powerSaving_officeHours_startHour_wednesday', '7'),
('powerSaving_officeHours_startHour_thursday', '7'),
('powerSaving_officeHours_startHour_friday', '7'),
('powerSaving_officeHours_startHour_saturday', '7'),
('powerSaving_officeHours_startHour_sunday', '7'),
('powerSaving_officeHours_duration_monday', '12'),
('powerSaving_officeHours_duration_tuesday', '12'),
('powerSaving_officeHours_duration_wednesday', '12'),
('powerSaving_officeHours_duration_thursday', '12'),
('powerSaving_officeHours_duration_friday', '12'),
('powerSaving_officeHours_duration_saturday', '0'),
('powerSaving_officeHours_duration_sunday', '0');";
$sql[]="INSERT IGNORE INTO `polycom_settings` (`keyword`, `value`) VALUES
('feature_corporateDirectory_enabled', '0'),
('feature_exchangeCalendar_enabled', '0');";
$sql[]='CREATE TABLE IF NOT EXISTS `polycom_networks` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
`cidr` varchar(18) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `cidr` (`cidr`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
$sql[]="INSERT IGNORE INTO `polycom_networks` (`id`, `name`, `cidr`) VALUES
('-1', 'Default Network', '0.0.0.0/0');";
$sql[]='CREATE TABLE IF NOT EXISTS `polycom_network_settings` (
`id` int(11) NOT NULL,
`keyword` varchar(50) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`id`,`keyword`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
// Migrate general settings to network settings
$sql[]="INSERT INTO polycom_network_settings (id, keyword, value)
SELECT '-1', keyword, value FROM polycom_settings
WHERE keyword IN ('address', 'port', 'tcpIpApp_sntp_address', 'tcpIpApp_sntp_gmtOffset', 'nat_keepalive_interval')";
// Delete migrated network settings
$sql[]="DELETE FROM polycom_settings
WHERE keyword IN ('address', 'port', 'tcpIpApp_sntp_address', 'tcpIpApp_sntp_gmtOffset', 'nat_keepalive_interval')";
$sql[]="INSERT IGNORE INTO polycom_network_settings (id, keyword, value) VALUES
('-1', 'prov_ssl', '0'),
('-1', 'prov_username', 'PlcmSpIp'),
('-1', 'prov_password', 'PlcmSpIp'),
('-1', 'prov_uploads', '1'),
('-1', 'address', '" . $db->escapeSimple($_SERVER['SERVER_NAME']) . "'),
('-1', 'port', '5060'),
('-1', 'expires', '3600'),
('-1', 'nat_keepalive_interval', '0'),
('-1', 'tcpIpApp_sntp_resyncPeriod', '86400'),
('-1', 'tcpIpApp_sntp_address_overrideDHCP', '0'),
('-1', 'tcpIpApp_sntp_gmtOffset_overrideDHCP', '0');";
$sql[]='CREATE TABLE IF NOT EXISTS `polycom_devices` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
`mac` varchar(12) NOT NULL,
`model` varchar(30) NOT NULL,
`lastconfig` datetime NOT NULL,
`lastip` varchar(15) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `mac` (`mac`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
$sql[]='CREATE TABLE IF NOT EXISTS `polycom_device_settings` (
`id` int(11) NOT NULL,
`keyword` varchar(50) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`id`,`keyword`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
// Delete migrated network settings
$sql[]="DELETE FROM polycom_device_settings
WHERE keyword IN ('nat_keepalive_interval')";
$sql[]='CREATE TABLE IF NOT EXISTS `polycom_device_lines` (
`id` int(11) NOT NULL,
`lineid` int(11) NOT NULL,
`deviceid` int(11) NULL,
`externalid` int(11) NULL,
PRIMARY KEY (`id`,`lineid`),
KEY `deviceid` (`deviceid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
$sql[]='CREATE TABLE IF NOT EXISTS `polycom_device_line_settings` (
`id` int(11) NOT NULL,
`lineid` int(11) NOT NULL,
`keyword` varchar(30) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`id`,`lineid`,`keyword`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
$sql[]='CREATE TABLE IF NOT EXISTS `polycom_device_attendants` (
`id` int(11) NOT NULL,
`attendantid` int(11) NOT NULL,
`keyword` varchar(30) NOT NULL,
`value` varchar(30) NOT NULL,
`label` varchar(30) NOT NULL,
`type` varchar(10) NOT NULL,
PRIMARY KEY (`id`,`attendantid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
$sql[]='CREATE TABLE IF NOT EXISTS `polycom_externallines` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
$sql[]='CREATE TABLE IF NOT EXISTS `polycom_externalline_settings` (
`id` int(11) NOT NULL,
`keyword` varchar(30) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`id`,`keyword`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
$sql[]='CREATE TABLE IF NOT EXISTS `polycom_alertinfo` (
`id` varchar(20) NOT NULL,
`name` varchar(30) NOT NULL,
`callwait` varchar(25) NOT NULL,
`micmute` tinyint(1) NOT NULL,
`ringer` varchar(10) NOT NULL,
`type` varchar(15) NOT NULL,
`alertinfo` varchar(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;';
$sql[]="INSERT IGNORE INTO `polycom_alertinfo` (`id`, `name`, `callwait`, `micmute`, `ringer`, `type`, `alertinfo`) VALUES
('default', 'Default', 'callWaiting', '0', 'ringer2', 'ring', ''),
('visual', 'Visual', 'callWaiting', '0', 'ringer1', 'visual', ''),
('answerMute', 'Answer Mute', 'callWaiting', '1', 'ringer2', 'answer', ''),
('autoAnswer', 'Auto Answer', 'callWaiting', '0', 'ringer2', 'answer', ''),
('ringAnswerMute', 'Ring Auto Mute', 'callWaiting', '1', 'ringer2', 'ring-answer', ''),
('ringAutoAnswer', 'Ring Auto Answer', 'callWaiting', '0', 'ringer2', 'ring-answer', 'Ring Answer'),
('internal', 'Internal', 'callWaiting', '0', 'ringer2', 'ring', ''),
('external', 'External', 'callWaiting', '0', 'ringer2', 'ring', ''),
('emergency', 'Emergency', 'callWaiting', '0', 'ringer2', 'ring', ''),
('precedence', 'Precedence', 'precedenceCallWaiting', '0', 'ringer13', 'ring', ''),
('splash', 'Default', 'callWaiting', '0', 'ringer14', 'ring', ''),
('custom1', 'Custom 1', 'callWaitingLong', '0', 'ringer5', 'ring', ''),
('custom2', 'Custom 2', 'callWaitingLong', '0', 'ringer7', 'ring', ''),
('custom3', 'Custom 3', 'callWaitingLong', '0', 'ringer9', 'ring', ''),
('custom4', 'Custom 4', 'callWaitingLong', '0', 'ringer11', 'ring', ''),
('custom5', 'Custom 5', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom6', 'Custom 6', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom7', 'Custom 7', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom8', 'Custom 8', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom9', 'Custom 9', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom10', 'Custom 10', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom11', 'Custom 11', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom12', 'Custom 12', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom13', 'Custom 13', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom14', 'Custom 14', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom15', 'Custom 15', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom16', 'Custom 16', 'callWaiting', '0', 'ringer2', 'ring', ''),
('custom17', 'Custom 17', 'callWaiting', '0', 'ringer2', 'ring', '');";
foreach ($sql as $statement){
$check = $db->query($statement);
if (DB::IsError($check)){
die_freepbx( "Can not execute $statement : " . $check->getMessage() . "\n");
}
}
// Add type column to attendant table
$sql = "SELECT type FROM polycom_device_attendants";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($check)) {
$sql = array();
$sql[] = "ALTER TABLE `polycom_device_attendants` ADD `type` varchar(10) NOT NULL;";
$sql[] = "UPDATE polycom_device_attendants SET type = 'normal';";
foreach ($sql as $statement){
$check = $db->query($statement);
if (DB::IsError($check)){
die_freepbx( "Can not execute $statement : " . $check->getMessage() . "\n");
}
}
}
// Add model column to devices table
$sql = "SELECT model FROM polycom_devices";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($check)) {
$sql = array();
$sql[] = "ALTER TABLE `polycom_devices` ADD `model` VARCHAR( 30 ) NOT NULL AFTER `mac`;";
foreach ($sql as $statement){
$check = $db->query($statement);
if (DB::IsError($check)){
die_freepbx( "Can not execute $statement : " . $check->getMessage() . "\n");
}
}
}
// Add version column to devices table
$sql = "SELECT version FROM polycom_devices";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($check)) {
$sql = array();
$sql[] = "ALTER TABLE `polycom_devices` ADD `version` VARCHAR( 20 ) NOT NULL AFTER `model`;";
foreach ($sql as $statement){
$check = $db->query($statement);
if (DB::IsError($check)){
die_freepbx( "Can not execute $statement : " . $check->getMessage() . "\n");
}
}
}
// Add new settings and default codec priorities to networks
$sql = "SELECT id FROM polycom_networks";
$networks = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if (DB::IsError($networks)){
die_freepbx( "Can not execute $sql : " . $networks->getMessage() . "\n");
}
foreach($networks as $network) {
$sql = "INSERT IGNORE INTO polycom_network_settings (id, keyword, value) VALUES
('" . $network['id'] . "', 'expires', '3600'),
('" . $network['id'] . "', 'tcpIpApp_sntp_resyncPeriod', '86400'),
('" . $network['id'] . "', 'tcpIpApp_sntp_gmtOffset_overrideDHCP', '0'),
('" . $network['id'] . "', 'voice_codecPref_G711_Mu', '6'),
('" . $network['id'] . "', 'voice_codecPref_G711_A', '7'),
('" . $network['id'] . "', 'voice_codecPref_G722', '4'),
('" . $network['id'] . "', 'voice_codecPref_G729_AB', '8');";
$check = $db->query($sql);
if (DB::IsError($check)){
die_freepbx( "Can not execute $sql : " . $check->getMessage() . "\n");
}
}
define("LOCAL_PATH", $amp_conf['AMPWEBROOT'] . '/admin/modules/polycomphones/');
define("SOFTWARE_PATH", $amp_conf['AMPWEBROOT'] . '/admin/modules/_polycom_software/');
define("PROVISIONING_PATH", $amp_conf['AMPWEBROOT'] . '/polycom');
// Link module assets to FreePBX assets folder
if(!is_link($amp_conf['AMPWEBROOT'] . "/admin/assets/polycomphones"))
{
out('Creating symlink to assets');
if (!symlink(LOCAL_PATH . "assets", $amp_conf['AMPWEBROOT'] . "/admin/assets/polycomphones")) {
out("<strong>Your permissions are wrong on " . $amp_conf['AMPWEBROOT'] . ", web assets link not created!</strong>");
}
}
// Create directory for phone software
foreach(array('', 'logs', 'overrides', 'contacts') as $folder)
{
if(!file_exists(SOFTWARE_PATH.$folder))
{
out("Creating phone software " . (empty($folder) ? 'root' : $folder) . " directory");
if(!mkdir(SOFTWARE_PATH.$folder, 0775)) {
out("<strong>Your permissions are wrong on " . $amp_conf['AMPWEBROOT'] . ", phone software directory not created!</strong>");
}
}
}
// Remove link from previous module version
if(is_link(PROVISIONING_PATH))
{
if(readlink(PROVISIONING_PATH) != SOFTWARE_PATH) {
out("Removing old symlink to web provisioner");
if(!unlink(PROVISIONING_PATH)) {
out("<strong>Your permissions are wrong on " . $amp_conf['AMPWEBROOT'] . ", unable to remove previous web provisioning link!</strong>");
}
}
}
// Remove all links for phone software folder
foreach(scandir(SOFTWARE_PATH) as $item)
{
if(is_file(SOFTWARE_PATH . $item) && is_link(SOFTWARE_PATH . $item)) {
if(!unlink(SOFTWARE_PATH . $item)) {
out("<strong>Your permissions are wrong on " . $amp_conf['AMPWEBROOT'] . ", unable to remove web provisioning file link!</strong>");
}
}
}
// Link provisioning files to software folder
foreach(scandir(LOCAL_PATH . "provisioning/") as $item)
{
if(is_file(LOCAL_PATH . "provisioning/" . $item)) {
if (!symlink(LOCAL_PATH . "provisioning/" . $item, SOFTWARE_PATH . $item)) {
out("<strong>Your permissions are wrong on " . $amp_conf['AMPWEBROOT'] . ", web provisioning file link not created!</strong>");
}
}
}
// Link software folder to provisioning path
if(!is_link(PROVISIONING_PATH))
{
out('Creating symlink to web provisioner');
if (!symlink(SOFTWARE_PATH, PROVISIONING_PATH)) {
out("<strong>Your permissions are wrong on " . $amp_conf['AMPWEBROOT'] . ", web provisioning link not created!</strong>");
}
}
// Allow execution of checkconfig
if (!chmod(LOCAL_PATH . 'checkconfig', '755')) {
out("<strong>Your permissions are wrong on " . $amp_conf['AMPWEBROOT'] . ", unable to set execute permission on checkconfig!</strong>");
}
?>