Project

General

Profile

Download (12.2 KB) Statistics
| Branch: | Tag: | Revision:
1 0927fb8c jim-p
<?php
2 63084885 Matthew Grooms
/*
3
	status_ovpenvpn.php
4
5 0927fb8c jim-p
    Copyright (C) 2010 Jim Pingle
6 63084885 Matthew Grooms
    Copyright (C) 2008 Shrew Soft Inc.
7 0927fb8c jim-p
8
    AJAX bits borrowed from diag_dump_states.php
9
    Copyright (C) 2005 Scott Ullrich, Colin Smith
10
11 63084885 Matthew Grooms
    All rights reserved.
12 0927fb8c jim-p
13 63084885 Matthew Grooms
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 0927fb8c jim-p
16 63084885 Matthew Grooms
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 0927fb8c jim-p
19 63084885 Matthew Grooms
	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 0927fb8c jim-p
23 63084885 Matthew Grooms
	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 61dda8f7 Matthew Grooms
/* DISABLE_PHP_LINT_CHECKING */
35 0927fb8c jim-p
/*
36 1d333258 Scott Ullrich
	pfSense_MODULE:	openvpn
37
*/
38 63084885 Matthew Grooms
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 e9d35ff5 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
47 7d7b5a48 jim-p
$shortcut_section = "openvpn";
48
49 63084885 Matthew Grooms
require("guiconfig.inc");
50 53663f57 jim-p
require_once("openvpn.inc");
51 2eaa97b9 jim-p
require_once("shortcuts.inc");
52 63084885 Matthew Grooms
53 0927fb8c jim-p
/* 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 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
63 0927fb8c jim-p
		}
64
		exit;
65
	}
66
}
67
68
69
function kill_client($port, $remipp) {
70 71ca2cb2 Ermal
	global $g;
71
72
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
73
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
74 0927fb8c jim-p
	$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 19e3d450 Ermal
		stream_set_timeout($fp, 1);
82 0927fb8c jim-p
		fputs($fp, "kill {$remipp}\n");
83
		while (!feof($fp)) {
84
			$line = fgets($fp, 1024);
85 b0140675 Ermal
86
			$info = stream_get_meta_data($fp);
87
			if ($info['timed_out'])
88
				break;
89
90 0927fb8c jim-p
			/* parse header list line */
91 68b04527 jim-p
			if (strpos($line, "INFO:") !== false)
92 0927fb8c jim-p
				continue;
93 68b04527 jim-p
			if (strpos($line, "SUCCESS") !== false) {
94 0927fb8c jim-p
				$killed = 0;
95
			}
96
			break;
97
		}
98
		fclose($fp);
99
	}
100
	return $killed;
101
}
102
103 53663f57 jim-p
$servers = openvpn_get_active_servers();
104 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
105 53663f57 jim-p
$clients = openvpn_get_active_clients();
106 63084885 Matthew Grooms
107 0927fb8c jim-p
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
	function killClient(mport, remipp) {
114 b9144088 jim-p
		var busy = function(index,icon) {
115 e03ef9a0 Vinicius Coque
			jQuery(icon).bind("onclick","");
116
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
117
			jQuery(icon).css("cursor","wait");
118 0927fb8c jim-p
		}
119
120 e03ef9a0 Vinicius Coque
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
121 0927fb8c jim-p
122 e03ef9a0 Vinicius Coque
		jQuery.ajax(
123 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
124
				"?action=kill&port=" + mport + "&remipp=" + remipp,
125 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
126 0927fb8c jim-p
		);
127
	}
128
129
	function killComplete(req) {
130
		var values = req.responseText.split("|");
131
		if(values[3] != "0") {
132
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
133
			return;
134
		}
135
136 e03ef9a0 Vinicius Coque
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
137
			function(index,row) { jQuery(row).fadeOut(1000); }
138 0927fb8c jim-p
		);
139
	}
140
</script>
141 ec970b50 jim-p
<?php $i = 0; ?>
142 0927fb8c jim-p
<?php foreach ($servers as $server): ?>
143
144
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
145
	<tr>
146
		<td colspan="6" class="listtopic">
147 95305736 jim-p
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
148 0927fb8c jim-p
		</td>
149
	</tr>
150
	<tr>
151
		<td>
152
			<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">
153
			<tr>
154 e9d35ff5 Carlos Eduardo Ramos
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
155
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
156
				<td class="listhdrr"><?=gettext("Virtual Address"); ?></td>
