Changeset 445 for branches


Ignore:
Timestamp:
Dec 11, 2013 2:30:49 AM (10 years ago)
Author:
anonymous
Message:

Fixed some issues introduced in changeset:439

Location:
branches/eli_branch/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eli_branch/lib/Auth_File.inc.php

    r439 r445  
    2121 */
    2222
    23 /**
     23/*
    2424 * Auth_File.inc.php
    2525 *
     
    5555    private $_default_params = array(
    5656
    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    );
    7677
    7778    // Associative array of usernames to hashed passwords.
    7879    private $_users = array();
    7980
    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;
    8991
    9092        // 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    {
    101104        if (isset($params) && is_array($params)) {
    102105            // 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    {
    115119        $app = &App::getInstance();
    116120
    117         if (isset($this -> _params[$param])) {
    118             return $this -> _params[$param];
     121        if (isset($this->_params[$param])) {
     122            return $this->_params[$param];
    119123        } 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__);
    121125            return null;
    122126        }
    123127    }
    124128
    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];
    161168        } else {
    162169            return $default;
     
    164171    }
    165172
    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    {
    178186        $app = &App::getInstance();
    179187
    180188        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__);
    182190            return false;
    183191        }
    184192
    185193        // 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__);
    195203            return false;
    196204        }
     
    200208    }
    201209
    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    {
    213222        $username = mb_strtolower(trim($username));
    214223
    215         $this -> clear();
    216 
    217         if (!$this -> authenticate($username, $password)) {
     224        $this->clear();
     225
     226        if (!$this->authenticate($username, $password)) {
    218227            // No login: failed authentication!
    219228            return false;
    220229        }
    221230
    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        );
    223238
    224239        // We're logged-in!
     
    226241    }
    227242
    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    {
    239255        $app = &App::getInstance();
    240256
    241257        // 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'])) {
    243259            $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__);
    245261        } else if (preg_match('/proxy.aol.com$/i', getRemoteAddr(true))) {
    246262            $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__);
    248264        } else {
    249265            $user_in_trusted_network = false;
     
    251267
    252268        // 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        ) {
    254276            // 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');
    256278            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) {
    259281                // 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__);
    261283            }
    262284
    263285            // Log the reason for login expiration.
    264286            $expire_reasons = array();
    265             if (empty($_SESSION['_auth_file'][$this -> _ns]['username'])) {
     287            if (empty($_SESSION['_auth_file'][$this->_ns]['username'])) {
    266288                $expire_reasons[] = 'username not found';
    267289            }
    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']) {
    269291                $expire_reasons[] = 'login_timeout expired';
    270292            }
    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']) {
    272294                $expire_reasons[] = 'idle_timeout expired';
    273295            }
    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__);
    278300        }
    279301
     
    281303    }
    282304
    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    {
    294317        $app = &App::getInstance();
    295318
    296         if (!$this -> isLoggedIn()) {
     319        if (!$this->isLoggedIn()) {
    297320            // Display message for requiring login. (RaiseMsg will ignore empty strings.)
    298             $app -> raiseMsg($message, $type, $file, $line);
     321            $app->raiseMsg($message, $type, $file, $line);
    299322
    300323            // 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      * Wrapper function for compatibility with lib/Lock.inc.php.
    308      *
    309      * @param  string  $username    Username to return.
    310      * @return string               Username, or false if none found.
    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    */
    312335    public function getUsername($username) {
    313336        if ('' != $username) {
     
    319342
    320343    /*
    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    {
    330354        $app = &App::getInstance();
    331355
    332356        static $users = null;
    333357
    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__);
    336360            return false;
    337361        }
    338362
    339363        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__);
    342366                return false;
    343367            }
     
    347371            foreach ($users as $u) {
    348372                list($user, $pass) = explode(':', $u, 2);
    349                 $this -> _users[trim($user)] = trim($pass);
     373                $this->_users[trim($user)] = trim($pass);
    350374            }
    351375            return true;
     
    354378    }
    355379
    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    {
    366391        switch ($this->_params['encryption_type']) {
    367             case AUTH_ENCRYPT_PLAINTEXT :
    368                 return $password;
    369                 break;
    370 
    371             case AUTH_ENCRYPT_SHA1 :
    372                 return sha1($password);
    373                 break;
    374 
    375             case AUTH_ENCRYPT_MD5 :
    376                 return md5($password);
    377                 break;
    378 
    379             case AUTH_ENCRYPT_CRYPT :
    380             default :
    381                 return crypt($password, $encrypted_password);
    382                 break;
     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;
    383408        }
    384409    }
  • branches/eli_branch/lib/DB.inc.php

    r439 r445  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    3737    // Database handle.
    3838    public $dbh;
    39    
     39
    4040    // Count how many queries run during the whole instance.
    4141    private $_query_count = 0;
     
    5858        // Display db errors. FALSE recommended for production sites.
    5959        'db_debug' => false,
    60        
     60
    6161        // Script stops on db error. TRUE recommended for production sites.
    6262        'db_die_on_failure' => true,
     
    7070
    7171    // Caches.
    72     public $existing_tables;
    73     public $table_columns;
     72    private $existing_tables;
     73    private $table_columns;
    7474
    7575    /**
     
    101101    {
    102102        $app =& App::getInstance();
    103    
     103
    104104        if (isset($params) && is_array($params)) {
    105105            // Merge new parameters with old overriding only those passed.
     
    120120    {
    121121        $app =& App::getInstance();
    122    
     122
    123123        if (isset($this->_params[$param])) {
    124124            return $this->_params[$param];
     
    139139    {
    140140        $app =& App::getInstance();
    141    
     141
    142142        if (!$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass')) {
    143143            $app->logMsg('Database credentials missing.', LOG_EMERG, __FILE__, __LINE__);
     
    193193        return mysql_close($this->dbh);
    194194    }
    195    
     195
    196196    /*
    197     * 
     197    *
    198198    *
    199199    * @access   public
    200     * @param   
    201     * @return   
     200    * @param
     201    * @return
    202202    * @author   Quinn Comendant <quinn@strangecode.com>
    203203    * @version  1.0
     
    209209        $this->connect();
    210210    }
    211    
     211
    212212    /*
    213213    * Die only if db_die_on_failure is true. This will be set to false for some cases
     
    260260        return (true === $this->_connected);
    261261    }
    262    
     262
    263263    /**
    264264     * Returns a properly escaped string using mysql_real_escape_string() with the current connection's charset.
     
    288288     */
    289289    public function query($query, $debug=false)
    290     {   
     290    {
    291291        $app =& App::getInstance();
    292292
     
    301301            echo "<!-- ----------------- Query $this->_query_count ---------------------\n$debugqry\n-->\n";
    302302        }
    303        
    304         // Ensure we have an active connection. 
     303
     304        // Ensure we have an active connection.
    305305        // If we continue on a dead connection we might experience a "MySQL server has gone away" error.
    306306        // http://dev.mysql.com/doc/refman/5.0/en/gone-away.html
     
    318318            if ($this->getParam('db_debug')) {
    319319                echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
    320             }           
     320            }
    321321            // Die if db_die_on_failure = true, or just continue without connection
    322322            return $this->_fail();
     
    339339    {
    340340        $app =& App::getInstance();
    341    
     341
    342342        if (!$this->_connected) {
    343343            return false;
     
    406406        }
    407407    }
    408    
     408
    409409    /*
    410410    * Return the total number of queries executed thus far.
  • branches/eli_branch/lib/PageNumbers.inc.php

    r439 r445  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    8585        // in special cases like using a /my/page/# scheme.
    8686        $this->url_base = $_SERVER['PHP_SELF'] . '?page_number=';
    87        
     87
    8888        $this->prefs = new Prefs($_SERVER['PHP_SELF']);
    8989        $this->prefs->setParam(array('persistent' => false));
Note: See TracChangeset for help on using the changeset viewer.