-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathantispam_by_cleantalk.php
224 lines (197 loc) · 8.21 KB
/
antispam_by_cleantalk.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/****************************************************************************
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
if (!defined('IN_MYBB')){
die('This file cannot be accessed directly.');
}
// CleanTalk version and agent
define( 'CLEANTALK_ANTISPAM_VERSION', '1.5' );
define( 'ENGINE', 'mybb-' . str_replace( '.', '', CLEANTALK_ANTISPAM_VERSION ) );
require_once MYBB_ROOT . 'inc/plugins/antispam_by_cleantalk/autoloader.php';
require_once MYBB_ROOT . 'inc/plugins/antispam_by_cleantalk/hooks_nandlers.php';
require_once MYBB_ROOT . 'inc/plugins/antispam_by_cleantalk/apbct_functions.php';
// The plugin's hooks
$plugins->add_hook('newthread_do_newthread_start', 'antispam_by_cleantalk_trigger');
$plugins->add_hook('newreply_do_newreply_start', 'antispam_by_cleantalk_trigger');
$plugins->add_hook('editpost_do_editpost_start', 'antispam_by_cleantalk_trigger');
$plugins->add_hook('member_do_register_start', 'antispam_by_cleantalk_regtrigger');
$plugins->add_hook('contact_do_start', 'antispam_by_cleantalk_contacttrigger');
$plugins->add_hook('pre_output_page', 'antispam_by_cleantalk_add_js');
$plugins->add_hook('global_start', 'antispam_by_cleantalk_set_global');
$plugins->add_hook('admin_config_settings_change_commit', 'savesettings_trigger');
function antispam_by_cleantalk_info()
{
return array(
"name" => "Antispam by CleanTalk (SPAM protection)",
"description" => "Max power, all-in-one, no Captcha, premium anti-spam plugin. No comment spam, no registration spam. Formerly Anti-Spam by CleanTalk",
"website" => "https://cleantalk.org/",
"author" => "CleanTalk",
"authorsite" => "https://cleantalk.org/",
"version" => "v" . CLEANTALK_ANTISPAM_VERSION,
"guid" => "",
"compatibility" => "18*"
);
}
function antispam_by_cleantalk_install()
{
global $db;
$ap_group = Array(
'name' => "antispam_by_cleantalk",
'title' => "Antispam by CleanTalk (SPAM protection)",
'description' => "",
'disporder' => 1,
'isdefault' => 1
);
$gid = $db->insert_query("settinggroups", $ap_group);
$antispam_by_cleantalk_settings = Array();
$antispam_by_cleantalk_settings[] = Array(
'name' => "antispam_by_cleantalk_enabled",
'title' => "Enabled?",
'description' => "Enable/disable Antispam by CleanTalk",
'optionscode' => "yesno",
'value' => "1",
'disporder' => 1,
'gid' => $gid
);
$antispam_by_cleantalk_settings[] = Array(
'name' => "antispam_by_cleantalk_regcheck",
'title' => "Check registrations",
'description' => "Spam-bots will be rejected with a statement of reasons",
'optionscode' => "yesno",
'value' => "1",
'disporder' => 2,
'gid' => $gid
);
$antispam_by_cleantalk_settings[] = Array(
'name' => "antispam_by_cleantalk_comcheck",
'title' => "Check posts",
'description' => "Posts and topics from users with numposts <=3 will be checked for spam",
'optionscode' => "yesno",
'value' => "1",
'disporder' => 3,
'gid' => $gid
);
$antispam_by_cleantalk_settings[] = Array(
'name' => "antispam_by_cleantalk_exclusions_url",
'title' => "URL exclusions",
'description' => "You could type here URL you want to exclude. Use comma as separator.",
'optionscode' => "text",
'value' => "",
'disporder' => 4,
'gid' => $gid
);
$antispam_by_cleantalk_settings[] = Array(
'name' => "antispam_by_cleantalk_exclusions_groups",
'title' => "User\'s groups exclusions",
'description' => "Roles which bypass spam test. Hold CTRL to select multiple roles.",
'optionscode' => "groupselect",
'value' => "",
'disporder' => 5,
'gid' => $gid
);
$antispam_by_cleantalk_settings[] = Array(
'name' => "antispam_by_cleantalk_sfw",
'title' => "Enable SFW",
'description' => "This option allows to filter spam bots before they access website. Also reduces CPU usage on hosting server and accelerates pages load time",
'optionscode' => "yesno",
'value' => "1",
'disporder' => 6,
'gid' => $gid
);
$antispam_by_cleantalk_settings[] = Array(
'name' => "antispam_by_cleantalk_footerlink",
'title' => "Tell others about CleanTalk?",
'description' => "Enabling this option places a small link in the footer of your site that lets others know what anti-spam tool protects your site.",
'optionscode' => "yesno",
'value' => "0",
'disporder' => 7,
'gid' => $gid
);
$antispam_by_cleantalk_settings[] = Array(
'name' => "antispam_by_cleantalk_accesskey",
'title' => "Access key",
'description' => "To get an access key, please register <a target=_blank href=https://cleantalk.org/register>here</a>",
'optionscode' => "text",
'value' => "",
'disporder' => 8,
'gid' => $gid
);
foreach ($antispam_by_cleantalk_settings as $setting){
$db->insert_query("settings", $setting);
}
rebuild_settings();
$template = '{$lang->error_nopermission_user_1}
<ol>
<li>{$lang->error_nopermission_user_2}</li>
<li>{$lang->error_nopermission_user_3}</li>
<li>{$lang->error_nopermission_user_4} (<a href="member.php?action=resendactivation">{$lang->error_nopermission_user_resendactivation}</a>)</li>
<li>{$lang->error_nopermission_user_5}</li>
</ol>
<br />
{$lang->error_nopermission_user_username}';
$insert_array = array(
'title' => 'antispam_by_cleantalk_error_page',
'template' => $db->escape_string($template),
'sid' => '-1',
'version' => '',
'dateline' => time()
);
$db->insert_query('templates', $insert_array);
$db->query("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."cleantalk_sfw (
`network` int(11) unsigned NOT NULL,
`mask` int(11) unsigned NOT NULL,
`status` TINYINT(1) NOT NULL DEFAULT 0,
INDEX ( `network` , `mask` ));
");
$db->query("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."cleantalk_sfw_logs (
`ip` VARCHAR(15) NOT NULL,
`all_entries` INT NOT NULL,
`blocked_entries` INT NOT NULL,
`entries_timestamp` INT NOT NULL,
PRIMARY KEY (`ip`));
");
// This is the hidden setting to contain cron jobs.
$antispam_by_cleantalk_cron = array(
'name' => \CleantalkAP\Mybb\Cron::CRON_OPTION_NAME,
'title' => "",
'description' => "",
'optionscode' => "text",
'value' => "",
'disporder' => 0,
'gid' => 0
);
$db->insert_query("settings", $antispam_by_cleantalk_cron);
rebuild_settings();
\CleantalkAP\Mybb\Cron::addTask('sfw_update', 'antispam_by_cleantalk_sfw_update', 86400, time()+300); // SFW update
\CleantalkAP\Mybb\Cron::addTask('send_sfw_logs', 'antispam_by_cleantalk_sfw_send_logs', 3600, time()+1800); // SFW send logs
}
function antispam_by_cleantalk_uninstall()
{
global $db;
$db->delete_query("settings", "name IN ('antispam_by_cleantalk_enabled','antispam_by_cleantalk_regcheck','antispam_by_cleantalk_comcheck', 'antispam_by_cleantalk_sfw', 'antispam_by_cleantalk_footerlink','antispam_by_cleantalk_accesskey','antispam_by_cleantalk_exclusions_url','antispam_by_cleantalk_exclusions_groups','antispam_by_cleantalk_cron')");
$db->delete_query("settinggroups", "name='antispam_by_cleantalk'");
$db->delete_query("templates", "title = 'antispam_by_cleantalk_error_page'");
$db->drop_table("cleantalk_sfw");
$db->drop_table("cleantalk_sfw_logs");
$db->delete_query("templates", "title='footer' AND sid='1'");
rebuild_settings();
}
function antispam_by_cleantalk_is_installed()
{
global $db;
$query = $db->simple_select('settinggroups', '*', "name='antispam_by_cleantalk'");
if ($db->num_rows($query)){
return true;
}
return false;
}