]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/wlanap.cgi
seperated core update files from update to 2.3
[people/teissler/ipfire-2.x.git] / html / cgi-bin / wlanap.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21 #
22 # WLAN AP cgi based on wlanap.cgi written by Markus Hoffmann & Olaf Westrik
23 #
24
25 use strict;
26
27 # enable only the following on debugging purpose
28 use warnings;
29 use CGI::Carp 'fatalsToBrowser';
30
31 require '/var/ipfire/general-functions.pl';
32 require '/var/ipfire/lang.pl';
33 require '/var/ipfire/header.pl';
34
35 my $debug = 0;
36 my $i = 0;
37 my $errormessage = '';
38 my $status_started = "<td align='center' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
39 my $status_stopped = "<td align='center' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
40
41 # get rid of used only once warnings
42 my @onlyonce = ( $Header::colourgreen, $Header::colourred );
43 undef @onlyonce;
44
45 my %selected=();
46 my %checked=();
47 my %color = ();
48 my %mainsettings = ();
49 my $channel = '';
50 my $txpower = '';
51
52 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
53 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
54
55 my %wlanapsettings=();
56 $wlanapsettings{'APMODE'} = 'on';
57 $wlanapsettings{'BOOTSTART'} = 'on';
58 $wlanapsettings{'SSID'} = 'IPFire';
59 $wlanapsettings{'HIDESSID'} = 'off';
60 $wlanapsettings{'ENC'} = 'wpa'; # none / wep / wpa / wep+wpa
61 $wlanapsettings{'ANTENNA'} = 'both';
62 $wlanapsettings{'TXPOWER'} = 'auto';
63 # $wlanapsettings{'CC'} = '276'; # CountryCode, 276 = Germany
64 $wlanapsettings{'CHAN'} = '5';
65
66 $wlanapsettings{'WEPKEY1'} = 'BF715772DADA8A3E7AFFA5C26B';
67 $wlanapsettings{'WEPKEY2'} = '';
68 $wlanapsettings{'WEPKEY3'} = '';
69 $wlanapsettings{'WEPKEY4'} = '';
70 $wlanapsettings{'USEDKEY'} = '1';
71
72 $wlanapsettings{'PWD'} = 'IPFire-2.x';
73 $wlanapsettings{'PSK'} = '69eb868ed7b3cc36d767b729048c9c585234723d1eafbe66e5a16957b7c85e9c';
74 $wlanapsettings{'WPA'} = '3';
75
76 $wlanapsettings{'SYSLOGLEVEL'} = '0';
77 $wlanapsettings{'DEBUG'} = '4';
78 $wlanapsettings{'DRIVER'} = 'MADWIFI'; # UNKNOWN / MADWIFI / RT2500 / PRISM54 / ...
79
80 # WLANMODE= (a/b/g)
81 &General::readhash("/var/ipfire/wlanap/settings", \%wlanapsettings);
82
83 my %netsettings=();
84 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
85
86 my %cgiparams=();
87 $cgiparams{'ACTION'} = '';
88 $cgiparams{'RUNNING'} = 'off';
89 $cgiparams{'APMODE'} = 'on';
90 $cgiparams{'BOOTSTART'} = 'on';
91 $cgiparams{'SSID'} = 'IPFire';
92 $cgiparams{'HIDESSID'} = 'off';
93 $cgiparams{'ENC'} = 'wpa'; # none / wep / wpa / wep+wpa
94 $cgiparams{'ANTENNA'} = 'both';
95 $cgiparams{'TXPOWER'} = 'auto';
96 $cgiparams{'CHAN'} = '5';
97
98 $cgiparams{'WEPKEY1'} = 'BF715772DADA8A3E7AFFA5C26B';
99 $cgiparams{'WEPKEY2'} = '';
100 $cgiparams{'WEPKEY3'} = '';
101 $cgiparams{'WEPKEY4'} = '';
102 $cgiparams{'USEDKEY'} = '1';
103 $cgiparams{'WEPPWD'} = '';
104 $cgiparams{'WEPKEYCALC'} = '';
105
106 $cgiparams{'PWD'} = 'IPFire-2.x';
107 $cgiparams{'PSK'} = '69eb868ed7b3cc36d767b729048c9c585234723d1eafbe66e5a16957b7c85e9c';
108 $cgiparams{'WPA'} = '3';
109
110 $cgiparams{'SYSLOGLEVEL'} = '0';
111 $cgiparams{'DEBUG'} = '4';
112 &Header::getcgihash(\%cgiparams);
113
114
115 &Header::showhttpheaders();
116
117 if ( $cgiparams{'ACTION'} eq "$Lang::tr{'save'}" ){
118 $wlanapsettings{'APMODE'} = $cgiparams{'APMODE'};
119 $wlanapsettings{'BOOTSTART'} = $cgiparams{'BOOTSTART'};
120 $wlanapsettings{'SSID'} = $cgiparams{'SSID'};
121 $wlanapsettings{'HIDESSID'} = $cgiparams{'HIDESSID'};
122 $wlanapsettings{'ENC'} = $cgiparams{'ENC'};
123 $wlanapsettings{'ANTENNA'} = $cgiparams{'ANTENNA'};
124 $wlanapsettings{'CHAN'} = $cgiparams{'CHAN'};
125 $wlanapsettings{'TXPOWER'} = $cgiparams{'TXPOWER'};
126
127 $wlanapsettings{'WEPKEY1'} = $cgiparams{'WEPKEY1'};
128 $wlanapsettings{'WEPKEY2'} = $cgiparams{'WEPKEY2'};
129 $wlanapsettings{'WEPKEY3'} = $cgiparams{'WEPKEY3'};
130 $wlanapsettings{'WEPKEY4'} = $cgiparams{'WEPKEY4'};
131 $wlanapsettings{'USEDKEY'} = $cgiparams{'USEDKEY'};
132
133 $wlanapsettings{'PWD'} = $cgiparams{'PWD'};
134 $wlanapsettings{'PSK'} = $cgiparams{'PSK'};
135 $wlanapsettings{'WPA'} = $cgiparams{'WPA'};
136 $wlanapsettings{'SYSLOGLEVEL'}= $cgiparams{'SYSLOGLEVEL'};
137 $wlanapsettings{'DEBUG'} = $cgiparams{'DEBUG'};
138
139 # verify WEP keys, allowed characters are 0..9A..F, length must be 10 or 26 characters
140 for $i ( 1 .. 4 ){
141 my $wepkey = $wlanapsettings{"WEPKEY${i}"};
142 next if ( $wepkey eq '' );
143 if ( (length($wepkey) != 10) && (length($wepkey) != 26) ){
144 $errormessage .= "Invalid length in WEP Key $i. Key must be 10 or 26 characters.<br />";
145 next;
146 }
147
148 if ( $wepkey !~ /[0-9A-Fa-f]$/ ){
149 $errormessage .= "Invalid character in WEP Key $i. Only A..F and 0..9 allowed.<br />";
150 next;
151 }
152
153 $wlanapsettings{"WEPKEY${i}"} = uc($wepkey);
154 }
155
156 # verify WPA Passphrase, must be 8 .. 63 characters
157 if ( (length($wlanapsettings{'PWD'}) < 8) || (length($wlanapsettings{'PWD'}) > 63) ){
158 $errormessage .= "Invalid length in WPA Passphrase. Must be between 8 and 63 characters.<br />";
159 }
160
161 if ( $errormessage eq '' ){
162 &WriteConfig();
163 &WriteConfig_hostapd();
164
165 system("/usr/local/bin/wlanapctrl start >/dev/null 2>&1") if ( $cgiparams{'RUNNING'} eq 'on' );
166 }
167 }elsif ( $cgiparams{'ACTION'} eq 'Start' ){
168 system("/usr/local/bin/wlanapctrl start >/dev/null 2>&1");
169 }elsif ( $cgiparams{'ACTION'} eq 'Stop' ){
170 system("/usr/local/bin/wlanapctrl stop >/dev/null 2>&1");
171 }elsif ( $cgiparams{'ACTION'} eq 'Calc WEP Key' ){
172 $cgiparams{'WEPKEYCALC'} = '';
173 $errormessage = "Invalid length in WEP Passphrase. Must be exactly 13 characters.<br />" if ( length($cgiparams{'WEPPWD'}) != 13 );
174
175 if ( $errormessage eq '' ){
176 $cgiparams{'WEPKEYCALC'} = uc(&WEPKeyCalc($cgiparams{'WEPPWD'}));
177 }
178 }elsif ( $cgiparams{'ACTION'} eq 'Random WEP Key' ){
179 $cgiparams{'WEPKEYCALC'} = &WEPKeyRandom();
180 }
181
182 &Header::openpage('WLAN', 1, '', '');
183 &Header::openbigbox('100%', 'left', '', $errormessage);
184 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>";
185
186 if ( $errormessage ){
187 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
188 print "<class name='base'>$errormessage\n";
189 print "&nbsp;</class>\n";
190 &Header::closebox();
191 }
192
193
194 # Found this usefull piece of code in BlockOutTraffic AddOn 8-)
195 # fwrules.cgi
196 ###############
197 # DEBUG DEBUG
198 if ( $debug ){
199 &Header::openbox('100%', 'left', 'DEBUG');
200 my $debugCount = 0;
201 foreach my $line (sort keys %cgiparams) {
202 print "$line = '$cgiparams{$line}'<br />\n";
203 $debugCount++;
204 }
205 print "&nbsp;Count: $debugCount\n";
206 &Header::closebox();
207 }
208 # DEBUG DEBUG
209 ###############
210
211 #
212 # Driver and status detection
213 #
214 my $wlan_card_status = 'dummy';
215 my $wlan_ap_status = '';
216 my $wlan_hostapd_status = '';
217 my $blue_message = "";
218
219 if ( ($netsettings{'BLUE_DEV'} eq '') || ($netsettings{'BLUE_DRIVER'} eq '') ){
220 $blue_message = "No BLUE Interface.";
221 }else{
222 my $cmd_out = `/usr/sbin/iwconfig $netsettings{'BLUE_DEV'} 2>/dev/null`;
223
224 if ( $cmd_out eq '' ){
225 $blue_message = "BLUE Interface is not a WLAN card.";
226 }else{
227 $cmd_out = `/sbin/ifconfig | /bin/grep $netsettings{'BLUE_DEV'}`;
228 if ( $cmd_out eq '' ){
229 $wlan_card_status = 'down';
230 }else{
231 $wlan_card_status = 'up';
232 $cmd_out = `/usr/sbin/iwconfig $netsettings{'BLUE_DEV'} | /bin/grep "Mode:Master"`;
233 if ( $cmd_out ne '' ){
234 $wlan_ap_status = 'up';
235 if ( -e "/var/run/hostapd.pid" ){
236 $wlan_hostapd_status = 'up';
237 }
238 }
239 }
240 }
241 }
242
243 my $disabled_apmode = "disabled='disabled'";
244 $disabled_apmode = '' if ( ($wlanapsettings{'DRIVER'} eq 'MADWIFI') || ($wlanapsettings{'DRIVER'} eq 'HOSTAP') || ($wlanapsettings{'DRIVER'} eq 'ACX100') );
245
246 my $checked_apmode = '';
247 my $checked_bootstart = '';
248 my $checked_hidessid = '';
249 $checked_apmode = "checked='checked'" if ( $wlanapsettings{'APMODE'} eq 'on' );
250 $checked_bootstart = "checked='checked'" if ( $wlanapsettings{'BOOTSTART'} eq 'on' );
251 $checked_hidessid = "checked='checked'" if ( $wlanapsettings{'HIDESSID'} eq 'on' );
252
253 $selected{'ENC'}{'none'} = '';
254 $selected{'ENC'}{'wep'} = '';
255 $selected{'ENC'}{'wpa'} = '';
256 $selected{'ENC'}{'wep+wpa'} = '';
257 $selected{'ENC'}{$wlanapsettings{'ENC'}} = "selected='selected'";
258
259 $selected{'ANTENNA'}{'both'} = '';
260 $selected{'ANTENNA'}{'1'} = '';
261 $selected{'ANTENNA'}{'2'} = '';
262 $selected{'ANTENNA'}{$wlanapsettings{'ANTENNA'}} = "selected='selected'";
263
264 my @channellist;
265 # get available channels
266 if ( -e "/var/ipfire/wlanap/channels" ){
267 open(CHANNELFILE, "/var/ipfire/wlanap/channels");
268 @channellist=<CHANNELFILE>;
269 close CHANNELFILE;
270 foreach $channel (@channellist){
271 chomp($channel);
272 $selected{'CHAN'}{$channel} = '';
273 }
274 $selected{'CHAN'}{$wlanapsettings{'CHAN'}} = 'selected="selected"';
275 }else{
276 $channellist[0] = '1';
277 $selected{'CHAN'}{'1'} = 'selected="selected"';
278 }
279
280 my @txpowerlist;
281 # get available txpowers
282 if ( -e "/var/ipfire/wlanap/txpower" ){
283 open(CHANNELFILE, "/var/ipfire/wlanap/txpower");
284 @txpowerlist=<CHANNELFILE>;
285 close CHANNELFILE;
286 foreach $txpower (@txpowerlist){
287 chomp($txpower);
288 $selected{'TXPOWER'}{$txpower} = '';
289 }
290 $selected{'TXPOWER'}{$wlanapsettings{'TXPOWER'}} = 'selected="selected"';
291 }else{
292 $txpowerlist[0] = 'auto';
293 $selected{'TXPOWER'}{'auto'} = 'selected="selected"';
294 }
295
296 $selected{'USEDKEY'}{'1'} = '';
297 $selected{'USEDKEY'}{'2'} = '';
298 $selected{'USEDKEY'}{'3'} = '';
299 $selected{'USEDKEY'}{'4'} = '';
300 $selected{'USEDKEY'}{$wlanapsettings{'USEDKEY'}} = "selected='selected'";
301
302 $selected{'WPA'}{'1'} = '';
303 $selected{'WPA'}{'2'} = '';
304 $selected{'WPA'}{'3'} = '';
305 $selected{'WPA'}{$wlanapsettings{'WPA'}} = "selected='selected'";
306
307 $selected{'SYSLOGLEVEL'}{'0'} = '';
308 $selected{'SYSLOGLEVEL'}{'1'} = '';
309 $selected{'SYSLOGLEVEL'}{'2'} = '';
310 $selected{'SYSLOGLEVEL'}{'3'} = '';
311 $selected{'SYSLOGLEVEL'}{'4'} = '';
312 $selected{'SYSLOGLEVEL'}{$wlanapsettings{'SYSLOGLEVEL'}} = "selected='selected'";
313
314 $selected{'DEBUG'}{'0'} = '';
315 $selected{'DEBUG'}{'1'} = '';
316 $selected{'DEBUG'}{'2'} = '';
317 $selected{'DEBUG'}{'3'} = '';
318 $selected{'DEBUG'}{'4'} = '';
319 $selected{'DEBUG'}{$wlanapsettings{'DEBUG'}} = "selected='selected'";
320
321 #
322 # Status box
323 #
324 &Header::openbox('100%', 'left', "WLAN Status");
325 print <<END
326 <table width='100%'>
327 END
328 ;
329 if ( $wlan_card_status ne '' ){
330 print "<tr><td class='base'><b>WLAN card ($wlanapsettings{'DRIVER'})</b></td>";
331 print $wlan_card_status eq 'up' ? $status_started : $status_stopped;
332 print "<td colspan='2'>&nbsp;</td></tr>";
333 print "<tr><td class='base'><b>Access Point</b></td>";
334 print $wlan_ap_status eq 'up' ? $status_started : $status_stopped;
335 print "<td colspan='2'>&nbsp;</td></tr>";
336 print "<tr><td class='base'><b>Hostapd</b></td>";
337 print $wlan_hostapd_status eq 'up' ? $status_started : $status_stopped;
338 print "<td colspan='2'>&nbsp;</td></tr>";
339 print "<tr><td width='30%' align='right'>&nbsp;</td>";
340 print "<td width='25' align='right'>&nbsp;</td>";
341 if ( $wlan_card_status eq 'up' ){
342 print "<td width='40%' align='center'><input type='submit' name='ACTION' value='Stop' /><input type='hidden' name='RUNNING' value='on' /></td>";
343 }else{
344 print "<td width='40%' align='center'><input type='submit' name='ACTION' value='Start' /></td>";
345 }
346 print "<td width='5%' align='right'>&nbsp;</td>";
347 print "</tr>";
348 }else{
349 print "<tr><td width='55%' class='base'><b>$blue_message</b></td><td width='40%' align='center'>&nbsp;";
350 if ( $netsettings{'CONFIG_TYPE'} & 0x04 ){
351 print "<input type='submit' name='ACTION' value='Detect' />"
352 }else{
353 print "</td><td>&nbsp;</td></tr><tr><td class='base' colspan='2'><b>Use setup on IPCop Console first to configure a (dummy) BLUE interface.</b>"
354 }
355 print "&nbsp;</td><td width='5%' align='right'>&nbsp;</td></tr>";
356 }
357 print <<END
358 </table><hr />
359 END
360 ;
361 &Header::closebox();
362
363 if ( $wlan_card_status eq '' ){
364 print "</form>";
365 &Header::closebigbox();
366 &Header::closepage();
367 exit 0;
368 }
369
370 #
371 # WLAN settings
372 #
373 &Header::openbox('100%', 'left', "WLAN Settings");
374 print <<END
375 <table width='100%'>
376 <tr><td width='25%' class='base'>Access Point:&nbsp;</td><td class='base' colspan='3'><input type='checkbox' name='APMODE' $checked_apmode $disabled_apmode /></td></tr>
377 <tr><td width='25%' class='base'>SSID:&nbsp;</td><td class='base' colspan='3'><input type='text' name='SSID' size='40' value='$wlanapsettings{'SSID'}' /></td></tr>
378 <tr><td width='25%' class='base'>Autostart after Boot:&nbsp;</td><td class='base' colspan='3'><input type='checkbox' name='BOOTSTART' $checked_bootstart /></td></tr>
379 <tr><td width='25%' class='base'>Disable SSID broadcast:&nbsp;</td><td class='base' colspan='3'><input type='checkbox' name='HIDESSID' $checked_hidessid $disabled_apmode /></td></tr>
380 <tr><td width='25%' class='base'>Encryption:&nbsp;</td><td class='base' colspan='3'>
381 <select name='ENC'>
382 <option value='none' $selected{'ENC'}{'none'}>none</option>
383 <option value='wep' $selected{'ENC'}{'wep'}>wep</option>
384 <option value='wpa' $selected{'ENC'}{'wpa'}>wpa</option>
385 <option value='wep+wpa' $selected{'ENC'}{'wep+wpa'}>wep+wpa</option>
386 </select>
387 </td></tr>
388 <tr><td width='25%' class='base'>Use Antenna:&nbsp;</td><td class='base' colspan='3'>
389 <select name='ANTENNA'>
390 <option value='both' $selected{'ANTENNA'}{'both'}>both</option>
391 <option value='1' $selected{'ANTENNA'}{'1'}>1 only</option>
392 <option value='2' $selected{'ANTENNA'}{'2'}>2 only</option>
393 </select>
394 </td></tr>
395 <!-- <tr><td width='25%' class='base'>Select Country:&nbsp;</td><td class='base' colspan='3'><input type='checkbox' name='CC' $checked_hidessid /></td></tr> -->
396 <tr><td width='25%' class='base'>Channel:&nbsp;</td><td class='base' colspan='3'>
397 <select name='CHAN'>
398 END
399 ;
400 foreach $channel (@channellist){
401 print "<option $selected{'CHAN'}{$channel}>$channel</option>";
402 }
403 print <<END
404 </select></td></tr>
405 <tr><td width='25%' class='base'>Tx Power:&nbsp;</td><td class='base' colspan='3'><select name='TXPOWER'>
406 END
407 ;
408 foreach $txpower (@txpowerlist){
409 print "<option $selected{'TXPOWER'}{$txpower}>$txpower</option>&nbsp;dBm";
410 }
411 print <<END
412 </select></td></tr>
413 </table>
414 <hr /><table width='100%'>
415 <tr>
416 <td width='55%' class='base' valign='top'>&nbsp;</td>
417 <td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
418 </tr>
419 </table>
420 END
421 ;
422 &Header::closebox();
423
424
425 #
426 # WEP
427 #
428 &Header::openbox('100%', 'left', "WEP Configuration");
429 print <<END
430 <table width='100%'>
431 <tr><td width='25%' class='base'>Key 1:&nbsp;</td><td class='base' colspan='3'><input type='text' name='WEPKEY1' size='32' value='$wlanapsettings{'WEPKEY1'}' /></td></tr>
432 <tr><td width='25%' class='base'>Key 2:&nbsp;<img src='/blob.gif' alt='*' />&nbsp;</td><td class='base' colspan='3'><input type='text' name='WEPKEY2' size='32' value='$wlanapsettings{'WEPKEY2'}' /></td></tr>
433 <tr><td width='25%' class='base'>Key 3:&nbsp;<img src='/blob.gif' alt='*' />&nbsp;</td><td class='base' colspan='3'><input type='text' name='WEPKEY3' size='32' value='$wlanapsettings{'WEPKEY3'}' /></td></tr>
434 <tr><td width='25%' class='base'>Key 4:&nbsp;<img src='/blob.gif' alt='*' />&nbsp;</td><td class='base' colspan='3'><input type='text' name='WEPKEY4' size='32' value='$wlanapsettings{'WEPKEY4'}' /></td></tr>
435 <tr><td width='25%' class='base'>WEP Key to Use:&nbsp;</td><td class='base' colspan='3'>
436 <select name='USEDKEY'>
437 <option value='1' $selected{'USEDKEY'}{'1'}>1</option>
438 <option value='2' $selected{'USEDKEY'}{'2'}>2</option>
439 <option value='3' $selected{'USEDKEY'}{'3'}>3</option>
440 <option value='4' $selected{'USEDKEY'}{'4'}>4</option>
441 </select>
442 </td></tr>
443 </table>
444 <hr /><table width='100%'>
445 <tr><td width='25%' class='base'>Passphrase:&nbsp;</td><td class='base' width='50%'><input type='text' name='WEPPWD' size='13' value='$cgiparams{'WEPPWD'}' /></td><td width='25%'><input type='submit' name='ACTION' value='Calc WEP Key' /></td></tr>
446 <tr><td width='25%' class='base'>WEP Key:&nbsp;</td><td class='base'><input type='text' name='WEPKEYCALC' size='32' value='$cgiparams{'WEPKEYCALC'}' /></td><td width='25%'><input type='submit' name='ACTION' value='Random WEP Key' /></td></tr>
447 </table>
448 <hr /><table width='100%'>
449 <tr>
450 <td width='55%' class='base' valign='top'><img src='/blob.gif' alt='*' />&nbsp;$Lang::tr{'this field may be blank'}</td>
451 <td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
452 </tr>
453 </table>
454 END
455 ;
456 &Header::closebox();
457
458
459 #
460 # WPA
461 #
462 &Header::openbox('100%', 'left', "WPA Configuration");
463 print <<END
464 <table width='100%'>
465 <tr><td width='25%' class='base'>Passphrase:&nbsp;</td><td class='base' colspan='3'><input type='text' name='PWD' size='63' value='$wlanapsettings{'PWD'}' /></td></tr>
466 <tr><td width='25%' class='base'>WPA Version:&nbsp;</td><td class='base' colspan='3'>
467 <select name='WPA'>
468 <option value='1' $selected{'WPA'}{'1'}>1</option>
469 <option value='2' $selected{'WPA'}{'2'}>2</option>
470 <option value='3' $selected{'WPA'}{'3'}>1+2</option>
471 </select>
472 </td></tr>
473 <tr><td width='25%' class='base'>Loglevel (hostapd):&nbsp;</td><td class='base' width='25%'>
474 <select name='SYSLOGLEVEL'>
475 <option value='0' $selected{'SYSLOGLEVEL'}{'0'}>0 (verbose)</option>
476 <option value='1' $selected{'SYSLOGLEVEL'}{'1'}>1 (debugging)</option>
477 <option value='2' $selected{'SYSLOGLEVEL'}{'2'}>2 (informations)</option>
478 <option value='3' $selected{'SYSLOGLEVEL'}{'3'}>3 (notifications)</option>
479 <option value='4' $selected{'SYSLOGLEVEL'}{'4'}>4 (warnings)</option>
480 </select>
481 </td>
482 <td width='25%' class='base'>Debuglevel (hostapd):&nbsp;</td><td class='base' width='25%'>
483 <select name='DEBUG'>
484 <option value='0' $selected{'DEBUG'}{'0'}>0 (no debugging)</option>
485 <option value='1' $selected{'DEBUG'}{'1'}>1 (minimal)</option>
486 <option value='2' $selected{'DEBUG'}{'2'}>2 (verbose)</option>
487 <option value='3' $selected{'DEBUG'}{'3'}>3 (msg dumps)</option>
488 <option value='4' $selected{'DEBUG'}{'4'}>4 (excessive)</option>
489 </select>
490 </td></tr>
491 </table>
492 <hr /><table width='100%'>
493 <tr>
494 <td width='55%' class='base' valign='top'>&nbsp;</td>
495 <td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
496 </tr>
497 </table>
498 END
499 ;
500 &Header::closebox();
501
502 print "</form>";
503 &Header::closebigbox();
504 &Header::closepage();
505
506 sub WEPKeyRandom{
507 my $length = 26; # 10 is also allowed
508 my $string = "0123456789ABCDEF";
509 my @chars = split(//,$string);
510 my $n = @chars;
511 my $index;
512 my $key = '';
513 for ( $i = 0; $i < $length; $i++){
514 $index = int(rand $n);
515 $key = $key . $chars[$index];
516 }
517 return $key;
518 }
519
520 sub WEPKeyCalc{
521 require Digest::MD5;
522 return substr Digest::MD5::md5_hex( substr( shift() x 64, 0, 64 ) ), 0, 26;
523 }
524
525 sub WriteConfig{
526 &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings);
527 }
528
529 sub WriteConfig_hostapd{
530 $wlanapsettings{'DRIVER_HOSTAPD'} = lc($wlanapsettings{'DRIVER'});
531
532 open (CONFIGFILE, ">/var/ipfire/wlanap/hostapd.conf");
533 print CONFIGFILE <<END
534 ##### hostapd configuration file ##############################################
535
536 interface=$netsettings{'BLUE_DEV'}
537 # Driver interface type (hostap/wired/madwifi; default: hostap)
538 driver=$wlanapsettings{'DRIVER_HOSTAPD'}
539 logger_syslog=-1
540 logger_syslog_level=$wlanapsettings{'SYSLOGLEVEL'}
541 logger_stdout=-1
542 logger_stdout_level=$wlanapsettings{'SYSLOGLEVEL'}
543 debug=$wlanapsettings{'DEBUG'}
544 dump_file=/tmp/hostapd.dump
545 ssid=$wlanapsettings{'SSID'}
546 eapol_key_index_workaround=0
547 eap_server=0
548 own_ip_addr=127.0.0.1
549 wpa=$wlanapsettings{'WPA'}
550 wpa_passphrase=$wlanapsettings{'PWD'}
551 wpa_key_mgmt=WPA-PSK
552 wpa_pairwise=CCMP TKIP
553 auth_algs=3
554 ctrl_interface=/var/run/hostapd
555 ctrl_interface_group=0
556 macaddr_acl=0
557 END
558 ;
559 close CONFIGFILE;
560 }