Example #1
0
/**
 * Function called for changing user attributes
 * @param $FH FormHandler of the page
 * @param $mode add or edit mode
 */
function _radius_changeUser($FH, $mode)
{
    global $result;
    $uid = $FH->getPostValue('uid');
    if ($FH->getPostValue("showradius")) {
        addRadiusObjectClass($uid);
        if ($FH->isUpdated("radiusCallingStationId")) {
            changeUserAttributes($uid, "radiusCallingStationId", $FH->getValue("radiusCallingStationId"), false);
            $result .= _T("Radius attributes updated.", "radius") . "<br />";
        }
    } else {
        if ($mode == 'edit' && hasRadiusObjectClass($uid)) {
            delRadiusObjectClass($FH->getPostValue('uid'));
            $result .= _T("Radius attributes deleted.", "radius") . "<br />";
        }
    }
    return 0;
}
Example #2
0
/**
 * Function called for changing user attributes
 * @param $FH FormHandler of the page
 * @param $mode add or edit mode
 */
function _base_changeUser($FH, $mode)
{
    global $result;
    global $error;
    $update = false;
    $base_errors = "";
    $uid = $FH->getPostValue("uid");
    if ($mode == "add") {
        // add mode
        if ($FH->getPostValue("createHomeDir") == "on") {
            $createHomeDir = true;
        } else {
            $createHomeDir = false;
        }
        if ($FH->getPostValue("ownHomeDir") == "on") {
            $ownHomeDir = true;
        } else {
            $ownHomeDir = false;
        }
        # create the user
        $ret = add_user($uid, $FH->getPostValue("pass"), $FH->getPostValue("givenName"), $FH->getPostValue("sn"), $FH->getPostValue("homeDirectory"), $createHomeDir, $ownHomeDir, $FH->getPostValue("primary"));
        $result .= $ret["info"];
        # password doesn't match the pwd policies
        # we set a random password for other plugins
        if ($ret["code"] == 5) {
            $randomPass = uniqid(rand(), true);
            $FH->setPostValue("pass", $randomPass);
            $FH->setValue("pass", $randomPass);
        }
        # add mail attribute
        if ($FH->getPostValue('mail')) {
            changeUserAttributes($uid, "mail", $FH->getPostValue("mail"));
        }
        if ($FH->getPostValue('loginShell')) {
            changeUserAttributes($uid, "loginShell", $FH->getPostValue('loginShell'));
        }
    } else {
        // edit mode
        if ($FH->getPostValue("deletephoto")) {
            changeUserAttributes($uid, "jpegPhoto", null);
            $result .= _("User photo deleted") . "<br />";
        }
        if ($FH->isUpdated("homeDirectory")) {
            move_home($uid, $FH->getValue("homeDirectory"));
            $result .= _(sprintf("Home user directory moved to %s", $FH->getValue("homeDirectory"))) . "<br />";
        }
    }
    // common stuff to add/edit mode
    if ($FH->isUpdated('isBaseDesactive')) {
        $shells = getDefaultShells();
        if ($FH->getValue('isBaseDesactive') == "on") {
            changeUserAttributes($uid, 'loginShell', $shells['disabledShell']);
            $result .= _("User disabled") . "<br />";
        } else {
            changeUserAttributes($uid, 'loginShell', $shells['enabledShell']);
            $result .= _("User enabled") . "<br />";
        }
    }
    if ($FH->isUpdated('telephoneNumber')) {
        changeUserTelephoneNumbers($uid, $FH->getValue("telephoneNumber"));
        $update = true;
    }
    if ($FH->isUpdated('givenName') or $FH->isUpdated('sn')) {
        change_user_main_attr($uid, $uid, $FH->getValue('givenName'), $FH->getValue('sn'));
        $update = true;
    }
    foreach (array('title', 'mobile', 'facsimileTelephoneNumber', 'homePhone', 'cn', 'mail', 'displayName', 'preferredLanguage') as $attr) {
        if ($FH->isUpdated($attr)) {
            changeUserAttributes($uid, $attr, $FH->getValue($attr));
            $update = true;
        }
    }
    /* Change photo */
    if (!empty($_FILES["photofilename"]["name"])) {
        $pfile = $_FILES["photofilename"]["tmp_name"];
        $size = getimagesize($pfile);
        if ($size["mime"] == "image/jpeg") {
            $maxwidth = 320;
            $maxheight = 320;
            if (in_array("gd", get_loaded_extensions())) {
                /* Resize file if GD extension is installed */
                $pfile = resizeJpg($_FILES["photofilename"]["tmp_name"], $maxwidth, $maxheight);
            }
            list($width, $height) = getimagesize($pfile);
            if ($width <= $maxwidth && $height <= $maxheight) {
                $obj = new Trans();
                $obj->scalar = "";
                $obj->xmlrpc_type = "base64";
                $f = fopen($pfile, "r");
                while (!feof($f)) {
                    $obj->scalar .= fread($f, 4096);
                }
                fclose($f);
                unlink($pfile);
                changeUserAttributes($uid, "jpegPhoto", $obj, False);
            } else {
                $base_errors .= sprintf(_("The photo is too big. The max size is %s x %s.\n                    Install php gd extension to resize the photo automatically"), $maxwidth, $maxheight) . "<br/>";
            }
        } else {
            $base_errors .= _("The photo is not a JPG file") . "<br/>";
        }
    }
    if ($mode == "edit" && $update) {
        $result .= _("User attributes updated") . "<br />";
    }
    $error .= $base_errors;
    return $base_errors ? 1 : 0;
}
Example #3
0
 function modify()
 {
     if ($this->modifiable) {
         $user = $this->user;
         $login = $user["login"];
         // the following are not permitted to be changed yet
         unset($user["login"], $user["firstname"], $user["surname"], $user["homedir"], $user["createhomedir"], $user["primaryGroup"]);
         if (key_exists("password", $user)) {
             $ret = callPluginFunction("changeUserPasswd", array(array($login, prepare_string($user["password"]))));
             if (isXMLRPCError()) {
                 foreach ($ret as $info) {
                     $this->result .= _("Password not updated") . "<br/>";
                 }
                 # set errorStatus to 0 in order to make next xmlcalls
                 global $errorStatus;
                 $errorStatus = 0;
             } else {
                 //update result display
                 $this->result .= _("Password updated.") . "<br />";
             }
             unset($user["password"]);
         }
         if (count($user) > 0) {
             foreach ($user as $attribute => $value) {
                 if ($this->checkAttribute($attribute)) {
                     changeUserAttributes($login, $attribute, $value);
                 } else {
                     unset($user[$attribute]);
                 }
             }
             $this->result .= count($user) . _T("Attribute(s) modified", "bulkimport");
         }
     }
 }