Project

General

Profile

Download (12.7 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
			if ($info['timed_out'])
89
				break;
90
91 0927fb8c jim-p
			/* parse header list line */
92 68b04527 jim-p
			if (strpos($line, "INFO:") !== false)
93 0927fb8c jim-p
				continue;
94 68b04527 jim-p
			if (strpos($line, "SUCCESS") !== false) {
95 0927fb8c jim-p
				$killed = 0;
96
			}
97
			break;
98
		}
99
		fclose($fp);
100
	}
101
	return $killed;
102
}
103
104 53663f57 jim-p
$servers = openvpn_get_active_servers();
105 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
106 53663f57 jim-p
$clients = openvpn_get_active_clients();
107 63084885 Matthew Grooms
108 0927fb8c jim-p
include("head.inc"); ?>
109
110
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
111
<?php include("fbegin.inc"); ?>
112
<form action="status_openvpn.php" method="get" name="iform">
113
<script type="text/javascript">
114 4d33138f Colin Fleming
//<![CDATA[
115 0927fb8c jim-p
	function killClient(mport, remipp) {
116 b9144088 jim-p
		var busy = function(index,icon) {
117 e03ef9a0 Vinicius Coque
			jQuery(icon).bind("onclick","");
118
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
119
			jQuery(icon).css("cursor","wait");
120 0927fb8c jim-p
		}
121
122 e03ef9a0 Vinicius Coque
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
123 0927fb8c jim-p
124 e03ef9a0 Vinicius Coque
		jQuery.ajax(
125 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
126
				"?action=kill&port=" + mport + "&remipp=" + remipp,
127 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
128 0927fb8c jim-p
		);
129
	}
130
131
	function killComplete(req) {
132
		var values = req.responseText.split("|");
133
		if(values[3] != "0") {
134
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
135
			return;
136
		}
137
138 e03ef9a0 Vinicius Coque
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
139
			function(index,row) { jQuery(row).fadeOut(1000); }
140 0927fb8c jim-p
		);
141
	}
142 4d33138f Colin Fleming
//]]>
143 0927fb8c jim-p
</script>
144 ec970b50 jim-p
<?php $i = 0; ?>
145 0927fb8c jim-p
<?php foreach ($servers as $server): ?>
146
147 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">
148 0927fb8c jim-p
	<tr>
149
		<td colspan="6" class="listtopic">
150 95305736 jim-p
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
151 0927fb8c jim-p
		</td>
152
	</tr>
153
	<tr>
154
		<td>
155 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">
156 0927fb8c jim-p
			<tr>
157 e9d35ff5 Carlos Eduardo Ramos
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
158
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
159
				<td class="listhdrr"><?=gettext("Virtual Address"); ?></td>
160
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
161
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
162
				<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
163 0927fb8c jim-p
			</tr>
164
165
			<?php foreach ($server['conns'] as $conn): ?>
166 4d33138f Colin Fleming
			<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
167 0927fb8c jim-p
				<td class="listlr">
168
					<?=$conn['common_name'];?>
169
				</td>
170
				<td class="listr">
171
					<?=$conn['remote_host'];?>
172
				</td>
173
				<td class="listr">
174
					<?=$conn['virtual_addr'];?>
175
				</td>
176
				<td class="listr">
177
					<?=$conn['connect_time'];?>
178
				</td>
179
				<td class="listr">
180 ef462f25 jim-p
					<?=format_bytes($conn['bytes_sent']);?>
181 0927fb8c jim-p
				</td>
182
				<td class="listr">
183 ef462f25 jim-p
					<?=format_bytes($conn['bytes_recv']);?>
184 0927fb8c jim-p
				</td>
185 4d33138f Colin Fleming
				<td class="list">
186
					<img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" height="17" width="17" border="0"
187
					   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style="cursor:pointer;"
188
					   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
189
					   title="<?php echo gettext("Kill client connection from") . " " . $conn['remote_host']; ?>" alt="delete" />
190 0927fb8c jim-p
				</td>
191
			</tr>
192
193
			<?php endforeach; ?>
194 f06f7cc0 PiBa-NL
			<tfoot>
195 0927fb8c jim-p
			<tr>
196 2eaa97b9 jim-p
				<td colspan="2" class="list" height="12">
197
				<table>
