Project

General

Profile

Download (12.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_openvpn.php
4

    
5
	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

    
10
	AJAX bits borrowed from diag_dump_states.php
11

    
12
	All rights reserved.
13

    
14
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16

    
17
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19

    
20
	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

    
24
	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
/*
36
	pfSense_MODULE:	openvpn
37
*/
38

    
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
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
47
$shortcut_section = "openvpn";
48

    
49
require("guiconfig.inc");
50
require_once("openvpn.inc");
51
require_once("shortcuts.inc");
52
require_once("service-utils.inc");
53

    
54
/* 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
			echo gettext("invalid input");
64
		}
65
		exit;
66
	}
67
}
68

    
69

    
70
function kill_client($port, $remipp) {
71
	global $g;
72

    
73
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
74
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
75
	$errval;
76
	$errstr;
77

    
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
		stream_set_timeout($fp, 1);
83
		fputs($fp, "kill {$remipp}\n");
84
		while (!feof($fp)) {
85
			$line = fgets($fp, 1024);
86

    
87
			$info = stream_get_meta_data($fp);
88
			if ($info['timed_out']) {
89
				break;
90
			}
91

    
92
			/* parse header list line */
93
			if (strpos($line, "INFO:") !== false) {
94
				continue;
95
			}
96
			if (strpos($line, "SUCCESS") !== false) {
97
				$killed = 0;
98
			}
99
			break;
100
		}
101
		fclose($fp);
102
	}
103
	return $killed;
104
}
105

    
106
$servers = openvpn_get_active_servers();
107
$sk_servers = openvpn_get_active_servers("p2p");
108
$clients = openvpn_get_active_clients();
109

    
110
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
//<![CDATA[
117
	function killClient(mport, remipp) {
118
		var busy = function(index,icon) {
119
			jQuery(icon).bind("onclick","");
120
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
121
			jQuery(icon).css("cursor","wait");
122
		}
123

    
124
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
125

    
126
		jQuery.ajax(
127
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
128
				"?action=kill&port=" + mport + "&remipp=" + remipp,
129
			{ type: "get", complete: killComplete }
130
		);
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
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
141
			function(index,row) { jQuery(row).fadeOut(1000); }
142
		);
143
	}
144
//]]>
145
</script>
146
<?php
147
	$i = 0;
148
	foreach ($servers as $server):
149
?>
150

    
151
<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
	<tr>
153
		<td colspan="6" class="listtopic">
154
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
155
		</td>
156
	</tr>
157
	<tr>
158
		<td>
159
			<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
				<tr>
161
					<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
				</tr>
168
<?php
169
		foreach ($server['conns'] as $conn):
170
?>
171
				<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
172
					<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
						<?=format_bytes($conn['bytes_sent']);?>
186
					</td>
187
					<td class="listr">
188
						<?=format_bytes($conn['bytes_recv']);?>
189
					</td>
190
					<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
					</td>
196
				</tr>
197
<?php
198
		endforeach;
199
?>
200
			<tfoot>
201
				<tr>
202
					<td colspan="2" class="list" height="12">
203
						<table>
204
							<tr>
205
								<td><?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
206
								<?= get_service_status_icon($ssvc, true, true); ?>
207
								<?= get_service_control_links($ssvc, true); ?></td>
208
							</tr>
209
						</table>
210
					</td>
211
					<td colspan="4" class="list" height="12">&nbsp;</td>
212
				</tr>
213
			</tfoot>
214
			</table>
215
		</td>
216
	</tr>
217
</table>
218
<?php
219
		if (is_array($server['routes']) && count($server['routes'])):
220
?>
221
<div id="shroutebut-<?= $i ?>">
222
	<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
	<br /><br />
224
</div>
225
<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
	<tr>
227
		<td colspan="6" class="listtopic">
228
			<?=$server['name'];?> <?=gettext("Routing Table"); ?>
229
		</td>
230
	</tr>
231
	<tr>
232
		<td>
233
			<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
				<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
<?php
242
			foreach ($server['routes'] as $conn):
243
?>
244
				<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
245
					<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
<?php
259
			endforeach;
260
?>
261
			<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
<?php
271
		endif;
272
?>
273
<br />
274
<?php
275
		$i++;
276
	endforeach;
277
?>
278
<br />
279

    
280
<?php
281
	if (!empty($sk_servers)) {
282
?>
283
<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
	<tr>
285
		<td colspan="6" class="listtopic">
286
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
287
		</td>
288
	</tr>
289
	<tr>
290
		<td>
291
			<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
				<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

    
303
<?php
304
		foreach ($sk_servers as $sk_server):
305
?>
306
				<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
307
					<td class="listlr">
308
						<?=$sk_server['name'];?>
309
					</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
						<?=format_bytes($sk_server['bytes_sent']);?>
324
					</td>
325
					<td class="listr">
326
						<?=format_bytes($sk_server['bytes_recv']);?>
327
					</td>
328
					<td class="listr">
329
						<table>
330
							<tr>
331
								<td><?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
332
									<?= get_service_status_icon($ssvc, false, true); ?>
333
									<?= get_service_control_links($ssvc, true); ?>
334
								</td>
335
							</tr>
336
						</table>
337
					</td>
338
				</tr>
339
<?php
340
		endforeach;
341
?>
342
			</table>
343
		</td>
344
	</tr>
345
</table>
346

    
347
<?php
348
	}
349
?>
350
<br />
351
<?php
352
	if (!empty($clients)) {
353
?>
354
<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
	<tr>
356
		<td colspan="6" class="listtopic">
357
			<?=gettext("Client Instance Statistics"); ?>
358
		</td>
359
	</tr>
360
	<tr>
361
		<td>
362
			<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
				<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

    
374
<?php
375
		foreach ($clients as $client):
376
?>
377
				<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
378
					<td class="listlr">
379
						<?=$client['name'];?>
380
					</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
						<?=format_bytes($client['bytes_sent']);?>
395
					</td>
396
					<td class="listr">
397
						<?=format_bytes($client['bytes_recv']);?>
398
					</td>
399
					<td class="listr" height="12">
400
						<table>
401
							<tr>
402
								<td>
403
									<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
404
									<?= get_service_status_icon($ssvc, false, true); ?>
405
									<?= get_service_control_links($ssvc, true); ?>
406
								</td>
407
							</tr>
408
						</table>
409
					</td>
410
				</tr>
411
<?php
412
		endforeach;
413
?>
414
			</table>
415
		</td>
416
	</tr>
417
</table>
418

    
419
<?php
420
	}
421

    
422
	if ($DisplayNote) {
423
		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
	}
425

    
426
	if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
427
		echo gettext("No OpenVPN instances defined");
428
	}
429
?>
430
</form>
431

    
432
<?php include("fend.inc"); ?>
433
<script type="text/javascript">
434
//<![CDATA[
435
function show_routes(id, buttonid) {
436
	document.getElementById(buttonid).innerHTML='';
437
	aodiv = document.getElementById(id);
438
	aodiv.style.display = "block";
439
}
440
//]]>
441
</script>
442
</body>
443
</html>
(192-192/252)