Exemplo n.º 1
0
 function AsteriskManagerAPI($action, $parameters, $return_data = false)
 {
     global $arrLang;
     $astman_host = "127.0.0.1";
     $astman_user = '******';
     $astman_pwrd = obtenerClaveAMIAdmin();
     $astman = new AGI_AsteriskManager();
     $astman->pagi = new dummy_pagi();
     if (!$astman->connect("{$astman_host}", "{$astman_user}", "{$astman_pwrd}")) {
         $this->errMsg = _tr("Error when connecting to Asterisk Manager");
     } else {
         $salida = $astman->send_request($action, $parameters);
         $astman->disconnect();
         if (strtoupper($salida["Response"]) != "ERROR") {
             if ($return_data) {
                 return $salida;
             } else {
                 return explode("\n", $salida["Response"]);
             }
         } else {
             return false;
         }
     }
     return false;
 }
 function __construct()
 {
     global $arrConf;
     $this->_actionid = get_class($this) . '-' . posix_getpid();
     foreach (array('phones', 'dahdi', 'iptrunks', 'conferences', 'parkinglots', 'queues') as $k) {
         $this->_internalState[$k] = array();
     }
     $this->_internalState['dahdi'] = array('chan2span' => array(), 'spans' => array());
     $this->_db = new paloDB($arrConf['elastix_dsn']["elastix"]);
     if ($this->_db->errMsg != '') {
         $this->_errMsg = $this->_db->errMsg;
         $this->_db = NULL;
         return;
     }
     $this->_dbConfig = new paloDB($arrConf['dsn_conn_database']);
     if ($this->_dbConfig->errMsg != '') {
         $this->_errMsg = $this->_dbConfig->errMsg;
         $this->_dbConfig = NULL;
         return;
     }
     $this->_ami = new AGI_AsteriskManager2();
     if (!$this->_ami->connect('localhost', 'admin', obtenerClaveAMIAdmin())) {
         $this->_errMsg = _tr("Error when connecting to Asterisk Manager");
         $this->_ami = NULL;
         return;
     }
     // Instalar todos los manejadores según el nombre del método
     foreach (get_class_methods(get_class($this)) as $sMetodo) {
         $regs = NULL;
         if (preg_match('/^msg_(.+)$/', $sMetodo, $regs)) {
             if ($regs[1] != 'Default') {
                 $this->_ami->add_event_handler($regs[1], array($this, $sMetodo));
             }
         }
     }
     if ($this->_debug && method_exists($this, 'msg_Default')) {
         $this->_ami->add_event_handler('*', array($this, 'msg_Default'));
     }
 }
 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;
 }
Exemplo n.º 4
0
 private function _get_AGI_AsteriskManager()
 {
     $ip_asterisk = '127.0.0.1';
     $user_asterisk = 'admin';
     $pass_asterisk = function_exists('obtenerClaveAMIAdmin') ? obtenerClaveAMIAdmin() : 'elastix456';
     $astman = new AGI_AsteriskManager();
     if (!$astman->connect($ip_asterisk, $user_asterisk, $pass_asterisk)) {
         $this->errMsg = "Error when connecting to Asterisk Manager";
         return NULL;
     } else {
         return $astman;
     }
 }
