2 # CGI script to get irc logs from scoop. Powers https://irclogs.armaanb.net.
4 channel=$(echo "$PATH_INFO" | awk -F / '{print $2}')
5 if [ -z "$channel" ]; then
6 echo "Content-type: text/plain
14 $(awk '{print " * " $0}' /etc/scoop-cgi/channels)
15 $(awk '{print " * " $0}' /etc/scoop-cgi/logbot)
20 date is optional, and defaults to the current day
24 https://git.armaanb.net/bin/tree/scoop-cgi
25 it's in the public domain!"
29 time=$(echo "$PATH_INFO" | awk -F / -v date="$(date -I)" '
30 {($3 != "" ) ? outp = $3 : outp = date; print outp}' | xargs date -I -d)
32 all=$(cat /etc/scoop-cgi/channels /etc/scoop-cgi/logbot)
33 channel=$(echo "$all" | grep -x "$channel")
34 if [ -z "$channel" ]; then
36 printf "Content-type: text/plain\n\n"
37 echo "404. Channel not logged."
41 printf "Content-type: text/plain\n\n"
43 if grep -qx "$channel" /etc/scoop-cgi/channels; then
44 db=$(cat /etc/scoop-cgi/database)
45 PAGER=/dev/tty scoop -d "$db" -p "$channel" -D "$time" \
46 -F "%Y-%m-%d %H:%M:%S" \
47 | awk '{$1=""; print substr($0, 2, length($0) - 1)}'
48 elif grep -qx "$channel" /etc/scoop-cgi/logbot; then
49 awk -v date="$time" 'substr($1, 0, 11) == date {outp = substr($1, 12);
50 for (i = 3; i <= NF; i++) outp = outp " " $i; print outp}' \
51 "/srv/www/scoop-cgi/$channel"