X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=html%2Fcgi-bin%2Fwlanap.cgi;h=eba5fe774e14e04b40461dd03d46b35bf566bbba;hb=HEAD;hp=ec9022ddfad8305013f9efd1200818726c33bbf2;hpb=6d3eb05e5c4c172153f60f924b2467dc7cc301f1;p=people%2Fpmueller%2Fipfire-2.x.git diff --git a/html/cgi-bin/wlanap.cgi b/html/cgi-bin/wlanap.cgi index ec9022ddfa..4de4c579c5 100644 --- a/html/cgi-bin/wlanap.cgi +++ b/html/cgi-bin/wlanap.cgi @@ -2,7 +2,7 @@ ############################################################################### # # # IPFire.org - A linux based firewall # -# Copyright (C) 2007-2014 IPFire Team # +# Copyright (C) 2007-2021 IPFire Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -18,224 +18,99 @@ # along with this program. If not, see . # # # ############################################################################### -# -# WLAN AP cgi based on wlanap.cgi written by Markus Hoffmann & Olaf Westrik -# use strict; # enable only the following on debugging purpose -#use warnings; -#use CGI::Carp 'fatalsToBrowser'; +use warnings; +use CGI::Carp 'fatalsToBrowser'; require '/var/ipfire/general-functions.pl'; require '/var/ipfire/lang.pl'; require '/var/ipfire/header.pl'; -my $debug = 0; -my $status = ''; my $errormessage = ''; -my $status_started = "$Lang::tr{'running'}"; -my $status_stopped = "$Lang::tr{'stopped'}"; -my $count=0; -my $col=''; -# get rid of used only once warnings -my @onlyonce = ( $Header::colourgreen, $Header::colourred ); -undef @onlyonce; - my %selected=(); my %checked=(); -my %color = (); -my %mainsettings = (); -my %netsettings=(); my %wlanapsettings=(); -my $channel = ''; -my $country = ''; -my $txpower = ''; - -&General::readhash("${General::swroot}/main/settings", \%mainsettings); -&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); -&General::readhash("/var/ipfire/ethernet/settings", \%netsettings); - -$wlanapsettings{'APMODE'} = 'on'; -$wlanapsettings{'ACTION'} = ''; -$wlanapsettings{'MACMODE'} = '0'; -$wlanapsettings{'INTERFACE'} = ''; -$wlanapsettings{'SSID'} = 'IPFire'; -$wlanapsettings{'HIDESSID'} = 'off'; -$wlanapsettings{'ENC'} = 'wpa2'; # none / wpa1 /wpa2 -$wlanapsettings{'TXPOWER'} = 'auto'; -$wlanapsettings{'CHANNEL'} = '6'; -$wlanapsettings{'COUNTRY'} = '00'; -$wlanapsettings{'HW_MODE'} = 'g'; -$wlanapsettings{'PWD'} = 'IPFire-2.x'; -$wlanapsettings{'SYSLOGLEVEL'} = '0'; -$wlanapsettings{'DEBUG'} = '4'; -$wlanapsettings{'DRIVER'} = 'MADWIFI'; -$wlanapsettings{'HTCAPS'} = ''; + +# Set defaults +&General::set_defaults(\%wlanapsettings, { + "APMODE" => "on", + "SSID" => "IPFire", + "HIDESSID" => "off", + "ENC" => "wpa2", + "TXPOWER" => "auto", + "CHANNEL" => "6", + "COUNTRY" => "00", + "HW_MODE" => "g", + "PWD" => "", + "HTCAPS" => "", + "VHTCAPS" => "", + "NOSCAN" => "off", + "CLIENTISOLATION" => "off", + "IEEE80211W" => "off", +}); &General::readhash("/var/ipfire/wlanap/settings", \%wlanapsettings); &Header::getcgihash(\%wlanapsettings); -my @macs = $wlanapsettings{'MACS'}; +# Find the selected interface +my $INTF = &Network::get_intf_by_address($wlanapsettings{'INTERFACE'}); delete $wlanapsettings{'__CGI__'}; delete $wlanapsettings{'x'}; delete $wlanapsettings{'y'}; -delete $wlanapsettings{'MACS'}; -delete $wlanapsettings{'ACCEPT_MACS'}; -delete $wlanapsettings{'DENY_MACS'}; &Header::showhttpheaders(); -my $string=(); -my $status=(); -my $errormessage = ''; -my $memory = 0; -my @memory=(); -my @pid=(); -my @hostapd=(); -sub pid -{ -# for pid and memory - open(FILE, '/usr/local/bin/addonctrl hostapd status | '); - @hostapd = ; - close(FILE); - $string = join("", @hostapd); - $string =~ s/[a-z_]//gi; - $string =~ s/\[[0-1]\;[0-9]+//gi; - $string =~ s/[\(\)\.]//gi; - $string =~ s/ //gi; - $string =~ s///gi; - @pid = split(/\s/,$string); - if (open(FILE, "/proc/$pid[0]/statm")){ - my $temp = ; - @memory = split(/ /,$temp); - close(FILE); - } - $memory+=$memory[0]; -} -pid(); - - - -if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap del interface'}" ){ - delete $wlanapsettings{'INTERFACE'}; - &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); -} - -if ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'save'}" ){ +if ($wlanapsettings{'ACTION'} eq "$Lang::tr{'save'}") { # verify WPA Passphrase - only with enabled enc - if (($wlanapsettings{'ENC'} eq "wpa1") || ($wlanapsettings{'ENC'} eq "wpa2") || ($wlanapsettings{'ENC'} eq "wpa1+2")){ + if ($wlanapsettings{'ENC'} ne "none") { # must be 8 .. 63 characters - if ( (length($wlanapsettings{'PWD'}) < 8) || (length($wlanapsettings{'PWD'}) > 63)){ + if ((length($wlanapsettings{'PWD'}) < 8) || (length($wlanapsettings{'PWD'}) > 63)) { $errormessage .= "$Lang::tr{'wlanap invalid wpa'}
"; } + # only ASCII alowed - if ( !($wlanapsettings{'PWD'} !~ /[^\x00-\x7f]/) ){ + if (!($wlanapsettings{'PWD'} !~ /[^\x00-\x7f]/)) { $errormessage .= "$Lang::tr{'wlanap invalid wpa'}
"; } } - if ( $errormessage eq '' ){ + if ($errormessage eq '') { &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); &WriteConfig_hostapd(); - system("/usr/local/bin/wlanapctrl restart >/dev/null 2>&1"); - pid(); + &General::system("/usr/local/bin/wlanapctrl", "restart"); } -}elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'wlanap interface'}" ){ - &General::writehash("/var/ipfire/wlanap/settings", \%wlanapsettings); -}elsif ( ($wlanapsettings{'ACTION'} eq "$Lang::tr{'start'}") && ($memory == 0) ){ - system("/usr/local/bin/wlanapctrl start >/dev/null 2>&1"); - pid(); -}elsif ( $wlanapsettings{'ACTION'} eq "$Lang::tr{'stop'}" ){ - system("/usr/local/bin/wlanapctrl stop >/dev/null 2>&1"); - $memory=0; -} -&Header::openpage('', 1, '', ''); -&Header::openbigbox('100%', 'left', '', $errormessage); +# Start +} elsif ($wlanapsettings{'ACTION'} eq "$Lang::tr{'start'}") { + &General::system("/usr/local/bin/wlanapctrl", "start"); -if ( $errormessage ){ - &Header::openbox('100%', 'center', $Lang::tr{'error messages'}); - print "$errormessage\n"; - print " \n"; - &Header::closebox(); +# Stop +} elsif ($wlanapsettings{'ACTION'} eq "$Lang::tr{'stop'}") { + &General::system("/usr/local/bin/wlanapctrl", "stop"); } +&Header::openpage($Lang::tr{'wlanap configuration'}, 1, '', ''); +&Header::openbigbox('100%', 'left', '', $errormessage); -# Found this usefull piece of code in BlockOutTraffic AddOn 8-) -# fwrules.cgi -############### -# DEBUG DEBUG -if ( $debug ){ - &Header::openbox('100%', 'center', 'DEBUG'); - my $debugCount = 0; - foreach my $line (sort keys %wlanapsettings) { - print "$line = '$wlanapsettings{$line}'
\n"; - $debugCount++; - } - print " Count: $debugCount\n"; - &Header::closebox(); -} -# DEBUG DEBUG -############### +# Show any errors +&Header::errorbox($errormessage); # # Driver and status detection # -my $wlan_card_status = 'dummy'; -my $wlan_ap_status = ''; my $message = ""; -$selected{'INTERFACE'}{'green0'} = ''; -$selected{'INTERFACE'}{'blue0'} = ''; -$selected{'ENC'}{$wlanapsettings{'INTERFACE'}} = "selected='selected'"; - -if ( ($wlanapsettings{'INTERFACE'} eq '') ){ - $message = $Lang::tr{'wlanap select interface'}; - &Header::openbox('100%', 'center', "WLAN AP"); -print < -
- -

