Skip to content

Commit

Permalink
Merge pull request #15 from effone/whitelist-gids
Browse files Browse the repository at this point in the history
Resolve #12 Whitelist usergroups to allow using proxy
  • Loading branch information
effone authored Sep 18, 2019
2 parents eefe0c6 + 14aac7a commit 72b6534
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion dist/inc/languages/english/admin/ipatrol.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
$l['ipatrol_dispomail_desc'] = "Identify and restrict usage of disposable email ids during user registration.";
$l['ipatrol_banproxy_title'] = "Ban users using proxy";
$l['ipatrol_banproxy_desc'] = "Ban the IP address of the users who use proxy to access the site.";
$l['ipatrol_whitegids_title'] = "Usergroups to allow using proxy";
$l['ipatrol_whitegids_desc'] = "Users under any of these groups will not be banned even if they use proxy to access the site.";
$l['ipatrol_whiteip_title'] = "Whitelist IP addresses";
$l['ipatrol_whiteip_desc'] = "Whitelist known IP addresses and those will never be banned by iPatrol. Enter single IP in each line.";
$l['ipatrol_postcheck_title'] = "Auto unapprove spam posts";
Expand All @@ -20,7 +22,7 @@
$l['ipatrol_postchecknum_title'] = "Spam detection post count";
$l['ipatrol_postchecknum_desc'] = "The post count limit for spam detection. Posts will be scanned for spam link by users having less of this post count.";
$l['ipatrol_postcheckgids_title'] = "Usergroups to scan for spamming";
$l['ipatrol_postcheckgids_desc'] = "The affected usergroups for spam check (GIDs, separated by comma). Check will be performed if posting user belongs to one of these groups.";
$l['ipatrol_postcheckgids_desc'] = "The affected usergroups for spam check. Check will be performed if posting user belongs to one of these groups.";
$l['ipatrol_postcheckwlist_title'] = "Whitelisted users from spam check";
$l['ipatrol_postcheckwlist_desc'] = "Define the user IDs whose posts will not be checked from spamming (separated by comma)";
// $l['ipatrol_honeypot_title'] = "Add Form Honeypot";
Expand Down
21 changes: 16 additions & 5 deletions dist/inc/plugins/ipatrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ipatrol_info()
'website' => 'https://github.com/mybbgroup/iPatrol',
'author' => 'effone</a> of <a href="https://mybb.group">MyBBGroup</a>',
'authorsite' => 'https://eff.one',
'version' => '1.0.0-alpha',
'version' => '1.1.0',
'compatibility' => '18*',
'codename' => 'ipatrol',
);
Expand Down Expand Up @@ -115,6 +115,12 @@ function ipatrol_install()
"value" => '1',
);

$ipatrol[] = array(
"name" => "ipatrol_whitegids",
"optionscode" => "groupselect",
"value" => '3,4,6',
);

$ipatrol[] = array(
"name" => "ipatrol_whiteip",
"optionscode" => "textarea",
Expand Down Expand Up @@ -147,7 +153,7 @@ function ipatrol_install()

$ipatrol[] = array(
"name" => "ipatrol_postcheckgids",
"optionscode" => "text",
"optionscode" => "groupselect",
"value" => '1,2,5,7',
);

Expand Down Expand Up @@ -266,6 +272,7 @@ function ipatrol_settingspeekers(&$peekers)
//$peekers[] = 'new Peeker($(".setting_ipatrol_noregdupe"), $("#row_setting_ipatrol_skipregdupe"),/1/,true)';
$peekers[] = 'new Peeker($(".setting_ipatrol_detectbot"), $("#row_setting_ipatrol_autoaddbot"),/1/,true)';
$peekers[] = 'new Peeker($(".setting_ipatrol_detectbot"), $("#row_setting_ipatrol_similarbot"),/1/,true)';
$peekers[] = 'new Peeker($(".setting_ipatrol_banproxy"), $("#row_setting_ipatrol_whitegids"),/1/,true)';
$peekers[] = 'new Peeker($(".setting_ipatrol_banproxy"), $("#row_setting_ipatrol_whiteip"),/1/,true)';
$peekers[] = 'new Peeker($(".setting_ipatrol_postcheck"), $("#row_setting_ipatrol_postcheckedit"),/1/,true)';
$peekers[] = 'new Peeker($(".setting_ipatrol_postcheck"), $("#row_setting_ipatrol_postcheckword"),/1/,true)';
Expand Down Expand Up @@ -337,12 +344,16 @@ function ipatrol_ban_proxy()
global $mybb;

// IP Ban the user using Proxy
if ($mybb->settings['ipatrol_banproxy']) {
if ($mybb->settings['ipatrol_banproxy']) {
// Don't try to track real IP using get_ip(), we need to punish presented IP
$ip = my_strtolower(trim($_SERVER['REMOTE_ADDR']));
$whitelist = array_map('trim', preg_split('/\r\n|\r|\n/', $mybb->settings['ipatrol_whiteip']));
$whitegroups = array_filter(array_unique(explode(',', $mybb->settings['ipatrol_whitegids'])));
$usergroups = array_filter(array_unique(explode(',', $mybb->user['usergroup'] . ',-1,' . $mybb->user['additionalgroups'])));

if (!is_banned_ip($ip) && !in_array($ip, $whitelist)) {
if (!is_banned_ip($ip)
&& empty(array_intersect($usergroups, $whitegroups))
&& !in_array($ip, $whitelist)) {
$response = ipatrol_ip_info($ip, 'proxy');
if (!empty($response) && json_decode($response, true)['proxy']) {
// Ban this IP
Expand Down Expand Up @@ -628,7 +639,7 @@ function ipatrol_spamcheck(&$post)
&& $mybb->settings['ipatrol_postcheck']
&& (int) $mybb->user['postnum'] < (int) $mybb->settings['ipatrol_postchecknum']) {
$suspectedgroups = array_filter(array_unique(explode(',', $mybb->settings['ipatrol_postcheckgids'])));
$usergroups = array_filter(array_unique(explode(',', $mybb->user['usergroup'] . ',' . $mybb->user['additionalgroups'])));
$usergroups = array_filter(array_unique(explode(',', $mybb->user['usergroup'] . ',-1,' . $mybb->user['additionalgroups'])));

if (!empty($suspectedgroups)
&& !empty(array_intersect($usergroups, $suspectedgroups))
Expand Down

0 comments on commit 72b6534

Please sign in to comment.