Пример #1
0
 function get_hint()
 {
     // We should always check the EXTUSER in case they logged into a device
     // but we will fall back to the old methond if $astman not open although
     // I'm pretty sure everything else will puke anyhow if not running
     //
     $error = "";
     $pDB = new paloDB(generarDSNSistema("asteriskuser", "elxpbx"));
     $astman = AsteriskManagerConnect($error);
     if ($astman != false) {
         //se obtine los dispositivos a los cuales la extension esta asociada
         $deviceDB = $astman->database_get("EXTUSER", $this->code . "/" . $this->exten . "/device");
         $device_arr = explode('&', $deviceDB);
         //se obtine como se marca a dichos dispositivos
         foreach ($device_arr as $device) {
             $tmp_dial = $astman->database_get("DEVICE", $this->code . "/" . $device . "/dial");
             if ($tmp_dial !== "ERROR") {
                 $dial[] = $tmp_dial;
             }
         }
     } else {
         $query = "SELECT dial from extension where exten=? and organization_domain=?";
         $arrayParam = array($this->exten, $this->domain);
         $results = $pDB->fetchTable($query, false, $arrayParam);
         //create an array of strings
         if (is_array($results)) {
             foreach ($results as $result) {
                 $dial[] = str_replace('ZAP', 'DAHDI', $result[0]);
             }
         }
     }
     //create a string with & delimiter
     if (isset($dial) && is_array($dial)) {
         $hint = implode($dial, "&");
     } else {
         $query = "SELECT dial from extension where exten=? and organization_domain=?";
         $results = $pDB->getFirstRowQuery($query, false, array($this->exten, $this->domain));
         if (isset($results[0])) {
             $hint = $results[0];
         } else {
             $hint = "";
         }
     }
     return $hint;
 }
 private function createDialPlanFuntionBlacklist(&$arrFromInt)
 {
     $arrContext = array();
     //se comprueba si se desean bloquear los numeros con callerid como unnowkn o unvailable
     $astMang = AsteriskManagerConnect($errorMng);
     if ($astMang == false) {
         $this->errMsg = $errorMng;
         $blck == "0";
     } else {
         $blck = $astMang->database_get("blacklist", "blocked");
         $astMang->disconnect();
     }
     //se crea el contexto app-black-list-check
     //en este contexto se verifica si un numero se encuentra dentro de la lista de blacklist
     if ($blck == "1") {
         $arrBLCheck[] = new paloExtensions("s", new ext_gotoIf('$["${CALLERID(number)}" = "Unknown"]', "check-blocked"), "1");
         $arrBLCheck[] = new paloExtensions("s", new ext_gotoIf('$["${CALLERID(number)}" = "Unavailable"]', "check-blocked"));
         $arrBLCheck[] = new paloExtensions("s", new ext_gotoIf('$["foo${CALLERID(number)}" = "foo"', "check-blocked", "check"));
         $arrBLCheck[] = new paloExtensions("s", new ext_gotoIf('$["${DB(blacklist/' . $this->code . '/blocked)}" = "1"]', "blacklisted"), "n", "check-blocked");
         $arrBLCheck[] = new paloExtensions("s", new ext_gotoIf('$["${BLACKLIST()}"="1"]', "blacklisted"), "n", "check");
     } else {
         $arrBLCheck[] = new paloExtensions("s", new ext_gotoIf('$["${BLACKLIST()}"="1"]', "blacklisted"), 1, "check");
     }
     $arrBLCheck[] = new paloExtensions("s", new ext_setvar("CALLED_BLACKLIST", "1"));
     $arrBLCheck[] = new paloExtensions("s", new ext_return());
     $arrBLCheck[] = new paloExtensions("s", new ext_answer(), "n", 'blacklisted');
     $arrBLCheck[] = new paloExtensions("s", new ext_wait("1"));
     $arrBLCheck[] = new paloExtensions("s", new ext_zapateller());
     $arrBLCheck[] = new paloExtensions("s", new ext_playback("ss-noservice"));
     $arrBLCheck[] = new paloExtensions("s", new ext_hangup());
     $contextoBLCheck = new paloContexto($this->code, "app-blacklist-check");
     if ($contextoBLCheck === false) {
         $contextoBLCheck->errMsg = "app-blacklist-check. Error: " . $contextoBLCheck->errMsg;
     } else {
         $contextoBLCheck->arrExtensions = $arrBLCheck;
         $arrFromInt[]["name"] = "app-blacklist-check";
     }
     $arrContext[] = $contextoBLCheck;
     $arrFeature = array("blacklist_num", "blacklist_lcall", "blacklist_rm");
     unset($this->arrFeatureCode);
     $this->setArrFCbyCategory($arrFeature);
     $contextoBLapp = new paloContexto($this->code, "app-blacklist");
     $arrFromInt[]["name"] = "app-blacklist";
     if (is_array($this->arrFeatureCode)) {
         foreach ($this->arrFeatureCode as $value) {
             if ($value != false) {
                 //funcion que me devuelve un arreglo con los contexto creados
                 $fname = "dialPlanBlacklist_" . $value->name;
                 $contexts = $this->{$fname}($contextoBLapp->arrExtensions, $value->getCurrentCode());
                 $arrContext = array_merge($arrContext, $contexts);
             }
         }
     }
     $arrContext[] = $contextoBLapp;
     return $arrContext;
 }
 private function insertDeviceASTDB($arrProp)
 {
     $arrSetting = array();
     $arrSetting["language"] = isset($arrProp["language"]) ? $arrProp["language"] : "\"\"";
     $arrSetting["voicemail"] = $arrProp["voicemail_context"];
     //validamos los recording
     switch (strtolower($arrProp["record_out"])) {
         case "always":
             $stRecord = "out=always";
             break;
         case "never":
             $stRecord = "out=never";
             break;
         default:
             $stRecord = "out=on_demand";
             break;
     }
     $stRecord .= "|";
     switch (strtolower($arrProp["record_in"])) {
         case "always":
             $stRecord .= "in=always";
             break;
         case "never":
             $stRecord .= "in=never";
             break;
         default:
             $stRecord .= "in=on_demand";
             break;
     }
     $arrSetting["recording"] = $stRecord;
     $error = false;
     $familia = "EXTUSER/{$arrProp['code']}/" . $arrProp['exten'];
     $arrInsert = array();
     $errorM = "";
     $astMang = AsteriskManagerConnect($errorM);
     if ($astMang == false) {
         $this->errMsg = $errorM;
         return false;
     } else {
         //seteo las propiedades en la base ASTDB de asterisk
         foreach ($arrSetting as $key => $value) {
             $result = $astMang->database_put($familia, $key, $value);
             if (strtoupper($result["Response"]) == "ERROR") {
                 $error = true;
                 break;
             }
         }
     }
     //si se habilito el donotdisturb ingresa ese dato a la base ASTDB
     if (isset($arrProp['doNotDisturb'])) {
         if ($arrProp['doNotDisturb'] == "yes") {
             $result = $astMang->database_put("DND/" . $arrProp['code'], $arrProp['exten'], "YES");
         } else {
             $result = $astMang->database_del("DND/" . $arrProp['code'], $arrProp['exten']);
         }
     } else {
         $result = $astMang->database_del("DND/" . $arrProp['code'], $arrProp['exten']);
     }
     if (strtoupper($result["Response"]) == "ERROR") {
         $error = true;
     }
     //si se habilito el callwaiting ingresa ese dato a la base ASTDB
     if (isset($arrProp['callwaiting'])) {
         if ($arrProp['callwaiting'] == "yes") {
             $result = $astMang->database_put("CW/" . $arrProp['code'], $arrProp['exten'], "ENABLED");
         } else {
             $result = $astMang->database_del("CW/" . $arrProp['code'], $arrProp['exten']);
         }
     } else {
         $result = $astMang->database_del("CW/" . $arrProp['code'], $arrProp['exten']);
     }
     if (strtoupper($result["Response"]) == "ERROR") {
         $error = true;
     }
     //si se habilito el callforward ingresa ese dato a la base ASTDB
     if (isset($arrProp['callForwardOpt'])) {
         if ($arrProp['callForwardOpt'] == "yes") {
             $result = $astMang->database_put("CF/" . $arrProp['code'], $arrProp['exten'], $arrProp['callForwardInp']);
         } else {
             $result = $astMang->database_del("CF/" . $arrProp['code'], $arrProp['exten']);
         }
     } else {
         $result = $astMang->database_del("CF/" . $arrProp['code'], $arrProp['exten']);
     }
     if (strtoupper($result["Response"]) == "ERROR") {
         $error = true;
     }
     //si se habilito el callforward Unavailable ingresa ese dato a la base ASTDB
     if (isset($arrProp['callForwardUnavailableOpt'])) {
         if ($arrProp['callForwardUnavailableOpt'] == "yes") {
             $result = $astMang->database_put("CFU/" . $arrProp['code'], $arrProp['exten'], $arrProp['callForwardUnavailableInp']);
         } else {
             $result = $astMang->database_del("CFU/" . $arrProp['code'], $arrProp['exten']);
         }
     } else {
         $result = $astMang->database_del("CFU/" . $arrProp['code'], $arrProp['exten']);
     }
     if (strtoupper($result["Response"]) == "ERROR") {
         $error = true;
     }
     //si se habilito el callforward Busy ingresa ese dato a la base ASTDB
     if (isset($arrProp['callForwardBusyOpt'])) {
         if ($arrProp['callForwardBusyOpt'] == "yes") {
             $result = $astMang->database_put("CFB/" . $arrProp['code'], $arrProp['exten'], $arrProp['callForwardBusyInp']);
         } else {
             $result = $astMang->database_del("CFB/" . $arrProp['code'], $arrProp['exten']);
         }
     } else {
         $result = $astMang->database_del("CFB/" . $arrProp['code'], $arrProp['exten']);
     }
     if (strtoupper($result["Response"]) == "ERROR") {
         $error = true;
     }
     $astMang->disconnect();
     return true;
 }
 function InviteCaller($room, $ext_room, $channel, $callerId)
 {
     $arrCallers = array();
     if (empty($this->domain) || empty($this->code)) {
         return false;
     }
     if (!preg_match("/^" . $this->code . "_[0-9]+\$/", $room)) {
         $this->errMsg = _tr("Invalid Room");
         return false;
     }
     if (count(preg_split("/[\r\n]+/", $ext_room)) > 1) {
         return FALSE;
     }
     $query = "Select exten from extension where dial=? and organization_domain=?";
     $result = $this->_DB->getFirstRowQuery($query, false, array($channel, $this->domain));
     if ($result == false) {
         $this->errMsg = _tr("Invalid Exten");
         return false;
     }
     $astMang = AsteriskManagerConnect($errorM);
     if ($astMang == false) {
         $this->errMsg = $errorM;
         return false;
     } else {
         $parameters['Channel'] = $channel;
         $parameters['Context'] = $this->code . "-ext-meetme";
         $parameters['Exten'] = $ext_room;
         $parameters['Priority'] = 1;
         $parameters['CallerID'] = $callerId;
         $parameters['Variable'] = "REALCALLERIDNUM=" . $result[0];
         $salida = $astMang->send_request('Originate', $parameters);
         $astMang->disconnect();
         if (strtoupper($salida["Response"]) != "ERROR") {
             return true;
         } else {
             return false;
         }
     }
     return false;
 }
