Project

General

Profile

Download (9.93 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-2016 Rubicon Communications, LLC (Netgate)
7
 * Copyright (c) 2008 Shrew Soft Inc.
8
 * All rights reserved.
9
 *
10
 * 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
 *
14
 * http://www.apache.org/licenses/LICENSE-2.0
15
 *
16
 * 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
 */
22

    
23
##|+PRIV
24
##|*IDENT=page-status-openvpn
25
##|*NAME=Status: OpenVPN
26
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
27
##|*MATCH=status_openvpn.php*
28
##|-PRIV
29

    
30
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
31
$shortcut_section = "openvpn";
32

    
33
require_once("guiconfig.inc");
34
require_once("openvpn.inc");
35
require_once("shortcuts.inc");
36
require_once("service-utils.inc");
37

    
38
/* Handle AJAX */
39
if ($_GET['action']) {
40
	if ($_GET['action'] == "kill") {
41
		$port  = $_GET['port'];
42
		$remipp  = $_GET['remipp'];
43
		if (!empty($port) and !empty($remipp)) {
44
			$retval = openvpn_kill_client($port, $remipp);
45
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
46
		} else {
47
			echo gettext("invalid input");
48
		}
49
		exit;
50
	}
51
}
52

    
53
$servers = openvpn_get_active_servers();
54
$sk_servers = openvpn_get_active_servers("p2p");
55
$clients = openvpn_get_active_clients();
56

    
57
include("head.inc"); ?>
58

    
59
<form action="status_openvpn.php" method="get" name="iform">
60
<script type="text/javascript">
61
//<![CDATA[
62
	function killClient(mport, remipp) {
63
		var busy = function(index,icon) {
64
			$(icon).bind("onclick","");
65
			$(icon).attr('src',$(icon).attr('src').replace("\.gif", "_d.gif"));
66
			$(icon).css("cursor","wait");
67
		}
68

    
69
		$('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
70

    
71
		$.ajax(
72
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
73
				"?action=kill&port=" + mport + "&remipp=" + remipp,
74
			{ type: "get", complete: killComplete }
75
		);
76
	}
77

    
78
	function killComplete(req) {
79
		var values = req.responseText.split("|");
80
		if (values[3] != "0") {
81
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
82
			return;
83
		}
84

    
85
		$('tr[id="r:' + values[1] + ":" + values[2] + '"]').each(
86
			function(index,row) { $(row).fadeOut(1000); }
87
		);
88
	}
89
//]]>
90
</script>
91

    
92
<?php
93
	$i = 0;
94
	foreach ($servers as $server):
95
?>
96

    
97
<div class="panel panel-default">
98
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext('Client Connections')?></h2></div>
99
		<div class="panel-body table-responsive">
100
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
101
				<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
						<th><!-- Icons --></th>
110
					</tr>
111
				</thead>
112
				<tbody>
113

    
114
					<?php
115
							foreach ($server['conns'] as $conn):
116
					?>
117
					<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
							<a
126
							   onclick="killClient('<?=$server['mgmt'];?>', '<?=$conn['remote_host'];?>');" style="cursor:pointer;"
127
							   id="<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>"
128
							   title="<?php echo sprintf(gettext("Kill client connection from %s"), $conn['remote_host']); ?>">
129
							<i class="fa fa-times"></i>
130
							</a>
131
						</td>
132
					</tr>
133
					<?php
134
							endforeach;
135
					?>
136
				</tbody>
137
				<tfoot>
138
					<tr>
139
						<td colspan="2">
140
							<table>
141
								<tr>
142
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
143
									<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
									</td>
149
								</tr>
150
							</table>
151
						</td>
152
						<td colspan="5">
153
						</td>
154
					</tr>
155
				</tfoot>
156
			</table>
157
		</div>
158
</div>
159
<?php
160
		if (is_array($server['routes']) && count($server['routes'])):
161
?>
162
<div id="shroutebut-<?= $i ?>">
163
	<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
</div>
170
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
171
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
172
		<div class="panel-body table-responsive">
173
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
174
				<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
				</thead>
182
				<tbody>
183

    
184
<?php
185
			foreach ($server['routes'] as $conn):
186
?>
187
					<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
<?php
194
			endforeach;
195
?>
196
				</tbody>
197
				<tfoot>
198
					<tr>
199
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
200
					</tr>
201
				</tfoot>
202
			</table>
203
		</div>
204
</div>
205
<?php
206
		endif;
207
?>
208
<br />
209
<?php
210
		$i++;
211
	endforeach;
212
?>
213
<br />
214

    
215
<?php
216
	if (!empty($sk_servers)) {
217
?>
218
<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
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
222
				<thead>
223
					<tr>
224
						<th><?=gettext("Name"); ?></th>
225
						<th><?=gettext("Status"); ?></th>
226
						<th><?=gettext("Connected Since"); ?></th>
227
						<th><?=gettext("Virtual Address"); ?></th>
228
						<th><?=gettext("Remote Host"); ?></th>
229
						<th><?=gettext("Bytes Sent"); ?></th>
230
						<th><?=gettext("Bytes Received"); ?></th>
231
						<th><?=gettext("Service"); ?></th>
232
					</tr>
233
				</thead>
234
				<tbody>
235

    
236
<?php
237
		foreach ($sk_servers as $sk_server):
238
?>
239
					<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
										<?= get_service_control_links($ssvc, true); ?>
254
									</td>
255
								</tr>
256
							</table>
257
						</td>
258
					</tr>
259
<?php
260
		endforeach;
261
?>
262
				</tbody>
263
			</table>
264
		</div>
265
</div>
266

    
267
<?php
268
	}
269
?>
270
<br />
271
<?php
272
	if (!empty($clients)) {
273
?>
274
<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
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
278
				<thead>
279
					<tr>
280
						<th><?=gettext("Name"); ?></th>
281
						<th><?=gettext("Status"); ?></th>
282
						<th><?=gettext("Connected Since"); ?></th>
283
						<th><?=gettext("Virtual Address"); ?></th>
284
						<th><?=gettext("Remote Host"); ?></th>
285
						<th><?=gettext("Bytes Sent"); ?></th>
286
						<th><?=gettext("Bytes Received"); ?></th>
287
						<th><?=gettext("Service"); ?></th>
288
					</tr>
289
				</thead>
290
				<tbody>
291

    
292
<?php
293
		foreach ($clients as $client):
294
?>
295
					<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
										<?= get_service_control_links($ssvc, true); ?>
310
									</td>
311
								</tr>
312
							</table>
313
						</td>
314
					</tr>
315
<?php
316
		endforeach;
317
?>
318
				</tbody>
319
			</table>
320
		</div>
321
	</div>
322

    
323
<?php
324
}
325

    
326
if ($DisplayNote) {
327
 	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
}
329

    
330
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
331
	print_info_box(gettext("No OpenVPN instances defined."));
332
}
333
?>
334
</form>
335

    
336
<script type="text/javascript">
337
//<![CDATA[
338

    
339
function show_routes(id, buttonid) {
340
	document.getElementById(buttonid).innerHTML='';
341
	aodiv = document.getElementById(id);
342
	aodiv.style.display = "block";
343
}
344

    
345
//]]>
346
</script>
347

    
348
<?php include("foot.inc"); ?>
(183-183/230)