Project

General

Profile

Download (9.27 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_ovpenvpn.php
4

    
5
    Copyright (C) 2010 Jim Pingle
6
    Copyright (C) 2008 Shrew Soft Inc.
7

    
8
    AJAX bits borrowed from diag_dump_states.php
9
    Copyright (C) 2005 Scott Ullrich, Colin Smith
10

    
11
    All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18

    
19
	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

    
23
	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
/* DISABLE_PHP_LINT_CHECKING */
35
/*
36
	pfSense_MODULE:	openvpn
37
*/
38

    
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
$pgtitle = array(gettext("Status"), gettext("OpenVPN"));
47
$shortcut_section = "openvpn";
48

    
49
require("guiconfig.inc");
50
require_once("openvpn.inc");
51

    
52
/* Handle AJAX */
53
if($_GET['action']) {
54
	if($_GET['action'] == "kill") {
55
		$port  = $_GET['port'];
56
		$remipp  = $_GET['remipp'];
57
		if (!empty($port) and !empty($remipp)) {
58
			$retval = kill_client($port, $remipp);
59
			echo htmlentities("|{$port}|{$remipp}|{$retval}|");
60
		} else {
61
			echo gettext("invalid input");
62
		}
63
		exit;
64
	}
65
}
66

    
67

    
68
function kill_client($port, $remipp) {
69
	global $g;
70

    
71
	//$tcpsrv = "tcp://127.0.0.1:{$port}";
72
	$tcpsrv = "unix://{$g['varetc_path']}/openvpn/{$port}.sock";
73
	$errval;
74
	$errstr;
75

    
76
	/* open a tcp connection to the management port of each server */
77
	$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1);
78
	$killed = -1;
79
	if ($fp) {
80
		stream_set_timeout($fp, 1);
81
		fputs($fp, "kill {$remipp}\n");
82
		while (!feof($fp)) {
83
			$line = fgets($fp, 1024);
84

    
85
			$info = stream_get_meta_data($fp);
86
			if ($info['timed_out'])
87
				break;
88

    
89
			/* parse header list line */
90
			if (strpos($line, "INFO:") !== false)
91
				continue;
92
			if (strpos($line, "SUCCESS") !== false) {
93
				$killed = 0;
94
			}
95
			break;
96
		}
97
		fclose($fp);
98
	}
99
	return $killed;
100
}
101

    
102
$servers = openvpn_get_active_servers();
103
$sk_servers = openvpn_get_active_servers("p2p");
104
$clients = openvpn_get_active_clients();
105

    
106
include("head.inc"); ?>
107

    
108
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
109
<?php include("fbegin.inc"); ?>
110
<form action="status_openvpn.php" method="get" name="iform">
111
<script type="text/javascript">
112
	function killClient(mport, remipp) {
113
		var busy = function(index,icon) {
114
			jQuery(icon).bind("onclick","");
115
			jQuery(icon).attr('src',jQuery(icon).attr('src').replace("\.gif", "_d.gif"));
116
			jQuery(icon).css("cursor","wait");
117
		}
118

    
119
		jQuery('img[name="i:' + mport + ":" + remipp + '"]').each(busy);
120

    
121
		jQuery.ajax(
122
			"<?=$_SERVER['SCRIPT_NAME'];?>" +
123
				"?action=kill&port=" + mport + "&remipp=" + remipp,
124
			{ type: "get", complete: killComplete }
125
		);
126
	}
127

    
128
	function killComplete(req) {
129
		var values = req.responseText.split("|");
130
		if(values[3] != "0") {
131
			alert('<?=gettext("An error occurred.");?>' + ' (' + values[3] + ')');
132
			return;
133
		}
134

    
135
		jQuery('tr[name="r:' + values[1] + ":" + values[2] + '"]').each(
136
			function(index,row) { jQuery(row).fadeOut(1000); }
137
		);
138
	}
139
</script>
140

    
141
<?php foreach ($servers as $server): ?>
142

    
143
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
144
	<tr>
145
		<td colspan="6" class="listtopic">
146
			<?=$server['name'];?> <?=gettext("Client connections"); ?>
147
		</td>
148
	</tr>
149
	<tr>
150
		<td>
151
			<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">
152
			<tr>
153
				<td class="listhdrr"><?=gettext("Common Name"); ?></td>
154
				<td class="listhdrr"><?=gettext("Real Address"); ?></td>
155
				<td class="listhdrr"><?=gettext("Virtual Address"); ?></td>
156
				<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
157
				<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
158
				<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
159
			</tr>
160

    
161
			<?php foreach ($server['conns'] as $conn): ?>
162
			<tr name='<?php echo "r:{$server['mgmt']}:{$conn['remote_host']}"; ?>'>
163
				<td class="listlr">
164
					<?=$conn['common_name'];?>
165
				</td>
166
				<td class="listr">
167
					<?=$conn['remote_host'];?>
168
				</td>
