package network::tools; use common; use run_program; use vars qw(@ISA @EXPORT); use MDK::Common::Globals "network", qw($in $prefix $disconnect_file $connect_prog $connect_file $disconnect_file); @ISA = qw(Exporter); @EXPORT = qw(write_cnx_script write_secret_backend ask_connect_now connect_backend disconnect_backend read_providers_backend ask_info2 type2interface connected disconnected); @EXPORT_OK = qw($in); sub write_cnx_script { my($netc, $type, $up, $down) = @_; $type or output ("$prefix$_", $netc->{internet_cnx}{$netc->{internet_cnx_choice}}{$_}) foreach ($connect_file, $disconnect_file); foreach ([$connect_file, $up], [$disconnect_file, $down]) { $netc->{internet_cnx}{$type}{$_->[0]}=$_->[1]; chmod 0755, "$prefix" . $_->[0]; } } sub write_secret_backend { my ($a, $b) = @_; foreach my $i ("pap-secrets", "chap-secrets") { substInFile { s/^'$a'.*\n//; $_ .= "\n'$a' * '$b' * \n" if eof } "$prefix/etc/ppp/$i"; } } sub ask_connect_now { $::Wizard_no_previous=1; #- FIXME : code the exception to be generated by ask_yesorno, to be able to remove the $::Wizard_no_previous=1; 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(); } 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(); } undef $::Wizard_no_previous; 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(_("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 (optional)"), val => \$netc->{dnsServer2} }), if __ ($netc->{dnsServer3}, { label => _("Provider dns 2 (optional)"), val => \$netc->{dnsServer3} }), if __ ($cnx->{dialing_mode}, { label => _("Dialing mode"), val => \$cnx->{dialing_mode},list=>["auto","manual"]}), if __ ($cnx->{speed}, { label => _("Connection speed"), val => \$cnx->{speed}, list => ["64 Kb/s", "128 Kb/s"]}), if __ ($cnx->{huptimeout}, { label => _("Connection timeout (in sec)"), val => \$cnx->{huptimeout} }), if __ ($cnx->{login}, { label => _("Account Login (user name)"), val => \$cnx->{login} }), if __ ($cnx->{passwd}, { label => _("Account Password"), val => \$cnx->{passwd} }), ] ) or return; 1; } 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("www.mandrakesoft.com") ? 1 : 0 } sub disconnected { }