function dundicheck_lookup_all($num)
{
    global $astman;
    $dundimap = array();
    $trunklist = core_trunks_list(true);
    if (is_array($trunklist)) {
        foreach ($trunklist as $trunkprops) {
            if (trim($trunkprops['value']) == 'on') {
                // value of on is disabled and for zap we don't create a context
                continue;
            }
            switch ($trunkprops['tech']) {
                case 'DUNDI':
                    $dundimap[] = $trunkprops['name'];
                    break;
                default:
            }
        }
    }
    $results = array();
    if ($astman) {
        foreach ($dundimap as $lookup) {
            $response = $astman->send_request('Command', array('Command' => "dundi lookup {$num}@{$lookup}"));
            if (strstr($response['data'], $num . ' (EXISTS)')) {
                $results[$lookup] = $response['data'];
            }
        }
        // if sound would have returned so return null
        return $results;
    }
}
Beispiel #2
0
function core_trunks_add($tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, $failtrunk, $disabletrunk, $name = "", $provider = "", $continue = "off", $dialopts = false)
{
    global $db;
    $name = trim($name) == "" ? $channelid : $name;
    // find the next available ID
    $trunknum = 1;
    // This is pretty ugle, will fix when we redo trunks and routes with proper uniqueids.
    // get the list, sort them, then look for a hole and use it, or overflow to the end if
    // not and use that
    //
    $trunk_hash = array();
    foreach (core_trunks_list() as $trunk) {
        $trunknum = ltrim($trunk[0], "OUT_");
        $trunk_hash[] = $trunknum;
    }
    sort($trunk_hash);
    $trunknum = 1;
    foreach ($trunk_hash as $trunk_id) {
        if ($trunk_id != $trunknum) {
            break;
        }
        $trunknum++;
    }
    core_trunks_backendAdd($trunknum, $tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, $failtrunk, $disabletrunk, $name, $provider, $continue, $dialopts);
    return $trunknum;
}
Beispiel #3
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;
}
Beispiel #4
0
} else {
    $trunks = array();
    $trunks_hash = array();
    foreach ($results as $trunk_call) {
        if (preg_match('/^dialout-(?:trunk|enum|dundi),([\\d]+),.*$/', $trunk_call, $match) != 1) {
            out(_("error detected"));
            out(sprintf(_("an erroneous entry, %s,  was found in extensions table that should not be there"), $trunk_call));
        } else {
            $trunks_hash[$match[1]] = "OUT_" . $match[1];
        }
    }
    $num_trunks = count($trunks_hash);
    out(sprintf(_("found %s"), $num_trunks));
    outn(_("checking for phantoms.."));
    require_once $amp_conf['AMPWEBROOT'] . '/admin/modules/core/functions.inc.php';
    $trunks = core_trunks_list(true);
    $bad_trunks = array();
    $cnt = 0;
    foreach ($trunks_hash as $trunknum => $globalvar) {
        $bad = true;
        foreach ($trunks as $trunk) {
            if ($trunk['globalvar'] == $globalvar) {
                $bad = false;
                break;
            }
        }
        if ($bad) {
            $cnt++;
            outn("{$trunknum}..");
            __core_routing_trunk_del($trunknum);
        }
Beispiel #5
0
    }
}
/* For testing:
*/
/*
include_once("common/json.inc.php");
*/
/* We can use the cached config data as we were just told that
   trunk params have changed and chose to update
 */
$filter = array('sip_username' => true, 'sip_password' => true, 'gateways' => true, 'asterisk_settings' => true);
$current_config = sipstation_get_config("xxx", false, $filter);
$need_reload = false;
$sip_user = $current_config['sip_username'];
$sip_pass = $current_config['sip_password'];
$tlist = core_trunks_list(true);
$tech = 'sip';
$peer_array = array();
foreach ($current_config['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 = $current_config['gateways'][$gidx];
    if (isset($tlist["SIP/{$channelid}"])) {
        $json_array['status'] = 'success';