User Tools

Site Tools


Legacy VPN manager

OMG code example. How it can worked, I do not know =)

cmd.php

cmd.php
<html>
<head>
<META HTTP-EQUIV="REFRESH" CONTENT="5; URL=cmd.php?">
<style>
.red {
    color: red;
}
.ok {
    color: darkgreen;
}
.cmd {
    color: brown;
}
</style>
</head>
<body>
<?
 
$c = isset($_GET['c']) ? $_GET['c'] : '';
$t = isset($_GET['s']) ? $_GET['t'] : '';
$s = isset($_GET['t']) ? $_GET['s'] : '';
 
if (md5($t.$c.'_') != $s) {
//    echo "<h1 style=\"red\">wrong params</h1>";
} else {
    $cmd = '/usr/bin/sudo '.$c;
    echo "<pre><code>Command 
";
    echo $cmd;
    echo "
 results in:

</pre>\n“;

  echo "<pre><code class=\"ok\">";
  echo `$cmd`;
  echo "</code></pre>\n";

}

?> </body></code>

cmdplain.php

cmdplain.php
<?
 
$c = isset($_GET['c']) ? $_GET['c'] : '';
$t = isset($_GET['s']) ? $_GET['t'] : '';
$s = isset($_GET['t']) ? $_GET['s'] : '';
 
if (md5($t.$c.'_') != $s) {
//    echo "<h1 style=\"red\">wrong params</h1>";
} else {
    $cmd = '/usr/bin/sudo '.$c;
    echo `$cmd`;
}
 
?>

do.php

do.php
<?php
 
// phpinfo();
$act = isset($_GET['act']) ? trim($_GET['act']) : '';
$id = isset($_GET['id']) ? trim($_GET['id']) : '';
 
if (in_array($act, array('on', 'off')) && ($id > '')) {
 
$cmd = sprintf('sudo /usr/sbin/service openvpn %s %s', ($act == 'off' ? 'stop' : 'restart'), escapeshellcmd($id));
 
echo `$cmd`;
} else {
#echo "Wrong invocate";
}
header('Location: ./?');
?>

index.php

index.php
<?php
 
ob_start("ob_gzhandler");
 
?><html>
<head>
<META HTTP-EQUIV="REFRESH" CONTENT="60">
<style>
p {
    height: 30px; 
    font-size: 16px; 
    font-family: Verdana,Arial,Sans-Serif; 
    padding: 0px; 
    margin: 0px;
    color: #999999;
}
p a {
    text-decoration: none;
    color: black;
    border: 1px #efefef solid;
    padding: 1px 4px 4px 4px;
}
p a:hover {
    text-decoration: none;
    border: 1px #999999 solid;
}
</style>
</head>
 
<body bgcolor="#efefef" color="#000000">
<h1>OpenVPN servers MSK-01</h1>
<div>
<?php
 
$cmd = '/usr/bin/sudo /usr/sbin/service openvpn status';
 
$pps = explode("\n", `$cmd`);
 
#  * VPN 'g-2293u' is running

 
foreach ($pps as $pp) {
    $pp = trim($pp);
    if (preg_match('|\*\s+VPN\s+\'(.+)\'\s+(.+)$|', $pp, $get)) {
	$warning = ($get[2] != 'is running');
	$count = '0';
	$desc = '';
 
#	if (substr($get[1], 0, 1) == 'g') {
	if (1) {
	    $idp = $get[1];
	    $cmd2 = sprintf('sudo /bin/cat /var/log/openvpn/%s.stat | /usr/bin/awk \'BEGIN{FS=","} $2 ~/:/ && $2 ~/^[1-9]/ {print $2}\' | /usr/bin/wc -l', $idp);
 
 
	    $ret = `$cmd2`;
	    $count = trim($ret);
 
	    switch ($idp) {
		case "s3101":
		    $desc = "VPNCs";
		    break;
		default:
		    $desc = "No description";
	    }
	}
	printf("<p class=\"%s\"><a href=\"./do.php?act=%s&id=%s\">".
"<img src=\"%s.gif\" border=\"0\" width=\"56\" height=\"16\" alt=\"\" align=\"absmiddle\"> %s</a> Count=%s <a href=\"./who.php?id=%s\">Who?</a> %s</p>\n", 
		$warning ? 'green' : 'red', 
		$warning ? 'on' : 'off', 
		urlencode($idp), 
		$warning ? 'off' : 'on', 
		$idp, 
		$count,
		urlencode($idp),
		$desc
	);
    }
}
 
