Added gitignore entries needed to ignore derived objects generated from full build...
[bash.git] / examples / scripts / websrv.sh
blobe07746bc57eef189a728369f9eb2478cf7d2bcdb
1 #!/bin/sh
2 #for instructions or updates go to:
3 #<A HREF="http://math.ucr.edu:8889/">This script's home page</A>
4 #email me questions or comments at:
5 #<A HREF="mailto:insom@math.ucr.edu">insom@math.ucr.edu</A>
6 #copyright chris ulrich; This software may be used or modified
7 #in any way so long as this notice remains intact.
9 # WWW server in sh
10 # Author: Chris Ulrich <chris@tinker.ucr.edu>
13 INDEX=index.html
14 date=`date`
15 DOCHOME=/home/insom/web-docs
16 BINHOME=/home/insom/web-bin
17 LOGHOME=/home/insom/web-logs
18 LOGFILE=$LOGHOME/access_log
19 #verbose=:
20 verbose=echo
21 exec 2>> $LOGHOME/error_log
23 hheader() {
24 echo "HTTP/1.0 200 OK
25 Server: WebSH/2.00
26 Connection: close
27 Date: $date"
30 header() {
31 echo "Content-type: $1
35 no_url() {
36 header "text/plain"
37 echo "No such url $1"
40 send() {
41 #case "$#" in 2) ;; *) echo eep! | mailx insom@math.ucr.edu ; exit 3 ;; esac
42 if test -f "$DOCHOME/$2"
43 then
44 header "$1"
45 cat "$DOCHOME/$2"
46 else
47 no_url "$2"
51 LsToHTML() {
52 if test -f "$DOCHOME/$url/.title"
53 then
54 header "text/html; charset=US-ASCII"
55 echo "<pre>"
56 cat "$DOCHOME/$url/.title"
57 echo "</pre>"
58 elif test -f "$DOCHOME/$url/.title.html"
59 then
60 header "text/html; charset=US-ASCII"
61 cat "$DOCHOME/$url/.title.html"
62 else
63 header "text/html; charset=US-ASCII"
66 case "$url" in
67 /) ;;
68 *) url="$url/"
69 esac
71 while read link
73 case $link in
74 *.cgi) ;;
76 echo "<A HREF=\"$url$link\">$link</A> <BR>"
78 esac
79 done
82 read method data
84 $verbose "
85 $date access from ${TCPREMOTEINFO:=NO-IDENT}@${TCPREMOTEHOST:=$TCPREMOTEIP}
86 on local machine $TCPLOCALHOST
87 $method $data " >> $LOGFILE
89 for hopeurl in $data
91 url="${url}${url:+ }$second"
92 second="$hopeurl"
93 done
95 case "$second" in
96 *[1-9].*)
97 read inheader
98 while
99 case "$inheader" in
100 ?|'') false
103 read inheader
105 esac
108 done
109 hheader
111 esac
113 case "$url" in
114 *..*)
115 no_url "$url"
116 exit 1
118 *.txt|*.[ch])
119 send "text/plain; charset=US-ASCII" "$url"
121 *.html)
122 send "text/html; charset=US-ASCII" "$url"
124 *.cgi)
125 if test -x "$DOCHOME/$url"
126 then
127 read message
128 echo "$message" | "$DOCHOME/$url"
129 else
130 no_url "$url"
133 *".cgi?"*)
134 oIFS="$IFS"
135 echo "$url" | {
136 IFS='?' read url QUERY_STRING
137 if test -x "$DOCHOME/$url"
138 then
139 IFS="$oIFS"
140 export QUERY_STRING
141 "$DOCHOME/$url"
142 else
143 no_url "$url"
147 *.[Gg][Ii][Ff])
148 send "image/gif" "$url"
150 *.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg])
151 send "image/jpeg" "$url"
153 *.tbl)
154 header "text/html; charset=US-ASCII"
155 echo "<pre>"
156 test -f "$DOCHOME/$url" &&
157 tbl < "$DOCHOME/$url" | nroff ||
158 no_url "$url"
159 echo "</pre>"
161 *.nroff)
162 header "text/html; charset=US-ASCII"
163 echo "<pre>"
164 test -f "$DOCHOME/$url" &&
165 nroff < "$DOCHOME/$url" ||
166 no_url "$url"
167 echo "</pre>"
169 *mp[23])
170 if test -f "$DOCHOME/$url"
171 then
172 header "application/mpstream"
173 echo "+$TCPLOCALIP:${MPSERVPORT:=9001}/$url"
174 else
175 no_url "$url"
178 *.[0-9]|*.[0-9][a-z])
179 header "text/html; charset=US-ASCII"
180 echo "<pre>"
181 if test -f "$DOCHOME/$url"
182 then
183 #nroff -man "$DOCHOME/$url" | $BINHOME/man2html
184 echo "perl at the moment is broken, so man2html doesn't work. Sorry."
185 echo "</pre>"
186 else
187 no_url "$url"
190 *.???|*.??)
191 send "unknown/data" "$url"
194 if test -d "$DOCHOME/$url"
195 then
196 ls "$DOCHOME/$url" | LsToHTML
200 if test -f "$DOCHOME/$url"
201 then
202 read filetype < "$DOCHOME/$url"
203 case "$filetype" in
204 \#!/*/*|\#!?/*/*)
205 header "text/plain; charset=US-ASCII"
206 cat "$DOCHOME/$url"
208 '<!*>')
209 header "text/html; charset=US-ASCII"
210 cat "$DOCHOME/$url"
213 header "text/html; charset=US-ASCII"
214 echo "<pre>"
215 cat "$DOCHOME/$url"
216 echo "</pre>"
218 esac
219 elif test -f "$DOCHOME/$url/$INDEX"
220 then
221 header "text/html; charset=US-ASCII"
222 cat "$DOCHOME/$url/$INDEX"
223 elif test -d "$DOCHOME/$url"
224 then
225 ls "$DOCHOME/$url" | LsToHTML
226 else
227 no_url "$url"
230 esac