OESF | ELSI | pdaXrom | OpenZaurus | Zaurus Themes | Community Links | Ibiblio

IPB

Welcome Guest ( Log In | Register )

> Crude Httpd On Zaurus, ...using shell scripting
speculatrix
post 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 cool.gif

--
edited quite a few times to ensure layout and clarity is up to standard!
Attached File(s)
Attached File  sh_httpd.txt ( 792bytes ) Number of downloads: 37
 
Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
koen
post Dec 5 2006, 05:14 AM
Post #2





Group: Members
Posts: 1,014
Joined: 4-January 05
From: Enschede, The Netherlands
Member No.: 6,107



or just use http://www.angstrom-distribution.org/repo/...ls&pnm=didiwiki smile.gif
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 20th December 2014 - 10:13 PM