function Obtain_Protocol($extension) { if ($extension) { $dsnAsterisk = generarDSNSistema('asteriskuser', 'asterisk'); $pDB = new paloDB($dsnAsterisk); $query = "SELECT dial, description, id FROM devices WHERE id=?"; $result = $pDB->getFirstRowQuery($query, TRUE, array($extension)); if ($result != FALSE) { return $result; } else { return FALSE; } } else { return FALSE; } }
/** * Procedimiento para obtener los datos de la extension usada por el usuario dentro de asterisk * @param int $idUser Id del usuario del que se quiere obtener los datos de su extension * @return array $ext Devuelte un arreglo donde esta el numero de la extension, la tegnologia usada y el nombre del dispositivo usado */ function getExtUser($id_user) { $arr_result2 = array(); $pDB2 = new paloDB(generarDSNSistema("asteriskuser", "elxpbx")); if (!preg_match('/^[[:digit:]]+$/', "{$id_user}")) { $this->errMsg = _tr("User ID must be numeric"); } else { $query = "SELECT a.extension, (Select domain from organization o where o.id=g.id_organization) FROM acl_user as a JOIN acl_group as g on a.id_group=g.id where a.id=?"; $arr_result = $this->_DB->getFirstRowQuery($query, false, array($id_user)); if ($arr_result === false) { $this->errMsg = _tr("Can't get extension user") . $this->_DB->errMsg; } elseif (count($arr_result) == 0) { $this->errMsg = _tr("User doesn't have a associated extension"); } else { $query2 = "SELECT id, exten, organization_domain, tech, dial, voicemail, device FROM extension where exten=? and organization_domain=?"; $arr_result2 = $pDB2->getFirstRowQuery($query2, true, array($arr_result[0], $arr_result[1])); if (!is_array($arr_result2) || count($arr_result2) == 0) { $this->errMsg = _tr("Can't get extension user") . $pDB2->errMsg; } } } return $arr_result2; }
function saveNeoToggleTabByUser($menu, $action_status) { include_once "libs/paloSantoACL.class.php"; $arrResult['status'] = FALSE; $arrResult['msg'] = _tr("Please your session id does not exist. Refresh the browser and try again."); if ($menu != "") { $user = isset($_SESSION['elastix_user']) ? $_SESSION['elastix_user'] : ""; global $arrConf; $pdbACL = new paloDB("sqlite3:///{$arrConf['elastix_dbdir']}/acl.db"); $pACL = new paloACL($pdbACL); $uid = $pACL->getIdUser($user); if ($uid !== FALSE) { $exist = false; $togglesTabs = "SELECT * FROM acl_user_shortcut WHERE id_user = ? AND type = 'NeoToggleTab'"; $arr_result1 = $pdbACL->getFirstRowQuery($togglesTabs, TRUE, array($uid)); if ($arr_result1 !== FALSE && count($arr_result1) > 0) { $exist = true; } if ($exist) { $pdbACL->beginTransaction(); $query = "UPDATE acl_user_shortcut SET description = ? WHERE id_user = ? AND type = ?"; $r = $pdbACL->genQuery($query, array($action_status, $uid, "NeoToggleTab")); if (!$r) { $pdbACL->rollBack(); $arrResult['status'] = FALSE; $arrResult['msg'] = _tr("Request cannot be completed. Please try again or contact with your elastix administrator and notify the next error: ") . $pdbACL->errMsg; return $arrResult; } else { $pdbACL->commit(); $arrResult['status'] = TRUE; $arrResult['msg'] = _tr("Request has been sent."); return $arrResult; } } else { $pdbACL->beginTransaction(); $query = "INSERT INTO acl_user_shortcut(id_user, id_resource, type, description) VALUES(?, ?, ?, ?)"; $r = $pdbACL->genQuery($query, array($uid, $uid, "NeoToggleTab", $action_status)); if (!$r) { $pdbACL->rollBack(); $arrResult['status'] = FALSE; $arrResult['msg'] = _tr("Request cannot be completed. Please try again or contact with your elastix administrator and notify the next error: ") . $pdbACL->errMsg; return $arrResult; } else { $pdbACL->commit(); $arrResult['status'] = TRUE; $arrResult['msg'] = _tr("Request has been sent."); return $arrResult; } } } } return $arrResult; }
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; }
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 getDataCardRegister($id_card) { global $arrConf; $dsn = "sqlite3:///{$arrConf['elastix_dbdir']}/hardware_detector.db"; $pDB = new paloDB($dsn); $query = "select * from car_system where hwd='{$id_card}'"; $result = $pDB->getFirstRowQuery($query, true); if ($result == FALSE) { $this->errMsg = $pDB->errMsg; return $result; } return "{$result['vendor']},{$result['num_serie']}"; }
function Obtain_Protocol_from_Ext($dsn, $id) { $pDB = new paloDB($dsn); $query = "SELECT dial, description FROM devices WHERE id=?"; $result = $pDB->getFirstRowQuery($query, TRUE, array($id)); if ($result != FALSE) { return $result; } else { $this->errMsg = $pDB->errMsg; return FALSE; } }
function createQueue($arrProp, $arrMembers) { if ($this->validateQueuePBX() == false) { return false; } if (!preg_match("/^[0-9]*\$/", $arrProp["name"])) { $this->errMsg = _tr("Invalid Queue Number"); return false; } //validamos que el numero de la cola no este siendo usado dentro del plan de marcado if ($this->existExtension($arrProp["name"], $this->domain)) { return false; } //validamos que no se haya alcanzado el maximo numero de colas en el servidor global $arrConf; $pDB = new paloDB($arrConf['elastix_dsn']['elastix']); $qOrg = "SELECT value from organization_properties where key=? and category=? and id_organization=(SELECT id from organization where domain=?)"; $res_num_queues = $pDB->getFirstRowQuery($qOrg, false, array("max_num_queues", "limit", $this->domain)); if ($res_num_queues != false) { $max_num_queues = $res_num_queues[0]; if (ctype_digit($max_num_queues)) { if ($max_num_queues != 0) { $numQueues = $this->getTotalQueues($this->domain); if ($numQueues >= $max_num_queues) { $this->errMsg = _tr("Err: You can't create new queues because you have reached the max numbers of queues permitted") . " ({$numQueues}) " . " Contact with the server's admin"; return false; } } } } $arrProp["organization_domain"] = $this->domain; $arrProp["queue_number"] = $arrProp["name"]; if (isset($arrProp["musicclass"])) { if ($arrProp["musicclass"] == "ring") { $arrProp["ringing_detail"] = "yes"; } else { $arrProp["ringing_detail"] = "no"; } if ($arrProp["musicclass"] == "ring" || $arrProp["musicclass"] == "inherit") { $arrProp["musicclass"] = null; } } if (isset($arrProp["monitor_format"])) { if ($arrProp["monitor_format"] == "no") { $arrProp["monitor_format"] = null; } } if (isset($arrProp["retry"])) { if ($arrProp["retry"] == "no_retry") { $arrProp["retry_detail"] = "no"; $arrProp["retry"] = "0"; } else { $arrProp["retry_detail"] = "yes"; } } if (isset($arrProp["skip_busy_detail"])) { if ($arrProp["skip_busy_detail"] == "0" || $arrProp["skip_busy_detail"] == "1") { $arrProp["ringinuse"] = "yes"; } else { $arrProp["ringinuse"] = "no"; } } if (isset($arrProp["min_announce_frequency"])) { if ($arrProp["min_announce_frequency"] == "0") { $arrProp["min_announce_frequency"] = null; } } if (isset($arrProp["announce_detail"])) { if ($arrProp["announce_detail"] == "none") { $arrProp["announce_detail"] = null; } else { //validamos que exista la grabacion y que pertenezca a dicha organizacion $file = $this->getFileRecordings($this->domain, $arrProp["announce_detail"]); if (is_null($file)) { $arrProp["announce_detail"] = null; } } } if (isset($arrProp["announce_caller_detail"])) { if ($arrProp["announce_caller_detail"] == "none") { $arrProp["announce_caller_detail"] = null; } else { //validamos que exista la grabacion y que pertenezca a dicha organizacion $file = $this->getFileRecordings($this->domain, $arrProp["announce_caller_detail"]); if (is_null($file)) { $arrProp["announce_caller_detail"] = null; } } } if (isset($arrProp["destination_detail"])) { if ($this->validateDestine($this->domain, $arrProp["destination_detail"]) == false) { $arrProp["destination_detail"] = null; } } if ($this->insertQueueDB($arrProp) == false) { $this->errMsg = _tr("Error trying created queue. ") . $this->errMsg; return false; } $code = $this->code; //insertamos los miembros a la cola //los miembros pueden ser de tipo dinamico o estaticos //si son de tipo dinamico los tenemos que registrar en la base ast_db //si son de tipos estaticos se deben registrar en la tabla queue_member $queryExt = "SELECT dial from extension where organization_domain=? and exten=?"; $queryIn = "INSERT INTO queue_member (queue_name,membername,interface,penalty,state_interface,exten) values(?,?,?,?,?,?)"; if (isset($arrMembers["static_members"])) { $arrMember = array(); $members = explode("\n", $arrMembers["static_members"]); foreach ($members as $value) { if (preg_match("/([0-9]+)((,)([0-9]+)){0,1}/", $value, $match)) { $exten = $match[1]; $penalty = isset($match[4]) ? $match[4] : 0; $interfaz = "Local/{$exten}@{$code}-from-queue/n"; //buscamos si el numero de extension introducio pertenece a una extension definida dentro del sistema //en ese caso obtenemos la interfaz de la extension $result = $this->_DB->getFirstRowQuery($queryExt, true, array($this->domain, $exten)); if ($result != false) { $state_int = $result["dial"]; } else { $state_int = "hint:{$exten}@{$code}-ext-local"; } $exito = $this->executeQuery($queryIn, array($code . "_" . $arrProp["name"], $exten, $interfaz, $penalty, $state_int, $exten)); if ($exito == false) { $this->errMsg = _tr("Error insert queue_members. ") . $this->errMsg; return false; } } } } $error = false; if (isset($arrMembers["dynamic_members"])) { $astMang = AsteriskManagerConnect($errorM); if ($astMang == false) { $this->errMsg .= $errorM; return false; } $familia = "QPENALTY/{$code}/{$code}" . "_" . $arrProp["name"] . "/agents"; $arrMember = array(); $members = explode("\n", $arrMembers["dynamic_members"]); foreach ($members as $value) { if (preg_match("/([0-9]+)((,)([0-9]+)){0,1}/", $value, $match)) { $exten = $match[1]; $penalty = isset($match[4]) ? $match[4] : 0; $result = $astMang->database_put($familia, $exten, $penalty); if (strtoupper($result["Response"]) == "ERROR") { $error = true; break; } } } } $dinamic = "no"; if (isset($arrProp["restriction_agent"])) { if ($arrProp["restriction_agent"] == "yes") { $dinamic = "yes"; } } $result = $astMang->database_put("QPENALTY/{$code}/{$code}" . "_" . $arrProp["name"], "dynmemberonly", $dinamic); if (strtoupper($result["Response"]) == "ERROR") { $error = true; } if ($error) { $this->errMsg = _tr("Error setting queue_member. ") . $this->errMsg; $result = $astMang->database_delTree("QPENALTY/{$code}/{$code}" . "_" . $arrProp["name"]); return false; } else { return true; } }
function paloContexto($code, $name) { global $arrConf; //valido que el codigo exista $pDB = new paloDB($arrConf['elastix_dsn']['elastix']); $queryCode = "SELECT count(code) from organization where code=?"; $recode = $pDB->getFirstRowQuery($queryCode, false, array($code)); if ($recode === false) { $this->errMsg = $pDB->errMsg; return false; } elseif (count($recode) == 0) { $this->errMsg = _tr("Organization doesn't exist"); return false; } $this->code = $code; if (preg_match("/^[A-Za-z0-9\\-_]+\$/", $name) || strlen($name) > 62) { if (substr($name, 0, 6) == "macro-") { $this->name = "[macro-" . $this->code . "-" . substr($name, 6) . "]"; } else { $this->name = "[" . $this->code . "-" . $name . "]"; } } else { $this->errMsg = _tr("Context names cannot contain special characters and have a maximum length of 62 characters"); return false; } }
private function _checkEmailPassword($email, $password) { global $arrConf; $pDB = new paloDB("sqlite3:///{$arrConf['elastix_dbdir']}/email.db"); $tupla = $pDB->getFirstRowQuery('SELECT password FROM accountuser WHERE username = ?', TRUE, array($email)); if (!is_array($tupla)) { $this->errMsg = $this->_DB->errMsg; return FALSE; } if (count($tupla) <= 0) { return FALSE; } return $password == $tupla['password']; }
/** funcion que sirve para obtener las credenciales de un usuario @return Array => ( idUser => (idUser or ""), id_organization => (ID_ORG or false), userlevel => (superadmin,organization), domain => (dominio de la ORG or false) ) */ function getUserCredentials($username) { global $arrConf, $elxPath; require_once "{$elxPath}/libs/paloSantoACL.class.php"; $pdbACL = new paloDB($arrConf['elastix_dsn']['elastix']); $pACL = new paloACL($pdbACL); $userLevel1 = "other"; $idOrganization = $domain = false; $idUser = $pACL->getIdUser($username); if ($idUser != false) { $idOrganization = $pACL->getIdOrganizationUser($idUser); if ($idOrganization != false) { if ($pACL->isUserSuperAdmin($username)) { $userLevel1 = "superadmin"; } elseif ($pACL->isUserAdministratorGroup($username)) { $userLevel1 = "admin"; } } } if ($idOrganization != false) { //obtenemos el dominio de las organizacion $query = "SELECT domain from organization where id=?"; $result = $pdbACL->getFirstRowQuery($query, false, array($idOrganization)); if ($result == false) { $domain = false; } else { if (!preg_match("/^(([[:alnum:]-]+)\\.)+([[:alnum:]])+\$/", $result[0])) { $domain = false; } else { $domain = $result[0]; } } } return array("idUser" => $idUser, "id_organization" => $idOrganization, "userlevel" => $userLevel1, "domain" => $domain); }