Help - Search - Members - Calendar
Full Version: Crude Httpd On Zaurus
OESF Forums > General Forums > General Support and Discussion > Security and Networking
speculatrix
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 cool.gif

--
edited quite a few times to ensure layout and clarity is up to standard!
matthis
Wow! Thank you this is really interesting! And I can't wait for the secret project!!
speculatrix
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
speculatrix
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.
speculatrix
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
Da_Blitz
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 smile.gif, perhaps i might do a bit of tinkering myself
speculatrix
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 smile.gif, perhaps i might do a bit of tinkering myself
*


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!
Da_Blitz
ahh, yes i see. not the way i would have done it however wink.gif

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 smile.gif

bring on the bloat!!

edit:

found somthing simmilar in case any one was intrested:
http://home.eol.ca/~parkw/httpd.sh
nilch
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 ?
koen
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
speculatrix
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!
Da_Blitz
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
speculatrix
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
koen
or just use http://www.angstrom-distribution.org/repo/...ls&pnm=didiwiki smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.