Project

General

Profile

Download (12.5 KB) Statistics
| Branch: | Tag: | Revision:
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
				<td class="listr" align="center">
199
				<?= get_service_status_icon($ssvc, true, true); ?>
200
				</td>
201
				<td><?= 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"); ?>"></input> - <?= gettext("Display OpenVPN's internal routing table for this server.") ?></a>
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 ?>">
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">
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 name='<?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">
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">
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 name='<?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
					<?=$sk_server['bytes_sent'];?>
305
				</td>
306
				<td class="listr">
307
					<?=$sk_server['bytes_recv'];?>
308
				</td>
309
				<td class="listr">
310
				<table>
311
				<tr>
312
				<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
313
				<td class="listr" align="center">
314
				<?= get_service_status_icon($ssvc, false, true); ?>
315
				</td>
316
				<td><?= get_service_control_links($ssvc, true); ?></td>
317
				</tr>
318
				</table>
319
				</td>
320
			</tr>
321
<?php endforeach; ?>
322
			</table>
323
		</td>
324
	</tr>
325
</table>
326

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

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

    
392
<?php 
393
}
394

    
395
if ($DisplayNote) {
396
	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.");
397
}
398

    
399
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
400
	echo gettext("No OpenVPN instance defined");
401
}
402
?>
403

    
404

    
405
<?php include("fend.inc"); ?>
406
<script type="text/javascript">
407
function show_routes(id, buttonid) {
408
	document.getElementById(buttonid).innerHTML='';
409
	aodiv = document.getElementById(id);
410
	aodiv.style.display = "block";
411
}
412
</script>
(187-187/246)