Project

General

Profile

Download (7.18 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
3
/*
4
	status_wireless.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9
	
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
	
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
	
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
	
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

    
32
require("guiconfig.inc");
33

    
34
function get_wireless_info($ifdescr) {
35
	
36
	global $config, $g;
37
	
38
	$ifinfo = array();
39
	$ifinfo['if'] = $config['interfaces'][$ifdescr]['if'];
40
	
41
	/* get signal strength cache */
42
	exec("/usr/sbin/wicontrol -i " . $ifinfo['if'] . " -C", $sscache);
43
	
44
	$ifinfo['sscache'] = array();
45
	foreach ($sscache as $ss) {
46
		if ($ss) {
47
			$ssa = preg_split("/\s+/", $ss);
48
			$sscent = array();
49
			$sscent['mac'] = chop($ssa[1], ",");
50
			$sscent['ipaddr'] = chop($ssa[2], ",");
51
			$sscent['sig'] = chop($ssa[4], ",");
52
			$sscent['noise'] = chop($ssa[6], ",");
53
			$sscent['qual'] = chop($ssa[8], ",");
54
			$ifinfo['sscache'][] = $sscent;
55
		}
56
	}
57
	
58
	/* if in hostap mode: get associated stations */
59
	if ($config['interfaces'][$ifdescr]['wireless']['mode'] == "hostap") {
60
		exec("/usr/sbin/wicontrol -i " . $ifinfo['if'] . " -l", $aslist);
61
		
62
		$ifinfo['aslist'] = array();
63
		array_shift($aslist);
64
		foreach ($aslist as $as) {
65
			if ($as) {
66
				$asa = preg_split("/\s+/", $as);
67
				$aslent = array();
68
				$aslent['mac'] = $asa[0];
69
				$aslent['rates'] = substr($asa[4], strpos($asa[4], "<")+1,
70
					strpos($asa[4], ">")-strpos($asa[4], "<")-1);
71
				$aslent['sig'] = substr($asa[5], strpos($asa[5], "=")+1);
72
				$ifinfo['aslist'][] = $aslent;
73
			}
74
		}
75
	}
76
	
77
	return $ifinfo;
78
}
79

    
80
?>
81
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
82
<html>
83
<head>
84
<title><?=gentitle("Status: Wireless");?></title>
85
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
86
<link href="gui.css" rel="stylesheet" type="text/css">
87
</head>
88

    
89
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
90
<?php include("fbegin.inc"); ?>
91
      <p class="pgtitle">Status: Wireless</p>
92
              <?php $i = 0; $ifdescrs = array();
93
			  
94
			  		if (is_array($config['interfaces']['wan']['wireless']) &&
95
							strstr($config['interfaces']['wan']['if'], "wi"))
96
							$ifdescrs['wan'] = 'WAN';
97
							
98
			  		if (is_array($config['interfaces']['lan']['wireless']) &&
99
							strstr($config['interfaces']['lan']['if'], "wi"))
100
							$ifdescrs['lan'] = 'LAN';
101
					
102
			  		for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
103
						if (is_array($config['interfaces']['opt' . $j]['wireless']) &&
104
							isset($config['interfaces']['opt' . $j]['enable']) &&
105
							strstr($config['interfaces']['opt' . $j]['if'], "wi"))
106
							$ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
107
					}
108
						
109
					if (count($ifdescrs) > 0): ?>
110
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
111
              <?php
112
			      foreach ($ifdescrs as $ifdescr => $ifname): 
113
				  $ifinfo = get_wireless_info($ifdescr);
114
			  ?>
115
              <?php if ($i): ?>
116
              <tr> 
117
                <td colspan="8" class="list" height="12"></td>
118
              </tr>
119
              <?php endif; ?>
120
              <tr> 
121
                <td colspan="2" class="listtopic"> 
122
                  <?=htmlspecialchars($ifname);?> interface (SSID &quot;<?=htmlspecialchars($config['interfaces'][$ifdescr]['wireless']['ssid']);?>&quot;)</td>
123
              </tr>
124
              <tr> 
125
                <td width="22%" valign="top" class="listhdrr">Signal strength 
126
                  cache</td>
127
                <td width="78%" class="listrpad"> 
128
                  <table width="100%" border="0" cellpadding="0" cellspacing="0">
129
                    <tr> 
130
                      <td width="30%" class="listhdrr">MAC address</td>
131
                      <td width="25%" class="listhdrr">IP address</td>
132
                      <td width="15%" class="listhdrr">Signal</td>
133
                      <td width="15%" class="listhdrr">Noise</td>
134
                      <td width="15%" class="listhdr">Quality</td>
135
                    </tr>
136
                    <?php foreach ($ifinfo['sscache'] as $ss): ?>
137
                    <tr> 
138
                      <td class="listlr"> 
139
                        <?=htmlspecialchars($ss['mac']);?>
140
                      </td>
141
                      <td class="listr"> 
142
                        <?=htmlspecialchars($ss['ipaddr']);?>
143
                      </td>
144
                      <td class="listr"> 
145
                        <?=htmlspecialchars($ss['sig']);?>
146
                      </td>
147
                      <td class="listr"> 
148
                        <?=htmlspecialchars($ss['noise']);?>
149
                      </td>
150
                      <td class="listr"> 
151
                        <?=htmlspecialchars($ss['qual']);?>
152
                      </td>
153
                    </tr>
154
                    <?php endforeach; ?>
155
                  </table></td>
156
              </tr><?php if ($ifinfo['aslist']): ?>
157
              <tr> 
158
                <td width="22%" valign="top" class="listhdrr">Associated stations 
159
                </td>
160
                <td width="78%" class="listrpad"> 
161
                  <table width="100%" border="0" cellpadding="0" cellspacing="0">
162
                    <tr> 
163
                      <td width="40%" class="listhdrr">MAC address</td>
164
                      <td width="40%" class="listhdrr">TX rates</td>
165
                      <td width="20%" class="listhdrr">Signal</td>
166
                    </tr>
167
                    <?php foreach ($ifinfo['aslist'] as $as): ?>
168
                    <tr> 
169
                      <td class="listlr"> 
170
                        <?=htmlspecialchars($as['mac']);?>
171
                      </td>
172
                      <td class="listr"> 
173
                        <?=htmlspecialchars($as['rates']);?>
174
                      </td>
175
                      <td class="listr"> 
176
                        <?=htmlspecialchars($as['sig']);?>
177
                      </td>
178
                    </tr>
179
                    <?php endforeach; ?>
180
                  </table></td>
181
              </tr><?php endif; ?>
182
              <?php $i++; endforeach; ?>
183
            </table>
184
<?php else: ?>
185
<p><strong>No supported wireless interfaces were found for status display.</strong></p>
186
<?php endif; ?>
187
<?php include("fend.inc"); ?>
188
</body>
189
</html>
(72-72/90)