#!/bin/sh
# http://httpd.apache.org/docs/mod/mod_log_config.html#formats
# http://www.rt.com/man/strftime.3.html
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
# http://www.netscape.com/newsref/std/cookie_spec.html

PARM=(
# version number
"%v" # The canonical ServerName of the server serving the request. (example.com)
"%V" # The server name according to the UseCanonicalName setting.
"%{Host}i" # Requested hostname (www.example.com)
"%a" # Remote IP-address (1.2.3.4)
#"%h" # Remote host (123-dsl.tele.dk)
"%A" # Local IP-address (192.168.1.2)
"%l" # Remote logname (from identd, if supplied)
"%u" # Auth user name (PHP_AUTH, Basic-realm)
"%{%F %T %z}t" # {ugenumre? %V %W %U} Time in ISO-8601 format (2004-12-31 23:59:59 +0200)
"%r" # First line of request (GET /index.html?q=test HTTP/1.1)
"%m" # The request method (GET, HEAD, TRACE, SEARCH)
"%U" # The URL path requested, not including any query string. (/index.html)
"%q" # The query string (prepended with a ? if a query string exists, otherwise an empty string) (?q=hello+world)
"%H" # The request protocol (HTTP/1.1)
"%f" # Filename (/home/www/example.com/index.html)
"%>s" # Status (200,302,404)
"%B" # Bytes sent, excluding HTTP headers. (1234)
"%b" # Bytes sent, excluding HTTP headers. In CLF format i.e. a '-' rather than a 0 when no bytes are sent.
"%T" # The time taken to serve the request, in seconds. (3)
"%c" # Connection status when response was completed. (X,+,-)
"%p" # The canonical Port of the server serving the request
"%P" # The process ID of the child that serviced the request.
"%{Referer}i" # (http://www.google.com/search?q=something)
"%{User-Agent}i" # (Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007)
"%{Accept-Language}i" # (da,en;q=0.7,es;q=0.3)
"%{Accept}i" # Client accept mime types (text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1)
"%{Accept-Encoding}i" # (gzip,deflate)
"%{Accept-Charset}i" # (ISO-8859-1,utf-8;q=0.7,*;q=0.7)
"%{Via}i" # Via gateway. Don't trust the IP-number for user-tracking.
"%{Cookie}i" # (PHPSESSID=705293186a499c4377fd5670f1de5ea9; Test=hej)
"%{Set-Cookie}o" # (Apache=port72.ds1-soeb.adsl.cybercity.dk.39601088521649810; path=/)
"%{cookie}n" # mod_usertrack, CookieName=Apache
"%{Keep-Alive}i" # (300)
"%{Connection}i" # (keep-alive)
"%{Date}o" # (Tue, 29 Jun 2004 14:40:04 GMT)
"%{Server}o" # (Apache-AdvancedExtranetServer/1.3.26 (Mandrake Linux/2mdk)PHP/4.1.2)
"%{X-Powered-By}o" # (PHP/4.1.2)
"%{Keep-Alive}o" # (timeout=15,max=100)
"%{Connection}o" # (Keep-Alive)
"%{Transfer-Encoding}o" # (chunked)
"%{Content-Type}o" # (text/html)
)

# Incoming request Mozilla:
#GET / HTTP/1.1..
#Host: w0.dk..
#User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007..
#Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1..
#Accept-Language: da,en;q=0.7,es;q=0.3..Accept-Encoding: gzip,deflate..
#Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7..
#Keep-Alive: 300..
#Connection: keep-alive....

# Outgoing respons:
#HTTP/1.1 200 OK..
#Date: Tue, 29 Jun 2004 14:40:04 GMT..
#Server: Apache-AdvancedExtranetServer/1.3.26 (Mandrake Linux/2mdk)PHP/4.1.2..
#X-Powered-By: PHP/4.1.2..
#Keep-Alive: timeout=15,max=100..
#Connection: Keep-Alive..
#Transfer-Encoding: chunked..
#Content-Type: text/html

# Incoming request MSIE:
#GET /curiosity/cooking/guinness.html HTTP/1.0..
#Via: 1.1 SEAMS052..
#User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)..
#Host: vibeke.schou.dk..
#Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, applicati on/x-shockwave-flash, */*..
#Referer: http://www.google.com/search?hl=en&ie=UTF-8&q=guinness+punch&spell=1..
#Accept-Language: en-us..
#Accept-Encoding: gzip, deflate..
#Connection: Keep-Alive

N=0
while ((N < ${#PARM[*]}))
do
	if [ -n "$LOGFORMAT" ]; then
		LOGFORMAT="${LOGFORMAT}"
	fi
	LOGFORMAT="${LOGFORMAT}${PARM[$N]}"
	let N=N+1
done

echo "# $(date -I)"
echo "<IfModule mod_log_config.c>"
echo "	LogFormat \"$N$LOGFORMAT\" toughlog"
echo "	CustomLog /var/log/apache/toughlog_access_log toughlog"
echo "</IfModule>"
echo
echo "<IfModule mod_usertrack.c>"
echo "	CookieTracking on"
echo "	CookieStyle RFC2965"
echo "</IfModule>"

