예제 #1
0
 /**
  * Método para compactibilidade com código do snep, aqui há uma melhoria
  * nas consultas simples reutilizando socket onde é possível.
  *
  * @param string $comando - Comando a ser executado
  *
  * @param string $quebra - Para retornar somente as linhas que contenham
  * o conteudo dessa variável
  *
  * @param boolean $tudo - Esse parametro não é usado (?!)
  *
  * @return Dados da consulta
  */
 public function status_asterisk($comando, $quebra, $tudo = False)
 {
     if ($comando != "Agents" && $comando != "Status") {
         $cmd = self::$asterisk->command($comando);
         $retorno = $cmd['data'];
         if ($quebra != "") {
             $ret_quebrado = " ";
             foreach (explode("\n", $cmd['data']) as $line) {
                 if (preg_match("/{$quebra}/", $line)) {
                     $ret_quebrado .= $line;
                     break;
                 }
             }
             return $ret_quebrado;
         } else {
             return $cmd['data'];
         }
     } else {
         // Enviando requisição de status
         self::$asterisk->send_request($comando, array());
         // Enviando esse objeto para cuidar dos responses
         self::$asterisk->wait_event($this);
         return $this->return;
     }
 }
예제 #2
0
        echo "0";
    } elseif ($editpin == '') {
        echo "0";
    } else {
        echo "1";
        $fname = explode('<', $callerid);
        $cid = $fname[0];
        $dname = explode('"', $cid);
        $name = $dname[1];
        $sql = "INSERT INTO sip_buddies(name,accountcode,secret,callerid,context,mailbox,nat,host,callgroup,pickupgroup,qualify,allow,videosupport,type,permit,deny,transport,dtmfmode,directmedia,encryption) Values('{$extension}','{$account}','{$secret}','{$callerid}','{$context}','{$mailbox}','{$nat}','{$host}','{$callgroup}','{$pickupgroup}','{$qualify}','{$allow}','{$videosupport}','{$type}','{$permit}','{$deny}','{$transport}','{$dtmfmode}','{$directmedia}','{$encryption}')";
        mysql_query($sql) or die(mysql_error());
        $sql1 = "INSERT INTO claves(clave_nombre,user_edit,user_exten) Values('{$name}','{$editpin}','{$mailbox}')";
        mysql_query($sql1) or die(mysql_error());
        $sql2 = "INSERT INTO voicemail_users(customer_id,context,mailbox,password,fullname,email) Values('{$extension}','default','{$mailbox}','{$extension}','{$name}','{$email}')";
        mysql_query($sql2) or die(mysql_error());
        $file = basename("/etc/asterisk/extensions.conf");
        $text = file_get_contents("/etc/asterisk/extensions.conf");
        $text = str_replace(';;last line extensions', 'exten => ' . ${extension} . ',1,GoSub(subSTDExten,internalcall,1(${EXTEN}))\\r;;last line extensions', $text);
        $text = str_replace(';;last line hints', 'exten => ' . ${extension} . ',hint,SIP/' . ${extension} . '\\r;;last line hints', $text);
        file_put_contents('/etc/asterisk/' . $file, $text);
        $asm = new AGI_AsteriskManager();
        if ($asm->connect('localhost', 'admin', 'managerpwd')) {
            $peer = $asm->command("sip reload");
            sleep(1);
            $peer = $asm->command("dialplan reload");
            sleep(1);
        }
        $asm->disconnect();
        exec("sh /etc/asterisk/rn.sh");
    }
}
예제 #3
0
<?php 
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
    header("Location: ../index.php");
} else {
    require_once '/var/lib/asterisk/agi-bin/phpagi/phpagi-asmanager.php';
    $asm = new AGI_AsteriskManager();
    if ($asm->connect('localhost', 'admin', 'managerpwd')) {
        $peer = $asm->command("iax2 show peers");
        //print_r($peer);
        preg_match('/\\[(.*)/', $peer['data'], $val);
        //print_r($val);
        $online = explode(",", $val[1]);
        $offline = explode(",", $val[1]);
        $offline = explode("Unmonitored", $offline[1]);
        //echo "ONline: ".$online[0];
        //echo "\noffline: ".$offline[0];
    }
    $asm->disconnect();
    $jsondata['regiax'] = $online[0];
    echo json_encode($jsondata);
}
?>


 function deleteExtensions()
 {
     $astman = new AGI_AsteriskManager();
     if (!$astman->connect("127.0.0.1", 'admin', obtenerClaveAMIAdmin())) {
         $this->errMsg = "Error connect AGI_AsteriskManager";
         return FALSE;
     }
     $exito = TRUE;
     $this->_DB->beginTransaction();
     // Lista de extensiones a borrar
     $sql = "SELECT id FROM devices WHERE tech = 'sip' OR tech = 'iax2'";
     $recordset = $this->_DB->fetchTable($sql);
     if (!is_array($recordset)) {
         $this->errMsg = $this->_DB->errMsg;
         $exito = FALSE;
     }
     $extlist = array();
     foreach ($recordset as $tupla) {
         $extlist[] = $tupla[0];
     }
     unset($recordset);
     foreach ($extlist as $ext) {
         // Borrar propiedades en base de datos de Asterisk
         foreach (array('AMPUSER', 'DEVICE', 'CW', 'CF', 'CFB', 'CFU') as $family) {
             $r = $astman->command("database deltree {$family}/{$ext}");
             if (!isset($r['Response'])) {
                 $r['Response'] = '';
             }
             if (strtoupper($r['Response']) == 'ERROR') {
                 $this->errMsg = _tr('Could not delete the ASTERISK database');
                 $exito = FALSE;
                 break;
             }
         }
         if (!$exito) {
             break;
         }
     }
     if ($exito) {
         foreach (array("DELETE s FROM sip s INNER JOIN devices d ON s.id=d.id and d.tech='sip'", "DELETE i FROM iax i INNER JOIN devices d ON i.id=d.id and d.tech='iax2'", "DELETE u FROM users u INNER JOIN devices d ON u.extension=d.id and (d.tech='sip' or d.tech='iax2')", "DELETE FROM devices WHERE tech='sip' or tech='iax2'") as $sql) {
             if (!$this->_DB->genQuery($sql)) {
                 $this->errMsg = $this->_DB->errMsg;
                 $exito = FALSE;
                 break;
             }
         }
     }
     // Aplicar cambios a la base de datos
     if (!$exito) {
         $this->_DB->rollBack();
         return FALSE;
     }
     $this->_DB->commit();
     $exito = $this->_recargarAsterisk($astman);
     $astman->disconnect();
     return $exito;
 }
