]> git.armaanb.net Git - bin.git/blob - scoop-cgi
3b2aef5c0dc730f3602d9fe8d8e20936a3bb49d2
[bin.git] / scoop-cgi
1 #!/usr/bin/env sh
2 # CGI script to get irc logs from scoop. Powers https://logs.armaanb.net.
3
4 channel=$(echo "$PATH_INFO" | awk -F / '{print $2}')
5 if [ -z "$channel" ]; then
6                 echo "Content-type: text/plain\n"
7                 echo "Logged channels:"
8                 cat /etc/scoop-cgi/channels
9                 echo "
10 url format: /channel/date
11 date is optional, and defaults to the current day"
12                 exit 0
13 fi
14
15 channel=$(grep -x "$channel" /etc/scoop-cgi/channels)
16 if [ -z "$channel" ]; then
17                 echo "Status: 404"
18                 echo "Content-type: text/plain\n"
19                 echo "404. Channel not logged."
20                 exit 0
21 fi
22
23 time=$(echo "$PATH_INFO" | awk -F / '{print $3}' | xargs date -I -d)
24 db=$(cat /etc/scoop-cgi/database)
25
26 echo "Content-type: text/plain\n"
27 scoop -d "$db" -p "$channel" -D "${time:-now}" -F "%Y-%m-%d %H:%M:%S" \
28                 | awk '{$1=""; print substr($0, 2, length($0) - 1)}'