From 99dbea146937da3e39ae135db359b322513f0e2b Mon Sep 17 00:00:00 2001 From: Alfredo Ramos Date: Mon, 6 Apr 2020 16:02:20 -0500 Subject: [PATCH] [ticket/16338] Add DuckDuckGo bot PHPBB3-16338 --- phpBB/includes/functions_convert.php | 1 + .../db/migration/data/v33x/bot_update.php | 91 +++++++++++++++++++ .../module/install_data/task/add_bots.php | 1 + 3 files changed, 93 insertions(+) create mode 100644 phpBB/phpbb/db/migration/data/v33x/bot_update.php diff --git a/phpBB/includes/functions_convert.php b/phpBB/includes/functions_convert.php index 96e108792d..ab1efc16c9 100644 --- a/phpBB/includes/functions_convert.php +++ b/phpBB/includes/functions_convert.php @@ -1840,6 +1840,7 @@ function add_bots() 'Ask Jeeves [Bot]' => array('Ask Jeeves', ''), 'Baidu [Spider]' => array('Baiduspider+(', ''), 'Bing [Bot]' => array('bingbot/', ''), + 'DuckDuckGo [Bot]' => array('DuckDuckBot/', ''), 'Exabot [Bot]' => array('Exabot/', ''), 'FAST Enterprise [Crawler]' => array('FAST Enterprise Crawler', ''), 'FAST WebCrawler [Crawler]' => array('FAST-WebCrawler/', ''), diff --git a/phpBB/phpbb/db/migration/data/v33x/bot_update.php b/phpBB/phpbb/db/migration/data/v33x/bot_update.php new file mode 100644 index 0000000000..cab5a5dde8 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v33x/bot_update.php @@ -0,0 +1,91 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\db\migration\data\v33x; + +class bot_update extends \phpbb\db\migration\migration +{ + static public function depends_on() + { + return ['\phpbb\db\migration\data\v330\v330']; + } + + public function update_data() + { + return [ + ['custom', [[$this, 'add_duckduckgo_bot']]], + ]; + } + + public function add_duckduckgo_bot() + { + $bot_name = 'DuckDuckGo [Bot]'; + $bot_name_clean = utf8_clean_string($bot_name); + + $sql = 'SELECT user_id + FROM ' . $this->table_prefix . 'users + WHERE ' . $this->db->sql_build_array('SELECT', ['username_clean' => $bot_name_clean]); + $result = $this->db->sql_query($sql); + $bot_exists = (bool) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if (!$bot_exists) + { + $bot_agent = 'DuckDuckBot/'; + $bot_ip = ''; + $sql = 'SELECT group_id, group_colour + FROM ' . $this->table_prefix . 'groups + WHERE ' . $this->db->sql_build_array('SELECT', ['group_name' => 'BOTS']); + $result = $this->db->sql_query($sql); + $group_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + // Default fallback, should never get here + if (!$group_row) + { + $group_row['group_id'] = 6; + $group_row['group_colour'] = '9E8DA7'; + } + + if (!function_exists('user_add')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $user_row = [ + 'user_type' => USER_IGNORE, + 'group_id' => $group_row['group_id'], + 'username' => $bot_name, + 'user_regdate' => time(), + 'user_password' => '', + 'user_colour' => $group_row['group_colour'], + 'user_email' => '', + 'user_lang' => $this->config['default_lang'], + 'user_style' => $this->config['default_style'], + 'user_timezone' => 0, + 'user_dateformat' => $this->config['default_dateformat'], + 'user_allow_massemail' => 0, + ]; + + $user_id = user_add($user_row); + $sql = 'INSERT INTO ' . $this->table_prefix . 'bots ' . $this->db->sql_build_array('INSERT', [ + 'bot_active' => 1, + 'bot_name' => (string) $bot_name, + 'user_id' => (int) $user_id, + 'bot_agent' => (string) $bot_agent, + 'bot_ip' => (string) $bot_ip, + ]); + $this->db->sql_query($sql); + } + } +} diff --git a/phpBB/phpbb/install/module/install_data/task/add_bots.php b/phpBB/phpbb/install/module/install_data/task/add_bots.php index 07f8e025cf..e53087a671 100644 --- a/phpBB/phpbb/install/module/install_data/task/add_bots.php +++ b/phpBB/phpbb/install/module/install_data/task/add_bots.php @@ -63,6 +63,7 @@ class add_bots extends \phpbb\install\task_base 'Ask Jeeves [Bot]' => array('Ask Jeeves', ''), 'Baidu [Spider]' => array('Baiduspider', ''), 'Bing [Bot]' => array('bingbot/', ''), + 'DuckDuckGo [Bot]' => array('DuckDuckBot/', ''), 'Exabot [Bot]' => array('Exabot', ''), 'FAST Enterprise [Crawler]' => array('FAST Enterprise Crawler', ''), 'FAST WebCrawler [Crawler]' => array('FAST-WebCrawler/', ''),