-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.inc.php
More file actions
422 lines (334 loc) · 14.2 KB
/
Copy pathfunctions.inc.php
File metadata and controls
422 lines (334 loc) · 14.2 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
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<?php
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
/*
* freepbx-misdn -- mISDN module for FreePBX
*
* Copyright (C) 2006, Thomas Liske.
*
* Thomas Liske <thomas.liske@beronet.com>
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
define('MISDN_PWD', dirname(__FILE__));
require_once(MISDN_PWD.'/xslt.inc.php');
// ************** components.class.php additions **************
class gui_text extends guiinput {
function gui_text($elemname, $currentvalue = '', $prompttext = '', $helptext = '') {
// call parent class contructor
$parent_class = get_parent_class($this);
parent::$parent_class($elemname, $currentvalue, $prompttext, $helptext);
$this->html_input = htmlentities($this->currentvalue);
}
}
// ************** Config File Generation **************
/* Configfile Generation Class */
class misdn_conf {
function get_filename() {
return array('misdn.conf');
}
function generateConf($file) {
global $misdn_fields;
if ($file == 'misdn.conf') {
if (misdn_general_get('bridging'))
$bridging = "yes";
else
$bridging = "no";
$ret = <<<EOF
[general]
bridging = $bridging
#include misdn_general_custom.conf
[default]
#include misdn_default_custom.conf
EOF;
foreach(misdn_groups_list() as $group) {
$name = $group['name'];
switch ($group['type']) {
case 0:
$context = 'from-internal';
break;
case 1:
$context = 'from-pstn';
break;
default:
$context = 's';
break;
}
$ports = join(',', misdn_ports_get_sel($name));
$ret .= <<<EOG
[$name]
context=$context
ports=$ports
EOG;
unset($group['name']);
unset($group['type']);
foreach(array_keys($group) as $key) {
$ret .= "$key=$group[$key]\n";
}
$ret .= '#include misdn_'.$name."_custom.conf\n\n";
}
return $ret;
}
}
}
// ************** Helper Functions **************
function misdn_general_get($key) {
$val = sql("SELECT `data` FROM `misdn` WHERE `keyword`='"._misdn_escape_string($key)."' AND `id`='XXXXXX'", "getOne");
return $val;
}
function misdn_general_set($key, $val) {
sql("UPDATE `misdn` SET `data`='"._misdn_escape_string($val)."' WHERE `keyword`='"._misdn_escape_string($key)."' AND `id`='XXXXXX'");
}
/* get all configured groups */
function misdn_groups_list($type = null) {
global $misdn_fields;
$tf = '';
if ($type != null)
$tf = "WHERE type=$type";
return sql("SELECT name, type, $misdn_fields FROM `misdn_groups` $tf ORDER BY `name` ASC", "getAll", DB_FETCHMODE_ASSOC);
}
/* get a specific group by name */
function misdn_groups_get($name) {
global $misdn_fields;
$ar = sql("SELECT name, type, $misdn_fields FROM `misdn_groups` WHERE `name` = '"._misdn_escape_string($name)."'", "getAll", DB_FETCHMODE_ASSOC);
return array_shift($ar);
}
/* get all ports which are used by other groups, so they are not available for the actual group */
function misdn_ports_get_na($name) {
global $misdn_fields;
$ar = sql("SELECT `port` FROM `misdn_ports` WHERE `group` <> '"._misdn_escape_string($name)."' ORDER BY `port` ASC", "getAll", DB_FETCHMODE_ASSOC);
$ret = array();
foreach($ar as $port)
$ret[$port['port']] = 1;
return $ret;
}
/* get ports for a specific group as values */
function misdn_ports_get_sel($name) {
global $misdn_fields;
$ar = sql("SELECT `port` FROM `misdn_ports` WHERE `group` = '"._misdn_escape_string($name)."' ORDER BY `port` ASC", "getAll", DB_FETCHMODE_ASSOC);
$ret = array();
foreach($ar as $port)
$ret[] = $port['port'];
return $ret;
}
/* get ports for a specific group as keys */
function misdn_ports_get($name) {
global $misdn_fields;
$ar = sql("SELECT `port` FROM `misdn_ports` WHERE `group` = '"._misdn_escape_string($name)."'", "getAll", DB_FETCHMODE_ASSOC);
$ret = array();
foreach($ar as $port)
$ret[$port['port']] = 1;
return $ret;
}
function _misdn_escape_string($var) {
global $db;
return $db->escapeSimple($var);
}
/* get all configured ports */
function misdn_ports_list_exts() {
global $misdn_fields;
return sql("SELECT misdn_ports.port FROM `misdn_ports`, `misdn_groups` WHERE misdn_ports.group = misdn_groups.name AND misdn_groups.type = 0 ORDER BY `port` ASC", "getAll", DB_FETCHMODE_ASSOC);
}
function misdn_ports_list_trunks() {
global $misdn_fields;
return sql("SELECT misdn_ports.port FROM `misdn_ports`, `misdn_groups` WHERE misdn_ports.group = misdn_groups.name AND misdn_groups.type = 1 ORDER BY `port` ASC", "getAll", DB_FETCHMODE_ASSOC);
}
/* retrieve all groups and ports, usefull for dialstring generation */
function misdn_groups_ports() {
$ret = array();
foreach(misdn_groups_list(1) as $group) {
$ret[] = 'g:'.$group['name'];
}
foreach(misdn_ports_list_trunks() as $port) {
$ret[] = $port['port'];
}
return $ret;
}
/* retrieve ISDN card configuration from mISDN */
function misdn_dump() {
$xsl = xslt_create();
$res = trim(xslt_process($xsl, '/etc/mISDN.conf', MISDN_PWD.'/misdn_dump.xsl'));
if (strlen($res) && !strstr($res, "\n"))
return array(explode(',', $res));
$ret = array();
foreach(explode("\n", $res) as $line)
$ret[] = explode(',', $line);
return $ret;
}
// ************** Page: GENERAL **************
/* apply hooks */
function misdn_mgeneral_configpageinit($dispnum) {
global $currentcomponent;
$currentcomponent->addprocessfunc('misdn_mgeneral_configprocess');
}
function misdn_mgeneral_configprocess() {
if (isset($_POST['bridging'])) {
$b = $_POST['bridging'];
settype($b, 'int');
misdn_general_set('bridging', $b);
needreload();
}
}
// ************** Page: GROUPS **************
$misdn_echo = array(
array('value' => 0, 'text' => '0 [off]'),
array('value' => 32, 'text' => '32'),
array('value' => 64, 'text' => '64'),
array('value' => 128, 'text' => '128 [default]'),
array('value' => 256, 'text' => '256')
);
$misdn_yesno = array(
array('value' => 1, 'text' => _('yes')),
array('value' => 0, 'text' => _('no')),
);
$misdn_methods = array(
array('value' => 'standard' , 'text' => _('Standard')),
array('value' => 'round_robin', 'text' => _('Round Robin')),
);
$misdn_txgains = array();
for($i=-8; $i<=8; $i++)
$misdn_txgains[] = array('value' => $i, 'text' => $i);
$misdn_dialplans = array(
array('value' => 0, 'text' => _('Unknown')),
array('value' => 1, 'text' => _('International')),
array('value' => 2, 'text' => _('National')),
array('value' => 4, 'text' => _('Subscriber')),
);
/* This is derived from the msisdn_groups table structure - so keep it in sync! */
$misdn_confkeys = array(
array('name' => 'msns' , 'title' => 'MSNs' , 'default' => '*', 'type' => 's', 'db' => 's', 'descr' => _("Give a comma separated list (or '*' to match any) of MSNs for TE ports.")),
array('name' => 'echocancel' , 'title' => 'Echocancellation' , 'default' => 0, 'type' => 'a', 'db' => 'i', 'alt' => $misdn_echo , 'descr' => _("This enables echocancellation, with the given number of taps. Be aware, move this setting only to outgoing portgroups! A value of zero turns echocancellation off.")),
array('name' => 'immediate' , 'title' => 'Immediate' , 'default' => 0, 'type' => 'a', 'db' => 'b', 'alt' => $misdn_yesno , 'descr' => ''),
array('name' => 'method' , 'title' => 'Method' , 'default' => 'standard', 'type' => 'a', 'db' => 's', 'alt' => $misdn_methods , 'descr' => _("Set the method to use for channel selection.<br /><i>Standard</i> always chooses the first free channel with the lowest number.<br /><i>Round Robin</i> uses the round robin algorithm to select a channel. Use this if you want to balance your load.")),
array('name' => 'pmp_l1_check' , 'title' => 'PMP L1 Check' , 'default' => 0, 'type' => 'a', 'db' => 'b', 'alt' => $misdn_yesno , 'descr' => _("This option defines, if chan_misdn should check the L1 on a PMP before making a group call on it. The L1 may go down for PMP Ports so we might need this.")),
array('name' => 'txgain' , 'title' => 'TX Gain' , 'default' => 0, 'type' => 'a', 'db' => 'i', 'alt' => $misdn_txgains , 'descr' => _("Changes the TX Gain.")),
array('name' => 'dialplan' , 'title' => 'Dialplan' , 'default' => 0, 'type' => 'a', 'db' => 'i', 'alt' => $misdn_dialplans, 'descr' => _("Type Of Number in ISDN Terms (for outgoing calls).")),
array('name' => 'nationalprefix' , 'title' => 'National Prefix' , 'default' => '0', 'type' => 's', 'db' => 's', 'descr' => _("National prefix is put before the oad if an according dialplan is set by the other end.")),
array('name' => 'internationalprefix' , 'title' => 'International Prefix', 'default' => '00', 'type' => 's', 'db' => 's', 'descr' => _("International prefix is put before the oad if an according dialplan is set by the other end.")),
array('name' => 'language' , 'title' => 'Language' , 'default' => 'en', 'type' => 's', 'db' => 's', 'descr' => ''),
array('name' => 'callgroup' , 'title' => 'Callgroup' , 'default' => 0, 'type' => 'i', 'db' => 'i', 'descr' => ''),
array('name' => 'pickupgroup' , 'title' => 'Pickupgroup' , 'default' => 0, 'type' => 'i', 'db' => 'i', 'descr' => ''),
array('name' => 'senddtmf' , 'title' => 'Send DTMF' , 'default' => 0, 'type' => 'a', 'db' => 'b', 'alt' => $misdn_yesno , 'descr' => _("Either if we should produce DTMF Tones ourselves.")),
array('name' => 'reject_cause' , 'title' => 'Reject Cause' , 'default' => 21, 'type' => 'i', 'db' => 'i', 'descr' => _("Reject code sent to the caller in PMP.<br /><i>16</i> normal call clearing.<br /><i>17</i> user busy.<br /><i>21</i> disconnected.")),
);
$misdn_fields_ar = array('`name`');
foreach($misdn_confkeys as $confkey) {
$misdn_fields_ar[] = '`'.$confkey['name'].'`';
}
global $misdn_fields;
$misdn_fields = implode(',', $misdn_fields_ar);
/* apply hooks */
function misdn_mgroups_configpageinit($dispnum) {
global $currentcomponent;
extract($_REQUEST);
$action = isset($_REQUEST['action'])?$_REQUEST['action']:null;
$tech_hardware = isset($_REQUEST['tech_hardware'])?$_REQUEST['tech_hardware']:null;
$extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
$display = isset($_REQUEST['display'])?$_REQUEST['display']:null;
$gdisplay = isset($_REQUEST['gdisplay'])?$_REQUEST['gdisplay']:null;
if ($display == 'extensions') {
// add entry to Basic->Extensions device list
if ($ports = misdn_ports_list_exts())
$currentcomponent->addoptlistitem('devicelist', 'misdn_generic', _('Generic mISDN Device'));
if ( $action == 'del' ) {
// nothing
} else {
$tmparr = array();
$tmparr['context'] = array('value' => 'from-internal', 'level' => 2);
if ($extdisplay)
$tmparr['dial'] = array('value' => '', 'level' => 0);
else {
$select = array();
foreach($ports as $port) {
$select[] = array('value' => 'mISDN/'.$port['port'], 'text' => 'mISDN/'.$port['port']);
}
$tmparr['port'] = array('value' => '', 'select' => $select, 'level' => 0);
};
$currentcomponent->addgeneralarrayitem('devtechs', 'misdn', $tmparr);
unset($tmparr);
}
}
else if ($dispnum == 'mgroups') {
if ($gdisplay) {
$currentcomponent->addgeneralarrayitem('misdn', 'group', misdn_groups_get($gdisplay));
$currentcomponent->addgeneralarrayitem('misdn', 'ports', misdn_ports_get($gdisplay));
}
$currentcomponent->addprocessfunc('misdn_mgroups_configprocess_mgroups');
}
global $devinfo_dial;
$devinfo_dial = "Port:";
}
function misdn_format_sql($ar, $val) {
if ($ar['type'] == 'a') {
$v = $ar['default'];
foreach($ar['alt'] as $alt) {
if ($alt['value'] == $val) {
$v = $val;
break;
}
}
}
else
$v = $val;
switch ($ar['db']) {
case 'b':
if ($v)
$v = 1;
else
$v = 0;
case 'i':
settype($v, 'int');
return $v;
default:
return "'"._misdn_escape_string($v)."'";
}
}
function misdn_mgroups_configprocess_mgroups() {
global $misdn_confkeys;
$gdisplay = isset($_REQUEST['gdisplay'])?$_REQUEST['gdisplay']:null;
if ($_GET['del'] && $gdisplay) {
$name = _misdn_escape_string($_GET['gdisplay']);
sql("DELETE FROM `misdn_ports` WHERE `group`='$name'");
sql("DELETE FROM `misdn_groups` WHERE `name`='$name'");
unset($_REQUEST['gdisplay']);
return;
}
if (!$_POST['name'])
return;
$_POST['name'] = trim($_POST['name']);
if ($_POST['editgroup']) {
$keyvals = array("`name`='"._misdn_escape_string($_POST['name'])."'");
foreach($misdn_confkeys as $confkey) {
$keyvals[] = '`'.$confkey['name'].'`='.misdn_format_sql($confkey, $_POST[$confkey['name']]);
}
$sql = "UPDATE `misdn_groups` SET ".implode(',', $keyvals)." WHERE `name`='"._misdn_escape_string($_POST['editgroup'])."'";
sql("DELETE FROM `misdn_ports` WHERE `group`='"._misdn_escape_string($_POST['editgroup'])."'");
}
else {
$keys = array();
$vals = array();
foreach($misdn_confkeys as $confkey) {
$keys[] = '`'.$confkey['name'].'`';
$vals[] = misdn_format_sql($confkey, $_POST[$confkey['name']]);
}
$type = $_POST['grouptype'];
settype($type, 'int');
$sql = 'INSERT INTO `misdn_groups` (`name`,`type`,'.implode(',', $keys).") VALUES ('"._misdn_escape_string($_POST['name'])."',$type,".implode(',', $vals).')';
}
sql($sql);
$i = 0;
foreach(misdn_dump() as $card) {
for($j=0; $j<$card[1]; $j++) {
$i++;
if ($_POST["port$i"])
sql("INSERT INTO `misdn_ports` (`port`, `group`) VALUES ($i, '"._misdn_escape_string($_POST['name'])."')");
}
}
needreload();
}