Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/session.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: session.php 9170 2008-12-04 12:56:12Z toonarmy $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    214214                $this->browser                          = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : '';
    215215                $this->referer                          = (!empty($_SERVER['HTTP_REFERER'])) ? htmlspecialchars((string) $_SERVER['HTTP_REFERER']) : '';
    216                 $this->forwarded_for            = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? (string) $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
     216                $this->forwarded_for            = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? htmlspecialchars((string) $_SERVER['HTTP_X_FORWARDED_FOR']) : '';
    217217
    218218                $this->host                                     = $this->extract_current_hostname();
     
    222222                if ($config['forwarded_for_check'])
    223223                {
    224                         $this->forwarded_for = preg_replace('#, +#', ', ', $this->forwarded_for);
     224                        $this->forwarded_for = preg_replace('#[ ]{2,}#', ' ', str_replace(array(',', ' '), ' ', $this->forwarded_for));
    225225
    226226                        // split the list of IPs
    227                         $ips = explode(', ', $this->forwarded_for);
     227                        $ips = explode(' ', $this->forwarded_for);
    228228                        foreach ($ips as $ip)
    229229                        {
     
    268268                // Why no forwarded_for et al? Well, too easily spoofed. With the results of my recent requests
    269269                // it's pretty clear that in the majority of cases you'll at least be left with a proxy/cache ip.
    270                 $this->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
     270                $this->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars((string) $_SERVER['REMOTE_ADDR']) : '';
     271                $this->ip = preg_replace('#[ ]{2,}#', ' ', str_replace(array(',', ' '), ' ', $this->ip));
     272
     273                // split the list of IPs
     274                $ips = explode(' ', $this->ip);
     275
     276                // Default IP if REMOTE_ADDR is invalid
     277                $this->ip = '127.0.0.1';
     278
     279                foreach ($ips as $ip)
     280                {
     281                        // check IPv4 first, the IPv6 is hopefully only going to be used very seldomly
     282                        if (!empty($ip) && !preg_match(get_preg_expression('ipv4'), $ip) && !preg_match(get_preg_expression('ipv6'), $ip))
     283                        {
     284                                // Just break
     285                                break;
     286                        }
     287
     288                        // Use the last in chain
     289                        $this->ip = $ip;
     290                }
     291
    271292                $this->load = false;
    272293
     
    397418                                                                $db->sql_query($sql);
    398419                                                        }
     420
     421                                                        if ($this->data['user_id'] != ANONYMOUS && !empty($config['new_member_post_limit']) && $this->data['user_new'] && $config['new_member_post_limit'] <= $this->data['user_posts'])
     422                                                        {
     423                                                                $this->leave_newly_registered();
     424                                                        }
    399425                                                }
    400426
     
    481507                                foreach (explode(',', $row['bot_ip']) as $bot_ip)
    482508                                {
     509                                        $bot_ip = trim($bot_ip);
     510
     511                                        if (!$bot_ip)
     512                                        {
     513                                                continue;
     514                                        }
     515
    483516                                        if (strpos($this->ip, $bot_ip) === 0)
    484517                                        {
     
    595628                        else
    596629                        {
    597                                 $ips = explode(', ', $this->forwarded_for);
     630                                $ips = explode(' ', $this->forwarded_for);
    598631                                $ips[] = $this->ip;
    599632                                $this->check_ban($this->data['user_id'], $ips);
     
    720753//              $db->sql_return_on_error(false);
    721754
     755                // Something quite important: session_page always holds the *last* page visited, except for the *first* visit.
     756                // We are not able to simply have an empty session_page btw, therefore we need to tell phpBB how to detect this special case.
     757                // If the session id is empty, we have a completely new one and will set an "identifier" here. This identifier is able to be checked later.
     758                if (empty($this->data['session_id']))
     759                {
     760                        // This is a temporary variable, only set for the very first visit
     761                        $this->data['session_created'] = true;
     762                }
     763
    722764                $this->session_id = $this->data['session_id'] = md5(unique_id());
    723765
     
    876918        function session_gc()
    877919        {
    878                 global $db, $config;
     920                global $db, $config, $phpbb_root_path, $phpEx;
    879921
    880922                $batch_size = 10;
     
    934976                                $db->sql_query($sql);
    935977                        }
    936                         $this->confirm_gc();
     978
     979                        // only called from CRON; should be a safe workaround until the infrastructure gets going
     980                        if (!class_exists('captcha_factory'))
     981                        {
     982                                include($phpbb_root_path . "includes/captcha/captcha_factory." . $phpEx);
     983                        }
     984                        phpbb_captcha_factory::garbage_collect($config['captcha_plugin']);
    937985                }
    938986
    939987                return;
    940988        }
    941 
    942         function confirm_gc($type = 0)
    943         {
    944                 global $db, $config;
    945 
    946                 $sql = 'SELECT DISTINCT c.session_id
    947                                 FROM ' . CONFIRM_TABLE . ' c
    948                                 LEFT JOIN ' . SESSIONS_TABLE . ' s ON (c.session_id = s.session_id)
    949                                 WHERE s.session_id IS NULL' .
    950                                         ((empty($type)) ? '' : ' AND c.confirm_type = ' . (int) $type);
    951                 $result = $db->sql_query($sql);
    952 
    953                 if ($row = $db->sql_fetchrow($result))
    954                 {
    955                         $sql_in = array();
    956                         do
    957                         {
    958                                 $sql_in[] = (string) $row['session_id'];
    959                         }
    960                         while ($row = $db->sql_fetchrow($result));
    961 
    962                         if (sizeof($sql_in))
    963                         {
    964                                 $sql = 'DELETE FROM ' . CONFIRM_TABLE . '
    965                                         WHERE ' . $db->sql_in_set('session_id', $sql_in);
    966                                 $db->sql_query($sql);
    967                         }
    968                 }
    969                 $db->sql_freeresult($result);
    970         }
    971 
    972989
    973990        /**
     
    12051222
    12061223                $dnsbl_check = array(
    1207                         'sbl-xbl.spamhaus.org'  => 'http://www.spamhaus.org/query/bl?ip=',
     1224                        'sbl.spamhaus.org'      => 'http://www.spamhaus.org/query/bl?ip=',
    12081225                );
    12091226
     
    13391356                global $config, $db;
    13401357
    1341                 $user_id = ($user_id === false) ? $this->data['user_id'] : $user_id;
     1358                $user_id = ($user_id === false) ? (int) $this->data['user_id'] : (int) $user_id;
    13421359
    13431360                $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . '
     
    13451362                $db->sql_query($sql);
    13461363
     1364                // If the user is logged in, update last visit info first before deleting sessions
     1365                $sql = 'SELECT session_time, session_page
     1366                        FROM ' . SESSIONS_TABLE . '
     1367                        WHERE session_user_id = ' . (int) $user_id . '
     1368                        ORDER BY session_time DESC';
     1369                $result = $db->sql_query_limit($sql, 1);
     1370                $row = $db->sql_fetchrow($result);
     1371                $db->sql_freeresult($result);
     1372
     1373                if ($row)
     1374                {
     1375                        $sql = 'UPDATE ' . USERS_TABLE . '
     1376                                SET user_lastvisit = ' . (int) $row['session_time'] . ", user_lastpage = '" . $db->sql_escape($row['session_page']) . "'
     1377                                WHERE user_id = " . (int) $user_id;
     1378                        $db->sql_query($sql);
     1379                }
     1380
    13471381                // Let's also clear any current sessions for the specified user_id
    13481382                // If it's the current user then we'll leave this session intact
    13491383                $sql_where = 'session_user_id = ' . (int) $user_id;
    1350                 $sql_where .= ($user_id === $this->data['user_id']) ? " AND session_id <> '" . $db->sql_escape($this->session_id) . "'" : '';
     1384                $sql_where .= ($user_id === (int) $this->data['user_id']) ? " AND session_id <> '" . $db->sql_escape($this->session_id) . "'" : '';
    13511385
    13521386                $sql = 'DELETE FROM ' . SESSIONS_TABLE . "
     
    13561390                // We're changing the password of the current user and they have a key
    13571391                // Lets regenerate it to be safe
    1358                 if ($user_id === $this->data['user_id'] && $this->cookie_data['k'])
     1392                if ($user_id === (int) $this->data['user_id'] && $this->cookie_data['k'])
    13591393                {
    13601394                        $this->set_login_key($user_id);
     
    13691403        function validate_referer($check_script_path = false)
    13701404        {
     1405                global $config;
     1406
    13711407                // no referer - nothing to validate, user's fault for turning it off (we only check on POST; so meta can't be the reason)
    13721408                if (empty($this->referer) || empty($this->host))
     
    13781414                $ref = substr($this->referer, strpos($this->referer, '://') + 3);
    13791415
    1380                 if (!(stripos($ref, $host) === 0))
     1416                if (!(stripos($ref, $host) === 0) && (!$config['force_server_vars'] || !(stripos($ref, $config['server_name']) === 0)))
    13811417                {
    13821418                        return false;
     
    14361472        var $img_array = array();
    14371473
    1438         // Able to add new option (id 7)
    1439         var $keyoptions = array('viewimg' => 0, 'viewflash' => 1, 'viewsmilies' => 2, 'viewsigs' => 3, 'viewavatars' => 4, 'viewcensors' => 5, 'attachsig' => 6, 'bbcode' => 8, 'smilies' => 9, 'popuppm' => 10);
     1474        // Able to add new options (up to id 31)
     1475        var $keyoptions = array('viewimg' => 0, 'viewflash' => 1, 'viewsmilies' => 2, 'viewsigs' => 3, 'viewavatars' => 4, 'viewcensors' => 5, 'attachsig' => 6, 'bbcode' => 8, 'smilies' => 9, 'popuppm' => 10, 'sig_bbcode' => 15, 'sig_smilies' => 16, 'sig_links' => 17);
    14401476        var $keyvalues = array();
    14411477
     
    15281564                $lang = &$this->lang;
    15291565
    1530                 if ((@include $this->lang_path . $this->lang_name . "/common.$phpEx") === false)
     1566                // Do not suppress error if in DEBUG_EXTRA mode
     1567                $include_result = (defined('DEBUG_EXTRA')) ? (include $this->lang_path . $this->lang_name . "/common.$phpEx") : (@include $this->lang_path . $this->lang_name . "/common.$phpEx");
     1568
     1569                if ($include_result === false)
    15311570                {
    15321571                        die('Language file ' . $this->lang_path . $this->lang_name . "/common.$phpEx" . " couldn't be opened.");
     
    15361575                unset($lang_set);
    15371576
    1538                 if (!empty($_GET['style']) && $auth->acl_get('a_styles'))
     1577                if (!empty($_GET['style']) && $auth->acl_get('a_styles') && !defined('ADMIN_START'))
    15391578                {
    15401579                        global $SID, $_EXTRA_URL;
     
    16581697                $this->img_lang = (file_exists($phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . $this->lang_name)) ? $this->lang_name : $config['default_lang'];
    16591698
    1660                 $sql = 'SELECT image_name, image_filename, image_lang, image_height, image_width
     1699                // Same query in style.php
     1700                $sql = 'SELECT *
    16611701                        FROM ' . STYLES_IMAGESET_DATA_TABLE . '
    16621702                        WHERE imageset_id = ' . $this->theme['imageset_id'] . "
     
    17571797                // Disable board if the install/ directory is still present
    17581798                // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally
    1759                 if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install'))
     1799                if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install'))
    17601800                {
    17611801                        // Adjust the message slightly according to the permissions
     
    17741814                if ($config['board_disable'] && !defined('IN_LOGIN') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
    17751815                {
    1776                         header('HTTP/1.1 503 Service Unavailable');
     1816                        if ($this->data['is_bot'])
     1817                        {
     1818                                header('HTTP/1.1 503 Service Unavailable');
     1819                        }
    17771820
    17781821                        $message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
     
    17901833                                if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
    17911834                                {
    1792                                         header('HTTP/1.1 503 Service Unavailable');
     1835                                        if ($this->data['is_bot'])
     1836                                        {
     1837                                                header('HTTP/1.1 503 Service Unavailable');
     1838                                        }
    17931839                                        trigger_error('BOARD_UNAVAILABLE');
    17941840                                }
     
    18281874                // Does the user need to change their password? If so, redirect to the
    18291875                // ucp profile reg_details page ... of course do not redirect if we're already in the ucp
    1830                 if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $config['chg_passforce'] && $this->data['is_registered'] && $auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - ($config['chg_passforce'] * 86400))
     1876                if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $config['chg_passforce'] && !empty($this->data['is_registered']) && $auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - ($config['chg_passforce'] * 86400))
    18311877                {
    18321878                        if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.$phpEx")
     
    20012047                        }
    20022048
    2003                         if ((@include $language_filename) === false)
     2049                        if (!file_exists($language_filename))
     2050                        {
     2051                                global $config;
     2052
     2053                                if ($this->lang_name == 'en')
     2054                                {
     2055                                        // The user's selected language is missing the file, the board default's language is missing the file, and the file doesn't exist in /en.
     2056                                        $language_filename = str_replace($this->lang_path . 'en', $this->lang_path . $this->data['user_lang'], $language_filename);
     2057                                        trigger_error('Language file ' . $language_filename . ' couldn\'t be opened.', E_USER_ERROR);
     2058                                }
     2059                                else if ($this->lang_name == basename($config['default_lang']))
     2060                                {
     2061                                        // Fall back to the English Language
     2062                                        $this->lang_name = 'en';
     2063                                        $this->set_lang($lang, $help, $lang_file, $use_db, $use_help);
     2064                                }
     2065                                else if ($this->lang_name == $this->data['user_lang'])
     2066                                {
     2067                                        // Fall back to the board default language
     2068                                        $this->lang_name = basename($config['default_lang']);
     2069                                        $this->set_lang($lang, $help, $lang_file, $use_db, $use_help);
     2070                                }
     2071
     2072                                // Reset the lang name
     2073                                $this->lang_name = (file_exists($this->lang_path . $this->data['user_lang'] . "/common.$phpEx")) ? $this->data['user_lang'] : basename($config['default_lang']);
     2074                                return;
     2075                        }
     2076
     2077                        // Do not suppress error if in DEBUG_EXTRA mode
     2078                        $include_result = (defined('DEBUG_EXTRA')) ? (include $language_filename) : (@include $language_filename);
     2079
     2080                        if ($include_result === false)
    20042081                        {
    20052082                                trigger_error('Language file ' . $language_filename . ' couldn\'t be opened.', E_USER_ERROR);
     
    20372114                        $date_cache[$format] = array(
    20382115                                'is_short'              => strpos($format, '|'),
    2039                                 'zone_offset'   => $this->timezone + $this->dst,
    20402116                                'format_short'  => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1),
    20412117                                'format_long'   => str_replace('|', '', $format),
     
    20502126                }
    20512127
     2128                // Zone offset
     2129                $zone_offset = $this->timezone + $this->dst;
     2130
    20522131                // Show date <= 1 hour ago as 'xx min ago'
    2053                 // A small tolerence is given for times in the future and times in the future but in the same minute are displayed as '< than a minute ago'
     2132                // A small tolerence is given for times in the future but in the same minute are displayed as '< than a minute ago'
    20542133                if ($delta <= 3600 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO']))
    20552134                {
     
    20592138                if (!$midnight)
    20602139                {
    2061                         list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $date_cache[$format]['zone_offset']));
    2062                         $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $date_cache[$format]['zone_offset'];
    2063                 }
    2064 
    2065                 if ($date_cache[$format]['is_short'] !== false && !$forcedate)
     2140                        list($d, $m, $y) = explode(' ', gmdate('j n Y', time() + $zone_offset));
     2141                        $midnight = gmmktime(0, 0, 0, $m, $d, $y) - $zone_offset;
     2142                }
     2143
     2144                if ($date_cache[$format]['is_short'] !== false && !$forcedate && !($gmepoch < $midnight - 86400 || $gmepoch > $midnight + 172800))
    20662145                {
    20672146                        $day = false;
     
    20822161                        if ($day !== false)
    20832162                        {
    2084                                 return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $date_cache[$format]['zone_offset']), $date_cache[$format]['lang']));
    2085                         }
    2086                 }
    2087 
    2088                 return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $date_cache[$format]['zone_offset']), $date_cache[$format]['lang']);
     2163                                return str_replace('||', $this->lang['datetime'][$day], strtr(@gmdate($date_cache[$format]['format_short'], $gmepoch + $zone_offset), $date_cache[$format]['lang']));
     2164                        }
     2165                }
     2166
     2167                return strtr(@gmdate($date_cache[$format]['format_long'], $gmepoch + $zone_offset), $date_cache[$format]['lang']);
    20892168        }
    20902169
     
    21562235                        }
    21572236
    2158                         $img_data['src'] = $phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . ($this->img_array[$img]['image_lang'] ? $this->img_array[$img]['image_lang'] .'/' : '') . $this->img_array[$img]['image_filename'];
     2237                        // Use URL if told so
     2238                        $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path;
     2239
     2240                        $img_data['src'] = $root_path . 'styles/' . rawurlencode($this->theme['imageset_path']) . '/imageset/' . ($this->img_array[$img]['image_lang'] ? $this->img_array[$img]['image_lang'] .'/' : '') . $this->img_array[$img]['image_filename'];
    21592241                        $img_data['width'] = $this->img_array[$img]['image_width'];
    21602242                        $img_data['height'] = $this->img_array[$img]['image_height'];
     
    22292311                }
    22302312        }
     2313
     2314        /**
     2315        * Funtion to make the user leave the NEWLY_REGISTERED system group.
     2316        * @access public
     2317        */
     2318        function leave_newly_registered()
     2319        {
     2320                global $db;
     2321
     2322                if (empty($this->data['user_new']))
     2323                {
     2324                        return false;
     2325                }
     2326
     2327                if (!function_exists('remove_newly_registered'))
     2328                {
     2329                        global $phpbb_root_path, $phpEx;
     2330
     2331                        include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
     2332                }
     2333                if ($group = remove_newly_registered($this->data['user_id'], $this->data))
     2334                {
     2335                        $this->data['group_id'] = $group;
     2336
     2337                }
     2338                $this->data['user_permissions'] = '';
     2339                $this->data['user_new'] = 0;
     2340
     2341                return true;
     2342        }
    22312343}
    22322344
Note: See TracChangeset for help on using the changeset viewer.