summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lighttpd.conf10
-rw-r--r--makefile2
-rwxr-xr-xyawp.sh71
3 files changed, 83 insertions, 0 deletions
diff --git a/lighttpd.conf b/lighttpd.conf new file mode 100644 index 0000000..53765a6 --- /dev/null +++ b/lighttpd.conf
@@ -0,0 +1,10 @@
1server.document-root = "/home/acdw/src/yawp"
2server.port = 3030
3server.username = "acdw"
4server.groupname = "acdw"
5
6index-file.names = ( "index.html", "yawp.sh" )
7
8server.modules += ( "mod_cgi", "mod_rewrite" )
9cgi.assign = ( ".sh" => "" )
10url.rewrite-if-not-file = ( "" => "/yawp.sh${url.path}${qsa}" ) \ No newline at end of file
diff --git a/makefile b/makefile new file mode 100644 index 0000000..efb10b9 --- /dev/null +++ b/makefile
@@ -0,0 +1,2 @@
1serve: yawp.sh lighttpd.conf
2 lighttpd -D -f lighttpd.conf
diff --git a/yawp.sh b/yawp.sh new file mode 100755 index 0000000..b74febb --- /dev/null +++ b/yawp.sh
@@ -0,0 +1,71 @@
1#!/bin/sh
2# yawp!
3
4crlf() { # crlf < INPUT
5 ## Convert LF to CRLF
6 sed 's/$/ /g'
7}
8
9http_response() { # http_response [STATUS:-200 OK] < CONTENT
10 cat <<HEADER | crlf
11HTTP/1.1 ${1:-200 OK}
12Date: $(date -R)
13Content-Type: text/html; charset=utf-8
14HEADER
15 echo
16 cat
17}
18
19main() {
20 case "$REQUEST_URI" in
21 /) new_post ;;
22 *) display_posts ;;
23 esac
24}
25
26debug_env() {
27 http_response<<EOF
28<pre>$(env)</pre>
29$(cat | tee /dev/shm/yawp)
30<hr>
31<pre>
32$(form_decode < /dev/shm/yawp)
33</pre>
34EOF
35}
36
37form_decode() { # form_decode << INPUT (application/x-www-form-urlencoded)
38 # TODO: multipart/form-data ..?
39 awk '/%[0-9A-Fa-f][0-9A-Fa-f]/ {
40 while (s = match($0, "%[0-9A-Fa-f][0-9a-fA-F]") > 0) {
41 chr = "";
42 hexdigits = "0123456789abcdef";
43 value = 16 * (index(hexdigits,tolower(substr($0,RSTART+1,1))) - 1);
44 value += index(hexdigits,tolower(substr($0,RSTART+2,1))) - 1;
45 chr = sprintf("%c", value);
46 value = 0;
47 $0 = substr($0, 1, RSTART - 1) chr substr($0, RSTART + RLENGTH);
48 }
49}
50{gsub(/+/," ");gsub(/&/,"\n");print}
51'
52}
53
54new_post() {
55 http_response <<EOF
56<!DOCTYPE html>
57<title>YAWP!</title>
58<form method="POST" action="/newpost">
59<button type="submit" name="yawp" value="yawp">YAWP!</button>
60<hr>
61<textarea id="content" name="content" required rows="40" cols="60">
62</textarea>
63</form>
64EOF
65}
66
67display_posts() {
68 debug_env
69}
70
71main "$@"