]>
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'; |
30313f28 | 68 | $wlanapsettings{'CHANNEL'} = '05'; |
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'; | |
8c2f203c | 74 | $wlanapsettings{'DRIVER'} = 'MADWIFI'; |
6e346fe0 | 75 | $wlanapsettings{'HTCAPS'} = ''; |
27731caa | 76 | |
27731caa | 77 | &General::readhash("/var/ipfire/wlanap/settings", \%wlanapsettings); |
23e368ab | 78 | &Header::getcgihash(\%wlanapsettings); |
27731caa | 79 | |
23e368ab | 80 | my @macs = $wlanapsettings{'MACS'}; |
27731caa | 81 | |
23e368ab CS |
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'}; | |
27731caa CS |
88 | |
89 | &Header::showhttpheaders(); | |
90 | ||
182a817a JPT |
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 | ||
23e368ab | 127 | if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'save'}" ){ |
3af89eb5 | 128 | # verify WPA Passphrase - only with enabled enc |
e62efbb7 | 129 | if (($wlanapsettings{'ENC'} eq "wpa1") || ($wlanapsettings{'ENC'} eq "wpa2") || ($wlanapsettings{'ENC'} eq "wpa1+2")){ |
3af89eb5 | 130 | # must be 8 .. 63 characters |
182a817a JPT |
131 | if ( (length($wlanapsettings{'PWD'}) < 8) || (length($wlanapsettings{'PWD'}) > 63)){ |
132 | $errormessage .= "$Lang::tr{'wlanap invalid wpa'}<br />"; | |
133 | } | |
3af89eb5 | 134 | # only ASCII alowed |
cdbeabe2 | 135 | if ( !($wlanapsettings{'PWD'} !~ /[^\x00-\x7f]/) ){ |
3af89eb5 AF |
136 | $errormessage .= "$Lang::tr{'wlanap invalid wpa'}<br />"; |
137 | } | |
27731caa CS |
138 | } |
139 | ||
140 | if ( $errormessage eq '' ){ | |
92f2665d | 141 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); |
27731caa CS |
142 | &WriteConfig_hostapd(); |
143 | ||
91197a3f | 144 | system("/usr/local/bin/wlanapctrl restart >/dev/null 2>&1"); |
182a817a | 145 | pid(); |
27731caa | 146 | } |
182a817a | 147 | }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap interface'}" ){ |
92f2665d | 148 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); |
182a817a | 149 | }elsif ( ($wlanapsettings{'ACTION'} eq "$Lang::tr{'start'}") && ($memory == 0) ){ |
27731caa | 150 | system("/usr/local/bin/wlanapctrl start >/dev/null 2>&1"); |
182a817a JPT |
151 | pid(); |
152 | }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'stop'}" ){ | |
27731caa | 153 | system("/usr/local/bin/wlanapctrl stop >/dev/null 2>&1"); |
182a817a | 154 | $memory=0; |
27731caa CS |
155 | } |
156 | ||
3827d1f6 | 157 | &Header::openpage('', 1, '', ''); |
27731caa | 158 | &Header::openbigbox('100%', 'left', '', $errormessage); |
27731caa CS |
159 | |
160 | if ( $errormessage ){ | |
54359730 | 161 | &Header::openbox('100%', 'center', $Lang::tr{'error messages'}); |
27731caa CS |
162 | print "<class name='base'>$errormessage\n"; |
163 | print " </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 ){ | |
54359730 | 173 | &Header::openbox('100%', 'center', 'DEBUG'); |
27731caa | 174 | my $debugCount = 0; |
23e368ab CS |
175 | foreach my $line (sort keys %wlanapsettings) { |
176 | print "$line = '$wlanapsettings{$line}'<br />\n"; | |
27731caa CS |
177 | $debugCount++; |
178 | } | |
179 | print " 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 = ''; | |
92f2665d CS |
190 | my $message = ""; |
191 | ||
192 | $selected{'INTERFACE'}{'green0'} = ''; | |
193 | $selected{'INTERFACE'}{'blue0'} = ''; | |
194 | $selected{'ENC'}{$wlanapsettings{'INTERFACE'}} = "selected='selected'"; | |
27731caa | 195 | |
92f2665d | 196 | if ( ($wlanapsettings{'INTERFACE'} eq '') ){ |
182a817a | 197 | $message = $Lang::tr{'wlanap select interface'}; |
92f2665d CS |
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'> | |
92f2665d CS |
203 | END |
204 | ; | |
205 | if ( $netsettings{'BLUE_DEV'} ne ''){ | |
206 | print "<option value='blue0' $selected{'INTERFACE'}{'blue0'}>blue0</option>"; | |
207 | } | |
208 | print <<END | |
182a817a | 209 | <option value='green0' $selected{'INTERFACE'}{'green0'}>green0</option> |
92f2665d | 210 | </select> |
182a817a JPT |
211 | <br /><br /> |
212 | <hr size='1'> | |
213 | <input type='submit' name='ACTION' value='$Lang::tr{'wlanap interface'}' /></form> | |
92f2665d CS |
214 | END |
215 | ; | |
216 | &Header::closebox(); | |
217 | &Header::closebigbox(); | |
218 | &Header::closepage(); | |
219 | exit; | |
27731caa | 220 | }else{ |
92f2665d | 221 | my $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} 2>/dev/null`; |
27731caa CS |
222 | |
223 | if ( $cmd_out eq '' ){ | |
182a817a | 224 | $message = "$Lang::tr{'wlanap no interface'}"; |
92f2665d | 225 | $wlan_card_status = ''; |
27731caa | 226 | }else{ |
92f2665d | 227 | $cmd_out = `/sbin/ifconfig | /bin/grep $wlanapsettings{'INTERFACE'}`; |
27731caa CS |
228 | if ( $cmd_out eq '' ){ |
229 | $wlan_card_status = 'down'; | |
230 | }else{ | |
231 | $wlan_card_status = 'up'; | |
92f2665d | 232 | $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} | /bin/grep "Mode:Master"`; |
27731caa CS |
233 | if ( $cmd_out ne '' ){ |
234 | $wlan_ap_status = 'up'; | |
27731caa CS |
235 | } |
236 | } | |
237 | } | |
238 | } | |
239 | ||
e62efbb7 AF |
240 | # Change old "n" to "gn" |
241 | if ( $wlanapsettings{'HW_MODE'} eq 'n' ) { | |
242 | $wlanapsettings{'HW_MODE'}='gn'; | |
243 | } | |
244 | ||
b8990355 CS |
245 | $checked{'HIDESSID'}{'off'} = ''; |
246 | $checked{'HIDESSID'}{'on'} = ''; | |
247 | $checked{'HIDESSID'}{$wlanapsettings{'HIDESSID'}} = "checked='checked'"; | |
27731caa | 248 | |
27731caa | 249 | $selected{'ENC'}{$wlanapsettings{'ENC'}} = "selected='selected'"; |
30313f28 | 250 | $selected{'CHANNEL'}{$wlanapsettings{'CHANNEL'}} = "selected='selected'"; |
c3d9a16d | 251 | $selected{'COUNTRY'}{$wlanapsettings{'COUNTRY'}} = "selected='selected'"; |
54359730 | 252 | $selected{'TXPOWER'}{$wlanapsettings{'TXPOWER'}} = "selected='selected'"; |
7d30ef24 | 253 | $selected{'HW_MODE'}{$wlanapsettings{'HW_MODE'}} = "selected='selected'"; |
92f2665d | 254 | $selected{'MACMODE'}{$wlanapsettings{'MACMODE'}} = "selected='selected'"; |
27731caa | 255 | |
c3d9a16d | 256 | my $monwlaninterface = $wlanapsettings{'INTERFACE'}; |
56c2cc65 | 257 | if ( -d '/sys/class/net/mon.'.$wlanapsettings{'INTERFACE'} ) { |
c3d9a16d AF |
258 | $monwlaninterface = 'mon.'.$wlanapsettings{'INTERFACE'}; |
259 | } | |
260 | ||
0f0d6a5a AF |
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 | ||
91eb94ee | 268 | @channellist_cmd = `iw phy phy$wiphy info | grep " MHz \\\[" | grep -v "(disabled)" | grep -v "no IBSS" | grep -v "passive scanning" 2>/dev/null`; |
0f0d6a5a AF |
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);} | |
276 | } | |
277 | @channellist = @temp; | |
278 | } else { | |
279 | @channellist_cmd = `iwlist $monwlaninterface channel|tail -n +2 2>/dev/null`; | |
27731caa | 280 | # get available channels |
27731caa | 281 | |
54359730 | 282 | my @temp; |
8c2f203c | 283 | foreach (@channellist_cmd){ |
54359730 | 284 | $_ =~ /(.*)Channel (\d+)(.*):/; |
8c2f203c | 285 | $channel = $2;chomp $channel; |
54359730 | 286 | if ( $channel =~ /\d+/ ){push(@temp,$channel);} |
27731caa | 287 | } |
0f0d6a5a AF |
288 | @channellist = @temp; |
289 | } | |
54359730 | 290 | |
c3d9a16d AF |
291 | my @countrylist_cmd = `regdbdump /usr/lib/crda/regulatory.bin 2>/dev/null`; |
292 | # get available country codes | |
293 | ||
294 | my @temp; | |
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 | |
27731caa | 308 | |
54359730 | 309 | my @temp; |
8c2f203c | 310 | foreach (@txpower_cmd){ |
54359730 | 311 | $_ =~ /(\s)(\d+)(\s)dBm(\s)(.*)(\W)(\d+)(.*)/; |
8c2f203c CS |
312 | $txpower = $7;chomp $txpower; |
313 | if ( $txpower =~ /\d+/ ){push(@temp,$txpower."mW");} | |
54359730 | 314 | } |
8c2f203c | 315 | my @txpower = @temp; |
54359730 | 316 | push(@txpower,"auto"); |
27731caa | 317 | |
27731caa | 318 | $selected{'SYSLOGLEVEL'}{$wlanapsettings{'SYSLOGLEVEL'}} = "selected='selected'"; |
27731caa CS |
319 | $selected{'DEBUG'}{$wlanapsettings{'DEBUG'}} = "selected='selected'"; |
320 | ||
321 | # | |
322 | # Status box | |
323 | # | |
54359730 | 324 | &Header::openbox('100%', 'center', "WLAN AP"); |
27731caa | 325 | print <<END |
3827d1f6 | 326 | <table width='80%' cellspacing='1' class='tbl'> |
27731caa CS |
327 | END |
328 | ; | |
182a817a | 329 | |
27731caa | 330 | if ( $wlan_card_status ne '' ){ |
3827d1f6 AM |
331 | 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>"; |
332 | print "<tr><td class='base'>$Lang::tr{'wlanap wlan card'} ($wlanapsettings{'DRIVER'})</td>"; | |
27731caa | 333 | print $wlan_card_status eq 'up' ? $status_started : $status_stopped; |
3827d1f6 AM |
334 | print"<td colspan='4'></td></tr>"; |
335 | print "<tr><td class='base' bgcolor='$color{'color22'}'>$Lang::tr{'wlanap access point'}</td>"; | |
27731caa | 336 | print $wlan_ap_status eq 'up' ? $status_started : $status_stopped; |
3827d1f6 AM |
337 | if ( ($memory != 0) && (@pid[0] ne "///") ){ |
338 | print "<td bgcolor='$color{'color22'}' align='center'>@pid[0]</td>"; | |
339 | print "<td bgcolor='$color{'color22'}' align='center'>$memory KB</td>"; | |
340 | 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>"; | |
341 | 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>"; | |
342 | }else{ | |
343 | print"<td colspan='2' bgcolor='$color{'color22'}'></td>"; | |
344 | 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>"; | |
345 | 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>"; | |
346 | } | |
182a817a | 347 | |
27731caa | 348 | }else{ |
3827d1f6 | 349 | print "<tr><td class='base'>$message"; |
182a817a JPT |
350 | } |
351 | print "</table>"; | |
352 | ||
3827d1f6 AM |
353 | if ( $wlan_card_status eq '' ){ |
354 | print "<br />"; | |
355 | print "<table width='80%' cellspacing='0' border='0'>"; | |
356 | print "<tr align='center'>"; | |
357 | print "<td colspan='4'></td>"; | |
182a817a | 358 | print "</tr>"; |
3827d1f6 AM |
359 | print "<tr align='center'>"; |
360 | print "<td width='40%'> </td>"; | |
361 | 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>"; | |
362 | print "<td width='20%'></td>"; | |
363 | print "<td width='20%'></td>"; | |
182a817a JPT |
364 | print "</tr>"; |
365 | print "</table>"; | |
27731caa | 366 | } |
27731caa CS |
367 | |
368 | if ( $wlan_card_status eq '' ){ | |
92f2665d | 369 | &Header::closebox(); |
27731caa CS |
370 | &Header::closebigbox(); |
371 | &Header::closepage(); | |
372 | exit 0; | |
373 | } | |
27731caa | 374 | print <<END |
3827d1f6 | 375 | <br><br> |
23e368ab | 376 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
3827d1f6 AM |
377 | <table width='80%' cellspacing='0' class='tbl' border='0'> |
378 | <tr><th bgcolor='$color{'color20'}' colspan='4' align='left'><strong>$Lang::tr{'wlanap wlan settings'}</strong></th></tr> | |
379 | <tr><td colspan='4'><br></td></tr> | |
380 | <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 |
381 | <!--SSID Broadcast: on => HIDESSID: off --> |
382 | <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 |
383 | |
384 | ||
385 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap country'}: </td><td class='base' colspan='3'> | |
386 | <select name='COUNTRY'> | |
387 | END | |
388 | ; | |
389 | foreach $country (@countrylist){ | |
390 | print "<option $selected{'COUNTRY'}{$country}>$country</option>"; | |
391 | } | |
392 | print<<END | |
393 | </select></td></tr> | |
7d30ef24 AF |
394 | <tr><td width='25%' class='base'>HW Mode: </td><td class='base' colspan='3'> |
395 | <select name='HW_MODE'> | |
182a817a JPT |
396 | <option value='a' $selected{'HW_MODE'}{'a'}>802.11a</option> |
397 | <option value='b' $selected{'HW_MODE'}{'b'}>802.11b</option> | |
398 | <option value='g' $selected{'HW_MODE'}{'g'}>802.11g</option> | |
e62efbb7 AF |
399 | <option value='an' $selected{'HW_MODE'}{'an'}>802.11an</option> |
400 | <option value='gn' $selected{'HW_MODE'}{'gn'}>802.11gn</option> | |
7d30ef24 AF |
401 | </select> |
402 | </td></tr> | |
fe3f3050 AF |
403 | END |
404 | ; | |
405 | ||
fe3f3050 AF |
406 | if ( scalar @channellist > 0 ){ |
407 | print <<END | |
182a817a | 408 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap channel'}: </td><td class='base' colspan='3'> |
30313f28 | 409 | <select name='CHANNEL'> |
27731caa CS |
410 | END |
411 | ; | |
fe3f3050 AF |
412 | foreach $channel (@channellist){ |
413 | print "<option $selected{'CHANNEL'}{$channel}>$channel</option>"; | |
414 | } | |
415 | print "</select></td></tr>" | |
416 | } else { | |
417 | print <<END | |
418 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap channel'}: </td><td class='base' colspan='3'> | |
419 | <input type='text' name='CHANNEL' size='10' value='$wlanapsettings{'CHANNEL'}' /> | |
420 | </td></tr> | |
421 | END | |
422 | ; | |
27731caa | 423 | } |
3827d1f6 AM |
424 | print<<END |
425 | <tr><td colspan='4'><br></td></tr> | |
426 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap encryption'}: </td><td class='base' colspan='3'> | |
427 | <select name='ENC'> | |
428 | <option value='none' $selected{'ENC'}{'none'}>$Lang::tr{'wlanap none'}</option> | |
429 | <option value='wpa1' $selected{'ENC'}{'wpa1'}>WPA1</option> | |
430 | <option value='wpa2' $selected{'ENC'}{'wpa2'}>WPA2</option> | |
431 | <option value='wpa1+2' $selected{'ENC'}{'wpa1+2'}>WPA1+2</option> | |
432 | </select> | |
433 | </td></tr> | |
434 | <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> | |
435 | <tr><td colspan='4'><br></td></tr> | |
c3d9a16d AF |
436 | END |
437 | ; | |
27731caa | 438 | print <<END |
3827d1f6 | 439 | <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> |
324cae81 | 440 | <tr><td width='25%' class='base'>Tx Power: </td><td class='base' colspan='3'> |
27731caa CS |
441 | END |
442 | ; | |
324cae81 AF |
443 | |
444 | if ( $wlanapsettings{'DRIVER'} eq 'MADWIFI' ){ | |
445 | print "<select name='TXPOWER'>"; | |
446 | foreach $txpower (@txpower){ | |
447 | print "<option $selected{'TXPOWER'}{$txpower}>$txpower</option> dBm"; | |
448 | } | |
449 | print " </select></td></tr>"; | |
450 | } else { | |
451 | print "<input type='text' name='TXPOWER' size='10' value='$wlanapsettings{'TXPOWER'}' /></td></tr>" | |
27731caa CS |
452 | } |
453 | print <<END | |
27731caa CS |
454 | <tr><td width='25%' class='base'>Loglevel (hostapd): </td><td class='base' width='25%'> |
455 | <select name='SYSLOGLEVEL'> | |
182a817a JPT |
456 | <option value='0' $selected{'SYSLOGLEVEL'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option> |
457 | <option value='1' $selected{'SYSLOGLEVEL'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option> | |
458 | <option value='2' $selected{'SYSLOGLEVEL'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option> | |
459 | <option value='3' $selected{'SYSLOGLEVEL'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option> | |
460 | <option value='4' $selected{'SYSLOGLEVEL'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option> | |
27731caa CS |
461 | </select> |
462 | </td> | |
463 | <td width='25%' class='base'>Debuglevel (hostapd): </td><td class='base' width='25%'> | |
464 | <select name='DEBUG'> | |
182a817a JPT |
465 | <option value='0' $selected{'DEBUG'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option> |
466 | <option value='1' $selected{'DEBUG'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option> | |
467 | <option value='2' $selected{'DEBUG'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option> | |
468 | <option value='3' $selected{'DEBUG'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option> | |
469 | <option value='4' $selected{'DEBUG'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option> | |
27731caa CS |
470 | </select> |
471 | </td></tr> | |
3827d1f6 | 472 | <tr><td colspan='4'><br></td></tr> |
27731caa | 473 | </table> |
92f2665d CS |
474 | END |
475 | ; | |
476 | if ( $wlanapsettings{'INTERFACE'} =~ /green0/ ){ | |
477 | print <<END | |
478 | <br /> | |
3827d1f6 AM |
479 | <table width='80%' cellspacing='0' class='tbl' border='1'> |
480 | <tr> | |
481 | <th colspan='3' align='left'>$Lang::tr{'mac filter'}</th> | |
482 | </tr> | |
92f2665d CS |
483 | <td width='25%' class='base'>Mac Filter: </td><td class='base' width='25%'> |
484 | <select name='MACMODE'> | |
485 | <option value='0' $selected{'MACMODE'}{'0'}>0 (off)</option> | |
8aa49c15 CS |
486 | <option value='1' $selected{'MACMODE'}{'1'}>1 (Accept MACs)</option> |
487 | <option value='2' $selected{'MACMODE'}{'2'}>2 (Deny MACs)</option> | |
92f2665d | 488 | </select> |
8aa49c15 | 489 | </td><td colspan='2'>Mac Adress List (one per line)<br /><textarea name='MACS' cols='20' rows='5' wrap='off'> |
92f2665d CS |
490 | END |
491 | ; | |
8aa49c15 | 492 | print `cat /var/ipfire/wlanap/macfile`; |
92f2665d CS |
493 | print <<END |
494 | </textarea></td> | |
92f2665d CS |
495 | </table> |
496 | END | |
497 | ; | |
498 | } | |
499 | print <<END | |
54359730 | 500 | <br /> |
3827d1f6 | 501 | <table width='80%' cellspacing='0'> |
735fce60 | 502 | <tr><td align='center'> |
182a817a | 503 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> |
735fce60 JPT |
504 | <input type='hidden' name='ACTION' value=$Lang::tr{'save'} /> |
505 | <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></form></td> | |
27731caa CS |
506 | </tr> |
507 | </table> | |
508 | END | |
509 | ; | |
0f0d6a5a | 510 | my @status; |
8c2f203c | 511 | if ( $wlanapsettings{'DRIVER'} eq 'MADWIFI' ){ |
0f0d6a5a | 512 | @status = `wlanconfig $wlanapsettings{'INTERFACE'} list`; |
8c2f203c | 513 | } |
7d30ef24 | 514 | if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ |
513c321e | 515 | @status = `iw dev $wlanapsettings{'INTERFACE'} info && iw dev $wlanapsettings{'INTERFACE'} station dump && echo ""`; |
7d30ef24 | 516 | } |
54359730 CS |
517 | print <<END |
518 | <br /> | |
3827d1f6 AM |
519 | <table width='80%' cellspacing='0' class='tbl'> |
520 | <tr><th colspan='3' bgcolor='$color{'color20'}' align='left'><strong>$Lang::tr{'wlanap wlan status'}</strong></th></tr> | |
521 | END | |
522 | ; | |
0f0d6a5a AF |
523 | |
524 | for (my $i=0;$i<$#status;$i++){ | |
525 | ||
526 | if (@status[$i]=~"^Station ") { $count++; } | |
527 | if ($count % 2){ | |
3827d1f6 AM |
528 | $col="bgcolor='$color{'color20'}'"; |
529 | }else{ | |
530 | $col="bgcolor='$color{'color22'}'"; | |
531 | } | |
0f0d6a5a AF |
532 | print"<tr><td colspan='3' $col><pre>@status[$i]</pre></td></tr>"; |
533 | if (! @status[$i]=~"^/t" ) { $count++; } | |
3827d1f6 | 534 | } |
0f0d6a5a AF |
535 | $count++; |
536 | ||
537 | foreach my $nr (@channellist_cmd){ | |
538 | if ($count % 2){ | |
3827d1f6 AM |
539 | $col="bgcolor='$color{'color20'}'"; |
540 | }else{ | |
541 | $col="bgcolor='$color{'color22'}'"; | |
542 | } | |
0f0d6a5a | 543 | print"<tr><td colspan='3' $col>$nr</td></tr>"; |
3827d1f6 AM |
544 | $count++; |
545 | } | |
0f0d6a5a AF |
546 | |
547 | for (my $i=0;$i<$#txpower_cmd;$i=$i+2){ | |
3827d1f6 AM |
548 | if ($count % 2){ |
549 | $col="bgcolor='$color{'color20'}'"; | |
550 | }else{ | |
551 | $col="bgcolor='$color{'color22'}'"; | |
552 | } | |
0f0d6a5a | 553 | print "<tr><td $col>@txpower_cmd[$i]</td></tr>"; |
3827d1f6 AM |
554 | $count++; |
555 | } | |
556 | print "</table><br>"; | |
557 | print <<END | |
182a817a | 558 | <br /> |
3827d1f6 AM |
559 | <table width='80%' cellspacing='0' class='tbl' border='0'> |
560 | <tr><td bgcolor='$color{'color20'}' align='left'><strong>$Lang::tr{'wlan clients'}</strong></td></tr> | |
182a817a JPT |
561 | <tr><td> <a href="/cgi-bin/wireless.cgi">$Lang::tr{'wlanap link wireless'}</a></td></tr> |
562 | <tr><td> <a href="/cgi-bin/dhcp.cgi">$Lang::tr{'wlanap link dhcp'}</a></td></tr> | |
3827d1f6 | 563 | <tr><td><br></td></tr> |
182a817a | 564 | </table> |
54359730 CS |
565 | END |
566 | ; | |
567 | &Header::closebox(); | |
27731caa CS |
568 | print "</form>"; |
569 | &Header::closebigbox(); | |
570 | &Header::closepage(); | |
571 | ||
27731caa CS |
572 | sub WriteConfig_hostapd{ |
573 | $wlanapsettings{'DRIVER_HOSTAPD'} = lc($wlanapsettings{'DRIVER'}); | |
574 | ||
575 | open (CONFIGFILE, ">/var/ipfire/wlanap/hostapd.conf"); | |
576 | print CONFIGFILE <<END | |
cdbeabe2 | 577 | driver=$wlanapsettings{'DRIVER_HOSTAPD'} |
54359730 | 578 | ######################### basic hostapd configuration ########################## |
891b6138 | 579 | # |
92f2665d | 580 | interface=$wlanapsettings{'INTERFACE'} |
cdbeabe2 AF |
581 | country_code=$wlanapsettings{'COUNTRY'} |
582 | ieee80211d=1 | |
f89678de | 583 | ieee80211h=1 |
7d30ef24 | 584 | channel=$wlanapsettings{'CHANNEL'} |
b8012afd CS |
585 | END |
586 | ; | |
e62efbb7 AF |
587 | if ( $wlanapsettings{'HW_MODE'} eq 'an' ){ |
588 | print CONFIGFILE <<END | |
589 | hw_mode=a | |
590 | ieee80211n=1 | |
591 | wmm_enabled=1 | |
592 | ht_capab=$wlanapsettings{'HTCAPS'} | |
593 | END | |
594 | ; | |
595 | ||
596 | }elsif ( $wlanapsettings{'HW_MODE'} eq 'gn' ){ | |
b8012afd CS |
597 | print CONFIGFILE <<END |
598 | hw_mode=g | |
599 | ieee80211n=1 | |
6e346fe0 CS |
600 | wmm_enabled=1 |
601 | ht_capab=$wlanapsettings{'HTCAPS'} | |
b8012afd CS |
602 | END |
603 | ; | |
604 | ||
605 | }else{ | |
606 | print CONFIGFILE <<END | |
8ad457eb CS |
607 | hw_mode=$wlanapsettings{'HW_MODE'} |
608 | END | |
b8012afd CS |
609 | ; |
610 | ||
611 | } | |
612 | ||
8ad457eb | 613 | print CONFIGFILE <<END |
27731caa CS |
614 | logger_syslog=-1 |
615 | logger_syslog_level=$wlanapsettings{'SYSLOGLEVEL'} | |
616 | logger_stdout=-1 | |
54359730 | 617 | logger_stdout_level=$wlanapsettings{'DEBUG'} |
27731caa | 618 | dump_file=/tmp/hostapd.dump |
7d30ef24 | 619 | auth_algs=1 |
27731caa CS |
620 | ctrl_interface=/var/run/hostapd |
621 | ctrl_interface_group=0 | |
27731caa CS |
622 | END |
623 | ; | |
54359730 CS |
624 | if ( $wlanapsettings{'HIDESSID'} eq 'on' ){ |
625 | print CONFIGFILE <<END | |
626 | ssid=$wlanapsettings{'SSID'} | |
627 | ignore_broadcast_ssid=2 | |
628 | END | |
629 | ; | |
630 | ||
631 | }else{ | |
632 | print CONFIGFILE <<END | |
633 | ssid=$wlanapsettings{'SSID'} | |
634 | ignore_broadcast_ssid=0 | |
635 | END | |
636 | ; | |
637 | ||
638 | } | |
92f2665d | 639 | |
8c2f203c CS |
640 | if ( $wlanapsettings{'ENC'} eq 'wpa1'){ |
641 | print CONFIGFILE <<END | |
642 | ######################### wpa hostapd configuration ############################ | |
891b6138 | 643 | # |
8c2f203c CS |
644 | wpa=1 |
645 | wpa_passphrase=$wlanapsettings{'PWD'} | |
891b6138 | 646 | wpa_key_mgmt=WPA-PSK |
e62efbb7 | 647 | wpa_pairwise=TKIP |
8c2f203c CS |
648 | END |
649 | ; | |
650 | }elsif ( $wlanapsettings{'ENC'} eq 'wpa2'){ | |
54359730 CS |
651 | print CONFIGFILE <<END |
652 | ######################### wpa hostapd configuration ############################ | |
891b6138 | 653 | # |
8c2f203c | 654 | wpa=2 |
54359730 | 655 | wpa_passphrase=$wlanapsettings{'PWD'} |
891b6138 | 656 | wpa_key_mgmt=WPA-PSK |
e62efbb7 AF |
657 | rsn_pairwise=CCMP |
658 | END | |
659 | ; | |
660 | } elsif ( $wlanapsettings{'ENC'} eq 'wpa1+2'){ | |
661 | print CONFIGFILE <<END | |
662 | ######################### wpa hostapd configuration ############################ | |
663 | # | |
664 | wpa=3 | |
665 | wpa_passphrase=$wlanapsettings{'PWD'} | |
666 | wpa_key_mgmt=WPA-PSK | |
667 | wpa_pairwise=TKIP | |
668 | rsn_pairwise=CCMP | |
54359730 CS |
669 | END |
670 | ; | |
671 | } | |
27731caa | 672 | close CONFIGFILE; |
92f2665d | 673 | |
8aa49c15 | 674 | open (MACFILE, ">/var/ipfire/wlanap/macfile"); |
23e368ab CS |
675 | foreach(@macs){ |
676 | $_ =~ s/\r//gi; | |
677 | chomp($_); | |
678 | if ( $_ ne "" ){print MACFILE $_;} | |
679 | } | |
92f2665d | 680 | close MACFILE; |
27731caa | 681 | } |