/**
  * Procedimiento que actualiza los passwords de un usuario dentro de elastix
  * La calve ingresada sera configurada para la cuenta de interfaz web, para su cuenta
  * de email, su secret en el caso de las extensiones sip e iax
  */
 function changeUserPassword($username, $password)
 {
     $pEmail = new paloEmail($this->_DB);
     $pFax = new paloFax($this->_DB);
     $pACL = new paloACL($this->_DB);
     //comprobamos que la calve este seteada y sea una clave fuerte
     //verificamos que la nueva contraseña sea fuerte
     if (!isStrongPassword($password)) {
         $this->errMsg = _tr("The new password can not be empty. It must have at least 10 characters and contain digits, uppers and little case letters");
         return false;
     }
     //obtenemos la conversion md5 de la clave
     $md5_password = md5($password);
     //verficamos que el usuario exista
     $idUser = $pACL->getIdUser($username);
     if ($idUser == false) {
         $this->errMsg = $pACL->errMsg == '' ? _tr("User does not exist") : _tr("DATABASE ERROR");
         return false;
     }
     //obtenemos los datos del usuario
     //extension de fax y de telefonia
     $arrUser = $pACL->getUsers($idUser);
     if ($arrUser == false) {
         $this->errMsg = $arrUser === false ? _tr("DATABASE ERROR") : _tr("User dosen't exist");
         return false;
     }
     $this->_DB->beginTransaction();
     if ($pACL->isUserSuperAdmin($username)) {
         //si es superadmin solo se cambia la clave de interfaz administrativa
         //cambiamos la clave en la insterfax administrativa
         if (!$pACL->changePassword($idUser, $md5_password)) {
             $this->_DB->rollBack();
             $this->errMsg = $pACL->errMsg;
             return false;
         } else {
             $this->_DB->commit();
             return true;
         }
     } else {
         //obtenemos el dominio al cual pertenece el usuario
         $arrOrgz = $this->getOrganizationById($arrUser[0][4]);
         if ($arrOrgz == false) {
             $this->errMsg = _tr("An error has ocurred to retrieve organization data");
             return false;
         }
         $domain = $arrOrgz['domain'];
         $extension = $arrUser[0][5];
         $fax_extension = $arrUser[0][6];
         $pDevice = new paloDevice($domain, "sip", $this->_DB);
         $arrExtUser = $pDevice->getExtension($extension);
         $listFaxs = $pFax->getFaxList(array("exten" => $fax_extension, "organization_domain" => $domain));
         $faxUser = $listFaxs[0];
         //cambiamos la clave en la insterfax administrativa
         if (!$pACL->changePassword($idUser, $md5_password)) {
             $this->_DB->rollBack();
             $this->errMsg = $pACL->errMsg;
             return false;
         }
         //cambiamos la clave en la extension telefonica
         if (!$pDevice->changePasswordExtension($password, $extension)) {
             $this->_DB->rollBack();
             $this->errMsg = _tr("Extension password couldn't be updated") . $pDevice->errMsg;
             return false;
         }
         //cambiamos la clave para el fax (peer, archivos de configuracion)
         if (!$pFax->editFaxToUser(array("idUser" => $idUser, "country_code" => $faxUser['country_code'], "area_code" => $faxUser['area_code'], "clid_name" => $faxUser['clid_name'], "clid_number" => $faxUser['clid_number']))) {
             $this->_DB->rollBack();
             $this->errMsg = _tr("Fax Extension password couldn't be updated") . $pFax->errMsg;
             return false;
         }
         //cambiamos la clave en el correo
         if (!$pEmail->setAccountPassword($username, $password)) {
             $this->_DB->rollBack();
             $this->errMsg = _tr("Error to update email account password");
             //reestauramos la configuracion anterior en los archivos de fax
             $pFax->editFaxFileConfig($faxUser['dev_id'], $faxUser['country_code'], $faxUser['area_code'], $faxUser['clid_name'], $faxUser['clid_number'], $arrUser[0][3], 0, $arrOrgz['domain']);
             return false;
         } else {
             $this->_DB->commit();
             //recargamos la configuracion en realtime de los dispositivos para que tomen efectos los cambios
             $pDevice->tecnologia->prunePeer($arrExtUser["device"], $arrExtUser["tech"]);
             $pDevice->tecnologia->loadPeer($arrExtUser["device"], $arrExtUser["tech"]);
             if (!empty($arrExtUser["elxweb_device"])) {
                 $pDevice->tecnologia->prunePeer($arrExtUser["elxweb_device"], $arrExtUser["tech"]);
                 $pDevice->tecnologia->loadPeer($arrExtUser["elxweb_device"], $arrExtUser["tech"]);
             }
             //se recarga la faxextension del usuario por los cambios que pudo haber
             $pDevice->tecnologia->prunePeer($faxUser["device"], $faxUser["tech"]);
             $pDevice->tecnologia->loadPeer($faxUser["device"], $faxUser["tech"]);
             $pFax->restartService();
             return true;
         }
     }
 }
Beispiel #2
0
function setUserPassword()
{
    include_once "libs/paloSantoACL.class.php";
    $old_pass = getParameter("oldPassword");
    $new_pass = getParameter("newPassword");
    $new_repass = getParameter("newRePassword");
    $arrResult = array();
    $arrResult['status'] = FALSE;
    if ($old_pass == "") {
        $arrResult['msg'] = _tr("Please write your current password.");
        return $arrResult;
    }
    if ($new_pass == "" || $new_repass == "") {
        $arrResult['msg'] = _tr("Please write the new password and confirm the new password.");
        return $arrResult;
    }
    if ($new_pass != $new_repass) {
        $arrResult['msg'] = _tr("The new password doesn't match with retype new password.");
        return $arrResult;
    }
    $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) {
        $arrResult['msg'] = _tr("Please your session id does not exist. Refresh the browser and try again.");
    } else {
        // verificando la clave vieja
        $val = $pACL->authenticateUser($user, md5($old_pass));
        if ($val === TRUE) {
            $status = $pACL->changePassword($uid, md5($new_pass));
            if ($status) {
                $arrResult['status'] = TRUE;
                $arrResult['msg'] = _tr("Elastix password has been changed.");
                $_SESSION['elastix_pass'] = md5($new_pass);
            } else {
                $arrResult['msg'] = _tr("Impossible to change your Elastix password.");
            }
        } else {
            $arrResult['msg'] = _tr("Impossible to change your Elastix password. User does not exist or password is wrong");
        }
    }
    return $arrResult;
}