From f726ef87713d9a79c5e3289c8d00e648b4ee67bd Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 25 Jun 2008 11:06:39 -0400 Subject: [PATCH] Updating the auth/ system to ISSO3 --- includes/auth/auth.php | 17 ++++------------- includes/auth/auth_default.php | 20 ++++++++++---------- includes/auth/auth_drupal.php | 20 ++++++++++---------- includes/auth/auth_phpbb2.php | 24 ++++++++++++------------ includes/auth/auth_vbulletin.php | 20 ++++++++++---------- includes/init.php | 11 ++++++----- 6 files changed, 52 insertions(+), 60 deletions(-) diff --git a/includes/auth/auth.php b/includes/auth/auth.php index 34f7cd0..b4d3fbc 100644 --- a/includes/auth/auth.php +++ b/includes/auth/auth.php @@ -47,12 +47,6 @@ class Authentication */ var $db; - /** - * The Bugdar registry - * @var object - */ - var $registry; - /** * Array of user data from the AUTHENTICATION database * @var array @@ -82,12 +76,9 @@ class Authentication */ function __construct() { - global $bugsys; - - $this->registry =& $bugsys; - $this->db =& $bugsys->db; + $this->db = BSApp::$db; - $this->registry->debug('authentication system: ' . get_class($this)); + BSApp::debug('authentication system: ' . get_class($this)); $this->_setupDatabase(); } @@ -243,7 +234,7 @@ class Authentication */ function _fetchBugdarUserFromAuthUser() { - $user = $this->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE authid = '" . $this->authUser[ $this->fieldMap['authid'] ] . "'"); + $user = $this->db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "user WHERE authid = '" . $this->authUser[ $this->fieldMap['authid'] ] . "'"); if (!$user) { return $this->_createBugdarUser(); @@ -264,7 +255,7 @@ class Authentication $user = new UserAPI($this->registry); // if the email already exists in the DB, it must be the same person so just hook up the authid - if ($check = $this->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $this->db->escape_string($this->authUser[ $this->fieldMap['email'] ]) . "'")) + if ($check = $this->db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $this->db->escape_string($this->authUser[ $this->fieldMap['email'] ]) . "'")) { $user->set('userid', $check['userid']); $user->set_condition(); diff --git a/includes/auth/auth_default.php b/includes/auth/auth_default.php index 0fe42ca..fc06ab9 100644 --- a/includes/auth/auth_default.php +++ b/includes/auth/auth_default.php @@ -37,25 +37,25 @@ class AuthenticationDefault extends Authentication // ################################################################### function _setupDatabase() { - $this->authDb =& $this->db; + $this->authDb = $this->db; } // ################################################################### function _fetchCookieUniqueId() { - return $this->registry->input_clean(COOKIE_PREFIX . 'userid', TYPE_UINT); + return BSApp::$input->inputClean(COOKIE_PREFIX . 'userid', TYPE_UINT); } // ################################################################### function _fetchCookiePassword() { - return $this->registry->in[COOKIE_PREFIX . 'authkey']; + return BSApp::$input->in[COOKIE_PREFIX . 'authkey']; } // ################################################################### function _fetchUserUsingCookies() { - return $this->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . $this->_fetchCookieUniqueId()); + return $this->db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . $this->_fetchCookieUniqueId()); } // ################################################################### @@ -67,15 +67,15 @@ class AuthenticationDefault extends Authentication // ################################################################### function _setCookies($sticky = false) { - $this->registry->funct->cookie(COOKIE_PREFIX . 'userid', $this->authUser['userid'], $sticky); - $this->registry->funct->cookie(COOKIE_PREFIX . 'authkey', $this->authUser['authkey'], $sticky); + BSFunctions::cookie(COOKIE_PREFIX . 'userid', $this->authUser['userid'], $sticky); + BSFunctions::cookie(COOKIE_PREFIX . 'authkey', $this->authUser['authkey'], $sticky); } // ################################################################### function clearCookies() { - $this->registry->funct->cookie(COOKIE_PREFIX . 'userid'); - $this->registry->funct->cookie(COOKIE_PREFIX . 'authkey'); + BSFunctions::cookie(COOKIE_PREFIX . 'userid'); + BSFunctions::cookie(COOKIE_PREFIX . 'authkey'); } // ################################################################### @@ -87,7 +87,7 @@ class AuthenticationDefault extends Authentication // ################################################################### function _fetchUserWithIdentifier($email) { - return $this->authDb->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $this->authDb->escape_string($email) . "'"); + return $this->authDb->queryFirst("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $this->authDb->escapeString($email) . "'"); } // ################################################################### @@ -106,4 +106,4 @@ class AuthenticationDefault extends Authentication || # $Id$ || ################################################################### \*=====================================================================*/ -?> +?> \ No newline at end of file diff --git a/includes/auth/auth_drupal.php b/includes/auth/auth_drupal.php index abcf296..2594a2a 100644 --- a/includes/auth/auth_drupal.php +++ b/includes/auth/auth_drupal.php @@ -53,14 +53,14 @@ class AuthenticationDrupal extends Authentication $this->cookieName = ($this->cookieName == null ? session_name() : $this->cookieName); // connect to the DB - $this->authDb = new DB_MySQL($this->registry); - $this->authDb->connect('DRUPAL_DATABASE_SERVER', 'DATABASE_USER', 'DATABASE_PASSWORD', 'DATABASE_NAME', false); + $this->authDb = new BSDbMySQLI(); + $this->authDb->connect('DRUPAL_DATABASE_SERVER', 'DATABASE_USER', 'DATABASE_PASSWORD', 'DATABASE_NAME'); } // ################################################################### function _fetchCookieUniqueId() { - return $this->registry->in[ $this->cookieName ]; + return BSApp::$input->in[$this->cookieName]; } // ################################################################### @@ -72,12 +72,12 @@ class AuthenticationDrupal extends Authentication // ################################################################### function _fetchUserUsingCookies() { - $session = $this->authDb->query_first("SELECT * FROM sessions WHERE sid = '" . $this->authDb->escape_string($this->_fetchCookieUniqueId()) . "'"); + $session = $this->authDb->queryFirst("SELECT * FROM sessions WHERE sid = '" . $this->authDb->escapeString($this->_fetchCookieUniqueId()) . "'"); if (!$session OR $session['uid'] == 0) { return false; } - return $this->authDb->query_first("SELECT * FROM users WHERE uid = " . $session['uid']); + return $this->authDb->queryFirst("SELECT * FROM users WHERE uid = " . $session['uid']); } // ################################################################### @@ -89,7 +89,7 @@ class AuthenticationDrupal extends Authentication // ################################################################### function _fetchUserWithIdentifier($string) { - return $this->authDb->query_first("SELECT * FROM users WHERE name = '" . $this->authDb->escape_string($string) . "'"); + return $this->authDb->queryFirst("SELECT * FROM users WHERE name = '" . $this->authDb->escapeString($string) . "'"); } // ################################################################### @@ -101,8 +101,8 @@ class AuthenticationDrupal extends Authentication // ################################################################### function clearCookies() { - $this->registry->funct->cookie($this->cookieName); - $this->authDb->query("DELETE FROM sessions WHERE sid = '" . $this->authDb->escape_string($this->_fetchCookieUniqueId()) . "'"); + BSFunctions::cookie($this->cookieName); + $this->authDb->query("DELETE FROM sessions WHERE sid = '" . $this->authDb->escapeString($this->_fetchCookieUniqueId()) . "'"); } // ################################################################### @@ -110,8 +110,8 @@ class AuthenticationDrupal extends Authentication { $sid = $this->_fetchCookieUniqueId(); $sid = ($sid ? $sid : md5(microtime() . rand())); - $this->registry->funct->cookie($this->cookieName, $sid, $permanent); - $this->authDb->query("REPLACE INTO sessions (sid, uid, hostname, timestamp) VALUES ('$sid', '" . $this->authUser['uid'] . "', '" . $this->authDb->escape_string($_SERVER['REMOTE_ADDR']) . "', " . time() . ")"); + BSFunctions::cookie($this->cookieName, $sid, $permanent); + $this->authDb->query("REPLACE INTO sessions (sid, uid, hostname, timestamp) VALUES ('$sid', '" . $this->authUser['uid'] . "', '" . $this->authDb->escapeString($_SERVER['REMOTE_ADDR']) . "', " . time() . ")"); } } diff --git a/includes/auth/auth_phpbb2.php b/includes/auth/auth_phpbb2.php index acabf9a..a4391fa 100644 --- a/includes/auth/auth_phpbb2.php +++ b/includes/auth/auth_phpbb2.php @@ -60,14 +60,14 @@ class AuthenticationPhpbb2 extends Authentication function _setupDatabase() { // connect to the DB - $this->authDb = new DB_MySQL($this->registry); - $this->authDb->connect('DATABASE_SERVER', 'DATABASE_USER', 'DATABASE_PASSWORD', 'DATABASE_NAME', false); + $this->authDb = new BSDbMySQLI($this->registry); + $this->authDb->connect('DATABASE_SERVER', 'DATABASE_USER', 'DATABASE_PASSWORD', 'DATABASE_NAME'); } // ################################################################### function _fetchCookieUniqueId() { - $val = $this->registry->in[$this->cookieName . '_sid']; + $val = BSApp::$input->in[$this->cookieName . '_sid']; return (!$val ? -1 : $val); // hack so we don't do stupid things but can still create a session } @@ -80,7 +80,7 @@ class AuthenticationPhpbb2 extends Authentication // ################################################################### function _fetchUserUsingCookies() { - $session = $this->authDb->query_first("SELECT * FROM {$this->phpBBTablePrefix}sessions WHERE session_id = '" . $this->authDb->escape_string($this->_fetchCookieUniqueId()) . "'"); + $session = $this->authDb->queryFirst("SELECT * FROM {$this->phpBBTablePrefix}sessions WHERE session_id = '" . $this->authDb->escapeString($this->_fetchCookieUniqueId()) . "'"); if (!$session) { // phpBB's wacky auto-login system @@ -89,7 +89,7 @@ class AuthenticationPhpbb2 extends Authentication { return false; } - return $this->authDb->query_first("SELECT * FROM {$this->phpBBTablePrefix}users WHERE user_id = " . $this->registry->clean($data['userid'], TYPE_UINT) . " AND user_password = '" . $this->authDb->escape_string($data['autologinid']) . "'"); + return $this->authDb->queryFirst("SELECT * FROM {$this->phpBBTablePrefix}users WHERE user_id = " . BSApp::$input->clean($data['userid'], TYPE_UINT) . " AND user_password = '" . $this->authDb->escapeString($data['autologinid']) . "'"); } else { @@ -97,7 +97,7 @@ class AuthenticationPhpbb2 extends Authentication { return false; } - return $this->authDb->query_first("SELECT * FROM {$this->phpBBTablePrefix}users WHERE user_id = " . $session['session_user_id']); + return $this->authDb->queryFirst("SELECT * FROM {$this->phpBBTablePrefix}users WHERE user_id = " . $session['session_user_id']); } } @@ -110,7 +110,7 @@ class AuthenticationPhpbb2 extends Authentication // ################################################################### function _fetchUserWithIdentifier($string) { - return $this->authDb->query_first("SELECT * FROM {$this->phpBBTablePrefix}users WHERE username = '" . $this->authDb->escape_string($string) . "'"); + return $this->authDb->queryFirst("SELECT * FROM {$this->phpBBTablePrefix}users WHERE username = '" . $this->authDb->escapeString($string) . "'"); } // ################################################################### @@ -122,9 +122,9 @@ class AuthenticationPhpbb2 extends Authentication // ################################################################### function clearCookies() { - $this->registry->funct->cookie($this->cookieName . '_data'); - $this->registry->funct->cookie($this->cookieName . '_sid'); - $this->authDb->query("DELETE FROM {$this->phpBBTablePrefix}sessions WHERE session_id = '" . $this->authDb->escape_string($this->_fetchCookieUniqueId()) . "'"); + BSFunctions::cookie($this->cookieName . '_data'); + BSFunctions::cookie($this->cookieName . '_sid'); + $this->authDb->query("DELETE FROM {$this->phpBBTablePrefix}sessions WHERE session_id = '" . $this->authDb->escapeString($this->_fetchCookieUniqueId()) . "'"); } // ################################################################### @@ -132,10 +132,10 @@ class AuthenticationPhpbb2 extends Authentication { $sid = $this->_fetchCookieUniqueId(); $sid = ($sid != '-1' ? $sid : md5(microtime() . rand())); - $this->registry->funct->cookie($this->cookieName . '_sid', $sid, false); + BSFunctions::cookie($this->cookieName . '_sid', $sid, false); if ($permanent) { - $this->registry->funct->cookie($this->cookieName . '_data', serialize(array('autologinid' => $this->authUser['user_password'], 'userid' => $this->authUser['user_id'])), true); + BSFunctions::cookie($this->cookieName . '_data', serialize(array('autologinid' => $this->authUser['user_password'], 'userid' => $this->authUser['user_id'])), true); } $this->authDb->query(" REPLACE INTO {$this->phpBBTablePrefix}sessions diff --git a/includes/auth/auth_vbulletin.php b/includes/auth/auth_vbulletin.php index 2d6da6b..b6e6f02 100644 --- a/includes/auth/auth_vbulletin.php +++ b/includes/auth/auth_vbulletin.php @@ -62,26 +62,26 @@ class AuthenticationVbulletin extends Authentication // ################################################################### function _setupDatabase() { - $this->authDb = new DB_MySQL($this->registry); - $this->authDb->connect('VBULLETIN_DATABASE_SERVER', 'VB_DATABASE_USER', 'VB_DATABASE_PASSWORD', 'VBULLETIN_DATABASE_NAME', false); + $this->authDb = new BSDbMySqlI($this->registry); + $this->authDb->connect('VBULLETIN_DATABASE_SERVER', 'VB_DATABASE_USER', 'VB_DATABASE_PASSWORD', 'VBULLETIN_DATABASE_NAME'); } // ################################################################### function _fetchCookieUniqueId() { - return $this->registry->input_clean('bbuserid', TYPE_UINT); + return BSApp::$input->inputClean('bbuserid', TYPE_UINT); } // ################################################################### function _fetchCookiePassword() { - return $this->registry->in['bbpassword']; + return BSApp::$input->in['bbpassword']; } // ################################################################### function _fetchUserUsingCookies() { - return $this->authDb->query_first("SELECT * FROM {$this->vBTablePrefix}user WHERE userid = " . $this->_fetchCookieUniqueId()); + return $this->authDb->queryFirst("SELECT * FROM {$this->vBTablePrefix}user WHERE userid = " . $this->_fetchCookieUniqueId()); } // ################################################################### @@ -93,21 +93,21 @@ class AuthenticationVbulletin extends Authentication // ################################################################### function _setCookies($sticky = false) { - $this->registry->funct->cookie('bbuserid', $this->authUser['userid'], $sticky); - $this->registry->funct->cookie('bbpassword', md5($this->authUser['password'] . $this->licenseKey), $sticky); + BSFunctions::cookie('bbuserid', $this->authUser['userid'], $sticky); + BSFunctions::cookie('bbpassword', md5($this->authUser['password'] . $this->licenseKey), $sticky); } // ################################################################### function clearCookies() { - $this->registry->funct->cookie('bbpassword'); - $this->registry->funct->cookie('bbuserid'); + BSFunctions::cookie('bbpassword'); + BSFunctions::cookie('bbuserid'); } // ################################################################### function _fetchUserWithIdentifier($username) { - return $this->authDb->query_first("SELECT * FROM {$this->vBTablePrefix}user WHERE username = '" . $this->authDb->escape_string($username) . "'"); + return $this->authDb->queryFirst("SELECT * FROM {$this->vBTablePrefix}user WHERE username = '" . $this->authDb->escapeString($username) . "'"); } // ################################################################### diff --git a/includes/init.php b/includes/init.php index cf2d30a..3862ebc 100755 --- a/includes/init.php +++ b/includes/init.php @@ -41,6 +41,12 @@ define('ISSO', getcwd() . '/includes/framework/'); require_once ISSO . '/App.php'; BSApp::set_debug($debug); +require_once ISSO . '/Functions.php'; +BSFunctions::set_cookie_timeout(3600); + +require_once ISSO . '/Input.php'; +$input = BSApp::$input = new BSInput(); + // ################################################################### // initialize the database @@ -53,11 +59,6 @@ if ($utf8) $db->query("SET NAMES utf8"); } -require_once ISSO . '/Functions.php'; - -// change cookie expiration to one hour -BSFunctions::set_cookie_timeout(3600); - define('DEVDEBUG', $debug); define('TABLE_PREFIX', $tableprefix); define('COOKIE_PREFIX', $cookieprefix); -- 2.43.5