Project

General

Profile

Download (11.4 KB) Statistics
| Branch: | Tag: | Revision:
1 0927fb8c jim-p
<?php
2 63084885 Matthew Grooms
/*
3 ce77a9c4 Phil Davis
	status_openvpn.php
4 63084885 Matthew Grooms
*/
5 b9043cdc Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 cb41dd63 Renato Botelho
 *	Copyright (c)  2008 Shrew Soft Inc.
8 b9043cdc Stephen Beaver
 *
9
 *	Redistribution and use in source and binary forms, with or without modification,
10
 *	are permitted provided that the following conditions are met:
11
 *
12
 *	1. Redistributions of source code must retain the above copyright notice,
13
 *		this list of conditions and the following disclaimer.
14
 *
15
 *	2. Redistributions in binary form must reproduce the above copyright
16
 *		notice, this list of conditions and the following disclaimer in
17
 *		the documentation and/or other materials provided with the
18
 *		distribution.
19
 *
20
 *	3. All advertising materials mentioning features or use of this software
21
 *		must display the following acknowledgment:
22
 *		"This product includes software developed by the pfSense Project
23
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
24
 *
25
 *	4. The names "pfSense" and "pfSense Project" must not be used to
26
 *		 endorse or promote products derived from this software without
27
 *		 prior written permission. For written permission, please contact
28
 *		 coreteam@pfsense.org.
29
 *
30
 *	5. Products derived from this software may not be called "pfSense"
31
 *		nor may "pfSense" appear in their names without prior written
32
 *		permission of the Electric Sheep Fencing, LLC.
33
 *
34
 *	6. Redistributions of any form whatsoever must retain the following
35
 *		acknowledgment:
36
 *
37
 *	"This product includes software developed by the pfSense Project
38
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
52
 *
53
 *	====================================================================
54
 *
55
 */
56 63084885 Matthew Grooms
57
##|+PRIV
58
##|*IDENT=page-status-openvpn
59 5230f468 jim-p
##|*NAME=Status: OpenVPN
60 63084885 Matthew Grooms
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
61
##|*MATCH=status_openvpn.php*
62
##|-PRIV
63
64 e9d35ff5 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
65 7d7b5a48 jim-p
$shortcut_section = "openvpn";
66
67 63084885 Matthew Grooms
require("guiconfig.inc");
68 53663f57 jim-p
require_once("openvpn.inc");
69 2eaa97b9 jim-p
require_once("shortcuts.inc");
70 c92ccc70 Renato Botelho
require_once("service-utils.inc");
71 63084885 Matthew Grooms
72 0927fb8c jim-p
/* Handle AJAX */
73 abe98adb Phil Davis
if ($_GET['action']) {
74
	if ($_GET['action'] == "kill") {
75 0927fb8c jim-p
		$port  = $_GET['port'];
76
		$remipp  = $_GET['remipp'];
77
		if (!empty($port) and !empty($remipp)) {
78 61fce4a6 Phil Davis
			$retval = openvpn_kill_client($port, $remipp);
79 0927fb8c jim-p
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
80
		} else {
81 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
82 0927fb8c jim-p
		}
83
		exit;
84
	}
85
}
86
87 53663f57 jim-p
$servers = openvpn_get_active_servers();
88 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
89 53663f57 jim-p
$clients = openvpn_get_active_clients();
90 63084885 Matthew Grooms
91 0927fb8c jim-p
include("head.inc"); ?>
92
93 c64a0911 Hari
<body>
94 0927fb8c jim-p
<form action="status_openvpn.php" method="get" name="iform">
95
<script type="text/javascript">
96 4d33138f Colin Fleming
//<![CDATA[
97 0927fb8c jim-p
	function killClient(mport, remipp) {
98 b9144088 jim-p
		var busy = function(index,icon) {
99 3f98044a Francisco Cavalcante
			$(icon).bind("onclick","");
100
			$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
101
			$(icon).css("cursor","wait");
102 0927fb8c jim-p
		}
103
104 3f98044a Francisco Cavalcante
		$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
105 0927fb8c jim-p
106 3f98044a Francisco Cavalcante
		$.ajax(
107 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
108
				"?action=kill&port=" + mport + "&remipp=" + remipp,
109 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
110 0927fb8c jim-p
		);
111
	}
112
113
	function killComplete(req) {
114
		var values = req.responseText.split("|");
115 abe98adb Phil Davis
		if (values[3] != "0") {
116 0927fb8c jim-p
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
117
			return;
118
		}
119
120 3f98044a Francisco Cavalcante
		$('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
121
			function(index,row) { $(row).fadeOut(1000); }
122 0927fb8c jim-p
		);
123
	}
124 4d33138f Colin Fleming
//]]>
125 0927fb8c jim-p
</script>
126 c64a0911 Hari
127 42b0c921 Phil Davis
<?php
128
	$i = 0;
129
	foreach ($servers as $server):
130
?>
131 0927fb8c jim-p
132 c64a0911 Hari
<div class="panel panel-default">
133
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client connections')?></h2></div>
134
		<div class="panel-body table-responsive">
