Project

General

Profile

Download (12.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_openvpn.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *	Copyright (c)  2008 Shrew Soft Inc.
8
 *
9
 *	Redistribution and use in source and binary forms, with or without modification,
10
 *	are permitted provided that the following conditions are met:
11
 *
12
 *	1. Redistributions of source code must retain the above copyright notice,
13
 *		this list of conditions and the following disclaimer.
14
 *
15
 *	2. Redistributions in binary form must reproduce the above copyright
16
 *		notice, this list of conditions and the following disclaimer in
17
 *		the documentation and/or other materials provided with the
18
 *		distribution.
19
 *
20
 *	3. All advertising materials mentioning features or use of this software
21
 *		must display the following acknowledgment:
22
 *		"This product includes software developed by the pfSense Project
23
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
24
 *
25
 *	4. The names "pfSense" and "pfSense Project" must not be used to
26
 *		 endorse or promote products derived from this software without
27
 *		 prior written permission. For written permission, please contact
28
 *		 coreteam@pfsense.org.
29
 *
30
 *	5. Products derived from this software may not be called "pfSense"
31
 *		nor may "pfSense" appear in their names without prior written
32
 *		permission of the Electric Sheep Fencing, LLC.
33
 *
34
 *	6. Redistributions of any form whatsoever must retain the following
35
 *		acknowledgment:
36
 *
37
 *	"This product includes software developed by the pfSense Project
38
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
39
 *
40
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
41
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
44
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
52
 *
53
 *	====================================================================
54
 *
55
 */
56
/*
57
	pfSense_MODULE:	openvpn
58
*/
59

    
60
##|+PRIV
61
##|*IDENT=page-status-openvpn
62
##|*NAME=Status: OpenVPN
63
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
64
##|*MATCH=status_openvpn.php*
65
##|-PRIV
66

    
67
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
68
$shortcut_section = "openvpn";
69

    
70
require("guiconfig.inc");
71
require_once("openvpn.inc");
72
require_once("shortcuts.inc");
73
require_once("service-utils.inc");
74

    
75
/* Handle AJAX */
76
if($_GET['action']) {
77
	if($_GET['action'] == "kill") {
78
		$port  = $_GET['port'];
79
		$remipp  = $_GET['remipp'];
80
		if (!empty($port) and !empty($remipp)) {
81
			$retval = kill_client($port, $remipp);
82
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
83
		} else {
84
			echo gettext("invalid input");
85
		}
86
		exit;
87
	}
88
}
89

    
90

    
91
function kill_client($port, $remipp) {
92
	global $g;
93

    
94
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
95
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
96
	$errval = null;
97
	$errstr = null;
98

    
99
	/* open a tcp connection to the management port of each server */
100
	$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
101
	$killed = -1;
102
	if ($fp) {
103
		stream_set_timeout($fp, 1);
104
		fputs($fp, "kill {$remipp}\n");
105
		while (!feof($fp)) {
106
			$line = fgets($fp, 1024);
107

    
108
			$info = stream_get_meta_data($fp);
109
			if ($info['timed_out']) {
110
				break;
111
			}
112

    
113
			/* parse header list line */
114
			if (strpos($line, "INFO:") !== false) {
115
				continue;
116
			}
117
			if (strpos($line, "SUCCESS") !== false) {
118
				$killed = 0;
119
			}
120
			break;
121
		}
122
		fclose($fp);
123
	}
124
	return $killed;
125
}
126

    
127
$servers = openvpn_get_active_servers();
128
$sk_servers = openvpn_get_active_servers("p2p");
129
$clients = openvpn_get_active_clients();
130

    
131
include("head.inc"); ?>
132

    
133
<body>
134
<form action="status_openvpn.php" method="get" name="iform">
135
<script type="text/javascript">
136
//<![CDATA[
137
	function killClient(mport, remipp) {
138
		var busy = function(index,icon) {
139
			jQuery(icon).bind("onclick","");
140
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
141
			jQuery(icon).css("cursor","wait");
142
		}
143

    
144
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
145

    
146
		jQuery.ajax(
147
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
148
				"?action=kill&port=" + mport + "&remipp=" + remipp,
149
			{ type: "get", complete: killComplete }
150
		);
151
	}
152

    
153
	function killComplete(req) {
154
		var values = req.responseText.split("|");
155
		if(values[3] != "0") {
156
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
157
			return;
158
		}
159

    
160
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
161
			function(index,row) { jQuery(row).fadeOut(1000); }
162
		);
163
	}
