-
Notifications
You must be signed in to change notification settings - Fork 9
/
getlog
executable file
·30 lines (24 loc) · 757 Bytes
/
getlog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
BOT_LOG_FILE=chatlog.db
PEER_ID=-12345678
PEER_TITLE='Some Interesting Group'
CACHE_PATH=img
URL_PREFIX=/img/
HARD_LIMIT=100000
if [ "$HTTP_IF_MODIFIED_SINCE" ]; then
if [ "$(date -u -d "$HTTP_IF_MODIFIED_SINCE" +%s)" -ge "$(stat -c %Y $BOT_LOG_FILE)" ]; then
echo 'Status: 304 Not Modified'
echo
exit 0
fi
fi
echo 'Status: 200 OK'
echo 'Content-Type: text/html; charset=utf-8'
echo "Last-Modified: $(date -R -u -d @$(stat -c %Y $BOT_LOG_FILE))"
echo
if [ "$QUERY_STRING" ]; then
limit="$(echo "$QUERY_STRING" | tr -Cd [[:digit:],])"
else
limit=500
fi
python3 logfmt.py -b $BOT_LOG_FILE -d '' -t html -D=$PEER_ID -o=- -P="$PEER_TITLE" -l $limit -L $HARD_LIMIT -c $CACHE_PATH -r $URL_PREFIX $PEER_ID