jdarwood007 commited on 2019-12-08 12:50:38
Showing 2 changed files, with 39 additions and 5 deletions.
... | ... |
@@ -238,12 +238,15 @@ class SFS |
238 | 238 |
array('title', 'sfsgentitle', 'label' => $txt['sfs_general_title']), |
239 | 239 |
|
240 | 240 |
array('check', 'sfs_enabled'), |
241 |
- array('check', 'sfs_log_debug'), |
|
241 |
+ array('int', 'sfs_expire'), |
|
242 | 242 |
'', |
243 | 243 |
array('check', 'sfs_emailcheck'), |
244 |
+ '', |
|
245 |
+ array('check', 'sfs_usernamecheck'), |
|
246 |
+ array('int', 'sfs_username_confidence'), |
|
247 |
+ '', |
|
244 | 248 |
array('check', 'sfs_ipcheck'), |
245 | 249 |
array('check', 'sfs_ipcheck_autoban'), |
246 |
- array('check', 'sfs_usernamecheck'), |
|
247 | 250 |
'', |
248 | 251 |
array('select', 'sfs_region', $this->sfsServerMapping('config')), |
249 | 252 |
'', |
... | ... |
@@ -274,6 +277,8 @@ class SFS |
274 | 277 |
), 'multiple' => true), |
275 | 278 |
array('text', 'sfs_verification_options_membersextra', 'subtext' => $txt['sfs_verification_options_extra_subtext']), |
276 | 279 |
array('int', 'sfs_verification_options_members_post_threshold'), |
280 |
+ '', |
|
281 |
+ array('check', 'sfs_log_debug'), |
|
277 | 282 |
); |
278 | 283 |
|
279 | 284 |
if ($return_config) |
... | ... |
@@ -703,6 +708,8 @@ class SFS |
703 | 708 |
// If this was a IP ban, note it. |
704 | 709 |
if ($resultType == 'ip' && !empty($extra)) |
705 | 710 |
$entries[$row['id_sfs']]['result'] .= ' ' . $txt['sfs_log_auto_banned']; |
711 |
+ if ($resultType == 'username' && !empty($extra)) |
|
712 |
+ $entries[$row['id_sfs']]['result'] .= ' ' . sprintf($txt['sfs_log_confidence'], $extra); |
|
706 | 713 |
} |
707 | 714 |
else |
708 | 715 |
$entries[$row['id_sfs']]['result'] = $row['result']; |
... | ... |
@@ -1090,17 +1097,35 @@ class SFS |
1090 | 1097 |
{ |
1091 | 1098 |
foreach ($response['username'] as $check) |
1092 | 1099 |
{ |
1093 |
- // !!! TODO: Expose confidence as a threshold? |
|
1094 | 1100 |
// Combine with $area we could also require admin approval above thresholds on things like register. |
1095 |
- // !!! TODO: Expose lastseen as a threshold? |
|
1096 | 1101 |
if (!empty($check['appears'])) |
1102 |
+ { |
|
1103 |
+ $shouldBlock = true; |
|
1104 |
+ $confidenceLevel = 0; |
|
1105 |
+ |
|
1106 |
+ // They meet the confidence level, block them. |
|
1107 |
+ if (!empty($modSettings['sfs_username_confidence']) && !empty($check['confidence']) && $area == 'register' && (float) $modSettings['sfs_username_confidence'] <= (float) $check['confidence']) |
|
1108 |
+ $confidenceLevel = $check['confidence']; |
|
1109 |
+ // We are not confident that they should be blocked. |
|
1110 |
+ if (!empty($modSettings['sfs_username_confidence']) && !empty($check['confidence']) && $area == 'register' && (float) $modSettings['sfs_username_confidence'] > (float) $check['confidence']) |
|
1111 |
+ { |
|
1112 |
+ // Incase we need to debug this. |
|
1113 |
+ if (!empty($modSettings['sfs_log_debug'])) |
|
1114 |
+ $this->logAllStats('all', $checks, 'username,' . $smcFunc['htmlspecialchars']($check['value']) . ',' . $check['confidence']); |
|
1115 |
+ |
|
1116 |
+ $shouldBlock = false; |
|
1117 |
+ } |
|
1118 |
+ |
|
1119 |
+ // Block them. |
|
1120 |
+ if ($shouldBlock) |
|
1097 | 1121 |
{ |
1098 | 1122 |
$this->logBlockedStats('username', $check); |
1099 |
- $requestBlocked = 'username,' . $smcFunc['htmlspecialchars']($check['value']); |
|
1123 |
+ $requestBlocked = 'username,' . $smcFunc['htmlspecialchars']($check['value']) . ',' . $confidenceLevel; |
|
1100 | 1124 |
break; |
1101 | 1125 |
} |
1102 | 1126 |
} |
1103 | 1127 |
} |
1128 |
+ } |
|
1104 | 1129 |
|
1105 | 1130 |
// If we didn't match a IP or username, handle Emails only if we are supposed to, this is just a double check. |
1106 | 1131 |
if (empty($requestBlocked) && !empty($modSettings['sfs_emailcheck']) && !empty($response['email'])) |
... | ... |
@@ -1325,6 +1350,10 @@ class SFS |
1325 | 1350 |
$url .= '&badtorexit'; |
1326 | 1351 |
// Default handling for Tor is to block all exit nodes, nothing needed here. |
1327 | 1352 |
|
1353 |
+ // Do we have to filter out from lastseen? |
|
1354 |
+ if (!empty($modSettings['sfs_expire'])) |
|
1355 |
+ $url .= '&expire=' . (int) $modSettings['sfs_expire']; |
|
1356 |
+ |
|
1328 | 1357 |
return $url; |
1329 | 1358 |
} |
1330 | 1359 |
|
... | ... |
@@ -1426,7 +1455,9 @@ class SFS |
1426 | 1455 |
// Specify the defaults, but only non empties. |
1427 | 1456 |
$defaultSettings = array( |
1428 | 1457 |
'sfs_enabled' => 1, |
1458 |
+ 'sfs_expire' => 90, |
|
1429 | 1459 |
'sfs_emailcheck' => 1, |
1460 |
+ 'sfs_username_confidence' => 50.01, |
|
1430 | 1461 |
'sfs_region' => 0, |
1431 | 1462 |
'sfs_verification_options_members_post_threshold' => 5, |
1432 | 1463 |
); |
... | ... |
@@ -9,10 +9,12 @@ $txt['sfs_general_title'] = 'General Configuration'; |
9 | 9 |
|
10 | 10 |
/* Admin section configuration options */ |
11 | 11 |
$txt['sfs_enabled'] = 'Enable Stop Forum Spam?'; |
12 |
+$txt['sfs_expire'] = 'Limit results to entries in the past x days'; |
|
12 | 13 |
$txt['sfs_log_debug'] = 'Enable Logging of all SFS requests (Debugging Only)?'; |
13 | 14 |
$txt['sfs_ipcheck'] = 'Check IP Address?'; |
14 | 15 |
$txt['sfs_ipcheck_autoban'] = 'Automatically ban IPs that are blacklisted?'; |
15 | 16 |
$txt['sfs_usernamecheck'] = 'Check Username?'; |
17 |
+$txt['sfs_username_confidence'] = 'Confidence level for usernames on registration'; |
|
16 | 18 |
$txt['sfs_emailcheck'] = 'Check Email? (Recommended)'; |
17 | 19 |
|
18 | 20 |
/* Admin section: Region Config */ |
... | ... |
@@ -80,6 +82,7 @@ $txt['sfs_log_types_2'] = 'Email'; |
80 | 82 |
$txt['sfs_log_types_3'] = 'IP Address'; |
81 | 83 |
$txt['sfs_log_matched_on'] = 'Matched on %1$s [%2$s]'; |
82 | 84 |
$txt['sfs_log_auto_banned'] = 'Banned'; |
85 |
+$txt['sfs_log_confidence'] = 'Confidence Level: %1$s'; |
|
83 | 86 |
|
84 | 87 |
// The ban group info. |
85 | 88 |
$txt['sfs_ban_group_name'] = 'SFS Automatic IP Bans'; |
86 | 89 |