Blob


1 #!/bin/sh
3 set -e
5 CHATFILE="${CHATFILE:-/tmp/lets-chat.log}"
7 if [ "$GATEWAY_INTERFACE" != "CGI/1.1" ]; then
8 echo "not a cgi script?" >&2
9 exit 1
10 fi
12 if [ "$SERVER_PROTOCOL" != "GEMINI" ]; then
13 echo "not running over gemini?" >&2
14 exit 1
15 fi
17 # if [ "$REMOTE_USER" = "" ]; then
18 # printf "60 client certificate required\r\n"
19 # exit 0
20 # fi
22 if [ "$PATH_INFO" = "" ]; then
23 printf "20 text/gemini\r\n"
24 echo "# Let's chat over Gemini!"
25 echo
26 echo "=> $SCRIPT_NAME/post Post a message"
27 echo "=> $SCRIPT_NAME/log Follow the conversation"
28 exit 0
29 fi
31 if [ "$PATH_INFO" = "/post" ]; then
32 if [ $# -eq 0 ]; then
33 exec printf "10 message to send: \r\n"
34 else
35 now="$(date '+%Y-%m-%d %H:%M')"
36 user="${REMOTE_USER##*/CN=}"
37 user="${user%%/*}"
38 echo "$now ${user:-anon}: $@" >> "${CHATFILE}"
39 exec printf "30 $SCRIPT_NAME\r\n"
40 fi
41 fi
43 if [ "$PATH_INFO" = "/log" ]; then
44 printf "20 text/gemini\r\n"
45 exec tail -f "${CHATFILE}"
46 fi
48 exec printf "51 not found\r\n"