Project

General

Profile

Download (12.6 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / status_openvpn.php @ a1b66bec

1
<?php
2
/*
3
	status_ovpenvpn.php
4

    
5
    Copyright (C) 2010 Jim Pingle
6
    Copyright (C) 2008 Shrew Soft Inc.
7

    
8
    AJAX bits borrowed from diag_dump_states.php
9
    Copyright (C) 2005 Scott Ullrich, Colin Smith
10

    
11
    All rights reserved.
12

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

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

    
19
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22

    
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34
/*
35
	pfSense_MODULE:	openvpn
36
*/
37

    
38
##|+PRIV
39
##|*IDENT=page-status-openvpn
40
##|*NAME=Status: OpenVPN page
41
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
42
##|*MATCH=status_openvpn.php*
43
##|-PRIV
44

    
45
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
46
$shortcut_section = "openvpn";
47

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

    
53
/* Handle AJAX */
54
if($_GET['action']) {
55
	if($_GET['action'] == "kill") {
56
		$port  = $_GET['port'];
57
		$remipp  = $_GET['remipp'];
58
		if (!empty($port) and !empty($remipp)) {
59
			$retval = kill_client($port, $remipp);
60
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
61
		} else {
62
			echo gettext("invalid input");
63
		}
64
		exit;
65
	}
66
}
67

    
68

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

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

    
77
	/* open a tcp connection to the management port of each server */
78
	$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
79
	$killed = -1;
80
	if ($fp) {
81
		stream_set_timeout($fp, 1);
82
		fputs($fp, "kill {$remipp}\n");
83
		while (!feof($fp)) {
84
			$line = fgets($fp, 1024);
85

    
86
			$info = stream_get_meta_data($fp);
87
			if ($info['timed_out'])
88
				break;
89

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

    
103
$servers = openvpn_get_active_servers();
104
$sk_servers = openvpn_get_active_servers("p2p");
105
$clients = openvpn_get_active_clients();
106

    
107
include("head.inc"); ?>
108

    
109
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
110
<?php include("fbegin.inc"); ?>
111
<form action="status_openvpn.php" method="get" name="iform">
112
<script type="text/javascript">
113
//<![CDATA[
114
	function killClient(mport, remipp) {
115
		var busy = function(index,icon) {
116
			jQuery(icon).bind("onclick","");
117
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
118
			jQuery(icon).css("cursor","wait");
119
		}
120

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

    
123
		jQuery.ajax(
124
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
125
				"?action=kill&port=" + mport + "&remipp=" + remipp,
126
			{ type: "get", complete: killComplete }
127
		);
128
	}
129

    
130
	function killComplete(req) {
131
		var values = req.responseText.split("|");
132
		if(values[3] != "0") {
133
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
134
			return;
135
		}
136

    
137
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
138
			function(index,row) { jQuery(row).fadeOut(1000); }
139
		);
140
	}
141
//]]>
142
</script>
143
<?php $i = 0; ?>
144
<?php foreach ($servers as $server): ?>
145

    
146
<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">
147
	<tr>
148
		<td colspan="6" class="listtopic">
149
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
150
		</td>
151
	</tr>
152
	<tr>
153
		<td>
154
			<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">
155
			<tr>
156
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
157
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
158
				<td class="listhdrr"><?=gettext("Virtual Address"); ?></td>
159
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
160
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
161
				<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
162
			</tr>
163

    
164
			<?php foreach ($server['conns'] as $conn): ?>
165
			<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
166
				<td class="listlr">
167
					<?=$conn['common_name'];?>
168
				</td>
169
				<td class="listr">
170
					<?=$conn['remote_host'];?>
171
				</td>
172
				<td class="listr">
173
					<?=$conn['virtual_addr'];?>
174
				</td>
175
				<td class="listr">
176
					<?=$conn['connect_time'];?>
177
				</td>
178
				<td class="listr">
179
					<?=format_bytes($conn['bytes_sent']);?>
180
				</td>
181
				<td class="listr">
182
					<?=format_bytes($conn['bytes_recv']);?>
183
				</td>
184
				<td class="list">
185
					<img src="/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif" height="17" width="17" border="0"
186
					   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style="cursor:pointer;"
187
					   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
188
					   title="<?php echo gettext("Kill client connection from") . " " . $conn['remote_host']; ?>" alt="delete" />
189
				</td>
190
			</tr>
191

    
192
			<?php endforeach; ?>
193
			<tfoot>
194
			<tr>
195
				<td colspan="2" class="list" height="12">
196
				<table>
197
				<tr>
198
				<td><?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
199
				<?= get_service_status_icon($ssvc, true, true); ?>
200
				<?= get_service_control_links($ssvc, true); ?></td>
201
				</tr>
202
				</table>
203
				</td>
204
				<td colspan="4" class="list" height="12">&nbsp;</td>
205
			</tr>
206
			</tfoot>
207
		</table>
208
		</td>
209
	</tr>
210
</table>
211
<?php if (is_array($server['routes']) && count($server['routes'])): ?>
212
<div id="shroutebut-<?= $i ?>">
213
<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.") ?>
214
<br /><br />
215
</div>
216
<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">
217
	<tr>
218
		<td colspan="6" class="listtopic">
219
			<?=$server['name'];?> <?=gettext("Routing Table"); ?>
220
		</td>
221
	</tr>
222
	<tr>
223
		<td>
224
			<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">
225
			<tr>
226
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
227
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
228
				<td class="listhdrr"><?=gettext("Target Network"); ?></td>
229
				<td class="listhdrr"><?=gettext("Last Used"); ?></td>
230
			</tr>
231

    
232
			<?php foreach ($server['routes'] as $conn): ?>
233
			<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
234
				<td class="listlr">
235
					<?=$conn['common_name'];?>
236
				</td>
237
				<td class="listr">
238
					<?=$conn['remote_host'];?>
239
				</td>
240
				<td class="listr">
241
					<?=$conn['virtual_addr'];?>
242
				</td>
243
				<td class="listr">
244
					<?=$conn['last_time'];?>
245
				</td>
246
			</tr>
247

    
248
			<?php endforeach; ?>
249
			<tfoot>
250
			<tr>
251
				<td colspan="6" class="list" height="12"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
252
			</tr>
253
			</tfoot>
254
		</table>
255
		</td>
256
	</tr>
257
</table>
258
<?php endif; ?>
259
<br />
260
<?php $i++; ?>
261
<?php endforeach; ?>
262
<br />
263

    
264
<?php if (!empty($sk_servers)) { ?>
265
<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">
266
	<tr>
267
		<td colspan="6" class="listtopic">
268
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
269
		</td>
270
	</tr>
271
	<tr>
272
		<td>
273
			<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">
274
			<tr>
275
				<td class="listhdrr"><?=gettext("Name"); ?></td>
276
				<td class="listhdrr"><?=gettext("Status"); ?></td>
277
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
278
				<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
279
				<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
280
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
281
				<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
282
				<td class="listhdrr"><?=gettext("Service"); ?></td>
283
			</tr>
284

    
285
<?php foreach ($sk_servers as $sk_server): ?>
286
			<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
287
				<td class="listlr">
288
					<?=$sk_server['name'];?>
289
				</td>
290
				<td class="listr">
291
					<?=$sk_server['status'];?>
292
				</td>
293
				<td class="listr">
294
					<?=$sk_server['connect_time'];?>
295
				</td>
296
				<td class="listr">
297
					<?=$sk_server['virtual_addr'];?>
298
				</td>
299
				<td class="listr">
300
					<?=$sk_server['remote_host'];?>
301
				</td>
302
				<td class="listr">
303
					<?=format_bytes($sk_server['bytes_sent']);?>
304
				</td>
305
				<td class="listr">
306
					<?=format_bytes($sk_server['bytes_recv']);?>
307
				</td>
308
				<td class="listr">
309
				<table>
310
				<tr>
311
				<td><?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
312
				<?= get_service_status_icon($ssvc, false, true); ?>
313
				<?= get_service_control_links($ssvc, true); ?></td>
314
				</tr>
315
				</table>
316
				</td>
317
			</tr>
318
<?php endforeach; ?>
319
			</table>
320
		</td>
321
	</tr>
322
</table>
323

    
324
<?php
325
} ?>
326
<br />
327
<?php if (!empty($clients)) { ?>
328
<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">
329
	<tr>
330
		<td colspan="6" class="listtopic">
331
			<?=gettext("Client Instance Statistics"); ?>
332
		</td>
333
	</tr>
334
	<tr>
335
		<td>
336
			<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">
337
			<tr>
338
				<td class="listhdrr"><?=gettext("Name"); ?></td>
339
				<td class="listhdrr"><?=gettext("Status"); ?></td>
340
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
341
				<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
342
				<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
343
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
344
				<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
345
				<td class="listhdrr"><?=gettext("Service"); ?></td>
346
			</tr>
347

    
348
<?php foreach ($clients as $client): ?>
349
			<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
350
				<td class="listlr">
351
					<?=$client['name'];?>
352
				</td>
353
				<td class="listr">
354
					<?=$client['status'];?>
355
				</td>
356
				<td class="listr">
357
					<?=$client['connect_time'];?>
358
				</td>
359
				<td class="listr">
360
					<?=$client['virtual_addr'];?>
361
				</td>
362
				<td class="listr">
363
					<?=$client['remote_host'];?>
364
				</td>
365
				<td class="listr">
366
					<?=format_bytes($client['bytes_sent']);?>
367
				</td>
368
				<td class="listr">
369
					<?=format_bytes($client['bytes_recv']);?>
370
				</td>
371
				<td class="listr" height="12">
372
				<table>
373
				<tr>
374
				<td><?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
375
				<?= get_service_status_icon($ssvc, false, true); ?>
376
				<?= get_service_control_links($ssvc, true); ?></td>
377
				</tr>
378
				</table>
379
				</td>
380
			</tr>
381
<?php endforeach; ?>
382
			</table>
383
		</td>
384
	</tr>
385
</table>
386

    
387
<?php 
388
}
389

    
390
if ($DisplayNote) {
391
	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.");
392
}
393

    
394
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
395
	echo gettext("No OpenVPN instance defined");
396
}
397
?>
398
</form>
399

    
400
<?php include("fend.inc"); ?>
401
<script type="text/javascript">
402
//<![CDATA[
403
function show_routes(id, buttonid) {
404
	document.getElementById(buttonid).innerHTML='';
405
	aodiv = document.getElementById(id);
406
	aodiv.style.display = "block";
407
}
408
//]]>
409
</script>
410
</body>
411
</html>
(196-196/256)