Loading ...
Sorry, an error occurred while loading the content.

Re: running scripts from html pages served by thttpd (UNSLUNG 6.8)

Expand Messages
  • Rob Conway
    I only have the standard thttpd services running, and was hoping I could easily start a script on the slug from a web page button. I looked at the linksys
    Message 1 of 6 , Aug 2, 2006
    • 0 Attachment
      I only have the standard thttpd services running, and was hoping I could easily start a script on the slug from a web page button.  I looked at the linksys pages for telnet enabling and this just seems to use "post" method and run a cgi file.  The telnet cgi file is not a script file though
      Can someone confirm how I get a simple bash script to run from a html web button PLEASE :) I DO NOT want to have to load apache PHP mysql etc etc as my web page requirements are minimal.
       
      Is it as simple as saving my bash script as xxx.cgi  I want my script to run with root privlidges.
       
      cheers
       
      rob
    • Marcel Nijenhof
      ... But there is no problem to place a script there with the name script.cgi . It will be executed if you call that page. See ipkg-web as example:
      Message 2 of 6 , Aug 2, 2006
      • 0 Attachment
        On Thu, 2006-08-03 at 07:47 +1000, Rob Conway wrote:
        > I only have the standard thttpd services running, and was hoping I
        > could easily start a script on the slug from a web page button. I
        > looked at the linksys pages for telnet enabling and this just seems to
        > use "post" method and run a cgi file. The telnet cgi file is not a
        > script file though.

        But there is no problem to place a script there with the name
        "script.cgi". It will be executed if you call that page.

        See "ipkg-web" as example:
        http://svn.nslu2-linux.org/svnroot/optware/trunk/sources/ipkg-web/package.cgi

        --
        marceln
      • Fernando Carolo
        ... script to run with root privlidges. Rob, I did some tests and it was quite esy to run a shell script as a .cgi under thttpd. These are the steps I had to
        Message 3 of 6 , Aug 3, 2006
        • 0 Attachment
          --- In nslu2-linux@yahoogroups.com, "Rob Conway" <rjconway@...> wrote:
          >
          > Is it as simple as saving my bash script as xxx.cgi I want my
          script to run with root privlidges.

          Rob,

          I did some tests and it was quite esy to run a shell script as a .cgi
          under thttpd. These are the steps I had to follow:

          - make sure your script starts with "#!/bin/sh", so it can be
          identified as a shell script that could be run directly;

          - make sure your script has a name ending in ".cgi", this is a
          requirement from the thttpd configuration under Unslung;

          - put your script under /home/httpd/html, or better, under
          /home/httpd/html/Management, together with the other cgi programs;

          - make sure the permissions for the script are 755 (-rwxr-xr-x), so do
          not forget to "chmod 755 your.cgi".

          For a quick test, you can copy the following script, paste it into an
          editor and save it as /home/httpd/html/Management/test.cgi. It is
          actually the test-cgi script from the default Apache distribution, but
          it runs perfectly under thttpd. Save it as test.cgi, adjust its
          permissions ("chmod 755 test.cgi") then point your browser to
          http://your_slug/Management/test.cgi.

          Regards,

          Fernando Carolo

          -----8<-----cut here-----8<-----
          #!/bin/sh
          # disable filename globbing
          set -f

          echo Content-type: text/plain
          echo

          echo CGI/1.0 test script report:
          echo

          echo argc is $#. argv is "$*".
          echo

          echo SERVER_SOFTWARE = $SERVER_SOFTWARE
          echo SERVER_NAME = $SERVER_NAME
          echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE
          echo SERVER_PROTOCOL = $SERVER_PROTOCOL
          echo SERVER_PORT = $SERVER_PORT
          echo REQUEST_METHOD = $REQUEST_METHOD
          echo HTTP_ACCEPT = "$HTTP_ACCEPT"
          echo PATH_INFO = "$PATH_INFO"
          echo PATH_TRANSLATED = "$PATH_TRANSLATED"
          echo SCRIPT_NAME = "$SCRIPT_NAME"
          echo QUERY_STRING = "$QUERY_STRING"
          echo REMOTE_HOST = $REMOTE_HOST
          echo REMOTE_ADDR = $REMOTE_ADDR
          echo REMOTE_USER = $REMOTE_USER
          echo AUTH_TYPE = $AUTH_TYPE
          echo CONTENT_TYPE = $CONTENT_TYPE
          echo CONTENT_LENGTH = $CONTENT_LENGTH
          -----8<-----cut here-----8<-----
        • Rob Conway
          Hi fernando, I got my script to run with your assistance, however a little strange. II have changed through the linksys interface the admin port number to
          Message 4 of 6 , Aug 21, 2006
          • 0 Attachment
            Hi fernando,
            I got my script to run with your assistance, however a little strange.
             
            II have changed through the linksys interface the admin port number to  8081.  My web server thttpd using port 80.  I think cgi scripts need to us port 8081
             
            So from my html page (hosted by thttpd) I have created a link to http://xxx.xxx.x.xx:8081/hope1.cgi  I can then run this file.  I think if its the ./management directory it has the linksys password implemeneted somehow, so moving it to /home/httpd/html works ok.
             
            Now my problem..My script runs does its script stuff and I want to return to my original webpage from which it was called. 
            Reading cgi I think I use the Location:webpage.html   to simply specifiy the web page to call up and it works whilst the webpage is on port 8081
             
            As my site is using port 80 the cgi always seems to append my location with  http://xxx.xxx.x.xx:8081/ I'm not sure what variables hold the original site adress which called the script.  I've tried to reset the path_info variable.
             
            any help appreciated...the good news for me as at least I can get scripts to run,,,now to retrun to the webpage !
             
            cheers  from australia
             
             
             
             
            ----- Original Message -----
            Sent: Friday, August 04, 2006 12:52 AM
            Subject: [nslu2-linux] Re: running scripts from html pages served by thttpd (UNSLUNG 6.8)

            --- In nslu2-linux@ yahoogroups. com, "Rob Conway" <rjconway@.. .> wrote:
            >
            > Is it as simple as saving my bash script as xxx.cgi I want my
            script to run with root privlidges.

            Rob,

            I did some tests and it was quite esy to run a shell script as a .cgi
            under thttpd. These are the steps I had to follow:

            - make sure your script starts with "#!/bin/sh", so it can be
            identified as a shell script that could be run directly;

            - make sure your script has a name ending in ".cgi", this is a
            requirement from the thttpd configuration under Unslung;

            - put your script under /home/httpd/ html, or better, under
            /home/httpd/ html/Management, together with the other cgi programs;

            - make sure the permissions for the script are 755 (-rwxr-xr-x) , so do
            not forget to "chmod 755 your.cgi".

            For a quick test, you can copy the following script, paste it into an
            editor and save it as /home/httpd/ html/Management/ test.cgi. It is
            actually the test-cgi script from the default Apache distribution, but
            it runs perfectly under thttpd. Save it as test.cgi, adjust its
            permissions ("chmod 755 test.cgi") then point your browser to
            http://your_ slug/Management/ test.cgi.

            Regards,

            Fernando Carolo

            -----8<----- cut here-----8<- ----
            #!/bin/sh
            # disable filename globbing
            set -f

            echo Content-type: text/plain
            echo

            echo CGI/1.0 test script report:
            echo

            echo argc is $#. argv is "$*".
            echo

            echo SERVER_SOFTWARE = $SERVER_SOFTWARE
            echo SERVER_NAME = $SERVER_NAME
            echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE
            echo SERVER_PROTOCOL = $SERVER_PROTOCOL
            echo SERVER_PORT = $SERVER_PORT
            echo REQUEST_METHOD = $REQUEST_METHOD
            echo HTTP_ACCEPT = "$HTTP_ACCEPT"
            echo PATH_INFO = "$PATH_INFO"
            echo PATH_TRANSLATED = "$PATH_TRANSLATED"
            echo SCRIPT_NAME = "$SCRIPT_NAME"
            echo QUERY_STRING = "$QUERY_STRING"
            echo REMOTE_HOST = $REMOTE_HOST
            echo REMOTE_ADDR = $REMOTE_ADDR
            echo REMOTE_USER = $REMOTE_USER
            echo AUTH_TYPE = $AUTH_TYPE
            echo CONTENT_TYPE = $CONTENT_TYPE
            echo CONTENT_LENGTH = $CONTENT_LENGTH
            -----8<----- cut here-----8<- ----

          • Rob Conway
            Dumb question sorry....forgot to put the echo in the command echo Location:http:/xxxxxxx cheers ... From: Rob Conway To: nslu2-linux@yahoogroups.com Sent:
            Message 5 of 6 , Aug 21, 2006
            • 0 Attachment
              Dumb question sorry....forgot to put the echo in the command
               
              echo "Location:http:/xxxxxxx"
               
              cheers
               
              ----- Original Message -----
              Sent: Tuesday, August 22, 2006 11:42 AM
              Subject: Re: [nslu2-linux] Re: running scripts from html pages served by thttpd (UNSLUNG 6.8)

              Hi fernando,
              I got my script to run with your assistance, however a little strange.
               
              II have changed through the linksys interface the admin port number to  8081.  My web server thttpd using port 80.  I think cgi scripts need to us port 8081
               
              So from my html page (hosted by thttpd) I have created a link to http://xxx.xxx. x.xx:8081/ hope1.cgi  I can then run this file.  I think if its the ./management directory it has the linksys password implemeneted somehow, so moving it to /home/httpd/ html works ok.
               
              Now my problem..My script runs does its script stuff and I want to return to my original webpage from which it was called. 
              Reading cgi I think I use the Location:webpage. html   to simply specifiy the web page to call up and it works whilst the webpage is on port 8081
               
              As my site is using port 80 the cgi always seems to append my location with  http://xxx.xxx. x.xx:8081/ I'm not sure what variables hold the original site adress which called the script.  I've tried to reset the path_info variable.
               
              any help appreciated. ..the good news for me as at least I can get scripts to run,,,now to retrun to the webpage !
               
              cheers  from australia
               
               
               
               
              ----- Original Message -----
              Sent: Friday, August 04, 2006 12:52 AM
              Subject: [nslu2-linux] Re: running scripts from html pages served by thttpd (UNSLUNG 6.8)

              --- In nslu2-linux@ yahoogroups. com, "Rob Conway" <rjconway@.. .> wrote:
              >
              > Is it as simple as saving my bash script as xxx.cgi I want my
              script to run with root privlidges.

              Rob,

              I did some tests and it was quite esy to run a shell script as a .cgi
              under thttpd. These are the steps I had to follow:

              - make sure your script starts with "#!/bin/sh", so it can be
              identified as a shell script that could be run directly;

              - make sure your script has a name ending in ".cgi", this is a
              requirement from the thttpd configuration under Unslung;

              - put your script under /home/httpd/ html, or better, under
              /home/httpd/ html/Management, together with the other cgi programs;

              - make sure the permissions for the script are 755 (-rwxr-xr-x) , so do
              not forget to "chmod 755 your.cgi".

              For a quick test, you can copy the following script, paste it into an
              editor and save it as /home/httpd/ html/Management/ test.cgi. It is
              actually the test-cgi script from the default Apache distribution, but
              it runs perfectly under thttpd. Save it as test.cgi, adjust its
              permissions ("chmod 755 test.cgi") then point your browser to
              http://your_ slug/Management/ test.cgi.

              Regards,

              Fernando Carolo

              -----8<----- cut here-----8<- ----
              #!/bin/sh
              # disable filename globbing
              set -f

              echo Content-type: text/plain
              echo

              echo CGI/1.0 test script report:
              echo

              echo argc is $#. argv is "$*".
              echo

              echo SERVER_SOFTWARE = $SERVER_SOFTWARE
              echo SERVER_NAME = $SERVER_NAME
              echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE
              echo SERVER_PROTOCOL = $SERVER_PROTOCOL
              echo SERVER_PORT = $SERVER_PORT
              echo REQUEST_METHOD = $REQUEST_METHOD
              echo HTTP_ACCEPT = "$HTTP_ACCEPT"
              echo PATH_INFO = "$PATH_INFO"
              echo PATH_TRANSLATED = "$PATH_TRANSLATED"
              echo SCRIPT_NAME = "$SCRIPT_NAME"
              echo QUERY_STRING = "$QUERY_STRING"
              echo REMOTE_HOST = $REMOTE_HOST
              echo REMOTE_ADDR = $REMOTE_ADDR
              echo REMOTE_USER = $REMOTE_USER
              echo AUTH_TYPE = $AUTH_TYPE
              echo CONTENT_TYPE = $CONTENT_TYPE
              echo CONTENT_LENGTH = $CONTENT_LENGTH
              -----8<----- cut here-----8<- ----

            • Fernando Carolo
              Hi Rob, ... to 8081. My web server thttpd using port 80. I think cgi scripts need to us port 8081 There is no special requirement for cgi scripts that they
              Message 6 of 6 , Aug 24, 2006
              • 0 Attachment
                Hi Rob,

                --- In nslu2-linux@yahoogroups.com, "Rob Conway" <rjconway@...> wrote:
                >
                > Hi fernando,
                > I got my script to run with your assistance, however a little strange.
                >
                > II have changed through the linksys interface the admin port number
                to 8081. My web server thttpd using port 80. I think cgi scripts
                need to us port 8081

                There is no special requirement for cgi scripts that they must (or
                even should) be run from a web server on a port number other than 80,
                but this won't hurt either.

                > So from my html page (hosted by thttpd) I have created a link to
                http://xxx.xxx.x.xx:8081/hope1.cgi I can then run this file. I think
                if its the ./management directory it has the linksys password
                implemeneted somehow, so moving it to /home/httpd/html works ok.

                Yes, the /Management directory has access control. You can do a "ls
                -a" inside it and you will see a .htpasswd file, meaning it can only
                be accessed by users listed in that file. If you want to be able to
                run your scripts without authenticating as admin, you can keep them in
                the top directory, or even create your own directory inside
                /home/httpd/html and place your scripts there.

                > Now my problem..My script runs does its script stuff and I want to
                return to my original webpage from which it was called.
                > Reading cgi I think I use the Location:webpage.html to simply
                specifiy the web page to call up and it works whilst the webpage is on
                port 8081
                >
                > As my site is using port 80 the cgi always seems to append my
                location with http://xxx.xxx.x.xx:8081/ I'm not sure what variables
                hold the original site adress which called the script. I've tried to
                reset the path_info variable.

                Every time you make an HTTP request to a server it must answer with a
                status code. When you add a "Location:" header, the server generates a
                302 status code, which means to the browser that it must fetch another
                document on another URL. Technically, this header must include a full,
                absolute URL starting with "http://", but most browsers will handle a
                relative URL and interpret it according to the original document being
                requested. In other words, the browser will look for the page
                mentioned in the Location: header in the same server. In HTTP terms, a
                server listening on a different port in the same machine is considered
                a different server, as if it were located on a different host.

                An example: if you request your cgi script on
                "http://yourslug:80801/script.cgi" and the script echoes back a
                "Location: /webpage.html" header, the browser believes that the page
                os located on the same server, on the same port. Therefore, it will
                look for "http://yourslug:80801/webpage.html".

                You want to redirect your clients to a web page on the default server
                on port 80, then your Location must point explicity to that server
                using an absolute URL. In the example, you should use "Location:
                http://yourslug/webpage.html", or "Location:
                http://${SERVER_NAME}/webpage.html" if it is a shell script.

                Regards,

                Fernando
              Your message has been successfully submitted and would be delivered to recipients shortly.