| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
error_reporting(0); |
|---|
| 11 |
|
|---|
| 12 |
include_once('sipstation.utility.php'); |
|---|
| 13 |
|
|---|
| 14 |
if (! @include_once("common/json.inc.php")) { |
|---|
| 15 |
$quietmode=1; |
|---|
| 16 |
include_once("/var/www/html/admin/common/json.inc.php"); |
|---|
| 17 |
include_once("/var/www/html/admin/functions.inc.php"); |
|---|
| 18 |
$amp_conf = parse_amportal_conf("/etc/amportal.conf"); |
|---|
| 19 |
include_once("/var/www/html/admin/common/db_connect.php"); |
|---|
| 20 |
include_once("/var/www/html/admin/modules/core/functions.inc.php"); |
|---|
| 21 |
if (!isset($active_modules)) { |
|---|
| 22 |
$active_modules = array(); |
|---|
| 23 |
} |
|---|
| 24 |
} |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
$filter = array( |
|---|
| 35 |
'sip_username' => true, |
|---|
| 36 |
'sip_password' => true, |
|---|
| 37 |
'gateways' => true, |
|---|
| 38 |
'asterisk_settings' => true, |
|---|
| 39 |
); |
|---|
| 40 |
$current_config = sipstation_get_config("xxx", false, $filter); |
|---|
| 41 |
|
|---|
| 42 |
$need_reload = false; |
|---|
| 43 |
|
|---|
| 44 |
$sip_user = $current_config['sip_username']; |
|---|
| 45 |
$sip_pass = $current_config['sip_password']; |
|---|
| 46 |
|
|---|
| 47 |
$tlist = core_trunks_list(true); |
|---|
| 48 |
$tech = 'sip'; |
|---|
| 49 |
|
|---|
| 50 |
$peer_array = array(); |
|---|
| 51 |
foreach ($current_config['asterisk_settings']['peer'] as $param) { |
|---|
| 52 |
$peerdetails .= trim($param)."\n"; |
|---|
| 53 |
$parts = explode('=',$param,2); |
|---|
| 54 |
$peer_array[$parts[0]] = $parts[1]; |
|---|
| 55 |
} |
|---|
| 56 |
$peerdetails .= "username=$sip_user\nsecret=$sip_pass\nhost="; |
|---|
| 57 |
$register = "$sip_user:$sip_pass@"; |
|---|
| 58 |
|
|---|
| 59 |
for ($i=1;$i<3;$i++) { |
|---|
| 60 |
$gidx = "gw$i"; |
|---|
| 61 |
$channelid = "fpbx-$i-$sip_user"; |
|---|
| 62 |
$gw = $current_config['gateways'][$gidx]; |
|---|
| 63 |
if (isset($tlist["SIP/$channelid"])) { |
|---|
| 64 |
$json_array['status'] = 'success'; |
|---|
| 65 |
if (!isset($_POST[$gidx]) || $_POST[$gidx] != 'yes') { |
|---|
| 66 |
continue; |
|---|
| 67 |
} |
|---|
| 68 |
$globalvar = $tlist["SIP/$channelid"]['globalvar']; |
|---|
| 69 |
$trunknum = ltrim($globalvar,'OUT_'); |
|---|
| 70 |
$trunk_details = core_trunks_getDetails($trunknum); |
|---|
| 71 |
$userconfig = core_trunks_getTrunkUserConfig($trunknum); |
|---|
| 72 |
$old_peerdetails = explode("\n",core_trunks_getTrunkPeerDetails($trunknum)); |
|---|
| 73 |
foreach ($old_peerdetails as $param) { |
|---|
| 74 |
$parts = explode('=',$param,2); |
|---|
| 75 |
switch (strtolower(trim($parts[0]))) { |
|---|
| 76 |
case 'allow': |
|---|
| 77 |
$allow = "allow=".$parts[1]."\n"; |
|---|
| 78 |
break; |
|---|
| 79 |
case 'disallow': |
|---|
| 80 |
$disallow = "disallow=".$parts[1]."\n"; |
|---|
| 81 |
break; |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
$peer_stuff = $peerdetails.$gw."\n".$disallow.$allow; |
|---|
| 85 |
$reg = $register.$gw; |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
*/ |
|---|
| 89 |
$tech = $trunk_details['tech']; |
|---|
| 90 |
$outcid = $trunk_details['outcid']; |
|---|
| 91 |
$maxchans = $trunk_details['maxchans']; |
|---|
| 92 |
$dialoutprefix = $trunk_details['dialoutprefix']; |
|---|
| 93 |
$keepcid = $trunk_details['keepcid']; |
|---|
| 94 |
$failtrunk = $trunk_details['failscript']; |
|---|
| 95 |
$disabletrunk = $trunk_details['disabled']; |
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
/* |
|---|
| 99 |
$provider = $trunk_details['provider']; |
|---|
| 100 |
$trunk_name = $trunk_details['name']; |
|---|
| 101 |
*/ |
|---|
| 102 |
core_trunks_edit($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peer_stuff, $usercontext, $userconfig, $reg, $keepcid, $failtrunk, $disabletrunk); |
|---|
| 103 |
$need_reload = true; |
|---|
| 104 |
$json_array['status'] = 'success'; |
|---|
| 105 |
$json_array['trunk_updated'][$gidx] = $trunknum; |
|---|
| 106 |
} |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
if ($need_reload) { |
|---|
| 113 |
needreload(); |
|---|
| 114 |
if ($_POST['send_reload'] == 'yes') { |
|---|
| 115 |
ob_start(); |
|---|
| 116 |
if (!@include ('views/freepbx_reloadbar.php')) { |
|---|
| 117 |
@include ('../../views/freepbx_reloadbar.php'); |
|---|
| 118 |
} |
|---|
| 119 |
$json_array['reload_bar'] = ob_get_clean(); |
|---|
| 120 |
ob_start(); |
|---|
| 121 |
if (!@include ('views/freepbx_reload.php')) { |
|---|
| 122 |
@include ('../../views/freepbx_reload.php'); |
|---|
| 123 |
} |
|---|
| 124 |
$json_array['reload_header'] = ob_get_clean(); |
|---|
| 125 |
} |
|---|
| 126 |
$json_array['show_reload'] = 'yes'; |
|---|
| 127 |
} else { |
|---|
| 128 |
$json_array['show_reload'] = 'no'; |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
$json = new Services_JSON(); |
|---|
| 132 |
$value = $json->decode($_POST); |
|---|
| 133 |
|
|---|
| 134 |
header("Content-type: application/json"); |
|---|
| 135 |
echo $json->encode($json_array); |
|---|
| 136 |
|
|---|