Projet

Général

Profil

Télécharger (12,6 ko) Statistiques
| Branche: | Tag: | Révision:

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

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
/* DISABLE_PHP_LINT_CHECKING */
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
			/* parse header list line */
92
			if (strpos($line, "INFO:") !== false)
93
				continue;
94
			if (strpos($line, "SUCCESS") !== false) {
95
				$killed = 0;
96
			}
97
			break;
98
		}
99
		fclose($fp);
100
	}
101
	return $killed;
102
}
103

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

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

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

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

    
147
<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
	<tr>
149
		<td colspan="6" class="listtopic">
150
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
151
		</td>
152
	</tr>
153
	<tr>
154
		<td>
155
			<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
			<tr>
157
				<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
			</tr>
164

    
165
			<?php foreach ($server['conns'] as $conn): ?>
166
			<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
167
				<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
					<?=format_bytes($conn['bytes_sent']);?>
181
				</td>
182
				<td class="listr">
183
					<?=format_bytes($conn['bytes_recv']);?>
184
				</td>
185
				<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
				</td>
191
			</tr>
192

    
193
			<?php endforeach; ?>
194
			<tfoot>
195
			<tr>
196
				<td colspan="2" class="list" height="12">
197
				<table>
198
				<tr>
199
				<td><?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
200
				<?= get_service_status_icon($ssvc, true, true); ?>
201
				<?= get_service_control_links($ssvc, true); ?></td>
202
				</tr>
203
				</table>
204
				</td>
205
				<td colspan="4" class="list" height="12">&nbsp;</td>
206
			</tr>
207
			</tfoot>
208
		</table>
209
		</td>
210
	</tr>
211
</table>
212
<?php if (is_array($server['routes']) && count($server['routes'])): ?>
213
<div id="shroutebut-<?= $i ?>">
214
<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
<br /><br />
216
</div>
217
<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
	<tr>
219
		<td colspan="6" class="listtopic">
220
			<?=$server['name'];?> <?=gettext("Routing Table"); ?>
221
		</td>
222
	</tr>
223
	<tr>
224
		<td>
225
			<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
			<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
			<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
235
				<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

    
249
			<?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
<br />
261
<?php $i++; ?>
262
<?php endforeach; ?>
263
<br />
264

    
265
<?php if (!empty($sk_servers)) { ?>
266
<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
	<tr>
268
		<td colspan="6" class="listtopic">
269
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
270
		</td>
271
	</tr>
272
	<tr>
273
		<td>
274
			<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
			<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

    
286
<?php foreach ($sk_servers as $sk_server): ?>
287
			<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
288
				<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
					<?=format_bytes($sk_server['bytes_sent']);?>
305
				</td>
306
				<td class="listr">
307
					<?=format_bytes($sk_server['bytes_recv']);?>
308
				</td>
309
				<td class="listr">
310
				<table>
311
				<tr>
312
				<td><?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
313
				<?= get_service_status_icon($ssvc, false, true); ?>
314
				<?= get_service_control_links($ssvc, true); ?></td>
315
				</tr>
316
				</table>
317
				</td>
318
			</tr>
319
<?php endforeach; ?>
320
			</table>
321
		</td>
322
	</tr>
323
</table>
324

    
325
<?php
326
} ?>
327
<br />
328
<?php if (!empty($clients)) { ?>
329
<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
	<tr>
331
		<td colspan="6" class="listtopic">
332
			<?=gettext("Client Instance Statistics"); ?>
333
		</td>
334
	</tr>
335
	<tr>
336
		<td>
337
			<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
			<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

    
349
<?php foreach ($clients as $client): ?>
350
			<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
351
				<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
					<?=format_bytes($client['bytes_sent']);?>
368
				</td>
369
				<td class="listr">
370
					<?=format_bytes($client['bytes_recv']);?>
371
				</td>
372
				<td class="listr" height="12">
373
				<table>
374
				<tr>
375
				<td><?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
376
				<?= get_service_status_icon($ssvc, false, true); ?>
377
				<?= get_service_control_links($ssvc, true); ?></td>
378
				</tr>
379
				</table>
380
				</td>
381
			</tr>
382
<?php endforeach; ?>
383
			</table>
384
		</td>
385
	</tr>
386
</table>
387

    
388
<?php 
389
}
390

    
391
if ($DisplayNote) {
392
	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
}
394

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

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