Project

General

Profile

Download (3.85 KB) Statistics
| Branch: | Tag: | Revision:
1 03dfcbc7 Scott Ullrich
#!/usr/local/bin/php
2
<?php 
3
/*
4
	HEAD
5
	status_ovpn.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7
	
8
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
9
	Copyright (C) 2005-2006 Peter Allgeyer <allgeyer@web.de>.
10
	All rights reserved.
11
	
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14
	
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17
	
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21
	
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
34
$pgtitle = array("Status", "OpenVPN");
35
require("guiconfig.inc");
36
37
$client_list = array();
38
$virtip_list = array();
39
40
function dump_log($type) {
41
	global $g, $config;
42
43
	unset($client_list);
44
	$client_list = array();
45
46
	unset($virtip_list);
47
	$virtip_list = array();
48
			
49
	$max = ($type == 'tun') ? 17 : 4;
50
	for ($i = 0; $i < $max; $i++) {
51 6578832f Scott Ullrich
		if (file_exists("/var/log/openvpn.log")) {
52 03dfcbc7 Scott Ullrich
53
			unset($string);
54
			unset($logarr);
55
			
56 6578832f Scott Ullrich
			exec("/bin/cat /var/log/openvpn.log", $logarr);
57 03dfcbc7 Scott Ullrich
	
58
			foreach ($logarr as $logent) {
59
				$logent = preg_split("/,/", $logent, 5);
60
				$string = preg_split("/:/", $logent[1]);
61
62
				/* search for ip address in second column */
63
				if (isset($string[0]) && is_ipaddr($string[0]))
64
					array_push($client_list, $logent);
65
				
66
				/* search for ip address in first column */
67
				else if (is_ipaddr($logent[0]))
68
					array_push($virtip_list, $logent);
69
			}
70
		}
71
	}
72
73
	if (count($client_list > 1)) {
74
		foreach ($client_list as $cent) {
75
			echo "<tr>\n";
76
			echo "<td class=\"listlr\" nowrap>" . htmlspecialchars($cent[0]) . "</td>\n";
77
			echo "<td class=\"listr\">" . htmlspecialchars($cent[1]) . "</td>\n";
78
79
			unset($found);
80
			if (isset($virtip_list)) {
81
				foreach ($virtip_list as $vent) {
82
					if ($cent[1] == $vent[2]) {
83
						$found = 1;
84
						echo "<td class=\"listr\">" . htmlspecialchars($vent[0]) . "&nbsp;</td>\n";
85
					}
86
				}
87
			}
88
			if (!isset($found))
89
				echo "<td class=\"listr\" align=\"center\">--</td>\n";
90
				
91
			$date = preg_split("/\s+/", $cent[4]);
92
			echo "<td nowrap class=\"listr\">" . htmlspecialchars($date[1]) . " " . htmlspecialchars($date[2]) . " " . htmlspecialchars($date[3]) . "</td>\n";
93
			echo "<td class=\"listr\">" . htmlspecialchars($cent[2]) . "</td>\n";
94
			echo "<td class=\"listr\">" . htmlspecialchars($cent[3]) . "</td>\n";
95
			echo "</tr>\n";
96
		}
97
	}
98
}
99
100
?>
101 a64fd7ff Scott Ullrich
<?php include("head.inc"); ?>
102 03dfcbc7 Scott Ullrich
<?php include("fbegin.inc"); ?>
103
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
104
  <td colspan="6" class="listtopic"> 
105
	    OpenVPN server status entries</td>
106
	</tr>
107
	 <tr>
108
	  <td class="listhdrr">Common Name</td>
109
	  <td class="listhdrr">Real Address</td>
110
	  <td class="listhdrr">Virtual Address</td>
111
	  <td class="listhdrr">Connected Since</td>
112
	  <td class="listhdrr">Bytes Received</td>
113
	  <td class="listhdr">Bytes Sent</td>
114
	</tr>
115
	<?php dump_log(tun); ?>
116
	<?php dump_log(tap); ?>
117
</table>
118
<br>
119
<strong class="red">Note:<br>
120
</strong>Please note that status entries are updated once every minute only.
121
<?php include("fend.inc"); ?>