示例#1
0
 /**
  * {@inheritdoc}
  */
 public function check_requirements()
 {
     $dbms = $this->config->get('dbms');
     $dbms_info = $this->database_helper->get_available_dbms($dbms);
     $schema_name = $dbms_info[$dbms]['SCHEMA'];
     if ($dbms === 'mysql') {
         if (version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) {
             $schema_name .= '_41';
         } else {
             $schema_name .= '_40';
         }
     }
     $this->schema_file_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql';
     return $this->filesystem->exists($this->schema_file_path);
 }
示例#2
0
 /**
  * Create fulltext index
  *
  * @return string|bool error string is returned incase of errors otherwise false
  */
 public function create_index($acp_module, $u_action)
 {
     // Make sure we can actually use MySQL with fulltext indexes
     if ($error = $this->init()) {
         return $error;
     }
     if (empty($this->stats)) {
         $this->get_stats();
     }
     $alter = array();
     if (!isset($this->stats['post_subject'])) {
         if ($this->db->get_sql_layer() == 'mysqli' || version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) {
             $alter[] = 'MODIFY post_subject varchar(255) COLLATE utf8_unicode_ci DEFAULT \'\' NOT NULL';
         } else {
             $alter[] = 'MODIFY post_subject text NOT NULL';
         }
         $alter[] = 'ADD FULLTEXT (post_subject)';
     }
     if (!isset($this->stats['post_content'])) {
         if ($this->db->get_sql_layer() == 'mysqli' || version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) {
             $alter[] = 'MODIFY post_text mediumtext COLLATE utf8_unicode_ci NOT NULL';
         } else {
             $alter[] = 'MODIFY post_text mediumtext NOT NULL';
         }
         $alter[] = 'ADD FULLTEXT post_content (post_text, post_subject)';
     }
     if (sizeof($alter)) {
         $this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
     }
     $this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
     return false;
 }