164
//]]>
165
</script>
166

    
167
<?php
168
	$i = 0;
169
	foreach ($servers as $server):
170
?>
171

    
172
<div class="panel panel-default">
173
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client connections')?></h2></div>
174
		<div class="panel-body table-responsive">
175
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
176
				<thead>
177
					<tr>
178
						<th><?=gettext("Common Name")?></th>
179
						<th><?=gettext("Real Address")?></th>
180
						<th><?=gettext("Virtual Address"); ?></th>
181
						<th><?=gettext("Connected Since"); ?></th>
182
						<th><?=gettext("Bytes Sent")?></th>
183
						<th><?=gettext("Bytes Received")?></th>
184
						<th><!-- Icons --></th>
185
					</tr>
186
				</thead>
187
				<tbody>
188

    
189
					<?php
190
							foreach ($server['conns'] as $conn):
191
					?>
192
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
193
						<td><?=$conn['common_name'];?></td>
194
						<td><?=$conn['remote_host'];?></td>
195
						<td><?=$conn['virtual_addr'];?></td>
196
						<td><?=$conn['connect_time'];?></td>
197
						<td><?=format_bytes($conn['bytes_sent']);?></td>
198
						<td><?=format_bytes($conn['bytes_recv']);?></td>
199
						<td>
200
							<a
201
							   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style="cursor:pointer;"
202
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
203
							   title="<?php echo gettext("Kill client connection from") . " " . $conn['remote_host']; ?>">
204
							<i class="fa fa-times"></i>
205
							</a>
206
						</td>
207
					</tr>
208
					<?php
209
							endforeach;
210
					?>
211
				</tbody>
212
				<tfoot>
213
					<tr>
214
						<td>
215
							<table>
216
								<tr>
217
									<td>
218
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
219
										<?= get_service_status_icon($ssvc, true, true); ?>
220
										<?= get_service_control_GET_links($ssvc, true); ?>
221
									</td>
222
								</tr>
223
							</table>
224
						</td>
225
					</tr>
226
				</tfoot>
227
			</table>
228
		</div>
229
</div>
230
<?php
231
		if (is_array($server['routes']) && count($server['routes'])):
232
?>
233
<div id="shroutebut-<?= $i ?>">
234
	<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.") ?>
235
		<br /><br />
236
</div>
237
<div class="panel panel-default">
238
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
239
		<div class="panel-body table-responsive">
240
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
241
				<thead>
242
					<tr>
243
						<th><?=gettext("Common Name"); ?></th>
244
						<th><?=gettext("Real Address"); ?></th>
245
						<th><?=gettext("Target Network"); ?></th>
246
						<th><?=gettext("Last Used"); ?></th>
247
					</tr>
248
				</thead>
249
				<tbody>
250

    
251
<?php
252
			foreach ($server['routes'] as $conn):
253
?>
254
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
255
						<td><?=$conn['common_name'];?></td>
256
						<td><?=$conn['remote_host'];?></td>
257
						<td><?=$conn['virtual_addr'];?></td>
258
						<td><?=$conn['last_time'];?></td>
259
					</tr>
260
<?php
261
			endforeach;
262
?>
263
				</tbody>
264
				<tfoot>
265
					<tr>
266
						<td><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
267
					</tr>
268
				</tfoot>
269
			</table>
270
		</div>
271
</div>
272
<?php
273
		endif;
274
?>
275
<br />
276
<?php
277
		$i++;
278
	endforeach;
