Author Topic: Crude Httpd On Zaurus  (Read 10745 times)

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
Crude Httpd On Zaurus
« on: November 25, 2006, 05:40:50 pm »
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: [Select]
http    stream  tcp     nowait  root    /usr/sbin/tcpd  /usr/local/bin/sh-httpddon'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: [Select]
# 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: [Select]
#!/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 ''
echo ''
echo ''
echo 'Zaurus sh-httpd daemon'
echo ''

echo "

"
echo "hello"
echo "

"
echo ""

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: [Select]
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!
« Last Edit: November 25, 2006, 05:50:46 pm by speculatrix »
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.

matthis

  • Full Member
  • ***
  • Posts: 217
    • View Profile
    • http://badaboum.bidibom.free.fr/mat/
Crude Httpd On Zaurus
« Reply #1 on: November 26, 2006, 07:45:10 am »
Wow! Thank you this is really interesting! And I can't wait for the secret project!!

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
Crude Httpd On Zaurus
« Reply #2 on: November 27, 2006, 06:22:02 pm »
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: [Select]
#!/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 ''
        echo '        echo ''
        echo 'Zaurus sh-httpd daemon'
        echo ''

        echo '

'
        echo 'sh-http
'
        date
        echo '

'
        echo 'namazu
'
        echo '
'
        env
        echo '
'
        echo ''
fi

# end sh-httpd

-- edit: cleanup
« Last Edit: November 27, 2006, 06:24:27 pm by speculatrix »
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
Crude Httpd On Zaurus
« Reply #3 on: November 27, 2006, 06:36:19 pm »
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.
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
Crude Httpd On Zaurus
« Reply #4 on: November 30, 2006, 12:35:38 pm »
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
« Last Edit: November 30, 2006, 12:36:54 pm by speculatrix »
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.

Da_Blitz

  • Hero Member
  • *****
  • Posts: 1579
    • View Profile
    • http://www.pocketnix.org
Crude Httpd On Zaurus
« Reply #5 on: December 02, 2006, 01:17:59 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 , perhaps i might do a bit of tinkering myself
Personal Blog
Code
Twitter

Gemini Order: #95 (roughly)
Current Device: Samsung Chromebook Gen 3
Current Arm Devices Count: ~30
Looking to acquire: Cavium Thunder X2 Hardware

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
Crude Httpd On Zaurus
« Reply #6 on: December 03, 2006, 06:28:29 pm »
Quote
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 , perhaps i might do a bit of tinkering myself
[div align=\"right\"][a href=\"index.php?act=findpost&pid=147761\"][{POST_SNAPBACK}][/a][/div]

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!
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.

Da_Blitz

  • Hero Member
  • *****
  • Posts: 1579
    • View Profile
    • http://www.pocketnix.org
Crude Httpd On Zaurus
« Reply #7 on: December 03, 2006, 10:09:46 pm »
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
« Last Edit: December 03, 2006, 10:32:26 pm by Da_Blitz »
Personal Blog
Code
Twitter

Gemini Order: #95 (roughly)
Current Device: Samsung Chromebook Gen 3
Current Arm Devices Count: ~30
Looking to acquire: Cavium Thunder X2 Hardware

nilch

  • Hero Member
  • *****
  • Posts: 668
    • View Profile
    • http://
Crude Httpd On Zaurus
« Reply #8 on: December 04, 2006, 10:17:43 am »
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 ?
New no more-C1000 / 5000D (sold my 6000 and 750) | Cacko ROM 1.23 on C1000 | 256 MB CF | 2GB PNY SD card | Socket Networker WiFi CF Card | USB Host cable from StreamlineCPUS | Mini Microphone (for voice recording) |

koen

  • Hero Member
  • *****
  • Posts: 1008
    • View Profile
    • http://dominion.thruhere.net/koen/cms/
Crude Httpd On Zaurus
« Reply #9 on: December 04, 2006, 10:25:29 am »
Quote
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 ?
[div align=\"right\"][a href=\"index.php?act=findpost&pid=147988\"][{POST_SNAPBACK}][/a][/div]

Try using cherokee, it rocks
Forums are not bugtrackers!!! Smart questions
Ångström release team
iPAQ h2210, iPAQ h5550, iPAQ hx4700, Zaurus SL-C700, Nokia 770, all running some form of GPE
My blog

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
Crude Httpd On Zaurus
« Reply #10 on: December 04, 2006, 10:39:50 am »
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!
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.

Da_Blitz

  • Hero Member
  • *****
  • Posts: 1579
    • View Profile
    • http://www.pocketnix.org
Crude Httpd On Zaurus
« Reply #11 on: December 05, 2006, 12:51:15 am »
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
Personal Blog
Code
Twitter

Gemini Order: #95 (roughly)
Current Device: Samsung Chromebook Gen 3
Current Arm Devices Count: ~30
Looking to acquire: Cavium Thunder X2 Hardware

speculatrix

  • Administrator
  • Hero Member
  • *****
  • Posts: 3707
    • View Profile
Crude Httpd On Zaurus
« Reply #12 on: December 05, 2006, 07:43:03 am »
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
Gemini 4G/Wi-Fi owner, formerly zaurus C3100 and 860 owner; also owner of an HTC Doubleshot, a Zaurus-like phone.

koen

  • Hero Member
  • *****
  • Posts: 1008
    • View Profile
    • http://dominion.thruhere.net/koen/cms/
Crude Httpd On Zaurus
« Reply #13 on: December 05, 2006, 08:14:24 am »
Forums are not bugtrackers!!! Smart questions
Ångström release team
iPAQ h2210, iPAQ h5550, iPAQ hx4700, Zaurus SL-C700, Nokia 770, all running some form of GPE
My blog