Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 57 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
add_bots | |
0.00% |
0 / 57 |
|
0.00% |
0 / 5 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
execute_step | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
12 | |||
get_step_count | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_task_lang_name | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\install\module\install_data\task; |
15 | |
16 | use Doctrine\DBAL\Driver\Statement as DriverStatement; |
17 | use Doctrine\DBAL\Exception; |
18 | use Doctrine\DBAL\Statement; |
19 | use phpbb\install\database_task; |
20 | use phpbb\install\helper\config; |
21 | use phpbb\install\helper\container_factory; |
22 | use phpbb\install\helper\database; |
23 | use phpbb\install\helper\iohandler\iohandler_interface; |
24 | use phpbb\install\sequential_task; |
25 | use phpbb\language\language; |
26 | |
27 | class add_bots extends database_task |
28 | { |
29 | use sequential_task; |
30 | |
31 | /** |
32 | * A list of the web-crawlers/bots we recognise by default |
33 | * |
34 | * Candidates but not included: |
35 | * 'Accoona [Bot]' 'Accoona-AI-Agent/' |
36 | * 'ASPseek [Crawler]' 'ASPseek/' |
37 | * 'Boitho [Crawler]' 'boitho.com-dc/' |
38 | * 'Bunnybot [Bot]' 'powered by www.buncat.de' |
39 | * 'Cosmix [Bot]' 'cfetch/' |
40 | * 'Crawler Search [Crawler]' '.Crawler-Search.de' |
41 | * 'Findexa [Crawler]' 'Findexa Crawler (' |
42 | * 'GBSpider [Spider]' 'GBSpider v' |
43 | * 'genie [Bot]' 'genieBot (' |
44 | * 'Hogsearch [Bot]' 'oegp v. 1.3.0' |
45 | * 'Insuranco [Bot]' 'InsurancoBot' |
46 | * 'IRLbot [Bot]' 'http://irl.cs.tamu.edu/crawler' |
47 | * 'ISC Systems [Bot]' 'ISC Systems iRc Search' |
48 | * 'Jyxobot [Bot]' 'Jyxobot/' |
49 | * 'Kraehe [Metasuche]' '-DIE-KRAEHE- META-SEARCH-ENGINE/' |
50 | * 'LinkWalker' 'LinkWalker' |
51 | * 'MMSBot [Bot]' 'http://www.mmsweb.at/bot.html' |
52 | * 'Naver [Bot]' 'nhnbot@naver.com)' |
53 | * 'NetResearchServer' 'NetResearchServer/' |
54 | * 'Nimble [Crawler]' 'NimbleCrawler' |
55 | * 'Ocelli [Bot]' 'Ocelli/' |
56 | * 'Onsearch [Bot]' 'onCHECK-Robot' |
57 | * 'Orange [Spider]' 'OrangeSpider' |
58 | * 'Sproose [Bot]' 'http://www.sproose.com/bot' |
59 | * 'Susie [Sync]' '!Susie (http://www.sync2it.com/susie)' |
60 | * 'Tbot [Bot]' 'Tbot/' |
61 | * 'Thumbshots [Capture]' 'thumbshots-de-Bot' |
62 | * 'Vagabondo [Crawler]' 'http://webagent.wise-guys.nl/' |
63 | * 'Walhello [Bot]' 'appie 1.1 (www.walhello.com)' |
64 | * 'WissenOnline [Bot]' 'WissenOnline-Bot' |
65 | * 'WWWeasel [Bot]' 'WWWeasel Robot v' |
66 | * 'Xaldon [Spider]' 'Xaldon WebSpider' |
67 | * |
68 | * @var array |
69 | */ |
70 | protected $bot_list = array( |
71 | 'AdsBot [Google]' => array('AdsBot-Google', ''), |
72 | 'Ahrefs [Bot]' => array('AhrefsBot/', ''), |
73 | 'Alexa [Bot]' => array('ia_archiver', ''), |
74 | 'Alta Vista [Bot]' => array('Scooter/', ''), |
75 | 'Amazon [Bot]' => array('Amazonbot/', ''), |
76 | 'Ask Jeeves [Bot]' => array('Ask Jeeves', ''), |
77 | 'Baidu [Spider]' => array('Baiduspider', ''), |
78 | 'Bing [Bot]' => array('bingbot/', ''), |
79 | 'DuckDuckGo [Bot]' => array('DuckDuckBot/', ''), |
80 | 'Exabot [Bot]' => array('Exabot/', ''), |
81 | 'FAST Enterprise [Crawler]' => array('FAST Enterprise Crawler', ''), |
82 | 'FAST WebCrawler [Crawler]' => array('FAST-WebCrawler/', ''), |
83 | 'Francis [Bot]' => array('http://www.neomo.de/', ''), |
84 | 'Gigabot [Bot]' => array('Gigabot/', ''), |
85 | 'Google Adsense [Bot]' => array('Mediapartners-Google', ''), |
86 | 'Google Desktop' => array('Google Desktop', ''), |
87 | 'Google Feedfetcher' => array('Feedfetcher-Google', ''), |
88 | 'Google [Bot]' => array('Googlebot', ''), |
89 | 'Heise IT-Markt [Crawler]' => array('heise-IT-Markt-Crawler', ''), |
90 | 'Heritrix [Crawler]' => array('heritrix/1.', ''), |
91 | 'IBM Research [Bot]' => array('ibm.com/cs/crawler', ''), |
92 | 'ICCrawler - ICjobs' => array('ICCrawler - ICjobs', ''), |
93 | 'ichiro [Crawler]' => array('ichiro/', ''), |
94 | 'Majestic-12 [Bot]' => array('MJ12bot/', ''), |
95 | 'Metager [Bot]' => array('MetagerBot/', ''), |
96 | 'MSN NewsBlogs' => array('msnbot-NewsBlogs/', ''), |
97 | 'MSN [Bot]' => array('msnbot/', ''), |
98 | 'MSNbot Media' => array('msnbot-media/', ''), |
99 | 'NG-Search [Bot]' => array('NG-Search/', ''), |
100 | 'Nutch [Bot]' => array('http://lucene.apache.org/nutch/', ''), |
101 | 'Nutch/CVS [Bot]' => array('NutchCVS/', ''), |
102 | 'OmniExplorer [Bot]' => array('OmniExplorer_Bot/', ''), |
103 | 'Online link [Validator]' => array('online link validator', ''), |
104 | 'psbot [Picsearch]' => array('psbot/0', ''), |
105 | 'Seekport [Bot]' => array('Seekbot/', ''), |
106 | 'Semrush [Bot]' => array('SemrushBot/', ''), |
107 | 'Sensis [Crawler]' => array('Sensis Web Crawler', ''), |
108 | 'SEO Crawler' => array('SEO search Crawler/', ''), |
109 | 'Seoma [Crawler]' => array('Seoma [SEO Crawler]', ''), |
110 | 'SEOSearch [Crawler]' => array('SEOsearch/', ''), |
111 | 'Snappy [Bot]' => array('Snappy/1.1 ( http://www.urltrends.com/ )', ''), |
112 | 'Steeler [Crawler]' => array('http://www.tkl.iis.u-tokyo.ac.jp/~crawler/', ''), |
113 | 'Synoo [Bot]' => array('SynooBot/', ''), |
114 | 'Telekom [Bot]' => array('crawleradmin.t-info@telekom.de', ''), |
115 | 'TurnitinBot [Bot]' => array('TurnitinBot/', ''), |
116 | 'Voyager [Bot]' => array('voyager/', ''), |
117 | 'W3 [Sitesearch]' => array('W3 SiteSearch Crawler', ''), |
118 | 'W3C [Linkcheck]' => array('W3C-checklink/', ''), |
119 | 'W3C [Validator]' => array('W3C_*Validator', ''), |
120 | 'WiseNut [Bot]' => array('http://www.WISEnutbot.com', ''), |
121 | 'YaCy [Bot]' => array('yacybot', ''), |
122 | 'Yahoo MMCrawler [Bot]' => array('Yahoo-MMCrawler/', ''), |
123 | 'Yahoo Slurp [Bot]' => array('Yahoo! DE Slurp', ''), |
124 | 'Yahoo [Bot]' => array('Yahoo! Slurp', ''), |
125 | 'YahooSeeker [Bot]' => array('YahooSeeker/', ''), |
126 | ); |
127 | |
128 | /** |
129 | * @var config |
130 | */ |
131 | protected $install_config; |
132 | |
133 | /** |
134 | * @var iohandler_interface |
135 | */ |
136 | protected $io_handler; |
137 | |
138 | /** |
139 | * @var language |
140 | */ |
141 | protected $language; |
142 | |
143 | /** |
144 | * @var string |
145 | */ |
146 | protected $phpbb_root_path; |
147 | |
148 | /** |
149 | * @var string |
150 | */ |
151 | protected $php_ext; |
152 | |
153 | /** |
154 | * @var string |
155 | */ |
156 | protected $groups_table; |
157 | |
158 | /** |
159 | * @var string |
160 | */ |
161 | protected $bots_table; |
162 | |
163 | /** |
164 | * @var DriverStatement|Statement |
165 | */ |
166 | protected $stmt; |
167 | |
168 | /** |
169 | * @var int |
170 | */ |
171 | protected $group_id; |
172 | |
173 | /** |
174 | * Constructor |
175 | * |
176 | * @param config $install_config Installer's config |
177 | * @param database $db_helper Database helper. |
178 | * @param iohandler_interface $iohandler Input-output handler for the installer |
179 | * @param container_factory $container Installer's DI container |
180 | * @param language $language Language provider |
181 | * @param string $phpbb_root_path Relative path to phpBB root |
182 | * @param string $php_ext PHP extension |
183 | */ |
184 | public function __construct(config $install_config, |
185 | database $db_helper, |
186 | iohandler_interface $iohandler, |
187 | container_factory $container, |
188 | language $language, |
189 | string $phpbb_root_path, |
190 | string $php_ext) |
191 | { |
192 | $this->install_config = $install_config; |
193 | $this->io_handler = $iohandler; |
194 | $this->language = $language; |
195 | $this->phpbb_root_path = $phpbb_root_path; |
196 | $this->php_ext = $php_ext; |
197 | |
198 | $this->bots_table = $container->get_parameter('tables.bots'); |
199 | $this->groups_table = $container->get_parameter('tables.groups'); |
200 | |
201 | parent::__construct( |
202 | self::get_doctrine_connection($db_helper, $install_config), |
203 | $this->io_handler, |
204 | true |
205 | ); |
206 | } |
207 | |
208 | /** |
209 | * {@inheritdoc} |
210 | */ |
211 | public function run() |
212 | { |
213 | $this->group_id = $this->install_config->get('bots_group_id'); |
214 | if ($this->group_id === false) |
215 | { |
216 | $sql = 'SELECT group_id FROM ' . $this->groups_table . " WHERE group_name = 'BOTS'"; |
217 | $result = $this->query($sql); |
218 | |
219 | try |
220 | { |
221 | $this->group_id = (int) $result->fetchOne(); |
222 | $result->free(); |
223 | } |
224 | catch (Exception $e) |
225 | { |
226 | $this->group_id = 0; |
227 | } |
228 | |
229 | $this->install_config->set('bots_group_id', $this->group_id); |
230 | } |
231 | |
232 | if (!$this->group_id) |
233 | { |
234 | // If we reach this point then something has gone very wrong |
235 | $this->io_handler->add_error_message('NO_GROUP'); |
236 | } |
237 | |
238 | $sql = 'INSERT INTO ' . $this->bots_table . ' ' |
239 | . '(bot_active, bot_name, user_id, bot_agent, bot_ip) VALUES ' |
240 | . '(:bot_active, :bot_name, :user_id, :bot_agent, :bot_ip)'; |
241 | $this->stmt = $this->create_prepared_stmt($sql); |
242 | $this->execute($this->install_config, $this->bot_list); |
243 | } |
244 | |
245 | /** |
246 | * {@inheritdoc} |
247 | */ |
248 | protected function execute_step($key, $value) : void |
249 | { |
250 | if (!function_exists('user_add')) |
251 | { |
252 | include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); |
253 | } |
254 | |
255 | $user_id = user_add([ |
256 | 'user_type' => USER_IGNORE, |
257 | 'group_id' => $this->group_id, |
258 | 'username' => $key, |
259 | 'user_regdate' => time(), |
260 | 'user_password' => '', |
261 | 'user_colour' => '9E8DA7', |
262 | 'user_email' => '', |
263 | 'user_lang' => $this->install_config->get('default_lang'), |
264 | 'user_style' => 1, |
265 | 'user_timezone' => 'UTC', |
266 | 'user_dateformat' => $this->language->lang('default_dateformat'), |
267 | 'user_allow_massemail' => 0, |
268 | 'user_allow_pm' => 0, |
269 | ]); |
270 | |
271 | if (!$user_id) |
272 | { |
273 | // If we can't insert this user then continue to the next one to avoid inconsistent data |
274 | $this->io_handler->add_error_message('CONV_ERROR_INSERT_BOT'); |
275 | return; |
276 | } |
277 | |
278 | $this->exec_prepared_stmt($this->stmt, [ |
279 | 'bot_active' => 1, |
280 | 'bot_name' => (string) $key, |
281 | 'user_id' => (int) $user_id, |
282 | 'bot_agent' => (string) $value[0], |
283 | 'bot_ip' => (string) $value[1], |
284 | ]); |
285 | } |
286 | |
287 | /** |
288 | * {@inheritdoc} |
289 | */ |
290 | public static function get_step_count() : int |
291 | { |
292 | return 1; |
293 | } |
294 | |
295 | /** |
296 | * {@inheritdoc} |
297 | */ |
298 | public function get_task_lang_name() : string |
299 | { |
300 | return 'TASK_ADD_BOTS'; |
301 | } |
302 | } |