Project

General

Profile

Download (11.8 KB) Statistics
| Branch: | Tag: | Revision:
1 0927fb8c jim-p
<?php
2 63084885 Matthew Grooms
/*
3 c5d81585 Renato Botelho
 * status_openvpn.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 8f585441 Luiz Souza
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * Copyright (c) 2008 Shrew Soft Inc.
10
 * All rights reserved.
11
 *
12 b12ea3fb Renato Botelho
 * 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 c5d81585 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
17 c5d81585 Renato Botelho
 *
18 b12ea3fb Renato Botelho
 * 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 b9043cdc Stephen Beaver
 */
24 63084885 Matthew Grooms
25
##|+PRIV
26
##|*IDENT=page-status-openvpn
27 5230f468 jim-p
##|*NAME=Status: OpenVPN
28 63084885 Matthew Grooms
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
29
##|*MATCH=status_openvpn.php*
30
##|-PRIV
31
32 e9d35ff5 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
33 7d7b5a48 jim-p
$shortcut_section = "openvpn";
34
35 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
36 53663f57 jim-p
require_once("openvpn.inc");
37 2eaa97b9 jim-p
require_once("shortcuts.inc");
38 c92ccc70 Renato Botelho
require_once("service-utils.inc");
39 63084885 Matthew Grooms
40 0927fb8c jim-p
/* Handle AJAX */
41 1a8b6554 Steve Beaver
if ($_REQUEST['action']) {
42
	if ($_REQUEST['action'] == "kill") {
43
		$port  = $_REQUEST['port'];
44
		$remipp  = $_REQUEST['remipp'];
45 0927fb8c jim-p
		if (!empty($port) and !empty($remipp)) {
46 61fce4a6 Phil Davis
			$retval = openvpn_kill_client($port, $remipp);
47 0927fb8c jim-p
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
48
		} else {
49 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
50 0927fb8c jim-p
		}
51
		exit;
52
	}
53
}
54
55 53663f57 jim-p
$servers = openvpn_get_active_servers();
56 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
57 53663f57 jim-p
$clients = openvpn_get_active_clients();
58 63084885 Matthew Grooms
59 0927fb8c jim-p
include("head.inc"); ?>
60
61
<form action="status_openvpn.php" method="get" name="iform">
62
<script type="text/javascript">
63 4d33138f Colin Fleming
//<![CDATA[
64 0927fb8c jim-p
	function killClient(mport, remipp) {
65 b9144088 jim-p
		var busy = function(index,icon) {
66 3f98044a Francisco Cavalcante
			$(icon).bind("onclick","");
67
			$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
68
			$(icon).css("cursor","wait");
69 0927fb8c jim-p
		}
70
71 3f98044a Francisco Cavalcante
		$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
72 0927fb8c jim-p
73 3f98044a Francisco Cavalcante
		$.ajax(
74 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
75
				"?action=kill&port=" + mport + "&remipp=" + remipp,
76 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
77 0927fb8c jim-p
		);
78
	}
79
80
	function killComplete(req) {
81
		var values = req.responseText.split("|");
82 abe98adb Phil Davis
		if (values[3] != "0") {
83 016260fe Steve Beaver
	//		alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
84 0927fb8c jim-p
			return;
85
		}
86
87 5a5a11cd bruno
		$('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
88 3f98044a Francisco Cavalcante
			function(index,row) { $(row).fadeOut(1000); }
89 0927fb8c jim-p
		);
90
	}
91 4d33138f Colin Fleming
//]]>
92 0927fb8c jim-p
</script>
93 c64a0911 Hari
94 42b0c921 Phil Davis
<?php
95
	$i = 0;
96
	foreach ($servers as $server):
97
?>
98 0927fb8c jim-p
99 c64a0911 Hari
<div class="panel panel-default">
100 8ad987ee gitdevmod
		<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 c64a0911 Hari
		<div class="panel-body table-responsive">
102 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
103 c64a0911 Hari
				<thead>
104
					<tr>
105
						<th><?=gettext("Common Name")?></th>
106
						<th><?=gettext("Real Address")?></th>
107 cbfd0754 jim-p
						<th><?=gettext("Virtual Address"); ?></th>
108 c64a0911 Hari
						<th><?=gettext("Connected Since"); ?></th>
109 f467ea24 jim-p
						<th><?=gettext("Bytes Sent")?></th>
110
						<th><?=gettext("Bytes Received")?></th>
111 f5736d98 Viktor G
						<th><?=gettext("Cipher")?></th>
112 ff59b884 Stephen Beaver
						<th><!-- Icons --></th>
113 c64a0911 Hari
					</tr>
114
				</thead>
115
				<tbody>
116 919d91f9 Phil Davis
117 9f605c1c Hari
					<?php
118
							foreach ($server['conns'] as $conn):
119
					?>
120 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
121 cbfd0754 jim-p
						<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 c64a0911 Hari
						<td><?=$conn['remote_host'];?></td>
131 cbfd0754 jim-p
						<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 c64a0911 Hari
						<td><?=$conn['connect_time'];?></td>
139 f467ea24 jim-p
						<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 f5736d98 Viktor G
						<td data-value="<?=trim($conn['cipher'])?>"><?=$conn['cipher'];?></td>
142 c64a0911 Hari
						<td>
143 9f605c1c Hari
							<a
144 5c0ab3cd NewEraCracker
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>');" style="cursor:pointer;"
145 c64a0911 Hari
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
146 98128ad6 Phil Davis
							   title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
147 1b7379f9 Jared Dillard
							<i class="fa fa-times"></i>
148 9f605c1c Hari
							</a>
149 c64a0911 Hari
						</td>
150
					</tr>
151 9f605c1c Hari
					<?php
152
							endforeach;
153
					?>
154 c64a0911 Hari
				</tbody>
155
				<tfoot>
156
					<tr>
157 e9701cfe Stephen Beaver
						<td colspan="2">
158 c64a0911 Hari
							<table>
159
								<tr>
160
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
161 7b05178d NOYB
									<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 c64a0911 Hari
									</td>
167
								</tr>
168
							</table>
169
						</td>
170 e9701cfe Stephen Beaver
						<td colspan="5">
171
						</td>
172 c64a0911 Hari
					</tr>
173
				</tfoot>
174
			</table>
175
		</div>
176
</div>
177 42b0c921 Phil Davis
<?php
178
		if (is_array($server['routes']) && count($server['routes'])):
179
?>
180 ec970b50 jim-p
<div id="shroutebut-<?= $i ?>">
181 37676f4e jim-p
	<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 ec970b50 jim-p
</div>
188 56fafd85 Stephen Beaver
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
189 c64a0911 Hari
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
190
		<div class="panel-body table-responsive">
191 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
192 c64a0911 Hari
				<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 919d91f9 Phil Davis
				</thead>
200 c64a0911 Hari
				<tbody>
201 ec970b50 jim-p
202 42b0c921 Phil Davis
<?php
203
			foreach ($server['routes'] as $conn):
204
?>
205 c64a0911 Hari
					<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 42b0c921 Phil Davis
<?php
212
			endforeach;
213
?>
214 c64a0911 Hari
				</tbody>
215
				<tfoot>
216
					<tr>
217 e9701cfe Stephen Beaver
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
218 c64a0911 Hari
					</tr>
219
				</tfoot>
220
			</table>
221
		</div>
222
</div>
223 42b0c921 Phil Davis
<?php
224
		endif;
225
?>
226 8cd558b6 ayvis
<br />
227 42b0c921 Phil Davis
<?php
228
		$i++;
229
	endforeach;
