From 838b9f0b8668a4c81c39c9ea9f777952f1b46a0a Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Sun, 29 Dec 2002 11:50:19 +0000 Subject: - move any::pppConfig() to network::modem::ppp_configure() - move any::miscellaneousNetwork() to network::network::proxy_configure() (and uses the parameter instead of $::o->{miscellaneous}) - move network::network::miscellaneousNetwork() to network::network::miscellaneous_choose() (and do not export it) (and uses a parameter instead of $::o->{miscellaneous}) - move network::modem::pppConfig() to network::modem::ppp_choose() (and change parameter order, and drop unused parameter $intf) - do not export network::network::write_interface_conf() (since it is only used locally (?)) - cleanup network::network::write_interface_conf() (one still needs to pass $::o->{miscellaneous}{track_network_id} more cleanly, and use run_program::rooted when calling /sbin/ip) --- perl-install/network/ethernet.pm | 2 +- perl-install/network/isdn.pm | 2 +- perl-install/network/modem.pm | 177 +++++++++++++++++++++++++++++++++++++-- perl-install/network/network.pm | 36 +++++--- 4 files changed, 194 insertions(+), 23 deletions(-) (limited to 'perl-install/network') diff --git a/perl-install/network/ethernet.pm b/perl-install/network/ethernet.pm index 410b81e13..f9d97e00c 100644 --- a/perl-install/network/ethernet.pm +++ b/perl-install/network/ethernet.pm @@ -207,7 +207,7 @@ such as ``mybox.mylab.myco.com''."), } else { configureNetworkNet($in, $netc, $last ||= {}, @l) or goto configureNetwork_step_1; } - miscellaneousNetwork($in) or goto configureNetwork_step_1; + network::network::miscellaneous_choose($in, $::o->{miscellaneous} ||= {}) or goto configureNetwork_step_1; 1; } diff --git a/perl-install/network/isdn.pm b/perl-install/network/isdn.pm index 2b747e255..8f7319bf9 100644 --- a/perl-install/network/isdn.pm +++ b/perl-install/network/isdn.pm @@ -48,7 +48,7 @@ We recommand the light configuration. $netcnx->{isdn_external}{is_light} = $netc->{autodetect}{isdn}{is_light}; $netcnx->{isdn_external}{special_command} = 'AT&F&O2B40'; require network::modem; - network::modem::pppConfig($netcnx->{isdn_external}, undef, $netc) or goto isdn_step_1; + network::modem::ppp_choose($netc, $netcnx->{isdn_external}) or goto isdn_step_1; } 1; } diff --git a/perl-install/network/modem.pm b/perl-install/network/modem.pm index fd2f54c50..4a339565e 100644 --- a/perl-install/network/modem.pm +++ b/perl-install/network/modem.pm @@ -6,13 +6,9 @@ use modules; use detect_devices; use mouse; use network::tools; -use vars qw(@ISA @EXPORT); use MDK::Common::Globals "network", qw($in $prefix); use Data::Dumper; -@ISA = qw(Exporter); -@EXPORT = qw(pppConfig); - sub configure { my ($netcnx, $mouse, $netc, $intf) = @_; $netcnx->{type} = 'modem'; @@ -37,7 +33,7 @@ sub configure { last; } } - pppConfig($modem, $mouse, $netc, $intf) or return; + ppp_choose($netc, $modem, $mouse) or return; write_cnx_script($netc, "modem", q( /sbin/route del default @@ -49,8 +45,173 @@ killall pppd 1; } -sub pppConfig { - my ($modem, $mouse, $netc, $_intf) = @_; +#-----modem conf +sub ppp_configure { + my ($in, $modem, $prefix) = @_; + $modem or return; + + any::devfssymlinkf($modem, 'modem') if $modem->{device} ne "/dev/modem"; + $in->do_pkgs->install('ppp') if !$::testing; + + my %toreplace; + $toreplace{$_} = $modem->{$_} foreach qw(connection phone login passwd auth domain dns1 dns2); + $toreplace{kpppauth} = ${{ 'Script-based' => 0, 'PAP' => 1, 'Terminal-based' => 2, }}{$modem->{auth}}; + $toreplace{kpppauth} = ${{ 'Script-based' => 0, 'PAP' => 1, 'Terminal-based' => 2, 'CHAP' => 3 }}{$modem->{auth}}; + $toreplace{phone} =~ s/[a-zA-Z]//g; + $toreplace{dnsserver} = join ',', map { $modem->{$_} } "dns1", "dns2"; + $toreplace{dnsserver} .= $toreplace{dnsserver} && ','; + + #- using peerdns or dns1,dns2 avoid writing a /etc/resolv.conf file. + $toreplace{peerdns} = "yes"; + + $toreplace{connection} ||= 'DialupConnection'; + $toreplace{domain} ||= 'localdomain'; + $toreplace{intf} ||= 'ppp0'; + $toreplace{papname} = ($modem->{auth} eq 'PAP' || $modem->{auth} eq 'CHAP') && $toreplace{login}; + + #- build ifcfg-ppp0. + my $various = <{special_command}) { + push @chat, <{special_command}' +END + } + push @chat, <{auth} eq 'Terminal-based' || $modem->{auth} eq 'Script-based') { + push @chat, <{auth} eq 'PAP' || $modem->{auth} eq 'CHAP') { + #- need to create a secrets file for the connection. + my $secrets = "$prefix/etc/ppp/" . lc($modem->{auth}) . "-secrets"; + my @l = cat_($secrets); + my $replaced = 0; + do { $replaced ||= 1 + if s/^\s*"?$toreplace{login}"?\s+ppp0\s+(\S+)/"$toreplace{login}" ppp0 "$toreplace{passwd}"/ } foreach @l; + if ($replaced) { + output($secrets, @l); + } else { + append_to_file($secrets, "$toreplace{login} ppp0 \"$toreplace{passwd}\"\n"); + } + #- restore access right to secrets file, just in case. + chmod 0600, $secrets; + } + + #- install kppprc file according to used configuration. + mkdir_p("$prefix/usr/share/config"); + + output("$prefix/usr/share/config/kppprc", c::to_utf8(<{miscellaneous}); +} + +sub ppp_choose { + my ($netc, $modem, $mouse) = @_; $mouse ||= {}; $mouse->{device} ||= readlink "$prefix/dev/mouse"; @@ -76,7 +237,7 @@ sub pppConfig { { label => N("Second DNS Server (optional)"), val => \$modem->{dns2} }, ]) or return; $netc->{DOMAINNAME2} = $modem->{domain}; - any::pppConfig($in, $modem, $prefix); + ppp_configure($in, $modem, $prefix); $netc->{$_} = 'ppp0' foreach 'NET_DEVICE', 'NET_INTERFACE'; 1; } diff --git a/perl-install/network/network.pm b/perl-install/network/network.pm index 12085f636..888630b3d 100644 --- a/perl-install/network/network.pm +++ b/perl-install/network/network.pm @@ -13,7 +13,7 @@ use log; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); -@EXPORT = qw(resolv configureNetworkIntf netmask dns is_ip masked_ip findIntf addDefaultRoute write_interface_conf read_all_conf dnsServers guessHostname configureNetworkNet read_resolv_conf read_interface_conf add2hosts gateway configureNetwork2 write_conf sethostname miscellaneousNetwork down_it read_conf write_resolv_conf up_it); +@EXPORT = qw(resolv configureNetworkIntf netmask dns is_ip masked_ip findIntf addDefaultRoute read_all_conf dnsServers guessHostname configureNetworkNet read_resolv_conf read_interface_conf add2hosts gateway configureNetwork2 write_conf sethostname down_it read_conf write_resolv_conf up_it); #-###################################################################################### #- Functions @@ -121,17 +121,20 @@ sub write_resolv_conf { sub write_interface_conf { my ($file, $intf, $prefix) = @_; + if ($::o->{miscellaneous}{track_network_id} && -e "$prefix/sbin/ip") { + $intf->{HWADDR} = undef; + if (my $s = `LC_ALL= LANG= $prefix/sbin/ip -o link show $intf->{DEVICE} 2>/dev/null`) { + if ($s =~ m|.*link/ether\s([0-9a-z:]+)\s|) { + $intf->{HWADDR} = $1; + } + } + } my @ip = split '\.', $intf->{IPADDR}; my @mask = split '\.', $intf->{NETMASK}; - my $hwaddr; - $::o->{miscellaneous}{track_network_id} and $hwaddr = -e "$prefix/sbin/ip" && `LC_ALL= LANG= $prefix/sbin/ip -o link show $intf->{DEVICE} 2>/dev/null`; - if ($hwaddr) { chomp $hwaddr; $hwaddr =~ s/.*link\/ether\s([0-9a-z:]+)\s.*/$1/ } - $hwaddr and $intf->{HWADDR} = undef; add2hash($intf, { BROADCAST => join('.', mapn { int($_[0]) | ((~int($_[1])) & 255) } \@ip, \@mask), NETWORK => join('.', mapn { int($_[0]) & $_[1] } \@ip, \@mask), ONBOOT => bool2yesno(!member($intf->{DEVICE}, map { $_->{device} } detect_devices::probeall())), - if_($::o->{miscellaneous}{track_network_id}, HWADDR => $hwaddr) }); setVarsInSh($file, $intf, qw(DEVICE BOOTPROTO IPADDR NETMASK NETWORK BROADCAST ONBOOT HWADDR), if_($intf->{wireless_eth}, qw(WIRELESS_MODE WIRELESS_ESSID WIRELESS_NWID WIRELESS_FREQ WIRELESS_SENS WIRELESS_RATE WIRELESS_ENC_KEY WIRELESS_RTS WIRELESS_FRAG WIRELESS_IWCONFIG WIRELESS_IWSPY WIRELESS_IWPRIV))); } @@ -372,12 +375,13 @@ You may also enter the IP address of the gateway if you have one"), ); } -sub miscellaneousNetwork { - my ($in, $clicked, $no_track_net) = @_; - my $u = $::o->{miscellaneous} ||= {}; - $::isInstall and $in->set_help('configureNetworkProxy'); +sub miscellaneous_choose { + my ($in, $u, $clicked, $no_track_net) = @_; + $in->set_help('configureNetworkProxy') if $::isInstall; + $u->{track_network_id} = detect_devices::isLaptop(); - $::expert || $clicked and ($in->ask_from('', + + $in->ask_from('', N("Proxies configuration"), [ { label => N("HTTP proxy"), val => \$u->{http_proxy} }, { label => N("FTP proxy"), val => \$u->{ftp_proxy} }, @@ -388,10 +392,16 @@ sub miscellaneousNetwork { $u->{ftp_proxy} =~ m,^($|ftp://|http://), or $in->ask_warn('', N("Url should begin with 'ftp:' or 'http:'")), return 1,1; 0; } - ) or return); + ) or return if $::expert || $clicked; 1; } +sub proxy_configure { + my ($u) = @_; + setExportedVarsInSh( "$::prefix/etc/profile.d/proxy.sh", $u, qw(http_proxy ftp_proxy)); + setExportedVarsInCsh("$::prefix/etc/profile.d/proxy.csh", $u, qw(http_proxy ftp_proxy)); +} + sub read_all_conf { my ($prefix, $netc, $intf) = @_; $netc ||= {}; $intf ||= {}; @@ -447,7 +457,7 @@ sub configureNetwork2 { } #-res_init(); #- reinit the resolver so DNS changes take affect - any::miscellaneousNetwork(); + proxy_configure($::o->{miscellaneous}); } -- cgit v1.2.1