]> git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/wlanap.cgi
hostapd: make client isolation configurable via WebUI
[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;
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 @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 @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}>$channel</option>";
418 }
419 print "</select></td></tr>"
420 } else {
421 print <<END
422 <tr><td width='25%' class='base'>$Lang::tr{'wlanap channel'}:&nbsp;</td><td class='base' colspan='3'>
423 <input type='text' name='CHANNEL' size='10' value='$wlanapsettings{'CHANNEL'}' />
424 </td></tr>
425 END
426 ;
427 }
428 print<<END
429 <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>
430 <tr><td colspan='4'><br></td></tr>
431 <tr><td width='25%' class='base'>$Lang::tr{'wlanap encryption'}:&nbsp;</td><td class='base' colspan='3'>
432 <select name='ENC'>
433 <option value='none' $selected{'ENC'}{'none'}>$Lang::tr{'wlanap none'}</option>
434 <option value='wpa1' $selected{'ENC'}{'wpa1'}>WPA1</option>
435 <option value='wpa2' $selected{'ENC'}{'wpa2'}>WPA2</option>
436 <option value='wpa1+2' $selected{'ENC'}{'wpa1+2'}>WPA1+2</option>
437 </select>
438 </td></tr>
439 <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>
440 <tr><td colspan='4'><br></td></tr>
441 END
442 ;
443 print <<END
444 <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>
445 <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>
446 <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>
447 <tr><td width='25%' class='base'>Loglevel (hostapd):&nbsp;</td><td class='base' width='25%'>
448 <select name='SYSLOGLEVEL'>
449 <option value='0' $selected{'SYSLOGLEVEL'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option>
450 <option value='1' $selected{'SYSLOGLEVEL'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option>
451 <option value='2' $selected{'SYSLOGLEVEL'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option>
452 <option value='3' $selected{'SYSLOGLEVEL'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option>
453 <option value='4' $selected{'SYSLOGLEVEL'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option>
454 </select>
455 </td>
456 <td width='25%' class='base'>Debuglevel (hostapd):&nbsp;</td><td class='base' width='25%'>
457 <select name='DEBUG'>
458 <option value='0' $selected{'DEBUG'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option>
459 <option value='1' $selected{'DEBUG'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option>
460 <option value='2' $selected{'DEBUG'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option>
461 <option value='3' $selected{'DEBUG'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option>
462 <option value='4' $selected{'DEBUG'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option>
463 </select>
464 </td></tr>
465 <tr><td colspan='4'><br></td></tr>
466 </table>
467 END
468 ;
469 if ( $wlanapsettings{'INTERFACE'} =~ /green0/ ){
470 print <<END
471 <br />
472 <table width='80%' cellspacing='0' class='tbl' border='1'>
473 <tr>
474 <th colspan='3' align='left'>$Lang::tr{'mac filter'}</th>
475 </tr>
476 <td width='25%' class='base'>Mac Filter:&nbsp;</td><td class='base' width='25%'>
477 <select name='MACMODE'>
478 <option value='0' $selected{'MACMODE'}{'0'}>0 (off)</option>
479 <option value='1' $selected{'MACMODE'}{'1'}>1 (Accept MACs)</option>
480 <option value='2' $selected{'MACMODE'}{'2'}>2 (Deny MACs)</option>
481 </select>
482 </td><td colspan='2'>Mac Adress List (one per line)<br /><textarea name='MACS' cols='20' rows='5' wrap='off'>
483 END
484 ;
485 print `cat /var/ipfire/wlanap/macfile`;
486 print <<END
487 </textarea></td>
488 </table>
489 END
490 ;
491 }
492 print <<END
493 <br />
494 <table width='80%' cellspacing='0'>
495 <tr><td align='center'>
496 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
497 <input type='hidden' name='ACTION' value=$Lang::tr{'save'} />
498 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></form></td>
499 </tr>
500 </table>
501 END
502 ;
503 my @status;
504 if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){
505 @status = `iw dev $wlanapsettings{'INTERFACE'} info && iw dev $wlanapsettings{'INTERFACE'} station dump && echo ""`;
506 }
507 print <<END
508 <br />
509 <table width='80%' cellspacing='0' class='tbl'>
510 <tr><th colspan='3' bgcolor='$color{'color20'}' align='left'><strong>$Lang::tr{'wlanap wlan status'}</strong></th></tr>
511 END
512 ;
513
514 for (my $i=0;$i<$#status;$i++){
515
516 if (@status[$i]=~"^Station ") { $count++; }
517 if ($count % 2){
518 $col="bgcolor='$color{'color20'}'";
519 }else{
520 $col="bgcolor='$color{'color22'}'";
521 }
522 print"<tr><td colspan='3' $col><pre>@status[$i]</pre></td></tr>";
523 if (! @status[$i]=~"^/t" ) { $count++; }
524 }
525 $count++;
526
527 foreach my $nr (@channellist_cmd){
528 if ($count % 2){
529 $col="bgcolor='$color{'color20'}'";
530 }else{
531 $col="bgcolor='$color{'color22'}'";
532 }
533 print"<tr><td colspan='3' $col>$nr</td></tr>";
534 $count++;
535 }
536
537 for (my $i=0;$i<$#txpower_cmd;$i=$i+2){
538 if ($count % 2){
539 $col="bgcolor='$color{'color20'}'";
540 }else{
541 $col="bgcolor='$color{'color22'}'";
542 }
543 print "<tr><td $col>@txpower_cmd[$i]</td></tr>";
544 $count++;
545 }
546 print "</table><br>";
547 print <<END
548 <br />
549 <table width='80%' cellspacing='0' class='tbl' border='0'>
550 <tr><td bgcolor='$color{'color20'}' align='left'><strong>$Lang::tr{'wlan clients'}</strong></td></tr>
551 <tr><td>&nbsp;<a href="/cgi-bin/wireless.cgi">$Lang::tr{'wlanap link wireless'}</a></td></tr>
552 <tr><td>&nbsp;<a href="/cgi-bin/dhcp.cgi">$Lang::tr{'wlanap link dhcp'}</a></td></tr>
553 <tr><td><br></td></tr>
554 </table>
555 END
556 ;
557 &Header::closebox();
558 print "</form>";
559 &Header::closebigbox();
560 &Header::closepage();
561
562 sub WriteConfig_hostapd{
563 $wlanapsettings{'DRIVER_HOSTAPD'} = lc($wlanapsettings{'DRIVER'});
564
565 open (CONFIGFILE, ">/var/ipfire/wlanap/hostapd.conf");
566 print CONFIGFILE <<END
567 driver=$wlanapsettings{'DRIVER_HOSTAPD'}
568 ######################### basic hostapd configuration ##########################
569 #
570 interface=$wlanapsettings{'INTERFACE'}
571 country_code=$wlanapsettings{'COUNTRY'}
572 ieee80211d=1
573 ieee80211h=1
574 channel=$wlanapsettings{'CHANNEL'}
575 END
576 ;
577 if ( $wlanapsettings{'HW_MODE'} eq 'an' ){
578 print CONFIGFILE <<END
579 hw_mode=a
580 ieee80211n=1
581 wmm_enabled=1
582 ht_capab=$wlanapsettings{'HTCAPS'}
583 END
584 ;
585
586 }elsif ( $wlanapsettings{'HW_MODE'} eq 'gn' ){
587 print CONFIGFILE <<END
588 hw_mode=g
589 ieee80211n=1
590 wmm_enabled=1
591 ht_capab=$wlanapsettings{'HTCAPS'}
592 END
593 ;
594
595 }elsif ( $wlanapsettings{'HW_MODE'} eq 'ac' ){
596 print CONFIGFILE <<END
597 hw_mode=a
598 ieee80211ac=1
599 ieee80211n=1
600 wmm_enabled=1
601 ht_capab=$wlanapsettings{'HTCAPS'}
602 vht_capab=$wlanapsettings{'VHTCAPS'}
603 END
604 ;
605
606 }else{
607 print CONFIGFILE <<END
608 hw_mode=$wlanapsettings{'HW_MODE'}
609 END
610 ;
611
612 }
613
614 print CONFIGFILE <<END
615 logger_syslog=-1
616 logger_syslog_level=$wlanapsettings{'SYSLOGLEVEL'}
617 logger_stdout=-1
618 logger_stdout_level=$wlanapsettings{'DEBUG'}
619 dump_file=/tmp/hostapd.dump
620 auth_algs=1
621 ctrl_interface=/var/run/hostapd
622 ctrl_interface_group=0
623 END
624 ;
625 if ( $wlanapsettings{'HIDESSID'} eq 'on' ){
626 print CONFIGFILE <<END
627 ssid=$wlanapsettings{'SSID'}
628 ignore_broadcast_ssid=2
629 END
630 ;
631
632 }else{
633 print CONFIGFILE <<END
634 ssid=$wlanapsettings{'SSID'}
635 ignore_broadcast_ssid=0
636 END
637 ;
638
639 }
640
641 # https://forum.ipfire.org/viewtopic.php?f=22&t=12274&p=79070#p79070
642 if ( $wlanapsettings{'CLIENTISOLATION'} eq 'on' ){
643 print CONFIGFILE <<END
644 ap_isolate=1
645 END
646 ;
647 }
648
649 if ( $wlanapsettings{'NOSCAN'} eq 'on' ){
650 print CONFIGFILE <<END
651 noscan=1
652 END
653 ;
654
655 }else{
656 print CONFIGFILE <<END
657 noscan=0
658 END
659 ;
660
661 }
662
663 if ( $wlanapsettings{'ENC'} eq 'wpa1'){
664 print CONFIGFILE <<END
665 ######################### wpa hostapd configuration ############################
666 #
667 wpa=1
668 wpa_passphrase=$wlanapsettings{'PWD'}
669 wpa_key_mgmt=WPA-PSK
670 wpa_pairwise=TKIP
671 END
672 ;
673 }elsif ( $wlanapsettings{'ENC'} eq 'wpa2'){
674 print CONFIGFILE <<END
675 ######################### wpa hostapd configuration ############################
676 #
677 wpa=2
678 wpa_passphrase=$wlanapsettings{'PWD'}
679 wpa_key_mgmt=WPA-PSK
680 rsn_pairwise=CCMP
681 END
682 ;
683 } elsif ( $wlanapsettings{'ENC'} eq 'wpa1+2'){
684 print CONFIGFILE <<END
685 ######################### wpa hostapd configuration ############################
686 #
687 wpa=3
688 wpa_passphrase=$wlanapsettings{'PWD'}
689 wpa_key_mgmt=WPA-PSK
690 wpa_pairwise=TKIP
691 rsn_pairwise=CCMP
692 END
693 ;
694 }
695 close CONFIGFILE;
696
697 open (MACFILE, ">/var/ipfire/wlanap/macfile");
698 foreach(@macs){
699 $_ =~ s/\r//gi;
700 chomp($_);
701 if ( $_ ne "" ){print MACFILE $_;}
702 }
703 close MACFILE;
704 }