230
?>
231 8cd558b6 ayvis
<br />
232 d0f6649c pierrepomes
233 42b0c921 Phil Davis
<?php
234
	if (!empty($sk_servers)) {
235
?>
236 c64a0911 Hari
<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 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
240 c64a0911 Hari
				<thead>
241 919d91f9 Phil Davis
					<tr>
242 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
243 e9701cfe Stephen Beaver
						<th><?=gettext("Status"); ?></th>
244 c64a0911 Hari
						<th><?=gettext("Connected Since"); ?></th>
245 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
246 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
247 f467ea24 jim-p
						<th><?=gettext("Bytes Sent"); ?></th>
248
						<th><?=gettext("Bytes Received"); ?></th>
249 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
250
					</tr>
251
				</thead>
252
				<tbody>
253 d0f6649c pierrepomes
254 42b0c921 Phil Davis
<?php
255
		foreach ($sk_servers as $sk_server):
256
?>
257 c64a0911 Hari
					<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 bffa3185 jim-p
						<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 c64a0911 Hari
						<td><?=$sk_server['remote_host'];?></td>
269 f467ea24 jim-p
						<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 c64a0911 Hari
						<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 29fda3d3 Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
278 c64a0911 Hari
									</td>
279
								</tr>
280
							</table>
281
						</td>
282
					</tr>
283 42b0c921 Phil Davis
<?php
284
		endforeach;
285
?>
286 c64a0911 Hari
				</tbody>
287 a5eb046f Renato Botelho
			</table>
288 c64a0911 Hari
		</div>
289
</div>
290 95305736 jim-p
291
<?php
292 42b0c921 Phil Davis
	}
293
?>
294 8cd558b6 ayvis
<br />
295 42b0c921 Phil Davis
<?php
296
	if (!empty($clients)) {
297
?>
298 c64a0911 Hari
<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 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
302 c64a0911 Hari
				<thead>
303 919d91f9 Phil Davis
					<tr>
304 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
305
						<th><?=gettext("Status"); ?></th>
306
						<th><?=gettext("Connected Since"); ?></th>
307 cbfd0754 jim-p
						<th><?=gettext("Local Address"); ?></th>
308 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
309 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
310 f467ea24 jim-p
						<th><?=gettext("Bytes Sent"); ?></th>
311
						<th><?=gettext("Bytes Received"); ?></th>
312 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
313
					</tr>
314
				</thead>
315
				<tbody>
316 d0f6649c pierrepomes
317 42b0c921 Phil Davis
<?php
318
		foreach ($clients as $client):
319
?>
320 c64a0911 Hari
					<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 2906d139 jim-p
						<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 cbfd0754 jim-p
						<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 2906d139 jim-p
						<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 f467ea24 jim-p
						<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 c64a0911 Hari
						<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 29fda3d3 Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
354 c64a0911 Hari
									</td>
355
								</tr>
356
							</table>
357
						</td>
358
					</tr>
359 42b0c921 Phil Davis
<?php
360
		endforeach;
361
?>
362 c64a0911 Hari
				</tbody>
363 a5eb046f Renato Botelho
			</table>
364 c64a0911 Hari
		</div>
365 56fafd85 Stephen Beaver
	</div>
366 d0f6649c pierrepomes
367 919d91f9 Phil Davis
<?php
368 cf1ced6d pierrepomes
}
369
370
if ($DisplayNote) {
371 530c7ccf NOYB
 	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 d0f6649c pierrepomes
}
373
374 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
375 8545adde k-paulius
	print_info_box(gettext("No OpenVPN instances defined."));
376 d0f6649c pierrepomes
}
377
?>
378 2a351d32 Colin Fleming
</form>
379 56fafd85 Stephen Beaver
380 ec970b50 jim-p
<script type="text/javascript">
381 4d33138f Colin Fleming
//<![CDATA[
382 56fafd85 Stephen Beaver
383 ec970b50 jim-p
function show_routes(id, buttonid) {
384
	document.getElementById(buttonid).innerHTML='';
385
	aodiv = document.getElementById(id);
386
	aodiv.style.display = "block";
387
}
388 56fafd85 Stephen Beaver
389 4d33138f Colin Fleming
//]]>
390 ec970b50 jim-p
</script>
391 c2081df1 NOYB
392
<?php include("foot.inc"); ?>