Exemplo n.º 5
0
 function AsteriskManager_Command($command_data, $return_data = true)
 {
     global $arrLang;
     $salida = array();
     $astman = new AGI_AsteriskManager();
     if (!$astman->connect("127.0.0.1", "admin", obtenerClaveAMIAdmin())) {
         $this->errMsg = $arrLang["Error when connecting to Asterisk Manager"];
     } else {
         $salida = $astman->send_request('Command', array('Command' => "{$command_data}"));
         $astman->disconnect();
         $salida["Response"] = isset($salida["Response"]) ? $salida["Response"] : "";
         if (strtoupper($salida["Response"]) != "ERROR") {
             if ($return_data) {
                 return explode("\n", $salida["data"]);
             } else {
                 return explode("\n", $salida["Response"]);
             }
         } else {
             return false;
         }
     }
     return false;
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 private function _getami()
 {
     $astman = new AGI_AsteriskManager();
     if (!$astman->connect("127.0.0.1", "admin", obtenerClaveAMIAdmin())) {
         $this->errMsg = _tr('Error when connecting to Asterisk Manager');
         return NULL;
     }
     return $astman;
 }
 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();
 }
 /**
  * Procedimiento que cuelga el primer canal activo asociado con la cuenta
  * que posee la extensión indicada.
  * 
  * @param   string  $target Extensión con un canal activo a colgar
  * 
  * @return  bool    VERDADERO en éxito, FALSO en error
  */
 function hangupExtension($target)
 {
     if (!preg_match('/^[[:digit:]#*]+$/', $target)) {
         $this->errMsg = _tr('Invalid target for call');
         return FALSE;
     }
     $ami = new AGI_AsteriskManager2();
     if (!$ami->connect('localhost', 'admin', obtenerClaveAMIAdmin())) {
         $this->_errMsg = _tr("Error when connecting to Asterisk Manager");
         return FALSE;
     }
     // Leer la cadena de dial para la fuente.
     list($dialchan, $cidname) = $this->_getDialString($ami, $target);
     if ($dialchan === FALSE) {
         $ami->disconnect();
         return FALSE;
     }
     // Listar los canales activos y buscar el que tiene como prefijo el $dialchan
     $r = $ami->Command('core show channels concise');
     if ($r['Response'] != 'Follows') {
         $this->errMsg = _tr('(internal) Failed to list channels');
         return FALSE;
     }
     $channel = NULL;
     foreach (explode("\n", $r['data']) as $s) {
         $tupla = explode('!', $s);
         if (count($tupla) >= 11 && strpos($tupla[0], $dialchan) === 0) {
             $channel = $tupla[0];
             break;
         }
     }
     if (is_null($channel)) {
         $this->errMsg = _tr('No active channels for target');
         $ami->disconnect();
         return FALSE;
     }
     // Colgar el canal que ha sido encontrado
     $r = $ami->Hangup($channel);
     $ami->disconnect();
     if ($r['Response'] != 'Success') {
         $this->errMsg = _tr('(internal) Failed to hangup active channel for target');
         return FALSE;
     }
     return TRUE;
 }
