![]() ![]() |
Nov 25 2006, 02:40 PM
Post
#1
|
|
![]() Group: Admin Posts: 3,281 Joined: 29-July 04 From: Cambridge, England Member No.: 4,149 |
Is anyone interested in my crude hackery which allows you to serve web pages on your zaurus without installing any software? I'll assume so!
At the end of the day, a web server can be written in a shell script, with the networking provided by inetd, so provided you generate the right http response headers it's actually quite trivial! I've used this for quite a few years and not come across anyone else doing it, and it seems to me that the Z is an ideal target for something so light weight. Add the following line to the bottom of your /etc/inetd.conf file: CODE http stream tcp nowait root /usr/sbin/tcpd /usr/local/bin/sh-httpd don't worry about the spacing. Then you need to HUP inetd process, by entering the command "ps -ef | grep inet", look for the first number and enter "kill -1 xxxx". Or, in desperation, reboot! e.g. CODE # ps -ef | grep inet root 4802 1 0 21:41 ? 00:00:00 /usr/sbin/inetd root 5726 5671 0 22:41 pts/0 00:00:00 grep inet # kill -1 4802 # Then create the following script, as /usr/local/bin/sh-httpd: CODE #!/bin/bash DBGFILE=/tmp/sh-httpd.log date >> $DBGFILE H="IGNORE" while [ "$H" != "" ]; do echo $H >> $DBGFILE read H H=`echo $H | sed -e 's/^M//g'` done echo 'HTTP/1.1 200 OK' echo -n "Date: "' date|sed 's/ /, /'' echo 'Server: sh-http/0.01 (Linux/bash)' echo 'Accept-Ranges: bytes' echo 'Connection: close' echo 'Content-Type: text/html' echo '' echo '<?xml version="1.0" encoding="ISO-8859-1"?>' echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' echo '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">' echo '<head><title>Zaurus sh-httpd daemon</title></head>' echo '<body bgcolor="#ffffff">' echo "<p>" echo "<b>hello</b>" echo "</p>" echo "</html>" echo "finished" >> $DBGFILE # end sh-httpd A key part in the script is that you see ^M in the while loop, but it's actually a ctrl-m, which you get in vi by typing ctrl-v ctrl-m. Or, attached is the script; I had to add a .txt type to make it uploadable. Once created, make it executable using CODE chmod ugo+x /usr/local/bin/sh-httpd Then test it, either from the local browser using "http://127.0.0.1" or remotely when usb networking is up (http://192.168.129.201) or over wifi. Note that if you've use iptables firewalling on your Z you need to punch a hole for port 80, e.g. "iptables -I INPUT -p tcp --dport 80 -j ACCEPT". BTW, I am doing this now because I want to write a somewhat more sophisticated version in order to produce some local management tools for the Z which aren't present in the normal ROM, and also for a small secret project which will be revealed soon -- edited quite a few times to ensure layout and clarity is up to standard!
Attached File(s)
|
|
|
|
Nov 26 2006, 04:45 AM
Post
#2
|
|
|
Group: Members Posts: 218 Joined: 12-February 06 From: Tokyo Member No.: 9,124 |
Wow! Thank you this is really interesting! And I can't wait for the secret project!!
|
|
|
|
Nov 27 2006, 03:22 PM
Post
#3
|
|
![]() Group: Admin Posts: 3,281 Joined: 29-July 04 From: Cambridge, England Member No.: 4,149 |
I can now reveal two things... an enhanced version of the "web server" which extracts the query string, and the secret project.
I've added to the oesf forum snapshot the ability to do free text searches. See forum snapshot install this as the /usr/local/bin/sh-httpd script: CODE #!/bin/bash read REQ_GET REQ_URL REQ_PROTO REQ_URI=`echo $REQ_URL | awk '-F?' '{print $1}'` export QUERY_STRING=`echo $REQ_URL | awk '-F?' '{print $2}'` V="IGNORE" while [ "$V" != "" ]; do read H V H=`echo $H | sed -e 's/:$//' -e 's/-/_/g'` V=`echo $V | sed -e 's/^M$//'` done echo 'HTTP/1.1 200 OK' echo -n 'Date: ' date|sed 's/ /, /' echo "Server: sh-http/0.01 (Linux/bash)" echo 'Accept-Ranges: bytes' echo 'Connection: close' if [ "$REQ_URI" = "/namazu.cgi" ]; then export SCRIPT_NAME=/namazu.cgi /mnt/card/namazu/namazu.cgi else echo 'Content-Type: text/html' echo '' echo '<?xml version="1.0" encoding="ISO-8859-1"?>' echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict. echo '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">' echo '<head><title>Zaurus sh-httpd daemon</title></head>' echo '<body bgcolor="#ffffff">' echo '<p>' echo '<b>sh-http</b><br />' date echo '</p>' echo '<a href="/namazu.cgi">namazu</a><br />' echo '<pre>' env echo '</pre>' echo '</html>' fi # end sh-httpd -- edit: cleanup |
|
|
|
Nov 27 2006, 03:36 PM
Post
#4
|
|
![]() Group: Admin Posts: 3,281 Joined: 29-July 04 From: Cambridge, England Member No.: 4,149 |
p.s. of course this also means it would be possible to add a full free-text search to the zaurus too if anyone really wanted their documents indexing.
|
|
|
|
Nov 30 2006, 09:35 AM
Post
#5
|
|
![]() Group: Admin Posts: 3,281 Joined: 29-July 04 From: Cambridge, England Member No.: 4,149 |
Apache is 100's of KB, and yet I claimed to write a web server in only 30 lines of shell script!
Did noone spot that this is a cheat? Well, don't forget that it uses bash to execute the script, that's nearly 700kB. And then there's inetd, which is 25kB. You can also do a similar hack to write a "finger daemon". become root and change inetd.conf: # echo "finger stream tcp nowait root /usr/sbin/tcpd /usr/local/bin/sh-fingerd" >> /etc/inetd.conf Then HUP inetd: # kill -1 `ps -ef | grep inetd | grep -v grep | awk '{print $2}'` Then create /usr/local/bin/sh-fingerd thus: # cat > /usr/local/bin/sh-fingerd #!/bin/bash echo "Hello, this is your zaurus" ^D make it executable: # chmod ugo+x /usr/local/bin/sh-fingerd Then back at your computer... > finger x@192.168.129.201 [usb-z/192.168.129.201] Hello, this is your zaurus |
|
|
|
Dec 1 2006, 10:17 PM
Post
#6
|
|
![]() Group: Members Posts: 1,565 Joined: 7-April 05 From: Sydney, Australia Member No.: 6,806 |
wasent there a full webserver written in AWK on the net here is one http://www.sunsite.ualberta.ca/Documentati...gawkinet_4.html
but i remeber there being one that could be run as a standalone daemon cant wait to see CGI support |
|
|
|
Dec 3 2006, 03:28 PM
Post
#7
|
|
![]() Group: Admin Posts: 3,281 Joined: 29-July 04 From: Cambridge, England Member No.: 4,149 |
QUOTE(Da_Blitz @ Dec 2 2006, 07:17 AM) wasent there a full webserver written in AWK on the net here is one http://www.sunsite.ualberta.ca/Documentati...gawkinet_4.html but i remeber there being one that could be run as a standalone daemon cant wait to see CGI support erm, the second version I posted with the call to namazu IS a cgi version... what is actually missing is the ability to serve files - in fact, the whole thing is really one big CGI! |
|
|
|
Dec 3 2006, 07:09 PM
Post
#8
|
|
![]() Group: Members Posts: 1,565 Joined: 7-April 05 From: Sydney, Australia Member No.: 6,806 |
ahh, yes i see. not the way i would have done it however
if i remeber correctlly the RFC for CGI says that you should launch it in a subshell (or fork) but i guess it might be a bit difficult to set the enviremet varibles. however its a challenge i am willing to try out now i really want to work on it, and allow it to execute and cgi that ends in cgi, sh or php if command line php has been installed bring on the bloat!! edit: found somthing simmilar in case any one was intrested: http://home.eol.ca/~parkw/httpd.sh |
|
|
|
Dec 4 2006, 07:17 AM
Post
#9
|
|
|
Group: Members Posts: 668 Joined: 3-December 03 From: US Member No.: 1,034 |
so now that we have this HTTP server working, how about something more full-fledged but light-weight like lightty? Is light-httpd been compiled for the Zaurus ?
I mean, if Apache can run on the Z, I am sure Lightty can too - or am I wrong ? |
|
|
|
Dec 4 2006, 07:25 AM
Post
#10
|
|
![]() Group: Members Posts: 1,014 Joined: 4-January 05 From: Enschede, The Netherlands Member No.: 6,107 |
QUOTE(nilch @ Dec 4 2006, 03:17 PM) so now that we have this HTTP server working, how about something more full-fledged but light-weight like lightty? Is light-httpd been compiled for the Zaurus ? I mean, if Apache can run on the Z, I am sure Lightty can too - or am I wrong ? Try using cherokee, it rocks |
|
|
|
Dec 4 2006, 07:39 AM
Post
#11
|
|
![]() Group: Admin Posts: 3,281 Joined: 29-July 04 From: Cambridge, England Member No.: 4,149 |
if you want a real webserver, try boa, the successor to tinyhttpd:
http://www.boa.org/ I am quite amused that a demonstration of my l33t hacking of shell scripts (!) which was really just for running the namazu.cgi, for free-text searching of the forum archive, is giving rise to serious discussion about small web servers! |
|
|
|
Dec 4 2006, 09:51 PM
Post
#12
|
|
![]() Group: Members Posts: 1,565 Joined: 7-April 05 From: Sydney, Australia Member No.: 6,806 |
ive never really had a problem with thttpd unless you want non cgi php support (unfortunattly i did)
actually i think this is a good idea to discuss this as i really want to run pmwiki on my PDA os it stores everything in files rather than a sql database, (the reason i like it so much, if need be you can go to sql) so its a good fit for most users i do belive that there is a wiki written in C that has a built in webserver. seems like a good idea but i am quite used to the advanced features of pmwiki (such as inserting content from one page such as an overview on the projects list so you have apage that gives an index and description of each project as well as my dynamically changing sidebar on my old site that only showed you the projects you had permission to view) the only down side was it needed php, and with thttpd that meant installing the cgi version. oh well, anyone know of a bash wiki? personally i find the idea of having a wiki, wikipedia and the oesf fourms on my PDA very appealing |
|
|
|
Dec 5 2006, 04:43 AM
Post
#13
|
|
![]() Group: Admin Posts: 3,281 Joined: 29-July 04 From: Cambridge, England Member No.: 4,149 |
have you looked at the Getting Things Done TiddlyWiki which is entirely javascript in a web page and doesn't need a web server at all? You just save the page to a file.
Works fine in opera, useless in Netfront. There's a discussion on it somewhere, search for GTDTiddlyWiki |
|
|
|
Dec 5 2006, 05:14 AM
Post
#14
|
|
![]() Group: Members Posts: 1,014 Joined: 4-January 05 From: Enschede, The Netherlands Member No.: 6,107 |
|
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 18th June 2013 - 02:37 PM |