]>
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/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
58 | &General::readhash("/var/ipfire/ethernet/settings", \%netsettings); | |
59 | ||
60 | $wlanapsettings{'APMODE'} = 'on'; | |
61 | $wlanapsettings{'ACTION'} = ''; | |
62 | $wlanapsettings{'MACMODE'} = '0'; | |
63 | $wlanapsettings{'INTERFACE'} = ''; | |
64 | $wlanapsettings{'SSID'} = 'IPFire'; | |
65 | $wlanapsettings{'HIDESSID'} = 'off'; | |
66 | $wlanapsettings{'ENC'} = 'wpa2'; # none / wpa1 /wpa2 | |
67 | $wlanapsettings{'TXPOWER'} = 'auto'; | |
68 | $wlanapsettings{'CHANNEL'} = '05'; | |
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'} = 'MADWIFI'; | |
75 | $wlanapsettings{'HTCAPS'} = ''; | |
76 | ||
77 | &General::readhash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
78 | &Header::getcgihash(\%wlanapsettings); | |
79 | ||
80 | my @macs = $wlanapsettings{'MACS'}; | |
81 | ||
82 | delete $wlanapsettings{'__CGI__'}; | |
83 | delete $wlanapsettings{'x'}; | |
84 | delete $wlanapsettings{'y'}; | |
85 | delete $wlanapsettings{'MACS'}; | |
86 | delete $wlanapsettings{'ACCEPT_MACS'}; | |
87 | delete $wlanapsettings{'DENY_MACS'}; | |
88 | ||
89 | &Header::showhttpheaders(); | |
90 | ||
91 | my $string=(); | |
92 | my $status=(); | |
93 | my $errormessage = ''; | |
94 | my $memory = 0; | |
95 | my @memory=(); | |
96 | my @pid=(); | |
97 | my @hostapd=(); | |
98 | sub pid | |
99 | { | |
100 | # for pid and memory | |
101 | open(FILE, '/usr/local/bin/addonctrl hostapd status | '); | |
102 | @hostapd = <FILE>; | |
103 | close(FILE); | |
104 | $string = join("", @hostapd); | |
105 | $string =~ s/[a-z_]//gi; | |
106 | $string =~ s/\[[0-1]\;[0-9]+//gi; | |
107 | $string =~ s/[\(\)\.]//gi; | |
108 | $string =~ s/ //gi; | |
109 | $string =~ s/\e//gi; | |
110 | @pid = split(/\s/,$string); | |
111 | if (open(FILE, "/proc/$pid[0]/statm")){ | |
112 | my $temp = <FILE>; | |
113 | @memory = split(/ /,$temp); | |
114 | close(FILE); | |
115 | } | |
116 | $memory+=$memory[0]; | |
117 | } | |
118 | pid(); | |
119 | ||
120 | ||
121 | ||
122 | if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap del interface'}" ){ | |
123 | delete $wlanapsettings{'INTERFACE'}; | |
124 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
125 | } | |
126 | ||
127 | if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'save'}" ){ | |
128 | # verify WPA Passphrase - only with enabled enc | |
129 | if (($wlanapsettings{'ENC'} eq "wpa1") || ($wlanapsettings{'ENC'} eq "wpa2") || ($wlanapsettings{'ENC'} eq "wpa1+2")){ | |
130 | # must be 8 .. 63 characters | |
131 | if ( (length($wlanapsettings{'PWD'}) < 8) || (length($wlanapsettings{'PWD'}) > 63)){ | |
132 | $errormessage .= "$Lang::tr{'wlanap invalid wpa'}<br />"; | |
133 | } | |
134 | # only ASCII alowed | |
135 | if ( !($wlanapsettings{'PWD'} !~ /[^\x00-\x7f]/) ){ | |
136 | $errormessage .= "$Lang::tr{'wlanap invalid wpa'}<br />"; | |
137 | } | |
138 | } | |
139 | ||
140 | if ( $errormessage eq '' ){ | |
141 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
142 | &WriteConfig_hostapd(); | |
143 | ||
144 | system("/usr/local/bin/wlanapctrl restart >/dev/null 2>&1"); | |
145 | pid(); | |
146 | } | |
147 | }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap interface'}" ){ | |
148 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
149 | }elsif ( ($wlanapsettings{'ACTION'} eq "$Lang::tr{'start'}") && ($memory == 0) ){ | |
150 | system("/usr/local/bin/wlanapctrl start >/dev/null 2>&1"); | |
151 | pid(); | |
152 | }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'stop'}" ){ | |
153 | system("/usr/local/bin/wlanapctrl stop >/dev/null 2>&1"); | |
154 | $memory=0; | |
155 | } | |
156 | ||
157 | &Header::openpage('', 1, '', ''); | |
158 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
159 | ||
160 | if ( $errormessage ){ | |
161 | &Header::openbox('100%', 'center', $Lang::tr{'error messages'}); | |
162 | print "<class name='base'>$errormessage\n"; | |
163 | print " </class>\n"; | |
164 | &Header::closebox(); | |
165 | } | |
166 | ||
167 | ||
168 | # Found this usefull piece of code in BlockOutTraffic AddOn 8-) | |
169 | # fwrules.cgi | |
170 | ############### | |
171 | # DEBUG DEBUG | |
172 | if ( $debug ){ | |
173 | &Header::openbox('100%', 'center', 'DEBUG'); | |
174 | my $debugCount = 0; | |
175 | foreach my $line (sort keys %wlanapsettings) { | |
176 | print "$line = '$wlanapsettings{$line}'<br />\n"; | |
177 | $debugCount++; | |
178 | } | |
179 | print " Count: $debugCount\n"; | |
180 | &Header::closebox(); | |
181 | } | |
182 | # DEBUG DEBUG | |
183 | ############### | |
184 | ||
185 | # | |
186 | # Driver and status detection | |
187 | # | |
188 | my $wlan_card_status = 'dummy'; | |
189 | my $wlan_ap_status = ''; | |
190 | my $message = ""; | |
191 | ||
192 | $selected{'INTERFACE'}{'green0'} = ''; | |
193 | $selected{'INTERFACE'}{'blue0'} = ''; | |
194 | $selected{'ENC'}{$wlanapsettings{'INTERFACE'}} = "selected='selected'"; | |
195 | ||
196 | if ( ($wlanapsettings{'INTERFACE'} eq '') ){ | |
197 | $message = $Lang::tr{'wlanap select interface'}; | |
198 | &Header::openbox('100%', 'center', "WLAN AP"); | |
199 | print <<END | |
200 | $message<br /> | |
201 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
202 | <select name='INTERFACE'> | |
203 | END | |
204 | ; | |
205 | if ( $netsettings{'BLUE_DEV'} ne ''){ | |
206 | print "<option value='blue0' $selected{'INTERFACE'}{'blue0'}>blue0</option>"; | |
207 | } | |
208 | print <<END | |
209 | <option value='green0' $selected{'INTERFACE'}{'green0'}>green0</option> | |
210 | </select> | |
211 | <br /><br /> | |
212 | <hr size='1'> | |
213 | <input type='submit' name='ACTION' value='$Lang::tr{'wlanap interface'}' /></form> | |
214 | END | |
215 | ; | |
216 | &Header::closebox(); | |
217 | &Header::closebigbox(); | |
218 | &Header::closepage(); | |
219 | exit; | |
220 | }else{ | |
221 | my $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} 2>/dev/null`; | |
222 | ||
223 | if ( $cmd_out eq '' ){ | |
224 | $message = "$Lang::tr{'wlanap no interface'}"; | |
225 | $wlan_card_status = ''; | |
226 | }else{ | |
227 | $cmd_out = `/sbin/ifconfig | /bin/grep $wlanapsettings{'INTERFACE'}`; | |
228 | if ( $cmd_out eq '' ){ | |
229 | $wlan_card_status = 'down'; | |
230 | }else{ | |
231 | $wlan_card_status = 'up'; | |
232 | $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} | /bin/grep "Mode:Master"`; | |
233 | if ( $cmd_out ne '' ){ | |
234 | $wlan_ap_status = 'up'; | |
235 | } | |
236 | } | |
237 | } | |
238 | } | |
239 | ||
240 | # Change old "n" to "gn" | |
241 | if ( $wlanapsettings{'HW_MODE'} eq 'n' ) { | |
242 | $wlanapsettings{'HW_MODE'}='gn'; | |
243 | } | |
244 | ||
245 | $checked{'HIDESSID'}{'off'} = ''; | |
246 | $checked{'HIDESSID'}{'on'} = ''; | |
247 | $checked{'HIDESSID'}{$wlanapsettings{'HIDESSID'}} = "checked='checked'"; | |
248 | ||
249 | $selected{'ENC'}{$wlanapsettings{'ENC'}} = "selected='selected'"; | |
250 | $selected{'CHANNEL'}{$wlanapsettings{'CHANNEL'}} = "selected='selected'"; | |
251 | $selected{'COUNTRY'}{$wlanapsettings{'COUNTRY'}} = "selected='selected'"; | |
252 | $selected{'TXPOWER'}{$wlanapsettings{'TXPOWER'}} = "selected='selected'"; | |
253 | $selected{'HW_MODE'}{$wlanapsettings{'HW_MODE'}} = "selected='selected'"; | |
254 | $selected{'MACMODE'}{$wlanapsettings{'MACMODE'}} = "selected='selected'"; | |
255 | ||
256 | my $monwlaninterface = $wlanapsettings{'INTERFACE'}; | |
257 | if ( -d '/sys/class/net/mon.'.$wlanapsettings{'INTERFACE'} ) { | |
258 | $monwlaninterface = 'mon.'.$wlanapsettings{'INTERFACE'}; | |
259 | } | |
260 | ||
261 | my @channellist_cmd; | |
262 | my @channellist; | |
263 | ||
264 | if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ | |
265 | my $wiphy = `iw dev $wlanapsettings{'INTERFACE'} info | grep wiphy | cut -d" " -f2`; | |
266 | chomp $wiphy; | |
267 | ||
268 | @channellist_cmd = `iw phy phy$wiphy info | grep " MHz \\\[" | grep -v "(disabled)" | grep -v "no IBSS" | grep -v "passive scanning" 2>/dev/null`; | |
269 | # get available channels | |
270 | ||
271 | my @temp; | |
272 | foreach (@channellist_cmd){ | |
273 | $_ =~ /(.*) \[(\d+)(.*)\]/; | |
274 | $channel = $2;chomp $channel; | |
275 | if ( $channel =~ /\d+/ ){push(@temp,$channel);} | |
276 | } | |
277 | @channellist = @temp; | |
278 | } else { | |
279 | @channellist_cmd = `iwlist $monwlaninterface channel|tail -n +2 2>/dev/null`; | |
280 | # get available channels | |
281 | ||
282 | my @temp; | |
283 | foreach (@channellist_cmd){ | |
284 | $_ =~ /(.*)Channel (\d+)(.*):/; | |
285 | $channel = $2;chomp $channel; | |
286 | if ( $channel =~ /\d+/ ){push(@temp,$channel);} | |
287 | } | |
288 | @channellist = @temp; | |
289 | } | |
290 | ||
291 | my @countrylist_cmd = `regdbdump /usr/lib/crda/regulatory.bin 2>/dev/null`; | |
292 | # get available country codes | |
293 | ||
294 | my @temp; | |
295 | foreach (@countrylist_cmd){ | |
296 | $_ =~ /country (.*):/; | |
297 | $country = $1;chomp $country; | |
298 | if ( $country =~ /[0,A-Z][0,A-Z]/ ) {push(@temp,$country);} | |
299 | } | |
300 | my @countrylist = @temp; | |
301 | ||
302 | my @txpower_cmd = `iwlist $monwlaninterface txpower 2>/dev/null`; | |
303 | if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ | |
304 | # There is a bug with NL80211 only all devices can displayed | |
305 | @txpower_cmd = `iwlist txpower 2>/dev/null | sed -e "s|unknown transmit-power information.||g"`; | |
306 | } | |
307 | # get available power | |
308 | ||
309 | my @temp; | |
310 | foreach (@txpower_cmd){ | |
311 | $_ =~ /(\s)(\d+)(\s)dBm(\s)(.*)(\W)(\d+)(.*)/; | |
312 | $txpower = $7;chomp $txpower; | |
313 | if ( $txpower =~ /\d+/ ){push(@temp,$txpower."mW");} | |
314 | } | |
315 | my @txpower = @temp; | |
316 | push(@txpower,"auto"); | |
317 | ||
318 | $selected{'SYSLOGLEVEL'}{$wlanapsettings{'SYSLOGLEVEL'}} = "selected='selected'"; | |
319 | $selected{'DEBUG'}{$wlanapsettings{'DEBUG'}} = "selected='selected'"; | |
320 | ||
321 | # | |
322 | # Status box | |
323 | # | |
324 | &Header::openbox('100%', 'center', "WLAN AP"); | |
325 | print <<END | |
326 | <table width='80%' cellspacing='1' class='tbl'> | |
327 | END | |
328 | ; | |
329 | ||
330 | if ( $wlan_card_status ne '' ){ | |
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>"; | |
333 | print $wlan_card_status eq 'up' ? $status_started : $status_stopped; | |
334 | print"<td colspan='4'></td></tr>"; | |
335 | print "<tr><td class='base' bgcolor='$color{'color22'}'>$Lang::tr{'wlanap access point'}</td>"; | |
336 | print $wlan_ap_status eq 'up' ? $status_started : $status_stopped; | |
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 | } | |
347 | ||
348 | }else{ | |
349 | print "<tr><td class='base'>$message"; | |
350 | } | |
351 | print "</table>"; | |
352 | ||
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>"; | |
358 | print "</tr>"; | |
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>"; | |
364 | print "</tr>"; | |
365 | print "</table>"; | |
366 | } | |
367 | ||
368 | if ( $wlan_card_status eq '' ){ | |
369 | &Header::closebox(); | |
370 | &Header::closebigbox(); | |
371 | &Header::closepage(); | |
372 | exit 0; | |
373 | } | |
374 | print <<END | |
375 | <br><br> | |
376 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
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> | |
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> | |
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> | |
394 | <tr><td width='25%' class='base'>HW Mode: </td><td class='base' colspan='3'> | |
395 | <select name='HW_MODE'> | |
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> | |
399 | <option value='an' $selected{'HW_MODE'}{'an'}>802.11an</option> | |
400 | <option value='gn' $selected{'HW_MODE'}{'gn'}>802.11gn</option> | |
401 | </select> | |
402 | </td></tr> | |
403 | END | |
404 | ; | |
405 | ||
406 | if ( scalar @channellist > 0 ){ | |
407 | print <<END | |
408 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap channel'}: </td><td class='base' colspan='3'> | |
409 | <select name='CHANNEL'> | |
410 | END | |
411 | ; | |
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 | ; | |
423 | } | |
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> | |
436 | END | |
437 | ; | |
438 | print <<END | |
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> | |
440 | <tr><td width='25%' class='base'>Tx Power: </td><td class='base' colspan='3'> | |
441 | END | |
442 | ; | |
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>" | |
452 | } | |
453 | print <<END | |
454 | <tr><td width='25%' class='base'>Loglevel (hostapd): </td><td class='base' width='25%'> | |
455 | <select name='SYSLOGLEVEL'> | |
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> | |
461 | </select> | |
462 | </td> | |
463 | <td width='25%' class='base'>Debuglevel (hostapd): </td><td class='base' width='25%'> | |
464 | <select name='DEBUG'> | |
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> | |
470 | </select> | |
471 | </td></tr> | |
472 | <tr><td colspan='4'><br></td></tr> | |
473 | </table> | |
474 | END | |
475 | ; | |
476 | if ( $wlanapsettings{'INTERFACE'} =~ /green0/ ){ | |
477 | print <<END | |
478 | <br /> | |
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> | |
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> | |
486 | <option value='1' $selected{'MACMODE'}{'1'}>1 (Accept MACs)</option> | |
487 | <option value='2' $selected{'MACMODE'}{'2'}>2 (Deny MACs)</option> | |
488 | </select> | |
489 | </td><td colspan='2'>Mac Adress List (one per line)<br /><textarea name='MACS' cols='20' rows='5' wrap='off'> | |
490 | END | |
491 | ; | |
492 | print `cat /var/ipfire/wlanap/macfile`; | |
493 | print <<END | |
494 | </textarea></td> | |
495 | </table> | |
496 | END | |
497 | ; | |
498 | } | |
499 | print <<END | |
500 | <br /> | |
501 | <table width='80%' cellspacing='0'> | |
502 | <tr><td align='center'> | |
503 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
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> | |
506 | </tr> | |
507 | </table> | |
508 | END | |
509 | ; | |
510 | my @status; | |
511 | if ( $wlanapsettings{'DRIVER'} eq 'MADWIFI' ){ | |
512 | @status = `wlanconfig $wlanapsettings{'INTERFACE'} list`; | |
513 | } | |
514 | if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ | |
515 | @status = `iw dev $wlanapsettings{'INTERFACE'} info && iw dev $wlanapsettings{'INTERFACE'} station dump && echo ""`; | |
516 | } | |
517 | print <<END | |
518 | <br /> | |
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 | ; | |
523 | ||
524 | for (my $i=0;$i<$#status;$i++){ | |
525 | ||
526 | if (@status[$i]=~"^Station ") { $count++; } | |
527 | if ($count % 2){ | |
528 | $col="bgcolor='$color{'color20'}'"; | |
529 | }else{ | |
530 | $col="bgcolor='$color{'color22'}'"; | |
531 | } | |
532 | print"<tr><td colspan='3' $col><pre>@status[$i]</pre></td></tr>"; | |
533 | if (! @status[$i]=~"^/t" ) { $count++; } | |
534 | } | |
535 | $count++; | |
536 | ||
537 | foreach my $nr (@channellist_cmd){ | |
538 | if ($count % 2){ | |
539 | $col="bgcolor='$color{'color20'}'"; | |
540 | }else{ | |
541 | $col="bgcolor='$color{'color22'}'"; | |
542 | } | |
543 | print"<tr><td colspan='3' $col>$nr</td></tr>"; | |
544 | $count++; | |
545 | } | |
546 | ||
547 | for (my $i=0;$i<$#txpower_cmd;$i=$i+2){ | |
548 | if ($count % 2){ | |
549 | $col="bgcolor='$color{'color20'}'"; | |
550 | }else{ | |
551 | $col="bgcolor='$color{'color22'}'"; | |
552 | } | |
553 | print "<tr><td $col>@txpower_cmd[$i]</td></tr>"; | |
554 | $count++; | |
555 | } | |
556 | print "</table><br>"; | |
557 | print <<END | |
558 | <br /> | |
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> | |
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> | |
563 | <tr><td><br></td></tr> | |
564 | </table> | |
565 | END | |
566 | ; | |
567 | &Header::closebox(); | |
568 | print "</form>"; | |
569 | &Header::closebigbox(); | |
570 | &Header::closepage(); | |
571 | ||
572 | sub WriteConfig_hostapd{ | |
573 | $wlanapsettings{'DRIVER_HOSTAPD'} = lc($wlanapsettings{'DRIVER'}); | |
574 | ||
575 | open (CONFIGFILE, ">/var/ipfire/wlanap/hostapd.conf"); | |
576 | print CONFIGFILE <<END | |
577 | driver=$wlanapsettings{'DRIVER_HOSTAPD'} | |
578 | ######################### basic hostapd configuration ########################## | |
579 | # | |
580 | interface=$wlanapsettings{'INTERFACE'} | |
581 | country_code=$wlanapsettings{'COUNTRY'} | |
582 | ieee80211d=1 | |
583 | ieee80211h=1 | |
584 | channel=$wlanapsettings{'CHANNEL'} | |
585 | END | |
586 | ; | |
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' ){ | |
597 | print CONFIGFILE <<END | |
598 | hw_mode=g | |
599 | ieee80211n=1 | |
600 | wmm_enabled=1 | |
601 | ht_capab=$wlanapsettings{'HTCAPS'} | |
602 | END | |
603 | ; | |
604 | ||
605 | }else{ | |
606 | print CONFIGFILE <<END | |
607 | hw_mode=$wlanapsettings{'HW_MODE'} | |
608 | END | |
609 | ; | |
610 | ||
611 | } | |
612 | ||
613 | print CONFIGFILE <<END | |
614 | logger_syslog=-1 | |
615 | logger_syslog_level=$wlanapsettings{'SYSLOGLEVEL'} | |
616 | logger_stdout=-1 | |
617 | logger_stdout_level=$wlanapsettings{'DEBUG'} | |
618 | dump_file=/tmp/hostapd.dump | |
619 | auth_algs=1 | |
620 | ctrl_interface=/var/run/hostapd | |
621 | ctrl_interface_group=0 | |
622 | END | |
623 | ; | |
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 | } | |
639 | ||
640 | if ( $wlanapsettings{'ENC'} eq 'wpa1'){ | |
641 | print CONFIGFILE <<END | |
642 | ######################### wpa hostapd configuration ############################ | |
643 | # | |
644 | wpa=1 | |
645 | wpa_passphrase=$wlanapsettings{'PWD'} | |
646 | wpa_key_mgmt=WPA-PSK | |
647 | wpa_pairwise=TKIP | |
648 | END | |
649 | ; | |
650 | }elsif ( $wlanapsettings{'ENC'} eq 'wpa2'){ | |
651 | print CONFIGFILE <<END | |
652 | ######################### wpa hostapd configuration ############################ | |
653 | # | |
654 | wpa=2 | |
655 | wpa_passphrase=$wlanapsettings{'PWD'} | |
656 | wpa_key_mgmt=WPA-PSK | |
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 | |
669 | END | |
670 | ; | |
671 | } | |
672 | close CONFIGFILE; | |
673 | ||
674 | open (MACFILE, ">/var/ipfire/wlanap/macfile"); | |
675 | foreach(@macs){ | |
676 | $_ =~ s/\r//gi; | |
677 | chomp($_); | |
678 | if ( $_ ne "" ){print MACFILE $_;} | |
679 | } | |
680 | close MACFILE; | |
681 | } |