Project

General

Profile

Download (10.8 KB) Statistics
| Branch: | Tag: | Revision:
1 0927fb8c jim-p
<?php
2 63084885 Matthew Grooms
/*
3 ce77a9c4 Phil Davis
	status_openvpn.php
4 63084885 Matthew Grooms
5 ce77a9c4 Phil Davis
	Copyright (C) 2005 Scott Ullrich, Colin Smith
6
	Copyright (C) 2008 Shrew Soft Inc.
7
	Copyright (C) 2010 Jim Pingle
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9 0927fb8c jim-p
10 ce77a9c4 Phil Davis
	AJAX bits borrowed from diag_dump_states.php
11 0927fb8c jim-p
12 ce77a9c4 Phil Davis
	All rights reserved.
13 0927fb8c jim-p
14 63084885 Matthew Grooms
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16 0927fb8c jim-p
17 63084885 Matthew Grooms
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19 0927fb8c jim-p
20 63084885 Matthew Grooms
	2. Redistributions in binary form must reproduce the above copyright
21
	   notice, this list of conditions and the following disclaimer in the
22
	   documentation and/or other materials provided with the distribution.
23 0927fb8c jim-p
24 63084885 Matthew Grooms
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
	POSSIBILITY OF SUCH DAMAGE.
34
*/
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 247c417f Sjon Hortensius
	$errval = null;
76
	$errstr = null;
77 0927fb8c jim-p
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 42b0c921 Phil Davis
			if ($info['timed_out']) {
89 b0140675 Ermal
				break;
90 42b0c921 Phil Davis
			}
91 b0140675 Ermal
92 0927fb8c jim-p
			/* parse header list line */
93 42b0c921 Phil Davis
			if (strpos($line, "INFO:") !== false) {
94 0927fb8c jim-p
				continue;
95 42b0c921 Phil Davis
			}
96 68b04527 jim-p
			if (strpos($line, "SUCCESS") !== false) {
97 0927fb8c jim-p
				$killed = 0;
98
			}
99
			break;
100
		}
101
		fclose($fp);
102
	}
103
	return $killed;
104
}
105
106 53663f57 jim-p
$servers = openvpn_get_active_servers();
107 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
108 53663f57 jim-p
$clients = openvpn_get_active_clients();
109 63084885 Matthew Grooms
110 0927fb8c jim-p
include("head.inc"); ?>
111
112 c64a0911 Hari
<body>
113 0927fb8c jim-p
<form action="status_openvpn.php" method="get" name="iform">
114
<script type="text/javascript">
115 4d33138f Colin Fleming
//<![CDATA[
116 0927fb8c jim-p
	function killClient(mport, remipp) {
117 b9144088 jim-p
		var busy = function(index,icon) {
118 e03ef9a0 Vinicius Coque
			jQuery(icon).bind("onclick","");
119
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
120
			jQuery(icon).css("cursor","wait");
121 0927fb8c jim-p
		}
122
123 e03ef9a0 Vinicius Coque
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
124 0927fb8c jim-p
125 e03ef9a0 Vinicius Coque
		jQuery.ajax(
126 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
127
				"?action=kill&port=" + mport + "&remipp=" + remipp,
128 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
129 0927fb8c jim-p
		);
130
	}
131
132
	function killComplete(req) {
133
		var values = req.responseText.split("|");
134
		if(values[3] != "0") {
135
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
136
			return;
137
		}
138
139 e03ef9a0 Vinicius Coque
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
140
			function(index,row) { jQuery(row).fadeOut(1000); }
141 0927fb8c jim-p
		);
142
	}
143 4d33138f Colin Fleming
//]]>
144 0927fb8c jim-p
</script>
145 c64a0911 Hari
146 42b0c921 Phil Davis
<?php
147
	$i = 0;
148
	foreach ($servers as $server):
149
?>
150 0927fb8c jim-p
151 c64a0911 Hari
<div class="panel panel-default">
152
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client connections')?></h2></div>
153
		<div class="panel-body table-responsive">
154
			<table class="table table-striped table-hover">
155
				<thead>
156
					<tr>
157
						<th><?=gettext("Common Name")?></th>
158
						<th><?=gettext("Real Address")?></th>
159
						<th><?=gettext("Virtual Address"); ?></th>
160
						<th><?=gettext("Connected Since"); ?></th>
161
						<th><?=gettext("Bytes Sent")?></th>
