Project

General

Profile

Download (9.25 KB) Statistics
| Branch: | Tag: | Revision:
1 0927fb8c jim-p
<?php
2 63084885 Matthew Grooms
/*
3
	status_ovpenvpn.php
4
5 0927fb8c jim-p
    Copyright (C) 2010 Jim Pingle
6 63084885 Matthew Grooms
    Copyright (C) 2008 Shrew Soft Inc.
7 0927fb8c jim-p
8
    AJAX bits borrowed from diag_dump_states.php
9
    Copyright (C) 2005 Scott Ullrich, Colin Smith
10
11 63084885 Matthew Grooms
    All rights reserved.
12 0927fb8c jim-p
13 63084885 Matthew Grooms
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 0927fb8c jim-p
16 63084885 Matthew Grooms
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 0927fb8c jim-p
19 63084885 Matthew Grooms
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22 0927fb8c jim-p
23 63084885 Matthew Grooms
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34 61dda8f7 Matthew Grooms
/* DISABLE_PHP_LINT_CHECKING */
35 0927fb8c jim-p
/*
36 1d333258 Scott Ullrich
	pfSense_MODULE:	openvpn
37
*/
38 63084885 Matthew Grooms
39
##|+PRIV
40
##|*IDENT=page-status-openvpn
41
##|*NAME=Status: OpenVPN page
42
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
43
##|*MATCH=status_openvpn.php*
44
##|-PRIV
45
46 e9d35ff5 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
47 63084885 Matthew Grooms
require("guiconfig.inc");
48 53663f57 jim-p
require_once("openvpn.inc");
49 63084885 Matthew Grooms
50 0927fb8c jim-p
/* Handle AJAX */
51
if($_GET['action']) {
52
	if($_GET['action'] == "kill") {
53
		$port  = $_GET['port'];
54
		$remipp  = $_GET['remipp'];
55
		if (!empty($port) and !empty($remipp)) {
56
			$retval = kill_client($port, $remipp);
57
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
58
		} else {
59 e9d35ff5 Carlos Eduardo Ramos
			echo gettext("invalid input");
60 0927fb8c jim-p
		}
61
		exit;
62
	}
63
}
64
65
66
function kill_client($port, $remipp) {
67 71ca2cb2 Ermal
	global $g;
68
69
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
70
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
71 0927fb8c jim-p
	$errval;
72
	$errstr;
73
74
	/* open a tcp connection to the management port of each server */
75
	$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
76
	$killed = -1;
77
	if ($fp) {
78 19e3d450 Ermal
		stream_set_timeout($fp, 1);
79 0927fb8c jim-p
		fputs($fp, "kill {$remipp}\n");
80
		while (!feof($fp)) {
81
			$line = fgets($fp, 1024);
82 b0140675 Ermal
83
			$info = stream_get_meta_data($fp);
84
			if ($info['timed_out'])
85
				break;
86
87 0927fb8c jim-p
			/* parse header list line */
88 68b04527 jim-p
			if (strpos($line, "INFO:") !== false)
89 0927fb8c jim-p
				continue;
90 68b04527 jim-p
			if (strpos($line, "SUCCESS") !== false) {
91 0927fb8c jim-p
				$killed = 0;
92
			}
93
			break;
94
		}
95
		fclose($fp);
96
	}
97
	return $killed;
98
}
99
100 53663f57 jim-p
$servers = openvpn_get_active_servers();
101 453d9c96 jim-p
$sk_servers = openvpn_get_active_servers("p2p");
102 53663f57 jim-p
$clients = openvpn_get_active_clients();
103 63084885 Matthew Grooms
104 0927fb8c jim-p
include("head.inc"); ?>
105
106
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
107
<script src="/javascript/sorttable.js" type="text/javascript"></script>
108
<?php include("fbegin.inc"); ?>
109
<form action="status_openvpn.php" method="get" name="iform">
110
<script type="text/javascript">
111
	function killClient(mport, remipp) {
112
		var busy = function(icon) {
113 e03ef9a0 Vinicius Coque
			jQuery(icon).bind("onclick","");
114
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
115
			jQuery(icon).css("cursor","wait");
116 0927fb8c jim-p
		}
117
118 e03ef9a0 Vinicius Coque
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
119 0927fb8c jim-p
120 e03ef9a0 Vinicius Coque
		jQuery.ajax(
121 0927fb8c jim-p
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
122
				"?action=kill&port=" + mport + "&remipp=" + remipp,
123 e03ef9a0 Vinicius Coque
			{ type: "get", complete: killComplete }
124 0927fb8c jim-p
		);
125
	}
126
127
	function killComplete(req) {
128
		var values = req.responseText.split("|");
129
		if(values[3] != "0") {
130
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
131
			return;
132
		}
133
134 e03ef9a0 Vinicius Coque
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
135
			function(index,row) { jQuery(row).fadeOut(1000); }
136 0927fb8c jim-p
		);
137
	}
138
</script>
139
140
<?php foreach ($servers as $server): ?>
141
142
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
143
	<tr>
144
		<td colspan="6" class="listtopic">
145 95305736 jim-p
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
146 0927fb8c jim-p
		</td>
147
	</tr>
148
	<tr>
149
		<td>
150
			<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
151
			<tr>
152 e9d35ff5 Carlos Eduardo Ramos
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
153
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
154
				<td class="listhdrr"><?=gettext("Virtual Address"); ?></td>