279
?>
280
<br />
281

    
282
<?php
283
	if (!empty($sk_servers)) {
284
?>
285
<div class="panel panel-default">
286
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
287
		<div class="panel-body table-responsive">
288
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
289
				<thead>
290
					<tr>
291
						<th><?=gettext("Name"); ?></th>
292
						<th><?=gettext("Connected Since"); ?></th>
293
						<th><?=gettext("Virtual Addr"); ?></th>
294
						<th><?=gettext("Remote Host"); ?></th>
295
						<th><?=gettext("Bytes Sent"); ?></th>
296
						<th><?=gettext("Bytes Rcvd"); ?></th>
297
						<th><?=gettext("Service"); ?></th>
298
					</tr>
299
				</thead>
300
				<tbody>
301

    
302
<?php
303
		foreach ($sk_servers as $sk_server):
304
?>
305
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
306
						<td><?=htmlspecialchars($sk_server['name']);?></td>
307
						<td><?=$sk_server['status'];?></td>
308
						<td><?=$sk_server['connect_time'];?></td>
309
						<td><?=$sk_server['virtual_addr'];?></td>
310
						<td><?=$sk_server['remote_host'];?></td>
311
						<td><?=format_bytes($sk_server['bytes_sent']);?></td>
312
						<td><?=format_bytes($sk_server['bytes_recv']);?></td>
313
						<td>
314
							<table>
315
								<tr>
316
									<td>
317
										<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
318
										<?= get_service_status_icon($ssvc, false, true); ?>
319
										<?= get_service_control_GET_links($ssvc, true); ?>
320
									</td>
321
								</tr>
322
							</table>
323
						</td>
324
					</tr>
325
<?php
326
		endforeach;
327
?>
328
				</tbody>
329
			</table>
330
		</div>
331
</div>
332

    
333
<?php
334
	}
335
?>
336
<br />
337
<?php
338
	if (!empty($clients)) {
339
?>
340
<div class="panel panel-default">
341
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
342
		<div class="panel-body table-responsive">
343
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
344
				<thead>
345
					<tr>
346
						<th><?=gettext("Name"); ?></th>
347
						<th><?=gettext("Status"); ?></th>
348
						<th><?=gettext("Connected Since"); ?></th>
349
						<th><?=gettext("Virtual Addr"); ?></th>
350
						<th><?=gettext("Remote Host"); ?></th>
351
						<th><?=gettext("Bytes Sent"); ?></th>
352
						<th><?=gettext("Bytes Rcvd"); ?></th>
353
						<th><?=gettext("Service"); ?></th>
354
					</tr>
355
				</thead>
356
				<tbody>
357

    
358
<?php
359
		foreach ($clients as $client):
360
?>
361
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
362
						<td><?=htmlspecialchars($client['name']);?></td>
363
						<td><?=$client['status'];?></td>
364
						<td><?=$client['connect_time'];?></td>
365
						<td><?=$client['virtual_addr'];?></td>
366
						<td><?=$client['remote_host'];?></td>
367
						<td><?=format_bytes($client['bytes_sent']);?></td>
368
						<td><?=format_bytes($client['bytes_recv']);?></td>
369
						<td>
370
							<table>
371
								<tr>
372
									<td>
373
										<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
374
										<?= get_service_status_icon($ssvc, false, true); ?>
375
										<?= get_service_control_GET_links($ssvc, true); ?>
376
									</td>
377
								</tr>
378
							</table>
379
						</td>
380
					</tr>
381
<?php
382
		endforeach;
383
?>
384
				</tbody>
385
			</table>
386
		</div>
387
</div>
388

    
389
<?php
390
}
391

    
392
if ($DisplayNote) {
393
 	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."));
394
}
395

    
396
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
397
	print_info_box(gettext("No OpenVPN instances defined"));
398
}
399
?>
400
</form>
401
<?php include("foot.inc"); ?>
402
<script type="text/javascript">
403
//<![CDATA[
404
function show_routes(id, buttonid) {
405
	document.getElementById(buttonid).innerHTML='';
406
	aodiv = document.getElementById(id);
407
	aodiv.style.display = "block";
408
}
409
//]]>
410
</script>
411
</body>
412
</html>
(177-177/228)