📄 functions.inc.php
字号:
<?php /* $id$ *///Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)////This program is free software; you can redistribute it and/or//modify it under the terms of the GNU General Public License//as published by the Free Software Foundation; either version 2//of the License, or (at your option) any later version.////This program is distributed in the hope that it will be useful,//but WITHOUT ANY WARRANTY; without even the implied warranty of//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the//GNU General Public License for more details.require_once('featurecodes.class.php');function parse_amportal_conf($filename) { $file = file($filename); if (is_array($file)) { foreach ($file as $line) { if (preg_match("/^\s*([a-zA-Z0-9]+)=([a-zA-Z0-9 .&-@=_<>\"\']+)\s*$/",$line,$matches)) { $conf[ $matches[1] ] = $matches[2]; } } } else { die("<h1>Missing or unreadable config file ($filename)...cannot continue</h1>"); } if ( !isset($conf["AMPDBENGINE"]) || ($conf["AMPDBENGINE"] == "")) { $conf["AMPDBENGINE"] = "mysql"; }/* if (($amp_conf["AMPDBENGINE"] == "sqlite") && (!isset($amp_conf["AMPDBENGINE"]))) $amp_conf["AMPDBFILE"] = "/var/lib/freepbx/freepbx.sqlite";*/ return $conf;}function parse_asterisk_conf($filename) { $file = file($filename); foreach ($file as $line) { if (preg_match("/^\s*([a-zA-Z0-9]+)\s* => \s*(.*)\s*([;#].*)?/",$line,$matches)) { $conf[ $matches[1] ] = $matches[2]; } } return $conf;}function getAmpAdminUsers() { global $db; $sql = "SELECT username FROM ampusers WHERE sections='*'"; $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } return $results;}function getAmpUser($username) { global $db; $sql = "SELECT username, password, extension_low, extension_high, deptname, sections FROM ampusers WHERE username = '".$username."'"; $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } if (count($results) > 0) { $user = array(); $user["username"] = $results[0][0]; $user["password"] = $results[0][1]; $user["extension_low"] = $results[0][2]; $user["extension_high"] = $results[0][3]; $user["deptname"] = $results[0][4]; $user["sections"] = explode(";",$results[0][5]); return $user; } else { return false; }}class ampuser { var $username; var $_password; var $_extension_high; var $_extension_low; var $_deptname; var $_sections; function ampuser($username) { $this->username = $username; if ($user = getAmpUser($username)) { $this->_password = $user["password"]; $this->_extension_high = $user["extension_high"]; $this->_extension_low = $user["extension_low"]; $this->_deptname = $user["deptname"]; $this->_sections = $user["sections"]; } else { // user doesn't exist $this->_password = false; $this->_extension_high = ""; $this->_extension_low = ""; $this->_deptname = ""; $this->_sections = array(); } } /** Give this user full admin access */ function setAdmin() { $this->_extension_high = ""; $this->_extension_low = ""; $this->_deptname = ""; $this->_sections = array("*"); } function checkPassword($password) { // strict checking so false will never match return ($this->_password === $password); } function checkSection($section) { // if they have * then it means all sections return in_array("*", $this->_sections) || in_array($section, $this->_sections); }}// returns true if extension is within allowed rangefunction checkRange($extension){ $low = isset($_SESSION["AMP_user"]->_extension_low)?$_SESSION["AMP_user"]->_extension_low:''; $high = isset($_SESSION["AMP_user"]->_extension_high)?$_SESSION["AMP_user"]->_extension_high:''; if ((($extension >= $low) && ($extension <= $high)) || ($low == '' && $high == '')) return true; else return false;}// returns true if department string matches dept for this userfunction checkDept($dept){ $deptname = isset($_SESSION["AMP_user"])?$_SESSION["AMP_user"]:null; if ( ($dept == null) || ($dept == $deptname) ) return true; else return false;}/* look for all modules in modules dir.** returns array:** array['module']['displayName']** array['module']['version']** array['module']['type']** array['module']['status']** array['module']['items'][array(items)]** Use find_modules() to return only specific type or status*//*function find_allmodules() { global $db; global $amp_conf; $dir = opendir($amp_conf['AMPWEBROOT'].'/admin/modules'); //loop through each module directory, ensure there is a module.ini file while ($file = readdir($dir)) { if (($file != ".") && ($file != "..") && ($file != "CVS") && ($file != ".svn") && is_dir($amp_conf['AMPWEBROOT'].'/admin/modules/'.$file) && is_file($amp_conf['AMPWEBROOT'].'/admin/modules/'.$file.'/module.ini')) { //open module.ini and read contents $inifile = file($amp_conf['AMPWEBROOT'].'/admin/modules/'.$file.'/module.ini'); foreach ($inifile as $line) { // parse the module display name and version from module.ini if (preg_match("/^\s*([a-zA-Z0-9]+)=([a-zA-Z0-9 .&-@=_<>\"\']+)\s*$/",$line,$matches)) { if (trim($matches[1]) == "name") $mod[ $file ]['displayName'] = $matches[2]; else if (trim($matches[1]) == "version") $mod[ $file ]['version'] = $matches[2]; else if (trim($matches[1]) == "type") $mod[ $file ]['type'] = $matches[2]; else if (trim($matches[1]) == "category") $mod[ $file ]['category'] = $matches[2]; else $mod[ $file ]['items'][ $matches[1] ] = $matches[2]; } // determine details about this module from database // modulename should match the directory name $sql = "SELECT * FROM modules WHERE modulename = '".$file."'"; $results = $db->getRow($sql,DB_FETCHMODE_ASSOC); if(DB::IsError($results)) { die($results->getMessage()); } //set status key based on results (0=not installed, 1=disabled, 2=enabled) if ($results) { if ($results['enabled'] != 0) $mod[ $file ]["status"] = 2; else $mod[ $file ]["status"] = 1; } else { $mod[ $file ]["status"] = 0; } } } } return $mod;} *//* look for all modules in modules dir.** returns array:** array['module']['displayName']** array['module']['version']** array['module']['type']** array['module']['status']** array['module']['items'][array(items)]** Use find_modules() to return only specific type or status*/function find_allmodules() { global $db; global $amp_conf; if (!is_dir($amp_conf['AMPWEBROOT'].'/admin/modules')) { mkdir( $amp_conf['AMPWEBROOT'].'/admin/modules' ); return; } $dir = opendir($amp_conf['AMPWEBROOT'].'/admin/modules'); $data = "<xml>"; //loop through each module directory, ensure there is a module.ini file while ($file = readdir($dir)) { if (($file != ".") && ($file != "..") && ($file != "CVS") && ($file != ".svn") && is_dir($amp_conf['AMPWEBROOT'].'/admin/modules/'.$file) && is_file($amp_conf['AMPWEBROOT'].'/admin/modules/'.$file.'/module.xml')) { //open module.xml and read contents if(is_file($amp_conf['AMPWEBROOT'].'/admin/modules/'.$file.'/module.xml')){ $data .=file_get_contents($amp_conf['AMPWEBROOT'].'/admin/modules/'.$file.'/module.xml'); } } } $data .= "</xml>"; $parser = new xml2ModuleArray($data); $xmlarray = $parser->parseModulesXML($data); // determine details about this module from database // modulename should match the directory name $sql = "SELECT * FROM modules"; $results = $db->getAll($sql,DB_FETCHMODE_ASSOC); if(DB::IsError($results)) { die($results->getMessage()); } if (is_array($results)) { foreach($results as $result) { /* set status key based on results -1=broken (in table, not not on filesystem) 0 or null=not installed 1=disabled 2=enabled 3=enabled and needs upgrade */ if(isset($xmlarray[ $result['modulename'] ] ) && is_array($xmlarray[ $result['modulename'] ])) { if ($result['enabled'] != 0) { // check if file and registered versions are the same // version_compare returns 0 if no difference if (version_compare($result['version'],$xmlarray[ $result['modulename'] ]["version"]) === 0) $xmlarray[ $result['modulename'] ]["status"] = 2; else $xmlarray[ $result['modulename'] ]["status"] = 3; } else { $xmlarray[ $result['modulename'] ]["status"] = 1; } } else { $xmlarray[ $result['modulename'] ]["status"] = -1; } } } //echo "<pre>"; print_r($xmlarray); echo "</pre>"; return $xmlarray;}/* finds modules of the specified status and type** $status can be 0 (not installed), 1 (disabled), 2 (enabled)** $type can be 'setup' or 'tool'**** returns array:** array['module']['displayName']** array['module']['version']** array['module']['type']** array['module']['status']** array['module']['items'][array(items)]*/function find_modules($status) { $modules = find_allmodules(); if (isset($modules) && is_array($modules)) { foreach(array_keys($modules) as $key) { //remove modules not matching status if(isset($modules[$key]['status']) && $modules[$key]['status'] == $status ){ $return_modules[$key] = $modules[$key]; } } return $return_modules; } else { return false; }}// This returns the version of a modulefunction modules_getversion($modname) { global $db; $sql = "SELECT version FROM modules WHERE modulename = '$modname'"; $results = $db->getRow($sql,DB_FETCHMODE_ASSOC); if (isset($results['version'])) return $results['version']; else return null;}// I bet you can't guess what this one does.function modules_setversion($modname, $vers) { global $db; return sql("UPDATE modules SET version='$vers' WHERE modulename = '$modname'");}/* queries database using PEAR.* $type can be query, getAll, getRow, getCol, getOne, etc* $fetchmode can be DB_FETCHMODE_ORDERED, DB_FETCHMODE_ASSOC, DB_FETCHMODE_OBJECT* returns array, unless using getOne*/function sql($sql,$type="query",$fetchmode=null) { global $db; $results = $db->$type($sql,$fetchmode); if(DB::IsError($results)) { die($results->getDebugInfo()); } return $results;}// sql text formatting -- couldn't see that one was available alreadyfunction sql_formattext($txt) { if (isset($txt)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -