Пример #1
0
function return_route($called, $caller, $no_forward = false)
{
    global $ev, $pickup_key, $max_routes, $s_fallbacks, $no_groups, $no_pbx, $caller_id, $caller_name, $system_prefix;
    $rtp_f = $ev->GetValue("rtp_forward");
    // keep the initial called number
    $initial_called_number = $called;
    $username = $ev->GetValue("username");
    $address = $ev->GetValue("address");
    $address = explode(":", $address);
    $address = $address[0];
    $reason = $ev->GetValue("reason");
    $isdn_address = $ev->GetValue("address");
    $isdn_address = explode("/", $isdn_address);
    $sig_trunk = $isdn_address[0];
    $already_auth = $ev->GetValue("already-auth");
    $trusted_auth = $ev->GetValue("trusted-auth");
    $call_type = $ev->GetValue("call_type");
    debug("entered return_route(called='{$called}',caller='{$caller}',username='******',address='{$address}',already-auth='{$already_auth}',reason='{$reason}', trusted='{$trusted_auth}', call_type='{$call_type}')");
    $params_to_copy = "maxcall,call_type,already-auth,trusted-auth";
    // make sure that if we forward any calls and for calls from pbxassist are accepted
    $ev->params["copyparams"] = $params_to_copy;
    $ev->params["pbxparams"] = "{$params_to_copy},copyparams";
    if ($already_auth != "yes" && $reason != "divert_busy" && $reason != "divert_noanswer") {
        // check to see if user is allowed to make this call
        $query = "SELECT value FROM settings WHERE param='annonymous_calls'";
        $res = query_to_array($query);
        $anonim = $res[0]["value"];
        if (strtolower($anonim) != "yes" || $username) {
            // if annonymous calls are not allowed the call has to be from a known extension or from a known ip
            $query = "SELECT extension_id,1 as trusted,'from inside' as call_type FROM extensions WHERE extension='{$username}' UNION SELECT incoming_gateway_id, trusted, 'from outside' as call_type FROM incoming_gateways,gateways WHERE gateways.gateway_id=incoming_gateways.gateway_id AND incoming_gateways.ip='{$address}' UNION SELECT gateway_id, trusted, 'from outside' as call_type FROM gateways LEFT OUTER JOIN sig_trunks ON gateways.sig_trunk_id=sig_trunks.sig_trunk_id WHERE server='{$address}' OR server LIKE '{$address}:%' OR sig_trunk='{$sig_trunk}'";
        } else {
            // if $called is the same as one of our extensions try and autentify it -> in order to have pbx rights
            if (!$username) {
                $query = "SELECT * FROM extensions WHERE extension='{$caller}'";
                $res = query_to_array($query);
                if (count($res)) {
                    debug("could not auth call but '{$caller}' seems to be in extensions");
                    set_retval(NULL, "noauth");
                    return;
                }
            }
            // if annonymous calls are allowed call to be for a inner group or extension  or from a known ip
            $query = "SELECT incoming_gateway_id, trusted, 'from outside' as call_type FROM incoming_gateways, gateways WHERE incoming_gateways.gateway_id=gateways.gateway_id AND incoming_gateways.ip='{$address}' UNION SELECT gateway_id, trusted, 'from outside' as call_type FROM gateways LEFT OUTER JOIN sig_trunks ON gateways.sig_trunk_id=sig_trunks.sig_trunk_id WHERE server='{$address}' OR server LIKE '{$address}:%' OR sig_trunk='{$sig_trunk}' UNION SELECT extension_id,1 as trusted,'to inside' as call_type FROM extensions WHERE extension='{$called}' OR '{$system_prefix}' || extension='{$called}' OR extension='{$username}' UNION SELECT group_id, 1 as trusted,'to inside' as call_type  FROM groups WHERE extension='{$called}' OR '{$system_prefix}' || extension='{$called}' UNION SELECT did_id, 1 as trusted,'to inside' as call_type  FROM dids WHERE number='{$called}' OR '{$system_prefix}' || number='{$called}'";
        }
        $res = query_to_array($query);
        if (!count($res)) {
            debug("could not auth call");
            set_retval(NULL, "noauth");
            return;
        }
        $trusted_auth = $res[0]["trusted"] == 1 ? "yes" : "no";
        $call_type = $res[0]["call_type"];
        //($username) ? "from inside" : "from outside";  // from inside/outside of freesentral
    }
    debug("classified call as being '{$call_type}'");
    // mark call as already autentified
    $ev->params["already-auth"] = "yes";
    $ev->params["trusted-auth"] = $trusted_auth;
    $ev->params["call_type"] = $call_type;
    if ($call_type != "from inside") {
        $ev->params["pbxguest"] = true;
    }
    routeToAddressBook($called, $username);
    if (routeToDid($called)) {
        return;
    }
    if (!$no_groups) {
        if (routeToGroup($called)) {
            return;
        }
        if (makePickUp($called, $caller)) {
            return;
        }
    }
    if (routeToExtension($called)) {
        return;
    }
    if (!checkInternationalCalls($called)) {
        debug("Forbidding call to '{$called}' because because international calls are off.");
        set_retval(null, "forbidden");
        return;
    }
    if ($call_type == "from outside" && $initial_called_number == $called && $trusted_auth != "yes") {
        // if this is a call from outside our system and would be routed outside(from first step) and the number that was initially called was not modified with passing thought any of the above steps  => don't send it
        debug("forbidding call to '{$initial_called_number}' because call is 'from outside'");
        // set_retval(null, "forbidden");
        //return;
    }
    $query = "SELECT * FROM dial_plans INNER JOIN gateways ON dial_plans.gateway_id=gateways.gateway_id WHERE (prefix IS NULL OR '{$called}' LIKE " . get_SQL_concat(array("prefix", "'%'")) . ") AND (gateways.username IS NULL OR gateways.status='online') ORDER BY length(coalesce(prefix,'')) DESC, priority LIMIT {$max_routes}";
    $res = query_to_array($query);
    if (!count($res)) {
        debug("Could not find a matching dial plan=> rejecting with error: noroute");
        set_retval(NULL, "noroute");
        return;
    }
    $id = $ev->GetValue("true_party") ? $ev->GetValue("true_party") : $ev->GetValue("id");
    $start = count($res) - 1;
    $j = 0;
    $fallback = array();
    for ($i = $start; $i >= 0; $i--) {
        $fallback[$j] = $ev->params;
        $custom_caller_id = $res[$i]["callerid"] ? $res[$i]["callerid"] : $caller_id;
        $custom_caller_name = $res[$i]["callername"] ? $res[$i]["callername"] : $caller_name;
        $custom_domain = $res[$i]["domain"];
        if ($res[$i]["send_extension"] == 0) {
            $fallback[$j]["caller"] = $custom_caller_id;
            if ($custom_domain) {
                $fallback[$j]["domain"] = $custom_domain;
            }
            $fallback[$j]["callername"] = $custom_caller_name;
        } elseif ($system_prefix && $call_type == "from inside") {
            $fallback[$j]["caller"] = $system_prefix . $fallback[$j]["caller"];
        }
        $fallback[$j]["called"] = rewrite_digits($res[$i], $called);
        $fallback[$j]["formats"] = $res[$i]["formats"] ? $res[$i]["formats"] : $ev->GetValue("formats");
        $fallback[$j]["rtp_forward"] = $rtp_f == "possible" && $res[$i]["rtp_forward"] == 1 ? "yes" : "no";
        $location = build_location($res[$i], rewrite_digits($res[$i], $called), $fallback[$j]);
        if (!$location) {
            continue;
        }
        $fallback[$j]["location"] = $location;
        $j++;
    }
    if (!count($fallback)) {
        set_retval(NULL, "noroute");
        return;
    }
    $best_option = count($fallback) - 1;
    set_retval($fallback[$best_option]["location"]);
    debug("Sending {$id} to " . $fallback[$best_option]["location"]);
    unset($fallback[$best_option]["location"]);
    $ev->params = $fallback[$best_option];
    unset($fallback[$best_option]);
    if (count($fallback)) {
        $s_fallbacks[$id] = $fallback;
    }
    //	debug("There are ".count($s_fallbacks)." in fallback : ".format_array($s_fallbacks));
    debug("There are " . count($s_fallbacks) . " in fallback");
    return;
}
Пример #2
0
 *    "Komunikator" technical support e-mail: support@komunikator.ru
 *    The project "Komunikator" are used:
 *      the source code of "YATE" project, http://yate.null.ro/pmwiki/
 *      the source code of "FREESENTRAL" project, http://www.freesentral.com/
 *      "Sencha Ext JS" project libraries, http://www.sencha.com/products/extjs
 *    "Komunikator" web application is a free/libre and open-source software. Therefore it grants user rights
 *  for distribution and (or) modification (including other rights) of this programming solution according
 *  to GNU General Public License terms and conditions published by Free Software Foundation in version 3.
 *    In case the file "License" that describes GNU General Public License terms and conditions,
 *  version 3, is missing (initially goes with software source code), you can visit the official site
 *  http://www.gnu.org/licenses/ and find terms specified in appropriate GNU General Public License
 *  version (version 3 as well).
 *  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 */
if (!$_SESSION['user']) {
    echo out(array("success" => false, "message" => "User is undefined"));
    exit;
}
$total = compact_array(query_to_array("SELECT count(*) FROM prompts"));
if (!is_array($total["data"])) {
    echo out(array("success" => false, "message" => $total));
}
$prompt_path = "auto_attendant/";
$data = compact_array(query_to_array("SELECT prompt_id as id, status, prompt, description, " . get_SQL_concat(array("'{$prompt_path}'", 'file')) . " FROM prompts " . get_sql_order_limit()));
if (!is_array($data["data"])) {
    echo out(array("success" => false, "message" => $data));
}
$obj = array("success" => true);
$obj["total"] = $total['data'][0][0];
$obj["data"] = $data['data'];
echo out($obj);