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