162
						<th><?=gettext("Bytes Received")?></th>
163
					</tr>
164
				</thead>
165
				<tbody>
166 9f605c1c Hari
					
167
					<?php
168
							foreach ($server['conns'] as $conn):
169
					?>
170 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
171
						<td><?=$conn['common_name'];?></td>
172
						<td><?=$conn['remote_host'];?></td>
173
						<td><?=$conn['virtual_addr'];?></td>
174
						<td><?=$conn['connect_time'];?></td>
175
						<td><?=format_bytes($conn['bytes_sent']);?></td>
176
						<td><?=format_bytes($conn['bytes_recv']);?></td>
177
						<td>
178 9f605c1c Hari
							<a
179 c64a0911 Hari
							   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style="cursor:pointer;"
180
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
181 9f605c1c Hari
							   title="<?php echo gettext("Kill client connection from") . " " . $conn['remote_host']; ?>">
182
							<i class="icon icon-remove"></i>
183
							</a>
184 c64a0911 Hari
						</td>
185
					</tr>
186 9f605c1c Hari
					<?php
187
							endforeach;
188
					?>
189 c64a0911 Hari
				</tbody>
190
				<tfoot>
191
					<tr>
192
						<td>
193
							<table>
194
								<tr>
195
									<td>
196
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
197
										<?= get_service_status_icon($ssvc, true, true); ?>
198
										<?= get_service_control_links($ssvc, true); ?>
199
									</td>
200
								</tr>
201
							</table>
202
						</td>
203
					</tr>
204
				</tfoot>
205
			</table>
206
		</div>
207
</div>
208 42b0c921 Phil Davis
<?php
209
		if (is_array($server['routes']) && count($server['routes'])):
210
?>
211 ec970b50 jim-p
<div id="shroutebut-<?= $i ?>">
212 c64a0911 Hari
	<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.") ?>
213
		<br /><br />
214 ec970b50 jim-p
</div>
215 c64a0911 Hari
<div class="panel panel-default">
216
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
217
		<div class="panel-body table-responsive">
218
			<table class="table table-striped table-hover">
219
				<thead>
220
					<tr>
221
						<th><?=gettext("Common Name"); ?></th>
222
						<th><?=gettext("Real Address"); ?></th>
223
						<th><?=gettext("Target Network"); ?></th>
224
						<th><?=gettext("Last Used"); ?></th>
225
					</tr>
226
				</thead>	
227
				<tbody>
228 ec970b50 jim-p
229 42b0c921 Phil Davis
<?php
230
			foreach ($server['routes'] as $conn):
231
?>
232 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
233
						<td><?=$conn['common_name'];?></td>
234
						<td><?=$conn['remote_host'];?></td>
235
						<td><?=$conn['virtual_addr'];?></td>
236
						<td><?=$conn['last_time'];?></td>
237
					</tr>
238 42b0c921 Phil Davis
<?php
239
			endforeach;
240
?>
241 c64a0911 Hari
				</tbody>
242
				<tfoot>
243
					<tr>
244
						<td><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
245
					</tr>
246
				</tfoot>
247
			</table>
248
		</div>
249
</div>
250 42b0c921 Phil Davis
<?php
251
		endif;
252
?>
253 8cd558b6 ayvis
<br />
254 42b0c921 Phil Davis
<?php
255
		$i++;
256
	endforeach;
