Exemplo n.º 1
0
/**
 * Function called before changing user attributes
 * @param $FH FormHandler of the page
 * @param $mode add or edit mode
 */
function _base_verifInfo($FH, $mode)
{
    global $error;
    global $conf;
    $base_errors = "";
    $uid = $FH->getPostValue("uid");
    $pass = $FH->getPostValue("pass");
    $confpass = $FH->getPostValue("confpass");
    $homedir = $FH->getPostValue("homeDirectory");
    $primary = $FH->getPostValue("primary");
    $firstname = $FH->getPostValue("givenName");
    $lastname = $FH->getPostValue("sn");
    $durete = $FH->testpassword($pass);
    if (!preg_match("/^[a-zA-Z0-9][A-Za-z0-9_.-]*\$/", $uid)) {
        $base_errors .= _("User's name invalid !") . "<br/>";
        setFormError("uid");
    }
    if ($mode == "add" && $uid && userExists($uid)) {
        $base_errors .= sprintf(_("The user %s already exists."), $uid) . "<br/>";
        setFormError("uid");
    }
    if ($mode == "add" && $pass == '') {
        $base_errors .= _("Password is empty.") . "<br/>";
        setFormError("pass");
    } else {
        if (strlen($pass) < intval($conf["global"]["minsizepassword"])) {
            $base_errors .= _("Minimum") . " " . $conf["global"]["minsizepassword"] . " " . _("characters for the password") . "<br/>";
            setFormError("pass");
        } else {
            if ($FH->testpassword($pass) < intval($conf["global"]["weakPassword"])) {
                if ($durete < 5) {
                    $msgval = _("very weak");
                } else {
                    if ($durete < 15) {
                        $msgval = _("weak");
                    } else {
                        if ($durete < 40) {
                            $msgval = _("medium");
                        } else {
                            $msgval = _("good");
                        }
                    }
                }
                $base_errors .= _("Password") . " : " . $msgval . "<br/>";
                setFormError("pass");
            }
        }
    }
    if ($mode == "add" && $lastname == '') {
        $base_errors .= _("Last name is empty.") . "<br/>";
        setFormError("sn");
    }
    if ($mode == "add" && $firstname == '') {
        $base_errors .= _("First name is empty.") . "<br/>";
        setFormError("givenName");
    }
    if ($pass != $confpass) {
        $base_errors .= _("The confirmation password does not match the new password.") . " <br/>";
        setFormError("pass");
        setFormError("confpass");
    }
    /* Check that the primary group name exists */
    if (!strlen($primary)) {
        $base_errors .= _("The primary group field can't be empty.") . "<br />";
        setFormError("primary");
    } else {
        if (!existGroup($primary)) {
            $base_errors .= sprintf(_("The group %s does not exist, and so can't be set as primary group."), $primary) . "<br />";
            setFormError("primary");
        }
    }
    /* Check that the homeDir does not exists */
    if ($mode == "add") {
        if ($FH->getPostValue("createHomeDir") == "on" && $FH->getPostValue("ownHomeDir") != "on" && $uid) {
            getHomeDir($uid, $FH->getValue("homeDirectory"));
        }
    } else {
        /* If we want to move the userdir check the destination */
        if ($FH->isUpdated("homeDirectory")) {
            getHomeDir($uid, $FH->getValue("homeDirectory"));
        }
    }
    $error .= $base_errors;
    return $base_errors ? 1 : 0;
}
Exemplo n.º 2
0
/**
 * Function called before changing user attributes
 * @param $FH FormHandler of the page
 * @param $mode add or edit mode
 */
function _base_verifInfo($FH, $mode)
{
    global $error;
    $base_errors = "";
    $uid = $FH->getPostValue("uid");
    $pass = $FH->getPostValue("pass");
    $confpass = $FH->getPostValue("confpass");
    $homedir = $FH->getPostValue("homeDirectory");
    $primary = $FH->getPostValue("primary");
    if (!preg_match("/^[a-zA-Z0-9][A-Za-z0-9_.-]*\$/", $uid)) {
        $base_errors .= _("User's name invalid !") . "<br/>";
        setFormError("uid");
    }
    if ($mode == "add" && $uid && userExists($uid)) {
        $base_errors .= sprintf(_("The user %s already exists."), $uid) . "<br/>";
        setFormError("uid");
    }
    if ($mode == "add" && $pass == '') {
        $base_errors .= _("Password is empty.") . "<br/>";
        setFormError("pass");
    }
    if ($pass != $confpass) {
        $base_errors .= _("The confirmation password does not match the new password.") . " <br/>";
        setFormError("pass");
        setFormError("confpass");
    }
    /* Check that the primary group name exists */
    if (!strlen($primary)) {
        $base_errors .= _("The primary group field can't be empty.") . "<br />";
        setFormError("primary");
    } else {
        if (!existGroup($primary)) {
            $base_errors .= sprintf(_("The group %s does not exist, and so can't be set as primary group."), $primary) . "<br />";
            setFormError("primary");
        }
    }
    /* Check that the homeDir does not exists */
    if ($mode == "add") {
        if ($FH->getPostValue("createHomeDir") == "on" && $FH->getPostValue("ownHomeDir") != "on" && $uid) {
            getHomeDir($uid, $FH->getValue("homeDirectory"));
        }
    } else {
        /* If we want to move the userdir check the destination */
        if ($FH->isUpdated("homeDirectory")) {
            getHomeDir($uid, $FH->getValue("homeDirectory"));
        }
    }
    $error .= $base_errors;
    return $base_errors ? 1 : 0;
}