[ic] [interchange] Update routine to recognize "RobotUAFinal"

Peter peter at pajamian.dhs.org
Wed Jan 18 04:38:30 UTC 2017


On 18/01/17 11:18, David Christensen wrote:
>  sub check_is_robot {
> -    my $ret = 1;
> +	my $ret = 1;
>  
>  #::logDebug("Check robot UA=$Global::RobotUA IP=$Global::RobotIP");
>  	if ($Global::RobotIP and $CGI::remote_addr =~ $Global::RobotIP) {
> @@ -303,13 +303,18 @@ sub check_is_robot {
>  			$ret = 1;
>  		}
>  	}
> -	unless ($Vend::Robot) { 
> -		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!");
> -			$ret = 1;
> +	if ($Global::RobotUAFinal and $CGI::useragent =~ $Global::RobotUAFinal) {
> +		$ret = 1;
> +	}
> +	else {
> +		unless ($Vend::Robot) {
> +			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!");
> +				$ret = 1;
> +			}
>  		}
>  	}
>  	return $ret;

There are cases where $ret is set to 1 and then further (wasted)
processing is done to determine if $ret should be set to 1.  The logic
is also insanely deep and confusing here.  I propose this simplification
which also fixes the other issues I mentioned (I'll push if you're
agreeable):

diff --git a/lib/Vend/Server.pm b/lib/Vend/Server.pm
index a7eb80b..d5b62b5 100644
--- a/lib/Vend/Server.pm
+++ b/lib/Vend/Server.pm
@@ -279,45 +279,44 @@ EOF
 #::logDebug("request_method=$CGI::request_method");
 #::logDebug("content_type=$CGI::content_type");

-       $Vend::Robot = check_is_robot();
+       $Vend::Robot ||= check_is_robot();

        $CGI::values{mv_tmp_session} ||= 1 if $Vend::Robot;
 }


 sub check_is_robot {
-       my $ret = 1;
-
 #::logDebug("Check robot UA=$Global::RobotUA IP=$Global::RobotIP");
-       if ($Global::RobotIP and $CGI::remote_addr =~ $Global::RobotIP) {
+    if ($Global::RobotIP and $CGI::remote_addr =~ $Global::RobotIP) {
 #::logDebug("It is a robot by IP!");
-               $ret = 1;
+       return 1;
+    }
+
+    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;
        }
-       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) {
+       if ($CGI::remote_host && $CGI::remote_host =~ $Global::RobotHost) {
 #::logDebug("It is a robot by host!");
-                       $ret = 1;
-               }
-       }
-       if ($Global::RobotUAFinal and $CGI::useragent =~
$Global::RobotUAFinal) {
-               $ret = 1;
-       }
-       else {
-               unless ($Vend::Robot) {
-                       if ($Global::NotRobotUA and $CGI::useragent =~
$Global::NotRobotUA) {
-                               # do nothing
-                       }


Peter



More information about the interchange-users mailing list