-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
317 lines (258 loc) · 11.1 KB
/
install.php
File metadata and controls
317 lines (258 loc) · 11.1 KB
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
<?php
/*
*Name : install.php
*Author : Michael Yara
*Created : August 15, 2008
*Last Updated : June 23, 2012
*History : 0.10
*Purpose : Create, upgrade, and populate isymphony tables
*Copyright : 2008 HEHE Enterprises, LLC
*/
global $db, $amp_conf;
//Column descriptor class
class isymphony_column {
var $name = "";
var $type = "";
var $defaultValue = "";
var $freePBXKey = "";
var $isUnique = false;
var $isNotNull = false;
function isymphony_column($nameVal, $typeVal, $defaultValueVal, $freePBXKeyVal, $isUniqueVal, $isNotNullVal) {
$this->name = $nameVal;
$this->type = $typeVal;
$this->defaultValue = $defaultValueVal;
$this->freePBXKey = $freePBXKeyVal;
$this->isUnique = $isUniqueVal;
$this->isNotNull = $isNotNullVal;
}
}
//Table descriptor class
class isymphony_table {
var $name = "";
var $columns = array();
function isymphony_table($nameVal, $columnsVal) {
$this->name = $nameVal;
$this->columns = $columnsVal;
}
}
//Table builder class
class isymphony_table_builder {
var $table = null;
function isymphony_table_builder($tableVal) {
$this->table = $tableVal;
}
function build($entries) {
echo "Creating \"" . $this->table->name . "\" Table....<br>";
if($this->createTableIfItDoesNotExist()) {
echo "Populating(New) \"" . $this->table->name. "\"....<br>";
$this->populateTableNew($entries);
} else {
echo "Upgrading \"" . $this->table->name. "\"....<br>";
$addedColumns = $this->upgradeTableColumns();
if(!empty($addedColumns)){
echo "Populating(Upgrade) \"" . $this->table->name. "\"....<br>";
$this->populateTableUpgrade($addedColumns);
}
}
echo "Done<br>";
}
function createTableIfItDoesNotExist() {
global $db;
//Build query to create table if it does not exists
$query = "CREATE TABLE " . $this->table->name . "(";
foreach($this->table->columns as $column) {
$query .= $this->buildColumnEntry($column) . ",";
}
$query = substr_replace($query, "", -1);
$query .= ")";
$result = $db->query($query);
if(DB::IsError($result)) {
if($result->getCode() != DB_ERROR_ALREADY_EXISTS) {
die_freepbx($result->getDebugInfo());
}
return false;
}
return true;
}
function upgradeTableColumns() {
global $db;
$addedColumns = array();
//Insert any missing columns
foreach($this->table->columns as $column) {
$query = "SELECT $column->name FROM " . $this->table->name;
$check = $db->getRow($query, DB_FETCHMODE_ASSOC);
if(DB::IsError($check)) {
$query = "ALTER TABLE " . $this->table->name . " ADD " . $this->buildColumnEntry($column);
$result = $db->query($query);
if(DB::IsError($result)) {
die_freepbx($result->getDebugInfo());
} else {
array_push($addedColumns, $column);
}
}
}
return $addedColumns;
}
function populateTableNew($entries) {
global $db;
//Populate a newly created table
foreach($entries as $entry) {
$queryKeys = "";
$queryValues = "";
$queryValueArray = array();
foreach($this->table->columns as $column) {
$queryKeys .= $column->name . ",";
$queryValues .= "?,";
$freePBXKey = $column->freePBXKey;
if($freePBXKey != "") {
array_push($queryValueArray, $entry[$freePBXKey]);
} else {
array_push($queryValueArray, $column->defaultValue);
}
}
$queryKeys = substr_replace($queryKeys, "", -1);
$queryValues = substr_replace($queryValues, "", -1);
$query = $db->prepare("INSERT INTO " . $this->table->name . " (" . $queryKeys . ") VALUES (" . $queryValues . ")");
$result = $db->execute($query, $queryValueArray);
if(DB::IsError($result)) {
die_freepbx($result->getDebugInfo());
}
}
}
function populateTableUpgrade($addedColumns) {
global $db;
//Upgrade a table
foreach($addedColumns as $column) {
$query = $db->prepare("UPDATE " . $this->table->name . " SET " . $column->name . " = ?");
$result = $db->execute($query, array($column->defaultValue));
if(DB::IsError($result)) {
die_freepbx($result->getDebugInfo());
}
}
}
function buildColumnEntry($column) {
$columnEntry = $column->name;
$modifierEntry = ($column->isUnique ? " UNIQUE" : "") . ($column->isNotNull ? " NOT NULL" : "");
switch ($column->type) {
case "primary":
$columnEntry .= " INT NOT NULL AUTO_INCREMENT PRIMARY KEY";
break;
case "string":
$columnEntry .= " VARCHAR(100)" . $modifierEntry;
break;
case "integer":
$columnEntry .= " INTEGER(10)" . $modifierEntry;
break;
case "boolean":
$columnEntry .= " INTEGER(1)" . $modifierEntry;
break;
}
return $columnEntry;
}
}
//Set operator panel web root
if(class_exists("freepbx_conf")) {
echo "Setting operator panel web root....<br>";
$set["FOPWEBROOT"] = "isymphony";
$freepbx_conf =& freepbx_conf::create();
$freepbx_conf->set_conf_values($set, true, true);
echo "Done<br>";
}
//Create symlink that points to the module directory in order to run the client redirect script
echo "Creating client symlink....<br>";
if(file_exists($amp_conf['AMPWEBROOT'] . '/isymphony')) {
unlink($amp_conf['AMPWEBROOT'] . '/isymphony');
}
symlink($amp_conf['AMPWEBROOT'] .'/admin/modules/isymphony/', $amp_conf['AMPWEBROOT'] . '/isymphony');
if(file_exists($amp_conf['AMPWEBROOT'] . '/admin/isymphony')) {
unlink($amp_conf['AMPWEBROOT'] . '/admin/isymphony');
}
symlink($amp_conf['AMPWEBROOT'] .'/admin/modules/isymphony/', $amp_conf['AMPWEBROOT'] . '/admin/isymphony');
echo "Done<br>";
//Build location table
$columns = array( new isymphony_column("admin_user_name", "string", "admin", "", false, false),
new isymphony_column("admin_password", "string", "secret", "", false, false),
new isymphony_column("originate_timeout", "integer", 30000, "", false, false),
new isymphony_column("auto_reload", "boolean", 1, "", false, false),
new isymphony_column("page_status_enabled", "boolean", 1, "", false, false),
new isymphony_column("jabber_host", "string", "", "", false, false),
new isymphony_column("jabber_domain", "string", "", "", false, false),
new isymphony_column("jabber_resource", "string", "iSymphony", "", false, false),
new isymphony_column("jabber_port", "integer", 5222, "", false, false),
new isymphony_column("log_jabber_messages", "boolean", 0, "", false, false),
new isymphony_column("isymphony_host", "string", "localhost", "", false, false),
new isymphony_column("isymphony_location", "string", "default", "", false, false),
new isymphony_column("isymphony_tenant", "string", "default", "", false, false),
new isymphony_column("isymphony_client_port", "integer", 50003, "", false, false),
new isymphony_column("asterisk_host", "string", "localhost", "", false, false));
$table = new isymphony_table("isymphony_location", $columns);
$builder = new isymphony_table_builder($table);
$builder->build(array(array("junk")));
//Build users table
$columns = array( new isymphony_column("isymphony_user_id", "primary", "", "", true, true),
new isymphony_column("user_id", "string", "", "user_id", true, true),
new isymphony_column("add_extension", "boolean", 1, "", false, false),
new isymphony_column("add_profile", "boolean", 1, "", false, false),
new isymphony_column("password", "string", "secret", "", false, false),
new isymphony_column("display_name", "string", "", "display_name", false, false),
new isymphony_column("peer", "string", "", "peer", false, false),
new isymphony_column("email", "string", "", "", false, false),
new isymphony_column("cell_phone", "string", "", "", false, false),
new isymphony_column("auto_answer", "boolean", 0, "", false, false),
new isymphony_column("jabber_host", "string", "", "", false, false),
new isymphony_column("jabber_domain", "string", "", "", false, false),
new isymphony_column("jabber_resource", "string", "iSymphony", "", false, false),
new isymphony_column("jabber_port", "integer", 5222, "", false, false),
new isymphony_column("jabber_user_name", "string", "", "", false, false),
new isymphony_column("jabber_password", "string", "", "", false, false));
$table = new isymphony_table("isymphony_users", $columns);
$builder = new isymphony_table_builder($table);
//Gather user info
$entries = array();
if((function_exists("core_users_list")) && (($freePBXUsers = core_users_list()) !== null)){
foreach($freePBXUsers as $freePBXUser) {
if(function_exists("core_devices_get")) {
$freePBXDeviceInfo = core_devices_get($freePBXUser[0]);
$userId = $freePBXUser[0];
$displayName = $freePBXUser[1] == "" ? $freePBXUser[0] : $freePBXUser[1];
$peer = ($freePBXDeviceInfo['dial'] != "") ? $freePBXDeviceInfo['dial'] : "SIP/$userId";
array_push($entries, array("user_id" => $userId, "display_name" => $displayName, "peer" => $peer));
}
}
}
$builder->build($entries);
//Build queues table
$columns = array( new isymphony_column("isymphony_queue_id", "primary", "", "", true, true),
new isymphony_column("queue_id", "string", "", "queue_id", true, true),
new isymphony_column("add_queue", "boolean", 1, "", false, false),
new isymphony_column("display_name", "string", "", "display_name", false, false));
$table = new isymphony_table("isymphony_queues", $columns);
$builder = new isymphony_table_builder($table);
//Gather queue info
$entries = array();
if((function_exists("queues_list")) && (($freePBXQueues = queues_list()) !== null)) {
foreach($freePBXQueues as $freePBXQueue) {
$queueId = $freePBXQueue[0];
$displayName = $freePBXQueue[1] == "" ? $freePBXQueue[0] : $freePBXQueue[1];
array_push($entries, array("queue_id" => $queueId, "display_name" => $displayName));
}
}
$builder->build($entries);
//Build conference rooms table
$columns = array( new isymphony_column("isymphony_conference_room_id", "primary", "", "", true, true),
new isymphony_column("conference_room_id", "string", "", "conference_room_id", true, true),
new isymphony_column("add_conference_room", "boolean", 1, "", false, false),
new isymphony_column("display_name", "string", "", "display_name", false, false));
$table = new isymphony_table("isymphony_conference_rooms", $columns);
$builder = new isymphony_table_builder($table);
//Gather queue info
$entries = array();
if((function_exists("conferences_list")) && (($freePBXConferenceRooms = conferences_list()) !== null)) {
foreach($freePBXConferenceRooms as $freePBXConferenceRoom) {
$conferenceRoomId = $freePBXConferenceRoom[0];
$conferenceRoomsDispalyName = $freePBXConferenceRoom[1] == "" ? $freePBXConferenceRoom[0] : $freePBXConferenceRoom[1];
array_push($entries, array("conference_room_id" => $conferenceRoomId, "display_name" => $conferenceRoomsDispalyName));
}
}
$builder->build($entries);
?>