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
|
|
46
|
$vpns = array('pptp' => 'PPTP', 'poes' => 'PPPoE', 'l2tp' => 'L2TP');
|
47
|
|
48
|
$pgtitle = array(gettext("Status"), gettext("System logs"), gettext("VPN"));
|
49
|
require("guiconfig.inc");
|
50
|
require_once("vpn.inc");
|
51
|
|
52
|
$nentries = $config['syslog']['nentries'];
|
53
|
if (!$nentries)
|
54
|
$nentries = 50;
|
55
|
|
56
|
if (htmlspecialchars($_POST['vpntype']))
|
57
|
$vpntype = htmlspecialchars($_POST['vpntype']);
|
58
|
elseif (htmlspecialchars($_GET['vpntype']))
|
59
|
$vpntype = htmlspecialchars($_GET['vpntype']);
|
60
|
else
|
61
|
$vpntype = "pptp";
|
62
|
|
63
|
if (htmlspecialchars($_POST['mode']))
|
64
|
$mode = htmlspecialchars($_POST['mode']);
|
65
|
elseif (htmlspecialchars($_GET['mode']))
|
66
|
$mode = htmlspecialchars($_GET['mode']);
|
67
|
else
|
68
|
$mode = "login";
|
69
|
|
70
|
switch ($vpntype) {
|
71
|
case 'pptp':
|
72
|
$logname = "pptps";
|
73
|
break;
|
74
|
case 'poes':
|
75
|
$logname = "poes";
|
76
|
break;
|
77
|
case 'l2tp':
|
78
|
$logname = "l2tps";
|
79
|
break;
|
80
|
}
|
81
|
|
82
|
if ($_POST['clear']) {
|
83
|
if ($mode != "raw")
|
84
|
clear_log_file("/var/log/vpn.log");
|
85
|
else
|
86
|
clear_log_file("/var/log/{$logname}.log");
|
87
|
}
|
88
|
|
89
|
function dump_clog_vpn($logfile, $tail) {
|
90
|
global $g, $config, $vpntype;
|
91
|
|
92
|
$sor = isset($config['syslog']['reverse']) ? "-r" : "";
|
93
|
|
94
|
$logarr = "";
|
95
|
|
96
|
if(isset($config['system']['usefifolog']))
|
97
|
exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . " | tail {$sor} -n " . $tail, $logarr);
|
98
|
else
|
99
|
exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . " | tail {$sor} -n " . $tail, $logarr);
|
100
|
|
101
|
$rows = 0;
|
102
|
foreach ($logarr as $logent) {
|
103
|
$logent = preg_split("/\s+/", $logent, 6);
|
104
|
$llent = explode(",", $logent[5]);
|
105
|
$iftype = substr($llent[1], 0, 4);
|
106
|
if ($iftype != $vpntype)
|
107
|
continue;
|
108
|
|
109
|
$rows++;
|
110
|
echo "<tr>\n";
|
111
|
echo "<td>" . htmlspecialchars(join(" ", array_slice($logent, 0, 3))) . "</td>\n";
|
112
|
|
113
|
if ($llent[0] == "login")
|
114
|
echo "<td>◀</td>\n";
|
115
|
else
|
116
|
echo "<td>►</td>\n";
|
117
|
|
118
|
echo "<td>" . htmlspecialchars($llent[3]) . "</td>\n";
|
119
|
echo "<td>" . htmlspecialchars($llent[2]) . " </td>\n";
|
120
|
echo "</tr>\n";
|
121
|
}
|
122
|
return($rows);
|
123
|
}
|
124
|
|
125
|
include("head.inc");
|
126
|
|
127
|
$tab_array = array();
|
128
|
$tab_array[] = array(gettext("System"), false, "diag_logs.php");
|
129
|
$tab_array[] = array(gettext("Firewall"), false, "diag_logs_filter.php");
|
130
|
$tab_array[] = array(gettext("DHCP"), false, "diag_logs.php?logfile=dhcpd");
|
131
|
$tab_array[] = array(gettext("Portal Auth"), false, "diag_logs.php?logfile=portalauth");
|
132
|
$tab_array[] = array(gettext("IPsec"), false, "diag_logs.php?logfile=ipsec");
|
133
|
$tab_array[] = array(gettext("PPP"), false, "diag_logs.php?logfile=ppp");
|
134
|
$tab_array[] = array(gettext("VPN"), true, "diag_logs_vpn.php");
|
135
|
$tab_array[] = array(gettext("Load Balancer"), false, "diag_logs.php?logfile=relayd");
|
136
|
$tab_array[] = array(gettext("OpenVPN"), false, "diag_logs.php?logfile=openvpn");
|
137
|
$tab_array[] = array(gettext("NTP"), false, "diag_logs.php?logfile=ntpd");
|
138
|
$tab_array[] = array(gettext("Settings"), false, "diag_logs_settings.php");
|
139
|
display_top_tabs($tab_array);
|
140
|
|
141
|
$tab_array = array();
|
142
|
$tab_array[] = array(gettext("PPTP Logins"),
|
143
|
(($vpntype == "pptp") && ($mode != "raw")),
|
144
|
"/diag_logs_vpn.php?vpntype=pptp");
|
145
|
$tab_array[] = array(gettext("PPTP Raw"),
|
146
|
(($vpntype == "pptp") && ($mode == "raw")),
|
147
|
"/diag_logs_vpn.php?vpntype=pptp&mode=raw");
|
148
|
$tab_array[] = array(gettext("PPPoE Logins"),
|
149
|
(($vpntype == "poes") && ($mode != "raw")),
|
150
|
"/diag_logs_vpn.php?vpntype=poes");
|
151
|
$tab_array[] = array(gettext("PPPoE Raw"),
|
152
|
(($vpntype == "poes") && ($mode == "raw")),
|
153
|
"/diag_logs_vpn.php?vpntype=poes&mode=raw");
|
154
|
$tab_array[] = array(gettext("L2TP Logins"),
|
155
|
(($vpntype == "l2tp") && ($mode != "raw")),
|
156
|
"/diag_logs_vpn.php?vpntype=l2tp");
|
157
|
$tab_array[] = array(gettext("L2TP Raw"),
|
158
|
(($vpntype == "l2tp") && ($mode == "raw")),
|
159
|
"/diag_logs_vpn.php?vpntype=l2tp&mode=raw");
|
160
|
display_top_tabs($tab_array, false, 'nav nav-tabs');
|
161
|
?>
|
162
|
|
163
|
<!-- Raw logs are displayed as preformatted text. vpn logs are displayed as a table-->
|
164
|
<div class="panel panel-default">
|
165
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Last ")?><?=$nentries?> <?=$vpns[$vpntype]?><?=gettext(" log entries")?></h2></div>
|
166
|
<div class="panel-body">
|
167
|
<?php
|
168
|
if ($mode != "raw") {
|
169
|
?>
|
170
|
<div class="table-responsive">
|
171
|
<table class="table table-striped table-hover table-condensed">
|
172
|
<thead>
|
173
|
<tr>
|
174
|
<th><?=gettext("Time")?></th>
|
175
|
<th><?=gettext("Action")?></th>
|
176
|
<th><?=gettext("User")?></th>
|
177
|
<th><?=gettext("IP address")?></th>
|
178
|
</tr>
|
179
|
</thead>
|
180
|
<tbody>
|
181
|
<?php
|
182
|
$rows = dump_clog_vpn("/var/log/vpn.log", $nentries); // dump_clog_vpn provides all the need <td></td>/<tr></tr> tags
|
183
|
?>
|
184
|
</tbody>
|
185
|
</table>
|
186
|
<?php
|
187
|
if($rows == 0)
|
188
|
print_info_box('No logs to display');
|
189
|
?>
|
190
|
</div>
|
191
|
<?php
|
192
|
}
|
193
|
else {
|
194
|
?>
|
195
|
<pre>
|
196
|
<?php
|
197
|
if(dump_clog_no_table("/var/log/{$logname}.log", $nentries) == 0)
|
198
|
print('No logs to display');
|
199
|
?>
|
200
|
</pre>
|
201
|
<?php
|
202
|
}
|
203
|
?>
|
204
|
<p>
|
205
|
<form action="diag_logs_vpn.php" method="post">
|
206
|
<input type="hidden" name="vpntype" id="vpntype" value="<?=$vpntype?>" />
|
207
|
<input type="hidden" name="mode" id="mode" value="<?=$mode?>" />
|
208
|
<input name="clear" type="submit" class="btn btn-danger" value="<?=gettext("Clear log")?>" />
|
209
|
</form>
|
210
|
</p>
|
211
|
</div>
|
212
|
</div>
|
213
|
<?php include("foot.inc");
|