예제 #5
0
<?php

session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
    header("Location: ../index.php");
} else {
    $app = $_GET['app'];
    require_once '/var/lib/asterisk/agi-bin/phpagi/phpagi-asmanager.php';
    $asm = new AGI_AsteriskManager();
    if ($asm->connect('localhost', 'admin', 'managerpwd')) {
        $peer = $asm->command("core show application " . $app);
        $test = preg_replace("/Privilege: Command/s", '', $peer['data']);
        $test1 = preg_replace("/\\n/s", '<br>', $test);
        $test2 = preg_replace("/\\[/s", '<b>[', $test1);
        $test3 = preg_replace("/\\]/s", ']</b>', $test2);
        echo $test3;
    }
    $asm->disconnect();
}
예제 #6
0
<?php 
require_once '/var/lib/asterisk/agi-bin/phpagi/phpagi-asmanager.php';
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
    header("Location: ../index.php");
} else {
    $asm = new AGI_AsteriskManager();
    if ($asm->connect('localhost', 'admin', 'managerpwd')) {
        $peer = $asm->command("core show channels");
        preg_match('/(.*) active call/', $peer['data'], $res);
        //print_r($res);
        $calls = explode(" ", $res[0]);
    }
    $asm->disconnect();
    $jsondata['calls'] = $calls[0];
    echo json_encode($jsondata);
}
?>


