<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!--
# Copyright 2003 Miohael Semcheski <mhs@nedyah.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#       This product contains software developed by Michael Semcheski.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
	<xsl:template match="/pf">
		<html>
			<head>
				<title>PF Output beginning 
					<xsl:value-of select="packet[position()=1]/timestamp/@date"/> and ending 
					<xsl:value-of select="packet[position()=last()]/timestamp/@date"/> 
				</title>
		<SCRIPT TYPE="text/javascript" LANGUAGE="javascript" >
		function sort(so) {
			var cElems = document.all.tags('tr');
			var iNumElems = cElems.length;
		  for (var i=1; i &lt; iNumElems; i++) {
		  	if (cElems[i].className == so) {
		  		cElems[i].style.display = "inline";
		  	}
		  	else
		 		{
		 			cElems[i].style.display = "none";
		 		}
		  }
		}
		function pageLoad() {
			sort('time');
		}
		</SCRIPT>				
			</head>
			<body onload="pageLoad();">
				<table border="0" cellpadding="2" cellspacing="2">
					<tr style="background-color: #999999">
						<th><a href="javascript:sort('source')">Source</a></th>
						<th><a href="javascript:sort('sport')">Port</a></th>
						<th><a href="javascript:sort('destination')">Destination</a></th>
						<th><a href="javascript:sort('dport')">Port</a></th>
						<th><a href="javascript:sort('time')">Time</a></th>
						<th><a href="javascript:sort('reason')">Reason</a></th>
						<th><a href="javascript:sort('extra')">Extra</a></th>
					</tr>
					<xsl:apply-templates select="packet">
						<xsl:sort select="source/@ip"/>
						<xsl:with-param name="sortOpt">source</xsl:with-param>
					</xsl:apply-templates>
					<xsl:apply-templates select="packet">
						<xsl:sort select="source/@port"/>
						<xsl:with-param name="sortOpt">sport</xsl:with-param>
					</xsl:apply-templates>
					<xsl:apply-templates select="packet">
						<xsl:sort select="destination/@ip"/>
						<xsl:with-param name="sortOpt">destination</xsl:with-param>
					</xsl:apply-templates>
					<xsl:apply-templates select="packet">
						<xsl:sort select="destination/@port"/>
						<xsl:with-param name="sortOpt">dport</xsl:with-param>
					</xsl:apply-templates>
					<xsl:apply-templates select="packet">
						<xsl:sort select="timestamp/@date"/>
						<xsl:sort select="timestamp/@time"/>
						<xsl:with-param name="sortOpt">time</xsl:with-param>
					</xsl:apply-templates>
					<xsl:apply-templates select="packet">
						<xsl:sort select="reason/@action"/>
						<xsl:with-param name="sortOpt">reason</xsl:with-param>
					</xsl:apply-templates>
					<xsl:apply-templates select="packet">
						<xsl:sort select="extra/@information"/>
						<xsl:with-param name="sortOpt">extra</xsl:with-param>
					</xsl:apply-templates>
				</table>
			</body>
		</html>
	</xsl:template>	
	<xsl:template match="packet">
		<xsl:param name="sortOpt"/>
		<xsl:param name="IP_Displayed"/>
		<tr>
			<xsl:attribute name="class"><xsl:value-of select="$sortOpt"/></xsl:attribute>
			<xsl:attribute name="style">
				<xsl:if test="position() mod 2">
					background-color: #ffffff
				</xsl:if>			
				<xsl:if test="not(position() mod 2)">
					background-color: #cccccc
				</xsl:if>			
			</xsl:attribute>
			<td>
				<xsl:value-of select="source/@ip"/>
			</td>
			<td>
				<xsl:value-of select="source/@port"/>
			</td>
			<td>
				<xsl:value-of select="destination/@ip"/>
			</td>
			<td>
				<xsl:value-of select="destination/@port"/>
			</td>
			<td>
				<xsl:call-template name="prettyTime"/>
			</td>
			<td>
				<xsl:value-of select="reason/@action"/>
			</td>
			<td>
				<xsl:value-of select="extra/@information"/>
			</td>
		</tr>
	</xsl:template>
	
	<xsl:template name="prettyTime">
		<xsl:param name="time" select="timestamp/@time"/>
		<xsl:param name="date" select="timestamp/@date"/>
		<xsl:value-of select="$date"/><br/>
		<xsl:call-template name="printTime">
			<xsl:with-param name="time" select="$time"/>
		</xsl:call-template>
	</xsl:template>

	<xsl:template name="printTime">
		<xsl:param name="time"/>
		<xsl:value-of select="substring-before(substring-after($time,':'),':')"/>:
		<xsl:value-of select="substring-before(substring-after(substring-after($time,':'),':'),'.')"/> GMT
	</xsl:template>
	
	<xsl:template name="printDate">
		<xsl:param name="date"/>
	</xsl:template>

</xsl:stylesheet>