135 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
136 c64a0911 Hari
				<thead>
137
					<tr>
138
						<th><?=gettext("Common Name")?></th>
139
						<th><?=gettext("Real Address")?></th>
140
						<th><?=gettext("Virtual Address"); ?></th>
141
						<th><?=gettext("Connected Since"); ?></th>
142
						<th><?=gettext("Bytes Sent")?></th>
143
						<th><?=gettext("Bytes Received")?></th>
144 ff59b884 Stephen Beaver
						<th><!-- Icons --></th>
145 c64a0911 Hari
					</tr>
146
				</thead>
147
				<tbody>
148 919d91f9 Phil Davis
149 9f605c1c Hari
					<?php
150
							foreach ($server['conns'] as $conn):
151
					?>
152 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
153
						<td><?=$conn['common_name'];?></td>
154
						<td><?=$conn['remote_host'];?></td>
155
						<td><?=$conn['virtual_addr'];?></td>
156
						<td><?=$conn['connect_time'];?></td>
157
						<td><?=format_bytes($conn['bytes_sent']);?></td>
158
						<td><?=format_bytes($conn['bytes_recv']);?></td>
159
						<td>
160 9f605c1c Hari
							<a
161 5c0ab3cd NewEraCracker
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>');" style="cursor:pointer;"
162 c64a0911 Hari
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
163 9f605c1c Hari
							   title="<?php echo gettext("Kill client connection from") . " " . $conn['remote_host']; ?>">
164 1b7379f9 Jared Dillard
							<i class="fa fa-times"></i>
165 9f605c1c Hari
							</a>
166 c64a0911 Hari
						</td>
167
					</tr>
168 9f605c1c Hari
					<?php
169
							endforeach;
170
					?>
171 c64a0911 Hari
				</tbody>
172
				<tfoot>
173
					<tr>
174 e9701cfe Stephen Beaver
						<td colspan="2">
175 c64a0911 Hari
							<table>
176
								<tr>
177
									<td>
178
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
179
										<?= get_service_status_icon($ssvc, true, true); ?>
180 1baa4e7b Stephen Beaver
										<?= get_service_control_GET_links($ssvc, true); ?>
181 c64a0911 Hari
									</td>
182
								</tr>
183
							</table>
184
						</td>
185 e9701cfe Stephen Beaver
						<td colspan="5">
186
						</td>
187 c64a0911 Hari
					</tr>
188
				</tfoot>
189
			</table>
190
		</div>
191
</div>
192 42b0c921 Phil Davis
<?php
193
		if (is_array($server['routes']) && count($server['routes'])):
194
?>
195 ec970b50 jim-p
<div id="shroutebut-<?= $i ?>">
196 c64a0911 Hari
	<input type="button" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>" /> - <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
197
		<br /><br />
198 ec970b50 jim-p
</div>
199 56fafd85 Stephen Beaver
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
200 c64a0911 Hari
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
201
		<div class="panel-body table-responsive">
202 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
203 c64a0911 Hari
				<thead>
204
					<tr>
205
						<th><?=gettext("Common Name"); ?></th>
206
						<th><?=gettext("Real Address"); ?></th>
207
						<th><?=gettext("Target Network"); ?></th>
208
						<th><?=gettext("Last Used"); ?></th>
209
					</tr>
210 919d91f9 Phil Davis
				</thead>
211 c64a0911 Hari
				<tbody>
212 ec970b50 jim-p
213 42b0c921 Phil Davis
<?php
214
			foreach ($server['routes'] as $conn):
215
?>
216 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
217
						<td><?=$conn['common_name'];?></td>
218
						<td><?=$conn['remote_host'];?></td>
219
						<td><?=$conn['virtual_addr'];?></td>
220
						<td><?=$conn['last_time'];?></td>
221
					</tr>
222 42b0c921 Phil Davis
<?php
223
			endforeach;
224
?>
225 c64a0911 Hari
				</tbody>
226
				<tfoot>
227
					<tr>
228 e9701cfe Stephen Beaver
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
229 c64a0911 Hari
					</tr>
230
				</tfoot>
231
			</table>
232
		</div>
233
</div>
234 42b0c921 Phil Davis
<?php
235
		endif;
236
?>
237 8cd558b6 ayvis
<br />
238 42b0c921 Phil Davis
<?php
239
		$i++;
240
	endforeach;
