00001 <?php 00037 class Auth { 00041 var $_session; 00042 00046 function __construct() { 00047 global $session; 00048 00049 $this->_session = &$session; 00050 // 00051 // /* if isGod and area previously set, then set area */ 00052 // /* perform overriding */ 00053 // $areaid = $session->getValue("areaid"); 00054 // if ($this->isGod() && isset($areaid)) { 00055 // global $cfg; 00056 // $cfg->initConfig($areaid); 00057 // } 00058 } 00059 00065 function isLoggedIn() { 00066 return ($this->_session->getValue("uid") <> ""); 00067 } 00068 00074 function isAdmin() { 00075 return ($this->isLoggedIn() && $this->_session->getValue("isadmin")); 00076 } 00077 00083 function isGod() { 00084 return ($this->isAdmin() && $this->_session->getValue("isgod")); 00085 } 00086 00092 // function getUserLevel() { 00093 // if ($this->isAdmin()) { 00094 // return 3; 00095 // } elseif ($this->isLoggedIn()) { 00096 // return ((strpos($this->_session->getValue("groups"), "1") === FALSE) ? 1 : 2); 00097 // } else { 00098 // return 0; 00099 // } 00100 // } 00101 00105 function validateUser() { 00106 global $log; 00107 00108 if (!$_POST['uid']) { 00109 $log->write("USERBADLOGIN", "userid = ``"); 00110 Content::setSysMessage(Content::SYSMSG_ERROR, "LANG_SYSMSG_BADLOGIN"); 00111 return "?login=1"; 00112 } 00113 00114 $sql = "SELECT id, userid, pwd, admin, groups " . 00115 "FROM users " . 00116 "WHERE (userid = '" . $_POST['uid'] . "') " . 00117 "AND enabled"; 00118 $res = mysql_query($sql); 00119 if (mysql_num_rows($res) > 0) { 00120 $line = mysql_fetch_assoc($res); 00121 mysql_free_result($res); 00122 if (md5($_POST['pwd']) == $line['pwd']) { 00123 $this->_session->setValue("uid", $line['id']); 00124 $this->_session->setValue("userid", $line['userid']); 00125 $this->_session->setValue("isadmin", $line['admin']); 00126 $this->_session->setValue("isgod", $line['admin'] && ($line['id_area'] == 0)); 00127 $this->_session->setValue("groups", $line['groups']); 00128 $this->_session->setUseridInSession($line['id']); 00129 00130 $log->write("USERLOGIN", $line['userid']); 00131 Content::setSysMessage(Content::SYSMSG_NOTIFY, "LANG_SYSMSG_LOGGEDIN"); 00132 } else { 00133 $log->write("USERBADLOGIN", "userid = `" . $_POST['uid'] . "`"); 00134 Content::setSysMessage(Content::SYSMSG_ERROR, "LANG_SYSMSG_BADLOGIN"); 00135 return "?login=1"; 00136 } 00137 } else { 00138 $log->write("USERBADLOGIN", "userid = `" . $_POST['uid'] . "`"); 00139 Content::setSysMessage(Content::SYSMSG_ERROR, "LANG_SYSMSG_BADLOGIN"); 00140 return "?login=1"; 00141 } 00142 } 00143 00153 // function validatePlugin($plugin, $mode) { 00154 // if (file_exists("include/plugins/" . $plugin . "/index.php")) { 00155 // $res = mysql_query("SELECT " . $mode . "perm, group_" . $mode . "perm FROM plugins WHERE (id = '" . $plugin . "') AND enabled"); 00156 // if (mysql_num_rows($res) > 0) { 00157 // $line = mysql_fetch_assoc($res); 00158 // mysql_free_result($res); 00159 // return $this->_userCanAccessPlugin($line[$mode . 'perm'], $line['group_' . $mode . 'perm']); 00160 // } else { 00161 // return FALSE; 00162 // } 00163 // } else { 00164 // return FALSE; 00165 // } 00166 // } 00167 00177 // function userCanWriteContent($id_owner, $writeperm, $group_writeperm, $visible = TRUE) { 00178 // if ($this->isAdmin()) { return TRUE; } 00179 // 00180 // $uid = $this->_session->getValue("uid"); 00181 // if (is_null($uid)) { $uid = 0; } 00182 // if ($uid == $id_owner) { return TRUE; } 00183 // 00184 // if (!$visible) { return FALSE; } 00185 // $userlevel = $this->getUserLevel(); 00186 // $usergroups = $this->_session->getValue("groups"); 00187 // if ($userlevel == 2) { 00188 // /* in the following condition, we enforce with ($writeperm == 2) since the field `group_writeperm` */ 00189 // /* in the table `content` can contain a value, although if writeperm <> 2 */ 00190 // return (($userlevel > $writeperm) || (intval($usergroups & $group_writeperm) && ($writeperm == 2))); 00191 // } else { 00192 // return ($userlevel >= $writeperm); 00193 // } 00194 // } 00195 00207 // function userCanReadContent($id_owner, $readperm, $group_readperm, $visible = TRUE) { 00208 // return $this->userCanWriteContent($id_owner, $readperm, $group_readperm, $visible); //FIXME ok... ok... :) 00209 // } 00210 00217 // function userCanWriteContentGivenId($id) { 00218 // /* TODO check write permissions before */ 00219 // $sql = "SELECT id_owner, writeperm, group_writeperm FROM content WHERE id = " . $id; 00220 // $res = mysql_query($sql); 00221 // if (mysql_num_rows($res) > 0) { 00222 // $line = mysql_fetch_assoc($res); 00223 // mysql_free_result($res); 00224 // return $this->userCanWriteContent($line['id_owner'], $line['writeperm'], $line['group_writeperm']); 00225 // } else { 00226 // return FALSE; 00227 // } 00228 // } 00229 00237 // function _userCanAccessPlugin($perm, $group_perm) { 00238 // if ($this->isAdmin()) { return TRUE; } 00239 // 00240 // $userlevel = $this->getUserLevel(); 00241 // $usergroups = $this->_session->getValue("groups"); 00242 // if ($userlevel == 2) { 00243 // return (($userlevel > $perm) || (intval($usergroups & $group_perm) && ($perm == 2))); 00244 // } else { 00245 // return ($userlevel >= $perm); 00246 // } 00247 // } 00248 } 00249 ?>
1.5.3