当前位置: 首页>>代码示例>>PHP>>正文


PHP phpbb_ip_normalise函数代码示例

本文整理汇总了PHP中phpbb_ip_normalise函数的典型用法代码示例。如果您正苦于以下问题:PHP phpbb_ip_normalise函数的具体用法?PHP phpbb_ip_normalise怎么用?PHP phpbb_ip_normalise使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了phpbb_ip_normalise函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: session_begin

    /**
     * Start session management
     *
     * This is where all session activity begins. We gather various pieces of
     * information from the client and server. We test to see if a session already
     * exists. If it does, fine and dandy. If it doesn't we'll go on to create a
     * new one ... pretty logical heh? We also examine the system load (if we're
     * running on a system which makes such information readily available) and
     * halt if it's above an admin definable limit.
     *
     * @param bool $update_session_page if true the session page gets updated.
     *			This can be set to circumvent certain scripts to update the users last visited page.
     */
    function session_begin($update_session_page = true)
    {
        global $phpEx, $SID, $_SID, $_EXTRA_URL, $db, $config, $phpbb_root_path;
        global $request, $phpbb_container, $user, $phpbb_log;
        // Give us some basic information
        $this->time_now = time();
        $this->cookie_data = array('u' => 0, 'k' => '');
        $this->update_session_page = $update_session_page;
        $this->browser = $request->header('User-Agent');
        $this->referer = $request->header('Referer');
        $this->forwarded_for = $request->header('X-Forwarded-For');
        $this->host = $this->extract_current_hostname();
        $this->page = $this->extract_current_page($phpbb_root_path);
        // if the forwarded for header shall be checked we have to validate its contents
        if ($config['forwarded_for_check']) {
            $this->forwarded_for = preg_replace('# {2,}#', ' ', str_replace(',', ' ', $this->forwarded_for));
            // split the list of IPs
            $ips = explode(' ', $this->forwarded_for);
            foreach ($ips as $ip) {
                // check IPv4 first, the IPv6 is hopefully only going to be used very seldomly
                if (!empty($ip) && !preg_match(get_preg_expression('ipv4'), $ip) && !preg_match(get_preg_expression('ipv6'), $ip)) {
                    // contains invalid data, don't use the forwarded for header
                    $this->forwarded_for = '';
                    break;
                }
            }
        } else {
            $this->forwarded_for = '';
        }
        if ($request->is_set($config['cookie_name'] . '_sid', \phpbb\request\request_interface::COOKIE) || $request->is_set($config['cookie_name'] . '_u', \phpbb\request\request_interface::COOKIE)) {
            $this->cookie_data['u'] = $request->variable($config['cookie_name'] . '_u', 0, false, \phpbb\request\request_interface::COOKIE);
            $this->cookie_data['k'] = $request->variable($config['cookie_name'] . '_k', '', false, \phpbb\request\request_interface::COOKIE);
            $this->session_id = $request->variable($config['cookie_name'] . '_sid', '', false, \phpbb\request\request_interface::COOKIE);
            $SID = defined('NEED_SID') ? '?sid=' . $this->session_id : '?sid=';
            $_SID = defined('NEED_SID') ? $this->session_id : '';
            if (empty($this->session_id)) {
                $this->session_id = $_SID = $request->variable('sid', '');
                $SID = '?sid=' . $this->session_id;
                $this->cookie_data = array('u' => 0, 'k' => '');
            }
        } else {
            $this->session_id = $_SID = $request->variable('sid', '');
            $SID = '?sid=' . $this->session_id;
        }
        $_EXTRA_URL = array();
        // Why no forwarded_for et al? Well, too easily spoofed. With the results of my recent requests
        // it's pretty clear that in the majority of cases you'll at least be left with a proxy/cache ip.
        $this->ip = htmlspecialchars_decode($request->server('REMOTE_ADDR'));
        $this->ip = preg_replace('# {2,}#', ' ', str_replace(',', ' ', $this->ip));
        // split the list of IPs
        $ips = explode(' ', trim($this->ip));
        // Default IP if REMOTE_ADDR is invalid
        $this->ip = '127.0.0.1';
        foreach ($ips as $ip) {
            if (function_exists('phpbb_ip_normalise')) {
                // Normalise IP address
                $ip = phpbb_ip_normalise($ip);
                if (empty($ip)) {
                    // IP address is invalid.
                    break;
                }
                // IP address is valid.
                $this->ip = $ip;
                // Skip legacy code.
                continue;
            }
            if (preg_match(get_preg_expression('ipv4'), $ip)) {
                $this->ip = $ip;
            } else {
                if (preg_match(get_preg_expression('ipv6'), $ip)) {
                    // Quick check for IPv4-mapped address in IPv6
                    if (stripos($ip, '::ffff:') === 0) {
                        $ipv4 = substr($ip, 7);
                        if (preg_match(get_preg_expression('ipv4'), $ipv4)) {
                            $ip = $ipv4;
                        }
                    }
                    $this->ip = $ip;
                } else {
                    // We want to use the last valid address in the chain
                    // Leave foreach loop when address is invalid
                    break;
                }
            }
        }
        $this->load = false;
        // Load limit check (if applicable)
//.........这里部分代码省略.........
开发者ID:Alexey3112,项目名称:phpbb,代码行数:101,代码来源:session.php

示例2: main

    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx;
        global $phpbb_dispatcher, $request;
        global $phpbb_container, $phpbb_log;
        $user->add_lang(array('posting', 'ucp', 'acp/users'));
        $this->tpl_name = 'acp_users';
        $error = array();
        $username = $request->variable('username', '', true);
        $user_id = $request->variable('u', 0);
        $action = $request->variable('action', '');
        // Get referer to redirect user to the appropriate page after delete action
        $redirect = $request->variable('redirect', '');
        $redirect_tag = "redirect={$redirect}";
        $redirect_url = append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$redirect}");
        $submit = isset($_POST['update']) && !isset($_POST['cancel']) ? true : false;
        $form_name = 'acp_users';
        add_form_key($form_name);
        // Whois (special case)
        if ($action == 'whois') {
            if (!function_exists('user_get_id_name')) {
                include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
            }
            $this->page_title = 'WHOIS';
            $this->tpl_name = 'simple_body';
            $user_ip = phpbb_ip_normalise($request->variable('user_ip', ''));
            $domain = gethostbyaddr($user_ip);
            $ipwhois = user_ipwhois($user_ip);
            $template->assign_vars(array('MESSAGE_TITLE' => sprintf($user->lang['IP_WHOIS_FOR'], $domain), 'MESSAGE_TEXT' => nl2br($ipwhois)));
            return;
        }
        // Show user selection mask
        if (!$username && !$user_id) {
            $this->page_title = 'SELECT_USER';
            $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=select_user&field=username&select_single=true')));
            return;
        }
        if (!$user_id) {
            $sql = 'SELECT user_id
				FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
            $result = $db->sql_query($sql);
            $user_id = (int) $db->sql_fetchfield('user_id');
            $db->sql_freeresult($result);
            if (!$user_id) {
                trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
            }
        }
        // Generate content for all modes
        $sql = 'SELECT u.*, s.*
			FROM ' . USERS_TABLE . ' u
				LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
			WHERE u.user_id = ' . $user_id . '
			ORDER BY s.session_time DESC';
        $result = $db->sql_query_limit($sql, 1);
        $user_row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$user_row) {
            trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
        }
        // Generate overall "header" for user admin
        $s_form_options = '';
        // Build modes dropdown list
        $sql = 'SELECT module_mode, module_auth
			FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_basename = 'acp_users'\n\t\t\t\tAND module_enabled = 1\n\t\t\t\tAND module_class = 'acp'\n\t\t\tORDER BY left_id, module_mode";
        $result = $db->sql_query($sql);
        $dropdown_modes = array();
        while ($row = $db->sql_fetchrow($result)) {
            if (!$this->p_master->module_auth_self($row['module_auth'])) {
                continue;
            }
            $dropdown_modes[$row['module_mode']] = true;
        }
        $db->sql_freeresult($result);
        foreach ($dropdown_modes as $module_mode => $null) {
            $selected = $mode == $module_mode ? ' selected="selected"' : '';
            $s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>';
        }
        $template->assign_vars(array('U_BACK' => empty($redirect) ? $this->u_action : $redirect_url, 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&amp;u={$user_id}"), 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id . (empty($redirect) ? '' : '&amp;' . $redirect_tag), 'S_FORM_OPTIONS' => $s_form_options, 'MANAGED_USERNAME' => $user_row['username']));
        // Prevent normal users/admins change/view founders if they are not a founder by themselves
        if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER) {
            trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action), E_USER_WARNING);
        }
        $this->page_title = $user_row['username'] . ' :: ' . $user->lang('ACP_USER_' . strtoupper($mode));
        switch ($mode) {
            case 'overview':
                if (!function_exists('user_get_id_name')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                $user->add_lang('acp/ban');
                $delete = $request->variable('delete', 0);
                $delete_type = $request->variable('delete_type', '');
                $ip = $request->variable('ip', 'ip');
                /**
                 * Run code at beginning of ACP users overview
                 *
                 * @event core.acp_users_overview_before
                 * @var	array   user_row    Current user data
                 * @var	string  mode        Active module
                 * @var	string  action      Module that should be run
//.........这里部分代码省略.........
开发者ID:bantu,项目名称:phpbb,代码行数:101,代码来源:acp_users.php

示例3: test_ip_normalise

 /**
  * @dataProvider data_provider
  */
 public function test_ip_normalise($ip_address, $expected)
 {
     $this->assertEquals($expected, phpbb_ip_normalise($ip_address));
 }
开发者ID:phpbb,项目名称:phpbb,代码行数:7,代码来源:ip_normalise_test.php

示例4: run

 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $server_name = $this->install_config->get('server_name');
     $current_time = time();
     $user_ip = phpbb_ip_normalise($this->iohandler->get_server_variable('REMOTE_ADDR'));
     $user_ip = $user_ip === false ? '' : $user_ip;
     $referer = $this->iohandler->get_server_variable('REFERER');
     // Calculate cookie domain
     $cookie_domain = $server_name;
     if (strpos($cookie_domain, 'www.') === 0) {
         $cookie_domain = substr($cookie_domain, 3);
     }
     // Set default config and post data, this applies to all DB's
     $sql_ary = array('INSERT INTO ' . $this->config_table . " (config_name, config_value)\n\t\t\t\tVALUES ('board_startdate', '{$current_time}')", 'INSERT INTO ' . $this->config_table . " (config_name, config_value)\n\t\t\t\tVALUES ('default_lang', '" . $this->db->sql_escape($this->install_config->get('default_lang')) . "')", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('img_imagick')) . "'\n\t\t\t\tWHERE config_name = 'img_imagick'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_name')) . "'\n\t\t\t\tWHERE config_name = 'server_name'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_port')) . "'\n\t\t\t\tWHERE config_name = 'server_port'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'\n\t\t\t\tWHERE config_name = 'board_email'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'\n\t\t\t\tWHERE config_name = 'board_contact'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($cookie_domain) . "'\n\t\t\t\tWHERE config_name = 'cookie_domain'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "'\n\t\t\t\tWHERE config_name = 'default_dateformat'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('email_enable')) . "'\n\t\t\t\tWHERE config_name = 'email_enable'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_delivery')) . "'\n\t\t\t\tWHERE config_name = 'smtp_delivery'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_host')) . "'\n\t\t\t\tWHERE config_name = 'smtp_host'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_port')) . "'\n\t\t\t\tWHERE config_name = 'smtp_port'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_auth')) . "'\n\t\t\t\tWHERE config_name = 'smtp_auth_method'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_user')) . "'\n\t\t\t\tWHERE config_name = 'smtp_username'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_pass')) . "'\n\t\t\t\tWHERE config_name = 'smtp_password'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('cookie_secure')) . "'\n\t\t\t\tWHERE config_name = 'cookie_secure'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('force_server_vars')) . "'\n\t\t\t\tWHERE config_name = 'force_server_vars'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('script_path')) . "'\n\t\t\t\tWHERE config_name = 'script_path'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_protocol')) . "'\n\t\t\t\tWHERE config_name = 'server_protocol'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE config_name = 'newest_username'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'avatar_salt'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'plupload_salt'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_name')) . "'\n\t\t\t\tWHERE config_name = 'sitename'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_description')) . "'\n\t\t\t\tWHERE config_name = 'site_desc'", 'UPDATE ' . $this->user_table . "\n\t\t\t\tSET username = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',\n\t\t\t\t\tuser_password='" . $this->password_manager->hash($this->install_config->get('admin_passwd')) . "',\n\t\t\t\t\tuser_ip = '" . $this->db->sql_escape($user_ip) . "',\n\t\t\t\t\tuser_lang = '" . $this->db->sql_escape($this->install_config->get('user_language', 'en')) . "',\n\t\t\t\t\tuser_email='" . $this->db->sql_escape($this->install_config->get('board_email')) . "',\n\t\t\t\t\tuser_dateformat='" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "',\n\t\t\t\t\tuser_email_hash = " . $this->db->sql_escape(phpbb_email_hash($this->install_config->get('board_email'))) . ",\n\t\t\t\t\tusername_clean = '" . $this->db->sql_escape(utf8_clean_string($this->install_config->get('admin_name'))) . "'\n\t\t\t\tWHERE username = 'Admin'", 'UPDATE ' . $this->moderator_cache_table . "\n\t\t\t\tSET username = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE username = 'Admin'", 'UPDATE ' . $this->forums_table . "\n\t\t\t\tSET forum_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE forum_last_poster_name = 'Admin'", 'UPDATE ' . $this->topics_table . "\n\t\t\t\tSET topic_first_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',\n\t\t\t\ttopic_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE topic_first_poster_name = 'Admin'\n\t\t\t\t\tOR topic_last_poster_name = 'Admin'", 'UPDATE ' . $this->user_table . "\n\t\t\t\tSET user_regdate = {$current_time}", 'UPDATE ' . $this->posts_table . "\n\t\t\t\tSET post_time = {$current_time}, poster_ip = '" . $this->db->sql_escape($user_ip) . "'", 'UPDATE ' . $this->topics_table . "\n\t\t\t\tSET topic_time = {$current_time}, topic_last_post_time = {$current_time}", 'UPDATE ' . $this->forums_table . "\n\t\t\t\tSET forum_last_post_time = {$current_time}", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->db->sql_server_info(true)) . "'\n\t\t\t\tWHERE config_name = 'dbms_version'");
     if (@extension_loaded('gd')) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = 'core.captcha.plugins.gd'\n\t\t\t\tWHERE config_name = 'captcha_plugin'";
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '1'\n\t\t\t\tWHERE config_name = 'captcha_gd'";
     }
     $ref = substr($referer, strpos($referer, '://') + 3);
     if (!(stripos($ref, $server_name) === 0)) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'referer_validation'";
     }
     // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
     $cookie_name = 'phpbb3_';
     $rand_str = md5(mt_rand());
     $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
     $rand_str = substr($rand_str, 0, 5);
     $cookie_name .= strtolower($rand_str);
     $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\tSET config_value = '" . $this->db->sql_escape($cookie_name) . "'\n\t\t\tWHERE config_name = 'cookie_name'";
     // Disable avatars if upload directory is not writable
     if (!$this->filesystem->is_writable($this->phpbb_root_path . 'images/avatars/upload/')) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'allow_avatar'";
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'allow_avatar_upload'";
     }
     $i = $this->install_config->get('add_config_settings_index', 0);
     $total = sizeof($sql_ary);
     $sql_ary = array_slice($sql_ary, $i);
     foreach ($sql_ary as $sql) {
         if (!$this->db->sql_query($sql)) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
         }
         $i++;
         // Stop execution if resource limit is reached
         if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) {
             break;
         }
     }
     if ($i < $total) {
         $this->install_config->set('add_config_settings_index', $i);
         throw new resource_limit_reached_exception();
     }
 }
