function initrpc() { global $freeiris_conf; // global $asterisk_conf; global $manager_conf; global $dbcon; // config read enginnger $freeiris_conf = new asteriskconf(); if ($freeiris_conf->parse_in_file('/etc/freeiris2/freeiris.conf') == false) { return rpcreturn(500, "can't open freeiris.conf", 100, null); } // $asterisk_conf = new asteriskconf(); // if ($asterisk_conf->parse_in_file($freeiris_conf->get('general','asterisketc').'/asterisk.conf')==false) // return(rpcreturn(500,"can't open ".$freeiris_conf->get('general','asterisketc').'/asterisk.conf',100,null)); $manager_conf = new asteriskconf(); if ($manager_conf->parse_in_file($freeiris_conf->get('general', 'asterisketc') . '/manager.conf') == false) { return rpcreturn(500, "can't open " . $freeiris_conf->get('general', 'asterisketc') . '/manager.conf', 100, null); } // 连接数据系统 $dbcon = mysql_pconnect($freeiris_conf->get('database', 'dbhost'), $freeiris_conf->get('database', 'dbuser'), $freeiris_conf->get('database', 'dbpasswd')); if (!$dbcon) { return rpcreturn(500, mysql_error(), 100, null); } // 选择库 $selectdb = mysql_select_db($freeiris_conf->get('database', 'dbname'), $dbcon); if (!$selectdb) { return rpcreturn(500, mysql_error(), 100, null); } return true; }
<?php include 'asteriskconf.inc.php'; $sip = new asteriskconf(); $sip->parse_in_file('delfrom.conf'); $sip->assign_delsection('1000'); // $sip->debug(); $sip->keep_resource_array = false; $sip->save_file('output.conf'); print $sip->errstr;
function option_confkey_edit($folder, $type, $section, $key, $newvalue) { global $freeiris_conf; global $dbcon; if ($folder == 'freeiris') { if ($type == 'freeiris.conf') { //取得配置 $confile = new asteriskconf(); if ($confile->parse_in_file('/etc/freeiris2/freeiris.conf') == false) { return rpcreturn(500, '/etc/freeiris2/freeiris.conf', 100, null); } $confile->assign_editkey($section, $key, $newvalue); //如果执行成功 $confile->save_file(); } else { $confile = new asteriskconf(); if ($confile->parse_in_file('/etc/freeiris2/' . $type) == false) { return rpcreturn(500, "can't open " . '/etc/freeiris2/' . $type, 100, null); } $confile->assign_editkey($section, $key, $newvalue); //如果执行成功 $confile->save_file(); } } elseif ($folder == 'asterisk') { $confile = new asteriskconf(); if ($confile->parse_in_file($freeiris_conf->get('general', 'asterisketc') . '/' . $type) == false) { return rpcreturn(500, "can't open " . $freeiris_conf->get('general', 'asterisketc') . '/' . $type, 100, null); } $confile->assign_editkey($section, $key, $newvalue); //如果执行成功 $confile->save_file(); } return rpcreturn(200, null, null, null, null); }
function voicefiles_delete($id) { global $freeiris_conf; global $dbcon; //取得主配置 $asterisk_conf = new asteriskconf(); if ($asterisk_conf->parse_in_file($freeiris_conf->get('general', 'asterisketc') . '/asterisk.conf') == false) { return rpcreturn(500, "can't open " . $freeiris_conf->get('general', 'asterisketc') . '/asterisk.conf', 100, null); } $result = mysql_query("select * from voicefiles where id = '" . $id . "'"); if (!$result) { return rpcreturn(500, mysql_error(), 100, null); } $resdata = mysql_fetch_array($result); mysql_free_result($result); if (!$resdata) { return rpcreturn(500, "can't find file", 113, null); } if ($resdata['label'] == 'sound') { $filepath = $asterisk_conf->get('directories', 'astvarlibdir') . '/sounds/' . $resdata['associate'] . '/' . $resdata['folder'] . '/' . $resdata['filename'] . '.' . $resdata['extname']; } elseif ($resdata['label'] == 'moh') { $filepath = $asterisk_conf->get('directories', 'astvarlibdir') . '/moh/' . $resdata['filename'] . '.' . $resdata['extname']; } elseif ($resdata['label'] == 'voicemail') { $filepath = $asterisk_conf->get('directories', 'astspooldir') . '/voicemail/freeiris/' . $resdata['folder'] . '/' . $resdata['filename'] . '.' . $resdata['extname']; } elseif ($resdata['label'] == 'onetouch') { $filepath = $asterisk_conf->get('directories', 'astspooldir') . '/voicemail/freeiris/' . $resdata['folder'] . '/' . $resdata['filename'] . '.' . $resdata['extname']; } elseif ($resdata['label'] == 'sysautomon') { $filepath = $asterisk_conf->get('directories', 'astspooldir') . '/monitor/' . $resdata['folder'] . '/' . $resdata['filename'] . '.' . $resdata['extname']; } elseif ($resdata['label'] == 'ivrmenu') { $filepath = $asterisk_conf->get('directories', 'astspooldir') . '/ivrmenu/' . $resdata['folder'] . '/' . $resdata['filename'] . '.' . $resdata['extname']; } //删除掉旧文件 unlink($filepath); //------------------------------------------------------删除 $result = mysql_query("delete from voicefiles where id = '" . $id . "'"); if (!$result) { return rpcreturn(500, mysql_error(), 100, null); } return rpcreturn(200, null, null, null, null); }
function fax_faxfile_download($faxid) { global $freeiris_conf; global $dbcon; //取得主配置 $asterisk_conf = new asteriskconf(); if ($asterisk_conf->parse_in_file($freeiris_conf->get('general', 'asterisketc') . '/asterisk.conf') == false) { return rpcreturn(500, "can't open " . $freeiris_conf->get('general', 'asterisketc') . '/asterisk.conf', 100, null); } //执行sql $result = mysql_query("select * from faxqueue where id = '" . $faxid . "'"); if (!$result) { return rpcreturn(500, mysql_error(), 100, null); } $resdata = mysql_fetch_array($result); mysql_free_result($result); if (!$resdata) { return rpcreturn(500, "can't find file", 113, null); } $filepath = $asterisk_conf->get('directories', 'astspooldir') . '/fax/' . $resdata['accountcode'] . '/' . $resdata['filename']; //打开文件body if (file_exists($filepath)) { $filestream = file_get_contents($filepath); } return rpcreturn(200, null, null, array('filestream' => $filestream, 'filename' => $resdata['filename'])); }
<?php include 'asteriskconf.inc.php'; $sip = new asteriskconf(); $sip->parse_in_file('t1.conf'); // $sip->assign_cleanfile(); // $sip->assign_matchreplace('secret=1234','secret=5678'); // $sip->assign_editkey('2000','type','peer'); // $sip->assign_delkey('pick','deleteme'); // $sip->assign_replacesection('replaceme',"type=friend\nport=5060\n"); //$sip->assign_replacesection('replaceme',array('type=friend','port=5060')); // $sip->assign_replacesection('replaceme',array('type'=>'friend','port'=>'5060')); // $sip->assign_delsection('1000'); // $sip->assign_addsection('1000'); // $sip->assign_addsection('9000'); //$sip->assign_append('down',NULL,'#tophead',NULL); //$sip->assign_append('up','general','language=en',NULL); //$sip->assign_append('down','general','language=en',NULL); //$sip->assign_append('foot','general','language=en',NULL); //$sip->assign_append('foot',NULL,'language=en',NULL); //$sip->assign_append('up','general','language=cn',array('useragent','as5300')); //$sip->assign_append('down','general','language=cn',array('useragent','as5300')); //$sip->assign_append('over','general','language=cn',array('useragent','as5300')); // $sip->debug(); // $sip->keep_resource_array=false; $sip->save_file('output.conf'); // print $sip->errstr;
function queue_delete($queuenumber) { global $freeiris_conf; global $dbcon; //------------------------------------------------------删除localnumber表记录 $result = mysql_query("delete from localnumber where number = '" . $queuenumber . "'"); if (!$result) { return rpcreturn(500, mysql_error(), 100, null); } //------------------------------------------------------删除基本数据 $dores = mysql_query("delete from queue where queuenumber = '" . $queuenumber . "'"); if (!$dores) { return rpcreturn(500, mysql_error(), 100, null); } //------------------------------------------------------删除配置数据 $queues_list_conf = new asteriskconf(); if ($queues_list_conf->parse_in_file($freeiris_conf->get('general', 'asterisketc') . '/queues_list.conf') == false) { return rpcreturn(500, "can't open " . $freeiris_conf->get('general', 'asterisketc') . '/queues_list.conf', 100, null); } $queues_list_conf->assign_delsection($queuenumber); //如果执行成功 if ($queues_list_conf->save_file() && $queues_list_conf->last_changed_file == $freeiris_conf->get('general', 'asterisketc') . '/queues_list.conf') { return rpcreturn(200, null, null, null, true); } else { return rpcreturn(200, null, null, null); } }
$mail = new PHPMailer(); $mail->PluginDir = dirname(__FILE__) . "/../lib/"; //version $VERSION = '1.0'; //debug?? if (array_key_exists(1, $_SERVER['argv']) == true && $_SERVER['argv'][1] == '--verbose') { $verbose = true; } message('notice', "fax deliver by hoowa sun " . $VERSION); //读出基本配置文件 $freeiris_conf = new asteriskconf(); if ($freeiris_conf->parse_in_file('/etc/freeiris2/freeiris.conf') == false) { exit; } $asterisk_conf = new asteriskconf(); if ($asterisk_conf->parse_in_file($freeiris_conf->get('general', 'asterisketc') . '/asterisk.conf') == false) { exit; } //查看自己是否已经在内存中了 if (check_processes($freeiris_conf->get('general', 'freeiris_root') . "/logs/faxdeliver.pid", $_SERVER['SCRIPT_NAME']) == true) { message('error', 'processes alreadly in memory , exists!'); } system("echo '" . getmypid() . "' > " . $freeiris_conf->get('general', 'freeiris_root') . "/logs/faxdeliver.pid"); #删除掉所有三个月以上的旧数据 //mysql_query("DELETE FROM faxqueue WHERE cretime <= '".date("Y-m-d",strtotime('-3 month'))." 00:00:00'",$db); //生成发送队列准备 $q_faxdeliver = array(); //取出一条记录进行处理 $db = mysql_connect($freeiris_conf->get('database', 'dbhost'), $freeiris_conf->get('database', 'dbuser'), $freeiris_conf->get('database', 'dbpasswd')); if (!$db) { message('error', 'Could not connect: ' . mysql_error());
function extension_add_fxs($exten) { global $freeiris_conf; global $dbcon; //------------------------------------------------------创建localnumber表记录 $result = mysql_query("insert into localnumber set number = '" . $exten['devicenumber'] . "',typeof = 'extension',assign = '" . $exten['accountcode'] . "'"); if (!$result) { return rpcreturn(500, mysql_error(), 100, null); } //------------------------------------------------------创建extension表记录 $result = mysql_query("insert into extension set accountcode = '" . $exten['accountcode'] . "',cretime=now()," . "password='******'password'] . "'," . "deviceproto='fxs'," . "devicenumber='" . $exten['devicenumber'] . "'," . "devicestring='" . $exten['devicestring'] . "'," . "fristchecked=0," . "transfernumber='" . $exten['transfernumber'] . "'," . "diallocal_failed='" . $exten['diallocal_failed'] . "'," . "info_name='" . $exten['info_name'] . "'," . "info_email='" . $exten['info_email'] . "'," . "info_detail='" . $exten['info_detail'] . "'," . "info_remark='" . $exten['info_remark'] . "'"); if (!$result) { return rpcreturn(500, mysql_error(), 100, null); } //------------------------------------------------------生成分组数据 foreach (split('[\\,|\\s|\\ ]', $exten['extengroup']) as $value) { $groupnames = $groupnames . " groupname = '{$value}' OR "; } $groupnames = rtrim($groupnames, 'OR '); $exten['callgroup'] = null; $exten['pickupgroup'] = null; $result = mysql_query("select * from extengroup where {$groupnames}"); if (!$result) { return rpcreturn(500, mysql_error(), 100, null); } while ($each = mysql_fetch_array($result)) { //创建分组 $dores = mysql_query("insert into extengroup_assign set groupid = '" . $each['groupid'] . "' , accountcode = '" . $exten['accountcode'] . "'"); if (!$dores) { return rpcreturn(500, mysql_error(), 100, null); } //补充sip template所需数据 $exten['callgroup'] = $exten['callgroup'] . $each['groupid'] . ','; $exten['pickupgroup'] = $exten['pickupgroup'] . $each['groupid'] . ','; } mysql_free_result($result); //------------------------------------------------------hints的数据处理 extension_hints_add($exten['devicenumber'], 'DAHDI', $exten['devicestring']); //------------------------------------------------------生成template数据格式 $tplcontents = conftpl_replace('/etc/freeiris2/chan_dahdi_fxs.conf.tpl', $exten); //存储到配置文件中 $fxs_conf = new asteriskconf(); if ($fxs_conf->parse_in_file($freeiris_conf->get('general', 'asterisketc') . '/chan_dahdi_fxs.conf') == false) { return rpcreturn(500, "can't open " . $freeiris_conf->get('general', 'asterisketc') . '/chan_dahdi_fxs.conf', 100, null); } $fxs_conf->assign_append('foot', null, $tplcontents, null); $fxs_conf->save_file(); return rpcreturn(200, null, null, null, true); }
<?php include 'asteriskconf.inc.php'; $sip = new asteriskconf(); $f = $sip->parse_in_file('sip.conf'); if ($f == false) { echo "false"; } $sections = $sip->section_list(); $parsed = $sip->section_all(); $keyslist = $sip->key_list('general'); $keyshash = $sip->key_all('general'); $keyvalue = $sip->get('general', 'language'); $sip->debug(); $sip->keep_resource_array = false; $sip->reload(); $sip->debug();
function trunk_add_fxo($devdata) { global $freeiris_conf; global $dbcon; //------------------------------------------------------创建trunk记录 $result = mysql_query("insert into trunk set trunkname = '" . $devdata['trunkname'] . "',cretime=now()," . "trunkproto='" . $devdata['trunkproto'] . "'," . "trunkprototype='" . $devdata['trunkprototype'] . "'," . "trunkdevice='" . $devdata['trunkdevice'] . "'," . "trunkremark='" . $devdata['trunkremark'] . "'"); if (!$result) { return rpcreturn(500, mysql_error(), 100, null); } //------------------------------------------------------创建trunk记录的id $result = mysql_query("select last_insert_id()"); $lastid = mysql_fetch_array($result); mysql_free_result($result); $lastid = $lastid[0]; //------------------------------------------------------创建localnumber表记录 $result = mysql_query("insert into localnumber set number = '" . $devdata['trunkdevice'] . "',typeof = 'trunk',assign = '" . $lastid . "'"); if (!$result) { return rpcreturn(500, mysql_error(), 100, null); } //------------------------------------------------------生成template数据格式 $devdata['channel'] = chanpacker($devdata['channel_array']); $tplcontents = conftpl_replace('/etc/freeiris2/chan_dahdi_fxo.conf.tpl', $devdata); //存储到配置文件中 $fxo_conf = new asteriskconf(); if ($fxo_conf->parse_in_file($freeiris_conf->get('general', 'asterisketc') . '/chan_dahdi_fxo.conf') == false) { return rpcreturn(500, "can't open " . $freeiris_conf->get('general', 'asterisketc') . '/chan_dahdi_fxo.conf', 100, null); } $fxo_conf->assign_append('foot', null, $tplcontents, null); $fxo_conf->save_file(); return rpcreturn(200, null, null, null, true); }
function base_registration_set($systemid, $register_name) { global $freeiris_conf; global $dbcon; $confile = new asteriskconf(); if ($confile->parse_in_file('/etc/freeiris2/freeiris.conf') == false) { return rpcreturn(500, "can't open " . '/etc/freeiris2/freeiris.conf', 100, null); } $confile->assign_editkey('registration', 'register_name', $register_name); $confile->assign_editkey('registration', 'systemid', $systemid); //如果执行成功 $confile->save_file(); return rpcreturn(200, null, null, null, null); }