jdarwood007 commited on 2019-12-24 18:20:16
Showing 2 changed files, with 236 additions and 130 deletions.
... | ... |
@@ -123,10 +123,7 @@ class SFS |
123 | 123 |
*/ |
124 | 124 |
private function setupAdminAreas(array &$admin_areas): void |
125 | 125 |
{ |
126 |
- global $txt, $scripturl; |
|
127 |
- |
|
128 |
- // Get our language in here. |
|
129 |
- $this->loadLanguage(); |
|
126 |
+ global $scripturl; |
|
130 | 127 |
|
131 | 128 |
// Add the menu item. |
132 | 129 |
if ($this->versionCheck('2.0', 'smf')) |
... | ... |
@@ -135,10 +132,10 @@ class SFS |
135 | 132 |
$this->adminLogURL = $scripturl . '?action=admin;area=modsettings;sa=sfslog'; |
136 | 133 |
|
137 | 134 |
$admin_areas['config']['areas']['modsettings']['subsections']['sfs'] = array( |
138 |
- $txt['sfs_admin_area'] |
|
135 |
+ $this->txt('sfs_admin_area') |
|
139 | 136 |
); |
140 | 137 |
$admin_areas['config']['areas']['modsettings']['subsections']['sfslog'] = array( |
141 |
- $txt['sfs_admin_logs'] |
|
138 |
+ $this->txt('sfs_admin_logs') |
|
142 | 139 |
); |
143 | 140 |
} |
144 | 141 |
else |
... | ... |
@@ -147,10 +144,10 @@ class SFS |
147 | 144 |
$this->adminLogURL = $scripturl . '?action=admin;area=logs;sa=sfslog'; |
148 | 145 |
|
149 | 146 |
$admin_areas['config']['areas']['securitysettings']['subsections']['sfs'] = array( |
150 |
- $txt['sfs_admin_area'] |
|
147 |
+ $this->txt('sfs_admin_area') |
|
151 | 148 |
); |
152 | 149 |
$admin_areas['config']['areas']['securitysettings']['subsections']['sfslog'] = array( |
153 |
- $txt['sfs_admin_logs'] |
|
150 |
+ $this->txt('sfs_admin_logs') |
|
154 | 151 |
); |
155 | 152 |
} |
156 | 153 |
} |
... | ... |
@@ -234,10 +231,10 @@ class SFS |
234 | 231 |
*/ |
235 | 232 |
private function setupSFSConfiguration(bool $return_config = false): array |
236 | 233 |
{ |
237 |
- global $txt, $scripturl, $context, $settings, $sc, $modSettings; |
|
234 |
+ global $scripturl, $context, $settings, $sc, $modSettings; |
|
238 | 235 |
|
239 | 236 |
$config_vars = array( |
240 |
- array('title', 'sfsgentitle', 'label' => $txt['sfs_general_title']), |
|
237 |
+ array('title', 'sfsgentitle', 'label' => $this->txt('sfs_general_title')), |
|
241 | 238 |
|
242 | 239 |
array('check', 'sfs_enabled'), |
243 | 240 |
array('int', 'sfs_expire'), |
... | ... |
@@ -257,28 +254,28 @@ class SFS |
257 | 254 |
array('check', 'sfs_wildcard_ip'), |
258 | 255 |
'', |
259 | 256 |
array('select', 'sfs_tor_check', array( |
260 |
- 0 => $txt['sfs_tor_check_block'], |
|
261 |
- 1 => $txt['sfs_tor_check_ignore'], |
|
262 |
- 2 => $txt['sfs_tor_check_bad'], |
|
257 |
+ 0 => $this->txt('sfs_tor_check_block'), |
|
258 |
+ 1 => $this->txt('sfs_tor_check_ignore'), |
|
259 |
+ 2 => $this->txt('sfs_tor_check_bad'), |
|
263 | 260 |
)), |
264 | 261 |
|
265 | 262 |
'', |
266 |
- array('title', 'sfsverftitle', 'label' => $txt['sfs_verification_title']), |
|
267 |
- array('desc', 'sfsverfdesc', 'label' => $txt['sfs_verification_desc']), |
|
263 |
+ array('title', 'sfsverftitle', 'label' => $this->txt('sfs_verification_title')), |
|
264 |
+ array('desc', 'sfsverfdesc', 'label' => $this->txt('sfs_verification_desc')), |
|
268 | 265 |
array('select', 'sfs_verification_options', array( |
269 |
- 'post' => $txt['sfs_verification_options_post'], |
|
270 |
- 'report' => $txt['sfs_verification_options_report'], |
|
271 |
- 'search' => $txt['sfs_verification_options_search'], |
|
266 |
+ 'post' => $this->txt('sfs_verification_options_post'), |
|
267 |
+ 'report' => $this->txt('sfs_verification_options_report'), |
|
268 |
+ 'search' => $this->txt('sfs_verification_options_search'), |
|
272 | 269 |
), 'multiple' => true), |
273 |
- array('text', 'sfs_verification_options_extra', 'subtext' => $txt['sfs_verification_options_extra_subtext']), |
|
270 |
+ array('text', 'sfs_verification_options_extra', 'subtext' => $this->txt('sfs_verification_options_extra_subtext')), |
|
274 | 271 |
|
275 | 272 |
'', |
276 |
- array('select', 'sfs_verification_options_members', array( |
|
277 |
- 'post' => $txt['sfs_verification_options_post'], |
|
278 |
- 'search' => $txt['sfs_verification_options_search'], |
|
273 |
+ array('select', 'sfs_verOptionsMembers', array( |
|
274 |
+ 'post' => $this->txt('sfs_verification_options_post'), |
|
275 |
+ 'search' => $this->txt('sfs_verification_options_search'), |
|
279 | 276 |
), 'multiple' => true), |
280 |
- array('text', 'sfs_verification_options_membersextra', 'subtext' => $txt['sfs_verification_options_extra_subtext']), |
|
281 |
- array('int', 'sfs_verification_options_members_post_threshold'), |
|
277 |
+ array('text', 'sfs_verOptionsMemExtra', 'subtext' => $this->txt('sfs_verification_options_extra_subtext')), |
|
278 |
+ array('int', 'sfs_verfOptMemPostThreshold'), |
|
282 | 279 |
'', |
283 | 280 |
array('check', 'sfs_log_debug'), |
284 | 281 |
); |
... | ... |
@@ -333,7 +330,7 @@ class SFS |
333 | 330 |
|
334 | 331 |
// Add it to the menu as well. |
335 | 332 |
$context[$context['admin_menu_name']]['tab_data']['tabs']['sfslog'] = array( |
336 |
- 'description' => $txt['sfs_admin_logs'], |
|
333 |
+ 'description' => $this->txt('sfs_admin_logs'), |
|
337 | 334 |
); |
338 | 335 |
} |
339 | 336 |
|
... | ... |
@@ -377,7 +374,7 @@ class SFS |
377 | 374 |
*/ |
378 | 375 |
public function loadLogs(bool $return_config = false): array |
379 | 376 |
{ |
380 |
- global $context, $txt, $smcFunc, $sourcedir; |
|
377 |
+ global $context, $smcFunc, $sourcedir; |
|
381 | 378 |
|
382 | 379 |
// No Configs. |
383 | 380 |
if ($return_config) |
... | ... |
@@ -386,7 +383,7 @@ class SFS |
386 | 383 |
loadLanguage('Modlog'); |
387 | 384 |
|
388 | 385 |
$context['url_start'] = $this->adminLogURL; |
389 |
- $context['page_title'] = $txt['sfs_admin_logs']; |
|
386 |
+ $context['page_title'] = $this->txt('sfs_admin_logs'); |
|
390 | 387 |
$context['can_delete'] = allowedTo('admin_forum'); |
391 | 388 |
|
392 | 389 |
// Remove all.. |
... | ... |
@@ -415,10 +412,10 @@ class SFS |
415 | 412 |
|
416 | 413 |
$listOptions = array( |
417 | 414 |
'id' => 'sfslog_list', |
418 |
- 'title' => $txt['sfs_admin_logs'], |
|
415 |
+ 'title' => $this->txt('sfs_admin_logs'), |
|
419 | 416 |
'width' => '100%', |
420 | 417 |
'items_per_page' => '50', |
421 |
- 'no_items_label' => $txt['sfs_log_no_entries_found'], |
|
418 |
+ 'no_items_label' => $this->txt('sfs_log_no_entries_found'), |
|
422 | 419 |
'base_href' => $context['url_start'] . (!empty($context['search_params']) ? ';params=' . $context['search_params'] : ''), |
423 | 420 |
'default_sort_col' => 'time', |
424 | 421 |
'get_items' => array( |
... | ... |
@@ -439,7 +436,7 @@ class SFS |
439 | 436 |
'columns' => array( |
440 | 437 |
'type' => array( |
441 | 438 |
'header' => array( |
442 |
- 'value' => $txt['sfs_log_header_type'], |
|
439 |
+ 'value' => $this->txt('sfs_log_header_type'), |
|
443 | 440 |
'class' => 'lefttext', |
444 | 441 |
), |
445 | 442 |
'data' => array( |
... | ... |
@@ -451,7 +448,7 @@ class SFS |
451 | 448 |
), |
452 | 449 |
'time' => array( |
453 | 450 |
'header' => array( |
454 |
- 'value' => $txt['sfs_log_header_time'], |
|
451 |
+ 'value' => $this->txt('sfs_log_header_time'), |
|
455 | 452 |
'class' => 'lefttext', |
456 | 453 |
), |
457 | 454 |
'data' => array( |
... | ... |
@@ -465,7 +462,7 @@ class SFS |
465 | 462 |
), |
466 | 463 |
'url' => array( |
467 | 464 |
'header' => array( |
468 |
- 'value' => $txt['sfs_log_header_url'], |
|
465 |
+ 'value' => $this->txt('sfs_log_header_url'), |
|
469 | 466 |
'class' => 'lefttext', |
470 | 467 |
), |
471 | 468 |
'data' => array( |
... | ... |
@@ -480,7 +477,7 @@ class SFS |
480 | 477 |
), |
481 | 478 |
'member' => array( |
482 | 479 |
'header' => array( |
483 |
- 'value' => $txt['sfs_log_header_member'], |
|
480 |
+ 'value' => $this->txt('sfs_log_header_member'), |
|
484 | 481 |
'class' => 'lefttext', |
485 | 482 |
), |
486 | 483 |
'data' => array( |
... | ... |
@@ -494,7 +491,7 @@ class SFS |
494 | 491 |
), |
495 | 492 |
'username' => array( |
496 | 493 |
'header' => array( |
497 |
- 'value' => $txt['sfs_log_header_username'], |
|
494 |
+ 'value' => $this->txt('sfs_log_header_username'), |
|
498 | 495 |
'class' => 'lefttext', |
499 | 496 |
), |
500 | 497 |
'data' => array( |
... | ... |
@@ -508,7 +505,7 @@ class SFS |
508 | 505 |
), |
509 | 506 |
'email' => array( |
510 | 507 |
'header' => array( |
511 |
- 'value' => $txt['sfs_log_header_email'], |
|
508 |
+ 'value' => $this->txt('sfs_log_header_email'), |
|
512 | 509 |
'class' => 'lefttext', |
513 | 510 |
), |
514 | 511 |
'data' => array( |
... | ... |
@@ -522,7 +519,7 @@ class SFS |
522 | 519 |
), |
523 | 520 |
'ip' => array( |
524 | 521 |
'header' => array( |
525 |
- 'value' => $txt['sfs_log_header_ip'], |
|
522 |
+ 'value' => $this->txt('sfs_log_header_ip'), |
|
526 | 523 |
'class' => 'lefttext', |
527 | 524 |
), |
528 | 525 |
'data' => array( |
... | ... |
@@ -536,7 +533,7 @@ class SFS |
536 | 533 |
), |
537 | 534 |
'ip2' => array( |
538 | 535 |
'header' => array( |
539 |
- 'value' => $txt['sfs_log_header_ip2'], |
|
536 |
+ 'value' => $this->txt('sfs_log_header_ip2'), |
|
540 | 537 |
'class' => 'lefttext', |
541 | 538 |
), |
542 | 539 |
'data' => array( |
... | ... |
@@ -550,7 +547,7 @@ class SFS |
550 | 547 |
), |
551 | 548 |
'checks' => array( |
552 | 549 |
'header' => array( |
553 |
- 'value' => $txt['sfs_log_checks'], |
|
550 |
+ 'value' => $this->txt('sfs_log_checks'), |
|
554 | 551 |
'class' => 'lefttext', |
555 | 552 |
), |
556 | 553 |
'data' => array( |
... | ... |
@@ -562,7 +559,7 @@ class SFS |
562 | 559 |
), |
563 | 560 |
'result' => array( |
564 | 561 |
'header' => array( |
565 |
- 'value' => $txt['sfs_log_result'], |
|
562 |
+ 'value' => $this->txt('sfs_log_result'), |
|
566 | 563 |
'class' => 'lefttext', |
567 | 564 |
), |
568 | 565 |
'data' => array( |
... | ... |
@@ -577,7 +574,8 @@ class SFS |
577 | 574 |
'value' => '<input type="checkbox" name="all" class="input_check" onclick="invertAll(this, this.form);" />', |
578 | 575 |
), |
579 | 576 |
'data' => array( |
580 |
- 'function' => function($entry) { |
|
577 |
+ 'function' => function($entry) |
|
578 |
+ { |
|
581 | 579 |
return '<input type="checkbox" class="input_check" name="delete[]" value="' . $entry['id'] . '"' . ($entry['editable'] ? '' : ' disabled="disabled"') . ' />'; |
582 | 580 |
}, |
583 | 581 |
'style' => 'text-align: center;', |
... | ... |
@@ -597,11 +595,11 @@ class SFS |
597 | 595 |
array( |
598 | 596 |
'position' => 'below_table_data', |
599 | 597 |
'value' => ' |
600 |
- ' . $txt['sfs_log_search'] . ' (' . $context['search']['label'] . '): |
|
601 |
- <input type="text" name="search" size="18" value="' . $smcFunc['htmlspecialchars']($context['search']['string']) . '" class="input_text" /> <input type="submit" name="is_search" value="' . $txt['modlog_go'] . '" class="button_submit" /> |
|
598 |
+ ' . $this->txt('sfs_log_search') . ' (' . $context['search']['label'] . '): |
|
599 |
+ <input type="text" name="search" size="18" value="' . $smcFunc['htmlspecialchars']($context['search']['string']) . '" class="input_text" /> <input type="submit" name="is_search" value="' . $this->txt('modlog_go') . '" class="button_submit" /> |
|
602 | 600 |
' . ($context['can_delete'] ? ' | |
603 |
- <input type="submit" name="remove" value="' . $txt['modlog_remove'] . '" class="button_submit" /> |
|
604 |
- <input type="submit" name="removeall" value="' . $txt['modlog_removeall'] . '" class="button_submit" />' : ''), |
|
601 |
+ <input type="submit" name="remove" value="' . $this->txt('modlog_remove') . '" class="button_submit" /> |
|
602 |
+ <input type="submit" name="removeall" value="' . $this->txt('modlog_removeall') . '" class="button_submit" />' : ''), |
|
605 | 603 |
), |
606 | 604 |
), |
607 | 605 |
); |
... | ... |
@@ -635,7 +633,7 @@ class SFS |
635 | 633 |
*/ |
636 | 634 |
public function getSFSLogEntries(int $start, int $items_per_page, string $sort, string $query_string = '', array $query_params = array()): array |
637 | 635 |
{ |
638 |
- global $context, $smcFunc, $txt; |
|
636 |
+ global $context, $smcFunc; |
|
639 | 637 |
|
640 | 638 |
// Fetch all of our logs. |
641 | 639 |
$result = $smcFunc['db_query']('', ' |
... | ... |
@@ -671,11 +669,11 @@ class SFS |
671 | 669 |
{ |
672 | 670 |
$entries[$row['id_sfs']] = array( |
673 | 671 |
'id' => $row['id_sfs'], |
674 |
- 'type' => $txt['sfs_log_types_' . $row['id_type']], |
|
672 |
+ 'type' => $this->txt('sfs_log_types_' . $row['id_type']), |
|
675 | 673 |
'time' => timeformat($row['log_time']), |
676 | 674 |
'url' => preg_replace('~http(s)?://~i', 'hxxp\\1://', $row['url']), |
677 | 675 |
'timestamp' => forum_time(true, $row['log_time']), |
678 |
- 'member_link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>' : (empty($row['real_name']) ? ($txt['guest'] . (!empty($row['extra']['member_acted']) ? ' (' . $row['extra']['member_acted'] . ')' : '')) : $row['real_name']), |
|
676 |
+ 'member_link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>' : (empty($row['real_name']) ? ($this->txt('guest') . (!empty($row['extra']['member_acted']) ? ' (' . $row['extra']['member_acted'] . ')' : '')) : $row['real_name']), |
|
679 | 677 |
'username' => $row['username'], |
680 | 678 |
'email' => $row['email'], |
681 | 679 |
'ip' => '<a href="' . sprintf($this->urlSFSipCheck, $row['ip']) . '">' . $row['ip'] . '</a>', |
... | ... |
@@ -708,13 +706,13 @@ class SFS |
708 | 706 |
if (strpos($row['result'], ',') !== false) |
709 | 707 |
{ |
710 | 708 |
list($resultType, $resultMatch, $extra) = explode(',', $row['result'] . ',,,'); |
711 |
- $entries[$row['id_sfs']]['result'] = sprintf($txt['sfs_log_matched_on'], $resultType, $resultMatch); |
|
709 |
+ $entries[$row['id_sfs']]['result'] = sprintf($this->txt('sfs_log_matched_on'), $resultType, $resultMatch); |
|
712 | 710 |
|
713 | 711 |
// If this was a IP ban, note it. |
714 | 712 |
if ($resultType == 'ip' && !empty($extra)) |
715 |
- $entries[$row['id_sfs']]['result'] .= ' ' . $txt['sfs_log_auto_banned']; |
|
713 |
+ $entries[$row['id_sfs']]['result'] .= ' ' . $this->txt('sfs_log_auto_banned'); |
|
716 | 714 |
if ($resultType == 'username' && !empty($extra)) |
717 |
- $entries[$row['id_sfs']]['result'] .= ' ' . sprintf($txt['sfs_log_confidence'], $extra); |
|
715 |
+ $entries[$row['id_sfs']]['result'] .= ' ' . sprintf($this->txt('sfs_log_confidence'), $extra); |
|
718 | 716 |
} |
719 | 717 |
else |
720 | 718 |
$entries[$row['id_sfs']]['result'] = $row['result']; |
... | ... |
@@ -860,9 +858,6 @@ class SFS |
860 | 858 |
if ($regOptions['interface'] == 'admin') |
861 | 859 |
return true; |
862 | 860 |
|
863 |
- // Get our language in here. |
|
864 |
- $this->loadLanguage(); |
|
865 |
- |
|
866 | 861 |
// Pass everything and let us handle what options we pass on. We pass the register_vars as these are what we have cleaned up. |
867 | 862 |
return $this->sfsCheck(array( |
868 | 863 |
array('username' => $regOptions['register_vars']['member_name']), |
... | ... |
@@ -909,15 +904,12 @@ class SFS |
909 | 904 |
*/ |
910 | 905 |
public function checkVerificationTest(array $thisVerification, array &$verification_errors): bool |
911 | 906 |
{ |
912 |
- global $user_info; |
|
907 |
+ global $user_info, $modSettings; |
|
913 | 908 |
|
914 | 909 |
// Registration is skipped as we process that differently. |
915 | 910 |
if ($thisVerification['id'] == 'register') |
916 | 911 |
return true; |
917 | 912 |
|
918 |
- // Get our language in here. |
|
919 |
- $this->loadLanguage(); |
|
920 |
- |
|
921 | 913 |
// Get our options data. |
922 | 914 |
$options = $this->getVerificationOptions(); |
923 | 915 |
|
... | ... |
@@ -939,7 +931,7 @@ class SFS |
939 | 931 |
|
940 | 932 |
} |
941 | 933 |
// Members and they don't have enough posts? |
942 |
- elseif (empty($user_info['posts']) || $user_info['posts'] < $modSettings['sfs_verification_options_members_post_threshold']) |
|
934 |
+ elseif (empty($user_info['posts']) || $user_info['posts'] < $modSettings['sfs_verfOptMemPostThreshold']) |
|
943 | 935 |
return $this->sfsCheck(array( |
944 | 936 |
array('username' => $user_info['username']), |
945 | 937 |
array('email' => $user_info['email']), |
... | ... |
@@ -961,7 +953,7 @@ class SFS |
961 | 953 |
), 'post'); |
962 | 954 |
} |
963 | 955 |
// We should avoid this on searches, as we can only send ips. |
964 |
- elseif ($thisVerification['id'] == 'search' && in_array('search', $options) && ($user_info['is_guest'] || empty($user_info['posts']) || $user_info['posts'] < $modSettings['sfs_verification_options_members_post_threshold'])) |
|
956 |
+ elseif ($thisVerification['id'] == 'search' && in_array('search', $options) && ($user_info['is_guest'] || empty($user_info['posts']) || $user_info['posts'] < $modSettings['sfs_verfOptMemPostThreshold'])) |
|
965 | 957 |
{ |
966 | 958 |
return $this->sfsCheck(array( |
967 | 959 |
array('ip' => $user_info['ip']), |
... | ... |
@@ -1020,46 +1012,64 @@ class SFS |
1020 | 1012 |
*/ |
1021 | 1013 |
private function sfsCheck(array $checks, string $area = null): bool |
1022 | 1014 |
{ |
1023 |
- global $sourcedir, $smcFunc, $context, $modSettings, $txt; |
|
1015 |
+ global $smcFunc, $context, $modSettings; |
|
1024 | 1016 |
|
1025 | 1017 |
$requestURL = $this->buildServerURL(); |
1026 | 1018 |
|
1027 | 1019 |
// Lets build our data set, always send it as a bulk. |
1028 |
- $singleCheckFound = false; |
|
1029 |
- foreach ($checks as $chk) |
|
1030 |
- { |
|
1031 |
- foreach ($chk as $type => $value) |
|
1032 |
- { |
|
1033 |
- // Hold up, we are not processing this check. |
|
1034 |
- if ( |
|
1035 |
- ($type == 'email' && empty($modSettings['sfs_emailcheck'])) || |
|
1036 |
- ($type == 'username' && empty($modSettings['sfs_usernamecheck'])) || |
|
1037 |
- ($type == 'ip' && empty($modSettings['sfs_ipcheck'])) |
|
1038 |
- ) |
|
1039 |
- continue; |
|
1040 |
- |
|
1041 |
- // No value? Can't do this. |
|
1042 |
- if (empty($value)) |
|
1043 |
- continue; |
|
1044 |
- |
|
1045 |
- // Emails and usernames must be UTF-8, Only a issue with SMF 2.0. |
|
1046 |
- if (!$context['utf8'] && ($type == 'email' || $type == 'username')) |
|
1047 |
- $requestURL .= '&' . $type . '[]=' . iconv($context['character_set'], 'UTF-8//IGNORE', $value); |
|
1048 |
- else |
|
1049 |
- $requestURL .= '&' . $type . '[]=' . urlencode($value); |
|
1050 |
- |
|
1051 |
- $singleCheckFound = true; |
|
1052 |
- } |
|
1053 |
- } |
|
1020 |
+ $singleCheckFound = $this->buildCheckPath($requestURL, $checks, $area); |
|
1054 | 1021 |
|
1055 | 1022 |
// No checks found? Can't do this. |
1056 | 1023 |
if (empty($singleCheckFound)) |
1057 | 1024 |
{ |
1058 | 1025 |
$this->logAllStats('error', $checks, 'error'); |
1059 |
- log_error($txt['sfs_request_failure_nodata'] . ':' . $requestURL, 'critical'); |
|
1026 |
+ log_error($this->txt('sfs_request_failure_nodata') . ':' . $requestURL, 'critical'); |
|
1060 | 1027 |
return true; |
1061 | 1028 |
} |
1062 | 1029 |
|
1030 |
+ // Send it off. |
|
1031 |
+ $resonse = $this->sendSFSCheck($requestURL); |
|
1032 |
+ $requestBlocked = ''; |
|
1033 |
+ |
|
1034 |
+ // Handle IPs only if we are supposed to, this is just a double check. |
|
1035 |
+ if (!empty($modSettings['sfs_ipcheck']) && !empty($response['ip'])) |
|
1036 |
+ $requestBlocked = $this->sfsCheck_ips($response['ip']); |
|
1037 |
+ |
|
1038 |
+ // If we didn't match a IP, handle Usernames only if we are supposed to, this is just a double check. |
|
1039 |
+ if (empty($requestBlocked) && !empty($modSettings['sfs_usernamecheck']) && !empty($response['username'])) |
|
1040 |
+ $requestBlocked = $this->sfsCheck_username($response['username']); |
|
1041 |
+ |
|
1042 |
+ // If we didn't match a IP or username, handle Emails only if we are supposed to, this is just a double check. |
|
1043 |
+ if (empty($requestBlocked) && !empty($modSettings['sfs_emailcheck']) && !empty($response['email'])) |
|
1044 |
+ $requestBlocked = $this->sfsCheck_email($response['email']); |
|
1045 |
+ |
|
1046 |
+ // Log all the stats? Debug mode here. |
|
1047 |
+ if (!empty($modSettings['sfs_log_debug'])) |
|
1048 |
+ $this->logAllStats('all', $checks, $requestBlocked); |
|
1049 |
+ |
|
1050 |
+ // At this point, we have checked everything, do what needs to be done for our good person. |
|
1051 |
+ if (empty($requestBlocked)) |
|
1052 |
+ return true; |
|
1053 |
+ |
|
1054 |
+ // You are a bad spammer, don't tell them what was blocked. |
|
1055 |
+ fatal_error($this->txt('sfs_request_blocked')); |
|
1056 |
+ } |
|
1057 |
+ |
|
1058 |
+ /** |
|
1059 |
+ * Send off the request to SFS and receive a response back |
|
1060 |
+ * |
|
1061 |
+ * @param string $requestURL The requested URL to send to SFS |
|
1062 |
+ * @in |
|
1063 |
+ * @internal |
|
1064 |
+ * @CalledIn SMF 2.0, SMF 2.1 |
|
1065 |
+ * @version 1.1 |
|
1066 |
+ * @since 1.1 |
|
1067 |
+ * @return array data we received back, could be a empty array. |
|
1068 |
+ */ |
|
1069 |
+ private function sendSFSCheck(string $requestURL): array |
|
1070 |
+ { |
|
1071 |
+ global $sourcedir; |
|
1072 |
+ |
|
1063 | 1073 |
// SMF 2.0 has the fetch_web_data in the Subs-Packages, 2.1 it is in Subs.php. |
1064 | 1074 |
if ($this->versionCheck('2.0', 'smf')) |
1065 | 1075 |
require_once($sourcedir . '/Subs-Package.php'); |
... | ... |
@@ -1069,7 +1079,7 @@ class SFS |
1069 | 1079 |
if ($result === false) |
1070 | 1080 |
{ |
1071 | 1081 |
$this->logAllStats('error', $checks, 'failure'); |
1072 |
- log_error($txt['sfs_request_failure'] . ':' . $requestURL, 'critical'); |
|
1082 |
+ log_error($this->txt('sfs_request_failure') . ':' . $requestURL, 'critical'); |
|
1073 | 1083 |
return true; |
1074 | 1084 |
} |
1075 | 1085 |
|
... | ... |
@@ -1079,16 +1089,29 @@ class SFS |
1079 | 1089 |
if (empty($response)) |
1080 | 1090 |
{ |
1081 | 1091 |
$this->logAllStats('error', $checks, 'failure'); |
1082 |
- log_error($txt['sfs_request_failure'] . ':' . $requestURL, 'critical'); |
|
1092 |
+ log_error($this->txt('sfs_request_failure') . ':' . $requestURL, 'critical'); |
|
1083 | 1093 |
return true; |
1084 | 1094 |
} |
1085 | 1095 |
|
1086 |
- $requestBlocked = ''; |
|
1096 |
+ return $response; |
|
1097 |
+ } |
|
1087 | 1098 |
|
1088 |
- // Handle IPs only if we are supposed to, this is just a double check. |
|
1089 |
- if (!empty($modSettings['sfs_ipcheck']) && !empty($response['ip'])) |
|
1099 |
+ /** |
|
1100 |
+ * Run checks for IPs |
|
1101 |
+ * |
|
1102 |
+ * @param array $ips All the IPs we are checking. |
|
1103 |
+ * @internal |
|
1104 |
+ * @CalledIn SMF 2.0, SMF 2.1 |
|
1105 |
+ * @version 1.1 |
|
1106 |
+ * @since 1.1 |
|
1107 |
+ * @return string Request Blocked data if any |
|
1108 |
+ */ |
|
1109 |
+ private function sfsCheck_ips(array $ips): string |
|
1090 | 1110 |
{ |
1091 |
- foreach ($response['ip'] as $check) |
|
1111 |
+ global $modSettings, $smcFunc; |
|
1112 |
+ |
|
1113 |
+ $requestBlocked = ''; |
|
1114 |
+ foreach ($ips as $check) |
|
1092 | 1115 |
{ |
1093 | 1116 |
// They appeared! Block this. |
1094 | 1117 |
if (!empty($check['appears'])) |
... | ... |
@@ -1103,12 +1126,26 @@ class SFS |
1103 | 1126 |
break; |
1104 | 1127 |
} |
1105 | 1128 |
} |
1129 |
+ |
|
1130 |
+ return $requestBlocked; |
|
1106 | 1131 |
} |
1107 | 1132 |
|
1108 |
- // If we didn't match a IP, handle Usernames only if we are supposed to, this is just a double check. |
|
1109 |
- if (empty($requestBlocked) && !empty($modSettings['sfs_usernamecheck']) && !empty($response['username'])) |
|
1133 |
+ /** |
|
1134 |
+ * Run checks for Usernames |
|
1135 |
+ * |
|
1136 |
+ * @params array $usernames All the usernames we are checking. |
|
1137 |
+ * @internal |
|
1138 |
+ * @CalledIn SMF 2.0, SMF 2.1 |
|
1139 |
+ * @version 1.1 |
|
1140 |
+ * @since 1.1 |
|
1141 |
+ * @return string Request Blocked data if any |
|
1142 |
+ */ |
|
1143 |
+ private function sfsCheck_username(array $usernames): string |
|
1110 | 1144 |
{ |
1111 |
- foreach ($response['username'] as $check) |
|
1145 |
+ global $modSettings, $smcFunc; |
|
1146 |
+ |
|
1147 |
+ $requestBlocked = ''; |
|
1148 |
+ foreach ($usernames as $check) |
|
1112 | 1149 |
{ |
1113 | 1150 |
// Combine with $area we could also require admin approval above thresholds on things like register. |
1114 | 1151 |
if (!empty($check['appears'])) |
... | ... |
@@ -1138,12 +1175,26 @@ class SFS |
1138 | 1175 |
} |
1139 | 1176 |
} |
1140 | 1177 |
} |
1178 |
+ |
|
1179 |
+ return $requestBlocked; |
|
1141 | 1180 |
} |
1142 | 1181 |
|
1143 |
- // If we didn't match a IP or username, handle Emails only if we are supposed to, this is just a double check. |
|
1144 |
- if (empty($requestBlocked) && !empty($modSettings['sfs_emailcheck']) && !empty($response['email'])) |
|
1182 |
+ /** |
|
1183 |
+ * Run checks for Email |
|
1184 |
+ * |
|
1185 |
+ * @params array $email All the email we are checking. |
|
1186 |
+ * @internal |
|
1187 |
+ * @CalledIn SMF 2.0, SMF 2.1 |
|
1188 |
+ * @version 1.1 |
|
1189 |
+ * @since 1.1 |
|
1190 |
+ * @return string Request Blocked data if any |
|
1191 |
+ */ |
|
1192 |
+ private function sfsCheck_email(array $email): string |
|
1145 | 1193 |
{ |
1146 |
- foreach ($response['email'] as $check) |
|
1194 |
+ global $modSettings, $smcFunc; |
|
1195 |
+ |
|
1196 |
+ $requestBlocked = ''; |
|
1197 |
+ foreach ($email as $check) |
|
1147 | 1198 |
{ |
1148 | 1199 |
if (!empty($check['appears'])) |
1149 | 1200 |
{ |
... | ... |
@@ -1152,20 +1203,55 @@ class SFS |
1152 | 1203 |
break; |
1153 | 1204 |
} |
1154 | 1205 |
} |
1206 |
+ |
|
1207 |
+ return $requestBlocked; |
|
1155 | 1208 |
} |
1156 | 1209 |
|
1210 |
+ /** |
|
1211 |
+ * Run checks against the SFS database. |
|
1212 |
+ * |
|
1213 |
+ * @param string $requestURL The initial url we will send. |
|
1214 |
+ * @param array $checks All the possible checks we would like to preform. |
|
1215 |
+ * @param string $area The area this is coming from. |
|
1216 |
+ * |
|
1217 |
+ * @internal |
|
1218 |
+ * @CalledIn SMF 2.0, SMF 2.1 |
|
1219 |
+ * @version 1.0 |
|
1220 |
+ * @since 1.0 |
|
1221 |
+ * @return bool True we found something to check, false nothing.. $requestURL will be updated with the new data. |
|
1222 |
+ */ |
|
1223 |
+ private function buildCheckPath(string &$requestURL, array $checks, string $area = null): bool |
|
1224 |
+ { |
|
1225 |
+ global $context, $modSettings; |
|
1157 | 1226 |
|
1158 |
- // Log all the stats? Debug mode here. |
|
1159 |
- if (!empty($modSettings['sfs_log_debug'])) |
|
1160 |
- $this->logAllStats('all', $checks, $requestBlocked); |
|
1227 |
+ $singleCheckFound = false; |
|
1228 |
+ foreach ($checks as $chk) |
|
1229 |
+ { |
|
1230 |
+ foreach ($chk as $type => $value) |
|
1231 |
+ { |
|
1232 |
+ // Hold up, we are not processing this check. |
|
1233 |
+ if ( |
|
1234 |
+ ($type == 'email' && empty($modSettings['sfs_emailcheck'])) || |
|
1235 |
+ ($type == 'username' && empty($modSettings['sfs_usernamecheck'])) || |
|
1236 |
+ ($type == 'ip' && empty($modSettings['sfs_ipcheck'])) |
|
1237 |
+ ) |
|
1238 |
+ continue; |
|
1161 | 1239 |
|
1162 |
- // At this point, we have checked everything, do what needs to be done for our good person. |
|
1163 |
- if (empty($requestBlocked)) |
|
1164 |
- return true; |
|
1240 |
+ // No value? Can't do this. |
|
1241 |
+ if (empty($value)) |
|
1242 |
+ continue; |
|
1165 | 1243 |
|
1166 |
- // You are a bad spammer, don't tell them what was blocked. |
|
1167 |
- $this->loadLanguage(); |
|
1168 |
- fatal_error($txt['sfs_request_blocked']); |
|
1244 |
+ // Emails and usernames must be UTF-8, Only a issue with SMF 2.0. |
|
1245 |
+ if (!$context['utf8'] && ($type == 'email' || $type == 'username')) |
|
1246 |
+ $requestURL .= '&' . $type . '[]=' . iconv($context['character_set'], 'UTF-8//IGNORE', $value); |
|
1247 |
+ else |
|
1248 |
+ $requestURL .= '&' . $type . '[]=' . urlencode($value); |
|
1249 |
+ |
|
1250 |
+ $singleCheckFound = true; |
|
1251 |
+ } |
|
1252 |
+ } |
|
1253 |
+ |
|
1254 |
+ return $singleCheckFound; |
|
1169 | 1255 |
} |
1170 | 1256 |
|
1171 | 1257 |
/** |
... | ... |
@@ -1382,23 +1468,21 @@ class SFS |
1382 | 1468 |
*/ |
1383 | 1469 |
private function sfsServerMapping($returnType = null) |
1384 | 1470 |
{ |
1385 |
- global $txt; |
|
1386 |
- |
|
1387 | 1471 |
// Global list of servers. |
1388 | 1472 |
$serverList = array( |
1389 | 1473 |
0 => array( |
1390 | 1474 |
'region' => 'global', |
1391 |
- 'label' => $txt['sfs_region_global'], |
|
1475 |
+ 'label' => $this->txt('sfs_region_global'), |
|
1392 | 1476 |
'host' => 'api.stopforumspam.org', |
1393 | 1477 |
), |
1394 | 1478 |
1 => array( |
1395 | 1479 |
'region' => 'us', |
1396 |
- 'label' => $txt['sfs_region_us'], |
|
1480 |
+ 'label' => $this->txt('sfs_region_us'), |
|
1397 | 1481 |
'host' => 'us.stopforumspam.org', |
1398 | 1482 |
), |
1399 | 1483 |
2 => array( |
1400 | 1484 |
'region' => 'eu', |
1401 |
- 'label' => $txt['sfs_region_eu'], |
|
1485 |
+ 'label' => $this->txt('sfs_region_eu'), |
|
1402 | 1486 |
'host' => 'eruope.stopforumspam.org', |
1403 | 1487 |
), |
1404 | 1488 |
); |
... | ... |
@@ -1428,8 +1512,8 @@ class SFS |
1428 | 1512 |
{ |
1429 | 1513 |
global $user_info, $modSettings; |
1430 | 1514 |
|
1431 |
- $optionsKey = $user_info['is_guest'] ? 'sfs_verification_options' : 'sfs_verification_options_members'; |
|
1432 |
- $optionsKeyExtra = $user_info['is_guest'] ? 'sfs_verification_options_extra' : 'sfs_verification_options_membersextra'; |
|
1515 |
+ $optionsKey = $user_info['is_guest'] ? 'sfs_verification_options' : 'sfs_verOptionsMembers'; |
|
1516 |
+ $optionsKeyExtra = $user_info['is_guest'] ? 'sfs_verification_options_extra' : 'sfs_verOptionsMemExtra'; |
|
1433 | 1517 |
|
1434 | 1518 |
// Standard options. |
1435 | 1519 |
if ($this->versionCheck('2.0', 'smf') && !empty($modSettings[$optionsKey])) |
... | ... |
@@ -1444,10 +1528,8 @@ class SFS |
1444 | 1528 |
{ |
1445 | 1529 |
$this->extraVerificationOptions = explode(',', $modSettings[$optionsKeyExtra]); |
1446 | 1530 |
|
1447 |
- if (is_array($options)) |
|
1531 |
+ if (is_array($options) && !empty($this->extraVerificationOptions)) |
|
1448 | 1532 |
$options = array_merge($options, $this->extraVerificationOptions); |
1449 |
- else |
|
1450 |
- $options = $this->extraVerificationOptions; |
|
1451 | 1533 |
} |
1452 | 1534 |
|
1453 | 1535 |
return $options; |
... | ... |
@@ -1476,7 +1558,7 @@ class SFS |
1476 | 1558 |
'sfs_emailcheck' => 1, |
1477 | 1559 |
'sfs_username_confidence' => 50.01, |
1478 | 1560 |
'sfs_region' => 0, |
1479 |
- 'sfs_verification_options_members_post_threshold' => 5, |
|
1561 |
+ 'sfs_verfOptMemPostThreshold' => 5 |
|
1480 | 1562 |
); |
1481 | 1563 |
|
1482 | 1564 |
// SMF 2.0 is serialized, SMF 2.1 is json. |
... | ... |
@@ -1562,6 +1644,30 @@ class SFS |
1562 | 1644 |
loadLanguage('StopForumSpam'); |
1563 | 1645 |
} |
1564 | 1646 |
|
1647 |
+ /** |
|
1648 |
+ * A global function for loading $txt strings. |
|
1649 |
+ * |
|
1650 |
+ * @param $key The Text Key |
|
1651 |
+ * @internal |
|
1652 |
+ * @CalledIn SMF 2.0, SMF 2.1 |
|
1653 |
+ * @version 1.1 |
|
1654 |
+ * @since 1.1 |
|
1655 |
+ * @return string The text string. |
|
1656 |
+ */ |
|
1657 |
+ public function txt($key): string |
|
1658 |
+ { |
|
1659 |
+ global $txt; |
|
1660 |
+ |
|
1661 |
+ // Load the language if its not here already. |
|
1662 |
+ if (!isset($txt[$key])) |
|
1663 |
+ $this->loadLanguage(); |
|
1664 |
+ |
|
1665 |
+ if (!isset($txt[$key])) |
|
1666 |
+ return ''; |
|
1667 |
+ |
|
1668 |
+ return $txt[$key]; |
|
1669 |
+ } |
|
1670 |
+ |
|
1565 | 1671 |
/** |
1566 | 1672 |
* Handle searching for logs. |
1567 | 1673 |
* |
... | ... |
@@ -1584,12 +1690,12 @@ class SFS |
1584 | 1690 |
|
1585 | 1691 |
// What we can search. |
1586 | 1692 |
$searchTypes = array( |
1587 |
- 'url' => array('sql' => 'l.url', 'label' => $txt['sfs_log_search_url']), |
|
1588 |
- 'member' => array('sql' => 'mem.real_name', 'label' => $txt['sfs_log_search_member']), |
|
1589 |
- 'username' => array('sql' => 'l.username', 'label' => $txt['sfs_log_search_username']), |
|
1590 |
- 'email' => array('sql' => 'l.email', 'label' => $txt['sfs_log_search_email']), |
|
1591 |
- 'ip' => array('sql' => 'lm.ip', 'label' => $txt['sfs_log_search_ip']), |
|
1592 |
- 'ip2' => array('sql' => 'lm.ip2', 'label' => $txt['sfs_log_search_ip2']) |
|
1693 |
+ 'url' => array('sql' => 'l.url', 'label' => $this->txt('sfs_log_search_url')), |
|
1694 |
+ 'member' => array('sql' => 'mem.real_name', 'label' => $this->txt('sfs_log_search_member')), |
|
1695 |
+ 'username' => array('sql' => 'l.username', 'label' => $this->txt('sfs_log_search_username')), |
|
1696 |
+ 'email' => array('sql' => 'l.email', 'label' => $this->txt('sfs_log_search_email')), |
|
1697 |
+ 'ip' => array('sql' => 'lm.ip', 'label' => $this->txt('sfs_log_search_ip')), |
|
1698 |
+ 'ip2' => array('sql' => 'lm.ip2', 'label' => $this->txt('sfs_log_search_ip2')) |
|
1593 | 1699 |
); |
1594 | 1700 |
|
1595 | 1701 |
// What we want to search for. |
... | ... |
@@ -1643,7 +1749,7 @@ class SFS |
1643 | 1749 |
WHERE name = {string:new_ban_name} |
1644 | 1750 |
LIMIT 1', |
1645 | 1751 |
array( |
1646 |
- 'new_ban_name' => substr($txt['sfs_ban_group_name'], 0, 20), |
|
1752 |
+ 'new_ban_name' => substr($this->txt('sfs_ban_group_name'), 0, 20), |
|
1647 | 1753 |
) |
1648 | 1754 |
); |
1649 | 1755 |
if ($smcFunc['db_num_rows']($request) == 1) |
... | ... |
@@ -1663,7 +1769,7 @@ class SFS |
1663 | 1769 |
|
1664 | 1770 |
// Ban Information, this follows the format from the function. |
1665 | 1771 |
$ban_info = array( |
1666 |
- 'name' => substr($txt['sfs_ban_group_name'], 0, 20), |
|
1772 |
+ 'name' => substr($this->txt('sfs_ban_group_name'), 0, 20), |
|
1667 | 1773 |
'cannot' => array( |
1668 | 1774 |
'access' => 1, |
1669 | 1775 |
'register' => 1, |
... | ... |
@@ -1671,8 +1777,8 @@ class SFS |
1671 | 1777 |
'login' => 1, |
1672 | 1778 |
), |
1673 | 1779 |
'db_expiration' => 'NULL', |
1674 |
- 'reason' => $txt['sfs_ban_group_reason'], |
|
1675 |
- 'notes' => $txt['sfs_ban_group_notes'] |
|
1780 |
+ 'reason' => $this->txt('sfs_ban_group_reason'), |
|
1781 |
+ 'notes' => $this->txt('sfs_ban_group_notes') |
|
1676 | 1782 |
); |
1677 | 1783 |
|
1678 | 1784 |
// If we can shortcut this.. |
... | ... |
@@ -17,7 +17,7 @@ |
17 | 17 |
if ($do_test) |
18 | 18 |
{ |
19 | 19 |
// Check against SFS |
20 |
- if (is_callable($smcFunc['classSFS'], 'checkRegisterPost')) |
|
20 |
+ if (!empty($smcFunc['classSFS']) && is_callable(array($smcFunc['classSFS'], 'checkVerificationTest'))) |
|
21 | 21 |
$smcFunc['classSFS']->checkVerificationTest($thisVerification, $verification_errors); |
22 | 22 |
|
23 | 23 |
// This cannot happen! |
24 | 24 |