198
				<tr>
199 4d33138f Colin Fleming
				<td><?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
200 2eaa97b9 jim-p
				<?= get_service_status_icon($ssvc, true, true); ?>
201 4d33138f Colin Fleming
				<?= get_service_control_links($ssvc, true); ?></td>
202 2eaa97b9 jim-p
				</tr>
203
				</table>
204
				</td>
205
				<td colspan="4" class="list" height="12">&nbsp;</td>
206 0927fb8c jim-p
			</tr>
207 f06f7cc0 PiBa-NL
			</tfoot>
208 0927fb8c jim-p
		</table>
209
		</td>
210
	</tr>
211
</table>
212 ec970b50 jim-p
<?php if (is_array($server['routes']) && count($server['routes'])): ?>
213
<div id="shroutebut-<?= $i ?>">
214 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.") ?>
215 8cd558b6 ayvis
<br /><br />
216 ec970b50 jim-p
</div>
217 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">
218 ec970b50 jim-p
	<tr>
219
		<td colspan="6" class="listtopic">
220
			<?=$server['name'];?> <?=gettext("Routing Table"); ?>
221
		</td>
222
	</tr>
223
	<tr>
224
		<td>
225 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">
226 ec970b50 jim-p
			<tr>
227
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
228
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
229
				<td class="listhdrr"><?=gettext("Target Network"); ?></td>
230
				<td class="listhdrr"><?=gettext("Last Used"); ?></td>
231
			</tr>
232
233
			<?php foreach ($server['routes'] as $conn): ?>
234 4d33138f Colin Fleming
			<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
235 ec970b50 jim-p
				<td class="listlr">
236
					<?=$conn['common_name'];?>
237
				</td>
238
				<td class="listr">
239
					<?=$conn['remote_host'];?>
240
				</td>
241
				<td class="listr">
242
					<?=$conn['virtual_addr'];?>
243
				</td>
244
				<td class="listr">
245
					<?=$conn['last_time'];?>
246
				</td>
247
			</tr>
248 63084885 Matthew Grooms
249 ec970b50 jim-p
			<?php endforeach; ?>
250
			<tfoot>
251
			<tr>
252
				<td colspan="6" class="list" height="12"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
253
			</tr>
254
			</tfoot>
255
		</table>
256
		</td>
257
	</tr>
