forked from FreePBX/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.php
1279 lines (1176 loc) · 66.9 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
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
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
//for translation only
if (false) {
_("Core");
_("User Logon");
_("User Logoff");
_("ZapBarge");
_("ChanSpy");
_("Simulate Incoming Call");
_("Directed Call Pickup");
_("Asterisk General Call Pickup");
_("In-Call Asterisk Blind Transfer");
_("In-Call Asterisk Attended Transfer");
_("In-Call Asterisk Toggle Call Recording");
_("In-Call Asterisk Disconnect Code");
}
function did_migrate($incoming){
global $db;
foreach ($incoming as $key => $val) {
${$key} = $db->escapeSimple($val);
}
// Check to make sure the did is not being used elsewhere
//
$sql = "SELECT * FROM incoming WHERE cidnum = '' AND extension = '$extension'";
$existing = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($existing)) {
outn(sprintf(_("ERROR: trying to check if %s already in use"),$extension));
return false;
}
if (empty($existing)) {
$sql="INSERT INTO incoming (cidnum,extension,destination,faxexten,faxemail,answer,wait,privacyman,alertinfo, ringing, mohclass, description, grppre) values ('$cidnum','$extension','$destination','$faxexten','$faxemail','$answer','$wait','$privacyman','$alertinfo', '$ringing', '$mohclass', '$description', '$grppre')";
sql($sql);
return true;
} else {
return false;
}
}
$freepbx_conf =& freepbx_conf::create();
$fcc = new featurecode('core', 'userlogon');
$fcc->setDescription('User Logon');
$fcc->setDefault('*11');
$fcc->update();
unset($fcc);
$fcc = new featurecode('core', 'userlogoff');
$fcc->setDescription('User Logoff');
$fcc->setDefault('*12');
$fcc->update();
unset($fcc);
$fcc = new featurecode('core', 'zapbarge');
$fcc->setDescription('ZapBarge');
$fcc->setDefault('888');
$fcc->setProvideDest();
$fcc->update();
unset($fcc);
$fcc = new featurecode('core', 'chanspy');
$fcc->setDescription('ChanSpy');
$fcc->setDefault('555');
$fcc->setProvideDest();
$fcc->update();
unset($fcc);
$fcc = new featurecode('core', 'simu_pstn');
$fcc->setDescription('Simulate Incoming Call');
$fcc->setDefault('7777');
$fcc->setProvideDest();
$fcc->update();
unset($fcc);
$fcc = new featurecode('core', 'pickup');
$fcc->setDescription('Directed Call Pickup');
$fcc->setDefault('**');
$fcc->update();
unset($fcc);
$fcc = new featurecode('core', 'pickupexten');
$fcc->setDescription('Asterisk General Call Pickup');
$fcc->setDefault('*8');
$fcc->update();
unset($fcc);
$fcc = new featurecode('core', 'blindxfer');
$fcc->setDescription('In-Call Asterisk Blind Transfer');
$fcc->setDefault('##');
$fcc->update();
unset($fcc);
$fcc = new featurecode('core', 'atxfer');
$fcc->setDescription('In-Call Asterisk Attended Transfer');
$fcc->setDefault('*2');
$fcc->update();
unset($fcc);
$fcc = new featurecode('core', 'automon');
$fcc->setDescription('In-Call Asterisk Toggle Call Recording');
$fcc->setDefault('*1');
$fcc->update();
unset($fcc);
$fcc = new featurecode('core', 'disconnect');
$fcc->setDescription('In-Call Asterisk Disconnect Code');
$fcc->setDefault('**');
$fcc->update();
unset($fcc);
// OUTBOUND_CID_UPDATE
//
$set['value'] = true;
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 0;
$set['hidden'] = 0;
$set['level'] = 0;
$set['module'] = '';
$set['category'] = 'Dialplan and Operational';
$set['emptyok'] = 0;
$set['name'] = 'Display CallerID on Calling Phone';
$set['description'] = "When set to true and when CONNECTEDLINE() capabilities are configured and supported by your handset, the CID value being transmitted on this call will be updated on your handset in the CNAM field prepended with CID: so you know what is being presented to the caller if the outbound trunk supports and honors setting the transmitted CID.";
$set['type'] = CONF_TYPE_BOOL;
$freepbx_conf->define_conf_setting('OUTBOUND_CID_UPDATE',$set);
// OUTBOUND_DIAL_UPDATE
//
$set['value'] = true;
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 0;
$set['hidden'] = 0;
$set['level'] = 0;
$set['module'] = '';
$set['category'] = 'Dialplan and Operational';
$set['emptyok'] = 0;
$set['name'] = 'Display Dialed Number on Calling Phone';
$set['description'] = "When set to true and when CONNECTEDLINE() capabilities are configured and supported by your handset, the number actually dialled will be updated on your handset in the CNUM field. This allows you to see the final manipulation of your number after outbound route and trunk dial manipulation rules have been applied. For example, if you have configured 7 digit dialing on a North America dialplan, the ultimate 10 or 11 digit transmission will be displayed back. Any 'Outbound Dial Prefixes' configured at the trunk level will NOT be shown as these are foten analog line pauses (w) or other characters that distort the CNUM field on updates.";
$set['type'] = CONF_TYPE_BOOL;
$freepbx_conf->define_conf_setting('OUTBOUND_DIAL_UPDATE',$set);
// Version 2.5 Upgrade needs to migrate directdid user info to incoming table
//
outn(_("Checking if directdids need migrating.."));
$sql = "SELECT `directdid` FROM `users`";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if(!DB::IsError($check)) {
out(_("starting migration"));
$errors = 0;
$sql = "SELECT * FROM `users` WHERE `directdid` != '' AND `directdid` IS NOT NULL";
$direct_dids_arr = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if(!DB::IsError($direct_dids_arr)) {
foreach ($direct_dids_arr as $direct_dids) {
$did_vars['destination'] = 'from-did-direct,'.$direct_dids['extension'].',1';
$did_vars['extension'] = $direct_dids['directdid'];
$did_vars['cidnum'] = '';
$did_vars['faxexten'] = $direct_dids['faxexten'];
$did_vars['faxemail'] = $direct_dids['faxemail'];
$did_vars['answer'] = $direct_dids['answer'];
$did_vars['wait'] = $direct_dids['wait'];
$did_vars['privacyman'] = $direct_dids['privacyman'];
$did_vars['alertinfo'] = $direct_dids['didalert'];
$did_vars['ringing'] = '';
$did_vars['mohclass'] = $direct_dids['mohclass'];
$did_vars['description'] = _("User: ").$direct_dids['extension'];
$did_vars['grppre'] = '';
if (!did_migrate($did_vars)) {
out(sprintf(_("ERROR: failed to insert %s for user %s"),$direct_dids['directdid'],$direct_dids['extension']));
$errors++;
}
}
if ($errors) {
out(sprintf(_("There were %s failures migrating directdids, users table not being changed"),$errors));
} else {
$migrate_array = array('directdid', 'didalert', 'mohclass', 'faxexten', 'faxemail', 'answer', 'wait', 'privacyman');
foreach ($migrate_array as $field) {
outn(sprintf(_("Removing field %s from users table.."),$field));
$sql = "ALTER TABLE `users` DROP `".$field."`";
$results = $db->query($sql);
if (DB::IsError($results)) {
out(_("not present"));
} else {
out(_("removed"));
}
}
}
} else {
out(_("ERROR: could not access user table to migrate directdids to incoming table, aborting"));
}
} else {
out(_("already done"));
}
// Add callgroup, pickupgroup to zap
outn(_("updating zap callgroup, pickupgroup.."));
$sql = "SELECT `id` FROM `devices` WHERE `tech` = 'zap'";
$results = $db->getCol($sql);
if(DB::IsError($results)) {
$results = null;
}
$count_pickup = 0;
$count_callgroup = 0;
if (isset($results) && !empty($results)) {
foreach ($results as $device) {
// if the insert fails then it is already there since it will violate the primary key but that is ok
//
$sql = "INSERT INTO `zap` (`id`, `keyword`, `data`, `flags`) VALUES ('$device', 'callgroup', '', '0')";
$try = $db->query($sql);
if(!DB::IsError($try)) {
$count_pickup++;
}
$sql = "INSERT INTO `zap` (`id`, `keyword`, `data`, `flags`) VALUES ('$device', 'pickupgroup', '', '0')";
$try = $db->query($sql);
if(!DB::IsError($try)) {
$count_callgroup++;
}
}
}
if ($count_callgroup || $count_pickup) {
out(sprintf(_("updated %s callgroups, %s pickupgroups"),$count_callgroup,$count_pickup));
} else {
out(_("not needed"));
}
// 2.5 new field
//
outn(_("checking for delay_answer field .."));
$sql = "SELECT `delay_answer` FROM `incoming`";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($check)) {
$sql = "ALTER TABLE `incoming` ADD `delay_answer` INT(2) DEFAULT NULL";
$result = $db->query($sql);
if(DB::IsError($result)) {
out(_("fatal error"));
die_freepbx($result->getDebugInfo());
} else {
out(_("added"));
}
} else {
out(_("already exists"));
}
outn(_("checking for pricid field .."));
$sql = "SELECT `pricid` FROM `incoming`";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($check)) {
$sql = "ALTER TABLE `incoming` ADD `pricid` VARCHAR(20) DEFAULT NULL";
$result = $db->query($sql);
if(DB::IsError($result)) {
out(_("fatal error"));
die_freepbx($result->getDebugInfo());
} else {
out(_("added"));
}
} else {
out(_("already exists"));
}
// This next set of functions and code are used to migrate from the old
// global variable storage of trunk data to the new trunk table and trunk
// pattern table for localprefixes.conf
//
//Sort trunks for sqlite
function __sort_trunks($a,$b) {
global $unique_trunks;
preg_match("/OUT_([0-9]+)/",$unique_trunks[$a][0],$trunk_num1);
preg_match("/OUT_([0-9]+)/",$unique_trunks[$b][0],$trunk_num2);
return ($trunk_num1[1] >= $trunk_num2[1]? 1:-1);
}
function __migrate_trunks_to_table() {
global $db;
global $amp_conf;
$sql = "
CREATE TABLE `trunks`
(
`trunkid` INTEGER,
`name` VARCHAR( 50 ) NOT NULL DEFAULT '',
`tech` VARCHAR( 20 ) NOT NULL ,
`outcid` VARCHAR( 40 ) NOT NULL DEFAULT '',
`keepcid` VARCHAR( 4 ) DEFAULT 'off',
`maxchans` VARCHAR( 6 ) DEFAULT '',
`failscript` VARCHAR( 255 ) NOT NULL DEFAULT '',
`dialoutprefix` VARCHAR( 255 ) NOT NULL DEFAULT '',
`channelid` VARCHAR( 255 ) NOT NULL DEFAULT '',
`usercontext` VARCHAR( 255 ) NULL,
`provider` VARCHAR( 40 ) NULL,
`disabled` VARCHAR( 4 ) DEFAULT 'off',
`continue` VARCHAR( 4 ) DEFAULT 'off',
PRIMARY KEY (`trunkid`, `tech`, `channelid`)
)
";
$check = $db->query($sql);
if(DB::IsError($check)) {
if($check->getCode() == DB_ERROR_ALREADY_EXISTS) {
//echo ("already exists\n");
return false;
} else {
die_freepbx($check->getDebugInfo());
}
}
// sqlite doesn't support the syntax required for the SQL so we have to do it the hard way
if ($amp_conf["AMPDBENGINE"] == "sqlite3") {
$sqlstr = "SELECT variable, value FROM globals WHERE variable LIKE 'OUT\_%' ESCAPE '\'";
$my_unique_trunks = sql($sqlstr,"getAll",DB_FETCHMODE_ASSOC);
$sqlstr = "SELECT variable, value FROM globals WHERE variable LIKE 'OUTDISABLE\_%' ESCAPE '\'";
$disable_states = sql($sqlstr,"getAll",DB_FETCHMODE_ASSOC);
foreach($disable_states as $arr) {
$disable_states_assoc[$arr['variable']] = $arr['value'];
}
global $unique_trunks;
$unique_trunks = array();
foreach ($my_unique_trunks as $this_trunk) {
$trunk_num = substr($this_trunk['variable'],4);
$this_state = (isset($disable_states_assoc['OUTDISABLE_'.$trunk_num]) ? $disable_states_assoc['OUTDISABLE_'.$trunk_num] : 'off');
$unique_trunks[] = array($this_trunk['variable'], $this_trunk['value'], $this_state);
}
// sort this array using a custom function __sort_trunks(), defined above
uksort($unique_trunks,"__sort_trunks");
// re-index the newly sorted array
foreach($unique_trunks as $arr) {
$unique_trunks_t[] = array($arr[0],$arr[1],$arr[2]);
}
$unique_trunks = $unique_trunks_t;
} else {
$sqlstr = "SELECT t.variable, t.value, d.value state FROM `globals` t ";
$sqlstr .= "JOIN (SELECT x.variable, x.value FROM globals x WHERE x.variable LIKE 'OUTDISABLE\_%') d ";
$sqlstr .= "ON substring(t.variable,5) = substring(d.variable,12) WHERE t.variable LIKE 'OUT\_%' ";
$sqlstr .= "UNION ALL ";
$sqlstr .= "SELECT v.variable, v.value, concat(substring(v.value,1,0),'off') state FROM `globals` v ";
$sqlstr .= "WHERE v.variable LIKE 'OUT\_%' AND concat('OUTDISABLE_',substring(v.variable,5)) NOT IN ";
$sqlstr .= " ( SELECT variable from globals WHERE variable LIKE 'OUTDISABLE\_%' ) ";
$sqlstr .= "ORDER BY variable";
$unique_trunks = sql($sqlstr,"getAll");
}
$trunkinfo = array();
foreach ($unique_trunks as $trunk) {
list($tech,$name) = explode('/',$trunk[1]);
$trunkid = ltrim($trunk[0],'OUT_');
$sqlstr = "
SELECT `variable`, `value` FROM `globals` WHERE `variable` IN (
'OUTCID_$trunkid', 'OUTFAIL_$trunkid', 'OUTKEEPCID_$trunkid',
'OUTMAXCHANS_$trunkid', 'OUTPREFIX_$trunkid')
";
$trunk_attribs = sql($sqlstr,'getAll',DB_FETCHMODE_ASSOC);
$trunk_attrib_hash = array();
foreach ($trunk_attribs as $attribs) {
$trunk_attrib_hash[$attribs['variable']] = $attribs['value'];
}
switch ($tech) {
case 'SIP':
$tech = 'sip';
$user = sql("SELECT `data` FROM `sip` WHERE `id` = '99999$trunkid' AND `keyword` = 'account'",'getOne');
break;
case 'IAX':
case 'IAX2':
$tech = 'iax';
$user = sql("SELECT `data` FROM `iax` WHERE `id` = '99999$trunkid' AND `keyword` = 'account'",'getOne');
break;
case 'ZAP':
case 'DUNDI':
case 'ENUM':
$tech = strtolower($tech);
$user = '';
break;
default:
if (substr($tech,0,4) == 'AMP:') {
$tech='custom';
$name = substr($trunk[1],4);
} else {
$tech = strtolower($tech);
}
$user = '';
}
$trunkinfo[] = array(
'trunkid' => $trunkid,
'tech' => $tech,
'outcid' => $trunk_attrib_hash['OUTCID_'.$trunkid],
'keepcid' => $trunk_attrib_hash['OUTKEEPCID_'.$trunkid],
'maxchans' => $trunk_attrib_hash['OUTMAXCHANS_'.$trunkid],
'failscript' => $trunk_attrib_hash['OUTFAIL_'.$trunkid],
'dialoutprefix' => $trunk_attrib_hash['OUTPREFIX_'.$trunkid],
'channelid' => $name,
'usercontext' => $user,
'disabled' => $trunk[2], // disable state
);
$sqlstr = "INSERT INTO `trunks`
( trunkid, tech, outcid, keepcid, maxchans, failscript, dialoutprefix, channelid, usercontext, disabled)
VALUES (
'".$db->escapeSimple($trunkid)."',
'".$db->escapeSimple($tech)."',
'".$db->escapeSimple($trunk_attrib_hash['OUTCID_'.$trunkid])."',
'".$db->escapeSimple($trunk_attrib_hash['OUTKEEPCID_'.$trunkid])."',
'".$db->escapeSimple($trunk_attrib_hash['OUTMAXCHANS_'.$trunkid])."',
'".$db->escapeSimple($trunk_attrib_hash['OUTFAIL_'.$trunkid])."',
'".$db->escapeSimple($trunk_attrib_hash['OUTPREFIX_'.$trunkid])."',
'".$db->escapeSimple($name)."',
'".$db->escapeSimple($user)."',
'".$db->escapeSimple($trunk[2])."'
)
";
sql($sqlstr);
}
return $trunkinfo;
}
// __migrate_trunks_to_table will return false if the trunks table already exists and
// no migration is needed
//
outn(_("Checking if trunk table migration required.."));
$trunks = __migrate_trunks_to_table();
if ($trunks !== false) {
outn(_("migrating.."));
foreach ($trunks as $trunk) {
$tech = $trunk['tech'];
$trunkid = $trunk['trunkid'];
switch ($tech) {
case 'sip':
case 'iax':
$sql = "UPDATE `$tech` SET `id` = 'tr-peer-$trunkid' WHERE `id` = '9999$trunkid'";
sql($sql);
$sql = "UPDATE `$tech` SET `id` = 'tr-user-$trunkid' WHERE `id` = '99999$trunkid'";
sql($sql);
$sql = "UPDATE `$tech` SET `id` = 'tr-reg-$trunkid' WHERE `id` = '9999999$trunkid' AND `keyword` = 'register'";
sql($sql);
break;
default:
break;
}
}
outn(_("removing globals.."));
// Don't do this above, in case something goes wrong
//
// At this point we have created our trunks table and update the sip and iax files
// time to get rid of the old globals which will not be auto-generated
//
foreach ($trunks as $trunk) {
$trunkid = $trunk['trunkid'];
$sqlstr = "
DELETE FROM `globals` WHERE `variable` IN (
'OUTCID_$trunkid', 'OUTFAIL_$trunkid', 'OUTKEEPCID_$trunkid',
'OUTMAXCHANS_$trunkid', 'OUTPREFIX_$trunkid', 'OUT_$trunkid',
'OUTDISABLE_$trunkid'
)
";
sql($sqlstr);
}
out(_("done"));
} else {
out(_("not needed"));
}
outn(_("Checking if privacy manager options exists.."));
$check = $db->query('SELECT pmmaxretries FROM incoming');
if(DB::IsError($check)){
$result = $db->query('alter table incoming add pmmaxretries varchar(2), add pmminlength varchar(2);');
if(DB::IsError($result)) {
die_freepbx($result->getDebugInfo().'fatal error adding fields to incoming table');
} else {
out(_("Added pmmaxretries and pmminlength"));
}
}else{
out(_("already exists"));
}
// This has already been done in the framework upgrades but is repeated
// here until confirmed there is no path where that code may not have been
// executed.
//
$new_cols = array('noanswer_cid','busy_cid','chanunavail_cid');
foreach ($new_cols as $col) {
outn(sprintf(_("Checking for %s field.."),$col));
$sql = "SELECT $col FROM `users`";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($check)) {
// add new field
$sql = "ALTER TABLE `users` ADD `$col` VARCHAR( 20 ) DEFAULT '';";
$result = $db->query($sql);
if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }
out(_("added"));
} else {
out(_("already exists"));
}
}
$new_cols = array('noanswer_dest','busy_dest','chanunavail_dest');
foreach ($new_cols as $col) {
outn(sprintf(_("Checking for %s field.."),$col));
$sql = "SELECT $col FROM `users`";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($check)) {
// add new field
$sql = "ALTER TABLE `users` ADD `$col` VARCHAR( 255 ) DEFAULT '';";
$result = $db->query($sql);
if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }
out(_("added"));
} else {
out(_("already exists"));
}
}
// The following are from General Settings that may need to be migrated.
// We will first create them all, the define_conf_settings() method will
// not change the value if already set. We will update the settings
// to the currently configured values from the globals table afer defining
// them here and then remove them from the globals table.
$globals_convert['VMX_CONTEXT'] = 'from-internal';
$globals_convert['VMX_PRI'] = '1';
$globals_convert['VMX_TIMEDEST_CONTEXT'] = '';
$globals_convert['VMX_TIMEDEST_EXT'] = 'dovm';
$globals_convert['VMX_TIMEDEST_PRI'] = '1';
$globals_convert['VMX_LOOPDEST_CONTEXT'] = '';
$globals_convert['VMX_LOOPDEST_EXT'] = 'dovm';
$globals_convert['VMX_LOOPDEST_PRI'] = '1';
$globals_convert['MIXMON_DIR'] = '';
$globals_convert['MIXMON_POST'] = '';
$globals_convert['MIXMON_FORMAT'] = 'wav';
$globals_convert['DIAL_OPTIONS'] = 'Ttr';
$globals_convert['TRUNK_OPTIONS'] = 'Tt';
$globals_convert['RINGTIMER'] = '15';
$globals_convert['TONEZONE'] = 'us';
// VMX_CONTEXT
//
$set['value'] = $globals_convert['VMX_CONTEXT'];
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 1;
$set['hidden'] = 0;
$set['level'] = 9;
$set['module'] = '';
$set['category'] = 'VmX Locater';
$set['emptyok'] = 0;
$set['name'] = 'VMX Default Context';
$set['description'] = 'Used to do extremely advanced and customized changes to the macro-vm VmX locater. Check the dialplan for a thorough understanding of how to use this.';
$set['type'] = CONF_TYPE_TEXT;
$freepbx_conf->define_conf_setting('VMX_CONTEXT',$set);
// VMX_PRI
//
$set['value'] = $globals_convert['VMX_PRI'];
$set['defaultval'] =& $set['value'];
$set['options'] = array(1,1000);
$set['readonly'] = 1;
$set['hidden'] = 0;
$set['level'] = 9;
$set['module'] = '';
$set['category'] = 'VmX Locater';
$set['emptyok'] = 0;
$set['name'] = 'VMX Default Priority';
$set['description'] = 'Used to do extremely advanced and customized changes to the macro-vm VmX locater. Check the dialplan for a thorough understanding of how to use this.';
$set['type'] = CONF_TYPE_INT;
$freepbx_conf->define_conf_setting('VMX_PRI',$set);
// VMX_TIMEDEST_CONTEXT
//
$set['value'] = $globals_convert['VMX_TIMEDEST_CONTEXT'];
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 1;
$set['hidden'] = 0;
$set['level'] = 9;
$set['module'] = '';
$set['category'] = 'VmX Locater';
$set['emptyok'] = 1;
$set['name'] = 'VMX Default Timeout Context';
$set['description'] = "Used to do extremely advanced and customized changes to the macro-vm VmX locater. Check the dialplan for a thorough understanding of how to use this. The default location that a caller will be sent if they don't press any key (timeout) or press # which is interpreted as a timeout. Set this to 'dovm' to go to voicemail (default).";
$set['type'] = CONF_TYPE_TEXT;
$freepbx_conf->define_conf_setting('VMX_TIMEDEST_CONTEXT',$set);
// VMX_TIMEDEST_EXT
//
$set['value'] = $globals_convert['VMX_TIMEDEST_EXT'];
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 1;
$set['hidden'] = 0;
$set['level'] = 9;
$set['module'] = '';
$set['category'] = 'VmX Locater';
$set['emptyok'] = 0;
$set['name'] = 'VMX Default Timeout Extension';
$set['description'] = "Used to do extremely advanced and customized changes to the macro-vm VmX locater. Check the dialplan for a thorough understanding of how to use this. The default location that a caller will be sent if they don't press any key (timeout) or press # which is interpreted as a timeout. Set this to 'dovm' to go to voicemail (default).";
$set['type'] = CONF_TYPE_TEXT;
$freepbx_conf->define_conf_setting('VMX_TIMEDEST_EXT',$set);
// VMX_TIMEDEST_PRI
//
$set['value'] = $globals_convert['VMX_TIMEDEST_PRI'];
$set['defaultval'] =& $set['value'];
$set['options'] = array(1,1000);
$set['readonly'] = 1;
$set['hidden'] = 0;
$set['level'] = 9;
$set['module'] = '';
$set['category'] = 'VmX Locater';
$set['emptyok'] = 0;
$set['name'] = 'VMX Default Timeout Priority';
$set['description'] = "Used to do extremely advanced and customized changes to the macro-vm VmX locater. Check the dialplan for a thorough understanding of how to use this. The default location that a caller will be sent if they don't press any key (timeout) or press # which is interpreted as a timeout. Set this to 'dovm' to go to voicemail (default).";
$set['type'] = CONF_TYPE_INT;
$freepbx_conf->define_conf_setting('VMX_TIMEDEST_PRI',$set);
// VMX_LOOPDEST_CONTEXT
//
$set['value'] = $globals_convert['VMX_LOOPDEST_CONTEXT'];
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 1;
$set['hidden'] = 0;
$set['level'] = 9;
$set['module'] = '';
$set['category'] = 'VmX Locater';
$set['emptyok'] = 1;
$set['name'] = 'VMX Default Loop Exceed Context';
$set['description'] = "Used to do extremely advanced and customized changes to the macro-vm VmX locater. Check the dialplan for a thorough understanding of how to use this. The default location that a caller will be sent if they press an invalid options too many times, as defined by the Maximum Loops count.";
$set['type'] = CONF_TYPE_TEXT;
$freepbx_conf->define_conf_setting('VMX_LOOPDEST_CONTEXT',$set);
// VMX_LOOPDEST_EXT
//
$set['value'] = $globals_convert['VMX_LOOPDEST_EXT'];
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 1;
$set['hidden'] = 0;
$set['level'] = 9;
$set['module'] = '';
$set['category'] = 'VmX Locater';
$set['emptyok'] = 0;
$set['name'] = 'VMX Default Loop Exceed Extension';
$set['description'] = "Used to do extremely advanced and customized changes to the macro-vm VmX locater. Check the dialplan for a thorough understanding of how to use this. The default location that a caller will be sent if they press an invalid options too many times, as defined by the Maximum Loops count.";
$set['type'] = CONF_TYPE_TEXT;
$freepbx_conf->define_conf_setting('VMX_LOOPDEST_EXT',$set);
// VMX_LOOPDEST_PRI
//
$set['value'] = $globals_convert['VMX_LOOPDEST_PRI'];
$set['defaultval'] =& $set['value'];
$set['options'] = array(1,1000);
$set['readonly'] = 1;
$set['hidden'] = 0;
$set['level'] = 9;
$set['module'] = '';
$set['category'] = 'VmX Locater';
$set['emptyok'] = 0;
$set['name'] = 'VMX Default Loop Exceed Priority';
$set['description'] = "Used to do extremely advanced and customized changes to the macro-vm VmX locater. Check the dialplan for a thorough understanding of how to use this. The default location that a caller will be sent if they press an invalid options too many times, as defined by the Maximum Loops count.";
$set['type'] = CONF_TYPE_INT;
$freepbx_conf->define_conf_setting('VMX_LOOPDEST_PRI',$set);
// MIXMON_DIR
//
$set['value'] = $globals_convert['MIXMON_DIR'];
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 1;
$set['hidden'] = 0;
$set['level'] = 9;
$set['module'] = '';
$set['category'] = 'Directory Layout';
$set['emptyok'] = 1;
$set['name'] = 'Override Call Recording Location';
$set['description'] = "Override the default location where asterisk will store call recordings. Be sure to set proper permissions on the directory for the asterisk user.";
$set['type'] = CONF_TYPE_DIR;
$freepbx_conf->define_conf_setting('MIXMON_DIR',$set);
// MIXMON_POST
//
$set['value'] = $globals_convert['MIXMON_POST'];
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 1;
$set['hidden'] = 0;
$set['level'] = 9;
$set['module'] = '';
$set['category'] = 'Developer and Customization';
$set['emptyok'] = 1;
$set['name'] = 'Post Call Recording Script';
$set['description'] = "An optional script to be run after the call is hangup. You can include channel and MixMon variables like \${CALLFILENAME}, \${MIXMON_FORMAT} and \${MIXMON_DIR}. To ensure that you variables are properly escaped, use the following notation: ^{MY_VAR}";
$set['type'] = CONF_TYPE_TEXT;
$freepbx_conf->define_conf_setting('MIXMON_POST',$set);
// MIXMON_FORMAT
$set['value'] = $globals_convert['MIXMON_FORMAT'];
$set['defaultval'] =& $set['value'];
$set['options'] = array('wav','WAV','ulaw','ulaw','alaw','sln','gsm','g729');
$set['name'] = 'Call Recording Format';
$set['description'] = "Format to save recoreded calls for most call recording unless specified differently in specific applications.";
$set['readonly'] = 0;
$set['hidden'] = 0;
$set['level'] = 0;
$set['module'] = '';
$set['category'] = 'System Setup';
$set['emptyok'] = 0;
$set['type'] = CONF_TYPE_SELECT;
$freepbx_conf->define_conf_setting('MIXMON_FORMAT',$set);
// DIAL_OPTIONS
//
$set['value'] = $globals_convert['DIAL_OPTIONS'];
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 0;
$set['hidden'] = 0;
$set['level'] = 0;
$set['module'] = '';
$set['category'] = 'Dialplan and Operational';
$set['emptyok'] = 1;
$set['name'] = 'Asterisk Dial Options';
$set['description'] = "Options to be passed to the Asterisk Dial Command when making internal calls or for calls ringing internal phones. The options are documented in Asterisk documentation, a subset of which are described here. The default options T and t allow the calling and called users to transfer a call with ##. The r option allows Asterisk to generate ringing back to the calling phones which is needed by some phones and sometimes needed in complex dialplan features that may otherwise result in silence to the caller.";
$set['type'] = CONF_TYPE_TEXT;
$freepbx_conf->define_conf_setting('DIAL_OPTIONS',$set);
// TRUNK_OPTIONS
//
$set['value'] = $globals_convert['TRUNK_OPTIONS'];
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 0;
$set['hidden'] = 0;
$set['level'] = 0;
$set['module'] = '';
$set['category'] = 'Dialplan and Operational';
$set['emptyok'] = 1;
$set['name'] = 'Asterisk Outbound Trunk Dial Options';
$set['description'] = "Options to be passed to the Asterisk Dial Command when making outbound calls on your trunks when not part of an Intra-Company Route. The options are documented in Asterisk documentation, a subset of which are described here. The default options T and t allow the calling and called users to transfer a call with ##. It is HIGHLY DISCOURAGED to use the r option here as this will prevent early media from being delivered from the PSTN and can result in the inability to interact with some external IVRs";
$set['type'] = CONF_TYPE_TEXT;
$freepbx_conf->define_conf_setting('TRUNK_OPTIONS',$set);
// RINGTIMER
$opts = array();
for ($i=0;$i<=120;$i++) {
$opts[]=$i;
}
$set['value'] = $globals_convert['RINGTIMER'];
$set['defaultval'] =& $set['value'];
$set['options'] = $opts;
$set['readonly'] = 0;
$set['hidden'] = 0;
$set['level'] = 0;
$set['module'] = '';
$set['category'] = 'Dialplan and Operational';
$set['name'] = 'Ringtime Default';
$set['description'] = 'Default number of seconds to ring phones before sending callers to voicemail or other extension destinations. This can be set per extension/user. Phones with no voicemail or other destination options will ring indefinitely.';
$set['type'] = CONF_TYPE_SELECT;
$freepbx_conf->define_conf_setting('RINGTIMER',$set);
unset($opts);
// CONNECTEDLINE_PRESENCESTATE
//
$set['value'] = true;
$set['defaultval'] =& $set['value'];
$set['options'] = '';
$set['readonly'] = 0;
$set['hidden'] = 0;
$set['level'] = 0;
$set['module'] = '';
$set['category'] = 'Dialplan and Operational';
$set['emptyok'] = 0;
$set['name'] = 'Display Presence State of Callee';
$set['description'] = "When set to true and when CONNECTEDLINE() capabilities are configured and supported by your handset, the name displayed will include the presence state of the callee.";
$set['type'] = CONF_TYPE_BOOL;
$freepbx_conf->define_conf_setting('CONNECTEDLINE_PRESENCESTATE',$set);
// TONEZONE
// This function will assure the table is there and then create/setup the Advanced Setting
//
_core_create_update_tonezones($globals_convert['TONEZONE'],false);
// Get all the globals that need to be migrated, then prepare the
// update array to set the current settings in freepbx_conf before
// deleting them.
//
$sql = "SELECT `variable`, `value`";
$sql_where = " FROM globals WHERE `variable` IN ('".implode("','",array_keys($globals_convert))."')";
$sql .= $sql_where;
$globals = $db->getAll($sql,DB_FETCHMODE_ASSOC);
if(DB::IsError($globals)) {
die_freepbx($globals->getMessage());
}
outn(_("Checking for General Setting migrations.."));
if (count($globals)) {
out(_("preparing"));
foreach ($globals as $global) {
$update_arr[trim($global['variable'])] = $global['value'];
out(sprintf(_("%s prepared"),$global['variable']));
}
// Now set the values differently from the defaults, and commit
$freepbx_conf->set_conf_values($update_arr,true);
} else {
out(_("not needed"));
// commit the previous defines if we didn't upate anything
$freepbx_conf->commit_conf_settings();
}
// Add any globals that need to be deleted here while we are
// othewise cleaning up the ones migrated. These would be ones
// no longer used. They will be deleted if other migrations
// occured above.
//
$globals_convert['RECORDING_STATE'] = true;
$globals_convert['DIAL_OUT'] = true;
$globals_convert['REGTIME'] = true;
$globals_convert['REGDAYS'] = true;
$globals_convert['DIALOUTIDS'] = true;
$globals_convert['IN_OVERRIDE'] = true;
$globals_convert['AFTER_INCOMING'] = true;
$globals_convert['DIRECTORY_OPTS'] = true;
$globals_convert['OPERATOR'] = true;
$globals_convert['TRANSFER_CONTEXT'] = true;
$globals_convert['NULL'] = true;
$globals_convert['PARKNOTIFY'] = true;
$globals_convert['CALLFILENAME'] = true;
$globals_convert['FAX'] = true;
$globals_convert['INCOMING'] = true;
$globals_convert['DIRECTORY'] = true;
$globals_convert['RECORDEXTEN'] = true;
// Re-compute the where clause to pull in the new ones added and then Delete The Globals
//
$sql_where = " FROM globals WHERE `variable` IN ('".implode("','",array_keys($globals_convert))."')";
if (count($globals)) {
out(_("General Settings migrated"));
}
outn(_("Deleting unused globals.."));
$sql = "DELETE".$sql_where;
$globals = $db->query($sql);
if(DB::IsError($globals)) {
out(_("Fatal DB error trying to delete globals, trying to carry on"));
} else {
out(_("done"));
}
// It's possible that SQL, LOG_SQL values could still bein in AMPSYSLOGLEVEL if amportal.conf
// remained writable. Once changed, this will set it properly next time core is upgraded since
// Framework upgrade scripts only run based on current version.
//
$log_level = strtoupper($amp_conf['AMPSYSLOGLEVEL']);
if ($log_level == 'SQL' || $log_level == 'LOG_SQL') {
outn(sprintf(_("Discontinued logging type %s changing to %s.."),$log_level,'FILE'));
$freepbx_conf->set_conf_values(array('AMPSYSLOGLEVEL' => 'FILE'));
out(_("ok"));
}
// AMPSYSLOGLEVEL
unset($set);
$set['value'] = 'FILE';
$set['options'] = 'FILE, LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG';
$freepbx_conf->define_conf_setting('AMPSYSLOGLEVEL',$set,true);
// Convert IAX notransfer to transfer (since 1.4)
//
outn(_("Converting IAX notransfer to transfer if needed.."));
$affected_rows = 0;
sql("UPDATE iax SET keyword = 'transfer', data = 'yes' WHERE keyword = 'notransfer' AND LOWER(data) = 'no'");
$affected_rows .= $db->affectedRows();
sql("UPDATE iax SET keyword = 'transfer', data = 'no' WHERE keyword = 'notransfer' AND LOWER(data) = 'yes'");
$affected_rows .= $db->affectedRows();
sql("UPDATE iax SET keyword = 'transfer' WHERE keyword = 'notransfer' AND LOWER(data) = 'mediaonly'");
$affected_rows .= $db->affectedRows();
$affected_rows ? out(sprintf(_("updated %s records"),$affected_rows)) : out(_("not needed"));
$tables = array('sip', 'iax', 'zap', 'dahdi');
outn(_("deleting obsoleted record_in and record_out entries.."));
foreach ($tables as $table) {
$sql = "DELETE FROM `$table` WHERE `keyword` in ('record_in', 'record_out')";
$db->query($sql);
}
out(_("ok"));
// Added 2.11
//
outn(_("checking for dest field in outbound_routes.."));
$sql = "SELECT `dest` FROM `outbound_routes`";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($check)) {
$sql = "ALTER TABLE `outbound_routes` ADD `dest` VARCHAR(255) DEFAULT NULL";
$result = $db->query($sql);
if(DB::IsError($result)) {
out(_("fatal error trying to add field"));
die_freepbx($result->getDebugInfo());
} else {
out(_("added"));
}
} else {
out(_("already exists"));
}
outn(_("checking for continue field in trunks.."));
$sql = "SELECT `continue` FROM `trunks`";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if(DB::IsError($check)) {
$sql = "ALTER TABLE `trunks` ADD `continue` VARCHAR( 4 ) DEFAULT 'off'";
$result = $db->query($sql);
if(DB::IsError($result)) {
out(_("fatal error trying to add field"));
die_freepbx($result->getDebugInfo());
} else {
out(_("added"));
}
} else {
out(_("already exists"));
}
// Migrate ALLOW_SIP_ANON from globals if needed
//
$sql = "SELECT `value` FROM globals WHERE `variable` = 'ALLOW_SIP_ANON'";
$globals = $db->getAll($sql,DB_FETCHMODE_ASSOC);
if(!DB::IsError($globals)) {
if (count($globals)) {
$allow_sip_anon = trim($globals[0]['value']);
$sql = "DELETE FROM globals WHERE `variable` = 'ALLOW_SIP_ANON'";
out(_("migrated ALLOW_SIP_ANON Value: $allow_sip_anon to admin table"));
outn(_("deleting ALLOW_SIP_ANON from globals.."));
$res = $db->query($sql);
if(!DB::IsError($globals)) {
out(_("done"));
} else {
out(_("could not delete"));
}
}
}
if (!empty($allow_sip_anon)) {
$result = $db->query("INSERT INTO `admin` (`variable`, `value`) VALUES ('ALLOW_SIP_ANON', '$allow_sip_anon')");
if(DB::IsError($result)) {
out(_("ERROR: could not insert previous value for ALLOW_SIP_ANON, it may already exist"));
} else {
out(_("Inserted ALLOW_SIP_ANON fine"));
}
}
// zapchandids to dahdichandids table rename
$dahditbl_res = $db->getAll("SELECT * FROM dahdichandids");
if (DB::IsError($dahditbl_res)) {
$sql = $amp_conf["AMPDBENGINE"] == "sqlite3" ?
'ALTER TABLE zapchandids RENAME TO dahdichandids' :
'RENAME TABLE zapchandids to dahdichandids';
outn(_("renaming table zapchandids to dahdichandids.."));
$result = $db->query($sql);
if (!DB::IsError($result)) {
out(_("ok"));
} else {
out(_("CRITICAL ERROR"));
out(_("Could not rename table, if no dahdichandids table present FATAL errors will occur"));
}
}
// migrate from zap table. If empty, remove table. If not empty AND dahdi table empty, then
// migrate data to dahdi table, otherwise just leave it be.
//
$zaptbl_size = $db->getOne("SELECT COUNT(*) FROM zap");
if (!DB::IsError($zaptbl_size)) {
if ($zaptbl_size == 0) {
outn(_("removing zap table.."));
$res = $db->query("DROP TABLE zap");
if (!DB::IsError($res)) {
out(_("ok"));
} else {
out(_("error dropping table"));
}
} else {
$dahditbl_size = $db->getOne("SELECT COUNT(*) FROM dahdi");
if (DB::IsError($dahditbl_size)) {
out(_("error checking dahdi table size to determine if zap table contents can be migrated"));
} else {
if ($dahditbl_size > 0) {
out(_("dahdi table not empty, can't migrate zap data there"));
} else {
outn(_("migrating zap table contents to dahdi table.."));
$res = $db->query("INSERT INTO dahdi (id, keyword, data, flags) (SELECT id, keyword, data, flags FROM zap)");
if (!DB::IsError($res)) {
out(_("ok"));
outn(_("removing zap table.."));