开发者ID:phpbb,项目名称:phpbb-core,代码行数:57,代码来源:add_config_settings.php

示例5: ip

 private function ip()
 {
     // Why no forwarded_for et al? Well, too easily spoofed. With the results of my recent requests
     // it's pretty clear that in the majority of cases you'll at least be left with a proxy/cache ip.
     $this->ip = htmlspecialchars_decode($this->request->server('REMOTE_ADDR'));
     $this->ip = preg_replace('# {2,}#', ' ', str_replace(',', ' ', $this->ip));
     // split the list of IPs
     $ips = explode(' ', trim($this->ip));
     // Default IP if REMOTE_ADDR is invalid
     $this->ip = '127.0.0.1';
     foreach ($ips as $ip) {
         if (function_exists('phpbb_ip_normalise')) {
             // Normalise IP address
             $ip = phpbb_ip_normalise($ip);
             if (empty($ip)) {
                 // IP address is invalid.
                 break;
             }
             // IP address is valid.
             $this->ip = $ip;
             // Skip legacy code.
             continue;
         }
         if (preg_match(get_preg_expression('ipv4'), $ip)) {
             $this->ip = $ip;
         } else {
             if (preg_match(get_preg_expression('ipv6'), $ip)) {
                 // Quick check for IPv4-mapped address in IPv6
                 if (stripos($ip, '::ffff:') === 0) {
                     $ipv4 = substr($ip, 7);
                     if (preg_match(get_preg_expression('ipv4'), $ipv4)) {
                         $ip = $ipv4;
                     }
                 }
                 $this->ip = $ip;
             } else {
                 // We want to use the last valid address in the chain
                 // Leave foreach loop when address is invalid
                 break;
             }
         }
     }
     return $this->ip;
 }
