WEB server

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 14:06, 16 May 2010 (edit)
Glenn (Talk | contribs)
(restore cat)
← Previous diff
Revision as of 16:59, 13 September 2010 (edit) (undo)
Magick777 (Talk | contribs)
(WEB server with v24 RC5)
Next diff →
Line 116: Line 116:
nvram commit nvram commit
reboot reboot
 +
 += WEB server with v24-preSP2 =
 +
 +Under v24-preSP2 it is possible to serve static HTML pages '''using the existing web server''' by symlinking them into the www/user directory, for example with
 +
 + mkdir /jffs/www
 + echo "test page" > /jffs/www/test.htm
 + ln -sf /jffs/www /www/user
 +
 +Arrange to create the symbolic link on startup, then pages from jffs/www can be served up as http://router.address/user/page.htm. This does mean that your info site & DD-WRT management page will be available on the same http server, so choose a strong password. However, this saves both the complexities and the memory usage of running two HTTP servers.
=How to access/edit pages= =How to access/edit pages=

Revision as of 16:59, 13 September 2010

DD-WRT runs a small httpd server used for configuring the router. This guide will show how to use it to serve you own pages to your LAN or to the world. Please remember that opening WEB server to the world could be potential security problem.

Contents

Assumptions

- You have telnet and SSH enabled on your router. See Telnet/SSH_and_the_Command_Line.
- You can send files via SSH to and from your desktop (e.g with WinSCP)
- You have jffs enabled and enough free space to store your files or you have working mmc mod.
- I will assume you are installing to the jffs partition. If you are not, replace jffs with mmc or some other folder
- You have the "Enable Info Site" enabled (Administration -> Management -> WEB Access)
- Optional: you have the "Wireless GUI Access" enabled (Wireless -> Advanced Settings)
- You MUST name your index file Info.htm (note upper case "I", thus "Info.htm" and NOT "info.htm")

How will this work?
- We will move the router's web admin to port 81
- We will start your WEB server at port 80
- Optional: we will open port 80 to the world

Procedure

For DD-WRT V23 SP2, the Info.htm doesn't work. Disable Info Site, and stay away of the router main pages or it will override your webpages. Please see the relevant discussion on the talk page for further details.

1) Copy your files to the router, i.e. to the /jffs folder
2) Open web admin Administration -> Diagnostics, press "Run"
3) Enter these lines to the Commands field:

killall httpd
cd /www
httpd -p 81 -h /www
cd /jffs
httpd -h /jffs

4) Press "Save Startup", the router will reboot or reboot it manually.


Optional: open to the world

1) Open web admin Administration -> Diagnostics, press "Run"
2) Enter this line to the Commands field:

/usr/sbin/iptables -I INPUT 1 -p tcp --dport 80 -j logaccept

3) Press "Save Firewall", the router will reboot or reboot it manually.

Congratulations!!!, you have your own web server running.

Please remember your router's config pages are now at 192.168.1.1:81

This method of changing the admin port will make remote web admin inoperable.

How to cancel this?

Telnet to the router and type:

nvram set rc_startup=""
nvram set rc_firewall=""
nvram commit
reboot

Notice: You will lose your startup and firewall commands through this.

Alternative

A better way is to set the http_lanport nvram variable instead. Like described in this blog post you can set the http_lanport variable in the nvram:

nvram set http_lanport=81
nvram commit
reboot

WEB server with v24 RC5

DD-WRT runs a small httpd server used for configuring the router. This guide will show how to use it to serve you own pages to your LAN or to the world. Please remember that opening WEB server to the world could be potential security problem.

Assumptions

- You have telnet and SSH enabled on your router. See Telnet/SSH_and_the_Command_Line.
- You can send files via SSH to and from your router (e.g with WinSCP)
- You have jffs enabled and enough free space to store your files or you have working mmc mod.
- I will assume you are installing to the jffs partition. If you are not, replace jffs with mmc or some other folder.
- Optional: you have the "Wireless GUI Access" enabled (Wireless -> Advanced Settings)
- You MUST name your index file index.htm (note: all lower case letters)

How will this work?
- We will move the router's web admin to port 81
- We will start your WEB server on port 80
- Optional: we will open port 80 to the world

Procedure

1) Copy your files to the router, i.e. to the /jffs folder
2) Open web admin Administration -> Diagnostics, press "Run"
3) Enter these lines to the Commands field:

killall httpd
httpd -p 81 -h /www
httpd -h /jffs

4) Press "Save Startup", the router will reboot or reboot it manually.


Optional: open to the world

Caution! The following steps could make the router's management pages accessible from the WAN (for example http://Your.WAN.IP/Management.asp). The password should be required however, so make sure it is strong.

1) Open web admin Administration -> Diagnostics, press "Run"
2) Enter this line to the Commands field:

/usr/sbin/iptables -I INPUT 1 -p tcp --dport 80 -j logaccept

3) Press "Save Firewall", the router will reboot or reboot it manually.

Congratulations!!!, you have your own web server running.

Please remember your router's config pages are now at 192.168.1.1:81

How to cancel this?

Telnet to the router and type:

nvram set rc_startup=""
nvram set rc_firewall=""
nvram commit
reboot

WEB server with v24-preSP2

Under v24-preSP2 it is possible to serve static HTML pages using the existing web server by symlinking them into the www/user directory, for example with

mkdir /jffs/www
echo "test page" > /jffs/www/test.htm
ln -sf /jffs/www /www/user

Arrange to create the symbolic link on startup, then pages from jffs/www can be served up as http://router.address/user/page.htm. This does mean that your info site & DD-WRT management page will be available on the same http server, so choose a strong password. However, this saves both the complexities and the memory usage of running two HTTP servers.

How to access/edit pages

For DD-WRT V24 pre SP2 (svn 12533+) CGI support has been disabled as a fix for an exploit. See this ticket if you would like support reintroduced.

I.

You can add your own pages to /tmp/www folder and then access them with http://192.168.1.1/user/Yourpage.asp

Only static html pages, but if you need dynamic pages you can use CGI scripts (sh scripts or some binary file)

Create the directory /tmp/www/cgi-bin

Then create a script like:

#!/bin/sh 
echo "<html><body>hello world</body></html>"

Save your script as script.cgi and

chmod +x /tmp/www/cgi-bin/script.cgi

You can execute the page going to http://192.168.1.1/user/cgi-bin/script.cgi

Reference: this thread

II.

Shellscripts with .sh will work in folder /tmp/www/cgi-bin as well...

example would be:

#!/bin/sh
echo '<HTML><HEAD><TITLE>Custom Script Test</TITLE></HEAD>'
echo '<BODY>'
nvram get router_name
echo ' sample custom script:<br>'

NOW=`date +%s`

echo "Unix-Time here on this device is ${NOW}. Nothing usefull...<br>"
echo "Just a test..."

save this as
/tmp/www/cgi-bin/custom.sh
and make it executable:
chmod +x /tmp/www/cgi-bin/custom.sh
and point your browser to it:
http://ROUTER.IP.HERE/user/cgi-bin/custom.sh

and you should see the generated output...

This is tested with
DD-WRT v24-sp2 (10/22/08) mega - build 10564M NEWD Eko

Reference: CaScAdE

Note: In these examples, we created scripts in the /tmp directory which is actually pointing to SDRAM. Any pages or scripts in this directory will be lost upon router reboot and/or power loss, unless you back them up first in jffs2/mmc/nvram.

Change SSL cert for HTTPS certificates

See forum topics Change SSL cert for HTTPS certificates and Adding user created ssl certificates.