Project

General

Profile

Download (9.93 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 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * Copyright (c) 2008 Shrew Soft Inc.
8
 * All rights reserved.
9
 *
10 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13 c5d81585 Renato Botelho
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 c5d81585 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
17
 * distributed under the License is distributed on an "AS IS" BASIS,
18
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
 * See the License for the specific language governing permissions and
20
 * limitations under the License.
21 b9043cdc Stephen Beaver
 */
22 63084885 Matthew Grooms
23
##|+PRIV
24
##|*IDENT=page-status-openvpn
25 5230f468 jim-p
##|*NAME=Status: OpenVPN
26 63084885 Matthew Grooms
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
27
##|*MATCH=status_openvpn.php*
28
##|-PRIV
29
30 e9d35ff5 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
31 7d7b5a48 jim-p
$shortcut_section = "openvpn";
32
33 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
34 53663f57 jim-p
require_once("openvpn.inc");
35 2eaa97b9 jim-p
require_once("shortcuts.inc");
36 c92ccc70 Renato Botelho
require_once("service-utils.inc");
37 63084885 Matthew Grooms
38 0927fb8c jim-p
/* Handle AJAX */
39 abe98adb Phil Davis
if ($_GET['action']) {
40
	if ($_GET['action'] == "kill") {
41 0927fb8c jim-p
		$port  = $_GET['port'];
42
		$remipp  = $_GET['remipp'];
43
		if (!empty($port) and !empty($remipp)) {
44 61fce4a6 Phil Davis
			$retval = openvpn_kill_client($port, $remipp);
45 0927fb8c jim-p
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
46
		} else {
47 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
48 0927fb8c jim-p
		}
49
		exit;
50
	}
51
}
52
53 53663f57 jim-p
$servers = openvpn_get_active_servers();
54 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
55 53663f57 jim-p
$clients = openvpn_get_active_clients();
56 63084885 Matthew Grooms
57 0927fb8c jim-p
include("head.inc"); ?>
58
59
<form action="status_openvpn.php" method="get" name="iform">
60
<script type="text/javascript">
61 4d33138f Colin Fleming
//<![CDATA[
62 0927fb8c jim-p
	function killClient(mport, remipp) {
63 b9144088 jim-p
		var busy = function(index,icon) {
64 3f98044a Francisco Cavalcante
			$(icon).bind("onclick","");
65
			$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
66
			$(icon).css("cursor","wait");
67 0927fb8c jim-p
		}
68
69 3f98044a Francisco Cavalcante
		$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
70 0927fb8c jim-p
71 3f98044a Francisco Cavalcante
		$.ajax(
72 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
73
				"?action=kill&port=" + mport + "&remipp=" + remipp,
74 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
75 0927fb8c jim-p
		);
76
	}
77
78
	function killComplete(req) {
79
		var values = req.responseText.split("|");
80 abe98adb Phil Davis
		if (values[3] != "0") {
81 0927fb8c jim-p
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
82
			return;
83
		}
84
85 5a5a11cd bruno
		$('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
86 3f98044a Francisco Cavalcante
			function(index,row) { $(row).fadeOut(1000); }
87 0927fb8c jim-p
		);
88
	}
89 4d33138f Colin Fleming
//]]>
90 0927fb8c jim-p
</script>
91 c64a0911 Hari
92 42b0c921 Phil Davis
<?php
93
	$i = 0;
94
	foreach ($servers as $server):
95
?>
96 0927fb8c jim-p
97 c64a0911 Hari
<div class="panel panel-default">
98 3d7a8696 k-paulius
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client Connections')?></h2></div>
99 c64a0911 Hari
		<div class="panel-body table-responsive">
100 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
101 c64a0911 Hari
				<thead>
102
					<tr>
103
						<th><?=gettext("Common Name")?></th>
104
						<th><?=gettext("Real Address")?></th>
105
						<th><?=gettext("Virtual Address"); ?></th>
106
						<th><?=gettext("Connected Since"); ?></th>
107
						<th><?=gettext("Bytes Sent")?></th>
108
						<th><?=gettext("Bytes Received")?></th>
109 ff59b884 Stephen Beaver
						<th><!-- Icons --></th>
110 c64a0911 Hari
					</tr>
111
				</thead>
112
				<tbody>
113 919d91f9 Phil Davis
114 9f605c1c Hari
					<?php
115
							foreach ($server['conns'] as $conn):
116
					?>
117 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
118
						<td><?=$conn['common_name'];?></td>
119
						<td><?=$conn['remote_host'];?></td>
120
						<td><?=$conn['virtual_addr'];?></td>
121
						<td><?=$conn['connect_time'];?></td>
122
						<td><?=format_bytes($conn['bytes_sent']);?></td>
123
						<td><?=format_bytes($conn['bytes_recv']);?></td>
124
						<td>
125 9f605c1c Hari
							<a
126 5c0ab3cd NewEraCracker
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>');" style="cursor:pointer;"
127 c64a0911 Hari
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
128 98128ad6 Phil Davis
							   title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
129 1b7379f9 Jared Dillard
							<i class="fa fa-times"></i>
130 9f605c1c Hari
							</a>
131 c64a0911 Hari
						</td>
132
					</tr>
133 9f605c1c Hari
					<?php
134
							endforeach;
135
					?>
136 c64a0911 Hari
				</tbody>
137
				<tfoot>
138
					<tr>
139 e9701cfe Stephen Beaver
						<td colspan="2">
140 c64a0911 Hari
							<table>
141
								<tr>
142
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
143 7b05178d NOYB
									<td>
144
										<?= gettext("Status") . ": " . get_service_status_icon($ssvc, false, true, false, "service_state"); ?>
145
									</td>
146
									<td>
147
										<?= gettext("Actions") . ": " . get_service_control_links($ssvc); ?>
148 c64a0911 Hari
									</td>
149
								</tr>
150
							</table>
151
						</td>
152 e9701cfe Stephen Beaver
						<td colspan="5">
153
						</td>
154 c64a0911 Hari
					</tr>
155
				</tfoot>
156
			</table>
157
		</div>
158
</div>
159 42b0c921 Phil Davis
<?php
160
		if (is_array($server['routes']) && count($server['routes'])):
161
?>
162 ec970b50 jim-p
<div id="shroutebut-<?= $i ?>">
163 37676f4e jim-p
	<button type="button" class="btn btn-info" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>">
164
		<i class="fa fa-plus-circle icon-embed-btn"></i>
165
		<?php echo gettext("Show Routing Table"); ?>
166
	</button>
167
	- <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
168
	<br /><br />
169 ec970b50 jim-p
</div>
170 56fafd85 Stephen Beaver
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
171 c64a0911 Hari
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
172
		<div class="panel-body table-responsive">
173 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
174 c64a0911 Hari
				<thead>
175
					<tr>
176
						<th><?=gettext("Common Name"); ?></th>
177
						<th><?=gettext("Real Address"); ?></th>
178
						<th><?=gettext("Target Network"); ?></th>
179
						<th><?=gettext("Last Used"); ?></th>
180
					</tr>
181 919d91f9 Phil Davis
				</thead>
182 c64a0911 Hari
				<tbody>
183 ec970b50 jim-p
184 42b0c921 Phil Davis
<?php
185
			foreach ($server['routes'] as $conn):
186
?>
187 c64a0911 Hari
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
188
						<td><?=$conn['common_name'];?></td>
189
						<td><?=$conn['remote_host'];?></td>
190
						<td><?=$conn['virtual_addr'];?></td>
191
						<td><?=$conn['last_time'];?></td>
192
					</tr>
193 42b0c921 Phil Davis
<?php
194
			endforeach;
195
?>
196 c64a0911 Hari
				</tbody>
197
				<tfoot>
198
					<tr>
199 e9701cfe Stephen Beaver
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
200 c64a0911 Hari
					</tr>
201
				</tfoot>
202
			</table>
203
		</div>
204
</div>
205 42b0c921 Phil Davis
<?php
206
		endif;
207
?>
208 8cd558b6 ayvis
<br />
209 42b0c921 Phil Davis
<?php
210
		$i++;
211
	endforeach;
212
?>
213 8cd558b6 ayvis
<br />
214 d0f6649c pierrepomes
215 42b0c921 Phil Davis
<?php
216
	if (!empty($sk_servers)) {
217
?>
218 c64a0911 Hari
<div class="panel panel-default">
219
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
220
		<div class="panel-body table-responsive">
221 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
222 c64a0911 Hari
				<thead>
223 919d91f9 Phil Davis
					<tr>
224 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
225 e9701cfe Stephen Beaver
						<th><?=gettext("Status"); ?></th>
226 c64a0911 Hari
						<th><?=gettext("Connected Since"); ?></th>
227 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
228 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
229
						<th><?=gettext("Bytes Sent"); ?></th>
230 a66ce627 NewEraCracker
						<th><?=gettext("Bytes Received"); ?></th>
231 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
232
					</tr>
233
				</thead>
234
				<tbody>
235 d0f6649c pierrepomes
236 42b0c921 Phil Davis
<?php
237
		foreach ($sk_servers as $sk_server):
238
?>
239 c64a0911 Hari
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
240
						<td><?=htmlspecialchars($sk_server['name']);?></td>
241
						<td><?=$sk_server['status'];?></td>
242
						<td><?=$sk_server['connect_time'];?></td>
243
						<td><?=$sk_server['virtual_addr'];?></td>
244
						<td><?=$sk_server['remote_host'];?></td>
245
						<td><?=format_bytes($sk_server['bytes_sent']);?></td>
246
						<td><?=format_bytes($sk_server['bytes_recv']);?></td>
247
						<td>
248
							<table>
249
								<tr>
250
									<td>
251
										<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
252
										<?= get_service_status_icon($ssvc, false, true); ?>
253 29fda3d3 Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
254 c64a0911 Hari
									</td>
255
								</tr>
256
							</table>
257
						</td>
258
					</tr>
259 42b0c921 Phil Davis
<?php
260
		endforeach;
261
?>
262 c64a0911 Hari
				</tbody>
263 a5eb046f Renato Botelho
			</table>
264 c64a0911 Hari
		</div>
265
</div>
266 95305736 jim-p
267
<?php
268 42b0c921 Phil Davis
	}
269
?>
270 8cd558b6 ayvis
<br />
271 42b0c921 Phil Davis
<?php
272
	if (!empty($clients)) {
273
?>
274 c64a0911 Hari
<div class="panel panel-default">
275
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
276
		<div class="panel-body table-responsive">
277 10fe1eb5 Stephen Beaver
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
278 c64a0911 Hari
				<thead>
279 919d91f9 Phil Davis
					<tr>
280 c64a0911 Hari
						<th><?=gettext("Name"); ?></th>
281
						<th><?=gettext("Status"); ?></th>
282
						<th><?=gettext("Connected Since"); ?></th>
283 a66ce627 NewEraCracker
						<th><?=gettext("Virtual Address"); ?></th>
284 c64a0911 Hari
						<th><?=gettext("Remote Host"); ?></th>
285
						<th><?=gettext("Bytes Sent"); ?></th>
286 a66ce627 NewEraCracker
						<th><?=gettext("Bytes Received"); ?></th>
287 c64a0911 Hari
						<th><?=gettext("Service"); ?></th>
288
					</tr>
289
				</thead>
290
				<tbody>
291 d0f6649c pierrepomes
292 42b0c921 Phil Davis
<?php
293
		foreach ($clients as $client):
294
?>
295 c64a0911 Hari
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
296
						<td><?=htmlspecialchars($client['name']);?></td>
297
						<td><?=$client['status'];?></td>
298
						<td><?=$client['connect_time'];?></td>
299
						<td><?=$client['virtual_addr'];?></td>
300
						<td><?=$client['remote_host'];?></td>
301
						<td><?=format_bytes($client['bytes_sent']);?></td>
302
						<td><?=format_bytes($client['bytes_recv']);?></td>
303
						<td>
304
							<table>
305
								<tr>
306
									<td>
307
										<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
308
										<?= get_service_status_icon($ssvc, false, true); ?>
309 29fda3d3 Stephen Beaver
										<?= get_service_control_links($ssvc, true); ?>
310 c64a0911 Hari
									</td>
311
								</tr>
312
							</table>
313
						</td>
314
					</tr>
315 42b0c921 Phil Davis
<?php
316
		endforeach;
317
?>
318 c64a0911 Hari
				</tbody>
319 a5eb046f Renato Botelho
			</table>
320 c64a0911 Hari
		</div>
321 56fafd85 Stephen Beaver
	</div>
322 d0f6649c pierrepomes
323 919d91f9 Phil Davis
<?php
324 cf1ced6d pierrepomes
}
325
326
if ($DisplayNote) {
327 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."));
328 d0f6649c pierrepomes
}
329
330 48b490ca Phil Davis
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
331 8545adde k-paulius
	print_info_box(gettext("No OpenVPN instances defined."));
332 d0f6649c pierrepomes
}
333
?>
334 2a351d32 Colin Fleming
</form>
335 56fafd85 Stephen Beaver
336 ec970b50 jim-p
<script type="text/javascript">
337 4d33138f Colin Fleming
//<![CDATA[
338 56fafd85 Stephen Beaver
339 ec970b50 jim-p
function show_routes(id, buttonid) {
340
	document.getElementById(buttonid).innerHTML='';
341
	aodiv = document.getElementById(id);
342
	aodiv.style.display = "block";
343
}
344 56fafd85 Stephen Beaver
345 4d33138f Colin Fleming
//]]>
346 ec970b50 jim-p
</script>
347 c2081df1 NOYB
348
<?php include("foot.inc"); ?>