summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordamien <damien@mandriva.com>2001-07-02 20:51:08 +0000
committerdamien <damien@mandriva.com>2001-07-02 20:51:08 +0000
commit6fcfa39325f63952260032fe0b2e42f620bc7734 (patch)
tree8cb7db55a0dc3f5f4ea0e1b2acad3696cda3f341
parent3e745b343439ebf6f58e1c41d0e831df7cc4b3e7 (diff)
downloaddrakx-6fcfa39325f63952260032fe0b2e42f620bc7734.tar
drakx-6fcfa39325f63952260032fe0b2e42f620bc7734.tar.gz
drakx-6fcfa39325f63952260032fe0b2e42f620bc7734.tar.bz2
drakx-6fcfa39325f63952260032fe0b2e42f620bc7734.tar.xz
drakx-6fcfa39325f63952260032fe0b2e42f620bc7734.zip
new network sources reorganization
-rw-r--r--perl-install/network.pm479
-rw-r--r--perl-install/network/adsl.pm200
-rw-r--r--perl-install/network/ethernet.pm117
-rw-r--r--perl-install/network/isdn.pm268
-rw-r--r--perl-install/network/modem.pm88
-rw-r--r--perl-install/network/netconnect.pm597
-rw-r--r--perl-install/network/network.pm486
-rw-r--r--perl-install/network/tools.pm76
-rwxr-xr-xperl-install/standalone/draknet2
9 files changed, 1834 insertions, 479 deletions
diff --git a/perl-install/network.pm b/perl-install/network.pm
index 6a426b76e..9979e439e 100644
--- a/perl-install/network.pm
+++ b/perl-install/network.pm
@@ -1,482 +1,5 @@
package network; # $Id$
-use diagnostics;
-use strict;
+use network::network;
-#-######################################################################################
-#- misc imports
-#-######################################################################################
-use Socket;
-
-use common qw(:common :file :system :functional);
-use detect_devices;
-use run_program;
-use any;
-use log;
-
-#-######################################################################################
-#- Functions
-#-######################################################################################
-sub read_conf {
- my ($file) = @_;
- my %netc = getVarsFromSh($file);
- \%netc;
-}
-
-sub read_resolv_conf {
- my ($file) = @_;
- my @l = qw(dnsServer dnsServer2 dnsServer3);
- my %netc;
-
- local *F; open F, $file or die "cannot open $file: $!";
- local $_;
- while (<F>) {
- /^\s*nameserver\s+(\S+)/ and $netc{shift @l} = $1;
- }
- \%netc;
-}
-
-sub read_interface_conf {
- my ($file) = @_;
- my %intf = getVarsFromSh($file) or die "cannot open file $file: $!";
-
- $intf{BOOTPROTO} ||= 'static';
- $intf{isPtp} = $intf{NETWORK} eq '255.255.255.255';
- $intf{isUp} = 1;
- \%intf;
-}
-
-sub up_it {
- my ($prefix, $intfs) = @_;
- $_->{isUp} and return foreach values %$intfs;
- my $f = "/etc/resolv.conf"; symlink "$prefix/$f", $f;
- run_program::rooted($prefix, "/etc/rc.d/init.d/network", "start");
- $_->{isUp} = 1 foreach values %$intfs;
-}
-sub down_it {
- my ($prefix, $intfs) = @_;
- run_program::rooted($prefix, "/etc/rc.d/init.d/network", "stop");
- $_->{isUp} = 1 foreach values %$intfs;
-}
-
-sub write_conf {
- my ($file, $netc) = @_;
-
- add2hash($netc, {
- NETWORKING => "yes",
- FORWARD_IPV4 => "false",
- HOSTNAME => "localhost.localdomain",
- });
- ($netc->{DOMAINNAME}) = ($netc->{HOSTNAME} =~ /\.(.*)/);
-
- setVarsInSh($file, $netc, qw(NETWORKING FORWARD_IPV4 DHCP_HOSTNAME HOSTNAME DOMAINNAME GATEWAY GATEWAYDEV NISDOMAIN));
-}
-
-sub write_resolv_conf {
- my ($file, $netc) = @_;
-
- #- get the list of used dns.
- my %used_dns; @used_dns{$netc->{dnsServer}, $netc->{dnsServer2}, $netc->{dnsServer3}} = (1, 2, 3);
-
- unless ($netc->{DOMAINNAME} || $netc->{DOMAINNAME2} || keys %used_dns > 0) {
- unlink($file);
- log::l("neither domain name nor dns server are configured");
- return 0;
- }
-
- my (%search, %dns, @unknown);
- local *F; open F, $file;
- local $_;
- while (<F>) {
- /^[#\s]*search\s+(.*?)\s*$/ and $search{$1} = $., next;
- /^[#\s]*nameserver\s+(.*?)\s*$/ and $dns{$1} = $., next;
- /^.*# ppp temp entry\s*$/ and next;
- /^[#\s]*(\S.*?)\s*$/ and push @unknown, $1;
- }
-
- close F; open F, ">$file" or die "cannot write $file: $!";
- print F "# search $_\n" foreach grep { $_ ne "$netc->{DOMAINNAME} $netc->{DOMAINNAME2}" } sort { $search{$a} <=> $search{$b} } keys %search;
- print F "search $netc->{DOMAINNAME} $netc->{DOMAINNAME2}\n\n" if ($netc->{DOMAINNAME} || $netc->{DOMAINNAME2});
- print F "# nameserver $_\n" foreach grep { ! exists $used_dns{$_} } sort { $dns{$a} <=> $dns{$b} } keys %dns;
- print F "nameserver $_\n" foreach sort { $used_dns{$a} <=> $used_dns{$b} } grep { $_ } keys %used_dns;
- print F "\n";
- print F "# $_\n" foreach @unknown;
- print F "\n";
- print F "# ppp temp entry\n";
-
- #-res_init(); # reinit the resolver so DNS changes take affect
- 1;
-}
-
-sub write_interface_conf {
- my ($file, $intf) = @_;
-
- my @ip = split '\.', $intf->{IPADDR};
- my @mask = split '\.', $intf->{NETMASK};
- add2hash($intf, {
- BROADCAST => join('.', mapn { int $_[0] | ~int $_[1] & 255 } \@ip, \@mask),
- NETWORK => join('.', mapn { int $_[0] & $_[1] } \@ip, \@mask),
- ONBOOT => bool2yesno(!member($intf->{DEVICE}, map { $_->{device} } detect_devices::probeall())),
- });
- setVarsInSh($file, $intf, qw(DEVICE BOOTPROTO IPADDR NETMASK NETWORK BROADCAST ONBOOT), ($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 {
- my ($file, $hostname, @ips) = @_;
- my %l;
- $l{$_} = $hostname foreach @ips;
-
- local *F;
- if (-e $file) {
- open F, $file or die "cannot open $file: $!";
- /\s*(\S+)(.*)/ and $l{$1} ||= $2 foreach <F>;
- }
- log::l("writing host information to $file");
- open F, ">$file" or die "cannot write $file: $!";
- while (my ($ip, $v) = each %l) {
- $ip or next;
- print F "$ip";
- if ($v =~ /^\s/) {
- print F $v;
- } else {
- print F "\t\t$v";
- print F " $1" if $v =~ /(.*?)\./;
- }
- print F "\n";
- }
-}
-
-# The interface/gateway needs to be configured before this will work!
-sub guessHostname {
- my ($prefix, $netc, $intf) = @_;
-
- $intf->{isUp} && dnsServers($netc) or return 0;
- $netc->{HOSTNAME} && $netc->{DOMAINNAME} and return 1;
-
- write_resolv_conf("$prefix/etc/resolv.conf", $netc);
-
- my $name = gethostbyaddr(Socket::inet_aton($intf->{IPADDR}), AF_INET) or log::l("reverse name lookup failed"), return 0;
-
- log::l("reverse name lookup worked");
-
- add2hash($netc, { HOSTNAME => $name });
- 1;
-}
-
-sub addDefaultRoute {
- my ($netc) = @_;
- c::addDefaultRoute($netc->{GATEWAY}) if $netc->{GATEWAY};
-}
-
-sub sethostname {
- my ($netc) = @_;
- 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::l("resolved $name in $a");
- $a;
-}
-
-sub dnsServers {
- my ($netc) = @_;
- my %used_dns; @used_dns{$netc->{dnsServer}, $netc->{dnsServer2}, $netc->{dnsServer3}} = (1, 2, 3);
- sort { $used_dns{$a} <=> $used_dns{$b} } grep { $_ } keys %used_dns;
-}
-
-sub findIntf {
- my ($intf, $device) = @_;
- $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) = @_;
- return 0 unless $ip =~ $ip_regexp;
- my @fields = ($1, $2, $3, $4);
- foreach (@fields) {
- return 0 if $_ < 0 || $_ > 255;
- }
- return 1;
-}
-
-sub netmask {
- my ($ip) = @_;
- return "255.255.255.0" unless is_ip($ip);
- $ip =~ $ip_regexp;
- if ($1 >= 1 && $1 < 127) {
- return "255.0.0.0"; #-1.0.0.0 to 127.0.0.0
- } elsif ($1 >= 128 && $1 <= 191 ){
- return "255.255.0.0"; #-128.0.0.0 to 191.255.0.0
- } elsif ($1 >= 192 && $1 <= 223) {
- return "255.255.255.0";
- } else {
- return "255.255.255.255"; #-experimental classes
- }
-}
-
-sub masked_ip {
- my ($ip) = @_;
- return "" unless is_ip($ip);
- my @mask = netmask($ip) =~ $ip_regexp;
- my @ip = $ip =~ $ip_regexp;
- for (my $i = 0; $i < @ip; $i++) {
- $ip[$i] &= int $mask[$i];
- }
- join(".", @ip);
-}
-
-sub dns {
- my ($ip) = @_;
- my $mask = masked_ip($ip);
- my @masked = masked_ip($ip) =~ $ip_regexp;
- $masked[3] = 2;
- join (".", @masked);
-
-}
-sub gateway {
- my ($ip) = @_;
- my @masked = masked_ip($ip) =~ $ip_regexp;
- $masked[3] = 1;
- join (".", @masked);
-
-}
-
-sub configureNetwork {
- my ($prefix, $netc, $in, $intf, $first_time) = @_;
- local $_;
- any::setup_thiskind($in, 'net', !$::expert, 1);
- my @l = detect_devices::getNet() or die _("no network card found");
- my @all_cards = netconnect::conf_network_card_backend ($prefix, $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(_("Hostname"), _("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_entries_refH(_("Configuring network"),
-_("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 => _("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;
- if ( $netc->{GATEWAY} ) {
- unlink "$prefix/etc/sysconfig/network-scripts/net_cnx_up";
- unlink "$prefix/etc/sysconfig/network-scripts/net_cnx_down";
- undef $netc->{NET_DEVICE};
- }
- }
- miscellaneousNetwork($in);
- 1;
-}
-
-
-sub configureNetworkIntf {
- my ($netc, $in, $intf, $net_device, $skip, $module) = @_;
- my $text;
- my @wireless_modules = ("airo_cs", "netwave_cs", "ray_cs", "wavelan_cs", "wvlan_cs");
- if (member($module, @wireless_modules)) {
- $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 = _("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 = _("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 @fields = qw(IPADDR NETMASK);
- $::isStandalone or $in->set_help('configureNetworkIP');
- $in->ask_from_entries_refH(_("Configuring network device %s", $intf->{DEVICE}),
- (_("Configuring network device %s", $intf->{DEVICE}) . ( $module ? _(" (driver $module)") : '' ) ."\n\n") .
- $text,
- [ { label => _("IP address"), val => \$intf->{IPADDR}, disabled => sub { $pump } },
- { label => _("Netmask"), val => \$intf->{NETMASK}, disabled => sub { $pump } },
- { label => _("Automatic IP"), val => \$pump, type => "bool", text => _("(bootp/dhcp)") },
- 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('', _("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('', _('Freq should have the suffix k, M or G (for example, "2.46G" for 2.46 GHz fre­
- quency), or add enough \'0\'.'));
- return (1,6);
- }
- if ($intf->{WIRELESS_RATE} !~ /[0-9.]*[kGM]/) {
- $in->ask_warn('', _('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]
- }
- );
-}
-
-sub configureNetworkNet {
- my ($in, $netc, $intf, @devices) = @_;
-
- $netc->{dnsServer} ||= dns($intf->{IPADDR});
- $netc->{GATEWAY} ||= gateway($intf->{IPADDR});
-
- $::isInstall and $in->set_help('configureNetworkHost');
- $in->ask_from_entries_refH(_("Configuring network"),
-_("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 => _("Host name"), val => \$netc->{HOSTNAME} },
- { label => _("DNS server"), val => \$netc->{dnsServer} },
- { label => _("Gateway"), val => \$netc->{GATEWAY} },
- if_($::expert,
- { label => _("Gateway device"), val => \$netc->{GATEWAYDEV}, list => \@devices },
- ),
- ],
- );
-}
-
-sub miscellaneousNetwork {
- my ($in, $clicked) = @_;
- my $u = $::o->{miscellaneous} ||= {};
- $::isInstall and $in->set_help('configureNetworkProxy');
- $::expert || $clicked and $in->ask_from_entries_refH('',
- _("Proxies configuration"),
- [ { label => _("HTTP proxy"), val => \$u->{http_proxy} },
- { label => _("FTP proxy"), val => \$u->{ftp_proxy} },
- ],
- complete => sub {
- $u->{http_proxy} =~ m,^($|http://), or $in->ask_warn('', _("Proxy should be http://...")), return 1,0;
- $u->{ftp_proxy} =~ m,^($|ftp://), or $in->ask_warn('', _("Proxy should be ftp://...")), return 1,1;
- 0;
- }
- ) || return;
-}
-
-sub read_all_conf {
- my ($prefix, $netc, $intf) = @_;
- $netc ||= {}; $intf ||= {};
- add2hash($netc, read_conf("$prefix/etc/sysconfig/network")) if -r "$prefix/etc/sysconfig/network";
- 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' && $1 !~ /ppp/) {
- my $intf = findIntf($intf, $1);
- add2hash($intf, { getVarsFromSh("$prefix/etc/sysconfig/network-scripts/$_") });
- }
- }
-}
-
-#- configureNetwork2 : configure the network interfaces.
-#- input
-#- $prefix
-#- $netc
-#- $intf
-#- $install : a function that takes a list of package and install them : ex sub { system("urpmi --auto --best-output " . join(' ', @_)); }
-#- $netc input
-#- NETWORKING : networking flag : string : "yes" by default
-#- FORWARD_IPV4 : forward IP flag : string : "false" by default
-#- HOSTNAME : hostname : string : "localhost.localdomain" by default
-#- DOMAINNAME : domainname : string : $netc->{HOSTNAME} =~ /\.(.*)/ by default
-#- DOMAINNAME2 : well it's another domainname : have to look further why we used 2
-#- The following are facultatives
-#- DHCP_HOSTNAME : If you have a dhcp and want to set the hostname
-#- GATEWAY : gateway
-#- GATEWAYDEV : gateway interface
-#- NISDOMAIN : nis domain
-#- $netc->{dnsServer} : dns server 1
-#- $netc->{dnsServer2} : dns server 2
-#- $netc->{dnsServer3} : dns server 3 : note that we uses the dns1 for the LAN, and the 2 others for the internet conx
-#- $intf input: for each $device (for example ethx)
-#- $intf->{$device}{IPADDR} : IP address
-#- $intf->{$device}{NETMASK} : netmask
-#- $intf->{$device}{DEVICE} : DEVICE = $device
-#- $intf->{$device}{BOOTPROTO} : boot prototype : "bootp" or "dhcp" or "pump" or ...
-sub configureNetwork2 {
- my ($in, $prefix, $netc, $intf, $install) = @_;
- my $etc = "$prefix/etc";
-
- $netc->{wireless_eth} and $install->('wireless-tools');
- write_conf("$etc/sysconfig/network", $netc);
- write_resolv_conf("$etc/resolv.conf", $netc);
- write_interface_conf("$etc/sysconfig/network-scripts/ifcfg-$_->{DEVICE}", $_) foreach grep { $_->{DEVICE} } values %$intf;
- add2hosts("$etc/hosts", $netc->{HOSTNAME}, map { $_->{IPADDR} } values %$intf);
-
- if (grep { $_->{BOOTPROTO} =~ /^(dhcp)$/ } values %$intf) {
- $::isStandalone ? $in->standalone::pkgs_install('dhcpcd') : $install->('dhcpcd');
- }
- if (grep { $_->{BOOTPROTO} =~ /^(pump|bootp)$/ } values %$intf) {
- $::isStandalone ? $in->standalone::pkgs_install('pump') : $install->('pump');
- }
- #-res_init(); #- reinit the resolver so DNS changes take affect
-
- any::miscellaneousNetwork($prefix);
-}
-
-
-#-######################################################################################
-#- Wonderful perl :(
-#-######################################################################################
1;
diff --git a/perl-install/network/adsl.pm b/perl-install/network/adsl.pm
new file mode 100644
index 000000000..a09f58823
--- /dev/null
+++ b/perl-install/network/adsl.pm
@@ -0,0 +1,200 @@
+package network::adsl;
+
+#use network::tools;
+
+use vars qw(@ISA @EXPORT);
+
+@ISA = qw(Exporter);
+@EXPORT = qw(adsl_ask_info adsl_detect adsl_conf adsl_conf_backend);
+
+sub configure{
+ $::isInstall and $in->set_help('configureNetworkADSL');
+ conf_adsl_step1:
+ my $type = $in->ask_from_list_(_("Connect to the Internet"),
+ _("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'"), [__("use pppoe"), __("use pptp"), __("use dhcp")]) or return;
+ $type =~ s/use //;
+ if ($type eq 'pppoe') {
+ $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(_("Network interface"),
+ _("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}");
+ }
+ }
+ if ($type eq 'dhcp') {
+ $install->(qw(dhcpcd));
+ go_ethernet($netc, $intf, 'dhcp', '', '', $first_time) or goto conf_adsl_step1;
+ }
+ if ($type eq 'pptp') {
+ $install->(qw(pptp-adsl-fr));
+ $netcnx->{type} = "adsl_$type";
+ $netcnx->{"adsl_$type"} = {};
+ adsl_conf($netcnx->{"adsl_$type"}, $netc, $intf, $type) or goto conf_adsl_step1;
+ }
+ 1;
+}
+
+sub adsl_ask_info {
+ my ($adsl, $netc, $intf) = @_;
+ add2hash($netc, { dnsServer2 => '', dnsServer3 => '', DOMAINNAME2 => '' });
+ add2hash($adsl, { login => '', passwd => '', passwd2 => '' });
+ ask_info2($adsl, $netc);
+}
+
+#- adsl_detect : detect adsl modem on a given interface
+#- input :
+#- $interface : interface where the modem is supposed to be connected : should be "ethx"
+#- output:
+#- true/false : success|failed
+sub adsl_detect {
+ return;
+ my ($interface) = @_;
+ run_program::rooted($prefix, "ifconfig $interface 10.0.0.10 netmask 255.255.255.0");
+ my $ret=run_program::rooted($prefix, "/bin/ping -c 1 10.0.0.138 2> /dev/null");
+ run_program::rooted($prefix, "ifconfig $interface 0.0.0.0 netmask 255.255.255.0");
+ $ret;
+}
+
+sub adsl_conf {
+ my ($adsl, $netc, $intf, $adsl_type) = @_;
+
+ adsl_conf_step_1:
+ adsl_ask_info ($adsl, $netc, $intf) or return;
+ adsl_conf_step_2:
+ conf_network_card ($in, $netc, $intf, 'static' , '10.0.0.10' ) or goto adsl_conf_step_1;
+ adsl_conf_backend($adsl, $netc, $adsl_type);
+
+ adsl_conf_step_3:
+ $adsl->{atboot} = $in->ask_yesorno(_("ADSL configuration"),
+ _("Do you want to start your connection at boot?")
+ );
+ $::isStandalone and ask_connect_now($adsl, 'ppp0');
+ 1;
+}
+
+#- adsl_conf_backend : write adsl configuration
+#- input :
+#- $adsl
+#- $netc
+#- $adsl_type : type of cnx : string : "pptp" or "pppoe"
+#- $adsl input:
+#- $adsl->{login}, $adsl->{passwd}, $adsl->{atboot}
+#- $netc input:
+#- $netc->{NET_DEVICE}
+#- $netc->{dnsServer2}
+#- $netc->{dnsServer3}
+#- $netc->{DOMAINNAME2}
+#- $netc output:
+#- $netc->{NET_INTERFACE} is set to "ppp0"
+sub adsl_conf_backend {
+ my ($adsl, $netc, $adsl_type) = @_;
+
+ output("$prefix/etc/ppp/options",
+ $adsl_type eq 'pptp' ?
+"lock
+noipdefault
+noauth
+usepeerdns
+defaultroute
+" :
+"noipdefault
+usepeerdns
+hide-password
+defaultroute
+persist
+lock
+") if $adsl_type =~ /pptp|pppoe/;
+
+ write_secret_backend($adsl->{login}, $adsl->{passwd});
+
+ if ($adsl_type eq 'pppoe') {
+ substInFile {
+ s/ETH=.*\n/ETH=$netc->{NET_DEVICE}\n/;
+ s/USER=.*\n/USER=$adsl->{login}\n/;
+ } "$prefix/etc/ppp/pppoe.conf";
+ }
+
+ output ("$prefix$connect_file",
+ $adsl_type eq 'pptp' ?
+"#!/bin/bash
+/sbin/route del default
+/usr/bin/pptp 10.0.0.138 name $adsl->{login}
+"
+:
+"#!/bin/bash
+/sbin/route del default
+LC_ALL=C LANG=C LANGUAGE=C LC_MESSAGES=C /usr/sbin/adsl-start $netc->{NET_DEVICE} $adsl->{login}
+");
+ output ("$prefix$disconnect_file",
+ $adsl_type eq 'pptp' ?
+ "#!/bin/bash
+/usr/bin/killall pptp pppd
+"
+:
+"#!/bin/bash
+/usr/sbin/adsl-stop
+/usr/bin/killall pppoe pppd
+");
+ chmod 0755, "$prefix$disconnect_file";
+ chmod 0755, "$prefix$connect_file";
+
+ if ($adsl->{atboot}) {
+ output ("$prefix/etc/rc.d/init.d/adsl",
+ qq{
+#!/bin/bash
+#
+# adsl Bring up/down adsl connection
+#
+# chkconfig: 2345 11 89
+# description: Activates/Deactivates the adsl interfaces
+ case "$1" in
+ start)
+ echo -n "Starting adsl connection: "
+ $connect_file
+ touch /var/lock/subsys/adsl
+ echo -n adsl
+ echo
+ ;;
+ stop)
+ echo -n "Stopping adsl connection: "
+ $disconnect_file
+ echo -n adsl
+ echo
+ rm -f /var/lock/subsys/adsl
+ ;;
+ restart)
+ $0 stop
+ echo -n "Waiting 10 sec before restarting adsl."
+ sleep 10
+ $0 start
+ ;;
+ status)
+ ;;
+ *)
+ echo "Usage: adsl {start|stop|status|restart}"
+ exit 1
+esac
+exit 0
+ });
+ chmod 0755, "$prefix/etc/rc.d/init.d/adsl";
+ $::isStandalone ? system("/sbin/chkconfig --add adsl") : do {
+ symlinkf ("../init.d/adsl", "$prefix/etc/rc.d/rc$_") foreach
+ '0.d/K11adsl', '1.d/K11adsl', '2.d/K11adsl', '3.d/S89adsl', '5.d/S89adsl', '6.d/K11adsl';
+ };
+ }
+ else {
+ -e "$prefix/etc/rc.d/init.d/adsl" and do{
+ system("/sbin/chkconfig --del adsl");
+ unlink "$prefix/etc/rc.d/init.d/adsl";
+ };
+ }
+ $netc->{NET_INTERFACE}="ppp0";
+}
+
+1;
diff --git a/perl-install/network/ethernet.pm b/perl-install/network/ethernet.pm
new file mode 100644
index 000000000..c03d64e9a
--- /dev/null
+++ b/perl-install/network/ethernet.pm
@@ -0,0 +1,117 @@
+package network::ethernet;
+
+use network;
+use modules;
+use any;
+use detect_devices;
+use common qw(:file);
+use vars qw(@ISA @EXPORT);
+
+@ISA = qw(Exporter);
+@EXPORT = qw(conf_network_card conf_network_card_backend go_ethernet);
+
+sub conf_network_card {
+ my ($netc, $intf, $type, $ipadr, $netadr) = @_;
+ #-type =static or dhcp
+ any::setup_thiskind($in, 'net', !$::expert, 1);
+ my @all_cards=conf_network_card_backend($prefix, $netc, $intf, $type, undef, $ipadr, $netadr);
+ my $interface;
+ @all_cards == () and $in->ask_warn('', _("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] and goto l1;
+ again :
+ $interface = $in->ask_from_list(_("Choose the network interface"),
+ _("Please choose which network adapter you want to use to connect to Internet"),
+ [ map { $_->[0] . ($_->[1] ? " ( using module $_->[1] )" : "") } @all_cards ]
+ ) or return;
+ defined $interface or goto again;
+ l1:
+ $::isStandalone and modules::write_conf($prefix);
+
+ my $device=conf_network_card_backend($prefix, $netc, $intf, $type, $interface, $ipadr, $netadr, $interface);
+ if ( $::isStandalone and !($type eq "dhcp")) {
+ $in->ask_yesorno(_("Network interface"),
+ _("I'm about to restart the network device:\n") . $device . _("\nDo you agree?"), 1) and network::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 setup_thiskind($in, 'net', !$::expert, 1) or setup_thiskind_backend before calling this function. Basically, you call this function in 2 times.
+#- input
+#- $prefix
+#- $netc
+#- $intf
+#- $type : type of interface, must be given if $interface is : string : "static" or "dhcp"
+#- $interface : facultative, if given, set this interface and return it in a proper form. If not, return @all_cards
+#- $ipadr : facultative, ip address of the interface : string
+#- $netadr : facultative, netaddress of the interface : string
+#- when $interface is given, informations are written in $intf and $netc. If not, @all_cards is returned.
+#- $intf output: $device is the result of
+#- $intf->{$device}->{DEVICE} : which device is concerned : $device is the result of $interface =~ /(eth[0-9]+)/; my $device = $1;;
+#- $intf->{$device}->{BOOTPROTO} : $type
+#- $intf->{$device}->{NETMASK} : '255.255.255.0'
+#- $intf->{$device}->{NETWORK} : $netadr
+#- $intf->{$device}->{ONBOOT} : "yes"
+#- $netc output:
+#- $netc->{nb_cards} : nb of ethernet cards
+#- $netc->{NET_DEVICE} : this is used to indicate that this eth card is used to connect to internet : $device
+#- output:
+#- $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 ($prefix, $netc, $intf, $type, $interface, $ipadr, $netadr) = @_;
+ #-type =static or dhcp
+ if (!$interface) {
+ my @all_cards = detect_devices::getNet();
+ $netc->{nb_cards} = @all_cards;
+
+ my @devs = modules::get_pcmcia_devices();
+ modules::mergein_conf("$prefix/etc/modules.conf");
+ my $saved_driver;
+ return map {
+ my $interface = $_;
+ my $a = modules::get_alias($interface);
+ my $b;
+ foreach (@devs) {
+ $_->{device} eq $interface and $b = $_->{driver};
+ }
+ $a ||= $b;
+ if ($a) { $saved_driver = $a }
+ [$interface, $saved_driver];
+ } @all_cards;
+ }
+ my ($device) = $interface =~ /(eth[0-9]+)/ or die("the interface is not an ethx");
+ $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};
+ network::configureNetwork($prefix, $netc, $in, $intf, $first_time) or return;
+ output "$prefix$connect_file",
+ qq(
+#!/bin/bash
+ifup $netc->{NET_DEVICE}
+);
+ output "$prefix$disconnect_file",
+ qq(
+#!/bin/bash
+ifdown $netc->{NET_DEVICE}
+);
+ chmod 0755, "$prefix$disconnect_file";
+ chmod 0755, "$prefix$connect_file";
+ if ( $::isStandalone and $netc->{NET_DEVICE}) {
+ $in->ask_yesorno(_("Network interface"),
+ _("I'm about to restart the network device $netc->{NET_DEVICE}. Do you agree?"), 1) and system("$prefix/sbin/ifdown $netc->{NET_DEVICE}; $prefix/sbin/ifup $netc->{NET_DEVICE}");
+ }
+ 1;
+}
+
+1;
diff --git a/perl-install/network/isdn.pm b/perl-install/network/isdn.pm
new file mode 100644
index 000000000..25c18cebf
--- /dev/null
+++ b/perl-install/network/isdn.pm
@@ -0,0 +1,268 @@
+package network::isdn;
+
+#use network::tools;
+use modules;
+use common qw(:file);
+use vars qw(@ISA @EXPORT);
+
+@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_step_1:
+ defined $netc->{autodetect}{isdn}{id} and goto intern_pci;
+ $::isInstall and $in->set_help('configureNetworkISDN');
+ my $e = $in->ask_from_list_(_("Network Configuration Wizard"),
+ _("What kind is your ISDN connection?"), [ __("Internal ISDN card"), __("External ISDN modem")]
+ ) or return;
+ if ($e =~ /card/) {
+ intern_pci:
+ $netcnx->{type}='isdn_internal';
+ $netcnx->{isdn_internal}={};
+ $netcnx->{isdn_internal}{$_} = $netc->{autodetect}{isdn}{$_} foreach ('description', 'vendor', 'id', 'driver', 'card_type', 'type');
+ isdn_detect($netcnx->{isdn_internal}, $netc) or return;
+ } else {
+ $netcnx->{type}='isdn_external';
+ $netcnx->{isdn_external}={};
+ $netcnx->{isdn_external}{device}=$netc->{autodetect}{modem};
+ $netcnx->{isdn_external}{special_command}='AT&F&O2B40';
+ pppConfig($netcnx->{isdn_external}, $mouse, $netc) or goto isdn_step_1;
+ }
+ 1;
+}
+
+sub isdn_write_config {
+ my ($isdn) = @_;
+ isdn_write_config_step_1:
+ my $e = $in->ask_from_list_(_("Network Configuration Wizard"),
+ _("Which ISDN configuration do you prefer?
+
+* The full configuration uses isdn4net. It contains powerfull tools, but is tricky to configure for a newbie, and not standard.
+
+* The light configuration is easier to understand, more standard, but with less tools.
+
+We recommand the light configuration.
+
+"), [ __("Light configuration"), __("Full configuration (isdn4net)")]
+ ) or return;
+ $install->($e =~ /Light/ ? 'isdn-light' : 'isdn4net', 'isdn4k-utils');
+ isdn_write_config_backend($isdn, $e =~ /Light/);
+ $::isStandalone and ask_connect_now($isdn, 'ippp0');
+ 1;
+}
+
+#- isdn_write_config_backend : write isdn info, only for ippp0 -> ask_connect_now
+#- input :
+#- $isdn
+#- $light : boolean : if yes : uses the isdn-light package, if not, isdn4net
+#- $isdn input:
+#- $isdn->{login} $isdn->{passwd} $isdn->{phone_in} $isdn->{phone_out} $isdn->{dialing_mode}
+#- $isdn->{driver} $isdn->{type} $isdn->{irq} $isdn->{mem} $isdn->{io} $isdn->{io0} $isdn->{io1}
+sub isdn_write_config_backend {
+ my ($isdn, $light) = @_;
+ if ($light) {
+ any::setup_thiskind($in, 'isdn', !$::expert, 1);
+ 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 = .*\n/EAZ = $isdn->{phone_in}/;
+ s/PHONE_OUT = .*\n/PHONE_OUT = $isdn->{phone_out}/;
+ } "$prefix/etc/isdn/$f";
+ chmod 0600, $f;
+ }
+ } else {
+ my $f = "$prefix/etc/isdn/profile/link/myisp";
+ output $f,
+ qq(
+I4L_USERNAME="$isdn->{login}"
+I4L_SYSNAME=""
+I4L_LOCALMSN="$isdn->{phone_in}"
+I4L_REMOTE_OUT="$isdn->{phone_out}"
+I4L_DIALMODE="$isdn->{dialing_mode}"
+);
+ chmod 0600, $f;
+
+ output "$prefix/etc/isdn/profile/card/mycard",
+ qq(
+I4L_MODULE="$isdn->{driver}"
+I4L_TYPE="$isdn->{type}"
+I4L_IRQ="$isdn->{irq}"
+I4L_MEMBASE="$isdn->{mem}"
+I4L_PORT="$isdn->{io}"
+I4L_IO0="$isdn->{io0}"
+I4L_IO1="$isdn->{io1}"
+);
+
+ output "$prefix/etc/ppp/ioptions",
+ "lock
+usepeerdns
+defaultroute
+";
+ system "$prefix/etc/rc.d/init.d/isdn4linux restart";
+ }
+ write_secret_backend($isdn->{login}, $isdn->{passwd});
+
+ output "$prefix$connect_file",
+ "#!/bin/bash
+/sbin/route del default
+/sbin/ifup ippp0
+/sbin/isdnctrl dial ippp0
+";
+
+ output "$prefix$disconnect_file",
+ "#!/bin/bash
+/sbin/isdnctrl hangup ippp0
+/sbin/ifdown ippp0
+";
+ chmod 0755, "$prefix$disconnect_file";
+ chmod 0755, "$prefix$connect_file";
+ 1;
+}
+
+#- get_info_isdn_backend : fills the infos from the line of the tree returned into $isdn and $netc
+#- input :
+#- $isdn
+#- $netc
+#- $name : the line choosen in the tree of ISP : string : /^(.*)\|(.*)\|(.*)$/ with $1=Land $2=City $3=ISP_name
+#- $file : 1st location of the file : ISDN_DB_FILE
+#- $file2 : 2nd location of the file : ISDN_DB_FILE
+#- $isdn ouput
+#- $isdn->{user_name}, $isdn->{phone_out}, $netc->{DOMAINNAME2}, $netc->{dnsServer2}, $netc->{dnsServer3},
+#- $netc output
+#- $netc->{DOMAINNAME2}, $netc->{dnsServer2}, $netc->{dnsServer3}
+sub get_info_providers_backend {
+ my ($isdn, $netc, $name, $file) = @_;
+ $name eq 'Unlisted - edit manually' and return;
+ foreach (catMaybeCompressed($file)) {
+ chop;
+ my ($name_, $phone, $real, $dns1, $dns2) = split '=>';
+ if ($name eq $name_) {
+ @{$isdn}{qw(user_name phone_out DOMAINNAME2 dnsServer3 dnsServer2)} =
+ ((split(/\|/, $name_))[2], $phone, $real, $dns1, $dns2);
+ }
+ }
+}
+
+sub isdn_ask_info {
+ my ($isdn, $netc) = @_;
+ my $f = "$ENV{SHARE_PATH}/ldetect-lst/isdn.db";
+ $f = "$prefix$f" if !-e $f;
+ my $str= $in->ask_from_treelist( _("ISDN Configuration"), _("Select your provider.\n If it's not in the list, choose Unlisted"),
+ '|', ['Unlisted - edit manually',
+ netconnect::read_providers_backend($f)], 'Unlisted - edit manually')
+ or return;
+ get_info_providers_backend($isdn, $netc, $str || 'Unlisted - edit manually', $f);
+ $isdn->{$_} ||= '' foreach qw(phone_in phone_out dialing_mode login passwd passwd2 idl);
+ add2hash($netc, { dnsServer2 => '', dnsServer3 => '', DOMAINNAME2 => '' });
+ ask_info2($isdn, $netc);
+}
+
+sub isdn_ask_protocol {
+ my @toto=(
+ { description => $::expert ? _("Europe (EDSS1)") : _("Europe"),
+ protokol => 2},
+ { description => $::expert ? _("Rest of the world \n no D-Channel (leased lines)") : _("Rest of the world"),
+ protokol => 3}
+ );
+ my $e = $in->ask_from_listf(_("ISDN Configuration"),
+ _("Which protocol do you want to use ?"),
+ sub { $_[0]{description} },
+ \@toto ) or return 0;
+ $e->{protokol};
+}
+
+sub isdn_ask {
+ my ($isdn, $netc, $label) = @_;
+ isdn_ask_step_1:
+ my $e = $in->ask_from_list_(_("ISDN Configuration"),
+ $label . "\n" . _("What kind of card do you have?"),
+ [ __("ISA / PCMCIA"), __("PCI"), __("I don't know") ]
+ ) or return;
+ if ($e =~ /PCI/) {
+ $isdn->{card_type} = 'pci';
+ } else {
+ $in->ask_from_list_(_("ISDN Configuration"),
+ _("
+If you have an ISA card, the values on the next screen should be right.\n
+If you have a PCMCIA card, you have to know the irq and io of your card.
+"),
+ [ __("Continue"), __("Abort") ]) eq 'Continue' or goto isdn_ask_step_1;
+ $isdn->{card_type} = 'isa';
+ }
+
+ isdn_ask_step_2:
+ $e = $in->ask_from_listf(_("ISDN Configuration"),
+ _("Which is your ISDN card ?"),
+ sub { $_[0]{description} },
+ [ grep {$_->{card} eq $isdn->{card_type}; } @isdndata ] ) or goto isdn_ask_step_1;
+ $isdn->{driver}='hisax';
+ $e->{$_} and $isdn->{$_} = $e->{$_} foreach qw(type mem io io0 io1 irq);
+
+ isdn_ask_step_3:
+ $isdn->{protocol} = isdn_ask_protocol() or goto isdn_ask_step_2;
+ isdn_ask_step_4:
+ isdn_ask_info($isdn, $netc) or goto isdn_ask_step_3;
+ isdn_write_config($isdn) or goto isdn_ask_step_4;
+ 1;
+}
+
+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, _("I have detected an ISDN PCI Card, but I don't know the type. Please select one 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) or goto isdn_detect_step_2;
+ }
+ } else {
+ isdn_ask($isdn, $netc, _("No ISDN PCI card found. Please select one on the next screen.")) or return;
+ }
+ $netc->{$_}='ippp0' foreach 'NET_DEVICE', 'NET_INTERFACE';
+ 1;
+}
+
+#- isdn_detect_backend : detects isdn pci card and fills the infos in $isdn : only detects one card
+#- input
+#- $isdn
+#- $isdn output:
+#- $isdn->{description} $isdn->{vendor} $isdn->{id} $isdn->{driver} $isdn->{card_type} $isdn->{type}
+
+sub isdn_detect_backend {
+ my ($isdn) = @_;
+ if (my ($c) = (modules::get_that_type('isdn'))) {
+ $isdn->{$_} = $c->{$_} foreach qw(description vendor id driver options);
+ $isdn->{$_} = sprintf("%0x", $isdn->{$_}) foreach ('vendor', 'id');
+ $isdn->{card_type} = 'pci';
+ $isdn->{type} = $isdnid2type{$isdn->{vendor} . $isdn->{id}}; #If the card is not listed, type is void. You have to ask it then.
+ }
+}
+
+#- isdn_get_list : return isdn cards descriptions list. This function is not use internally.
+#- output : descriptions : list of strings
+
+sub isdn_get_list {
+ map { $_->{description} } @isdndata;
+}
+
+#- isdn_get_info : return isdn card infos. This function is not use internally.
+#- input : the description of the card (see isdn_get_list)
+#- output : a reference on the decription of the card. : ref on a hash(description,type,irq,mem,io,io0,io1card,)
+
+sub isdn_get_info {
+ my ($desc) = @_;
+ foreach (@isdndata) {
+ return $_ if ($_->{description} eq $desc);
+ }
+}
+
+1;
diff --git a/perl-install/network/modem.pm b/perl-install/network/modem.pm
new file mode 100644
index 000000000..e97ad13fd
--- /dev/null
+++ b/perl-install/network/modem.pm
@@ -0,0 +1,88 @@
+package network::modem;
+use common qw(:common :file);
+use network::tools;
+use vars qw(@ISA @EXPORT);
+
+@ISA = qw(Exporter);
+@EXPORT = qw(pppConfig modem_detect_backend);
+
+sub configure{
+ my ($netcnx, $mouse, $netc) = @_;
+ $netcnx->{type}='modem';
+ $netcnx->{$netcnx->{type}}={};
+ $netcnx->{modem}{device}=$netc->{autodetect}{modem};
+ modem_step_1:
+ pppConfig($netcnx->{$netcnx->{type}}, $mouse, $netc) or return;
+ output "$prefix$connect_file",
+ q(#!/bin/bash
+ifup ppp0
+);
+ output "$prefix$disconnect_file",
+ q(#!/bin/bash
+ifdown ppp0
+killall pppd
+);
+ chmod 0755, "$prefix$disconnect_file";
+ chmod 0755, "$prefix$connect_file";
+ if ($::isStandalone) { ask_connect_now($netcnx->{$netcnx->{type}}, 'ppp0') or goto modem_step_1 }
+ 1;
+}
+
+sub pppConfig {
+ my ($modem, $mouse, $netc) = @_;
+
+ $mouse ||={};
+ $mouse->{device} ||= readlink "$prefix/dev/mouse";
+ $::isInstall and $in->set_help('selectSerialPort');
+ $modem->{device} ||= $in->ask_from_listf('', _("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;
+
+ $::isStandalone || $in->set_help('configureNetworkISP');
+ $in->ask_from_entries_refH('', _("Dialup options"), [
+{ label => _("Connection name"), val => \$modem->{connection} },
+{ label => _("Phone number"), val => \$modem->{phone} },
+{ label => _("Login ID"), val => \$modem->{login} },
+{ label => _("Password"), val => \$modem->{passwd}, hidden => 1 },
+{ label => _("Authentication"), val => \$modem->{auth}, list => [ __("PAP"), __("Terminal-based"), __("Script-based") ] },
+{ label => _("Domain name"), val => \$modem->{domain} },
+{ label => _("First DNS Server (optional)"), val => \$modem->{dns1} },
+{ label => _("Second DNS Server (optional)"), val => \$modem->{dns2} },
+ ]) or return;
+ any::pppConfig($modem, $install);
+ $netc->{$_}='ppp0' foreach 'NET_DEVICE', 'NET_INTERFACE';
+ 1;
+}
+#-AT&F&O2B40
+#- DialString=ATDT0231389595((
+
+#- modem_detect_backend : detects modem on serial ports and fills the infos in $modem : detects only one card
+#- input
+#- $modem
+#- $mouse : facultative, hash containing device to exclude not to test mouse port : ( device => /ttyS[0-9]/ )
+#- output:
+#- $modem->{device} : device where the modem were detected
+sub modem_detect_backend {
+ my ($modem, $mouse) = @_;
+ $mouse ||={};
+ $mouse->{device} ||= readlink "/dev/mouse";
+ my $serdev = arch() =~ /ppc/ ? "macserial" : "serial";
+ eval { modules::load("$serdev") };
+
+ detect_devices::probeSerialDevices();
+ foreach ('modem', map { "ttyS$_" } (0..7)) {
+ next if $mouse->{device} =~ /$_/;
+ next unless -e "/dev/$_";
+ detect_devices::hasModem("/dev/$_") and $modem->{device} = "$_", last;
+ }
+
+ #- add an alias for macserial on PPC
+ modules::add_alias('serial', $serdev) if (arch() =~ /ppc/ && $modem->{device});
+ my @devs = modules::get_pcmcia_devices();
+ foreach (@devs) {
+ $_->{type} =~ /serial/ and $modem->{device} = $_->{device};
+ }
+
+}
+
+1;
diff --git a/perl-install/network/netconnect.pm b/perl-install/network/netconnect.pm
new file mode 100644
index 000000000..73a00a64e
--- /dev/null
+++ b/perl-install/network/netconnect.pm
@@ -0,0 +1,597 @@
+
+package netconnect;
+
+use diagnostics;
+use strict;
+use vars qw($in $install $prefix $isdn_init @isdndata %isdnid2type $connect_file $disconnect_file $connect_prog);
+
+use common qw(:common :file :functional :system);
+use log;
+use detect_devices;
+use run_program;
+use network::netconnect_consts;
+use modules;
+use any;
+use mouse;
+use network;
+use commands;
+#require Data::Dumper;
+
+use network::tools;
+
+$connect_file = "/etc/sysconfig/network-scripts/net_cnx_up";
+$disconnect_file = "/etc/sysconfig/network-scripts/net_cnx_down";
+$connect_prog = "/etc/sysconfig/network-scripts/net_cnx_pg";
+
+sub init { ($prefix, $in, $install) = @_ }
+
+#- intro is called only in standalone.
+sub intro {
+ ($prefix, my $netcnx, $in, $install) = @_;
+ my ($netc, $mouse, $intf) = ({}, {}, {});
+ my $text;
+ my $connected;
+ read_net_conf($netcnx, $netc);
+ if (!$::isWizard) {
+ if (connected($netc)) {
+ $text=_("You are currently connected to internet.") . (-e $disconnect_file ? _("\nYou can disconnect or reconfigure your connection.") : _("\nYou can reconfigure your connection."));
+ $connected=1;
+ } else {
+ $text=_("You are not currently connected to Internet.") . (-e $connect_file ? _("\nYou can connect to Internet or reconfigure your connection.") : _("\nYou can reconfigure your connection."));
+ $connected=0;
+ }
+ my @l=(
+ !$connected && -e $connect_file ? { description => _("Connect to Internet"),
+ c => 1} : (),
+ $connected && -e $disconnect_file ? { description => _("Disconnect from Internet"),
+ c => 2} : (),
+ { description => _("Configure network connection (LAN or Internet)"),
+ c => 3},
+ );
+ my $e = $in->ask_from_listf(_("Internet connection & configuration"),
+ _($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, $install, 0, 0) if ($e->{c}==3);
+ } else {
+ main($prefix, $netcnx, $netc, $mouse, $in, $intf, $install, 0, 0);
+ }
+}
+
+sub detect {
+ 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/.*\|//;
+
+ any::setup_thiskind_backend('net', undef);
+ require network::ethernet;
+ network::ethernet->import;
+ my @all_cards = conf_network_card_backend ('', undef, undef, undef, undef, undef, undef);
+ require network::adsl;
+ network::adsl->import;
+ map {
+ ( !$net_install and adsl_detect("", $_->[0]) ) ? $auto_detect->{adsl}=$_->[0] : $auto_detect->{lan}{$_->[0]}=$_->[1]; } @all_cards;
+ my $modem={};
+ require network::modem;
+ network::modem->import;
+ modem_detect_backend($modem);#, $mouse);
+ $modem->{device} and $auto_detect->{modem}=$modem->{device};
+}
+
+sub main {
+ ($prefix, my $netcnx, my $netc, my $mouse, $in, my $intf, $install, my $first_time, my $direct_fr) = @_;
+ $netc->{minus_one}=0; #When one configure an eth in dhcp without gateway
+ $::isInstall and $in->set_help('configureNetwork');
+ my $continue = !(!$::expert && values %$intf > 0 && $first_time);
+ $::isStandalone and read_net_conf($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::read_all_conf($prefix, $netc ||= {}, $intf ||= {});
+# $in->set_help('') unless $::isStandalone;
+
+#use network::adsl;
+#use network::ethernet;
+#use network::isdn;
+#use network::modem;
+
+ my $configure_modem = sub {
+ require network::modem;
+ network::modem::configure($netcnx, $mouse, $netc);
+ };
+
+ my $configure_isdn = sub {
+ require network::isdn;
+ network::isdn::configure($netcnx, $netc);
+ };
+ my $configure_adsl = sub {
+ require network::adsl;
+ network::adsl::configure($netcnx, $netc);
+ };
+ my $configure_cable = sub {
+ $::isInstall and $in->set_help('configureNetworkCable');
+ $netcnx->{type}='cable';
+ # $netcnx->{cable}={};
+ # $in->ask_from_entries_ref(_("Cable connection"),
+ # _("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''."),
+ # [_("Host name:")], [ \$netcnx->{cable}{hostname} ]);
+ if ($::expert) {
+ #- dhcpcd, etc are program names; no need to translate them.
+ my @m=(
+ { description => "dhcpcd",
+ c => 1},
+ { description => "dhcpxd",
+ c => 3},
+ { description => "dhcp-client",
+ c => 4},
+ );
+ if (my $f = $in->ask_from_listf(_("Connect to the Internet"),
+ _("Which dhcp client do you want to use?
+Default is dhcpcd"),
+ sub { $_[0]{description} },
+ \@m )) {
+ $f->{c}==1 and $netcnx->{dhcp_client}="dhcpcd" and $install->(qw(dhcpcd));
+ $f->{c}==3 and $netcnx->{dhcp_client}="dhcpxd" and $install->(qw(dhcpxd));
+ $f->{c}==4 and $netcnx->{dhcp_client}="dhcp-client" and $install->(qw(dhcp-client));
+ }
+ } else {
+ $install->(qw(dhcpcd));
+ }
+ go_ethernet($netc, $intf, 'dhcp', '', '', $first_time);
+ };
+ my $configure_lan = sub {
+ $::isInstall and $in->set_help('configureNetworkIP');
+ network::configureNetwork($prefix, $netc, $in, $intf, $first_time) or return;
+ network::configureNetwork2($in, $prefix, $netc, $intf, $install);
+ if ($::isStandalone and $in->ask_yesorno(_("Network configuration"),
+ _("Do you want to restart the network"), 1)) {
+ run_program::rooted($prefix, "/etc/rc.d/init.d/network stop");
+ if (!run_program::rooted($prefix, "/etc/rc.d/init.d/network start")) {
+ $in->ask_okcancel(_("Network Configuration"), _("A problem occured while restarting the network: \n\n%s", `/etc/rc.d/init.d/network start`), 0) or return;
+ }
+ }
+ $netc->{NETWORKING} = "yes";
+ if ($netc->{GATEWAY}) {
+ $netcnx->{type}='lan';
+ $netcnx->{NET_DEVICE} = $netc->{NET_DEVICE} = '';
+ $netcnx->{NET_INTERFACE} = 'lan';#$netc->{NET_INTERFACE};
+ }
+ output "$prefix$connect_file",
+ qq(
+#!/bin/bash
+/etc/rc.d/init.d/network restart
+);
+ output "$prefix$disconnect_file",
+ qq(
+#!/bin/bash
+/etc/rc.d/init.d/network stop
+/sbin/ifup lo
+);
+ chmod 0755, "$prefix$disconnect_file";
+ chmod 0755, "$prefix$connect_file";
+ $::isStandalone and modules::write_conf($prefix);
+ 1;
+ };
+
+ 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 or $in->ask_okcancel(_("Network Configuration"),
+ _("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 {
+ output "$prefix$connect_file",
+ qq(
+#!/bin/bash
+ifup eth0
+);
+ output "$prefix$disconnect_file",
+ qq(
+#!/bin/bash
+ifdown eth0
+);
+ chmod 0755, "$prefix$disconnect_file";
+ chmod 0755, "$prefix$connect_file";
+ $direct_net_install = 1;
+ goto step_5;
+};
+ }
+
+ $netc->{autodetection}=1;
+ $netc->{autodetect}={};
+
+ step_1:
+ $::Wizard_no_previous=1;
+ my @profiles=get_profiles();
+ $in->ask_from_entries_refH(_("Network Configuration Wizard"),
+ _("Welcome to The Network Configuration Wizard\n\nWe are about to configure your internet/network connection.\nIf you don't want to use the auto detection, deselect the checkbox.\n"),
+ [
+ if_(@profiles > 1, { label => _("Choose the profile to configure"), val => \$netcnx->{PROFILE}, list => \@profiles }),
+ { label => _("Use auto detection"), val => \$netc->{autodetection}, type => 'bool' },
+ ]
+ ) or goto step_5;
+ undef $::Wizard_no_previous;
+ set_profile($netcnx);
+ if ($netc->{autodetection}) {
+ my $w = $in->wait_message(_("Network Configuration Wizard"), _("Detecting devices..."));
+ detect($netc->{autodetect}, $::isInstall && ($in->{method} eq "ftp" || $in->{method} eq "http" || $in->{method} eq "nfs"));
+ }
+
+ step_2:
+ my $set_default;
+ my %conf;
+ my @l = (
+ [_("Normal modem connection"), $netc->{autodetect}{modem}, __("detected on port %s"), \$conf{modem}],
+ [_("ISDN connection"), $netc->{autodetect}{isdn}{description}, __("detected %s"), \$conf{isdn}],
+ [_("DSL (or ADSL) connection"), $netc->{autodetect}{adsl}, __("detected on interface %s"), \$conf{adsl}],
+ [_("Cable connection"), $netc->{autodetect}{cable}, __("cable connection detected"), \$conf{cable}],
+ [_("LAN connection"), $netc->{autodetect}{lan}, __("ethernet card(s) detected"), \$conf{lan}]
+ );
+ my $i=0;
+ map { defined $set_default or do { $_->[1] and $set_default=$i; }; $i++; } @l;
+ foreach (keys %{$netc->{autodetect}}) { print "plop $_\n" };
+# my $e = $in->ask_from_listf(_("Network Configuration Wizard"),
+# _("How do you want to connect to the Internet?"), sub { translate($_[0][0]) . if_($_[0][1], " - " . _ ($_[0][2], $_[0][1])) }, \@l , $l[$set_default]
+# ) or goto step_1;
+
+# my @l2 = map {
+#{
+# label => $_[0][0] . if_($_[0][1], " - " . _ ($_[0][2], $_[0][1])),
+# val => $_[0][3], type => 'bool'}
+# } @l;
+ my $e = $in->ask_from_entries_refH(_("Network Configuration Wizard"),
+ _("Choose"),
+ [
+ map { {
+ label => $_->[0] . if_($_->[1], " - " . _ ($_->[2], $_->[1])),
+ val => $_->[3], type => 'bool'} } @l
+ ]
+ ) or goto step_1;
+
+# load_conf ($netcnx, $netc, $intf);
+
+ $conf{modem} and do { $configure_modem->() or goto step_2 };
+ $conf{isdn} and do { $configure_isdn->() or goto step_2 };
+ $conf{adsl} and do { $configure_adsl->() or goto step_2 };
+ $conf{cable} and do { $configure_cable->() or goto step_2 };
+ $conf{lan} and do { $configure_lan->() or goto step_2 };
+
+ step_3:
+
+ my $m = _("Congratulation, The network and internet configuration is finished.
+
+The configuration will now be applied to your system.") . if_($::isStandalone,
+_("After that is done, we recommend you to restart your X
+environnement to avoid hostname changing problem."));
+ if ($::isWizard) {
+ $::Wizard_no_previous=1;
+ $::Wizard_finished=1;
+ $in->ask_okcancel(_("Network Configuration"), $m, 1);
+ undef $::Wizard_no_previous;
+ undef $::Wizard_finished;
+ } else { $in->ask_warn('', $m ); }
+
+ step_5:
+
+ network::configureNetwork2($in, $prefix, $netc, $intf, $install);
+
+ if ($netcnx->{type} =~ /modem/ || $netcnx->{type} =~ /isdn_external/) {
+ output "$prefix$connect_prog",
+ qq(
+#!/bin/bash
+if [ -n "\$DISPLAY" ]; then
+if [ -e /usr/bin/kppp ]; then
+/usr/bin/kppp &
+else
+/usr/sbin/net_monitor --connect
+fi
+else
+$connect_file
+fi
+);
+ } elsif ($netcnx->{type}) {
+ output "$prefix$connect_prog",
+ qq(
+#!/bin/bash
+if [ -n "\$DISPLAY" ]; then
+/usr/sbin/net_monitor --connect
+else
+$connect_file
+fi
+);
+ } else {
+ output "$prefix$connect_prog",
+ qq(
+#!/bin/bash
+/usr/sbin/draknet
+);
+ }
+ if ($direct_net_install) {
+ output "$prefix$connect_prog",
+ qq(
+#!/bin/bash
+if [ -n "\$DISPLAY" ]; then
+/usr/sbin/net_monitor --connect
+else
+$connect_file
+fi
+);
+ }
+ chmod 0755, "$prefix$connect_prog";
+ $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 ($netc->{NET_DEVICE} and $netc->{NETWORKING} ne 'no' and $::isStandalone and $::expert) {
+#- exists $netc->{nb_cards} or do {
+#- any::setup_thiskind($in, 'net', !$::expert, 1);
+#- $netc->{nb_cards} = listlength(detect_devices::getNet());
+#- };
+#- ($netc->{nb_cards} - $netc->{minus_one} - (get_net_device($prefix) =~ /eth.+/ ? 1 : 0) > 0) and $in->ask_okcancel(_("Network Configuration"),
+#-_("Now that your Internet connection is configured,
+#-your computer can be configured to share its Internet connection.
+#-Note: you need a dedicated Network Adapter to set up a Local Area Network (LAN).
+#-
+#-Would you like to setup the Internet Connection Sharing?
+#-"), 1) and system("/usr/sbin/drakgw --direct");
+#- }
+}
+
+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}};
+ any::setup_thiskind_backend('net', undef);
+ my @all_cards = conf_network_card_backend ($prefix, $netc, $intf, undef, undef, undef, undef);
+
+ $intf = { %$intf };
+
+ output("$prefix/etc/sysconfig/network-scripts/draknet_conf",
+ "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->{NET_DEVICE} : $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}
+ISDNHomePhone=$isdn->{phone_in}
+ISDNLogin=$isdn->{login}
+ISDNPassword=$isdn->{passwd}
+ISDNConfirmPassword=$isdn->{passwd2}
+
+PPPInterfacesList=
+PPPDevice=$modem->{device}
+PPPDeviceSpeed=
+PPPConnectionName=$modem->{connection}
+PPPProviderPhone=$modem->{phone}
+PPPProviderDomain=$modem->{domain}
+PPPProviderDNS1=$modem->{dns1}
+PPPProviderDNS2=$modem->{dns2}
+PPPLogin=$modem->{connection}
+PPPPassword=$modem->{login}
+PPPConfirmPassword=$modem->{passwd}
+PPPAuthentication=$modem->{auth}
+PPPSpecialCommand=" . ($netcnx->{type} eq 'isdn_external' ? $netcnx->{isdn_external}{special_command} : '' ) . "
+
+ADSLInterfacesList=
+ADSLModem=" . q(# Obsolete information. Please don't use it.) . "
+ADSLType=" . ($netcnx->{type} =~ /adsl/ ? $netcnx->{type} : '') . "
+ADSLProviderDomain=$netc->{DOMAINNAME2}
+ADSLProviderDNS1=$netc->{dnsServer2}
+ADSLProviderDNS2=$netc->{dnsServer3}
+ADSLLogin=$adsl->{login}
+ADSLPassword=$adsl->{passwd}
+DOMAINNAME2=$netc->{DOMAINNAME2}"
+ );
+ chmod 0600, "$prefix/etc/sysconfig/network-scripts/draknet_conf";
+ my $a = $netcnx->{PROFILE} ? $netcnx->{PROFILE} : "default";
+ commands::cp("-f", "$prefix/etc/sysconfig/network-scripts/draknet_conf", "$prefix/etc/sysconfig/network-scripts/draknet_conf." . $a);
+ chmod 0600, "$prefix/etc/sysconfig/network-scripts/draknet_conf";
+ chmod 0600, "$prefix/etc/sysconfig/network-scripts/draknet_conf." . $a;
+ foreach ( ["$prefix$connect_file", "up"], ["$prefix$disconnect_file", "down"], ["$prefix$connect_prog", "prog"] ) {
+ my $file = "$prefix/etc/sysconfig/network-scripts/net_" . $_->[1] . "." . $a;
+ -e ($_->[0]) and commands::cp("-f", $_->[0], $file) and chmod 0755, $file;
+ }
+}
+
+sub set_profile {
+ my ($netcnx, $profile) = @_;
+ $profile ||= $netcnx->{PROFILE};
+ $profile or return;
+ my $f = "$prefix/etc/sysconfig/network-scripts/draknet_conf";
+ -e ($f . "." . $profile) or return;
+ $netcnx->{PROFILE}=$profile;
+ print "changing to $profile\n";
+ commands::cp("-f", $f . "." . $profile, $f);
+ foreach ( ["up", "$prefix$connect_file"], ["down", "$prefix$disconnect_file"], ["prog", "$prefix$connect_prog"]) {
+ my $c = "$prefix/etc/sysconfig/network-scripts/net_" . $_->[0] . "." . $profile;
+ -e ($c) and commands::cp("-f", $c, $_->[1]);
+ }
+}
+
+sub del_profile {
+ my ($netcnx, $profile) = @_;
+ $profile or return;
+ $profile eq "default" and return;
+ print "deleting $profile\n";
+ commands::rm("-f", "$prefix/etc/sysconfig/network-scripts/draknet_conf." . $profile);
+ commands::rm("-f", "$prefix/etc/sysconfig/network-scripts/net_{up,down,prog}." . $profile);
+}
+
+sub add_profile {
+ my ($netcnx, $profile) = @_;
+ $profile or return;
+ $profile eq "default" and return;
+ print "creating $profile\n";
+ my $cmd1 = "$prefix/etc/sysconfig/network-scripts/draknet_conf." . ($netcnx->{PROFILE} ? $netcnx->{PROFILE} : "default");
+ my $cmd2 = "$prefix/etc/sysconfig/network-scripts/draknet_conf." . $profile;
+ commands::cp("-f", $cmd1, $cmd2);
+}
+
+sub get_profiles {
+ my @a;
+ my $i=0;
+ foreach (glob("/etc/sysconfig/network-scripts/draknet_conf.*")) {
+ s/.*\.//;
+ $a[$i] = $_;
+ $i++;
+ }
+ @a;
+}
+
+sub load_conf {
+ my ($netcnx, $netc, $intf)=@_;
+ my $adsl_pptp={};
+ my $adsl_pppoe={};
+ my $modem={};
+ my $isdn_external={};
+ my $isdn={};
+ my $system_name;
+ my $domain_name;
+
+ if (-e "$prefix/etc/sysconfig/network-scripts/draknet_conf") {
+ foreach (cat_("$prefix/etc/sysconfig/network-scripts/draknet_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;
+ /^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;
+ /^PPPProviderPhone=(.*)$/ and $modem->{phone} = $1;
+ /^PPPProviderDomain=(.*)$/ and $modem->{domain} = $1;
+ /^PPPProviderDNS1=(.*)$/ and $modem->{dns1} = $1;
+ /^PPPProviderDNS2=(.*)$/ and $modem->{dns2} = $1;
+ /^PPPLogin=(.*)$/ and $modem->{login} = $1;
+ /^PPPPassword=(.*)$/ and $modem->{passwd} = $1;
+ /^PPPAuthentication=(.*)$/ and $modem->{auth} = $1;
+ 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));
+ }
+}
+
+sub get_net_device {
+ ${{ getVarsFromSh("/etc/sysconfig/draknet") }}{NET_DEVICE};
+}
+
+sub read_net_conf {
+ my ($netcnx, $netc)=@_;
+ add2hash($netcnx, { getVarsFromSh("$prefix/etc/sysconfig/draknet") });
+ $netc->{$_} = $netcnx->{$_} foreach 'NET_DEVICE', 'NET_INTERFACE';
+#- print "type : $netcnx->{type}\n device : $netcnx->{NET_DEVICE}\n interface : $netcnx->{NET_INTERFACE}\n";
+ add2hash($netcnx->{$netcnx->{type}}, { getVarsFromSh("$prefix/etc/sysconfig/draknet." . $netcnx->{type}) });
+}
+
+sub set_net_conf {
+ my ($netcnx, $netc)=@_;
+ setVarsInShMode("$prefix/etc/sysconfig/draknet", 0600, $netcnx, "NET_DEVICE", "NET_INTERFACE", "type", "PROFILE" );
+ setVarsInShMode("$prefix/etc/sysconfig/draknet." . $netcnx->{type}, 0600, $netcnx->{$netcnx->{type}}); #- doesn't work, don't know why
+ setVarsInShMode("$prefix/etc/sysconfig/draknet.netc", 0600, $netc); #- doesn't work, don't know why
+}
+
+#---------------------------------------------
+# WONDERFULL pad
+#---------------------------------------------
+1;
diff --git a/perl-install/network/network.pm b/perl-install/network/network.pm
new file mode 100644
index 000000000..091675646
--- /dev/null
+++ b/perl-install/network/network.pm
@@ -0,0 +1,486 @@
+package network::network; # $Id$
+
+use diagnostics;
+use strict;
+
+#-######################################################################################
+#- misc imports
+#-######################################################################################
+use Socket;
+
+use common qw(:common :file :system :functional);
+use detect_devices;
+use run_program;
+use any;
+use log;
+use vars qw(@ISA @EXPORT);
+
+@ISA = qw(Exporter);
+@EXPORT = qw(resolv configureNetworkIntf netmask dns is_ip configureNetwork masked_ip findIntf addDefaultRoute all write_interface_conf read_all_conf dnsServers guessHostname configureNetworkNet read_resolv_conf getVarsFromSh 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) = @_;
+ my %netc = getVarsFromSh($file);
+ \%netc;
+}
+
+sub read_resolv_conf {
+ my ($file) = @_;
+ my @l = qw(dnsServer dnsServer2 dnsServer3);
+ my %netc;
+
+ local *F; open F, $file or die "cannot open $file: $!";
+ local $_;
+ while (<F>) {
+ /^\s*nameserver\s+(\S+)/ and $netc{shift @l} = $1;
+ }
+ \%netc;
+}
+
+sub read_interface_conf {
+ my ($file) = @_;
+ my %intf = getVarsFromSh($file) or die "cannot open file $file: $!";
+
+ $intf{BOOTPROTO} ||= 'static';
+ $intf{isPtp} = $intf{NETWORK} eq '255.255.255.255';
+ $intf{isUp} = 1;
+ \%intf;
+}
+
+sub up_it {
+ my ($prefix, $intfs) = @_;
+ $_->{isUp} and return foreach values %$intfs;
+ my $f = "/etc/resolv.conf"; symlink "$prefix/$f", $f;
+ run_program::rooted($prefix, "/etc/rc.d/init.d/network", "start");
+ $_->{isUp} = 1 foreach values %$intfs;
+}
+sub down_it {
+ my ($prefix, $intfs) = @_;
+ run_program::rooted($prefix, "/etc/rc.d/init.d/network", "stop");
+ $_->{isUp} = 1 foreach values %$intfs;
+}
+
+sub write_conf {
+ my ($file, $netc) = @_;
+
+ add2hash($netc, {
+ NETWORKING => "yes",
+ FORWARD_IPV4 => "false",
+ HOSTNAME => "localhost.localdomain",
+ });
+ ($netc->{DOMAINNAME}) = ($netc->{HOSTNAME} =~ /\.(.*)/);
+
+ setVarsInSh($file, $netc, qw(NETWORKING FORWARD_IPV4 DHCP_HOSTNAME HOSTNAME DOMAINNAME GATEWAY GATEWAYDEV NISDOMAIN));
+}
+
+sub write_resolv_conf {
+ my ($file, $netc) = @_;
+
+ #- get the list of used dns.
+ my %used_dns; @used_dns{$netc->{dnsServer}, $netc->{dnsServer2}, $netc->{dnsServer3}} = (1, 2, 3);
+
+ unless ($netc->{DOMAINNAME} || $netc->{DOMAINNAME2} || keys %used_dns > 0) {
+ unlink($file);
+ log::l("neither domain name nor dns server are configured");
+ return 0;
+ }
+
+ my (%search, %dns, @unknown);
+ local *F; open F, $file;
+ local $_;
+ while (<F>) {
+ /^[#\s]*search\s+(.*?)\s*$/ and $search{$1} = $., next;
+ /^[#\s]*nameserver\s+(.*?)\s*$/ and $dns{$1} = $., next;
+ /^.*# ppp temp entry\s*$/ and next;
+ /^[#\s]*(\S.*?)\s*$/ and push @unknown, $1;
+ }
+
+ close F; open F, ">$file" or die "cannot write $file: $!";
+ print F "# search $_\n" foreach grep { $_ ne "$netc->{DOMAINNAME} $netc->{DOMAINNAME2}" } sort { $search{$a} <=> $search{$b} } keys %search;
+ print F "search $netc->{DOMAINNAME} $netc->{DOMAINNAME2}\n\n" if ($netc->{DOMAINNAME} || $netc->{DOMAINNAME2});
+ print F "# nameserver $_\n" foreach grep { ! exists $used_dns{$_} } sort { $dns{$a} <=> $dns{$b} } keys %dns;
+ print F "nameserver $_\n" foreach sort { $used_dns{$a} <=> $used_dns{$b} } grep { $_ } keys %used_dns;
+ print F "\n";
+ print F "# $_\n" foreach @unknown;
+ print F "\n";
+ print F "# ppp temp entry\n";
+
+ #-res_init(); # reinit the resolver so DNS changes take affect
+ 1;
+}
+
+sub write_interface_conf {
+ my ($file, $intf) = @_;
+
+ my @ip = split '\.', $intf->{IPADDR};
+ my @mask = split '\.', $intf->{NETMASK};
+ add2hash($intf, {
+ BROADCAST => join('.', mapn { int $_[0] | ~int $_[1] & 255 } \@ip, \@mask),
+ NETWORK => join('.', mapn { int $_[0] & $_[1] } \@ip, \@mask),
+ ONBOOT => bool2yesno(!member($intf->{DEVICE}, map { $_->{device} } detect_devices::probeall())),
+ });
+ setVarsInSh($file, $intf, qw(DEVICE BOOTPROTO IPADDR NETMASK NETWORK BROADCAST ONBOOT), ($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 {
+ my ($file, $hostname, @ips) = @_;
+ my %l;
+ $l{$_} = $hostname foreach @ips;
+
+ local *F;
+ if (-e $file) {
+ open F, $file or die "cannot open $file: $!";
+ /\s*(\S+)(.*)/ and $l{$1} ||= $2 foreach <F>;
+ }
+ log::l("writing host information to $file");
+ open F, ">$file" or die "cannot write $file: $!";
+ while (my ($ip, $v) = each %l) {
+ $ip or next;
+ print F "$ip";
+ if ($v =~ /^\s/) {
+ print F $v;
+ } else {
+ print F "\t\t$v";
+ print F " $1" if $v =~ /(.*?)\./;
+ }
+ print F "\n";
+ }
+}
+
+# The interface/gateway needs to be configured before this will work!
+sub guessHostname {
+ my ($prefix, $netc, $intf) = @_;
+
+ $intf->{isUp} && dnsServers($netc) or return 0;
+ $netc->{HOSTNAME} && $netc->{DOMAINNAME} and return 1;
+
+ write_resolv_conf("$prefix/etc/resolv.conf", $netc);
+
+ my $name = gethostbyaddr(Socket::inet_aton($intf->{IPADDR}), AF_INET) or log::l("reverse name lookup failed"), return 0;
+
+ log::l("reverse name lookup worked");
+
+ add2hash($netc, { HOSTNAME => $name });
+ 1;
+}
+
+sub addDefaultRoute {
+ my ($netc) = @_;
+ c::addDefaultRoute($netc->{GATEWAY}) if $netc->{GATEWAY};
+}
+
+sub sethostname {
+ my ($netc) = @_;
+ 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::l("resolved $name in $a");
+ $a;
+}
+
+sub dnsServers {
+ my ($netc) = @_;
+ my %used_dns; @used_dns{$netc->{dnsServer}, $netc->{dnsServer2}, $netc->{dnsServer3}} = (1, 2, 3);
+ sort { $used_dns{$a} <=> $used_dns{$b} } grep { $_ } keys %used_dns;
+}
+
+sub findIntf {
+ my ($intf, $device) = @_;
+ $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) = @_;
+ return 0 unless $ip =~ $ip_regexp;
+ my @fields = ($1, $2, $3, $4);
+ foreach (@fields) {
+ return 0 if $_ < 0 || $_ > 255;
+ }
+ return 1;
+}
+
+sub netmask {
+ my ($ip) = @_;
+ return "255.255.255.0" unless is_ip($ip);
+ $ip =~ $ip_regexp;
+ if ($1 >= 1 && $1 < 127) {
+ return "255.0.0.0"; #-1.0.0.0 to 127.0.0.0
+ } elsif ($1 >= 128 && $1 <= 191 ){
+ return "255.255.0.0"; #-128.0.0.0 to 191.255.0.0
+ } elsif ($1 >= 192 && $1 <= 223) {
+ return "255.255.255.0";
+ } else {
+ return "255.255.255.255"; #-experimental classes
+ }
+}
+
+sub masked_ip {
+ my ($ip) = @_;
+ return "" unless is_ip($ip);
+ my @mask = netmask($ip) =~ $ip_regexp;
+ my @ip = $ip =~ $ip_regexp;
+ for (my $i = 0; $i < @ip; $i++) {
+ $ip[$i] &= int $mask[$i];
+ }
+ join(".", @ip);
+}
+
+sub dns {
+ my ($ip) = @_;
+ my $mask = masked_ip($ip);
+ my @masked = masked_ip($ip) =~ $ip_regexp;
+ $masked[3] = 2;
+ join (".", @masked);
+
+}
+sub gateway {
+ my ($ip) = @_;
+ my @masked = masked_ip($ip) =~ $ip_regexp;
+ $masked[3] = 1;
+ join (".", @masked);
+
+}
+
+sub configureNetwork {
+ my ($prefix, $netc, $in, $intf, $first_time) = @_;
+ local $_;
+ any::setup_thiskind($in, 'net', !$::expert, 1);
+ my @l = detect_devices::getNet() or die _("no network card found");
+ my @all_cards = netconnect::conf_network_card_backend ($prefix, $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(_("Hostname"), _("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_entries_refH(_("Configuring network"),
+_("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 => _("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;
+ if ( $netc->{GATEWAY} ) {
+ unlink "$prefix/etc/sysconfig/network-scripts/net_cnx_up";
+ unlink "$prefix/etc/sysconfig/network-scripts/net_cnx_down";
+ undef $netc->{NET_DEVICE};
+ }
+ }
+ miscellaneousNetwork($in);
+ 1;
+}
+
+
+sub configureNetworkIntf {
+ my ($netc, $in, $intf, $net_device, $skip, $module) = @_;
+ my $text;
+ my @wireless_modules = ("airo_cs", "netwave_cs", "ray_cs", "wavelan_cs", "wvlan_cs");
+ if (member($module, @wireless_modules)) {
+ $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 = _("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 = _("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 @fields = qw(IPADDR NETMASK);
+ $::isStandalone or $in->set_help('configureNetworkIP');
+ $in->ask_from_entries_refH(_("Configuring network device %s", $intf->{DEVICE}),
+ (_("Configuring network device %s", $intf->{DEVICE}) . ( $module ? _(" (driver $module)") : '' ) ."\n\n") .
+ $text,
+ [ { label => _("IP address"), val => \$intf->{IPADDR}, disabled => sub { $pump } },
+ { label => _("Netmask"), val => \$intf->{NETMASK}, disabled => sub { $pump } },
+ { label => _("Automatic IP"), val => \$pump, type => "bool", text => _("(bootp/dhcp)") },
+ 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('', _("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('', _('Freq should have the suffix k, M or G (for example, "2.46G" for 2.46 GHz fre­
+ quency), or add enough \'0\'.'));
+ return (1,6);
+ }
+ if ($intf->{WIRELESS_RATE} !~ /[0-9.]*[kGM]/) {
+ $in->ask_warn('', _('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]
+ }
+ );
+}
+
+sub configureNetworkNet {
+ my ($in, $netc, $intf, @devices) = @_;
+
+ $netc->{dnsServer} ||= dns($intf->{IPADDR});
+ $netc->{GATEWAY} ||= gateway($intf->{IPADDR});
+
+ $::isInstall and $in->set_help('configureNetworkHost');
+ $in->ask_from_entries_refH(_("Configuring network"),
+_("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 => _("Host name"), val => \$netc->{HOSTNAME} },
+ { label => _("DNS server"), val => \$netc->{dnsServer} },
+ { label => _("Gateway"), val => \$netc->{GATEWAY} },
+ if_($::expert,
+ { label => _("Gateway device"), val => \$netc->{GATEWAYDEV}, list => \@devices },
+ ),
+ ],
+ );
+}
+
+sub miscellaneousNetwork {
+ my ($in, $clicked) = @_;
+ my $u = $::o->{miscellaneous} ||= {};
+ $::isInstall and $in->set_help('configureNetworkProxy');
+ $::expert || $clicked and $in->ask_from_entries_refH('',
+ _("Proxies configuration"),
+ [ { label => _("HTTP proxy"), val => \$u->{http_proxy} },
+ { label => _("FTP proxy"), val => \$u->{ftp_proxy} },
+ ],
+ complete => sub {
+ $u->{http_proxy} =~ m,^($|http://), or $in->ask_warn('', _("Proxy should be http://...")), return 1,0;
+ $u->{ftp_proxy} =~ m,^($|ftp://), or $in->ask_warn('', _("Proxy should be ftp://...")), return 1,1;
+ 0;
+ }
+ ) || return;
+}
+
+sub read_all_conf {
+ my ($prefix, $netc, $intf) = @_;
+ $netc ||= {}; $intf ||= {};
+ add2hash($netc, read_conf("$prefix/etc/sysconfig/network")) if -r "$prefix/etc/sysconfig/network";
+ 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' && $1 !~ /ppp/) {
+ my $intf = findIntf($intf, $1);
+ add2hash($intf, { getVarsFromSh("$prefix/etc/sysconfig/network-scripts/$_") });
+ }
+ }
+}
+
+#- configureNetwork2 : configure the network interfaces.
+#- input
+#- $prefix
+#- $netc
+#- $intf
+#- $install : a function that takes a list of package and install them : ex sub { system("urpmi --auto --best-output " . join(' ', @_)); }
+#- $netc input
+#- NETWORKING : networking flag : string : "yes" by default
+#- FORWARD_IPV4 : forward IP flag : string : "false" by default
+#- HOSTNAME : hostname : string : "localhost.localdomain" by default
+#- DOMAINNAME : domainname : string : $netc->{HOSTNAME} =~ /\.(.*)/ by default
+#- DOMAINNAME2 : well it's another domainname : have to look further why we used 2
+#- The following are facultatives
+#- DHCP_HOSTNAME : If you have a dhcp and want to set the hostname
+#- GATEWAY : gateway
+#- GATEWAYDEV : gateway interface
+#- NISDOMAIN : nis domain
+#- $netc->{dnsServer} : dns server 1
+#- $netc->{dnsServer2} : dns server 2
+#- $netc->{dnsServer3} : dns server 3 : note that we uses the dns1 for the LAN, and the 2 others for the internet conx
+#- $intf input: for each $device (for example ethx)
+#- $intf->{$device}{IPADDR} : IP address
+#- $intf->{$device}{NETMASK} : netmask
+#- $intf->{$device}{DEVICE} : DEVICE = $device
+#- $intf->{$device}{BOOTPROTO} : boot prototype : "bootp" or "dhcp" or "pump" or ...
+sub configureNetwork2 {
+ my ($in, $prefix, $netc, $intf, $install) = @_;
+ my $etc = "$prefix/etc";
+
+ $netc->{wireless_eth} and $install->('wireless-tools');
+ write_conf("$etc/sysconfig/network", $netc);
+ write_resolv_conf("$etc/resolv.conf", $netc);
+ write_interface_conf("$etc/sysconfig/network-scripts/ifcfg-$_->{DEVICE}", $_) foreach grep { $_->{DEVICE} } values %$intf;
+ add2hosts("$etc/hosts", $netc->{HOSTNAME}, map { $_->{IPADDR} } values %$intf);
+
+ if (grep { $_->{BOOTPROTO} =~ /^(dhcp)$/ } values %$intf) {
+ $::isStandalone ? $in->standalone::pkgs_install('dhcpcd') : $install->('dhcpcd');
+ }
+ if (grep { $_->{BOOTPROTO} =~ /^(pump|bootp)$/ } values %$intf) {
+ $::isStandalone ? $in->standalone::pkgs_install('pump') : $install->('pump');
+ }
+ #-res_init(); #- reinit the resolver so DNS changes take affect
+
+ any::miscellaneousNetwork($prefix);
+}
+
+
+#-######################################################################################
+#- Wonderful perl :(
+#-######################################################################################
+1;
diff --git a/perl-install/network/tools.pm b/perl-install/network/tools.pm
new file mode 100644
index 000000000..8f89b9cc0
--- /dev/null
+++ b/perl-install/network/tools.pm
@@ -0,0 +1,76 @@
+package network::tools;
+
+use vars qw(@ISA @EXPORT);
+
+@ISA = qw(Exporter);
+@EXPORT = qw(write_secret_backend ask_connect_now connect_backend disconnect_backend read_providers_backend ask_info2 connected disconnected);
+
+sub write_secret_backend {
+ my ($a, $b) = @_;
+ foreach ("pap-secrets", "chap-secrets") {
+ substInFile { s/^$a.*\n//; $_ .= "\n'$a' * '$b' * \n" if eof } "$prefix/etc/ppp/$_";
+ }
+}
+
+sub ask_connect_now {
+ my ($cnx, $inter) = @_;
+ if ($in->ask_yesorno(_("Internet configuration"),
+ _("Do you want to try to connect to the Internet now?")
+ )) {
+ my $up;
+ {
+ my $w = $in->wait_message('', _("Testing your connection..."), 1);
+ connect_backend();
+ sleep 5;
+ my $netc = {};
+ $up=connected($netc);
+ }
+ my $m = $up ? (_("The system is now connected to Internet.") .
+ if_($::isInstall, _("For Security reason, it will be disconnected now.")) ) :
+ _("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(_("Network Configuration"), $m, 1);
+ undef $::Wizard_no_previous;
+ undef $::Wizard_finished;
+ } else { $in->ask_warn('', $m ); }
+ $::isInstall and disconnect_backend();
+ }
+ 1;
+}
+
+sub connect_backend { run_program::rooted($prefix, "$connect_prog &") }
+
+sub disconnect_backend { run_program::rooted($prefix, "$disconnect_file &") }
+
+sub read_providers_backend { my ($file) = @_; map { /(.*?)=>/ } catMaybeCompressed($file) }
+
+sub ask_info2 {
+ my ($cnx, $netc) = @_;
+ $::isInstall and $in->set_help('configureNetworkDNS');
+ $in->ask_from_entries_refH(_("Connection Configuration"),
+ _("Please fill or check the field below"),
+ [
+ if__ ($cnx->{irq}, { label => _("Card IRQ"), val => \$cnx->{irq} }) ,
+ if__ ($cnx->{mem}, { label => _("Card mem (DMA)"), val => \$cnx->{mem} }),
+ if__ ($cnx->{io}, { label => _("Card IO"), val => \$cnx->{io} }),
+ if__ ($cnx->{io0}, { label => _("Card IO_0"), val => \$cnx->{io0} }),
+ if__ ($cnx->{io1}, { label => _("Card IO_1"), val => \$cnx->{io1} }),
+ if__ ($cnx->{phone_in}, { label => _("Your personal phone number"), val => \$cnx->{phone_in} }),
+ if__ ($netc->{DOMAINNAME2}, { label => _("Provider name (ex provider.net)"), val => \$netc->{DOMAINNAME2} }),
+ if__ ($cnx->{phone_out}, { label => _("Provider phone number"), val => \$cnx->{phone_out} }),
+ if__ ($netc->{dnsServer2}, { label => _("Provider dns 1"), val => \$netc->{dnsServer2} }),
+ if__ ($netc->{dnsServer3}, { label => _("Provider dns 2"), val => \$netc->{dnsServer3} }),
+ if__ ($cnx->{dialing_mode}, { label => _("Dialing mode"), val => \$cnx->{dialing_mode}, list => [ "auto", "manual"] }),
+ if__ ($cnx->{login}, { label => _("Account Login (user name)"), val => \$cnx->{login} }),
+ if__ ($cnx->{passwd}, { label => _("Account Password"), val => \$cnx->{passwd} }),
+ ]
+ ) or return;
+ 1;
+}
+
+sub connected { gethostbyname("www.mandrakesoft.com") ? 1 : 0; }
+
+sub disconnected { }
diff --git a/perl-install/standalone/draknet b/perl-install/standalone/draknet
index 847d12564..c2671dde4 100755
--- a/perl-install/standalone/draknet
+++ b/perl-install/standalone/draknet
@@ -22,7 +22,7 @@ use lib qw(/usr/lib/libDrakX);
use interactive;
use standalone;
-use netconnect;
+use network::netconnect;
use c;
my $xpm_path="/usr/share/libDrakX/pixmaps";