1

I'm trying to block a IP list generated by CustomLog using IfDefine to avoid log ip again, but it's not working. I changed CustomLog conditional and something bizarre behavior can be observed:

RewriteMap blacklist txt:/var/www/blacklist.log
RewriteCond   ${blacklist:%{REMOTE_ADDR}|NOT-FOUND} !=NOT-FOUND [OR]
RewriteCond   ${blacklist:%{REMOTE_HOST}|NOT-FOUND} !=NOT-FOUND
RewriteRule   ^ - [F,E=BLOCKED_IP]

<IfDefine !BLOCKED_IP>
  SetEnvIf Request_URI "^/xmlrpc\.php$" BAD_BEHAVIOR
  CustomLog /var/log/apache2/blacklist.log "%h ## %t BAD_BEHAVIOR \"%r\" %>s %b \"%{User-agent}i\"" env=BLOCKED_IP
</IfDefine>

Even when BLOCKED_IP true the code inside IfDefine executes and CustomLog has a inverse conditional... It doesnt make any sense -.-

  1. RewriteRule define BLOCKED_IP
  2. IfDefine !BLOCKED_IP pass (why?)
  3. CustomLog works with a inverse conditional (why again?)
  4. blacklist.log has added same IP

Can someone explain this behavior??

Arthur Ronconi
  • 2,290
  • 25
  • 25

2 Answers2

0

IfDefine do not work with env variables defined after the start of the application.

It only works with parameter set on the command line via -Dparameter

Julien
  • 206
  • 1
  • 7
0

Usage like <IfDefine !xxx> is not supported in Apache 2.4, remove "!" will work normally