257
?>
258 8cd558b6 ayvis
<br />
259 d0f6649c pierrepomes
260 42b0c921 Phil Davis
<?php
261
	if (!empty($sk_servers)) {
262
?>
263 c64a0911 Hari
<div class="panel panel-default">
264
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
265
		<div class="panel-body table-responsive">
266
			<table class="table table-striped table-hover">
267
				<thead>
268
					<tr>  
269
						<th><?=gettext("Name"); ?></th>
270
						<th><?=gettext("Connected Since"); ?></th>
271
						<th><?=gettext("Virtual Addr"); ?></th>
272
						<th><?=gettext("Remote Host"); ?></th>
273
						<th><?=gettext("Bytes Sent"); ?></th>
274
						<th><?=gettext("Bytes Rcvd"); ?></th>
275
						<th><?=gettext("Service"); ?></th>
276
					</tr>
277
				</thead>
278
				<tbody>
279 d0f6649c pierrepomes
280 42b0c921 Phil Davis
<?php
281
		foreach ($sk_servers as $sk_server):
282
?>
283 c64a0911 Hari
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
284
						<td><?=htmlspecialchars($sk_server['name']);?></td>
285
						<td><?=$sk_server['status'];?></td>
286
						<td><?=$sk_server['connect_time'];?></td>
287
						<td><?=$sk_server['virtual_addr'];?></td>
288
						<td><?=$sk_server['remote_host'];?></td>
289
						<td><?=format_bytes($sk_server['bytes_sent']);?></td>
290
						<td><?=format_bytes($sk_server['bytes_recv']);?></td>
291
						<td>
292
							<table>
293
								<tr>
294
									<td>
295
										<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
296
										<?= get_service_status_icon($ssvc, false, true); ?>
297
										<?= get_service_control_links($ssvc, true); ?>
298
									</td>
299
								</tr>
300
							</table>
301
						</td>
302
					</tr>
303 42b0c921 Phil Davis
<?php
304
		endforeach;
305
?>
306 c64a0911 Hari
				</tbody>
307 a5eb046f Renato Botelho
			</table>
308 c64a0911 Hari
		</div>
309
</div>
310 95305736 jim-p
311
<?php
312 42b0c921 Phil Davis
	}
313
?>
314 8cd558b6 ayvis
<br />
315 42b0c921 Phil Davis
<?php
316
	if (!empty($clients)) {
317
?>
318 c64a0911 Hari
<div class="panel panel-default">
319
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
320
		<div class="panel-body table-responsive">
321
			<table class="table table-striped table-hover">
322
				<thead>
323
					<tr>  
324
						<th><?=gettext("Name"); ?></th>
325
						<th><?=gettext("Status"); ?></th>
326
						<th><?=gettext("Connected Since"); ?></th>
327
						<th><?=gettext("Virtual Addr"); ?></th>
328
						<th><?=gettext("Remote Host"); ?></th>
329
						<th><?=gettext("Bytes Sent"); ?></th>
330
						<th><?=gettext("Bytes Rcvd"); ?></th>
331
						<th><?=gettext("Service"); ?></th>
332
					</tr>
333
				</thead>
334
				<tbody>
335 d0f6649c pierrepomes
336 42b0c921 Phil Davis
<?php
337
		foreach ($clients as $client):
338
?>
339 c64a0911 Hari
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
340
						<td><?=htmlspecialchars($client['name']);?></td>
341
						<td><?=$client['status'];?></td>
342
						<td><?=$client['connect_time'];?></td>
343
						<td><?=$client['virtual_addr'];?></td>
344
						<td><?=$client['remote_host'];?></td>
345
						<td><?=format_bytes($client['bytes_sent']);?></td>
346
						<td><?=format_bytes($client['bytes_recv']);?></td>
347
						<td>
348
							<table>
349
								<tr>
350
									<td>
351
										<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
352
										<?= get_service_status_icon($ssvc, false, true); ?>
353
										<?= get_service_control_links($ssvc, true); ?>
354
									</td>
355
								</tr>
356
							</table>
357
						</td>
358
					</tr>
359 42b0c921 Phil Davis
<?php
360
		endforeach;
361
?>
362 c64a0911 Hari
				</tbody>
363 a5eb046f Renato Botelho
			</table>
364 c64a0911 Hari
		</div>
365
</div>
366 d0f6649c pierrepomes
367 cf1ced6d pierrepomes
<?php 
368
}
369
370
if ($DisplayNote) {
371 9f605c1c Hari
 	print_info_box(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."));
372 d0f6649c pierrepomes
}
373
374 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
375 c64a0911 Hari
	print_info_box(gettext("No OpenVPN instances defined"));
376 d0f6649c pierrepomes
}
377
?>
378 2a351d32 Colin Fleming
</form>
379 63084885 Matthew Grooms
<?php include("fend.inc"); ?>
380 ec970b50 jim-p
<script type="text/javascript">
381 4d33138f Colin Fleming
//<![CDATA[
382 ec970b50 jim-p
function show_routes(id, buttonid) {
383
	document.getElementById(buttonid).innerHTML='';
384
	aodiv = document.getElementById(id);
385
	aodiv.style.display = "block";
386
}
387 4d33138f Colin Fleming
//]]>
388 ec970b50 jim-p
</script>
389 4d33138f Colin Fleming
</body>
390
</html>