#!/bin/sh # http://neil.franklin.ch/Projects/squid_log - Squid 1.0.20 log disp via http # author Neil Franklin, last modification 1999.04.10 # this script only works with the old Squid log file format as used in 1.0.20 # squid 1.0.20 log files are space separated tables with the fields: # # to install squid_log on your Squid server put it into /etc/inetd.conf: # stream tcp nowait /squid_log # to use squid_log type in any Web browser the URL: # http://:/[?] # valid output-types (file sorted by) are: name size time # ? is facultative and only lets through fitting lines # there is no security whatsoever, user tcpd or xinetd if you need it # OK, one can do this by Apache+CGI, but where is the fun in doing that? ## inetd provides us with: waiting on port, forking, IO socket, change user ## parse HTTP request read command # strip the \r that HTTP allows/demands in input stream # no ";" evaluation after "$" evaluation, so no security hole command=`echo $command | tr -d "\r"` # split HTTP request method=`echo $command | cut -f 1 -d " "` url=`echo $command | cut -f 2 -d " "` http_version=`echo $command | cut -f 3 -d " "` # if HTTP/1.* is being used, digest the request header fields, do nothing if [ "$http_version" != "" ] ; then option="dummy" while [ "$option" != "" ] ; do read option option=`echo $option | tr -d "\r"` done fi ## decide what to do # what method does the user want, we only implement HEAD and GET if [ "$method" != "HEAD" -a "$method" != "GET" ] ; then echo "HTTP/1.0 501 Not Implemented" echo echo "" echo " " echo " 501 Method Not Implemented" echo " " echo " " echo "

Method Not Implemented

" echo " Method" $method "does not fit list: HEAD GET" echo " " echo "" exit 1 fi ## generate HTTP response - header # we are simple HTTP 1.0, no 1.1 fancies are supported or expected echo "HTTP/1.0 200 OK" # date -u for GMT, to fit RFC 2086 (HTTP/1.1) format echo "Date:" `date -u "+%a, %d %b %Y %X GMT"` echo "Server: http://neil.franklin.ch/Projects/squid_log, yes, sh script!" # last mod = date (we generate output now), file date is unreliable anyway echo "Last-Modified:" `date -u "+%a, %d %b %Y %X GMT` echo "Connection: close" echo "Content-type: text/html" echo "Content-Language: en" echo # method HEAD does not deliver any data, so exit now if [ "$method" = "HEAD" ] ; then exit 0 fi ## generate HTTP response - HTML output output=$url # strip http: off path if it was in URL if [ "`echo $output | cut -c 1-5`" = "http:" ] ; then output=`echo $output | cut -c 6-` fi # strip /// off path if it was in URL if [ "`echo $output | cut -c 1-2`" = "//" ] ; then output=`echo $output | cut -f 4- -d "/"` else # strip first / off path if it was (and still is) in URL if [ "`echo $output | cut -c 1`" = "/" ] ; then output=`echo $output | cut -f 2- -d "/"` fi fi # isolate the grep-pattern part greppat=".*" # compare with $output because cut -f 2 gives entire text, not(!) empty if [ ! `echo $output | cut -f 2 -d "?"` = "$output" ] ; then greppat=`echo $output | cut -f 2 -d "?"` output=`echo $output | cut -f 1 -d "?"` fi echo "" echo " " echo " Files in Squid Log, sorted by $output " echo " " echo " " echo "

Files in Squid Log, sorted by $output

" echo # any putting an ";" into $output gives syntax (t)error, so no security hole case "$output" in name ) grep -i "$greppat" /var/spool/squid/log | sort +1 | awk '{ printf " %s
\n",$2,$2 }' ;; size ) grep -i "$greppat" /var/spool/squid/log | sort -n +4 | awk '{ printf " %s-%s
\n",$2,$5,$2 }' ;; time ) grep -i "$greppat" /var/spool/squid/log | sort -n +3 | awk '{ printf " %s-%s
\n",$2,$4,$2 }' ;; * ) echo "

Output Type Unknown

" echo " Output type $output does not fit list: name size time" ;; esac echo echo "
" echo echo " This script is by " echo " Neil Franklin, last modification 1999.04.10" echo " " echo ""