]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2009 Michael Tremer & Christian Schmidt # | |
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' width='75%' bgcolor='${Header::colourgreen}'><font color='white'><strong>$Lang::tr{'running'}</strong></font></td></tr>"; | |
39 | my $status_stopped = "<td align='center' width='75%' bgcolor='${Header::colourred}'><font color='white'><strong>$Lang::tr{'stopped'}</strong></font></td></tr>"; | |
40 | ||
41 | # get rid of used only once warnings | |
42 | my @onlyonce = ( $Header::colourgreen, $Header::colourred ); | |
43 | undef @onlyonce; | |
44 | ||
45 | my %selected=(); | |
46 | my %checked=(); | |
47 | my %color = (); | |
48 | my %mainsettings = (); | |
49 | my %netsettings=(); | |
50 | my %wlanapsettings=(); | |
51 | my $channel = ''; | |
52 | my $txpower = ''; | |
53 | ||
54 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
55 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
56 | &General::readhash("/var/ipfire/ethernet/settings", \%netsettings); | |
57 | ||
58 | $wlanapsettings{'APMODE'} = 'on'; | |
59 | $wlanapsettings{'ACTION'} = ''; | |
60 | $wlanapsettings{'MACMODE'} = '0'; | |
61 | $wlanapsettings{'INTERFACE'} = ''; | |
62 | $wlanapsettings{'SSID'} = 'IPFire'; | |
63 | $wlanapsettings{'HIDESSID'} = 'off'; | |
64 | $wlanapsettings{'ENC'} = 'wpa2'; # none / wpa1 /wpa2 | |
65 | $wlanapsettings{'TXPOWER'} = 'auto'; | |
66 | $wlanapsettings{'CHANNEL'} = '05'; | |
67 | $wlanapsettings{'HW_MODE'} = 'g'; | |
68 | $wlanapsettings{'PWD'} = 'IPFire-2.x'; | |
69 | $wlanapsettings{'SYSLOGLEVEL'} = '0'; | |
70 | $wlanapsettings{'DEBUG'} = '4'; | |
71 | $wlanapsettings{'DRIVER'} = 'MADWIFI'; | |
72 | ||
73 | &General::readhash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
74 | &Header::getcgihash(\%wlanapsettings); | |
75 | ||
76 | my @macs = $wlanapsettings{'MACS'}; | |
77 | ||
78 | delete $wlanapsettings{'__CGI__'}; | |
79 | delete $wlanapsettings{'x'}; | |
80 | delete $wlanapsettings{'y'}; | |
81 | delete $wlanapsettings{'MACS'}; | |
82 | delete $wlanapsettings{'ACCEPT_MACS'}; | |
83 | delete $wlanapsettings{'DENY_MACS'}; | |
84 | ||
85 | &Header::showhttpheaders(); | |
86 | ||
87 | my $string=(); | |
88 | my $status=(); | |
89 | my $errormessage = ''; | |
90 | my $memory = 0; | |
91 | my @memory=(); | |
92 | my @pid=(); | |
93 | my @hostapd=(); | |
94 | sub pid | |
95 | { | |
96 | # for pid and memory | |
97 | open(FILE, '/usr/local/bin/addonctrl hostapd status | '); | |
98 | @hostapd = <FILE>; | |
99 | close(FILE); | |
100 | $string = join("", @hostapd); | |
101 | $string =~ s/[a-z_]//gi; | |
102 | $string =~ s/\[[0-1]\;[0-9]+//gi; | |
103 | $string =~ s/[\(\)\.]//gi; | |
104 | $string =~ s/ //gi; | |
105 | $string =~ s/\e//gi; | |
106 | @pid = split(/\s/,$string); | |
107 | if (open(FILE, "/proc/$pid[0]/statm")){ | |
108 | my $temp = <FILE>; | |
109 | @memory = split(/ /,$temp); | |
110 | close(FILE); | |
111 | } | |
112 | $memory+=$memory[0]; | |
113 | } | |
114 | pid(); | |
115 | ||
116 | ||
117 | ||
118 | if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap del interface'}" ){ | |
119 | delete $wlanapsettings{'INTERFACE'}; | |
120 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
121 | } | |
122 | ||
123 | if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'save'}" ){ | |
124 | # verify WPA Passphrase, must be 8 .. 63 characters - only wiht enabled enc | |
125 | if (($wlanapsettings{'ENC'} eq "wpa1") || ($wlanapsettings{'ENC'} eq "wpa2")){ | |
126 | if ( (length($wlanapsettings{'PWD'}) < 8) || (length($wlanapsettings{'PWD'}) > 63)){ | |
127 | $errormessage .= "$Lang::tr{'wlanap invalid wpa'}<br />"; | |
128 | } | |
129 | } | |
130 | ||
131 | if ( $errormessage eq '' ){ | |
132 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
133 | &WriteConfig_hostapd(); | |
134 | ||
135 | system("/usr/local/bin/wlanapctrl restart >/dev/null 2>&1"); | |
136 | pid(); | |
137 | } | |
138 | }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap interface'}" ){ | |
139 | &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); | |
140 | }elsif ( ($wlanapsettings{'ACTION'} eq "$Lang::tr{'start'}") && ($memory == 0) ){ | |
141 | system("/usr/local/bin/wlanapctrl start >/dev/null 2>&1"); | |
142 | pid(); | |
143 | }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'stop'}" ){ | |
144 | system("/usr/local/bin/wlanapctrl stop >/dev/null 2>&1"); | |
145 | $memory=0; | |
146 | }elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'restart'}" ){ | |
147 | system("/usr/local/bin/wlanapctrl restart >/dev/null 2>&1"); | |
148 | pid(); | |
149 | } | |
150 | ||
151 | &Header::openpage('Wireless LAN', 1, '', ''); | |
152 | &Header::openbigbox('100%', 'left', '', $errormessage); | |
153 | ||
154 | if ( $errormessage ){ | |
155 | &Header::openbox('100%', 'center', $Lang::tr{'error messages'}); | |
156 | print "<class name='base'>$errormessage\n"; | |
157 | print " </class>\n"; | |
158 | &Header::closebox(); | |
159 | } | |
160 | ||
161 | ||
162 | # Found this usefull piece of code in BlockOutTraffic AddOn 8-) | |
163 | # fwrules.cgi | |
164 | ############### | |
165 | # DEBUG DEBUG | |
166 | if ( $debug ){ | |
167 | &Header::openbox('100%', 'center', 'DEBUG'); | |
168 | my $debugCount = 0; | |
169 | foreach my $line (sort keys %wlanapsettings) { | |
170 | print "$line = '$wlanapsettings{$line}'<br />\n"; | |
171 | $debugCount++; | |
172 | } | |
173 | print " Count: $debugCount\n"; | |
174 | &Header::closebox(); | |
175 | } | |
176 | # DEBUG DEBUG | |
177 | ############### | |
178 | ||
179 | # | |
180 | # Driver and status detection | |
181 | # | |
182 | my $wlan_card_status = 'dummy'; | |
183 | my $wlan_ap_status = ''; | |
184 | my $message = ""; | |
185 | ||
186 | $selected{'INTERFACE'}{'green0'} = ''; | |
187 | $selected{'INTERFACE'}{'blue0'} = ''; | |
188 | $selected{'ENC'}{$wlanapsettings{'INTERFACE'}} = "selected='selected'"; | |
189 | ||
190 | if ( ($wlanapsettings{'INTERFACE'} eq '') ){ | |
191 | $message = $Lang::tr{'wlanap select interface'}; | |
192 | &Header::openbox('100%', 'center', "WLAN AP"); | |
193 | print <<END | |
194 | $message<br /> | |
195 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
196 | <select name='INTERFACE'> | |
197 | END | |
198 | ; | |
199 | if ( $netsettings{'BLUE_DEV'} ne ''){ | |
200 | print "<option value='blue0' $selected{'INTERFACE'}{'blue0'}>blue0</option>"; | |
201 | } | |
202 | print <<END | |
203 | <option value='green0' $selected{'INTERFACE'}{'green0'}>green0</option> | |
204 | </select> | |
205 | <br /><br /> | |
206 | <hr size='1'> | |
207 | <input type='submit' name='ACTION' value='$Lang::tr{'wlanap interface'}' /></form> | |
208 | END | |
209 | ; | |
210 | &Header::closebox(); | |
211 | &Header::closebigbox(); | |
212 | &Header::closepage(); | |
213 | exit; | |
214 | }else{ | |
215 | my $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} 2>/dev/null`; | |
216 | ||
217 | if ( $cmd_out eq '' ){ | |
218 | $message = "$Lang::tr{'wlanap no interface'}"; | |
219 | $wlan_card_status = ''; | |
220 | }else{ | |
221 | $cmd_out = `/sbin/ifconfig | /bin/grep $wlanapsettings{'INTERFACE'}`; | |
222 | if ( $cmd_out eq '' ){ | |
223 | $wlan_card_status = 'down'; | |
224 | }else{ | |
225 | $wlan_card_status = 'up'; | |
226 | $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} | /bin/grep "Mode:Master"`; | |
227 | if ( $cmd_out ne '' ){ | |
228 | $wlan_ap_status = 'up'; | |
229 | } | |
230 | } | |
231 | } | |
232 | } | |
233 | ||
234 | $checked{'HIDESSID'}{'off'} = ''; | |
235 | $checked{'HIDESSID'}{'on'} = ''; | |
236 | $checked{'HIDESSID'}{$wlanapsettings{'HIDESSID'}} = "checked='checked'"; | |
237 | ||
238 | $selected{'ENC'}{$wlanapsettings{'ENC'}} = "selected='selected'"; | |
239 | $selected{'CHANNEL'}{$wlanapsettings{'CHANNEL'}} = "selected='selected'"; | |
240 | $selected{'TXPOWER'}{$wlanapsettings{'TXPOWER'}} = "selected='selected'"; | |
241 | $selected{'HW_MODE'}{$wlanapsettings{'HW_MODE'}} = "selected='selected'"; | |
242 | $selected{'MACMODE'}{$wlanapsettings{'MACMODE'}} = "selected='selected'"; | |
243 | ||
244 | my @channellist_cmd = `iwlist $wlanapsettings{'INTERFACE'} channel`; | |
245 | # get available channels | |
246 | ||
247 | my @temp; | |
248 | foreach (@channellist_cmd){ | |
249 | $_ =~ /(.*)Channel (\d+)(.*):/; | |
250 | $channel = $2;chomp $channel; | |
251 | if ( $channel =~ /\d+/ ){push(@temp,$channel);} | |
252 | } | |
253 | my @channellist = @temp; | |
254 | ||
255 | my @txpower_cmd = `iwlist $wlanapsettings{'INTERFACE'} txpower`; | |
256 | # get available channels | |
257 | ||
258 | my @temp; | |
259 | foreach (@txpower_cmd){ | |
260 | $_ =~ /(\s)(\d+)(\s)dBm(\s)(.*)(\W)(\d+)(.*)/; | |
261 | $txpower = $7;chomp $txpower; | |
262 | if ( $txpower =~ /\d+/ ){push(@temp,$txpower."mW");} | |
263 | } | |
264 | my @txpower = @temp; | |
265 | push(@txpower,"auto"); | |
266 | ||
267 | $selected{'SYSLOGLEVEL'}{$wlanapsettings{'SYSLOGLEVEL'}} = "selected='selected'"; | |
268 | $selected{'DEBUG'}{$wlanapsettings{'DEBUG'}} = "selected='selected'"; | |
269 | ||
270 | # | |
271 | # Status box | |
272 | # | |
273 | &Header::openbox('100%', 'center', "WLAN AP"); | |
274 | print <<END | |
275 | <table width='95%' cellspacing='0'> | |
276 | END | |
277 | ; | |
278 | ||
279 | if ( $wlan_card_status ne '' ){ | |
280 | print "<tr><td bgcolor='$color{'color20'}' colspan='3' align='left'><strong>$Lang::tr{'wlanap wlan services'}</strong></td></tr>"; | |
281 | print "<tr><td colspan='1' class='base'>$Lang::tr{'wlanap wlan card'} ($wlanapsettings{'DRIVER'})</td>"; | |
282 | print $wlan_card_status eq 'up' ? $status_started : $status_stopped; | |
283 | print "<tr><td colspan='1' class='base'>$Lang::tr{'wlanap access point'}</td>"; | |
284 | print $wlan_ap_status eq 'up' ? $status_started : $status_stopped; | |
285 | ||
286 | }else{ | |
287 | print "<tr><td colspan='2' class='base'>$message"; | |
288 | } | |
289 | print "</table>"; | |
290 | ||
291 | if ( ($memory != 0) && (@pid[0] ne "///") && ($wlan_card_status ne '') ){ | |
292 | print "<table width='95%' cellspacing='0' border='0'>"; | |
293 | print "<tr>"; | |
294 | print "<td align='center'></td>"; | |
295 | print "<td bgcolor='$color{'color20'}' align='center'><strong>PID</strong></td>"; | |
296 | print "<td bgcolor='$color{'color20'}' align='center'><strong>$Lang::tr{'memory'}</strong></td>"; | |
297 | print "</tr>"; | |
298 | print "<tr>"; | |
299 | print "<td width='35%' align='right'><strong>hostapd</strong> </td>"; | |
300 | print "<td bgcolor='$color{'color22'}' align='center'>@pid[0]</td>"; | |
301 | print "<td bgcolor='$color{'color22'}' align='center'>$memory KB</td>"; | |
302 | print "</tr>"; | |
303 | print "</table>"; | |
304 | } | |
305 | ||
306 | if ( $wlan_card_status ne '' ){ | |
307 | print "<br />"; | |
308 | print "<table width='95%' cellspacing='0' border='0'>"; | |
309 | print "<tr align='center'>"; | |
310 | print "<td colspan='4'><hr size='1'></td>"; | |
311 | print "</tr>"; | |
312 | print "<tr align='center'>"; | |
313 | print "<td width='40%'> </td>"; | |
314 | print "<td width='20%'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='submit' name='ACTION' value='$Lang::tr{'start'}' /></form></td>"; | |
315 | print "<td width='20%'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='submit' name='ACTION' value='$Lang::tr{'stop'}' /></form></td>"; | |
316 | print "<td width='20%'><form method='post' action='$ENV{'SCRIPT_NAME'}'><input type='submit' name='ACTION' value='$Lang::tr{'restart'}' /></form></td>"; | |
317 | print "</tr>"; | |
318 | print "</table>"; | |
319 | }else{ | |
320 | print "<br />"; | |
321 | print "<table width='95%' cellspacing='0' border='0'>"; | |
322 | print "<tr align='center'>"; | |
323 | print "<td colspan='4'><hr size='1'></td>"; | |
324 | print "</tr>"; | |
325 | print "<tr align='center'>"; | |
326 | print "<td width='40%'> </td>"; | |
327 | 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>"; | |
328 | print "<td width='20%'></td>"; | |
329 | print "<td width='20%'></td>"; | |
330 | print "</tr>"; | |
331 | print "</table>"; | |
332 | } | |
333 | ||
334 | if ( $wlan_card_status eq '' ){ | |
335 | &Header::closebox(); | |
336 | &Header::closebigbox(); | |
337 | &Header::closepage(); | |
338 | exit 0; | |
339 | } | |
340 | print <<END | |
341 | <br /> | |
342 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
343 | <table width='95%' cellspacing='0'> | |
344 | <tr><td bgcolor='$color{'color20'}' colspan='4' align='left'><strong>$Lang::tr{'wlanap wlan settings'}</strong> | |
345 | <tr><td width='25%' class='base'>SSID: </td><td class='base' colspan='3'><input type='text' name='SSID' size='40' value='$wlanapsettings{'SSID'}' /></td></tr> | |
346 | <!--SSID Broadcast: on => HIDESSID: off --> | |
347 | <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> | |
348 | <tr><td width='25%' class='base'>HW Mode: </td><td class='base' colspan='3'> | |
349 | <select name='HW_MODE'> | |
350 | <option value='a' $selected{'HW_MODE'}{'a'}>802.11a</option> | |
351 | <option value='b' $selected{'HW_MODE'}{'b'}>802.11b</option> | |
352 | <option value='g' $selected{'HW_MODE'}{'g'}>802.11g</option> | |
353 | <option value='n' $selected{'HW_MODE'}{'n'}>802.11n</option> | |
354 | </select> | |
355 | </td></tr> | |
356 | ||
357 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap encryption'}: </td><td class='base' colspan='3'> | |
358 | <select name='ENC'> | |
359 | <option value='none' $selected{'ENC'}{'none'}>$Lang::tr{'wlanap none'}</option> | |
360 | <option value='wpa1' $selected{'ENC'}{'wpa1'}>WPA1</option> | |
361 | <option value='wpa2' $selected{'ENC'}{'wpa2'}>WPA2</option> | |
362 | </select> | |
363 | </td></tr> | |
364 | <tr><td width='25%' class='base'>$Lang::tr{'wlanap channel'}: </td><td class='base' colspan='3'> | |
365 | <select name='CHANNEL'> | |
366 | END | |
367 | ; | |
368 | foreach $channel (@channellist){ | |
369 | print "<option $selected{'CHANNEL'}{$channel}>$channel</option>"; | |
370 | } | |
371 | ||
372 | print <<END | |
373 | </select></td></tr> | |
374 | <tr><td width='25%' class='base'>Tx Power: </td><td class='base' colspan='3'><select name='TXPOWER'> | |
375 | END | |
376 | ; | |
377 | foreach $txpower (@txpower){ | |
378 | print "<option $selected{'TXPOWER'}{$txpower}>$txpower</option> dBm"; | |
379 | } | |
380 | print <<END | |
381 | </select></td></tr> | |
382 | <tr><td width='25%' class='base'>Passphrase: </td><td class='base' colspan='3'><input type='text' name='PWD' size='63' value='$wlanapsettings{'PWD'}' /></td></tr> | |
383 | <tr><td width='25%' class='base'>Loglevel (hostapd): </td><td class='base' width='25%'> | |
384 | <select name='SYSLOGLEVEL'> | |
385 | <option value='0' $selected{'SYSLOGLEVEL'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option> | |
386 | <option value='1' $selected{'SYSLOGLEVEL'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option> | |
387 | <option value='2' $selected{'SYSLOGLEVEL'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option> | |
388 | <option value='3' $selected{'SYSLOGLEVEL'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option> | |
389 | <option value='4' $selected{'SYSLOGLEVEL'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option> | |
390 | </select> | |
391 | </td> | |
392 | <td width='25%' class='base'>Debuglevel (hostapd): </td><td class='base' width='25%'> | |
393 | <select name='DEBUG'> | |
394 | <option value='0' $selected{'DEBUG'}{'0'}>0 ($Lang::tr{'wlanap verbose'})</option> | |
395 | <option value='1' $selected{'DEBUG'}{'1'}>1 ($Lang::tr{'wlanap debugging'})</option> | |
396 | <option value='2' $selected{'DEBUG'}{'2'}>2 ($Lang::tr{'wlanap informations'})</option> | |
397 | <option value='3' $selected{'DEBUG'}{'3'}>3 ($Lang::tr{'wlanap notifications'})</option> | |
398 | <option value='4' $selected{'DEBUG'}{'4'}>4 ($Lang::tr{'wlanap warnings'})</option> | |
399 | </select> | |
400 | </td></tr> | |
401 | </table> | |
402 | END | |
403 | ; | |
404 | if ( $wlanapsettings{'INTERFACE'} =~ /green0/ ){ | |
405 | print <<END | |
406 | <br /> | |
407 | <table width='95%' cellspacing='0'> | |
408 | <td width='25%' class='base'>Mac Filter: </td><td class='base' width='25%'> | |
409 | <select name='MACMODE'> | |
410 | <option value='0' $selected{'MACMODE'}{'0'}>0 (off)</option> | |
411 | <option value='1' $selected{'MACMODE'}{'1'}>1 (Accept MACs)</option> | |
412 | <option value='2' $selected{'MACMODE'}{'2'}>2 (Deny MACs)</option> | |
413 | </select> | |
414 | </td><td colspan='2'>Mac Adress List (one per line)<br /><textarea name='MACS' cols='20' rows='5' wrap='off'> | |
415 | END | |
416 | ; | |
417 | print `cat /var/ipfire/wlanap/macfile`; | |
418 | print <<END | |
419 | </textarea></td> | |
420 | </table> | |
421 | END | |
422 | ; | |
423 | } | |
424 | print <<END | |
425 | <br /> | |
426 | <table width='95%' cellspacing='0'> | |
427 | <tr><td align='center'><hr size='1'> | |
428 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
429 | <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></form></td> | |
430 | </tr> | |
431 | </table> | |
432 | END | |
433 | ; | |
434 | ||
435 | if ( $wlanapsettings{'DRIVER'} eq 'MADWIFI' ){ | |
436 | $status = `wlanconfig $wlanapsettings{'INTERFACE'} list`; | |
437 | } | |
438 | if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ | |
439 | $status = `iw dev $wlanapsettings{'INTERFACE'} station dump`; | |
440 | } | |
441 | print <<END | |
442 | <br /> | |
443 | <table width='95%' cellspacing='0'> | |
444 | <tr><td bgcolor='$color{'color20'}' colspan='2' align='left'><strong>$Lang::tr{'wlanap wlan status'}</strong></td></tr> | |
445 | <tr><td><pre>@channellist_cmd</pre></td><td><pre>@txpower_cmd</pre></td></tr> | |
446 | <tr><td colspan='2'><pre>$status</pre></td></tr> | |
447 | </table> | |
448 | <br /> | |
449 | <table width='95%' cellspacing='0'> | |
450 | <tr><td bgcolor='$color{'color20'}' align='left'><strong>WLan Clients</strong></td></tr> | |
451 | <tr><td> <a href="/cgi-bin/wireless.cgi">$Lang::tr{'wlanap link wireless'}</a></td></tr> | |
452 | <tr><td> <a href="/cgi-bin/dhcp.cgi">$Lang::tr{'wlanap link dhcp'}</a></td></tr> | |
453 | </table> | |
454 | END | |
455 | ; | |
456 | &Header::closebox(); | |
457 | print "</form>"; | |
458 | &Header::closebigbox(); | |
459 | &Header::closepage(); | |
460 | ||
461 | sub WriteConfig_hostapd{ | |
462 | $wlanapsettings{'DRIVER_HOSTAPD'} = lc($wlanapsettings{'DRIVER'}); | |
463 | ||
464 | open (CONFIGFILE, ">/var/ipfire/wlanap/hostapd.conf"); | |
465 | print CONFIGFILE <<END | |
466 | ######################### basic hostapd configuration ########################## | |
467 | # | |
468 | interface=$wlanapsettings{'INTERFACE'} | |
469 | driver=$wlanapsettings{'DRIVER_HOSTAPD'} | |
470 | channel=$wlanapsettings{'CHANNEL'} | |
471 | END | |
472 | ; | |
473 | if ( $wlanapsettings{'HW_MODE'} eq 'n' ){ | |
474 | print CONFIGFILE <<END | |
475 | hw_mode=g | |
476 | ieee80211n=1 | |
477 | END | |
478 | ; | |
479 | ||
480 | }else{ | |
481 | print CONFIGFILE <<END | |
482 | hw_mode=$wlanapsettings{'HW_MODE'} | |
483 | END | |
484 | ; | |
485 | ||
486 | } | |
487 | ||
488 | print CONFIGFILE <<END | |
489 | logger_syslog=-1 | |
490 | logger_syslog_level=$wlanapsettings{'SYSLOGLEVEL'} | |
491 | logger_stdout=-1 | |
492 | logger_stdout_level=$wlanapsettings{'DEBUG'} | |
493 | dump_file=/tmp/hostapd.dump | |
494 | auth_algs=1 | |
495 | ctrl_interface=/var/run/hostapd | |
496 | ctrl_interface_group=0 | |
497 | END | |
498 | ; | |
499 | if ( $wlanapsettings{'HIDESSID'} eq 'on' ){ | |
500 | print CONFIGFILE <<END | |
501 | ssid=$wlanapsettings{'SSID'} | |
502 | ignore_broadcast_ssid=2 | |
503 | END | |
504 | ; | |
505 | ||
506 | }else{ | |
507 | print CONFIGFILE <<END | |
508 | ssid=$wlanapsettings{'SSID'} | |
509 | ignore_broadcast_ssid=0 | |
510 | END | |
511 | ; | |
512 | ||
513 | } | |
514 | ||
515 | if ( $wlanapsettings{'ENC'} eq 'wpa1'){ | |
516 | print CONFIGFILE <<END | |
517 | ######################### wpa hostapd configuration ############################ | |
518 | # | |
519 | wpa=1 | |
520 | wpa_passphrase=$wlanapsettings{'PWD'} | |
521 | wpa_key_mgmt=WPA-PSK | |
522 | wpa_pairwise=CCMP TKIP | |
523 | END | |
524 | ; | |
525 | }elsif ( $wlanapsettings{'ENC'} eq 'wpa2'){ | |
526 | print CONFIGFILE <<END | |
527 | ######################### wpa hostapd configuration ############################ | |
528 | # | |
529 | wpa=2 | |
530 | wpa_passphrase=$wlanapsettings{'PWD'} | |
531 | wpa_key_mgmt=WPA-PSK | |
532 | wpa_pairwise=CCMP TKIP | |
533 | END | |
534 | ; | |
535 | } | |
536 | close CONFIGFILE; | |
537 | ||
538 | open (MACFILE, ">/var/ipfire/wlanap/macfile"); | |
539 | foreach(@macs){ | |
540 | $_ =~ s/\r//gi; | |
541 | chomp($_); | |
542 | if ( $_ ne "" ){print MACFILE $_;} | |
543 | } | |
544 | close MACFILE; | |
545 | } |