📄 user.class
字号:
WHERE user_id='". $this->getID()."' "); if (!$res) { $this->setError('ERROR - Could Not Update User Status: '.db_error()); db_rollback(); return false; } else { $this->data_array['status']=$status; if ($status == 'D') { // Remove this user from all groups $res = db_query(" DELETE FROM user_group WHERE user_id='".$this->getID()."' "); if (!$res) { $this->setError('ERROR - Could Not Propogate Deleted Status: '.db_error()); db_rollback(); return false; } } db_commit(); return true; } } /** * isActive - whether this user is confirmed and active. * * Database field status of 'A' returns true. * @return boolean is_active. */ function isActive() { if ($this->getStatus()=='A') { return true; } else { return false; } } /** * getUnixStatus - Status of activation of unix account. * * @return char (N)one, (A)ctive, (S)uspended or (D)eleted */ function getUnixStatus() { return $this->data_array['unix_status']; } /** * setUnixStatus - Sets status of activation of unix account. * * @param string The unix status. * @return boolean success. */ function setUnixStatus($status) { db_begin(); if ($status != 'N') { $this->setUpUnixUID () ; } $res=db_query(" UPDATE users SET unix_status='$status' WHERE user_id='". $this->getID()."' "); if (!$res) { $this->setError('ERROR - Could Not Update User Unix Status: '.db_error()); db_rollback(); return false; } else { if ($status == 'A') { if (!sf_ldap_check_create_user($this->getID())) { $this->setError(sf_ldap_get_error_msg()); db_rollback(); return false; } } else { if (sf_ldap_check_user($this->getID())) { if (!sf_ldap_remove_user($this->getID())) { $this->setError(sf_ldap_get_error_msg()); db_rollback(); return false; } } } $this->data_array['unix_status']=$status; db_commit(); return true; } } /** * getUnixName - the user's unix_name. * * @return string This user's unix/login name. */ function getUnixName() { return strtolower($this->data_array['user_name']); } /** * getUnixPasswd - get the user's password. * * @return string This user's unix crypted passwd. */ function getUnixPasswd() { return $this->data_array['unix_pw']; } /** * getUnixBox - the hostname of the unix box this user has an account on. * * @return string This user's shell login machine. */ function getUnixBox() { return $this->data_array['unix_box']; } /** * getMD5Passwd - the password. * * @return string This user's MD5-crypted passwd. */ function getMD5Passwd() { return $this->data_array['user_pw']; } /** * getConfirmHash - the confirm hash in the db. * * @return string This user's confirmation hash. */ function getConfirmHash() { return $this->data_array['confirm_hash']; } /** * getEmail - the user's email address. * * @return string This user's email address. */ function getEmail() { return $this->data_array['email']; } /** * getNewEmail - while changing an email address, it is stored here until confirmation. * * getNewEmail is a private operation for email change. * * @return string This user's new (not yet confirmed) email address. * @private */ function getNewEmail() { return $this->data_array['email_new']; } /** * setEmail - set a new email address, which must be confirmed. * * @param string The email address. * @return boolean success. */ function setEmail($email) { if (!$email || !validate_email($email)) { $this->setError('ERROR: Invalid Email'); return false; } $res=db_query(" UPDATE users SET email='$email' WHERE user_id='". $this->getID()."' "); if (!$res) { $this->setError('ERROR - Could Not Update User Email: '.db_error()); return false; } else { $this->data_array['email'] = $email; return true; } } /** * setNewEmailAndHash - setNewEmailAndHash is a private operation for email change. * * @param string The email address. * @param string The email hash. * @return boolean success. */ function setNewEmailAndHash($email, $hash='') { if (!$hash) { $hash = substr(md5(strval(time()) . strval(mt_rand())), 0, 16); } if (!$email || !validate_email($email)) { $this->setError('ERROR - Invalid Email'); return false; } $res=db_query(" UPDATE users SET confirm_hash='$hash', email_new='$email' WHERE user_id='".$this->getID()."' "); if (!$res) { $this->setError('ERROR - Could Not Update User Email And Hash: '.db_error()); return false; } else { $this->data_array['email_new'] = $email; $this->data_array['confirm_hash'] = $hash; return true; } } /** * getRealName - get the user's real name. * * @return string This user's real name. */ function getRealName() { return $this->data_array['realname']; } /** * getAddDate - this user's unix time when account was opened. * * @return int This user's unix time when account was opened. */ function getAddDate() { return $this->data_array['add_date']; } /** * getTimeZone - this user's timezone setting. * * @return string This user's timezone setting. */ function getTimeZone() { return $this->data_array['timezone']; } /** * getShell - this user's preferred shell. * * @return string This user's preferred shell. */ function getShell() { return $this->data_array['shell']; } /** * setShell - sets user's preferred shell. * * @param string The users preferred shell. * @return boolean success. */ function setShell($shell) { $shells = file('/etc/shells'); $shells[count($shells)] = "/bin/cvssh"; $out_shells = array(); foreach ($shells as $s) { if (substr($s, 0, 1) == '#') { continue; } $out_shells[] = chop($s); } if (!in_array($shell, $out_shells)) { $this->setError('ERROR: Invalid Shell'); return false; } db_begin(); $res=db_query(" UPDATE users SET shell='$shell' WHERE user_id='". $this->getID()."' "); if (!$res) { $this->setError('ERROR - Could Not Update User Unix Shell: '.db_error()); db_rollback(); return false; } else { // Now change LDAP attribute, but only if corresponding // entry exists (i.e. if user have shell access) if (sf_ldap_check_user($this->getID())) { if (!sf_ldap_user_set_attribute($this->getID(),"loginShell",$shell)) { $this->setError(sf_ldap_get_error_msg()); db_rollback(); return false; } } $this->data_array['shell']=$shell; } db_commit(); return true; } /** * getUnixUid - this user's unix_uid. * * @return int This user's unix_uid. */ function getUnixUID() { return $this->data_array['unix_uid']; } /** * getLanguage - this user's language_id from supported_languages table. * * @return int This user's language_id. */ function getLanguage() { return $this->data_array['language']; } /** * getJabberAddress - this user's optional jabber address. * * @return string This user's jabber address. */ function getJabberAddress() { return $this->data_array['jabber_address']; } /** * getJabberOnly - whether this person wants updates sent ONLY to jabber. * * @return boolean This user's jabber preference. */ function getJabberOnly() { return $this->data_array['jabber_only']; } /** * getAuthorizedKeys - the SSH authorized keys set by the user. * * @return string This user's SSH authorized (public) keys. */ function getAuthorizedKeys() { return ereg_replace("###", "\n", $this->data_array['authorized_keys']); } /** * setAuthorizedKeys - set the SSH authorized keys for the user. * * @param string The users public keys. * @return boolean success. */ function setAuthorizedKeys($keys) { $keys = trim($keys); $keys = ereg_replace("(\r\n)|(\n)", "###", $keys); $res=db_query(" UPDATE users SET authorized_keys='$keys' WHERE user_id='".$this->getID()."' "); if (!$res) { $this->setError('ERROR - Could Not Update User SSH Keys'); return false; } else { $this->data_array['authorized_keys'] = $keys; return true; } } /** * setLoggedIn($val) - Really only used by session code. * * @param boolean The session value. */ function setLoggedIn($val=true) { $this->is_logged_in=$val; if ($val) { //if this is the logged in user - //see if they are a super user $sql="SELECT * FROM user_group ". "WHERE user_id='". $this->getID() ."' AND group_id='1' AND admin_flags='A'"; $result=db_query($sql); if (!$result || db_numrows($result) < 1) { $this->is_super_user=false; } else { $this->is_super_user=true; } } } /** * isLoggedIn - only used by session code. * * @return boolean is_logged_in. */ function isLoggedIn() { return $this->is_logged_in; } /** * setPreference - set a new preference for this user. * * @param string The unique field name for this preference. * @param string The value you are setting this preference to. * @return boolean success. */ function setPreference($preference_name,$value) { $preference_name=strtolower(trim($preference_name)); $result=db_query("UPDATE user_preferences SET preference_value='$value',set_date='". time() ."' ". "WHERE user_id='". $this->getID() ."' ".
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -