Project

General

Profile

Download (4.46 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
/* DISABLE_PHP_LINT_CHECKING */
30
/*	
31
	pfSense_MODULE:	openvpn
32
*/
33

    
34
##|+PRIV
35
##|*IDENT=page-status-openvpn
36
##|*NAME=Status: OpenVPN page
37
##|*DESCR=Allow access to the 'Status: OpenVPN' page.
38
##|*MATCH=status_openvpn.php*
39
##|-PRIV
40

    
41
$pgtitle = array("Status", "OpenVPN");
42
require("guiconfig.inc");
43
require_once("vpn.inc");
44

    
45
$servers = array();
46

    
47
if (is_array($config['openvpn']['openvpn-server'])) {
48
	foreach ($config['openvpn']['openvpn-server'] as & $settings) {
49

    
50
		$prot = $settings['protocol'];
51
		$port = $settings['local_port'];
52

    
53
		$server = array();
54
		if ($settings['description'])
55
			$server['name'] = "{$settings['description']} {$prot}:{$port}";
56
		else
57
			$server['name'] = "Server {$prot}:{$port}";
58
		$server['conns'] = array();
59

    
60
		$tcpsrv = "tcp://127.0.0.1:{$port}";
61
		$errval;
62
		$errstr;
63

    
64
		/* open a tcp connection to the management port of each server */
65
		$fp = stream_socket_client($tcpsrv, $errval, $errstr, 1);
66
		if ($fp) {
67

    
68
			/* send our status request */
69
			fputs($fp, "status 2\n");
70

    
71
			/* recv all response lines */
72
			$buff = "";
73
			while (!feof($fp)) {
74

    
75
				/* read the next line */
76
				$line = fgets($fp, 1024);
77

    
78
				/* parse header list line */
79
				if (strstr($line, "HEADER"))
80
					continue;
81

    
82
				/* parse end of output line */
83
				if (strstr($line, "END"))
84
					break;
85

    
86
				/* parse client list line */
87
				if (strstr($line, "CLIENT_LIST")) {
88
					$list = explode(",", $line);
89
					$conn = array();
90
					$conn['common_name'] = $list[1];
91
					$conn['remote_host'] = $list[2];
92
					$conn['virtual_addr'] = $list[3];
93
					$conn['bytes_recv'] = $list[4];
94
					$conn['bytes_sent'] = $list[5];
95
					$conn['connect_time'] = $list[6];
96
					$server['conns'][] = $conn;
97
				}
98
			}
99

    
100
			/* cleanup */
101
			fclose($fp);
102
		}
103

    
104
		$servers[] = $server;
105
	}
106
}
107

    
108
include("head.inc");
109
include("fbegin.inc");
110

    
111
echo $buff;
112

    
113
?>
114
	<?php foreach ($servers as $server): ?>
115

    
116
	<table style="padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px" width="100%" border="0" cellpadding="0" cellspacing="0">
117
		<tr>
118
			<td colspan="6" class="listtopic"> 
119
				Client connections for <?=$server['name'];?>
120
			</td>
121
		</tr>
122
		<tr>
123
			<td>
124
				<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">
125
				<tr>
126
					<td class="listhdrr">Common Name</td>
127
					<td class="listhdrr">Real Address</td>
128
					<td class="listhdrr">Virtual Address</td>
129
					<td class="listhdrr">Connected Since</td>
130
					<td class="listhdrr">Bytes Sent</td>
131
					<td class="listhdrr">Bytes Received</td>
132
				</tr>
133

    
134
				<?php foreach ($server['conns'] as $conn): ?>
135
				<tr>
136
					<td class="listlr">
137
						<?=$conn['common_name'];?>
138
					</td>
139
					<td class="listr">
140
						<?=$conn['remote_host'];?>
141
					</td>
142
					<td class="listr">
143
						<?=$conn['virtual_addr'];?>
144
					</td>
145
					<td class="listr">
146
						<?=$conn['connect_time'];?>
147
					</td>
148
					<td class="listr">
149
						<?=$conn['bytes_sent'];?>
150
					</td>
151
					<td class="listr">
152
						<?=$conn['bytes_recv'];?>
153
					</td>
154
				</tr>
155

    
156
				<?php endforeach; ?>
157
				<tr>
158
					<td colspan="6" class="list" height="12"></td>
159
				</tr>
160

    
161
			</table>
162
			</td>
163
		</tr>
164
	</table>
165

    
166
	<?php endforeach; ?>
167

    
168
<?php include("fend.inc"); ?>
(155-155/214)