Project

General

Profile

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

    
55
##|+PRIV
56
##|*IDENT=page-status-openvpn
57
##|*NAME=Status: OpenVPN
58
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
59
##|*MATCH=status_openvpn.php*
60
##|-PRIV
61

    
62
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
63
$shortcut_section = "openvpn";
64

    
65
require_once("guiconfig.inc");
66
require_once("openvpn.inc");
67
require_once("shortcuts.inc");
68
require_once("service-utils.inc");
69

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

    
85
$servers = openvpn_get_active_servers();
86
$sk_servers = openvpn_get_active_servers("p2p");
87
$clients = openvpn_get_active_clients();
88

    
89
include("head.inc"); ?>
90

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

    
101
		$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
102

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

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

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

    
124
<?php
125
	$i = 0;
126
	foreach ($servers as $server):
127
?>
128

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

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

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

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

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

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

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

    
353
<?php
354
}
355

    
356
if ($DisplayNote) {
357
 	print_info_box(gettext("If there are 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."));
358
}
359

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

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

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

    
375
//]]>
376
</script>
377

    
378
<?php include("foot.inc"); ?>
(178-178/225)