155
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
156
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
157
				<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
158 0927fb8c jim-p
			</tr>
159
160
			<?php foreach ($server['conns'] as $conn): ?>
161 68b04527 jim-p
			<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
162 0927fb8c jim-p
				<td class="listlr">
163
					<?=$conn['common_name'];?>
164
				</td>
165
				<td class="listr">
166
					<?=$conn['remote_host'];?>
167
				</td>
168
				<td class="listr">
169
					<?=$conn['virtual_addr'];?>
170
				</td>
171
				<td class="listr">
172
					<?=$conn['connect_time'];?>
173
				</td>
174
				<td class="listr">
175
					<?=$conn['bytes_sent'];?>
176
				</td>
177
				<td class="listr">
178
					<?=$conn['bytes_recv'];?>
179
				</td>
180
				<td class='list'>
181
					<img src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' height='17' width='17' border='0'
182 71ca2cb2 Ermal
					   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style='cursor:pointer;'
183 68b04527 jim-p
					   name='<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>'
184
					   title='<?php echo gettext("Kill client connection from") . ' ' . $conn['remote_host']; ?>' alt='' />
185 0927fb8c jim-p
				</td>
186
			</tr>
187
188
			<?php endforeach; ?>
189
			<tr>
190
				<td colspan="6" class="list" height="12"></td>
191
			</tr>
192
193
		</table>
194
		</td>
195
	</tr>
196
</table>
197 63084885 Matthew Grooms
198 0927fb8c jim-p
<?php endforeach; ?>
199 d0f6649c pierrepomes
<br>
200
201 95305736 jim-p
<?php if (!empty($sk_servers)) { ?>
202
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
203
	<tr>
204
		<td colspan="6" class="listtopic">
205 453d9c96 jim-p
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
206 95305736 jim-p
		</td>
207
	</tr>
208
	<tr>
209
		<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
210
		<tr>
211
			<td class="listhdrr"><?=gettext("Name"); ?></td>
212
			<td class="listhdrr"><?=gettext("Status"); ?></td>
213
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
214
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
215
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
216
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
217
			<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
218
		</tr>
219 d0f6649c pierrepomes
220 95305736 jim-p
<?php foreach ($sk_servers as $sk_server): ?>
221
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
222
			<td class="listlr">
223
				<?=$sk_server['name'];?>
224
			</td>
225
			<td class="listlr">
226
				<?=$sk_server['status'];?>
227
			</td>
228
			<td class="listr">
229
				<?=$sk_server['connect_time'];?>
230
			</td>
231
			<td class="listr">
232
				<?=$sk_server['virtual_addr'];?>
233
			</td>
234
			<td class="listr">
235
				<?=$sk_server['remote_host'];?>
236
			</td>
237
			<td class="listr">
238
				<?=$sk_server['bytes_sent'];?>
239
			</td>
240
			<td class="listr">
241
				<?=$sk_server['bytes_recv'];?>
242
			</td>
243
		</tr>
244
<?php endforeach; ?>
245
		</table>
246
	</tr>
247
</table>
248
249
<?php
250
} ?>
251
<br>
252 cf1ced6d pierrepomes
<?php if (!empty($clients)) { ?>
253 d0f6649c pierrepomes
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
254
	<tr>
255
		<td colspan="6" class="listtopic">
256 95305736 jim-p
			<?=gettext("Client Instance Statistics"); ?>
257 d0f6649c pierrepomes
		</td>
258
	</tr>
259
	<tr>
260
		<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
261
		<tr>
262 e9d35ff5 Carlos Eduardo Ramos
			<td class="listhdrr"><?=gettext("Name"); ?></td>
263
			<td class="listhdrr"><?=gettext("Status"); ?></td>
264
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
265
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
266
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
267
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
268
			<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
269 d0f6649c pierrepomes
		</tr>
270
271
<?php foreach ($clients as $client): ?>
272
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
273
			<td class="listlr">
274
				<?=$client['name'];?>
275
			</td>
276
			<td class="listlr">
277
				<?=$client['status'];?>
278
			</td>
279
			<td class="listr">
280
				<?=$client['connect_time'];?>
281
			</td>
282
			<td class="listr">
283
				<?=$client['virtual_addr'];?>
284
			</td>
285
			<td class="listr">
286
				<?=$client['remote_host'];?>
287
			</td>
288
			<td class="listr">
289
				<?=$client['bytes_sent'];?>
290
			</td>
291
			<td class="listr">
292
				<?=$client['bytes_recv'];?>
293
			</td>
294
		</tr>
295
<?php endforeach; ?>
296
		</table>
297
	</tr>
298
</table>
299
300 cf1ced6d pierrepomes
<?php 
301
}
302
303
if ($DisplayNote) {
304 e9d35ff5 Carlos Eduardo Ramos
	echo "<br/><b>" . gettext("NOTE") . ":</b> " . gettext("You need to bind each OpenVPN client to enable its management daemon: use 'Local port' setting in the OpenVPN client screen");
305 d0f6649c pierrepomes
}
306
307 cf1ced6d pierrepomes
if ((empty($clients)) && (empty($servers))) {
308 e9d35ff5 Carlos Eduardo Ramos
	echo gettext("No OpenVPN instance defined");
309 d0f6649c pierrepomes
}
310
?>
311
312 63084885 Matthew Grooms
313
<?php include("fend.inc"); ?>