diag_logs_vpn.php 4.77 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4
	Copyright (C) 2014 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
	Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	1. Redistributions of source code must retain the above copyright notice,
	   this list of conditions and the following disclaimer.

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/

$pgtitle = array(gettext("Status"), gettext("System logs"), gettext("VPN"));
31
require_once("guiconfig.inc");
Ad Schellevis's avatar
Ad Schellevis committed
32
require_once("vpn.inc");
33
require_once("system.inc");
34
require_once("interfaces.inc");
Ad Schellevis's avatar
Ad Schellevis committed
35

36 37 38 39 40
if (empty($config['syslog']['nentries'])) {
        $nentries = 50;
} else {
        $nentries = $config['syslog']['nentries'];
}
Ad Schellevis's avatar
Ad Schellevis committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

if (htmlspecialchars($_POST['vpntype']))
	$vpntype = htmlspecialchars($_POST['vpntype']);
elseif (htmlspecialchars($_GET['vpntype']))
	$vpntype = htmlspecialchars($_GET['vpntype']);
else
	$vpntype = "pptp";

if (htmlspecialchars($_POST['mode']))
	$mode = htmlspecialchars($_POST['mode']);
elseif (htmlspecialchars($_GET['mode']))
	$mode = htmlspecialchars($_GET['mode']);
else
	$mode = "login";

switch ($vpntype) {
	case 'pptp':
		$logname = "pptps";
		break;
	case 'poes':
		$logname = "poes";
		break;
	case 'l2tp':
		$logname = "l2tps";
		break;
}

if ($_POST['clear']) {
69 70 71 72 73
	if ($mode != "raw") {
		clear_clog("/var/log/vpn.log");
	} else {
		clear_clog("/var/log/{$logname}.log");
	}
Ad Schellevis's avatar
Ad Schellevis committed
74 75 76 77 78 79 80 81
}

function dump_clog_vpn($logfile, $tail) {
	global $g, $config, $vpntype;

	$sor = isset($config['syslog']['reverse']) ? "-r" : "";

	$logarr = "";
82

83
	exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . " | tail {$sor} -n " . $tail, $logarr);
Ad Schellevis's avatar
Ad Schellevis committed
84

85
	foreach ($logarr as $logent) {
Ad Schellevis's avatar
Ad Schellevis committed
86 87 88 89 90 91 92 93 94
		$logent = preg_split("/\s+/", $logent, 6);
		$llent = explode(",", $logent[5]);
		$iftype = substr($llent[1], 0, 4);
		if ($iftype != $vpntype)
			continue;
		echo "<tr>\n";
		echo "<td class=\"listlr nowrap\">" . htmlspecialchars(join(" ", array_slice($logent, 0, 3))) . "</td>\n";

		if ($llent[0] == "login")
95
			echo "<td class=\"listr\"><span class=\"glyphicon glyphicon-arrow-right\" aria-hidden=\"true\" alt=\"in\"></span></td>\n";
Ad Schellevis's avatar
Ad Schellevis committed
96
		else
97
			echo "<td class=\"listr\"><span class=\"glyphicon glyphicon-arrow-left\" aria-hidden=\"true\" alt=\"out\"></span></td>\n";
Ad Schellevis's avatar
Ad Schellevis committed
98 99 100 101 102 103 104 105 106 107

		echo "<td class=\"listr\">" . htmlspecialchars($llent[3]) . "</td>\n";
		echo "<td class=\"listr\">" . htmlspecialchars($llent[2]) . "&nbsp;</td>\n";
		echo "</tr>\n";
	}
}

include("head.inc");

?>
108 109 110 111


<body>

Ad Schellevis's avatar
Ad Schellevis committed
112
<?php include("fbegin.inc"); ?>
113 114

	<section class="page-content-main">
115
		<div class="container-fluid">
116
			<div class="row">
117

118
				<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
119

120
			    <section class="col-xs-12">
121 122 123 124

					<div class="tab-content content-box col-xs-12">


125
							 <div class="table-responsive">
126
								<table class="table table-striped table-sort">
127
									<tr><td colspan="4"><?php $tab_group = 'vpn'; include('diag_logs_pills.inc'); ?></td></tr>
128
									 <?php if ($mode != "raw"): ?>
129 130 131 132 133 134 135
										<tr>
											<td class="listhdrr"><?=gettext("Time");?></td>
											<td class="listhdrr"><?=gettext("Action");?></td>
											<td class="listhdrr"><?=gettext("User");?></td>
											<td class="listhdrr"><?=gettext("IP address");?></td>
										</tr>
											<?php dump_clog_vpn("/var/log/vpn.log", $nentries); ?>
136
										<?php else:
137 138
											dump_clog("/var/log/{$logname}.log", $nentries);
									  endif; ?>
Franco Fichtner's avatar
Franco Fichtner committed
139
							<tr><td colspan="4">
140 141 142 143 144
							<form action="diag_logs_vpn.php" method="post">
								<input type="hidden" name="vpntype" id="vpntype" value="<?=$vpntype;?>" />
								<input type="hidden" name="mode" id="mode" value="<?=$mode;?>" />
								<input name="clear" type="submit" class="btn" value="<?= gettext("Clear log");?>" />
							</form>
Franco Fichtner's avatar
Franco Fichtner committed
145 146 147
							</td></tr>
								</table>
							 </div>
148 149


150
				    </div>
151
			</section>
152 153 154
			</div>
		</div>
	</section>
155 156

<?php include("foot.inc"); ?>