📄 functions.inc.php
字号:
$fmt = str_replace("'", "''", $txt); $fmt = "'" . $fmt . "'"; } else { $fmt = 'null'; } return $fmt;}//tell application we need to reload asteriskfunction 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 numberfunction 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 pagingfunction drawListMenu($results, $skip, $dispnum, $extdisplay, $description) { $perpage=20; $skipped = 0; $index = 0; if ($skip == "") $skip = 0; echo "<li><a id=\"".($extdisplay=='' ? 'current':'')."\" href=\"config.php?display=".$dispnum."\">"._("Add")." ".$description."</a></li>"; if (isset($results)) { foreach ($results AS $key=>$result) { if ($index >= $perpage) { $shownext= 1; break; } if ($skipped<$skip && $skip!= 0) { $skipped= $skipped + 1; continue; } $index= $index + 1; echo "<li><a id=\"".($extdisplay==$result[0] ? 'current':'')."\" href=\"config.php?display=".$dispnum."&extdisplay={$result[0]}&skip={$skip}\">{$result[1]} <{$result[0]}></a></li>"; } } if ($index >= $perpage) { print "<li><center>"; } if ($skip) { $prevskip= $skip - $perpage; if ($prevskip<0) $prevskip= 0; $prevtag_pre= "<a href='?display=".$dispnum."&skip=$prevskip'>[PREVIOUS]</a>"; print "$prevtag_pre"; } if (isset($shownext)) { $nextskip= $skip + $index; if ($prevtag_pre) $prevtag .= " | "; print "$prevtag <a href='?display=".$dispnum."&skip=$nextskip'>[NEXT]</a>"; } elseif ($skip) { print "$prevtag"; } print "</center></li>"; }// this function simply makes a connection to the asterisk manager, and should be called by modules that require it (ie: dbput/dbget)function checkAstMan() { require_once('common/php-asmanager.php'); global $amp_conf; $astman = new AGI_AsteriskManager(); if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) { return $astman->disconnect(); } else { echo "<h3>Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]."</h3>This module requires access to the Asterisk Manager. Please ensure Asterisk is running and access to the manager is available.</div>"; exit; }}/** Recursively read voicemail.conf (and any included files) * This function is called by getVoicemailConf() */function parse_voicemailconf($filename, &$vmconf, &$section) { if (is_null($vmconf)) { $vmconf = array(); } if (is_null($section)) { $section = "general"; } if (file_exists($filename)) { $fd = fopen($filename, "r"); while ($line = fgets($fd, 1024)) { if (preg_match("/^\s*(\d+)\s*=>\s*(\d*),(.*),(.*),(.*),(.*)\s*([;#].*)?/",$line,$matches)) { // "mailbox=>password,name,email,pager,options" // this is a voicemail line $vmconf[$section][ $matches[1] ] = array("mailbox"=>$matches[1], "pwd"=>$matches[2], "name"=>$matches[3], "email"=>$matches[4], "pager"=>$matches[5], "options"=>array(), ); // parse options //output($matches); foreach (explode("|",$matches[6]) as $opt) { $temp = explode("=",$opt); //output($temp); if (isset($temp[1])) { list($key,$value) = $temp; $vmconf[$section][ $matches[1] ]["options"][$key] = $value; } } } else if (preg_match("/^\s*(\d+)\s*=>\s*dup,(.*)\s*([;#].*)?/",$line,$matches)) { // "mailbox=>dup,name" // duplace name line $vmconf[$section][ $matches[1] ]["dups"][] = $matches[2]; } else if (preg_match("/^\s*#include\s+(.*)\s*([;#].*)?/",$line,$matches)) { // include another file if ($matches[1][0] == "/") { // absolute path $filename = $matches[1]; } else { // relative path $filename = dirname($filename)."/".$matches[1]; } parse_voicemailconf($filename, $vmconf, $section); } else if (preg_match("/^\s*\[(.+)\]/",$line,$matches)) { // section name $section = strtolower($matches[1]); } else if (preg_match("/^\s*([a-zA-Z0-9-_]+)\s*=\s*(.*?)\s*([;#].*)?$/",$line,$matches)) { // name = value // option line $vmconf[$section][ $matches[1] ] = $matches[2]; } } fclose($fd); }}function getVoicemail() { $vmconf = null; $section = null; // yes, this is hardcoded.. is this a bad thing? parse_voicemailconf("/etc/asterisk/voicemail.conf", $vmconf, $section); return $vmconf;}/** Write the voicemail.conf file * This is called by saveVoicemail() * It's important to make a copy of $vmconf before passing it. Since this is a recursive function, has to * pass by reference. At the same time, it removes entries as it writes them to the file, so if you don't have * a copy, by the time it's done $vmconf will be empty.*/function write_voicemailconf($filename, &$vmconf, &$section, $iteration = 0) { if ($iteration == 0) { $section = null; } $output = array(); if (file_exists($filename)) { $fd = fopen($filename, "r"); while ($line = fgets($fd, 1024)) { if (preg_match("/^(\s*)(\d+)(\s*)=>(\s*)(\d*),(.*),(.*),(.*),(.*)(\s*[;#].*)?$/",$line,$matches)) { // "mailbox=>password,name,email,pager,options" // this is a voicemail line //DEBUG echo "\nmailbox"; // make sure we have something as a comment if (!isset($matches[10])) { $matches[10] = ""; } // $matches[1] [3] and [4] are to preserve indents/whitespace, we add these back in if (isset($vmconf[$section][ $matches[2] ])) { // we have this one loaded // repopulate from our version $temp = & $vmconf[$section][ $matches[2] ]; $options = array(); foreach ($temp["options"] as $key=>$value) { $options[] = $key."=".$value; } $output[] = $matches[1].$temp["mailbox"].$matches[3]."=>".$matches[4].$temp["pwd"].",".$temp["name"].",".$temp["email"].",".$temp["pager"].",". implode("|",$options).$matches[10]; // remove this one from $vmconf unset($vmconf[$section][ $matches[2] ]); } else { // we don't know about this mailbox, so it must be deleted // (and hopefully not JUST added since we did read_voiceamilconf) // do nothing } } else if (preg_match("/^(\s*)(\d+)(\s*)=>(\s*)dup,(.*)(\s*[;#].*)?$/",$line,$matches)) { // "mailbox=>dup,name" // duplace name line // leave it as-is (for now) //DEBUG echo "\ndup mailbox"; $output[] = $line; } else if (preg_match("/^(\s*)#include(\s+)(.*)(\s*[;#].*)?$/",$line,$matches)) { // include another file //DEBUG echo "\ninclude ".$matches[3]."<blockquote>"; // 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 "</blockquote>"; } 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 "<blockquote><i>"; //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 "</i></blockquote>"; } $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!! <blockquote><i>"; //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 ]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -