From f9c93985d776bdb7608ec22cbccee3fc6318e8f4 Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Sun, 2 Apr 2023 09:21:43 +1000 Subject: [PATCH] Add a stupid little guetsboook demo --- guestbook | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ guestbook.txt | 0 index.md | 1 + 3 files changed, 86 insertions(+) create mode 100755 guestbook create mode 100644 guestbook.txt diff --git a/guestbook b/guestbook new file mode 100755 index 0000000..29fb55f --- /dev/null +++ b/guestbook @@ -0,0 +1,85 @@ +#!/bin/sh + +# guestbook - display the current guestbook entries, append a +# simple form for visitors to add their own comments, and +# accept and process new guest entries. Works with a separate +# data file that actually contains the guest data. + +data="/Users/prologic/Projects/zs-starter-template" +guestbook="$data/guestbook.txt" +tempfile="/tmp/guestbook.$$" +sedtemp="/tmp/guestbook.sed.$$" + +trap '/bin/rm -f $tempfile $sedtemp' 0 + +echo "Content-type: text/html" +echo "" + +echo "Guestbook for $(hostname)" +echo "

Guestbook for $(hostname)

" + +if [ "$REQUEST_METHOD" = "POST" ]; then + + cat - | tr '&+' '\n ' >$tempfile # save the input stream + + name="$(grep 'yourname=' $tempfile | cut -d= -f2)" + email="$(grep 'email=' $tempfile | cut -d= -f2 | sed 's/%40/@/')" + + # Now, given a URL encoded string, decode some of the most important + # punctuation (but not all punctuation!) + + cat <<"EOF" >$sedtemp +s/%2C/,/g;s/%21/!/g;s/%3F/?/g;s/%40/@/g;s/%23/#/g;s/%24/$/g +s/%25/%/g;s/%26/\&/g;s/%28/(/g;s/%29/)/g;s/%2B/+/g;s/%3A/:/g +s/%3B/;/g;s/%2F/\//g;s/%27/'/g;s/%22/"/g +EOF + + comment="$(grep 'comment=' $tempfile | cut -d= -f2 | sed -f $sedtemp)" + + # sequences to look out for: %3C = < %3E = > %60 = ` + + if echo $name $email $comment | grep '%'; then + echo "

Failed: illegal character or characters in input:" + echo "Not saved.
Please also note that no HTML is allowed.

" + elif [ ! -w $guestbook ]; then + echo "

Sorry, can't write to the guestbook at this time.

" + else + # all is well. Save it to the datafile! + echo "$(date)|$name|$email|$comment" >>$guestbook + chmod 777 $guestbook # ensure it's not locked out to webmaster + fi +fi + +# do we have a guestbook to work with? + +if [ -f $guestbook ]; then + echo "" + + while read line; do + date="$(echo $line | cut -d\| -f1)" + name="$(echo $line | cut -d\| -f2)" + email="$(echo $line | cut -d\| -f3)" + comment="$(echo $line | cut -d\| -f4)" + echo "" + echo "" + echo "" + done <$guestbook + + echo "
$name signed thusly:
$comment
Added $date" + echo "
" +fi + +# input form... + +echo "
" +echo "Please feel free to sign our guestbook too:
" +echo "Your name:
" +echo "Your email address:
" +echo "And your comment:
" +echo "" +echo "
" +echo "
" + +echo "" + +exit 0 diff --git a/guestbook.txt b/guestbook.txt new file mode 100644 index 0000000..e69de29 diff --git a/index.md b/index.md index d5a342e..f895f13 100644 --- a/index.md +++ b/index.md @@ -81,6 +81,7 @@ With the [wikilink][wikilink] extension you can link to other pages more easily ### Remember cgi scripts? - [[TestCGI]] +- [Guest Book](./guestbook) ## License