Ejemplo n.º 1
0
 private function _getConnection($sConn)
 {
     $arrConf['cadena_dsn'] = "mysql://*****:*****@localhost/call_center";
     switch ($sConn) {
         case 'asterisk':
             if (!is_null($this->_oDB_asterisk)) {
                 return $this->_oDB_asterisk;
             }
             $sDSN = generarDSNSistema('asteriskuser', 'asterisk');
             $oDB = new paloDB($sDSN);
             if ($oDB->connStatus) {
                 $this->_errMsg = '(internal) Unable to create asterisk DB conn - ' . $oDB->errMsg;
                 die($this->_errMsg);
             }
             $this->_oDB_asterisk = $oDB;
             return $this->_oDB_asterisk;
             break;
         case 'call_center':
             if (!is_null($this->_oDB_call_center)) {
                 return $this->_oDB_call_center;
             }
             $sDSN = $arrConf['cadena_dsn'];
             $oDB = new paloDB($sDSN);
             if ($oDB->connStatus) {
                 $this->_errMsg = '(internal) Unable to create asterisk DB conn - ' . $oDB->errMsg;
                 die($this->_errMsg);
             }
             $this->_oDB_asterisk = $oDB;
             return $this->_oDB_asterisk;
             break;
         case 'ECCP':
             if (!is_null($this->_eccp)) {
                 return $this->_eccp;
             }
             $sUsernameECCP = 'agentconsole';
             $sPasswordECCP = 'agentconsole';
             // Verificar si existe la contraseña de ECCP, e insertar si necesario
             $dbConnCC = $this->_getConnection('call_center');
             $md5_passwd = $dbConnCC->getFirstRowQuery('SELECT md5_password FROM eccp_authorized_clients WHERE username = ?', TRUE, array($sUsernameECCP));
             if (is_array($md5_passwd)) {
                 if (count($md5_passwd) <= 0) {
                     $dbConnCC->genQuery('INSERT INTO eccp_authorized_clients (username, md5_password) VALUES(?, md5(?))', array($sUsernameECCP, $sPasswordECCP));
                 }
             }
             $oECCP = new ECCP();
             // TODO: configurar credenciales
             $oECCP->connect("localhost", $sUsernameECCP, $sPasswordECCP);
             if (!is_null($this->_agent)) {
                 $oECCP->setAgentNumber($this->_agent);
                 // El siguiente código asume agente SIP/9000
                 if (preg_match('|^SIP/(\\d+)$|', $this->_agent, $regs)) {
                     $sAgentNumber = $regs[1];
                 } else {
                     $sAgentNumber = $this->_agent;
                 }
                 /* Privilegio de localhost - se puede recuperar la clave del
                  * agente sin tener que pedirla explícitamente */
                 $tupla = $dbConnCC->getFirstRowQuery('SELECT eccp_password FROM agent WHERE number = ? AND estatus="A"', FALSE, array($sAgentNumber));
                 if (!is_array($tupla)) {
                     throw new ECCPConnFailedException('Failed to retrieve agent password');
                 }
                 if (count($tupla) <= 0) {
                     throw new ECCPUnauthorizedException('Agent not found');
                 }
                 if (is_null($tupla[0])) {
                     throw new ECCPUnauthorizedException('Agent not authorized for ECCP - ECCP password not set');
                 }
                 $oECCP->setAgentPass($tupla[0]);
                 // Filtrar los eventos sólo para el agente actual
                 $oECCP->filterbyagent();
             }
             $this->_eccp = $oECCP;
             return $this->_eccp;
             break;
     }
     return NULL;
 }
Ejemplo n.º 2
0
 private function _obtenerConexion($sConn)
 {
     global $arrConf;
     switch ($sConn) {
         case 'asterisk':
             if (!is_null($this->_oDB_asterisk)) {
                 return $this->_oDB_asterisk;
             }
             $sDSN = generarDSNSistema('asteriskuser', 'asterisk');
             $oDB = new paloDB($sDSN);
             if ($oDB->connStatus) {
                 $this->_errMsg = '(internal) Unable to create asterisk DB conn - ' . $oDB->errMsg;
                 die($this->_errMsg);
             }
             $this->_oDB_asterisk = $oDB;
             return $this->_oDB_asterisk;
             break;
         case 'call_center':
             if (!is_null($this->_oDB_call_center)) {
                 return $this->_oDB_call_center;
             }
             $sDSN = $arrConf['cadena_dsn'];
             $oDB = new paloDB($sDSN);
             if ($oDB->connStatus) {
                 $this->_errMsg = '(internal) Unable to create asterisk DB conn - ' . $oDB->errMsg;
                 die($this->_errMsg);
             }
             $this->_oDB_call_center = $oDB;
             return $this->_oDB_call_center;
             break;
         case 'ECCP':
             if (!is_null($this->_eccp)) {
                 return $this->_eccp;
             }
             $sUsernameECCP = 'agentconsole';
             $sPasswordECCP = 'agentconsole';
             // Verificar si existe la contraseña de ECCP, e insertar si necesario
             $dbConnCC = $this->_obtenerConexion('call_center');
             $md5_passwd = $dbConnCC->getFirstRowQuery('SELECT md5_password FROM eccp_authorized_clients WHERE username = ?', TRUE, array($sUsernameECCP));
             if (is_array($md5_passwd)) {
                 if (count($md5_passwd) <= 0) {
                     $dbConnCC->genQuery('INSERT INTO eccp_authorized_clients (username, md5_password) VALUES(?, md5(?))', array($sUsernameECCP, $sPasswordECCP));
                 }
             }
             $oECCP = new ECCP();
             // TODO: configurar credenciales
             $cr = $oECCP->connect("localhost", $sUsernameECCP, $sPasswordECCP);
             if (isset($cr->failure)) {
                 throw new ECCPUnauthorizedException(_tr('Failed to authenticate to ECCP') . ': ' . (string) $cr->failure->message);
             }
             if (!is_null($this->_agent)) {
                 $oECCP->setAgentNumber($this->_agent);
                 /* Privilegio de localhost - se puede recuperar la clave del
                  * agente sin tener que pedirla explícitamente */
                 $tupla = $dbConnCC->getFirstRowQuery("SELECT eccp_password FROM agent WHERE CONCAT(type,'/',number) = ? AND estatus='A'", FALSE, array($this->_agent));
                 if (!is_array($tupla)) {
                     throw new ECCPConnFailedException(_tr('Failed to retrieve agent password'));
                 }
                 if (count($tupla) <= 0) {
                     throw new ECCPUnauthorizedException(_tr('Agent not found'));
                 }
                 if (is_null($tupla[0])) {
                     throw new ECCPUnauthorizedException(_tr('Agent not authorized for ECCP - ECCP password not set'));
                 }
                 $oECCP->setAgentPass($tupla[0]);
                 // Filtrar los eventos sólo para el agente actual
                 $oECCP->filterbyagent();
             }
             $this->_eccp = $oECCP;
             return $this->_eccp;
             break;
     }
     return NULL;
 }