Project

General

Profile

Download (4.05 KB) Statistics
| Branch: | Tag: | Revision:
1 63084885 Matthew Grooms
<?php 
2
/*
3
	status_ovpenvpn.php
4
5
    Copyright (C) 2008 Shrew Soft Inc.
6
    All rights reserved.
7
	
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10
	
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13
	
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17
	
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29 61dda8f7 Matthew Grooms
/* DISABLE_PHP_LINT_CHECKING */
30 63084885 Matthew Grooms
31
##|+PRIV
32
##|*IDENT=page-status-openvpn
33
##|*NAME=Status: OpenVPN page
34
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
35
##|*MATCH=status_openvpn.php*
36
##|-PRIV
37
38
39
$pgtitle = array("Status", "OpenVPN");
40
require("guiconfig.inc");
41
42
$servers = array();
43
44
if (is_array($config['openvpn']['openvpn-server'])) {
45
	foreach ($config['openvpn']['openvpn-server'] as & $settings) {
46
47
		$prot = $settings['protocol'];
48
		$port = $settings['local_port'];
49
50
		$server = array();
51
		if ($settings['description'])
52
			$server['name'] = "{$settings['description']} {$prot}:{$port}";
53
		else
54
			$server['name'] = "Server {$prot}:{$port}";
55
		$server['conns'] = array();
56
57
		$tcpsrv = "tcp://127.0.0.1:{$port}";
58
		$errval;
59
		$errstr;
60
61
		/* open a tcp connection to the management port of each server */
62
		$fp = stream_socket_client($tcpsrv, $errval, $errstr, 1);
63
		if ($fp) {
64
65
			/* send our status request */
66
			fputs($fp, "status 2\n");
67
68
			/* recv all response lines */
69
			$buff = "";
70
			while (!feof($fp)) {
71
72
				/* read the next line */
73
				$line = fgets($fp, 1024);
74
75
				/* parse header list line */
76
				if (strstr($line, "HEADER"))
77
					continue;
78
79
				/* parse end of output line */
80
				if (strstr($line, "END"))
81
					break;
82
83
				/* parse client list line */
84
				if (strstr($line, "CLIENT_LIST")) {
85
					$list = explode(",", $line);
86
					$conn = array();
87
					$conn['common_name'] = $list[1];
88
					$conn['remote_host'] = $list[2];
89
					$conn['virtual_addr'] = $list[3];
90
					$conn['bytes_recv'] = $list[4];
91
					$conn['bytes_sent'] = $list[5];
92
					$conn['connect_time'] = $list[6];
93
					$server['conns'][] = $conn;
94
				}
95
			}
96
97
			/* cleanup */
98
			fclose($fp);
99
		}
100
101
		$servers[] = $server;
102
	}
103
}
104
105
include("head.inc");
106
include("fbegin.inc");
107
108
echo $buff;
109
110
?>
111
	<?php foreach ($servers as $server): ?>
112
113
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
114
		<tr>
115
			<td colspan="6" class="listtopic"> 
116
				Client connections for <?=$server['name'];?>
117
			</td>
118
		</tr>
119
		<tr>
120
			<td class="listhdrr">Common Name</td>
121
			<td class="listhdrr">Real Address</td>
122
			<td class="listhdrr">Virtual Address</td>
123
			<td class="listhdrr">Connected Since</td>
124
			<td class="listhdrr">Bytes Sent</td>
125
			<td class="listhdrr">Bytes Received</td>
126
		</tr>
127
128
		<?php foreach ($server['conns'] as $conn): ?>
129
		<tr>
130
			<td class="listlr">
131
				<?=$conn['common_name'];?>
132
			</td>
133
			<td class="listr">
134
				<?=$conn['remote_host'];?>
135
			</td>
136
			<td class="listr">
137
				<?=$conn['virtual_addr'];?>
138
			</td>
139
			<td class="listr">
140
				<?=$conn['connect_time'];?>
141
			</td>
142
			<td class="listr">
143
				<?=$conn['bytes_sent'];?>
144
			</td>
145
			<td class="listr">
146
				<?=$conn['bytes_recv'];?>
147
			</td>
148
		</tr>
149 61dda8f7 Matthew Grooms
150
		<?php endforeach; ?>
151 63084885 Matthew Grooms
		<tr>
152
			<td colspan="6" class="list" height="12"></td>
153
		</tr>
154
155
	</table>
156
157
	<?php endforeach; ?>
158
159
<?php include("fend.inc"); ?>