]>
Commit | Line | Data |
---|---|---|
27731caa CS |
1 | #!/usr/bin/perl |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
f89678de | 5 | # Copyright (C) 2007-2014 IPFire Team <info@ipfire.org> # |
27731caa CS |
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 | |
8aa49c15 CS |
28 | #use warnings; |
29 | #use CGI::Carp 'fatalsToBrowser'; | |
27731caa CS |
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; | |
8c2f203c | 36 | my $status = ''; |
27731caa | 37 | my $errormessage = ''; |
3827d1f6 AM |
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=''; | |
27731caa CS |
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 = (); | |
54359730 CS |
50 | my %netsettings=(); |
51 | my %wlanapsettings=(); | |
27731caa | 52 | my $channel = ''; |
c3d9a16d | 53 | my $country = ''; |
27731caa CS |
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); | |
54359730 | 58 | &General::readhash("/var/ipfire/ethernet/settings", \%netsettings); |
27731caa | 59 | |
27731caa | 60 | $wlanapsettings{'APMODE'} = 'on'; |
23e368ab | 61 | $wlanapsettings{'ACTION'} = ''; |
92f2665d CS |
62 | $wlanapsettings{'MACMODE'} = '0'; |
63 | $wlanapsettings{'INTERFACE'} = ''; | |
27731caa CS |
64 | $wlanapsettings{'SSID'} = 'IPFire'; |
65 | $wlanapsettings{'HIDESSID'} = 'off'; | |
91197a3f | 66 | $wlanapsettings{'ENC'} = 'wpa2'; # none / wpa1 /wpa2 |
27731caa | 67 | $wlanapsettings{'TXPOWER'} = 'auto'; |
2bb836df | 68 | $wlanapsettings{'CHANNEL'} = '6'; |
c3d9a16d | 69 | $wlanapsettings{'COUNTRY'} = '00'; |
7d30ef24 | 70 | $wlanapsettings{'HW_MODE'} = 'g'; |
27731caa | 71 | $wlanapsettings{'PWD'} = 'IPFire-2.x'; |
27731caa CS |
72 | $wlanapsettings{'SYSLOGLEVEL'} = '0'; |
73 | $wlanapsettings{'DEBUG'} = '4'; | |
c17883fd | 74 | $wlanapsettings{'DRIVER'} = 'NL80211'; |
6e346fe0 | 75 | $wlanapsettings{'HTCAPS'} = ''; |
f887bf5f | 76 | $wlanapsettings{'VHTCAPS'} = ''; |
27731caa | 77 | |
27731caa | 78 | &General::readhash("/var/ipfire/wlanap/settings", \%wlanapsettings); |
23e368ab | 79 | &Header::getcgihash(\%wlanapsettings); |
27731caa | 80 | |
23e368ab | 81 | my @macs = $wlanapsettings{'MACS'}; |
27731caa | 82 | |
23e368ab CS |
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'}; | |
27731caa CS |
89 | |
90 | &Header::showhttpheaders(); | |
91 | ||
182a817a JPT |
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 | ||
23e368ab | 128 | if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'save'}" ){ |
3af89eb5 | 129 | # verify WPA Passphrase - only with enabled enc |
e62efbb7 | 130 | if (($wlanapsettings{'ENC'} eq "wpa1") || ($wlanapsettings{'ENC'} eq "wpa2") || ($wlanapsettings{'ENC'} eq "wpa1+2")){ |
3af89eb5 | 131 | # must be 8 .. 63 characters |
182a817a JPT |
132 | if ( (length($wlanapsettings{'PWD'}) < 8) || (length($wlanapsettings{'PWD'}) > 63)){ |
133 | $errormessage .= "$Lang::tr{'wlanap invalid wpa'}<br />"; | |
134 | } | |
3af89eb5 | 135 | # only ASCII alowed |
cdbeabe2 | 136 | if ( !($wlanapsettings{'PWD'} !~ /[^\x00-\x7f]/) ){ |
3af89eb5 AF |
137 | $errormessage .= "$Lang::tr{'wlanap invalid wpa'}<br />"; |
138 | } | |
27731caa CS |
139 | } |
140 | ||
141 | if ( $errormessage eq '' ){ | |
92f2665d | 142 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); |
27731caa CS |
143 | &WriteConfig_hostapd(); |
144 | ||
91197a3f | 145 | system("/usr/local/bin/wlanapctrl restart >/dev/null 2>&1"); |
182a817a | 146 | pid(); |
27731caa | 147 | } |
182a817a | 148 | }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap interface'}" ){ |
92f2665d | 149 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); |
182a817a | 150 | }elsif ( ($wlanapsettings{'ACTION'} eq "$Lang::tr{'start'}") && ($memory == 0) ){ |
27731caa | 151 | system("/usr/local/bin/wlanapctrl start >/dev/null 2>&1"); |
182a817a JPT |
152 | pid(); |
153 | }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'stop'}" ){ | |
27731caa | 154 | system("/usr/local/bin/wlanapctrl stop >/dev/null 2>&1"); |
182a817a | 155 | $memory=0; |
27731caa CS |
156 | } |
157 | ||
d3790c6a | 158 | &Header::openpage($Lang::tr{'wlanap configuration'}, 1, '', ''); |
27731caa | 159 | &Header::openbigbox('100%', 'left', '', $errormessage); |
27731caa CS |
160 | |
161 | if ( $errormessage ){ | |
54359730 | 162 | &Header::openbox('100%', 'center', $Lang::tr{'error messages'}); |
27731caa CS |
163 | print "<class name='base'>$errormessage\n"; |
164 | print " </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 ){ | |
54359730 | 174 | &Header::openbox('100%', 'center', 'DEBUG'); |
27731caa | 175 | my $debugCount = 0; |
23e368ab CS |
176 | foreach my $line (sort keys %wlanapsettings) { |
177 | print "$line = '$wlanapsettings{$line}'<br />\n"; | |
27731caa CS |
178 | $debugCount++; |
179 | } | |
180 | print " 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 = ''; | |
92f2665d CS |
191 | my $message = ""; |
192 | ||
193 | $selected{'INTERFACE'}{'green0'} = ''; | |
194 | $selected{'INTERFACE'}{'blue0'} = ''; | |
195 | $selected{'ENC'}{$wlanapsettings{'INTERFACE'}} = "selected='selected'"; | |
27731caa | 196 | |
92f2665d | 197 | if ( ($wlanapsettings{'INTERFACE'} eq '') ){ |
182a817a | 198 | $message = $Lang::tr{'wlanap select interface'}; |
92f2665d CS |
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'> | |
92f2665d CS |
204 | END |
205 | ; | |
206 | if ( $netsettings{'BLUE_DEV'} ne ''){ | |
207 | print "<option value='blue0' $selected{'INTERFACE'}{'blue0'}>blue0</option>"; | |
208 | } | |
209 | print <<END | |
182a817a | 210 | <option value='green0' $selected{'INTERFACE'}{'green0'}>green0</option> |
92f2665d | 211 | </select> |
182a817a JPT |
212 | <br /><br /> |
213 | <hr size='1'> | |
214 | <input type='submit' name='ACTION' value='$Lang::tr{'wlanap interface'}' /></form> | |
92f2665d CS |
215 | END |
216 | ; | |
217 | &Header::closebox(); | |
218 | &Header::closebigbox(); | |
219 | &Header::closepage(); | |
220 | exit; | |
27731caa | 221 | }else{ |
92f2665d | 222 | my $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} 2>/dev/null`; |
27731caa CS |
223 | |
224 | if ( $cmd_out eq '' ){ | |
182a817a | 225 | $message = "$Lang::tr{'wlanap no interface'}"; |
92f2665d | 226 | $wlan_card_status = ''; |
27731caa | 227 | }else{ |
92f2665d | 228 | $cmd_out = `/sbin/ifconfig | /bin/grep $wlanapsettings{'INTERFACE'}`; |
27731caa CS |
229 | if ( $cmd_out eq '' ){ |
230 | $wlan_card_status = 'down'; | |
231 | }else{ | |
232 | $wlan_card_status = 'up'; | |
92f2665d | 233 | $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} | /bin/grep "Mode:Master"`; |
27731caa CS |
234 | if ( $cmd_out ne '' ){ |
235 | $wlan_ap_status = 'up'; | |
27731caa CS |
236 | } |
237 | } | |
238 | } | |
239 | } | |
240 | ||
e62efbb7 AF |
241 | # Change old "n" to "gn" |
242 | if ( $wlanapsettings{'HW_MODE'} eq 'n' ) { | |
243 | $wlanapsettings{'HW_MODE'}='gn'; | |
244 | } | |
245 | ||
b8990355 CS |
246 | $checked{'HIDESSID'}{'off'} = ''; |
247 | $checked{'HIDESSID'}{'on'} = ''; | |
248 | $checked{'HIDESSID'}{$wlanapsettings{'HIDESSID'}} = "checked='checked'"; | |
27731caa | 249 | |
27731caa | 250 | $selected{'ENC'}{$wlanapsettings{'ENC'}} = "selected='selected'"; |
30313f28 | 251 | $selected{'CHANNEL'}{$wlanapsettings{'CHANNEL'}} = "selected='selected'"; |
c3d9a16d | 252 | $selected{'COUNTRY'}{$wlanapsettings{'COUNTRY'}} = "selected='selected'"; |
54359730 | 253 | $selected{'TXPOWER'}{$wlanapsettings{'TXPOWER'}} = "selected='selected'"; |
7d30ef24 | 254 | $selected{'HW_MODE'}{$wlanapsettings{'HW_MODE'}} = "selected='selected'"; |
92f2665d | 255 | $selected{'MACMODE'}{$wlanapsettings{'MACMODE'}} = "selected='selected'"; |
27731caa | 256 | |
c3d9a16d | 257 | my $monwlaninterface = $wlanapsettings{'INTERFACE'}; |
56c2cc65 | 258 | if ( -d '/sys/class/net/mon.'.$wlanapsettings{'INTERFACE'} ) { |
c3d9a16d AF |
259 | $monwlaninterface = 'mon.'.$wlanapsettings{'INTERFACE'}; |
260 | } | |
261 | ||
0f0d6a5a AF |
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 | ||
05583186 | 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`; |
0f0d6a5a AF |
270 | # get available channels |
271 | ||
272 | my @temp; | |
273 | foreach (@channellist_cmd){ | |
274 | $_ =~ /(.*) \[(\d+)(.*)\]/; | |
275 | $channel = $2;chomp $channel; | |
12f74b8f | 276 | if ( $channel =~ /\d+/ ){push(@temp,$channel + 0);} |
0f0d6a5a AF |
277 | } |
278 | @channellist = @temp; | |
279 | } else { | |
280 | @channellist_cmd = `iwlist $monwlaninterface channel|tail -n +2 2>/dev/null`; | |
27731caa | 281 | # get available channels |
27731caa | 282 | |
54359730 | 283 | my @temp; |
8c2f203c | 284 | foreach (@channellist_cmd){ |
54359730 | 285 | $_ =~ /(.*)Channel (\d+)(.*):/; |
8c2f203c | 286 | $channel = $2;chomp $channel; |
12f74b8f | 287 | if ( $channel =~ /\d+/ ){push(@temp,$channel + 0);} |
27731caa | 288 | } |
0f0d6a5a AF |
289 | @channellist = @temp; |
290 | } | |
54359730 | 291 | |
c3d9a16d AF |
292 | my @countrylist_cmd = `regdbdump /usr/lib/crda/regulatory.bin 2>/dev/null`; |
293 | # get available country codes | |
294 | ||
8e23b351 | 295 | my @temp = "00"; |
c3d9a16d AF |
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 | |
27731caa | 309 | |
27731caa | 310 | $selected{'SYSLOGLEVEL'}{$wlanapsettings{'SYSLOGLEVEL'}} = "selected='selected'"; |
27731caa CS |
311 | $selected{'DEBUG'}{$wlanapsettings{'DEBUG'}} = "selected='selected'"; |
312 | ||
313 | # | |
314 | # Status box | |
315 | # | |
54359730 | 316 | &Header::openbox('100%', 'center', "WLAN AP"); |
27731caa | 317 | print <<END |
3827d1f6 | 318 | <table width='80%' cellspacing='1' class='tbl'> |
27731caa CS |
319 | END |
320 | ; | |
182a817a | 321 | |
27731caa | 322 | if ( $wlan_card_status ne '' ){ |
3827d1f6 AM |
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>"; | |
27731caa | 325 | print $wlan_card_status eq 'up' ? $status_started : $status_stopped; |
3827d1f6 | 326 | print"<td colspan='4'></td></tr>"; |
d3790c6a | 327 | print "<tr><td class='base' bgcolor='$color{'color22'}'>$Lang::tr{'wlanap'}</td>"; |
27731caa | 328 | print $wlan_ap_status eq 'up' ? $status_started : $status_stopped; |
3827d1f6 AM |
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 | } | |
182a817a | 339 | |
27731caa | 340 | }else{ |
3827d1f6 | 341 | print "<tr><td class='base'>$message"; |
182a817a JPT |
342 | } |
343 | print "</table>"; | |
344 | ||
3827d1f6 AM |
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>"; | |
182a817a | 350 | print "</tr>"; |
3827d1f6 AM |
351 | print "<tr align='center'>"; |
352 | print "<td width='40%'> </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>"; | |
182a817a JPT |
356 | print "</tr>"; |
357 | print "</table>"; | |
27731caa | 358 | } |
27731caa CS |
359 | |
360 | if ( $wlan_card_status eq '' ){ | |
92f2665d | 361 | &Header::closebox(); |
27731caa CS |
362 | &Header::closebigbox(); |
363 | &Header::closepage(); | |
364 | exit 0; | |
365 | } | |
27731caa | 366 | print <<END |
3827d1f6 | 367 | <br><br> |
23e368ab | 368 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
3827d1f6 AM |
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: </td><td class='base' colspan='3'><input type='text' name='SSID' size='30' value='$wlanapsettings{'SSID'}' /></td></tr> | |
0d4e628e JPT |
373 | <!--SSID Broadcast: on => HIDESSID: off --> |
374 | <tr><td width='25%' class='base'>SSID Broadcast: </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> | |
3827d1f6 AM |
375 | |
376 | ||
377 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap country'}: </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> | |
7d30ef24 AF |
386 | <tr><td width='25%' class='base'>HW Mode: </td><td class='base' colspan='3'> |
387 | <select name='HW_MODE'> | |
182a817a JPT |
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> | |
e62efbb7 AF |
391 | <option value='an' $selected{'HW_MODE'}{'an'}>802.11an</option> |
392 | <option value='gn' $selected{'HW_MODE'}{'gn'}>802.11gn</option> | |
f887bf5f | 393 | <option value='ac' $selected{'HW_MODE'}{'ac'}>802.11ac</option> |
7d30ef24 AF |
394 | </select> |
395 | </td></tr> | |
fe3f3050 AF |
396 | END |
397 | ; | |
398 | ||
fe3f3050 AF |
399 | if ( scalar @channellist > 0 ){ |
400 | print <<END | |
182a817a | 401 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap channel'}: </td><td class='base' colspan='3'> |
30313f28 | 402 | <select name='CHANNEL'> |
27731caa CS |
403 | END |
404 | ; | |
fe3f3050 AF |
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'}: </td><td class='base' colspan='3'> | |
412 | <input type='text' name='CHANNEL' size='10' value='$wlanapsettings{'CHANNEL'}' /> | |
413 | </td></tr> | |
414 | END | |
415 | ; | |
27731caa | 416 | } |
3827d1f6 AM |
417 | print<<END |
418 | <tr><td colspan='4'><br></td></tr> | |
419 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap encryption'}: </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: </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> | |
c3d9a16d AF |
429 | END |
430 | ; | |
27731caa | 431 | print <<END |
3827d1f6 | 432 | <tr><td width='25%' class='base'>HT Caps: </td><td class='base' colspan='3'><input type='text' name='HTCAPS' size='30' value='$wlanapsettings{'HTCAPS'}' /></td></tr> |
f887bf5f | 433 | <tr><td width='25%' class='base'>VHT Caps: </td><td class='base' colspan='3'><input type='text' name='VHTCAPS' size='30' value='$wlanapsettings{'VHTCAPS'}' /></td></tr> |
c17883fd | 434 | <tr><td width='25%' class='base'>Tx Power: </td><td class='base' colspan='3'><input type='text' name='TXPOWER' size='10' value='$wlanapsettings{'TXPOWER'}' /></td></tr> |
27731caa CS |
435 | <tr><td width='25%' class='base'>Loglevel (hostapd): </td><td class='base' width='25%'> |
436 | <select name='SYSLOGLEVEL'> | |
182a817a JPT |
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> | |
27731caa CS |
442 | </select> |
443 | </td> | |
444 | <td width='25%' class='base'>Debuglevel (hostapd): </td><td class='base' width='25%'> | |
445 | <select name='DEBUG'> | |
182a817a JPT |
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> | |
27731caa CS |
451 | </select> |
452 | </td></tr> | |
3827d1f6 | 453 | <tr><td colspan='4'><br></td></tr> |
27731caa | 454 | </table> |
92f2665d CS |
455 | END |
456 | ; | |
457 | if ( $wlanapsettings{'INTERFACE'} =~ /green0/ ){ | |
458 | print <<END | |
459 | <br /> | |
3827d1f6 AM |
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> | |
92f2665d CS |
464 | <td width='25%' class='base'>Mac Filter: </td><td class='base' width='25%'> |
465 | <select name='MACMODE'> | |
466 | <option value='0' $selected{'MACMODE'}{'0'}>0 (off)</option> | |
8aa49c15 CS |
467 | <option value='1' $selected{'MACMODE'}{'1'}>1 (Accept MACs)</option> |
468 | <option value='2' $selected{'MACMODE'}{'2'}>2 (Deny MACs)</option> | |
92f2665d | 469 | </select> |
8aa49c15 | 470 | </td><td colspan='2'>Mac Adress List (one per line)<br /><textarea name='MACS' cols='20' rows='5' wrap='off'> |
92f2665d CS |
471 | END |
472 | ; | |
8aa49c15 | 473 | print `cat /var/ipfire/wlanap/macfile`; |
92f2665d CS |
474 | print <<END |
475 | </textarea></td> | |
92f2665d CS |
476 | </table> |
477 | END | |
478 | ; | |
479 | } | |
480 | print <<END | |
54359730 | 481 | <br /> |
3827d1f6 | 482 | <table width='80%' cellspacing='0'> |
735fce60 | 483 | <tr><td align='center'> |
182a817a | 484 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
735fce60 JPT |
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> | |
27731caa CS |
487 | </tr> |
488 | </table> | |
489 | END | |
490 | ; | |
0f0d6a5a | 491 | my @status; |
7d30ef24 | 492 | if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ |
513c321e | 493 | @status = `iw dev $wlanapsettings{'INTERFACE'} info && iw dev $wlanapsettings{'INTERFACE'} station dump && echo ""`; |
7d30ef24 | 494 | } |
54359730 CS |
495 | print <<END |
496 | <br /> | |
3827d1f6 AM |
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 | ; | |
0f0d6a5a AF |
501 | |
502 | for (my $i=0;$i<$#status;$i++){ | |
503 | ||
504 | if (@status[$i]=~"^Station ") { $count++; } | |
505 | if ($count % 2){ | |
3827d1f6 AM |
506 | $col="bgcolor='$color{'color20'}'"; |
507 | }else{ | |
508 | $col="bgcolor='$color{'color22'}'"; | |
509 | } | |
0f0d6a5a AF |
510 | print"<tr><td colspan='3' $col><pre>@status[$i]</pre></td></tr>"; |
511 | if (! @status[$i]=~"^/t" ) { $count++; } | |
3827d1f6 | 512 | } |
0f0d6a5a AF |
513 | $count++; |
514 | ||
515 | foreach my $nr (@channellist_cmd){ | |
516 | if ($count % 2){ | |
3827d1f6 AM |
517 | $col="bgcolor='$color{'color20'}'"; |
518 | }else{ | |
519 | $col="bgcolor='$color{'color22'}'"; | |
520 | } | |
0f0d6a5a | 521 | print"<tr><td colspan='3' $col>$nr</td></tr>"; |
3827d1f6 AM |
522 | $count++; |
523 | } | |
0f0d6a5a AF |
524 | |
525 | for (my $i=0;$i<$#txpower_cmd;$i=$i+2){ | |
3827d1f6 AM |
526 | if ($count % 2){ |
527 | $col="bgcolor='$color{'color20'}'"; | |
528 | }else{ | |
529 | $col="bgcolor='$color{'color22'}'"; | |
530 | } | |
0f0d6a5a | 531 | print "<tr><td $col>@txpower_cmd[$i]</td></tr>"; |
3827d1f6 AM |
532 | $count++; |
533 | } | |
534 | print "</table><br>"; | |
535 | print <<END | |
182a817a | 536 | <br /> |
3827d1f6 AM |
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> | |
182a817a JPT |
539 | <tr><td> <a href="/cgi-bin/wireless.cgi">$Lang::tr{'wlanap link wireless'}</a></td></tr> |
540 | <tr><td> <a href="/cgi-bin/dhcp.cgi">$Lang::tr{'wlanap link dhcp'}</a></td></tr> | |
3827d1f6 | 541 | <tr><td><br></td></tr> |
182a817a | 542 | </table> |
54359730 CS |
543 | END |
544 | ; | |
545 | &Header::closebox(); | |
27731caa CS |
546 | print "</form>"; |
547 | &Header::closebigbox(); | |
548 | &Header::closepage(); | |
549 | ||
27731caa CS |
550 | sub WriteConfig_hostapd{ |
551 | $wlanapsettings{'DRIVER_HOSTAPD'} = lc($wlanapsettings{'DRIVER'}); | |
552 | ||
553 | open (CONFIGFILE, ">/var/ipfire/wlanap/hostapd.conf"); | |
554 | print CONFIGFILE <<END | |
cdbeabe2 | 555 | driver=$wlanapsettings{'DRIVER_HOSTAPD'} |
54359730 | 556 | ######################### basic hostapd configuration ########################## |
891b6138 | 557 | # |
92f2665d | 558 | interface=$wlanapsettings{'INTERFACE'} |
cdbeabe2 AF |
559 | country_code=$wlanapsettings{'COUNTRY'} |
560 | ieee80211d=1 | |
f89678de | 561 | ieee80211h=1 |
7d30ef24 | 562 | channel=$wlanapsettings{'CHANNEL'} |
b8012afd CS |
563 | END |
564 | ; | |
e62efbb7 AF |
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' ){ | |
b8012afd CS |
575 | print CONFIGFILE <<END |
576 | hw_mode=g | |
577 | ieee80211n=1 | |
6e346fe0 CS |
578 | wmm_enabled=1 |
579 | ht_capab=$wlanapsettings{'HTCAPS'} | |
b8012afd | 580 | END |
f887bf5f MT |
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 | |
b8012afd CS |
592 | ; |
593 | ||
594 | }else{ | |
595 | print CONFIGFILE <<END | |
8ad457eb CS |
596 | hw_mode=$wlanapsettings{'HW_MODE'} |
597 | END | |
b8012afd CS |
598 | ; |
599 | ||
600 | } | |
601 | ||
8ad457eb | 602 | print CONFIGFILE <<END |
27731caa CS |
603 | logger_syslog=-1 |
604 | logger_syslog_level=$wlanapsettings{'SYSLOGLEVEL'} | |
605 | logger_stdout=-1 | |
54359730 | 606 | logger_stdout_level=$wlanapsettings{'DEBUG'} |
27731caa | 607 | dump_file=/tmp/hostapd.dump |
7d30ef24 | 608 | auth_algs=1 |
27731caa CS |
609 | ctrl_interface=/var/run/hostapd |
610 | ctrl_interface_group=0 | |
27731caa CS |
611 | END |
612 | ; | |
54359730 CS |
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 | } | |
92f2665d | 628 | |
8c2f203c CS |
629 | if ( $wlanapsettings{'ENC'} eq 'wpa1'){ |
630 | print CONFIGFILE <<END | |
631 | ######################### wpa hostapd configuration ############################ | |
891b6138 | 632 | # |
8c2f203c CS |
633 | wpa=1 |
634 | wpa_passphrase=$wlanapsettings{'PWD'} | |
891b6138 | 635 | wpa_key_mgmt=WPA-PSK |
e62efbb7 | 636 | wpa_pairwise=TKIP |
8c2f203c CS |
637 | END |
638 | ; | |
639 | }elsif ( $wlanapsettings{'ENC'} eq 'wpa2'){ | |
54359730 CS |
640 | print CONFIGFILE <<END |
641 | ######################### wpa hostapd configuration ############################ | |
891b6138 | 642 | # |
8c2f203c | 643 | wpa=2 |
54359730 | 644 | wpa_passphrase=$wlanapsettings{'PWD'} |
891b6138 | 645 | wpa_key_mgmt=WPA-PSK |
e62efbb7 AF |
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 | |
54359730 CS |
658 | END |
659 | ; | |
660 | } | |
27731caa | 661 | close CONFIGFILE; |
92f2665d | 662 | |
8aa49c15 | 663 | open (MACFILE, ">/var/ipfire/wlanap/macfile"); |
23e368ab CS |
664 | foreach(@macs){ |
665 | $_ =~ s/\r//gi; | |
666 | chomp($_); | |
667 | if ( $_ ne "" ){print MACFILE $_;} | |
668 | } | |
92f2665d | 669 | close MACFILE; |
27731caa | 670 | } |