Project

General

Profile

Download (9.02 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php 
2
/* $Id$ */
3
/*
4
	interfaces_wlan.inc
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7
	Copyright (C) 2003-2005 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
$wlchannels = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,42,44,48,50,52,56,58,60,64,149,152,153,157,160,161,165);
33

    
34
function wireless_config_init() {
35
	global $optcfg, $pconfig;
36
	
37
	$pconfig['standard'] = $optcfg['wireless']['standard'];
38
	$pconfig['mode'] = $optcfg['wireless']['mode'];
39
	$pconfig['ssid'] = $optcfg['wireless']['ssid'];
40
	$pconfig['stationname'] = $optcfg['wireless']['stationname'];
41
	$pconfig['channel'] = $optcfg['wireless']['channel'];
42
	$pconfig['wep_enable'] = isset($optcfg['wireless']['wep']['enable']);
43
	
44
	if (is_array($optcfg['wireless']['wep']['key'])) {
45
		$i = 1;
46
		foreach ($optcfg['wireless']['wep']['key'] as $wepkey) {
47
			$pconfig['key' . $i] = $wepkey['value'];
48
			if (isset($wepkey['txkey']))
49
				$pconfig['txkey'] = $i;
50
			$i++;
51
		}
52
		if (!isset($wepkey['txkey']))
53
			$pconfig['txkey'] = 1;
54
	}
55
}
56

    
57
function wireless_config_post() {
58
	global $optcfg, $pconfig;
59

    
60
	unset($input_errors);
61

    
62
	/* input validation */
63
	if ($_POST['enable']) {
64
		$reqdfields = explode(" ", "mode ssid channel");
65
		$reqdfieldsn = explode(",", "Mode,SSID,Channel");
66
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
67
		
68
		if (!$input_errors) {
69
			/* bridge check (hostap only!) */
70
			if ($pconfig['bridge'] && ($pconfig['mode'] != "hostap"))
71
				$input_errors[] = "Bridging a wireless interface is only possible in hostap mode.";
72
		}
73
	}
74

    
75
	if (!$input_errors) {
76
	
77
		$optcfg['wireless']['standard'] = $_POST['standard'];
78
		$optcfg['wireless']['mode'] = $_POST['mode'];
79
		$optcfg['wireless']['ssid'] = $_POST['ssid'];
80
		$optcfg['wireless']['stationname'] = $_POST['stationname'];
81
		$optcfg['wireless']['channel'] = $_POST['channel'];
82
		$optcfg['wireless']['wep']['enable'] = $_POST['wep_enable'] ? true : false;
83
		
84
		$optcfg['wireless']['wep']['key'] = array();
85
		for ($i = 1; $i <= 4; $i++) {
86
			if ($_POST['key' . $i]) {
87
				$newkey = array();
88
				$newkey['value'] = $_POST['key' . $i];
89
				if ($_POST['txkey'] == $i)
90
					$newkey['txkey'] = true;
91
				$optcfg['wireless']['wep']['key'][] = $newkey;
92
			}
93
		}
94
	}
95
	
96
	return $input_errors;
97
}
98

    
99
function wireless_config_print() {
100
	global $optcfg, $pconfig, $wlchannels;
101
?>
102
                <tr> 
103
                  <td colspan="2" valign="top" height="16"></td>
104
				</tr>
105
                <tr> 
106
                  <td colspan="2" valign="top" class="listtopic">Wireless configuration</td>
107
				</tr>
108
				
109
				<?php if (stristr($optcfg['if'], "ath") == true): ?>
110
                <tr> 
111
                  <td valign="top" class="vncellreq">Standard</td>
112
                  <td class="vtable"><select name="standard" class="formfld" id="standard">
113
                      <?php
114
					  $standards = array("11b" => "802.11b", "11g" => "802.11g", "11a" => "802.11a");
115
					  foreach ($standards as $sn => $sv): ?>
116
                      <option value="<?=$sn;?>" <?php if ($sn == $pconfig['standard']) echo "selected";?>>
117
                      <?=$sv;?>
118
                      </option>
119
                      <?php endforeach; ?>
120
                    </select></td>
121
                </tr>
122
				<?php endif; ?>
123
                <tr> 
124
                  <td valign="top" class="vncellreq">Mode</td>
125
                  <td class="vtable"><select name="mode" class="formfld" id="mode">
126
                      <?php 
127
						$opts = array();
128
						if (strstr($optcfg['if'], "wi") ||
129
							strstr($optcfg['if'], "ath"))
130
							$opts[] = "hostap";
131
						$opts[] = "BSS";
132
						$opts[] = "IBSS";
133
				foreach ($opts as $opt): ?>
134
                      <option <?php if ($opt == $pconfig['mode']) echo "selected";?>> 
135
                      <?=htmlspecialchars($opt);?>
136
                      </option>
137
                      <?php endforeach; ?>
138
                    </select> <br>
139
                    Note: IBSS mode is sometimes also called &quot;ad-hoc&quot; 
140
                    mode;<br>
141
                    BSS mode is also known as &quot;infrastructure&quot; mode</td>
142
				</tr>
143
                <tr> 
144
                  <td valign="top" class="vncellreq">SSID</td>
145
                  <td class="vtable"><?=$mandfldhtml;?><input name="ssid" type="text" class="formfld" id="ssid" size="20" value="<?=htmlspecialchars($pconfig['ssid']);?>">
146
                  </td>
147
                </tr>
148
                <tr> 
149
                  <td valign="top" class="vncellreq">Channel</td>
150
                  <td class="vtable"><select name="channel" class="formfld" id="channel">
151
                      <option <?php if ($pconfig['channel'] == 0) echo "selected";?> value="0">Auto</option>
152
                      <?php
153
					  foreach ($wlchannels as $channel): ?>
154
                      <option <?php if ($channel == $pconfig['channel']) echo "selected";?> value="<?=$channel;?>">
155
                      <?=$channel;?>
156
                      </option>
157
                      <?php endforeach; ?>
158
                    </select> <br>
159
                    Note: Not all channels may be supported by your card</td>
160
                </tr>
161
                <tr> 
162
                  <td valign="top" class="vncell">Station name</td>
163
                  <td class="vtable"><input name="stationname" type="text" class="formfld" id="stationname" size="20" value="<?=htmlspecialchars($pconfig['stationname']);?>"> 
164
                    <br>
165
                    Hint: this field can usually be left blank</td>
166
                </tr>
167
                <tr> 
168
                  <td valign="top" class="vncell">WEP</td>
169
                  <td class="vtable"> <input name="wep_enable" type="checkbox" id="wep_enable" value="yes" <?php if ($pconfig['wep_enable']) echo "checked"; ?>> 
170
                    <strong>Enable WEP</strong>
171
                    <table border="0" cellspacing="0" cellpadding="0">
172
                      <tr> 
173
                        <td>&nbsp;</td>
174
                        <td>&nbsp;</td>
175
                        <td>&nbsp;TX key&nbsp;</td>
176
                      </tr>
177
                      <tr> 
178
                        <td>Key 1:&nbsp;&nbsp;</td>
179
                        <td> <input name="key1" type="text" class="formfld" id="key1" size="30" value="<?=htmlspecialchars($pconfig['key1']);?>"></td>
180
                        <td align="center"> <input name="txkey" type="radio" value="1" <?php if ($pconfig['txkey'] == 1) echo "checked";?>> 
181
                        </td>
182
                      </tr>
183
                      <tr> 
184
                        <td>Key 2:&nbsp;&nbsp;</td>
185
                        <td> <input name="key2" type="text" class="formfld" id="key2" size="30" value="<?=htmlspecialchars($pconfig['key2']);?>"></td>
186
                        <td align="center"> <input name="txkey" type="radio" value="2" <?php if ($pconfig['txkey'] == 2) echo "checked";?>></td>
187
                      </tr>
188
                      <tr> 
189
                        <td>Key 3:&nbsp;&nbsp;</td>
190
                        <td> <input name="key3" type="text" class="formfld" id="key3" size="30" value="<?=htmlspecialchars($pconfig['key3']);?>"></td>
191
                        <td align="center"> <input name="txkey" type="radio" value="3" <?php if ($pconfig['txkey'] == 3) echo "checked";?>></td>
192
                      </tr>
193
                      <tr> 
194
                        <td>Key 4:&nbsp;&nbsp;</td>
195
                        <td> <input name="key4" type="text" class="formfld" id="key4" size="30" value="<?=htmlspecialchars($pconfig['key4']);?>"></td>
196
                        <td align="center"> <input name="txkey" type="radio" value="4" <?php if ($pconfig['txkey'] == 4) echo "checked";?>></td>
197
                      </tr>
198
                    </table>
199
                    <br>
200
                    40 (64) bit keys may be entered as 5 ASCII characters or 10 
201
                    hex digits preceded by '0x'.<br>
202
                    104 (128) bit keys may be entered as 13 ASCII characters or 
203
                    26 hex digits preceded by '0x'.</td>
204
                </tr>
205
<?php } ?>
(56-56/117)