Projet

Général

Profil

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

univnautes / usr / local / www / status_openvpn.php @ 0fab7eb1

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
	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
</script>
142
<?php $i = 0; ?>
143
<?php foreach ($servers as $server): ?>
144

    
145
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
146
	<tr>
147
		<td colspan="6" class="listtopic">
148
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
149
		</td>
150
	</tr>
151
	<tr>
152
		<td>
153
			<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">
154
			<tr>
155
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
156
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
157
				<td class="listhdrr"><?=gettext("Virtual Address"); ?></td>
158
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
159
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
160
				<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
161
			</tr>
162

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

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

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

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

    
263
<?php if (!empty($sk_servers)) { ?>
264
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
265
	<tr>
266
		<td colspan="6" class="listtopic">
267
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
268
		</td>
269
	</tr>
270
	<tr>
271
		<td>
272
			<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">
273
			<tr>
274
				<td class="listhdrr"><?=gettext("Name"); ?></td>
275
				<td class="listhdrr"><?=gettext("Status"); ?></td>
276
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
277
				<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
278
				<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
279
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
280
				<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
281
				<td class="listhdrr"><?=gettext("Service"); ?></td>
282
			</tr>
283

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

    
323
<?php
324
} ?>
325
<br />
326
<?php if (!empty($clients)) { ?>
327
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
328
	<tr>
329
		<td colspan="6" class="listtopic">
330
			<?=gettext("Client Instance Statistics"); ?>
331
		</td>
332
	</tr>
333
	<tr>
334
		<td>
335
			<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">
336
			<tr>
337
				<td class="listhdrr"><?=gettext("Name"); ?></td>
338
				<td class="listhdrr"><?=gettext("Status"); ?></td>
339
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
340
				<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
341
				<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
342
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
343
				<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
344
				<td class="listhdrr"><?=gettext("Service"); ?></td>
345
			</tr>
346

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

    
386
<?php 
387
}
388

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

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

    
398

    
399
<?php include("fend.inc"); ?>
400
<script type="text/javascript">
401
function show_routes(id, buttonid) {
402
	document.getElementById(buttonid).innerHTML='';
403
	aodiv = document.getElementById(id);
404
	aodiv.style.display = "block";
405
}
406
</script>
(194-194/254)