| version 1.6, 2002/05/29 15:08:32 |
version 1.7, 2002/07/31 15:34:14 |
|
|
| |
|
| require_once 'DB.php'; |
require_once 'DB.php'; |
| |
|
| define('AUTH_DB_COOKIE_NAME', 'AuthDB_session_id_cookie'); |
define('AUTH_DB_COOKIE_NAME', 'AuthDB_session_id_cookie'); |
| define('AUTH_DB_UNDEFINED', 0); |
define('AUTH_DB_UNDEFINED', 0); |
| define('AUTH_DB_NOT_LOGGED', -1); |
define('AUTH_DB_NOT_LOGGED', -1); |
| define('AUTH_DB_LOGGED_IN', 1); |
define('AUTH_DB_LOGGED_IN', 1); |
|
|
| function _processStatus() |
function _processStatus() |
| { |
{ |
| $this->_checkDB(); |
$this->_checkDB(); |
| $this->_dbUpdateTimeout(); |
$this->_DBupdateTimeout(); |
| |
|
| if ($this->_dbCheckLogin()) |
if ($this->_DBcheckLogin()) |
| return AUTH_DB_LOGGED_IN; |
return AUTH_DB_LOGGED_IN; |
| |
|
| |
|
|
|
| $status = $this->login(); |
$status = $this->login(); |
| |
|
| if ($status == AUTH_DB_LOGGED_IN) { |
if ($status == AUTH_DB_LOGGED_IN) { |
| $this->_dbInsert(); |
$this->_DBinsert(); |
| } |
} elseif ($status == AUTH_DB_FAILED) { |
| elseif ($status == AUTH_DB_FAILED) { |
$this->_DBlog(); |
| $this->_dbLog(); |
|
| } |
} |
| |
|
| return $status; |
return $status; |
|
|
| |
|
| 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']))) { |
&& ! strcmp($password, md5($this->_props['password']))) { |
| $status = AUTH_DB_LOGGED_IN; |
$status = AUTH_DB_LOGGED_IN; |
| } |
} else { |
| else { |
|
| $status = AUTH_DB_FAILED; |
$status = AUTH_DB_FAILED; |
| } |
} |
| } |
} else { |
| else { |
|
| $status = AUTH_DB_NOT_LOGGED; |
$status = AUTH_DB_NOT_LOGGED; |
| } |
} |
| |
|
|
|
| function logout() |
function logout() |
| { |
{ |
| if ($this->getAuth()) { |
if ($this->getAuth()) { |
| $this->_dbLogout(); |
$this->_DBlogout(); |
| $this->_status = AUTH_DB_LOGGED_OUT; |
$this->_status = AUTH_DB_LOGGED_OUT; |
| } |
} |
| } |
} |
| |
|
| function getUsername() |
function getUsername() |
| { |
{ |
| return $this->_dbGetUsername(); |
return $this->_DBgetUsername(); |
| } |
} |
| |
|
| function getUserInfo() |
function getUserInfo() |
| { |
{ |
| if ($this->getAuth()) { |
if ($this->getAuth()) { |
| $this->_props['username'] = $this->getUsername(); |
$this->_props['username'] = $this->getUsername(); |
| return $this->_dbGetUserInfo(); |
return $this->_DBgetUserInfo(); |
| } |
} |
| |
|
| return false; |
return false; |
|
|
| |
|
| function _error($error) |
function _error($error) |
| { |
{ |
| echo "AuthDB error: " |
echo 'AuthDB error: ' |
| . $error->getMessage() . "<br>" |
. $error->getMessage() . '<br>' |
| . $error->getDebugInfo() . "<br>"; |
. $error->getDebugInfo() . '<br>'; |
| die(); |
die(); |
| } |
} |
| |
|
|
|
| if (isset($HTTP_COOKIE_VARS[AUTH_DB_COOKIE_NAME])) { |
if (isset($HTTP_COOKIE_VARS[AUTH_DB_COOKIE_NAME])) { |
| $ret = $HTTP_COOKIE_VARS[AUTH_DB_COOKIE_NAME]; |
$ret = $HTTP_COOKIE_VARS[AUTH_DB_COOKIE_NAME]; |
| $ret = intval(stripslashes($ret)); |
$ret = intval(stripslashes($ret)); |
| } |
} else { |
| else { |
|
| $ret = ''; |
$ret = ''; |
| } |
} |
| break; |
break; |
|
|
| return $ret; |
return $ret; |
| } |
} |
| |
|
| function _dbGetPassword() |
function _DBgetPassword() |
| { |
{ |
| $query = sprintf('SELECT %s FROM %s WHERE %s = %s', |
$query = sprintf('SELECT %s FROM %s WHERE %s = %s', |
| $this->_options['users']['cols']['password'], |
$this->_options['users']['cols']['password'], |
|
|
| return $password; |
return $password; |
| } |
} |
| |
|
| function _dbInsert() |
function _DBinsert() |
| { |
{ |
| mt_srand((double) microtime() * 1000000); |
mt_srand((double) microtime() * 1000000); |
| |
|
|
|
| return true; |
return true; |
| } |
} |
| |
|
| function _dbLog() |
function _DBlog() |
| { |
{ |
| $query = sprintf('INSERT INTO %s' |
$query = sprintf('INSERT INTO %s' |
| .' (status, login, logout,' |
.' (status, login, logout,' |
|
|
| return true; |
return true; |
| } |
} |
| |
|
| function _dbUpdateTimeout() |
function _DBupdateTimeout() |
| { |
{ |
| if (intval($this->_options['timeout']) <= 0) { |
if (intval($this->_options['timeout']) <= 0) { |
| return true; |
return true; |
|
|
| } |
} |
| |
|
| // This method needs ISDN fastfix |
// This method needs ISDN fastfix |
| function _dbLogout() |
function _DBlogout() |
| { |
{ |
| $query = sprintf('UPDATE %s' |
$query = sprintf('UPDATE %s' |
| .' SET status = "logout", logout = sysdate() ' |
.' SET status = "logout", logout = sysdate() ' |
|
|
| } |
} |
| |
|
| // This method needs ISDN fastfix |
// This method needs ISDN fastfix |
| function _dbUpdateLogin() |
function _DBupdateLogin() |
| { |
{ |
| $query = sprintf('UPDATE %s' |
$query = sprintf('UPDATE %s' |
| .' SET logout = sysdate()' |
.' SET logout = sysdate()' |
|
|
| } |
} |
| |
|
| // This method needs ISDN fastfix |
// This method needs ISDN fastfix |
| function _dbCheckLogin() |
function _DBcheckLogin() |
| { |
{ |
| if ($this->_dbUpdateLogin() == true) |
if ($this->_DBupdateLogin() == true) |
| return true; |
return true; |
| |
|
| $query = sprintf('SELECT id FROM %s' |
$query = sprintf('SELECT id FROM %s' |
|
|
| } |
} |
| |
|
| // This method needs ISDN fastfix |
// This method needs ISDN fastfix |
| function _dbGetUsername() |
function _DBgetUsername() |
| { |
{ |
| $query = sprintf('SELECT username FROM %s' |
$query = sprintf('SELECT username FROM %s' |
| .' WHERE status = "online"' |
.' WHERE status = "online"' |
|
|
| return $res[0]; |
return $res[0]; |
| } |
} |
| |
|
| function _dbGetUserInfo() |
function _DBgetUserInfo() |
| { |
{ |
| $select_cols = array(); |
$select_cols = array(); |
| $select_tables = array(); |
$select_tables = array(); |
|
|
| $select_tables[] = $table; |
$select_tables[] = $table; |
| |
|
| foreach ($cols as $col_val) |
foreach ($cols as $col_val) |
| $select_cols[] = "$table.$col_val AS $prefix"."$col_val"; |
$select_cols[] = "$table.$col_val AS ".$prefix.$col_val; |
| } |
} |
| |
|
| if (count($select_tables) == 0 || count($select_cols) == 0) |
if (count($select_tables) == 0 || count($select_cols) == 0) |