Пример #5
0
function getNewListElastixAccounts($searchFilter, &$errmsg)
{
    global $arrConf;
    $error = '';
    $pDB = new paloDB($arrConf['elastix_dsn']["elastix"]);
    $pACL = new paloACL($pDB);
    $astMang = AsteriskManagerConnect($error);
    if ($astMang == false) {
        $this->errMsg = $error;
        return false;
    }
    $arrCredentials = getUserCredentials($_SESSION['elastix_user']);
    //obtenemos el codigo pbx de la organizacion
    $query = "SELECT code from organization where id=?";
    $result = $pDB->getFirstRowQuery($query, false, array($arrCredentials["id_organization"]));
    if ($result == false) {
        $errmsg = "An error has ocurred to retrieved organization data. ";
        return false;
    } else {
        $pbxCode = $result[0];
    }
    //1) obtenemos los parametros generales de configuracion para asterisk websocket y el cliente de chat de elastix
    $chatConfig = getChatClientConfig($pDB, $error);
    if ($chatConfig == false) {
        $errmsg = "An error has ocurred to retrieved server configuration params. " . $error;
        return false;
    }
    //2) TODO:obtener el dominio sip de la organizacion si no se encuentra configurado utilizar
    //   el ws_server
    $dominio = $chatConfig['elastix_chat_server'];
    //3) obtenemos la informacion de las cuentas de los usuarios
    $name = null;
    if (!empty($searchFilter)) {
        $name = $searchFilter;
    }
    $result = $pACL->getUsersAccountsInfoByDomain($arrCredentials["id_organization"], $name);
    if ($result === false) {
        //hubo un error de la base de datos ahi que desactivar la columna lateral
        $errmsg = "An error has ocurred to retrieved Contacts Info. " . $pACL->errMsg;
        return false;
    } else {
        $arrContacts = array();
        foreach ($result as $key => $value) {
            //TODO: por el momento se obtine la presencia del usuario al
            // travès de AMI con la función que extension_state
            // en el futuro esto debe ser manejado con la libreria jssip
            // actualmente este libreria no tiene esa funcion implementada
            /*
            -1 = Extension not found
            0 = Idle
            1 = In Use
            2 = Busy
            4 = Unavailable
            8 = Ringing
            16 = On Hold
            */
            if ($value['extension'] != '' && isset($value['extension'])) {
                $result = $astMang->send_request('ExtensionState', array('Exten' => "{$value['extension']}", 'Context' => "{$pbxCode}-ext-local"));
                if ($result['Response'] == 'Success') {
                    $status = getStatusContactFromCode($result['Status']);
                    $st_code = $result['Status'];
                    if ($result['Status'] == '-1') {
                        $index_st = 'not_found';
                    } elseif ($result['Status'] == '4') {
                        $index_st = 'unava';
                    } else {
                        $index_st = 'ava';
                    }
                } else {
                    //TODO:ahi un error con el manager y nopuede determinar le estado de los
                    //contactos por lo tanto dejo a todas como disponibles
                    $index_st = 'ava';
                    $st_code = 0;
                    $status = _tr('Idle');
                }
                if ($value['id'] != $arrCredentials['idUser']) {
                    $arrContacts[$index_st][$key]['idUser'] = $value['id'];
                    $arrContacts[$index_st][$key]['display_name'] = $value['name'];
                    $arrContacts[$index_st][$key]['username'] = $value['username'];
                    $arrContacts[$index_st][$key]['presence'] = $status;
                    $arrContacts[$index_st][$key]['st_code'] = $st_code;
                    $arrContacts[$index_st][$key]['uri'] = "{$value['elxweb_device']}@{$dominio}";
                    $arrContacts[$index_st][$key]['alias'] = "{$value['alias']}@{$dominio}";
                } else {
                    $arrContacts['my_info']['uri'] = "{$value['elxweb_device']}@{$dominio}";
                    $arrContacts['my_info']['ws_servers'] = $chatConfig['ws_servers'];
                    $arrContacts['my_info']['password'] = $_SESSION['elastix_pass2'];
                    $arrContacts['my_info']['display_name'] = $value['name'];
                    $arrContacts['my_info']['elxuser_username'] = $value['username'];
                    $arrContacts['my_info']['elxuser_exten'] = $value['extension'];
                    $arrContacts['my_info']['elxuser_faxexten'] = $value['fax_extension'];
                    $arrContacts['my_info']['st_code'] = $st_code;
                    foreach ($chatConfig as $key => $value) {
                        $arrContacts['my_info'][$key] = $value;
                    }
                }
            }
        }
        $resultado = $arrContacts;
    }
    $astMang->disconnect();
    return $resultado;
}
 function getExtensionById($id, $domain = null)
 {
     global $arrConf;
     $arrExtension = array();
     $where = "";
     if (!preg_match('/^[[:digit:]]+$/', "{$id}")) {
         $this->errMsg = "Extension ID must be numeric";
         return false;
     }
     $param = array($id);
     if (isset($domain)) {
         if (!preg_match("/^(([[:alnum:]-]+)\\.)+([[:alnum:]])+\$/", $domain)) {
             $this->errMsg = "Invalid domain format";
             return false;
         } else {
             $where = " and organization_domain=?";
             $param[] = $domain;
         }
     }
     $query = "SELECT tech, exten, outboundcid, rt, record_in, record_out, organization_domain, voicemail, device, clid_name, clid_number,alias,elxweb_device,enable_chat from extension where id=? {$where}";
     $result = $this->_DB->getFirstRowQuery($query, true, $param);
     if ($result === false) {
         $this->errMsg = $this->_DB->errMsg;
         return false;
     } elseif (count($result) > 0) {
         //get organization_code
         $org_code = $this->getOrganizationCode($result["organization_domain"]);
         if ($org_code === false) {
             return false;
         }
         $arrExtension["technology"] = $result["tech"];
         $arrExtension["exten"] = $result["exten"];
         $arrExtension["clid_name"] = $result["clid_name"];
         $arrExtension["clid_number"] = $result["clid_number"];
         $arrExtension["ring_timer"] = $result["rt"];
         $arrExtension["record_in"] = $result["record_in"];
         $arrExtension["record_out"] = $result["record_out"];
         $arrExtension["out_clid"] = $result["outboundcid"];
         $arrExtension["alias"] = $result["alias"];
         $arrExtension["elxweb_device"] = $result["elxweb_device"];
         $arrExtension["enable_chat"] = $result["enable_chat"];
         //obtenemos las caracteristicas de voicemail de la extension en caso de que este tenga creada uno
         if (isset($result["voicemail"]) && $result["voicemail"] != "novm") {
             $query = "SELECT * from voicemail where mailbox=? and organization_domain=?";
             $voicemail = $this->_DB->getFirstRowQuery($query, true, array($result["exten"], $result["organization_domain"]));
             if ($voicemail == false) {
                 $arrExtension["create_vm"] = "no";
                 if ($voicemail === false) {
                     $this->errMsg .= _tr("Error getting voicemail") . $this->_DB->errMsg;
                 }
             } else {
                 $arrExtension["create_vm"] = "yes";
                 $option = "";
                 foreach ($voicemail as $key => $value) {
                     switch ($key) {
                         case "password":
                             $arrExtension["vmpassword"] = $value;
                             break;
                         case "email":
                             $arrExtension["vmemail"] = $value;
                             break;
                         case "attach":
                             $arrExtension["vmattach"] = $value;
                             break;
                         case "saycid":
                             $arrExtension["vmsaycid"] = $value;
                             break;
                         case "deletevoicemail":
                             $arrExtension["vmdelete"] = $value;
                             break;
                         case "envelope":
                             $arrExtension["vmenvelope"] = $value;
                             break;
                         case "context":
                             $arrExtension["vmcontext"] = substr_replace($value, '', 0, strlen($org_code) + 1);
                             //eliminamos la parte del string que contiene el codigo de la organization
                             break;
                         case "emailsubject":
                             $arrExtension["vmemailsubject"] = $value;
                             break;
                         case "emailbody":
                             $arrExtension["vmemailbody"] = $value;
                             break;
                         case "mailbox":
                             break;
                         case "fullname":
                             break;
                         default:
                             if (isset($value)) {
                                 if ($key != "uniqueid" && $key != "organization_domain" && $key != "stamp" && $key != "dialout" && $key != "callback") {
                                     $option .= "{$key}={$value}|";
                                 }
                                 if ($key == "dialout" || $key == "callback" || $key == "exitcontext") {
                                     $option .= "{$key}=" . substr($arrExten["vmcontext"], 16) . "|";
                                 }
                             }
                     }
                     $arrExtension["vmoptions"] = empty($option) ? "" : substr($option, 0, -1);
                 }
             }
         }
         //obtenemos las otras caracticas de la configuracion del dispositivo
         if ($result["tech"] == "iax2") {
             $queryDev = "SELECT context,dial,host,type,allow,disallow,port,qualify,accountcode,deny,permit,language,amaflags,";
             $queryDev .= "defaultip,username,mohinterpret,mohsuggest,transfer,requirecalltoken,mask,jitterbuffer,forcejitterbuffer,";
             $queryDev .= "codecpriority,qualifysmoothing,qualifyfreqok,qualifyfreqnotok,encryption,timezone,sendani,adsi from iax where name=? and organization_domain=?";
         } elseif ($result["tech"] == "sip") {
             $queryDev = "SELECT context,dial,host,type,allow,disallow,port,qualify,accountcode,deny,permit,language,amaflags,";
             $queryDev .= "defaultip,username,mohinterpret,mohsuggest,dtmfmode,nat,allowtransfer,namedcallgroup,namedpickupgroup,";
             $queryDev .= "mailbox,vmexten,defaultuser,useragent,directmedia,sendrpid,trustrpid,transport,callcounter,busylevel,subscribecontext,videosupport,maxcallbitrate,";
             $queryDev .= "qualifyfreq,rtptimeout,rtpholdtimeout,rtpkeepalive,progressinband,g726nonstandard,vmexten from sip where name=?   and organization_domain=?";
         } else {
             $this->errMsg .= _tr("Invalid Technology");
             return false;
         }
         if (isset($queryDev)) {
             $device = $this->_DB->getFirstRowQuery($queryDev, true, array($result["device"], trim($result["organization_domain"])));
             if ($device == false) {
                 $this->errMsg .= _tr("Error getting device settings") . $this->_DB->errMsg;
                 return false;
             } else {
                 foreach ($device as $key => $value) {
                     if (isset($value)) {
                         if ($key == "namedcallgroup" || $key == "namedpickupgroup" || $key == "context" || $key == 'subscribecontext') {
                             $arrExtension[$key] = substr_replace($value, '', 0, strlen($org_code) + 1);
                         } else {
                             $arrExtension[$key] = $value;
                         }
                     }
                 }
             }
         }
         $arrExtension["domain"] = $result["organization_domain"];
         $arrExtension["device"] = $result["device"];
         $pORGZ = new paloSantoOrganization($arrConf['elastix_dsn']['elastix']);
         $orgTmp = $pORGZ->getOrganizationByDomain_Name($result["organization_domain"]);
         if ($orgTmp != false) {
             $astMang = AsteriskManagerConnect($errorM);
             if ($astMang == false) {
                 $this->errMsg .= $errorM;
                 return false;
             } else {
                 $familia = "EXTUSER/" . $orgTmp["code"] . "/" . $result["exten"];
                 $arrExtension["call_waiting"] = $astMang->database_get("CW/" . $orgTmp["code"], $result["exten"]) == "ENABLED" ? "yes" : "no";
                 $arrExtension["screen"] = $astMang->database_get($familia, "screen");
                 $enDictate = $astMang->database_get($familia . "/dictate", "enabled");
                 $arrExtension["dictate"] = $enDictate == "enabled" ? "yes" : "no";
                 $arrExtension["dictformat"] = $astMang->database_get($familia . "/dictate", "format");
                 $arrExtension["dictemail"] = $astMang->database_get($familia . "/dictate", "email");
                 //vmx_locator options
                 $vmx_unavail = $astMang->database_get("{$familia}/vmx/unavail", "state");
                 $vmx_busy = $astMang->database_get("{$familia}/vmx/busy", "state");
                 if ($vmx_unavail == "enabled" || $vmx_busy == "enabled") {
                     $arrExtension["vmx_locator"] = "enabled";
                 } else {
                     $arrExtension["vmx_locator"] = "disabled";
                 }
                 if ($vmx_unavail == "enabled" && $vmx_busy == "enabled") {
                     $arrExtension["vmx_use"] = "both";
                 } else {
                     if ($vmx_unavail == "enabled") {
                         $arrExtension["vmx_use"] = "unavailable";
                     } else {
                         $arrExtension["vmx_use"] = "busy";
                     }
                 }
                 $arrExtension["vmx_extension_0"] = $astMang->database_get($familia . "/vmx/0", "ext");
                 if (isset($arrExtension["vmx_extension_0"]) && $arrExtension["vmx_extension_0"] != "") {
                     $arrExtension["vmx_operator"] = "off";
                 } else {
                     $arrExtension["vmx_operator"] = "on";
                 }
                 $arrExtension["vmx_extension_1"] = $astMang->database_get($familia . "/vmx/1", "ext");
                 $arrExtension["vmx_extension_2"] = $astMang->database_get($familia . "/vmx/2", "ext");
             }
         }
     }
     return $arrExtension;
 }
 function deleteOrganizationPBX($domain, $code)
 {
     require_once "/var/lib/asterisk/agi-bin/phpagi-asmanager.php";
     // 1. Eliminar las entradas dentro de astDB que correspondan a la organizacion
     // 2. actualizamos los  registros de los did que  hayan pertenecido a una organizacion
     $queryd = "UPDATE did set organization_domain=NULL where organization_domain=?";
     if ($this->_DB->genQuery($queryd, array($domain)) == false) {
         $this->errMsg .= $this->_DB->errMsg;
         return false;
     }
     //borramos las entradas de la organizacion dentro de astDB
     $errorMng = "";
     $astMang = AsteriskManagerConnect($errorMng);
     if ($astMang == false) {
         $this->errMsg = $errorMng;
         return false;
     } else {
         $result = $astMang->database_delTree("EXTUSER/" . $code);
         $result = $astMang->database_delTree("DEVICE/" . $code);
         $result = $astMang->database_delTree("DND/" . $code);
         $result = $astMang->database_delTree("CALLTRACE/" . $code);
         $result = $astMang->database_delTree("CFU/" . $code);
         $result = $astMang->database_delTree("CFB/" . $code);
         $result = $astMang->database_delTree("CF/" . $code);
         $result = $astMang->database_delTree("CW/" . $code);
         $result = $astMang->database_delTree("BLACKLIST/" . $code);
         $result = $astMang->database_delTree("QPENALTY/" . $code);
     }
     $astMang->disconnect();
     return true;
 }
 function deleteQueue($qname)
 {
     if ($this->validateQueuePBX() == false) {
         return false;
     }
     $query = "SELECT count(name) from queue where name=? and organization_domain=?";
     $result = $this->_DB->getFirstRowQuery($query, false, array($qname, $this->domain));
     if ($result === false) {
         $this->errMsg = $this->_DB->errMsg;
         return false;
     } else {
         if ($result[0] = 0) {
             $this->errMsg = _tr("Queue doesn't exist");
             return false;
         }
     }
     //si existe la cola borramos los miembros estaticos que pertencen a esa cola
     $query = "DELETE from queue_member where queue_name=?";
     $result = $this->executeQuery($query, array($qname));
     if ($result) {
         if ($result == false) {
             $this->errMsg = _tr("Error deleting Queue Members. ") . $this->errMsg;
             return false;
         }
     }
     $query = "DELETE from queue where name=? and organization_domain=?";
     $result = $this->executeQuery($query, array($qname, $this->domain));
     if ($result) {
         if ($result == false) {
             $this->errMsg = _tr("Error deleting Queue. ") . $this->errMsg;
             return false;
         }
     }
     $code = $this->code;
     //borramos los datos de la cola de la base ast_db
     $astMang = AsteriskManagerConnect($errorM);
     if ($astMang == false) {
         $this->errMsg .= $errorM;
         return false;
     } else {
         $result = $astMang->database_delTree("QPENALTY/{$code}/{$qname}");
         if (strtoupper($result["Response"]) == "ERROR") {
             $this->errMsg .= _tr("Error deleting estatic members from queue. ");
             return false;
         }
     }
     return true;
 }
