Project

General

Profile

Download (6.76 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	diag_logs_vpn.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9
	All rights reserved.
10

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

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

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

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

    
33
/*	
34
	pfSense_BUILDER_BINARIES:	/usr/sbin/fifolog_reader	/usr/local/sbin/clog
35
	pfSense_MODULE:	vpn
36
*/
37

    
38
##|+PRIV
39
##|*IDENT=page-diagnostics-logs-pptpvpn
40
##|*NAME=Diagnostics: Logs: VPN page
41
##|*DESCR=Allow access to the 'Diagnostics: Logs: VPN' page.
42
##|*MATCH=diag_logs_vpn.php*
43
##|-PRIV
44

    
45
$pgtitle = array(gettext("Status"), gettext("System logs"), gettext("VPN"));
46
require("guiconfig.inc");
47
require_once("vpn.inc");
48

    
49
$nentries = $config['syslog']['nentries'];
50
if (!$nentries)
51
	$nentries = 50;
52

    
53
if (htmlspecialchars($_POST['vpntype']))
54
	$vpntype = htmlspecialchars($_POST['vpntype']);
55
elseif (htmlspecialchars($_GET['vpntype']))
56
	$vpntype = htmlspecialchars($_GET['vpntype']);
57
else
58
	$vpntype = "pptp";
59

    
60
if (htmlspecialchars($_POST['mode']))
61
	$mode = htmlspecialchars($_POST['mode']);
62
elseif (htmlspecialchars($_GET['mode']))
63
	$mode = htmlspecialchars($_GET['mode']);
64
else
65
	$mode = "login";
66

    
67
switch ($vpntype) {
68
	case 'pptp':
69
		$logname = "pptps";
70
		break;
71
	case 'poes':
72
		$logname = "poes";
73
		break;
74
	case 'l2tp':
75
		$logname = "l2tps";
76
		break;
77
}
78

    
79
if ($_POST['clear']) {
80
	if ($mode != "raw")
81
		clear_log_file("/var/log/vpn.log");
82
	else
83
		clear_log_file("/var/log/{$logname}.log");
84
}
85

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

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

    
91
	$logarr = "";
92
	
93
	if(isset($config['system']['usefifolog'])) 
94
		exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . " | tail {$sor} -n " . $tail, $logarr);
95
	else 
96
		exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . " | tail {$sor} -n " . $tail, $logarr);
97

    
98
	foreach ($logarr as $logent) {
99
		$logent = preg_split("/\s+/", $logent, 6);
100
		$llent = explode(",", $logent[5]);
101
		$iftype = substr($llent[1], 0, 4);
102
		if ($iftype != $vpntype)
103
			continue;
104
		echo "<tr>\n";
105
		echo "<td class=\"listlr nowrap\">" . htmlspecialchars(join(" ", array_slice($logent, 0, 3))) . "</td>\n";
106

    
107
		if ($llent[0] == "login")
108
			echo "<td class=\"listr\"><img src=\"/themes/{$g['theme']}/images/icons/icon_in.gif\" width=\"11\" height=\"11\" title=\"login\" alt=\"in\" /></td>\n";
109
		else
110
			echo "<td class=\"listr\"><img src=\"/themes/{$g['theme']}/images/icons/icon_out.gif\" width=\"11\" height=\"11\" title=\"logout\" alt=\"out\" /></td>\n";
111

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

    
118
include("head.inc");
119

    
120
?>
121
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
122
<?php include("fbegin.inc"); ?>
123
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="logs vpn">
124
  <tr><td class="tabnavtbl">
125
<?php
126
	$tab_array = array();
127
	$tab_array[] = array(gettext("System"), false, "diag_logs.php");
128
	$tab_array[] = array(gettext("Firewall"), false, "diag_logs_filter.php");
129
	$tab_array[] = array(gettext("DHCP"), false, "diag_logs_dhcp.php");
130
	$tab_array[] = array(gettext("Portal Auth"), false, "diag_logs_auth.php");
131
	$tab_array[] = array(gettext("IPsec"), false, "diag_logs_ipsec.php");
132
	$tab_array[] = array(gettext("PPP"), false, "diag_logs_ppp.php");
133
	$tab_array[] = array(gettext("VPN"), true, "diag_logs_vpn.php");
134
	$tab_array[] = array(gettext("Load Balancer"), false, "diag_logs_relayd.php");
135
	$tab_array[] = array(gettext("OpenVPN"), false, "diag_logs_openvpn.php");
136
	$tab_array[] = array(gettext("NTP"), false, "diag_logs_ntpd.php");
137
	$tab_array[] = array(gettext("Settings"), false, "diag_logs_settings.php");
138
	display_top_tabs($tab_array);
139
?>
140
  </td></tr>
141
  <tr><td class="tabnavtbl">
142
<?php
143
	$tab_array = array();
144
	$tab_array[] = array(gettext("PPTP Logins"),
145
				(($vpntype == "pptp") && ($mode != "raw")),
146
				"/diag_logs_vpn.php?vpntype=pptp");
147
	$tab_array[] = array(gettext("PPTP Raw"),
148
				(($vpntype == "pptp") && ($mode == "raw")),
149
				"/diag_logs_vpn.php?vpntype=pptp&amp;mode=raw");
150
	$tab_array[] = array(gettext("PPPoE Logins"),
151
				(($vpntype == "poes") && ($mode != "raw")),
152
				"/diag_logs_vpn.php?vpntype=poes");
153
	$tab_array[] = array(gettext("PPPoE Raw"),
154
				(($vpntype == "poes") && ($mode == "raw")),
155
				"/diag_logs_vpn.php?vpntype=poes&amp;mode=raw");
156
	$tab_array[] = array(gettext("L2TP Logins"),
157
				(($vpntype == "l2tp") && ($mode != "raw")),
158
				"/diag_logs_vpn.php?vpntype=l2tp");
159
	$tab_array[] = array(gettext("L2TP Raw"),
160
				(($vpntype == "l2tp") && ($mode == "raw")),
161
				"/diag_logs_vpn.php?vpntype=l2tp&amp;mode=raw");
162
	display_top_tabs($tab_array);
163
?>
164
  </td></tr>
165
  <tr>
166
    <td class="tabcont">
167
	<form action="diag_logs_vpn.php" method="post">
168
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
169
		<tr>
170
		<td colspan="4" class="listtopic">
171
			<?php printf(gettext('Last %1$s %2$s VPN log entries'),$nentries,$vpns[$vpntype]);?></td>
172
		</tr>
173
		<?php if ($mode != "raw"): ?>
174
		<tr>
175
			<td class="listhdrr"><?=gettext("Time");?></td>
176
			<td class="listhdrr"><?=gettext("Action");?></td>
177
			<td class="listhdrr"><?=gettext("User");?></td>
178
			<td class="listhdrr"><?=gettext("IP address");?></td>
179
		</tr>
180
			<?php dump_clog_vpn("/var/log/vpn.log", $nentries); ?>
181
		<?php else: 
182
			dump_clog("/var/log/{$logname}.log", $nentries);
183
		      endif; ?>
184
	</table>
185
	<br />
186
	<input type="hidden" name="vpntype" id="vpntype" value="<?=$vpntype;?>" />
187
	<input type="hidden" name="mode" id="mode" value="<?=$mode;?>" />
188
	<input name="clear" type="submit" class="formbtn" value="<?=gettext("Clear log"); ?>" />
189
	</form>
190
	</td>
191
  </tr>
192
</table>
193
<?php include("fend.inc"); ?>
194
</body>
195
</html>
(35-35/252)