forked from FreePBX/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.inc.php
7902 lines (6931 loc) · 381 KB
/
functions.inc.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
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// vim: :set filetype=php tabstop=4 shiftwidth=4 autoindent smartindent:
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
// License for all code of this FreePBX module can be found in the license file inside the module directory
// Copyright 2006-2014 Schmooze Com Inc.
//
class core_conf {
var $_sip_general = array();
var $_sip_additional = array();
var $_sip_notify = array();
var $_iax_general = array();
var $_iax_additional = array();
var $_dahdi_additional = array();
var $_featuregeneral = array();
var $_featuregeneralsection = array();
var $_featuremap = array();
var $_applicationmap = array();
var $_res_odbc = array();
var $_rtp_additional = array();
var $dev_user_map;
// map the actual vmcontext and user devicename if the device is fixed
private function map_dev_user($account, $keyword, $data) {
global $amp_conf;
if (!isset($this->dev_user_map)) {
$this->dev_user_map = core_devices_get_user_mappings();
}
if (!empty($this->dev_user_map[$account]) && $this->dev_user_map[$account]['devicetype'] == 'fixed') {
switch (strtolower($keyword)) {
case 'callerid':
$user_option = $this->dev_user_map[$account]['description'] . ' <' . $account . '>';
break;
case 'mailbox':
if ((empty($this->dev_user_map[$account]['vmcontext']) || $this->dev_user_map[$account]['vmcontext'] == 'novm')
&& strtolower($data) == "$account" . "@device" && $amp_conf['DEVICE_REMOVE_MAILBOX']) {
// they have no vm so don't put a mailbox=line
return "";
} elseif (strtolower($data) == "$account" . "@device"
&& !empty($this->dev_user_map[$account]['vmcontext']) &&
$this->dev_user_map[$account]['vmcontext'] != 'novm') {
$user_option = $this->dev_user_map[$account]['user'] . "@" . $this->dev_user_map[$account]['vmcontext'];
} else {
$user_option = $data;
}
}
$output = $keyword . "=" . $user_option . "\n";
} else {
$output = $keyword . "=" . $data . "\n";
}
return $output;
}
// return an array of filenames to write
function get_filename() {
global $chan_dahdi;
$files = array(
'sip_additional.conf',
'sip_registrations.conf',
'iax_additional.conf',
'iax_registrations.conf',
'sip_general_additional.conf',
'iax_general_additional.conf',
'features_general_additional.conf',
'features_applicationmap_additional.conf',
'features_featuremap_additional.conf',
'localprefixes.conf',
'sip_notify_additional.conf',
'res_odbc_additional.conf',
'chan_dahdi_additional.conf',
'rtp_additional.conf',
'http_additional.conf'
);
return $files;
}
// return the output that goes in each of the files
function generateConf($file) {
global $version;
global $amp_conf;
switch ($file) {
case 'sip_general_additional.conf':
return $this->generate_sip_general_additional($version);
break;
case 'sip_additional.conf':
return $this->generate_sip_additional($version);
break;
case 'sip_registrations.conf':
return $this->generate_sip_registrations($version);
break;
case 'sip_notify_additional.conf':
return $this->generate_sip_notify_additional($version);
break;
case 'iax_general_additional.conf':
return $this->generate_iax_general_additional($version);
break;
case 'iax_additional.conf':
return $this->generate_iax_additional($version);
break;
case 'iax_registrations.conf':
return $this->generate_iax_registrations($version);
break;
case 'chan_dahdi_additional.conf':
return $this->generate_zapata_additional($version, 'dahdi').$this->generate_zapata_additional($version);
break;
case 'zapata_additional.conf':
return $this->generate_zapata_additional($version);
break;
case 'features_general_additional.conf':
return $this->generate_featuregeneral_additional($version);
break;
case 'features_applicationmap_additional.conf':
return $this->generate_applicationmap_additional($version);
break;
case 'features_featuremap_additional.conf':
return $this->generate_featuremap_additional($version);
break;
case 'res_odbc_additional.conf':
return $this->generate_res_odbc_additional($version);
break;
case 'rtp_additional.conf':
return $this->generate_rtp_additional($version);
break;
case 'http_additional.conf':
return $this->generate_http_additional($version);
break;
}
}
// If sipsettings isn't there this will try to set the rtp.conf value
//
function setDefaultRtp() {
// if we have sipsettings then we don't need to do anything
// it will be done there
if (function_exists('sipsettings_hookGet_config')) {
return true;
}
$sql = "SELECT value FROM admin WHERE variable = 'RTPSTART'";
$rtpstart = sql($sql,'getOne');
$rtpstart = $rtpstart ? $rtpstart : '10000';
$sql = "SELECT value FROM admin WHERE variable = 'RTPEND'";
$rtpend = sql($sql,'getOne');
$rtpend = $rtpend ? $rtpend : '20000';
$this->addRtpAdditional('general', array('rtpstart' => $rtpstart));
$this->addRtpAdditional('general', array('rtpend' => $rtpend));
return true;
}
function addRtpAdditional($section,$entries) {
$this->_rtp_additional[$section][] = $entries;
}
function generate_rtp_additional($ast_version) {
$output = '';
if (empty($this->_rtp_additional)) {
$this->setDefaultRtp();
}
foreach ($this->_rtp_additional as $section => $entries) {
$output .= "[".$section."]\n";
foreach ($entries as $key => $entry) {
foreach ($entry as $ekey => $value) {
$output .= "$ekey=$value\n";
}
}
$output .= "\n";
}
return $output;
}
function generate_http_additional($ast_version) {
$freepbx_conf =& freepbx_conf::create();
$output = "[general]\n";
$output .= "enabled=".($freepbx_conf->get_conf_setting('HTTPENABLED') ? 'yes' : 'no')."\n";
$output .= "enablestatic=".($freepbx_conf->get_conf_setting('HTTPENABLESTATIC') ? 'yes' : 'no')."\n";
$output .= "bindaddr=".$freepbx_conf->get_conf_setting('HTTPBINDADDRESS')."\n";
$output .= "bindport=".$freepbx_conf->get_conf_setting('HTTPBINDPORT')."\n";
$output .= "prefix=".$freepbx_conf->get_conf_setting('HTTPPREFIX')."\n";
return $output;
}
function addSipNotify($section,$entries) {
$this->_sip_notify[] = array('section' => $section, 'entries' => $entries);
}
function generate_sip_notify_additional($ast_version) {
$output = '';
if (isset($this->_sip_notify) && is_array($this->_sip_notify)) {
foreach ($this->_sip_notify as $section) {
$output .= "[".$section['section']."]\n";
foreach ($section['entries'] as $key => $value) {
if (strtolower($key) == 'content-length') {
continue;
}
$output .= "$key=>$value\n";
}
$output .= "\n";
}
}
return $output;
}
function addResOdbc($section,$entries) {
$this->_res_odbc[$section][] = $entries;
}
function generate_res_odbc_additional($ast_version) {
$output = '';
if (!empty($this->_res_odbc)) {
foreach ($this->_res_odbc as $section => $entries) {
$output .= "[".$section."]\n";
foreach ($entries as $key => $entry) {
foreach ($entry as $key => $value) {
$output .= "$key=>$value\n";
}
}
$output .= "\n";
}
}
return $output;
}
function addSipAdditional($section, $key, $value) {
$this->_sip_additional[$section][] = array('key' => $key, 'value' => $value);
}
function addSipGeneral($key, $value) {
$this->_sip_general[] = array('key' => $key, 'value' => $value);
}
function generate_sip_general_additional($ast_version) {
$output = '';
if (isset($this->_sip_general) && is_array($this->_sip_general)) {
foreach ($this->_sip_general as $values) {
$output .= $values['key']."=".$values['value']."\n";
}
}
return $output;
}
function addIaxGeneral($key, $value) {
$this->_iax_general[] = array('key' => $key, 'value' => $value);
}
function generate_iax_general_additional($ast_version) {
$output = '';
if (isset($this->_iax_general) && is_array($this->_iax_general)) {
foreach ($this->_iax_general as $values) {
$output .= $values['key']."=".$values['value']."\n";
}
}
return $output;
}
function addFeatureGeneral($key, $value) {
$this->_featuregeneral[] = array('key' => $key, 'value' => $value);
}
function addFeatureGeneralSection($section, $key, $value) {
$this->_featuregeneralsection[$section][] = array('key' => $key, 'value' => $value);
}
function generate_featuregeneral_additional($ast_version) {
$output = '';
if (isset($this->_featuregeneral) && is_array($this->_featuregeneral)) {
foreach ($this->_featuregeneral as $values) {
$output .= $values['key']."=".$values['value']."\n";
}
}
foreach ($this->_featuregeneralsection as $section => $values) {
$output .= "\n[$section]\n";
foreach ($values as $value) {
$output .= $value['key'] . "=" . $value['value'] . "\n";
}
}
return $output;
}
function addFeatureMap($key, $value) {
$this->_featuremap[] = array('key' => $key, 'value' => $value);
}
function generate_featuremap_additional($ast_version) {
$output = '';
if (isset($this->_featuremap) && is_array($this->_featuremap)) {
foreach ($this->_featuremap as $values) {
$output .= $values['key']."=".$values['value']."\n";
}
}
return $output;
}
function addApplicationMap($key, $value, $add_to_dynamic_features=false) {
global $ext;
$this->_applicationmap[] = array('key' => $key, 'value' => $value);
//
// Now add it to the DYNAMIC_FEATURES
// TODO: one caveat, if we ever want to make such an application conditional, we will have to change
// this as for now it makes it for everyone.
//
if ($add_to_dynamic_features) {
$ext->_globals['DYNAMIC_FEATURES'] = empty($ext->_globals['DYNAMIC_FEATURES']) ? $key : $ext->_globals['DYNAMIC_FEATURES'] . ',' . $key;
}
}
function generate_applicationmap_additional($ast_version) {
$output = '';
if (isset($this->_applicationmap) && is_array($this->_applicationmap)) {
foreach ($this->_applicationmap as $values) {
$output .= $values['key']."=>".$values['value']."\n";
}
}
return $output;
}
function generate_sip_additional($ast_version) {
global $db;
$table_name = "sip";
$additional = "";
$output = "";
// Asterisk 1.4 requires call-limit be set for hints to work properly
//
if (version_compare($ast_version, "1.6.1", "ge")) {
$call_limit = "callcounter=yes\n";
$ver12 = false;
} else if (version_compare($ast_version, "1.4", "ge")) {
$call_limit = "call-limit=50\n";
$ver12 = false;
} else {
$call_limit = "";
$ver12 = true;
}
if (version_compare($ast_version, "1.6", "ge")) {
$faxdetect = "faxdetect=no\n";
$ver16 = true;
} else {
$faxdetect = "";
$ver16 = false;
}
// TODO: Temporary Kludge until CCSS is fixed
//
if (function_exists('campon_get_config') && version_compare($ast_version, "1.8", "ge")) {
$cc_monitor_policy = "cc_monitor_policy=generic\n";
} else {
$cc_monitor_policy = "";
}
$sql = "SELECT keyword,data from $table_name where id=-1 and keyword <> 'account' and flags <> 1";
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($results)) {
die($results->getMessage());
}
foreach ($results as $result) {
if ($ver12) {
$additional .= $result['keyword']."=".$result['data']."\n";
} else {
$option = $result['data'];
switch (strtolower($result['keyword'])) {
case 'insecure':
if ($option == 'very')
$additional .= "insecure=port,invite\n";
else if ($option == 'yes')
$additional .= "insecure=port\n";
else
$additional .= $result['keyword']."=$option\n";
break;
case 'allow':
case 'disallow':
case 'accountcode':
if ($option != '')
$additional .= $result['keyword']."=$option\n";
break;
default:
$additional .= $result['keyword']."=$option\n";
}
}
}
$sql = "SELECT data,id from $table_name where keyword='account' and flags <> 1 group by data";
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($results)) {
die($results->getMessage());
}
foreach ($results as $result) {
$account = $result['data'];
$id = $result['id'];
$output .= "[$account]\n";
$sql = "SELECT keyword,data from $table_name where id='$id' and keyword <> 'account' and flags <> 1 order by flags, keyword DESC";
$results2_pre = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($results2_pre)) {
die($results2->getMessage());
}
// Move all 'disallow=all' and 'deny' to the top to avoid errors
//
$results2 = array();
foreach ($results2_pre as $element) {
if (strtolower(trim($element['keyword'])) != 'secret') {
$options = explode("&", $element['data']);
foreach ($options as $option) {
if (($element['keyword'] == 'disallow' && $option == 'all') | ($element['keyword'] == 'deny')) {
array_unshift($results2,array('keyword'=>$element['keyword'],'data'=>$option));
} else {
$results2[] = array('keyword'=>$element['keyword'],'data'=>$option);
}
}
} else {
$results2[] = array('keyword'=>$element['keyword'],'data'=>str_replace(';','\;',$element['data']));
}
}
unset($results2_pre);
$context='';
foreach ($results2 as $result2) {
$option = strtolower($result2['data']);
if ($ver12) {
switch (strtolower($result2['keyword'])) {
case 'context':
$context = $option;
//fall-through
default:
$output .= $result2['keyword']."=".$result2['data']."\n";
}
} else {
switch (strtolower($result2['keyword'])) {
case 'insecure':
if ($option == 'very')
$output .= "insecure=port,invite\n";
else if ($option == 'yes')
$output .= "insecure=port\n";
else
$output .= $result2['keyword']."=".$result2['data']."\n";
break;
case 'allow':
case 'disallow':
case 'accountcode':
if ($option != '')
$output .= $result2['keyword']."=".$result2['data']."\n";
break;
case 'callerid':
case 'mailbox':
$output .= $this->map_dev_user($account, $result2['keyword'], $result2['data']);
break;
case 'context':
$context = $result2['data'];
//fall-through
default:
$output .= $result2['keyword']."=".$result2['data']."\n";
}
}
}
switch (substr($id,0,8)) {
case 'tr-peer-':
if ($context == '') {
$output .= "context=from-trunk-sip-$account\n";
}
break;
case 'tr-user-':
if ($context == '') {
$tn = substr($id, 8);
// this is a 'user' trunk, we need to get the name of the corresponding 'peer'
// trunk so we can set the context appropriately for the group count
//
$td = core_trunks_getDetails($tn);
if (isset($td['channelid'])) {
$output .= "context=from-trunk-sip-".$td['channelid']."\n";
}
}
break;
default:
if ($call_limit) {
$output .= $call_limit;
}
if ($faxdetect) {
$output .= $faxdetect;
}
if ($cc_monitor_policy) {
$output .= $cc_monitor_policy;
}
}
if (isset($this->_sip_additional[$account])) {
foreach ($this->_sip_additional[$account] as $asetting) {
$output .= $asetting['key'] . "=" . $asetting['value'] . "\n";
}
}
$output .= $additional."\n";
}
return $output;
}
function generate_sip_registrations($ast_version) {
global $db;
$table_name = "sip";
$output = "";
$sql = "SELECT keyword,data FROM $table_name WHERE `id` LIKE 'tr-reg-%' AND keyword <> 'account' AND flags <> 1";
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($results)) {
die($results->getMessage());
}
foreach ($results as $result) {
$output .= $result['keyword']."=".$result['data']."\n";
}
return $output;
}
function addIaxAdditional($section, $key, $value) {
$this->_iax_additional[$section][] = array('key' => $key, 'value' => $value);
}
function generate_iax_additional($ast_version) {
global $db;
$table_name = "iax";
$additional = "";
$output = "";
$ver12 = version_compare($ast_version, '1.4', 'lt');
$sql = "SELECT keyword,data from $table_name where id=-1 and keyword <> 'account' and flags <> 1";
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($results)) {
die($results->getMessage());
}
foreach ($results as $result) {
if ($ver12) {
$additional .= $result['keyword']."=".$result['data']."\n";
} else {
$option = $result['data'];
switch ($result['keyword']) {
case 'notransfer':
if (strtolower($option) == 'yes') {
$additional .= "transfer=no\n";
} else if (strtolower($option) == 'no') {
$additional .= "transfer=yes\n";
} else if (strtolower($option) == 'mediaonly') {
$additional .= "transfer=mediaonly\n";
} else {
$additional .= $result['keyword']."=$option\n";
}
break;
case 'allow':
case 'disallow':
case 'accountcode':
if ($option != '')
$additional .= $result['keyword']."=$option\n";
break;
case 'requirecalltoken':
if ($option != '')
$additional .= $result['keyword']."=$option\n";
break;
default:
$additional .= $result['keyword']."=$option\n";
}
}
}
$sql = "SELECT data,id from $table_name where keyword='account' and flags <> 1 group by data";
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($results)) {
die($results->getMessage());
}
foreach ($results as $result) {
$account = $result['data'];
$id = $result['id'];
$output .= "[$account]\n";
$sql = "SELECT keyword,data from $table_name where id='$id' and keyword <> 'account' and flags <> 1 order by flags, keyword DESC";
$results2_pre = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($results2_pre)) {
die($results2_pre->getMessage());
}
// Move all 'disallow=all' and 'deny=' to the top to avoid errors
//
$results2 = array();
foreach ($results2_pre as $element) {
if (strtolower(trim($element['keyword'])) != 'secret') {
$options = explode("&", $element['data']);
foreach ($options as $option) {
if (($element['keyword'] == 'disallow' && $option == 'all') | ($element['keyword'] == 'deny')) {
array_unshift($results2,array('keyword'=>$element['keyword'],'data'=>$option));
} else {
$results2[] = array('keyword'=>$element['keyword'],'data'=>$option);
}
}
} else {
$results2[] = array('keyword'=>$element['keyword'],'data'=>str_replace(';','\;',$element['data']));
}
}
unset($results2_pre);
$context='';
foreach ($results2 as $result2) {
$option = strtolower($result2['data']);
if ($ver12) {
switch (strtolower($result2['keyword'])) {
case 'context':
$context = $result2['data'];
//fall-through
default:
$output .= $result2['keyword']."=".$result2['data']."\n";
}
} else {
switch ($result2['keyword']) {
case 'notransfer':
if (strtolower($option) == 'yes') {
$output .= "transfer=no\n";
} else if (strtolower($option) == 'no') {
$output .= "transfer=yes\n";
} else if (strtolower($option) == 'mediaonly') {
$output .= "transfer=mediaonly\n";
} else {
$output .= $result2['keyword']."=".$result2['data']."\n";
}
break;
case 'allow':
case 'disallow':
case 'accountcode':
if ($option != '')
$output .= $result2['keyword']."=".$result2['data']."\n";
break;
case 'requirecalltoken':
if ($option != '')
$output .= $result2['keyword']."=".$result2['data']."\n";
break;
case 'callerid':
case 'mailbox':
$output .= $this->map_dev_user($account, $result2['keyword'], $result2['data']);
break;
case 'context':
$context = $option;
//fall-through
default:
$output .= $result2['keyword']."=".$result2['data']."\n";
}
}
}
switch (substr($id,0,8)) {
case 'tr-peer-':
if ($context == '') {
$output .= "context=from-trunk-iax2-$account\n";
}
break;
case 'tr-user-':
if ($context == '') {
$tn = substr($id, 8);
// this is a 'user' trunk, we need to get the name of the corresponding 'peer'
// trunk so we can set the context appropriately for the group count
//
$td = core_trunks_getDetails($tn);
if (isset($td['channelid'])) {
$output .= "context=from-trunk-iax2-".$td['channelid']."\n";
}
}
break;
default:
}
if (isset($this->_iax_additional[$account])) {
foreach ($this->_iax_additional[$account] as $asetting) {
$output .= $asetting['key'] . "=" . $asetting['value'] . "\n";
}
}
$output .= $additional."\n";
}
return $output;
}
function generate_iax_registrations($ast_version) {
global $db;
$table_name = "iax";
$output = "";
$sql = "SELECT keyword,data FROM $table_name WHERE `id` LIKE 'tr-reg-%' AND keyword <> 'account' AND flags <> 1";
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($results)) {
die($results->getMessage());
}
foreach ($results as $result) {
$output .= $result['keyword']."=".$result['data']."\n";
}
return $output;
}
function addDahdiAdditional($section, $key, $value) {
$this->_dahdi_additional[$section][] = array('key' => $key, 'value' => $value);
}
function generate_zapata_additional($ast_version, $table_name = 'zap') {
global $db;
$additional = "";
$output = '';
$sql = "SELECT keyword,data from $table_name where id=-1 and keyword <> 'account' and flags <> 1";
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($results)) {
if($table_name == 'zap') {
return '';
} else {
die($results->getMessage());
}
}
foreach ($results as $result) {
$additional .= $result['keyword']."=".$result['data']."\n";
}
$sql = "SELECT data,id from $table_name where keyword='account' and flags <> 1 group by data";
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($results)) {
die($results->getMessage());
}
foreach ($results as $result) {
$account = $result['data'];
$id = $result['id'];
$output .= ";;;;;;[$account]\n";
$sql = "SELECT keyword,data from $table_name where id=$id and keyword <> 'account' and flags <> 1 order by keyword DESC";
$results2 = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($results2)) {
die($results2->getMessage());
}
$zapchannel="";
foreach ($results2 as $result2) {
switch ($result2['keyword']) {
case 'channel':
$zapchannel = $result2['data'];
break;
// These are not zapata.conf variables so keep out of file
case 'dial':
break;
case 'callerid':
case 'mailbox':
$output .= $this->map_dev_user($account, $result2['keyword'], $result2['data']);
break;
default:
$output .= $result2['keyword']."=".$result2['data']."\n";
}
}
if (isset($this->_dahdi_additional[$account])) {
foreach ($this->_dahdi_additional[$account] as $asetting) {
$output .= $asetting['key'] . "=" . $asetting['value'] . "\n";
}
}
$output .= $additional ? $additional."\n" : '';
$output .= "channel=>$zapchannel\n";
}
return $output;
}
}
function core_destination_popovers() {
global $amp_conf;
if ($amp_conf['AMPEXTENSIONS'] == "deviceanduser") {
$ret['users'] = 'Users';
} else {
$ret['extensions'] = 'Extensions';
}
return $ret;
}
// The destinations this module provides
// returns a associative arrays with keys 'destination' and 'description'
function core_destinations() {
global $amp_conf;
//static destinations
$extens = array();
$td = textdomain();
textdomain("amp");
$category = _("Terminate Call");
$ds_id = 'blackhole';
$extens[] = array('destination' => 'app-blackhole,hangup,1', 'description' => _("Hangup"), 'category' => $category, 'id' => $ds_id);
$extens[] = array('destination' => 'app-blackhole,congestion,1', 'description' => _("Congestion"), 'category' => $category, 'id' => $ds_id);
$extens[] = array('destination' => 'app-blackhole,busy,1', 'description' => _("Busy"), 'category' => $category, 'id' => $ds_id);
$extens[] = array('destination' => 'app-blackhole,zapateller,1', 'description' => _("Play SIT Tone (Zapateller)"), 'category' => $category, 'id' => $ds_id);
$extens[] = array('destination' => 'app-blackhole,musiconhold,1', 'description' => _("Put caller on hold forever"), 'category' => $category, 'id' => $ds_id);
$extens[] = array('destination' => 'app-blackhole,ring,1', 'description' => _("Play ringtones to caller until they hangup"), 'category' => $category, 'id' => $ds_id);
textdomain($td);
//get the list of meetmes
$results = core_users_list();
if (isset($results) && function_exists('voicemail_getVoicemail')) {
//get voicemail
$uservm = voicemail_getVoicemail();
$vmcontexts = array_keys($uservm);
foreach ($results as $thisext) {
$extnum = $thisext[0];
// search vm contexts for this extensions mailbox
foreach ($vmcontexts as $vmcontext) {
if(isset($uservm[$vmcontext][$extnum])){
//$vmname = $uservm[$vmcontext][$extnum]['name'];
//$vmboxes[$extnum] = array($extnum, '"' . $vmname . '" <' . $extnum . '>');
$vmboxes[$extnum] = true;
}
}
}
}
// return an associative array with destination and description
// core provides both users and voicemail boxes as destinations
if (isset($results)) {
$cat_id = ($amp_conf['AMPEXTENSIONS'] == "deviceanduser")?'users':'extensions';
$cat = ($amp_conf['AMPEXTENSIONS'] == "deviceanduser")?'Users':'Extensions';
foreach($results as $result) {
$extens[] = array('destination' => 'from-did-direct,'.$result['0'].',1', 'description' => ' <'.$result['0'].'> '.$result['1'], 'category' => $cat, 'id' => $cat_id);
if(isset($vmboxes[$result['0']])) {
$extens[] = array('destination' => 'ext-local,vmb'.$result['0'].',1', 'description' => '<'.$result[0].'> '.$result[1].' (busy)', 'category' => 'Voicemail', 'id' => 'voicemail');
$extens[] = array('destination' => 'ext-local,vmu'.$result['0'].',1', 'description' => '<'.$result[0].'> '.$result[1].' (unavail)', 'category' => 'Voicemail', 'id' => 'voicemail');
$extens[] = array('destination' => 'ext-local,vms'.$result['0'].',1', 'description' => '<'.$result[0].'> '.$result[1].' (no-msg)', 'category' => 'Voicemail', 'id' => 'voicemail');
}
}
}
$trunklist = core_trunks_listbyid();
if (is_array($trunklist)) foreach ($trunklist as $trunk) {
switch($trunk['tech']) {
case 'enum':
break;
default:
$extens[] = array('destination' => 'ext-trunk,'.$trunk['trunkid'].',1', 'description' => $trunk['name'].' ('.$trunk['tech'].')', 'category' => 'Trunks', 'id' => 'trunks');
break;
}
}
if (isset($extens))
return $extens;
else
return null;
}
function core_getdest($exten) {
$dests[] = 'from-did-direct,'.$exten.',1';
$dests[] = 'ext-trunk,'.$exten.',1';
if (!function_exists('voicemail_mailbox_get')) {
return $dests;
}
$box = voicemail_mailbox_get($exten);
if ($box == null) {
return $dests;
}
$dests[] = 'ext-local,vmb'.$exten.',1';
$dests[] = 'ext-local,vmu'.$exten.',1';
$dests[] = 'ext-local,vms'.$exten.',1';
return $dests;
}
function core_getdestinfo($dest) {
global $amp_conf;
global $active_modules;
// Check for Extension Number Destinations
//
if (substr(trim($dest),0,16) == 'from-did-direct,') {
$exten = explode(',',$dest);
$exten = $exten[1];
$thisexten = core_users_get($exten);
if (empty($thisexten)) {
return array();
} else {
//$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
$display = ($amp_conf['AMPEXTENSIONS'] == "deviceanduser")?'users':'extensions';
return array('description' => sprintf(_("User Extension %s: %s"),$exten,$thisexten['name']),
'edit_url' => "config.php?type=setup&display=$display&extdisplay=".urlencode($exten)."&skip=0",
);
}
} else if (substr(trim($dest),0,10) == 'ext-trunk,') {
$exten = explode(',',$dest);
$exten = $exten[1];
$thisexten = core_trunks_getDetails($exten);
if (empty($thisexten)) {
return array();
} else {
$display = 'trunks';
$name = isset($thisexten['name']) && $thisexten['name'] ? $thisexten['name'] : '';
return array('description' => sprintf(_('Trunk: %s (%s)'),$name,$thisexten['tech']),
'edit_url' => "config.php?type=setup&display=$display&extdisplay=OUT_".urlencode($exten),
);
}
// Check for voicemail box destinations
//
} else if (substr(trim($dest),0,12) == 'ext-local,vm') {
$exten = explode(',',$dest);
$exten = substr($exten[1],3);
if (!function_exists('voicemail_mailbox_get')) {
return array();
}
$thisexten = core_users_get($exten);
if (empty($thisexten)) {
return array();
}
$box = voicemail_mailbox_get($exten);
if ($box == null) {
return array();
}
$display = ($amp_conf['AMPEXTENSIONS'] == "deviceanduser")?'users':'extensions';
return array('description' => 'User Extension '.$exten.': '.$thisexten['name'],
'edit_url' => "config.php?type=setup&display=$display&extdisplay=".urlencode($exten)."&skip=0",
);
// Check for blackhole Termination Destinations
//
} else if (substr(trim($dest),0,14) == 'app-blackhole,') {
$exten = explode(',',$dest);
$exten = $exten[1];
switch ($exten) {
case 'hangup':
$description = 'Hangup';
break;
case 'congestion':
$description = 'Congestion';
break;
case 'busy':
$description = 'Busy';
break;
case 'zapateller':
$description = 'Play SIT Tone (Zapateller)';
break;
case 'musiconhold':
$description = 'Put caller on hold forever';
break;
case 'ring':
$description = 'Play ringtones to caller';
break;
default:
$description = false;
}
if ($description) {
return array('description' => 'Core: '.$description,
'edit_url' => false,
);
} else {
return array();
}
// None of the above, so not one of ours
//
} else {
return false;
}
}
/* Generates dialplan for "core" components (extensions & inbound routing)
We call this with retrieve_conf
*/
function core_do_get_config($engine) {
global $ext; // is this the best way to pass this?
global $version; // this is not the best way to pass this, this should be passetd together with $engine
global $engineinfo;
global $amp_conf;
global $core_conf;
global $chan_dahdi;
global $chan_dahdi_loaded;
global $astman;
$modulename = "core";
$callrecording = 'callrecording';
$callrecording_uid = 'MISSING_CALLRECORDINGS';
$getCallRecordingModInfo = module_getinfo($callrecording, MODULE_STATUS_ENABLED);
$nt =& notifications::create($db);
if (!isset($getCallRecordingModInfo[$callrecording]) || ($getCallRecordingModInfo[$callrecording]['status'] !== MODULE_STATUS_ENABLED)) {
if(!$nt->exists($modulename, $callrecording_uid)) {
$nt->add_notice($modulename, $callrecording_uid, _('Call Recording Module Not Enabled'), _('The Call Recording module is not enabled. Since this feature is required for call recording you may not be able to record calls until the module is installed and enabled.'), '', true, true);
}
} else {
if($nt->exists($modulename, $callrecording_uid)) {
$nt->delete($modulename, $callrecording_uid);
}
}