241
?>
242 8cd558b6 ayvis
<br />
243 d0f6649c pierrepomes
244 42b0c921 Phil Davis
<?php
245
	if (!empty($sk_servers)) {
246
?>
247 c64a0911 Hari
<div class="panel panel-default">
248
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
249
		<div class="panel-body table-responsive">
250 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
251 c64a0911 Hari
				<thead>
252 919d91f9 Phil Davis
					<tr>
253 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
254 e9701cfe Stephen Beaver
						<th><?=gettext("Status"); ?></th>
255 c64a0911 Hari
						<th><?=gettext("Connected Since"); ?></th>
256 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
257 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
258
						<th><?=gettext("Bytes Sent"); ?></th>
259 a66ce627 NewEraCracker
						<th><?=gettext("Bytes Received"); ?></th>
260 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
261
					</tr>
262
				</thead>
263
				<tbody>
264 d0f6649c pierrepomes
265 42b0c921 Phil Davis
<?php
266
		foreach ($sk_servers as $sk_server):
267
?>
268 c64a0911 Hari
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
269
						<td><?=htmlspecialchars($sk_server['name']);?></td>
270
						<td><?=$sk_server['status'];?></td>
271
						<td><?=$sk_server['connect_time'];?></td>
272
						<td><?=$sk_server['virtual_addr'];?></td>
273
						<td><?=$sk_server['remote_host'];?></td>
274
						<td><?=format_bytes($sk_server['bytes_sent']);?></td>
275
						<td><?=format_bytes($sk_server['bytes_recv']);?></td>
276
						<td>
277
							<table>
278
								<tr>
279
									<td>
280
										<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
281
										<?= get_service_status_icon($ssvc, false, true); ?>
282 1baa4e7b Stephen Beaver
										<?= get_service_control_GET_links($ssvc, true); ?>
283 c64a0911 Hari
									</td>
284
								</tr>
285
							</table>
286
						</td>
287
					</tr>
288 42b0c921 Phil Davis
<?php
289
		endforeach;
290
?>
291 c64a0911 Hari
				</tbody>
292 a5eb046f Renato Botelho
			</table>
293 c64a0911 Hari
		</div>
294
</div>
295 95305736 jim-p
296
<?php
297 42b0c921 Phil Davis
	}
298
?>
299 8cd558b6 ayvis
<br />
300 42b0c921 Phil Davis
<?php
301
	if (!empty($clients)) {
302
?>
303 c64a0911 Hari
<div class="panel panel-default">
304
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
305
		<div class="panel-body table-responsive">
306 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
307 c64a0911 Hari
				<thead>
308 919d91f9 Phil Davis
					<tr>
309 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
310
						<th><?=gettext("Status"); ?></th>
311
						<th><?=gettext("Connected Since"); ?></th>
312 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
313 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
314
						<th><?=gettext("Bytes Sent"); ?></th>
315 a66ce627 NewEraCracker
						<th><?=gettext("Bytes Received"); ?></th>
316 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
317
					</tr>
318
				</thead>
319
				<tbody>
320 d0f6649c pierrepomes
321 42b0c921 Phil Davis
<?php
322
		foreach ($clients as $client):
323
?>
324 c64a0911 Hari
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
325
						<td><?=htmlspecialchars($client['name']);?></td>
326
						<td><?=$client['status'];?></td>
327
						<td><?=$client['connect_time'];?></td>
328
						<td><?=$client['virtual_addr'];?></td>
329
						<td><?=$client['remote_host'];?></td>
330
						<td><?=format_bytes($client['bytes_sent']);?></td>
331
						<td><?=format_bytes($client['bytes_recv']);?></td>
332
						<td>
333
							<table>
334
								<tr>
335
									<td>
336
										<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
337
										<?= get_service_status_icon($ssvc, false, true); ?>
338 1baa4e7b Stephen Beaver
										<?= get_service_control_GET_links($ssvc, true); ?>
339 c64a0911 Hari
									</td>
340
								</tr>
341
							</table>
342
						</td>
343
					</tr>
344 42b0c921 Phil Davis
<?php
345
		endforeach;
346
?>
347 c64a0911 Hari
				</tbody>
348 a5eb046f Renato Botelho
			</table>
349 c64a0911 Hari
		</div>
350 56fafd85 Stephen Beaver
	</div>
351 d0f6649c pierrepomes
352 919d91f9 Phil Davis
<?php
353 cf1ced6d pierrepomes
}
354
355
if ($DisplayNote) {
356 9f605c1c Hari
 	print_info_box(gettext("If you have custom options that override the management features of OpenVPN on a client or server, they will cause that OpenVPN instance to not work correctly with this status page."));
357 d0f6649c pierrepomes
}
358
359 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
360 c64a0911 Hari
	print_info_box(gettext("No OpenVPN instances defined"));
361 d0f6649c pierrepomes
}
362
?>
363 2a351d32 Colin Fleming
</form>
364 56fafd85 Stephen Beaver
365 01036a9a Stephen Beaver
<?php include("foot.inc"); ?>
366 56fafd85 Stephen Beaver
367 ec970b50 jim-p
<script type="text/javascript">
368 4d33138f Colin Fleming
//<![CDATA[
369 56fafd85 Stephen Beaver
370 ec970b50 jim-p
function show_routes(id, buttonid) {
371
	document.getElementById(buttonid).innerHTML='';
372
	aodiv = document.getElementById(id);
373
	aodiv.style.display = "block";
374
}
375 56fafd85 Stephen Beaver
376 4d33138f Colin Fleming
//]]>
377 ec970b50 jim-p
</script>