} } else { $from_file[] = ''; } $connections = $connections + $from_file; /*?><pre>connections:<?print_r($connections);?></pre><?*/ echo json_encode($connections); // $smarty->assign('data', $connections); // $smarty->display('operator-json2d.tpl'); } //запрос текущих каналов, состояния агента, и всего прочего, что делается периодически //для уменьшения количества запросов к web серверу //возвращает данные в трехмерном JSON массиве if ($_REQUEST['query'] == 'currentstate') { if ($asterisk_version == '1.4') { $tmp = $ami->Command("show channels concise"); $sBridgeCall = "Bridged Call"; $cDialplanSeparator = '|'; $iSecondLegIndex = 11; $iDurationIndex = 10; } else { $tmp = $ami->Command("core show channels concise"); $sBridgeCall = "AppDial"; $cDialplanSeparator = ','; $iSecondLegIndex = 12; $iDurationIndex = 11; } $databaseUser = $ami->database_show('AMPUSER'); $databaseCall = $ami->database_show('CURRCALL'); //найдем нашего агента и вернем данные только по нему //все взаимодействие через переменную сессий $AgentAccount
function Reload_Asterisk_SIP_IAX($security_key) { if (!$this->Check_SecurityKey ($security_key)) { return array("ERROR", "INVALID KEY"); } include (dirname(__FILE__)."/phpagi/phpagi-asmanager.php"); $as = new AGI_AsteriskManager(); $res = $as->connect(MANAGER_HOST, MANAGER_USERNAME, MANAGER_SECRET); if ($res) { $res_sip = $as->Command('sip reload'); $res_iax = $as->Command('iax2 reload'); $as->disconnect(); } else { return array(false, "Cannot connect to the Asterisk Manager !"); } return array (true, 'Asterisk SIP / IAX config reloaded SUCCESS'); }
include '../lib/agent.smarty.php'; $FG_DEBUG = 0; getpost_ifset(array('action', 'atmenu')); if (!has_rights(ACX_CUSTOMER)) { Header("HTTP/1.0 401 Unauthorized"); Header("Location: PP_error.php?c=accessdenied"); die; } $DBHandle = DbConnect(); if ($action == "reload") { $as = new AGI_AsteriskManager(); // && CONNECTING connect($server=NULL, $username=NULL, $secret=NULL) $res = $as->connect(MANAGER_HOST, MANAGER_USERNAME, MANAGER_SECRET); if ($res) { if ($atmenu == "sipfriend") { $res = $as->Command('sip reload'); } else { $res = $as->Command('iax2 reload'); } $actiondone = 1; // && DISCONNECTING $as->disconnect(); } else { $error_msg = "</br><center><b><font color=red>" . gettext("Cannot connect to the asterisk manager!<br>Please check your manager configuration.") . "</font></b></center>"; } } else { if ($atmenu == "sipfriend") { $TABLE_BUDDY = 'cc_sip_buddies'; $buddyfile = BUDDY_SIP_FILE; $_SESSION["is_sip_changed"] = 0; if ($_SESSION["is_iax_changed"] == 0) {
function Aastra_get_user_hint_asterisk($user) { # Retrieve real user $user = Aastra_get_userdevice_Asterisk($user); # Initial status $status = ''; # Connect to AGI $as = new AGI_AsteriskManager(); $res = $as->connect(); # SIP show peer if (Aastra_compare_version_Asterisk('1.6')) { $res = $as->Command('core show hint ' . $user); } else { $res = $as->Command('core show hints'); } # Disconnect properly $as->disconnect(); # Process answer $line = split("\n", $res['data']); foreach ($line as $parameter) { if (Aastra_compare_version_Asterisk('1.6')) { $test = strstr($parameter, 'ext-local'); } else { $test = strstr($parameter, 'ext-local') && strstr($parameter, $user); } if ($test) { $status = preg_split('/ /', $parameter, NULL, PREG_SPLIT_NO_EMPTY); $extension = split('@', $status[0]); if ($extension[0] == $user) { $state = split(':', $status[3]); $status = $state[1]; break; } } } # Return answer return $status; }
/** * Function create_sipiax_friends_reload * @public */ static public function create_sipiax_friends_reload() { $FormHandler = FormHandler::GetInstance(); self :: create_sipiax_friends(); // RELOAD SIP & IAX CONF require_once (dirname(__FILE__)."/../phpagi/phpagi-asmanager.php"); $as = new AGI_AsteriskManager(); // && CONNECTING connect($server=NULL, $username=NULL, $secret=NULL) $res =@ $as->connect(MANAGER_HOST,MANAGER_USERNAME,MANAGER_SECRET); if ($res) { $res = $as->Command('sip reload'); $res = $as->Command('iax2 reload'); // && DISCONNECTING $as->disconnect(); } else { echo "Error : Manager Connection"; } }
$access_result = true; if ($access_result) { // re-read configuration /*@system($conf->_OC_reset_cmd, $result); if ($result == 0) { echo "<br>Reset succeded.<br>"; } else { echo "<br>Reset failed.<br>"; }*/ $as = new AGI_AsteriskManager(); $res = $as->connect(MANAGER_HOST, MANAGER_USERNAME, MANAGER_SECRET); if ($res) { $res = $as->Command('reload'); } if ($res) { echo "<br>Reset succeded.<br>"; } else { echo "<br>Reset failed.<br>"; } $as->disconnect(); } } else { $page->OC_HTML_doHtmlHeader_a2billing($smarty); if (isset($_GET['dir'])) { $conf->OC_setConfDir($_GET['dir'], $conf_directories); } $_SESSION['confdir'] = $conf->_OC_conf_dir; // grab and display conf files for current directory
function reload_userdata($host, $uname, $password, $issip, &$err_msg) { global $FG_DEBUG; $as = new AGI_AsteriskManager(); // && CONNECTING connect($server=NULL, $username=NULL, $secret=NULL) $res = $as->connect($host, $uname, $password); if (!$res) { $err_msg .= str_params(_("<p><font color=red>Cannot connect to asterisk manager @%1<br>Please check manager configuration...</font></p>"), array($host), 1); return false; } if ($issip) { $res = $as->Command('sip reload'); } else { $res = $as->Command('iax2 reload'); } if ($res) { $err_msg .= str_params(_("<p><font color=green>The %2 file at %1 has been reload</font></p>"), array($host, $issip ? 'sip' : 'iax')); } return $res; }
if (!$DBHandle) { echo "Error Database connection!"; exit(); } echo "Max number of account to call : $max_call_account \n\n"; $as = new AGI_AsteriskManager(); $res = $as->connect(MANAGER_HOST, MANAGER_USERNAME, MANAGER_SECRET); if ($res) { $account_sip = array(); $res = $as->Command('sip show peers'); $res_splitted = preg_split("/\n/", $res['data']); $fl_array = preg_grep("/OK \(/", $res_splitted); //print_r ($fl_array); foreach ($fl_array as $inst_fl) { preg_match('/(?P<digit>\d+)/', $inst_fl, $matches); if (strlen($matches[0]) > 1) { $account_sip[] = $matches[0]; } } if (count($account_sip) > 0) { implode(",", $array); $comma_separated = '\''.implode("' , '", $account_sip).'\'';
function AsteriskManager_Command($host, $user, $password, $command) { global $arrLang; $astman = new AGI_AsteriskManager(); if (!$astman->connect("{$host}", "{$user}", "{$password}")) { $this->errMsg = $arrLang["Error when connecting to Asterisk Manager"]; } else { $salida = $astman->Command("{$command}"); $astman->disconnect(); if (strtoupper($salida["Response"]) != "ERROR") { return explode("\n", $salida["data"]); } } return false; }
/** * Procedimiento para listar todos los grupos de troncales DAHDI que han sido * definidos. Este procedimiento requiere que Asterisk esté en ejecución en el * sistema y que soporte el comando "dahdi show channels group N". * * @return mixed Arreglo de la siguiente forma: * array(0 => array("DAHDI/1", "DAHDI/2", "DAHDI/3"), 1 => array("DAHDI/4", "DAHDI/5", "DAHDI/6")) */ function getTrunkGroupsDAHDI() { require_once '/var/lib/asterisk/agi-bin/phpagi-asmanager.php'; require_once 'libs/paloSantoConfig.class.php'; // Obtener las credenciales y abrir la conexión Asterisk $pConfig = new paloConfig("/etc", "amportal.conf", "=", "[[:space:]]*=[[:space:]]*"); $arrConfig = $pConfig->leer_configuracion(false); $astman = new AGI_AsteriskManager(); if (!$astman->connect('localhost', $arrConfig['AMPMGRUSER']['valor'], $arrConfig['AMPMGRPASS']['valor'])) { // No se puede conectar a AMI, se intenta parsear configuración return $grupos = getTrunkGroupsDAHDI_config(); } else { /* Chan Extension Context Language MOH Interpret Blocked State 1 from-pstn default In Service 2 from-pstn default In Service 3 from-pstn default In Service 4 from-pstn default In Service */ // Se conoce que los números de grupo van de 0 a 63 $grupos = array(); $bSoportado = TRUE; // Se asume que el comando soporta listar por grupos for ($iGrupo = 0; $iGrupo < 64 && $bSoportado; $iGrupo++) { $r = $astman->Command("dahdi show channels group {$iGrupo}"); if (isset($r['data'])) { $lineas = explode("\n", $r['data']); foreach ($lineas as $sLinea) { /* Si una línea empieza con Usage, entonces la versión de Asterisk no soporta la extensión "group N" del comando "dahdi show channels" */ if (strpos($sLinea, 'Usage') === 0) { $bSoportado = FALSE; break; } if (preg_match('/^\\s+(\\d+)/', $sLinea, $regs)) { $grupos[$iGrupo][] = 'DAHDI/' . $regs[1]; } } } } $astman->disconnect(); if (!$bSoportado) { // Comando AMI no soportado, se intenta parsear configuración $grupos = getTrunkGroupsDAHDI_config(); } return $grupos; } }