Skip to content

Commit

Permalink
Resolve issue #1. ver.1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
findlabnet committed Nov 25, 2020
1 parent 753b789 commit a0fbfc9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ such as "wp-admin.php", "xmlrpc.php" and so on.

Installation
------------
Install this module using the official Backdrop CMS instructions at
https://backdropcms.org/guide/modules
Install this module using the official Backdrop CMS instructions at https://backdropcms.org/guide/modules

Configuration and usage
-----------------------
Expand All @@ -21,6 +20,7 @@ User accounts > Antiscan* (admin/config/people/antiscan)
and may be used for:

- add your patterns for paths to be restricted (some usefull patterns are already added out of the box);
- set paths or portions of paths that will NOT be restricted to avoid self-blocking;
- enable or disable logging for blocked access attempts (enabled by default);
- select the time after which the blocked IP will be unblocked automatically;
- use "Test Mode" to test your patterns, your current IP will not be blocked, but you may see a message when you try to visit the restricted path.
Expand Down
34 changes: 30 additions & 4 deletions antiscan.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function antiscan_form() {
'#default_value' => $path_patterns,
'#title' => t('Restricted path patterns'),
'#required' => TRUE,
'#description' => t('Enter paths or parts of paths to restrict, separating them with commas or new lines.')
. '<br />' . t('Please note: the <b>*</b> character is a wildcard for end of pattern, so pattern like') . '<b> wp-* </b>'
'#description' => t('Enter paths or portions of paths to restrict, separating them with commas or new lines.')
. '<br>' . t('Please note: the <b>*</b> character is a wildcard for end of pattern, so pattern like') . '<b> wp-* </b>'
. t('will match to any path containing "wp-admin", "wp-login", etc.'),

);
Expand All @@ -34,7 +34,26 @@ function antiscan_form() {
$form['info'] = array(
'#markup' => '<p><b>'. t('Please note') .': </b>' . t('you can manage the list of blocked IPs at <a href="@url">this page</a>.', array('@url' => $url)) . '</p>',
);

$form['noblock'] = array(
'#type' => 'fieldset',
'#title' => t('Additional settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);

$path_noblock = $config->get('path_noblock');
$form['noblock']['path_noblock'] = array(
'#type' => 'textarea',
'#title' => t('Not blockable path patterns'),
'#rows' => 6,
'#columns' => 60,
'#default_value' => $path_noblock,
'#required' => TRUE,
'#description' => t('Enter paths or portions of paths that will NOT be restricted to avoid self-blocking your users.')
. '<br>' . t('Same format of rules as above.'),
);

$form['log_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable logging'),
Expand Down Expand Up @@ -87,8 +106,13 @@ function antiscan_form_validate($form, &$form_state) {
$path_noblock = $config->get('path_noblock');
$path_patterns = trim($form_state['values']['path_patterns']);

if (strpos(strtolower($path_patterns), $path_noblock) !== FALSE) {
form_set_error('path_patterns', t('You cannot use "%path_noblock" within pattern. If you need restrict users login ability, please use another module.', array('%path_noblock' => $path_noblock)));
$noblock_array = _textarea_to_array($path_noblock);
$patterns_array = _textarea_to_array($path_patterns);
$matched = array_intersect($noblock_array, $patterns_array);

if (!empty($matched)) {
$matched_patterns = implode(", ", $matched);
form_set_error('path_patterns', t('You cannot use "%matched_patterns" for a pattern. Please verify "Not blockable path patterns" under "Additional settings" below.', array('%matched_patterns' => $matched_patterns)));
}
}

Expand All @@ -98,12 +122,14 @@ function antiscan_form_validate($form, &$form_state) {
function antiscan_form_submit($form, &$form_state) {
$config = config('antiscan.settings');
$path_patterns = trim($form_state['values']['path_patterns']);
$path_noblock = trim($form_state['values']['path_noblock']);
$log_enabled = (int) $form_state['values']['log_enabled'];
$unblock = (int) $form_state['values']['unblock'];
$unblock_after = (int) $form_state['values']['unblock_after'];
$test_mode = (int) $form_state['values']['test_mode'];

$config->set('path_patterns', strtolower($path_patterns));
$config->set('path_noblock', strtolower($path_noblock));
$config->set('log_enabled', $log_enabled);
$config->set('unblock', $unblock);
$config->set('unblock_after', $unblock_after);
Expand Down
2 changes: 1 addition & 1 deletion antiscan.info
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ dependencies[] = ip_blocking (>=1.0.5)

configure = admin/config/people/antiscan

version = 1.0.2
version = 1.0.3
4 changes: 2 additions & 2 deletions config/antiscan.settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_config_name": "antiscan.settings",
"path_patterns": "administrator,elrekt,eval-stdin.php,fck,phpMyAdmin,wp-*,wlwmanifest.xml,xmlrpc.php",
"path_noblock": "user/",
"path_patterns": "elrekt,eval-stdin.php,/fck,phpMyAdmin,/wp-*,wlwmanifest.xml,xmlrpc.php",
"path_noblock": "user/,admin/",
"log_enabled": 1,
"test_mode": 0,
"unblock": 1,
Expand Down

0 comments on commit a0fbfc9

Please sign in to comment.