?>
</div>
</body>

multi.php

multi.php
<?
 
ob_start("ob_gzhandler");
header('Content-Type: text/html; charset=UTF-8');
 
?>
<html>
<head>
<title>Multi attempts</title>
 
<link rel="stylesheet" href="cssnormalize-min.css">
<style>
body, p, .half {
    line-height: 170%;
    font-size: 12px;
    font-family: Verdana,Arial,Sans-Serif;
    padding: 0px;
    margin: 0px;
    color: #000;
}
 
.half {
    width: 49%; 
    float: left; 
    overflow: scroll;
    overflow-x: scroll;
    overflow-y: hidden;
    white-space: nowrap;
}
 
</style>
</head>
<body>
 
<h1>Список попыток двойного подключения с тем же сертификатом на тот же порт</h1>
 
<p><a href="./?"><< вернуться к общей картине</a>. Красным выделены ошибки за последние 4 часа. Слева - Микротики, справа - подключения с ПК. Выводятся данные только для портов, где имеются ошибки с момента последнего перезапуска сервиса на порту.</p>
 
<div class="half" style="margin-right: 1%;">
<?
 
$ll = glob('/etc/openvpn/logs/6*.log');
 
// var_dump($ll);
 
foreach ($ll as $fn) {
    $pp = pathinfo($fn);
//var_dump($pp);
    $cmd = '/usr/bin/sudo /bin/grep -h "will cause previous active sessions" '.$fn.' | /bin/grep MULTI | /usr/bin/tail -n 15';
    $out = `$cmd`;
    $out = trim($out);
    if ($out > '') {
    echo "<h2>".htmlspecialchars($pp["filename"])."</h2>\n";
    foreach (explode("\n", $out) as $l) {
	$l = trim($l);
	if ($l > '') {
	    $pp = explode(' ', $l, 12);
	    $t = $pp[2].' '.$pp[1].' '.$pp[4].', '.$pp[3];
	    if ((time() - strtotime($t)) < 60*60*4) {
		echo $t.' '.$pp[5].' '.$pp[6].' '.$pp[7].' '.$pp[8].' '.$pp[9].' '.'<span style="color: red; font-size: 120%">'.$pp[10].'</span> '.$pp[11];
	    } else {
		$color = '#999';
		if ((time() - strtotime($t)) > 60*60*24) $color = '#ccc';
		echo '<span style="color: '.$color.'">'.$t.' '.$pp[5].' '.$pp[6].' '.$pp[7].' '.$pp[8].' '.$pp[9].' '.'<span style="font-weight: bold;">'.$pp[10].'</span> '.$pp[11].'</span>';
	    }
	    echo "\n";
	}
    }
    }
}
 
?>
</div>
 
<div class="half"  style="margin-left: 1%;">
<?
 
$ll = glob('/etc/openvpn/logs/4*.log');
 
// var_dump($ll);
 
