Project

General

Profile

Download (12.8 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 ce77a9c4 Phil Davis
	Copyright (C) 2005 Scott Ullrich, Colin Smith
6
	Copyright (C) 2008 Shrew Soft Inc.
7
	Copyright (C) 2010 Jim Pingle
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9 0927fb8c jim-p
10 ce77a9c4 Phil Davis
	AJAX bits borrowed from diag_dump_states.php
11 0927fb8c jim-p
12 ce77a9c4 Phil Davis
	All rights reserved.
13 0927fb8c jim-p
14 63084885 Matthew Grooms
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16 0927fb8c jim-p
17 63084885 Matthew Grooms
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19 0927fb8c jim-p
20 63084885 Matthew Grooms
	2. Redistributions in binary form must reproduce the above copyright
21
	   notice, this list of conditions and the following disclaimer in the
22
	   documentation and/or other materials provided with the distribution.
23 0927fb8c jim-p
24 63084885 Matthew Grooms
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
	POSSIBILITY OF SUCH DAMAGE.
34
*/
35 0927fb8c jim-p
/*
36 1d333258 Scott Ullrich
	pfSense_MODULE:	openvpn
37
*/
38 63084885 Matthew Grooms
39
##|+PRIV
40
##|*IDENT=page-status-openvpn
41
##|*NAME=Status: OpenVPN page
42
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
43
##|*MATCH=status_openvpn.php*
44
##|-PRIV
45
46 e9d35ff5 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
47 7d7b5a48 jim-p
$shortcut_section = "openvpn";
48
49 63084885 Matthew Grooms
require("guiconfig.inc");
50 53663f57 jim-p
require_once("openvpn.inc");
51 2eaa97b9 jim-p
require_once("shortcuts.inc");
52 c92ccc70 Renato Botelho
require_once("service-utils.inc");
53 63084885 Matthew Grooms
54 0927fb8c jim-p
/* Handle AJAX */
55
if($_GET['action']) {
56
	if($_GET['action'] == "kill") {
57
		$port  = $_GET['port'];
58
		$remipp  = $_GET['remipp'];
59
		if (!empty($port) and !empty($remipp)) {
60
			$retval = kill_client($port, $remipp);
61
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
62
		} else {
63 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
64 0927fb8c jim-p
		}
65
		exit;
66
	}
67
}
68
69
70
function kill_client($port, $remipp) {
71 71ca2cb2 Ermal
	global $g;
72
73
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
74
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
75 247c417f Sjon Hortensius
	$errval = null;
76
	$errstr = null;
77 0927fb8c jim-p
78
	/* open a tcp connection to the management port of each server */
79
	$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
80
	$killed = -1;
81
	if ($fp) {
82 19e3d450 Ermal
		stream_set_timeout($fp, 1);
83 0927fb8c jim-p
		fputs($fp, "kill {$remipp}\n");
84
		while (!feof($fp)) {
85
			$line = fgets($fp, 1024);
86 b0140675 Ermal
87
			$info = stream_get_meta_data($fp);
88 42b0c921 Phil Davis
			if ($info['timed_out']) {
89 b0140675 Ermal
				break;
90 42b0c921 Phil Davis
			}
91 b0140675 Ermal
92 0927fb8c jim-p
			/* parse header list line */
93 42b0c921 Phil Davis
			if (strpos($line, "INFO:") !== false) {
94 0927fb8c jim-p
				continue;
95 42b0c921 Phil Davis
			}
96 68b04527 jim-p
			if (strpos($line, "SUCCESS") !== false) {
97 0927fb8c jim-p
				$killed = 0;
98
			}
99
			break;
100
		}
101
		fclose($fp);
102
	}
103
	return $killed;
104
}
105
106 53663f57 jim-p
$servers = openvpn_get_active_servers();
107 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
108 53663f57 jim-p
$clients = openvpn_get_active_clients();
109 63084885 Matthew Grooms
110 0927fb8c jim-p
include("head.inc"); ?>
111
112
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
113
<?php include("fbegin.inc"); ?>
114
<form action="status_openvpn.php" method="get" name="iform">
115
<script type="text/javascript">
116 4d33138f Colin Fleming
//<![CDATA[
117 0927fb8c jim-p
	function killClient(mport, remipp) {
118 b9144088 jim-p
		var busy = function(index,icon) {
119 e03ef9a0 Vinicius Coque
			jQuery(icon).bind("onclick","");
120
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
121
			jQuery(icon).css("cursor","wait");
122 0927fb8c jim-p
		}
123
124 e03ef9a0 Vinicius Coque
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
125 0927fb8c jim-p
126 e03ef9a0 Vinicius Coque
		jQuery.ajax(
127 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
128
				"?action=kill&port=" + mport + "&remipp=" + remipp,
129 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
130 0927fb8c jim-p
		);
131
	}
132
133
	function killComplete(req) {
134
		var values = req.responseText.split("|");
135
		if(values[3] != "0") {
136
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
137
			return;
138
		}
139
140 e03ef9a0 Vinicius Coque
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
141
			function(index,row) { jQuery(row).fadeOut(1000); }
142 0927fb8c jim-p
		);
143
	}
