]> git.armaanb.net Git - bin.git/blob - scoop-cgi
chrooter: drop script
[bin.git] / scoop-cgi
1 #!/usr/bin/env sh
2 # CGI script to get irc logs from scoop. Powers https://irclogs.armaanb.net.
3
4 channel=$(echo "$PATH_INFO" | awk -F / '{print $2}')
5 if [ -z "$channel" ]; then
6                 echo "Content-type: text/plain
7
8 =================
9 acheam's IRC logs
10 =================
11
12 logged channels
13 ---------------
14 $(awk '{print "  * " $0}' /etc/scoop-cgi/channels)
15
16 url format
17 ----------
18 /channel/date
19 date is optional, and defaults to the current day
20
21 source
22 ------
23 https://git.armaanb.net/bin/tree/scoop-cgi
24 it's in the public domain!"
25                 exit 0
26 fi
27
28 channel=$(grep -x "$channel" /etc/scoop-cgi/channels)
29 if [ -z "$channel" ]; then
30                 echo "Status: 404"
31                 printf "Content-type: text/plain\n\n"
32                 echo "404. Channel not logged."
33                 exit 0
34 fi
35
36 time=$(echo "$PATH_INFO" | awk -F / '{print $3}' | xargs date -I -d)
37 today=$(date -I)
38 time=${time:-$today}
39 db=$(cat /etc/scoop-cgi/database)
40
41 printf "Content-type: text/plain\n\n"
42 PAGER=/dev/tty scoop -d "$db" -p "$channel" -D "$time" -F "%Y-%m-%d %H:%M:%S" \
43                 | awk '{$1=""; print substr($0, 2, length($0) - 1)}'