Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00034 include_once 'Auth/Auth.php';
00035
00036 define('IL_AUTH_MD5',1);
00037 define('IL_AUTH_PLAIN',2);
00038
00039 class ilBaseAuthentication
00040 {
00041
00042
00043
00044
00045
00046 var $auth = null;
00047
00048
00049
00050
00051
00052
00053
00054 var $sid = '';
00055
00056
00057
00058
00059
00060 var $username = '';
00061
00062
00063
00064
00065
00066 var $password = '';
00067
00068
00069
00070
00071
00072
00073 var $client = '';
00074
00075 function ilBaseAuthentication()
00076 {
00077 $this->__setMessage('');
00078 $this->__setMessageCode('Client');
00079 $this->check_setting = true;
00080 }
00081
00082
00083
00084 function setClient($a_client)
00085 {
00086 $this->client = $a_client;
00087 $_COOKIE['ilClientId'] = $a_client;
00088 }
00089 function getClient()
00090 {
00091 return $this->client;
00092 }
00093 function setUsername($a_username)
00094 {
00095 $this->username = $a_username;
00096 $_POST['username'] = $a_username;
00097 }
00098 function getUsername()
00099 {
00100 return $this->username;
00101 }
00102 function setPassword($a_password)
00103 {
00104 $this->password = $a_password;
00105 $_POST['password'] = $a_password;
00106 }
00107 function getPassword()
00108 {
00109 return $this->password;
00110 }
00111 function setSid($a_sid)
00112 {
00113 $this->sid = $a_sid;
00114 $_COOKIE['PHPSESSID'] = $this->sid;
00115 }
00116 function getSid()
00117 {
00118 return $this->sid;
00119 }
00120
00121 function getMessage()
00122 {
00123 return $this->message;
00124 }
00125 function getMessageCode()
00126 {
00127 return $this->message_code;
00128 }
00129 function __setMessage($a_message)
00130 {
00131 $this->message = $a_message;
00132 }
00133 function __setMessageCode($a_message_code)
00134 {
00135 $this->message_code = $a_message_code;
00136 }
00137
00138 function setPasswordType($a_type)
00139 {
00140 $this->password_type = $a_type;
00141 }
00142 function getPasswordType()
00143 {
00144 return isset($this->password_type) ? $this->password_type : IL_AUTH_PLAIN;
00145 }
00146
00147 function authenticate()
00148 {
00149 if(!$this->getClient())
00150 {
00151 $this->__setMessage('No client given');
00152 return false;
00153 }
00154 if(!$this->getUsername())
00155 {
00156 $this->__setMessage('No username given');
00157 return false;
00158 }
00159
00160 if(!$this->__buildDSN())
00161 {
00162 return false;
00163 }
00164 if(!$this->__setSessionSaveHandler())
00165 {
00166 return false;
00167 }
00168 if(!$this->__buildAuth())
00169 {
00170 return false;
00171 }
00172 $this->auth->start();
00173
00174 if(!$this->auth->getAuth())
00175 {
00176 $this->__getAuthStatus();
00177
00178 return false;
00179 }
00180
00181 $this->setSid(session_id());
00182
00183 return true;
00184 }
00185
00186 function start()
00187 {
00188 if(!$this->getSid())
00189 {
00190 $this->__setMessage('No session id given');
00191 return false;
00192 }
00193
00194 $this->auth->start();
00195
00196 return true;
00197 }
00198
00199 function validateSession()
00200 {
00201 if(!$this->getClient())
00202 {
00203 $this->__setMessage('No client given');
00204 return false;
00205 }
00206 if(!$this->getSid())
00207 {
00208 $this->__setMessage('No session id given');
00209 return false;
00210 }
00211
00212 if(!$this->__buildAuth())
00213 {
00214 return false;
00215 }
00216 if(!$this->__setSessionSaveHandler())
00217 {
00218 return false;
00219 }
00220
00221 $this->auth->start();
00222 if(!$this->auth->getAuth())
00223 {
00224 $this->__setMessage('Session not valid');
00225
00226 return false;
00227 }
00228
00229 return true;
00230 }
00231
00232 function logout()
00233 {
00234 if(!$this->getClient())
00235 {
00236 $this->__setMessage('No client given');
00237 return false;
00238 }
00239 if(!$this->getSid())
00240 {
00241 $this->__setMessage('No session id given');
00242 return false;
00243 }
00244
00245
00246 #if(!$this->__buildAuth())
00247 #{
00248 # return false;
00249 #}
00250 #if(!$this->__setSessionSaveHandler())
00251 #{
00252 # return false;
00253 #}
00254
00255
00256 #$this->auth->start();
00257 $this->auth->logout();
00258 session_destroy();
00259
00260 return true;
00261
00262 }
00263
00264 function __buildDSN()
00265 {
00266 include_once './classes/class.ilIniFile.php';
00267
00268
00269 $this->ilias_ini =& new ilIniFile('./ilias.ini.php');
00270 $this->ilias_ini->read();
00271
00272 if(!@file_exists("./".$this->ilias_ini->readVariable('clients','path')."/".$this->getClient()."/client.ini.php"))
00273 {
00274 $this->__setMessageCode('Client');
00275 $this->__setMessage('Client does not exist');
00276
00277 return false;
00278 }
00279
00280 $this->ini =& new ilIniFile("./".$this->ilias_ini->readVariable('clients','path')."/".$this->getClient()."/client.ini.php");
00281 $this->ini->read();
00282
00283 $this->dsn = $this->ini->readVariable("db","type").
00284 "://".$this->ini->readVariable("db", "user").
00285 ":".$this->ini->readVariable("db", "pass").
00286 "@".$this->ini->readVariable("db", "host").
00287 "/".$this->ini->readVariable("db", "name");
00288
00289 return true;
00290 }
00291
00292 function __buildAuth()
00293 {
00294 $this->auth_params = array(
00295 'dsn' => $this->dsn,
00296 'table' => $this->ini->readVariable("auth", "table"),
00297 'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00298 'passwordcol' => $this->ini->readVariable("auth", "passcol")
00299 );
00300
00301 if($this->getPasswordType() == IL_AUTH_MD5)
00302 {
00303 $this->auth_params['cryptType'] = 'none';
00304 }
00305
00306 $this->auth = new Auth("DB", $this->auth_params,"",false);
00307
00308 return true;
00309 }
00310
00311 function __setSessionSaveHandler()
00312 {
00313 include_once './include/inc.db_session_handler.php';
00314 include_once "./Services/Utilities/classes/class.ilUtil.php";
00315 include_once './classes/class.ilErrorHandling.php';
00316 include_once './classes/class.ilDBx.php';
00317
00318
00319 $GLOBALS['ilDB'] =& new ilDBx($this->dsn);
00320
00321 if(ini_get('session.save_handler') != 'user')
00322 {
00323 ini_set("session.save_handler", "user");
00324 }
00325 if(!db_set_save_handler())
00326 {
00327 $this->__setMessageCode('Server');
00328 $this->__setMessage('Cannot set session handler');
00329
00330 return false;
00331 }
00332
00333 return true;
00334 }
00335
00336 function __getAuthStatus()
00337 {
00338 switch($this->auth->getStatus())
00339 {
00340 case AUTH_EXPIRED:
00341 $this->__setMessageCode('Server');
00342 $this->__setMessage('Session expired');
00343
00344 return false;
00345
00346 case AUTH_IDLED:
00347 $this->__setMessageCode('Server');
00348 $this->__setMessage('Session idled');
00349
00350 return false;
00351
00352 case AUTH_WRONG_LOGIN:
00353 default:
00354 $this->__setMessageCode('Client');
00355 $this->__setMessage('Wrong Login or Password');
00356
00357 return false;
00358
00359
00360 }
00361 }
00362 }
00363 ?>