Making a .php page a .cgi page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew DeFaria

    Making a .php page a .cgi page

    I have somebody or some people who are abusing a Perl based .cgi script.
    I have written a PHP page which reports this abuse as per
    $_SERVER[REMOTE_ADDR]. My intentions were to replace the .cgi script
    with this .php script. Problem is these people are coming in with some
    web crawler or something like that (i.e. wget
    http://myserver.com/thescript.cgi). Now if I replace thescript.cgi with
    thescript.php they will not hit it. And if I replace thescript.cgi with
    my PHP page, because it's not a Perl script yet ends in .cgi Apache is
    saying "Exec format error: exec of '/path/to/script/thescript.cgi'
    failed". Is there a way I can configure Apache or otherwise have
    thescript.cgi execute PHP code (without crippling other .cgi Perl
    scripts on my site)?
    --
    Why do you always turn down your radio when looking for an address?
  • Colin McKinnon

    #2
    Re: Making a .php page a .cgi page

    Andrew DeFaria wrote:
    [color=blue]
    > I have somebody or some people who are abusing a Perl based .cgi script.
    > I have written a PHP page which reports this abuse as per
    > $_SERVER[REMOTE_ADDR]. My intentions were to replace the .cgi script
    > with this .php script. Problem is these people are coming in with some
    > web crawler or something like that (i.e. wget
    > http://myserver.com/thescript.cgi). Now if I replace thescript.cgi with
    > thescript.php they will not hit it. And if I replace thescript.cgi with
    > my PHP page, because it's not a Perl script yet ends in .cgi Apache is
    > saying "Exec format error: exec of '/path/to/script/thescript.cgi'
    > failed". Is there a way I can configure Apache or otherwise have
    > thescript.cgi execute PHP code (without crippling other .cgi Perl
    > scripts on my site)?[/color]

    Not really. You could try writing a wee wrapper in Perl to replace
    script.cgi which then calls the PHP script - but you won't be able to see
    most of the parameters.

    C.

    Comment

    • Daniel Tryba

      #3
      Re: Making a .php page a .cgi page

      Andrew DeFaria <Andrew@defaria .com> wrote:[color=blue]
      > And if I replace thescript.cgi with my PHP page, because it's not a
      > Perl script yet ends in .cgi Apache is saying "Exec format error: exec
      > of '/path/to/script/thescript.cgi' failed".[/color]

      Then you are doing something wrong. Extensions have no meaning, it's
      just a hint for humans (and that broken browser).
      [color=blue]
      > Is there a way I can configure Apache or otherwise have thescript.cgi
      > execute PHP code (without crippling other .cgi Perl scripts on my
      > site)?[/color]

      So a file named foo.cgi with a content like:
      #!/usr/bin/php4
      <?php
      echo "Hello World!";
      ?>

      doesn't work?

      Take a look at the Apaches RewriteEngine (mod_rewrite). Alternatively
      modify the existing cgi to redirect to the php script.

      Comment

      • Jerry Stuckle

        #4
        Re: Making a .php page a .cgi page

        Andrew DeFaria wrote:[color=blue]
        > I have somebody or some people who are abusing a Perl based .cgi script.
        > I have written a PHP page which reports this abuse as per
        > $_SERVER[REMOTE_ADDR]. My intentions were to replace the .cgi script
        > with this .php script. Problem is these people are coming in with some
        > web crawler or something like that (i.e. wget
        > http://myserver.com/thescript.cgi). Now if I replace thescript.cgi with
        > thescript.php they will not hit it. And if I replace thescript.cgi with
        > my PHP page, because it's not a Perl script yet ends in .cgi Apache is
        > saying "Exec format error: exec of '/path/to/script/thescript.cgi'
        > failed". Is there a way I can configure Apache or otherwise have
        > thescript.cgi execute PHP code (without crippling other .cgi Perl
        > scripts on my site)?[/color]

        You'll need to tell Apache to parse this file as PHP. I haven't tried
        it, but something like this might work in you httpd.conf:

        AddType application/x-httpd-php thescript.cgi

        If you don't have access to httpd.conf, you probably can add it to your
        ..htaccess file, but I haven't tried it.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Andrew DeFaria

          #5
          Re: Making a .php page a .cgi page

          Colin McKinnon wrote:
          [color=blue]
          > Andrew DeFaria wrote:
          >[color=green]
          >> I have somebody or some people who are abusing a Perl based .cgi
          >> script.I have written a PHP page which reports this abuse as per
          >> $_SERVER[REMOTE_ADDR]. My intentions were to replace the .cgi script
          >> with this .php script. Problem is these people are coming in with
          >> some web crawler or something like that (i.e. wget
          >> http://myserver.com/thescript.cgi). Now if I replace thescript.cgi
          >> with thescript.php they will not hit it. And if I replace
          >> thescript.cgi with my PHP page, because it's not a Perl script yet
          >> ends in .cgi Apache is saying "Exec format error: exec of
          >> '/path/to/script/thescript.cgi' failed". Is there a way I can
          >> configure Apache or otherwise have thescript.cgi execute PHP code
          >> (without crippling other .cgi Perl scripts on my site)?[/color]
          >
          > Not really. You could try writing a wee wrapper in Perl to replace
          > script.cgi which then calls the PHP script - but you won't be able to
          > see most of the parameters.[/color]

          I was wondering if a simple CGI script that redirects to a similarly
          named PHP page would work. I will try that tonight.
          --
          If I want your opinion, I'll ask you to fill out the necessary forms.

          Comment

          • Andrew DeFaria

            #6
            Re: Making a .php page a .cgi page

            Jerry Stuckle wrote:
            [color=blue]
            > Andrew DeFaria wrote:
            >[color=green]
            >> I have somebody or some people who are abusing a Perl based .cgi
            >> script. I have written a PHP page which reports this abuse as per
            >> $_SERVER[REMOTE_ADDR]. My intentions were to replace the .cgi script
            >> with this .php script. Problem is these people are coming in with
            >> some web crawler or something like that (i.e. wget
            >> http://myserver.com/thescript.cgi). Now if I replace thescript.cgi
            >> with thescript.php they will not hit it. And if I replace
            >> thescript.cgi with my PHP page, because it's not a Perl script yet
            >> ends in .cgi Apache is saying "Exec format error: exec of
            >> '/path/to/script/thescript.cgi' failed". Is there a way I can
            >> configure Apache or otherwise have thescript.cgi execute PHP code
            >> (without crippling other .cgi Perl scripts on my site)?[/color]
            >
            > You'll need to tell Apache to parse this file as PHP. I haven't tried
            > it, but something like this might work in you httpd.conf:
            >
            > AddType application/x-httpd-php thescript.cgi
            >
            > If you don't have access to httpd.conf, you probably can add it to
            > your .htaccess file, but I haven't tried it.[/color]

            That would cripple all the other .cgi Perl scripts on my site. I have
            configured the CGIType in Apache and normally I want .cgi files to
            execute Perl. But in this instance I want the .cgi to be executed by PHP.

            I may try a redirect later tonight. Either that or instead of a web page
            with embedded PHP I might try the shebang line of #!/usr/bin/php and
            have it write out all of the necessary HTML - you know the content
            header, etc...
            --
            It doesn't matter what you do in the bedroom as long as you don't do it
            in the street and frighten the horses

            Comment

            • Andrew DeFaria

              #7
              Re: Making a .php page a .cgi page

              Daniel Tryba wrote:
              [color=blue]
              > Andrew DeFaria <Andrew@defaria .com> wrote:
              >[color=green]
              >> And if I replace thescript.cgi with my PHP page, because it's not a
              >> Perl script yet ends in .cgi Apache is saying "Exec format error:
              >> exec of '/path/to/script/thescript.cgi' failed".[/color]
              >
              > Then you are doing something wrong. Extensions have no meaning, it's
              > just a hint for humans (and that broken browser).[/color]

              Extensions have meaning once meaning is assigned. I have configured the
              CGI type in Apache. Therefore Apache views all .cgi files a Perl scripts.
              [color=blue][color=green]
              >> Is there a way I can configure Apache or otherwise have thescript.cgi
              >> execute PHP code (without crippling other .cgi Perl scripts on my site)?[/color]
              >
              > So a file named foo.cgi with a content like:
              > #!/usr/bin/php4
              > <?php
              > echo "Hello World!";
              > ?>
              >
              > doesn't work?[/color]

              No it doesn't I got "malformed header from script. Bad header=Hello
              World!: foo.cgi"
              [color=blue]
              > Take a look at the Apaches RewriteEngine (mod_rewrite). Alternatively
              > modify the existing cgi to redirect to the php script.[/color]

              I suspect a better approach is to leave .cgi scripts alone and instead
              to do a redirect.
              --
              Why did kamikaze pilots wear helmets?

              Comment

              • Daniel Tryba

                #8
                Re: Making a .php page a .cgi page

                Andrew DeFaria <Andrew@defaria .com> wrote:

                Please don't post HTML (or any other attachments).
                [color=blue][color=green]
                >> Then you are doing something wrong. Extensions have no meaning, it's
                >> just a hint for humans (and that broken browser).[/color]
                >
                > Extensions have meaning once meaning is assigned. I have configured the
                > CGI type in Apache. Therefore Apache views all .cgi files a Perl scripts.[/color]

                A very unfortunate assignment.
                [color=blue][color=green]
                >> Take a look at the Apaches RewriteEngine (mod_rewrite). Alternatively
                >> modify the existing cgi to redirect to the php script.[/color]
                >
                > I suspect a better approach is to leave .cgi scripts alone and instead
                > to do a redirect.[/color]

                That is what the RewriteEngine can be used for...

                Comment

                • Zachary Kessin

                  #9
                  Re: Making a .php page a .cgi page

                  Andrew DeFaria <Andrew@DeFaria .com> writes:
                  [color=blue]
                  > I have somebody or some people who are abusing a Perl based .cgi
                  > script. I have written a PHP page which reports this abuse as per
                  > $_SERVER[REMOTE_ADDR]. My intentions were to replace the .cgi script
                  > with this .php script. Problem is these people are coming in with some
                  > web crawler or something like that (i.e. wget
                  > http://myserver.com/thescript.cgi). Now if I replace thescript.cgi
                  > with thescript.php they will not hit it. And if I replace
                  > thescript.cgi with my PHP page, because it's not a Perl script yet
                  > ends in .cgi Apache is saying "Exec format error: exec of
                  > '/path/to/script/thescript.cgi' failed". Is there a way I can
                  > configure Apache or otherwise have thescript.cgi execute PHP code
                  > (without crippling other .cgi Perl scripts on my site)?
                  > --
                  > Why do you always turn down your radio when looking for an address?[/color]

                  Use mod_rewrite, it can do what you want (I think)

                  --Zach

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: Making a .php page a .cgi page

                    Andrew DeFaria wrote:[color=blue]
                    > Jerry Stuckle wrote:
                    >[color=green]
                    >> Andrew DeFaria wrote:
                    >>[color=darkred]
                    >>> I have somebody or some people who are abusing a Perl based .cgi
                    >>> script. I have written a PHP page which reports this abuse as per
                    >>> $_SERVER[REMOTE_ADDR]. My intentions were to replace the .cgi script
                    >>> with this .php script. Problem is these people are coming in with
                    >>> some web crawler or something like that (i.e. wget
                    >>> http://myserver.com/thescript.cgi). Now if I replace thescript.cgi
                    >>> with thescript.php they will not hit it. And if I replace
                    >>> thescript.cgi with my PHP page, because it's not a Perl script yet
                    >>> ends in .cgi Apache is saying "Exec format error: exec of
                    >>> '/path/to/script/thescript.cgi' failed". Is there a way I can
                    >>> configure Apache or otherwise have thescript.cgi execute PHP code
                    >>> (without crippling other .cgi Perl scripts on my site)?[/color]
                    >>
                    >>
                    >> You'll need to tell Apache to parse this file as PHP. I haven't tried
                    >> it, but something like this might work in you httpd.conf:
                    >>
                    >> AddType application/x-httpd-php thescript.cgi
                    >>
                    >> If you don't have access to httpd.conf, you probably can add it to
                    >> your .htaccess file, but I haven't tried it.[/color]
                    >
                    >
                    > That would cripple all the other .cgi Perl scripts on my site. I have
                    > configured the CGIType in Apache and normally I want .cgi files to
                    > execute Perl. But in this instance I want the .cgi to be executed by PHP.
                    >
                    > I may try a redirect later tonight. Either that or instead of a web page
                    > with embedded PHP I might try the shebang line of #!/usr/bin/php and
                    > have it write out all of the necessary HTML - you know the content
                    > header, etc...[/color]

                    Andrew,

                    No, it will only execute "thescript.cgi" . If you put in there "*.cgi"
                    it would cripple all the other scripts.



                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    Working...