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
					</tr>
185
				</thead>
186
				<tbody>
187

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

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

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

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

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

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

    
388
<?php
389
}
390

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

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