Project

General

Profile

Download (11.7 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-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2008 Shrew Soft Inc.
10
 * All rights reserved.
11
 *
12
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15
 *
16
 * http://www.apache.org/licenses/LICENSE-2.0
17
 *
18
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23
 */
24

    
25
##|+PRIV
26
##|*IDENT=page-status-openvpn
27
##|*NAME=Status: OpenVPN
28
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
29
##|*MATCH=status_openvpn.php*
30
##|-PRIV
31

    
32
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
33
$shortcut_section = "openvpn";
34

    
35
require_once("guiconfig.inc");
36
require_once("openvpn.inc");
37
require_once("shortcuts.inc");
38
require_once("service-utils.inc");
39

    
40
/* Handle AJAX */
41
if ($_REQUEST['action']) {
42
	if ($_REQUEST['action'] == "kill") {
43
		$port  = $_REQUEST['port'];
44
		$remipp  = $_REQUEST['remipp'];
45
		if (!empty($port) and !empty($remipp)) {
46
			$retval = openvpn_kill_client($port, $remipp);
47
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
48
		} else {
49
			echo gettext("invalid input");
50
		}
51
		exit;
52
	}
53
}
54

    
55
$servers = openvpn_get_active_servers();
56
$sk_servers = openvpn_get_active_servers("p2p");
57
$clients = openvpn_get_active_clients();
58

    
59
include("head.inc"); ?>
60

    
61
<form action="status_openvpn.php" method="get" name="iform">
62
<script type="text/javascript">
63
//<![CDATA[
64
	function killClient(mport, remipp) {
65
		var busy = function(index,icon) {
66
			$(icon).bind("onclick","");
67
			$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
68
			$(icon).css("cursor","wait");
69
		}
70

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

    
73
		$.ajax(
74
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
75
				"?action=kill&port=" + mport + "&remipp=" + remipp,
76
			{ type: "get", complete: killComplete }
77
		);
78
	}
79

    
80
	function killComplete(req) {
81
		var values = req.responseText.split("|");
82
		if (values[3] != "0") {
83
	//		alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
84
			return;
85
		}
86

    
87
		$('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
88
			function(index,row) { $(row).fadeOut(1000); }
89
		);
90
	}
91
//]]>
92
</script>
93

    
94
<?php
95
	$i = 0;
96
	foreach ($servers as $server):
97
?>
98

    
99
<div class="panel panel-default">
100
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client Connections') . ": " . ($server['conns'][0]['common_name'] != '[error]' ? sizeof($server['conns']) : '0');?></h2></div>
101
		<div class="panel-body table-responsive">
102
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
103
				<thead>
104
					<tr>
105
						<th><?=gettext("Common Name")?></th>
106
						<th><?=gettext("Real Address")?></th>
107
						<th><?=gettext("Virtual Address"); ?></th>
108
						<th><?=gettext("Connected Since"); ?></th>
109
						<th><?=gettext("Bytes Sent")?></th>
110
						<th><?=gettext("Bytes Received")?></th>
111
						<th><!-- Icons --></th>
112
					</tr>
113
				</thead>
114
				<tbody>
115

    
116
					<?php
117
							foreach ($server['conns'] as $conn):
118
					?>
119
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
120
						<td>
121
							<?=$conn['common_name'];?>
122
					<?php if (!empty($conn['common_name']) && !empty($conn['user_name']) && ($conn['user_name'] != "UNDEF")): ?>
123
							<br />
124
					<?php endif; ?>
125
					<?php if (!empty($conn['user_name']) && ($conn['user_name'] != "UNDEF")): ?>
126
							<?=$conn['user_name'];?>
127
					<?php endif; ?>
128
						</td>
129
						<td><?=$conn['remote_host'];?></td>
130
						<td>
131
							<?=$conn['virtual_addr'];?>
132
					<?php if (!empty($conn['virtual_addr']) && !empty($conn['virtual_addr6'])): ?>
133
							<br />
134
					<?php endif; ?>
135
							<?=$conn['virtual_addr6'];?>
136
						</td>
137
						<td><?=$conn['connect_time'];?></td>
138
						<td data-value="<?=trim($conn['bytes_sent'])?>"><?=format_bytes($conn['bytes_sent']);?></td>
139
						<td data-value="<?=trim($conn['bytes_recv'])?>"><?=format_bytes($conn['bytes_recv']);?></td>
140
						<td>
141
							<a
142
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>');" style="cursor:pointer;"
143
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
144
							   title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
145
							<i class="fa fa-times"></i>
146
							</a>
147
						</td>
148
					</tr>
149
					<?php
150
							endforeach;
151
					?>
152
				</tbody>
153
				<tfoot>
154
					<tr>
155
						<td colspan="2">
156
							<table>
157
								<tr>
158
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
159
									<td>
160
										<?= gettext("Status") . ": " . get_service_status_icon($ssvc, false, true, false, "service_state"); ?>
161
									</td>
162
									<td>
163
										<?= gettext("Actions") . ": " . get_service_control_links($ssvc); ?>
164
									</td>
165
								</tr>
166
							</table>
167
						</td>
168
						<td colspan="5">
169
						</td>
170
					</tr>
171
				</tfoot>
172
			</table>
173
		</div>
174
</div>
175
<?php
176
		if (is_array($server['routes']) && count($server['routes'])):
177
?>
178
<div id="shroutebut-<?= $i ?>">
179
	<button type="button" class="btn btn-info" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>">
180
		<i class="fa fa-plus-circle icon-embed-btn"></i>
181
		<?php echo gettext("Show Routing Table"); ?>
182
	</button>
183
	- <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
184
	<br /><br />
185
</div>
186
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
187
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
188
		<div class="panel-body table-responsive">
189
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
190
				<thead>
191
					<tr>
192
						<th><?=gettext("Common Name"); ?></th>
193
						<th><?=gettext("Real Address"); ?></th>
194
						<th><?=gettext("Target Network"); ?></th>
195
						<th><?=gettext("Last Used"); ?></th>
196
					</tr>
197
				</thead>
198
				<tbody>
199

    
200
<?php
201
			foreach ($server['routes'] as $conn):
202
?>
203
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
204
						<td><?=$conn['common_name'];?></td>
205
						<td><?=$conn['remote_host'];?></td>
206
						<td><?=$conn['virtual_addr'];?></td>
207
						<td><?=$conn['last_time'];?></td>
208
					</tr>
209
<?php
210
			endforeach;
211
?>
212
				</tbody>
213
				<tfoot>
214
					<tr>
215
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
216
					</tr>
217
				</tfoot>
218
			</table>
219
		</div>
220
</div>
221
<?php
222
		endif;
223
?>
224
<br />
225
<?php
226
		$i++;
227
	endforeach;
228
?>
229
<br />
230

    
231
<?php
232
	if (!empty($sk_servers)) {
233
?>
234
<div class="panel panel-default">
235
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></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("Name"); ?></th>
241
						<th><?=gettext("Status"); ?></th>
242
						<th><?=gettext("Connected Since"); ?></th>
243
						<th><?=gettext("Virtual Address"); ?></th>
244
						<th><?=gettext("Remote Host"); ?></th>
245
						<th><?=gettext("Bytes Sent"); ?></th>
246
						<th><?=gettext("Bytes Received"); ?></th>
247
						<th><?=gettext("Service"); ?></th>
248
					</tr>
249
				</thead>
250
				<tbody>
251

    
252
<?php
253
		foreach ($sk_servers as $sk_server):
254
?>
255
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
256
						<td><?=htmlspecialchars($sk_server['name']);?></td>
257
						<td><?=$sk_server['status'];?></td>
258
						<td><?=$sk_server['connect_time'];?></td>
259
						<td>
260
							<?=$sk_server['virtual_addr'];?>
261
					<?php if (!empty($sk_server['virtual_addr']) && !empty($sk_server['virtual_addr6'])): ?>
262
							<br />
263
					<?php endif; ?>
264
							<?=$sk_server['virtual_addr6'];?>
265
						</td>
266
						<td><?=$sk_server['remote_host'];?></td>
267
						<td data-value="<?=trim($sk_server['bytes_sent'])?>"><?=format_bytes($sk_server['bytes_sent']);?></td>
268
						<td data-value="<?=trim($sk_server['bytes_recv'])?>"><?=format_bytes($sk_server['bytes_recv']);?></td>
269
						<td>
270
							<table>
271
								<tr>
272
									<td>
273
										<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
274
										<?= get_service_status_icon($ssvc, false, true); ?>
275
										<?= get_service_control_links($ssvc, true); ?>
276
									</td>
277
								</tr>
278
							</table>
279
						</td>
280
					</tr>
281
<?php
282
		endforeach;
283
?>
284
				</tbody>
285
			</table>
286
		</div>
287
</div>
288

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

    
315
<?php
316
		foreach ($clients as $client):
317
?>
318
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
319
						<td><?=htmlspecialchars($client['name']);?></td>
320
						<td><?=$client['status'];?></td>
321
						<td><?=$client['connect_time'];?></td>
322
						<td>
323
					<?php if (empty($client['local_host']) && empty($client['local_port'])): ?>
324
							(pending)
325
					<?php else: ?>
326
							<?=$client['local_host'];?>:<?=$client['local_port'];?>
327
					<?php endif; ?>
328
						</td>
329
						<td>
330
							<?=$client['virtual_addr'];?>
331
					<?php if (!empty($client['virtual_addr']) && !empty($client['virtual_addr6'])): ?>
332
							<br />
333
					<?php endif; ?>
334
							<?=$client['virtual_addr6'];?>
335
						</td>
336
						<td>
337
					<?php if (empty($client['remote_host']) && empty($client['remote_port'])): ?>
338
							(pending)
339
					<?php else: ?>
340
							<?=$client['remote_host'];?>:<?=$client['remote_port'];?>
341
					<?php endif; ?>
342
						</td>
343
						<td data-value="<?=trim($client['bytes_sent'])?>"><?=format_bytes($client['bytes_sent']);?></td>
344
						<td data-value="<?=trim($client['bytes_recv'])?>"><?=format_bytes($client['bytes_recv']);?></td>
345
						<td>
346
							<table>
347
								<tr>
348
									<td>
349
										<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
350
										<?= get_service_status_icon($ssvc, false, true); ?>
351
										<?= get_service_control_links($ssvc, true); ?>
352
									</td>
353
								</tr>
354
							</table>
355
						</td>
356
					</tr>
357
<?php
358
		endforeach;
359
?>
360
				</tbody>
361
			</table>
362
		</div>
363
	</div>
364

    
365
<?php
366
}
367

    
368
if ($DisplayNote) {
369
 	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."));
370
}
371

    
372
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
373
	print_info_box(gettext("No OpenVPN instances defined."));
374
}
375
?>
376
</form>
377

    
378
<script type="text/javascript">
379
//<![CDATA[
380

    
381
function show_routes(id, buttonid) {
382
	document.getElementById(buttonid).innerHTML='';
383
	aodiv = document.getElementById(id);
384
	aodiv.style.display = "block";
385
}
386

    
387
//]]>
388
</script>
389

    
390
<?php include("foot.inc"); ?>
(180-180/229)