开发者ID:bb3mobi,项目名称:bb3top,代码行数:44,代码来源:counter.php

示例6: load_schema


//.........这里部分代码省略.........
         $db_table_schema = @file_get_contents('schemas/schema.json');
         $db_table_schema = json_decode($db_table_schema, true);
     } else {
         global $phpbb_root_path, $phpEx, $table_prefix;
         $table_prefix = 'phpbb_';
         if (!defined('CONFIG_TABLE')) {
             // We need to include the constants file for the table constants
             // when we generate the schema from the migration files.
             include $phpbb_root_path . 'includes/constants.' . $phpEx;
         }
         $finder = new \phpbb\finder(new \phpbb\filesystem\filesystem(), $phpbb_root_path, null, $phpEx);
         $classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
         $sqlite_db = new \phpbb\db\driver\sqlite();
         $factory = new \phpbb\db\tools\factory();
         $db_tools = $factory->get($sqlite_db, true);
         $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $sqlite_db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix);
         $db_table_schema = $schema_generator->get_schema();
     }
     if (!defined('CONFIG_TABLE')) {
         // CONFIG_TABLE is required by sql_create_index() to check the
         // length of index names. However table_prefix is not defined
         // here yet, so we need to create the constant ourselves.
         define('CONFIG_TABLE', $data['table_prefix'] . 'config');
     }
     $factory = new \phpbb\db\tools\factory();
     $db_tools = $factory->get($db);
     foreach ($db_table_schema as $table_name => $table_data) {
         $db_tools->sql_create_table($data['table_prefix'] . substr($table_name, 6), $table_data);
     }
     // Ok tables have been built, let's fill in the basic information
     $sql_query = file_get_contents('schemas/schema_data.sql');
     // Deal with any special comments and characters
     switch ($data['dbms']) {
         case 'mssql':
         case 'mssql_odbc':
         case 'mssqlnative':
             $sql_query = preg_replace('#\\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \\##s', 'SET IDENTITY_INSERT \\1 \\2;', $sql_query);
             break;
         case 'postgres':
             $sql_query = preg_replace('#\\# POSTGRES (BEGIN|COMMIT) \\##s', '\\1; ', $sql_query);
             break;
         case 'mysql':
         case 'mysqli':
             $sql_query = str_replace('\\', '\\\\', $sql_query);
             break;
     }
     // Change prefix
     $sql_query = preg_replace('# phpbb_([^\\s]*) #i', ' ' . $data['table_prefix'] . '\\1 ', $sql_query);
     // Change language strings...
     $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', 'adjust_language_keys_callback', $sql_query);
     $sql_query = phpbb_remove_comments($sql_query);
     $sql_query = split_sql_file($sql_query, ';');
     foreach ($sql_query as $sql) {
         //$sql = trim(str_replace('|', ';', $sql));
         if (!$db->sql_query($sql)) {
             $error = $db->sql_error();
             $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
         }
     }
     unset($sql_query);
     $current_time = time();
     $user_ip = $request->server('REMOTE_ADDR') ? phpbb_ip_normalise($request->server('REMOTE_ADDR')) : '';
     if ($data['script_path'] !== '/') {
         // Adjust destination path (no trailing slash)
         if (substr($data['script_path'], -1) == '/') {
             $data['script_path'] = substr($data['script_path'], 0, -1);
         }
         $data['script_path'] = str_replace(array('../', './'), '', $data['script_path']);
         if ($data['script_path'][0] != '/') {
             $data['script_path'] = '/' . $data['script_path'];
         }
     }
     // Set default config and post data, this applies to all DB's
     $sql_ary = array('INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)\n\t\t\t\tVALUES ('board_startdate', '{$current_time}')", 'INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)\n\t\t\t\tVALUES ('default_lang', '" . $db->sql_escape($data['default_lang']) . "')", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['img_imagick']) . "'\n\t\t\t\tWHERE config_name = 'img_imagick'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['server_name']) . "'\n\t\t\t\tWHERE config_name = 'server_name'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['server_port']) . "'\n\t\t\t\tWHERE config_name = 'server_port'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['board_email']) . "'\n\t\t\t\tWHERE config_name = 'board_email'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['board_email']) . "'\n\t\t\t\tWHERE config_name = 'board_contact'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($cookie_domain) . "'\n\t\t\t\tWHERE config_name = 'cookie_domain'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($lang['default_dateformat']) . "'\n\t\t\t\tWHERE config_name = 'default_dateformat'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['email_enable']) . "'\n\t\t\t\tWHERE config_name = 'email_enable'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_delivery']) . "'\n\t\t\t\tWHERE config_name = 'smtp_delivery'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_host']) . "'\n\t\t\t\tWHERE config_name = 'smtp_host'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_auth']) . "'\n\t\t\t\tWHERE config_name = 'smtp_auth_method'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_user']) . "'\n\t\t\t\tWHERE config_name = 'smtp_username'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_pass']) . "'\n\t\t\t\tWHERE config_name = 'smtp_password'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['cookie_secure']) . "'\n\t\t\t\tWHERE config_name = 'cookie_secure'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['force_server_vars']) . "'\n\t\t\t\tWHERE config_name = 'force_server_vars'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['script_path']) . "'\n\t\t\t\tWHERE config_name = 'script_path'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['server_protocol']) . "'\n\t\t\t\tWHERE config_name = 'server_protocol'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['admin_name']) . "'\n\t\t\t\tWHERE config_name = 'newest_username'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'avatar_salt'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'plupload_salt'", 'UPDATE ' . $data['table_prefix'] . "users\n\t\t\t\tSET username = '" . $db->sql_escape($data['admin_name']) . "', user_password='" . $db->sql_escape(md5($data['admin_pass1'])) . "', user_ip = '" . $db->sql_escape($user_ip) . "', user_lang = '" . $db->sql_escape($data['default_lang']) . "', user_email='" . $db->sql_escape($data['board_email']) . "', user_dateformat='" . $db->sql_escape($lang['default_dateformat']) . "', user_email_hash = " . $db->sql_escape(phpbb_email_hash($data['board_email'])) . ", username_clean = '" . $db->sql_escape(utf8_clean_string($data['admin_name'])) . "'\n\t\t\t\tWHERE username = 'Admin'", 'UPDATE ' . $data['table_prefix'] . "moderator_cache\n\t\t\t\tSET username = '" . $db->sql_escape($data['admin_name']) . "'\n\t\t\t\tWHERE username = 'Admin'", 'UPDATE ' . $data['table_prefix'] . "forums\n\t\t\t\tSET forum_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'\n\t\t\t\tWHERE forum_last_poster_name = 'Admin'", 'UPDATE ' . $data['table_prefix'] . "topics\n\t\t\t\tSET topic_first_poster_name = '" . $db->sql_escape($data['admin_name']) . "', topic_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'\n\t\t\t\tWHERE topic_first_poster_name = 'Admin'\n\t\t\t\t\tOR topic_last_poster_name = 'Admin'", 'UPDATE ' . $data['table_prefix'] . "users\n\t\t\t\tSET user_regdate = {$current_time}", 'UPDATE ' . $data['table_prefix'] . "posts\n\t\t\t\tSET post_time = {$current_time}, poster_ip = '" . $db->sql_escape($user_ip) . "'", 'UPDATE ' . $data['table_prefix'] . "topics\n\t\t\t\tSET topic_time = {$current_time}, topic_last_post_time = {$current_time}", 'UPDATE ' . $data['table_prefix'] . "forums\n\t\t\t\tSET forum_last_post_time = {$current_time}", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($db->sql_server_info(true)) . "'\n\t\t\t\tWHERE config_name = 'dbms_version'");
     if (@extension_loaded('gd')) {
         $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = 'core.captcha.plugins.gd'\n\t\t\t\tWHERE config_name = 'captcha_plugin'";
         $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '1'\n\t\t\t\tWHERE config_name = 'captcha_gd'";
     }
     $ref = substr($referer, strpos($referer, '://') + 3);
     if (!(stripos($ref, $server_name) === 0)) {
         $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'referer_validation'";
     }
     // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
     $cookie_name = 'phpbb3_';
     $rand_str = md5(mt_rand());
     $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
     $rand_str = substr($rand_str, 0, 5);
     $cookie_name .= strtolower($rand_str);
     $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\tSET config_value = '" . $db->sql_escape($cookie_name) . "'\n\t\t\tWHERE config_name = 'cookie_name'";
     foreach ($sql_ary as $sql) {
         //$sql = trim(str_replace('|', ';', $sql));
         if (!$db->sql_query($sql)) {
             $error = $db->sql_error();
             $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__);
         }
     }
     $submit = $lang['NEXT_STEP'];
     $url = $this->p_master->module_url . "?mode={$mode}&amp;sub=final";
     $template->assign_vars(array('BODY' => $lang['STAGE_CREATE_TABLE_EXPLAIN'], 'L_SUBMIT' => $submit, 'S_HIDDEN' => build_hidden_fields($data), 'U_ACTION' => $url));
 }
开发者ID:hgchen,项目名称:phpbb,代码行数:101,代码来源:install_install.php


注:本文中的phpbb_ip_normalise函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。