foreach ($ll as $fn) {
    $pp = pathinfo($fn);
//var_dump($pp);
    $cmd = '/usr/bin/sudo /bin/grep -h "will cause previous active sessions" '.$fn.' | /bin/grep MULTI | /usr/bin/tail -n 15';
    $out = `$cmd`;
    $out = trim($out);
    if ($out > '') {
    echo "<h2>".htmlspecialchars($pp["filename"])."</h2>\n";
    foreach (explode("\n", $out) as $l) {
	$l = trim($l);
	if ($l > '') {
	    $pp = explode(' ', $l, 12);
	    $t = $pp[2].' '.$pp[1].' '.$pp[4].', '.$pp[3];
	    if ((time() - strtotime($t)) < 60*60*4) {
		echo $t.' '.$pp[5].' '.$pp[6].' '.$pp[7].' '.$pp[8].' '.$pp[9].' '.'<span style="color: red; font-size: 120%">'.$pp[10].'</span> '.$pp[11];
	    } else {
		$color = '#999';
		if ((time() - strtotime($t)) > 60*60*24) $color = '#ccc';
		echo '<span style="color: '.$color.'">'.$t.' '.$pp[5].' '.$pp[6].' '.$pp[7].' '.$pp[8].' '.$pp[9].' '.'<span style="font-weight: bold;">'.$pp[10].'</span> '.$pp[11].'</span>';
	    }
	    echo "\n";
	}
    }
    } else {
echo "*".$out."*";
    }
}
 
?>
</div>
<div style="clear: both;"><pre><code><?
echo trim(`/bin/uname -a`);
?>

</pre></div> </body> </html></code>

openvpn.php

openvpn.php
<html>
<head>
<META HTTP-EQUIV="REFRESH" CONTENT="3">
</head>
<body>
<?php
 
// phpinfo();
 
$cmd = '/usr/sbin/service openvpn status';
 
echo "<pre><code>";
echo `$cmd`;
echo "

</pre>”;

?> </body></code>

ps.php

ps.php
<html>
<head>
<META HTTP-EQUIV="REFRESH" CONTENT="3">
</head>
<body>
<?php
 
// phpinfo();
 
$cmd = '/bin/ps -eo pcpu,pid,user,args | /bin/grep -v www-data | /bin/grep -v COMMAND | /bin/grep -v CPU | grep openvpn | /usr/bin/sort -k 1 -r';
 
echo "<pre><code>";
echo `$cmd`;
echo "

</pre>“;

?> </body></code>

test.php

test.php
<?
 
$c = '/usr/bin/sudo whoami';
 
?>

uptime.php

uptime.php
<html>
<head>
<META HTTP-EQUIV="REFRESH" CONTENT="5">
</head>
<body>
<?php
 
// phpinfo();
 
$cmd = '/usr/bin/uptime';
 
echo "<pre><code>";
echo `$cmd`;
echo "

</pre>”;

?> </body></code>

who.php

who.php
<?php
 
// phpinfo();
 
 
$id = isset($_GET['id']) ? trim($_GET['id']) : '';
 
if ($id > '') {
 
    echo "<h1> Who has a connection to ".$id."?</h1>\n";
 
    echo "<dl>\n";
 
    $cmd = sprintf('sudo /bin/cat /var/log/openvpn/%s.stat |awk \'BEGIN{FS=","} $1~/^[1-9][1-90].*[1-90]$/ && $1 !~/[\/A-Z]/ {print}\'', $id);
    foreach (explode("\n", `$cmd`) as $line) {
	$line = trim($line);
	if ($line > '') {
	    $pp = explode(",", $line);
	    printf('<dt><b>%s</b></dt><dd>%s<br>WAN: %s<br>LAN: %s</dd>'."\n", 
		htmlspecialchars($pp[1]),
		htmlspecialchars($pp[3]), 
		htmlspecialchars($pp[2]), 
		htmlspecialchars($pp[0]));
	}
    }
    echo "</dl>\n";
}
?>

50x.html

50x.html
<html>
<head>
<title>The page is temporarily unavailable</title>
<style>
body { font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body bgcolor="white" text="black">
<table width="100%" height="100%">
<tr>
<td align="center" valign="middle">
The page you are looking for is temporarily unavailable.<br/>
Please try again later.
</td>
</tr>
</table>
</body>
</html>

index.html

index.html
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>