]>
Commit | Line | Data |
---|---|---|
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/ipfire/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 | $wlanapsettings{'VHTCAPS'} = ''; | |
77 | $wlanapsettings{'NOSCAN'} = 'off'; | |
78 | $wlanapsettings{'CLIENTISOLATION'} = 'off'; | |
79 | $wlanapsettings{'IEEE80211W'} = 'off'; | |
80 | ||
81 | &General::readhash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
82 | &Header::getcgihash(\%wlanapsettings); | |
83 | ||
84 | # Find the selected interface | |
85 | my $INTF = &Network::get_intf_by_address($wlanapsettings{'INTERFACE'}); | |
86 | ||
87 | my @macs = $wlanapsettings{'MACS'}; | |
88 | ||
89 | delete $wlanapsettings{'__CGI__'}; | |
90 | delete $wlanapsettings{'x'}; | |
91 | delete $wlanapsettings{'y'}; | |
92 | delete $wlanapsettings{'MACS'}; | |
93 | delete $wlanapsettings{'ACCEPT_MACS'}; | |
94 | delete $wlanapsettings{'DENY_MACS'}; | |
95 | ||
96 | &Header::showhttpheaders(); | |
97 | ||
98 | my $string=(); | |
99 | my $status=(); | |
100 | my $errormessage = ''; | |
101 | my $memory = 0; | |
102 | my @memory=(); | |
103 | my @pid=(); | |
104 | my @hostapd=(); | |
105 | sub pid | |
106 | { | |
107 | # for pid and memory | |
108 | open(FILE, '/usr/local/bin/addonctrl hostapd status | '); | |
109 | @hostapd = <FILE>; | |
110 | close(FILE); | |
111 | $string = join("", @hostapd); | |
112 | $string =~ s/[a-z_]//gi; | |
113 | $string =~ s/\[[0-1]\;[0-9]+//gi; | |
114 | $string =~ s/[\(\)\.]//gi; | |
115 | $string =~ s/ //gi; | |
116 | $string =~ s/\e//gi; | |
117 | @pid = split(/\s/,$string); | |
118 | if (open(FILE, "/proc/$pid[0]/statm")){ | |
119 | my $temp = <FILE>; | |
120 | @memory = split(/ /,$temp); | |
121 | close(FILE); | |
122 | } | |
123 | $memory+=$memory[0]; | |
124 | } | |
125 | pid(); | |
126 | ||
127 | ||
128 | ||
129 | if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap del interface'}" ){ | |
130 | delete $wlanapsettings{'INTERFACE'}; | |
131 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
132 | } | |
133 | ||
134 | if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'save'}" ){ | |
135 | # verify WPA Passphrase - only with enabled enc | |
136 | if ($wlanapsettings{'ENC'} ne "none") { | |
137 | # must be 8 .. 63 characters | |
138 | if ( (length($wlanapsettings{'PWD'}) < 8) || (length($wlanapsettings{'PWD'}) > 63)){ | |
139 | $errormessage .= "$Lang::tr{'wlanap invalid wpa'}<br />"; | |
140 | } | |
141 | # only ASCII alowed | |
142 | if ( !($wlanapsettings{'PWD'} !~ /[^\x00-\x7f]/) ){ | |
143 | $errormessage .= "$Lang::tr{'wlanap invalid wpa'}<br />"; | |
144 | } | |
145 | } | |
146 | ||
147 | if ( $errormessage eq '' ){ | |
148 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
149 | &WriteConfig_hostapd(); | |
150 | ||
151 | &General::system("/usr/local/bin/wlanapctrl", "restart"); | |
152 | pid(); | |
153 | } | |
154 | }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap interface'}" ){ | |
155 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
156 | }elsif ( ($wlanapsettings{'ACTION'} eq "$Lang::tr{'start'}") && ($memory == 0) ){ | |
157 | &General::system("/usr/local/bin/wlanapctrl", "start"); | |
158 | pid(); | |
159 | }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'stop'}" ){ | |
160 | &General::system("/usr/local/bin/wlanapctrl", "stop"); | |
161 | $memory=0; | |
162 | } | |
163 | ||
164 | &Header::openpage($Lang::tr{'wlanap configuration'}, 1, '', ''); | |
165 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
166 | ||
167 | if ( $errormessage ){ | |
168 | &Header::openbox('100%', 'center', $Lang::tr{'error messages'}); | |
169 | print "<class name='base'>$errormessage\n"; | |
170 | print " </class>\n"; | |
171 | &Header::closebox(); | |
172 | } | |
173 | ||
174 | ||
175 | # Found this usefull piece of code in BlockOutTraffic AddOn 8-) | |
176 | # fwrules.cgi | |
177 | ############### | |
178 | # DEBUG DEBUG | |
179 | if ( $debug ){ | |
180 | &Header::openbox('100%', 'center', 'DEBUG'); | |
181 | my $debugCount = 0; | |
182 | foreach my $line (sort keys %wlanapsettings) { | |
183 | print "$line = '$wlanapsettings{$line}'<br />\n"; | |
184 | $debugCount++; | |
185 | } | |
186 | print " Count: $debugCount\n"; | |
187 | &Header::closebox(); | |
188 | } | |
189 | # DEBUG DEBUG | |
190 | ############### | |
191 | ||
192 | # | |
193 | # Driver and status detection | |
194 | # | |
195 | my $wlan_card_status = 'dummy'; | |
196 | my $wlan_ap_status = ''; | |
197 | my $message = ""; | |
198 | ||
199 | my %INTERFACES = &Network::list_wireless_interfaces(); | |
200 | ||
201 | foreach my $intf (keys %INTERFACES) { | |
202 | $selected{'INTERFACE'}{$intf} = ''; | |
203 | } | |
204 | $selected{'ENC'}{$wlanapsettings{'INTERFACE'}} = "selected='selected'"; | |
205 | ||
206 | if ( ($wlanapsettings{'INTERFACE'} eq '') ){ | |
207 | $message = $Lang::tr{'wlanap select interface'}; | |
208 | &Header::openbox('100%', 'center', "WLAN AP"); | |
209 | print <<END | |
210 | $message<br /> | |
211 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
212 | <select name='INTERFACE'> | |
213 | END | |
214 | ; | |
215 | ||
216 | foreach my $intf (sort keys %INTERFACES) { | |
217 | print "<option value='${intf}' $selected{'INTERFACE'}{$intf}>$INTERFACES{$intf}</option>"; | |
218 | } | |
219 | ||
220 | print <<END | |
221 | </select> | |
222 | <br /><br /> | |
223 | <hr size='1'> | |
224 | <input type='submit' name='ACTION' value='$Lang::tr{'wlanap interface'}' /></form> | |
225 | END | |
226 | ; | |
227 | &Header::closebox(); | |
228 | &Header::closebigbox(); | |
229 | &Header::closepage(); | |
230 | exit; | |
231 | }else{ | |
232 | my $cmd_out = `/usr/sbin/iwconfig $INTF 2>/dev/null`; | |
233 | ||
234 | if ( $cmd_out eq '' ){ | |
235 | $message = "$Lang::tr{'wlanap no interface'}"; | |
236 | $wlan_card_status = ''; | |
237 | }else{ | |
238 | $cmd_out = `/sbin/ifconfig $INTF`; | |
239 | if ( $cmd_out eq '' ){ | |
240 | $wlan_card_status = 'down'; | |
241 | }else{ | |
242 | $wlan_card_status = 'up'; | |
243 | $cmd_out = `/usr/sbin/iwconfig $INTF | /bin/grep "Mode:Master"`; | |
244 | if ( $cmd_out ne '' ){ | |
245 | $wlan_ap_status = 'up'; | |
246 | } | |
247 | } | |
248 | } | |
249 | } | |
250 | ||
251 | # Change old "n" to "gn" | |
252 | if ( $wlanapsettings{'HW_MODE'} eq 'n' ) { | |
253 | $wlanapsettings{'HW_MODE'}='gn'; | |
254 | } | |
255 | ||
256 | $checked{'HIDESSID'}{'off'} = ''; | |
257 | $checked{'HIDESSID'}{'on'} = ''; | |
258 | $checked{'HIDESSID'}{$wlanapsettings{'HIDESSID'}} = "checked='checked'"; | |
259 | ||
260 | $checked{'NOSCAN'}{'off'} = ''; | |
261 | $checked{'NOSCAN'}{'on'} = ''; | |
262 | $checked{'NOSCAN'}{$wlanapsettings{'NOSCAN'}} = "checked='checked'"; | |
263 | ||
264 | $checked{'CLIENTISOLATION'}{'off'} = ''; | |
265 | $checked{'CLIENTISOLATION'}{'on'} = ''; | |
266 | $checked{'CLIENTISOLATION'}{$wlanapsettings{'CLIENTISOLATION'}} = "checked='checked'"; | |
267 | ||
268 | $selected{'IEEE80211W'}{'off'} = ''; | |
269 | $selected{'IEEE80211W'}{'optional'} = ''; | |
270 | $selected{'IEEE80211W'}{'on'} = ''; | |
271 | $selected{'IEEE80211W'}{$wlanapsettings{'IEEE80211W'}} = "selected"; | |
272 | ||
273 | $selected{'ENC'}{$wlanapsettings{'ENC'}} = "selected='selected'"; | |
274 | $selected{'CHANNEL'}{$wlanapsettings{'CHANNEL'}} = "selected='selected'"; | |
275 | $selected{'COUNTRY'}{$wlanapsettings{'COUNTRY'}} = "selected='selected'"; | |
276 | $selected{'TXPOWER'}{$wlanapsettings{'TXPOWER'}} = "selected='selected'"; | |
277 | $selected{'HW_MODE'}{$wlanapsettings{'HW_MODE'}} = "selected='selected'"; | |
278 | $selected{'MACMODE'}{$wlanapsettings{'MACMODE'}} = "selected='selected'"; | |
279 | ||
280 | my $monwlaninterface = $INTF; | |
281 | if ( -d '/sys/class/net/mon.' . $INTF) { | |
282 | $monwlaninterface = 'mon.' . $INTF; | |
283 | } | |
284 | ||
285 | my @channellist_cmd; | |
286 | my @channellist = (0); | |
287 | ||
288 | if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ | |
289 | my $wiphy = `iw dev $INTF info | grep wiphy | cut -d" " -f2`; | |
290 | chomp $wiphy; | |
291 | ||
292 | @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`; | |
293 | # get available channels | |
294 | ||
295 | my @temp; | |
296 | foreach (@channellist_cmd){ | |
297 | $_ =~ /(.*) \[(\d+)(.*)\]/; | |
298 | $channel = $2;chomp $channel; | |
299 | if ( $channel =~ /\d+/ ){push(@temp,$channel + 0);} | |
300 | } | |
301 | push(@channellist, @temp); | |
302 | } else { | |
303 | @channellist_cmd = `iwlist $monwlaninterface channel|tail -n +2 2>/dev/null`; | |
304 | # get available channels | |
305 | ||
306 | my @temp; | |
307 | foreach (@channellist_cmd){ | |
308 | $_ =~ /(.*)Channel (\d+)(.*):/; | |
309 | $channel = $2;chomp $channel; | |
310 | if ( $channel =~ /\d+/ ){push(@temp,$channel + 0);} | |
311 | } | |
312 | push(@channellist, @temp); | |
313 | } | |
314 | ||
315 | my @countrylist_cmd = `regdbdump /usr/lib/crda/regulatory.bin 2>/dev/null`; | |
316 | # get available country codes | |
317 | ||
318 | my @temp = "00"; | |
319 | foreach (@countrylist_cmd){ | |
320 | $_ =~ /country (.*):/; | |
321 | $country = $1;chomp $country; | |
322 | if ( $country =~ /[0,A-Z][0,A-Z]/ ) {push(@temp,$country);} | |
323 | } | |
324 | my @countrylist = @temp; | |
325 | ||
326 | my @txpower_cmd = `iwlist $monwlaninterface txpower 2>/dev/null`; | |
327 | if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ | |
328 | # There is a bug with NL80211 only all devices can displaye | |
329 | @txpower_cmd = `iwlist txpower 2>/dev/null | sed -e "s|unknown transmit-power information.||g"`; | |
330 | } | |
331 | # get available power | |
332 | ||
333 | $selected{'SYSLOGLEVEL'}{$wlanapsettings{'SYSLOGLEVEL'}} = "selected='selected'"; | |
334 | $selected{'DEBUG'}{$wlanapsettings{'DEBUG'}} = "selected='selected'"; | |
335 | ||
336 | # | |
337 | # Status box | |
338 | # | |
339 | &Header::openbox('100%', 'center', "WLAN AP"); | |
340 | print <<END | |
341 | <table width='80%' cellspacing='1' class='tbl'> | |
342 | END | |
343 | ; | |
344 | ||
345 | if ( $wlan_card_status ne '' ){ | |
346 | 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>"; | |
347 | print "<tr><td class='base'>$Lang::tr{'wlanap wlan card'} ($wlanapsettings{'DRIVER'})</td>"; | |
348 | print $wlan_card_status eq 'up' ? $status_started : $status_stopped; | |
349 | print"<td colspan='4'></td></tr>"; | |
350 | print "<tr><td class='base' bgcolor='$color{'color22'}'>$Lang::tr{'wlanap'}</td>"; | |
351 | print $wlan_ap_status eq 'up' ? $status_started : $status_stopped; | |
352 | if ( ($memory != 0) && (@pid[0] ne "///") ){ | |
353 | print "<td bgcolor='$color{'color22'}' align='center'>@pid[0]</td>"; | |
354 | print "<td bgcolor='$color{'color22'}' align='center'>$memory KB</td>"; | |
355 | 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>"; | |
356 | 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>"; | |
357 | }else{ | |
358 | print"<td colspan='2' bgcolor='$color{'color22'}'></td>"; | |
359 | 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>"; | |
360 | 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>"; | |
361 | } | |
362 | ||
363 | }else{ | |
364 | print "<tr><td class='base'>$message"; | |
365 | } | |
366 | print "</table>"; | |
367 | ||
368 | if ( $wlan_card_status eq '' ){ | |
369 | print "<br />"; | |
370 | print "<table width='80%' cellspacing='0' border='0'>"; | |
371 | print "<tr align='center'>"; | |
372 | print "<td colspan='4'></td>"; | |
373 | print "</tr>"; | |
374 | print "<tr align='center'>"; | |
375 | print "<td width='40%'> </td>"; | |
376 | 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>"; | |
377 | print "<td width='20%'></td>"; | |
378 | print "<td width='20%'></td>"; | |
379 | print "</tr>"; | |
380 | print "</table>"; | |
381 | } | |
382 | ||
383 | if ( $wlan_card_status eq '' ){ | |
384 | &Header::closebox(); | |
385 | &Header::closebigbox(); | |
386 | &Header::closepage(); | |
387 | exit 0; | |
388 | } | |
389 | print <<END | |
390 | <br><br> | |
391 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
392 | <table width='80%' cellspacing='0' class='tbl' border='0'> | |
393 | <tr><th bgcolor='$color{'color20'}' colspan='4' align='left'><strong>$Lang::tr{'wlanap wlan settings'}</strong></th></tr> | |
394 | <tr><td colspan='4'><br></td></tr> | |
395 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap ssid'}: </td><td class='base' colspan='3'><input type='text' name='SSID' size='30' value='$wlanapsettings{'SSID'}' /></td></tr> | |
396 | <!--SSID Broadcast: on => HIDESSID: off --> | |
397 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap broadcast ssid'}: </td><td class='base' colspan='3'>$Lang::tr{'on'} <input type='radio' name='HIDESSID' value='off' $checked{'HIDESSID'}{'off'} /> | <input type='radio' name='HIDESSID' value='on' $checked{'HIDESSID'}{'on'} /> $Lang::tr{'off'}</td></tr> | |
398 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap client isolation'}: </td><td class='base' colspan='3'>$Lang::tr{'on'} <input type='radio' name='CLIENTISOLATION' value='on' $checked{'CLIENTISOLATION'}{'on'} /> | <input type='radio' name='CLIENTISOLATION' value='off' $checked{'CLIENTISOLATION'}{'off'} /> $Lang::tr{'off'}</td></tr> | |
399 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap country'}: </td><td class='base' colspan='3'> | |
400 | <select name='COUNTRY'> | |
401 | END | |
402 | ; | |
403 | foreach $country (@countrylist){ | |
404 | print "<option $selected{'COUNTRY'}{$country}>$country</option>"; | |
405 | } | |
406 | print<<END | |
407 | </select></td></tr> | |
408 | <tr><td width='25%' class='base'>HW Mode: </td><td class='base' colspan='3'> | |
409 | <select name='HW_MODE'> | |
410 | <option value='a' $selected{'HW_MODE'}{'a'}>802.11a</option> | |
411 | <option value='b' $selected{'HW_MODE'}{'b'}>802.11b</option> | |
412 | <option value='g' $selected{'HW_MODE'}{'g'}>802.11g</option> | |
413 | <option value='an' $selected{'HW_MODE'}{'an'}>802.11an</option> | |
414 | <option value='gn' $selected{'HW_MODE'}{'gn'}>802.11gn</option> | |
415 | <option value='ac' $selected{'HW_MODE'}{'ac'}>802.11ac</option> | |
416 | </select> | |
417 | </td></tr> | |
418 | END | |
419 | ; | |
420 | ||
421 | if ( scalar @channellist > 0 ){ | |
422 | print <<END | |
423 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap channel'}: </td><td class='base' colspan='3'> | |
424 | <select name='CHANNEL'> | |
425 | END | |
426 | ; | |
427 | foreach $channel (@channellist){ | |
428 | print "<option $selected{'CHANNEL'}{$channel}>"; | |
429 | if ($channel eq 0) { | |
430 | print "- $Lang::tr{'wlanap auto'} -"; | |
431 | } else { | |
432 | print $channel; | |
433 | } | |
434 | print "</option>"; | |
435 | } | |
436 | print "</select></td></tr>" | |
437 | } else { | |
438 | print <<END | |
439 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap channel'}: </td><td class='base' colspan='3'> | |
440 | <input type='text' name='CHANNEL' size='10' value='$wlanapsettings{'CHANNEL'}' /> | |
441 | </td></tr> | |
442 | END | |
443 | ; | |
444 | } | |
445 | print<<END | |
446 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap neighbor scan'}: </td><td class='base' >$Lang::tr{'on'} <input type='radio' name='NOSCAN' value='off' $checked{'NOSCAN'}{'off'} /> | <input type='radio' name='NOSCAN' value='on' $checked{'NOSCAN'}{'on'} /> $Lang::tr{'off'}</td><td class='base' colspan='2'>$Lang::tr{'wlanap neighbor scan warning'}</td></tr> | |
447 | <tr><td colspan='4'><br></td></tr> | |
448 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap encryption'}: </td><td class='base' colspan='3'> | |
449 | <select name='ENC'> | |
450 | <option value='none' $selected{'ENC'}{'none'}>$Lang::tr{'wlanap none'}</option> | |
451 | <option value='wpa1' $selected{'ENC'}{'wpa1'}>WPA1</option> | |
452 | <option value='wpa2' $selected{'ENC'}{'wpa2'}>WPA2</option> | |
453 | <option value='wpa3' $selected{'ENC'}{'wpa3'}>WPA3</option> | |
454 | <option value='wpa1+2' $selected{'ENC'}{'wpa1+2'}>WPA1+2</option> | |
455 | <option value='wpa2+3' $selected{'ENC'}{'wpa2+3'}>WPA2+3</option> | |
456 | </select> | |
457 | </td></tr> | |
458 | <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> | |
459 | <tr> | |
460 | <td width='25%' class='base'>$Lang::tr{'wlanap management frame protection'}: </td> | |
461 | <td class='base' colspan="3"> | |
462 | <select name="IEEE80211W"> | |
463 | <option value="off" $selected{'IEEE80211W'}{'off'}>$Lang::tr{'wlanap 802.11w disabled'}</option> | |
464 | <option value="optional" $selected{'IEEE80211W'}{'optional'}>$Lang::tr{'wlanap 802.11w optional'}</option> | |
465 | <option value="on" $selected{'IEEE80211W'}{'on'}>$Lang::tr{'wlanap 802.11w enforced'}</option> | |
466 | </select> | |
467 | </td> | |
468 | </tr> | |
469 | <tr><td colspan='4'><br></td></tr> | |
470 | END | |
471 | ; | |
472 | print <<END | |
473 | <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> | |
474 | <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> | |
475 | <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> | |
476 | <tr><td width='25%' class='base'>Loglevel (hostapd): </td><td class='base' width='25%'> | |
477 | <select name='SYSLOGLEVEL'> | |
478 | <option value='0' $selected{'SYSLOGLEVEL'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option> | |
479 | <option value='1' $selected{'SYSLOGLEVEL'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option> | |
480 | <option value='2' $selected{'SYSLOGLEVEL'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option> | |
481 | <option value='3' $selected{'SYSLOGLEVEL'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option> | |
482 | <option value='4' $selected{'SYSLOGLEVEL'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option> | |
483 | </select> | |
484 | </td> | |
485 | <td width='25%' class='base'>Debuglevel (hostapd): </td><td class='base' width='25%'> | |
486 | <select name='DEBUG'> | |
487 | <option value='0' $selected{'DEBUG'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option> | |
488 | <option value='1' $selected{'DEBUG'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option> | |
489 | <option value='2' $selected{'DEBUG'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option> | |
490 | <option value='3' $selected{'DEBUG'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option> | |
491 | <option value='4' $selected{'DEBUG'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option> | |
492 | </select> | |
493 | </td></tr> | |
494 | <tr><td colspan='4'><br></td></tr> | |
495 | </table> | |
496 | END | |
497 | ; | |
498 | if ( $INTF =~ /green0/ ){ | |
499 | print <<END | |
500 | <br /> | |
501 | <table width='80%' cellspacing='0' class='tbl' border='1'> | |
502 | <tr> | |
503 | <th colspan='3' align='left'>$Lang::tr{'mac filter'}</th> | |
504 | </tr> | |
505 | <td width='25%' class='base'>Mac Filter: </td><td class='base' width='25%'> | |
506 | <select name='MACMODE'> | |
507 | <option value='0' $selected{'MACMODE'}{'0'}>0 (off)</option> | |
508 | <option value='1' $selected{'MACMODE'}{'1'}>1 (Accept MACs)</option> | |
509 | <option value='2' $selected{'MACMODE'}{'2'}>2 (Deny MACs)</option> | |
510 | </select> | |
511 | </td><td colspan='2'>Mac Adress List (one per line)<br /><textarea name='MACS' cols='20' rows='5' wrap='off'> | |
512 | END | |
513 | ; | |
514 | print `cat /var/ipfire/wlanap/macfile`; | |
515 | print <<END | |
516 | </textarea></td> | |
517 | </table> | |
518 | END | |
519 | ; | |
520 | } | |
521 | print <<END | |
522 | <br /> | |
523 | <table width='80%' cellspacing='0'> | |
524 | <tr><td align='center'> | |
525 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
526 | <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></form></td> | |
527 | </tr> | |
528 | </table> | |
529 | END | |
530 | ; | |
531 | my @status; | |
532 | if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ | |
533 | @status = `iw dev $INTF info && iw dev $INTF station dump && echo ""`; | |
534 | } | |
535 | print <<END | |
536 | <br /> | |
537 | <table width='80%' cellspacing='0' class='tbl'> | |
538 | <tr><th colspan='3' bgcolor='$color{'color20'}' align='left'><strong>$Lang::tr{'wlanap wlan status'}</strong></th></tr> | |
539 | END | |
540 | ; | |
541 | ||
542 | for (my $i=0;$i<$#status;$i++){ | |
543 | ||
544 | if (@status[$i]=~"^Station ") { $count++; } | |
545 | if ($count % 2){ | |
546 | $col="bgcolor='$color{'color20'}'"; | |
547 | }else{ | |
548 | $col="bgcolor='$color{'color22'}'"; | |
549 | } | |
550 | print"<tr><td colspan='3' $col><pre>@status[$i]</pre></td></tr>"; | |
551 | if (! @status[$i]=~"^/t" ) { $count++; } | |
552 | } | |
553 | $count++; | |
554 | ||
555 | foreach my $nr (@channellist_cmd){ | |
556 | if ($count % 2){ | |
557 | $col="bgcolor='$color{'color20'}'"; | |
558 | }else{ | |
559 | $col="bgcolor='$color{'color22'}'"; | |
560 | } | |
561 | print"<tr><td colspan='3' $col>$nr</td></tr>"; | |
562 | $count++; | |
563 | } | |
564 | ||
565 | for (my $i=0;$i<$#txpower_cmd;$i=$i+2){ | |
566 | if ($count % 2){ | |
567 | $col="bgcolor='$color{'color20'}'"; | |
568 | }else{ | |
569 | $col="bgcolor='$color{'color22'}'"; | |
570 | } | |
571 | print "<tr><td $col>@txpower_cmd[$i]</td></tr>"; | |
572 | $count++; | |
573 | } | |
574 | print "</table>"; | |
575 | &Header::closebox(); | |
576 | print "</form>"; | |
577 | &Header::closebigbox(); | |
578 | &Header::closepage(); | |
579 | ||
580 | sub WriteConfig_hostapd{ | |
581 | $wlanapsettings{'DRIVER_HOSTAPD'} = lc($wlanapsettings{'DRIVER'}); | |
582 | ||
583 | open (CONFIGFILE, ">/var/ipfire/wlanap/hostapd.conf"); | |
584 | print CONFIGFILE <<END | |
585 | driver=$wlanapsettings{'DRIVER_HOSTAPD'} | |
586 | ######################### basic hostapd configuration ########################## | |
587 | # | |
588 | country_code=$wlanapsettings{'COUNTRY'} | |
589 | ieee80211d=1 | |
590 | ieee80211h=1 | |
591 | channel=$wlanapsettings{'CHANNEL'} | |
592 | END | |
593 | ; | |
594 | if ( $wlanapsettings{'HW_MODE'} eq 'an' ){ | |
595 | print CONFIGFILE <<END | |
596 | hw_mode=a | |
597 | ieee80211n=1 | |
598 | wmm_enabled=1 | |
599 | ht_capab=$wlanapsettings{'HTCAPS'} | |
600 | END | |
601 | ; | |
602 | ||
603 | }elsif ( $wlanapsettings{'HW_MODE'} eq 'gn' ){ | |
604 | print CONFIGFILE <<END | |
605 | hw_mode=g | |
606 | ieee80211n=1 | |
607 | wmm_enabled=1 | |
608 | ht_capab=$wlanapsettings{'HTCAPS'} | |
609 | END | |
610 | ; | |
611 | ||
612 | }elsif ( $wlanapsettings{'HW_MODE'} eq 'ac' ){ | |
613 | print CONFIGFILE <<END | |
614 | hw_mode=a | |
615 | ieee80211ac=1 | |
616 | ieee80211n=1 | |
617 | wmm_enabled=1 | |
618 | ht_capab=$wlanapsettings{'HTCAPS'} | |
619 | vht_capab=$wlanapsettings{'VHTCAPS'} | |
620 | vht_oper_chwidth=1 | |
621 | END | |
622 | ; | |
623 | ||
624 | }else{ | |
625 | print CONFIGFILE <<END | |
626 | hw_mode=$wlanapsettings{'HW_MODE'} | |
627 | END | |
628 | ; | |
629 | ||
630 | } | |
631 | ||
632 | print CONFIGFILE <<END | |
633 | logger_syslog=-1 | |
634 | logger_syslog_level=$wlanapsettings{'SYSLOGLEVEL'} | |
635 | logger_stdout=-1 | |
636 | logger_stdout_level=$wlanapsettings{'DEBUG'} | |
637 | auth_algs=1 | |
638 | ctrl_interface=/var/run/hostapd | |
639 | ctrl_interface_group=0 | |
640 | disassoc_low_ack=1 | |
641 | END | |
642 | ; | |
643 | if ( $wlanapsettings{'HIDESSID'} eq 'on' ){ | |
644 | print CONFIGFILE <<END | |
645 | ssid=$wlanapsettings{'SSID'} | |
646 | ignore_broadcast_ssid=2 | |
647 | END | |
648 | ; | |
649 | ||
650 | }else{ | |
651 | print CONFIGFILE <<END | |
652 | ssid=$wlanapsettings{'SSID'} | |
653 | ignore_broadcast_ssid=0 | |
654 | END | |
655 | ; | |
656 | ||
657 | } | |
658 | ||
659 | # https://forum.ipfire.org/viewtopic.php?f=22&t=12274&p=79070#p79070 | |
660 | if ( $wlanapsettings{'CLIENTISOLATION'} eq 'on' ){ | |
661 | print CONFIGFILE <<END | |
662 | ap_isolate=1 | |
663 | END | |
664 | ; | |
665 | } | |
666 | ||
667 | if ( $wlanapsettings{'NOSCAN'} eq 'on' ){ | |
668 | print CONFIGFILE <<END | |
669 | noscan=1 | |
670 | END | |
671 | ; | |
672 | ||
673 | }else{ | |
674 | print CONFIGFILE <<END | |
675 | noscan=0 | |
676 | END | |
677 | ; | |
678 | ||
679 | } | |
680 | ||
681 | # Management Frame Protection (802.11w) | |
682 | if ($wlanapsettings{'IEEE80211W'} eq "on") { | |
683 | print CONFIGFILE "ieee80211w=2\n"; | |
684 | } elsif ($wlanapsettings{'IEEE80211W'} eq "optional") { | |
685 | print CONFIGFILE "ieee80211w=1\n"; | |
686 | } else { | |
687 | print CONFIGFILE "ieee80211w=0\n"; | |
688 | } | |
689 | ||
690 | if ( $wlanapsettings{'ENC'} eq 'wpa1'){ | |
691 | print CONFIGFILE <<END | |
692 | ######################### wpa hostapd configuration ############################ | |
693 | # | |
694 | wpa=1 | |
695 | wpa_passphrase=$wlanapsettings{'PWD'} | |
696 | wpa_key_mgmt=WPA-PSK | |
697 | wpa_pairwise=TKIP | |
698 | END | |
699 | ; | |
700 | }elsif ( $wlanapsettings{'ENC'} eq 'wpa2'){ | |
701 | print CONFIGFILE <<END | |
702 | ######################### wpa hostapd configuration ############################ | |
703 | # | |
704 | wpa=2 | |
705 | wpa_passphrase=$wlanapsettings{'PWD'} | |
706 | wpa_key_mgmt=WPA-PSK | |
707 | rsn_pairwise=CCMP | |
708 | END | |
709 | ; | |
710 | }elsif ( $wlanapsettings{'ENC'} eq 'wpa3'){ | |
711 | print CONFIGFILE <<END | |
712 | ######################### wpa hostapd configuration ############################ | |
713 | # | |
714 | wpa=2 | |
715 | wpa_passphrase=$wlanapsettings{'PWD'} | |
716 | wpa_key_mgmt=SAE | |
717 | rsn_pairwise=CCMP | |
718 | END | |
719 | ; | |
720 | } elsif ( $wlanapsettings{'ENC'} eq 'wpa1+2'){ | |
721 | print CONFIGFILE <<END | |
722 | ######################### wpa hostapd configuration ############################ | |
723 | # | |
724 | wpa=3 | |
725 | wpa_passphrase=$wlanapsettings{'PWD'} | |
726 | wpa_key_mgmt=WPA-PSK | |
727 | wpa_pairwise=TKIP | |
728 | rsn_pairwise=CCMP | |
729 | END | |
730 | ; | |
731 | }elsif ( $wlanapsettings{'ENC'} eq 'wpa2+3'){ | |
732 | print CONFIGFILE <<END | |
733 | ######################### wpa hostapd configuration ############################ | |
734 | # | |
735 | wpa=2 | |
736 | wpa_passphrase=$wlanapsettings{'PWD'} | |
737 | wpa_key_mgmt=WPA-PSK SAE | |
738 | rsn_pairwise=CCMP | |
739 | END | |
740 | ; | |
741 | } | |
742 | close CONFIGFILE; | |
743 | ||
744 | open (MACFILE, ">/var/ipfire/wlanap/macfile"); | |
745 | foreach(@macs){ | |
746 | $_ =~ s/\r//gi; | |
747 | chomp($_); | |
748 | if ( $_ ne "" ){print MACFILE $_;} | |
749 | } | |
750 | close MACFILE; | |
751 | } |