157
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
158
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
159
				<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
160 0927fb8c jim-p
			</tr>
161
162
			<?php foreach ($server['conns'] as $conn): ?>
163 68b04527 jim-p
			<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
164 0927fb8c jim-p
				<td class="listlr">
165
					<?=$conn['common_name'];?>
166
				</td>
167
				<td class="listr">
168
					<?=$conn['remote_host'];?>
169
				</td>
170
				<td class="listr">
171
					<?=$conn['virtual_addr'];?>
172
				</td>
173
				<td class="listr">
174
					<?=$conn['connect_time'];?>
175
				</td>
176
				<td class="listr">
177
					<?=$conn['bytes_sent'];?>
178
				</td>
179
				<td class="listr">
180
					<?=$conn['bytes_recv'];?>
181
				</td>
182
				<td class='list'>
183
					<img src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' height='17' width='17' border='0'
184 71ca2cb2 Ermal
					   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style='cursor:pointer;'
185 68b04527 jim-p
					   name='<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>'
186
					   title='<?php echo gettext("Kill client connection from") . ' ' . $conn['remote_host']; ?>' alt='' />
187 0927fb8c jim-p
				</td>
188
			</tr>
189
190
			<?php endforeach; ?>
191 f06f7cc0 PiBa-NL
			<tfoot>
192 0927fb8c jim-p
			<tr>
193 2eaa97b9 jim-p
				<td colspan="2" class="list" height="12">
194
				<table>
195
				<tr>
196
				<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
197
				<?= get_service_status_icon($ssvc, true, true); ?>
198
				<td><?= get_service_control_links($ssvc, true); ?></td>
199
				</tr>
200
				</table>
201
				</td>
202
				<td colspan="4" class="list" height="12">&nbsp;</td>
203 0927fb8c jim-p
			</tr>
204 f06f7cc0 PiBa-NL
			</tfoot>
205 0927fb8c jim-p
		</table>
206
		</td>
207
	</tr>
208
</table>
209 ec970b50 jim-p
<?php if (is_array($server['routes']) && count($server['routes'])): ?>
210
<div id="shroutebut-<?= $i ?>">
211 39f245c8 jim-p
<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>
212 ec970b50 jim-p
<br/><br/>
213
</div>
214 39f245c8 jim-p
<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 ?>">
215 ec970b50 jim-p
	<tr>
216
		<td colspan="6" class="listtopic">
217
			<?=$server['name'];?> <?=gettext("Routing Table"); ?>
218
		</td>
219
	</tr>
220
	<tr>
221
		<td>
222
			<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">
223
			<tr>
224
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
225
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
226
				<td class="listhdrr"><?=gettext("Target Network"); ?></td>
227
				<td class="listhdrr"><?=gettext("Last Used"); ?></td>
228
			</tr>
229
230
			<?php foreach ($server['routes'] as $conn): ?>
231
			<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
232
				<td class="listlr">
233
					<?=$conn['common_name'];?>
234
				</td>
235
				<td class="listr">
236
					<?=$conn['remote_host'];?>
237
				</td>
238
				<td class="listr">
239
					<?=$conn['virtual_addr'];?>
240
				</td>
241
				<td class="listr">
242
					<?=$conn['last_time'];?>
243
				</td>
244
			</tr>
245 63084885 Matthew Grooms
246 ec970b50 jim-p
			<?php endforeach; ?>
247
			<tfoot>
248
			<tr>
249
				<td colspan="6" class="list" height="12"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
250
			</tr>
251
			</tfoot>
252
		</table>
253
		</td>
254
	</tr>