예제 #7
0
            echo "<div style='display:none'>";
        }
        echo "Executing post apply script <b>" . $amp_conf["POST_RELOAD"] . "</b><pre>";
        system($amp_conf["POST_RELOAD"]);
        echo "</pre>";
        if (!isset($amp_conf["POST_RELOAD_DEBUG"]) || $amp_conf["POST_RELOAD_DEBUG"] != "1" && $amp_conf["POST_RELOAD_DEBUG"] != "true") {
            echo "</div><br>";
        }
        echo "\n\t\t\t<script>\n\t\t\t\tfunction hideWaitBanner()\n\t\t\t\t{\n\t\t\t\t\tdocument.getElementById('idWaitBanner').className = 'clsHidden';\n\t\t\t\t}\n\n\t\t\t\tdocument.getElementById('idWaitBanner').innerHTML = 'Configuration applied';\n\t\t\t\tdocument.getElementById('idWaitBanner').className = 'clsWaitFinishOK';\n\t\t\t\tsetTimeout('hideWaitBanner()',3000);\n\t\t\t</script>\n\t\t";
    }
    $amp_conf = parse_amportal_conf("/etc/amportal.conf");
    $hosts = split(',', $amp_conf['MANAGERHOSTS']);
    foreach ($hosts as $host) {
        $astman = new AGI_AsteriskManager();
        if ($res = $astman->connect($host, $amp_conf["AMPMGRUSER"], $amp_conf["AMPMGRPASS"])) {
            $astman->command("reload");
            $astman->disconnect();
        } else {
            echo "<h3>Cannot connect to Asterisk Manager {$host} 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;
        }
    }
    $wOpBounce = rtrim($_SERVER['SCRIPT_FILENAME'], $currentFile) . 'bounce_op.sh';
    exec($wOpBounce . '>/dev/null');
    $sql = "UPDATE admin SET value = 'false' WHERE variable = 'need_reload'";
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die($result->getMessage());
    }
    $need_reload[0] = 'false';
}
예제 #8
0
			<div class="row-fluid">
				<div class="box span12">
					<div class="box-header well">
						<h2><i class="icon-info-sign"></i>System Info</h2>
						<div class="box-icon">
							<!--<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>-->
							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
							<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
						</div>
					</div>
					<div class="box-content">
						<?php 
require_once '/var/lib/asterisk/agi-bin/phpagi/phpagi-asmanager.php';
$asm = new AGI_AsteriskManager();
if ($asm->connect('localhost', 'admin', 'm4nag3rt3ts')) {
    $peer = $asm->command("core show version");
    //print_r($peer);
    $astv = str_replace("Privilege: Command", "", $peer['data']);
} else {
    $astv = "<div class='alert alert-error' align='center'><b>WARNING ASTERISK IS NOT RUNNING</b></div>";
}
$asm->disconnect();
$specs = exec("cat /proc/version");
//$astv=exec("rasterisk | grep -m1 ','");
$os = exec("cat /etc/issue | grep -m1 '('");
echo "<span class='label label-important'>Your server is Running on:</span><h3><small>" . $specs . "</small></h3>\n\t\t\t\t\t\t\t\t<br><span class='label label-important'>Your Operating System is:</span><br><h3><small>" . $os . "</small></h3>\n\t\t\t\t\t\t\t\t<br><span class='label label-important'>And The Asterisk PBX Version is:</span><br><h3><small>" . $astv . "</small></h3>";
?>
						<div class="clearfix"></div>
					</div>
				</div>
			</div>
예제 #9
0
?>
						<div id='appsinfo'></div>
						

                	                </div>

					<div class="tab-pane" id="funcs">
						<p>
							View the Help on the Listed Functions				
						</p>

						<?php 
require_once '/var/lib/asterisk/agi-bin/phpagi/phpagi-asmanager.php';
$asm = new AGI_AsteriskManager();
if ($asm->connect('localhost', 'admin', 'm4nag3rt3ts')) {
    $peer = $asm->command("core show functions");
    $data = array();
    echo "<select id='astfunc' name='astfunc' class='text ui-widget-content ui-corner-all'>";
    foreach (explode("\n", $peer['data']) as $line) {
        $func = explode(" ", $line);
        $astfunc = preg_replace("/\\s/", "", $func[0]);
        echo "<option value='" . $astfunc . "'>" . $func[0] . "</option>";
    }
    echo "</select>";
}
$asm->disconnect();
?>
						<div id='funcinfo'></div>


					</div>
