| version 1.10, 2003/07/19 11:52:04 |
version 1.11, 2003/07/27 15:42:30 |
|
|
| * ____________________________________________________________ |
* ____________________________________________________________ |
| * |
* |
| * Developed by Ondrej Jombik <nepto@platon.sk> |
* Developed by Ondrej Jombik <nepto@platon.sk> |
| * Copyright (c) 2001-2002 Platon SDG, http://platon.sk/ |
* Copyright (c) 2001-2003 Platon SDG, http://platon.sk/ |
| * All rights reserved. |
* All rights reserved. |
| * |
* |
| * See README file for more information about this software. |
* See README file for more information about this software. |
|
|
| * http://platon.sk/projects/phpPlatonLib/ |
* http://platon.sk/projects/phpPlatonLib/ |
| */ |
*/ |
| |
|
| /* $Platon: AuthDB.php,v 1.7 2002/07/31 15:34:14 nepto Exp $ */ |
/* $Platon: phpPlatonLib/Auth_AuthDB/AuthDB.php,v 1.10 2003/07/19 11:52:04 nepto Exp $ */ |
| |
|
| /* |
/* |
| * History: |
* History: |
|
|
| * 05/9/2002 - expiration & timeout implementation |
* 05/9/2002 - expiration & timeout implementation |
| * - better HTTP_X_FORWARDED_FOR handling in authentification |
* - better HTTP_X_FORWARDED_FOR handling in authentification |
| * - extensive code cleanup |
* - extensive code cleanup |
| |
* 27/7/2003 - support for authentification via another cooperative |
| |
* authentification interface |
| */ |
*/ |
| |
|
| require_once 'DB.php'; |
require_once 'DB.php'; |
| Line 46 define('AUTH_DB_FAILED', -5); |
|
| Line 48 define('AUTH_DB_FAILED', -5); |
|
| |
|
| class AuthDB |
class AuthDB |
| { |
{ |
| var $_status = AUTH_DB_UNDEFINED; |
var $_status = AUTH_DB_UNDEFINED; |
| var $_options = null; |
var $_options = null; |
| var $_db = null; |
var $_db = null; |
| var $_props = array( |
var $_logged_fnc = null; |
| |
var $_props = array( |
| 'username' => null, |
'username' => null, |
| 'password' => null, |
'password' => null, |
| 'session_id' => null, |
'session_id' => null, |
|
|
| $this->_options = $options; |
$this->_options = $options; |
| } |
} |
| |
|
| |
/** |
| |
* Tells AuthDB, that particular user is already authentificated |
| |
* via another cooperative authetification interface. |
| |
* |
| |
* @param fncname name of the function, which returns |
| |
* username of already logged in user |
| |
* @return status |
| |
*/ |
| |
function setLoggedFunction($fncname) |
| |
{ |
| |
$this->_logged_fnc = $fncname; |
| |
} |
| |
|
| |
|
| function assignData() |
function assignData() |
| { |
{ |
| global $HTTP_POST_VARS; |
global $HTTP_POST_VARS; |
|
|
| |
|
| function _processStatus() |
function _processStatus() |
| { |
{ |
| |
if ($this->_logged_fnc != null && function_exists($this->_logged_fnc)) { |
| |
$this->_props['username'] = call_user_func($this->_logged_fnc); |
| |
} |
| $this->_checkDB(); |
$this->_checkDB(); |
| $this->_DBupdateTimeout(); |
$this->_DBupdateTimeout(); |
| |
|
| $status = $this->_DBcheckLogin(); |
$status = $this->_DBcheckLogin(); |
| if ($status != AUTH_DB_UNDEFINED) { |
|
| |
/* If there is a defined login status returns it. |
| |
Exception is, if we are in "logged" mode, which means we are |
| |
authentificated via another cooperative authentification interface. |
| |
In this case only LOGGED_IN and FAILED are returned. |
| |
Other statuses purpously force login function again. */ |
| |
if ($status != AUTH_DB_UNDEFINED && ($this->_logged_fnc == null |
| |
|| $status == AUTH_DB_FAILED |
| |
|| $status == AUTH_DB_LOGGED_IN)) { |
| if ($status != AUTH_DB_LOGGED_IN) { |
if ($status != AUTH_DB_LOGGED_IN) { |
| setcookie(AUTH_DB_COOKIE_NAME, '', time() - 100000); |
setcookie(AUTH_DB_COOKIE_NAME, '', time() - 100000); |
| } |
} |
| return $status; |
return $status; |
| } |
} |
| |
|
| |
/* If not in "logged" mode, assign login data into variables. */ |
| $this->assignData(); |
$this->_logged_fnc != null || $this->assignData(); |
| $status = $this->login(); |
$status = $this->login(); |
| |
|
| if ($status == AUTH_DB_LOGGED_IN) { |
if ($status == AUTH_DB_LOGGED_IN) { |
| $this->_DBinsert(); |
$this->_DBinsert(); |
| setcookie(AUTH_DB_COOKIE_NAME, |
setcookie(AUTH_DB_COOKIE_NAME, |
| $this->_getProperty('session_id'), |
$this->_getProperty('session_id'), 0, '', '', false); |
| 0, '', '', false); |
|
| } elseif ($status == AUTH_DB_FAILED) { |
} elseif ($status == AUTH_DB_FAILED) { |
| $this->_DBlog(); |
$this->_DBlog(); |
| } |
} |
|
|
| $status = AUTH_DB_UNDEFINED; |
$status = AUTH_DB_UNDEFINED; |
| |
|
| if (! empty($this->_props['username'])) { |
if (! empty($this->_props['username'])) { |
| |
|
| $password = $this->_DBgetPassword(); |
$password = $this->_DBgetPassword(); |
| if (isset($password) |
if (isset($password)) { |
| && ! strcmp($password, md5($this->_props['password']))) { |
if ($this->_logged_fnc || |
| $status = AUTH_DB_LOGGED_IN; |
! strcmp($password, md5($this->_props['password']))) { |
| |
$status = AUTH_DB_LOGGED_IN; |
| |
} else { |
| |
$status = AUTH_DB_FAILED; |
| |
} |
| } else { |
} else { |
| $status = AUTH_DB_FAILED; |
$status = AUTH_DB_FAILED; |
| } |
} |
|
|
| case 'remote_ip': |
case 'remote_ip': |
| global $HTTP_SERVER_VARS; |
global $HTTP_SERVER_VARS; |
| /* Sending HTTP_X_FORWARDED_FOR? OK, send anything you want, |
/* Sending HTTP_X_FORWARDED_FOR? OK, send anything you want, |
| but it must persis for whole session. */ |
but it must persist for the whole session. */ |
| $ret = array(); |
$ret = array(); |
| foreach (array('REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR') as $key) { |
foreach (array('REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR') as $key) { |
| if (isset($HTTP_SERVER_VARS[$key])) |
if (isset($HTTP_SERVER_VARS[$key])) |