169
				<td class="listr">
170
					<?=$conn['virtual_addr'];?>
171
				</td>
172
				<td class="listr">
173
					<?=$conn['connect_time'];?>
174
				</td>
175
				<td class="listr">
176
					<?=$conn['bytes_sent'];?>
177
				</td>
178
				<td class="listr">
179
					<?=$conn['bytes_recv'];?>
180
				</td>
181
				<td class='list'>
182
					<img src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' height='17' width='17' border='0'
183
					   onclick="killClient('<?php echo $server['mgmt']; ?>', '<?php echo $conn['remote_host']; ?>');" style='cursor:pointer;'
184
					   name='<?php echo "i:{$server['mgmt']}:{$conn['remote_host']}"; ?>'
185
					   title='<?php echo gettext("Kill client connection from") . ' ' . $conn['remote_host']; ?>' alt='' />
186
				</td>
187
			</tr>
188

    
189
			<?php endforeach; ?>
190
			<tfoot>
191
			<tr>
192
				<td colspan="6" class="list" height="12"></td>
193
			</tr>
194
			</tfoot>
195

    
196
		</table>
197
		</td>
198
	</tr>
199
</table>
200

    
201
<?php endforeach; ?>
202
<br>
203

    
204
<?php if (!empty($sk_servers)) { ?>
205
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
206
	<tr>
207
		<td colspan="6" class="listtopic">
208
			<?=gettext("Peer to Peer Server Instance Statistics"); ?>
209
		</td>
210
	</tr>
211
	<tr>
212
		<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">
213
		<tr>
214
			<td class="listhdrr"><?=gettext("Name"); ?></td>
215
			<td class="listhdrr"><?=gettext("Status"); ?></td>
216
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
217
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
218
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
219
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
220
			<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
221
		</tr>
222

    
223
<?php foreach ($sk_servers as $sk_server): ?>
224
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
225
			<td class="listlr">
226
				<?=$sk_server['name'];?>
227
			</td>
228
			<td class="listlr">
229
				<?=$sk_server['status'];?>
230
			</td>
231
			<td class="listr">
232
				<?=$sk_server['connect_time'];?>
233
			</td>
234
			<td class="listr">
235
				<?=$sk_server['virtual_addr'];?>
236
			</td>
237
			<td class="listr">
238
				<?=$sk_server['remote_host'];?>
239
			</td>
240
			<td class="listr">
241
				<?=$sk_server['bytes_sent'];?>
242
			</td>
243
			<td class="listr">
244
				<?=$sk_server['bytes_recv'];?>
245
			</td>
246
		</tr>
247
<?php endforeach; ?>
248
		</table>
249
	</tr>
250
</table>
251

    
252
<?php
253
} ?>
254
<br>
255
<?php if (!empty($clients)) { ?>
256
<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
257
	<tr>
258
		<td colspan="6" class="listtopic">
259
			<?=gettext("Client Instance Statistics"); ?>
260
		</td>
261
	</tr>
262
	<tr>
263
		<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">
264
		<tr>
265
			<td class="listhdrr"><?=gettext("Name"); ?></td>
266
			<td class="listhdrr"><?=gettext("Status"); ?></td>
267
			<td class="listhdrr"><?=gettext("Connected Since"); ?></td>
268
			<td class="listhdrr"><?=gettext("Virtual Addr"); ?></td>
269
			<td class="listhdrr"><?=gettext("Remote Host"); ?></td>
270
			<td class="listhdrr"><?=gettext("Bytes Sent"); ?></td>
271
			<td class="listhdrr"><?=gettext("Bytes Received"); ?></td>
272
		</tr>
273

    
274
<?php foreach ($clients as $client): ?>
275
		<tr name='<?php echo "r:{$client['port']}:{$conn['remote_host']}"; ?>'>
276
			<td class="listlr">
277
				<?=$client['name'];?>
278
			</td>
279
			<td class="listlr">
280
				<?=$client['status'];?>
281
			</td>
282
			<td class="listr">
283
				<?=$client['connect_time'];?>
284
			</td>
285
			<td class="listr">
286
				<?=$client['virtual_addr'];?>
287
			</td>
288
			<td class="listr">
289
				<?=$client['remote_host'];?>
290
			</td>
291
			<td class="listr">
292
				<?=$client['bytes_sent'];?>
293
			</td>
294
			<td class="listr">
295
				<?=$client['bytes_recv'];?>
296
			</td>
297
		</tr>
298
<?php endforeach; ?>
299
		</table>
300
	</tr>
301
</table>
302

    
303
<?php 
304
}
305

    
306
if ($DisplayNote) {
307
	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");
308
}
309

    
310
if ((empty($clients)) && (empty($servers)) && (empty($sk_servers))) {
311
	echo gettext("No OpenVPN instance defined");
312
}
313
?>
314

    
315

    
316
<?php include("fend.inc"); ?>
(189-189/249)