示例#1
0
文件: functions.php 项目: Peaso/CER
function checkTokenESB($token)
{
    global $debugar;
    if ($debugar) {
        echo 'checkTokenESB(): checking token "' . $token . '".<br />' . "\n";
    }
    if (!isset($token)) {
        if ($debugar) {
            echo 'checkTokenESB(): KO, empty token.<br />' . "\n";
        }
        $token = isset($_REQUEST['token']) ? $_REQUEST['token'] : null;
    }
    if ($token == NULL) {
        if ($debugar) {
            echo 'checkTokenESB(): KO, null token.<br />' . "\n";
        }
        $output[] = array('errorNumber' => 1, 'errorText' => 'Identification token is required');
        echo json_encode($output);
        die;
    } else {
        // Check credentials in EBS
        // http://esb.exactls.com/collage/cas/user?token=ST-114-vC2Gb1k1vDGgxlkoefFm-cas01.example.org
        // If the token is invalid, file_get_contents raises an error.
        $credentials = getUserCredentials($token);
        if ($debugar) {
            echo 'checkTokenESB(): downloaded credentials: "' . print_r($credentials, TRUE) . '".<br />' . "\n";
        }
        return $credentials;
    }
}
示例#2
0
function _moduleContent(&$smarty, $module_name)
{
    //folder path for custom templates
    $local_templates_dir = getWebDirModule($module_name);
    //user credentials
    $arrCredentiasls = getUserCredentials($_SESSION['elastix_user']);
    //user permissions
    global $arrPermission;
    $arrPermission = getResourceActionsByUser($arrCredentiasls['idUser'], $module_name);
    if ($arrPermission == false) {
        header("Location: index.php");
    }
    //actions
    $action = getAction();
    $content = "";
    switch ($action) {
        case "save_new":
            $content = saveApplets_Admin($module_name);
            break;
        default:
            // view_form
            $content = showApplets_Admin($module_name);
            break;
    }
    return $content;
}
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;
}
 /**
  * Functional point that deletes a document fax of the database, and deletes also the PDF document associated to the fax if exist
  *
  * @param   integer      $id        ID of the fax to be deleted
  * @return  boolean      true if the document fax was deleted, false if an error exists
  */
 function delFaxDoc($id)
 {
     if (!$this->_checkUserAuthorized('faxviewer')) {
         return false;
     }
     // Verificar presencia de ID del fax
     if (!isset($id) || !preg_match('/^\\d+$/', $id)) {
         $this->errMsg["fc"] = 'PARAMERROR';
         $this->errMsg["fm"] = 'Invalid ID';
         $this->errMsg["fd"] = 'Fax ID must be nonnegative integer';
         $this->errMsg["cn"] = get_class($this);
         return false;
     }
     $id = (int) $id;
     //obtenemos las credenciales del usuario
     $arrCredentials = getUserCredentials();
     // Borrar el registro y el documento de fax, dado su ID
     $oFax = new paloFaxVisor();
     $bExito = $oFax->deleteInfoFax($id, $arrCredentials["id_organization"]);
     if (!$bExito) {
         $this->errMsg["fm"] = 'Database operation failed';
         $this->errMsg["cn"] = get_class($oFax);
         if ($oFax->errMsg != '') {
             $this->errMsg["fc"] = 'DBERROR';
             $this->errMsg["fd"] = 'Unable to delete fax information - ' . $oFax->errMsg;
         } else {
             $this->errMsg["fc"] = 'INTERNALERROR';
             $this->errMsg["fd"] = 'Unable to delete fax document';
         }
     }
     return $bExito;
 }
