]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/wlanap.cgi
Merge remote-tracking branch 'stevee/pakfire3-fixes' into next
[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) 2005-2012 IPFire Team <info@ipfire.org> #
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 $status = '';
37 my $errormessage = '';
38 my $status_started = "<td align='center' width='75%' bgcolor='${Header::colourgreen}'><font color='white'><strong>$Lang::tr{'running'}</strong></font></td></tr>";
39 my $status_stopped = "<td align='center' width='75%' bgcolor='${Header::colourred}'><font color='white'><strong>$Lang::tr{'stopped'}</strong></font></td></tr>";
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 %netsettings=();
50 my %wlanapsettings=();
51 my $channel = '';
52 my $country = '';
53 my $txpower = '';
54
55 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
56 &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
57 &General::readhash("/var/ipfire/ethernet/settings", \%netsettings);
58
59 $wlanapsettings{'APMODE'} = 'on';
60 $wlanapsettings{'ACTION'} = '';
61 $wlanapsettings{'MACMODE'} = '0';
62 $wlanapsettings{'INTERFACE'} = '';
63 $wlanapsettings{'SSID'} = 'IPFire';
64 $wlanapsettings{'HIDESSID'} = 'off';
65 $wlanapsettings{'ENC'} = 'wpa2'; # none / wpa1 /wpa2
66 $wlanapsettings{'TXPOWER'} = 'auto';
67 $wlanapsettings{'CHANNEL'} = '05';
68 $wlanapsettings{'COUNTRY'} = '00';
69 $wlanapsettings{'HW_MODE'} = 'g';
70 $wlanapsettings{'PWD'} = 'IPFire-2.x';
71 $wlanapsettings{'SYSLOGLEVEL'} = '0';
72 $wlanapsettings{'DEBUG'} = '4';
73 $wlanapsettings{'DRIVER'} = 'MADWIFI';
74 $wlanapsettings{'HTCAPS'} = '';
75
76 &General::readhash("/var/ipfire/wlanap/settings", \%wlanapsettings);
77 &Header::getcgihash(\%wlanapsettings);
78
79 my @macs = $wlanapsettings{'MACS'};
80
81 delete $wlanapsettings{'__CGI__'};
82 delete $wlanapsettings{'x'};
83 delete $wlanapsettings{'y'};
84 delete $wlanapsettings{'MACS'};
85 delete $wlanapsettings{'ACCEPT_MACS'};
86 delete $wlanapsettings{'DENY_MACS'};
87
88 &Header::showhttpheaders();
89
90 my $string=();
91 my $status=();
92 my $errormessage = '';
93 my $memory = 0;
94 my @memory=();
95 my @pid=();
96 my @hostapd=();
97 sub pid
98 {
99 # for pid and memory
100 open(FILE, '/usr/local/bin/addonctrl hostapd status | ');
101 @hostapd = <FILE>;
102 close(FILE);
103 $string = join("", @hostapd);
104 $string =~ s/[a-z_]//gi;
105 $string =~ s/\[[0-1]\;[0-9]+//gi;
106 $string =~ s/[\(\)\.]//gi;
107 $string =~ s/ //gi;
108 $string =~ s/\e//gi;
109 @pid = split(/\s/,$string);
110 if (open(FILE, "/proc/$pid[0]/statm")){
111 my $temp = <FILE>;
112 @memory = split(/ /,$temp);
113 close(FILE);
114 }
115 $memory+=$memory[0];
116 }
117 pid();
118
119
120
121 if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap del interface'}" ){
122 delete $wlanapsettings{'INTERFACE'};
123 &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings);
124 }
125
126 if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'save'}" ){
127 # verify WPA Passphrase, must be 8 .. 63 characters - only wiht enabled enc
128 if (($wlanapsettings{'ENC'} eq "wpa1") || ($wlanapsettings{'ENC'} eq "wpa2") || ($wlanapsettings{'ENC'} eq "wpa1+2")){
129 if ( (length($wlanapsettings{'PWD'}) < 8) || (length($wlanapsettings{'PWD'}) > 63)){
130 $errormessage .= "$Lang::tr{'wlanap invalid wpa'}<br />";
131 }
132 }
133
134 if ( $errormessage eq '' ){
135 &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings);
136 &WriteConfig_hostapd();
137
138 system("/usr/local/bin/wlanapctrl restart >/dev/null 2>&1");
139 pid();
140 }
141 }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap interface'}" ){
142 &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings);
143 }elsif ( ($wlanapsettings{'ACTION'} eq "$Lang::tr{'start'}") && ($memory == 0) ){
144 system("/usr/local/bin/wlanapctrl start >/dev/null 2>&1");
145 pid();
146 }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'stop'}" ){
147 system("/usr/local/bin/wlanapctrl stop >/dev/null 2>&1");
148 $memory=0;
149 }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'restart'}" ){
150 system("/usr/local/bin/wlanapctrl restart >/dev/null 2>&1");
151 pid();
152 }
153
154 &Header::openpage('Wireless LAN', 1, '', '');
155 &Header::openbigbox('100%', 'left', '', $errormessage);
156
157 if ( $errormessage ){
158 &Header::openbox('100%', 'center', $Lang::tr{'error messages'});
159 print "<class name='base'>$errormessage\n";
160 print "&nbsp;</class>\n";
161 &Header::closebox();
162 }
163
164
165 # Found this usefull piece of code in BlockOutTraffic AddOn 8-)
166 # fwrules.cgi
167 ###############
168 # DEBUG DEBUG
169 if ( $debug ){
170 &Header::openbox('100%', 'center', 'DEBUG');
171 my $debugCount = 0;
172 foreach my $line (sort keys %wlanapsettings) {
173 print "$line = '$wlanapsettings{$line}'<br />\n";
174 $debugCount++;
175 }
176 print "&nbsp;Count: $debugCount\n";
177 &Header::closebox();
178 }
179 # DEBUG DEBUG
180 ###############
181
182 #
183 # Driver and status detection
184 #
185 my $wlan_card_status = 'dummy';
186 my $wlan_ap_status = '';
187 my $message = "";
188
189 $selected{'INTERFACE'}{'green0'} = '';
190 $selected{'INTERFACE'}{'blue0'} = '';
191 $selected{'ENC'}{$wlanapsettings{'INTERFACE'}} = "selected='selected'";
192
193 if ( ($wlanapsettings{'INTERFACE'} eq '') ){
194 $message = $Lang::tr{'wlanap select interface'};
195 &Header::openbox('100%', 'center', "WLAN AP");
196 print <<END
197 $message<br />
198 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
199 <select name='INTERFACE'>
200 END
201 ;
202 if ( $netsettings{'BLUE_DEV'} ne ''){
203 print "<option value='blue0' $selected{'INTERFACE'}{'blue0'}>blue0</option>";
204 }
205 print <<END
206 <option value='green0' $selected{'INTERFACE'}{'green0'}>green0</option>
207 </select>
208 <br /><br />
209 <hr size='1'>
210 <input type='submit' name='ACTION' value='$Lang::tr{'wlanap interface'}' /></form>
211 END
212 ;
213 &Header::closebox();
214 &Header::closebigbox();
215 &Header::closepage();
216 exit;
217 }else{
218 my $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} 2>/dev/null`;
219
220 if ( $cmd_out eq '' ){
221 $message = "$Lang::tr{'wlanap no interface'}";
222 $wlan_card_status = '';
223 }else{
224 $cmd_out = `/sbin/ifconfig | /bin/grep $wlanapsettings{'INTERFACE'}`;
225 if ( $cmd_out eq '' ){
226 $wlan_card_status = 'down';
227 }else{
228 $wlan_card_status = 'up';
229 $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} | /bin/grep "Mode:Master"`;
230 if ( $cmd_out ne '' ){
231 $wlan_ap_status = 'up';
232 }
233 }
234 }
235 }
236
237 # Change old "n" to "gn"
238 if ( $wlanapsettings{'HW_MODE'} eq 'n' ) {
239 $wlanapsettings{'HW_MODE'}='gn';
240 }
241
242 $checked{'HIDESSID'}{'off'} = '';
243 $checked{'HIDESSID'}{'on'} = '';
244 $checked{'HIDESSID'}{$wlanapsettings{'HIDESSID'}} = "checked='checked'";
245
246 $selected{'ENC'}{$wlanapsettings{'ENC'}} = "selected='selected'";
247 $selected{'CHANNEL'}{$wlanapsettings{'CHANNEL'}} = "selected='selected'";
248 $selected{'COUNTRY'}{$wlanapsettings{'COUNTRY'}} = "selected='selected'";
249 $selected{'TXPOWER'}{$wlanapsettings{'TXPOWER'}} = "selected='selected'";
250 $selected{'HW_MODE'}{$wlanapsettings{'HW_MODE'}} = "selected='selected'";
251 $selected{'MACMODE'}{$wlanapsettings{'MACMODE'}} = "selected='selected'";
252
253 my $monwlaninterface = $wlanapsettings{'INTERFACE'};
254 if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){
255 $monwlaninterface = 'mon.'.$wlanapsettings{'INTERFACE'};
256 }
257
258 my @channellist_cmd = `iwlist $monwlaninterface channel 2>/dev/null`;
259 # get available channels
260
261 my @temp;
262 foreach (@channellist_cmd){
263 $_ =~ /(.*)Channel (\d+)(.*):/;
264 $channel = $2;chomp $channel;
265 if ( $channel =~ /\d+/ ){push(@temp,$channel);}
266 }
267 my @channellist = @temp;
268
269 my @countrylist_cmd = `regdbdump /usr/lib/crda/regulatory.bin 2>/dev/null`;
270 # get available country codes
271
272 my @temp;
273 foreach (@countrylist_cmd){
274 $_ =~ /country (.*):/;
275 $country = $1;chomp $country;
276 if ( $country =~ /[0,A-Z][0,A-Z]/ ) {push(@temp,$country);}
277 }
278 my @countrylist = @temp;
279
280 my @txpower_cmd = `iwlist $monwlaninterface txpower 2>/dev/null`;
281 if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){
282 # There is a bug with NL80211 only all devices can displayed
283 @txpower_cmd = `iwlist txpower 2>/dev/null | sed -e "s|unknown transmit-power information.||g"`;
284 }
285 # get available power
286
287 my @temp;
288 foreach (@txpower_cmd){
289 $_ =~ /(\s)(\d+)(\s)dBm(\s)(.*)(\W)(\d+)(.*)/;
290 $txpower = $7;chomp $txpower;
291 if ( $txpower =~ /\d+/ ){push(@temp,$txpower."mW");}
292 }
293 my @txpower = @temp;
294 push(@txpower,"auto");
295
296 $selected{'SYSLOGLEVEL'}{$wlanapsettings{'SYSLOGLEVEL'}} = "selected='selected'";
297 $selected{'DEBUG'}{$wlanapsettings{'DEBUG'}} = "selected='selected'";
298
299 #
300 # Status box
301 #
302 &Header::openbox('100%', 'center', "WLAN AP");
303 print <<END
304 <table width='95%' cellspacing='0'>
305 END
306 ;
307
308 if ( $wlan_card_status ne '' ){
309 print "<tr><td bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'wlanap wlan services'}</strong></td></tr>";
310 print "<tr><td colspan='1' class='base'>$Lang::tr{'wlanap wlan card'} ($wlanapsettings{'DRIVER'})</td>";
311 print $wlan_card_status eq 'up' ? $status_started : $status_stopped;
312 print "<tr><td colspan='1' class='base'>$Lang::tr{'wlanap access point'}</td>";
313 print $wlan_ap_status eq 'up' ? $status_started : $status_stopped;
314
315 }else{
316 print "<tr><td colspan='2' class='base'>$message";
317 }
318 print "</table>";
319
320 if ( ($memory != 0) && (@pid[0] ne "///") && ($wlan_card_status ne '') ){
321 print "<table width='95%' cellspacing='0' border='0'>";
322 print "<tr>";
323 print "<td align='center'></td>";
324 print "<td bgcolor='$color{'color20'}' align='center'><strong>PID</strong></td>";
325 print "<td bgcolor='$color{'color20'}' align='center'><strong>$Lang::tr{'memory'}</strong></td>";
326 print "</tr>";
327 print "<tr>";
328 print "<td width='35%' align='right'><strong>hostapd</strong>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
329 print "<td bgcolor='$color{'color22'}' align='center'>@pid[0]</td>";
330 print "<td bgcolor='$color{'color22'}' align='center'>$memory KB</td>";
331 print "</tr>";
332 print "</table>";
333 }
334
335 if ( $wlan_card_status ne '' ){
336 print "<br />";
337 print "<table width='95%' cellspacing='0' border='0'>";
338 print "<tr align='center'>";
339 print "</tr>";
340 print "<tr align='center'>";
341 print "<td width='40%'>&nbsp;</td>";
342 print "<td width='20%'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='$Lang::tr{'start'}' /><input type='image' alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' /></form></td>";
343 print "<td width='20%'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='$Lang::tr{'stop'}' /><input type='image' alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go-down.png' /></form></td>";
344 print "<td width='20%'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='hidden' name='ACTION' value='$Lang::tr{'restart'}' /><input type='image' alt='$Lang::tr{'restart'}' title='$Lang::tr{'restart'}' src='/images/view-refresh.png' /></form></td>";
345 print "</tr>";
346 print "</table>";
347 }else{
348 print "<br />";
349 print "<table width='95%' cellspacing='0' border='0'>";
350 print "<tr align='center'>";
351 print "<td colspan='4'><hr size='1'></td>";
352 print "</tr>";
353 print "<tr align='center'>";
354 print "<td width='40%'>&nbsp;</td>";
355 print "<td width='20%'><form method='post' action='/cgi-bin/wlanap.cgi'><input type='submit' name='ACTION' value='$Lang::tr{'wlanap del interface'}' /></form></td>";
356 print "<td width='20%'></td>";
357 print "<td width='20%'></td>";
358 print "</tr>";
359 print "</table>";
360 }
361
362 if ( $wlan_card_status eq '' ){
363 &Header::closebox();
364 &Header::closebigbox();
365 &Header::closepage();
366 exit 0;
367 }
368 print <<END
369 <br />
370 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
371 <table width='95%' cellspacing='0'>
372 <tr><td bgcolor='$color{'color20'}' colspan='4' align='left'><strong>$Lang::tr{'wlanap wlan settings'}</strong>
373 <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>
374 <!--SSID Broadcast: on => HIDESSID: off -->
375 <tr><td width='25%' class='base'>SSID Broadcast:&nbsp;</td><td class='base' colspan='3'>on <input type='radio' name='HIDESSID' value='off' $checked{'HIDESSID'}{'off'} /> | <input type='radio' name='HIDESSID' value='on' $checked{'HIDESSID'}{'on'} /> off</td></tr>
376 <tr><td width='25%' class='base'>HW Mode:&nbsp;</td><td class='base' colspan='3'>
377 <select name='HW_MODE'>
378 <option value='a' $selected{'HW_MODE'}{'a'}>802.11a</option>
379 <option value='b' $selected{'HW_MODE'}{'b'}>802.11b</option>
380 <option value='g' $selected{'HW_MODE'}{'g'}>802.11g</option>
381 <option value='an' $selected{'HW_MODE'}{'an'}>802.11an</option>
382 <option value='gn' $selected{'HW_MODE'}{'gn'}>802.11gn</option>
383 </select>
384 </td></tr>
385
386 <tr><td width='25%' class='base'>$Lang::tr{'wlanap encryption'}:&nbsp;</td><td class='base' colspan='3'>
387 <select name='ENC'>
388 <option value='none' $selected{'ENC'}{'none'}>$Lang::tr{'wlanap none'}</option>
389 <option value='wpa1' $selected{'ENC'}{'wpa1'}>WPA1</option>
390 <option value='wpa2' $selected{'ENC'}{'wpa2'}>WPA2</option>
391 <option value='wpa1+2' $selected{'ENC'}{'wpa1+2'}>WPA1+2</option>
392 </select>
393 </td></tr>
394 <tr><td width='25%' class='base'>$Lang::tr{'wlanap channel'}:&nbsp;</td><td class='base' colspan='3'>
395 <select name='CHANNEL'>
396 END
397 ;
398 foreach $channel (@channellist){
399 print "<option $selected{'CHANNEL'}{$channel}>$channel</option>";
400 }
401
402 print <<END
403 </select></td></tr>
404 <tr><td width='25%' class='base'>$Lang::tr{'wlanap country'}:&nbsp;</td><td class='base' colspan='3'>
405 <select name='COUNTRY'>
406 END
407 ;
408 foreach $country (@countrylist){
409 print "<option $selected{'COUNTRY'}{$country}>$country</option>";
410 }
411
412 print <<END
413 </select></td></tr>
414 <tr><td width='25%' class='base'>Tx Power:&nbsp;</td><td class='base' colspan='3'>
415 END
416 ;
417
418 if ( $wlanapsettings{'DRIVER'} eq 'MADWIFI' ){
419 print "<select name='TXPOWER'>";
420 foreach $txpower (@txpower){
421 print "<option $selected{'TXPOWER'}{$txpower}>$txpower</option>&nbsp;dBm";
422 }
423 print " </select></td></tr>";
424 } else {
425 print "<input type='text' name='TXPOWER' size='10' value='$wlanapsettings{'TXPOWER'}' /></td></tr>"
426 }
427 print <<END
428 <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>
429 <tr><td width='25%' class='base'>HT Caps:&nbsp;</td><td class='base' colspan='3'><input type='text' name='HTCAPS' size='63' value='$wlanapsettings{'HTCAPS'}' /></td></tr>
430 <tr><td width='25%' class='base'>Loglevel (hostapd):&nbsp;</td><td class='base' width='25%'>
431 <select name='SYSLOGLEVEL'>
432 <option value='0' $selected{'SYSLOGLEVEL'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option>
433 <option value='1' $selected{'SYSLOGLEVEL'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option>
434 <option value='2' $selected{'SYSLOGLEVEL'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option>
435 <option value='3' $selected{'SYSLOGLEVEL'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option>
436 <option value='4' $selected{'SYSLOGLEVEL'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option>
437 </select>
438 </td>
439 <td width='25%' class='base'>Debuglevel (hostapd):&nbsp;</td><td class='base' width='25%'>
440 <select name='DEBUG'>
441 <option value='0' $selected{'DEBUG'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option>
442 <option value='1' $selected{'DEBUG'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option>
443 <option value='2' $selected{'DEBUG'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option>
444 <option value='3' $selected{'DEBUG'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option>
445 <option value='4' $selected{'DEBUG'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option>
446 </select>
447 </td></tr>
448 </table>
449 END
450 ;
451 if ( $wlanapsettings{'INTERFACE'} =~ /green0/ ){
452 print <<END
453 <br />
454 <table width='95%' cellspacing='0'>
455 <td width='25%' class='base'>Mac Filter:&nbsp;</td><td class='base' width='25%'>
456 <select name='MACMODE'>
457 <option value='0' $selected{'MACMODE'}{'0'}>0 (off)</option>
458 <option value='1' $selected{'MACMODE'}{'1'}>1 (Accept MACs)</option>
459 <option value='2' $selected{'MACMODE'}{'2'}>2 (Deny MACs)</option>
460 </select>
461 </td><td colspan='2'>Mac Adress List (one per line)<br /><textarea name='MACS' cols='20' rows='5' wrap='off'>
462 END
463 ;
464 print `cat /var/ipfire/wlanap/macfile`;
465 print <<END
466 </textarea></td>
467 </table>
468 END
469 ;
470 }
471 print <<END
472 <br />
473 <table width='95%' cellspacing='0'>
474 <tr><td align='center'>
475 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
476 <input type='hidden' name='ACTION' value=$Lang::tr{'save'} />
477 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></form></td>
478 </tr>
479 </table>
480 END
481 ;
482
483 if ( $wlanapsettings{'DRIVER'} eq 'MADWIFI' ){
484 $status = `wlanconfig $wlanapsettings{'INTERFACE'} list`;
485 }
486 if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){
487 $status = `iw dev $wlanapsettings{'INTERFACE'} station dump`;
488 }
489 print <<END
490 <br />
491 <table width='95%' cellspacing='0'>
492 <tr><td bgcolor='$color{'color20'}' colspan='2' align='left'><strong>$Lang::tr{'wlanap wlan status'}</strong></td></tr>
493 <tr><td><pre>@channellist_cmd</pre></td><td><pre>@txpower_cmd</pre></td></tr>
494 <tr><td colspan='2'><pre>$status</pre></td></tr>
495 </table>
496 <br />
497 <table width='95%' cellspacing='0'>
498 <tr><td bgcolor='$color{'color20'}' align='left'><strong>WLan Clients</strong></td></tr>
499 <tr><td>&nbsp;<a href="/cgi-bin/wireless.cgi">$Lang::tr{'wlanap link wireless'}</a></td></tr>
500 <tr><td>&nbsp;<a href="/cgi-bin/dhcp.cgi">$Lang::tr{'wlanap link dhcp'}</a></td></tr>
501 </table>
502 END
503 ;
504 &Header::closebox();
505 print "</form>";
506 &Header::closebigbox();
507 &Header::closepage();
508
509 sub WriteConfig_hostapd{
510 $wlanapsettings{'DRIVER_HOSTAPD'} = lc($wlanapsettings{'DRIVER'});
511
512 open (CONFIGFILE, ">/var/ipfire/wlanap/hostapd.conf");
513 print CONFIGFILE <<END
514 ######################### basic hostapd configuration ##########################
515 #
516 interface=$wlanapsettings{'INTERFACE'}
517 driver=$wlanapsettings{'DRIVER_HOSTAPD'}
518 channel=$wlanapsettings{'CHANNEL'}
519 END
520 ;
521 if ( $wlanapsettings{'HW_MODE'} eq 'an' ){
522 print CONFIGFILE <<END
523 hw_mode=a
524 ieee80211n=1
525 wmm_enabled=1
526 ht_capab=$wlanapsettings{'HTCAPS'}
527 END
528 ;
529
530 }elsif ( $wlanapsettings{'HW_MODE'} eq 'gn' ){
531 print CONFIGFILE <<END
532 hw_mode=g
533 ieee80211n=1
534 wmm_enabled=1
535 ht_capab=$wlanapsettings{'HTCAPS'}
536 END
537 ;
538
539 }else{
540 print CONFIGFILE <<END
541 hw_mode=$wlanapsettings{'HW_MODE'}
542 END
543 ;
544
545 }
546
547 print CONFIGFILE <<END
548 logger_syslog=-1
549 logger_syslog_level=$wlanapsettings{'SYSLOGLEVEL'}
550 logger_stdout=-1
551 logger_stdout_level=$wlanapsettings{'DEBUG'}
552 dump_file=/tmp/hostapd.dump
553 auth_algs=1
554 ctrl_interface=/var/run/hostapd
555 ctrl_interface_group=0
556 END
557 ;
558 if ( $wlanapsettings{'HIDESSID'} eq 'on' ){
559 print CONFIGFILE <<END
560 ssid=$wlanapsettings{'SSID'}
561 ignore_broadcast_ssid=2
562 END
563 ;
564
565 }else{
566 print CONFIGFILE <<END
567 ssid=$wlanapsettings{'SSID'}
568 ignore_broadcast_ssid=0
569 END
570 ;
571
572 }
573
574 if ( $wlanapsettings{'ENC'} eq 'wpa1'){
575 print CONFIGFILE <<END
576 ######################### wpa hostapd configuration ############################
577 #
578 wpa=1
579 wpa_passphrase=$wlanapsettings{'PWD'}
580 wpa_key_mgmt=WPA-PSK
581 wpa_pairwise=TKIP
582 END
583 ;
584 }elsif ( $wlanapsettings{'ENC'} eq 'wpa2'){
585 print CONFIGFILE <<END
586 ######################### wpa hostapd configuration ############################
587 #
588 wpa=2
589 wpa_passphrase=$wlanapsettings{'PWD'}
590 wpa_key_mgmt=WPA-PSK
591 rsn_pairwise=CCMP
592 END
593 ;
594 } elsif ( $wlanapsettings{'ENC'} eq 'wpa1+2'){
595 print CONFIGFILE <<END
596 ######################### wpa hostapd configuration ############################
597 #
598 wpa=3
599 wpa_passphrase=$wlanapsettings{'PWD'}
600 wpa_key_mgmt=WPA-PSK
601 wpa_pairwise=TKIP
602 rsn_pairwise=CCMP
603 END
604 ;
605 }
606 close CONFIGFILE;
607
608 open (MACFILE, ">/var/ipfire/wlanap/macfile");
609 foreach(@macs){
610 $_ =~ s/\r//gi;
611 chomp($_);
612 if ( $_ ne "" ){print MACFILE $_;}
613 }
614 close MACFILE;
615 }