示例#3
0
 /**
  * {@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 = '******'admin_name')) . "',\n\t\t\t\t\tuser_password='******'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 = '******'", 'UPDATE ' . $this->moderator_cache_table . "\n\t\t\t\tSET username = '******'admin_name')) . "'\n\t\t\t\tWHERE username = '******'", '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();
     }
 }
示例#4
0
/**
* Removes moderators and administrators from foe lists.
*
* @param \phpbb\db\driver\driver_interface $db Database connection
* @param \phpbb\auth\auth $auth Authentication object
* @param array|bool $group_id If an array, remove all members of this group from foe lists, or false to ignore
* @param array|bool $user_id If an array, remove this user from foe lists, or false to ignore
* @return null
*/
function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false)
{
    // update foes for some user
    if (is_array($user_id) && sizeof($user_id)) {
        $sql = 'DELETE FROM ' . ZEBRA_TABLE . '
			WHERE ' . $db->sql_in_set('zebra_id', $user_id) . '
				AND foe = 1';
        $db->sql_query($sql);
        return;
    }
    // update foes for some group
    if (is_array($group_id) && sizeof($group_id)) {
        // Grab group settings...
        $sql_ary = array('SELECT' => 'a.group_id', 'FROM' => array(ACL_OPTIONS_TABLE => 'ao', ACL_GROUPS_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(ACL_ROLES_DATA_TABLE => 'r'), 'ON' => 'a.auth_role_id = r.role_id')), 'WHERE' => '(ao.auth_option_id = a.auth_option_id OR ao.auth_option_id = r.auth_option_id)
				AND ' . $db->sql_in_set('a.group_id', $group_id) . "\n\t\t\t\tAND ao.auth_option IN ('a_', 'm_')", 'GROUP_BY' => 'a.group_id');
        $sql = $db->sql_build_query('SELECT', $sql_ary);
        $result = $db->sql_query($sql);
        $groups = array();
        while ($row = $db->sql_fetchrow($result)) {
            $groups[] = (int) $row['group_id'];
        }
        $db->sql_freeresult($result);
        if (!sizeof($groups)) {
            return;
        }
        switch ($db->get_sql_layer()) {
            case 'mysqli':
            case 'mysql4':
                $sql = 'DELETE ' . ($db->get_sql_layer() === 'mysqli' || version_compare($db->sql_server_info(true), '4.1', '>=') ? 'z.*' : ZEBRA_TABLE) . '
					FROM ' . ZEBRA_TABLE . ' z, ' . USER_GROUP_TABLE . ' ug
					WHERE z.zebra_id = ug.user_id
						AND z.foe = 1
						AND ' . $db->sql_in_set('ug.group_id', $groups);
                $db->sql_query($sql);
                break;
            default:
                $sql = 'SELECT user_id
					FROM ' . USER_GROUP_TABLE . '
					WHERE ' . $db->sql_in_set('group_id', $groups);
                $result = $db->sql_query($sql);
                $users = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $users[] = (int) $row['user_id'];
                }
                $db->sql_freeresult($result);
                if (sizeof($users)) {
                    $sql = 'DELETE FROM ' . ZEBRA_TABLE . '
						WHERE ' . $db->sql_in_set('zebra_id', $users) . '
							AND foe = 1';
                    $db->sql_query($sql);
                }
                break;
        }
        return;
    }
    // update foes for everyone
    $perms = array();
    foreach ($auth->acl_get_list(false, array('a_', 'm_'), false) as $forum_id => $forum_ary) {
        foreach ($forum_ary as $auth_option => $user_ary) {
            $perms = array_merge($perms, $user_ary);
        }
    }
    if (sizeof($perms)) {
        $sql = 'DELETE FROM ' . ZEBRA_TABLE . '
			WHERE ' . $db->sql_in_set('zebra_id', array_unique($perms)) . '
				AND foe = 1';
        $db->sql_query($sql);
    }
    unset($perms);
}
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $dbms = $this->config->get('dbms');
     $dbms_info = $this->database_helper->get_available_dbms($dbms);
     $schema_name = $dbms_info[$dbms]['SCHEMA'];
     $delimiter = $dbms_info[$dbms]['DELIM'];
     $table_prefix = $this->config->get('table_prefix');
     if ($dbms === 'mysql') {
         if (version_compare($this->db->sql_server_info(true), '4.1.3', '>=')) {
             $schema_name .= '_41';
         } else {
             $schema_name .= '_40';
         }
     }
     $db_schema_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql';
     // Load database vendor specific code if there is any
     if ($this->filesystem->exists($db_schema_path)) {
         $sql_query = @file_get_contents($db_schema_path);
         $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
         $sql_query = $this->database_helper->remove_comments($sql_query);
         $sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
         foreach ($sql_query 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']);
             }
         }
         unset($sql_query);
     }
     $change_prefix = false;
     // Generate database schema
     if ($this->filesystem->exists($this->phpbb_root_path . 'install/schemas/schema.json')) {
         $db_table_schema = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema.json');
         $db_table_schema = json_decode($db_table_schema, true);
         $change_prefix = true;
     } else {
         global $table_prefix;
         $table_prefix = $this->config->get('table_prefix');
         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 $this->phpbb_root_path . 'includes/constants.' . $this->php_ext;
         }
         $finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, null, $this->php_ext);
         $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
         $factory = new \phpbb\db\tools\factory();
         $db_tools = $factory->get($this->db, true);
         $schema_generator = new \phpbb\db\migration\schema_generator($migrator_classes, new \phpbb\config\config(array()), $this->db, $db_tools, $this->phpbb_root_path, $this->php_ext, $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', $table_prefix . 'config');
     }
     foreach ($db_table_schema as $table_name => $table_data) {
         $this->db_tools->sql_create_table($change_prefix ? $table_prefix . substr($table_name, 6) : $table_name, $table_data);
     }
 }
示例#6
0
 /**
  * Check for FULLTEXT index support
  *
  * @return bool True if FULLTEXT is supported, false otherwise
  */
 public function is_supported()
 {
     // FULLTEXT is supported on InnoDB since MySQL 5.6.4 according to
     // http://dev.mysql.com/doc/refman/5.6/en/innodb-storage-engine.html
     return $this->get_engine() === 'myisam' || $this->get_engine() === 'innodb' && phpbb_version_compare($this->db->sql_server_info(true), '5.6.4', '>=');
 }