示例#1
0
    message('error', 'Could not connect: ' . mysql_error());
}
mysql_select_db($freeiris_conf->get('database', 'dbname'), $db);
$result = mysql_query("select * from faxqueue where mode = 0 and status = 0 order by id asc", $db);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    message('notice', "NEW SENDFAX ID (" . $row['id'] . ")");
    message('notice', "        NUMBER (" . $row['number'] . ")");
    message('notice', "   ACCOUNTCODE (" . $row['accountcode'] . ")");
    message('notice', "      FILENAME (" . $row['filename'] . ")");
    message('notice', "       CRETIME (" . $row['cretime'] . ")");
    message('notice', "        STATUS (" . $row['status'] . ")");
    array_push($q_faxdeliver, $row);
}
mysql_free_result($result);
//connect ami with stream timeout 8 sec
$asm = new freeiris_ami('freeiris', 'freeiris', 'localhost', 5038, 8);
if (!$asm->connect()) {
    message('error', 'ami connect failed');
}
$asm->send_request('Events', array('EVENTMASK' => 'off'));
//发送队列处理
foreach ($q_faxdeliver as $key => $eachone) {
    //允许前一个发送X秒等待时间,防止超过传真授权许可数量
    if ($key > 0) {
        message('notice', "NEXT SEND WILL BE START AFTER 10sec");
        sleep(10);
    }
    //检测系统已有并发量和限制
    $amimessages = $asm->send_request('command', array('ActionID' => uniqid(), 'command' => 'fax show stats'));
    $currentfax = null;
    $licensedfax = null;
示例#2
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));
    }
}
示例#3
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));
}
示例#4
0
文件: outgoing.php 项目: ljhcj/IRISCC
    //如果存在被叫队列就记录
    if (count($row['members']) > 0) {
        array_push($q_outgoing_number, $row);
        message('notice', "NEW OUTGOING ID (" . $row['id'] . ")");
        message('notice', "       CALLBACK (" . $row['localnumber'] . ")");
        message('notice', "       STARTIME (" . $row['startime'] . ")");
        message('notice', "        MEMBERS (" . $row['numbercount'] . ")");
        message('notice', "         CALLED (" . $row['calledcount'] . ")");
        //如果不存在或其他原因直接设置此队列为完成状态
    } else {
        mysql_query("update outgoing set tune=1 where id = '" . $row['id'] . "'");
    }
}
mysql_free_result($result);
//connect ami with stream timeout 8 sec
$asm = new freeiris_ami('freeiris', 'freeiris', 'localhost', 5038, 8);
if (!$asm->connect()) {
    message('error', 'ami connect failed');
}
$asm->send_request('Events', array('EVENTMASK' => 'off'));
//开始处理
foreach ($q_outgoing_number as $eachone) {
    //读出每个member
    $i = 0;
    foreach ($eachone['members'] as $member) {
        message('notice', $eachone['name'] . " CALLING " . $member['number']);
        $amimessages = $asm->send_request('Originate', array('ActionID' => uniqid(), 'Channel' => "LOCAL/" . $member['number'] . "@sub-outgoing/n\n", 'Context' => 'sub-outgoing-callback', 'Exten' => $eachone['localnumber'], 'Priority' => '1', 'Timeout' => $eachone['outgoing_waittime'] * 1000, 'CallerID' => $eachone['outgoing_callerid'] . " <" . $eachone['outgoing_callerid'] . ">", 'Variable' => "CHANNEL(language)=cn|FRI2_OUTGOING_MEMBERID=" . $member['id'] . "|FRI2_OUTGOING_ID=" . $eachone['id'] . "|FRI2_OUTGOING_NUMBER=" . $member['number'], 'Async' => 'true'));
        //更新members记录
        mysql_query("update outgoing_members set status=1 where id = '" . $member['id'] . "'", $db);
        $i++;
    }