[ic] Server.pm logic for NotRobotUA too exclusive

John Young john_young at sonic.net
Wed Jul 7 21:00:16 EDT 2004


On 30 Apr 2004 Server.pm was modified to accommodate the new NotRobotUA
config option, and the bit of code looks like (logDebugs indented for
readability):

     if ($Global::RobotIP and $CGI::remote_addr =~ $Global::RobotIP) {
         #::logDebug("It is a robot by IP!");
         $CGI::values{mv_tmp_session} = 1;
     }
     elsif ($Global::HostnameLookups && $Global::RobotHost) {
         if (!$CGI::remote_host && $CGI::remote_addr) {
             $CGI::remote_host = 
gethostbyaddr(Socket::inet_aton($CGI::remote_addr),Socket::AF_INET);
             $CGI::host = $CGI::remote_host || $CGI::remote_addr;
         }
         if ($CGI::remote_host && $CGI::remote_host =~ $Global::RobotHost) {
             #::logDebug("It is a robot by host!");
             $CGI::values{mv_tmp_session} = 1;
         }
     }
     elsif ($Global::NotRobotUA and $CGI::useragent =~ 
$Global::NotRobotUA) {
         # do nothing
     }
     elsif ($Global::RobotUA and $CGI::useragent =~ $Global::RobotUA) {
         #::logDebug("It is a robot by UA!");
         $CGI::values{mv_tmp_session} = 1;
     }

That logic tends to ignore RobotUA if HostnameLookups and RobotHost are
true.  IOW, any use of HostnameLookups + RobotHost negates the use of
RobotUA (no Robot identification by a compilation of RobotHost and RobotUA).
Unless the intent is to ONLY use RobotHost OR RobotUA, something like the
following logic might be more desirable (three if's instead of one, and
two return's added to bail early):

     if ($Global::RobotIP and $CGI::remote_addr =~ $Global::RobotIP) {
         #::logDebug("It is a robot by IP!");
         $CGI::values{mv_tmp_session} = 1;
         return;
     }
     if ($Global::HostnameLookups && $Global::RobotHost) {
         if (!$CGI::remote_host && $CGI::remote_addr) {
             $CGI::remote_host = 
gethostbyaddr(Socket::inet_aton($CGI::remote_addr),Socket::AF_INET);
             $CGI::host = $CGI::remote_host || $CGI::remote_addr;
         }
         if ($CGI::remote_host && $CGI::remote_host =~ $Global::RobotHost) {
             #::logDebug("It is a robot by host!");
             $CGI::values{mv_tmp_session} = 1;
             return;
         }
     }
     if ($Global::NotRobotUA and $CGI::useragent =~ $Global::NotRobotUA) {
         # do nothing
     }
     elsif ($Global::RobotUA and $CGI::useragent =~ $Global::RobotUA) {
         #::logDebug("It is a robot by UA!");
         $CGI::values{mv_tmp_session} = 1;
         # Perhaps a third 'return;' here to be consistent even though 
we are at the end of the sub.
     }


Comments appreciated,
John Young






More information about the interchange-users mailing list