Simple (Rookie) Question

A

Annie

A kind volunteer wrote an effective perl script for my website ten or
more years back.

The script was called from header.html, and worked flawlessly for
years...until someone decided to mess with the headers and removed the
call to the cgi script.

This is the script - it delivered custom headers based on the visitor's
domain, and worked perfectly:

#!/usr/bin/env perl
use strict;

sub do_default {
open (HTMLIN, "header-default.html") or die "Error opening default
header";
while (<HTMLIN>) {
print;
}
close HTMLIN;
}

sub do_header {
my $domain;
$domain = shift(@_);

if (open (HTMLIN, "header-$domain.html")) {

while (<HTMLIN>) {
print;
}

close HTMLIN;
} else {
do_default;
}
}

MAIN: {
my($domain, $html, $toplevel);

$domain=$ENV{"REMOTE_HOST"};

$domain =~ /.+\.(.{1,3})$/;
$toplevel = $1;

print "Content-Type: text/html\n\n";

do_header($toplevel);
}

Can some kind soul provide me with a line of code that will call this
script?
 
J

Jason C

A kind volunteer wrote an effective perl script for my website ten or

more years back.



The script was called from header.html, and worked flawlessly for

years...until someone decided to mess with the headers and removed the

call to the cgi script.



This is the script - it delivered custom headers based on the visitor's

domain, and worked perfectly:



#!/usr/bin/env perl

use strict;



sub do_default {

open (HTMLIN, "header-default.html") or die "Error opening default

header";

while (<HTMLIN>) {

print;

}

close HTMLIN;

}



sub do_header {

my $domain;

$domain = shift(@_);



if (open (HTMLIN, "header-$domain.html")) {



while (<HTMLIN>) {

print;

}



close HTMLIN;

} else {

do_default;

}

}



MAIN: {

my($domain, $html, $toplevel);



$domain=$ENV{"REMOTE_HOST"};



$domain =~ /.+\.(.{1,3})$/;

$toplevel = $1;



print "Content-Type: text/html\n\n";



do_header($toplevel);

}



Can some kind soul provide me with a line of code that will call this

script?

From your description, I think you are using SSI. It's been a LONG time since I've worked with that, but I think you're looking for:

<!--#exec cgi="cgi-bin/script_name.cgi"-->

The path "cgi-bin/script_name.cgi" would vary based on the name and location of the script.

HTH.
 
W

William Humpboys

From your description, I think you are using SSI. It's been a LONG time since I've worked with that, but I think you're looking for:

<!--#exec cgi="cgi-bin/script_name.cgi"-->

The path "cgi-bin/script_name.cgi" would vary based on the name and location of the script.

In my case, that becomes:

<!--#exec cgi="/find_header"-->

and generates an apache error

"[an error occurred while processing this directive]"

http://nizkor.org/test.html
 
J

Jason C

On Sun, 28 Oct 2012 17:48:55 -0700 (PDT), Jason C
From your description, I think you are using SSI. It's been a LONG time since I've worked with that, but I think you're looking for:

<!--#exec cgi="cgi-bin/script_name.cgi"-->

The path "cgi-bin/script_name.cgi" would vary based on the name and location of the script.



In my case, that becomes:



<!--#exec cgi="/find_header"-->



and generates an apache error



"[an error occurred while processing this directive]"



http://nizkor.org/test.html

Are you sure that the name of the script is "find_header", and not "find_header.cgi" or "find_header.pl"? You might have your program set to not show extensions.

Do you have access to your site's error log? If so, that will probably give you more insight on why you're getting this error.
 
A

Annie

Are you sure that the name of the script is "find_header", and not
"find_header.cgi" or "find_header.pl"? You might have your program set
to not show extensions.

Do you have access to your site's error log? If so, that will probably
give you more insight on why you're getting this error.

Stupid me - thanks for pointing that out. I've changed it to correct the
omission, and now get a blank page. Thanks for the help - I'll keep
playing with it and see if I can figure out the rest.

Cheers
 
H

Hans Mulder

From your description, I think you are using SSI. It's been a LONG time since I've worked with that, but I think you're looking for:

<!--#exec cgi="cgi-bin/script_name.cgi"-->

The path "cgi-bin/script_name.cgi" would vary based on the name and location of the script.

In my case, that becomes:

<!--#exec cgi="/find_header"-->

and generates an apache error

"[an error occurred while processing this directive]"

http://nizkor.org/test.html

In that case, you'll want to look at the error message.
You can find it in the Apache error log.


Hope this helps,

-- HansM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,818
Messages
2,569,727
Members
45,675
Latest member
benn

Latest Threads

Top