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