예제 #10
0
    $secret = $_GET['secret'];
    $callerid = $_GET['callerid'];
    $context = $_GET['context'];
    $mailbox = $_GET['mailbox'];
    $nat = $_GET['nat'];
    $host = $_GET['host'];
    $callgroup = $_GET['callgroup'];
    $pickupgroup = $_GET['pickupgroup'];
    $qualify = $_GET['qualify'];
    $allow = $_GET['allow'];
    $videosupport = $_GET['videosupport'];
    $type = $_GET['type'];
    $account = $_GET['account'];
    $editpin = $_GET['editpin'];
    $permit = $_GET['permit'];
    $deny = $_GET['deny'];
    $transport = $_GET['transport'];
    $dtmfmode = $_GET['dtmfmode'];
    $directmedia = $_GET['directmedia'];
    $encryption = $_GET['encryption'];
    $sql = "UPDATE sip_buddies SET name='{$extension}', accountcode='{$account}', secret='{$secret}', callerid='{$callerid}', context='{$context}', mailbox='{$mailbox}', nat='{$nat}', host='{$host}', callgroup='{$callgroup}', pickupgroup='{$pickupgroup}', qualify='{$qualify}', allow='{$allow}', videosupport='{$videosupport}', type='{$type}', permit='{$permit}',deny='{$deny}',transport='{$transport}',dtmfmode='{$dtmfmode}',directmedia='{$directmedia}',encryption='{$encryption}' WHERE id='{$id}'";
    mysql_query($sql) or die(mysql_error());
    $sql1 = "UPDATE claves set user_edit='{$editpin}' where user_exten='{$extension}'";
    mysql_query($sql1) or die(mysql_error());
    $asm = new AGI_AsteriskManager();
    if ($asm->connect('localhost', 'admin', 'managerpwd')) {
        $peer = $asm->command("sip reload");
        sleep(1);
    }
    $asm->disconnect();
}
예제 #11
0
<?php

session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
    header("Location: ../index.php");
} else {
    $func = $_GET['func'];
    require_once '/var/lib/asterisk/agi-bin/phpagi/phpagi-asmanager.php';
    $asm = new AGI_AsteriskManager();
    if ($asm->connect('localhost', 'admin', 'managerpwd')) {
        $peer = $asm->command("core show function " . $func);
        $test = preg_replace("/Privilege: Command/s", '', $peer['data']);
        $test1 = preg_replace("/\\n/s", '<br>', $test);
        $test2 = preg_replace("/\\[/s", '<b>[', $test1);
        $test3 = preg_replace("/\\]/s", ']</b>', $test2);
        echo $test3;
    }
    $asm->disconnect();
}
예제 #12
0
 function AMI_Command($command)
 {
     $astman = new AGI_AsteriskManager();
     $return = false;
     if (!$astman->connect("127.0.0.1", 'admin', obtenerClaveAMIAdmin())) {
         $this->errMsg = "Error connect AGI_AsteriskManager";
         $return = false;
     } else {
         $r = $astman->command($command);
         $return = $r["data"];
         $astman->disconnect();
     }
     return $return;
 }
예제 #13
0
<?php

session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
    header("Location: ../index.php");
} else {
    include '../include/loginsql.php';
    require_once '/var/lib/asterisk/agi-bin/phpagi/phpagi-asmanager.php';
    $id = $_GET['id'];
    $sql0 = "Select name from sip_buddies Where id='{$id}'";
    $res = mysql_query($sql0) or die(mysql_error());
    $row = mysql_fetch_assoc($res);
    $name = $row['name'];
    $sql1 = "Delete from sip_buddies where id={$id}";
    mysql_query($sql1) or die(mysql_error());
    $sql2 = "Delete from voicemail_users where customer_id={$name}";
    mysql_query($sql2) or die(mysql_error());
    $file = basename("/etc/asterisk/extensions.conf");
    $text = file_get_contents("/etc/asterisk/extensions.conf");
    $text = str_replace('exten => ' . ${name} . ',1,GoSub(subSTDExten,internalcall,1(${EXTEN}))', '', $text);
    $text = str_replace('exten => ' . ${name} . ',hint,SIP/' . ${name} . '', '', $text);
    file_put_contents('/etc/asterisk/' . $file, $text);
    $asm = new AGI_AsteriskManager();
    if ($asm->connect('localhost', 'admin', 'managerpwd')) {
        $dp = $asm->command("dialplan reload");
        sleep(1);
    }
    $asm->disconnect();
}
예제 #14
0
 function processCallWaiting($callwaiting, $extension)
 {
     $callwaiting = trim(strtolower($callwaiting));
     $astman = new AGI_AsteriskManager();
     if (!$astman->connect("127.0.0.1", 'admin', obtenerClaveAMIAdmin())) {
         $this->errMsg = "Error connect AGI_AsteriskManager";
     }
     if (preg_match("/^enable/", $callwaiting)) {
         $r = $astman->command("database put CW {$extension} \"ENABLED\"");
         return (bool) strstr($r["data"], "success");
     } else {
         $r = $astman->command("database del CW {$extension}");
         return (bool) strstr($r["data"], "removed") || (bool) strstr($r["data"], "not exist");
     }
     $astman->disconnect();
 }
