package network::modem; # $Id$ use strict; use common; use any; use modules; use detect_devices; use mouse; use network::tools; #-----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(auth AutoName connection dns1 dns2 domain IPAddr login passwd phone SubnetMask); $toreplace{kpppauth} = ${{ N("Script-based") => 0, N("PAP") => 1, N("Terminal-based") => 2, N("CHAP") => 3, N("PAP/CHAP") => 4 }}{$modem->{auth}}; $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} = ($modem->{auth} eq 'PAP' || $modem->{auth} eq 'CHAP') && $toreplace{login}; # 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, <{auth} eq 'Terminal-based' || $modem->{auth} eq 'Script-based') { push @chat, <{auth} eq 'PAP' || $modem->{auth} eq 'CHAP') { #- need to create a secrets file for the connection. my $secrets = "$::prefix/etc/ppp/" . lc($modem->{auth}) . "-secrets"; my @l = cat_($secrets); my $replaced = 0; do { $replaced ||= 1 if s/^\s*"?$toreplace{login}"?\s+ppp0\s+(\S+)/"$toreplace{login}" ppp0 "$toreplace{passwd}"/ } foreach @l; if ($replaced) { output($secrets, @l); } else { append_to_file($secrets, qq($toreplace{login} ppp0 "$toreplace{passwd}"\n)); } #- restore access right to secrets file, just in case. chmod 0600, $secrets; } #- install kppprc file according to used configuration. mkdir_p("$::prefix/usr/share/config"); output("$::prefix/usr/share/config/kppprc", c::to_utf8(<{miscellaneous}); } 1;