예제 #1
0
     if ($usercontext != '' && $usercontext == $sv_usercontext) {
         $usercontext .= '_copy_' . $trunknum;
     }
     $disabletrunk = 'on';
     $continue = 'on';
     $trunknum = '';
     $extdisplay = '';
     // Fallthrough to addtrunk now...
     //
 // Fallthrough to addtrunk now...
 //
 case "addtrunk":
     if ($tech == 'pjsip') {
         $channelid = !empty($_REQUEST['trunk_name']) ? $_REQUEST['trunk_name'] : '';
     }
     $trunknum = core_trunks_add($tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk), $disabletrunk, $trunk_name, $provider, $continue, $dialopts);
     core_trunks_update_dialrules($trunknum, $dialpattern_insert);
     needreload();
     redirect_standard();
     break;
 case "edittrunk":
     if ($tech == 'pjsip') {
         $channelid = !empty($_REQUEST['trunk_name']) ? $_REQUEST['trunk_name'] : '';
     }
     core_trunks_edit($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk), $disabletrunk, $trunk_name, $provider, $continue, $dialopts);
     // this can rewrite too, so edit is the same
     core_trunks_update_dialrules($trunknum, $dialpattern_insert, true);
     needreload();
     redirect_standard('extdisplay');
     break;
 case "deltrunk":
예제 #2
0
function sipstation_get_or_create_trunks(&$json_array, &$globalvar1, &$trunknum1, &$globalvar2, &$trunknum2)
{
    // now check on trunk config
    // fpbx-1-$sip_user / fpbx-2-$sip_user
    // TODO: 2.6 has trunkname, provider options that should be used
    //
    global $ast_codec_hash;
    $sip_user = $json_array['sip_username'];
    $sip_pass = $json_array['sip_password'];
    $default_did = $json_array['e911_address']['default_did'];
    $need_reload = false;
    $tlist = core_trunks_list(true);
    $tech = 'sip';
    $keepcid = 'off';
    $disabletrunk = 'off';
    $peerdetails = "disallow=all\nallow=" . implode('&', array_keys($ast_codec_hash)) . "\n";
    $peer_array = array();
    foreach ($json_array['asterisk_settings']['peer'] as $param) {
        $peerdetails .= trim($param) . "\n";
        $parts = explode('=', $param, 2);
        $peer_array[$parts[0]] = $parts[1];
    }
    $peerdetails .= "username={$sip_user}\nsecret={$sip_pass}\nhost=";
    $register = "{$sip_user}:{$sip_pass}@";
    for ($i = 1; $i < 3; $i++) {
        $gidx = "gw{$i}";
        $channelid = "fpbx-{$i}-{$sip_user}";
        $gw = $json_array['gateways'][$gidx];
        if (isset($tlist["SIP/{$channelid}"])) {
            $globalvar = $tlist["SIP/{$channelid}"]['globalvar'];
            $trunknum = ltrim($globalvar, 'OUT_');
            // Now get some trunk status info
            $trunk_status = sipstation_get_peer_status($channelid);
            if ($trunk_status['sipstation_status'] == 'ok') {
                $json_array['trunk_qualify'][$gidx] = $trunk_status['Status'];
                $json_array['trunk_codecs'][$gidx] = implode(' | ', sipstation_get_configured_codecs($channelid, $trunk_status));
            } else {
                //TODO: probably nothing
            }
            $json_array['trunk_name'][$gidx] = core_trunks_getTrunkTrunkName($trunknum);
        } else {
            $trunknum = core_trunks_add($tech, $channelid, '', '', $default_did, $peerdetails . $gw, '', '', $register . $gw, $keepcid, '', $disabletrunk);
            $globalvar = "OUT_" . $trunknum;
            $need_reload = true;
            $json_array['created_trunks'][$gidx] = $channelid;
            // TODO: 2.6 should be name
            $json_array['trunk_name'][$gidx] = "SIP/{$channelid}";
        }
        // We need these next and need them past back up
        $gv = "globalvar{$i}";
        $tn = "trunknum{$i}";
        ${$gv} = $globalvar;
        ${$tn} = $trunknum;
    }
    $peer_array['username'] = $sip_user;
    $peer_array['secret'] = $sip_pass;
    $trunk_check = array($trunknum1, $trunknum2);
    $cnt = 1;
    foreach ($trunk_check as $tr) {
        $json_array['trunk_id']["gw{$cnt}"] = $tr;
        // need to get this set for both anyhow
        $gw = $json_array['gateways']["gw{$cnt}"];
        $peer_array['host'] = $gw;
        $peer_stuff = array();
        $tr_reg = core_trunks_getTrunkRegister($tr);
        foreach (explode("\n", core_trunks_getTrunkPeerDetails($tr)) as $elem) {
            $temp = explode("=", $elem, 2);
            if ($temp[0] == 'allow') {
                $peer_stuff[$temp[0]] = explode('&', $temp[1]);
            } elseif ($temp[0] != '') {
                $peer_stuff[$temp[0]] = $temp[1];
            }
        }
        // Unset some settings that do not hurt to change and might help
        //
        if (isset($peer_stuff['allow'])) {
            unset($peer_stuff['allow']);
        }
        if (isset($peer_stuff['disallow'])) {
            unset($peer_stuff['disallow']);
        }
        unset($peer_array['qualify']);
        if (isset($peer_stuff['qualify'])) {
            unset($peer_stuff['qualify']);
        }
        unset($peer_array['qualify']);
        if (isset($peer_stuff['context'])) {
            unset($peer_stuff['context']);
        }
        unset($peer_array['context']);
        if (isset($peer_stuff['qualifyfreq'])) {
            unset($peer_stuff['qualifyfreq']);
        }
        if (isset($peer_stuff['dtmfmode'])) {
            switch ($peer_stuff['dtmfmode']) {
                case 'inband':
                case 'rfc2833':
                case 'auto':
                    unset($peer_stuff['dtmfmode']);
                    unset($peer_array['dtmfmode']);
                    break;
            }
        }
        if ($peer_array != $peer_stuff || $tr_reg != $register . $gw) {
            $json_array['changed_trunks']["gw{$cnt}"] = $tr;
        }
        $cnt++;
    }
    return $need_reload;
}