예제 #15
0
<?php 
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
    header("Location: ../index.php");
} else {
    require_once '/var/lib/asterisk/agi-bin/phpagi/phpagi-asmanager.php';
    $asm = new AGI_AsteriskManager();
    if ($asm->connect('localhost', 'admin', 'managerpwd')) {
        $peer = $asm->command("sip show peers");
        //print_r($peer);
        preg_match('/\\[(.*)/', $peer['data'], $val);
        //print_r($val);
        $online = explode(",", $val[1]);
        $offline = explode(",", $val[1]);
        $offline = explode("Unmonitored", $offline[1]);
        echo "ONline: " . $online[0];
        echo "\noffline: " . $offline[0];
    }
    $asm->disconnect();
    $jsondata['offiax'] = $offline[0];
    echo json_encode($jsondata);
}
?>

예제 #16
0
$asm = new AGI_AsteriskManager();
/*
 * Try to connect to server
 */
if ($asm->connect($_asm_host, $_asm_user, $_asm_passwd)) {
    /*
     * Parse IVR config
     */
    $menu_table = json_decode(file_get_contents($_ivr_config_path), TRUE);
    if (!$menu_table || !count($menu_table)) {
        return false;
    }
    /*
     * Get active channels with AGI lounched
     */
    $info = $asm->command("core show channels");
    $data = array();
    /*
     * Filter lines with AGI
     */
    foreach (preg_grep("/.*@.*:.*AGI/", explode("\n", $info["data"])) as $line) {
        $chan = preg_split("/ +/", $line);
        if (preg_match("/.*AGI\\((.*).*\\)/", $chan[3], $matches)) {
            $agi_params = preg_split("/,/", $matches[1]);
            /*
             * if ivr menu with name of second AGI param exist
             */
            if ($menu_table[$agi_params[1]]) {
                $call = array();
                $call['channel'] = $chan[0];
                $call['location'] = $chan[1];
예제 #17
0
            header("location:dialplan.php");
            break;
        case 'sip':
            $asm = new AGI_AsteriskManager();
            if ($asm->connect('localhost', 'admin', 'managerpwd')) {
                $dp = $asm->command("sip reload");
                sleep(1);
            }
            $asm->disconnect();
            header("location:sipf.php");
            break;
        case 'iax':
            $asm = new AGI_AsteriskManager();
            if ($asm->connect('localhost', 'admin', 'managerpwd')) {
                $dp = $asm->command("iax2 reload");
                sleep(1);
            }
            $asm->disconnect();
            header("location:iaxf.php");
            break;
        case 'dahdi':
            $asm = new AGI_AsteriskManager();
            if ($asm->connect('localhost', 'admin', 'managerpwd')) {
                $dp = $asm->command("dahdi restart");
                sleep(1);
            }
            $asm->disconnect();
            header("location:dahdif.php");
            break;
    }
}
예제 #18
0
<?php

session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
    header("Location: ../userlog.php.php");
} else {
    include "loginsql.php";
    require_once '/var/lib/asterisk/agi-bin/phpagi/phpagi-asmanager.php';
    $peer = $_GET['peer'];
    $value = $_GET['value'];
    $sql = "Update followme SET isset={$value} WHERE name={$peer}";
    mysql_query($sql) or die(mysql_error());
    $asm = new AGI_AsteriskManager();
    if ($asm->connect('localhost', 'admin', 'm4nag3rt3ts')) {
        $peer = $asm->command("database put Custom/User/FollowMe {$peer} {$value}");
        sleep(1);
    }
    $asm->disconnect();
}