#!/bin/sh # Name of your apache access log file. Assumes a log rotation # scheme is being used like Debian's default LOG=/var/log/apache-ssl/ftp.parisc-linux.org-access.log # A GET /a/b/c request in access.log must be matched with # the actual file to determine the file size. This path is computed # as $BASEDIR/a/b/c BASEDIR=~ftp # BASEDIR=/var/www # A command which sends your FTP (wu and proftpd tested) log to stdout # Set this to nothing to disable this feature. If you use it, you'll # probably also need to change "/extra/ftp" to whatever is the prefix # on file names in your ftp logs XFERLOG="sudo /usr/local/sbin/xferlog" case "$QUERY_STRING" in *showscript*) echo "content-type: text/plain" echo cat $SCRIPT_FILENAME exit ;; ?*) OIFS="$IFS"; IFS='&'; set -- $QUERY_STRING; IFS="$OIFS" while [ $# != 0 ] do grepfor="$grepfor -e $1" shift 1 done ;; esac default() { TMP=/tmp/9.$$ echo content-type: text/html echo echo '
Check the download statistics at the ESIEE mirror in France." echo "Show this script." echo "
" [ -z "$grepfor" ] && grepfor=/ #echo "";set;echo "" #echo "grepfor=$grepfor" (zcat $LOG.[1-5].gz; cat $LOG.0 $LOG; $XFERLOG) | fgrep $grepfor | awk -vTMP=$TMP ' BEGIN { total=0 fail=0 OFMT = "%.1f" showall = "[[[showall]]]" } ($6 = "\"GET" && $7 ~ /\.iso/ && ($9 == "200" || $9 == "206")) { if (!($1 in bytes_ip)) uniqhosts++ $7 = "." $7 total_attempts++ attempts_iso[$7]++ total_bytes += $10 bytes_iso[$7] += $10 bytes_ip[$1] += $10 } ($9 ~ /\.iso/) { if (!($7 in bytes_ip)) uniqhosts++ iso = $9 bytes = $8 sub("/extra/ftp", ".", iso) total_attempts++ attempts_iso[iso]++ total_bytes += bytes bytes_iso[iso] += bytes bytes_ip[$7] += bytes } function mb(x) { return x / 1024 / 1024 } END { for (file in bytes_iso) { #print "FILE:", file print file > TMP } close(TMP) #print "TMP:", TMP cmd = "cd '$BASEDIR' && xargs ls -l 2>/dev/null < " TMP #print "CMD:", cmd while ((cmd | getline) > 0) { #print "TMP>", $0 size_iso[$NF] = $5 #print "SZ", $NF, $5 } print "
| File | Possible #downloads | #attempts | xfer MB | File MB" printf(" |
|---|---|---|---|---|
| %s", file) > TMP printf(" | %d", d) > TMP printf(" | %d", attempts_iso[file]) > TMP printf(" | %.1f", mb(bytes_iso[file])) > TMP printf(" | %.1f\n", mb(size_iso[file])) > TMP } printf(" |
| %s", "Total") > TMP printf(" | %d", downloads) > TMP printf(" | %d", total_attempts) > TMP printf(" | %.1f", mb(total_bytes)) > TMP printf(" | n/a\n") > TMP } ' sort -tp +1 < $TMP echo " |