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