package network::netconnect; # $Id$
use strict;
use common;
use log;
use detect_devices;
use run_program;
use modules;
use any;
use mouse;
use network::network;
use network::tools;
use MDK::Common::Globals "network", qw($in);
sub detect {
my ($auto_detect, $o_class) = @_;
my %l = (
isdn => sub {
require network::isdn;
$auto_detect->{isdn} = network::isdn::detect_backend();
},
lan => sub { # ethernet
modules::load_category('network/main|gigabit|usb');
require network::ethernet;
$auto_detect->{lan} = { map { $_->[0] => $_->[1] } network::ethernet::get_eth_cards() };
},
adsl => sub {
require network::adsl;
$auto_detect->{adsl} = network::adsl::adsl_detect();
},
modem => sub {
$auto_detect->{modem} = { map { $_->{description} || "$_->{MANUFACTURER}|$_->{DESCRIPTION} ($_->{device})" => $_ } detect_devices::getModem() };
},
);
$l{$_}->() foreach $o_class || keys %l;
return;
}
sub init_globals {
my ($in) = @_;
MDK::Common::Globals::init(in => $in);
}
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("$::prefix/etc/sysconfig/clock");
my @country;
foreach (keys %tmz2country) {
if ($_ eq $tm_parse{ZONE}) {
unshift @country, $tmz2country{$_};
} else { push @country, $tmz2country{$_} };
}
\@country;
}
# load sub category's wizard pages into main wizard data structure
sub get_subwizard {
my ($wiz, $type) = @_;
my %net_conf_callbacks = (adsl => sub { require network::adsl; &network::adsl::get_wizard },
#cable => sub { require network::ethernet; &network::ethernet::get_wizard },
#isdn => sub { require network::isdn; &network::isdn::get_wizard },
#lan => sub { require network::ethernet; &network::ethernet::get_wizard },
#modem => sub { require network::modem; &network::modem::get_wizard },
);
$net_conf_callbacks{$type}->($wiz);
}
# configuring all network devices
sub real_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, @all_cards, %eth_intf);
my (%connections, @connection_list, $is_wireless);
my ($modem, $modem_name, $modem_conf_read, $modem_dyn_dns, $modem_dyn_ip);
my ($adsl_type, @adsl_devices, $adsl_failed, $adsl_answer, %adsl_data, $adsl_data, $adsl_provider, $adsl_old_provider);
my ($ntf_name, $ipadr, $netadr, $gateway_ex, $up, $need_restart_network);
my ($isdn, $isdn_name, $isdn_type, %isdn_cards);
my $my_isdn = join('', N("Manual choice"), " (", N("Internal ISDN card"), ")");
my ($module, $auto_ip, $protocol, $onboot, $needhostname, $hotplug, $track_network_id, @fields); # lan config
my $success = 1;
my $ethntf = {};
my $db_path = "$::prefix/usr/share/apps/kppp/Provider";
my (%countries, @isp, $country, $provider, $old_provider);
my $config = {};
eval(cat_("$::prefix/etc/sysconfig/drakconnect"));
my %wireless_mode = (N("Ad-hoc") => "Ad-hoc",
N("Managed") => "Managed",
N("Master") => "Master",
N("Repeater") => "Repeater",
N("Secondary") => "Secondary",
N("Auto") => "Auto",
);
my %l10n_lan_protocols = (
static => N("Manual configuration"),
dhcp => N("Automatic IP (BOOTP/DHCP)"),
if_(0,
dhcp_zeroconf => N("Automatic IP (BOOTP/DHCP/Zeroconf)"),
)
);
my $_w = N("Protocol for the rest of the world");
my %isdn_protocols = (
2 => N("European protocol (EDSS1)"),
3 => N("Protocol for the rest of the world\nNo D-Channel (leased lines)"),
);
network::tools::remove_initscript();
init_globals($in);
network::network::read_net_conf($netcnx, $netc, $intf);
modules::mergein_conf();
$netc->{autodetect} = {};
my $lan_detect = sub {
detect($netc->{autodetect}, 'lan');
modules::interactive::load_category($in, 'network/main|gigabit|pcmcia|usb|wireless', !$::expert, 0);
@all_cards = network::ethernet::get_eth_cards();
%eth_intf = network::ethernet::get_eth_cards_names(@all_cards);
require list_modules;
%eth_intf = map { $_->[0] => join(': ', $_->[0], $_->[2]) }
grep { $is_wireless ^ !c::isNetDeviceWirelessAware($_->[0]) } @all_cards;
};
my $find_lan_module = sub {
if (my $dev = find { $_->{device} eq $ethntf->{DEVICE} } detect_devices::pcmcia_probe()) { # PCMCIA case
$module = $dev->{driver};
} elsif ($dev = find { $_->[0] eq $ethntf->{DEVICE} } @all_cards) {
$module = $dev->[1];
} else { $module = "" }
};
my $is_hotplug_blacklisted = sub {
bool2yesno($is_wireless ||
member($module, qw(b44 forcedeth madwifi_pci)) ||
find { $_->{device} eq $ntf_name } detect_devices::pcmcia_probe());
};
my %adsl_devices = (
speedtouch => N("Alcatel speedtouch USB modem"),
sagem => N("Sagem USB modem"),
bewan => N("Bewan modem"),
eci => N("ECI Hi-Focus modem"), # this one needs eci agreement
);
my %adsl_types = (
dhcp => N("Dynamic Host Configuration Protocol (DHCP)"),
manual => N("Manual TCP/IP configuration"),
pptp => N("Point to Point Tunneling Protocol (PPTP)"),
pppoe => N("PPP over Ethernet (PPPoE)"),
pppoa => N("PPP over ATM (PPPoA)"),
);
my %encapsulations = (
1 => N("Bridged Ethernet LLC"),
2 => N("Bridged Ethernet VC"),
3 => N("Routed IP LLC"),
4 => N("Routed IP VC"),
5 => N("PPPOA LLC"),
6 => N("PPPOA VC"),
);
my %ppp_auth_methods = (
0 => N("Script-based"),
1 => N("PAP"),
2 => N("Terminal-based"),
3 => N("CHAP"),
4 => N("PAP/CHAP"),
);
my $offer_to_connect = sub {
return "ask_connect_now" if $netc->{internet_cnx_choice} eq 'adsl' && $adsl_devices{$ntf_name};
return "ask_connect_now" if member($netc->{internet_cnx_choice}, qw(modem isdn));
return "end";
};
my $after_start_on_boot_step = sub {
if ($netc->{internet_cnx_choice}) {
write_cnx_script($netc);
$netcnx->{type} = $netc->{internet_cnx}{$netc->{internet_cnx_choice}}{type} if $netc->{internet_cnx_choice};
} else {
undef $netc->{NET_DEVICE};
}
network::network::configureNetwork2($in, $::prefix, $netc, $intf);
$network_configured = 1;
return "restart" if $need_restart_network && $::isStandalone && !$::expert;
return $offer_to_connect->();
};
my $goto_start_on_boot_ifneeded = sub {
return $after_start_on_boot_step->() if $netcnx->{type} =~ /lan|cable/;
return "network_on_boot";
};
my $save_cnx = sub {
if (keys %$config) {
require Data::Dumper;
output("$::prefix/etc/sysconfig/drakconnect", Data::Dumper->Dump([ $config ], [ '$p' ]));
}
return $goto_start_on_boot_ifneeded->();
};
my $handle_multiple_cnx = sub {
$need_restart_network = 1 if $netcnx->{type} =~ /adsl|cable|lan/;
my $nb = keys %{$netc->{internet_cnx}};
if (1 < $nb) {
return "multiple_internet_cnx";
} else {
$netc->{internet_cnx_choice} = (keys %{$netc->{internet_cnx}})[0] if $nb == 1;
$save_cnx->();
return $goto_start_on_boot_ifneeded->()
}
};
# main wizard:
my $wiz;
$wiz =
{
defaultimage => "drakconnect.png",
name => N("Network & Internet Configuration"),
pages => {
welcome =>
{
pre => sub {
# keep b/c of translations in case they can be reused somewhere else:
my @_a = (N("(detected on port %s)", 'toto'),
#-PO: here, "(detected)" string will be appended to eg "ADSL connection"
N("(detected %s)", 'toto'), N("(detected)"));
my @connections =
([ N("Modem connection"), "modem" ],
[ N("ISDN connection"), "isdn" ],
[ N("ADSL connection"), "adsl" ],
[ N("Cable connection"), "cable" ],
[ N("LAN connection"), "lan" ],
[ N("Wireless connection"), "lan" ],
|