144 4d33138f Colin Fleming
//]]>
145 0927fb8c jim-p
</script>
146 42b0c921 Phil Davis
<?php
147
	$i = 0;
148
	foreach ($servers as $server):
149
?>
150 0927fb8c jim-p
151 4d33138f Colin Fleming
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0" summary="status openvpn">
152 0927fb8c jim-p
	<tr>
153
		<td colspan="6" class="listtopic">
154 7bc8484b jim-p
			<?=htmlspecialchars($server['name']);?> <?=gettext("Client connections"); ?>
155 0927fb8c jim-p
		</td>
156
	</tr>
157
	<tr>
158
		<td>
159 4d33138f Colin Fleming
			<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="connections">
160 0927fb8c jim-p
			<tr>
161 e9d35ff5 Carlos Eduardo Ramos
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
162
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
163
				<td class="listhdrr"><?=gettext("Virtual Address"); ?></td>
164
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
165
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
166
				<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
167 0927fb8c jim-p
			</tr>
168 42b0c921 Phil Davis
<?php
169
		foreach ($server['conns'] as $conn):
170
?>
171 4d33138f Colin Fleming
			<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
172 0927fb8c jim-p
				<td class="listlr">
173
					<?=$conn['common_name'];?>
174
				</td>
175
				<td class="listr">
176
					<?=$conn['remote_host'];?>
177
				</td>
178
				<td class="listr">
179
					<?=$conn['virtual_addr'];?>
180
				</td>
181
				<td class="listr">
182
					<?=$conn['connect_time'];?>
183
				</td>
184
				<td class="listr">
185 ef462f25 jim-p
					<?=format_bytes($conn['bytes_sent']);?>
186 0927fb8c jim-p
				</td>
187
				<td class="listr">
188 ef462f25 jim-p
					<?=format_bytes($conn['bytes_recv']);?>
189 0927fb8c jim-p
				</td>
190 4d33138f Colin Fleming
				<td class="list">
191
					<img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" height="17" width="17" border="0"
192
					   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style="cursor:pointer;"
193
					   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
194
					   title="<?php echo gettext("Kill client connection from") . " " . $conn['remote_host']; ?>" alt="delete" />
195 0927fb8c jim-p
				</td>
196
			</tr>
197 42b0c921 Phil Davis
<?php
198
		endforeach;
199
?>
200 f06f7cc0 PiBa-NL
			<tfoot>
201 0927fb8c jim-p
			<tr>
202 2eaa97b9 jim-p
				<td colspan="2" class="list" height="12">
203
				<table>
204
				<tr>
205 4d33138f Colin Fleming
				<td><?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
206 2eaa97b9 jim-p
				<?= get_service_status_icon($ssvc, true, true); ?>
207 4d33138f Colin Fleming
				<?= get_service_control_links($ssvc, true); ?></td>
208 2eaa97b9 jim-p
				</tr>
209
				</table>
210
				</td>
211
				<td colspan="4" class="list" height="12">&nbsp;</td>
212 0927fb8c jim-p
			</tr>
213 f06f7cc0 PiBa-NL
			</tfoot>
214 0927fb8c jim-p
		</table>
215
		</td>
216
	</tr>
217
</table>
218 42b0c921 Phil Davis
<?php
219
		if (is_array($server['routes']) && count($server['routes'])):
