Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Maybe you should come at this from a different direction - why are they being banned? Is there something like fail2ban you should be using instead?</p> <p>However, this is also bad - anyone visiting your site from behind a company firewall will all share the same IP, so you'll be banning an entire company not just an individual.</p> <p>Solution 1; Your code has a race condition where two threads could read and write to the same file simultaneously, which would be bad since it could corrupt your IPTABLES setup. If you insist on doing this, exclusive-lock the the bans.txt file before processing the entries.</p> <pre><code>$banlogFp = fopen("bans.txt","a+"); // open for r+w $tnow = time(); //loop until have lock, or 2 seconds elapsed //(since will be invoked again after 3 sec) while (!flock("bans.txt") &amp;&amp; (time() - $tnow &lt; 2) { $banlogTxt = fread($handle, filesize($filename)); $banlogTxt = preg_replace('/\.\\r\\n/m', '@\n', $s); //any CRLF to LF $banlog = explode("\n", $banlogTxt); //Convert to array, splittng on LF foreach($banlog as $ip) { //validate $ip is numeric - don't want malicious hacker to break IPTABLES if (preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$ip+)) { exec("iptables -I INPUT -s $ip -j DROP"); } } ftruncate($banlogFp, 0); fclose($banlogFp); } </code></pre> <p>Solution 2; You don't need to use the "Deny from aaa.bbb.ccc.ddd" command in .htaccess, instead you can use a rewrite rule to point them to any page of your choosing. Much safer than modifying IPTABLES, but still has the big-stick problem of banning other individuals sharing the IP address. E.g.</p> <pre><code>SetEnvIf REMOTE_ADDR 192.12.131.1 REDIR="redir" SetEnvIf REMOTE_ADDR 192.12.131.2 REDIR="redir" SetEnvIf REMOTE_ADDR 192.12.131.3 REDIR="redir" RewriteCond %{REDIR} redir RewriteRule ^/$ /you_are_banned.html </code></pre> <p>Solution 3 (best!); Don't allow anyone to post to your site unless they've registered a username + password, then just ban the username, not the IP address. Use a database like MySQL to store users and passwords, and a flag to say if they're banned. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload