package network::modem; # $Id$ use strict; use common; use any; use modules; use detect_devices; use mouse; use network::tools; sub first_modem { my ($netc) = @_; first(grep { $_->{device} =~ m!^/dev! } values %{$netc->{autodetect}{modem}}); } sub ppp_read_conf { my ($netcnx, $netc) = @_; my $modem = $netcnx->{$netcnx->{type}} ||= {}; $modem->{device} ||= first_modem($netc)->{device}; my %l = getVarsFromSh("$::prefix/usr/share/config/kppprc"); $l{Authentication} = 4 if !exists $l{Authentication}; $modem->{$_} ||= $l{$_} foreach qw(Authentication Gateway IPAddr SubnetMask); $modem->{connection} ||= $l{Name}; $modem->{domain} ||= $l{Domain}; ($modem->{dns1}, $modem->{dns2}) = split(',', $l{DNS}); foreach (cat_("/etc/sysconfig/network-scripts/chat-ppp0")) { /.*ATDT(\d*)/ and $modem->{phone} ||= $1; } foreach (cat_("/etc/sysconfig/network-scripts/ifcfg-ppp0")) { /NAME=(['"]?)(.*)\1/ and $modem->{login} ||= $2; } $modem->{login} ||= $l{Username}; my $secret = network::tools::read_secret_backend(); foreach (@$secret) { $modem->{passwd} ||= $_->{passwd} if $_->{login} eq $modem->{login}; } #my $secret = network::tools::read_secret_backend(); #my @cnx_list = map { $_->{server} } @$secret; $modem->{$_} ||= '' foreach qw(connection phone login passwd auth domain dns1 dns2); $modem->{auto_gateway} ||= defined $modem->{Gateway} && $modem->{Gateway} ne '0.0.0.0' ? N("Manual") : N("Automatic"); $modem->{auto_ip} ||= defined $modem->{IPAddr} && $modem->{IPAddr} ne '0.0.0.0' ? N("Manual") : N("Automatic"); $modem->{auto_dns} ||= $modem->{dns1} || $modem->{dns2} ? N("Manual") : N("Automatic"); } #-----modem conf sub ppp_configure { my ($in, $modem) = @_; $modem or return; $in->do_pkgs->install('ppp') if !$::testing; $in->do_pkgs->install('kdenetwork-kppp') if !$::testing && $in->do_pkgs->is_installed('kdebase'); any::devfssymlinkf($modem, 'modem') if $modem->{device} ne "/dev/modem"; my %toreplace = map { $_ => $modem->{$_} } qw(Authentication AutoName connection dns1 dns2 domain IPAddr login passwd phone SubnetMask); $toreplace{phone} =~ s/[a-zA-Z]//g; if ($modem->{auto_dns} ne N("Automatic")) { $toreplace{dnsserver} = join ',', map { $modem->{$_} } "dns1", "dns2"; $toreplace{dnsserver} .= $toreplace{dnsserver} && ','; } #- using peerdns or dns1,dns2 avoid writing a /etc/resolv.conf file. $toreplace{peerdns} = "yes"; $toreplace{connection} ||= 'DialupConnection'; $toreplace{domain} ||= 'localdomain'; $toreplace{intf} ||= 'ppp0'; $toreplace{papname} = $toreplace{login} if member($modem->{Authentication}, 1, 3, 4); # handle static/dynamic settings: if ($modem->{auto_ip} eq N("Automatic")) { $toreplace{$_} = '0.0.0.0' foreach qw(IPAddr SubnetMask); } else { $toreplace{$_} = $modem->{$_} foreach qw(IPAddr SubnetMask); } $toreplace{Gateway} = $modem->{auto_gateway} eq N("Automatic") ? '0.0.0.0' : $modem->{Gateway}; #- build ifcfg-ppp0. my $various = <{auto_dns} ne N("Automatic"), map { qq(DNS$_=$toreplace{"dns$_"}\n) } grep { $toreplace{"dns$_"} } 1..2)); #- build chat-ppp0. my @chat = <{special_command}) { push @chat, <{special_command}' END } push @chat, <{Authentication}, 0, 2)) { push @chat, <{miscellaneous}); } 1;