From e24ddaf60e543e311ef9bb3107d6208c5a92aaea Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Thu, 24 Feb 2005 16:45:25 +0000 Subject: move wlan-ng stuff in network::network --- perl-install/network/netconnect.pm | 41 +---------------------------------- perl-install/network/network.pm | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/perl-install/network/netconnect.pm b/perl-install/network/netconnect.pm index 1f4558b48..479bc4f5c 100644 --- a/perl-install/network/netconnect.pm +++ b/perl-install/network/netconnect.pm @@ -1196,46 +1196,7 @@ See iwpriv(8) man page for further information."), post => sub { # untranslate parameters $ethntf->{WIRELESS_MODE} = $wireless_mode{$ethntf->{WIRELESS_MODE}}; - if ($module =~ /^prism2_/) { - $in->do_pkgs->install('prism2-utils'); - if ($ethntf->{WIRELESS_ESSID}) { - my $update_vars_in_wlan = sub { #- FIXME: to be improved (quotes, comments) and moved in common files - my ($file, $vars) = @_; - substInFile { - while (my ($key, $value) = each(%$vars)) { - s/^#?\Q$key\E=(?:"[^#]*"|[^#\s]*)(\s*#.*)?/$key=$value$1/ and delete $vars->{$key}; - } - $_ .= join('', map { "$_=$vars->{$_}\n" } keys %$vars) if eof; - } $file; - }; - my $wlan_conf_file = "$::prefix/etc/wlan/wlan.conf"; - my @wlan_devices = split(/ /, (cat_($wlan_conf_file) =~ /^WLAN_DEVICES="(.*)"/m)[0]); - push @wlan_devices, $ethntf->{DEVICE} unless member($ethntf->{DEVICE}, @wlan_devices); - #- enable device and make it use the choosen ESSID - $update_vars_in_wlan->($wlan_conf_file, - { - WLAN_DEVICES => qq("@wlan_devices"), - "SSID_$ethntf->{DEVICE}" => qq("$ethntf->{WIRELESS_ESSID}"), - "ENABLE_$ethntf->{DEVICE}" => "y" - }); - my $wlan_ssid_file = "$::prefix/etc/wlan/wlancfg-$ethntf->{WIRELESS_ESSID}"; - #- copy default settings for this ESSID if config file does not exist - -f $wlan_ssid_file or cp_f("$::prefix/etc/wlan/wlancfg-DEFAULT", $wlan_ssid_file); - #- enable/disable encryption - $update_vars_in_wlan->($wlan_ssid_file, - { - (map { $_ => $ethntf->{WIRELESS_ENC_KEY} ? "true" : "false" } qw(lnxreq_hostWEPEncrypt lnxreq_hostWEPDecrypt dot11PrivacyInvoked dot11ExcludeUnencrypted)), - AuthType => $ethntf->{WIRELESS_ENC_KEY} ? qq("sharedkey") : qq("opensystem"), - if_($ethntf->{WIRELESS_ENC_KEY}, - dot11WEPDefaultKeyID => 0, - dot11WEPDefaultKey0 => qq("$ethntf->{WIRELESS_ENC_KEY}") - ) - }); - #- apply settings on wlan interface - require services; - services::restart($module eq 'prism2_cs' ? 'pcmcia' : 'wlan'); - } - } + $module =~ /^prism2_/ and network::network::wlan_ng_configure($in, $ethntf, $module); return "static_hostname"; }, }, diff --git a/perl-install/network/network.pm b/perl-install/network/network.pm index 1f1e78a84..c2cf30dd5 100644 --- a/perl-install/network/network.pm +++ b/perl-install/network/network.pm @@ -477,6 +477,50 @@ sub easy_dhcp { 1; } +#- FIXME: to be improved (quotes, comments) and moved in common files +sub wlan_ng_update_vars { + my ($file, $vars) = @_; + substInFile { + while (my ($key, $value) = each(%$vars)) { + s/^#?\Q$key\E=(?:"[^#]*"|[^#\s]*)(\s*#.*)?/$key=$value$1/ and delete $vars->{$key}; + } + $_ .= join('', map { "$_=$vars->{$_}\n" } keys %$vars) if eof; + } $file; +} + +sub wlan_ng_configure { + my ($in, $ethntf, $module) = @_; + $in->do_pkgs->install('prism2-utils'); + if ($ethntf->{WIRELESS_ESSID}) { + my $wlan_conf_file = "$::prefix/etc/wlan/wlan.conf"; + my @wlan_devices = split(/ /, (cat_($wlan_conf_file) =~ /^WLAN_DEVICES="(.*)"/m)[0]); + push @wlan_devices, $ethntf->{DEVICE} unless member($ethntf->{DEVICE}, @wlan_devices); + #- enable device and make it use the choosen ESSID + wlan_ng_update_vars($wlan_conf_file, + { + WLAN_DEVICES => qq("@wlan_devices"), + "SSID_$ethntf->{DEVICE}" => qq("$ethntf->{WIRELESS_ESSID}"), + "ENABLE_$ethntf->{DEVICE}" => "y" + }); + my $wlan_ssid_file = "$::prefix/etc/wlan/wlancfg-$ethntf->{WIRELESS_ESSID}"; + #- copy default settings for this ESSID if config file does not exist + -f $wlan_ssid_file or cp_f("$::prefix/etc/wlan/wlancfg-DEFAULT", $wlan_ssid_file); + #- enable/disable encryption + wlan_ng_update_vars($wlan_ssid_file, + { + (map { $_ => $ethntf->{WIRELESS_ENC_KEY} ? "true" : "false" } qw(lnxreq_hostWEPEncrypt lnxreq_hostWEPDecrypt dot11PrivacyInvoked dot11ExcludeUnencrypted)), + AuthType => $ethntf->{WIRELESS_ENC_KEY} ? qq("sharedkey") : qq("opensystem"), + if_($ethntf->{WIRELESS_ENC_KEY}, + dot11WEPDefaultKeyID => 0, + dot11WEPDefaultKey0 => qq("$ethntf->{WIRELESS_ENC_KEY}") + ) + }); + #- apply settings on wlan interface + require services; + services::restart($module eq 'prism2_cs' ? 'pcmcia' : 'wlan'); + } +} + sub wpa_supplicant_add_network { my ($new_network) = @_; my $wpa_supplicant_conf = "$::prefix/etc/wpa_supplicant.conf"; -- cgit v1.2.1