Пример #9
0
 function TranferCall($extension_to_transfer, $dial, $context, $code)
 {
     //validamos $extension_to_transfer, $context, $callerid
     if (count(preg_split("/[\r\n]+/", $extension_to_transfer)) > 1) {
         $this->errMsg = _tr("Invalid parameter");
         return false;
     }
     if (count(preg_split("/[\r\n]+/", $context)) > 1) {
         $this->errMsg = _tr("Invalid parameter");
         return false;
     }
     if (count(preg_split("/[\r\n]+/", $dial)) > 1) {
         $this->errMsg = _tr("Invalid parameter");
         return false;
     }
     $context = "{$code}-{$context}";
     exec("/usr/sbin/asterisk -rx 'core show channels concise' | grep ^" . escapeshellarg($dial), $arrConsole, $flagStatus);
     if ($flagStatus == 0) {
         foreach ($arrConsole as $data) {
             $arrData = explode("!", $data);
             $channel = explode("-", $arrData[0]);
             if ($channel[0] == $dial) {
                 $channel_to_transfer = $arrData[12];
                 $astMang = AsteriskManagerConnect($errorM);
                 if ($astMang == false) {
                     $this->errMsg = $errorM;
                     return false;
                 } else {
                     $salida = $astMang->Redirect($channel_to_transfer, "", $extension_to_transfer, $context, $priority = 1);
                     $astMang->disconnect();
                     if (strtoupper($salida["Response"]) != "ERROR") {
                         return true;
                     } else {
                         return false;
                     }
                 }
             }
         }
         $this->errMsg = "Can't find the channel";
         return false;
     }
     $this->errMsg = "Can't find the channel";
     return false;
 }
 function deleteAstDBExt($exten, $tech)
 {
     //validamos que la instacia del objeto haya sido creada correctamente
     if (!$this->validatePaloDevice()) {
         return false;
     }
     $errorM = "";
     $astMang = AsteriskManagerConnect($errorM);
     if ($astMang == false) {
         $this->errMsg = $errorM;
         return false;
     } else {
         //borro las propiedades dentro de la base ASTDB de asterisk
         //obtenemos la lista de los dispositivos relacionados con la tecnologia
         //$deviceDB=$astMang->database_get("EXTUSER",$this->code."/$exten/device");
         //$device_arr = explode('&',$deviceDB);
         //foreach($device_arr as $device){
         $result = $astMang->database_delTree("DEVICE/{$this->code}/{$this->code}_{$exten}");
         //}
         $result = $astMang->database_delTree("EXTUSER/" . $this->code . "/" . $exten);
         $result = $astMang->database_del("DND", $this->code . "/" . $exten);
         $result = $astMang->database_del("CALLTRACE", $this->code . "/" . $exten);
         $result = $astMang->database_del("CFU", $this->code . "/" . $exten);
         $result = $astMang->database_del("CFB", $this->code . "/" . $exten);
         $result = $astMang->database_del("CF", $this->code . "/" . $exten);
         $result = $astMang->database_del("CW", $this->code . "/" . $exten);
         $astMang->disconnect();
     }
     return true;
 }
