1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

web server

Discussion in 'Tomato Firmware' started by puffer, Jul 5, 2007.

  1. puffer

    puffer Network Guru Member

    First off I want to say I understand Tomato has to be light and fast. I was thinking that it is already serving web pages. Is there a way to have it host a website on port 80 and have the internal web config moved to port 8080 or something? I would like to just set up a simple site. How easy or hard would this be? Thanks
  2. mikester

    mikester Network Guru Member

    You would need to add a new web server daemon that didn't require a log on password, otherwise you can add web pages that are viewable after logging in. You can put the web pages in a CIFS directory. The easiest thing to do is to route/port forward open web pages to a web server somewhere on your network.
  3. puffer

    puffer Network Guru Member

    k figured a few things out... don't laugh I an new at this stuff. K a Daemon seems to be like a windows service or a running process anyway httpd -p 8080 would set up another http server on whatever directory I run it from as the default. question is how do i change the default router web interface port from 80 to something eles?
  4. mikester

    mikester Network Guru Member

    download the source code, add your desired packages, recompile new firmware on a linux box, upload new firmware, test it
  5. silentaccord

    silentaccord Network Guru Member

    I haven't tried this but you might be able to free up port 80 by setting Tomato's web admin to use only HTTPS which would be port 443. Another option would be to use port forwarding to redirect external port 80 to whatever internal port you start the server on. But I don't think you'll be able to host your site with the built in httpd because it doesn't allow you to specify a directory. If I'm wrong about this, someone please correct me.

    I have a method for running a second web server with Tomato that stores everything locally on the router. The only problem is that it stores it in /tmp which is lost when the router reboots. You'll need another web or ftp server, either inside or outside your LAN, that the router can download the files from when it starts up. If you're interested in this method, let me know and I can post details.
  6. mikester

    mikester Network Guru Member

    please post it, I'd like to try!

    You mean you don't need to log in as admin to view the web page? I ended up putting my own web pages on /CIFS as it makes it easier to test and modify the code on a network share rather than rebuilding the firmware each time.

  7. puffer

    puffer Network Guru Member

    It uses whatever directory you invoke the httpd -p 8080 from otherwise no you cannot specify the directory.

    Usage: httpd [options]
    -d Debug mode / do not demonize
    -p <port> Port to listen on
    -s Use HTTPS

    Two great solutions you can up with.Thanks!

    The port forward I forgot you can redirect to a different port.. I think I like the https 443 solution better though.. Good point about the tmp directory. isn't there a directory I could put the web page in that would not be reset? I do have a networked usbhub that has a usb flashed drive in it acting as a smb share and ftp. Not sure the wget lets you specify username and password though..

    EDIT: I can pass the username an password in ftp duh.... wget ftp://username:password@ Sillentaccord I have no idea how to do a script if you could put some sample up.... The Problem now for me is the wget only lets me specify 1 file at a time any idea how I could specify more than 1 file. I tried *.* I tried just the directory wait wget is just for files is there a wdirget or something ( I am thinking aloud again sry) going to check into this.
  8. silentaccord

    silentaccord Network Guru Member

    Here is the method I use. The instructions are written for Tomato but the same basic procedure should work with other firmware projects too. There's no login required to view pages hosted this way because the router downloads a copy of busybox and uses it to start the web server instead of the built-in httpd. The file attached to this post contains an example index.html file and an example httpd.conf file which is only needed if you want CGI scripting (this is what I use the web server for). I would have included a copy of busybox but it's too large to upload to the forum. You can get a copy by downloading BatBox: http://www.batbox.org/wrt54g-linux.html. When you unpack the downloaded archive, all you need is the file called "busybox" and you can discard everything else.

    Once you get the files on a web or ftp server that your router can access, go the the Admin-Scripts page of Tomato's configuration (e.g., Add these lines to the Init (startup) script:
    sleep 20
    mkdir -p /var/bin/web
    wget -P /var/bin/ [url]http://location_of_files/busybox[/url]
    wget -P /var/bin/web/ [url]http://location_of_files/index.html[/url]
    ln -s /var/bin/busybox /var/bin/web/httpd
    chmod 755 /var/bin/busybox
    /var/bin/web/httpd -p 81 -h /var/bin/web/
    And add this line to the Firewall script:
    iptables -I INPUT -p tcp --dport 81 -j ACCEPT
    Then reboot the router to test it.

    The sleep command is there because I had to make sure the router was fully booted before the script ran. You can adjust the time or remove the command to suit your needs. If you host the files on an ftp server, you can try ftpget instead of wget. I don't think ftpget allows you to specify the destination directory so you may need to add lines to the script to cd to the destination directories before downloading the files. The number in the last line of the init script and in the firewall script is the port the server runs on. You can change it to whatever you like except for any port already in use by the built-in web server, ssh daemon, or telnet daemon.

    If you want the ability to run CGI scripts from the web server, use this modified init script instead of the one above (the firewall script remains the same):
    sleep 20
    mkdir -p /var/bin/web/cgi-bin
    wget -P /var/bin/ [url]http://location_of_files/busybox[/url]
    wget -P /var/bin/ [url]http://location_of_files/httpd.conf[/url]
    wget -P /var/bin/web/ [url]http://location_of_files/index.html[/url]
    wget -P /var/bin/web/cgi-bin [url]http://location_of_files/your_script.cgi[/url]
    ln -s /var/bin/busybox /var/bin/web/httpd
    chmod -R 755 /var/bin/
    /var/bin/web/httpd -p 81 -h /var/bin/web/ -c /var/bin/web/httpd.conf

    Attached Files:

  9. mikester

    mikester Network Guru Member

    Cool, will try

    Question - why am I thinking busybox is already on tomato? Am I thinking of something else?
  10. silentaccord

    silentaccord Network Guru Member

    There is a version of busybox already in tomato but I don't know of a way to use its httpd without requiring authentication. That's why I use another copy to start the web server.
  11. puffer

    puffer Network Guru Member

    Could be wrong here but i think if you use httpd with just the port # it will not require login... I can never be sure cause sometimes it keeps me logged in

Share This Page