258
</table>
259
<?php endif; ?>
260 8cd558b6 ayvis
<br />
261 ec970b50 jim-p
<?php $i++; ?>
262 0927fb8c jim-p
<?php endforeach; ?>
263 8cd558b6 ayvis
<br />
264 d0f6649c pierrepomes
265 95305736 jim-p
<?php if (!empty($sk_servers)) { ?>
266 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">
267 95305736 jim-p
	<tr>
268
		<td colspan="6" class="listtopic">
269 453d9c96 jim-p
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
270 95305736 jim-p
		</td>
271
	</tr>
272
	<tr>
273 a5eb046f Renato Botelho
		<td>
274 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">
275 a5eb046f Renato Botelho
			<tr>
276
				<td class="listhdrr"><?=gettext("Name"); ?></td>
277
				<td class="listhdrr"><?=gettext("Status"); ?></td>
278
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
279
				<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
280
				<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
281
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
282
				<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
283
				<td class="listhdrr"><?=gettext("Service"); ?></td>
284
			</tr>
285 d0f6649c pierrepomes
286 95305736 jim-p
<?php foreach ($sk_servers as $sk_server): ?>
287 4d33138f Colin Fleming
			<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
288 a5eb046f Renato Botelho
				<td class="listlr">
289
					<?=$sk_server['name'];?>
290
				</td>
291
				<td class="listr">
292
					<?=$sk_server['status'];?>
293
				</td>
294
				<td class="listr">
295
					<?=$sk_server['connect_time'];?>
296
				</td>
297
				<td class="listr">
298
					<?=$sk_server['virtual_addr'];?>
299
				</td>
300
				<td class="listr">
301
					<?=$sk_server['remote_host'];?>
302
				</td>
303
				<td class="listr">
304 ef462f25 jim-p
					<?=format_bytes($sk_server['bytes_sent']);?>
305 a5eb046f Renato Botelho
				</td>
306
				<td class="listr">
307 ef462f25 jim-p
					<?=format_bytes($sk_server['bytes_recv']);?>
308 a5eb046f Renato Botelho
				</td>
309
				<td class="listr">
310
				<table>
311
				<tr>
312 4d33138f Colin Fleming
				<td><?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
313 a5eb046f Renato Botelho
				<?= get_service_status_icon($ssvc, false, true); ?>
314 4d33138f Colin Fleming
				<?= get_service_control_links($ssvc, true); ?></td>
315 a5eb046f Renato Botelho
				</tr>
316
				</table>
317
				</td>
318 2eaa97b9 jim-p
			</tr>
319 6a7230b6 jim-p
<?php endforeach; ?>
320 a5eb046f Renato Botelho
			</table>
321
		</td>
322 95305736 jim-p
	</tr>
323
</table>
324
325
<?php
326
} ?>
327 8cd558b6 ayvis
<br />
328 cf1ced6d pierrepomes
<?php if (!empty($clients)) { ?>
329 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">
330 d0f6649c pierrepomes
	<tr>
331
		<td colspan="6" class="listtopic">
332 95305736 jim-p
			<?=gettext("Client Instance Statistics"); ?>
333 d0f6649c pierrepomes
		</td>
334
	</tr>
335
	<tr>
336 a5eb046f Renato Botelho
		<td>
337 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">
338 a5eb046f Renato Botelho
			<tr>
339
				<td class="listhdrr"><?=gettext("Name"); ?></td>
340
				<td class="listhdrr"><?=gettext("Status"); ?></td>
341
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
342
				<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
343
				<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
344
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
345
				<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
346
				<td class="listhdrr"><?=gettext("Service"); ?></td>
347
			</tr>
348 d0f6649c pierrepomes
349
<?php foreach ($clients as $client): ?>
350 4d33138f Colin Fleming
			<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
351 a5eb046f Renato Botelho
				<td class="listlr">
352
					<?=$client['name'];?>
353
				</td>
354
				<td class="listr">
355
					<?=$client['status'];?>
356
				</td>
357
				<td class="listr">
358
					<?=$client['connect_time'];?>
359
				</td>
360
				<td class="listr">
361
					<?=$client['virtual_addr'];?>
362
				</td>
363
				<td class="listr">
364
					<?=$client['remote_host'];?>
365
				</td>
366
				<td class="listr">
367 ef462f25 jim-p
					<?=format_bytes($client['bytes_sent']);?>
368 a5eb046f Renato Botelho
				</td>
369
				<td class="listr">
370 ef462f25 jim-p
					<?=format_bytes($client['bytes_recv']);?>
371 a5eb046f Renato Botelho
				</td>
372
				<td class="listr" height="12">
373
				<table>
374
				<tr>
375 4d33138f Colin Fleming
				<td><?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
376 a5eb046f Renato Botelho
				<?= get_service_status_icon($ssvc, false, true); ?>
377 4d33138f Colin Fleming
				<?= get_service_control_links($ssvc, true); ?></td>
378 a5eb046f Renato Botelho
				</tr>
379
				</table>
380
				</td>
381 2eaa97b9 jim-p
			</tr>
382 6a7230b6 jim-p
<?php endforeach; ?>
383 a5eb046f Renato Botelho
			</table>
384
		</td>
385 d0f6649c pierrepomes
	</tr>
386
</table>
387
388 cf1ced6d pierrepomes
<?php 
389
}
390
391
if ($DisplayNote) {
392 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.");
393 d0f6649c pierrepomes
}
394
395 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
396 b7b3f343 Chris Buechler
	echo gettext("No OpenVPN instances defined");
397 d0f6649c pierrepomes
}
398
?>
399 2a351d32 Colin Fleming
</form>
400 63084885 Matthew Grooms
401
<?php include("fend.inc"); ?>
402 ec970b50 jim-p
<script type="text/javascript">
403 4d33138f Colin Fleming
//<![CDATA[
404 ec970b50 jim-p
function show_routes(id, buttonid) {
405
	document.getElementById(buttonid).innerHTML='';
406
	aodiv = document.getElementById(id);
407
	aodiv.style.display = "block";
408
}
409 4d33138f Colin Fleming
//]]>
410 ec970b50 jim-p
</script>
411 4d33138f Colin Fleming
</body>
412
</html>