Simple (Rookie) Question

Discussion in 'Perl Misc' started by Annie, Oct 28, 2012.

  1. Annie

    Annie Guest

    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?
     
    Annie, Oct 28, 2012
    #1
    1. Advertising

  2. Annie

    Jason C Guest

    On Sunday, October 28, 2012 5:33:17 PM UTC-4, Annie wrote:
    > 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.
     
    Jason C, Oct 29, 2012
    #2
    1. Advertising

  3. On Sun, 28 Oct 2012 17:48:55 -0700 (PDT), Jason C
    <> wrote:

    >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
     
    William Humpboys, Oct 29, 2012
    #3
  4. Annie

    Jason C Guest

    On Sunday, October 28, 2012 10:52:35 PM UTC-4, William Humpboys wrote:
    > 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.
     
    Jason C, Oct 29, 2012
    #4
  5. Annie

    Annie Guest

    Jason C <> wrote in
    news::

    >> 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.


    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




    --
    Obama Voters Are Ignorami:
    http://spectator.org/blog/2012/09/25/obama-voters-ignoramuses
    In His Own Words: Barack Obama Reviewed
    http://www.youtube.com/watch?v=o8R5GvwUFU8
     
    Annie, Oct 29, 2012
    #5
  6. Annie

    Hans Mulder Guest

    On 29/10/12 03:52:10, William Humpboys wrote:
    > On Sun, 28 Oct 2012 17:48:55 -0700 (PDT), Jason C
    > <> wrote:
    >
    >>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
     
    Hans Mulder, Oct 31, 2012
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Big E

    Rookie Question

    Big E, Jun 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    368
    avnrao
    Jun 17, 2004
  2. Greg Smith

    Rookie question

    Greg Smith, Oct 7, 2005, in forum: Java
    Replies:
    4
    Views:
    369
    Monique Y. Mudama
    Oct 8, 2005
  3. Ian
    Replies:
    4
    Views:
    397
    Ian Rutgers
    Jan 22, 2005
  4. Don Bruder
    Replies:
    12
    Views:
    591
    Duncan Booth
    Sep 26, 2003
  5. Steve D. Perkins

    Rookie question about data types (hashtables)

    Steve D. Perkins, Jan 29, 2004, in forum: Python
    Replies:
    7
    Views:
    388
    Rainer Deyke
    Jan 29, 2004
Loading...

Share This Page