-
-
-END -; - &Header::closebox(); - &Header::closebigbox(); - &Header::closepage(); - exit; -}else{ - my $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} 2>/dev/null`; - - if ( $cmd_out eq '' ){ - $message = "$Lang::tr{'wlanap no interface'}"; - $wlan_card_status = ''; - }else{ - $cmd_out = `/sbin/ifconfig | /bin/grep $wlanapsettings{'INTERFACE'}`; - if ( $cmd_out eq '' ){ - $wlan_card_status = 'down'; - }else{ - $wlan_card_status = 'up'; - $cmd_out = `/usr/sbin/iwconfig $wlanapsettings{'INTERFACE'} | /bin/grep "Mode:Master"`; - if ( $cmd_out ne '' ){ - $wlan_ap_status = 'up'; - } - } - } +my %INTERFACES = &Network::list_wireless_interfaces(); + +foreach my $intf (keys %INTERFACES) { + $selected{'INTERFACE'}{$intf} = ''; } +$selected{'INTERFACE'}{$wlanapsettings{'INTERFACE'}} = "selected='selected'"; # Change old "n" to "gn" if ( $wlanapsettings{'HW_MODE'} eq 'n' ) { @@ -246,342 +121,280 @@ $checked{'HIDESSID'}{'off'} = ''; $checked{'HIDESSID'}{'on'} = ''; $checked{'HIDESSID'}{$wlanapsettings{'HIDESSID'}} = "checked='checked'"; +$checked{'NOSCAN'}{'off'} = ''; +$checked{'NOSCAN'}{'on'} = ''; +$checked{'NOSCAN'}{$wlanapsettings{'NOSCAN'}} = "checked='checked'"; + +$checked{'CLIENTISOLATION'}{'off'} = ''; +$checked{'CLIENTISOLATION'}{'on'} = ''; +$checked{'CLIENTISOLATION'}{$wlanapsettings{'CLIENTISOLATION'}} = "checked='checked'"; + +$selected{'IEEE80211W'}{'off'} = ''; +$selected{'IEEE80211W'}{'optional'} = ''; +$selected{'IEEE80211W'}{'on'} = ''; +$selected{'IEEE80211W'}{$wlanapsettings{'IEEE80211W'}} = "selected"; + $selected{'ENC'}{$wlanapsettings{'ENC'}} = "selected='selected'"; $selected{'CHANNEL'}{$wlanapsettings{'CHANNEL'}} = "selected='selected'"; $selected{'COUNTRY'}{$wlanapsettings{'COUNTRY'}} = "selected='selected'"; $selected{'TXPOWER'}{$wlanapsettings{'TXPOWER'}} = "selected='selected'"; $selected{'HW_MODE'}{$wlanapsettings{'HW_MODE'}} = "selected='selected'"; -$selected{'MACMODE'}{$wlanapsettings{'MACMODE'}} = "selected='selected'"; -my $monwlaninterface = $wlanapsettings{'INTERFACE'}; -if ( -d '/sys/class/net/mon.'.$wlanapsettings{'INTERFACE'} ) { - $monwlaninterface = 'mon.'.$wlanapsettings{'INTERFACE'}; -} +# Fetch all available channels +my @channellist = &get_channellist($INTF); -my @channellist_cmd; -my @channellist; +# Fetch countries +my @countrylist = &get_countrylist(); -if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ -my $wiphy = `iw dev $wlanapsettings{'INTERFACE'} info | grep wiphy | cut -d" " -f2`; -chomp $wiphy; +# Show status +&Header::opensection(); -@channellist_cmd = `iw phy phy$wiphy info | grep " MHz \\\[" | grep -v "(disabled)" | grep -v "no IBSS" | grep -v "passive scanning" 2>/dev/null`; -# get available channels +&Header::ServiceStatus({ + "$Lang::tr{'wlanap'}" => { + "process" => "hostapd", + } +}); + +print < + + +
+ +
+ +
+ +
+ + + +EOF + +&Header::closesection(); -my @temp; -foreach (@channellist_cmd){ -$_ =~ /(.*) \[(\d+)(.*)\]/; -$channel = $2;chomp $channel; -if ( $channel =~ /\d+/ ){push(@temp,$channel + 0);} -} -@channellist = @temp; -} else { -@channellist_cmd = `iwlist $monwlaninterface channel|tail -n +2 2>/dev/null`; -# get available channels - -my @temp; -foreach (@channellist_cmd){ -$_ =~ /(.*)Channel (\d+)(.*):/; -$channel = $2;chomp $channel; -if ( $channel =~ /\d+/ ){push(@temp,$channel + 0);} -} -@channellist = @temp; -} +# +# Configuration +# +&Header::openbox("100%", "center", $Lang::tr{'wlanap configuration'}); -my @countrylist_cmd = `regdbdump /usr/lib/crda/regulatory.bin 2>/dev/null`; -# get available country codes +print < +
$Lang::tr{'wlanap configuration'}
-my @temp = "00"; -foreach (@countrylist_cmd){ -$_ =~ /country (.*):/; -$country = $1;chomp $country; -if ( $country =~ /[0,A-Z][0,A-Z]/ ) {push(@temp,$country);} -} -my @countrylist = @temp; + + + -my @txpower_cmd = `iwlist $monwlaninterface txpower 2>/dev/null`; -if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ - # There is a bug with NL80211 only all devices can displayed - @txpower_cmd = `iwlist txpower 2>/dev/null | sed -e "s|unknown transmit-power information.||g"`; -} -# get available power + + + + + + + + + + + + + + + + + + + + + "; - print ""; - print $wlan_card_status eq 'up' ? $status_started : $status_stopped; - print""; - print ""; - print $wlan_ap_status eq 'up' ? $status_started : $status_stopped; - if ( ($memory != 0) && (@pid[0] ne "///") ){ - print ""; - print ""; - print ""; - print ""; - }else{ - print""; - print ""; - print ""; - } - -}else{ - print "
$Lang::tr{'wlanap interface'} +
$Lang::tr{'wlanap ssid'} + +
$Lang::tr{'wlanap broadcast ssid'} + +
$Lang::tr{'wlanap client isolation'} + +
$Lang::tr{'wlanap country'} +
$Lang::tr{'service'}StatusPID$Lang::tr{'memory'}$Lang::tr{'action'}
$Lang::tr{'wlanap wlan card'} ($wlanapsettings{'DRIVER'})
$Lang::tr{'wlanap access point'}@pid[0]$memory KB
$message"; -} - print "
"; - -if ( $wlan_card_status eq '' ){ - print "
"; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print "
 
"; +foreach my $country (@countrylist){ + print " "; } -if ( $wlan_card_status eq '' ){ - &Header::closebox(); - &Header::closebigbox(); - &Header::closepage(); - exit 0; -} -print <
-
- - - - - - - - - + + + + + + + + + + - -END -; -if ( scalar @channellist > 0 ){ - print <" -} else { - print < -END -; + print ""; } -print< - - - -END -; -print < -"; -} else { - print "" -} -print < - - -
$Lang::tr{'wlanap wlan settings'}

SSID: 
SSID Broadcast: on | off
$Lang::tr{'wlanap country'}:  -
$Lang::tr{'wlanap wireless mode'} + +
$Lang::tr{'wlanap channel'} +
HW Mode:  - -
$Lang::tr{'wlanap channel'}:  -
$Lang::tr{'wlanap channel'}:  - -

$Lang::tr{'wlanap encryption'}:  - -
Passphrase: 

HT Caps: 
Tx Power:  -END -; -if ( $wlanapsettings{'DRIVER'} eq 'MADWIFI' ){ - print "
Loglevel (hostapd):  - -Debuglevel (hostapd):  - -

-END -; -if ( $wlanapsettings{'INTERFACE'} =~ /green0/ ){ - print < - - - - - -
$Lang::tr{'mac filter'}
Mac Filter:  - -Mac Adress List (one per line)
+print < + + + + + $Lang::tr{'wlanap neighbor scan'} + + + + $Lang::tr{'wlanap neighbor scan warning'} + + + + + $Lang::tr{'wlanap encryption'} + + + + + + + $Lang::tr{'wlanap psk'} + + + + + + + $Lang::tr{'wlanap management frame protection'} + + + + + + + HT Caps + + + + + + + VHT Caps + + + + + + + Tx Power + + + + + + + + + + + + END ; -} -print < - - - -
-
- -
+ +&Header::closebox(); + +&Header::opensection(); + +my @status = `iw dev $INTF info`; + +if (@status) { + print <$Lang::tr{'wlanap wlan status'} + +
@status
END -; -my @status; -if ( $wlanapsettings{'DRIVER'} eq 'MADWIFI' ){ - @status = `wlanconfig $wlanapsettings{'INTERFACE'} list`; -} -if ( $wlanapsettings{'DRIVER'} eq 'NL80211' ){ - @status = `iw dev $wlanapsettings{'INTERFACE'} info && iw dev $wlanapsettings{'INTERFACE'} station dump && echo ""`; } -print < - - -END -; -for (my $i=0;$i<$#status;$i++){ +my @status = `iw dev $INTF station dump`; -if (@status[$i]=~"^Station ") { $count++; } -if ($count % 2){ - $col="bgcolor='$color{'color20'}'"; - }else{ - $col="bgcolor='$color{'color22'}'"; - } - print""; - if (! @status[$i]=~"^/t" ) { $count++; } -} - $count++; +if (@status) { + print <$Lang::tr{'wlanap clients'} -foreach my $nr (@channellist_cmd){ - if ($count % 2){ - $col="bgcolor='$color{'color20'}'"; - }else{ - $col="bgcolor='$color{'color22'}'"; - } - print""; - $count++; +
@status
+END } -for (my $i=0;$i<$#txpower_cmd;$i=$i+2){ - if ($count % 2){ - $col="bgcolor='$color{'color20'}'"; - }else{ - $col="bgcolor='$color{'color22'}'"; - } - print ""; - $count++; -} -print "
$Lang::tr{'wlanap wlan status'}
@status[$i]
$nr
@txpower_cmd[$i]

"; -print < - - - - - -
$Lang::tr{'wlan clients'}
 $Lang::tr{'wlanap link wireless'}
 $Lang::tr{'wlanap link dhcp'}

-END -; -&Header::closebox(); -print ""; +&Header::closesection(); &Header::closebigbox(); &Header::closepage(); sub WriteConfig_hostapd{ - $wlanapsettings{'DRIVER_HOSTAPD'} = lc($wlanapsettings{'DRIVER'}); - open (CONFIGFILE, ">/var/ipfire/wlanap/hostapd.conf"); print CONFIGFILE <) { + chomp $_; + + $phy = $_; + last; + } + + close($file); - open (MACFILE, ">/var/ipfire/wlanap/macfile"); - foreach(@macs){ - $_ =~ s/\r//gi; - chomp($_); - if ( $_ ne "" ){print MACFILE $_;} + return $phy; +} + +sub get_channellist($) { + my $intf = shift; + + # Fetch the PHY ID + my $phy = &get_phy($intf); + + my @channels = (0); + + open(my $command, "iw phy phy$phy info |"); + + while (<$command>) { + # Skip everything we are not interested in + next unless ($_ =~ m/MHz \[(\d+)\]/); + + my $channel = $1; + + # Skip disabled and otherwise unusable channels + next if ($_ =~ m/disabled/); + next if ($_ =~ m/no IBSS/); + next if ($_ =~ m/no IR/); + next if ($_ =~ m/passive scanning/); + + push(@channels, $channel); } - close MACFILE; + + close($command); + + return @channels; +} + +sub get_countrylist() { + open(my $file, ") { + if ($_ =~ m/^country ([A-Z0-9]{2}):/) { + push(@countries, $1); + } + } + + close($file); + + return @countries; }