Running A Script From The Browser

Discussion in 'Tomato Firmware' started by tx33, Jul 30, 2008.

  1. tx33

    tx33 Addicted to LI Member

    I have a simple shell script that I would like to call from a web browser.

    Here is how my script starts:
    I've attempted to place my script, named, in the wwwext folder as outlined in I've given it execute privileges, but I get a 404 error when I attempt to navigate to How can I do this? Can ASP files run shell commands?
  2. fyellin

    fyellin LI Guru Member

    I'm pretty sure that what you're trying to do isn't currently supported. Tomato will display .asp files that are in the wwwext folder, but it doesn't have support for user-defined executables.

    Support for code execution is hard-wired. Certain "commands" execute certain subroutines that are hardwired in the httpd server. If you do find out a way to do this, let us know.
  3. HennieM

    HennieM Network Guru Member

    When a web server gets

    GET /somefile
    POST /somefile

    it attempts to read that file and display it on the calling browser.

    Therefore, web servers have certain directories marked as "execute rather than display". These are commonly known as the cgi-bin dirs.

    Tomato's web server seems to have those executable files complied into the binary, so there's probably no executable dir defined in Tomato's web server.

    Further, Tomato seems to have some protection in that it does not read files with .sh extension. If you rename your file run.txt, and then go, Tomato will display the file's content in your browser.

    So, bottom line, I don't think there's a way to run a script on Tomato via a browser. What you might consider, is running the script via telnet (or ssh) like this from the remote machine:
    ( commands to execute .... ) | telnet tomato.IP.address
    Google for "automating telnet scripts" or something like that.
  4. tx33

    tx33 Addicted to LI Member

    My "script" really only consists of a single iptables command. Is there any way to code this in ASP? Or perhaps, can ASP execute a shell script? I know that Tomato doesn't really parse ASP, but it should be able to do at least one of these things, I'm just not sure how Tomato's ASP parsing works.
  5. fyellin

    fyellin LI Guru Member

    You can probably write an .asp page that changes the value of an nvram variable in a specific way. A separate start-up script could then poll this variable periodically (once a minute??) to see if it has changed, and if so, to execute the action you want.

    But there is no way that I know of to directly execute a piece of code.

    Is there a specific reason this action needs to happen via a browser window, rather than via your ssh'ing or telnet'ing into the machine?
  6. tx33

    tx33 Addicted to LI Member

    I prefer using the browser over telnet or ssh for two reasons. Firstly, this script will be executed from another script. It is far easier to call a web page from a script than to setup telnet or ssh login and commands. Secondly, this script will be called several times per hour and should execute quickly. Loading a web page is far quicker than logging in to telnet or ssh.
  7. fyellin

    fyellin LI Guru Member

    Two quick questions:
    • Do you know how to set up your router so that you can ssh directly into it?
    • Do you know how to set up public/private keys for ssh so that you can securely log into the router without a password?
    Once you have those set up, you can easily execute commands remotely like:
    ssh -p 1234 /usr/sbin/iptables --list
    and the command is run on the router.

    (Obviously, replace 1234 and with whatever is appropriate for your machine).

    This is far simpler (and more secure!) than accessing a URL.
  8. HennieM

    HennieM Network Guru Member

    As mentioned, you need cgi-bin stuff, and Tomato's web server does not have that defined. Don't confuse the .asp extension on files with MS's ASP stuff. You can call a web page by any name you want, Tomato just happened to use .asp.

    The ssh shell exec suggested by fyellin, if run from a batch file, would be much faster than what you can do with a browser or wget I would think....
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice