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 echo
29 echo "=> https://git.omarpolo.com/blog/tree/resources/cgi/lets-chat source"
30 exit 0
31 fi
33 if [ "$PATH_INFO" = "/post" ]; then
34 if [ $# -eq 0 ]; then
35 exec printf "10 message to send: \r\n"
36 else
37 now="$(date '+%Y-%m-%d %H:%M')"
38 user="${REMOTE_USER##*/CN=}"
39 user="${user%%/*}"
40 echo "$now ${user:-anon}: $@" >> "${CHATFILE}"
41 exec printf "30 $SCRIPT_NAME\r\n"
42 fi
43 fi
45 if [ "$PATH_INFO" = "/log" ]; then
46 printf "20 text/gemini\r\n"
47 exec tail -f "${CHATFILE}"
48 fi
50 exec printf "51 not found\r\n"