]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/wlanap.cgi
Merge remote-tracking branch 'origin/master' into next
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / wlanap.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-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
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;
262 my @channellist;
263
264 if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){
265 my $wiphy = `iw dev $wlanapsettings{'INTERFACE'} info | grep wiphy | cut -d" " -f2`;
266 chomp $wiphy;
267
268 @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`;
269 # get available channels
270
271 my @temp;
272 foreach (@channellist_cmd){
273 $_ =~ /(.*) \[(\d+)(.*)\]/;
274 $channel = $2;chomp $channel;
275 if ( $channel =~ /\d+/ ){push(@temp,$channel + 0);}
276 }
277 @channellist = @temp;
278 } else {
279 @channellist_cmd = `iwlist $monwlaninterface channel|tail -n +2 2>/dev/null`;
280 # get available channels
281
282 my @temp;
283 foreach (@channellist_cmd){
284 $_ =~ /(.*)Channel (\d+)(.*):/;
285 $channel = $2;chomp $channel;
286 if ( $channel =~ /\d+/ ){push(@temp,$channel + 0);}
287 }
288 @channellist = @temp;
289 }
290
291 my @countrylist_cmd = `regdbdump /usr/lib/crda/regulatory.bin 2>/dev/null`;
292 # get available country codes
293
294 my @temp = "00";
295 foreach (@countrylist_cmd){
296 $_ =~ /country (.*):/;
297 $country = $1;chomp $country;
298 if ( $country =~ /[0,A-Z][0,A-Z]/ ) {push(@temp,$country);}
299 }
300 my @countrylist = @temp;
301
302 my @txpower_cmd = `iwlist $monwlaninterface txpower 2>/dev/null`;
303 if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){
304 # There is a bug with NL80211 only all devices can displayed
305 @txpower_cmd = `iwlist txpower 2>/dev/null | sed -e "s|unknown transmit-power information.||g"`;
306 }
307 # get available power
308
309 $selected{'SYSLOGLEVEL'}{$wlanapsettings{'SYSLOGLEVEL'}} = "selected='selected'";
310 $selected{'DEBUG'}{$wlanapsettings{'DEBUG'}} = "selected='selected'";
311
312 #
313 # Status box
314 #
315 &Header::openbox('100%', 'center', "WLAN AP");
316 print <<END
317 <table width='80%' cellspacing='1' class='tbl'>
318 END
319 ;
320
321 if ( $wlan_card_status ne '' ){
322 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>";
323 print "<tr><td class='base'>$Lang::tr{'wlanap wlan card'} ($wlanapsettings{'DRIVER'})</td>";
324 print $wlan_card_status eq 'up' ? $status_started : $status_stopped;
325 print"<td colspan='4'></td></tr>";
326 print "<tr><td class='base' bgcolor='$color{'color22'}'>$Lang::tr{'wlanap access point'}</td>";
327 print $wlan_ap_status eq 'up' ? $status_started : $status_stopped;
328 if ( ($memory != 0) && (@pid[0] ne "///") ){
329 print "<td bgcolor='$color{'color22'}' align='center'>@pid[0]</td>";
330 print "<td bgcolor='$color{'color22'}' align='center'>$memory KB</td>";
331 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>";
332 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>";
333 }else{
334 print"<td colspan='2' bgcolor='$color{'color22'}'></td>";
335 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>";
336 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>";
337 }
338
339 }else{
340 print "<tr><td class='base'>$message";
341 }
342 print "</table>";
343
344 if ( $wlan_card_status eq '' ){
345 print "<br />";
346 print "<table width='80%' cellspacing='0' border='0'>";
347 print "<tr align='center'>";
348 print "<td colspan='4'></td>";
349 print "</tr>";
350 print "<tr align='center'>";
351 print "<td width='40%'>&nbsp;</td>";
352 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>";
353 print "<td width='20%'></td>";
354 print "<td width='20%'></td>";
355 print "</tr>";
356 print "</table>";
357 }
358
359 if ( $wlan_card_status eq '' ){
360 &Header::closebox();
361 &Header::closebigbox();
362 &Header::closepage();
363 exit 0;
364 }
365 print <<END
366 <br><br>
367 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
368 <table width='80%' cellspacing='0' class='tbl' border='0'>
369 <tr><th bgcolor='$color{'color20'}' colspan='4' align='left'><strong>$Lang::tr{'wlanap wlan settings'}</strong></th></tr>
370 <tr><td colspan='4'><br></td></tr>
371 <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>
372 <!--SSID Broadcast: on => HIDESSID: off -->
373 <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>
374
375
376 <tr><td width='25%' class='base'>$Lang::tr{'wlanap country'}:&nbsp;</td><td class='base' colspan='3'>
377 <select name='COUNTRY'>
378 END
379 ;
380 foreach $country (@countrylist){
381 print "<option $selected{'COUNTRY'}{$country}>$country</option>";
382 }
383 print<<END
384 </select></td></tr>
385 <tr><td width='25%' class='base'>HW Mode:&nbsp;</td><td class='base' colspan='3'>
386 <select name='HW_MODE'>
387 <option value='a' $selected{'HW_MODE'}{'a'}>802.11a</option>
388 <option value='b' $selected{'HW_MODE'}{'b'}>802.11b</option>
389 <option value='g' $selected{'HW_MODE'}{'g'}>802.11g</option>
390 <option value='an' $selected{'HW_MODE'}{'an'}>802.11an</option>
391 <option value='gn' $selected{'HW_MODE'}{'gn'}>802.11gn</option>
392 </select>
393 </td></tr>
394 END
395 ;
396
397 if ( scalar @channellist > 0 ){
398 print <<END
399 <tr><td width='25%' class='base'>$Lang::tr{'wlanap channel'}:&nbsp;</td><td class='base' colspan='3'>
400 <select name='CHANNEL'>
401 END
402 ;
403 foreach $channel (@channellist){
404 print "<option $selected{'CHANNEL'}{$channel}>$channel</option>";
405 }
406 print "</select></td></tr>"
407 } else {
408 print <<END
409 <tr><td width='25%' class='base'>$Lang::tr{'wlanap channel'}:&nbsp;</td><td class='base' colspan='3'>
410 <input type='text' name='CHANNEL' size='10' value='$wlanapsettings{'CHANNEL'}' />
411 </td></tr>
412 END
413 ;
414 }
415 print<<END
416 <tr><td colspan='4'><br></td></tr>
417 <tr><td width='25%' class='base'>$Lang::tr{'wlanap encryption'}:&nbsp;</td><td class='base' colspan='3'>
418 <select name='ENC'>
419 <option value='none' $selected{'ENC'}{'none'}>$Lang::tr{'wlanap none'}</option>
420 <option value='wpa1' $selected{'ENC'}{'wpa1'}>WPA1</option>
421 <option value='wpa2' $selected{'ENC'}{'wpa2'}>WPA2</option>
422 <option value='wpa1+2' $selected{'ENC'}{'wpa1+2'}>WPA1+2</option>
423 </select>
424 </td></tr>
425 <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>
426 <tr><td colspan='4'><br></td></tr>
427 END
428 ;
429 print <<END
430 <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>
431 <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>
432 <tr><td width='25%' class='base'>Loglevel (hostapd):&nbsp;</td><td class='base' width='25%'>
433 <select name='SYSLOGLEVEL'>
434 <option value='0' $selected{'SYSLOGLEVEL'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option>
435 <option value='1' $selected{'SYSLOGLEVEL'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option>
436 <option value='2' $selected{'SYSLOGLEVEL'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option>
437 <option value='3' $selected{'SYSLOGLEVEL'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option>
438 <option value='4' $selected{'SYSLOGLEVEL'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option>
439 </select>
440 </td>
441 <td width='25%' class='base'>Debuglevel (hostapd):&nbsp;</td><td class='base' width='25%'>
442 <select name='DEBUG'>
443 <option value='0' $selected{'DEBUG'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option>
444 <option value='1' $selected{'DEBUG'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option>
445 <option value='2' $selected{'DEBUG'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option>
446 <option value='3' $selected{'DEBUG'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option>
447 <option value='4' $selected{'DEBUG'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option>
448 </select>
449 </td></tr>
450 <tr><td colspan='4'><br></td></tr>
451 </table>
452 END
453 ;
454 if ( $wlanapsettings{'INTERFACE'} =~ /green0/ ){
455 print <<END
456 <br />
457 <table width='80%' cellspacing='0' class='tbl' border='1'>
458 <tr>
459 <th colspan='3' align='left'>$Lang::tr{'mac filter'}</th>
460 </tr>
461 <td width='25%' class='base'>Mac Filter:&nbsp;</td><td class='base' width='25%'>
462 <select name='MACMODE'>
463 <option value='0' $selected{'MACMODE'}{'0'}>0 (off)</option>
464 <option value='1' $selected{'MACMODE'}{'1'}>1 (Accept MACs)</option>
465 <option value='2' $selected{'MACMODE'}{'2'}>2 (Deny MACs)</option>
466 </select>
467 </td><td colspan='2'>Mac Adress List (one per line)<br /><textarea name='MACS' cols='20' rows='5' wrap='off'>
468 END
469 ;
470 print `cat /var/ipfire/wlanap/macfile`;
471 print <<END
472 </textarea></td>
473 </table>
474 END
475 ;
476 }
477 print <<END
478 <br />
479 <table width='80%' cellspacing='0'>
480 <tr><td align='center'>
481 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
482 <input type='hidden' name='ACTION' value=$Lang::tr{'save'} />
483 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></form></td>
484 </tr>
485 </table>
486 END
487 ;
488 my @status;
489 if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){
490 @status = `iw dev $wlanapsettings{'INTERFACE'} info && iw dev $wlanapsettings{'INTERFACE'} station dump && echo ""`;
491 }
492 print <<END
493 <br />
494 <table width='80%' cellspacing='0' class='tbl'>
495 <tr><th colspan='3' bgcolor='$color{'color20'}' align='left'><strong>$Lang::tr{'wlanap wlan status'}</strong></th></tr>
496 END
497 ;
498
499 for (my $i=0;$i<$#status;$i++){
500
501 if (@status[$i]=~"^Station ") { $count++; }
502 if ($count % 2){
503 $col="bgcolor='$color{'color20'}'";
504 }else{
505 $col="bgcolor='$color{'color22'}'";
506 }
507 print"<tr><td colspan='3' $col><pre>@status[$i]</pre></td></tr>";
508 if (! @status[$i]=~"^/t" ) { $count++; }
509 }
510 $count++;
511
512 foreach my $nr (@channellist_cmd){
513 if ($count % 2){
514 $col="bgcolor='$color{'color20'}'";
515 }else{
516 $col="bgcolor='$color{'color22'}'";
517 }
518 print"<tr><td colspan='3' $col>$nr</td></tr>";
519 $count++;
520 }
521
522 for (my $i=0;$i<$#txpower_cmd;$i=$i+2){
523 if ($count % 2){
524 $col="bgcolor='$color{'color20'}'";
525 }else{
526 $col="bgcolor='$color{'color22'}'";
527 }
528 print "<tr><td $col>@txpower_cmd[$i]</td></tr>";
529 $count++;
530 }
531 print "</table><br>";
532 print <<END
533 <br />
534 <table width='80%' cellspacing='0' class='tbl' border='0'>
535 <tr><td bgcolor='$color{'color20'}' align='left'><strong>$Lang::tr{'wlan clients'}</strong></td></tr>
536 <tr><td>&nbsp;<a href="/cgi-bin/wireless.cgi">$Lang::tr{'wlanap link wireless'}</a></td></tr>
537 <tr><td>&nbsp;<a href="/cgi-bin/dhcp.cgi">$Lang::tr{'wlanap link dhcp'}</a></td></tr>
538 <tr><td><br></td></tr>
539 </table>
540 END
541 ;
542 &Header::closebox();
543 print "</form>";
544 &Header::closebigbox();
545 &Header::closepage();
546
547 sub WriteConfig_hostapd{
548 $wlanapsettings{'DRIVER_HOSTAPD'} = lc($wlanapsettings{'DRIVER'});
549
550 open (CONFIGFILE, ">/var/ipfire/wlanap/hostapd.conf");
551 print CONFIGFILE <<END
552 driver=$wlanapsettings{'DRIVER_HOSTAPD'}
553 ######################### basic hostapd configuration ##########################
554 #
555 interface=$wlanapsettings{'INTERFACE'}
556 country_code=$wlanapsettings{'COUNTRY'}
557 ieee80211d=1
558 ieee80211h=1
559 channel=$wlanapsettings{'CHANNEL'}
560 END
561 ;
562 if ( $wlanapsettings{'HW_MODE'} eq 'an' ){
563 print CONFIGFILE <<END
564 hw_mode=a
565 ieee80211n=1
566 wmm_enabled=1
567 ht_capab=$wlanapsettings{'HTCAPS'}
568 END
569 ;
570
571 }elsif ( $wlanapsettings{'HW_MODE'} eq 'gn' ){
572 print CONFIGFILE <<END
573 hw_mode=g
574 ieee80211n=1
575 wmm_enabled=1
576 ht_capab=$wlanapsettings{'HTCAPS'}
577 END
578 ;
579
580 }else{
581 print CONFIGFILE <<END
582 hw_mode=$wlanapsettings{'HW_MODE'}
583 END
584 ;
585
586 }
587
588 print CONFIGFILE <<END
589 logger_syslog=-1
590 logger_syslog_level=$wlanapsettings{'SYSLOGLEVEL'}
591 logger_stdout=-1
592 logger_stdout_level=$wlanapsettings{'DEBUG'}
593 dump_file=/tmp/hostapd.dump
594 auth_algs=1
595 ctrl_interface=/var/run/hostapd
596 ctrl_interface_group=0
597 END
598 ;
599 if ( $wlanapsettings{'HIDESSID'} eq 'on' ){
600 print CONFIGFILE <<END
601 ssid=$wlanapsettings{'SSID'}
602 ignore_broadcast_ssid=2
603 END
604 ;
605
606 }else{
607 print CONFIGFILE <<END
608 ssid=$wlanapsettings{'SSID'}
609 ignore_broadcast_ssid=0
610 END
611 ;
612
613 }
614
615 if ( $wlanapsettings{'ENC'} eq 'wpa1'){
616 print CONFIGFILE <<END
617 ######################### wpa hostapd configuration ############################
618 #
619 wpa=1
620 wpa_passphrase=$wlanapsettings{'PWD'}
621 wpa_key_mgmt=WPA-PSK
622 wpa_pairwise=TKIP
623 END
624 ;
625 }elsif ( $wlanapsettings{'ENC'} eq 'wpa2'){
626 print CONFIGFILE <<END
627 ######################### wpa hostapd configuration ############################
628 #
629 wpa=2
630 wpa_passphrase=$wlanapsettings{'PWD'}
631 wpa_key_mgmt=WPA-PSK
632 rsn_pairwise=CCMP
633 END
634 ;
635 } elsif ( $wlanapsettings{'ENC'} eq 'wpa1+2'){
636 print CONFIGFILE <<END
637 ######################### wpa hostapd configuration ############################
638 #
639 wpa=3
640 wpa_passphrase=$wlanapsettings{'PWD'}
641 wpa_key_mgmt=WPA-PSK
642 wpa_pairwise=TKIP
643 rsn_pairwise=CCMP
644 END
645 ;
646 }
647 close CONFIGFILE;
648
649 open (MACFILE, ">/var/ipfire/wlanap/macfile");
650 foreach(@macs){
651 $_ =~ s/\r//gi;
652 chomp($_);
653 if ( $_ ne "" ){print MACFILE $_;}
654 }
655 close MACFILE;
656 }