Project

General

Profile

Download (11.8 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-2021 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><?=gettext("Cipher")?></th>
112
						<th><!-- Icons --></th>
113
					</tr>
114
				</thead>
115
				<tbody>
116

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

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

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

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

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

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

    
367
<?php
368
}
369

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

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

    
380
<script type="text/javascript">
381
//<![CDATA[
382

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

    
389
//]]>
390
</script>
391

    
392
<?php include("foot.inc"); ?>
(178-178/227)