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