Error Script to handle redirections based on errors

 
Post new topic   Reply to topic    Aprelium Forum Index -> FastCGI/CGI
View previous topic :: View next topic  
Author Message
Chris45
-


Joined: 24 Mar 2004
Posts: 5

PostPosted: Mon Mar 29, 2004 7:34 pm    Post subject: Error Script to handle redirections based on errors Reply with quote

Will not show path ect:
any help on this please.

Thanks
Chris

Code:
#!/usr/local/bin/perl

$error = $ENV{'QUERY_STRING'};
$redirect_request = $ENV{'REDIRECT_REQUEST'};
($redirect_method,$request_url,$redirect_protocal) = split(' ',$redirect_request);
$redirect_status = $ENV{'REDIRECT_STATUS'};
if (!defined($redirect_status)) {
  $redirect_status = "200 Ok";
}
($redirect_number,$redirect_message) = split(' ',$redirect_status);
$error =~ s/error=//;

$title = "<HEAD><TITLE>".$redirect_status."</TITLE></HEAD>";

if ($redirect_method eq "HEAD") {
   $head_only = 1;
} else {
   $head_only = 0;
}

printf("%s %s\r\n",$ENV{'SERVER_PROTOCOL'},$redirect_status);
printf("Server: %s\r\n",$ENV{'SERVER_SOFTWARE'});
printf("Content-type: text/html\r\n");

$redirect_status = "<img alt=\"\" src=/images/errorman.jpg>".$redirect_status;
if ($redirect_number == 302) {
   if ($error !~ /http:/) {   
      printf("xLocation: http://%s:%s%s\r\n",
         $ENV{'SERVER_NAME'},
         $ENV{'SERVER_PORT'},
         $error);
   if (!$head_only) {
      printf("%s\r\n",$title);
      printf("<BODY><H1>%s</H1>\r\n",$redirect_status);
      printf("This document has moved");
      printf("<A HREF=\"http://%s:%s%s\">here</A>.\r\n",
             $ENV{'SERVER_NAME'},
             $ENV{'SERVER_PORT'},
             $error);
      }
   } else {
                printf("Location: %s\r\n",$error);
   if (!$head_only) {
                printf("%s\r\n",$title);
                printf("<BODY><H1>%s</H1>\r\n",$redirect_status);
                printf("This document has moved");
                printf("<A HREF=\"%s\">here</A>.\r\n",$error);
      }
   }
} elsif ($redirect_number == 400) {
   printf("\r\n");
   if (!$head_only) {
      printf("%s\r\n",$title);
      printf("<BODY><H1>%s</H1>\r\n",$redirect_status);
      printf("Your client sent a request that this server didn't");
      printf(" understand.<br><b>Reason:</b> %s\r\n",$error);
   }
} elsif ($redirect_number == 401) {
   printf("WWW-Authenticate: %s\r\n",$error);
   printf("\r\n");
   if (!$head_only) {
      printf("%s\r\n",$title);
      printf("<BODY><H1>%s</H1>\r\n",$redirect_status);
      printf("Browser not authentication-capable or ");
      printf("authentication failed.\r\n");
   }
} elsif ($redirect_number == 403) {
   printf("\r\n");
        if (!$head_only) {
                printf("%s\r\n",$title);
                printf("<BODY><H1>%s</H1>\r\n",$redirect_status);
                printf("Your client does not have permission to get");
                printf("URL:%s from this server.\r\n",$ENV{'REDIRECT_URL'});
        }
} elsif ($redirect_number == 404) {
   printf("\r\n");
   if (!$head_only) {
      printf("%s\r\n",$title);
      printf("<BODY><H1>%s</H1>\r\n",$redirect_status);
      printf("The requested URL:<code>%s</code> ",
         $ENV{'REDIRECT_URL'});
      printf("was not found on this server.\r\n");
   }
} elsif ($redirect_number == 500) {
        printf("\r\n");
        if (!$head_only) {
                printf("%s\r\n",$title);
                printf("<BODY><H1>%s</H1>\r\n",$redirect_status);
                printf("The server encountered an internal error or ");
                printf("misconfiguration and was unable to complete your ");
                printf("request \"<code>%s</code>\"\r\n",$redirect_request);
        }
} elsif ($redirect_number == 501) {
   printf("\r\n");
   if (!$head_only) {
      printf("%s\r\n",$title);
      printf("<BODY><H1>%s</H1>\r\n",$redirect_status);
      printf("The server is unable to perform the method ");
      printf("<b>%s</b> at this time.",$redirect_method);
   }
} else {
   printf("\r\n");
   if (!$head_only) {
      printf("%s\r\n",$title);
      printf("<BODY><H1>%s</H1>\r\n",$redirect_status);
   }
}

if (!$head_only) {
   printf("<p>The following might be useful in determining the problem:");
   printf("<pre>\r\n");
   open(ENV,"env|");
   while (<ENV>) {
      printf("$_");
   }
   close(ENV);
   printf("</pre>\r\n<hr>");
   printf("<A HREF=\"http://%s:%s/\"><img alt=\"[Back to Top]\" src=\"/images/back.jpg\"> Back to Root of Server</A>\r\n",
      $ENV{'SERVER_NAME'},$ENV{'SERVER_PORT'});
   printf("<hr><i><a href=\"mailto:sat_ring\@hotmail.com\">webmaster\@%s</a></i> / ",
      $ENV{'SERVER_NAME'},$ENV{'SERVER_NAME'});
   printf("<i>It's all going wrong</i>");
   printf("</BODY>\r\n");
}

[/code]
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Tue Mar 30, 2004 2:07 pm    Post subject: Re: Error Script to handle redirections based on errors Reply with quote

This script uses non standard CGI variables. To fix it, change:

Code:
$redirect_request = $ENV{'REDIRECT_REQUEST'};
($redirect_method,$request_url,$redirect_protocal) = split(' ',$redirect_request);


with

Code:

$redirect_method = $ENV{'REDIRECT_REQUEST_METHOD'};
$request_url = $ENV{'REDIRECT_SCRIPT_NAME'};
$redirect_protocal = $ENV{'REDIRECT_SERVER_PROTOCOL'};


You must also change all the occurences of $ENV{'REDIRECT_URL'} with $ENV{'REDIRECT_SCRIPT_NAME'}

Does it work now?
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Chris45
-


Joined: 24 Mar 2004
Posts: 5

PostPosted: Wed Mar 31, 2004 10:39 am    Post subject: Reply with quote

Thanks aprelium,

How one looks at things all night and just can't see whats in front of one's nose :-))

Or I just could be thick as S*** ,
whaat ever it's working so time to keep playing :-((

Don't you just love windows !!!!!!

Regards
Chris
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> FastCGI/CGI All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group