Project

General

Profile

Download (7.43 KB) Statistics
| Branch: | Tag: | Revision:
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;
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
This program is currently undergoing changes and is broke.  Check back before release!
94

    
95
<?php
96

    
97
exit;
98

    
99
?>
100

    
101
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
102
<?php include("fbegin.inc"); ?>
103
<p class="pgtitle"><?=$pgtitle?></p>
104
<?php $i = 0; $ifdescrs = array();
105

    
106
	if (is_array($config['interfaces']['wan']['wireless']) &&
107
			preg_match($g['wireless_regex'], $config['interfaces']['wan']['if']))
108
			$ifdescrs['wan'] = 'WAN';
109
			
110
	if (is_array($config['interfaces']['lan']['wireless']) &&
111
			preg_match($g['wireless_regex'], $config['interfaces']['lan']['if']))
112
			$ifdescrs['lan'] = 'LAN';
113
	
114
	for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
115
		if (is_array($config['interfaces']['opt' . $j]['wireless']) &&
116
			isset($config['interfaces']['opt' . $j]['enable']) &&
117
			preg_match($g['wireless_regex'], $config['interfaces']['opt' . $j]['if']))
118
			$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
119
	}
120
		
121
	if (count($ifdescrs) > 0): ?>
122
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
123
              <?php
124
			      foreach ($ifdescrs as $ifdescr => $ifname): 
125
				  $ifinfo = get_wireless_info($ifdescr);
126
			  ?>
127
              <?php if ($i): ?>
128
              <tr> 
129
                <td colspan="8" class="list" height="12"></td>
130
              </tr>
131
              <?php endif; ?>
132
              <tr> 
133
                <td colspan="2" class="listtopic"> 
134
                  <?=htmlspecialchars($ifname);?> interface (SSID &quot;<?=htmlspecialchars($config['interfaces'][$ifdescr]['wireless']['ssid']);?>&quot;)</td>
135
              </tr>
136
              <tr> 
137
                <td width="22%" valign="top" class="vncellt">Signal strength 
138
                  cache</td>
139
                <td width="78%" class="listrpad"> 
140
                  <table width="100%" border="0" cellpadding="0" cellspacing="0">
141
                    <tr> 
142
                      <td width="30%" class="listhdrr">MAC address</td>
143
                      <td width="25%" class="listhdrr">IP address</td>
144
                      <td width="15%" class="listhdrr">Signal</td>
145
                      <td width="15%" class="listhdrr">Noise</td>
146
                      <td width="15%" class="listhdr">Quality</td>
147
                    </tr>
148
                    <?php foreach ($ifinfo['sscache'] as $ss): ?>
149
		    <?php if($ss['ipaddr'] <> "0.0.0.0"
150
			  and $ss['ipaddr'] <> ""): ?>
151
                    <tr>                                 
152
                      <td class="listlr"> 
153
                        <?=htmlspecialchars($ss['mac']);?>
154
                      </td>
155
                      <td class="listr"> 
156
                        <?=htmlspecialchars($ss['ipaddr']);?>
157
                      </td>
158
                      <td class="listr"> 
159
                        <?=htmlspecialchars($ss['sig']);?>
160
                      </td>
161
                      <td class="listr"> 
162
                        <?=htmlspecialchars($ss['noise']);?>
163
                      </td>
164
                      <td class="listr"> 
165
                        <?=htmlspecialchars($ss['qual']);?>
166
                      </td>
167
                    </tr>
168
		    <?php endif; ?>
169
                    <?php endforeach; ?>
170
                  </table></td>
171
              </tr><?php if ($ifinfo['aslist']): ?>
172
              <tr> 
173
                <td width="22%" valign="top" class="vncellt">Associated stations 
174
                </td>
175
                <td width="78%" class="listrpad"> 
176
                  <table width="100%" border="0" cellpadding="0" cellspacing="0">
177
                    <tr> 
178
                      <td width="40%" class="listhdrr">BSSID</td>
179
                      <td width="30%" class="listhdrr">Signal</td>
180
                      <td width="30%" class="listhdrr">Noise</td>
181
                    </tr>
182
                    <?php foreach ($ifinfo['aslist'] as $as): ?>
183
                    <tr> 
184
                      <td class="listlr"> 
185
                        <?=htmlspecialchars($as['bssid']);?>
186
                      </td>
187
                      <td class="listr"> 
188
                        <?=htmlspecialchars($as['sig']);?> dBm
189
                      </td>
190
                      <td class="listr"> 
191
                        <?=htmlspecialchars($as['noise']);?> dBm
192
                      </td>
193
                    </tr>
194
                    <?php endforeach; ?>
195
                  </table></td>
196
              </tr><?php endif; ?>
197
              <?php $i++; endforeach; ?>
198
            </table>
199
<?php else: ?>
200
<strong>No supported wireless interfaces were found for status display (only cards that use the wi[n], ath[n], an[n], ral[n], ural[n] and wai[n] driver are supported).</strong>
201
<?php endif; ?>
202
<?php include("fend.inc"); ?>
(116-116/147)