diff options
author | Case Duckworth | 2023-04-30 22:29:09 -0500 |
---|---|---|
committer | Case Duckworth | 2023-04-30 22:29:09 -0500 |
commit | 3f7954f8e1c2274e4b6f1b794bc36a908f28afce (patch) | |
tree | 36481a91868f94fbb701a7b6db697e614b440e2b | |
download | yawp.sh-3f7954f8e1c2274e4b6f1b794bc36a908f28afce.tar.gz yawp.sh-3f7954f8e1c2274e4b6f1b794bc36a908f28afce.zip |
Initial commit
-rw-r--r-- | lighttpd.conf | 10 | ||||
-rw-r--r-- | makefile | 2 | ||||
-rwxr-xr-x | yawp.sh | 71 |
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 @@ | |||
1 | server.document-root = "/home/acdw/src/yawp" | ||
2 | server.port = 3030 | ||
3 | server.username = "acdw" | ||
4 | server.groupname = "acdw" | ||
5 | |||
6 | index-file.names = ( "index.html", "yawp.sh" ) | ||
7 | |||
8 | server.modules += ( "mod_cgi", "mod_rewrite" ) | ||
9 | cgi.assign = ( ".sh" => "" ) | ||
10 | url.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 @@ | |||
1 | serve: 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 | |||
4 | crlf() { # crlf < INPUT | ||
5 | ## Convert LF to CRLF | ||
6 | sed 's/$/ /g' | ||
7 | } | ||
8 | |||
9 | http_response() { # http_response [STATUS:-200 OK] < CONTENT | ||
10 | cat <<HEADER | crlf | ||
11 | HTTP/1.1 ${1:-200 OK} | ||
12 | Date: $(date -R) | ||
13 | Content-Type: text/html; charset=utf-8 | ||
14 | HEADER | ||
15 | echo | ||
16 | cat | ||
17 | } | ||
18 | |||
19 | main() { | ||
20 | case "$REQUEST_URI" in | ||
21 | /) new_post ;; | ||
22 | *) display_posts ;; | ||
23 | esac | ||
24 | } | ||
25 | |||
26 | debug_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> | ||
34 | EOF | ||
35 | } | ||
36 | |||
37 | form_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 | |||
54 | new_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> | ||
64 | EOF | ||
65 | } | ||
66 | |||
67 | display_posts() { | ||
68 | debug_env | ||
69 | } | ||
70 | |||
71 | main "$@" | ||