Project

General

Profile

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