Пример #1
0
function trunk_list($order, $limitfrom, $limitoffset)
{
    global $freeiris_conf;
    global $dbcon;
    //先从AMI里取得匹配用数据
    $asm = new freeiris_ami('freeiris', 'freeiris', 'localhost', 5038);
    if (!$asm->connect()) {
        return rpcreturn(500, 'ami connect failed', 108, null);
    }
    //get sip registry
    $amimessages = $asm->send_request('command', array('ActionID' => 'acs', command => 'sip show registry'));
    $peersarray = preg_split('/\\n/', $amimessages['data']);
    $peersresult_sip = asunpacker($peersarray[2], $peersarray);
    //get iax2 registry
    $amimessages = $asm->send_request('command', array('ActionID' => 'acs', command => 'iax2 show registry'));
    $peersarray = preg_split('/\\n/', $amimessages['data']);
    $peersresult_iax2 = asunpacker($peersarray[2], $peersarray);
    $asm->disconnect();
    //从配置中取数据
    $sip_trunk_conf = new asteriskconf();
    if ($sip_trunk_conf->parse_in_file($freeiris_conf->get('general', 'asterisketc') . '/sip_trunk.conf') == false) {
        return rpcreturn(500, "can't open " . $freeiris_conf->get('general', 'asterisketc') . '/sip_trunk.conf', 100, null);
    }
    $iax2_trunk_conf = new asteriskconf();
    if ($iax2_trunk_conf->parse_in_file($freeiris_conf->get('general', 'asterisketc') . '/iax_trunk.conf') == false) {
        return rpcreturn(500, "can't open " . $freeiris_conf->get('general', 'asterisketc') . '/iax_trunk.conf', 100, null);
    }
    //执行sql
    $result_array = array();
    $result = mysql_query("select * from trunk {$order} limit {$limitfrom},{$limitoffset}");
    if (!$result) {
        return array('response' => array('statcode' => 500, 'message' => mysql_error()));
    }
    while ($each = mysql_fetch_array($result)) {
        $match_host = null;
        $match_username = null;
        $peersresult = array();
        //如果是SIP注册模式
        if ($each['trunkproto'] == 'sip' && $each['trunkprototype'] == 'reg') {
            $match_host = $sip_trunk_conf->get($each['trunkdevice'], 'host') . ':' . $sip_trunk_conf->get($each['trunkdevice'], 'port');
            $match_username = $sip_trunk_conf->get($each['trunkdevice'], 'username');
            $peersresult = $peersresult_sip;
        } elseif ($each['trunkproto'] == 'iax2' && $each['trunkprototype'] == 'reg') {
            $match_host = $iax2_trunk_conf->get($each['trunkdevice'], 'host') . ':' . $iax2_trunk_conf->get($each['trunkdevice'], 'port');
            $match_username = $iax2_trunk_conf->get($each['trunkdevice'], 'username');
            $peersresult = $peersresult_iax2;
        }
        //如果需要进行查找
        if (count($peersresult) > 0) {
            //查找这个帐户是否已经注册上了
            for ($i = 3; $i <= count($peersresult) - 2; $i++) {
                $oneres = $peersresult[$i];
                if (!array_key_exists('Host', $oneres)) {
                    continue;
                }
                if ($oneres['Host'] == $match_host && $oneres['Username'] == $match_username) {
                    $each['reg_state'] = $oneres['State'];
                    break;
                }
            }
        }
        array_push($result_array, $each);
    }
    mysql_free_result($result);
    return rpcreturn(200, null, null, array('trunks' => $result_array));
}
Пример #2
0
            message('error', 'not found fax application');
        }
        message('notice', 'get licensed failed ignore!');
    } elseif ($currentfax == $licensedfax) {
        //已经达到并发量,本程序退出
        message('error', 'fax licensed $currentfax of $licen');
    }
    message('notice', $eachone['accountcode'] . " SENDING " . $eachone['number']);
    //进行发送
    $amimessages = $asm->send_request('Originate', array('ActionID' => uniqid(), 'Channel' => "LOCAL/" . $eachone['number'] . "@sub-outgoing/n\n", 'CallerID' => $eachone['accountcode'] . " <" . $eachone['accountcode'] . ">", 'Timeout' => $freeiris_conf->get('fastagi', 'dial_ringtime') * 1000, 'Context' => 'app-sendfax', 'Exten' => 'inprocess', 'Priority' => '1', 'Variable' => "CHANNEL(language)=cn|FRI2_FAXQUEUEID=" . $eachone['id'] . "|FRI2_FAXSENDANNOUNCE=" . $eachone['sendannounce'], 'Async' => 'true'));
    //更新记录
    if ($eachone['status'] != 1) {
        mysql_query("update faxqueue set status = 1 where id = '" . $eachone['id'] . "'", $db);
    }
}
$asm->disconnect();
mysql_close($db);
//-----------------------------------信息输出
function message($type, $message)
{
    global $verbose;
    if ($verbose == true) {
        echo "{$message}\n";
    }
    if ($type == 'error') {
        exit;
    }
    return true;
}
function check_processes($pid, $keyname)
{
Пример #3
0
function ami_originate($actionid, $parameter)
{
    global $freeiris_conf;
    global $manager_conf;
    global $dbcon;
    //连接AMI
    $asm = new freeiris_ami('freeiris', 'freeiris', 'localhost', 5038);
    if (!$asm->connect()) {
        return rpcreturn(500, 'ami connect failed', 108, null);
    } else {
        $amimessages = $asm->send_request('Originate', array_merge(array('ActionID' => $actionid), $parameter));
        $asm->disconnect();
        return rpcreturn(200, null, null, array('ami' => $amimessages));
    }
}