示例#5
0
function handleJSON_changeImageProfile($smarty, $module_name)
{
    global $arrConf;
    Header('Content-Type: application/json');
    $arrCredentials = getUserCredentials($_SESSION['elastix_user']);
    $pDB = new paloDB($arrConf['elastix_dsn']["elastix"]);
    $pACL = new paloACL($pDB);
    $jsonObject = new PaloSantoJSON();
    $idUser = $arrCredentials['idUser'];
    foreach ($_FILES['picture']['error'] as $key => $error) {
        if ($error == UPLOAD_ERR_OK) {
            $pictureUpload = $_FILES['picture']['name'][$key];
            if (!preg_match("/^(\\w|-|\\.|\\(|\\)|\\s)+\\.(png|PNG|JPG|jpg|JPEG|jpeg)\$/", $pictureUpload)) {
                $jsonObject->set_error(_tr("Invalid file extension.- It must be png or jpg or jpeg"));
                return $jsonObject->createJSON();
            } elseif (preg_match("/(\\.php)/", $pictureUpload)) {
                $jsonObject->set_error(_tr("Possible file upload attack."));
                return $jsonObject->createJSON();
            } else {
                if (is_uploaded_file($_FILES['picture']['tmp_name'][$key])) {
                    $ancho = 159;
                    $alto = 159;
                    redimensionarImagen($_FILES['picture']['tmp_name'][$key], $_FILES['picture']['tmp_name'][$key], $ancho, $alto);
                    $picture_type = $_FILES['picture']['type'][$key];
                    $picture_content = file_get_contents($_FILES['picture']['tmp_name'][$key]);
                    $Exito = $pACL->setUserPicture($idUser, $picture_type, $picture_content);
                    if ($Exito === false) {
                        $jsonObject->set_error(_tr("Image couldn't be upload."));
                        return $jsonObject->createJSON();
                    }
                } else {
                    $jsonObject->set_error(_tr("Possible file upload attack. Filename") . " : " . $pictureUpload);
                    return $jsonObject->createJSON();
                }
            }
            $url = "index.php?menu=_elastixutils&action=getImage&ID={$idUser}&rawmode=yes";
            $jsonObject->set_message($url);
            return $jsonObject->createJSON();
        }
    }
    return $jsonObject->createJSON();
}
 private function includeModule($module)
 {
     global $arrConf;
     //comprobamos que exista el index del modulo
     if (!file_exists("{$arrConf['elxPath']}/apps/{$module}/index.php")) {
         return array('data' => "Error: The module <b>{$arrConf['elxPath']}/apps/{$module}/index.php</b> could not be found!<br/>");
     }
     require_once "apps/{$module}/index.php";
     //si existe el archivo de configuracion del modulo se los incluye y se cargan las configuraciones
     //especificas del modulo elegido
     if (file_exists("{$arrConf['elxPath']}/apps/{$module}/configs/default.conf.php")) {
         include_once "apps/{$module}/configs/default.conf.php";
         global $arrConf;
         global $arrConfModule;
         if (is_array($arrConfModule)) {
             $arrConf = array_merge($arrConf, $arrConfModule);
         }
     }
     //se incluyen las librerias que esten dentro de apps/$module/libs
     $dirLibs = "{$arrConf['elxPath']}/apps/{$module}/libs";
     if (is_dir($dirLibs)) {
         $arr_libs = $this->obtainFiles($dirLibs, "class.php");
         if ($arr_libs != false && count($arr_libs) > 0) {
             for ($i = 0; $i < count($arr_libs); $i++) {
                 include_once "apps/{$module}/libs/" . $arr_libs[$i];
             }
         }
     }
     // Cargar las traducciones para el módulo elegido
     load_language_module($module);
     // Cargar las creadenciales del usuario
     global $arrCredentials;
     $arrCredentials = getUserCredentials($_SESSION['elastix_user']);
     if ($arrCredentials == false) {
         return array('data' => "Error to load User Credentials: {$_SESSION['elastix_user']}");
     }
     //cargar los permisos del modulo
     global $arrPermission;
     $arrPermission = getResourceActionsByUser($arrCredentials['idUser'], $module);
     if ($arrPermission == false) {
         return array('data' => "Error to load Module Permissions: {$module}");
     }
     if (!function_exists("_moduleContent")) {
         return array('data' => "Wrong module: apps/{$module}/index.php");
     }
     $CssJsModule = $this->putHEAD_MODULE_HTML($module);
     $moduleContent = _moduleContent($this->_smarty, $module);
     return array("data" => $moduleContent, "JS_CSS_HEAD" => $CssJsModule);
 }