Exemplo n.º 1
0
 $dialoutprefix = htmlentities($trunk_details['dialoutprefix']);
 $keepcid = htmlentities($trunk_details['keepcid']);
 $failtrunk = htmlentities($trunk_details['failscript']);
 $failtrunk_enable = $failtrunk == "" ? '' : 'CHECKED';
 $disabletrunk = htmlentities($trunk_details['disabled']);
 $continue = htmlentities($trunk_details['continue']);
 $provider = $trunk_details['provider'];
 $trunk_name = htmlentities($trunk_details['name']);
 $dialopts = $trunk_details['dialopts'] === false ? false : htmlentities($trunk_details['dialopts']);
 if ($tech != "enum") {
     $channelid = htmlentities($trunk_details['channelid']);
     if ($tech != "custom" && $tech != "dundi") {
         // custom trunks will not have user/peer details in database table
         // load from db
         if (empty($peerdetails)) {
             $peerdetails = core_trunks_getTrunkPeerDetails($trunknum);
         }
         if (empty($usercontext)) {
             $usercontext = htmlentities($trunk_details['usercontext']);
         }
         if (empty($userconfig)) {
             $userconfig = core_trunks_getTrunkUserConfig($trunknum);
         }
         if (empty($register)) {
             $register = core_trunks_getTrunkRegister($trunknum);
         }
     }
 }
 if (count($dialpattern_array) == 0) {
     $dialpattern_array = core_trunks_get_dialrules($trunknum);
 }
Exemplo n.º 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;
}
Exemplo n.º 3
0
/**
* @pram string; can be a trunk id, all or *, or registered/reg for just trunks that are registered
* @pram boolean; true disables trunk, false is enables trunk
*/
function core_trunks_disable($trunk, $switch)
{
    switch ($trunk) {
        case 'all':
        case '*':
            $trunks = core_trunks_getDetails();
            break;
        case 'reg':
        case 'registered':
            foreach (core_trunks_getDetails() as $t) {
                if ($reg = core_trunks_getTrunkRegister($t['trunkid'])) {
                    $trunks[] = $t;
                }
            }
            break;
        case '':
            return false;
            //cannot call without a trunk
            break;
        default:
            $trunks[] = core_trunks_getDetails($trunk);
            break;
    }
    //return if no trunks!
    if (empty($trunks)) {
        return false;
    }
    foreach ($trunks as $t) {
        $trunk = core_trunks_getDetails($t['trunkid']);
        $regstring = core_trunks_getTrunkRegister($t['trunkid']);
        $userconfig = core_trunks_getTrunkUserConfig($t['trunkid']);
        $peerdetails = core_trunks_getTrunkPeerDetails($t['trunkid']);
        $disabled = $switch ? 'on' : 'off';
        core_trunks_edit($trunk['trunkid'], $trunk['channelid'], $trunk['dialoutprefix'], $trunk['maxchans'], $trunk['outcid'], $peerdetails, $trunk['usercontext'], $userconfig, $regstring, $trunk['keepcid'], $trunk['failscript'], $disabled, $trunk['name'], $trunk['provider'], $trunk['continue']);
    }
}
Exemplo n.º 4
0
$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 = $current_config['gateways'][$gidx];
    if (isset($tlist["SIP/{$channelid}"])) {
        $json_array['status'] = 'success';
        if (!isset($_POST[$gidx]) || $_POST[$gidx] != 'yes') {
            continue;
        }
        $globalvar = $tlist["SIP/{$channelid}"]['globalvar'];
        $trunknum = ltrim($globalvar, 'OUT_');
        $trunk_details = core_trunks_getDetails($trunknum);
        $userconfig = core_trunks_getTrunkUserConfig($trunknum);
        $old_peerdetails = explode("\n", core_trunks_getTrunkPeerDetails($trunknum));
        foreach ($old_peerdetails as $param) {
            $parts = explode('=', $param, 2);
            switch (strtolower(trim($parts[0]))) {
                case 'allow':
                    $allow = "allow=" . $parts[1] . "\n";
                    break;
                case 'disallow':
                    $disallow = "disallow=" . $parts[1] . "\n";
                    break;
            }
        }
        $peer_stuff = $peerdetails . $gw . "\n" . $disallow . $allow;
        $reg = $register . $gw;
        /* Extract the allow/disallow now
         */