Project

General

Profile

Download (12.3 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 c92ccc70 Renato Botelho
require_once("service-utils.inc");
53 63084885 Matthew Grooms
54 0927fb8c jim-p
/* 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 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
64 0927fb8c jim-p
		}
65
		exit;
66
	}
67
}
68
69
70
function kill_client($port, $remipp) {
71 71ca2cb2 Ermal
	global $g;
72
73
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
74
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
75 0927fb8c jim-p
	$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 19e3d450 Ermal
		stream_set_timeout($fp, 1);
83 0927fb8c jim-p
		fputs($fp, "kill {$remipp}\n");
84
		while (!feof($fp)) {
85
			$line = fgets($fp, 1024);
86 b0140675 Ermal
87
			$info = stream_get_meta_data($fp);
88
			if ($info['timed_out'])
89
				break;
90
91 0927fb8c jim-p
			/* parse header list line */
92 68b04527 jim-p
			if (strpos($line, "INFO:") !== false)
93 0927fb8c jim-p
				continue;
94 68b04527 jim-p
			if (strpos($line, "SUCCESS") !== false) {
95 0927fb8c jim-p
				$killed = 0;
96
			}
97
			break;
98
		}
99
		fclose($fp);
100
	}
101
	return $killed;
102
}
103
104 53663f57 jim-p
$servers = openvpn_get_active_servers();
105 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
106 53663f57 jim-p
$clients = openvpn_get_active_clients();
107 63084885 Matthew Grooms
108 0927fb8c jim-p
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 b9144088 jim-p
		var busy = function(index,icon) {
116 e03ef9a0 Vinicius Coque
			jQuery(icon).bind("onclick","");
117
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
118
			jQuery(icon).css("cursor","wait");
119 0927fb8c jim-p
		}
120
121 e03ef9a0 Vinicius Coque
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
122 0927fb8c jim-p
123 e03ef9a0 Vinicius Coque
		jQuery.ajax(
124 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
125
				"?action=kill&port=" + mport + "&remipp=" + remipp,
126 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
127 0927fb8c jim-p
		);
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 e03ef9a0 Vinicius Coque
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
138
			function(index,row) { jQuery(row).fadeOut(1000); }
139 0927fb8c jim-p
		);
140
	}
141
</script>
142 ec970b50 jim-p
<?php $i = 0; ?>
143 0927fb8c jim-p
<?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 95305736 jim-p
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
149 0927fb8c jim-p
		</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 e9d35ff5 Carlos Eduardo Ramos
				<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 0927fb8c jim-p
			</tr>
162
163
			<?php foreach ($server['conns'] as $conn): ?>
164 68b04527 jim-p
			<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
165 0927fb8c jim-p
				<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 71ca2cb2 Ermal
					   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style='cursor:pointer;'
186 68b04527 jim-p
					   name='<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>'
187
					   title='<?php echo gettext("Kill client connection from") . ' ' . $conn['remote_host']; ?>' alt='' />
188 0927fb8c jim-p
				</td>
189
			</tr>
190
191
			<?php endforeach; ?>
192 f06f7cc0 PiBa-NL
			<tfoot>
193 0927fb8c jim-p
			<tr>
194 2eaa97b9 jim-p
				<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 0927fb8c jim-p
			</tr>
205 f06f7cc0 PiBa-NL
			</tfoot>
206 0927fb8c jim-p
		</table>
207
		</td>
208
	</tr>
209
</table>
210 ec970b50 jim-p
<?php if (is_array($server['routes']) && count($server['routes'])): ?>
211
<div id="shroutebut-<?= $i ?>">
212 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>
213 ec970b50 jim-p
<br/><br/>
214
</div>
215 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 ?>">
216 ec970b50 jim-p
	<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 63084885 Matthew Grooms
247 ec970b50 jim-p
			<?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 0927fb8c jim-p
<?php endforeach; ?>
261 ec970b50 jim-p
<br/>
262 d0f6649c pierrepomes
263 95305736 jim-p
<?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 453d9c96 jim-p
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
268 95305736 jim-p
		</td>
269
	</tr>
270
	<tr>
271 a5eb046f Renato Botelho
		<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 d0f6649c pierrepomes
284 95305736 jim-p
<?php foreach ($sk_servers as $sk_server): ?>
285 a5eb046f Renato Botelho
			<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 2eaa97b9 jim-p
			</tr>
317 6a7230b6 jim-p
<?php endforeach; ?>
318 a5eb046f Renato Botelho
			</table>
319
		</td>
320 95305736 jim-p
	</tr>
321
</table>
322
323
<?php
324
} ?>
325
<br>
326 cf1ced6d pierrepomes
<?php if (!empty($clients)) { ?>
327 d0f6649c pierrepomes
<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 95305736 jim-p
			<?=gettext("Client Instance Statistics"); ?>
331 d0f6649c pierrepomes
		</td>
332
	</tr>
333
	<tr>
334 a5eb046f Renato Botelho
		<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 d0f6649c pierrepomes
347
<?php foreach ($clients as $client): ?>
348 a5eb046f Renato Botelho
			<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 2eaa97b9 jim-p
			</tr>
380 6a7230b6 jim-p
<?php endforeach; ?>
381 a5eb046f Renato Botelho
			</table>
382
		</td>
383 d0f6649c pierrepomes
	</tr>
384
</table>
385
386 cf1ced6d pierrepomes
<?php 
387
}
388
389
if ($DisplayNote) {
390 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.");
391 d0f6649c pierrepomes
}
392
393 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
394 e9d35ff5 Carlos Eduardo Ramos
	echo gettext("No OpenVPN instance defined");
395 d0f6649c pierrepomes
}
396
?>
397
398 63084885 Matthew Grooms
399
<?php include("fend.inc"); ?>
400 ec970b50 jim-p
<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>