/**
  * 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;
         }
     }
 }
예제 #2
0
function setUserPassword()
{
    global $arrConf;
    include_once "libs/paloSantoACL.class.php";
    include_once "libs/paloSantoOrganization.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;
    }
    //verificamos que la nueva contraseña sea fuerte
    if (!isStrongPassword($new_pass)) {
        $arrResult['msg'] = _tr("The new password can not be empty. It must have at least 10 characters and contain digits, uppers and little case letters");
        return $arrResult;
    }
    $user = isset($_SESSION['elastix_user']) ? $_SESSION['elastix_user'] : "";
    $pDB = new paloDB($arrConf['elastix_dsn']['elastix']);
    $pACL = new paloACL($pDB);
    $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) {
            $pORG = new paloSantoOrganization($pDB);
            $status = $pORG->changeUserPassword($user, $new_pass);
            if ($status) {
                $arrResult['status'] = TRUE;
                $arrResult['msg'] = _tr("Elastix password has been changed.");
                $_SESSION['elastix_pass'] = md5($new_pass);
                $_SESSION['elastix_pass2'] = $new_pass;
            } else {
                $arrResult['msg'] = _tr("Impossible to change your Elastix password.") . " " . $pORG->errMsg;
            }
        } else {
            $arrResult['msg'] = _tr("Impossible to change your Elastix password. User does not exist or password is wrong");
        }
    }
    return $arrResult;
}
예제 #3
0
function saveEditUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls)
{
    $pACL = new paloACL($pDB);
    $pORGZ = new paloSantoOrganization($pDB);
    $exito = false;
    $idUser = getParameter("id");
    $errorImg = "";
    $renameFile = "";
    $reAsterisk = false;
    //obtenemos la informacion del usuario por el id dado, sino existe el usuario mostramos un mensaje de error
    if (!isset($idUser)) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("Invalid User"));
        return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    } else {
        if ($arrCredentiasls['userlevel'] == "superadmin") {
            $arrUsers = $pACL->getUsers($idUser);
        } else {
            $arrUsers = $pACL->getUsers($idUser, $arrCredentiasls['id_organization']);
        }
    }
    if ($arrUsers === false) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr($pACL->errMsg));
        return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    } else {
        if (count($arrUsers) == 0) {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr("User doesn't exist"));
            return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
        } else {
            $idOrgz = $arrUsers[0][4];
            //una vez creado un usuario este no se puede cambiar de organizacion
            $arrOrgz = array();
            $temp = $pACL->getGroupsPaging(null, null, $idOrgz);
            if ($temp === false) {
                $smarty->assign("mb_title", _tr("ERROR"));
                $smarty->assign("mb_message", _tr($pACL->errMsg));
                return reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
            }
            foreach ($temp as $value) {
                $arrGrupos[$value[0]] = $value[1];
            }
            $arrFormOrgz = createFieldForm($arrGrupos, $arrOrgz);
            $oForm = new paloForm($smarty, $arrFormOrgz);
            if (!$oForm->validateForm($_POST)) {
                // Validation basic, not empty and VALIDATION_TYPE
                $smarty->assign("mb_title", _tr("Validation Error"));
                $arrErrores = $oForm->arrErroresValidacion;
                $strErrorMsg = "<b>" . _tr("The following fields contain errors") . ":</b><br/>";
                if (is_array($arrErrores) && count($arrErrores) > 0) {
                    foreach ($arrErrores as $k => $v) {
                        $strErrorMsg .= "{$k} [{$v['mensaje']}], ";
                    }
                }
                $smarty->assign("mb_message", $strErrorMsg);
                return viewFormUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
            } else {
                $password1 = getParameter("password1");
                $password2 = getParameter("password2");
                $quota = getParameter("email_quota");
                $countryCode = getParameter("country_code");
                $areaCode = getParameter("area_code");
                $idGrupo = getParameter("group");
                $extension = getParameter("extension");
                $fax_extension = getParameter("fax_extension");
                $name = getParameter("name");
                $md5password = md5($password1);
                $clidNumber = getParameter("clid_number");
                $cldiName = getParameter("clid_name");
                if ($pACL->isUserSuperAdmin($arrUsers[0][1])) {
                    $idGrupo = $arrUsers[0][7];
                    $email_contact = getParameter("email_contact");
                    $exito = $pORGZ->updateUserSuperAdmin($idUser, $name, $md5password, $password1, $email_contact, $arrCredentiasls['userlevel']);
                    $error = $pORGZ->errMsg;
                } else {
                    if ($password1 != $password2) {
                        $error = _tr("Passwords don't match");
                    } elseif ($password1 != "" && !isStrongPassword($password1)) {
                        $error = _tr("Secret can not be empty, must be at least 10 characters, contain digits, uppers and little case letters");
                    } elseif (!isset($quota) || $quota == "") {
                        $error = _tr("Qouta must not be empty");
                    } elseif (!isset($countryCode) || $countryCode == "") {
                        $error = _tr("Country Code must not be empty");
                    } elseif (!isset($areaCode) || $areaCode == "") {
                        $error = _tr("Area Code must not be empty");
                    } elseif (!isset($clidNumber) || $clidNumber == "") {
                        $error = _tr("C er Id Number must not be empty");
                    } elseif (!isset($cldiName) || $cldiName == "") {
                        $error = _tr("Caller Id Name must not be empty");
                    } else {
                        $exito = $pORGZ->updateUserOrganization($idUser, $name, $md5password, $password1, $extension, $fax_extension, $countryCode, $areaCode, $clidNumber, $cldiName, $idGrupo, $quota, $arrCredentiasls['userlevel'], $reAsterisk);
                        $error = $pORGZ->errMsg;
                    }
                }
            }
        }
    }
    if ($exito) {
        //esta seccion es solo si el usuario quiere subir una imagen a su cuenta
        if (isset($_FILES['picture']['name']) && $_FILES['picture']['name'] != "") {
            uploadImage($idUser, $pDB, $errorImg);
        }
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", _tr("User has been edited successfully") . "<br>{$errorImg}");
        if ($reAsterisk) {
            //mostramos el mensaje para crear los archivos de ocnfiguracion
            $pAstConf = new paloSantoASteriskConfig($pDB);
            $orgTmp2 = $pORGZ->getOrganization(array("id" => $idOrgz));
            $pAstConf->setReloadDialplan($orgTmp2[0]["domain"], true);
        }
        $content = reportUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    } else {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", $error);
        $content = viewFormUser($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrCredentiasls);
    }
    return $content;
}
예제 #4
0
function saveEditExten($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials)
{
    $pExten = new paloSantoExtensions($pDB);
    $error = "";
    $continuar = true;
    $exito = false;
    $belonguser = false;
    $idExten = getParameter("id_exten");
    //obtenemos la informacion del usuario por el id dado, sino existe la extension mostramos un mensaje de error
    if (!isset($idExten)) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("Invalid Exten"));
        return reportExten($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    $domain = getParameter('organization');
    if ($credentials['userlevel'] != 'superadmin') {
        $domain = $credentials['domain'];
    }
    $arrExten = $pExten->getExtensionById($idExten, $domain);
    if ($arrExten === false) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr($pExten->errMsg));
        return reportExten($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    } else {
        if (count($arrExten) == 0) {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr("Extension doesn't exist"));
            return reportExten($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        } else {
            $exten = $arrExten["exten"];
            //comprobamos si la extension le pertenece a algun usuario
            //si le pertenece a un usuario el secret no puede ser editado
            $belonguser = extenBelongToUser($pDB, $arrExten["exten"], $arrExten["domain"]);
            $secret = getParameter("secret");
            if ($belonguser) {
                $secret = "";
            }
            if (isset($secret) && $secret != "") {
                if (!isStrongPassword($secret)) {
                    $error .= _tr("Secret can not be empty, must be at least 10 characters, contain digits, uppers and little case letters");
                    $continuar = false;
                }
            }
            $type = $arrExten["technology"];
            if (!isset($type) || !($type == "sip" || $type == "iax2")) {
                $error .= _tr("Invalid technology");
                $continuar = false;
            }
            //no puede contener caracteres esoeciales ni salto de lineas
            $arrProp["fullname"] = getParameter("clid_name");
            if ($arrProp["fullname"] != '') {
                if (!preg_match("/^[[:alnum:]_[:space:]-]+\$/", $arrProp["fullname"])) {
                    $error .= _tr("CID Name is invalid");
                    $continuar = false;
                }
            } else {
                $arrProp["fullname"] = $exten;
            }
            $arrProp["clid_number"] = getParameter('clid_number');
            if ($arrProp["clid_number"] != '') {
                if (!preg_match("/^[[:alnum:]_[:space:]-]+\$/", $arrProp["clid_number"])) {
                    $error .= _tr("CID Number is invalid");
                    $continuar = false;
                }
            } else {
                $arrProp["clid_number"] = $exten;
            }
            if ($continuar) {
                //seteamos un arreglo con los parametros configurados
                $arrProp["exten"] = $exten;
                $arrProp["name"] = $arrExten["device"];
                $arrProp["dial"] = $arrExten["dial"];
                if ($belonguser) {
                    $arrProp["alias"] = $arrExten["alias"];
                    $arrProp["elxweb_device"] = $arrExten["elxweb_device"];
                    $arrProp["enable_chat"] = $arrExten["enable_chat"];
                }
                $arrProp['secret'] = getParameter("secret");
                $arrProp['rt'] = getParameter("ring_timer");
                $arrProp['record_in'] = getParameter("record_in");
                $arrProp['record_out'] = getParameter("record_out");
                $arrProp['language'] = getParameter("language");
                $arrProp['out_clid'] = getParameter("out_clid");
                $arrProp['callwaiting'] = getParameter("call_waiting");
                $arrProp['screen'] = getParameter("screen");
                $arrProp['dictate'] = getParameter("dictate");
                $arrProp['dictformat'] = getParameter("dictformat");
                $arrProp['dictemail'] = getParameter("dictemail");
                //obtenemos los datos para la creacion de voicemail
                if (getParameter("create_vm") == "yes") {
                    $vmpassword = getParameter("vmpassword");
                    if (!preg_match('/^[[:digit:]]+$/', "{$vmpassword}")) {
                        $error = _tr("Voicemail password cannot be empty and must only contain digits");
                        $continuar = false;
                    } else {
                        $arrProp["create_vm"] = "yes";
                        $arrProp["vmpassword"] = $vmpassword;
                        $arrProp["vmemail"] = getParameter("vmemail");
                        $arrProp["vmattach"] = getParameter("vmattach");
                        $arrProp["vmsaycid"] = getParameter("vmsaycid");
                        $arrProp["vmdelete"] = getParameter("vmdelete");
                        $arrProp["vmenvelope"] = getParameter("vmenvelope");
                        $arrProp["vmcontext"] = getParameter("vmcontext");
                        $arrProp["vmoptions"] = getParameter("vmoptions");
                        $arrProp["vmemailsubject"] = getParameter("vmemailsubject");
                        $arrProp["vmemailbody"] = getParameter("vmemailbody");
                        //vmx_locator settings
                        $arrProp["vmx_locator"] = getParameter("vmx_locator");
                        $arrProp["vmx_use"] = getParameter("vmx_use");
                        $arrProp["vmx_extension_0"] = getParameter("vmx_extension_0");
                        $arrProp["vmx_extension_1"] = getParameter("vmx_extension_1");
                        $arrProp["vmx_extension_2"] = getParameter("vmx_extension_2");
                        $arrProp["vmx_operator"] = getParameter("vmx_operator");
                    }
                } else {
                    $arrProp["create_vm"] = "no";
                }
            }
            if ($continuar) {
                $arrPropT = array_merge(propersParamByTech($type), $arrProp);
                $pDevice = new paloDevice($domain, $type, $pDB);
                $pDB->beginTransaction();
                $exito = $pDevice->editDevice($arrPropT);
                if ($exito) {
                    $pDB->commit();
                    //recargamos la configuracion en realtime para que tomen efecto los cambios hechos en el dispositivo
                    $pDevice->tecnologia->prunePeer($arrExten["device"], $type);
                    $pDevice->tecnologia->loadPeer($arrExten["device"], $type);
                } else {
                    $pDB->rollBack();
                }
                $error .= $pDevice->errMsg;
            }
        }
    }
    $smarty->assign("mostra_adv", getParameter("mostra_adv"));
    $smarty->assign("id_exten", $idExten);
    if ($exito) {
        $smarty->assign("mb_title", _tr("MESSAGE"));
        $smarty->assign("mb_message", _tr("Extension has been edited successfully"));
        //mostramos el mensaje para crear los archivos de ocnfiguracion
        $pAstConf = new paloSantoASteriskConfig($pDB);
        $pAstConf->setReloadDialplan($domain, true);
        $content = reportExten($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    } else {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", $error);
        $content = viewFormExten($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    return $content;
}
예제 #5
0
 function validateParams()
 {
     $error = array();
     $req = "Required Field: ";
     $bf = "Bad Format: ";
     //parametros requeridos
     if (!isset($_POST["domain"])) {
         $error[] = "domain";
     }
     if (!isset($_POST["email_contact"])) {
         $error[] = "email_contact";
     }
     if (!isset($_POST["org_user_pswd"])) {
         $error[] = "org_user_pswd";
     }
     if (count($error) != 0) {
         $this->errMsg = $req . implode(",", $error);
         return false;
     }
     $arrParam = array();
     if (!preg_match("/^(([[:alnum:]-]+)\\.)+([[:alnum:]])+\$/", $_POST["domain"])) {
         $error[] = "domain";
     } else {
         $arrParam["domain"] = $_POST["domain"];
     }
     if (!preg_match("/^[a-z0-9]+([\\._\\-]?[a-z0-9]+[_\\-]?)*@[a-z0-9]+([\\._\\-]?[a-z0-9]+)*(\\.[a-z0-9]{2,4})+\$/", $_POST["email_contact"])) {
         $error[] = "email_contact";
     } else {
         $arrParam["email_contact"] = $_POST["email_contact"];
     }
     if (!isStrongPassword($_POST["org_user_pswd"])) {
         $error[] = "org_user_pswd";
     } else {
         $arrParam["org_user_pswd"] = $_POST["org_user_pswd"];
     }
     $arrParam["name"] = empty($_POST["name"]) ? $arrParam["domain"] : $_POST["name"];
     $arrParam["country"] = isset($_POST["country"]) ? $_POST["country"] : "";
     $arrParam["city"] = isset($_POST["city"]) ? $_POST["city"] : "";
     $arrParam["address"] = isset($_POST["address"]) ? $_POST["address"] : "";
     $arrParam["country_code"] = empty($_POST["country_code"]) ? "1" : $_POST["country_code"];
     $arrParam["area_code"] = empty($_POST["area_code"]) ? "0" : $_POST["area_code"];
     if (isset($_POST["quota"])) {
         if (!ctype_digit($_POST["quota"]) || $_POST["quota"] + 0 == 0) {
             $error[] = "quota (digit > 0)";
         } else {
             $arrParam["quota"] = $_POST["quota"];
         }
     } else {
         $arrParam["quota"] = "30";
     }
     if (isset($_POST["numUser"])) {
         if (!ctype_digit($_POST["numUser"])) {
             $error[] = "numUser (digit)";
         } else {
             $arrParam["numUser"] = $_POST["numUser"];
         }
     } else {
         $arrParam["numUser"] = "******";
     }
     if (isset($_POST["numExtensions"])) {
         if (!ctype_digit($_POST["numExtensions"])) {
             $error[] = "numExtensions (digit)";
         } elseif ($_POST["numExtensions"] < $arrParam["numUser"] && $arrParam["numUser"] != 0 && $_POST["numExtensions"] != 0 || $arrParam["numUser"] == 0 && $_POST["numExtensions"] != 0) {
             $error[] = "numExtensions (numExtensions>=numUser)";
         } else {
             $arrParam["numExtensions"] = $_POST["numExtensions"];
         }
     } else {
         $arrParam["numExtensions"] = "0";
     }
     if (isset($_POST["numQueues"])) {
         if (!ctype_digit($_POST["numQueues"])) {
             $error[] = "numQueues (digit)";
         } else {
             $arrParam["numQueues"] = $_POST["numQueues"];
         }
     } else {
         $arrParam["numQueues"] = "0";
     }
     $arrParam["send_email"] = empty($_POST["send_email"]) ? false : true;
     if (count($error) > 0) {
         $this->errMsg = $bf . implode(",", $error);
         return false;
     }
     return $arrParam;
 }