220
?>
221 ec970b50 jim-p
<div id="shroutebut-<?= $i ?>">
222 4d33138f Colin Fleming
<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.") ?>
223 8cd558b6 ayvis
<br /><br />
224 ec970b50 jim-p
</div>
225 4d33138f Colin Fleming
<table style="display: none; padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0" id="tabroute-<?= $i ?>" summary="routing table">
226 ec970b50 jim-p
	<tr>
227
		<td colspan="6" class="listtopic">
228 7bc8484b jim-p
			<?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?>
229 ec970b50 jim-p
		</td>
230
	</tr>
231
	<tr>
232
		<td>
233 4d33138f Colin Fleming
			<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="results">
234 ec970b50 jim-p
			<tr>
235
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
236
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
237
				<td class="listhdrr"><?=gettext("Target Network"); ?></td>
238
				<td class="listhdrr"><?=gettext("Last Used"); ?></td>
239
			</tr>
240
241 42b0c921 Phil Davis
<?php
242
			foreach ($server['routes'] as $conn):
243
?>
244 4d33138f Colin Fleming
			<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
245 ec970b50 jim-p
				<td class="listlr">
246
					<?=$conn['common_name'];?>
247
				</td>
248
				<td class="listr">
249
					<?=$conn['remote_host'];?>
250
				</td>
251
				<td class="listr">
252
					<?=$conn['virtual_addr'];?>
253
				</td>
254
				<td class="listr">
255
					<?=$conn['last_time'];?>
256
				</td>
257
			</tr>
258 42b0c921 Phil Davis
<?php
259
			endforeach;
260
?>
261 ec970b50 jim-p
			<tfoot>
262
			<tr>
263
				<td colspan="6" class="list" height="12"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
264
			</tr>
265
			</tfoot>
266
		</table>
267
		</td>
268
	</tr>
269
</table>
270 42b0c921 Phil Davis
<?php
271
		endif;
272
?>
273 8cd558b6 ayvis
<br />
274 42b0c921 Phil Davis
<?php
275
		$i++;
276
	endforeach;
277
?>
278 8cd558b6 ayvis
<br />
279 d0f6649c pierrepomes
280 42b0c921 Phil Davis
<?php
281
	if (!empty($sk_servers)) {
282
?>
283 4d33138f Colin Fleming
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0" summary="peer to peer stats">
284 95305736 jim-p
	<tr>
285
		<td colspan="6" class="listtopic">
286 453d9c96 jim-p
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
287 95305736 jim-p
		</td>
288
	</tr>
289
	<tr>
290 a5eb046f Renato Botelho
		<td>
291 4d33138f Colin Fleming
			<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="results">
292 a5eb046f Renato Botelho
			<tr>
293
				<td class="listhdrr"><?=gettext("Name"); ?></td>
294
				<td class="listhdrr"><?=gettext("Status"); ?></td>
295
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
296
				<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
297
				<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
298
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
299
				<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
300
				<td class="listhdrr"><?=gettext("Service"); ?></td>
301
			</tr>
302 d0f6649c pierrepomes
303 42b0c921 Phil Davis
<?php
304
		foreach ($sk_servers as $sk_server):
305
?>
306 4d33138f Colin Fleming
			<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
307 a5eb046f Renato Botelho
				<td class="listlr">
308 7295f5d0 jim-p
					<?=htmlspecialchars($sk_server['name']);?>
309 a5eb046f Renato Botelho
				</td>
310
				<td class="listr">
311
					<?=$sk_server['status'];?>
312
				</td>
313
				<td class="listr">
314
					<?=$sk_server['connect_time'];?>
315
				</td>
316
				<td class="listr">
317
					<?=$sk_server['virtual_addr'];?>
318
				</td>
319
				<td class="listr">
320
					<?=$sk_server['remote_host'];?>
321
				</td>
322
				<td class="listr">
323 ef462f25 jim-p
					<?=format_bytes($sk_server['bytes_sent']);?>
324 a5eb046f Renato Botelho
				</td>
325
				<td class="listr">
326 ef462f25 jim-p
					<?=format_bytes($sk_server['bytes_recv']);?>
327 a5eb046f Renato Botelho
				</td>
328
				<td class="listr">
329
				<table>
330
				<tr>
331 4d33138f Colin Fleming
				<td><?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
332 a5eb046f Renato Botelho
				<?= get_service_status_icon($ssvc, false, true); ?>
333 42b0c921 Phil Davis
									<?= get_service_control_links($ssvc, true); ?>
334
								</td>
335 a5eb046f Renato Botelho
				</tr>
336
				</table>
337
				</td>
338 2eaa97b9 jim-p
			</tr>
339 42b0c921 Phil Davis
<?php
340
		endforeach;
341
?>
342 a5eb046f Renato Botelho
			</table>
343
		</td>
344 95305736 jim-p
	</tr>
345
</table>
346
347
<?php
348 42b0c921 Phil Davis
	}
