OpenVPN_Management_GUI/Admin/Modules/Logviewer/index.php

176 lines
6.1 KiB
PHP
Raw Normal View History

2012-07-16 21:30:19 +02:00
<?php
include($_SERVER["DOCUMENT_ROOT"]."/Site/checkadmin.php");
include ($_SERVER["DOCUMENT_ROOT"]."/Config/_dbconfig_.php");
@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;
}
$sort = mysql_real_escape_string($_POST["dirsort"]); //$_GET["sort"];
$by = mysql_real_escape_string($_POST["sortby"]); //$_GET["by"];
$table = mysql_real_escape_string($_POST["table"]); //$_GET["table"];
$client= mysql_real_escape_string($_POST["client"]);
?>
<!-- MAIN CONTENT BEGINN ################################################################################ -->
2012-07-17 21:15:23 +02:00
<!-- MAIN -->
<div id="main">
<div class="wrapper">
<form action="<?php echo $PHP_SELF; ?>" method="post">
<br>
<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>
2012-07-16 21:30:19 +02:00
2012-07-17 21:15:23 +02:00
<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>
2012-07-16 21:30:19 +02:00
2012-07-17 21:15:23 +02:00
<select name="sortby" size=1>
<option <?php if($by=="id") echo "selected";?> value="id">ID</option>
<option <?php if($by=="client") echo "selected";?> value="client">Client</option>
<option <?php if($by=="sent") echo "selected";?> value="sent">Sent</option>
<option <?php if($by=="received") echo "selected";?> value="received">Received</option>
<option <?php if($by=="ip") echo "selected";?> value="ip">IP</option>
</select>
Search Client:<input type="text" name="client" size="20" <?php if($client !="") echo "value=".$client;?> ></td>
<input type="submit" value="go!">
</form>
2012-07-16 21:30:19 +02:00
<!------ Sorting Leiste Start-->
<?
// MYsql befehl basteln
$sql = "SELECT * FROM $table ORDER BY $by $sort;";
$result = mysql_query($sql);
echo "<br><table border=1>";
if($table=='connections')
{
echo "<tr><td>Start Time</td><td>Stop Time</td><td>Client Name</td><td>Client IP</td><td>Download
</td><td>Upload</td></tr>\n";
}
else if($table=='month')
{
echo "<tr><td>Month</td><td>Year</td><td>Connection Time</td><td>Client Name</td><td>Download
</td><td>Upload</td></tr>\n";
}
else if($table=='year')
{
echo "<tr><td>Year</td><td>Connection Time</td><td>Client Name</td><td>Download
</td><td>Upload</td></tr>\n";
}
else
{
}
// ------------------------------------------------ Mysql lesen
if ($result)
{
while ($ar=mysql_fetch_array($result,MYSQL_ASSOC))
{
if($ar["sent"]>1024)
{
$sentbytes = round($ar["sent"]/1024,2) . " KiB";
if($ar["sent"]>1048576)
{
$sentbytes = round($ar["sent"]/1024/1024,2) . " MiB";
if($ar["sent"]>1073741824)
{
$sentbytes = round($ar["sent"]/1024/1024/1024,2) . " GiB";
}
}
}
else
{
$sentbytes = $ar["sent"]. " Byte";
}
if($ar["received"]>1024)
{
$receivedbytes = round($ar["received"]/1024,2) . " KiB";
if($ar["received"]>1048576)
{
$receivedbytes = round($ar["received"]/1024/1024,2) . " MiB";
if($ar["received"]>1073741824)
{
$receivedbytes = round($ar["received"]/1024/1024/1024,2) . " GiB";
}
}
}
else
{
$receivedbytes = $ar["received"]. " Byte";
}
if($table=='connections')
{
if($ar["stop"] != 0)
{
$stop = date("r",$ar["stop"]);
}
else
{
$stop = "running session";
}
if($client == "" || $ar["client"] == $client)
{
echo "<tr><td>",date("r",$ar["start"]),"</td><td>",$stop,"</td><td>",$ar["client"],
"</td><td>",$ar["ip"],
"</td><td align=right>",$sentbytes,
"</td><td align=right>",$receivedbytes,
"</td></tr>\n";
}
}
else if($table=='month')
{
$hour = floor($ar["time"]/3600);
$min = floor($ar["time"]/60 - $hour *60);
$sec = $ar["time"]-$hour*3600-$min*60;
$timestring = $hour .":". $min .":". $sec;
if($client == "" || $ar["client"] == $client)
{
echo "<tr><td>",$ar["month"],"</td><td>",$ar["year"],"</td><td>",$timestring,
"</td><td>",$ar["client"],
"</td><td align=right>",$sentbytes,"</td><td align=right>",$receivedbytes,
"</td></tr>\n";
}
}
else if($table=='year')
{
$hour = floor($ar["time"]/3600);
$min = floor($ar["time"]/60 - $hour *60);
$sec = $ar["time"]-$hour*3600-$min*60;
$timestring = $hour .":". $min .":". $sec;
if($client == "" || $ar["client"] == $client)
{
echo "<tr><td>",$ar["year"],"</td><td>",$timestring,
"</td><td>",$ar["client"],
"</td><td align=right>",$sentbytes,"</td><td align=right>",$receivedbytes,
"</td></tr>\n";
}
}
else
{
}
}
}
else
{
echo "<br>";
}
echo "</table>";
mysql_close();
?>
2012-07-17 21:15:23 +02:00
</div>
</div>