Example #1
0
function conftpl_keys($file)
{
    //打开文件
    $handle = fopen($file, "r");
    if (!$handle) {
        return rpcreturn(500, "failed to open template file : {$file}", 100, null);
    }
    $contents = null;
    while (!feof($handle)) {
        $contents .= fread($handle, 8192);
    }
    fclose($handle);
    //取出所有key
    //preg_match_all('/(\$\w+)/',$contents,$tpl_key_array);
    preg_match_all('/(\\$[\\w|\\-]+)/', $contents, $tpl_key_array);
    $tpl_key_array = $tpl_key_array[0];
    arsort($tpl_key_array);
    return array($tpl_key_array, $contents);
}
Example #2
0
function extension_list($order, $limitfrom, $limitoffset)
{
    //验证请求者权限
    session_start();
    if (!isset($_SESSION["client_authorized"]) || $_SESSION["client_authorized"] == false) {
        return rpcreturn(401, 'authorization failed', 102, null);
    }
}
Example #3
0
function router_recall($routerid, $proirety)
{
    global $freeiris_conf;
    global $dbcon;
    //------------------------------------------------------router changed
    $sql = "update router set proirety='" . $proirety . "' where id = '" . $routerid . "'";
    $result = mysql_query($sql);
    if (!$result) {
        return rpcreturn(500, mysql_error(), 100, null);
    }
    return rpcreturn(200, null, null, null, null);
}
Example #4
0
function hardware_chandahdi_signalling_set($type, $signalling)
{
    global $freeiris_conf;
    $changetype = null;
    if ($type == 'pri') {
        $changetype = 3;
    } else {
        return rpcreturn(200, null, null, null, true);
    }
    #--------------------------------------------开始修改参数
    $filebody = file_get_contents($freeiris_conf->get('general', 'asterisketc') . '/chan_dahdi.conf');
    $chan_dahdi = fopen($freeiris_conf->get('general', 'asterisketc') . '/chan_dahdi.conf', 'w');
    if ($chan_dahdi) {
        $signalling_reshow = 0;
        foreach (preg_split("/\n/", $filebody) as $line) {
            trim($line);
            if ($line == '') {
                continue;
            }
            if (preg_match("/^signalling/", $line)) {
                $signalling_reshow++;
                if ($signalling_reshow == $changetype) {
                    fwrite($chan_dahdi, "signalling=" . $signalling . "\n");
                    continue;
                } else {
                    fwrite($chan_dahdi, $line . "\n");
                    continue;
                }
            } else {
                fwrite($chan_dahdi, $line . "\n");
                continue;
            }
        }
        fclose($chan_dahdi);
    }
    return rpcreturn(200, null, null, null, true);
}
Example #5
0
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);
}
Example #6
0
function base_clientlogin($adminid, $passwd)
{
    global $freeiris_conf;
    global $dbcon;
    //判断用户帐户
    $result = mysql_query("select * from admin where adminid = '{$adminid}' and passwd = '{$passwd}'", $dbcon);
    if (!$result) {
        return rpcreturn(500, mysql_error(), 100, null);
    }
    $queryres = mysql_fetch_array($result);
    mysql_free_result($result);
    //如果不存在
    if (!$queryres) {
        return rpcreturn(401, 'authorization failed', 102, null);
    } else {
        //为这个远程呼叫产生session
        session_start();
        $_SESSION["client_authorized"] = true;
        return rpcreturn(200, null, null, array('res_admin' => $queryres));
    }
    return $result;
}
Example #7
0
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']));
}
Example #8
0
function outgoing_delete($id)
{
    return rpcreturn(500, 'function outgoing_delete was deprecated and removed!', 109, null);
    /*
    	global $freeiris_conf;
    	global $dbcon;
    
    	//------------------------------------------------------删除
    	$result=mysql_query("delete from outgoing where id = '".$id."'");
    	if (!$result)
    		return(rpcreturn(500,mysql_error(),100,null));
    
    	return(rpcreturn(200,null,null,null,null));
    */
}
Example #9
0
function extengroup_edit($groupid, $putdata)
{
    global $freeiris_conf;
    global $dbcon;
    //执行
    if (count($putdata) > 0) {
        //生成数据结构
        foreach ($putdata as $key => $value) {
            $sqlstruct = $sqlstruct . ',' . $key . "='" . $value . "'";
        }
        $sqlstruct = trim($sqlstruct, ',');
        $sql = $sqlstruct;
        if (!mysql_query("update extengroup set {$sql} where groupid = '{$groupid}'", $dbcon)) {
            return rpcreturn(500, mysql_error(), 100, null);
        }
        mysql_free_result($result);
    }
    return rpcreturn(200, null, null, null);
}
Example #10
0
function trunk_delete_fxo($trunkid)
{
    global $freeiris_conf;
    global $dbcon;
    //------------------------------------------------------先取出来找到真正的trunkdevice
    $result = mysql_query("select * from trunk where id = '" . $trunkid . "'");
    if (!$result) {
        return rpcreturn(500, mysql_error(), 100, null);
    }
    $trunkres = mysql_fetch_array($result);
    mysql_free_result($result);
    //------------------------------------------------------删除localnumber表记录
    $result = mysql_query("delete from localnumber where assign = '" . $trunkid . "' and number = '" . $trunkres['trunkdevice'] . "'");
    if (!$result) {
        return rpcreturn(500, mysql_error(), 100, null);
    }
    //------------------------------------------------------删除基本数据
    $dores = mysql_query("delete from trunk where id = '" . $trunkid . "'");
    if (!$dores) {
        return rpcreturn(500, mysql_error(), 100, null);
    }
    //------------------------------------------------------删除配置数据
    $findset = false;
    $filebody = file_get_contents($freeiris_conf->get('general', 'asterisketc') . '/chan_dahdi_fxo.conf');
    $chan_dahdi_fxo = fopen($freeiris_conf->get('general', 'asterisketc') . '/chan_dahdi_fxo.conf', 'w');
    if ($chan_dahdi_fxo) {
        foreach (preg_split("/\n/", $filebody) as $line) {
            $line = trim($line);
            if ($line == '') {
                continue;
            }
            if (preg_match("/^accountcode\\=" . $trunkres['trunkdevice'] . "/", $line)) {
                $findset = true;
                continue;
                //} elseif (preg_match("/^channel\=/",$line) && $findset==true) {
            } elseif (preg_match("/^;friautocreate\\=" . $trunkres['trunkdevice'] . "/", $line) && ($findset = true)) {
                $findset = false;
                continue;
            } elseif ($findset == true) {
                continue;
            } else {
                fwrite($chan_dahdi_fxo, $line . "\n");
                continue;
            }
        }
        fclose($chan_dahdi_fxo);
    }
    return rpcreturn(200, null, null, null, true);
}
Example #11
0
function stat_memory_usage()
{
    $results['ram'] = array('total' => 0, 'free' => 0, 'used' => 0, 'percent' => 0);
    $results['swap'] = array('total' => 0, 'free' => 0, 'used' => 0, 'percent' => 0);
    $results['devswap'] = array();
    $bufr = rfts('/proc/meminfo');
    if ($bufr != "ERROR") {
        $bufe = explode("\n", $bufr);
        foreach ($bufe as $buf) {
            if (preg_match('/^MemTotal:\\s+(.*)\\s*kB/i', $buf, $ar_buf)) {
                $results['ram']['total'] = $ar_buf[1];
            } else {
                if (preg_match('/^MemFree:\\s+(.*)\\s*kB/i', $buf, $ar_buf)) {
                    $results['ram']['free'] = $ar_buf[1];
                } else {
                    if (preg_match('/^Cached:\\s+(.*)\\s*kB/i', $buf, $ar_buf)) {
                        $results['ram']['cached'] = $ar_buf[1];
                    } else {
                        if (preg_match('/^Buffers:\\s+(.*)\\s*kB/i', $buf, $ar_buf)) {
                            $results['ram']['buffers'] = $ar_buf[1];
                        }
                    }
                }
            }
        }
        $results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
        $results['ram']['percent'] = round($results['ram']['used'] * 100 / $results['ram']['total']);
        // values for splitting memory usage这里可以获取更多的信息,但目前不需要
        //if (isset($results['ram']['cached']) && isset($results['ram']['buffers'])) {
        //  $results['ram']['app'] = $results['ram']['used'] - $results['ram']['cached'] - $results['ram']['buffers'];
        //  $results['ram']['app_percent'] = round(($results['ram']['app'] * 100) / $results['ram']['total']);
        //  $results['ram']['buffers_percent'] = round(($results['ram']['buffers'] * 100) / $results['ram']['total']);
        //  $results['ram']['cached_percent'] = round(($results['ram']['cached'] * 100) / $results['ram']['total']);
        //}
    }
    return rpcreturn(200, null, null, array('percent' => $results['ram']['percent'], 'total' => $results['ram']['total'], 'free' => $results['ram']['free'], 'cached' => $results['ram']['cached'], 'buffers' => $results['ram']['buffers'], 'used' => $results['ram']['used']));
}