\"\']+)\s*$/",$line,$matches)) {
$conf[ $matches[1] ] = $matches[2];
}
}
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 range
function 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 user
function 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;
$dir = opendir($amp_conf['AMPWEBROOT'].'/admin/modules');
$data = "
"; print_r($xmlarray); echo ""; 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,$type) { $modules = find_allmodules(); //$return_modules = $modules; // add only modules of type=$status foreach(array_keys($modules) as $key) { //remove modules not matching status or type if(isset($modules[$key]['status']) && $modules[$key]['status'] == $status && isset($modules[$key]['type']) && $modules[$key]['type'] == $type) { $return_modules[$key] = $modules[$key]; } } return $return_modules; } // This returns the version of a module function 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 already function sql_formattext($txt) { if (isset($txt)) { $fmt = str_replace("'", "''", $txt); $fmt = "'" . $fmt . "'"; } else { $fmt = 'null'; } return $fmt; } //tell application we need to reload asterisk function needreload() { global $db; $sql = "UPDATE admin SET value = 'true' WHERE variable = 'need_reload'"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getMessage()); } } //get the version number function getversion() { global $db; $sql = "SELECT value FROM admin WHERE variable = 'version'"; $results = $db->getAll($sql); if(DB::IsError($results)) { die($results->getMessage()); } return $results; } // draw list for users and devices with paging function drawListMenu($results, $skip, $dispnum, $extdisplay, $description) { $perpage=20; $skipped = 0; $index = 0; if ($skip == "") $skip = 0; echo "
"; // make sure we have something as a comment if (!isset($matches[4])) { $matches[4] = ""; } if ($matches[3][0] == "/") { // absolute path $include_filename = $matches[3]; } else { // relative path $include_filename = dirname($filename)."/".$matches[3]; } $output[] = $matches[1]."#include".$matches[2].$matches[3].$matches[4]; write_voicemailconf($include_filename, $vmconf, $section, $iteration+1); //DEBUG echo ""; } else if (preg_match("/^(\s*)\[(.+)\](\s*[;#].*)?$/",$line,$matches)) { // section name //DEBUG echo "\nsection"; // make sure we have something as a comment if (!isset($matches[3])) { $matches[3] = ""; } // check if this is the first run (section is null) if ($section !== null) { // we need to add any new entries here, before the section changes //DEBUG echo "
"; //DEBUG var_dump($vmconf[$section]); if (isset($vmconf[$section])){ //need this, or we get an error if we unset the last items in this section - should probably automatically remove the section/context from voicemail.conf foreach ($vmconf[$section] as $key=>$value) { if (is_array($value)) { // mailbox line $temp = & $vmconf[$section][ $key ]; $options = array(); foreach ($temp["options"] as $key1=>$value) { $options[] = $key1."=".$value; } $output[] = $temp["mailbox"]." => ".$temp["pwd"].",".$temp["name"].",".$temp["email"].",".$temp["pager"].",". implode("|",$options); // remove this one from $vmconf unset($vmconf[$section][ $key ]); } else { // option line $output[] = $key."=".$vmconf[$section][ $key ]; // remove this one from $vmconf unset($vmconf[$section][ $key ]); } } } //DEBUG echo ""; } $section = strtolower($matches[2]); $output[] = $matches[1]."[".$section."]".$matches[3]; $existing_sections[] = $section; //remember that this section exists } else if (preg_match("/^(\s*)([a-zA-Z0-9-_]+)(\s*)=(\s*)(.*?)(\s*[;#].*)?$/",$line,$matches)) { // name = value // option line //DEBUG echo "\noption line"; // make sure we have something as a comment if (!isset($matches[6])) { $matches[6] = ""; } if (isset($vmconf[$section][ $matches[2] ])) { $output[] = $matches[1].$matches[2].$matches[3]."=".$matches[4].$vmconf[$section][ $matches[2] ].$matches[6]; // remove this one from $vmconf unset($vmconf[$section][ $matches[2] ]); } // else it's been deleted, so we don't write it in } else { // unknown other line -- probably a comment or whitespace //DEBUG echo "\nother: ".$line; $output[] = str_replace(array("\n","\r"),"",$line); // str_replace so we don't double-space } } if ($iteration == 0) { // we need to add any new entries here, since it's the end of the file //DEBUG echo "END OF FILE!!
"; //DEBUG var_dump($vmconf); foreach (array_keys($vmconf) as $section) { if (!in_array($section,$existing_sections)) // If this is a new section, write the context label $output[] = "[".$section."]"; foreach ($vmconf[$section] as $key=>$value) { if (is_array($value)) { // mailbox line $temp = & $vmconf[$section][ $key ]; $options = array(); foreach ($temp["options"] as $key=>$value) { $options[] = $key."=".$value; } $output[] = $temp["mailbox"]." => ".$temp["pwd"].",".$temp["name"].",".$temp["email"].",".$temp["pager"].",". implode("|",$options); // remove this one from $vmconf unset($vmconf[$section][ $key ]); } else { // option line $output[] = $key."=".$vmconf[$section][ $key ]; // remove this one from $vmconf unset($vmconf[$section][$key ]); } } } //DEBUG echo ""; } fclose($fd); //DEBUG echo "\n\nwriting ".$filename; //DEBUG echo "\n-----------\n"; //DEBUG echo implode("\n",$output); //DEBUG echo "\n-----------\n"; // write this file back out if ($fd = fopen($filename, "w")) { fwrite($fd, implode("\n",$output)."\n"); fclose($fd); } } } function saveVoicemail($vmconf) { // yes, this is hardcoded.. is this a bad thing? write_voicemailconf("/etc/asterisk/voicemail.conf", $vmconf, $section); } // $goto is the current goto destination setting // $i is the destination set number (used when drawing multiple destination sets in a single form ie: digital receptionist) // esnure that any form that includes this calls the setDestinations() javascript function on submit. // ie: if the form name is "edit", and drawselects has been called with $i=2 then use onsubmit="setDestinations(edit,2)" function drawselects($goto,$i) { /* --- MODULES BEGIN --- */ global $active_modules; // This is purely to remove a warning. if (!isset($selectHtml)) { $selectHtml=''; } $selectHtml .= '
"; print_r($arrOutput); echo ""; // ignore the regular xml garbage ([0]['children']) & loop through each module if(!is_array($arrOutput[0]['children'])) return false; foreach($arrOutput[0]['children'] as $module) { if(!is_array($module['children'])) return false; // loop through each modules's tags foreach($module['children'] as $modTags) { if(isset($modTags['children']) && is_array($modTags['children'])) { $$modTags['name'] = $modTags['children']; // loop if there are children (menuitems and requirements) foreach($modTags['children'] as $subTag) { $subTags[strtolower($subTag['name'])] = $subTag['tagData']; } $$modTags['name'] = $subTags; unset($subTags); } else { // create a variable for each tag we find $$modTags['name'] = $modTags['tagData']; } } // now build our return array $arrModules[$RAWNAME]['rawname'] = $RAWNAME; // This has to be set $arrModules[$RAWNAME]['displayName'] = $NAME; // This has to be set $arrModules[$RAWNAME]['version'] = $VERSION; // This has to be set $arrModules[$RAWNAME]['type'] = isset($TYPE)?$TYPE:'setup'; $arrModules[$RAWNAME]['category'] = isset($CATEGORY)?$CATEGORY:'Unknown'; $arrModules[$RAWNAME]['info'] = isset($INFO)?$INFO:'http://www.freepbx.org/wiki/'.$RAWNAME; $arrModules[$RAWNAME]['location'] = isset($LOCATION)?$LOCATION:'local'; $arrModules[$RAWNAME]['items'] = isset($MENUITEMS)?$MENUITEMS:null; $arrModules[$RAWNAME]['requirements'] = isset($REQUIREMENTS)?$REQUIREMENTS:null; $arrModules[$RAWNAME]['md5sum'] = isset($MD5SUM)?$MD5SUM:null; //print_r($arrModules); //unset our variables unset($NAME); unset($VERSION); unset($TYPE); unset($CATEGORY); unset($AUTHOR); unset($EMAIL); unset($LOCATION); unset($MENUITEMS); unset($REQUIREMENTS); unset($MD5SUM); } //echo "
"; print_r($arrModules); echo ""; return $arrModules; } } class moduleHook { var $hookHtml = ''; var $arrHooks = array(); function install_hooks($viewing_itemid,$target_module,$target_menuid = '') { global $active_modules; // loop through all active modules foreach($active_modules as $this_module) { // look for requested hooks for $module // ie: findme_hook_extensions() $funct = $this_module['rawname'] . '_hook_' . $target_module; if( function_exists( $funct ) ) { // execute the function, appending the // html output to that of other hooking modules if ($hookReturn = $funct($viewing_itemid,$target_menuid)) $this->hookHtml .= $hookReturn; // remember who installed hooks // we need to know this for processing form vars $this->arrHooks[] = $this_module['rawname']; } } } // process the request from the module we hooked function process_hooks($viewing_itemid, $target_module, $target_menuid, $request) { if(is_array($this->arrHooks)) { foreach($this->arrHooks as $hookingMod) { // check if there is a processing function $funct = $hookingMod . '_hookProcess_' . $target_module; if( function_exists( $funct ) ) { $funct($viewing_itemid, $request); } } } } } /* // just for testing hooks, i'll delete it later function queues_hook_core($viewing_itemid, $target_menuid) { switch ($target_menuid) { case 'did': //get the current setting for this display (if any) $alertinfo = $viewing_itemid; return '