' . $this->language->lang('RETURN_TOPIC', 'root_path}viewtopic.$this->php_ext?t=" . $topicid) . '">', '');
187 |
188 | return $this->helper->message($message);
189 | }
190 |
191 | if (confirm_box(true))
192 | {
193 | $response = $this->sfsapi->sfsapi('add', $username, $userip, $useremail, $evidence, $this->config['sfs_api_key']);
194 |
195 | $json_decode = json_decode($response, true);
196 | // ajax stuffs
197 | if (isset($json_decode[$this->language->lang('CURL_ERROR')]) && $this->request->is_ajax())
198 | {
199 | $data = [
200 | 'MESSAGE_TITLE' => $this->language->lang('AJAX_ERROR_TITLE'),
201 | 'MESSAGE_TEXT' => $json_decode[$this->language->lang('CURL_ERROR')],
202 | 'success' => false,
203 | ];
204 | return new JsonResponse($data);
205 | }
206 | else if (!$response && $this->request->is_ajax())
207 | {
208 | $data = [
209 | 'MESSAGE_TITLE' => $this->language->lang('AJAX_ERROR_TITLE'),
210 | 'MESSAGE_TEXT' => $this->language->lang('SFS_ERROR_MESSAGE'),
211 | 'success' => false,
212 | ];
213 | return new JsonResponse($data);
214 | }
215 | //non-ajax stuffs
216 | else if (isset($json_decode[$this->language->lang('CURL_ERROR')]))
217 | {
218 | $this->template->assign_vars([
219 | 'MESSAGE_TITLE' => $this->language->lang('ERROR'),
220 | 'MESSAGE_TEXT' => $json_decode[$this->language->lang('CURL_ERROR')]
221 | ]);
222 |
223 | return $this->helper->render('message_body.html');
224 | }
225 | else if (!$response)
226 | {
227 | $this->template->assign_vars([
228 | 'MESSAGE_TITLE' => $this->language->lang('ERROR'),
229 | 'MESSAGE_TEXT' => $this->language->lang('SFS_ERROR_MESSAGE')
230 | ]);
231 |
232 | return $this->helper->render('message_body.html');
233 | }
234 |
235 | // Report the uhmmm reported?
236 | if ($this->config['sfs_notify'])
237 | {
238 | $this->check_report($postid);
239 | }
240 |
241 | $sql = 'UPDATE ' . POSTS_TABLE . '
242 | SET sfs_reported = 1
243 | WHERE post_id = ' . (int) $postid;
244 | $this->db->sql_query($sql);
245 |
246 | $sfs_username = $this->language->lang('SFS_USERNAME_STOPPED', $username);
247 |
248 | $this->sfsapi->sfs_ban('user', $username);
249 |
250 | $this->log->add('mod', $this->user->data['user_id'], $this->user->ip, 'LOG_SFS_REPORTED', false, [$sfs_username, 'forum_id' => $forumid, 'topic_id' => $topicid, 'post_id' => $postid]);
251 |
252 | if ($this->request->is_ajax())
253 | {
254 | $data = [
255 | 'MESSAGE_TITLE' => $this->language->lang('SFS_SUCCESS'),
256 | 'MESSAGE_TEXT' => $this->language->lang('SFS_SUCCESS_MESSAGE'),
257 | 'success' => true,
258 | 'postid' => $postid,
259 | ];
260 | return new JsonResponse($data);
261 | }
262 | else
263 | {
264 | $this->template->assign_vars([
265 | 'MESSAGE_TITLE' => $this->language->lang('SFS_SUCCESS'),
266 | 'MESSAGE_TEXT' => $this->language->lang('SFS_SUCCESS_MESSAGE')
267 | ]);
268 |
269 | return $this->helper->render('message_body.html');
270 | }
271 | }
272 | else
273 | {
274 | if ($this->request->is_ajax())
275 | {
276 | confirm_box(
277 | false,
278 | $this->language->lang('SFS_CONFIRM'),
279 | '',
280 | 'confirm_body.html',
281 | $this->helper->route(
282 | 'rmcgirr83_stopforumspam_core_reporttosfs',
283 | [
284 | 'postid' => $postid,
285 | 'posterid' => $posterid,
286 | ],
287 | true,
288 | false,
289 | UrlGeneratorInterface::ABSOLUTE_URL
290 | )
291 | );
292 | }
293 | else
294 | {
295 | confirm_box(false, $this->language->lang('SFS_CONFIRM'));
296 | }
297 | }
298 | }
299 |
300 | /*
301 | * check_report check to see if the post msg has already been reported
302 | * @param $postid postid from the report to sfs
303 | * @return json|html response if found
304 | */
305 | private function check_report($postid)
306 | {
307 | $sql = 'SELECT *
308 | FROM ' . POSTS_TABLE . '
309 | WHERE post_id = ' . (int) $postid;
310 | $result = $this->db->sql_query($sql);
311 | $report_data = $this->db->sql_fetchrow($result);
312 | $this->db->sql_freeresult($result);
313 |
314 | if (!$report_data && $this->request->is_ajax())
315 | {
316 | $data = [
317 | 'MESSAGE_TITLE' => $this->language->lang('ERROR'),
318 | 'MESSAGE_TEXT' => $this->language->lang('POST_NOT_EXIST'),
319 | 'success' => false,
320 | ];
321 | return new JsonResponse($data);
322 | }
323 | else if (!$report_data)
324 | {
325 | $this->template->assign_vars([
326 | 'MESSAGE_TITLE' => $this->language->lang('ERROR'),
327 | 'MESSAGE_TEXT' => $this->language->lang('POST_NOT_EXIST'),
328 | ]);
329 |
330 | return $this->helper->render('message_body.html');
331 | }
332 |
333 | // if the post isn't reported, then report it
334 | if (!$report_data['post_reported'])
335 | {
336 | $report_name = 'other';
337 | $report_text = $this->language->lang('SFS_WAS_REPORTED');
338 |
339 | $sql = 'SELECT *
340 | FROM ' . REPORTS_REASONS_TABLE . "
341 | WHERE reason_title = '" . $this->db->sql_escape($report_name). "'";
342 | $result = $this->db->sql_query($sql);
343 | $row = $this->db->sql_fetchrow($result);
344 | $this->db->sql_freeresult($result);
345 |
346 | $phpbb_notifications = $this->container->get('phpbb.report.handlers.report_handler_post');
347 | $phpbb_notifications->add_report($postid, $row['reason_id'], $report_text, 0);
348 | }
349 | }
350 | }
351 |
--------------------------------------------------------------------------------
/controller/admin_controller.php:
--------------------------------------------------------------------------------
1 | cache = $cache;
104 | $this->config = $config;
105 | $this->db = $db;
106 | $this->language = $language;
107 | $this->log = $log;
108 | $this->request = $request;
109 | $this->template = $template;
110 | $this->user = $user;
111 | $this->sfsgroups = $sfsgroups;
112 | $this->root_path = $root_path;
113 | $this->php_ext = $php_ext;
114 | $this->contactadmin = $contactadmin;
115 | }
116 |
117 | /**
118 | * Display the options a user can configure for this extension
119 | *
120 | * @return null
121 | * @access public
122 | */
123 | public function display_options()
124 | {
125 | // Add the language files
126 | $this->language->add_lang('acp/acp_stopforumspam', 'rmcgirr83/stopforumspam');
127 | $this->language->add_lang('acp/ban');
128 |
129 | $action = $this->request->variable('action', '');
130 |
131 | add_form_key('sfs');
132 | $curl_active = $this->allow_sfs();
133 |
134 | $cache_built = '';
135 | if (!$this->cache->get('_sfs_adminsmods') && $this->config['sfs_api_key'])
136 | {
137 | $cache_built = $this->language->lang('SFS_NEED_CACHE');
138 | }
139 |
140 | $sql = 'SELECT COUNT(sfs_reported) AS stat
141 | FROM ' . POSTS_TABLE . '
142 | WHERE sfs_reported = 1';
143 | $result = $this->db->sql_query($sql);
144 | $row = $this->db->sql_fetchfield('stat');
145 | $this->db->sql_freeresult($result);
146 |
147 | $posts_reported = $row;
148 |
149 | $sql = 'SELECT COUNT(sfs_reported) AS stat
150 | FROM ' . PRIVMSGS_TABLE . '
151 | WHERE sfs_reported = 1';
152 | $result = $this->db->sql_query($sql);
153 | $row = $this->db->sql_fetchfield('stat');
154 | $this->db->sql_freeresult($result);
155 |
156 | $pms_reported = $row;
157 |
158 | $sfs_posts_pms_count = (int) $posts_reported + (int) $pms_reported;
159 |
160 | switch ($action)
161 | {
162 | case 'sfsclrreports':
163 | //if none have been reported there's nothing to do
164 | if (empty($sfs_posts_pms_count))
165 | {
166 | return false;
167 | }
168 |
169 | if (confirm_box(true))
170 | {
171 | $this->sfsclrreports();
172 | }
173 | else
174 | {
175 | confirm_box(false, 'SFS_CLEAR_SURE');
176 | }
177 | break;
178 |
179 | case 'build_adminsmods':
180 |
181 | $this->build_adminsmods();
182 |
183 | break;
184 | }
185 |
186 | if ($this->request->is_set_post('submit'))
187 | {
188 | // Test if the submitted form is valid
189 | if (!check_form_key('sfs'))
190 | {
191 | trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action));
192 | }
193 |
194 | if (!function_exists('validate_data'))
195 | {
196 | include($this->root_path . 'includes/functions_user.' . $this->php_ext);
197 | }
198 |
199 | $has_api_key = $this->request->variable('sfs_api_key', '', true);
200 |
201 | $check_row = ['sfs_threshold' => $this->request->variable('sfs_threshold', 0)];
202 | $validate_row = ['sfs_threshold' => ['num', false, 1, 99]];
203 | $error = validate_data($check_row, $validate_row);
204 |
205 | if (!sizeof($error))
206 | {
207 | if (!empty($has_api_key))
208 | {
209 | $this->sfsgroups->build_adminsmods_cache();
210 | }
211 |
212 | // Set the options the user configured
213 | $this->set_options();
214 |
215 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SFS_CONFIG_SAVED');
216 |
217 | trigger_error($this->language->lang('SFS_SETTINGS_SUCCESS') . adm_back_link($this->u_action));
218 | }
219 | }
220 |
221 | $this->template->assign_vars([
222 | 'ERROR' => isset($error) ? ((sizeof($error)) ? implode(' ', $error) : '') : '',
223 | 'SFS_API_KEY' => $this->config['sfs_api_key'],
224 | 'ALLOW_SFS' => ($this->config['allow_sfs'] && $curl_active) ? true : false,
225 | 'CURL_ACTIVE' => (!$curl_active) ? $this->language->lang('LOG_SFS_NEED_CURL') : false,
226 | 'SFS_THRESHOLD' => (int) $this->config['sfs_threshold'],
227 | 'SFS_BAN_IP' => ($this->config['sfs_ban_ip']) ? true : false,
228 | 'SFS_LOG_MESSAGE' => ($this->config['sfs_log_message']) ? true : false,
229 | 'SFS_DOWN' => ($this->config['sfs_down']) ? true : false,
230 | 'SFS_BY_NAME' => ($this->config['sfs_by_name']) ? true : false,
231 | 'SFS_BY_EMAIL' => ($this->config['sfs_by_email']) ? true : false,
232 | 'SFS_BY_IP' => ($this->config['sfs_by_ip']) ? true : false,
233 | 'SFS_BAN_REASON' => ($this->config['sfs_ban_reason']) ? true : false,
234 | 'SFS_REPORT_PM' => ($this->config['sfs_report_pm']) ? true : false,
235 | 'SFS_BAN_TIME' => $this->display_ban_time($this->config['sfs_ban_time']),
236 | 'SFS_NOTIFY' => ($this->config['sfs_notify']) ? true : false,
237 | 'SFS_POSTS_PMS_COUNT' => $sfs_posts_pms_count,
238 | 'SFS_CONTACTADMIN' => ($this->config['sfs_contactadmin']) ? true : false,
239 | 'NOTICE' => $cache_built,
240 | 'POSTS_REPORTED' => (int) $posts_reported,
241 | 'PMS_REPORTED' => (int) $pms_reported,
242 | 'S_CONTACTADMIN' => ($this->contactadmin) ? true : false,
243 |
244 | 'U_BUILD_CACHE' => $this->u_action . '&action=build_adminsmods',
245 | 'U_CLR_REPORTS' => $this->u_action . '&action=sfsclrreports',
246 | 'U_ACTION' => $this->u_action,
247 | ]);
248 | }
249 |
250 | /**
251 | * Set the options a user can configure
252 | *
253 | * @return void
254 | * @access protected
255 | */
256 | protected function set_options()
257 | {
258 | $this->config->set('sfs_threshold', $this->request->variable('sfs_threshold', 0));
259 | $this->config->set('allow_sfs', $this->request->variable('allow_sfs', 0));
260 | $this->config->set('sfs_ban_ip', $this->request->variable('sfs_ban_ip', 0));
261 | $this->config->set('sfs_log_message', $this->request->variable('sfs_log_message', 0));
262 | $this->config->set('sfs_down', $this->request->variable('sfs_down', 0));
263 | $this->config->set('sfs_by_name', $this->request->variable('sfs_by_name', 0));
264 | $this->config->set('sfs_by_email', $this->request->variable('sfs_by_email', 0));
265 | $this->config->set('sfs_by_ip', $this->request->variable('sfs_by_ip', 0));
266 | $this->config->set('sfs_ban_reason', $this->request->variable('sfs_ban_reason', 0));
267 | $this->config->set('sfs_api_key', $this->request->variable('sfs_api_key', '', true));
268 | $this->config->set('sfs_ban_time', $this->request->variable('sfs_ban_time', 0));
269 | $this->config->set('sfs_notify', $this->request->variable('sfs_notify', 0));
270 | $this->config->set('sfs_report_pm', $this->request->variable('sfs_report_pm', 0));
271 | $this->config->set('sfs_contactadmin', $this->request->variable('sfs_contactadmin', 0));
272 | }
273 |
274 | /**
275 | * Ensure cURL is active on server
276 | *
277 | * @return bool
278 | * @access protected
279 | */
280 | protected function allow_sfs()
281 | {
282 | // Determine if cURL is enabled on the server
283 | $curl = false;
284 | if (function_exists('curl_init'))
285 | {
286 | $curl = true;
287 | }
288 |
289 | if (!$curl)
290 | {
291 | $this->config->set('allow_sfs', false);
292 | }
293 |
294 | return $curl;
295 | }
296 | /**
297 | * Generate a select of ban time options
298 | *
299 | * @return string
300 | * @access protected
301 | */
302 | protected function display_ban_time($ban_time = 0)
303 | {
304 | // Ban length options
305 | $ban_text = [0 => $this->language->lang('PERMANENT'), 30 => $this->language->lang('30_MINS'), 60 => $this->language->lang('1_HOUR'), 360 => $this->language->lang('6_HOURS'), 1440 => $this->language->lang('1_DAY'), 10080 => $this->language->lang('7_DAYS'), 20160 => $this->language->lang('2_WEEKS'), 40320 => $this->language->lang('1_MONTH'), 524160 => $this->language->lang('1_YEAR')];
306 |
307 | $ban_options = '';
308 | foreach ($ban_text as $length => $text)
309 | {
310 | $selected = ($length == $ban_time) ? ' selected="selected"' : '';
311 | $ban_options .= "";
312 | }
313 |
314 | return $ban_options;
315 | }
316 |
317 | /**
318 | * Clear reported posts and pms
319 | *
320 | * @return json response
321 | * @access protected
322 | */
323 | protected function sfsclrreports()
324 | {
325 | $sql = 'UPDATE ' . POSTS_TABLE . ' SET sfs_reported = 0
326 | WHERE sfs_reported = 1';
327 | $this->db->sql_query($sql);
328 |
329 | $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' SET sfs_reported = 0
330 | WHERE sfs_reported = 1';
331 | $this->db->sql_query($sql);
332 |
333 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SFS_REPORTED_CLEARED');
334 |
335 | $data = [
336 | 'MESSAGE_TITLE' => $this->language->lang('SUCCESS'),
337 | 'MESSAGE_TEXT' => $this->language->lang('SFS_REPORTED_CLEARED'),
338 | 'success' => true,
339 | ];
340 |
341 | $json_response = new json_response;
342 | $json_response->send($data);
343 | }
344 |
345 | /**
346 | * Generate admin and mods cache
347 | *
348 | * @return json response
349 | * @access protected
350 | */
351 | protected function build_adminsmods()
352 | {
353 | if (empty($this->config['sfs_api_key']))
354 | {
355 | trigger_error('SFS_NEEDS_API');
356 | }
357 |
358 | $this->sfsgroups->build_adminsmods_cache();
359 |
360 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ADMINSMODS_CACHE_BUILT');
361 |
362 | $data = [
363 | 'MESSAGE_TITLE' => $this->language->lang('SUCCESS'),
364 | 'MESSAGE_TEXT' => $this->language->lang('LOG_ADMINSMODS_CACHE_BUILT'),
365 | 'success' => true,
366 | ];
367 |
368 | $json_response = new json_response;
369 | $json_response->send($data);
370 | }
371 |
372 | /**
373 | * Set page url
374 | *
375 | * @param string $u_action Custom form action
376 | * @return null
377 | * @access public
378 | */
379 | public function set_page_url($u_action)
380 | {
381 | $this->u_action = $u_action;
382 | }
383 | }
384 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Library General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License
307 | along with this program; if not, write to the Free Software
308 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
309 |
310 |
311 | Also add information on how to contact you by electronic and paper mail.
312 |
313 | If the program is interactive, make it output a short notice like this
314 | when it starts in an interactive mode:
315 |
316 | Gnomovision version 69, Copyright (C) year name of author
317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318 | This is free software, and you are welcome to redistribute it
319 | under certain conditions; type `show c' for details.
320 |
321 | The hypothetical commands `show w' and `show c' should show the appropriate
322 | parts of the General Public License. Of course, the commands you use may
323 | be called something other than `show w' and `show c'; they could even be
324 | mouse-clicks or menu items--whatever suits your program.
325 |
326 | You should also get your employer (if you work as a programmer) or your
327 | school, if any, to sign a "copyright disclaimer" for the program, if
328 | necessary. Here is a sample; alter the names:
329 |
330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
332 |
333 | , 1 April 1989
334 | Ty Coon, President of Vice
335 |
336 | This General Public License does not permit incorporating your program into
337 | proprietary programs. If your program is a subroutine library, you may
338 | consider it more useful to permit linking proprietary applications with the
339 | library. If this is what you want to do, use the GNU Library General
340 | Public License instead of this License.
341 |
--------------------------------------------------------------------------------
/event/main_listener.php:
--------------------------------------------------------------------------------
1 | auth = $auth;
92 | $this->cache = $cache;
93 | $this->config = $config;
94 | $this->helper = $helper;
95 | $this->language = $language;
96 | $this->log = $log;
97 | $this->request = $request;
98 | $this->template = $template;
99 | $this->user = $user;
100 | $this->sfsgroups = $sfsgroups;
101 | $this->sfsapi = $sfsapi;
102 | $this->root_path = $root_path;
103 | $this->php_ext = $php_ext;
104 | $this->contactadmin = $contactadmin;
105 | }
106 |
107 | static public function getSubscribedEvents()
108 | {
109 | return [
110 | 'core.user_setup_after' => 'user_setup_after',
111 | 'core.ucp_register_data_after' => 'user_sfs_validate_registration',
112 | 'core.posting_modify_template_vars' => 'poster_data_email',
113 | 'core.posting_modify_message_text' => 'poster_modify_message_text',
114 | 'core.posting_modify_submission_errors' => 'user_sfs_validate_posting',
115 | 'core.group_add_user_after' => 'update_sfs_admin_mods',
116 | 'core.group_delete_user_after' => 'update_sfs_admin_mods',
117 | // report to sfs?
118 | 'core.viewtopic_before_f_read_check' => 'viewtopic_before_f_read_check',
119 | 'core.viewtopic_post_rowset_data' => 'viewtopic_post_rowset_data',
120 | 'core.viewtopic_modify_post_row' => 'viewtopic_modify_post_row',
121 | 'core.ucp_pm_view_message' => 'ucp_pm_view_message',
122 | // Custom events for integration with Contact Admin Extension
123 | 'rmcgirr83.contactadmin.modify_data_and_error' => 'user_sfs_validate_registration',
124 | // phpBB default contact us page
125 | 'core.message_admin_form_submit_before' => 'message_admin_form_submit_before',
126 | ];
127 | }
128 |
129 | /**
130 | * Check for and create if needed admins and mods cache
131 | *
132 | * @param object $event The event object
133 | * @return void
134 | * @access public
135 | */
136 | public function user_setup_after($event)
137 | {
138 | $this->language->add_lang(['sfs_mcp', 'stopforumspam'], 'rmcgirr83/stopforumspam');
139 | $this->sfsgroups->build_adminsmods_cache();
140 | }
141 |
142 | /*
143 | * user_sfs_validate_registration validate a users registration event
144 | *
145 | * @param $event the event object
146 | * @return null
147 | * @access public
148 | */
149 | public function user_sfs_validate_registration($event)
150 | {
151 | if ($this->config['allow_sfs'] == false)
152 | {
153 | return false;
154 | }
155 |
156 | if ($this->user->page['page_name'] == 'app.' . $this->php_ext . '/contactadmin' && !$this->config['sfs_contactadmin'])
157 | {
158 | return false;
159 | }
160 |
161 | $error_array = $event['error'];
162 |
163 | // validate the user ip
164 | $userip_error = $this->validate_ip($this->user->ip);
165 | if ($userip_error)
166 | {
167 | $error_array[] = $userip_error;
168 | }
169 |
170 | /* On registration and only when all errors have cleared
171 | * do not want the admin message area to fill up
172 | */
173 | if (!sizeof($error_array))
174 | {
175 | $check = $this->stopforumspam_check($event['data']['username'], $this->user->ip, $event['data']['email']);
176 |
177 | if ($check)
178 | {
179 | if ($this->config['sfs_down'] && $check === 'sfs_down')
180 | {
181 | return;
182 | }
183 | $error_array[] = $this->show_message($check);
184 | // now ban the spammer by IP
185 | if (is_int($check) && $this->config['sfs_ban_ip'])
186 | {
187 | $this->sfsapi->sfs_ban('ip', $this->user->ip, (int) $check);
188 | }
189 | }
190 | }
191 | $event['error'] = $error_array;
192 | }
193 |
194 | /*
195 | * poster_data_email inject email address into posting if allowed for guests
196 | *
197 | * @param $event the event object
198 | * @return void
199 | * @access public
200 | */
201 | public function poster_data_email($event)
202 | {
203 | if ($this->user->data['user_id'] == ANONYMOUS && $this->config['allow_sfs'])
204 | {
205 | // Output the data vars to the template
206 | $this->template->assign_vars([
207 | 'SFS' => true,
208 | 'EMAIL' => $this->request->variable('email', ''),
209 | ]);
210 | }
211 | }
212 |
213 | /*
214 | * poster_modify_message_text inject email address into post data for validation
215 | *
216 | * @param $event the event object
217 | * @return void
218 | * @access public
219 | */
220 | public function poster_modify_message_text($event)
221 | {
222 | if ($event['mode'] == 'post' && $this->user->data['user_id'] == ANONYMOUS && $this->config['allow_sfs'])
223 | {
224 | $event['post_data'] = array_merge($event['post_data'], [
225 | 'email' => strtolower($this->request->variable('email', '')),
226 | 'username' => strtolower($this->request->variable('username', '')),
227 | 'user_ip' => $this->user->ip
228 | ]);
229 | }
230 | }
231 |
232 | /*
233 | * user_sfs_validate_posting validate username and email for guest posting
234 | *
235 | * @param $event the event object
236 | * @return void
237 | * @access public
238 | */
239 | public function user_sfs_validate_posting($event)
240 | {
241 | $error_array = $event['error'];
242 |
243 | if ($this->user->data['user_id'] == ANONYMOUS && $this->config['allow_sfs'])
244 | {
245 | $this->language->add_lang('ucp');
246 |
247 | if (!function_exists('phpbb_validate_email'))
248 | {
249 | include($this->root_path . 'includes/functions_user.' . $this->php_ext);
250 | }
251 |
252 | // ensure email is populated on posting
253 | $error = $this->validate_email($event['post_data']['email']);
254 | if ($error)
255 | {
256 | $error_array[] = $this->language->lang($error . '_EMAIL');
257 | }
258 | // I just hate empty usernames for guest posting
259 | if (empty($event['post_data']['username']))
260 | {
261 | $username_error = $this->validate_username($event['post_data']['username']);
262 | if ($username_error)
263 | {
264 | $error_array[] = $username_error;
265 | }
266 | }
267 |
268 | // validate the user ip
269 | $userip_error = $this->validate_ip($event['post_data']['user_ip']);
270 | if ($userip_error)
271 | {
272 | $error_array[] = $userip_error;
273 | }
274 |
275 | if (!sizeof($error_array))
276 | {
277 | $check = $this->stopforumspam_check($event['post_data']['username'], $this->user->ip, $event['post_data']['email']);
278 |
279 | if ($check)
280 | {
281 | if ($this->config['sfs_down'] && is_string($check))
282 | {
283 | return;
284 | }
285 | $error_array[] = $this->show_message($check);
286 |
287 | // now ban the spammer by IP
288 | if (is_int($check))
289 | {
290 | $this->sfsapi->sfs_ban('ip', $this->user->ip, (int) $check);
291 | }
292 | }
293 | }
294 | }
295 | $event['error'] = $error_array;
296 | }
297 |
298 | /*
299 | * update_sfs_admin_mods update admin and mods cache when adding|deleting users to|from a group
300 | * @param $event event object
301 | * @return void
302 | * @access public
303 | */
304 | public function update_sfs_admin_mods($event)
305 | {
306 | // can't determine group id by default so always run this when updating groups
307 | // apparently no way to get around this
308 | $this->cache->destroy('_sfs_adminsmods');
309 | $this->sfsgroups->build_adminsmods_cache();
310 | }
311 |
312 | /*
313 | * viewtopic_before_f_read_check() inject lang vars and grab admins and mods
314 | * @param $event event object
315 | * @return void
316 | * @access public
317 | */
318 | public function viewtopic_before_f_read_check($event)
319 | {
320 | if ($this->config['allow_sfs'])
321 | {
322 | if (!empty($this->config['sfs_api_key']))
323 | {
324 | // get mods and admins
325 | $this->sfs_admins_mods = $this->sfsgroups->getadminsmods($event['forum_id']);
326 | }
327 | }
328 | }
329 |
330 | /*
331 | * viewtopic_post_rowset_data add the posters ip into the rowset
332 | * @param $event event object
333 | * @return void
334 | * @access public
335 | */
336 | public function viewtopic_post_rowset_data($event)
337 | {
338 | $rowset = $event['rowset_data'];
339 | $row = $event['row'];
340 |
341 | $rowset['poster_ip'] = $row['poster_ip'];
342 | $rowset['user_email'] = $row['user_email'];
343 | $rowset['sfs_reported'] = $row['sfs_reported'];
344 |
345 | $event['rowset_data'] = $rowset;
346 | }
347 |
348 | /*
349 | * viewtopic_modify_post_row show a link to admins and mods to report the spammer
350 | * @param $event event object
351 | * @return void
352 | * @access public
353 | */
354 | public function viewtopic_modify_post_row($event)
355 | {
356 | if (empty($this->config['allow_sfs']) || empty($this->config['sfs_api_key']))
357 | {
358 | return;
359 | }
360 |
361 | $row = $event['row'];
362 |
363 | // ensure we have an IP and email address..this may happen if users have "post" bots on the forum
364 | // also ensure the IP is something other than 127.0.0.1 which can happen if the anonymised extension is installed
365 | if (empty($this->validate_ip($row['poster_ip'])) && filter_var($row['poster_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE))
366 | {
367 | $sfs_report_allowed = (!empty($row['user_email']) && $event['poster_id'] != ANONYMOUS && !$row['sfs_reported']) ? true : false;
368 |
369 | if ($sfs_report_allowed && in_array($this->user->data['user_id'], $this->sfs_admins_mods) && !in_array((int) $event['poster_id'], $this->sfs_admins_mods))
370 | {
371 | $reporttosfs_url = $this->helper->route('rmcgirr83_stopforumspam_core_reporttosfs', ['postid' => (int) $row['post_id'], 'posterid' => (int) $event['poster_id']]);
372 | $event['post_row'] = array_merge($event['post_row'], [
373 | 'S_SFS' => true,
374 | 'U_SFS' => $reporttosfs_url,
375 | ]);
376 | }
377 | }
378 | }
379 |
380 | /*
381 | * ucp_pm_view_message show a link to report a spammer
382 | * @param $event event object
383 | * @return bool
384 | * @access public
385 | */
386 | public function ucp_pm_view_message($event)
387 | {
388 | $user_info = $event['user_info'];
389 |
390 | $allowed = ($this->config['allow_sfs'] && $this->config['allow_pm_report'] && !empty($this->config['sfs_api_key']) && $this->config['sfs_report_pm']) ? true : false;
391 |
392 | if (!$allowed || $this->user->data['user_id'] == $user_info['user_id'])
393 | {
394 | return false;
395 | }
396 |
397 | // get mods and admins
398 | $this->sfs_admins_mods = $this->sfsgroups->getadminsmods(0);
399 |
400 | if (in_array((int) $user_info['user_id'], $this->sfs_admins_mods))
401 | {
402 | return false;
403 | }
404 |
405 | $message_row = $event['message_row'];
406 |
407 | // ensure we have an IP and email address..this may happen if users have "post" bots on the forum
408 | // also ensure the IP is something other than 127.0.0.1 which can happen if the anonymised extension is installed
409 | if (empty($this->validate_ip($user_info['author_ip'])) && filter_var($user_info['author_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE))
410 | {
411 | $sfs_report_allowed = (!empty($user_info['user_email'])) ? true : false;
412 |
413 | if ($sfs_report_allowed && !$message_row['sfs_reported'] )
414 | {
415 | $reporttosfs_url = $this->helper->route('rmcgirr83_stopforumspam_core_report_pm_to_sfs', ['postid' => (int) $message_row['msg_id'], 'posterid' => (int) $user_info['user_id']]);
416 |
417 | $event['msg_data'] = array_merge($event['msg_data'], [
418 | 'S_SFS' => true,
419 | 'U_SFS' => $reporttosfs_url,
420 | ]);
421 | }
422 | }
423 | }
424 |
425 | /*
426 | * message_admin_form_submit_before
427 | *
428 | * @param $event the event object
429 | * @return null
430 | * @access public
431 | */
432 | public function message_admin_form_submit_before($event)
433 | {
434 | if ($this->config['allow_sfs'] == false)
435 | {
436 | return false;
437 | }
438 |
439 | $errors = $event['errors'];
440 |
441 | // validate the user ip
442 | $userip_error = $this->validate_ip($this->user->ip);
443 | if ($userip_error)
444 | {
445 | $errors[] = $userip_error;
446 | }
447 |
448 | /* On registration and only when all errors have cleared
449 | * do not want the admin message area to fill up
450 | */
451 | if (!sizeof($errors))
452 | {
453 | $check = $this->stopforumspam_check($this->request->variable('name', '', true), $this->user->ip, $this->request->variable('email', ''));
454 |
455 | if ($check)
456 | {
457 | if ($this->config['sfs_down'] && $check === 'sfs_down')
458 | {
459 | return;
460 | }
461 | $errors[] = $this->show_message($check);
462 | // now ban the spammer by IP
463 | if (is_int($check) && $this->config['sfs_ban_ip'])
464 | {
465 | $this->sfsapi->sfs_ban('ip', $this->user->ip, (int) $check);
466 | }
467 | }
468 | }
469 | $event['errors'] = $errors;
470 | }
471 |
472 | /*
473 | * show_message
474 | * @param string $check the type of check we are, uhmmm, checking
475 | * @return string
476 | * @access private
477 | */
478 | private function show_message($check = '')
479 | {
480 | if ($check === 'sfs_down')
481 | {
482 | return $this->language->lang('SFS_ERROR_MESSAGE');
483 | }
484 | else
485 | {
486 | if ($this->contactadmin !== null && !empty($this->config['contactadmin_enable']))
487 | {
488 | $message = $this->language->lang('NO_SOUP_FOR_YOU', '', '');
489 | }
490 | else if ($this->config['contact_admin_form_enable'])
491 | {
492 | $link = ($this->config['email_enable']) ? append_sid("{$this->root_path}memberlist.$this->php_ext", 'mode=contactadmin') : 'mailto:' . phpbb_get_board_contact($this->config, $this->php_ext);
493 | $message = $this->language->lang('NO_SOUP_FOR_YOU', '','');
494 | }
495 | else
496 | {
497 | $message = $this->language->lang('NO_SOUP_FOR_YOU_NO_CONTACT');
498 | }
499 | return $message;
500 | }
501 | }
502 |
503 | /*
504 | * stopforumspam_check
505 | * @param string $username username from the forum inputs
506 | * @param string $ip the users ip
507 | * @param string $email email from the forum inputs
508 | * @return bool|string true if found, false if not, string if other
509 | * @access private
510 | */
511 | private function stopforumspam_check($username, $ip, $email)
512 | {
513 |
514 | $sfs_log_message = !empty($this->config['sfs_log_message']) ? $this->config['sfs_log_message'] : false;
515 |
516 | // Threshold score to reject registration and/or guest posting
517 | $sfs_threshold = !empty($this->config['sfs_threshold']) ? $this->config['sfs_threshold'] : 1;
518 |
519 | // Query the SFS database and pull the data into script
520 | $json = $this->sfsapi->sfsapi('query', $username, $ip, $email);
521 |
522 | $json_decode = json_decode($json, true);
523 |
524 | // If there is a curl error as set in sfs_api, log the error
525 | if (isset($json_decode[$this->language->lang('CURL_ERROR')]))
526 | {
527 | return 'sfs_down';
528 | }
529 |
530 | // Check if user is a spammer, but only if we successfully got the SFS data
531 | if (isset($json_decode['success']))
532 | {
533 | $username_freq = (int) $json_decode['username']['frequency'];
534 | $email_freq = (int) $json_decode['email']['frequency'];
535 | $ip_freq = (int) $json_decode['ip']['frequency'];
536 |
537 | // ACP settings in effect
538 | if ($this->config['sfs_by_name'] == false)
539 | {
540 | $username_freq = 0;
541 | }
542 |
543 | if ($this->config['sfs_by_email'] == false)
544 | {
545 | $email_freq = 0;
546 | }
547 |
548 | if ($this->config['sfs_by_ip'] == false)
549 | {
550 | $ip_freq = 0;
551 | }
552 | // Return the total score
553 | $spam_score = (int) ($username_freq + $email_freq + $ip_freq);
554 |
555 | // If we've got a spammer we'll take away their soup!
556 | if ($spam_score >= $sfs_threshold)
557 | {
558 | if ($sfs_log_message)
559 | {
560 | $this->log_message($username, $ip, 'LOG_SFS_MESSAGE', $email, $username_freq, $ip_freq, $email_freq);
561 | }
562 | //user is a spammer
563 | return $spam_score;
564 | }
565 | else
566 | {
567 | return false;
568 | }
569 | }
570 | else
571 | {
572 | if ($sfs_log_message)
573 | {
574 | if ($this->config['sfs_down'])
575 | {
576 | $this->log->add('admin', $username, $ip, 'LOG_SFS_DOWN_USER_ALLOWED', $email);
577 | }
578 | else
579 | {
580 | $this->log->add('admin', $username, $ip, 'LOG_SFS_DOWN', $email);
581 | }
582 | }
583 | return 'sfs_down';
584 | }
585 | }
586 |
587 | /*
588 | * log_message function used in this class to inject messages into the logs
589 | * @param string $username the users name
590 | * @param string $ip the users ip
591 | * @param string $message the message we are injecting
592 | * @param string $email email from the forum inputs
593 | * @return void
594 | * @access private
595 | */
596 | private function log_message($username, $ip, $message, $email, $username_score = 0, $ip_score = 0, $email_score = 0)
597 | {
598 |
599 | $sfs_ip = $this->language->lang('SFS_IP_STOPPED', $ip);
600 | $sfs_username = $this->language->lang('SFS_USERNAME_STOPPED', $username);
601 | $sfs_email = $this->language->lang('SFS_EMAIL_STOPPED', $email);
602 |
603 | if ($this->config['sfs_by_name'] == false)
604 | {
605 | $username_score = $this->language->lang('SFS_NOT_CHECKED');
606 | }
607 | else
608 | {
609 | $username_score = $this->language->lang('SFS_FREQUENCY', $username_score);
610 | }
611 |
612 | if ($this->config['sfs_by_email'] == false)
613 | {
614 | $email_score = $this->language->lang('SFS_NOT_CHECKED');
615 | }
616 | else
617 | {
618 | if ($email_score == (int) 255)
619 | {
620 | $email_score = $this->language->lang('SFS_MARKED_TOXIC');
621 | }
622 | else
623 | {
624 | $email_score = $this->language->lang('SFS_FREQUENCY', $email_score);
625 | }
626 | }
627 |
628 | if ($this->config['sfs_by_ip'] == false)
629 | {
630 | $ip_score = $this->language->lang('SFS_NOT_CHECKED');
631 | }
632 | else
633 | {
634 | $ip_score = $this->language->lang('SFS_FREQUENCY', $ip_score);
635 | }
636 | $sfs_ip .= $ip_score;
637 | $sfs_username .= $username_score;
638 | $sfs_email .= $email_score;
639 |
640 | $this->log->add('user', $this->user->data['user_id'], $ip, $message, false, ['reportee_id' => $this->user->data['user_id'], $sfs_username, $sfs_ip, $sfs_email]);
641 | }
642 |
643 | /*
644 | * validate_email function used in this class to validate a guest posters email address
645 | * @param string $email email from the forum inputs
646 | * @return string
647 | * @access private
648 | */
649 | private function validate_email($email)
650 | {
651 | $error = validate_user_email($email);
652 |
653 | return $error;
654 | }
655 |
656 | /*
657 | * validate_username function used in this class to validate a guest posters username
658 | * @param string $username username from the forum inputs
659 | * @return array
660 | * @access private
661 | */
662 | private function validate_username($username)
663 | {
664 | $error = [];
665 | if (($result = validate_username($username)) !== false)
666 | {
667 | $error[] = $this->language->lang($result . '_USERNAME');
668 | }
669 |
670 | if (($result = validate_string($username, false, $this->config['min_name_chars'], $this->config['max_name_chars'])) !== false)
671 | {
672 | $min_max_amount = ($result == 'TOO_SHORT') ? $this->config['min_name_chars'] : $this->config['max_name_chars'];
673 | $error[] = $this->language->lang('FIELD_' . $result, $min_max_amount, $this->language->lang('USERNAME'));
674 | }
675 |
676 | return $error;
677 | }
678 |
679 | /*
680 | * validate_ip function used in this class to validate an ip address
681 | * @param string $ip the users ip
682 | * @return string
683 | * @access private
684 | */
685 | private function validate_ip($ip)
686 | {
687 | $error = '';
688 |
689 | if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) === false)
690 | {
691 | $error = $this->language->lang('INVALID_IP_ADDRESS');
692 | }
693 |
694 | return $error;
695 | }
696 | }
697 |
--------------------------------------------------------------------------------