Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 83 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
bot_update | |
0.00% |
0 / 83 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
depends_on | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
update_data | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
update_bing_bot | |
0.00% |
0 / 46 |
|
0.00% |
0 / 1 |
20 | |||
update_bots | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
30 |
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\db\migration\data\v310; |
15 | |
16 | class bot_update extends \phpbb\db\migration\migration |
17 | { |
18 | public static function depends_on() |
19 | { |
20 | return array('\phpbb\db\migration\data\v310\rc6'); |
21 | } |
22 | |
23 | public function update_data() |
24 | { |
25 | return array( |
26 | array('custom', array(array(&$this, 'update_bing_bot'))), |
27 | array('custom', array(array(&$this, 'update_bots'))), |
28 | ); |
29 | } |
30 | |
31 | public function update_bing_bot() |
32 | { |
33 | $bot_name = 'Bing [Bot]'; |
34 | $bot_name_clean = utf8_clean_string($bot_name); |
35 | |
36 | $sql = 'SELECT user_id |
37 | FROM ' . USERS_TABLE . " |
38 | WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; |
39 | $result = $this->db->sql_query($sql); |
40 | $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); |
41 | $this->db->sql_freeresult($result); |
42 | |
43 | if (!$bing_already_added) |
44 | { |
45 | $bot_agent = 'bingbot/'; |
46 | $bot_ip = ''; |
47 | $sql = 'SELECT group_id, group_colour |
48 | FROM ' . GROUPS_TABLE . " |
49 | WHERE group_name = 'BOTS'"; |
50 | $result = $this->db->sql_query($sql); |
51 | $group_row = $this->db->sql_fetchrow($result); |
52 | $this->db->sql_freeresult($result); |
53 | |
54 | if (!$group_row) |
55 | { |
56 | // default fallback, should never get here |
57 | $group_row = []; |
58 | $group_row['group_id'] = 6; |
59 | $group_row['group_colour'] = '9E8DA7'; |
60 | } |
61 | |
62 | if (!function_exists('user_add')) |
63 | { |
64 | include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); |
65 | } |
66 | |
67 | $user_row = array( |
68 | 'user_type' => USER_IGNORE, |
69 | 'group_id' => $group_row['group_id'], |
70 | 'username' => $bot_name, |
71 | 'user_regdate' => time(), |
72 | 'user_password' => '', |
73 | 'user_colour' => $group_row['group_colour'], |
74 | 'user_email' => '', |
75 | 'user_lang' => $this->config['default_lang'], |
76 | 'user_style' => $this->config['default_style'], |
77 | 'user_timezone' => 0, |
78 | 'user_dateformat' => $this->config['default_dateformat'], |
79 | 'user_allow_massemail' => 0, |
80 | ); |
81 | |
82 | $user_id = user_add($user_row); |
83 | |
84 | $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( |
85 | 'bot_active' => 1, |
86 | 'bot_name' => (string) $bot_name, |
87 | 'user_id' => (int) $user_id, |
88 | 'bot_agent' => (string) $bot_agent, |
89 | 'bot_ip' => (string) $bot_ip, |
90 | )); |
91 | |
92 | $this->sql_query($sql); |
93 | } |
94 | } |
95 | |
96 | public function update_bots() |
97 | { |
98 | // Update bots |
99 | if (!function_exists('user_delete')) |
100 | { |
101 | include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); |
102 | } |
103 | |
104 | $bots_updates = array( |
105 | // Bot Deletions |
106 | 'NG-Search [Bot]' => false, |
107 | 'Nutch/CVS [Bot]' => false, |
108 | 'OmniExplorer [Bot]' => false, |
109 | 'Seekport [Bot]' => false, |
110 | 'Synoo [Bot]' => false, |
111 | 'WiseNut [Bot]' => false, |
112 | |
113 | // Bot Updates |
114 | // Bot name to bot user agent map |
115 | 'Baidu [Spider]' => 'Baiduspider', |
116 | 'Exabot [Bot]' => 'Exabot', |
117 | 'Voyager [Bot]' => 'voyager/', |
118 | 'W3C [Validator]' => 'W3C_Validator', |
119 | ); |
120 | |
121 | foreach ($bots_updates as $bot_name => $bot_agent) |
122 | { |
123 | $sql = 'SELECT user_id |
124 | FROM ' . USERS_TABLE . ' |
125 | WHERE user_type = ' . USER_IGNORE . " |
126 | AND username_clean = '" . $this->db->sql_escape(utf8_clean_string($bot_name)) . "'"; |
127 | $result = $this->db->sql_query($sql); |
128 | $bot_user_id = (int) $this->db->sql_fetchfield('user_id'); |
129 | $this->db->sql_freeresult($result); |
130 | |
131 | if ($bot_user_id) |
132 | { |
133 | if ($bot_agent === false) |
134 | { |
135 | $sql = 'DELETE FROM ' . BOTS_TABLE . " |
136 | WHERE user_id = $bot_user_id"; |
137 | $this->sql_query($sql); |
138 | |
139 | user_delete('retain', $bot_user_id); |
140 | } |
141 | else |
142 | { |
143 | $sql = 'UPDATE ' . BOTS_TABLE . " |
144 | SET bot_agent = '" . $this->db->sql_escape($bot_agent) . "' |
145 | WHERE user_id = $bot_user_id"; |
146 | $this->sql_query($sql); |
147 | } |
148 | } |
149 | } |
150 | } |
151 | } |