Last active
April 17, 2019 13:02
-
-
Save Xeyame/7eef77af06b03a9cb46fa282952a8b0a to your computer and use it in GitHub Desktop.
Crappy openvpn status web viewer in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<style> | |
body { | |
margin: 50px; | |
font-family: arial, sans-serif; | |
} | |
table, th, td { | |
border: 1px solid black; | |
} | |
table { | |
border-collapse: collapse; | |
width: 100%; | |
} | |
td, th { | |
border: 1px solid #dddddd; | |
text-align: left; | |
padding: 8px; | |
} | |
tr:nth-child(even) { | |
background-color: #dddddd; | |
} | |
</style> | |
</head> | |
<body> | |
<?php | |
//Warning: Do not try to fix this code if its broken, Just rewrite it all. | |
//also this gives a lot of console errors, but thats "fixed" like this | |
error_reporting(0); | |
$fileloc = "/etc/openvpn/openvpn-status.log"; | |
$linenum = 0; | |
$routingtableLine = 0; | |
$globalstatsline = 0; | |
if ($file = fopen("$fileloc", "r")) { | |
while(!feof($file)) { | |
$line = fgets($file); | |
$linenum = $linenum + 1; | |
if ($linenum < 2) { | |
echo "<h1>$line</h1>"; | |
} | |
if ($linenum == 2) { | |
$values = explode(",", $line); | |
echo '<table style="width:100%">'; | |
echo '<tr>'; | |
foreach ($values as $value) { | |
echo "<th>".$value."</th>"; | |
} | |
echo '</tr>'; | |
echo '</table>'; | |
echo '<br>'; | |
} | |
if (preg_match('/ROUTING/',$line)) { | |
$routingtable = 1; | |
} | |
if (preg_match('/GLOBAL/',$line)) { | |
$globalstats = 1; | |
} | |
if ($linenum ==3) { | |
echo '<table style="width:100%">'.PHP_EOL; | |
echo '<tr>'; | |
$columns = explode(",", $line); | |
foreach($columns as $columname) { | |
echo "<th>".$columname."</th>"; | |
} | |
echo '</tr>'; | |
} | |
if (($linenum > 3) && ($routingtable != 1) && ($globalstats !=1)) { | |
echo '<tr>'; | |
$values = explode(",", $line); | |
foreach($values as $value) { | |
echo "<th>".$value."</th>"; | |
} | |
echo '</tr>'; | |
} | |
if (isset($routingtable)) { | |
if (($routingtable == 1) && ($globalstats !=1)) { | |
$routingtableLine = $routingtableLine + 1; | |
} | |
} | |
if (($routingtableLine == 1) && ($globalstats !=1)) { | |
echo '</table><br>'; | |
echo "<h3>$line</h3>"; | |
} | |
if (($routingtableLine == 2) && ($globalstats !=1)) { | |
echo '<table style="width:100%">'; | |
echo '<tr>'; | |
$columns = explode(",", $line); | |
foreach($columns as $columname) { | |
echo "<th>".$columname."</th>"; | |
} | |
echo '</tr>'; | |
} | |
if (($routingtableLine > 2) && ($globalstats !=1)) { | |
echo '<tr>'; | |
$values = explode(",", $line); | |
foreach($values as $value) { | |
echo "<th>".$value."</th>"; | |
} | |
echo '</tr>'; | |
} | |
if (isset($globalstats)) { | |
if ($globalstats == 1) { | |
echo '</table><br>'; | |
$globalstatsline = $globalstatsline + 1; | |
if ($globalstatsline == 1) { | |
echo "<h3>$line</h3>"; | |
} | |
if ($globalstatsline ==2) { | |
$values = explode(",", $line); | |
echo '<table style="width:100%">'; | |
echo '<tr>'; | |
foreach ($values as $value) { | |
echo "<th>".$value."</th>"; | |
} | |
echo '</tr>'; | |
echo '</table>'; | |
} | |
} | |
} | |
} | |
fclose($file); | |
} else { | |
echo "File not found."; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment