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
##|+PRIV
58
##|*IDENT=page-status-openvpn
59
##|*NAME=Status: OpenVPN
60
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
61
##|*MATCH=status_openvpn.php*
62
##|-PRIV
63

    
64
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
65
$shortcut_section = "openvpn";
66

    
67
require("guiconfig.inc");
68
require_once("openvpn.inc");
69
require_once("shortcuts.inc");
70
require_once("service-utils.inc");
71

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

    
87

    
88
function kill_client($port, $remipp) {
89
	global $g;
90

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

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

    
105
			$info = stream_get_meta_data($fp);
106
			if ($info['timed_out']) {
107
				break;
108
			}
109

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

    
124
$servers = openvpn_get_active_servers();
125
$sk_servers = openvpn_get_active_servers("p2p");
126
$clients = openvpn_get_active_clients();
127

    
128
include("head.inc"); ?>
129

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

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

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

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

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

    
164
<?php
165
	$i = 0;
166
	foreach ($servers as $server):
167
?>
168

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

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

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

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

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

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

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

    
386
<?php
387
}
388

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

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