-
Notifications
You must be signed in to change notification settings - Fork 0
/
goaccess.cgi
executable file
·48 lines (36 loc) · 1.38 KB
/
goaccess.cgi
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
set -Eeuo pipefail
# Allow extended patterns and empty results
shopt -s extglob nullglob
BASE=$(dirname "$0")
HOME=${HOME:-${DOCUMENT_ROOT%/"${DOCUMENT_ROOT#/home/*/}"}}
PATH=$BASE/bin:$PATH
# shellcheck source=/dev/null
[[ -f "$BASE/.env" ]] && source "$BASE"/.env
LOGS=${LOGS:-$HOME/logs}
SITEGLOB=${1:-$(basename "$SCRIPT_URL")}
# Sanitize glob to only allow chars in domains and glob patterns
SITEGLOB=${SITEGLOB//[^a-zA-Z0-9\-.*?+@!\^()\[\]|]/}
readarray -t SITES < <(find "$LOGS"/$SITEGLOB/http?(s)/access.log -mtime -4 -exec dirname {} \;)
# Calc log size, but note that it is compressed size.
ALLLOGS=( ${SITES[@]/%//access.log?(.2*)} )
LOGSIZE=$(du --total --byte "${ALLLOGS[@]}" | tail -1 | cut --fields=1)
function vcombinelogs {
for SITE in "${SITES[@]}"
do
VHOST=$(basename $(dirname "$SITE"))
SITELOGS=("$SITE"/access.log?(.2*))
zcat -f "${SITELOGS[@]}" | sed "s/^/$VHOST:0 /"
done
}
echo "Content-type: text/html"
echo ""
vcombinelogs \
| goaccess - -o html --no-progress --no-global-config \
--date-format='%d/%b/%Y' --time-format='%H:%M:%S' \
--log-format='%v:%^ %h %^ %e [%d:%t %^] "%r" %s %b "%R" "%u"' \
--html-report-title="$SITEGLOB" --log-size="$LOGSIZE" --html-prefs='{"theme":"bright"}' \
--unknowns-as-crawlers \
${GEOIP:-} \
--agent-list --http-protocol=no --http-method=yes --ignore-panel=KEYPHRASES \
--all-static-files --real-os