OpenVPN_Management_GUI/Modules/ServerTraffic/index.php

221 lines
5.6 KiB
PHP
Raw Permalink Normal View History

2012-07-16 21:30:19 +02:00
<?php
include($_SERVER["DOCUMENT_ROOT"]."/Config/_dbconfig_.php");
@$y = mysql_connect($MYSQL_HOST,$MYSQL_USER,$MYSQL_PASS);
@$x = mysql_select_db($MYSQL_DATABASE);
if (empty($x))
{
echo "ERROR 0x01, Failed to connect to database!<br>";
exit;
}
$by = "id"; //$_GET["by"];
if($_POST["dirsort"] != "")
{
$sort = mysql_real_escape_string($_POST["dirsort"]);
}
else
{
$sort = $_POST["dirsort"];
}
if($_POST["table"] != "")
{
$table = mysql_real_escape_string($_POST["table"]);
}
else
{
$table = $_POST["table"];
}
function Potenz($sent_sum)
{
if($sent_sum>1024)
{
$sent_sum_anz=round($sent_sum/1024,2) . "kiB";
if($sent_sum>1024*1024)
{
$sent_sum_anz=round($sent_sum/(1024*1024),2) . "MiB";
if($sent_sum>1024*1024*1024)
{
$sent_sum_anz=round($sent_sum/(1024*1024*1024),2) . "GiB";
}
}
}
else
{
$sent_sum_anz=$sent_sum . "Byte";
}
return $sent_sum_anz;
}
?>
<!-- MAIN CONTENT BEGINN ################################################################################ -->
2012-07-16 22:56:46 +02:00
<!-- MAIN -->
<div id="main">
<div class="wrapper">
<br />
<form action="<?php echo $PHP_SELF; ?>" method="post">
<select name="dirsort" size=1>
<option <?php if($sort=="ASC") echo "selected";?> value="ASC">Up</option>
<option <?php if($sort=="DESC") echo "selected";?> value="DESC">Down</option>
</select>
<select name="table" size=1>
<option <?php if($table=="year") echo "selected";?> value="year">Year</option>
<option <?php if($table=="month") echo "selected";?> value="month">Month</option>
<option <?php if($table=="connections") echo "selected";?> value="connections">All</option>
</select>
<input type="submit" value="go!" />
</form>
<!-- Sorting Leiste Start-->
<?
// MYsql befehl basteln
$sql = "SELECT * FROM $table ORDER BY $by $sort;";
$result = mysql_query($sql);
2012-07-17 21:15:23 +02:00
echo "<table style=\"border: 1px solid;\">";
2012-07-16 22:56:46 +02:00
if($table=='connections')
{
2012-07-17 21:15:23 +02:00
echo "<tr style=\"border: 1px solid;\"><td>Start Time</td><td>Stop Time</td><td>Client IP</td><td>Download
2012-07-16 22:56:46 +02:00
</td><td>Upload</td></tr>\n";
}
else if($table=='month')
{
2012-07-17 21:15:23 +02:00
echo "<tr style=\"border: 1px solid;\"><td>Month</td><td>Year</td><td>Connection Time</td><td>Download
2012-07-16 22:56:46 +02:00
</td><td>Upload</td></tr>\n";
}
else if($table=='year')
{
2012-07-17 21:15:23 +02:00
echo "<tr style=\"border: 1px solid;\"><td>Year</td><td>Connection Time</td><td>Download
2012-07-16 22:56:46 +02:00
</td><td>Upload</td></tr>\n";
}
else
{
}
// ------------------------------------------------ Mysql lesen
if ($result)
{
//Zusammenzaehlen
$time_sum=0;
$month=0;
$year=0;
$sent_sum=0;
$received_sum=0;
while ($ar=mysql_fetch_array($result,MYSQL_ASSOC))
{
if($table=='connections')
{
if($ar["stop"] != 0)
{
$stop = date("r",$ar["stop"]);
}
else
{
$stop = "running session";
}
echo "<tr><td align=right>",date("r",$ar["start"]),"</td><td align=right>",$stop,"</td><td>",$ar["ip"],
"</td><td align=right>",Potenz($ar["sent"]),"</td><td align=right>",Potenz($ar["received"]),
"</td></tr>\n";
}
else if($table=='month')
{
if($month!=$ar["month"] && $month!=0)
{
$hour = floor($time_sum/3600);
$min = floor($time_sum/60 - $hour *60);
$sec = $time_sum-$hour*3600-$min*60;
$timestring = $hour .":". $min .":". $sec;
$sent_sum_anz = Potenz($sent_sum);
$received_sum_anz = Potenz($received_sum);
echo "<tr><td>",$month,"</td><td>",$year,"</td><td>",$timestring,
"</td><td align=right>",$sent_sum_anz,"</td><td align=right>",$received_sum_anz,
"</td></tr>\n";
$sent_sum=0;
$received_sum=0;
$time_sum=0;
}
else
{
}
$month=$ar["month"];
$year=$ar["year"];
$time_sum += $ar["time"];
$sent_sum += $ar["sent"];
$received_sum += $ar["received"];
}
else if($table=='year')
{
if($year!=$ar["year"] && $year!=0)
{
$hour = floor($time_sum/3600);
$min = floor($time_sum/60 - $hour *60);
$sec = $time_sum-$hour*3600-$min*60;
$timestring = $hour .":". $min .":". $sec;
$sent_sum_anz = Potenz($sent_sum);
$received_sum_anz = Potenz($received_sum);
echo "<tr><td>",$year,"</td><td>",$timestring,
"</td><td align=right>",$sent_sum_anz,"</td><td align=right>",$received_sum_anz,
"</td></tr>\n";
$sent_sum=0;
$received_sum=0;
$time_sum=0;
}
else
{
}
$year=$ar["year"];
$time_sum += $ar["time"];
$sent_sum += $ar["sent"];
$received_sum += $ar["received"];
}
else
{
}
}
//letzen Datensatz ausgeben
$hour = floor($time_sum/3600);
$min = floor($time_sum/60 - $hour *60);
$sec = $time_sum-$hour*3600-$min*60;
$timestring = $hour .":". $min .":". $sec;
$sent_sum_anz = Potenz($sent_sum);
$received_sum_anz = Potenz($received_sum);
if($table=='year')
{
echo "<tr><td>",$year,"</td><td>",$timestring,
"</td><td align=right>",$sent_sum_anz,"</td><td align=right>",$received_sum_anz,
"</td></tr>\n";
}
else if($table=='month')
{
echo "<tr><td>",$month,"</td><td>",$year,"</td><td>",$timestring,
"</td><td align=right>",$sent_sum_anz,"</td><td align=right>",$received_sum_anz,
"</td></tr>\n";
}
$sent_sum=0;
$received_sum=0;
$time_sum=0;
//---------------------------------
}
else
{
echo "<br>";
}
echo "</table>";
mysql_close();
?>
</div>
</div>
2012-07-16 21:30:19 +02:00
<!-- END CONTENT BEGINN ################################################################################# -->