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