349
?>
350 8cd558b6 ayvis
<br />
351 42b0c921 Phil Davis
<?php
352
	if (!empty($clients)) {
353
?>
354 4d33138f Colin Fleming
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0" summary="client stats">
355 d0f6649c pierrepomes
	<tr>
356
		<td colspan="6" class="listtopic">
357 95305736 jim-p
			<?=gettext("Client Instance Statistics"); ?>
358 d0f6649c pierrepomes
		</td>
359
	</tr>
360
	<tr>
361 a5eb046f Renato Botelho
		<td>
362 4d33138f Colin Fleming
			<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="results">
363 a5eb046f Renato Botelho
			<tr>
364
				<td class="listhdrr"><?=gettext("Name"); ?></td>
365
				<td class="listhdrr"><?=gettext("Status"); ?></td>
366
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
367
				<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
368
				<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
369
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
370
				<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
371
				<td class="listhdrr"><?=gettext("Service"); ?></td>
372
			</tr>
373 d0f6649c pierrepomes
374 42b0c921 Phil Davis
<?php
375
		foreach ($clients as $client):
376
?>
377 4d33138f Colin Fleming
			<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
378 a5eb046f Renato Botelho
				<td class="listlr">
379 7295f5d0 jim-p
					<?=htmlspecialchars($client['name']);?>
380 a5eb046f Renato Botelho
				</td>
381
				<td class="listr">
382
					<?=$client['status'];?>
383
				</td>
384
				<td class="listr">
385
					<?=$client['connect_time'];?>
386
				</td>
387
				<td class="listr">
388
					<?=$client['virtual_addr'];?>
389
				</td>
390
				<td class="listr">
391
					<?=$client['remote_host'];?>
392
				</td>
393
				<td class="listr">
394 ef462f25 jim-p
					<?=format_bytes($client['bytes_sent']);?>
395 a5eb046f Renato Botelho
				</td>
396
				<td class="listr">
397 ef462f25 jim-p
					<?=format_bytes($client['bytes_recv']);?>
398 a5eb046f Renato Botelho
				</td>
399
				<td class="listr" height="12">
400
				<table>
401
				<tr>
402 42b0c921 Phil Davis
								<td>
403
									<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
404 a5eb046f Renato Botelho
				<?= get_service_status_icon($ssvc, false, true); ?>
405 42b0c921 Phil Davis
									<?= get_service_control_links($ssvc, true); ?>
406
								</td>
407 a5eb046f Renato Botelho
				</tr>
408
				</table>
409
				</td>
410 2eaa97b9 jim-p
			</tr>
411 42b0c921 Phil Davis
<?php
412
		endforeach;
413
?>
414 a5eb046f Renato Botelho
			</table>
415
		</td>
416 d0f6649c pierrepomes
	</tr>
417
</table>
418
419 cf1ced6d pierrepomes
<?php 
420
}
421
422
if ($DisplayNote) {
423 8cd558b6 ayvis
	echo "<br /><b>" . gettext("NOTE") . ":</b> " . 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.");
424 d0f6649c pierrepomes
}
425
426 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
427 b7b3f343 Chris Buechler
	echo gettext("No OpenVPN instances defined");
428 d0f6649c pierrepomes
}
429
?>
430 2a351d32 Colin Fleming
</form>
431 63084885 Matthew Grooms
432
<?php include("fend.inc"); ?>
433 ec970b50 jim-p
<script type="text/javascript">
434 4d33138f Colin Fleming
//<![CDATA[
435 ec970b50 jim-p
function show_routes(id, buttonid) {
436
	document.getElementById(buttonid).innerHTML='';
437
	aodiv = document.getElementById(id);
438
	aodiv.style.display = "block";
439
}
440 4d33138f Colin Fleming
//]]>
441 ec970b50 jim-p
</script>
442 4d33138f Colin Fleming
</body>
443
</html>