Project

General

Profile

Download (11.1 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-2019 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')?></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/Received")?></th>
110
						<th><!-- Icons --></th>
111
					</tr>
112
				</thead>
113
				<tbody>
114

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

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

    
229
<?php
230
	if (!empty($sk_servers)) {
231
?>
232
<div class="panel panel-default">
233
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
234
		<div class="panel-body table-responsive">
235
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
236
				<thead>
237
					<tr>
238
						<th><?=gettext("Name"); ?></th>
239
						<th><?=gettext("Status"); ?></th>
240
						<th><?=gettext("Connected Since"); ?></th>
241
						<th><?=gettext("Virtual Address"); ?></th>
242
						<th><?=gettext("Remote Host"); ?></th>
243
						<th><?=gettext("Bytes Sent / Received"); ?></th>
244
						<th><?=gettext("Service"); ?></th>
245
					</tr>
246
				</thead>
247
				<tbody>
248

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

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

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

    
359
<?php
360
}
361

    
362
if ($DisplayNote) {
363
 	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."));
364
}
365

    
366
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
367
	print_info_box(gettext("No OpenVPN instances defined."));
368
}
369
?>
370
</form>
371

    
372
<script type="text/javascript">
373
//<![CDATA[
374

    
375
function show_routes(id, buttonid) {
376
	document.getElementById(buttonid).innerHTML='';
377
	aodiv = document.getElementById(id);
378
	aodiv.style.display = "block";
379
}
380

    
381
//]]>
382
</script>
383

    
384
<?php include("foot.inc"); ?>
(177-177/225)