Project

General

Profile

Download (11.5 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 = openvpn_kill_client($port, $remipp);
79
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
80
		} else {
81
			echo gettext("invalid input");
82
		}
83
		exit;
84
	}
85
}
86

    
87
$servers = openvpn_get_active_servers();
88
$sk_servers = openvpn_get_active_servers("p2p");
89
$clients = openvpn_get_active_clients();
90

    
91
include("head.inc"); ?>
92

    
93
<body>
94
<form action="status_openvpn.php" method="get" name="iform">
95
<script type="text/javascript">
96
//<![CDATA[
97
	function killClient(mport, remipp) {
98
		var busy = function(index,icon) {
99
			jQuery(icon).bind("onclick","");
100
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
101
			jQuery(icon).css("cursor","wait");
102
		}
103

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

    
106
		jQuery.ajax(
107
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
108
				"?action=kill&port=" + mport + "&remipp=" + remipp,
109
			{ type: "get", complete: killComplete }
110
		);
111
	}
112

    
113
	function killComplete(req) {
114
		var values = req.responseText.split("|");
115
		if (values[3] != "0") {
116
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
117
			return;
118
		}
119

    
120
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
121
			function(index,row) { jQuery(row).fadeOut(1000); }
122
		);
123
	}
124
//]]>
125
</script>
126

    
127
<?php
128
	$i = 0;
129
	foreach ($servers as $server):
130
?>
131

    
132
<div class="panel panel-default">
133
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client connections')?></h2></div>
134
		<div class="panel-body table-responsive">
135
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
136
				<thead>
137
					<tr>
138
						<th><?=gettext("Common Name")?></th>
139
						<th><?=gettext("Real Address")?></th>
140
						<th><?=gettext("Virtual Address"); ?></th>
141
						<th><?=gettext("Connected Since"); ?></th>
142
						<th><?=gettext("Bytes Sent")?></th>
143
						<th><?=gettext("Bytes Received")?></th>
144
						<th><!-- Icons --></th>
145
					</tr>
146
				</thead>
147
				<tbody>
148

    
149
					<?php
150
							foreach ($server['conns'] as $conn):
151
					?>
152
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
153
						<td><?=$conn['common_name'];?></td>
154
						<td><?=$conn['remote_host'];?></td>
155
						<td><?=$conn['virtual_addr'];?></td>
156
						<td><?=$conn['connect_time'];?></td>
157
						<td><?=format_bytes($conn['bytes_sent']);?></td>
158
						<td><?=format_bytes($conn['bytes_recv']);?></td>
159
						<td>
160
							<a
161
							   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style="cursor:pointer;"
162
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
163
							   title="<?php echo gettext("Kill client connection from") . " " . $conn['remote_host']; ?>">
164
							<i class="fa fa-times"></i>
165
							</a>
166
						</td>
167
					</tr>
168
					<?php
169
							endforeach;
170
					?>
171
				</tbody>
172
				<tfoot>
173
					<tr>
174
						<td colspan="2">
175
							<table>
176
								<tr>
177
									<td>
178
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
179
										<?= get_service_status_icon($ssvc, true, true); ?>
180
										<?= get_service_control_GET_links($ssvc, true); ?>
181
									</td>
182
								</tr>
183
							</table>
184
						</td>
185
						<td colspan="5">
186
						</td>
187
					</tr>
188
				</tfoot>
189
			</table>
190
		</div>
191
</div>
192
<?php
193
		if (is_array($server['routes']) && count($server['routes'])):
194
?>
195
<div id="shroutebut-<?= $i ?>">
196
	<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.") ?>
197
		<br /><br />
198
</div>
199
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
200
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
201
		<div class="panel-body table-responsive">
202
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
203
				<thead>
204
					<tr>
205
						<th><?=gettext("Common Name"); ?></th>
206
						<th><?=gettext("Real Address"); ?></th>
207
						<th><?=gettext("Target Network"); ?></th>
208
						<th><?=gettext("Last Used"); ?></th>
209
					</tr>
210
				</thead>
211
				<tbody>
212

    
213
<?php
214
			foreach ($server['routes'] as $conn):
215
?>
216
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
217
						<td><?=$conn['common_name'];?></td>
218
						<td><?=$conn['remote_host'];?></td>
219
						<td><?=$conn['virtual_addr'];?></td>
220
						<td><?=$conn['last_time'];?></td>
221
					</tr>
222
<?php
223
			endforeach;
224
?>
225
				</tbody>
226
				<tfoot>
227
					<tr>
