- Timestamp:
- Dec 11, 2013 2:30:49 AM (10 years ago)
- Location:
- branches/eli_branch/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eli_branch/lib/Auth_File.inc.php
r439 r445 21 21 */ 22 22 23 /* *23 /* 24 24 * Auth_File.inc.php 25 25 * … … 55 55 private $_default_params = array( 56 56 57 // Full path to htpasswd file. 58 'htpasswd_file' => null, 59 60 // The type of encryption to use for passwords stored in the db_table. Use one of the AUTH_ENCRYPT_* types specified above. 61 'encryption_type' => AUTH_ENCRYPT_CRYPT, 62 63 // The URL to the login script. 64 'login_url' => '/', 65 66 // The maximum amount of time a user is allowed to be logged in. They will be forced to login again if they expire. 67 // This applies to admins and users. In seconds. 21600 seconds = 6 hours. 68 'login_timeout' => 21600, 69 70 // The maximum amount of time a user is allowed to be idle before their session expires. They will be forced to login again if they expire. 71 // This applies to admins and users. In seconds. 3600 seconds = 1 hour. 72 'idle_timeout' => 3600, 73 74 // An array of IP blocks that are bypass the remote_ip comparison check. Useful for dynamic IPs or those behind proxy servers. 75 'trusted_networks' => array(), ); 57 // Full path to htpasswd file. 58 'htpasswd_file' => null, 59 60 // The type of encryption to use for passwords stored in the db_table. Use one of the AUTH_ENCRYPT_* types specified above. 61 'encryption_type' => AUTH_ENCRYPT_CRYPT, 62 63 // The URL to the login script. 64 'login_url' => '/', 65 66 // The maximum amount of time a user is allowed to be logged in. They will be forced to login again if they expire. 67 // This applies to admins and users. In seconds. 21600 seconds = 6 hours. 68 'login_timeout' => 21600, 69 70 // The maximum amount of time a user is allowed to be idle before their session expires. They will be forced to login again if they expire. 71 // This applies to admins and users. In seconds. 3600 seconds = 1 hour. 72 'idle_timeout' => 3600, 73 74 // An array of IP blocks that are bypass the remote_ip comparison check. Useful for dynamic IPs or those behind proxy servers. 75 'trusted_networks' => array(), 76 ); 76 77 77 78 // Associative array of usernames to hashed passwords. 78 79 private $_users = array(); 79 80 80 /** 81 * Constructs a new htpasswd authentication object. 82 * 83 * @access public 84 * 85 * @param optional array $params A hash containing parameters. 86 */ 87 public function __construct($namespace = '') { 88 $this -> _ns = $namespace; 81 /* 82 * Constructs a new htpasswd authentication object. 83 * 84 * @access public 85 * 86 * @param optional array $params A hash containing parameters. 87 */ 88 public function __construct($namespace='') 89 { 90 $this->_ns = $namespace; 89 91 90 92 // Initialize default parameters. 91 $this -> setParam($this -> _default_params); 92 } 93 94 /** 95 * Set the params of an auth object. 96 * 97 * @param array $params Array of parameter keys and value to set. 98 * @return bool true on success, false on failure 99 */ 100 public function setParam($params) { 93 $this->setParam($this->_default_params); 94 } 95 96 /* 97 * Set the params of an auth object. 98 * 99 * @param array $params Array of parameter keys and value to set. 100 * @return bool true on success, false on failure 101 */ 102 public function setParam($params) 103 { 101 104 if (isset($params) && is_array($params)) { 102 105 // Merge new parameters with old overriding only those passed. 103 $this -> _params = array_merge($this -> _params, $params); 104 } 105 } 106 107 /** 108 * Return the value of a parameter, if it exists. 109 * 110 * @access public 111 * @param string $param Which parameter to return. 112 * @return mixed Configured parameter value. 113 */ 114 public function getParam($param) { 106 $this->_params = array_merge($this->_params, $params); 107 } 108 } 109 110 /* 111 * Return the value of a parameter, if it exists. 112 * 113 * @access public 114 * @param string $param Which parameter to return. 115 * @return mixed Configured parameter value. 116 */ 117 public function getParam($param) 118 { 115 119 $app = &App::getInstance(); 116 120 117 if (isset($this ->_params[$param])) {118 return $this ->_params[$param];121 if (isset($this->_params[$param])) { 122 return $this->_params[$param]; 119 123 } else { 120 $app ->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);124 $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__); 121 125 return null; 122 126 } 123 127 } 124 128 125 /** 126 * Clear any authentication tokens in the current session. A.K.A. logout. 127 * 128 * @access public 129 */ 130 public function clear() { 131 $_SESSION['_auth_file'][$this -> _ns] = array('authenticated' => false); 132 } 133 134 /** 135 * Sets a variable into a registered auth session. 136 * 137 * @access public 138 * @param mixed $key Which value to set. 139 * @param mixed $val Value to set variable to. 140 */ 141 public function set($key, $val) { 142 if (!isset($_SESSION['_auth_file'][$this -> _ns]['user_data'])) { 143 $_SESSION['_auth_file'][$this -> _ns]['user_data'] = array(); 144 } 145 $_SESSION['_auth_file'][$this -> _ns]['user_data'][$key] = $val; 146 } 147 148 /** 149 * Returns a specified value from a registered auth session. 150 * 151 * @access public 152 * @param mixed $key Which value to return. 153 * @param mixed $default Value to return if key not found in user_data. 154 * @return mixed Value stored in session. 155 */ 156 public function get($key, $default = '') { 157 if (isset($_SESSION['_auth_file'][$this -> _ns][$key])) { 158 return $_SESSION['_auth_file'][$this -> _ns][$key]; 159 } else if (isset($_SESSION['_auth_file'][$this -> _ns]['user_data'][$key])) { 160 return $_SESSION['_auth_file'][$this -> _ns]['user_data'][$key]; 129 /* 130 * Clear any authentication tokens in the current session. A.K.A. logout. 131 * 132 * @access public 133 */ 134 public function clear() 135 { 136 $_SESSION['_auth_file'][$this->_ns] = array('authenticated' => false); 137 } 138 139 /* 140 * Sets a variable into a registered auth session. 141 * 142 * @access public 143 * @param mixed $key Which value to set. 144 * @param mixed $val Value to set variable to. 145 */ 146 public function set($key, $val) 147 { 148 if (!isset($_SESSION['_auth_file'][$this->_ns]['user_data'])) { 149 $_SESSION['_auth_file'][$this->_ns]['user_data'] = array(); 150 } 151 $_SESSION['_auth_file'][$this->_ns]['user_data'][$key] = $val; 152 } 153 154 /* 155 * Returns a specified value from a registered auth session. 156 * 157 * @access public 158 * @param mixed $key Which value to return. 159 * @param mixed $default Value to return if key not found in user_data. 160 * @return mixed Value stored in session. 161 */ 162 public function get($key, $default='') 163 { 164 if (isset($_SESSION['_auth_file'][$this->_ns][$key])) { 165 return $_SESSION['_auth_file'][$this->_ns][$key]; 166 } else if (isset($_SESSION['_auth_file'][$this->_ns]['user_data'][$key])) { 167 return $_SESSION['_auth_file'][$this->_ns]['user_data'][$key]; 161 168 } else { 162 169 return $default; … … 164 171 } 165 172 166 /** 167 * Find out if a set of login credentials are valid. Only supports 168 * htpasswd files with DES passwords right now. 169 * 170 * @access public 171 * 172 * @param string $username The username to check. 173 * @param array $password The password to compare to username. 174 * 175 * @return boolean Whether or not the credentials are valid. 176 */ 177 public function authenticate($username, $password) { 173 /* 174 * Find out if a set of login credentials are valid. Only supports 175 * htpasswd files with DES passwords right now. 176 * 177 * @access public 178 * 179 * @param string $username The username to check. 180 * @param array $password The password to compare to username. 181 * 182 * @return boolean Whether or not the credentials are valid. 183 */ 184 public function authenticate($username, $password) 185 { 178 186 $app = &App::getInstance(); 179 187 180 188 if ('' == trim($password)) { 181 $app ->logMsg(_("No password provided for authentication."), LOG_INFO, __FILE__, __LINE__);189 $app->logMsg(_("No password provided for authentication."), LOG_INFO, __FILE__, __LINE__); 182 190 return false; 183 191 } 184 192 185 193 // Load users file. 186 $this ->_loadHTPasswdFile();187 188 if (!isset($this ->_users[$username])) {189 $app ->logMsg(_("User ID provided does not exist."), LOG_INFO, __FILE__, __LINE__);190 return false; 191 } 192 193 if ($this -> _encrypt($password, $this -> _users[$username]) != $this ->_users[$username]) {194 $app ->logMsg(sprintf('Authentication failed for user %s', $username), LOG_INFO, __FILE__, __LINE__);194 $this->_loadHTPasswdFile(); 195 196 if (!isset($this->_users[$username])) { 197 $app->logMsg(_("User ID provided does not exist."), LOG_INFO, __FILE__, __LINE__); 198 return false; 199 } 200 201 if ($this->_encrypt($password, $this->_users[$username]) != $this->_users[$username]) { 202 $app->logMsg(sprintf('Authentication failed for user %s', $username), LOG_INFO, __FILE__, __LINE__); 195 203 return false; 196 204 } … … 200 208 } 201 209 202 /** 203 * If user passes authentication create authenticated session. 204 * 205 * @access public 206 * 207 * @param string $username The username to check. 208 * @param array $password The password to compare to username. 209 * 210 * @return boolean Whether or not the credentials are valid. 211 */ 212 public function login($username, $password) { 210 /* 211 * If user passes authentication create authenticated session. 212 * 213 * @access public 214 * 215 * @param string $username The username to check. 216 * @param array $password The password to compare to username. 217 * 218 * @return boolean Whether or not the credentials are valid. 219 */ 220 public function login($username, $password) 221 { 213 222 $username = mb_strtolower(trim($username)); 214 223 215 $this ->clear();216 217 if (!$this ->authenticate($username, $password)) {224 $this->clear(); 225 226 if (!$this->authenticate($username, $password)) { 218 227 // No login: failed authentication! 219 228 return false; 220 229 } 221 230 222 $_SESSION['_auth_file'][$this -> _ns] = array('authenticated' => true, 'username' => $username, 'login_datetime' => date('Y-m-d H:i:s'), 'last_access_datetime' => date('Y-m-d H:i:s'), 'remote_ip' => getRemoteAddr()); 231 $_SESSION['_auth_file'][$this->_ns] = array( 232 'authenticated' => true, 233 'username' => $username, 234 'login_datetime' => date('Y-m-d H:i:s'), 235 'last_access_datetime' => date('Y-m-d H:i:s'), 236 'remote_ip' => getRemoteAddr() 237 ); 223 238 224 239 // We're logged-in! … … 226 241 } 227 242 228 /** 229 * Test if user has a currently logged-in session. 230 * - authentication flag set to true 231 * - username not empty 232 * - total logged-in time is not greater than login_timeout 233 * - idle time is not greater than idle_timeout 234 * - remote address is the same as the login remote address. 235 * 236 * @access public 237 */ 238 public function isLoggedIn() { 243 /* 244 * Test if user has a currently logged-in session. 245 * - authentication flag set to true 246 * - username not empty 247 * - total logged-in time is not greater than login_timeout 248 * - idle time is not greater than idle_timeout 249 * - remote address is the same as the login remote address. 250 * 251 * @access public 252 */ 253 public function isLoggedIn() 254 { 239 255 $app = &App::getInstance(); 240 256 241 257 // Some users will access from networks with a changing IP number (i.e. behind a proxy server). These users must be allowed entry by adding their IP to the list of trusted_networks. 242 if ($trusted_net = ipInRange(getRemoteAddr(), $this ->_params['trusted_networks'])) {258 if ($trusted_net = ipInRange(getRemoteAddr(), $this->_params['trusted_networks'])) { 243 259 $user_in_trusted_network = true; 244 $app -> logMsg(sprintf('User %s accessing from trusted network %s', $_SESSION['_auth_file'][$this ->_ns]['username'], $trusted_net), LOG_DEBUG, __FILE__, __LINE__);260 $app->logMsg(sprintf('User %s accessing from trusted network %s', $_SESSION['_auth_file'][$this->_ns]['username'], $trusted_net), LOG_DEBUG, __FILE__, __LINE__); 245 261 } else if (preg_match('/proxy.aol.com$/i', getRemoteAddr(true))) { 246 262 $user_in_trusted_network = true; 247 $app -> logMsg(sprintf('User %s accessing from trusted network proxy.aol.com', $_SESSION['_auth_file'][$this ->_ns]['username']), LOG_DEBUG, __FILE__, __LINE__);263 $app->logMsg(sprintf('User %s accessing from trusted network proxy.aol.com', $_SESSION['_auth_file'][$this->_ns]['username']), LOG_DEBUG, __FILE__, __LINE__); 248 264 } else { 249 265 $user_in_trusted_network = false; … … 251 267 252 268 // Test login with information stored in session. Skip IP matching for users from trusted networks. 253 if (isset($_SESSION['_auth_file'][$this -> _ns]) && true === $_SESSION['_auth_file'][$this -> _ns]['authenticated'] && !empty($_SESSION['_auth_file'][$this -> _ns]['username']) && strtotime($_SESSION['_auth_file'][$this -> _ns]['login_datetime']) > time() - $this -> _params['login_timeout'] && strtotime($_SESSION['_auth_file'][$this -> _ns]['last_access_datetime']) > time() - $this -> _params['idle_timeout'] && ($_SESSION['_auth_file'][$this -> _ns]['remote_ip'] == getRemoteAddr() || $user_in_trusted_network)) { 269 if (isset($_SESSION['_auth_file'][$this->_ns]) 270 && true === $_SESSION['_auth_file'][$this->_ns]['authenticated'] 271 && !empty($_SESSION['_auth_file'][$this->_ns]['username']) 272 && strtotime($_SESSION['_auth_file'][$this->_ns]['login_datetime']) > time() - $this->_params['login_timeout'] 273 && strtotime($_SESSION['_auth_file'][$this->_ns]['last_access_datetime']) > time() - $this->_params['idle_timeout'] 274 && ($_SESSION['_auth_file'][$this->_ns]['remote_ip'] == getRemoteAddr() || $user_in_trusted_network) 275 ) { 254 276 // User is authenticated! 255 $_SESSION['_auth_file'][$this ->_ns]['last_access_datetime'] = date('Y-m-d H:i:s');277 $_SESSION['_auth_file'][$this->_ns]['last_access_datetime'] = date('Y-m-d H:i:s'); 256 278 return true; 257 } else if (isset($_SESSION['_auth_file'][$this -> _ns]) && true === $_SESSION['_auth_file'][$this ->_ns]['authenticated']) {258 if (strtotime($_SESSION['_auth_file'][$this ->_ns]['last_access_datetime']) > time() - 43200) {279 } else if (isset($_SESSION['_auth_file'][$this->_ns]) && true === $_SESSION['_auth_file'][$this->_ns]['authenticated']) { 280 if (strtotime($_SESSION['_auth_file'][$this->_ns]['last_access_datetime']) > time() - 43200) { 259 281 // Only raise message if last session is less than 12 hours old. 260 $app ->raiseMsg(_("Your session has closed. You need to log-in again."), MSG_NOTICE, __FILE__, __LINE__);282 $app->raiseMsg(_("Your session has closed. You need to log-in again."), MSG_NOTICE, __FILE__, __LINE__); 261 283 } 262 284 263 285 // Log the reason for login expiration. 264 286 $expire_reasons = array(); 265 if (empty($_SESSION['_auth_file'][$this ->_ns]['username'])) {287 if (empty($_SESSION['_auth_file'][$this->_ns]['username'])) { 266 288 $expire_reasons[] = 'username not found'; 267 289 } 268 if (strtotime($_SESSION['_auth_file'][$this -> _ns]['login_datetime']) <= time() - $this ->_params['login_timeout']) {290 if (strtotime($_SESSION['_auth_file'][$this->_ns]['login_datetime']) <= time() - $this->_params['login_timeout']) { 269 291 $expire_reasons[] = 'login_timeout expired'; 270 292 } 271 if (strtotime($_SESSION['_auth_file'][$this -> _ns]['last_access_datetime']) <= time() - $this ->_params['idle_timeout']) {293 if (strtotime($_SESSION['_auth_file'][$this->_ns]['last_access_datetime']) <= time() - $this->_params['idle_timeout']) { 272 294 $expire_reasons[] = 'idle_timeout expired'; 273 295 } 274 if ($_SESSION['_auth_file'][$this ->_ns]['remote_ip'] != getRemoteAddr() && !$user_in_trusted_network) {275 $expire_reasons[] = sprintf('remote_ip not matched (%s != %s)', $_SESSION['_auth_file'][$this ->_ns]['remote_ip'], getRemoteAddr());276 } 277 $app -> logMsg(sprintf('User %s session expired: %s', $_SESSION['_auth_file'][$this ->_ns]['username'], join(', ', $expire_reasons)), LOG_INFO, __FILE__, __LINE__);296 if ($_SESSION['_auth_file'][$this->_ns]['remote_ip'] != getRemoteAddr() && !$user_in_trusted_network) { 297 $expire_reasons[] = sprintf('remote_ip not matched (%s != %s)', $_SESSION['_auth_file'][$this->_ns]['remote_ip'], getRemoteAddr()); 298 } 299 $app->logMsg(sprintf('User %s session expired: %s', $_SESSION['_auth_file'][$this->_ns]['username'], join(', ', $expire_reasons)), LOG_INFO, __FILE__, __LINE__); 278 300 } 279 301 … … 281 303 } 282 304 283 /** 284 * Redirect user to login page if they are not logged in. 285 * 286 * @param string $message The text description of a message to raise. 287 * @param int $type The type of message: MSG_NOTICE, 288 * MSG_SUCCESS, MSG_WARNING, or MSG_ERR. 289 * @param string $file __FILE__. 290 * @param string $line __LINE__. 291 * @access public 292 */ 293 public function requireLogin($message = '', $type = MSG_NOTICE, $file = null, $line = null) { 305 /* 306 * Redirect user to login page if they are not logged in. 307 * 308 * @param string $message The text description of a message to raise. 309 * @param int $type The type of message: MSG_NOTICE, 310 * MSG_SUCCESS, MSG_WARNING, or MSG_ERR. 311 * @param string $file __FILE__. 312 * @param string $line __LINE__. 313 * @access public 314 */ 315 public function requireLogin($message='', $type=MSG_NOTICE, $file=null, $line=null) 316 { 294 317 $app = &App::getInstance(); 295 318 296 if (!$this ->isLoggedIn()) {319 if (!$this->isLoggedIn()) { 297 320 // Display message for requiring login. (RaiseMsg will ignore empty strings.) 298 $app ->raiseMsg($message, $type, $file, $line);321 $app->raiseMsg($message, $type, $file, $line); 299 322 300 323 // Login scripts must have the same 'login' tag for boomerangURL verification/manipulation. 301 $app ->setBoomerangURL(absoluteMe(), 'login');302 $app -> dieURL($this ->_params['login_url']);303 } 304 } 305 306 /* *307 308 309 310 311 324 $app->setBoomerangURL(absoluteMe(), 'login'); 325 $app->dieURL($this->_params['login_url']); 326 } 327 } 328 329 /* 330 * Wrapper function for compatibility with lib/Lock.inc.php. 331 * 332 * @param string $username Username to return. 333 * @return string Username, or false if none found. 334 */ 312 335 public function getUsername($username) { 313 336 if ('' != $username) { … … 319 342 320 343 /* 321 * Reads the configured htpasswd file into the _users array. 322 * 323 * @access public 324 * @return false on error, true on success. 325 * @author Quinn Comendant <quinn@strangecode.com> 326 * @version 1.0 327 * @since 18 Apr 2006 18:17:48 328 */ 329 private function _loadHTPasswdFile() { 344 * Reads the configured htpasswd file into the _users array. 345 * 346 * @access public 347 * @return false on error, true on success. 348 * @author Quinn Comendant <quinn@strangecode.com> 349 * @version 1.0 350 * @since 18 Apr 2006 18:17:48 351 */ 352 private function _loadHTPasswdFile() 353 { 330 354 $app = &App::getInstance(); 331 355 332 356 static $users = null; 333 357 334 if (!file_exists($this ->_params['htpasswd_file'])) {335 $app -> logMsg(sprintf('htpasswd file missing or not specified: %s', $this ->_params['htpasswd_file']), LOG_ERR, __FILE__, __LINE__);358 if (!file_exists($this->_params['htpasswd_file'])) { 359 $app->logMsg(sprintf('htpasswd file missing or not specified: %s', $this->_params['htpasswd_file']), LOG_ERR, __FILE__, __LINE__); 336 360 return false; 337 361 } 338 362 339 363 if (!isset($users)) { 340 if (false === ($users = file($this ->_params['htpasswd_file']))) {341 $app -> logMsg(sprintf('Could not read htpasswd file: %s', $this ->_params['htpasswd_file']), LOG_ERR, __FILE__, __LINE__);364 if (false === ($users = file($this->_params['htpasswd_file']))) { 365 $app->logMsg(sprintf('Could not read htpasswd file: %s', $this->_params['htpasswd_file']), LOG_ERR, __FILE__, __LINE__); 342 366 return false; 343 367 } … … 347 371 foreach ($users as $u) { 348 372 list($user, $pass) = explode(':', $u, 2); 349 $this ->_users[trim($user)] = trim($pass);373 $this->_users[trim($user)] = trim($pass); 350 374 } 351 375 return true; … … 354 378 } 355 379 356 /** 357 * Hash a given password according to the configured encryption 358 * type. 359 * 360 * @param string $password The password to encrypt. 361 * @param string $encrypted_password The currently encrypted password to use as salt, if needed. 362 * 363 * @return string The hashed password. 364 */ 365 private function _encrypt($password, $encrypted_password = null) { 380 /* 381 * Hash a given password according to the configured encryption 382 * type. 383 * 384 * @param string $password The password to encrypt. 385 * @param string $encrypted_password The currently encrypted password to use as salt, if needed. 386 * 387 * @return string The hashed password. 388 */ 389 private function _encrypt($password, $encrypted_password=null) 390 { 366 391 switch ($this->_params['encryption_type']) { 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 392 case AUTH_ENCRYPT_PLAINTEXT : 393 return $password; 394 break; 395 396 case AUTH_ENCRYPT_SHA1 : 397 return sha1($password); 398 break; 399 400 case AUTH_ENCRYPT_MD5 : 401 return md5($password); 402 break; 403 404 case AUTH_ENCRYPT_CRYPT : 405 default : 406 return crypt($password, $encrypted_password); 407 break; 383 408 } 384 409 } -
branches/eli_branch/lib/DB.inc.php
r439 r445 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 37 37 // Database handle. 38 38 public $dbh; 39 39 40 40 // Count how many queries run during the whole instance. 41 41 private $_query_count = 0; … … 58 58 // Display db errors. FALSE recommended for production sites. 59 59 'db_debug' => false, 60 60 61 61 // Script stops on db error. TRUE recommended for production sites. 62 62 'db_die_on_failure' => true, … … 70 70 71 71 // Caches. 72 p ublic$existing_tables;73 p ublic$table_columns;72 private $existing_tables; 73 private $table_columns; 74 74 75 75 /** … … 101 101 { 102 102 $app =& App::getInstance(); 103 103 104 104 if (isset($params) && is_array($params)) { 105 105 // Merge new parameters with old overriding only those passed. … … 120 120 { 121 121 $app =& App::getInstance(); 122 122 123 123 if (isset($this->_params[$param])) { 124 124 return $this->_params[$param]; … … 139 139 { 140 140 $app =& App::getInstance(); 141 141 142 142 if (!$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass')) { 143 143 $app->logMsg('Database credentials missing.', LOG_EMERG, __FILE__, __LINE__); … … 193 193 return mysql_close($this->dbh); 194 194 } 195 195 196 196 /* 197 * 197 * 198 198 * 199 199 * @access public 200 * @param 201 * @return 200 * @param 201 * @return 202 202 * @author Quinn Comendant <quinn@strangecode.com> 203 203 * @version 1.0 … … 209 209 $this->connect(); 210 210 } 211 211 212 212 /* 213 213 * Die only if db_die_on_failure is true. This will be set to false for some cases … … 260 260 return (true === $this->_connected); 261 261 } 262 262 263 263 /** 264 264 * Returns a properly escaped string using mysql_real_escape_string() with the current connection's charset. … … 288 288 */ 289 289 public function query($query, $debug=false) 290 { 290 { 291 291 $app =& App::getInstance(); 292 292 … … 301 301 echo "<!-- ----------------- Query $this->_query_count ---------------------\n$debugqry\n-->\n"; 302 302 } 303 304 // Ensure we have an active connection. 303 304 // Ensure we have an active connection. 305 305 // If we continue on a dead connection we might experience a "MySQL server has gone away" error. 306 306 // http://dev.mysql.com/doc/refman/5.0/en/gone-away.html … … 318 318 if ($this->getParam('db_debug')) { 319 319 echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>'; 320 } 320 } 321 321 // Die if db_die_on_failure = true, or just continue without connection 322 322 return $this->_fail(); … … 339 339 { 340 340 $app =& App::getInstance(); 341 341 342 342 if (!$this->_connected) { 343 343 return false; … … 406 406 } 407 407 } 408 408 409 409 /* 410 410 * Return the total number of queries executed thus far. -
branches/eli_branch/lib/PageNumbers.inc.php
r439 r445 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 85 85 // in special cases like using a /my/page/# scheme. 86 86 $this->url_base = $_SERVER['PHP_SELF'] . '?page_number='; 87 87 88 88 $this->prefs = new Prefs($_SERVER['PHP_SELF']); 89 89 $this->prefs->setParam(array('persistent' => false));
Note: See TracChangeset
for help on using the changeset viewer.