1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
status_wireless.php
|
6
|
part of m0n0wall (http://m0n0.ch/wall)
|
7
|
|
8
|
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
|
33
|
require("guiconfig.inc");
|
34
|
|
35
|
function get_wireless_info($ifdescr) {
|
36
|
|
37
|
global $config, $g;
|
38
|
|
39
|
$ifinfo = array();
|
40
|
$ifinfo['if'] = $config['interfaces'][$ifdescr]['if'];
|
41
|
|
42
|
/* get signal strength cache */
|
43
|
exec("/usr/sbin/wicontrol -i " . $ifinfo['if'] . " -C", $sscache);
|
44
|
|
45
|
$ifinfo['sscache'] = array();
|
46
|
foreach ($sscache as $ss) {
|
47
|
if ($ss) {
|
48
|
$ssa = preg_split("/\s+/", $ss);
|
49
|
$sscent = array();
|
50
|
$sscent['mac'] = chop($ssa[1], ",");
|
51
|
$sscent['ipaddr'] = chop($ssa[2], ",");
|
52
|
$sscent['sig'] = chop($ssa[4], ",");
|
53
|
$sscent['noise'] = chop($ssa[6], ",");
|
54
|
$sscent['qual'] = chop($ssa[8], ",");
|
55
|
$ifinfo['sscache'][] = $sscent;
|
56
|
}
|
57
|
}
|
58
|
|
59
|
/* if in hostap mode: get associated stations */
|
60
|
if ($config['interfaces'][$ifdescr]['wireless']['mode'] == "hostap") {
|
61
|
exec("/usr/sbin/wicontrol -i " . $ifinfo['if'] . " -l", $aslist);
|
62
|
|
63
|
$ifinfo['aslist'] = array();
|
64
|
array_shift($aslist);
|
65
|
foreach ($aslist as $as) {
|
66
|
if ($as) {
|
67
|
if (preg_match("/^ap/", $as)) {
|
68
|
if (is_array($aslent) && count($aslent))
|
69
|
$ifinfo['aslist'][] = $aslent;
|
70
|
$aslent = array();
|
71
|
} else if (preg_match("/BSSID:\s*\[ (.*) \]/", $as, $matches)) {
|
72
|
$aslent['bssid'] = $matches[1];
|
73
|
} else if (preg_match("/\[dBm\]:\s*\[ .* \/ (.*) \/ (.*) \]/", $as, $matches)) {
|
74
|
$aslent['sig'] = $matches[1];
|
75
|
$aslent['noise'] = $matches[2];
|
76
|
}
|
77
|
}
|
78
|
}
|
79
|
if (is_array($aslent) && count($aslent))
|
80
|
$ifinfo['aslist'][] = $aslent;
|
81
|
}
|
82
|
|
83
|
return $ifinfo;
|
84
|
}
|
85
|
|
86
|
$pgtitle = "Status: Wireless";
|
87
|
include("head.inc");
|
88
|
|
89
|
?>
|
90
|
|
91
|
<form>
|
92
|
|
93
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
94
|
<?php include("fbegin.inc"); ?>
|
95
|
<p class="pgtitle"><?=$pgtitle?></p>
|
96
|
<?php $i = 0; $ifdescrs = array();
|
97
|
|
98
|
if (is_array($config['interfaces']['wan']['wireless']) &&
|
99
|
(strstr($config['interfaces']['wan']['if'], "wi") || strstr($config['interfaces']['wan']['if'], "ath")))
|
100
|
$ifdescrs['wan'] = 'WAN';
|
101
|
|
102
|
if (is_array($config['interfaces']['lan']['wireless']) &&
|
103
|
(strstr($config['interfaces']['lan']['if'], "wi") || strstr($config['interfaces']['lan']['if'], "ath")))
|
104
|
$ifdescrs['lan'] = 'LAN';
|
105
|
|
106
|
for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
|
107
|
if (is_array($config['interfaces']['opt' . $j]['wireless']) &&
|
108
|
isset($config['interfaces']['opt' . $j]['enable']) &&
|
109
|
(strstr($config['interfaces']['opt' . $j]['if'], "wi") || strstr($config['interfaces']['opt' . $j]['if'], "ath")))
|
110
|
$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
|
111
|
}
|
112
|
|
113
|
if (count($ifdescrs) > 0): ?>
|
114
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
115
|
<?php
|
116
|
foreach ($ifdescrs as $ifdescr => $ifname):
|
117
|
$ifinfo = get_wireless_info($ifdescr);
|
118
|
?>
|
119
|
<?php if ($i): ?>
|
120
|
<tr>
|
121
|
<td colspan="8" class="list" height="12"></td>
|
122
|
</tr>
|
123
|
<?php endif; ?>
|
124
|
<tr>
|
125
|
<td colspan="2" class="listtopic">
|
126
|
<?=htmlspecialchars($ifname);?> interface (SSID "<?=htmlspecialchars($config['interfaces'][$ifdescr]['wireless']['ssid']);?>")</td>
|
127
|
</tr>
|
128
|
<tr>
|
129
|
<td width="22%" valign="top" class="vncellt">Signal strength
|
130
|
cache</td>
|
131
|
<td width="78%" class="listrpad">
|
132
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
133
|
<tr>
|
134
|
<td width="30%" class="listhdrr">MAC address</td>
|
135
|
<td width="25%" class="listhdrr">IP address</td>
|
136
|
<td width="15%" class="listhdrr">Signal</td>
|
137
|
<td width="15%" class="listhdrr">Noise</td>
|
138
|
<td width="15%" class="listhdr">Quality</td>
|
139
|
</tr>
|
140
|
<?php foreach ($ifinfo['sscache'] as $ss): ?>
|
141
|
<tr>
|
142
|
<td class="listlr">
|
143
|
<?=htmlspecialchars($ss['mac']);?>
|
144
|
</td>
|
145
|
<td class="listr">
|
146
|
<?=htmlspecialchars($ss['ipaddr']);?>
|
147
|
</td>
|
148
|
<td class="listr">
|
149
|
<?=htmlspecialchars($ss['sig']);?>
|
150
|
</td>
|
151
|
<td class="listr">
|
152
|
<?=htmlspecialchars($ss['noise']);?>
|
153
|
</td>
|
154
|
<td class="listr">
|
155
|
<?=htmlspecialchars($ss['qual']);?>
|
156
|
</td>
|
157
|
</tr>
|
158
|
<?php endforeach; ?>
|
159
|
</table></td>
|
160
|
</tr><?php if ($ifinfo['aslist']): ?>
|
161
|
<tr>
|
162
|
<td width="22%" valign="top" class="vncellt">Associated stations
|
163
|
</td>
|
164
|
<td width="78%" class="listrpad">
|
165
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
166
|
<tr>
|
167
|
<td width="40%" class="listhdrr">BSSID</td>
|
168
|
<td width="30%" class="listhdrr">Signal</td>
|
169
|
<td width="30%" class="listhdrr">Noise</td>
|
170
|
</tr>
|
171
|
<?php foreach ($ifinfo['aslist'] as $as): ?>
|
172
|
<tr>
|
173
|
<td class="listlr">
|
174
|
<?=htmlspecialchars($as['bssid']);?>
|
175
|
</td>
|
176
|
<td class="listr">
|
177
|
<?=htmlspecialchars($as['sig']);?> dBm
|
178
|
</td>
|
179
|
<td class="listr">
|
180
|
<?=htmlspecialchars($as['noise']);?> dBm
|
181
|
</td>
|
182
|
</tr>
|
183
|
<?php endforeach; ?>
|
184
|
</table></td>
|
185
|
</tr><?php endif; ?>
|
186
|
<?php $i++; endforeach; ?>
|
187
|
</table>
|
188
|
<?php else: ?>
|
189
|
<strong>No supported wireless interfaces were found for status display (only cards that use the wi[n] or ath[n] driver are supported).</strong>
|
190
|
<?php endif; ?>
|
191
|
<?php include("fend.inc"); ?>
|