Project

General

Profile

Download (11.7 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 0284d79e jim-p
 * Copyright (c) 2014-2020 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 ff59b884 Stephen Beaver
						<th><!-- Icons --></th>
112 c64a0911 Hari
					</tr>
113
				</thead>
114
				<tbody>
115 919d91f9 Phil Davis
116 9f605c1c Hari
					<?php
117
							foreach ($server['conns'] as $conn):
118
					?>
119 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
120 cbfd0754 jim-p
						<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 c64a0911 Hari
						<td><?=$conn['remote_host'];?></td>
130 cbfd0754 jim-p
						<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 c64a0911 Hari
						<td><?=$conn['connect_time'];?></td>
138 f467ea24 jim-p
						<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 c64a0911 Hari
						<td>
141 9f605c1c Hari
							<a
142 5c0ab3cd NewEraCracker
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>');" style="cursor:pointer;"
143 c64a0911 Hari
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
144 98128ad6 Phil Davis
							   title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
145 1b7379f9 Jared Dillard
							<i class="fa fa-times"></i>
146 9f605c1c Hari
							</a>
147 c64a0911 Hari
						</td>
148
					</tr>
149 9f605c1c Hari
					<?php
150
							endforeach;
151
					?>
152 c64a0911 Hari
				</tbody>
153
				<tfoot>
154
					<tr>
155 e9701cfe Stephen Beaver
						<td colspan="2">
156 c64a0911 Hari
							<table>
157
								<tr>
158
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
159 7b05178d NOYB
									<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 c64a0911 Hari
									</td>
165
								</tr>
166
							</table>
167
						</td>
168 e9701cfe Stephen Beaver
						<td colspan="5">
169
						</td>
170 c64a0911 Hari
					</tr>
171
				</tfoot>
172
			</table>
173
		</div>
174
</div>
175 42b0c921 Phil Davis
<?php
176
		if (is_array($server['routes']) && count($server['routes'])):
177
?>
178 ec970b50 jim-p
<div id="shroutebut-<?= $i ?>">
179 37676f4e jim-p
	<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 ec970b50 jim-p
</div>
186 56fafd85 Stephen Beaver
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
187 c64a0911 Hari
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
188
		<div class="panel-body table-responsive">
189 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
190 c64a0911 Hari
				<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 919d91f9 Phil Davis
				</thead>
198 c64a0911 Hari
				<tbody>
199 ec970b50 jim-p
200 42b0c921 Phil Davis
<?php
201
			foreach ($server['routes'] as $conn):
202
?>
203 c64a0911 Hari
					<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 42b0c921 Phil Davis
<?php
210
			endforeach;
211
?>
212 c64a0911 Hari
				</tbody>
213
				<tfoot>
214
					<tr>
215 e9701cfe Stephen Beaver
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
216 c64a0911 Hari
					</tr>
217
				</tfoot>
218
			</table>
219
		</div>
220
</div>
221 42b0c921 Phil Davis
<?php
222
		endif;
223
?>
224 8cd558b6 ayvis
<br />
225 42b0c921 Phil Davis
<?php
226
		$i++;
227
	endforeach;
228
?>
229 8cd558b6 ayvis
<br />
230 d0f6649c pierrepomes
231 42b0c921 Phil Davis
<?php
232
	if (!empty($sk_servers)) {
233
?>
234 c64a0911 Hari
<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 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
238 c64a0911 Hari
				<thead>
239 919d91f9 Phil Davis
					<tr>
240 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
241 e9701cfe Stephen Beaver
						<th><?=gettext("Status"); ?></th>
242 c64a0911 Hari
						<th><?=gettext("Connected Since"); ?></th>
243 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
244 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
245 f467ea24 jim-p
						<th><?=gettext("Bytes Sent"); ?></th>
246
						<th><?=gettext("Bytes Received"); ?></th>
247 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
248
					</tr>
249
				</thead>
250
				<tbody>
251 d0f6649c pierrepomes
252 42b0c921 Phil Davis
<?php
253
		foreach ($sk_servers as $sk_server):
254
?>
255 c64a0911 Hari
					<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 bffa3185 jim-p
						<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 c64a0911 Hari
						<td><?=$sk_server['remote_host'];?></td>
267 f467ea24 jim-p
						<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 c64a0911 Hari
						<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 29fda3d3 Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
276 c64a0911 Hari
									</td>
277
								</tr>
278
							</table>
279
						</td>
280
					</tr>
281 42b0c921 Phil Davis
<?php
282
		endforeach;
283
?>
284 c64a0911 Hari
				</tbody>
285 a5eb046f Renato Botelho
			</table>
286 c64a0911 Hari
		</div>
287
</div>
288 95305736 jim-p
289
<?php
290 42b0c921 Phil Davis
	}
291
?>
292 8cd558b6 ayvis
<br />
293 42b0c921 Phil Davis
<?php
294
	if (!empty($clients)) {
295
?>
296 c64a0911 Hari
<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 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
300 c64a0911 Hari
				<thead>
301 919d91f9 Phil Davis
					<tr>
302 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
303
						<th><?=gettext("Status"); ?></th>
304
						<th><?=gettext("Connected Since"); ?></th>
305 cbfd0754 jim-p
						<th><?=gettext("Local Address"); ?></th>
306 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
307 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
308 f467ea24 jim-p
						<th><?=gettext("Bytes Sent"); ?></th>
309
						<th><?=gettext("Bytes Received"); ?></th>
310 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
311
					</tr>
312
				</thead>
313
				<tbody>
314 d0f6649c pierrepomes
315 42b0c921 Phil Davis
<?php
316
		foreach ($clients as $client):
317
?>
318 c64a0911 Hari
					<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 2906d139 jim-p
						<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 cbfd0754 jim-p
						<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 2906d139 jim-p
						<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 f467ea24 jim-p
						<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 c64a0911 Hari
						<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 29fda3d3 Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
352 c64a0911 Hari
									</td>
353
								</tr>
354
							</table>
355
						</td>
356
					</tr>
357 42b0c921 Phil Davis
<?php
358
		endforeach;
359
?>
360 c64a0911 Hari
				</tbody>
361 a5eb046f Renato Botelho
			</table>
362 c64a0911 Hari
		</div>
363 56fafd85 Stephen Beaver
	</div>
364 d0f6649c pierrepomes
365 919d91f9 Phil Davis
<?php
366 cf1ced6d pierrepomes
}
367
368
if ($DisplayNote) {
369 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."));
370 d0f6649c pierrepomes
}
371
372 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
373 8545adde k-paulius
	print_info_box(gettext("No OpenVPN instances defined."));
374 d0f6649c pierrepomes
}
375
?>
376 2a351d32 Colin Fleming
</form>
377 56fafd85 Stephen Beaver
378 ec970b50 jim-p
<script type="text/javascript">
379 4d33138f Colin Fleming
//<![CDATA[
380 56fafd85 Stephen Beaver
381 ec970b50 jim-p
function show_routes(id, buttonid) {
382
	document.getElementById(buttonid).innerHTML='';
383
	aodiv = document.getElementById(id);
384
	aodiv.style.display = "block";
385
}
386 56fafd85 Stephen Beaver
387 4d33138f Colin Fleming
//]]>
388 ec970b50 jim-p
</script>
389 c2081df1 NOYB
390
<?php include("foot.inc"); ?>