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