[EMAIL PROTECTED]:

I am getting ready to study "MySQL and Perl for the Web" [Paul DuBois,
2002] and I have come across some baffling behavior with CGI scripts on
Apache 1.3.26 on Debian 3.0r1 -- sometimes Apache executes the scripts
as expected, other times it tries to download them or generates an
error.  The behavior seems to depend on the script name, not the
content.  The gory details follow.


Following the directions on:

http://httpd.apache.org/docs/howto/cgi.html#cgioutsideofscriptaliasdirectories


I have added the following lines to the main Apache configuration file:

    [EMAIL PROTECTED]:~/d3020g/etc/apache:CVS> cvs -q diff httpd.conf
    Index: httpd.conf
    ===================================================================
    RCS file: /cvs/dpchrist/d3020g/etc/apache/httpd.conf,v
    retrieving revision 1.1
    diff -r1.1 httpd.conf
    378a379,382
    > <Directory /home/dpchrist/public_html/cgi-bin>
    >     Options ExecCGI
    > </Directory>
    >
    780a785
    >     AddHandler cgi-script pl


I loaded the configuration:

    [EMAIL PROTECTED]:~/d3020g/etc/apache:CVS> cp httpd.conf /etc/apache/.
    cp: overwrite `/etc/apache/./httpd.conf'? y

    [EMAIL PROTECTED]:~/d3020g/etc/apache:CVS> apachectl configtest
    [Mon Sep 29 22:57:33 2003] [warn] module config_log_module is
already loaded, skipping
    [Mon Sep 29 22:57:33 2003] [warn] module mime_module is already
loaded, skipping

    [Mon Sep 29 22:57:33 2003] [alert] apache: Could not determine the
server's fully qualified domain name, using 192.168.254.2 for ServerName
    Syntax OK

    [EMAIL PROTECTED]:~/d3020g/etc/apache:CVS> apachectl graceful
    /usr/sbin/apachectl graceful: httpd gracefully restarted


I then put Perl CGI scripts into /home/dpchrist/public_html/cgi-bin and
attempted to access them via the URL
http://192.168.254.2/~dpchrist/cgi-bin/*.  Some scripts are executed
while others do various naughty
things.  Here are some scripts that execute as expected in Mozilla 1.4
and Internet Explorer 6.0.2800.1106:

1.  [EMAIL PROTECTED]:~/public_html/cgi-bin:CVS> cat foo.pl
    #! /usr/bin/perl
    print "Content-type: text/html\r\n\r\n";
    print "Hello, World.";

2.  [EMAIL PROTECTED]:~/public_html/cgi-bin:CVS> cat intro4.pl
    #!/usr/bin/perl -w
    use strict;

    use CGI;
    my $cgi = new CGI;

    print $cgi->header(),
        $cgi->start_html("My Page Title"),
        $cgi->p("My page body"),
        $cgi->end_html(),
        "\n";

    exit(0);

3.  [EMAIL PROTECTED]:~/public_html/cgi-bin:CVS> cat intro5.pl
    #!/usr/bin/perl -w
    use strict;

    use CGI qw( :standard );

    print header(),
        start_html("My Page Titel"),
        p("My page body"),
        end_html(),
        "\n";

    exit(0);

And here is one that Mozilla attempts to download, while IE says "The
page cannot be found":

    [EMAIL PROTECTED]:~/public_html/cgi-bin:CVS> cat intro3.pl
    #!/usr/bin/perl -w
    use strict;

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

    print <<END;
    <html>
    <head><title>My Page Title</title></head>
    <body><p>My page body</p></body>
    </html>
    END
    exit(0);


The really weird part is that if I rename a "bad" script to a "good"
name, it then executes!

    [EMAIL PROTECTED]:~/public_html/cgi-bin:CVS> mv intro3.pl bar.pl


Here are the Apache logs:

    [EMAIL PROTECTED]:/var/log/apache# tail -n 4 access.log
    192.168.1.10 - - [29/Sep/2003:23:01:55 -0700] "GET
/~dpchrist/cgi-bin/foo.pl HTTP/1.1" 200 25 "-" "Mozilla/5.0 (Windows; U;
Windows NT 5.0; en-US; rv:1.4) Gecko/20030624"
    192.168.1.10 - - [29/Sep/2003:23:02:07 -0700] "GET
/~dpchrist/cgi-bin/intro4.pl HTTP/1.1" 200 301 "-" "Mozilla/5.0
(Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624"
    192.168.1.10 - - [29/Sep/2003:23:02:15 -0700] "GET
/~dpchrist/cgi-bin/intro5.pl HTTP/1.1" 200 301 "-" "Mozilla/5.0
(Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624"
    192.168.1.10 - - [29/Sep/2003:23:02:38 -0700] "GET
/~dpchrist/cgi-bin/bar.pl HTTP/1.1" 200 102 "-" "Mozilla/5.0 (Windows;
U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624"

    [EMAIL PROTECTED]:/var/log/apache# tail -n 8 error.log
    [Mon Sep 29 22:57:58 2003] [notice] SIGUSR1 received.  Doing
graceful restart
    [Mon Sep 29 22:57:58 2003] [warn] module config_log_module is
already loaded, skipping
    [Mon Sep 29 22:57:58 2003] [warn] module mime_module is already
loaded, skipping

    [Mon Sep 29 22:57:58 2003] [alert] apache: Could not determine the
server's fully qualified domain name, using 192.168.254.2 for ServerName
    [Mon Sep 29 22:57:59 2003] [error] (2)No such file or directory:
mod_mime_magic: can't read magic file /etc/apache/share/magic
    [Mon Sep 29 22:57:59 2003] [notice] Apache/1.3.26 (Unix) Debian
GNU/Linux configured -- resuming normal operations
    [Mon Sep 29 22:57:59 2003] [notice] suEXEC mechanism enabled
(wrapper: /usr/lib/apache/suexec)
    [Mon Sep 29 22:57:59 2003] [notice] Accept mutex: sysvsem (Default:
sysvsem)

    [EMAIL PROTECTED]:/var/log/apache# tail -n 4 suexec.log
    [2003-09-29 23:01:55]: info: (target/actual) uid:
(dpchrist/dpchrist) gid: (dpchrist/dpchrist) cmd: foo.pl
    [2003-09-29 23:02:06]: info: (target/actual) uid:
(dpchrist/dpchrist) gid: (dpchrist/dpchrist) cmd: intro4.pl
    [2003-09-29 23:02:15]: info: (target/actual) uid:
(dpchrist/dpchrist) gid: (dpchrist/dpchrist) cmd: intro5.pl
    [2003-09-29 23:02:38]: info: (target/actual) uid:
(dpchrist/dpchrist) gid: (dpchrist/dpchrist) cmd: bar.pl


Here is the script directory:

    [EMAIL PROTECTED]:~/public_html/cgi-bin:CVS> ls -al
    total 36
    drwxr-xr-x    3 dpchrist dpchrist     4096 Sep 29 23:04 .
    drwxr-xr-x    4 dpchrist dpchrist     4096 Sep 28 21:41 ..
    drwxr-xr-x    2 dpchrist dpchrist     4096 Sep 29 23:04 CVS
    -rwxr-xr-x    1 dpchrist dpchrist      186 Sep 29 22:42 bar.pl
    -rwxr-xr-x    1 dpchrist dpchrist       81 Sep 29 17:46 foo.pl
    -rwxr-xr-x    1 dpchrist dpchrist      186 Sep 29 23:04 intro3.pl
    -rwxr-xr-x    1 dpchrist dpchrist      193 Sep 29 22:42 intro4.pl
    -rwxr-xr-x    1 dpchrist dpchrist      166 Sep 29 22:42 intro5.pl
    -rwxr-xr-x    1 dpchrist dpchrist      747 Sep 29 22:42 intro7.pl


Any ideas?


TIA,

David



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to