#!/bin/bash
 
NS_VSERVER="$1"
HTML_FILE="/srv/www/htdocs/${NS_VSERVER}.html"
 
cat > $HTML_FILE << EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
	"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>$NS_VSERVER - Anzahl Clients nach Datum</title>
	<style>
	.ns {
		margin:0px;padding:0px;
		width:100%;
		border:1px solid #000000;
		-moz-border-radius-bottomleft:0px;
		-webkit-border-bottom-left-radius:0px;
		border-bottom-left-radius:0px;
		-moz-border-radius-bottomright:0px;
		-webkit-border-bottom-right-radius:0px;
		border-bottom-right-radius:0px;
		-moz-border-radius-topright:0px;
		-webkit-border-top-right-radius:0px;
		border-top-right-radius:0px;
		-moz-border-radius-topleft:0px;
		-webkit-border-top-left-radius:0px;
		border-top-left-radius:0px;
	}.ns table{
		border-collapse: collapse;
		border-spacing: 0;
		width:100%;
		height:100%;
		margin:0px;padding:0px;
	}.ns th{
		font-size:14px;
		font-family:Verdana;
		font-weight:bold;
		border:1px solid #000000;
		border-width:0px 1px 1px 0px;
		text-align:left;
		padding:7px;
	}.ns tr:last-child td:last-child {
		-moz-border-radius-bottomright:0px;
		-webkit-border-bottom-right-radius:0px;
		border-bottom-right-radius:0px;
	}
	.ns table tr:first-child td:first-child {
		-moz-border-radius-topleft:0px;
		-webkit-border-top-left-radius:0px;
		border-top-left-radius:0px;
	}
	.ns table tr:first-child td:last-child {
		-moz-border-radius-topright:0px;
		-webkit-border-top-right-radius:0px;
		border-top-right-radius:0px;
	}.ns tr:last-child td:first-child{
		-moz-border-radius-bottomleft:0px;
		-webkit-border-bottom-left-radius:0px;
		border-bottom-left-radius:0px;
	}.ns tr:hover td{
 
	}
	.ns tr:nth-child(odd){ background-color:#aad4ff; }
	.ns tr:nth-child(even)    { background-color:#ffffff; }.ns td{
		vertical-align:middle;
		border:1px solid #000000;
		border-width:0px 1px 1px 0px;
		text-align:left;
		padding:7px;
		font-size:14px;
		font-family:Verdana;
		font-weight:normal;
		color:#000000;
	}.ns tr:last-child td{
		border-width:0px 1px 0px 0px;
	}.ns tr td:last-child{
		border-width:0px 0px 1px 0px;
	}.ns tr:last-child td:last-child{
		border-width:0px 0px 0px 0px;
	}
	.ns tr:first-child td{
			background:-o-linear-gradient(bottom, #005fbf 5%, #003f7f 100%);	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #005fbf), color-stop(1, #003f7f) );
		background:-moz-linear-gradient( center top, #005fbf 5%, #003f7f 100% );
		filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#005fbf", endColorstr="#003f7f");	background: -o-linear-gradient(top,#005fbf,003f7f);
		background-color:#005fbf;
		border:0px solid #000000;
		text-align:center;
		border-width:0px 0px 1px 1px;
		font-size:14px;
		font-family:Verdana;
		font-weight:bold;
		color:#ffffff;
	}
	.ns tr:first-child:hover td{
		background:-o-linear-gradient(bottom, #005fbf 5%, #003f7f 100%);	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #005fbf), color-stop(1, #003f7f) );
		background:-moz-linear-gradient( center top, #005fbf 5%, #003f7f 100% );
		filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#005fbf", endColorstr="#003f7f");	background: -o-linear-gradient(top,#005fbf,003f7f);
		background-color:#005fbf;
	}
	.ns tr:first-child td:first-child{
		border-width:0px 0px 1px 0px;
	}
	.ns tr:first-child td:last-child{
		border-width:0px 0px 1px 1px;
	}
	</style>
</head>
<body>
 
<h3>NetScaler Vserver $NS_VSERVER - sortiert nach Datum</h1>
 
<div class="ns">
	<table border="1">
		<tr>
			<th>Datum</th>
			<th>Zeit</th>
			<th>Anzahl Clients</th>
		</tr>
EOF
 
for line in $( tac /srv/www/${NS_VSERVER}_conntable.log ); do
	DATE="$( echo $line | cut -d\; -f1 | cut -d_ -f1 )"
	TIME="$( echo $line | cut -d\; -f1 | cut -d_ -f2 )"
	CONNECTIONS="$( echo $line | cut -d\; -f2 )"
 
	cat >> $HTML_FILE << EOF
		<tr>
			<td>$DATE</td>
			<td>$TIME</td>
			<td>$CONNECTIONS</td>
		</tr>
EOF
done
 
cat >> $HTML_FILE << EOF
</div>
</body>
</html>
EOF