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)); }
} 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; foreach (preg_split("/\n/", $amimessages['data']) as $value) {
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)); } }