228
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
229
					</tr>
230
				</tfoot>
231
			</table>
232
		</div>
233
</div>
234
<?php
235
		endif;
236
?>
237
<br />
238
<?php
239
		$i++;
240
	endforeach;
241
?>
242
<br />
243

    
244
<?php
245
	if (!empty($sk_servers)) {
246
?>
247
<div class="panel panel-default">
248
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
249
		<div class="panel-body table-responsive">
250
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
251
				<thead>
252
					<tr>
253
						<th><?=gettext("Name"); ?></th>
254
						<th><?=gettext("Status"); ?></th>
255
						<th><?=gettext("Connected Since"); ?></th>
256
						<th><?=gettext("Virtual Addr"); ?></th>
257
						<th><?=gettext("Remote Host"); ?></th>
258
						<th><?=gettext("Bytes Sent"); ?></th>
259
						<th><?=gettext("Bytes Rcvd"); ?></th>
260
						<th><?=gettext("Service"); ?></th>
261
					</tr>
262
				</thead>
263
				<tbody>
264

    
265
<?php
266
		foreach ($sk_servers as $sk_server):
267
?>
268
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
269
						<td><?=htmlspecialchars($sk_server['name']);?></td>
270
						<td><?=$sk_server['status'];?></td>
271
						<td><?=$sk_server['connect_time'];?></td>
272
						<td><?=$sk_server['virtual_addr'];?></td>
273
						<td><?=$sk_server['remote_host'];?></td>
274
						<td><?=format_bytes($sk_server['bytes_sent']);?></td>
275
						<td><?=format_bytes($sk_server['bytes_recv']);?></td>
276
						<td>
277
							<table>
278
								<tr>
279
									<td>
280
										<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
281
										<?= get_service_status_icon($ssvc, false, true); ?>
282
										<?= get_service_control_GET_links($ssvc, true); ?>
283
									</td>
284
								</tr>
285
							</table>
286
						</td>
287
					</tr>
288
<?php
289
		endforeach;
290
?>
291
				</tbody>
292
			</table>
293
		</div>
294
</div>
295

    
296
<?php
297
	}
298
?>
299
<br />
300
<?php
301
	if (!empty($clients)) {
302
?>
303
<div class="panel panel-default">
304
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
305
		<div class="panel-body table-responsive">
306
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
307
				<thead>
308
					<tr>
309
						<th><?=gettext("Name"); ?></th>
310
						<th><?=gettext("Status"); ?></th>
311
						<th><?=gettext("Connected Since"); ?></th>
312
						<th><?=gettext("Virtual Addr"); ?></th>
313
						<th><?=gettext("Remote Host"); ?></th>
314
						<th><?=gettext("Bytes Sent"); ?></th>
315
						<th><?=gettext("Bytes Rcvd"); ?></th>
316
						<th><?=gettext("Service"); ?></th>
317
					</tr>
318
				</thead>
319
				<tbody>
320

    
321
<?php
322
		foreach ($clients as $client):
323
?>
324
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
325
						<td><?=htmlspecialchars($client['name']);?></td>
326
						<td><?=$client['status'];?></td>
327
						<td><?=$client['connect_time'];?></td>
328
						<td><?=$client['virtual_addr'];?></td>
329
						<td><?=$client['remote_host'];?></td>
330
						<td><?=format_bytes($client['bytes_sent']);?></td>
331
						<td><?=format_bytes($client['bytes_recv']);?></td>
332
						<td>
333
							<table>
334
								<tr>
335
									<td>
336
										<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
337
										<?= get_service_status_icon($ssvc, false, true); ?>
338
										<?= get_service_control_GET_links($ssvc, true); ?>
339
									</td>
340
								</tr>
341
							</table>
342
						</td>
343
					</tr>
344
<?php
345
		endforeach;
346
?>
347
				</tbody>
348
			</table>
349
		</div>
350
	</div>
351

    
352
<?php
353
}
354

    
355
if ($DisplayNote) {
356
 	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."));
357
}
358

    
359
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
360
	print_info_box(gettext("No OpenVPN instances defined"));
361
}
362
?>
363
</form>
364

    
365
<?php include("foot.inc"); ?>
366

    
367
<script type="text/javascript">
368
//<![CDATA[
369

    
370
function show_routes(id, buttonid) {
371
	document.getElementById(buttonid).innerHTML='';
372
	aodiv = document.getElementById(id);
373
	aodiv.style.display = "block";
374
}
375

    
376
//]]>
377
</script>
(178-178/229)