Project

General

Profile

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

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

    
53
function wireless_config_post() {
54
	global $optcfg, $pconfig;
55

    
56
	unset($input_errors);
57

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

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

    
94
function wireless_config_print() {
95
	global $optcfg, $pconfig;
96
?>
97
                <tr> 
98
                  <td colspan="2" valign="top" height="16"></td>
99
				</tr>
100
                <tr> 
101
                  <td colspan="2" valign="top" class="listtopic">Wireless configuration</td>
102
				</tr>
103
                <tr> 
104
                  <td valign="top" class="vncellreq">Mode</td>
105
                  <td class="vtable"> <select name="mode" class="formfld" id="mode">
106
                      <?php 
107
						$opts = array();
108
						if (strstr($optcfg['if'], "wi"))
109
							$opts[] = "hostap";
110
						$opts[] = "BSS";
111
						$opts[] = "IBSS";
112
				foreach ($opts as $opt): ?>
113
                      <option <?php if ($opt == $pconfig['mode']) echo "selected";?>> 
114
                      <?=htmlspecialchars($opt);?>
115
                      </option>
116
                      <?php endforeach; ?>
117
                    </select> <br>
118
                    Note: IBSS mode is sometimes also called &quot;ad-hoc&quot; 
119
                    mode;<br>
120
                    BSS mode is also known as &quot;infrastructure&quot; mode</td>
121
				</tr>
122
                <tr> 
123
                  <td valign="top" class="vncellreq">SSID</td>
124
                  <td class="vtable"><input name="ssid" type="text" class="formfld" id="ssid" size="20" value="<?=htmlspecialchars($pconfig['ssid']);?>">
125
                  </td>
126
                </tr>
127
                <tr> 
128
                  <td valign="top" class="vncellreq">Channel</td>
129
                  <td class="vtable"><select name="channel" class="formfld" id="channel">
130
                      <?php
131
					  for ($i = 0; $i <= 14; $i++): ?>
132
                      <option <?php if ($i == $pconfig['channel']) echo "selected";?>>
133
                      <? echo($i==0 ? "Auto" : $i) ?>
134
                      </option>
135
                      <?php endfor; ?>
136
                    </select></td>
137
                </tr>
138
                <tr> 
139
                  <td valign="top" class="vncell">Station name</td>
140
                  <td class="vtable"><input name="stationname" type="text" class="formfld" id="stationname" size="20" value="<?=htmlspecialchars($pconfig['stationname']);?>"> 
141
                    <br>
142
                    Hint: this field can usually be left blank</td>
143
                </tr>
144
                <tr> 
145
                  <td valign="top" class="vncell">WEP</td>
146
                  <td class="vtable"> <input name="wep_enable" type="checkbox" id="wep_enable" value="yes" <?php if ($pconfig['wep_enable']) echo "checked"; ?>> 
147
                    <strong>Enable WEP</strong><br>
148
                    &nbsp; <table border="0" cellspacing="0" cellpadding="0">
149
                      <tr> 
150
                        <td>&nbsp;</td>
151
                        <td>&nbsp;</td>
152
                        <td>&nbsp;TX key&nbsp;</td>
153
                      </tr>
154
                      <tr> 
155
                        <td>Key 1:&nbsp;&nbsp;</td>
156
                        <td> <input name="key1" type="text" class="formfld" id="key1" size="30" value="<?=htmlspecialchars($pconfig['key1']);?>"></td>
157
                        <td align="center"> <input name="txkey" type="radio" value="1" <?php if ($pconfig['txkey'] == 1) echo "checked";?>> 
158
                        </td>
159
                      </tr>
160
                      <tr> 
161
                        <td>Key 2:&nbsp;&nbsp;</td>
162
                        <td> <input name="key2" type="text" class="formfld" id="key2" size="30" value="<?=htmlspecialchars($pconfig['key2']);?>"></td>
163
                        <td align="center"> <input name="txkey" type="radio" value="2" <?php if ($pconfig['txkey'] == 2) echo "checked";?>></td>
164
                      </tr>
165
                      <tr> 
166
                        <td>Key 3:&nbsp;&nbsp;</td>
167
                        <td> <input name="key3" type="text" class="formfld" id="key3" size="30" value="<?=htmlspecialchars($pconfig['key3']);?>"></td>
168
                        <td align="center"> <input name="txkey" type="radio" value="3" <?php if ($pconfig['txkey'] == 3) echo "checked";?>></td>
169
                      </tr>
170
                      <tr> 
171
                        <td>Key 4:&nbsp;&nbsp;</td>
172
                        <td> <input name="key4" type="text" class="formfld" id="key4" size="30" value="<?=htmlspecialchars($pconfig['key4']);?>"></td>
173
                        <td align="center"> <input name="txkey" type="radio" value="4" <?php if ($pconfig['txkey'] == 4) echo "checked";?>></td>
174
                      </tr>
175
                    </table>
176
                    <br>
177
                    40 (64) bit keys may be entered as 5 ASCII characters or 10 
178
                    hex digits preceded by '0x'.<br>
179
                    104 (128) bit keys may be entered as 13 ASCII characters or 
180
                    26 hex digits preceded by '0x'.</td>
181
                </tr>
182
<?php } ?>
(50-50/100)