Elxis CMS Forum

Support => Elxis 4.x/5.x DEV => Topic started by: Amigamerlin on August 17, 2016, 12:46:01

Title: Defender improvement request
Post by: Amigamerlin on August 17, 2016, 12:46:01
Hello, I wolud like to ask , if possible, the option to Ban  ip address according a number of seconds. When the Ip reach 3 times currently it's banned in a permanent way. What I'm requesting is to can setup a time until the ip still be banned. After this time site will become available again.
Thank you for your attention.
Title: Re: Defender improvement request
Post by: datahell on August 19, 2016, 18:26:08
If someone is attacking your site why not to block him immediately???
What about automatic unban after some time? This is easier and makes more sense as attackers IPs change after a while.
Title: Re: Defender improvement request
Post by: webgift on August 22, 2016, 10:30:52
Quote
What about automatic unban after some time? This is easier and makes more sense as attackers IPs change after a while.
+1!
Title: Re: Defender improvement request
Post by: Amigamerlin on August 22, 2016, 12:00:45
What about automatic unban after some time? This is easier and makes more sense as attackers IPs change after a while.

Was my request :)  written in different way but was my request.
Only let the user decide the time (example 36000 seconds) after that it will be unban.
Then, if the IP is banned after 36000 seconds will be unban  :).

Thank you !!
 
Title: Re: Defender improvement request
Post by: Amigamerlin on February 26, 2017, 18:42:48
Hello Datahell, any news about this?
Title: Re: Defender improvement request
Post by: datahell on February 27, 2017, 18:29:15
You can do that by your selves.

Here is the idea:
Elxis supports custom cron jobs. Set up a cron job to automatically delete ban entries after any time you want. Each ban entry is like this:

'127x0x0x1' => array('times' => 1, 'refcode' => 'SEC-DEFG-00XXX', 'date' => '2017-02-09 19:37:28'),

You can check the date in comparison to the current date and delete the ban array this difference is higher than a limit.

include('some_path/'.defender_ban.php');
if (count($ban) > 0) {
      $current_time = time();
      $unban_seconds = 1800;//half an hour
      $new_ban = array();
      foreach ($bans a $ip => $row) {
            $ban_time = strtotime($row['date']);
            if ($time - $ban_time < $unban_seconds) {
                    $new_ban[$ip] = $row;
           }
      }
      if (count($new_ban) <> count($ban) {
            //re-create contents of defender_ban.php file with the entries from $new_ban array
     }
}

Creating custom cron jobs
Create a folder named "cronjobs" in Elxis repository folder.
{repository}/cronjobs/
Place there the php files containing the code you want Elxis to execute periodically (you can name the files what ever you want).
That's all!

Tip
When you open defender_ban.php file for writing lock the file and unlock it when saved.
$fp = @fopen('path_to_repository/logs/defender_ban.php', 'w');
if ($fp) {
   $ok = false;
   if (flock($fp, LOCK_EX)) {
      $ok = fwrite($fp, $data);
      flock($fp, LOCK_UN);
   }
   fclose($fp);
}