Exemplo n.º 10
0
function load_extension_from_csv($smarty, $ruta_archivo, $base_dir, $pDB, $arrAST, $arrAMP)
{
    $Messages = "";
    $arrayColumnas = array();
    $data_connection = array('host' => "127.0.0.1", 'user' => "admin", 'password' => obtenerClaveAMIAdmin());
    $result = isValidCSV($pDB, $ruta_archivo, $arrayColumnas);
    if ($result != "valided") {
        $smarty->assign("mb_message", $result);
        return;
    }
    $hArchivo = fopen($ruta_archivo, 'r+');
    $cont = 0;
    $pLoadExtension = new paloSantoLoadExtension($pDB);
    if ($hArchivo) {
        //Linea 1 header ignorada
        $tupla = fgetcsv($hArchivo, 4096, ",");
        $prueba = count($tupla);
        //Desde linea 2 son datos
        while ($tupla = fgetcsv($hArchivo, 4096, ",")) {
            if (is_array($tupla) && count($tupla) >= 3) {
                $Name = $tupla[$arrayColumnas[0]];
                $Ext = $tupla[$arrayColumnas[1]];
                $Direct_DID = isset($arrayColumnas[2]) ? $tupla[$arrayColumnas[2]] : "";
                $Outbound_CID = isset($arrayColumnas[3]) ? $tupla[$arrayColumnas[3]] : "";
                $Call_Waiting = isset($arrayColumnas[4]) ? $tupla[$arrayColumnas[4]] : "";
                $Secret = $tupla[$arrayColumnas[5]];
                $VoiceMail = isset($arrayColumnas[6]) ? $tupla[$arrayColumnas[6]] : "";
                $VoiceMail_PW = isset($arrayColumnas[7]) ? $tupla[$arrayColumnas[7]] : "";
                $VM_Email_Address = isset($arrayColumnas[8]) ? $tupla[$arrayColumnas[8]] : "";
                $VM_Pager_Email_Addr = isset($arrayColumnas[9]) ? $tupla[$arrayColumnas[9]] : "";
                $VM_Options = isset($arrayColumnas[10]) ? $tupla[$arrayColumnas[10]] : "";
                $VM_EmailAttachment = isset($arrayColumnas[11]) ? $tupla[$arrayColumnas[11]] : "";
                $VM_Play_CID = isset($arrayColumnas[12]) ? $tupla[$arrayColumnas[12]] : "";
                $VM_Play_Envelope = isset($arrayColumnas[13]) ? $tupla[$arrayColumnas[13]] : "";
                $VM_Delete_Vmail = isset($arrayColumnas[14]) ? $tupla[$arrayColumnas[14]] : "";
                $Context = isset($arrayColumnas[15]) ? $tupla[$arrayColumnas[15]] : "from-internal";
                if (trim($Context) == "") {
                    $Context = "from-internal";
                }
                $Tech = strtolower($tupla[$arrayColumnas[16]]);
                $Callgroup = isset($arrayColumnas[17]) ? $tupla[$arrayColumnas[17]] : "";
                $Pickupgroup = isset($arrayColumnas[18]) ? $tupla[$arrayColumnas[18]] : "";
                $Disallow = isset($arrayColumnas[19]) ? $tupla[$arrayColumnas[19]] : "";
                $Allow = isset($arrayColumnas[20]) ? $tupla[$arrayColumnas[20]] : "";
                $Deny = isset($arrayColumnas[21]) ? $tupla[$arrayColumnas[21]] : "";
                $Permit = isset($arrayColumnas[22]) ? $tupla[$arrayColumnas[22]] : "";
                $Record_Incoming = isset($arrayColumnas[23]) ? $tupla[$arrayColumnas[23]] : "";
                $Record_Outgoing = isset($arrayColumnas[24]) ? $tupla[$arrayColumnas[24]] : "";
                //////////////////////////////////////////////////////////////////////////////////
                $Record_Incoming = strtolower($Record_Incoming);
                $Record_Outgoing = strtolower($Record_Outgoing);
                if (preg_match("/^(on demand|adhoc)/", $Record_Incoming)) {
                    $Record_Incoming = "Adhoc";
                } elseif (preg_match("/^always/", $Record_Incoming)) {
                    $Record_Incoming = "always";
                } elseif (preg_match("/^never/", $Record_Incoming)) {
                    $Record_Incoming = "never";
                }
                if (preg_match("/(on demand|adhoc)/", $Record_Outgoing)) {
                    $Record_Outgoing = "Adhoc";
                } elseif (preg_match("/^always/", $Record_Outgoing)) {
                    $Record_Outgoing = "always";
                } elseif (preg_match("/^never/", $Record_Outgoing)) {
                    $Record_Outgoing = "never";
                }
                //////////////////////////////////////////////////////////////////////////////////
                // validando para que coja las comillas
                $Outbound_CID = preg_replace('/“/', "\"", $Outbound_CID);
                $Outbound_CID = preg_replace('/”/', "\"", $Outbound_CID);
                //////////////////////////////////////////////////////////////////////////////////
                //Paso 1: creando en la tabla sip - iax
                if (!$pLoadExtension->createTechDevices($Ext, $Secret, $VoiceMail, $Context, $Tech, $Disallow, $Allow, $Deny, $Permit, $Callgroup, $Pickupgroup, $Record_Incoming, $Record_Outgoing)) {
                    $Messages .= "Ext: {$Ext} - " . _tr('Error updating Tech') . ": " . $pLoadExtension->errMsg . "<br />";
                } else {
                    //Paso 2: creando en la tabla users
                    if (!$pLoadExtension->createUsers($Ext, $Name, $VoiceMail, $Direct_DID, $Outbound_CID, $Record_Incoming, $Record_Outgoing)) {
                        $Messages .= "Ext: {$Ext} - " . _tr('Error updating Users') . ": " . $pLoadExtension->errMsg . "<br />";
                    }
                    //Paso 3: creando en la tabla devices
                    if (!$pLoadExtension->createDevices($Ext, $Tech, $Name)) {
                        $Messages .= "Ext: {$Ext} - " . _tr('Error updating Devices') . ": " . $pLoadExtension->errMsg . "<br />";
                    }
                    //Paso 4: creando en el archivo /etc/asterisk/voicemail.conf los voicemails
                    if (!$pLoadExtension->writeFileVoiceMail($Ext, $Name, $VoiceMail, $VoiceMail_PW, $VM_Email_Address, $VM_Pager_Email_Addr, $VM_Options, $VM_EmailAttachment, $VM_Play_CID, $VM_Play_Envelope, $VM_Delete_Vmail)) {
                        $Messages .= "Ext: {$Ext} - " . _tr('Error updating Voicemail') . "<br />";
                    }
                    //Paso 5: Configurando el call waiting
                    if (!$pLoadExtension->processCallWaiting($Call_Waiting, $Ext)) {
                        $Messages .= "Ext: {$Ext} - " . _tr('Error processing CallWaiting') . "<br />";
                    }
                    $outboundcid = preg_replace("/\"/", "'", $Outbound_CID);
                    $outboundcid = preg_replace("/\"/", "'", $outboundcid);
                    $outboundcid = preg_replace("/ /", "", $outboundcid);
                    if (!$pLoadExtension->putDataBaseFamily($data_connection, $Ext, $Tech, $Name, $VoiceMail, $outboundcid, $Record_Incoming, $Record_Outgoing)) {
                        $Messages .= "Ext: {$Ext} - " . _tr('Error processing Database Family') . "<br />";
                    }
                    $cont++;
                }
                ////////////////////////////////////////////////////////////////////////
                //Paso 7: Escribiendo en tabla incoming
                if ($Direct_DID !== "") {
                    if (!$pLoadExtension->createDirect_DID($Ext, $Direct_DID)) {
                        $Messages .= "Ext: {$Ext} - " . _tr('Error to insert or update Direct DID') . "<br />";
                    }
                }
                /////////////////////////////////////////////////////////////////////////
            }
        }
        //Paso 6: Realizo reload
        if (!$pLoadExtension->do_reloadAll($data_connection, $arrAST, $arrAMP)) {
            $Messages .= $pLoadExtension->errMsg;
        }
        $Messages .= _tr('Total extension updated') . ": {$cont}<br />";
        $smarty->assign("mb_message", $Messages);
    }
    unlink($ruta_archivo);
}
Exemplo n.º 11
0
  +----------------------------------------------------------------------+
  | Cdla. Nueva Kennedy Calle E 222 y 9na. Este                          |
  | Telfs. 2283-268, 2294-440, 2284-356                                  |
  | Guayaquil - Ecuador                                                  |
  | http://www.palosanto.com                                             |
  +----------------------------------------------------------------------+
  | The contents of this file are subject to the General Public License  |
  | (GPL) Version 2 (the "License"); you may not use this file except in |
  | compliance with the License. You may obtain a copy of the License at |
  | http://www.opensource.org/licenses/gpl-license.php                   |
  |                                                                      |
  | Software distributed under the License is distributed on an "AS IS"  |
  | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See  |
  | the License for the specific language governing rights and           |
  | limitations under the License.                                       |
  +----------------------------------------------------------------------+
  | The Original Code is: Elastix Open Source.                           |
  | The Initial Developer of the Original Code is PaloSanto Solutions    |
  +----------------------------------------------------------------------+
  $Id: default.conf.php,v 1.1 2010-12-21 09:08:11 Alberto Santos asantos@palosanto.com Exp $ */
global $arrConf;
global $arrConfModule;
$arrConfModule['module_name'] = 'sec_weak_keys';
$arrConfModule['templates_dir'] = 'themes';
//ex1: $arrConfModule['dsn_conn_database'] = "sqlite3:///$arrConf[elastix_dbdir]/base_name.db";
//$arrConfModule['dsn_conn_database'] = "mysql://*****:*****@localhost/asterisk";
$arrConfModule['dsn_conn_database'] = '';
$arrConfModule['AMI_HOST'] = "127.0.0.1";
$arrConfModule['AMI_USER'] = "******";
$arrConfModule['AMI_PASS'] = obtenerClaveAMIAdmin();