]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/wlanap.cgi
aca9e358ecbfd8ea6315f48291fe41f8eab00116
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
22 # WLAN AP cgi based on wlanap.cgi written by Markus Hoffmann & Olaf Westrik
27 # enable only the following on debugging purpose
29 #use CGI::Carp 'fatalsToBrowser';
31 require '/var/ipfire/general-functions.pl';
32 require '/var/ipfire/lang.pl';
33 require '/var/ipfire/header.pl';
37 my $errormessage = '';
38 my $status_started = "<td align='center' width='75%' bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td></tr>";
39 my $status_stopped = "<td align='center' width='75%' bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td></tr>";
41 # get rid of used only once warnings
42 my @onlyonce = ( $Header::colourgreen
, $Header::colourred
);
48 my %mainsettings = ();
50 my %wlanapsettings=();
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);
58 $wlanapsettings{'APMODE'} = 'on';
59 $wlanapsettings{'INTERFACE'} = $netsettings{'BLUE_DEV'};
60 $wlanapsettings{'SSID'} = 'IPFire';
61 $wlanapsettings{'HIDESSID'} = 'off';
62 $wlanapsettings{'ENC'} = 'wpa'; # none / wpa1 /wpa2
63 $wlanapsettings{'TXPOWER'} = 'auto';
64 $wlanapsettings{'CHAN'} = '05';
65 $wlanapsettings{'PWD'} = 'IPFire-2.x';
66 $wlanapsettings{'SYSLOGLEVEL'} = '0';
67 $wlanapsettings{'DEBUG'} = '4';
68 $wlanapsettings{'DRIVER'} = 'MADWIFI';
70 &General
::readhash
("/var/ipfire/wlanap/settings", \
%wlanapsettings);
73 $cgiparams{'ACTION'} = '';
74 $cgiparams{'APMODE'} = 'on';
75 $cgiparams{'SSID'} = 'IPFire';
76 $cgiparams{'HIDESSID'} = 'off';
77 $cgiparams{'ENC'} = 'wpa'; # none / wep / wpa / wep+wpa
78 $cgiparams{'TXPOWER'} = 'auto';
79 $cgiparams{'CHAN'} = '05';
80 $cgiparams{'PWD'} = 'IPFire-2.x';
81 $cgiparams{'SYSLOGLEVEL'} = '0';
82 $cgiparams{'DEBUG'} = '4';
83 &Header
::getcgihash
(\
%cgiparams);
86 &Header
::showhttpheaders
();
88 if ( $cgiparams{'ACTION'} eq "$Lang::tr{'save'}" ){
89 $wlanapsettings{'SSID'} = $cgiparams{'SSID'};
90 $wlanapsettings{'HIDESSID'} = $cgiparams{'HIDESSID'};
91 $wlanapsettings{'ENC'} = $cgiparams{'ENC'};
92 $wlanapsettings{'CHAN'} = $cgiparams{'CHAN'};
93 $wlanapsettings{'TXPOWER'} = $cgiparams{'TXPOWER'};
95 $wlanapsettings{'PWD'} = $cgiparams{'PWD'};
96 $wlanapsettings{'SYSLOGLEVEL'}= $cgiparams{'SYSLOGLEVEL'};
97 $wlanapsettings{'DEBUG'} = $cgiparams{'DEBUG'};
99 # verify WPA Passphrase, must be 8 .. 63 characters
100 if ( (length($wlanapsettings{'PWD'}) < 8) || (length($wlanapsettings{'PWD'}) > 63) ){
101 $errormessage .= "Invalid length in WPA Passphrase. Must be between 8 and 63 characters.<br />";
104 if ( $errormessage eq '' ){
106 &WriteConfig_hostapd
();
108 system("/usr/local/bin/wlanapctrl restart >/dev/null 2>&1")
110 }elsif ( $cgiparams{'ACTION'} eq 'Start' ){
111 system("/usr/local/bin/wlanapctrl start >/dev/null 2>&1");
112 }elsif ( $cgiparams{'ACTION'} eq 'Stop' ){
113 system("/usr/local/bin/wlanapctrl stop >/dev/null 2>&1");
116 &Header
::openpage
('WLAN', 1, '', '');
117 &Header
::openbigbox
('100%', 'left', '', $errormessage);
118 print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>";
120 if ( $errormessage ){
121 &Header
::openbox
('100%', 'center', $Lang::tr
{'error messages'});
122 print "<class name='base'>$errormessage\n";
123 print " </class>\n";
128 # Found this usefull piece of code in BlockOutTraffic AddOn 8-)
133 &Header
::openbox
('100%', 'center', 'DEBUG');
135 foreach my $line (sort keys %cgiparams) {
136 print "$line = '$cgiparams{$line}'<br />\n";
139 print " Count: $debugCount\n";
146 # Driver and status detection
148 my $wlan_card_status = 'dummy';
149 my $wlan_ap_status = '';
150 my $blue_message = "";
152 if ( ($netsettings{'BLUE_DEV'} eq '') || ($netsettings{'BLUE_DRIVER'} eq '') ){
153 $blue_message = "No BLUE Interface.";
155 my $cmd_out = `/usr/sbin/iwconfig $netsettings{'BLUE_DEV'} 2>/dev/null`;
157 if ( $cmd_out eq '' ){
158 $blue_message = "BLUE Interface is not a WLAN card.";
160 $cmd_out = `/sbin/ifconfig | /bin/grep $netsettings{'BLUE_DEV'}`;
161 if ( $cmd_out eq '' ){
162 $wlan_card_status = 'down';
164 $wlan_card_status = 'up';
165 $cmd_out = `/usr/sbin/iwconfig $netsettings{'BLUE_DEV'} | /bin/grep "Mode:Master"`;
166 if ( $cmd_out ne '' ){
167 $wlan_ap_status = 'up';
173 my $checked_hidessid = '';
174 $checked_hidessid = "checked='checked'" if ( $wlanapsettings{'HIDESSID'} eq 'on' );
176 $selected{'ENC'}{'none'} = '';
177 $selected{'ENC'}{'wpa1'} = '';
178 $selected{'ENC'}{'wpa2'} = '';
179 $selected{'ENC'}{$wlanapsettings{'ENC'}} = "selected='selected'";
180 $selected{'CHAN'}{$wlanapsettings{'CHAN'}} = "selected='selected'";
181 $selected{'TXPOWER'}{$wlanapsettings{'TXPOWER'}} = "selected='selected'";
183 my @channellist_cmd = `iwlist $netsettings{'BLUE_DEV'} channel`;
184 # get available channels
187 foreach (@channellist_cmd){
188 $_ =~ /(.*)Channel (\d+)(.*):/;
189 $channel = $2;chomp $channel;
190 if ( $channel =~ /\d+/ ){push(@temp,$channel);}
192 my @channellist = @temp;
194 my @txpower_cmd = `iwlist $netsettings{'BLUE_DEV'} txpower`;
195 # get available channels
198 foreach (@txpower_cmd){
199 $_ =~ /(\s)(\d+)(\s)dBm(\s)(.*)(\W)(\d+)(.*)/;
200 $txpower = $7;chomp $txpower;
201 if ( $txpower =~ /\d+/ ){push(@temp,$txpower."mW");}
204 push(@txpower,"auto");
206 $selected{'SYSLOGLEVEL'}{'0'} = '';
207 $selected{'SYSLOGLEVEL'}{'1'} = '';
208 $selected{'SYSLOGLEVEL'}{'2'} = '';
209 $selected{'SYSLOGLEVEL'}{'3'} = '';
210 $selected{'SYSLOGLEVEL'}{'4'} = '';
211 $selected{'SYSLOGLEVEL'}{$wlanapsettings{'SYSLOGLEVEL'}} = "selected='selected'";
213 $selected{'DEBUG'}{'0'} = '';
214 $selected{'DEBUG'}{'1'} = '';
215 $selected{'DEBUG'}{'2'} = '';
216 $selected{'DEBUG'}{'3'} = '';
217 $selected{'DEBUG'}{'4'} = '';
218 $selected{'DEBUG'}{$wlanapsettings{'DEBUG'}} = "selected='selected'";
223 &Header
::openbox
('100%', 'center', "WLAN AP");
225 <table width='95%' cellspacing='0'>
226 <tr><td bgcolor='$color{'color20'}' colspan='2' align='left'><b>WLAN Services</b></td></tr>
229 if ( $wlan_card_status ne '' ){
230 print "<tr><td class='base'>WLAN card ($wlanapsettings{'DRIVER'})</td>";
231 print $wlan_card_status eq 'up' ?
$status_started : $status_stopped;
232 print "<tr><td class='base'>Access Point</td>";
233 print $wlan_ap_status eq 'up' ?
$status_started : $status_stopped;
234 if ( $wlan_card_status eq 'up' ){
235 print "<tr><td colspan='2' align='center'><input type='submit' name='ACTION' value='Stop' /><input type='hidden' name='RUNNING' value='on' /></td></tr>";
237 print "<tr><td colspan='2' align='center'><input type='submit' name='ACTION' value='Start' /></td></tr>";
240 print "<tr><td colspan='2' class='base'><b>$blue_message</b></td></tr>";
244 if ( $wlan_card_status eq '' ){
246 &Header
::closebigbox
();
247 &Header
::closepage
();
252 <table width='95%' cellspacing='0'>
253 <tr><td bgcolor='$color{'color20'}' colspan='4' align='left'><b>WLAN Settings</b>
254 <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>
255 <tr><td width='25%' class='base'>Disable SSID broadcast: </td><td class='base' colspan='3'><input type='checkbox' name='HIDESSID' $checked_hidessid /></td></tr>
256 <tr><td width='25%' class='base'>Encryption: </td><td class='base' colspan='3'>
258 <option value='none' $selected{'ENC'}{'none'}>none</option>
259 <option value='wpa1' $selected{'ENC'}{'wpa1'}>wpa1</option>
260 <option value='wpa2' $selected{'ENC'}{'wpa2'}>wpa2</option>
263 <tr><td width='25%' class='base'>Channel: </td><td class='base' colspan='3'>
267 foreach $channel (@channellist){
268 print "<option $selected{'CHAN'}{$channel}>$channel</option>";
273 <tr><td width='25%' class='base'>Tx Power: </td><td class='base' colspan='3'><select name='TXPOWER'>
276 foreach $txpower (@txpower){
277 print "<option $selected{'TXPOWER'}{$txpower}>$txpower</option> dBm";
281 <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>
282 <tr><td width='25%' class='base'>Loglevel (hostapd): </td><td class='base' width='25%'>
283 <select name='SYSLOGLEVEL'>
284 <option value='0' $selected{'SYSLOGLEVEL'}{'0'}>0 (verbose)</option>
285 <option value='1' $selected{'SYSLOGLEVEL'}{'1'}>1 (debugging)</option>
286 <option value='2' $selected{'SYSLOGLEVEL'}{'2'}>2 (informations)</option>
287 <option value='3' $selected{'SYSLOGLEVEL'}{'3'}>3 (notifications)</option>
288 <option value='4' $selected{'SYSLOGLEVEL'}{'4'}>4 (warnings)</option>
291 <td width='25%' class='base'>Debuglevel (hostapd): </td><td class='base' width='25%'>
292 <select name='DEBUG'>
293 <option value='0' $selected{'DEBUG'}{'0'}>0 (verbose)</option>
294 <option value='1' $selected{'DEBUG'}{'1'}>1 (debugging)</option>
295 <option value='2' $selected{'DEBUG'}{'2'}>2 (informations)</option>
296 <option value='3' $selected{'DEBUG'}{'3'}>3 (notifications)</option>
297 <option value='4' $selected{'DEBUG'}{'4'}>4 (warnings)</option>
302 <table width='10%' cellspacing='0'>
303 <tr><td align='center'><form method='post' action='$ENV{'SCRIPT_NAME'}'>
304 <input type='hidden' name='ACTION' value=$Lang::tr{'save'} />
305 <input type='image' alt='$Lang::tr{'save'}' title='$Lang::tr{'save'}' src='/images/media-floppy.png' /></form></td>
311 if ( $wlanapsettings{'DRIVER'} eq 'MADWIFI' ){
312 $status = `cat /proc/net/madwifi/$netsettings{'BLUE_DEV'}/associated_sta`;
316 <table width='95%' cellspacing='0'>
317 <tr><td bgcolor='$color{'color20'}' colspan='2' align='left'><b>WLAN Status</b></td></tr>
318 <tr><td><pre>@channellist_cmd</pre></td><td><pre>@txpower_cmd</pre></td></tr>
319 <tr><td colspan='2'><pre>Connected Stations<br />$status</pre></td></tr>
325 &Header
::closebigbox
();
326 &Header
::closepage
();
329 &General
::writehash
("/var/ipfire/wlanap/settings", \
%wlanapsettings);
332 sub WriteConfig_hostapd
{
333 $wlanapsettings{'DRIVER_HOSTAPD'} = lc($wlanapsettings{'DRIVER'});
335 open (CONFIGFILE
, ">/var/ipfire/wlanap/hostapd.conf");
336 print CONFIGFILE
<<END
337 ######################### basic hostapd configuration ##########################
339 interface=$netsettings{'BLUE_DEV'}
340 driver=$wlanapsettings{'DRIVER_HOSTAPD'}
342 logger_syslog_level=$wlanapsettings{'SYSLOGLEVEL'}
344 logger_stdout_level=$wlanapsettings{'DEBUG'}
345 dump_file=/tmp/hostapd.dump
346 ignore_broadcast_ssid=0
347 eapol_key_index_workaround=0
349 own_ip_addr=127.0.0.1
351 ctrl_interface=/var/run/hostapd
352 ctrl_interface_group=0
356 if ( $wlanapsettings{'HIDESSID'} eq 'on' ){
357 print CONFIGFILE
<<END
358 ssid=$wlanapsettings{'SSID'}
359 ignore_broadcast_ssid=2
364 print CONFIGFILE
<<END
365 ssid=$wlanapsettings{'SSID'}
366 ignore_broadcast_ssid=0
372 if ( $wlanapsettings{'ENC'} eq 'wpa1'){
373 print CONFIGFILE
<<END
374 ######################### wpa hostapd configuration ############################
377 wpa_passphrase=$wlanapsettings{'PWD'}
378 wpa_key_mgmt=WPA-PSK WPA-EAP
379 wpa_pairwise=CCMP TKIP
382 }elsif ( $wlanapsettings{'ENC'} eq 'wpa2'){
383 print CONFIGFILE
<<END
384 ######################### wpa hostapd configuration ############################
387 wpa_passphrase=$wlanapsettings{'PWD'}
388 wpa_key_mgmt=WPA-PSK WPA-EAP
389 wpa_pairwise=CCMP TKIP