255
</table>
256
<?php endif; ?>
257
<br/>
258
<?php $i++; ?>
259 0927fb8c jim-p
<?php endforeach; ?>
260 ec970b50 jim-p
<br/>
261 d0f6649c pierrepomes
262 95305736 jim-p
<?php if (!empty($sk_servers)) { ?>
263
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
264
	<tr>
265
		<td colspan="6" class="listtopic">
266 453d9c96 jim-p
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
267 95305736 jim-p
		</td>
268
	</tr>
269
	<tr>
270
		<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">
271
		<tr>
272
			<td class="listhdrr"><?=gettext("Name"); ?></td>
273
			<td class="listhdrr"><?=gettext("Status"); ?></td>
274
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
275
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
276
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
277
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
278 6a7230b6 jim-p
			<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
279 b4e98881 jim-p
			<td class="listhdrr"><?=gettext("Service"); ?></td>
280 95305736 jim-p
		</tr>
281 d0f6649c pierrepomes
282 95305736 jim-p
<?php foreach ($sk_servers as $sk_server): ?>
283
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
284
			<td class="listlr">
285
				<?=$sk_server['name'];?>
286
			</td>
287
			<td class="listlr">
288
				<?=$sk_server['status'];?>
289
			</td>
290
			<td class="listr">
291
				<?=$sk_server['connect_time'];?>
292
			</td>
293
			<td class="listr">
294
				<?=$sk_server['virtual_addr'];?>
295
			</td>
296
			<td class="listr">
297
				<?=$sk_server['remote_host'];?>
298
			</td>
299
			<td class="listr">
300
				<?=$sk_server['bytes_sent'];?>
301
			</td>
302
			<td class="listr">
303
				<?=$sk_server['bytes_recv'];?>
304
			</td>
305 6a7230b6 jim-p
			<td class="listr">
306 2eaa97b9 jim-p
			<table>
307
			<tr>
308
			<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
309 6a7230b6 jim-p
			<?= get_service_status_icon($ssvc, false, true); ?>
310 2eaa97b9 jim-p
			<td><?= get_service_control_links($ssvc, true); ?></td>
311
			</tr>
312
			</table>
313
			</td>
314
		</tr>
315 6a7230b6 jim-p
<?php endforeach; ?>
316 95305736 jim-p
		</table>
317
	</tr>
318
</table>
319
320
<?php
321
} ?>
322
<br>
323 cf1ced6d pierrepomes
<?php if (!empty($clients)) { ?>
324 d0f6649c pierrepomes
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
325
	<tr>
326
		<td colspan="6" class="listtopic">
327 95305736 jim-p
			<?=gettext("Client Instance Statistics"); ?>
328 d0f6649c pierrepomes
		</td>
329
	</tr>
330
	<tr>
331
		<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">
332
		<tr>
333 e9d35ff5 Carlos Eduardo Ramos
			<td class="listhdrr"><?=gettext("Name"); ?></td>
334
			<td class="listhdrr"><?=gettext("Status"); ?></td>
335
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
336
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
337
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
338
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
339 6a7230b6 jim-p
			<td class="listhdrr"><?=gettext("Bytes Rcvd"); ?></td>
340 b4e98881 jim-p
			<td class="listhdrr"><?=gettext("Service"); ?></td>
341 d0f6649c pierrepomes
		</tr>
342
343
<?php foreach ($clients as $client): ?>
344
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
345
			<td class="listlr">
346
				<?=$client['name'];?>
347
			</td>
348
			<td class="listlr">
349
				<?=$client['status'];?>
350
			</td>
351
			<td class="listr">
352
				<?=$client['connect_time'];?>
353
			</td>
354
			<td class="listr">
355
				<?=$client['virtual_addr'];?>
356
			</td>
357
			<td class="listr">
358
				<?=$client['remote_host'];?>
359
			</td>
360
			<td class="listr">
361
				<?=$client['bytes_sent'];?>
362
			</td>
363
			<td class="listr">
364
				<?=$client['bytes_recv'];?>
365
			</td>
366 6a7230b6 jim-p
			<td class="listr" height="12">
367 2eaa97b9 jim-p
			<table>
368
			<tr>
369
			<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
370 6a7230b6 jim-p
			<?= get_service_status_icon($ssvc, false, true); ?>
371 2eaa97b9 jim-p
			<td><?= get_service_control_links($ssvc, true); ?></td>
372
			</tr>
373
			</table>
374
			</td>
375
		</tr>
376 6a7230b6 jim-p
<?php endforeach; ?>
377 d0f6649c pierrepomes
		</table>
378
	</tr>
379
</table>
380
381 cf1ced6d pierrepomes
<?php 
382
}
383
384
if ($DisplayNote) {
385 2eaa97b9 jim-p
	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.");
386 d0f6649c pierrepomes
}
387
388 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
389 e9d35ff5 Carlos Eduardo Ramos
	echo gettext("No OpenVPN instance defined");
390 d0f6649c pierrepomes
}
391
?>
392
393 63084885 Matthew Grooms
394
<?php include("fend.inc"); ?>
395 ec970b50 jim-p
<script type="text/javascript">
396
function show_routes(id, buttonid) {
397
	document.getElementById(buttonid).innerHTML='';
398
	aodiv = document.getElementById(id);
399
	aodiv.style.display = "block";
400
}
401
</script>