Пример #11
0
function showCallers($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials)
{
    global $arrPermission;
    $error = "";
    $success = false;
    $id_conf = getParameter("id_conf");
    $domain = getParameter('organization');
    if ($credentials['userlevel'] != 'superadmin') {
        $domain = $credentials['domain'];
    }
    $pConf = new paloConference($pDB, $domain);
    $conference = $pConf->getConferenceById($id_conf);
    if ($conference == false) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", $pConf->errMsg);
        return reportConference($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    } else {
        $date = time();
        if ($date >= strtotime($conference["startTime"]) && $date <= strtotime($conference["endtime"]) || $conference["startTime"] == "1900-01-01 12:00:00") {
            $room = $conference["confno"];
            $total = $conference["members"];
        } else {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr("Conference out of Time"));
            return reportConference($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        }
    }
    $limit = 20;
    $oGrid = new paloSantoGrid($smarty);
    $oGrid->setLimit($limit);
    $oGrid->setTotal($total);
    $offset = $oGrid->calculateOffset();
    $end = $offset + $limit <= $total ? $offset + $limit : $total;
    $oGrid->setTitle(_tr('Conference') . ": {$conference['name']} ({$conference['ext_conf']})");
    //$oGrid->setIcon('url de la imagen');
    $oGrid->setWidth("99%");
    $oGrid->setStart($total == 0 ? 0 : $offset + 1);
    $oGrid->setEnd($end);
    $oGrid->setTotal($total);
    $oGrid->setURL($url = "?menu={$module_name}&action=current_conf&id_conf={$id_conf}");
    //permission
    $invite_part = in_array("admin_conference_participant", $arrPermission);
    $arrColum = array();
    $arrColum[] = _tr("Orden Join");
    $arrColum[] = _tr("CallerId");
    $arrColum[] = _tr("Time in Conference");
    $arrColum[] = _tr("Mode");
    if ($invite_part) {
        $arrColum[] = "<input type='button' name='mute_caller' value=" . _tr("Mute") . " class='button' onclick='javascript:muteCaller()'/>";
        $msgKill = _tr("Are you sure you wish to Kick all caller (s)?");
        $arrColum[] = "<input type='button' name='kick_caller' value=" . _tr("Kick") . " class='button' onclick=\"javascript:kickCaller('{$msgKill}');\"/>";
    }
    $oGrid->setColumns($arrColum);
    $arrData = array();
    $arrMemb = array();
    if ($total != 0) {
        $arrMemb = $pConf->ObtainCallers($room);
    }
    $session = getSession();
    if ($arrMemb === false) {
        $error = _tr("Error getting conference data.") . $pConf->errMsg;
    } else {
        $membPagg = array_slice($arrMemb, $offset, $limit);
        foreach ($membPagg as $memb) {
            $arrTmp = array();
            $arrTmp[0] = $memb['userId'];
            $arrTmp[1] = trim($memb['callerId']);
            $arrTmp[2] = $memb['duration'];
            $arrTmp[3] = empty($memb['mode']) ? "user" : "admin";
            if ($invite_part) {
                $status = strstr($memb['status'], "Muted");
                //falso si no encuentra la palabra en el arreglo
                $checked = empty($status) ? "" : "checked";
                $arrTmp[4] = "<input type='checkbox' name=mute_{$memb['userId']} class='conf_mute' {$checked}>";
                $arrTmp[5] = "<input type='checkbox' name=kick_{$memb['userId']} class='conf_kick'>";
            }
            $arrData[] = $arrTmp;
            //se usa para comprobar si ha habido cambios en el estado de las conferencias
            $session['conference']["current_conf"][$memb['userId']] = $memb['callerId'];
        }
    }
    //se escribe en session el estado actual de las conferencias
    if (!isset($session['conference']["current_conf"])) {
        $session['conference']["current_conf"] = array();
    }
    putSession($session);
    //filters
    $extens = $pConf->getAllDevice($domain);
    $arrExten = array("" => "--unselected--");
    if ($extens != false) {
        $astMang = AsteriskManagerConnect($errorM);
        $result = $pConf->getCodeByDomain($domain);
        foreach ($extens as $value) {
            $cidname = "";
            if ($astMang != false && $result != false) {
                $cidname = $astMang->database_get("EXTUSER/" . $result["code"] . "/" . $value["exten"], "cidname");
            }
            $arrExten[$value["dial"]] = isset($cidname) ? $cidname . " <{$value["exten"]}>" : $value["exten"] . " ({$value["dial"]})";
        }
    }
    if ($invite_part) {
        $oGrid->addComboAction("invite_caller", _tr("Invite Caller"), $arrExten, "Invite Caller to Conference", "invite_caller", "javascript:inviteCaller()");
        $oGrid->addButtonAction("kick_all", $alt = "Kick All Callers", "../web/_common/images/delete5.png", "javascript:kickAll('{$msgKill}')");
        $oGrid->addButtonAction("mute_all", $alt = "Mute All Callers", null, "javascript:muteAll()");
    }
    if ($error != "") {
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", $error);
    }
    $contenidoModulo = $oGrid->fetchGrid(array(), $arrData);
    $contenidoModulo .= "<input type='hidden' name='id_conf' id='id_conf' value='{$id_conf}'>";
    $contenidoModulo .= "<input type='hidden' name='organization' id='organization' value='{$domain}'>";
    $contenidoModulo .= "<input type='hidden' name='grid_limit' id='grid_limit' value='{$limit}'>";
    $contenidoModulo .= "<input type='hidden' name='grid_offset' id='grid_offset' value='{$offset}'>";
    $contenidoModulo .= "<input type='hidden' name='conf_action' id='conf_action' value='showCallers'>";
    return $contenidoModulo;
}
Пример #12
0
function createFieldForm($goto, $destination, $pDB, $domain)
{
    $pRG = new paloSantoRG($pDB, $domain);
    $strategy = array('ringall' => 'ringall', 'ringall-prim' => 'ringall-prim', 'hunt' => 'hunt', 'hunt-prim' => 'hunt-prim', 'memoryhunt' => 'memoryhunt', 'memoryhunt-prim' => 'memoryhunt-prim', 'firstavailable' => 'firstavailable', 'firstnotonphone' => 'firstnotonphone');
    $time = generateOptionNum(1, 60);
    $arrYesNo = array(_tr("yes") => _tr("Yes"), "no" => "No");
    $arrRecording = $pRG->getRecordingsSystem($domain);
    $arrMoH = $pRG->getMoHClass($domain);
    $recording = array(_tr("none") => _tr("None"));
    $recording2 = array("default" => "Default");
    if (is_array($arrRecording)) {
        foreach ($arrRecording as $key => $value) {
            $recording[$key] = $value;
            $recording2[$key] = $value;
        }
    }
    $arrMusic = array("ring" => _tr("Only Ring"));
    if (is_array($arrMoH)) {
        foreach ($arrMoH as $key => $value) {
            $arrMusic[$key] = $value;
        }
    }
    $extens = $pRG->getAllDevice($domain);
    $arrExten = array("" => _tr("--unselected--"));
    if ($extens != false) {
        $astMang = AsteriskManagerConnect($errorM);
        $result = $pRG->getCodeByDomain($domain);
        foreach ($extens as $value) {
            $cidname = "";
            if ($astMang != false && $result != false) {
                $cidname = $astMang->database_get("EXTUSER/" . $result["code"] . "/" . $value["exten"], "cidname");
            }
            $arrExten[$value["exten"]] = isset($cidname) ? $cidname . " <{$value["exten"]}>" : $value["exten"] . " ({$value["dial"]})";
        }
    }
    $arrFormElements = array("rg_name" => array("LABEL" => _tr('Name'), "DESCRIPTION" => _tr("Name"), "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => array("style" => "width:200px"), "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_number" => array("LABEL" => _tr("Number"), "DESCRIPTION" => _tr("Number"), "REQUIRED" => "yes", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => array("style" => "width:200px"), "VALIDATION_TYPE" => "numeric", "VALIDATION_EXTRA_PARAM" => ""), "rg_strategy" => array("LABEL" => _tr("Strategy"), "DESCRIPTION" => _tr("Strategy"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $strategy, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_alertinfo" => array("LABEL" => _tr("Alert Info"), "DESCRIPTION" => _tr("RG_alertinfo"), "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => array("style" => "width:100px"), "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_cid_prefix" => array("LABEL" => _tr("CID Name Prefix"), "DESCRIPTION" => _tr("RG_cidnameprefix"), "REQUIRED" => "no", "INPUT_TYPE" => "TEXT", "INPUT_EXTRA_PARAM" => array("style" => "width:100px"), "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_moh" => array("LABEL" => _tr("Music On Hold"), "DESCRIPTION" => _tr("RG_musiconhold"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrMusic, "VALIDATION_TYPE" => "", "VALIDATION_EXTRA_PARAM" => ""), "rg_time" => array("LABEL" => _tr("Ring Time"), "DESCRIPTION" => _tr("Ring Time"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $time, "VALIDATION_TYPE" => "numeric", "VALIDATION_EXTRA_PARAM" => ""), "goto" => array("LABEL" => _tr("Destine"), "DESCRIPTION" => _tr("RG_destine"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $goto, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "destination" => array("LABEL" => _tr(""), "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $destination, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_cf_ignore" => array("LABEL" => _tr("Ignore CF"), "DESCRIPTION" => _tr("RG_ignorecallforward"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrYesNo, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_skipbusy" => array("LABEL" => _tr("Skip Busy Extensions"), "DESCRIPTION" => _tr("RG_skipbusyextension"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrYesNo, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_pickup" => array("LABEL" => _tr("Enable Call Pickup"), "DESCRIPTION" => _tr("RG_enablecallpickup"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrYesNo, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_confirm_call" => array("LABEL" => _tr("Confirm Call"), "DESCRIPTION" => _tr("RG_confirmcall"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrYesNo, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_recording" => array("LABEL" => _tr("Recording"), "DESCRIPTION" => _tr("RG_recording"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $recording, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_record_remote" => array("LABEL" => _tr("Recording Remote"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $recording2, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_record_toolate" => array("LABEL" => _tr("Recording Too Late"), "REQUIRED" => "yes", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $recording2, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""), "rg_extensions" => array("LABEL" => _tr("Extensions List"), "DESCRIPTION" => _tr("RG List"), "REQUIRED" => "no", "INPUT_TYPE" => "TEXTAREA", "INPUT_EXTRA_PARAM" => array("style" => "width:200px;resize:none"), "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => "", "ROWS" => "5", "COLS" => "2"), "pickup_extensions" => array("LABEL" => _tr(""), "REQUIRED" => "no", "INPUT_TYPE" => "SELECT", "INPUT_EXTRA_PARAM" => $arrExten, "VALIDATION_TYPE" => "text", "VALIDATION_EXTRA_PARAM" => ""));
    return $arrFormElements;
}
 function actDesacTrunk($id, $action)
 {
     if (!preg_match('/^[[:digit:]]+$/', "{$id}")) {
         $this->errMsg = _tr("Invalid Trunk ID");
         return false;
     }
     $query = "SELECT channelid,sec_call_time from trunk where trunkid=?";
     $result = $this->_DB->getFirstRowQuery($query, true, array($id));
     if ($result === false || count($result) == 0) {
         $this->errMsg = _tr("Trunk doesn't exist. ") . $this->_DB->errMsg;
         return false;
     }
     $action = $action == "on" ? "on" : "off";
     //cambiamos en la base de datos el parametro disabled
     $query = "Update trunk set disabled=? where trunkid=?";
     if ($this->_DB->genQuery($query, array($action, $id)) == false) {
         $this->errMsg .= _tr("Trunk can't be enabled. ") . $this->_DB->errMsg;
         return false;
     }
     $astMang = AsteriskManagerConnect($errorM);
     if ($astMang == false) {
         $this->errMsg = $errorM;
         return false;
     } else {
         if ($action == "off") {
             //borro las propiedades dentro de la base ASTDB de asterisk
             if ($result["sec_call_time"] == "yes") {
                 $result = $astMang->database_del("TRUNK/{$id}/COUNT_TIME", "BLOCK");
                 $result = $astMang->database_del("TRUNK/{$id}/COUNT_TIME", "NUM_FAIL");
                 $astMang->database_put("TRUNK/{$id}/COUNT_TIME", "COUNT", 0);
             }
             $result = $astMang->database_del("TRUNK/{$id}", "OUTDISABLE");
         } else {
             $astMang->database_put("TRUNK/{$id}", "OUTDISABLE", "on");
             $astMang->disabled;
         }
     }
     return true;
 }