summaryrefslogtreecommitdiffstats
path: root/perl-install/network/modem.pm
blob: 87f04220844274905915b075cef68efb2faee4cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package network::modem;

use common;
use any;
use modules;
use detect_devices;
use mouse;
use network::tools;
use vars qw(@ISA @EXPORT);
use MDK::Common::Globals "network", qw($in $prefix);
use Data::Dumper;

@ISA = qw(Exporter);
@EXPORT = qw(pppConfig);

sub configure {
    my ($netcnx, $mouse, $netc, $intf) = @_;
    $netcnx->{type} = 'modem';
    my $modem = $netcnx->{$netcnx->{type}};
#    $netcnx->{$netcnx->{type}} = {};
    $modem->{device} = $netc->{autodetect}{modem};
#  modem_step_1:
#    $modem->{login} = ($modem->{auth} eq 'PAP' ||$modem->{auth} eq 'CHAP') && $intf->{ppp0}{PAPNAME};
#    $netcnx->{$netcnx->{type}}->{connection} = ($netcnx->{$netcnx->{type}}->{auth} eq 'PAP' || $netcnx->{$netcnx->{type}}->{auth} eq 'CHAP') && $intf->{ppp0}{PAPNAME};
#    $modem->{device} = readlink "$prefix/dev/modem";
    foreach (cat_("/usr/share/config/kppprc")) {
	/^DNS=(.*)$/ and ($modem->{dns1}, $modem->{dns2}) = split(',', $1);
    }
    my $secret = network::tools::read_secret_backend();
    foreach (@$secret) {
	$modem->{passwd} = $_->{passwd} if $_->{login} eq $modem->{login};
    }
    foreach (cat_("/etc/sysconfig/network-scripts/chat-ppp0")) {
	if (/.*ATDT(\d*).*/) {
	    $modem->{phone} = $1;
	    last;
	}
    }
    pppConfig($modem, $mouse, $netc, $intf) or return;
    write_cnx_script($netc, "modem",
q(
/sbin/route del default
ifup ppp0
),
q(ifdown ppp0
killall pppd
), $netcnx->{type});
    1;
}

sub pppConfig {
    my ($modem, $mouse, $netc, $_intf) = @_;
    $mouse ||= {};

    $mouse->{device} ||= readlink "$prefix/dev/mouse";
    $::isInstall and $in->set_help('selectSerialPort');
    $modem->{device} ||= $in->ask_from_listf('', N("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;

    my @cnx_list;
    my $secret = network::tools::read_secret_backend();
    foreach (@$secret) {
	push @cnx_list, $_->{server};
    }
    $::isStandalone || $in->set_help('configureNetworkISP');
    $in->ask_from('', N("Dialup options"), [
{ label => N("Connection name"), val => \$modem->{connection} },
{ label => N("Phone number"), val => \$modem->{phone} },
{ label => N("Login ID"), val => \$modem->{login} },
{ label => N("Password"), val => \$modem->{passwd}, hidden => 1 },
{ label => N("Authentication"), val => \$modem->{auth}, list => [ N_("PAP"), N_("Terminal-based"), N_("Script-based"), N_("CHAP") ] },
{ label => N("Domain name"), val => \$modem->{domain} },
{ label => N("First DNS Server (optional)"), val => \$modem->{dns1} },
{ label => N("Second DNS Server (optional)"), val => \$modem->{dns2} },
    ]) or return;
    $netc->{DOMAINNAME2} = $modem->{domain};
    any::pppConfig($in, $modem, $prefix);
    $netc->{$_} = 'ppp0' foreach 'NET_DEVICE', 'NET_INTERFACE';
    1;
}

#- TODO: add choice between hcf/hsf
sub winmodemConfigure {
    my ($netc) = @_;
    my $type;
    
    foreach (keys %{$netc->{autodetect}{winmodem}}) {
    	my $temp;
    	/Hcf/ and $temp = "hcf";
    	/Hsf/ and $temp = "hsf";
    	$temp and $in->do_pkgs->what_provides("${temp}linmodem") and $type = "${temp}linmodem";
    }
    
    $type || $in->ask_warn(N("Warning"), N("Your modem isn't supported by the system.
Take a look at http://www.linmodems.org")) && return 1;
    my $e = $in->ask_from_list(N("Title"), N("\"%s\" based winmodem detected, do you want to install needed software ?", $type), [N("Install rpm"), N("Do nothing")]) or return 0;
    $e =~ /rpm/ ? $in->do_pkgs->install($type) : return 1;
    1;
}

1;