diff options
author | Mystery Man <unknown@mandriva.org> | 2004-01-09 21:14:12 +0000 |
---|---|---|
committer | Mystery Man <unknown@mandriva.org> | 2004-01-09 21:14:12 +0000 |
commit | 426b28dc63b1a571898e8edd580a0134e0239499 (patch) | |
tree | 8fbcfd82a41f005786abe4a1b1f1eef4cca01166 /perl-install/network | |
parent | 9fc2f8c1fe91c12ae413617392b02ad12571d361 (diff) | |
download | drakx-426b28dc63b1a571898e8edd580a0134e0239499.tar drakx-426b28dc63b1a571898e8edd580a0134e0239499.tar.gz drakx-426b28dc63b1a571898e8edd580a0134e0239499.tar.bz2 drakx-426b28dc63b1a571898e8edd580a0134e0239499.tar.xz drakx-426b28dc63b1a571898e8edd580a0134e0239499.zip |
This commit was manufactured by cvs2svn to create tag 'V9_3_15mdk'.V9_3_15mdk
Diffstat (limited to 'perl-install/network')
-rw-r--r-- | perl-install/network/adsl.pm | 301 | ||||
-rw-r--r-- | perl-install/network/drakfirewall.pm | 71 | ||||
-rw-r--r-- | perl-install/network/ethernet.pm | 181 | ||||
-rw-r--r-- | perl-install/network/isdn.pm | 228 | ||||
-rw-r--r-- | perl-install/network/isdn_consts.pm | 15 | ||||
-rw-r--r-- | perl-install/network/modem.pm | 241 | ||||
-rw-r--r-- | perl-install/network/netconnect.pm | 1407 | ||||
-rw-r--r-- | perl-install/network/network.pm | 367 | ||||
-rw-r--r-- | perl-install/network/nfs.pm | 38 | ||||
-rw-r--r-- | perl-install/network/shorewall.pm | 67 | ||||
-rw-r--r-- | perl-install/network/smb.pm | 36 | ||||
-rw-r--r-- | perl-install/network/smbnfs.pm | 4 | ||||
-rw-r--r-- | perl-install/network/tools.pm | 262 |
13 files changed, 1432 insertions, 1786 deletions
diff --git a/perl-install/network/adsl.pm b/perl-install/network/adsl.pm index 02d249b8f..99a5a6b5b 100644 --- a/perl-install/network/adsl.pm +++ b/perl-install/network/adsl.pm @@ -1,108 +1,96 @@ -package network::adsl; # $Id$ +package network::adsl; use common; use run_program; use network::tools; use network::ethernet; use modules; +use Data::Dumper; use vars qw(@ISA @EXPORT); use MDK::Common::Globals "network", qw($in $prefix); @ISA = qw(Exporter); @EXPORT = qw(adsl_ask_info adsl_detect adsl_conf adsl_conf_backend); - -sub get_wizard { - my ($wiz, $_type) = @_; - my $netc = $wiz->{var}{netc}; - - my %l = ( - 'pppoe' => N("use pppoe"), - 'pptp' => N("use pptp"), - 'dhcp' => N("use dhcp"), - 'speedtouch' => N("Alcatel speedtouch usb") . if_($netc->{autodetect}{adsl}{speedtouch}, N(" - detected")), - 'sagem' => N("Sagem (using pppoa) usb") . if_($netc->{autodetect}{adsl}{sagem}, N(" - detected")), - 'sagem_dhcp' => N("Sagem (using dhcp) usb") . if_($netc->{autodetect}{adsl}{sagem}, N(" - detected")), - # 'eci' => N("ECI Hi-Focus"), # this one needs eci agreement - ); - - $wiz->{var}{adsl} = { - connection_list => \%l, - type => "", - }; - add2hash($wiz->{pages}, - { - adsl => { - name => N("Connect to the Internet") . "\n\n" . - N("The most common way to connect with adsl is pppoe. -Some connections use pptp, a few use dhcp. -If you don't know, choose 'use pppoe'"), - data => [ - { - label => N("ADSL connection type :"), val_ref => \$wiz->{var}{adsl}{type}, list => [ sort values %l ] }, - ], - pre => sub { - $wiz->{var}{adsl}{type} = $l{sagem}; # debug - $wiz->{var}{adsl}{type} ||= find { $netc->{autodetect}{adsl}{$_} } keys %l; - print "\n\ntype is «$wiz->{var}{adsl}{type}»\n\n"; - }, - post => sub { - $wiz->{var}{adsl}{type} = find { $l{$_} eq $wiz->{var}{adsl}{type} } keys %l; - my $adsl = $wiz->{var}{adsl}{connection}; - my $type = $wiz->{var}{adsl}{type}; - my $netcnx = $wiz->{var}{netcnx}; - $netcnx->{type} = "adsl_$type"; - - my %packages = ( - 'dhcp' => [ 'dhcpcd' ], - 'eci' => [ 'eciadsl' ], - 'pppoe' => [ 'rp-pppoe' ], - 'pptp' => [ 'pptp-adsl' ], - 'sagem' => [ 'adiusbadsl' ], - 'sagem_dhcp' => [ qw(adiusbadsl dhcpcd) ], - 'speedtouch' => [ 'speedtouch' ], - ); - $in->do_pkgs->install(@{$packages{$type}}); - $netcnx->{"adsl_$type"} = {}; - $netcnx->{"adsl_$type"}{vpivci} = '' if $type =~ /eci|speedtouch/; - return 'ethernet' if $type eq 'dhcp'; - adsl_probe_info($adsl, $netc, $type); - # my ($adsl, $netc, $intf, $adsl_type) = @_; - # ask_info2($adsl, $netc); - return "hw_account"; - }, - }, - adsl_conf2 => { - #$adsl_type =~ /sagem|speedtouch|eci/ or conf_network_card($netc, $intf, 'static', '10.0.0.10') or goto adsl_conf_step_1; - #adsl_conf_backend($adsl, $netc, $adsl_type) or goto adsl_conf_step_1; - #1; - }, - ethernet => { - #go_ethernet($netc, $intf, 'dhcp', '', '', $first_time); - }, - end => { - post => sub { - $wiz->{var}{adsl}{type} =~ /speedtouch|eci/ or $netconnect::need_restart_network = 1; - }, - }, - }); -}; - -sub adsl_probe_info { - my ($adsl, $netc, $adsl_type) = @_; - my $pppoe_file = "$prefix/etc/ppp/pppoe.conf"; - my $pptp_file = "$prefix/etc/sysconfig/network-scripts/net_cnx_up"; - my %pppoe_conf; %pppoe_conf = getVarsFromSh($pppoe_file) if (! defined $adsl_type || $adsl_type =~ /pppoe/) && -f $pppoe_file; - my $login = $pppoe_conf{USER}; - foreach (qw(/etc/ppp/peers/adsl /etc/ppp/options /etc/ppp/options.adsl)) { - ($login) = map { if_(/^user\s+"([^"]+)"/, $1) } cat_("$prefix/$_") if !$login && -r "$prefix/$_"; +sub configure { + my ($netcnx, $netc, $intf, $first_time) = @_; + $::isInstall and $in->set_help('configureNetworkADSL'); + conf_adsl_step1: + # my $type = $in->ask_from_list_(N("Connect to the Internet"), + # N("The most common way to connect with adsl is pppoe. + # Some connections use pptp, a few ones use dhcp. + # If you don't know, choose 'use pppoe'"), [N_("use pppoe"), N_("use pptp"), N_("use dhcp"), N_("Alcatel speedtouch usb"), N_("ECI Hi-Focus")]) or return; + my $l = [ N_("use pppoe"), + N_("use pptp"), + N_("use dhcp"), + N_("Alcatel speedtouch usb") . if_($netc->{autodetect}{adsl}{speedtouch}, " - detected"), + N_("Sagem (using pppoe) usb") . if_($netc->{autodetect}{adsl}{sagem}, " - detected"), + ]; + my $type = $in->ask_from_list_(N("Connect to the Internet"), + N("The most common way to connect with adsl is pppoe. +Some connections use pptp, a few ones use dhcp. +If you don't know, choose 'use pppoe'"), $l) or return; + $type =~ s/use //; + if ($type eq 'pppoe') { + $in->do_pkgs->install("rp-$type"); + $netcnx->{type} = "adsl_$type"; +# $netcnx->{"adsl_$type"} = {}; + adsl_conf($netcnx->{"adsl_$type"}, $netc, $intf, $type) or goto conf_adsl_step1; + #-network::configureNetwork($prefix, $netc, $in, $intf, $first_time); +# if ($::isStandalone and $netc->{NET_DEVICE}) { +# $in->ask_yesorno(N("Network interface"), +# N("I'm about to restart the network device %s. Do you agree?", $netc->{NET_DEVICE}), 1) +# and system("$prefix/sbin/ifdown $netc->{NET_DEVICE}; $prefix/sbin/ifup $netc->{NET_DEVICE}"); +# } + } + #- use pppoe for Sagem modem, but NET_DEVICE is now ADIModem instead of ethx. + if ($type =~ /Sagem/) { + $in->do_pkgs->install(qw(rp-pppoe adiusbadsl)); + $netcnx->{type} = "adsl_pppoe"; + $netcnx->{adsl_pppoe} = {}; + modules::add_alias('ADIModem', 'adiusbadsl'); + $netc->{$_} = 'ADIModem' foreach qw(NET_DEVICE NET_INTERFACE); + adsl_conf($netcnx->{adsl_pppoe}, $netc, $intf, $type) or goto conf_adsl_step1; + } + if ($type eq 'dhcp') { + $in->do_pkgs->install(qw(dhcpcd)); + go_ethernet($netc, $intf, 'dhcp', '', '', $first_time) or goto conf_adsl_step1; + } + if ($type eq 'pptp') { + $in->do_pkgs->install(qw(pptp-adsl)); + $netcnx->{type} = "adsl_$type"; + $netcnx->{"adsl_$type"} = {}; + adsl_conf($netcnx->{"adsl_$type"}, $netc, $intf, $type) or goto conf_adsl_step1; } - ($login) = map { if_(/\sname\s+([^ \n]+)/, $1) } cat_($pptp_file) if (! defined $adsl_type || $adsl_type =~ /pptp/) && -r $pptp_file; - my $passwd = passwd_by_login($login); - $pppoe_conf{DNS1} ||= ''; - $pppoe_conf{DNS2} ||= ''; - add2hash($netc, { dnsServer2 => $pppoe_conf{DNS1}, dnsServer3 => $pppoe_conf{DNS2}, DOMAINNAME2 => '' }); - add2hash($adsl, { login => $login, passwd => $passwd, passwd2 => '' }); + if ($type =~ /speedtouch/) { + $type = 'speedtouch'; + $in->do_pkgs->install(qw(speedtouch)); + $netcnx->{type} = "adsl_$type"; + $netcnx->{"adsl_$type"} = {}; + $netcnx->{"adsl_$type"}{vpivci} = ''; + adsl_conf($netcnx->{"adsl_$type"}, $netc, $intf, $type) or goto conf_adsl_step1; + } + if ($type =~ /ECI/) { + $type = 'eci'; + $in->do_pkgs->install(qw(eciadsl)); + $netcnx->{type} = "adsl_$type"; + $netcnx->{"adsl_$type"} = {}; + $netcnx->{"adsl_$type"}{vpivci} = ''; + adsl_conf($netcnx->{"adsl_$type"}, $netc, $intf, $type) or goto conf_adsl_step1; + } + $type =~ /speedtouch|eci/ or $netconnect::need_restart_network = 1; + 1; +} + +sub adsl_ask_info { + my ($adsl, $netc, $_intf, $adsl_type) = @_; + my $pppoe_file = "/etc/ppp/pppoe.conf"; + my $pppoe_conf = { getVarsFromSh($pppoe_file) } if $adsl_type =~ /pppoe/ && -f $pppoe_file; + $pppoe_conf->{DNS1} ||= ''; + $pppoe_conf->{DNS2} ||= ''; + add2hash($netc, { dnsServer2 => $pppoe_conf->{DNS1}, dnsServer3 => $pppoe_conf->{DNS2}, DOMAINNAME2 => '' }); + add2hash($adsl, { login => $pppoe_conf->{USER}, passwd => passwd_by_login($pppoe_conf->{USER}), passwd2 => '' }); + ask_info2($adsl, $netc); } sub adsl_detect { @@ -113,9 +101,20 @@ sub adsl_detect { return $adsl if $adsl->{speedtouch} || $adsl->{sagem}; } +sub adsl_conf { + my ($adsl, $netc, $intf, $adsl_type) = @_; + + adsl_conf_step_1: + adsl_ask_info($adsl, $netc, $intf, $adsl_type) or return; + adsl_conf_step_2: + $adsl_type =~ /speedtouch|eci/ or conf_network_card($netc, $intf, 'static', '10.0.0.10') or goto adsl_conf_step_1; + adsl_conf_backend($adsl, $netc, $adsl_type); + 1; +} + sub adsl_conf_backend { - my ($adsl, $netc, $adsl_type, $o_netcnx) = @_; - defined $o_netcnx and $netc->{adsltype} = $o_netcnx->{type}; + my ($adsl, $netc, $adsl_type, $netcnx) = @_; + defined $netcnx and $netc->{adsltype} = $netcnx->{type}; $netc->{adsltype} ||= "adsl_$adsl_type"; mkdir_p("$prefix/etc/ppp"); output("$prefix/etc/ppp/options", @@ -138,47 +137,12 @@ defaultroute } "$prefix/etc/ppp/pppoe.conf"; } - if ($adsl_type eq 'sagem') { - substInFile { - s/VCI=.*\n/VCI=00000023\n/; - s/Encapsulation=.*\n/Encapsulation=00000006\n/; - } "$prefix/etc/analog/adiusbadsl"; - output("$prefix/etc/ppp/peers/adsl", -qq(noauth -noipdefault -pty "/usr/sbin/pppoa -I `/usr/sbin/adictrl -s; /usr/sbin/adictrl -i`" -mru 1492 -mtu 1492 -kdebug 1 -nobsdcomp -nodeflate -noaccomp -am -nopcomp -noccp -novj -novjccomp -holdoff 4 -maxfail 25 -persist -usepeerdns -defaultroute -user "$adsl->{login}" -)); - } - - if ($adsl_type eq 'sagem_dhcp') { - substInFile { - s/VCI=.*\n/VCI=00000024\n/; - s/Encapsulation=.*\n/Encapsulation=00000004\n/; - } "$prefix/etc/analog/adiusbadsl"; - } - if ($adsl_type eq 'speedtouch') { - my ($vpi, $vci) = $netc->{vpivci} =~ /(\d+)_(\d+)/ or return; + $netc->{vpivci} =~ /(\d+)_(\d+)/; output("$prefix/etc/ppp/peers/adsl", qq(noauth noipdefault -pty "/usr/sbin/pppoa3 -e 1 -c -vpi $vpi -vci $vci" +pty "/usr/bin/pppoa3 -vpi $1 -vci $2" sync kdebug 1 noaccomp @@ -192,50 +156,29 @@ usepeerdns defaultroute user "$adsl->{login}" )); - modules::add_alias($_->[0], $_->[1]) foreach ['speedtch', 'off'], - ['char-major-108', 'ppp_generic'], + modules::add_alias($_->[0], $_->[1]) foreach ['char-major-108', 'ppp_generic'], ['tty-ldisc-3', 'ppp_async'], ['tty-ldisc-13', 'n_hdlc'], ['tty-ldisc-14', 'ppp_synctty'], ['ppp-compress-21', 'bsd_comp'], ['ppp-compress-24', 'ppp_deflate'], ['ppp-compress-26', 'ppp_deflate']; - $::isStandalone and modules::write_conf(); - $in->do_pkgs->what_provides("speedtouch_mgmt") and $in->do_pkgs->ensure_is_installed('speedtouch_mgmt', '/usr/share/speedtouch/mgmt.o', 'auto'); - -e "$prefix/usr/share/speedtouch/mgmt.o" and goto end_firmware; - - firmware: - - my $l = [ N_("Use a floppy"), - N_("Use my Windows partition"), - N_("Do it later"), - ]; - - my $answer = $in->ask_from_list_(N("Firmware needed"), - N("You need the Alcatel microcode. -You can provide it now via a floppy or your windows partition, -or skip and do it later."), $l) or return; - - my $destination = "$prefix/usr/share/speedtouch/"; - $answer eq 'Use a floppy' && network::tools::copy_firmware('floppy', $destination, 'mgmt.o') || goto firmware; - $answer eq 'Use my Windows partition' && network::tools::copy_firmware('windows', $destination, 'alcaudsl.sys') || goto firmware; - $answer eq 'Do it later' and $in->ask_warn('', N("You need the Alcatel microcode. -Download it at: -%s -and copy the mgmt.o in /usr/share/speedtouch", 'http://prdownloads.sourceforge.net/speedtouch/speedtouch-20011007.tar.bz2')); - - -e "$destination/alcaudsl.sys" and rename "$destination/alcaudsl.sys", "$destination/mgmt.o"; - end_firmware: + $::isStandalone and modules::write_conf($prefix); + $in->do_pkgs->what_provides("speedtouch_mgmt") and $in->do_pkgs->install('speedtouch_mgmt'); + -e "$prefix/usr/share/speedtouch/mgmt.o" or $in->ask_warn('', N("You need the alcatel microcode. +Download it at +http://www.speedtouchdsl.com/dvrreg_lx.htm +and copy the mgmt.o in /usr/share/speedtouch")); } - - if ($adsl_type eq 'eci') { - my ($vpi, $vci) = $netc->{vpivci} =~ /(\d+)_(\d+)/ or return; - output("$prefix/etc/ppp/peers/adsl", + +if ($adsl_type eq 'eci') { + $netc->{vpivci} =~ /(\d+)_(\d+)/; + output("$prefix/etc/ppp/peers/adsl", qq(debug kdebug 1 noipdefault defaultroute -pty "/usr/bin/pppoeci -v 1 -vpi $vpi -vci $vci" +pty "/usr/bin/pppoeci -v 1 -vpi $1 -vci $2" sync noaccomp nopcomp @@ -249,11 +192,11 @@ usepeerdns noauth lcp-echo-interval 0 )); - modules::add_alias($_->[0], $_->[1]) foreach ['char-major-108', 'ppp_generic'], - ['tty-ldisc-14', 'ppp_synctty'], - ['tty-ldisc-13', 'n_hdlc']; - $::isStandalone and modules::write_conf(); - } + modules::add_alias($_->[0], $_->[1]) foreach ['char-major-108', 'ppp_generic'], + ['tty-ldisc-14', 'ppp_synctty'], + ['tty-ldisc-13', 'n_hdlc']; + $::isStandalone and modules::write_conf($prefix); +} if ($adsl_type eq 'pptp') { write_cnx_script($netc, "adsl", @@ -274,30 +217,12 @@ LC_ALL=C LANG=C LANGUAGE=C LC_MESSAGES=C /usr/sbin/adsl-start $netc->{NET_DEVICE /usr/share/speedtouch/speedtouch.sh start ', '/usr/share/speedtouch/speedtouch.sh stop -', $netc->{adsltype}) } elsif ($adsl_type eq 'sagem') { - write_cnx_script($netc, 'adsl', -'/sbin/route del default -/usr/sbin/adictrl -w -#INTERFACE=`/usr/sbin/adictrl -i` -#/sbin/ifconfig $INTERFACE 192.168.60.30 netmask 255.255.255.0 up -/usr/sbin/pppd file /etc/ppp/peers/adsl -', -'/usr/sbin/stopadsl -', $netc->{adsltype}) } elsif ($adsl_type eq 'sagem_dhcp') { - write_cnx_script($netc, 'adsl', -'/sbin/route del default -/usr/sbin/adictrl -w -INTERFACE=`/usr/sbin/adictrl -i` -/sbin/dhcpcd $INTERFACE -', -'INTERFACE=`/usr/sbin/adictrl -i` -/sbin/ifdown $INTERFACE ', $netc->{adsltype}) } elsif ($adsl_type eq 'eci') { write_cnx_script($netc, 'adsl', '/sbin/route del default /usr/bin/startmodem ', -"# stop is still beta... +"# et pour le stop on se touche c'est du beta... echo 'not yet implemented, still beta software' ", $netc->{adsltype}) } diff --git a/perl-install/network/drakfirewall.pm b/perl-install/network/drakfirewall.pm index 428c855c2..8951ecd44 100644 --- a/perl-install/network/drakfirewall.pm +++ b/perl-install/network/drakfirewall.pm @@ -1,7 +1,7 @@ package network::drakfirewall; # $Id$ -use strict; use diagnostics; +use strict; use network::shorewall; use common; @@ -9,49 +9,43 @@ use common; my @all_servers = ( { - name => N_("Web Server"), + name => N("Web Server"), pkg => 'apache apache-mod_perl boa', ports => '80/tcp 443/tcp', }, { - name => N_("Domain Name Server"), + name => N("Domain Name Server"), pkg => 'bind', ports => '53/tcp 53/udp', }, { - name => N_("SSH server"), + name => "SSH", pkg => 'openssh-server', ports => '22/tcp', }, { - name => N_("FTP server"), + name => "FTP", pkg => 'ftp-server-krb5 wu-ftpd proftpd pure-ftpd', ports => '20/tcp 21/tcp', }, { - name => N_("Mail Server"), + name => N("Mail Server"), pkg => 'sendmail postfix qmail', ports => '25/tcp', }, { - name => N_("POP and IMAP Server"), + name => N("POP and IMAP Server"), pkg => 'imap courier-imap-pop', ports => '109/tcp 110/tcp 143/tcp', }, { - name => N_("Telnet server"), + name => "Telnet", pkg => 'telnet-server-krb5', ports => '23/tcp', hide => 1, }, { - name => N_("Samba server"), - pkg => 'samba-server', - ports => '137/tcp 137/udp 138/tcp 138/udp 139/tcp 139/udp ', - hide => 1, - }, - { - name => N_("CUPS server"), + name => "CUPS", pkg => 'cups', ports => '631/tcp 631/udp', hide => 1, @@ -60,9 +54,10 @@ my @all_servers = sub port2server { my ($port) = @_; - find { - any { $port eq $_ } split(' ', $_->{ports}); - } @all_servers; + foreach (@all_servers) { + return $_ if grep { $port eq $_ } split ' ', $_->{ports}; + } + undef; } sub check_ports_syntax { @@ -100,43 +95,41 @@ sub default_from_pkgs { my @pkgs = $in->do_pkgs->are_installed(map { split ' ', $_->{pkg} } @all_servers); [ grep { my $s = $_; - any { member($_, @pkgs) } (split ' ', $s->{pkg}); + grep { member($_, @pkgs) } split ' ', $s->{pkg}; } @all_servers ]; } sub get_ports { - my ($in, $_ports) = @_; - my $shorewall = network::shorewall::read($in, 'silent') or return; + my ($_ports) = @_; + my $shorewall = network::shorewall::read() or return; \$shorewall->{ports}; } sub set_ports { - my ($in, $disabled, $ports) = @_; - my $shorewall = network::shorewall::read($in, 'not_silent') || network::shorewall::default_interfaces($in) or die \N("No network card"); - if (!$disabled || -x "$::prefix/sbin/shorewall") { - $in->do_pkgs->ensure_is_installed('shorewall', '/sbin/shorewall', $::isInstall) or return; - - $shorewall->{disabled} = $disabled; - $shorewall->{ports} = $$ports; - network::shorewall::write($shorewall); - } + my ($disabled, $ports) = @_; + + my $shorewall = network::shorewall::read() || network::shorewall::default_interfaces() or die N("No network card"); + $shorewall->{disabled} = $disabled; + $shorewall->{ports} = $$ports; + + network::shorewall::write($shorewall); } sub get_conf { - my ($in, $disabled, $o_ports) = @_; - + my ($in, $disabled, $ports) = @_; + my $possible_servers = default_from_pkgs($in); $_->{hide} = 0 foreach @$possible_servers; - if ($o_ports) { - $disabled, from_ports($o_ports); - } elsif (my $shorewall = network::shorewall::read($in, 'silent')) { + if ($ports) { + $disabled, from_ports($ports); + } elsif (my $shorewall = network::shorewall::read()) { $shorewall->{disabled}, from_ports(\$shorewall->{ports}); } else { $in->ask_okcancel('', N("drakfirewall configurator This configures a personal firewall for this Mandrake Linux machine. -For a powerful and dedicated firewall solution, please look to the +For a powerful dedicated firewall solution, please look to the specialized MandrakeSecurity Firewall distribution."), 1) or return; $in->ask_okcancel('', N("drakfirewall configurator @@ -172,7 +165,7 @@ where port is between 1 and 65535.", $invalid_port)); } }, [ { text => N("Everything (no firewall)"), val => \$disabled, type => 'bool' }, - (map { { text => translate($_->{name}), val => \$_->{on}, type => 'bool', disabled => sub { $disabled } } } @l), + (map { { text => $_->{name}, val => \$_->{on}, type => 'bool', disabled => sub { $disabled } } } @l), { label => N("Other ports"), val => \$unlisted, advanced => 1, disabled => sub { $disabled } } ]) or return; @@ -184,7 +177,9 @@ sub main { ($disabled, my $servers, my $unlisted) = get_conf($in, $disabled) or return; + $in->do_pkgs->ensure_is_installed('shorewall', '/sbin/shorewall', $::isInstall) or return; + ($disabled, my $ports) = choose($in, $disabled, $servers, $unlisted) or return; - set_ports($in, $disabled, $ports); + set_ports($disabled, $ports); } diff --git a/perl-install/network/ethernet.pm b/perl-install/network/ethernet.pm index 80419f9b5..410b81e13 100644 --- a/perl-install/network/ethernet.pm +++ b/perl-install/network/ethernet.pm @@ -1,29 +1,68 @@ -package network::ethernet; # $Id$ - +package network::ethernet; use network::network; use modules; -use modules::interactive; +use any; use detect_devices; use common; use run_program; use network::tools; use vars qw(@ISA @EXPORT); - use MDK::Common::Globals "network", qw($in $prefix); @ISA = qw(Exporter); -@EXPORT = qw(conf_network_card conf_network_card_backend go_ethernet); - -my (@cards, @ether_steps, $last, %last); +@EXPORT = qw(configureNetwork conf_network_card conf_network_card_backend go_ethernet); +sub configure_cable { + my ($netcnx, $netc, $intf, $first_time) = @_; + $::isInstall and $in->set_help('configureNetworkCable'); + $netcnx->{type} = 'cable'; + # $netcnx->{cable}={}; + # $in->ask_from_entries_ref(N("Cable connection"), + # N("Please enter your host name if you know it. + # Some DHCP servers require the hostname to work. + # Your host name should be a fully-qualified host name, + # such as ``mybox.mylab.myco.com''."), + # [N("Host name:")], [ \$netcnx->{cable}{hostname} ]); + if ($::expert) { + my @m = ( + { description => "dhcp-client", + c => 1 }, + { description => "dhcpcd", + c => 3 }, + { description => "dhcpxd", + c => 4 }, + ); + if (my $f = $in->ask_from_listf(N("Connect to the Internet"), + N("Which dhcp client do you want to use? +Default is dhcp-client"), + sub { $_[0]{description} }, + \@m)) { + $f->{c} == 3 and $netcnx->{dhcp_client} = "dhcpcd" and $in->do_pkgs->install(qw(dhcpcd)); + $f->{c} == 4 and $netcnx->{dhcp_client} = "dhcpxd" and $in->do_pkgs->install(qw(dhcpxd)); + $f->{c} == 1 and $netcnx->{dhcp_client} = "dhcp-client" and $in->do_pkgs->install(qw(dhcp-client)); + } + } else { + $in->do_pkgs->install(qw(dhcp-client)); + } + go_ethernet($netc, $intf, 'dhcp', '', '', $first_time); + write_cnx_script($netc, "cable", +qq( +/sbin/ifup $netc->{NET_DEVICE} +), +qq( +/sbin/ifdown $netc->{NET_DEVICE} +), $netcnx->{type}); + 1; +} -sub ether_conf{ - # my ($netcnx, $netc, $intf, $first_time) = @_; - my ($in, $prefix, $netc, $intf) = @_; +sub configure_lan { + my ($netcnx, $netc, $intf, $first_time) = @_; + $::isInstall and $in->set_help('configureNetworkIP'); + configureNetwork($netc, $intf, $first_time) or return; configureNetwork2($in, $prefix, $netc, $intf); $netc->{NETWORKING} = "yes"; - if ($netc->{GATEWAY} || any { $_->{BOOTPROTO} =~ /dhcp/ } values %$intf) { + if ($netc->{GATEWAY} || grep { $_->{BOOTPROTO} eq 'dhcp' } values %$intf) { $netcnx->{type} = 'lan'; $netcnx->{NET_DEVICE} = $netc->{NET_DEVICE} = ''; $netcnx->{NET_INTERFACE} = 'lan'; #$netc->{NET_INTERFACE}; @@ -36,12 +75,36 @@ qq( /sbin/ifup lo ), $netcnx->{type}); } - $::isStandalone and modules::write_conf(); + $::isStandalone and modules::write_conf($prefix); 1; } +sub conf_network_card { + my ($netc, $intf, $type, $ipadr, $netadr) = @_; + #-type =static or dhcp + any::load_category($in, 'network/main|usb', !$::expert, 1); + my @all_cards = conf_network_card_backend($netc, $intf, $type, undef, $ipadr, $netadr); + my $interface; + @all_cards == () and $in->ask_warn('', N("No ethernet network adapter has been detected on your system. +I cannot set up this connection type.")) and return; + @all_cards == 1 and $interface = $all_cards[0][0]; + while (!$interface) { + $interface = $in->ask_from_list(N("Choose the network interface"), + N("Please choose which network adapter you want to use to connect to Internet"), + [ map { $_->[0] . ($_->[1] ? " (using module $_->[1])" : "") } @all_cards ] + ) or return; + } + $::isStandalone and modules::write_conf($prefix); + + my $_device = conf_network_card_backend($netc, $intf, $type, $interface, $ipadr, $netadr, $interface); +# if ( $::isStandalone and !($type eq "dhcp")) { +# $in->ask_yesorno(N("Network interface"), +# N("I'm about to restart the network device:\n") . $device . N("\nDo you agree?"), 1) and configureNetwork2($in, $prefix, $netc, $intf) and system("$prefix/sbin/ifdown $device;$prefix/sbin/ifup $device"); +# } + 1; +} -#- conf_network_card_backend : configure the network cards and return the list of them, or configure one specified interface : WARNING, you have to setup the ethernet cards, by calling load_category($in, 'network/main|gigabit|usb', !$::expert, 1) or load_category_backend before calling this function. Basically, you call this function in 2 times. +#- conf_network_card_backend : configure the network cards and return the list of them, or configure one specified interface : WARNING, you have to setup the ethernet cards, by calling load_category($in, 'network/main|usb', !$::expert, 1) or load_category_backend before calling this function. Basically, you call this function in 2 times. #- input #- $prefix #- $netc @@ -63,39 +126,89 @@ qq( #- $all_cards : a list of a list ( [eth1, module1], ... , [ethn, modulen]). Pass the ethx as $interface in further call. #- $device : only returned in case $interface was given it's $interface, but filtered by /eth[0-9+]/ : string : /eth[0-9+]/ sub conf_network_card_backend { - my ($netc, $intf, $o_type, $o_interface, $o_ipadr, $o_netadr) = @_; + my ($netc, $intf, $type, $interface, $ipadr, $netadr) = @_; #-type =static or dhcp - if (!$o_interface) { + if (!$interface) { my @all_cards = detect_devices::getNet(); + my @unconfigured_interfaces = qw(ADIModem); my @devs = detect_devices::pcmcia_probe(); modules::mergein_conf("$prefix/etc/modules.conf"); my $saved_driver; return map { my $interface = $_; - my $a = c::getNetDriver($interface) || modules::get_alias($interface); - my $b = find { $_->{device} eq $interface } @devs; - $a ||= $b->{driver}; - $a and $saved_driver = $a; # handle multiple cards managed by the same driver - [ $interface, $saved_driver ] - } @all_cards; + my $a = modules::get_alias($interface); + my $b; + foreach (@devs) { + $_->{device} eq $interface and $b = $_->{driver}; + } + $a ||= $b; + $a and $saved_driver = $a; + if_(!member($interface, @unconfigured_interfaces) || $a, [$interface, $saved_driver]); + } @all_cards, @unconfigured_interfaces; } - $o_interface =~ /eth[0-9]+/ or die("the interface is not an ethx"); - - $netc->{NET_DEVICE} = $o_interface; #- one consider that there is only ONE Internet connection device.. - - @{$intf->{$o_interface}}{qw(DEVICE BOOTPROTO NETMASK NETWORK ONBOOT)} = ($o_interface, $o_type, '255.255.255.0', $o_netadr, 'yes'); - - $intf->{$o_interface}{IPADDR} = $o_ipadr if $o_ipadr; - $o_interface; + my ($device) = $interface =~ /(ADIModem|eth[0-9]+)/ or die("the interface is not an ethx or other (like ADIModem)"); + $netc->{NET_DEVICE} = $device; #- one consider that there is only ONE Internet connection device.. + + @{$intf->{$device}}{qw(DEVICE BOOTPROTO NETMASK NETWORK ONBOOT)} = + ($device, $type, '255.255.255.0', $netadr, 'yes'); + + $intf->{$device}{IPADDR} = $ipadr if $ipadr; + $device; +} + +sub go_ethernet { + my ($netc, $intf, $type, $ipadr, $netadr, $first_time) = @_; + conf_network_card($netc, $intf, $type, $ipadr, $netadr) or return; + $netc->{NET_INTERFACE} = $netc->{NET_DEVICE}; + configureNetwork($netc, $intf, $first_time) or return; +# if ( $::isStandalone and $netc->{NET_DEVICE}) { +# $in->ask_yesorno(N("Network interface"), +# N("I'm about to restart the network device %s. Do you agree?", $netc->{NET_DEVICE}), 1) and system("$prefix/sbin/ifdown $netc->{NET_DEVICE}; $prefix/sbin/ifup $netc->{NET_DEVICE}"); +# } + 1; } -# automatic net aliases configuration -sub configure_eth_aliases() { - foreach (detect_devices::getNet()) { - my $driver = c::getNetDriver($_) or next; - modules::add_alias($_, $driver); +sub configureNetwork { + my ($netc, $intf, $_first_time) = @_; + local $_; + any::load_category($in, 'network/main|usb|pcmcia', !$::expert, 1) or return; + my @l = detect_devices::getNet() or die N("no network card found"); + my @all_cards = conf_network_card_backend($netc, $intf, undef, undef, undef, undef); + + configureNetwork_step_1: + my $n_card = 0; + $netc ||= {}; + my $last; foreach (@l) { + my $intf2 = findIntf($intf ||= {}, $_); + add2hash($intf2, $last); + add2hash($intf2, { NETMASK => '255.255.255.0' }); + configureNetworkIntf($netc, $in, $intf2, $netc->{NET_DEVICE}, 0, $all_cards[$n_card][1]) or return; + + $last = $intf2; + $n_card++; + } + #- { + #- my $wait = $o->wait_message(N("Hostname"), N("Determining host name and domain...")); + #- network::guessHostname($o->{prefix}, $o->{netc}, $o->{intf}); + #- } + $last or return; + if ($last->{BOOTPROTO} =~ /^(dhcp|bootp)$/) { + $netc->{minus_one} = 1; + my $dhcp_hostname = $netc->{HOSTNAME}; + $::isInstall and $in->set_help('configureNetworkHostDHCP'); + $in->ask_from(N("Configuring network"), +N("Please enter your host name if you know it. +Some DHCP servers require the hostname to work. +Your host name should be a fully-qualified host name, +such as ``mybox.mylab.myco.com''."), + [ { label => N("Host name"), val => \$netc->{HOSTNAME} } ]) or goto configureNetwork_step_1; + $netc->{HOSTNAME} ne $dhcp_hostname and $netc->{DHCP_HOSTNAME} = $netc->{HOSTNAME}; + } else { + configureNetworkNet($in, $netc, $last ||= {}, @l) or goto configureNetwork_step_1; } + miscellaneousNetwork($in) or goto configureNetwork_step_1; + 1; } 1; diff --git a/perl-install/network/isdn.pm b/perl-install/network/isdn.pm index b66edfe75..2b747e255 100644 --- a/perl-install/network/isdn.pm +++ b/perl-install/network/isdn.pm @@ -1,6 +1,5 @@ -package network::isdn; # $Id$ +package network::isdn; -use strict; use network::isdn_consts; use common; use any; @@ -11,24 +10,98 @@ use network::tools; use vars qw(@ISA @EXPORT); use MDK::Common::Globals "network", qw($in $prefix); use MDK::Common::File; - - @ISA = qw(Exporter); @EXPORT = qw(isdn_write_config isdn_write_config_backend get_info_providers_backend isdn_ask_info isdn_ask_protocol isdn_ask isdn_detect isdn_detect_backend isdn_get_list isdn_get_info); +sub configure { + my ($netcnx, $netc, $isdn) = @_; + isdn_step_1: + defined $netc->{autodetect}{isdn}{id} and goto intern_pci; + $::isInstall and $in->set_help('configureNetworkISDN'); + my $e = $in->ask_from_list_(N("Network Configuration Wizard"), + N("Which ISDN configuration do you prefer? + +* The Old configuration uses isdn4net. It contains powerful + tools, but is tricky to configure, and not standard. + +* The New configuration is easier to understand, more + standard, but with less tools. + +We recommand the light configuration. +"), [ N_("New configuration (isdn-light)"), N_("Old configuration (isdn4net)") ] + ) or return; + $netc->{autodetect}{isdn}{is_light} = $e =~ /light/ ? 1 : undef; + $e = $in->ask_from_list_(N("Network Configuration Wizard"), + N("What kind is your ISDN connection?"), [ N_("Internal ISDN card"), N_("External ISDN modem") ] + ) or return; + + if ($e =~ /card/) { + intern_pci: + $netc->{isdntype} = 'isdn_internal'; + $netcnx->{isdn_internal} = isdn_read_config($isdn); + $netcnx->{isdn_internal}{$_} = $netc->{autodetect}{isdn}{$_} foreach 'description', 'vendor', 'id', 'driver', 'card_type', 'type', 'is_light'; + isdn_detect($netcnx->{isdn_internal}, $netc) or return; + } else { + $netc->{isdntype} = 'isdn_external'; + $netcnx->{isdn_external} = isdn_read_config($isdn); + $netcnx->{isdn_external}{device} = $netc->{autodetect}{modem}; + $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; + } + 1; +} sub isdn_write_config { my ($isdn, $netc) = @_; - $in->do_pkgs->install('isdn4net', if_($isdn->{speed} =~ /128/, 'ibod'), 'isdn4k-utils'); + isdn_write_config_step_1: + my ($rmpackage, $instpackage) = $isdn->{is_light} ? ('isdn4net', 'isdn-light') : ('isdn-light', 'isdn4net'); + if (!$::isStandalone) { + require pkgs; + my $p = pkgs::packageByName($in->{packages}, $rmpackage); + $p && $p->flag_selected and pkgs::unselectPackage($in->{packages}, $p); + } + run_program::rooted($prefix, "rpm", "-e", $rmpackage); + $in->do_pkgs->install($instpackage, if_($isdn->{speed} =~ /128/, 'ibod'), 'isdn4k-utils'); isdn_write_config_backend($isdn, $netc); 1; } sub isdn_write_config_backend { - my ($isdn, $netc, $o_netcnx) = @_; - defined $o_netcnx and $netc->{isdntype} = $o_netcnx->{type}; - - output_with_perm("$prefix/etc/isdn/profile/link/myisp", 0600, + my ($isdn, $netc, $netcnx) = @_; + defined $netcnx and $netc->{isdntype} = $netcnx->{type}; + if ($isdn->{is_light}) { + modules::mergein_conf("$prefix/etc/modules.conf"); + if ($isdn->{id}) { + isdn_detect_backend($isdn); + } else { + my $a = ""; + defined $isdn->{$_} and $a .= "$_=" . $isdn->{$_} . " " foreach qw(type protocol mem io io0 io1 irq); + $isdn->{driver} eq "hisax" and $a .= "id=HiSax"; + modules::set_options($isdn->{driver}, $a); + } + modules::add_alias("ippp0", $isdn->{driver}); + $::isStandalone and modules::write_conf($prefix); + foreach my $f ('ioptions1B', 'ioptions2B') { + substInFile { s/^name .*\n//; $_ .= "name $isdn->{login}\n" if eof } "$prefix/etc/ppp/$f"; + chmod 0600, $f; + } + foreach my $f ('isdn1B.conf', 'isdn2B.conf') { + substInFile { + s/EAZ =.*/EAZ = $isdn->{phone_in}/; + s/PHONE_OUT =.*/PHONE_OUT = $isdn->{phone_out}/; + if (/NAME = ippp0/ .. /PPPBIND = 0/) { + s/HUPTIMEOUT =.*/HUPTIMEOUT = $isdn->{huptimeout}/; + } + } "$prefix/etc/isdn/$f"; + chmod 0600, $f; + } + my $bundle = $isdn->{speed} =~ /64/ ? "1B" : "2B"; + symlinkf("isdn" . $bundle . ".conf", "$prefix/etc/isdn/isdnctrl.conf"); + symlinkf("ioptions" . $bundle, "$prefix/etc/ppp/ioptions"); + } else { + output_with_perm("$prefix/etc/isdn/profile/link/myisp", 0600, qq( I4L_USERNAME="$isdn->{login}" I4L_SYSNAME="" @@ -56,22 +129,20 @@ usepeerdns defaultroute "; system "$prefix/etc/rc.d/init.d/isdn4linux restart"; + } substInFile { s/^FIRMWARE.*\n//; $_ .= qq(FIRMWARE="$isdn->{firmware}"\n) if eof } "$prefix/etc/sysconfig/network-scripts/ifcfg-ippp0"; - # we start the virtual interface at boot (we dial only on demand. - substInFile { s/^ONBOOT.*\n//; $_ .= qq(ONBOOT=yes\n) if eof } "$prefix/etc/sysconfig/network-scripts/ifcfg-ippp$isdn->{intf_id}"; - write_secret_backend($isdn->{login}, $isdn->{passwd}); write_cnx_script($netc, "isdn", -"#/sbin/route del default -#/sbin/ifup ippp0 -/usr/sbin/isdnctrl dial ippp0 +"/sbin/route del default +/sbin/ifup ippp0 +/sbin/isdnctrl dial ippp0 " . if_($isdn->{speed} =~ /128/, "service ibod restart "), -"/usr/sbin/isdnctrl hangup ippp0 -#/sbin/ifdown ippp0 +"/sbin/isdnctrl hangup ippp0 +/sbin/ifdown ippp0 " . if_($isdn->{speed} =~ /128/, "service ibod stop "), $netc->{isdntype}); 1; @@ -80,25 +151,52 @@ defaultroute sub isdn_read_config { my ($isdn) = @_; - my %match = (I4L_USERNAME => 'login', - I4L_LOCALMSN => 'phone_in', - I4L_REMOTE_OUT => 'phone_out', - I4L_DIALMODE => 'dialing_mode', - I4L_MODULE => 'driver', - I4L_TYPE => 'type', - I4L_IRQ => 'irq', - I4L_MEMBASE => 'mem', - I4L_PORT => 'io', - I4L_IO0 => 'io0', - I4L_IO1 => 'io1', - I4L_FIRMWARE => 'firmware'); - foreach ('link/myisp', 'card/mycard') { - my %conf = getVarsFromSh("$prefix/etc/isdn/profile/$_"); - foreach (keys %conf) { - $isdn->{$match{$_}} = $conf{$_} if $match{$_}; + if ($isdn->{is_light}) { + my $c = modules::read_conf("/etc/modules.conf"); + $isdn->{driver} = $c->{ippp0}{alias}; + #- 'type' 'protocol' 'mem' 'io' 'io0' 'io1' 'irq' 'id' + foreach (split(' ', $c->{$isdn->{driver}}{options})) { + /(.*)=(.*)/; + $isdn->{$1} = $2; + } + foreach my $f ('ioptions1B', 'ioptions2B') { + foreach (cat_("$prefix/etc/ppp/$f")) { + if (/^\s*name\s*(.*)/) { + $isdn->{login} = $1; + goto NEXT; + } + } + } + NEXT: + foreach my $f ('isdn1B.conf', 'isdn2B.conf') { + foreach (cat_("$prefix/etc/isdn/$f")) { + /^\s*EAZ\s*=\s*(.*)/ and $isdn->{phone_in} = $1; + /^\s*PHONE_OUT\s*=\s*(.*)/ and $isdn->{phone_out} = $1; + if (/^\s*NAME\s*=\s*ippp0/ .. /PPPBIND\s*=\s*0/) { + /^\s*HUPTIMEOUT\s*=\s*(.*)/ and $isdn->{huptimeout} = $1; + } + } + } + } else { + my %match = (I4L_USERNAME => 'login', + I4L_LOCALMSN => 'phone_in', + I4L_REMOTE_OUT => 'phone_out', + I4L_DIALMODE => 'dialing_mode', + I4L_MODULE => 'driver', + I4L_TYPE => 'type', + I4L_IRQ => 'irq', + I4L_MEMBASE => 'mem', + I4L_PORT => 'io', + I4L_IO0 => 'io0', + I4L_IO1 => 'io1', + I4L_FIRMWARE => 'firmware'); + foreach ('link/myisp', 'card/mycard') { + my %conf = getVarsFromSh("$prefix/etc/isdn/profile/$_"); + foreach (keys %conf) { + $isdn->{$match{$_}} = $conf{$_} if $match{$_}; + } } } - $isdn->{passwd} = network::tools::passwd_by_login($isdn->{login}); #$isdn->{description} = ''; #$isdn->{vendor} = ''; @@ -113,7 +211,7 @@ sub get_info_providers_backend { chop; my ($name_, $phone, $real, $dns1, $dns2) = split '=>'; if ($name eq $name_) { - @$isdn{qw(user_name phone_out DOMAINNAME2 dnsServer3 dnsServer2)} = + @{$isdn}{qw(user_name phone_out DOMAINNAME2 dnsServer3 dnsServer2)} = ((split(/\|/, $name_))[2], $phone, $real, $dns1, $dns2); } } @@ -123,7 +221,6 @@ sub isdn_ask_info { my ($isdn, $netc) = @_; my $f = "$ENV{SHARE_PATH}/ldetect-lst/isdn.db"; $f = "$prefix$f" if !-e $f; - isdn_ask_info_step1: my $str = $in->ask_from_treelist(N("ISDN Configuration"), N("Select your provider.\nIf it isn't listed, choose Unlisted."), '|', ['Unlisted - edit manually', read_providers_backend($f)], 'Unlisted - edit manually') @@ -132,12 +229,12 @@ sub isdn_ask_info { $isdn->{huptimeout} = 180; $isdn->{$_} ||= '' foreach qw(phone_in phone_out dialing_mode login passwd passwd2 idl speed); add2hash($netc, { dnsServer2 => '', dnsServer3 => '', DOMAINNAME2 => '' }); - ask_info2($isdn, $netc) or goto isdn_ask_info_step1; + ask_info2($isdn, $netc); } -sub isdn_ask_protocol() { +sub isdn_ask_protocol { my @toto = ( - { description => $::expert ? N("European protocol (EDSS1)") : N("European protocol"), + { description => $::expert ? N("Europe protocol (EDSS1)") : N("Europe protocol"), protokol => 2 }, { description => $::expert ? N("Protocol for the rest of the world\nNo D-Channel (leased lines)") : N("Protocol for the rest of the world"), protokol => 3 } @@ -162,13 +259,10 @@ sub isdn_ask { isdn_ask_step_1: my $e = $in->ask_from_list_(N("ISDN Configuration"), $label . "\n" . N("What kind of card do you have?"), - [ N_("ISA / PCMCIA"), N_("PCI"), N_("USB"), N_("I don't know") ] + [ N_("ISA / PCMCIA"), N_("PCI"), N_("I don't know") ] ) or return; - isdn_ask_step_1b: if ($e =~ /PCI/) { $isdn->{card_type} = 'pci'; - } elsif ($e =~ /USB/) { - $isdn->{card_type} = 'usb'; } else { $in->ask_from_list_(N("ISDN Configuration"), N(" @@ -181,9 +275,9 @@ If you have a PCMCIA card, you have to know the \"irq\" and \"io\" of your card. isdn_ask_step_2: $e = $in->ask_from_listf(N("ISDN Configuration"), - N("Which of the following is your ISDN card?"), + N("Which is your ISDN card?"), sub { $_[0]{description} }, - [ grep { $_->{card} eq $isdn->{card_type} } @isdndata ]) or goto($isdn->{card_type} =~ /usb|pci/ ? 'isdn_ask_step_1' : 'isdn_ask_step_1b'); + [ grep { $_->{card} eq $isdn->{card_type} } @isdndata ]) or goto isdn_ask_step_1; $e->{$_} and $isdn->{$_} = $e->{$_} foreach qw(driver type mem io io0 io1 irq firmware); isdn_ask_step_3: @@ -194,33 +288,51 @@ If you have a PCMCIA card, you have to know the \"irq\" and \"io\" of your card. 1; } -sub isdn_detect_backend() { - my $isdn = { }; - each_index { - my $c = $_; - $isdn->{$::i} = { map { $_ => $c->{$_} } qw(description vendor id driver card_type type) }; - my $isdn = $isdn->{$::i}; - $isdn->{intf_id} = $::i; +sub isdn_detect { + my ($isdn, $netc) = @_; + if ($isdn->{id}) { + log::l("found isdn card : $isdn->{description}; vendor : $isdn->{vendor}; id : $isdn->{id}; driver : $isdn->{driver}\n"); + $isdn->{description} =~ s/\|/ -- /; + if ($isdn->{type} eq '') { + isdn_ask($isdn, $netc, N("I have detected an ISDN PCI card, but I don't know its type. Please select a PCI card on the next screen.")) or return; + } else { + isdn_detect_step_1: + $isdn->{protocol} = isdn_ask_protocol() or return; + isdn_detect_step_2: + isdn_ask_info($isdn, $netc) or goto isdn_detect_step_1; + isdn_write_config($isdn, $netc) or goto isdn_detect_step_2; + } + } else { + isdn_ask($isdn, $netc, N("No ISDN PCI card found. Please select one on the next screen.")) or return; + } + $netc->{$_} = 'ippp0' foreach 'NET_DEVICE', 'NET_INTERFACE'; + 1; +} + +sub isdn_detect_backend { + my ($isdn) = @_; + if (my ($c) = modules::probe_category('network/isdn')) { + $isdn->{$_} = $c->{$_} foreach qw(description vendor id driver options firmware); $isdn->{$_} = sprintf("%0x", $isdn->{$_}) foreach 'vendor', 'id'; - $isdn->{card_type} = $c->{bus} eq 'USB' ? 'usb' : 'pci'; + $isdn->{card_type} = 'pci'; ($isdn->{type}) = $isdn->{options} =~ /type=(\d+)/; - $isdn->{description} =~ s/.*\|//; # $c->{options} !~ /id=HiSax/ && $isdn->{driver} eq "hisax" and $c->{options} .= " id=HiSax"; if ($c->{options} !~ /protocol=/ && $isdn->{protocol} =~ /\d/) { modules::set_options($c->{driver}, $c->{options} . " protocol=" . $isdn->{protocol}); } $c->{options} =~ /protocol=(\d)/ and $isdn->{protocol} = $1; - } modules::probe_category('network/isdn'); - $isdn; + } } -sub isdn_get_list() { +sub isdn_get_list { map { $_->{description} } @isdndata; } sub isdn_get_info { my ($desc) = @_; - find { $_->{description} eq $desc } @isdndata; + foreach (@isdndata) { + return $_ if $_->{description} eq $desc; + } } 1; diff --git a/perl-install/network/isdn_consts.pm b/perl-install/network/isdn_consts.pm index c38297641..b93a75e11 100644 --- a/perl-install/network/isdn_consts.pm +++ b/perl-install/network/isdn_consts.pm @@ -1,7 +1,4 @@ -package network::isdn_consts; # $Id$ -use vars qw(@ISA @EXPORT); -@ISA = qw(Exporter); -@EXPORT = qw(@isdndata); +package network::isdn; # $Id$ our @isdndata = ( @@ -324,16 +321,6 @@ our @isdndata = type => '36', card => 'pci', }, - { description => "BeWAN R834 (USB)", - driver => 'hisax_st5481', - type => '99', - card => 'usb', - }, - { description => "Gazel 128 (USB)", - driver => 'hisax_st5481', - type => '99', - card => 'usb', - }, ); 1; diff --git a/perl-install/network/modem.pm b/perl-install/network/modem.pm index f1ef4d9f7..fd2f54c50 100644 --- a/perl-install/network/modem.pm +++ b/perl-install/network/modem.pm @@ -1,176 +1,103 @@ -package network::modem; # $Id$ +package network::modem; -use strict; use common; use any; 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 ppp_configure_raw { - my ($in, $netc, $modem) = @_; - $netc->{DOMAINNAME2} = $modem->{domain}; - $in->do_pkgs->install('ppp') if !$::testing; - $in->do_pkgs->install('kdenetwork-kppp') if $in->do_pkgs->is_installed('kdebase'); - any::devfssymlinkf($modem, 'modem') if $modem->{device} ne "/dev/modem"; - - 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 = <<END; -DEVICE="$toreplace{intf}" -ONBOOT="no" -USERCTL="no" -MODEMPORT="/dev/modem" -LINESPEED="115200" -PERSIST="yes" -DEFABORT="yes" -DEBUG="yes" -INITSTRING="ATZ" -DEFROUTE="yes" -HARDFLOWCTL="yes" -ESCAPECHARS="no" -PPPOPTIONS="" -PAPNAME="$toreplace{papname}" -REMIP="" -NETMASK="" -IPADDR="" -MRU="" -MTU="" -DISCONNECTTIMEOUT="5" -RETRYTIMEOUT="60" -BOOTPROTO="none" -PEERDNS="$toreplace{peerdns}" -END - output("$::prefix/etc/sysconfig/network-scripts/ifcfg-ppp0", - $various, - map { qq(DNS$_=$toreplace{"dns$_"}\n) } grep { $toreplace{"dns$_"} } 1..2); - - #- build chat-ppp0. - my @chat = <<END; -'ABORT' 'BUSY' -'ABORT' 'ERROR' -'ABORT' 'NO CARRIER' -'ABORT' 'NO DIALTONE' -'ABORT' 'Invalid Login' -'ABORT' 'Login incorrect' -'' 'ATZ' -END - if ($modem->{special_command}) { - push @chat, <<END; -'OK' '$modem->{special_command}' -END +sub configure { + my ($netcnx, $mouse, $netc, $intf) = @_; + $netcnx->{type} = 'modem'; + my $modem = $netcnx->{$netcnx->{type}}; +# $netcnx->{$netcnx->{type}} = {}; + $modem->{device} = $netc->{autodetect}{modem}; +# modem_step_1: +# $modem->{login} = ($modem->{auth} eq 'PAP' ||$modem->{auth} eq 'CHAP') && $intf->{ppp0}{PAPNAME}; +# $netcnx->{$netcnx->{type}}->{connection} = ($netcnx->{$netcnx->{type}}->{auth} eq 'PAP' || $netcnx->{$netcnx->{type}}->{auth} eq 'CHAP') && $intf->{ppp0}{PAPNAME}; +# $modem->{device} = readlink "$prefix/dev/modem"; + foreach (cat_("/usr/share/config/kppprc")) { + /^DNS=(.*)$/ and ($modem->{dns1}, $modem->{dns2}) = split(',', $1); } - push @chat, <<END; -'OK' 'ATDT$toreplace{phone}' -'CONNECT' '' -END - if ($modem->{auth} eq 'Terminal-based' || $modem->{auth} eq 'Script-based') { - push @chat, <<END; -'ogin:--ogin:' '$toreplace{login}' -'ord:' '$toreplace{passwd}' -END + my $secret = network::tools::read_secret_backend(); + foreach (@$secret) { + $modem->{passwd} = $_->{passwd} if $_->{login} eq $modem->{login}; } - push @chat, <<END; -'TIMEOUT' '5' -'~--' '' -END - my $chat_file = "$::prefix/etc/sysconfig/network-scripts/chat-ppp0"; - output_with_perm($chat_file, 0600, @chat); - if ($modem->{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, qq($toreplace{login} ppp0 "$toreplace{passwd}"\n)); + foreach (cat_("/etc/sysconfig/network-scripts/chat-ppp0")) { + if (/.*ATDT(\d*).*/) { + $modem->{phone} = $1; + last; } - #- restore access right to secrets file, just in case. - chmod 0600, $secrets; } + pppConfig($modem, $mouse, $netc, $intf) or return; + write_cnx_script($netc, "modem", +q( +/sbin/route del default +ifup ppp0 +), +q(ifdown ppp0 +killall pppd +), $netcnx->{type}); + 1; +} - #- install kppprc file according to used configuration. - mkdir_p("$::prefix/usr/share/config"); +sub pppConfig { + my ($modem, $mouse, $netc, $_intf) = @_; + $mouse ||= {}; - output("$::prefix/usr/share/config/kppprc", c::to_utf8(<<END)); -# KDE Config File -[Account0] -ExDNSDisabled=0 -AutoName=0 -ScriptArguments= -AccountingEnabled=0 -DialString=ATDT -Phonenumber=$toreplace{phone} -IPAddr=0.0.0.0 -Domain=$toreplace{domain} -Name=$toreplace{connection} -VolumeAccountingEnabled=0 -pppdArguments= -Password=$toreplace{passwd} -BeforeDisconnect= -Command= -ScriptCommands= -Authentication=$toreplace{kpppauth} -DNS=$toreplace{dnsserver} -SubnetMask=0.0.0.0 -AccountingFile= -DefaultRoute=1 -Username=$toreplace{login} -Gateway=0.0.0.0 -StorePassword=1 -DisconnectCommand= -[Modem] -BusyWait=0 -Enter=CR -FlowControl=CRTSCTS -Volume=0 -Timeout=60 -UseCDLine=0 -UseLockFile=1 -Device=/dev/modem -Speed=115200 -[Graph] -InBytes=0,0,255 -Text=0,0,0 -Background=255,255,255 -Enabled=true -OutBytes=255,0,0 -[General] -QuitOnDisconnect=0 -ShowLogWindow=0 -DisconnectOnXServerExit=1 -DefaultAccount=$toreplace{connection} -iconifyOnConnect=1 -Hint_QuickHelp=0 -AutomaticRedial=0 -PPPDebug=0 -NumberOfAccounts=1 -ShowClock=1 -DockIntoPanel=0 -pppdTimeout=30 -END - network::network::proxy_configure($::o->{miscellaneous}); + $mouse->{device} ||= readlink "$prefix/dev/mouse"; + $::isInstall and $in->set_help('selectSerialPort'); + $modem->{device} ||= $in->ask_from_listf('', N("Please choose which serial port your modem is connected to."), + \&mouse::serial_port2text, + [ grep { $_ ne $mouse->{device} } (mouse::serial_ports(), if_(-e '/dev/modem', '/dev/modem')) ]) || return; + + my @cnx_list; + my $secret = network::tools::read_secret_backend(); + foreach (@$secret) { + push @cnx_list, $_->{server}; + } + $::isStandalone || $in->set_help('configureNetworkISP'); + $in->ask_from('', N("Dialup options"), [ +{ label => N("Connection name"), val => \$modem->{connection} }, +{ label => N("Phone number"), val => \$modem->{phone} }, +{ label => N("Login ID"), val => \$modem->{login} }, +{ label => N("Password"), val => \$modem->{passwd}, hidden => 1 }, +{ label => N("Authentication"), val => \$modem->{auth}, list => [ N_("PAP"), N_("Terminal-based"), N_("Script-based"), N_("CHAP") ] }, +{ label => N("Domain name"), val => \$modem->{domain} }, +{ label => N("First DNS Server (optional)"), val => \$modem->{dns1} }, +{ label => N("Second DNS Server (optional)"), val => \$modem->{dns2} }, + ]) or return; + $netc->{DOMAINNAME2} = $modem->{domain}; + any::pppConfig($in, $modem, $prefix); + $netc->{$_} = 'ppp0' foreach 'NET_DEVICE', 'NET_INTERFACE'; + 1; +} + +#- TODO: add choice between hcf/hsf +sub winmodemConfigure { + my ($netc) = @_; + my $type; + + foreach (keys %{$netc->{autodetect}{winmodem}}) { + my $temp; + /Hcf/ and $temp = "hcf"; + /Hsf/ and $temp = "hsf"; + $temp and $in->do_pkgs->what_provides("${temp}linmodem") and $type = "${temp}linmodem"; + } + + $type || $in->ask_warn(N("Warning"), N("Your modem isn't supported by the system. +Take a look at http://www.linmodems.org")) && return 1; + my $e = $in->ask_from_list(N("Title"), N("\"%s\" based winmodem detected, do you want to install needed software ?", $type), [N("Install rpm"), N("Do nothing")]) or return 0; + $e =~ /rpm/ ? $in->do_pkgs->install($type) : return 1; + 1; } 1; diff --git a/perl-install/network/netconnect.pm b/perl-install/network/netconnect.pm index f944dd762..32a3c17c3 100644 --- a/perl-install/network/netconnect.pm +++ b/perl-install/network/netconnect.pm @@ -1,6 +1,5 @@ -package network::netconnect; # $Id$ +package network::netconnect; -use strict; use common; use log; use detect_devices; @@ -8,36 +7,101 @@ use run_program; use modules; use any; use mouse; -use network::network; +use network; +use Data::Dumper; use network::tools; use MDK::Common::Globals "network", qw($in $prefix $connect_file $disconnect_file $connect_prog); -my %conf; +my %conf; +#- intro is called only in standalone. +sub intro { + my ($prefix, $netcnx, $in) = @_; + my ($netc, $mouse, $intf) = ({}, {}, {}); + my $text; + my $connected; + my $connect_file = "/etc/sysconfig/network-scripts/net_cnx_up"; + my $disconnect_file = "/etc/sysconfig/network-scripts/net_cnx_down"; + my $connect_prog = "/etc/sysconfig/network-scripts/net_cnx_pg"; + read_net_conf($prefix, $netcnx, $netc); + if (!$::isWizard) { + if (connected()) { + $text = N("You are currently connected to internet.") . (-e $disconnect_file ? N("\nYou can disconnect or reconfigure your connection.") : N("\nYou can reconfigure your connection.")); + $connected = 1; + } else { + $text = N("You are not currently connected to Internet.") . (-e $connect_file ? N("\nYou can connect to Internet or reconfigure your connection.") : N("\nYou can reconfigure your connection.")); + $connected = 0; + } + my @l = ( + if_(!$connected && -e $connect_file, { description => N("Connect"), c => 1 }), + if_($connected && -e $disconnect_file, { description => N("Disconnect"), c => 2 }), + { description => N("Configure the connection"), c => 3 }, + { description => N("Cancel"), c => 4 }, + ); + my $e = $in->ask_from_listf(N("Internet connection & configuration"), + translate($text), + sub { $_[0]{description} }, + \@l); + run_program::rooted($prefix, $connect_prog) if $e->{c} == 1; + run_program::rooted($prefix, $disconnect_file) if $e->{c} == 2; + main($prefix, $netcnx, $netc, $mouse, $in, $intf, 0, 0) if $e->{c} == 3; + $in->exit(0) if $e->{c} == 4; + } else { + main($prefix, $netcnx, $netc, $mouse, $in, $intf, 0, 0); + } +} sub detect { - my ($auto_detect, $o_class) = @_; - my %l = ( - isdn => sub { - require network::isdn; - $auto_detect->{isdn} = network::isdn::isdn_detect_backend(); - }, - lan => sub { # ethernet - modules::load_category('network/main|gigabit|usb'); - require network::ethernet; - $auto_detect->{lan} = { map { $_->[0] => $_->[1] } network::ethernet::conf_network_card_backend() }; - }, - adsl => sub { - require network::adsl; - $auto_detect->{adsl} = network::adsl::adsl_detect(); - }, - modem => sub { - my ($modem, @pci_modems) = detect_devices::getModem(); - $modem->{device} and $auto_detect->{modem} = $modem->{device}; - @pci_modems and $auto_detect->{winmodem}{$_->{driver}} = $_->{description} foreach @pci_modems; - }, - ); - $l{$_}->() foreach ($o_class || (keys %l)); - return; + my ($auto_detect, $net_install) = @_; + my $isdn = {}; + require network::isdn; + network::isdn->import; + isdn_detect_backend($isdn); + $auto_detect->{isdn}{$_} = $isdn->{$_} foreach qw(description vendor id driver card_type type); + $auto_detect->{isdn}{description} =~ s/.*\|//; + + modules::load_category('network/main|usb'); + require network::ethernet; + network::ethernet->import; + my @all_cards = conf_network_card_backend(undef, undef, undef, undef, undef, undef); + map { $auto_detect->{lan}{$_->[0]} = $_->[1] } @all_cards if !$net_install; + + my $adsl = {}; + require network::adsl; + network::adsl->import; + $auto_detect->{adsl} = adsl_detect($adsl); + + require network::modem; + network::modem->import; + my ($modem, @pci_modems) = detect_devices::getModem(); + $modem->{device} and $auto_detect->{modem} = $modem->{device}; + @pci_modems and $auto_detect->{winmodem}{$_->{driver}} = $_->{description} foreach @pci_modems; +} + +sub pre_func { + my ($text) = @_; + $in->isa('interactive_gtk') or return; + $::Wizard_no_previous = 1; + if ($::isStandalone) { + $::Wizard_splash = 1; + require ugtk2; + ugtk2->import(qw(:wrappers)); + my $W = ugtk2->new(N("Network Configuration Wizard")); + gtkadd($W->{window}, + gtkpack_(new Gtk2::VBox(0, 0), + 1, write_on_pixmap(gtkcreate_img("drakconnect_step"), + 20,200, + N("We are now going to configure the %s connection.", translate($text)), + ), + 0, $W->create_okcancel(N("OK")) + ) + ); + $W->main; + $::Wizard_splash = 0; + } else { + #- for i18n : %s is the type of connection of the list: (modem, isdn, adsl, cable, local network); + $in->ask_okcancel(N("Network Configuration Wizard"), N("\n\n\nWe are now going to configure the %s connection.\n\n\nPress OK to continue.", translate($_[0])), 1); + } + undef $::Wizard_no_previous; } sub init_globals { @@ -50,891 +114,180 @@ sub init_globals { connect_prog => "/etc/sysconfig/network-scripts/net_cnx_pg"); } -sub detect_timezone() { - my %tmz2country = ( - 'Europe/Paris' => N("France"), - 'Europe/Amsterdam' => N("Netherlands"), - 'Europe/Rome' => N("Italy"), - 'Europe/Brussels' => N("Belgium"), - 'America/New_York' => N("United States"), - 'Europe/London' => N("United Kingdom") - ); - my %tm_parse = MDK::Common::System::getVarsFromSh('/etc/sysconfig/clock'); - my @country; - foreach (keys %tmz2country) { - if ($_ eq $tm_parse{ZONE}) { - unshift @country, $tmz2country{$_}; - } else { push @country, $tmz2country{$_} }; +sub main { + my ($prefix, $netcnx, $netc, $mouse, $in, $intf, $first_time, $_direct_fr, $noauto) = @_; + init_globals($in, $prefix); + $netc->{minus_one} = 0; #When one configure an eth in dhcp without gateway + $::isInstall and $in->set_help('configureNetwork'); + $::isStandalone and read_net_conf($prefix, $netcnx, $netc); # REDONDANCE with intro. FIXME + $netc->{NET_DEVICE} = $netcnx->{NET_DEVICE} if $netcnx->{NET_DEVICE}; # REDONDANCE with read_conf. FIXME + $netc->{NET_INTERFACE} = $netcnx->{NET_INTERFACE} if $netcnx->{NET_INTERFACE}; # REDONDANCE with read_conf. FIXME + network::network::read_all_conf($prefix, $netc ||= {}, $intf ||= {}); + + modules::mergein_conf("$prefix/etc/modules.conf"); + + my $direct_net_install; + if ($first_time && $::isInstall && ($in->{method} eq "ftp" || $in->{method} eq "http" || $in->{method} eq "nfs")) { + (!($::expert || $noauto) or $in->ask_okcancel(N("Network Configuration"), + N("Because you are doing a network installation, your network is already configured. +Click on Ok to keep your configuration, or cancel to reconfigure your Internet & Network connection. +"), 1)) and do { + $netcnx->{type} = 'lan'; + output_with_perm("$prefix$connect_file", 0755, + qq( +ifup eth0 +)); + output("$prefix$disconnect_file", 0755, + qq( +ifdown eth0 +)); + $direct_net_install = 1; + goto step_5; +}; } - \@country; -} - - -# configuring all network devices - sub main { - my ($_prefix, $netcnx, $in, $o_netc, $o_mouse, $o_intf, $o_first_time, $o_noauto) = @_; - my $netc = $o_netc || {}; - my $mouse = $o_mouse || {}; - my $intf = $o_intf || {}; - my $first_time = $o_first_time || 0; - my ($network_configured, $direct_net_install, $cnx_type, $type, $interface, @cards, @all_cards, @devices); - my (%connection_steps, %connections, %rconnections, @connection_list); - my ($ntf_name, $ipadr, $netadr, $gateway_ex, $up, $modem, $isdn, $isdn_type, $adsl_type, $need_restart_network); - my ($module, $text, $auto_ip, $net_device, $onboot, $needhostname, $hotplug, $track_network_id, @fields); # lan config - my $success = 1; - my $ethntf = {}; - use Data::Dumper; - - my %yesno = (yes => N("Yes"), no => N("No")); - - my %wireless_mode = (N("Ad-hoc") => "Ad-hoc", - N("Managed") => "Managed", - N("Master") => "Master", - N("Repeater") => "Repeater", - N("Secondary") => "Secondary", - N("Auto") => "Auto", - ); + $netc->{autodetection} = 1; + $netc->{autodetect} = {}; - init_globals($in, $::prefix); - $netc->{NET_DEVICE} = $netcnx->{NET_DEVICE} if $netcnx->{NET_DEVICE}; # REDONDANCE with read_conf. FIXME - $netc->{NET_INTERFACE} = $netcnx->{NET_INTERFACE} if $netcnx->{NET_INTERFACE}; # REDONDANCE with read_conf. FIXME - network::network::read_all_conf($::prefix, $netc, $intf); - - modules::mergein_conf("$::prefix/etc/modules.conf"); - - $netc->{autodetection} = 0; - $netc->{autodetect} = {}; - - my $next_cnx_step = sub { - my $next = connection_steps{$cnx_type}; - # FIXME: we want this in standalone mode too: - $need_restart_network = 1 if $next =~ /lan|cable/; - if ($next eq "multiple_internet_cnx") { - return 1 < scalar(keys %{$netc->{internet_cnx}}) ? "multiple_internet_cnx" : $connection_steps{multiple_internet_cnx}; - } - return $next; - }; - - my $ppp_first_step = sub { - $mouse ||= {}; - $mouse->{device} ||= readlink "$::prefix/dev/mouse"; - write_cnx_script($netc, "modem", join("\n", if_($::testing, "/sbin/route del default"), "ifup ppp0"), - q(ifdown ppp0 -killall pppd -), $netcnx->{type}); - my $need_to_ask = $modem->{device} || !$netc->{autodetect}{winmodem}; - return $need_to_ask ? "ppp_choose" : "ppp_choose2"; - }; - - # main wizard: - my $wiz; - $wiz = - { - defaultimage => "wiz_drakconnect.png", - name => N("Network & Internet Configuration"), - pages => { - install => - { - if_($::isInstall, no_back => 1), - name => N("Welcome to The Network Configuration Wizard. + step_1: + $::Wizard_no_previous = 1; + my @profiles = get_profiles(); + $in->ask_from(N("Network Configuration Wizard"), + N("Welcome to The Network Configuration Wizard. We are about to configure your internet/network connection. If you don't want to use the auto detection, deselect the checkbox. "), - interactive_help_id => 'configureNetwork', - data => [ - { text => N("Use auto detection"), val => \$netc->{autodetection}, type => 'bool' }, - { text => N("Expert Mode"), val => \$::expert, type => 'bool' }, - ], - post => sub { - if ($netc->{autodetection}) { - my $_w = $in->wait_message(N("Network Configuration Wizard"), N("Detecting devices...")); - detect($netc->{autodetect}); - } - - $conf{$_} = values %{$netc->{autodetect}{$_}} ? 1 : 0 foreach 'lan'; - $conf{$_} = $netc->{autodetect}{$_} ? 1 : 0 foreach qw(adsl cable modem winmodem); - $conf{isdn} = any { $_->{driver} } values %{$netc->{autodetect}{isdn}}; - return "connection"; - }, - }, - - connection => - { - pre => sub { - if (!$::isInstall) { - $conf{$_} = 0 foreach qw(adsl cable isdn lan modem winmodem); - } - my @connections = - ( - [ #-PO: here, "(detected)" string will be appended to eg "ADSL connection" - N("Normal modem connection"), N("(detected on port %s)", $netc->{autodetect}{modem}), "modem" ], - [ N("Winmodem connection"), N("(detected)"), "winmodem" ], - [ N("ISDN connection"), N("(detected %s)", join(', ', map { $_->{description} } values %{$netc->{autodetect}{isdn}})), "isdn" ], - [ N("ADSL connection"), N("(detected)"), "adsl" ], - [ N("Cable connection"), N("(detected)"), "cable" ], - [ N("LAN connection"), N("(detected)"), "lan" ], - # if we ever want to split out wireless connection, we'd to split out modules between network/main and network/wlan: - if_(0, [ N("Wireless connection"), N("(detected)"), "lan" ]), - ); - - foreach (@connections) { - my ($str, $extra_str, $type) = @$_; - my $string = join('', $str, if_($conf{$type}, " - ", $extra_str)); - $connections{$string} = $type; - } - %rconnections = reverse %connections; - if ($::isInstall) { - @connection_list = map { - my (undef, undef, $type) = @$_; - +{ text => $rconnections{$type}, val => \$conf{$type}, type => 'bool' } - } @connections; - } else { - @connection_list = ({ val => \$type, type => 'list', list => [ map { $_->[0] } @connections ], }); - } - }, - if_(!$::isInstall, no_back => 1), - name => N("Choose the connection you want to configure"), - interactive_help_id => 'configureNetwork', - data => \@connection_list, - changed => sub { - return if !$netc->{autodetection}; - my $c = 0; - #- $conf{adsl} and $c++; - $conf{cable} and $c++; - my $a = keys(%{$netc->{autodetect}{lan}}); - 0 < $a && $a <= $c and $conf{lan} = undef; - }, - complete => sub { - # at least one connection type must be choosen - return 0 if !$::isInstall; - return !any { $conf{$_} } keys %conf; - }, - post => sub { - load_conf($netcnx, $netc, $intf) if $::isInstall; # :-( - # while in installer, we need to link connections steps depending of which connections the user selected - my @l; - if ($::isInstall) { - @l = grep { $conf{$_} } keys %conf; - } else { - $type = $connections{$type}; - @l = ($type); - } - my $first = shift @l; - my @steps = (@l, - "multiple_internet_cnx", - ($::isInstall ? "miscellaneous_choose" : "apply_settings")); - foreach my $cnx ($first, @l) { - $connection_steps{$cnx} = shift @steps; - } - # FIXME: s/$type/"${type}_standalone"/ (because of newer steps for standalone mode just break all but lan paths: - return $::isInstall ? "prepare_detection" : "${type}_standalone"; - }, - }, - - prepare_detection => - { - name => N("We are now going to configure the %s connection.\n\n\nPress \"%s\" to continue.", - translate($type), N("Next")), - post => $next_cnx_step, - }, - - - hw_account => - { # ask_info2 - #my ($cnx, $netc) = @_; - - name => N("Connection Configuration") . "\n\n" . - N("Please fill or check the field below"), - data => [], - pre => sub { - push @{$wiz->{pages}{hw_account}{data}}, map { - my ($dstruct, $field, $item) = @$_; - $item->{val} = \$wiz->{var}{$dstruct}{$field}; - if__($wiz->{var}{$dstruct}{$field}, $item); - } ([ "cnx", "irq", { label => N("Card IRQ") } ], - [ "cnx", "mem", { label => N("Card mem (DMA)") } ], - [ "cnx", "io", { label => N("Card IO") } ], - [ "cnx", "io0", { label => N("Card IO_0") } ], - [ "cnx", "io1", { label => N("Card IO_1") } ], - [ "cnx", "phone_in", { label => N("Your personal phone number") } ], - [ "netc", "DOMAINNAME2", { label => N("Provider name (ex provider.net)") } ], - [ "cnx", "phone_out", { label => N("Provider phone number") } ], - [ "netc", "dnsServer2", { label => N("Provider dns 1 (optional)") } ], - [ "netc", "dnsServer3", { label => N("Provider dns 2 (optional)") } ], - [ "cnx", "vpivci", { label => N("Choose your country"), list => detect_timezone() } ], - [ "cnx", "dialing_mode", { label => N("Dialing mode"), list => ["auto", "manual"] } ], - [ "cnx", "speed", { label => N("Connection speed"), list => ["64 Kb/s", "128 Kb/s"] } ], - [ "cnx", "huptimeout", { label => N("Connection timeout (in sec)") } ], - ); - push @{$wiz->{pages}{hw_account}{data}}, - ({ label => N("Account Login (user name)"), val => \$wiz->{var}{cnx}{login} }, - { - label => N("Account Password"), val => \$wiz->{var}{cnx}{passwd}, hidden => 1 }, - ); - } - }, - post => sub { - my $netc = $wiz->{var}{netc}; - if ($netc->{vpivci}) { - my %h = (N("Belgium") => '8_35' , - N("France") => '8_35' , - N("Italy") => '8_35' , - N("Netherlands") => '8_48' , - N("United Kingdom") => '0_38' , - N("United States") => '8_35', - ); - $netc->{vpivci} = $h{$netc->{vpivci}}; - } - }, - - cable => - { - name => N("Connect to the Internet") . "\n\n" . - N("Which dhcp client do you want to use ? (default is dhcp-client)"), - data => - [ { val => \$netcnx->{dhcp_client}, list => ["dhcp-client", "dhcpcd", "dhcpxd"] } ], - - post => sub { - $netcnx->{type} = $type = 'cable'; - $in->do_pkgs->install($netcnx->{dhcp_client}); - write_cnx_script($netc, "cable", qq( -/sbin/ifup $netc->{NET_DEVICE} -), - qq( -/sbin/ifdown $netc->{NET_DEVICE} -), $netcnx->{type}); - return "go_ethernet"; - }, - }, - - go_ethernet => - { - pre => sub { - # my ($netc, $intf, $type, $ipadr, $netadr, $first_time) = @_; - conf_network_card($netc, $intf, $type, $ipadr, $netadr) or return; - $netc->{NET_INTERFACE} = $netc->{NET_DEVICE}; - configureNetwork($netc, $intf, $first_time) or return; - }, - }, - - isdn => - { - pre=> sub { - detect($netc->{autodetect}, 'isdn') if !$::isInstall && !$netc->{autodetection}; - # FIXME: offer to pick any card from values %{$netc->{autodetect}{isdn}} - $isdn = top(values %{$netc->{autodetect}{isdn}}); - isdn_step_1: - defined $isdn->{id} and goto intern_pci; - }, - # !intern_pci: - name => N("What kind is your ISDN connection?"), - data => [ { val => \$isdn_type, type => "list", list => [ N_("Internal ISDN card"), N_("External ISDN modem") ], } ], - post => sub { - if ($isdn_type =~ /card/) { - intern_pci: - $netc->{isdntype} = 'isdn_internal'; - $netcnx->{isdn_internal} = $isdn; - $netcnx->{isdn_internal} = isdn_read_config($netcnx->{isdn_internal}); - isdn_detect($netcnx->{isdn_internal}, $netc) or goto isdn_step_1; - } else { - $netc->{isdntype} = 'isdn_external'; - $netcnx->{isdn_external}{device} = $netc->{autodetect}{modem}; - $netcnx->{isdn_external} = isdn_read_config($netcnx->{isdn_external}); - $netcnx->{isdn_external}{special_command} = 'AT&F&O2B40'; - require network::modem; - $modem = $netcnx->{isdn_external}; - return &$ppp_first_step->(); - }; - - }, - }, - - isdn_detect => - { - pre => sub { - my ($isdn, $netc) = @_; - if ($isdn->{id}) { - log::explanations("found isdn card : $isdn->{description}; vendor : $isdn->{vendor}; id : $isdn->{id}; driver : $isdn->{driver}\n"); - $isdn->{description} =~ s/\|/ -- /; - - isdn_detect_step_0: - defined $isdn->{type} and my $new = $in->ask_yesorno(N("ISDN Configuration"), N("Do you want to start a new configuration ?"), 1); - - if ($isdn->{type} eq '' || $new) { - isdn_ask($isdn, $netc, N("I have detected an ISDN PCI card, but I don't know its type. Please select a PCI card on the next screen.")) or goto isdn_detect_step_0; - } else { - isdn_detect_step_1: - $isdn->{protocol} = isdn_ask_protocol() or goto isdn_detect_step_0; - isdn_detect_step_2: - isdn_ask_info($isdn, $netc) or goto isdn_detect_step_1; - isdn_write_config($isdn, $netc) or goto isdn_detect_step_2; - } - } else { - isdn_ask($isdn, $netc, N("No ISDN PCI card found. Please select one on the next screen.")) or return; - } - $netc->{$_} = 'ippp0' foreach 'NET_DEVICE', 'NET_INTERFACE'; - 1; - } - }, - - winmodem => - { - pre => sub { - my ($in, $netcnx, $mouse, $netc) = @_; - my %relocations = (ltmodem => $in->do_pkgs->check_kernel_module_packages('ltmodem')); - my $type; - - detect($netc->{autodetect}, 'lan') if !$::isInstall && !$netc->{autodetection}; - $netc->{autodetect}{winmodem} or ($in->ask_warn(N("Warning"), N("You don't have any winmodem")) ? return 1 : $in->exit(0)); - - foreach (keys %{$netc->{autodetect}{winmodem}}) { - /Hcf/ and $type = "hcfpcimodem"; - /Hsf/ and $type = "hsflinmodem"; - /LT/ and $type = "ltmodem"; - $relocations{$type} || $type && $in->do_pkgs->what_provides($type) or $type = undef; - } - - $type or ($in->ask_warn(N("Warning"), N("Your modem isn't supported by the system. -Take a look at http://www.linmodems.org")) ? return 1 : $in->exit(0)); - my $e = $in->ask_from_list(N("Title"), N("\"%s\" based winmodem detected, do you want to install needed software ?", $type), [N("Install rpm"), N("Do nothing")]) or return 0; - if ($e =~ /rpm/) { - if ($in->do_pkgs->install($relocations{$type} ? @{$relocations{$type}} : $type)) { - unless ($::isInstall) { - #- fallback to modem configuration (beware to never allow test it). - $netcnx->{type} = 'modem'; - #$type eq 'ltmodem' and $netc->{autodetect}{modem} = '/dev/ttyS14'; - return configure($in, $netcnx, $mouse, $netc); - } - } else { - return 0; - } - } - return 1; - }, - }, - - no_winmodem => - { - name => N("Warning") . "\n\n" . N("You don't have any winmodem"), - }, - - no_supported_winmodem => - { - name => N("Warning") . "\n\n" . N("Your modem isn't supported by the system. -Take a look at http://www.linmodems.org") - }, - - - - - modem => - { - pre => sub { - my ($in, $netcnx, $mouse, $netc) = @_; - $netcnx->{type} = 'modem'; - my $modem = $netcnx->{$netcnx->{type}}; - $modem->{device} = $netc->{autodetect}{modem}; - my %l = getVarsFromSh("$::prefix/usr/share/config/kppprc"); - $modem->{connection} = $l{Name}; - $modem->{domain} = $l{Domain}; - ($modem->{dns1}, $modem->{dns2}) = split(',', $l{DNS}); - - foreach (cat_("/etc/sysconfig/network-scripts/chat-ppp0")) { - /.*ATDT(\d*)/ and $modem->{phone} = $1; - } - foreach (cat_("/etc/sysconfig/network-scripts/ifcfg-ppp0")) { - /NAME=(['"]?)(.*)\1/ and $modem->{login} = $2; - } - my $secret = network::tools::read_secret_backend(); - foreach (@$secret) { - $modem->{passwd} = $_->{passwd} if $_->{login} eq $modem->{login}; - } - - return &$ppp_first_step->(); - }, - }, - - # FIXME: only if $need_to_ask - ppp_choose => - { - pre => sub { - $mouse ||= {}; - $mouse->{device} ||= readlink "$::prefix/dev/mouse"; - write_cnx_script($netc, "modem", join("\n", if_($::testing, "/sbin/route del default"), "ifup ppp0"), - q(ifdown ppp0 -killall pppd -), $netcnx->{type}); - my $need_to_ask = $modem->{device} || !$netc->{autodetect}{winmodem}; - }, - - name => N("Please choose which serial port your modem is connected to."), - interactive_help_id => 'selectSerialPort', - data => [ { var => \$modem->{device}, format => \&mouse::serial_port2text, type => "list", - list => [ grep { $_ ne $o_mouse->{device} } (if_(-e '/dev/modem', '/dev/modem'), mouse::serial_ports()) ] } ], - - next => "ppp_choose2", - }, - - ppp_choose2 => - { - pre => sub { - #my $secret = network::tools::read_secret_backend(); - #my @cnx_list = map { $_->{server} } @$secret; - }, - name => N("Dialup options"), - data => [ - { label => N("Connection name"), val => \$modem->{connection} }, - { label => N("Phone number"), val => \$modem->{phone} }, - { label => N("Login ID"), val => \$modem->{login} }, - { label => N("Password"), val => \$modem->{passwd}, hidden => 1 }, - { label => N("Authentication"), val => \$modem->{auth}, list => [ N_("PAP"), N_("Terminal-based"), N_("Script-based"), N_("CHAP") ] }, - { label => N("Domain name"), val => \$modem->{domain} }, - { label => N("First DNS Server (optional)"), val => \$modem->{dns1} }, - { label => N("Second DNS Server (optional)"), val => \$modem->{dns2} }, - ], - post => sub { - network::modem::ppp_configure($in, $netc, $modem); - $netc->{$_} = 'ppp0' foreach 'NET_DEVICE', 'NET_INTERFACE'; - &$next_cnx_step->(); - }, - }, - - - lan_standalone => - { - pre => sub { - detect($netc->{autodetect}, 'lan') if !$::isInstall; - modules::interactive::load_category($in, 'network/main|gigabit|usb|pcmcia', !$::expert, 1); - @all_cards = network::ethernet::conf_network_card_backend($netc, $intf); - @cards = map { $_->[0] } @all_cards; - foreach my $card (@all_cards) { - modules::remove_alias($card->[1]); - modules::add_alias($card->[0], $card->[1]); - } - }, - name => N("Select the network interface to configure:"), - data => [ { label => N("Net Device"), val => \$ntf_name, list => [ detect_devices::getNet() ], allow_empty_list => 1 } ], - post => sub { - delete $ethntf->{$_} foreach keys %$ethntf; - add2hash($ethntf, $intf->{$ntf_name}); - return 'lan'; - }, - }, - - - # FIXME: is_install: no return for each card "last step" because of manual popping - # better construct an hash of { current_netintf => next_step } which next_step = last_card ? next_eth_step : next_card ? - lan => - { - pre => sub { - # FIXME: set $module - $net_device = $netc->{NET_DEVICE}; - if ($net_device eq $ethntf->{DEVICE}) { - $text = N("WARNING: this device has been previously configured to connect to the Internet. -Simply accept to keep this device configured. -Modifying the fields below will override this configuration."); - } else { - $text = N("Please enter the IP configuration for this machine. -Each item should be entered as an IP address in dotted-decimal -notation (for example, 1.2.3.4)."); - } - $auto_ip = $ethntf->{BOOTPROTO} !~ /static/; - $onboot = $ethntf->{ONBOOT} ? $ethntf->{ONBOOT} =~ /yes/ : bool2yesno(!member($ethntf->{DEVICE}, - map { $_->{device} } detect_devices::pcmcia_probe())); - $needhostname = $ethntf->{NEEDHOSTNAME} !~ /no/; - $hotplug = $::isStandalone && !$ethntf->{MII_NOT_SUPPORTED} || 1; - $track_network_id = $::isStandalone && $ethntf->{HWADDR} || detect_devices::isLaptop(); - delete $ethntf->{NETWORK}; - delete $ethntf->{BROADCAST}; - @fields = qw(IPADDR NETMASK); - }, - name => sub { N("Configuring network device %s", $ethntf->{DEVICE}) . ($module ? N(" (driver %s)", $module) : '') . "\n\n" . $text }, - data => sub { - [ { label => N("Automatic IP"), val => \$auto_ip, type => "bool", text => N("(bootp/dhcp/zeroconf)") }, - { label => N("IP address"), val => \$ethntf->{IPADDR}, disabled => sub { $auto_ip } }, - { label => N("Netmask"), val => \$ethntf->{NETMASK}, disabled => sub { $auto_ip } }, - { label => N("DHCP host name"), val => \$ethntf->{DHCP_HOSTNAME}, disabled => sub { ! ($auto_ip && $needhostname) }, advanced => 1 }, - { text => N("Track network card id (useful for laptops)"), val => \$track_network_id, type => "bool", advanced => 1 }, - { text => N("Network Hotplugging"), val => \$hotplug, type => "bool", advanced => 1 }, - { text => N("Assign host name from DHCP address"), val => \$needhostname, type => "bool", disabled => sub { ! $auto_ip }, advanced => 1 }, - { text => N("Start at boot"), val => \$onboot, type => "bool", advanced => 1 }, - ], - }, - complete => sub { - $ethntf->{BOOTPROTO} = $auto_ip ? join('', if_($auto_ip, "dhcp")) : "static"; - $netc->{DHCP} = $auto_ip; - return 0 if $auto_ip; - if (my @bad = map_index { if_(!is_ip($ethntf->{$_}), $::i) } @fields) { - $in->ask_warn('', N("IP address should be in format 1.2.3.4")); - return 1, $bad[0]; - } - $in->ask_warn('', N("Warning : IP address %s is usually reserved !", $ethntf->{IPADDR})) if is_ip_forbidden($ethntf->{IPADDR}); - }, - focus_out => sub { - $ethntf->{NETMASK} ||= netmask($ethntf->{IPADDR}) unless $_[0] - }, - post => sub { - $ethntf->{ONBOOT} = bool2yesno($onboot); - $ethntf->{NEEDHOSTNAME} = bool2yesno($needhostname); - $ethntf->{MII_NOT_SUPPORTED} = bool2yesno(!$hotplug); - $ethntf->{HWADDR} = $track_network_id or delete $ethntf->{HWADDR}; - - #FIXME "wireless" if $ethntf->{wireless_eth}; - # FIXME: only ask for zeroconf if no dynamic host *AND* no adsl/isdn/modem (aka type being lan|wireless) - return is_dynamic_ip($intf) ? - (is_dynamic_host($ethntf) ? "dhcp_hostname" : "zeroconf") - : "static_hostname"; - }, - }, - - wireless => - { - pre => sub { - if (is_wireless_intf($module)) { - $ethntf->{wireless_eth} = 1; - $netc->{wireless_eth} = 1; - $ethntf->{WIRELESS_MODE} = "Managed"; - $ethntf->{WIRELESS_ESSID} = "any"; - } - }, - name => N("Please enter the wireless parameters for this card:"), - data => [ - { label => N("Operating Mode"), val => \$ethntf->{WIRELESS_MODE}, - list => [ keys %wireless_mode ] }, - { label => N("Netwok name (ESSID)"), val => \$ethntf->{WIRELESS_ESSID} }, - { label => N("Network ID"), val => \$ethntf->{WIRELESS_NWID} }, - { label => N("Operating frequency"), val => \$ethntf->{WIRELESS_FREQ} }, - { label => N("Sensitivity threshold"), val => \$ethntf->{WIRELESS_SENS} }, - { label => N("Bitrate (in b/s)"), val => \$ethntf->{WIRELESS_RATE} }, - { label => N("Encryption key"), val => \$ethntf->{WIRELESS_ENC_KEY} }, - { label => N("RTS/CTS"), val => \$ethntf->{WIRELESS_RTS}, - help => N("RTS/CTS adds a handshake before each packet transmission to make sure that the -channel is clear. This adds overhead, but increase performance in case of hidden -nodes or large number of active nodes. This parameters set the size of the -smallest packet for which the node sends RTS, a value equal to the maximum -packet size disable the scheme. You may also set this parameter to auto, fixed -or off.") - }, - { label => N("Fragmentation"), val => \$ethntf->{WIRELESS_FRAG} }, - { label => N("Iwconfig command extra arguments"), val => \$ethntf->{WIRELESS_IWCONFIG}, advanced => 1, - help => N("Here, one can configure some extra wireless parameters such as: -ap, channel, commit, enc, power, retry, sens, txpower (nick is already set as the hostname). - -See iwpconfig(8) man page for further information."), - }, - { label => N("Iwspy command extra arguments"), val => \$ethntf->{WIRELESS_IWSPY}, advanced => 1, - help => N("Iwspy is used to set a list of addresses in a wireless network -interface and to read back quality of link information for each of those. - -This information is the same as the one available in /proc/net/wireless : -quality of the link, signal strength and noise level. - -See iwpspy(8) man page for further information."), - }, - { label => N("Iwpriv command extra arguments"), val => \$ethntf->{WIRELESS_IWPRIV}, advanced => 1, - help => N("Iwpriv enable to set up optionals (private) parameters of a wireless network -interface. + [ + if_(@profiles > 1, { label => N("Choose the profile to configure"), val => \$netcnx->{PROFILE}, list => \@profiles }), + { label => N("Use auto detection"), val => \$netc->{autodetection}, type => 'bool' }, + if_($::isStandalone, { label => N("Expert Mode"), val => \$::expert, type => 'bool' }), + ] + ) or goto step_5; + undef $::Wizard_no_previous; + set_profile($netcnx); + if ($netc->{autodetection}) { + my $_w = $in->wait_message(N("Network Configuration Wizard"), N("Detecting devices...")); + detect($netc->{autodetect}, $::isInstall && ($in->{method} eq "ftp" || $in->{method} eq "http" || $in->{method} eq "nfs")); + } -Iwpriv deals with parameters and setting specific to each driver (as opposed to -iwconfig which deals with generic ones). + step_2: + +# my $set_default; + $conf{$_} = $netc->{autodetect}{$_} ? 1 : 0 foreach 'modem', 'winmodem', 'adsl', 'cable', 'lan'; + $conf{isdn} = $netc->{autodetect}{isdn}{description} ? 1 : 0; + + $::isInstall and $in->set_help('configureNetwork'); + my @l = ( + [N("Normal modem connection") . if_($netc->{autodetect}{modem}, " - " . N("detected on port %s", $netc->{autodetect}{modem})), \$conf{modem}], + [N("Winmodem connection") . if_($netc->{autodetect}{winmodem}, " - " . N("detected")), \$conf{winmodem}], + [N("ISDN connection") . if_($netc->{autodetect}{isdn}{description}, " - " . N("detected %s", $netc->{autodetect}{isdn}{description})), \$conf{isdn}], + [N("ADSL connection") . if_($netc->{autodetect}{adsl}, " - " . N("detected")), \$conf{adsl}], + [N("Cable connection") . if_($netc->{autodetect}{cable}, " - " . N("cable connection detected")), \$conf{cable}], + [N("LAN connection") . if_($netc->{autodetect}{lan}, " - " . N("ethernet card(s) detected")), \$conf{lan}] + ); + $::isInstall and $in->set_help('configureNetwork'); + $in->ask_from(N("Network Configuration Wizard"), N("Choose the connection you want to configure"), + [ map { { label => $_->[0], val => $_->[1], type => 'bool' } } @l ], + changed => sub { + return if !$netc->{autodetection}; + my $c = 0; + #- $conf{adsl} and $c++; + $conf{cable} and $c++; + my $a = keys(%{$netc->{autodetect}{lan}}); + 0 < $a && $a <= $c and $conf{lan} = undef; + } + ) or goto step_1; + load_conf($netcnx, $netc, $intf); + $conf{modem} and do { pre_func("modem"); require network::modem; network::modem::configure($netcnx, $mouse, $netc, $intf) or goto step_2 }; + $conf{winmodem} and do { pre_func("winmodem"); require network::modem; network::modem::winmodemConfigure($netc) or goto step_2 }; + $conf{isdn} and do { pre_func("isdn"); require network::isdn; network::isdn::configure($netcnx, $netc, $isdn) or goto step_2 }; + $conf{adsl} and do { pre_func("adsl"); require network::adsl; network::adsl::configure($netcnx, $netc, $intf, $first_time) or goto step_2 }; + $conf{cable} and do { pre_func("cable"); require network::ethernet; network::ethernet::configure_cable($netcnx, $netc, $intf, $first_time) or goto step_2; $netconnect::need_restart_network = 1 }; + $conf{lan} and do { pre_func("local network"); require network::ethernet; network::ethernet::configure_lan($netcnx, $netc, $intf, $first_time) or goto step_2; $netconnect::need_restart_network = 1 }; + + step_2_1: + my $nb = keys %{$netc->{internet_cnx}}; + if ($nb < 1) { + } elsif ($nb > 1) { + $in->ask_from(N("Network Configuration Wizard"), + N("You have configured multiple ways to connect to the Internet.\nChoose the one you want to use.\n\n") . if_(!$::isStandalone, "You may want to configure some profiles after the installation, in the Mandrake Control Center"), + [ { label => N("Internet connection"), val => \$netc->{internet_cnx_choice}, list => [ keys %{$netc->{internet_cnx}} ] } ] + ) or goto step_2; + } elsif ($nb == 1) { + $netc->{internet_cnx_choice} = (keys %{$netc->{internet_cnx}})[0]; + } + member($netc->{internet_cnx_choice}, ('adsl', 'isdn')) and + $netc->{at_boot} = $in->ask_yesorno(N("Network Configuration Wizard"), N("Do you want to start the connection at boot?")); + if ($netc->{internet_cnx_choice}) { + write_cnx_script($netc); + $netcnx->{type} = $netc->{internet_cnx}{$netc->{internet_cnx_choice}}{type}; + } else { + unlink "$prefix/etc/sysconfig/network-scripts/net_cnx_up"; + unlink "$prefix/etc/sysconfig/network-scripts/net_cnx_down"; + undef $netc->{NET_DEVICE}; + } -In theory, the documentation of each device driver should indicate how to use -those interface specific commands and their effect. + my $success = 1; + network::configureNetwork2($in, $prefix, $netc, $intf); + my $network_configured = 1; + + if ($netconnect::need_restart_network && $::isStandalone and ($::expert or $in->ask_yesorno(N("Network configuration"), + N("The network needs to be restarted"), 1))) { +#- run_program::rooted($prefix, "/etc/rc.d/init.d/network stop"); + if (!run_program::rooted($prefix, "/etc/rc.d/init.d/network restart")) { + $success = 0; + $in->ask_okcancel(N("Network Configuration"), N("A problem occured while restarting the network: \n\n%s", `/etc/rc.d/init.d/network restart`), 0); + } + } -See iwpriv(8) man page for further information."), - } - ], - complete => sub { - if ($ethntf->{WIRELESS_FREQ} !~ /[0-9.]*[kGM]/) { - $in->ask_warn('', N("Freq should have the suffix k, M or G (for example, \"2.46G\" for 2.46 GHz frequency), or add enough '0' (zeroes).")); - return 1, 6; - } - if ($ethntf->{WIRELESS_RATE} !~ /[0-9.]*[kGM]/) { - $in->ask_warn('', N("Rate should have the suffix k, M or G (for example, \"11M\" for 11M), or add enough '0' (zeroes).")); - return 1, 8; - } - }, - post => sub { - # untranslate parameters - $ethntf->{WIRELESS_MODE} = $wireless_mode{$ethntf->{WIRELESS_MODE}}; - }, - }, - - conf_network_card => - { - pre => sub { - # my ($netc, $intf, $type, $ipadr, $o_netadr) = @_; - #-type =static or dhcp - modules::interactive::load_category($in, 'network/main|gigabit|usb', !$::expert, 1); - @all_cards = conf_network_card_backend($netc, $intf, $type, undef, $ipadr, $netadr) or - # FIXME: fix this - $in->ask_warn('', N("No ethernet network adapter has been detected on your system. -I cannot set up this connection type.")), return; - - }, - name => N("Choose the network interface") . "\n\n" . - N("Please choose which network adapter you want to use to connect to Internet."), - data => [ { var => \$interface, type => "list", list => \@all_cards, } ], - format => sub { my ($e) = @_; $e->[0] . ($e->[1] ? " (using module $e->[1])" : "") }, - - post => sub { - modules::write_conf() if $::isStandalone; - my $_device = conf_network_card_backend($netc, $intf, $type, $interface->[0], $ipadr, $netadr); - return "lan"; - }, - }, - - static_hostname => - { - pre => sub { - my ($in, $netc, $intf, @devices) = @_; - - $netc->{dnsServer} ||= dns($intf->{IPADDR}); - $gateway_ex = gateway($intf->{IPADDR}); - #- $netc->{GATEWAY} ||= gateway($intf->{IPADDR}); - }, - name => N("Please enter your host name. -Your host name should be a fully-qualified host name, -such as ``mybox.mylab.myco.com''. -You may also enter the IP address of the gateway if you have one."), - data => - [ { label => N("Host name"), val => \$netc->{HOSTNAME} }, - { label => N("DNS server"), val => \$netc->{dnsServer} }, - { label => N("Gateway (e.g. %s)", $gateway_ex), val => \$netc->{GATEWAY} }, - if_(@devices > 1, - { label => N("Gateway device"), val => \$netc->{GATEWAYDEV}, list => \@devices }, - ), - ], - complete => sub { - if ($netc->{dnsServer} && !is_ip($netc->{dnsServer})) { - $in->ask_warn('', N("DNS server address should be in format 1.2.3.4")); - return 1; - } - if ($netc->{GATEWAY} && !is_ip($netc->{GATEWAY})) { - $in->ask_warn('', N("Gateway address should be in format 1.2.3.4")); - return 1; - } - }, - next => "miscellaneous_choose", - }, - - dhcp_hostname => - { - }, - - zeroconf => - { - name => N("Enter a Zeroconf host name which will be the one that your machine will get back to other machines on the network:"), - data => [ { label => N("Zeroconf Host name"), val => \$netc->{ZEROCONF_HOSTNAME} } ], - complete => sub { - if ($netc->{ZEROCONF_HOSTNAME} =~ /\./) { - $in->ask_warn('', N("Zeroconf host name must not contain a .")); - return 1; - } - }, - next => "miscellaneous_choose", - }, - - multiple_internet_cnx => - { - pre => sub { - my $nb = keys %{$netc->{internet_cnx}}; - if ($nb > 1) { - # BUG: remember to remove reference to profiles in mcc if we do not restore this feature - $in->ask_from("", - N("You have configured multiple ways to connect to the Internet.\nChoose the one you want to use.\n\n") . if_(!$::isStandalone, "You may want to configure some profiles after the installation, in the Mandrake Control Center"), - [ { label => N("Internet connection"), val => \$netc->{internet_cnx_choice}, list => [ keys %{$netc->{internet_cnx}} ] } ] - ) or goto step_2; - } elsif ($nb == 1) { - $netc->{internet_cnx_choice} = (keys %{$netc->{internet_cnx}})[0]; - } - }, - post => sub { $::isInstall ? "miscellaneous_choose" : "apply_settings" }, - }, - - miscellaneous_choose => - { - name => N("Proxies configuration"), - data => [ - { label => N("HTTP proxy"), val => \$::o->{miscellaneous}->{http_proxy} }, - { label => N("FTP proxy"), val => \$::o->{miscellaneous}->{ftp_proxy} }, - ], - complete => sub { - if ($::o->{miscellaneous}->{http_proxy} !~ m,^($|http://),) { - $in->ask_warn('', N("Proxy should be http://...")); - return 1, 0; - } - if ($::o->{miscellaneous}->{ftp_proxy} !~ m,^($|ftp://|http://),) { - $in->ask_warn('', N("URL should begin with 'ftp:' or 'http:'")); - return 1, 1; - } - 0; - }, - # FIXME: call ether_conf(); - post => sub { return !$::isInstall ? "apply_settings" : "network_on_boot" }, - }, - - apply_settings => - { - name => N("Configuration is complete, do you want to apply settings ?"), - data => [], # FIXME: yesorno - next => "network_on_boot", - }, - - network_on_boot => - { - pre => sub { - member($netc->{internet_cnx_choice}, ('adsl', 'isdn')) and $netc->{at_boot} = $in->ask_yesorno(N("Network Configuration Wizard"), N("Do you want to start the connection at boot?")); - - if ($netc->{internet_cnx_choice}) { - write_cnx_script($netc); - $netcnx->{type} = $netc->{internet_cnx}{$netc->{internet_cnx_choice}}{type}; - } else { - unlink "$::prefix/etc/sysconfig/network-scripts/net_cnx_up"; - unlink "$::prefix/etc/sysconfig/network-scripts/net_cnx_down"; - undef $netc->{NET_DEVICE}; - } - - network::network::configureNetwork2($in, $::prefix, $netc, $intf); - $network_configured = 1; - }, - name => N("Do you want to start the connection at boot?"), - data => [], # FIXME yes/no - }, + write_initscript(); + $::isStandalone && member($netc->{internet_cnx_choice}, ('modem', 'adsl', 'isdn')) and + $success = ask_connect_now($netc->{internet_cnx_choice}); - restart => - { - # FIXME: condition is "if ($netconnect::need_restart_network && $::isStandalone && (!$::expert || $in->ask_yesorno(..." - name => N("The network needs to be restarted. Do you want to restart it ?"), - # data => [ { label => N("Connection:"), val => \$type, type => 'list', list => [ sort values %l ] }, ], - post => sub { - if (!$::testing && !run_program::rooted($::prefix, "/etc/rc.d/init.d/network restart")) { - $success = 0; - $in->ask_okcancel(N("Network Configuration"), - N("A problem occured while restarting the network: \n\n%s", `/etc/rc.d/init.d/network restart`), 0); - } - write_initscript(); - return $::isStandalone && member($netc->{internet_cnx_choice}, qw(modem adsl isdn)) ? "ask_connect_now" : "end"; - }, - }, - - ask_connect_now => - { - no_back => 1, - name => N("Do you want to try to connect to the Internet now?"), - data => [], # FIXME: yes/no - post => sub { - my ($a) = @_; - my ($type) = $netc->{internet_cnx_choice}; - $up = 1; - #- FIXME : code the exception to be generated by ask_yesorno, to be able to remove the $::Wizard_no_previous=1; - if ($a) { - # local $::isWizard = 0; - my $_w = $in->wait_message('', N("Testing your connection..."), 1); - connect_backend(); - my $s = 30; - $type =~ /modem/ and $s = 50; - $type =~ /adsl/ and $s = 35; - $type =~ /isdn/ and $s = 20; - sleep $s; - $up = connected(); - } - $success = $up; - return $a ? "disconnect" : "end"; - } - }, - disconnect => - { - name => sub { - $up ? N("The system is now connected to the Internet.") . - if_($::isInstall, N("For security reasons, it will be disconnected now.")) : - N("The system doesn't seem to be connected to the Internet. -Try to reconfigure your connection."); - }, - no_back => 1, - end => 1, - post => sub { - $::isInstall and disconnect_backend(); - return "end"; - }, - }, + step_3: - end => - { - name => sub { - return $success ? join('', N("Congratulations, the network and Internet configuration is finished. + my $m = $success ? N("Congratulations, the network and Internet configuration is finished. +The configuration will now be applied to your system. -"), if_($::isStandalone && $in->isa('interactive::gtk'), - N("After this is done, we recommend that you restart your X environment to avoid any hostname-related problems."))) : - N("Problems occured during configuration. +") . if_($::isStandalone && $in->isa('interactive_gtk'), +N("After this is done, we recommend that you restart your X environment to avoid any hostname-related problems.")) : + N("Problems occured during configuration. Test your connection via net_monitor or mcc. If your connection doesn't work, you might want to relaunch the configuration."); - }, - end => 1, - }, - }, - }; - - my $use_wizard = 1; - if ($::isInstall) { - if ($first_time && $in->{method} =~ /^(ftp|http|nfs)$/) { - !$::expert && !$o_noauto || $in->ask_okcancel(N("Network Configuration"), - N("Because you are doing a network installation, your network is already configured. -Click on Ok to keep your configuration, or cancel to reconfigure your Internet & Network connection. -"), 1) - and do { - $netcnx->{type} = 'lan'; - output_with_perm("$::prefix$connect_file", 0755, qq(ifup eth0 -)); - output("$::prefix$disconnect_file", 0755, qq( -ifdown eth0 -)); - $direct_net_install = 1; - $use_wizard = 0; - }; - } else { - $wiz->{pages}{welcome} = $wiz->{pages}{install}; - } - } else { - $wiz->{pages}{welcome} = $wiz->{pages}{connection}; - }; - - if ($use_wizard) { - require wizards; - $wiz->{var} = { - netc => $o_netc || {}, - mouse => $o_mouse || {}, - intf => $o_intf || {}, - }; - wizards->new->safe_process($wiz, $in); - } + if ($::isWizard) { + $::Wizard_no_previous = 1; + $::Wizard_finished = 1; + $in->ask_okcancel(N("Network Configuration"), $m, 1); + undef $::Wizard_no_previous; + undef $::Wizard_finished; + } else { $::isStandalone and $in->ask_warn('', $m) } - # install needed packages: - $network_configured or network::network::configureNetwork2($in, $::prefix, $netc, $intf); + step_5: + + $network_configured or network::configureNetwork2($in, $prefix, $netc, $intf); my $connect_cmd; if ($netcnx->{type} =~ /modem/ || $netcnx->{type} =~ /isdn_external/) { $connect_cmd = qq( #!/bin/bash if [ -n "\$DISPLAY" ]; then - if [ -e /usr/bin/kppp ]; then - /sbin/route del default - /usr/bin/kppp & - else - /usr/sbin/net_monitor --connect - fi - else - $connect_file +if [ -e /usr/bin/kppp ]; then +/sbin/route del default +/usr/bin/kppp & +else +/usr/sbin/net_monitor --connect +fi +else +$connect_file fi ); } elsif ($netcnx->{type}) { $connect_cmd = qq( #!/bin/bash if [ -n "\$DISPLAY" ]; then - /usr/sbin/net_monitor --connect +/usr/sbin/net_monitor --connect else - $connect_file +$connect_file fi ); } else { @@ -947,15 +300,18 @@ fi $connect_cmd = qq( #!/bin/bash if [ -n "\$DISPLAY" ]; then - /usr/sbin/net_monitor --connect +/usr/sbin/net_monitor --connect else - $connect_file +$connect_file fi ); } output_with_perm("$prefix$connect_prog", 0755, $connect_cmd) if $connect_cmd; $netcnx->{$_} = $netc->{$_} foreach qw(NET_DEVICE NET_INTERFACE); + + $netcnx->{NET_INTERFACE} and set_net_conf($netcnx, $netc); $netcnx->{type} =~ /adsl/ or system("/sbin/chkconfig --del adsl 2> /dev/null"); + save_conf($netcnx, $netc, $intf); if ($::isInstall && $::o->{security} >= 3) { require network::drakfirewall; @@ -963,69 +319,275 @@ fi } } -sub set_profile { - my ($netcnx) = @_; - system(qq(/sbin/set-netprofile "$netcnx->{PROFILE}")); - log::explanations(qq(Switching to "$netcnx->{PROFILE}" profile)); +sub save_conf { + my ($netcnx, $netc, $intf) = @_; + my $adsl; + my $modem; + my $isdn; + $netcnx->{type} =~ /adsl/ and $adsl = $netcnx->{$netcnx->{type}}; + $netcnx->{type} eq 'isdn_external' || $netcnx->{type} eq 'modem' and $modem = $netcnx->{$netcnx->{type}}; + $netcnx->{type} eq 'isdn_internal' and $isdn = $netcnx->{$netcnx->{type}}; + modules::load_category('network/main|usb'); + require network::ethernet; + network::ethernet->import; + my @_all_cards = conf_network_card_backend($netc, $intf, undef, undef, undef, undef); + + $intf = { %$intf }; +# "SystemName=" . do { $netc->{HOSTNAME} =~ /([^\.]*)\./; $1 } . " +#DomainName=" . do { $netc->{HOSTNAME} =~ /\.(.*)/; $1 } . " +#InternetAccessType=" . do { if ($netcnx->{type}) { $netcnx->{type} } else { $netc->{GATEWAY} ? "lan" : "" } } . " +#InternetInterface=" . ($netc->{GATEWAY} && (!$netcnx->{type} || $netcnx->{type} eq 'lan') ? $netc->{GATEWAYDEV} : $netcnx->{NET_INTERFACE}) . " +# InternetGateway=$netc->{GATEWAY} +# DNSPrimaryIP=$netc->{dnsServer} +# DNSSecondaryIP=$netc->{dnsServer2} +# DNSThirdIP=$netc->{dnsServer3} +# AdminInterface= + +# " . join ('', map { +# "Eth${_}Known=" . ($intf->{"eth$_"}{DEVICE} eq "eth$_" ? 'true' : 'false') . " +# Eth${_}IP=" . $intf->{"eth$_"}{IPADDR} . " +# Eth${_}Mask=" . $intf->{"eth$_"}{NETMASK} . " +# Eth${_}Mac= +# Eth${_}BootProto=" . $intf->{"eth$_"}{BOOTPROTO} . " +# Eth${_}OnBoot=" . $intf->{"eth$_"}{ONBOOT} . " +# Eth${_}Hostname=$netc->{HOSTNAME} +# Eth${_}HostAlias=" . do { $netc->{HOSTNAME} =~ /([^\.]*)\./; $1 } . " +# Eth${_}Driver=$all_cards[$_][1] +# Eth${_}Irq= +# Eth${_}Port= +# Eth${_}DHCPClient=" . ($intf->{"eth$_"}{BOOTPROTO} eq 'dhcp' ? $netcnx->{dhcp_client} : '') . " +# Eth${_}DHCPServerName=" . ($intf->{"eth$_"}{BOOTPROTO} eq 'dhcp' ? $netc->{HOSTNAME} : '') . "\n" +# } (0..9)) . +# ISDNDriver=$isdn->{driver} +# ISDNDeviceType=$isdn->{type} +# ISDNIrq=$isdn->{irq} +# ISDNMem=$isdn->{mem} +# ISDNIo=$isdn->{io} +# ISDNIo0=$isdn->{io0} +# ISDNIo1=$isdn->{io1} +# ISDNProtocol=$isdn->{protocol} +# ISDNCardDescription=$isdn->{description} +# ISDNCardVendor=$isdn->{vendor} +# ISDNId=$isdn->{id} +# ISDNProvider=$netc->{DOMAINNAME2} +# ISDNProviderPhone=$isdn->{phone_out} +# ISDNProviderDomain=" . do { $netc->{DOMAINNAME2} =~ /\.(.*)/; $1 } . " +# ISDNProviderDNS1=$netc->{dnsServer2} +# ISDNProviderDNS2=$netc->{dnsServer3} +# ISDNDialing=$isdn->{dialing_mode} +# ISDNSpeed=$isdn->{speed} +# ISDNTimeout=$isdn->{huptimeout} +# ISDNHomePhone=$isdn->{phone_in} +# ISDNLogin=$isdn->{login} +# ISDNPassword=$isdn->{passwd} +# ISDNConfirmPassword=$isdn->{passwd2} +# PPPProviderPhone=$modem->{phone} +# PPPProviderDNS1=$modem->{dns1} +# PPPProviderDNS2=$modem->{dns2} +# PPPPassword=$modem->{passwd} +# PPPConfirmPassword=$modem->{passwd} +# ADSLProviderDNS1=$netc->{dnsServer2} +# ADSLProviderDNS2=$netc->{dnsServer3} + + my $str; + $str .= " +PPPDevice=$modem->{device} +PPPDeviceSpeed= +PPPConnectionName=$modem->{connection} +PPPProviderDomain=$modem->{domain} +PPPLogin=$modem->{login} +PPPAuthentication=$modem->{auth} +PPPSpecialCommand=" . ($netcnx->{type} eq 'isdn_external' ? $netcnx->{isdn_external}{special_command} : '') if $conf{modem}; + + $str .= " +ADSLInterfacesList= +ADSLModem=" . q( # Obsolete information. Please don't use it.) . " +ADSLType=" . ($netcnx->{type} =~ /adsl/ ? $netcnx->{type} : '') . " +ADSLProviderDomain=$netc->{DOMAINNAME2} +ADSLLogin=$adsl->{login} +" . #ADSLPassword=$adsl->{passwd} +"DOMAINNAME2=$netc->{DOMAINNAME2}" if $conf{adsl}; + + output_with_perm("$prefix/etc/sysconfig/network-scripts/drakconnect_conf", 0600, $str); + my $a = $netcnx->{PROFILE} ? $netcnx->{PROFILE} : "default"; + cp_af("$prefix/etc/sysconfig/network-scripts/drakconnect_conf", "$prefix/etc/sysconfig/network-scripts/drakconnect_conf." . $a); + chmod 0600, "$prefix/etc/sysconfig/network-scripts/drakconnect_conf"; + chmod 0600, "$prefix/etc/sysconfig/network-scripts/drakconnect_conf." . $a; + foreach (["$prefix$connect_file", "up"], + ["$prefix$disconnect_file", "down"], + ["$prefix$connect_prog", "prog"], + ["$prefix/etc/ppp/ioptions1B", "iop1B"], + ["$prefix/etc/ppp/ioptions2B", "iop2B"], + ["$prefix/etc/isdn/isdn1B.conf", "isdn1B"], + ["$prefix/etc/isdn/isdn2B.conf", "isdn2B"], + ["$prefix/etc/resolv.conf", "resolv"], + ["$prefix/etc/ppp/peers/adsl", "speedtouch"], + ["$prefix/etc/ppp/peers/adsl", "eci"], + ) { + my $file = "$prefix/etc/sysconfig/network-scripts/net_" . $_->[1] . "." . $a; + -e ($_->[0]) and cp_af($_->[0], $file) and chmod 0755, $file; + } } -sub save_profile { - my ($netcnx) = @_; - system(qq(/sbin/save-netprofile "$netcnx->{PROFILE}")); - log::explanations(qq(Saving "$netcnx->{PROFILE}" profile)); +sub set_profile { + my ($netcnx, $profile) = @_; + $profile ||= $netcnx->{PROFILE}; + $profile or return; + my $f = "$prefix/etc/sysconfig/network-scripts/drakconnect_conf"; + -e ($f . "." . $profile) or return; + $netcnx->{PROFILE} = $profile; + cp_af($f . "." . $profile, $f); + foreach (["$prefix$connect_file", "up"], + ["$prefix$disconnect_file", "down"], + ["$prefix$connect_prog", "prog"], + ["$prefix/etc/ppp/ioptions1B", "iop1B"], + ["$prefix/etc/ppp/ioptions2B", "iop2B"], + ["$prefix/etc/isdn/isdn1B.conf", "isdn1B"], + ["$prefix/etc/isdn/isdn2B.conf", "isdn2B"], + ["$prefix/etc/resolv.conf", "resolv"], + ["$prefix/etc/ppp/peers/adsl", "speedtouch"], + ["$prefix/etc/ppp/peers/adsl", "eci"], + ) { + my $c = "$prefix/etc/sysconfig/network-scripts/net_" . $_->[1] . "." . $profile; + -e ($c) and cp_af($c, $_->[0]); + } } sub del_profile { - my ($profile) = @_; - return if !$profile || $profile eq "default"; - rm_rf("$::prefix/etc/netprofile/profiles/$profile"); - log::explanations(qq(Deleting "$profile" profile)); + my ($_netcnx, $profile) = @_; + $profile or return; + $profile eq "default" and return; + rm_rf("$prefix/etc/sysconfig/network-scripts/drakconnect_conf." . $profile); + rm_rf(glob_("$prefix/etc/sysconfig/network-scripts/net_{up,down,prog,iop1B,iop2B,isdn1B,isdn2B,resolv,speedtouch}." . $profile)); } sub add_profile { my ($netcnx, $profile) = @_; - return if !$profile || $profile eq "default" || member($profile, get_profiles()); - system(qq(/sbin/clone-netprofile "$netcnx->{PROFILE}" "$profile")); - log::explanations(qq("Creating "$profile" profile)); + $profile or return; + $profile eq "default" and return; + my $cmd1 = "$prefix/etc/sysconfig/network-scripts/drakconnect_conf." . ($netcnx->{PROFILE} ? $netcnx->{PROFILE} : "default"); + my $cmd2 = "$prefix/etc/sysconfig/network-scripts/drakconnect_conf." . $profile; + cp_af($cmd1, $cmd2); } -sub get_profiles() { - map { if_(m!([^/]*)/$!, $1) } glob("$::prefix/etc/netprofile/profiles/*/"); +sub get_profiles { + map { if_(/drakconnect_conf\.(.*)/, $1) } all("$::prefix/etc/sysconfig/network-scripts"); } + sub load_conf { my ($netcnx, $netc, $intf) = @_; - my $current = { getVarsFromSh("$prefix/etc/netprofile/current") }; - - $netcnx->{PROFILE} = $current->{PROFILE} || 'default'; - network::network::read_all_conf($prefix, $netc, $intf); + my $adsl_pptp = {}; + my $adsl_pppoe = {}; + my $modem = {}; + my $isdn_external = {}; + my $isdn = {}; + + if (-e "$prefix/etc/sysconfig/network-scripts/drakconnect_conf") { + foreach (cat_("$prefix/etc/sysconfig/network-scripts/drakconnect_conf")) { +# /^DNSPrimaryIP=(.*)$/ and $netc->{dnsServer} = $1; +# /^DNSSecondaryIP=(.*)$/ and $netc->{dnsServer2} = $1; +# /^DNSThirdIP=(.*)$/ and $netc->{dnsServer3} = $1; +# /^InternetAccessType=(.*)$/ and $netcnx->{type} = $1; +# /^InternetInterface=(.*)$/ and $netcnx->{NET_INTERFACE} = $1; +# /^InternetGateway=(.*)$/ and $netc->{GATEWAY} = $1; +# /^SystemName=(.*)$/ and $system_name = $1; +# /^DomainName=(.*)$/ and $domain_name = $1; +# /^Eth([0-9])Known=true$/ and $intf->{"eth$1"}{DEVICE} = "eth$1"; +# /^Eth([0-9])IP=(.*)$/ && $intf->{"eth$1"}{DEVICE} and $intf->{"eth$1"}{IPADDR} = $2; +# /^Eth([0-9])Mask=(.*)\n/ && $intf->{"eth$1"}{DEVICE} and $intf->{"eth$1"}{NETMASK} = $2; +# /^Eth([0-9])BootProto=(.*)\n/ && $intf->{"eth$1"}{DEVICE} and $intf->{"eth$1"}{BOOTPROTO} = $2; +# /^Eth([0-9])OnBoot=(.*)\n/ && $intf->{"eth$1"}{DEVICE} and $intf->{"eth$1"}{ONBOOT} = $2; +# /^Eth([0-9])Hostname=(.*)\n/ && $intf->{"eth$1"}{DEVICE} and $netc->{HOSTNAME} = $2; +# /^Eth([0-9])Driver=(.*)\n/ && $intf->{"eth$1"}{DEVICE} and $intf->{"eth$1"}{driver} = $2; +# /^ISDNDriver=(.*)$/ and $isdn->{driver} = $1; +# /^ISDNDeviceType=(.*)$/ and $isdn->{type} = $1; +# /^ISDNIrq=(.*)/ and $isdn->{irq} = $1; +# /^ISDNMem=(.*)$/ and $isdn->{mem} = $1; +# /^ISDNIo=(.*)$/ and $isdn->{io} = $1; +# /^ISDNIo0=(.*)$/ and $isdn->{io0} = $1; +# /^ISDNIo1=(.*)$/ and $isdn->{io1} = $1; +# /^ISDNProtocol=(.*)$/ and $isdn->{protocol} = $1; +# /^ISDNCardDescription=(.*)$/ and $isdn->{description} = $1; +# /^ISDNCardVendor=(.*)$/ and $isdn->{vendor} = $1; +# /^ISDNId=(.*)$/ and $isdn->{id} = $1; +# /^ISDNProviderPhone=(.*)$/ and $isdn->{phone_out} = $1; +# /^ISDNDialing=(.*)$/ and $isdn->{dialing_mode} = $1; +# /^ISDNISDNSpeed=(.*)$/ and $isdn->{speed} = $1; +# /^ISDNTimeout=(.*)$/ and $isdn->{huptimeout} = $1; +# /^ISDNHomePhone=(.*)$/ and $isdn->{phone_in} = $1; +# /^ISDNLogin=(.*)$/ and $isdn->{login} = $1; +# /^ISDNPassword=(.*)$/ and $isdn->{passwd} = $1; +# /^ISDNConfirmPassword=(.*)$/ and $isdn->{passwd2} = $1; + + #/^PPPDevice=(.*)$/ and $modem->{device} = $1; + /^PPPConnectionName=(.*)$/ and $modem->{connection} = $1; # Keep this for futur multiple cnx support + #/^PPPProviderPhone=(.*)$/ and $modem->{phone} = $1; + /^PPPProviderDomain=(.*)$/ and $modem->{domain} = $1; # used only for kppp + #/^PPPProviderDNS1=(.*)$/ and $modem->{dns1} = $1; # be aware that this value is now extracted from kppprc file ONLY + #/^PPPProviderDNS2=(.*)$/ and $modem->{dns2} = $1; + /^PPPLogin=(.*)$/ and $modem->{login} = $1; + #/^PPPPassword=(.*)$/ and $modem->{passwd} = $1; + /^PPPAuthentication=(.*)$/ and $modem->{auth} = $1; # We keep this because system is configured the same for both PAP and CHAP. + if (/^PPPSpecialCommand=(.*)$/) { + $netcnx->{type} eq 'isdn_external' and $netcnx->{$netcnx->{type}}{special_command} = $1; + } +# /^ADSLLogin=(.*)$/ and $adsl_pppoe->{login} = $1; +# /^ADSLPassword=(.*)$/ and $adsl_pppoe->{passwd} = $1; + /^DOMAINNAME2=(.*)$/ and $netc->{DOMAINNAME2} = $1; + } + } +# $system_name && $domain_name and $netc->{HOSTNAME} = join ('.', $system_name, $domain_name); + $adsl_pptp->{$_} = $adsl_pppoe->{$_} foreach 'login', 'passwd', 'passwd2'; + $isdn_external->{$_} = $modem->{$_} foreach 'device', 'connection', 'phone', 'domain', 'dns1', 'dns2', 'login', 'passwd', 'auth'; + $netcnx->{adsl_pptp} = $adsl_pptp; + $netcnx->{adsl_pppoe} = $adsl_pppoe; + $netcnx->{modem} = $modem; + $netcnx->{modem} = $isdn_external; + $netcnx->{isdn_internal} = $isdn; +# -e "$prefix/etc/sysconfig/network" and put_in_hash($netc, network::read_conf("$prefix/etc/sysconfig/network")); +# foreach (glob_("$prefix/etc/sysconfig/ifcfg-*")) { +# my $l = network::read_interface_conf($_); +# $intf->{$l->{DEVICE}} = $l; +# } +# my $file = "$prefix/etc/resolv.conf"; +# if (-e $file) { +# put_in_hash($netc, network::read_resolv_conf($file)); +# } + network::read_all_conf($prefix, $netc, $intf); } -sub get_net_device() { - my $connect_file = "/etc/sysconfig/network-scripts/net_cnx_up"; - my $network_file = "/etc/sysconfig/network"; - if (cat_("$prefix$connect_file") =~ /ifup/) { - if_(cat_($connect_file) =~ /^\s*ifup\s+(.*)/m, split(' ', $1)) - } elsif (cat_("$prefix$connect_file") =~ /network/) { - ${{ getVarsFromSh("$prefix$network_file") }}{GATEWAYDEV}; - } elsif (cat_("$prefix$connect_file") =~ /isdn/) { - "ippp+"; - } else { - "ppp+"; - }; +#- ensures the migration from old config files +sub read_raw_net_conf { + my ($suffix) = @_; + my $dir = "$::prefix/etc/sysconfig/network-scripts"; +# $suffix = $suffix ? ".$suffix" : ''; + rename "$dir/draknet$suffix", "$dir/drakconnect$suffix"; + getVarsFromSh("$dir/drakconnect_conf"); +} + +sub get_net_device { + ${{ read_raw_net_conf() }}{InternetInterface}; } sub read_net_conf { my ($_prefix, $netcnx, $netc) = @_; + add2hash($netcnx, { read_raw_net_conf('_conf') }); $netc->{$_} = $netcnx->{$_} foreach 'NET_DEVICE', 'NET_INTERFACE'; $netcnx->{$netcnx->{type}} ||= {}; + add2hash($netcnx->{$netcnx->{type}}, { read_raw_net_conf($netcnx->{type}) }); +} + +sub set_net_conf { + my ($netcnx, $netc) = @_; + setVarsInShMode("$prefix/etc/sysconfig/drakconnect", 0600, $netcnx, "NET_DEVICE", "NET_INTERFACE", "type", "PROFILE"); + setVarsInShMode("$prefix/etc/sysconfig/drakconnect." . $netcnx->{type}, 0600, $netcnx->{$netcnx->{type}}); #- doesn't work, don't know why + setVarsInShMode("$prefix/etc/sysconfig/drakconnect.netc", 0600, $netc); #- doesn't work, don't know why } sub start_internet { my ($o) = @_; init_globals($o, $o->{prefix}); - #- give a chance for module to be loaded using kernel-BOOT modules... - $::isStandalone or modules::load_category('network/main|gigabit|usb'); run_program::rooted($prefix, $connect_file); } @@ -1035,6 +597,9 @@ sub stop_internet { run_program::rooted($prefix, $disconnect_file); } +#--------------------------------------------- +# WONDERFULL pad +#--------------------------------------------- 1; =head1 network::netconnect::detect() diff --git a/perl-install/network/network.pm b/perl-install/network/network.pm index abd0cf486..12085f636 100644 --- a/perl-install/network/network.pm +++ b/perl-install/network/network.pm @@ -3,48 +3,38 @@ package network::network; # $Id$wir #-###################################################################################### #- misc imports #-###################################################################################### - -use strict; - use Socket; + use common; use detect_devices; use run_program; -use network::tools; use any; -use vars qw(@ISA @EXPORT); use log; +use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); -@EXPORT = qw(add2hosts addDefaultRoute configureNetwork2 dns dnsServers down_it findIntf gateway guessHostname is_ip is_ip_forbidden masked_ip netmask read_all_conf read_conf read_interface_conf read_resolv_conf resolv sethostname up_it write_conf write_resolv_conf); +@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); #-###################################################################################### #- Functions #-###################################################################################### sub read_conf { my ($file) = @_; - +{ getVarsFromSh($file) }; -} - -sub read_resolv_conf_raw { - my ($file) = @_; - $file ||= "$::prefix/etc/resolv.conf"; - { nameserver => [ cat_($file) =~ /^\s*nameserver\s+(\S+)/mg ], - search => [ if_(cat_($file) =~ /^\s*search\s+(.*)/m, split(' ', $1)) ] }; + my %netc = getVarsFromSh($file); + \%netc; } sub read_resolv_conf { my ($file) = @_; - my $resolv_conf = read_resolv_conf_raw($file); - +{ - (mapn { $_[0] => $_[1] } [ qw(dnsServer dnsServer2 dnsServer3) ], $resolv_conf->{nameserver}), - (mapn { $_[0] => $_[1] } [ qw(DOMAINNAME DOMAINNAME2 DOMAINNAME3) ], $resolv_conf->{search}), - }; + my @l = map { if_(/^\s*nameserver\s+(\S+)/, $1) } cat_($file); + + my %netc = mapn { $_[0] => $_[1] } [ qw(dnsServer dnsServer2 dnsServer3) ], \@l; + \%netc; } sub read_interface_conf { my ($file) = @_; - my %intf = getVarsFromSh($file); + my %intf = getVarsFromSh($file) or die "cannot open file $file: $!"; $intf{BOOTPROTO} ||= 'static'; $intf{isPtp} = $intf{NETWORK} eq '255.255.255.255'; @@ -52,31 +42,6 @@ sub read_interface_conf { \%intf; } -sub read_dhcpd_conf { - my ($file) = @_; - $file ||= "$::prefix/etc/dhcpd.conf"; - { option_routers => [ cat_($file) =~ /^\s*option routers\s+(\S+);/mg ], - subnet_mask => [ if_(cat_($file) =~ /^\s*option subnet-mask\s+(.*);/mg, split(' ', $1)) ], - domain_name => [ if_(cat_($file) =~ /^\s*option domain-name\s+"(.*)";/mg, split(' ', $1)) ], - domain_name_servers => [ if_(cat_($file) =~ /^\s*option domain-name-servers\s+(.*);/m, split(' ', $1)) ], - dynamic_bootp => [ if_(cat_($file) =~ /^\s*range dynamic-bootp\s+\S+\.(\d+)\s+\S+\.(\d+)\s*;/m, split(' ', $1)) ], - default_lease_time => [ if_(cat_($file) =~ /^\s*default-lease-time\s+(.*);/m, split(' ', $1)) ], - max_lease_time => [ if_(cat_($file) =~ /^\s*max-lease-time\s+(.*);/m, split(' ', $1)) ] }; -} - -sub read_tmdns_conf { - my ($file) = @_; - local *F; open F, $file or die "cannot open file $file: $!"; - local $_; - my %outf; - - while (<F>) { - ($outf{ZEROCONF_HOSTNAME}) = /^\s*hostname\s*=\s*(\w+)/ and return \%outf; - } - - \%outf; -} - sub up_it { my ($prefix, $intfs) = @_; $_->{isUp} and return foreach values %$intfs; @@ -94,24 +59,25 @@ sub down_it { sub write_conf { my ($file, $netc) = @_; - if ($netc->{HOSTNAME} && $netc->{HOSTNAME} =~ /\.(.+)$/) { - $netc->{DOMAINNAME} = $1; + if ($netc->{HOSTNAME}) { + $netc->{HOSTNAME} =~ /\.(.*)$/; + $1 and $netc->{DOMAINNAME} = $1; } - $netc->{NETWORKING} = 'yes'; - - setVarsInSh($file, $netc, qw(HOSTNAME NETWORKING GATEWAY GATEWAYDEV NISDOMAIN)); -} + ($netc->{DOMAINNAME}) ||= 'localdomain'; + add2hash($netc, { + NETWORKING => "yes", + FORWARD_IPV4 => "false", + HOSTNAME => "localhost.$netc->{DOMAINNAME}", + }); -sub write_zeroconf { - my ($file, $zhostname) = @_; - eval { substInFile { s/^\s*(hostname)\s*=.*/$1 = $zhostname/ } $file }; + setVarsInSh($file, $netc, qw(NETWORKING FORWARD_IPV4 DHCP_HOSTNAME HOSTNAME DOMAINNAME GATEWAY GATEWAYDEV NISDOMAIN)); } sub write_resolv_conf { my ($file, $netc) = @_; my %new = ( - search => [ grep { $_ } uniq(@$netc{'DOMAINNAME', 'DOMAINNAME2', 'DOMAINNAME3'}) ], + search => [ grep { $_ } uniq(@$netc{'DOMAINNAME', 'DOMAINNAME2'}) ], nameserver => [ grep { $_ } uniq(@$netc{'dnsServer', 'dnsServer2', 'dnsServer3'}) ], ); @@ -142,43 +108,32 @@ sub write_resolv_conf { my @old = map { "# nameserver $_\n" } @{$prev{nameserver}}; @new, @old; }; - output_with_perm($file, 0644, @search, @nameserver, (map { "# $_\n" } @unknown), "\n# ppp temp entry\n"); - + output($file, @search, @nameserver, (map { "# $_\n" } @unknown), "\n# ppp temp entry\n"); + #-res_init(); # reinit the resolver so DNS changes take affect 1; } else { - log::explanations("neither domain name nor dns server are configured"); + log::l("neither domain name nor dns server are configured"); 0; } } sub write_interface_conf { - my ($file, $intf, $_netc, $prefix) = @_; - - if ($intf->{HWADDR} && -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 ($file, $intf, $prefix) = @_; + 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::pcmcia_probe())), + ONBOOT => bool2yesno(!member($intf->{DEVICE}, map { $_->{device} } detect_devices::probeall())), + if_($::o->{miscellaneous}{track_network_id}, HWADDR => $hwaddr) }); - - $intf->{BOOTPROTO} =~ s/dhcp.*/dhcp/; - - setVarsInSh($file, $intf, qw(DEVICE BOOTPROTO IPADDR NETMASK NETWORK BROADCAST ONBOOT HWADDR MII_NOT_SUPPORTED), - 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), - if_($intf->{BOOTPROTO} eq "dhcp", qw(DHCP_HOSTNAME NEEDHOSTNAME)) - ); - log::explanations("written $intf->{DEVICE} interface configuration in $file"); + 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))); } sub add2hosts { @@ -190,7 +145,7 @@ sub add2hosts { my $sub_hostname = $hostname =~ /(.*?)\./ ? " $1" : ''; $l{$_} = "\t\t$hostname$sub_hostname" foreach grep { $_ } @ips; - log::explanations("writing host information to $file"); + log::l("writing host information to $file"); output($file, map { "$_$l{$_}\n" } keys %l); } @@ -203,9 +158,9 @@ sub guessHostname { write_resolv_conf("$prefix/etc/resolv.conf", $netc); - my $name = gethostbyaddr(Socket::inet_aton($intf->{IPADDR}), Socket::AF_INET()) or log::explanations("reverse name lookup failed"), return 0; + my $name = gethostbyaddr(Socket::inet_aton($intf->{IPADDR}), Socket::AF_INET()) or log::l("reverse name lookup failed"), return 0; - log::explanations("reverse name lookup worked"); + log::l("reverse name lookup worked"); add2hash($netc, { HOSTNAME => $name }); 1; @@ -218,16 +173,14 @@ sub addDefaultRoute { sub sethostname { my ($netc) = @_; - my $text; - syscall_("sethostname", $netc->{HOSTNAME}, length $netc->{HOSTNAME}) ? ($text="set sethostname to $netc->{HOSTNAME}") : ($text="sethostname failed: $!"); - log::explanations($text); + syscall_("sethostname", $netc->{HOSTNAME}, length $netc->{HOSTNAME}) or log::l("sethostname failed: $!"); } sub resolv($) { my ($name) = @_; is_ip($name) and return $name; my $a = join(".", unpack "C4", (gethostbyname $name)[4]); - #-log::explanations("resolved $name in $a"); + #-log::l("resolved $name in $a"); $a; } @@ -242,31 +195,14 @@ sub findIntf { $intf->{$device}{DEVICE} = $device; $intf->{$device}; } - +#PAD \s* a la fin my $ip_regexp = qr/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; - sub is_ip { my ($ip) = @_; my @fields = $ip =~ $ip_regexp or return; - every { 0 <= $_ && $_ <= 255 } @fields or return; + return if grep { $_ < 0 || $_ > 255 } @fields; @fields; } - -sub ip_compare { - my ($ip1, $ip2) = @_; - my (@ip1_fields) = $ip1 =~ $ip_regexp; - my (@ip2_fields) = $ip2 =~ $ip_regexp; - - every { $ip1_fields[$_] eq $ip2_fields[$_] } (0 .. 3); -} - -sub is_ip_forbidden { - my ($ip) = @_; - my @forbidden = ('127.0.0.1', '255.255.255.255'); - - any { ip_compare($ip, $_) } @forbidden; -} - sub is_domain_name { my ($name) = @_; my @fields = split /\./, $name; @@ -276,7 +212,7 @@ sub is_domain_name { sub netmask { my ($ip) = @_; return "255.255.255.0" unless is_ip($ip); - $ip =~ $ip_regexp or warn "IP_regexp failed\n" and return "255.255.255.0"; + $ip =~ $ip_regexp; if ($1 >= 1 && $1 < 127) { "255.0.0.0"; #-1.0.0.0 to 127.0.0.0 } elsif ($1 >= 128 && $1 <= 191) { @@ -305,70 +241,168 @@ sub dns { join(".", @masked); } - sub gateway { my ($ip) = @_; my @masked = masked_ip($ip) =~ $ip_regexp; $masked[3] = 1; join(".", @masked); + } -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 configureNetworkIntf { + my ($netc, $in, $intf, $net_device, $skip, $module) = @_; + my $text; + my @wireless_modules = qw(aironet_cs aironet4500_cs hermes airo orinoco_cs orinoco airo_cs netwave_cs ray_cs wavelan_cs wvlan_cs airport); + my $flag = 0; + foreach (@wireless_modules) { + $module =~ /$_/ and $flag = 1; + } + if ($flag) { + $intf->{wireless_eth} = 1; + $netc->{wireless_eth} = 1; + $intf->{WIRELESS_MODE} = "Managed"; + $intf->{WIRELESS_ESSID} = "any"; +#- $intf->{WIRELESS_NWID} = ""; +#- $intf->{WIRELESS_FREQ} = ""; +#- $intf->{WIRELESS_SENS} = ""; +#- $intf->{WIRELESS_RATE} = ""; +#- $intf->{WIRELESS_ENC_KEY} = ""; +#- $intf->{WIRELESS_RTS} = ""; +#- $intf->{WIRELESS_FRAG} = ""; +#- $intf->{WIRELESS_IWCONFIG} = ""; +#- $intf->{WIRELESS_IWSPY} = ""; +#- $intf->{WIRELESS_IWPRIV} = ""; + } + if ($net_device eq $intf->{DEVICE}) { + $skip and return 1; + $text = N("WARNING: this device has been previously configured to connect to the Internet. +Simply accept to keep this device configured. +Modifying the fields below will override this configuration."); + } + else { + $text = N("Please enter the IP configuration for this machine. +Each item should be entered as an IP address in dotted-decimal +notation (for example, 1.2.3.4)."); + } + my $pump = $intf->{BOOTPROTO} =~ /^(dhcp|bootp)$/; + delete $intf->{NETWORK}; + delete $intf->{BROADCAST}; + my $onboot = 1; + my @fields = qw(IPADDR NETMASK); + $::isStandalone or $in->set_help('configureNetworkIP'); + $in->ask_from(N("Configuring network device %s", $intf->{DEVICE}), + (N("Configuring network device %s", $intf->{DEVICE}) . ($module ? N(" (driver %s)", $module) : '') . "\n\n") . + $text, + [ { label => N("IP address"), val => \$intf->{IPADDR}, disabled => sub { $pump } }, + { label => N("Netmask"), val => \$intf->{NETMASK}, disabled => sub { $pump } }, + { label => N("Automatic IP"), val => \$pump, type => "bool", text => N("(bootp/dhcp)") }, + if_($::expert, { label => N("Start at boot"), val => \$onboot, type => "bool" }), + if_($intf->{wireless_eth}, + { label => "WIRELESS_MODE", val => \$intf->{WIRELESS_MODE}, list => [ "Ad-hoc", "Managed", "Master", "Repeater", "Secondary", "Auto" ] }, + { label => "WIRELESS_ESSID", val => \$intf->{WIRELESS_ESSID} }, + { label => "WIRELESS_NWID", val => \$intf->{WIRELESS_NWID} }, + { label => "WIRELESS_FREQ", val => \$intf->{WIRELESS_FREQ} }, + { label => "WIRELESS_SENS", val => \$intf->{WIRELESS_SENS} }, + { label => "WIRELESS_RATE", val => \$intf->{WIRELESS_RATE} }, + { label => "WIRELESS_ENC_KEY", val => \$intf->{WIRELESS_ENC_KEY} }, + { label => "WIRELESS_RTS", val => \$intf->{WIRELESS_RTS} }, + { label => "WIRELESS_FRAG", val => \$intf->{WIRELESS_FRAG} }, + { label => "WIRELESS_IWCONFIG", val => \$intf->{WIRELESS_IWCONFIG} }, + { label => "WIRELESS_IWSPY", val => \$intf->{WIRELESS_IWSPY} }, + { label => "WIRELESS_IWPRIV", val => \$intf->{WIRELESS_IWPRIV} } + ), + ], + complete => sub { + $intf->{BOOTPROTO} = $pump ? "dhcp" : "static"; + return 0 if $pump; + for (my $i = 0; $i < @fields; $i++) { + unless (is_ip($intf->{$fields[$i]})) { + $in->ask_warn('', N("IP address should be in format 1.2.3.4")); + return (1,$i); + } + return 0; + } + if ($intf->{WIRELESS_FREQ} !~ /[0-9.]*[kGM]/) { + $in->ask_warn('', N("Freq should have the suffix k, M or G (for example, \"2.46G\" for 2.46 GHz frequency), or add enough \'0\'.")); + return (1,6); + } + if ($intf->{WIRELESS_RATE} !~ /[0-9.]*[kGM]/) { + $in->ask_warn('', N("Rate should have the suffix k, M or G (for example, \"11M\" for 11M), or add enough \'0\'.")); + return (1,8); + } + }, + focus_out => sub { + $intf->{NETMASK} ||= netmask($intf->{IPADDR}) unless $_[0] + } + ) or return; + $intf->{ONBOOT} = bool2yesno($onboot); +} + +sub configureNetworkNet { + my ($in, $netc, $intf, @devices) = @_; + + $netc->{dnsServer} ||= dns($intf->{IPADDR}); + my $gateway_ex = gateway($intf->{IPADDR}); +#- $netc->{GATEWAY} ||= gateway($intf->{IPADDR}); + + $::isInstall and $in->set_help('configureNetworkHost'); + $in->ask_from(N("Configuring network"), +N("Please enter your host name. +Your host name should be a fully-qualified host name, +such as ``mybox.mylab.myco.com''. +You may also enter the IP address of the gateway if you have one"), + [ { label => N("Host name"), val => \$netc->{HOSTNAME} }, + { label => N("DNS server"), val => \$netc->{dnsServer} }, + { label => N("Gateway (e.g. %s)", $gateway_ex), val => \$netc->{GATEWAY} }, + if_(@devices > 1, + { label => N("Gateway device"), val => \$netc->{GATEWAYDEV}, list => \@devices }, + ), + ], + complete => sub { + if ($netc->{dnsServer} and !is_ip($netc->{dnsServer})) { + $in->ask_warn('', N("DNS server address should be in format 1.2.3.4")); + return 1; + } + if ($netc->{GATEWAY} and !is_ip($netc->{GATEWAY})) { + $in->ask_warn('', N("Gateway address should be in format 1.2.3.4")); + return 1; + } + 0; + } + ); +} + +sub miscellaneousNetwork { + my ($in, $clicked, $no_track_net) = @_; + my $u = $::o->{miscellaneous} ||= {}; + $::isInstall and $in->set_help('configureNetworkProxy'); + $u->{track_network_id} = detect_devices::isLaptop(); + $::expert || $clicked and ($in->ask_from('', + N("Proxies configuration"), + [ { label => N("HTTP proxy"), val => \$u->{http_proxy} }, + { label => N("FTP proxy"), val => \$u->{ftp_proxy} }, + if_(!$no_track_net, { label => N("Track network card id (useful for laptops)"), val => \$u->{track_network_id}, type => "bool" }), + ], + complete => sub { + $u->{http_proxy} =~ m,^($|http://), or $in->ask_warn('', N("Proxy should be http://...")), return 1,0; + $u->{ftp_proxy} =~ m,^($|ftp://|http://), or $in->ask_warn('', N("Url should begin with 'ftp:' or 'http:'")), return 1,1; + 0; + } + ) or return); + 1; } sub read_all_conf { - my ($prefix, $netc, $intf, $o_netcnx) = @_; + my ($prefix, $netc, $intf) = @_; $netc ||= {}; $intf ||= {}; - my $netcnx = $o_netcnx || {}; add2hash($netc, read_conf("$prefix/etc/sysconfig/network")) if -r "$prefix/etc/sysconfig/network"; - add2hash($netc, read_resolv_conf()); - add2hash($netc, read_tmdns_conf("$prefix/etc/tmdns.conf")) if -r "$prefix/etc/tmdns.conf"; + add2hash($netc, read_resolv_conf("$prefix/etc/resolv.conf")) if -r "$prefix/etc/resolv.conf"; foreach (all("$prefix/etc/sysconfig/network-scripts")) { - if (/^ifcfg-(\w+)$/ && $1 ne 'lo') { + if (/ifcfg-(\w+)/ && $1 ne 'lo') { my $intf = findIntf($intf, $1); add2hash($intf, { getVarsFromSh("$prefix/etc/sysconfig/network-scripts/$_") }); } } - $netcnx->{type} or probe_netcnx_type($prefix, $netc, $intf, $netcnx); -} - -sub probe_netcnx_type { - my ($prefix, $_netc, $intf, $netcnx) = @_; - #- try to probe $netcnx->{type} which is used almost everywhere. - unless ($netcnx->{type}) { - #- ugly hack to determine network type (avoid saying not configured in summary). - -e "$prefix/etc/ppp/peers/adsl" and $netcnx->{type} ||= 'adsl'; # enough ? - -e "$prefix/etc/ppp/ioptions1B" || -e "$prefix/etc/ppp/ioptions2B" and $netcnx->{type} ||= 'isdn'; # enough ? - $intf->{ppp0} and $netcnx->{type} ||= 'modem'; - $intf->{eth0} and $netcnx->{type} ||= 'lan'; - } -} - -sub easy_dhcp { - my ($netc, $intf) = @_; - - return if text2bool($netc->{NETWORKING}); - - require modules; - require network::ethernet; - modules::load_category('network/main|gigabit|usb'); - my @all_cards = network::ethernet::conf_network_card_backend(); - - #- only for a single network card - (any { $_->[0] eq 'eth0' } @all_cards) && (every { $_->[0] ne 'eth1' } @all_cards) or return; - - log::explanations("easy_dhcp: found eth0"); - - network::ethernet::conf_network_card_backend($netc, $intf, 'dhcp', 'eth0'); - - put_in_hash($netc, { - NETWORKING => "yes", - DHCP => "yes", - }); - 1; } #- configureNetwork2 : configure the network interfaces. @@ -398,22 +432,23 @@ sub easy_dhcp { sub configureNetwork2 { my ($in, $prefix, $netc, $intf) = @_; my $etc = "$prefix/etc"; - if (!$::testing) { - $netc->{wireless_eth} and $in->do_pkgs->ensure_is_installed('wireless-tools', '/sbin/iwconfig', 'auto'); - write_conf("$etc/sysconfig/network", $netc); - write_resolv_conf("$etc/resolv.conf", $netc) if ! $netc->{DHCP}; - write_interface_conf("$etc/sysconfig/network-scripts/ifcfg-$_->{DEVICE}", $_, $netc, $prefix) foreach grep { $_->{DEVICE} ne 'ppp0' } values %$intf; - add2hosts("$etc/hosts", $netc->{HOSTNAME}, map { $_->{IPADDR} } values %$intf) if $netc->{HOSTNAME} && !$netc->{DHCP}; - add2hosts("$etc/hosts", "localhost", "127.0.0.1"); - - any { $_->{BOOTPROTO} eq "dhcp" } values %$intf and $in->do_pkgs->install($netc->{dhcp_client} || 'dhcp-client'); - $in->do_pkgs->ensure_is_installed('tmdns', '/sbin/tmdns', 'auto') if !$in->do_pkgs->is_installed('bind'); - $in->do_pkgs->ensure_is_installed('zcip', '/sbin/zcip', 'auto'); - $netc->{ZEROCONF_HOSTNAME} and write_zeroconf("$etc/tmdns.conf", $netc->{ZEROCONF_HOSTNAME}); - any { $_->{BOOTPROTO} =~ /^(pump|bootp)$/ } values %$intf and $in->do_pkgs->install('pump'); + + $netc->{wireless_eth} and $in->do_pkgs->install(qw(wireless-tools)); + write_conf("$etc/sysconfig/network", $netc); + write_resolv_conf("$etc/resolv.conf", $netc); + write_interface_conf("$etc/sysconfig/network-scripts/ifcfg-$_->{DEVICE}", $_, $prefix) foreach grep { $_->{DEVICE} } values %$intf; + add2hosts("$etc/hosts", $netc->{HOSTNAME}, map { $_->{IPADDR} } values %$intf); + + if (grep { $_->{BOOTPROTO} =~ /^(dhcp)$/ } values %$intf) { + $in->do_pkgs->install($netc->{dhcp_client} ? $netc->{dhcp_client} : 'dhcpcd'); + } + if (grep { $_->{BOOTPROTO} =~ /^(pump|bootp)$/ } values %$intf) { + $in->do_pkgs->install('pump'); } + #-res_init(); #- reinit the resolver so DNS changes take affect - proxy_configure($::o->{miscellaneous}); + any::miscellaneousNetwork(); } + 1; diff --git a/perl-install/network/nfs.pm b/perl-install/network/nfs.pm index 39faa716e..87f336e36 100644 --- a/perl-install/network/nfs.pm +++ b/perl-install/network/nfs.pm @@ -29,41 +29,35 @@ sub to_dev_raw { sub check { my ($_class, $in) = @_; - $in->do_pkgs->ensure_is_installed('nfs-utils-clients', '/usr/sbin/showmount') or return; - system('/etc/init.d/portmap start') if system('/etc/init.d/portmap status') != 0; - 1; + $in->do_pkgs->ensure_is_installed('nfs-utils-clients', '/usr/sbin/showmount'); } sub find_servers { - open(my $F2, "rpcinfo-flushed -b mountd 2 |"); - open(my $F3, "rpcinfo-flushed -b mountd 3 |"); + my $pid = open(my $F, "rpcinfo-flushed -b mountd 2 |"); + $SIG{ALRM} = sub { kill(15, $pid) }; + alarm 1; - common::nonblock($F2); - common::nonblock($F3); my $domain = chomp_(`domainname`); - my ($s, %servers); - my $quit; - while (!$quit) { - $quit = 1; - sleep 1; - while ($s = <$F2> || <$F3>) { - $quit = 0; - my ($ip, $name) = $s =~ /(\S+)\s+(\S+)/ or log::explanations("bad line in rpcinfo output"), next; - $name =~ s/\.$//; - $name =~ s/\Q.$domain\E$//; - $servers{$ip} ||= { ip => $ip, if_($name ne '(unknown)', name => $name) }; - } + my @servers; + local $_; + while (<$F>) { + chomp; + my ($ip, $name) = /(\S+)\s+(\S+)/ or log::l("bad line in rpcinfo output"), next; + $name =~ s/\Q.$domain//; + $name =~ s/\.$//; + push @servers, { ip => $ip, if_($name ne '(unknown)', name => $name) }; } - values %servers; + @servers; } sub find_exports { my ($_class, $server) = @_; my @l; - run_program::raw({ timeout => 1 }, "showmount", '>', \@l, "--no-headers", "-e", $server->{ip} || $server->{name}); + run_program::raw({ timeout => 1 }, "showmount", '>', \@l, "-e", $server->{ip} || $server->{name}); - map { if_(/(\S+(\s*\S+)*)\s+(\S+)/, { name => $1, comment => $3, server => $server }) } @l; + shift @l; #- drop first line + map { /(\S+)\s*(\S+)/; { name => $1, comment => $2, server => $server } } @l; } 1; diff --git a/perl-install/network/shorewall.pm b/perl-install/network/shorewall.pm index bd069f063..a173c13f8 100644 --- a/perl-install/network/shorewall.pm +++ b/perl-install/network/shorewall.pm @@ -24,7 +24,7 @@ sub check_iptables { }; !$existing_config || $in->ask_okcancel(N("Firewalling configuration detected!"), - N("Warning! An existing firewalling configuration has been detected. You may need some manual fixes after installation.")); + N("Warning! An existing firewalling configuration has been detected. You may need some manual fix after installation.")); } sub set_config_file { @@ -46,58 +46,34 @@ sub get_config_file { map { [ split ' ' ] } grep { !/^#/ } cat_("$::prefix/etc/shorewall/$file"); } -sub default_interfaces_silent { - my ($_in) = @_; - my %conf; - my @l = detect_devices::getNet() or return; - if (@l == 1) { +sub default_interfaces { + my %conf; + + my @l = detect_devices::getNet() or return; + if (@l == 1) { $conf{net_interface} = $l[0]; } else { $conf{net_interface} = network::netconnect::get_net_device() || $l[0]; - $conf{loc_interface} = [ grep { $_ ne $conf{net_interface} } @l ]; + $conf{loc_interface} = [ grep { $_ ne $conf{net_interface} } @l ]; } \%conf; } -sub default_interfaces { - my ($in) = @_; - my %conf; - my $card_netconnect = network::netconnect::get_net_device() || "eth0"; - defined $card_netconnect and log::l("[drakgw] Information from netconnect: ignore card $card_netconnect"); - - my @l = detect_devices::getNet() or return; - $in->ask_from('', - N("Please enter the name of the interface connected to the internet. - -Examples: - ppp+ for modem or DSL connections, - eth0, or eth1 for cable connection, - ippp+ for a isdn connection. -", $card_netconnect), - [ { label => N("Net Device"), val => \$card_netconnect, list => \@l } ]); - $conf{net_interface} = $card_netconnect; - #$conf{net_interface} = network::netconnect::get_net_device() || $l[0]; - $conf{loc_interface} = [ grep { $_ ne $conf{net_interface} } @l ]; - \%conf; -} - sub read { - my ($in, $mode) = @_; - my %conf = (disabled => !glob_("$::prefix/etc/rc3.d/S*shorewall"), - ports => join(' ', map { - my $e = $_; - map { "$_/$e->[3]" } split(',', $e->[4]); - } grep { $_->[0] eq 'ACCEPT' && $_->[1] eq 'net' } get_config_file('rules')) - ); + my %conf; + + $conf{disabled} = !glob_("$::prefix/etc/rc3.d/S*shorewall"); + + $conf{ports} = + join(' ', map { + my $e = $_; + map { "$_/$e->[3]" } split(',', $e->[4]); + } grep { $_->[0] eq 'ACCEPT' && $_->[1] eq 'net' } get_config_file('rules')); if (my ($e) = get_config_file('masq')) { $conf{masquerade}{subnet} = $e->[1] if $e->[1]; } - if ($mode eq 'silent') { - put_in_hash(\%conf, default_interfaces_silent($in)); - } else { - put_in_hash(\%conf, default_interfaces($in)); - }; + put_in_hash(\%conf, default_interfaces()); foreach (get_config_file('interfaces')) { my ($name, $interface) = @$_; if ($name eq 'masq') { @@ -110,7 +86,6 @@ sub read { sub write { my ($conf) = @_; - my $connect_file = "/etc/sysconfig/network-scripts/net_cnx_up"; my %ports_by_proto; foreach (split ' ', $conf->{ports}) { @@ -136,20 +111,16 @@ sub write { [ 'all', 'all', 'REJECT', 'info' ], ); set_config_file('rules', - if_(cat_("$::prefix$connect_file") =~ /pptp/, [ 'ACCEPT', 'fw', 'loc:10.0.0.138', 'tcp', '1723' ]), - if_(cat_("$::prefix$connect_file") =~ /pptp/, [ 'ACCEPT', 'fw', 'loc:10.0.0.138', 'gre' ]), (map { map_each { [ 'ACCEPT', $_, 'fw', $::a, join(',', @$::b), '-' ] } %ports_by_proto } ('net', if_($conf->{masquerade}, 'masq'), if_($conf->{loc_interface}, 'loc'))), if_($conf->{masquerade}, map { [ 'ACCEPT', 'masq', 'fw', $_, join(',', @drakgw_ports), '-' ] } 'tcp', 'udp'), - if_($conf->{masquerade}, map { [ 'ACCEPT', 'fw', 'masq', $_, join(',', @internal_ports), '-' ] } 'tcp', 'udp'), + if_($conf->{masquerade}, map { [ 'ACCEPT', 'fw', 'masq', $_, join(',', @internal_ports), '-' ] } 'tcp', 'udp'), ); set_config_file('masq', $conf->{masquerade} ? [ $conf->{net_interface}, $conf->{masquerade}{subnet} ] : (), ); - system('uniq /etc/shorewall/masq > /etc/shorewall/masq.uniq'); - rename("/etc/shorewall/masq.uniq", "/etc/shorewall/masq"); - + if ($conf->{disabled}) { run_program::rooted($::prefix, 'chkconfig', '--del', 'shorewall'); run_program::run('service', '>', '/dev/null', 'shorewall', 'stop') if $::isStandalone; diff --git a/perl-install/network/smb.pm b/perl-install/network/smb.pm index 941463c65..7adf01a3a 100644 --- a/perl-install/network/smb.pm +++ b/perl-install/network/smb.pm @@ -70,7 +70,7 @@ sub find_servers { my ($group, $name) = split(' ', lc($_)); # already done - next if any { $group eq $_->{group} } values %servers; + next if grep { $group eq $_->{group} } values %servers; $l{$name} = $group; } @@ -100,7 +100,7 @@ sub find_exports { @l; } -sub authentications_available { +sub authentifications_available { my ($server) = @_; map { if_(/^auth.\Q$server->{name}.\E(.*)/, $1) } all("/etc/samba"); } @@ -146,36 +146,4 @@ sub read_credentials { put_in_hash($server, read_credentials_raw(to_credentials($server->{name}, $username))); } - -sub write_smb_conf { - my ($domain) = @_; - - #- was going to just have a canned config in samba-winbind - #- and replace the domain, but sylvestre/buchan didn't bless it yet - - my $f = "$::prefix/etc/samba/smb.conf"; - rename $f, "$f.orig"; - output($f, " -[global] - workgroup = $domain - server string = Samba Server %v - security = domain - encrypt passwords = Yes - password server = * - log file = /var/log/samba/log.%m - max log size = 50 - socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192 - character set = ISO8859-15 - os level = 18 - local master = No - dns proxy = No - winbind uid = 10000-20000 - winbind gid = 10000-20000 - winbind separator = + - template homedir = /home/%D/%U - template shell = /bin/bash - winbind use default domain = yes -"); -} - 1; diff --git a/perl-install/network/smbnfs.pm b/perl-install/network/smbnfs.pm index 97f2bd6e6..528a87be2 100644 --- a/perl-install/network/smbnfs.pm +++ b/perl-install/network/smbnfs.pm @@ -7,8 +7,8 @@ use fs; sub new { - my ($class, $o_v) = @_; - bless($o_v || {}, $class); + my ($class, $v) = @_; + bless($v || {}, $class); } sub server_to_string { diff --git a/perl-install/network/tools.pm b/perl-install/network/tools.pm index 9735aef4b..489e0d966 100644 --- a/perl-install/network/tools.pm +++ b/perl-install/network/tools.pm @@ -1,6 +1,5 @@ -package network::tools; # $Id$ +package network::tools; -use strict; use common; use run_program; use c; @@ -9,14 +8,14 @@ use MDK::Common::Globals "network", qw($in $prefix $disconnect_file $connect_pro use MDK::Common::System qw(getVarsFromSh); @ISA = qw(Exporter); -@EXPORT = qw(ask_info2 connect_backend connected connected_bg disconnect_backend is_dynamic_ip is_wireless_intf passwd_by_login read_providers_backend read_secret_backend test_connected write_cnx_script write_initscript write_secret_backend); +@EXPORT = qw(write_cnx_script write_secret_backend read_secret_backend passwd_by_login write_initscript ask_connect_now connect_backend disconnect_backend read_providers_backend ask_info2 type2interface connected connected_bg test_connected connected2 disconnected); @EXPORT_OK = qw($in); sub write_cnx_script { - my ($netc, $o_type, $o_up, $o_down, $o_type2) = @_; - if ($o_type) { - $netc->{internet_cnx}{$o_type}{$_->[0]} = $_->[1] foreach [$connect_file, $o_up], [$disconnect_file, $o_down]; - $netc->{internet_cnx}{$o_type}{type} = $o_type2; + my ($netc, $type, $up, $down, $type2) = @_; + if ($type) { + $netc->{internet_cnx}{$type}{$_->[0]} = $_->[1] foreach [$connect_file, $up], [$disconnect_file, $down]; + $netc->{internet_cnx}{$type}{type} = $type2; } else { foreach ($connect_file, $disconnect_file) { output_with_perm("$prefix$_", 0755, @@ -29,19 +28,18 @@ sub write_cnx_script { sub write_secret_backend { my ($a, $b) = @_; - foreach my $i ("$prefix/etc/ppp/pap-secrets", "$prefix/etc/ppp/chap-secrets") { - substInFile { s/^'$a'.*\n//; $_ .= "\n'$a' * '$b' * \n" if eof } $i; - #- restore access right to secrets file, just in case. - chmod 0600, $i; + foreach my $i ("pap-secrets", "chap-secrets") { + substInFile { s/^'$a'.*\n//; $_ .= "\n'$a' * '$b' * \n" if eof } "$prefix/etc/ppp/$i"; } } sub unquotify { my ($word) = @_; - $$word =~ s/^(['"]?)(.*)\1$/$2/; + my ($a, $b, $c) = $$word =~ /"(.*)"|'(.*)'|(.*)/; + $$word = $a ? $a : $b ? $b : $c; } -sub read_secret_backend() { +sub read_secret_backend { my $conf; foreach my $i ("pap-secrets", "chap-secrets") { foreach (cat_("$prefix/etc/ppp/$i")) { @@ -69,30 +67,124 @@ sub passwd_by_login { } } -sub connect_backend() { run_program::rooted($prefix, "$connect_file &") } +sub ask_connect_now { + my ($type) = @_; + $::Wizard_no_previous = 1; + my $up; + #- FIXME : code the exception to be generated by ask_yesorno, to be able to remove the $::Wizard_no_previous=1; + if ($in->ask_yesorno(N("Internet configuration"), + N("Do you want to try to connect to the Internet now?") + )) { + { + my $_w = $in->wait_message('', N("Testing your connection..."), 1); + connect_backend(); + my $s = 30; + $type =~ /modem/ and $s = 50; + $type =~ /adsl/ and $s = 35; + $type =~ /isdn/ and $s = 20; + sleep $s; + $up = connected(); + } + my $m = $up ? N("The system is now connected to Internet.") . + if_($::isInstall, N("For security reason, it will be disconnected now.")) : + N("The system doesn't seem to be connected to internet. +Try to reconfigure your connection."); + if ($::isWizard) { + $::Wizard_no_previous = 1; + $::Wizard_finished = 1; + $in->ask_okcancel(N("Network Configuration"), $m, 1); + undef $::Wizard_no_previous; + undef $::Wizard_finished; + } else { $in->ask_warn('', $m) } + $::isInstall and disconnect_backend(); + } + undef $::Wizard_no_previous; + $up; +} + +sub connect_backend { run_program::rooted($prefix, "$connect_prog &") } -sub disconnect_backend() { run_program::rooted($prefix, "$disconnect_file &") } +sub disconnect_backend { run_program::rooted($prefix, "$disconnect_file &") } sub read_providers_backend { my ($file) = @_; map { /(.*?)=>/ } catMaybeCompressed($file) } -sub connected() { gethostbyname("mandrakesoft.com") ? 1 : 0 } +sub ask_info2 { + my ($cnx, $netc) = @_; + $::isInstall and $in->set_help('configureNetworkDNS'); + $in->ask_from(N("Connection Configuration"), + N("Please fill or check the field below"), + [ + if__($cnx->{irq}, { label => N("Card IRQ"), val => \$cnx->{irq} }), + if__($cnx->{mem}, { label => N("Card mem (DMA)"), val => \$cnx->{mem} }), + if__($cnx->{io}, { label => N("Card IO"), val => \$cnx->{io} }), + if__($cnx->{io0}, { label => N("Card IO_0"), val => \$cnx->{io0} }), + if__($cnx->{io1}, { label => N("Card IO_1"), val => \$cnx->{io1} }), + if__($cnx->{phone_in}, { label => N("Your personal phone number"), val => \$cnx->{phone_in} }), + if__($netc->{DOMAINNAME2}, { label => N("Provider name (ex provider.net)"), val => \$netc->{DOMAINNAME2} }), + if__($cnx->{phone_out}, { label => N("Provider phone number"), val => \$cnx->{phone_out} }), + if__($netc->{dnsServer2}, { label => N("Provider dns 1 (optional)"), val => \$netc->{dnsServer2} }), + if__($netc->{dnsServer3}, { label => N("Provider dns 2 (optional)"), val => \$netc->{dnsServer3} }), + if__($cnx->{vpivci}, { label => N("Choose your country"), val => \$netc->{vpivci}, list => detect_timezone() }), + if__($cnx->{dialing_mode}, { label => N("Dialing mode"), val => \$cnx->{dialing_mode},list => ["auto", "manual"] }), + if__($cnx->{speed}, { label => N("Connection speed"), val => \$cnx->{speed}, list => ["64 Kb/s", "128 Kb/s"] }), + if__($cnx->{huptimeout}, { label => N("Connection timeout (in sec)"), val => \$cnx->{huptimeout} }), + if__($cnx->{login}, { label => N("Account Login (user name)"), val => \$cnx->{login} }), + if__($cnx->{passwd}, { label => N("Account Password"), val => \$cnx->{passwd}, hidden => 1 }), + ] + ) or return; + if ($netc->{vpivci}) { + foreach ([N("Netherlands"), '8_48'], [N("France"), '8_35'], [N("Belgium"), '8_35'], [N("Italy"), '8_35'], [N("United Kingdom"), '0_38'], [N("United States"), '8_35']) { + $netc->{vpivci} eq $_->[0] and $netc->{vpivci} = $_->[1]; + } + } + 1; +} + +sub detect_timezone { + my %tmz2country = ( + 'Europe/Paris' => N("France"), + 'Europe/Amsterdam' => N("Netherlands"), + 'Europe/Rome' => N("Italy"), + 'Europe/Brussels' => N("Belgium"), + 'America/New_York' => N("United States"), + 'Europe/London' => N("United Kingdom") + ); + my %tm_parse = MDK::Common::System::getVarsFromSh('/etc/sysconfig/clock'); + my @country; + foreach (keys %tmz2country) { + if ($_ eq $tm_parse{ZONE}) { + unshift @country, $tmz2country{$_}; + } else { push @country, $tmz2country{$_} }; + } + \@country; +} -# request a ref on a bg_connect and a ref on a scalar -sub connected_bg__raw { - my ($kid_pipe, $status) = @_; - local $| = 1; - if (ref($kid_pipe) && ref($$kid_pipe)) { - my $fd = $$kid_pipe->{fd}; - fcntl($fd, c::F_SETFL(), c::O_NONBLOCK()) or die "can't fcntl F_SETFL: $!"; - my $a = <$fd>; - $$status = $a if defined $a; - } else { $$kid_pipe = check_link_beat() } +sub type2interface { + my ($i) = @_; + $i =~ /$_->[0]/ and return $_->[1] foreach [ modem => 'ppp' ], + [ isdn_internal => 'ippp' ], + [ isdn_external => 'ppp' ], + [ adsl => 'ppp' ], + [ cable => 'eth' ], + [ lan => 'eth' ]; } +sub connected { gethostbyname("mandrakesoft.com") ? 1 : 0 } + my $kid_pipe; sub connected_bg { - my ($status) = @_; - connected_bg__raw(\$kid_pipe, $status); + local $| = 1; + my ($ref) = @_; + if (defined $kid_pipe) { + fcntl($kid_pipe, c::F_SETFL(), c::O_NONBLOCK()) or die "can't fcntl F_SETFL: $!"; + my $a; + if (defined($a = <$kid_pipe>)) { + close($kid_pipe) || warn "kid exited $?"; + undef $kid_pipe; + $$ref = $a; + } + } else { $kid_pipe = connected2() } + 1; } # test if connected; @@ -104,38 +196,60 @@ sub connected_bg { # return : nothing # cmd = 3 : return current status even if a test is in progress my $kid_pipe_connect; +my $kid_pid; my $current_connection_status; sub test_connected { local $| = 1; my ($cmd) = @_; - - $current_connection_status = -1 if !defined $current_connection_status; - + + if (!defined $current_connection_status) { $current_connection_status = -1 } + if ($cmd == 0) { - connected_bg__raw(\$kid_pipe_connect, \$current_connection_status); - } elsif ($cmd == 1) { + if (defined $kid_pipe_connect) { + fcntl($kid_pipe_connect, c::F_SETFL(), c::O_NONBLOCK()) or die "can't fcntl F_SETFL: $!"; + my $a; + if (defined($a = <$kid_pipe_connect>)) { + close($kid_pipe_connect) || warn "kid exited $?"; + undef $kid_pipe_connect; + undef $kid_pid; + $current_connection_status = $a; + } + } + return $current_connection_status; + } + + if ($cmd == 1) { if ($current_connection_status != -2) { $current_connection_status = -2; - $kid_pipe_connect = check_link_beat(); + $kid_pipe_connect = connected2(); } - } elsif ($cmd == 2) { - if (defined($kid_pipe_connect)) { - kill -9, $kid_pipe_connect->{pid}; - undef $kid_pipe_connect; + } + if ($cmd == 2) { + if (defined($kid_pid)) { + kill -9, $kid_pid; + undef $kid_pid; } } return $current_connection_status; } -sub check_link_beat() { - bg_command->new(sub { - require Net::Ping; - print Net::Ping->new("icmp")->ping("mandrakesoft.com") ? 1 : 0; - }); +sub connected2 { + if ($kid_pid = open(my $kid_to_read, "-|")) { + #- parent + $kid_to_read; + } else { + #- child + my $a = gethostbyname("mandrakesoft.com") ? 1 : 0; + print $a; + c::_exit(0); + } } -sub write_initscript() { +sub disconnected {} + + +sub write_initscript { $::testing and return; output_with_perm("$prefix/etc/rc.d/init.d/internet", 0755, sprintf(<<'EOF', $connect_file, $connect_file, $disconnect_file, $disconnect_file)); @@ -188,64 +302,4 @@ EOF }; } -sub copy_firmware { - my ($device, $destination, $file) = @_; - my ($source, $failed, $mounted); - - $device eq 'floppy' and do { $mounted = 1; ($source, $failed) = use_floppy($file) }; - $device eq 'windows' and ($source, $failed) = use_windows(); - - $source eq $failed and return; - $mounted and my $_b = before_leaving { fs::umount('/mnt') }; - if ($failed) { - eval { $in->ask_warn('', $failed) }; $in->exit if $@ =~ /wizcancel/; - return; - } - - if (-e "$source/$file") { cp_af("$source/$file", $destination) } - else { $failed = N("Firmware copy failed, file %s not found", $file) } - eval { $in->ask_warn('', $failed || N("Firmware copy succeeded")) }; $in->exit if $@ =~ /wizcancel/; - log::explanations($failed || "Firmware copy $file in $destination succeeded"); - - $failed ? 0 : 1; -} - -sub use_windows() { - my $all_hds = fsedit::get_hds({}, undef); - fs::get_info_from_fstab($all_hds, ''); - my $part = find { $_->{device_windobe} eq 'C' } fsedit::get_fstab(@{$all_hds->{hds}}); - $part or my $failed = N("No partition available"); - my $source = -d "$part->{mntpoint}/windows/" ? "$part->{mntpoint}/windows/system" : "$part->{mntpoint}/winnt/system"; - log::explanations($failed || "Seek in $source to find firmware"); - - return $source, $failed; -} - -sub use_floppy { - my ($file) = @_; - my $floppy = detect_devices::floppy(); - $in->ask_okcancel(N("Insert floppy"), - N("Insert a FAT formatted floppy in drive %s with %s in root directory and press %s", $floppy, $file, N("Next"))) or return; - eval { fs::mount(devices::make($floppy), '/mnt', 'vfat', 'readonly'); 1 } or my $failed = N("Floppy access error, unable to mount device %s", $floppy); - log::explanations($failed || "Mounting floppy device $floppy in /mnt"); - - return '/mnt', $failed; -} - - -sub is_wireless_intf { - my ($module) = @_; - member($module, qw(acx100_pci airo aironet_cs aironet4500_cs airo_cs airport at76c503 hermes netwave_cs orinoco_cs prism2_usb orinoco ray_cs usbvnet_rfmd wavelan_cs wvlan_cs)) -} - -sub is_dynamic_ip { - my ($intf) = @_; - any { $_->{BOOTPROTO} !~ /^(none|static|)$/ } values %$intf; -} - -sub is_dynamic_host { - my ($intf) = @_; - any { defined $_->{DHCP_HOSTNAME} } values %$intf; -} - 1; |