Project

General

Profile

Download (9.81 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 Electric Sheep Fencing, LLC
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[name="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
									<td>
143
										<?php $ssvc = find_service_by_openvpn_vpnid($server['vpnid']); ?>
144
										<?= get_service_status_icon($ssvc, true, true); ?>
145
										<?= get_service_control_links($ssvc); ?>
146
									</td>
147
								</tr>
148
							</table>
149
						</td>
150
						<td colspan="5">
151
						</td>
152
					</tr>
153
				</tfoot>
154
			</table>
155
		</div>
156
</div>
157
<?php
158
		if (is_array($server['routes']) && count($server['routes'])):
159
?>
160
<div id="shroutebut-<?= $i ?>">
161
	<button type="button" class="btn btn-info" onClick="show_routes('tabroute-<?= $i ?>','shroutebut-<?= $i ?>')" value="<?php echo gettext("Show Routing Table"); ?>">
162
		<i class="fa fa-plus-circle icon-embed-btn"></i>
163
		<?php echo gettext("Show Routing Table"); ?>
164
	</button>
165
	- <?= gettext("Display OpenVPN's internal routing table for this server.") ?>
166
	<br /><br />
167
</div>
168
<div class="panel panel-default" id="tabroute-<?=$i?>" style="display: none;">
169
		<div class="panel-heading"><h2 class="panel-title"><?=htmlspecialchars($server['name']);?> <?=gettext("Routing Table"); ?></h2></div>
170
		<div class="panel-body table-responsive">
171
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
172
				<thead>
173
					<tr>
174
						<th><?=gettext("Common Name"); ?></th>
175
						<th><?=gettext("Real Address"); ?></th>
176
						<th><?=gettext("Target Network"); ?></th>
177
						<th><?=gettext("Last Used"); ?></th>
178
					</tr>
179
				</thead>
180
				<tbody>
181

    
182
<?php
183
			foreach ($server['routes'] as $conn):
184
?>
185
					<tr id="<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>">
186
						<td><?=$conn['common_name'];?></td>
187
						<td><?=$conn['remote_host'];?></td>
188
						<td><?=$conn['virtual_addr'];?></td>
189
						<td><?=$conn['last_time'];?></td>
190
					</tr>
191
<?php
192
			endforeach;
193
?>
194
				</tbody>
195
				<tfoot>
196
					<tr>
197
						<td colspan="4"><?= gettext("An IP address followed by C indicates a host currently connected through the VPN.") ?></td>
198
					</tr>
199
				</tfoot>
200
			</table>
201
		</div>
202
</div>
203
<?php
204
		endif;
205
?>
206
<br />
207
<?php
208
		$i++;
209
	endforeach;
210
?>
211
<br />
212

    
213
<?php
214
	if (!empty($sk_servers)) {
215
?>
216
<div class="panel panel-default">
217
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Peer to Peer Server Instance Statistics"); ?></h2></div>
218
		<div class="panel-body table-responsive">
219
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
220
				<thead>
221
					<tr>
222
						<th><?=gettext("Name"); ?></th>
223
						<th><?=gettext("Status"); ?></th>
224
						<th><?=gettext("Connected Since"); ?></th>
225
						<th><?=gettext("Virtual Address"); ?></th>
226
						<th><?=gettext("Remote Host"); ?></th>
227
						<th><?=gettext("Bytes Sent"); ?></th>
228
						<th><?=gettext("Bytes Received"); ?></th>
229
						<th><?=gettext("Service"); ?></th>
230
					</tr>
231
				</thead>
232
				<tbody>
233

    
234
<?php
235
		foreach ($sk_servers as $sk_server):
236
?>
237
					<tr id="<?php echo "r:{$sk_server['port']}:{$sk_server['vpnid']}"; ?>">
238
						<td><?=htmlspecialchars($sk_server['name']);?></td>
239
						<td><?=$sk_server['status'];?></td>
240
						<td><?=$sk_server['connect_time'];?></td>
241
						<td><?=$sk_server['virtual_addr'];?></td>
242
						<td><?=$sk_server['remote_host'];?></td>
243
						<td><?=format_bytes($sk_server['bytes_sent']);?></td>
244
						<td><?=format_bytes($sk_server['bytes_recv']);?></td>
245
						<td>
246
							<table>
247
								<tr>
248
									<td>
249
										<?php $ssvc = find_service_by_openvpn_vpnid($sk_server['vpnid']); ?>
250
										<?= get_service_status_icon($ssvc, false, true); ?>
251
										<?= get_service_control_links($ssvc, true); ?>
252
									</td>
253
								</tr>
254
							</table>
255
						</td>
256
					</tr>
257
<?php
258
		endforeach;
259
?>
260
				</tbody>
261
			</table>
262
		</div>
263
</div>
264

    
265
<?php
266
	}
267
?>
268
<br />
269
<?php
270
	if (!empty($clients)) {
271
?>
272
<div class="panel panel-default">
273
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Client Instance Statistics"); ?></h2></div>
274
		<div class="panel-body table-responsive">
275
			<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
276
				<thead>
277
					<tr>
278
						<th><?=gettext("Name"); ?></th>
279
						<th><?=gettext("Status"); ?></th>
280
						<th><?=gettext("Connected Since"); ?></th>
281
						<th><?=gettext("Virtual Address"); ?></th>
282
						<th><?=gettext("Remote Host"); ?></th>
283
						<th><?=gettext("Bytes Sent"); ?></th>
284
						<th><?=gettext("Bytes Received"); ?></th>
285
						<th><?=gettext("Service"); ?></th>
286
					</tr>
287
				</thead>
288
				<tbody>
289

    
290
<?php
291
		foreach ($clients as $client):
292
?>
293
					<tr id="<?php echo "r:{$client['port']}:{$client['vpnid']}"; ?>">
294
						<td><?=htmlspecialchars($client['name']);?></td>
295
						<td><?=$client['status'];?></td>
296
						<td><?=$client['connect_time'];?></td>
297
						<td><?=$client['virtual_addr'];?></td>
298
						<td><?=$client['remote_host'];?></td>
299
						<td><?=format_bytes($client['bytes_sent']);?></td>
300
						<td><?=format_bytes($client['bytes_recv']);?></td>
301
						<td>
302
							<table>
303
								<tr>
304
									<td>
305
										<?php $ssvc = find_service_by_openvpn_vpnid($client['vpnid']); ?>
306
										<?= get_service_status_icon($ssvc, false, true); ?>
307
										<?= get_service_control_links($ssvc, true); ?>
308
									</td>
309
								</tr>
310
							</table>
311
						</td>
312
					</tr>
313
<?php
314
		endforeach;
315
?>
316
				</tbody>
317
			</table>
318
		</div>
319
	</div>
320

    
321
<?php
322
}
323

    
324
if ($DisplayNote) {
325
 	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."));
326
}
327

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

    
334
<script type="text/javascript">
335
//<![CDATA[
336

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

    
343
//]]>
344
</script>
345

    
346
<?php include("foot.inc"); ?>
(180-180/227)