summaryrefslogtreecommitdiffstats
path: root/lib/network/connection/cable.pm
blob: e74ac6abc4cfd0f72aa50427d0e7d7a80a7e4a3f (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
package network::connection::cable;

use strict;
use common;

use base qw(network::connection::ethernet);

use strict;
use common;
use modules;
use detect_devices;

sub get_type_name() { N("Cable") }
sub get_type_description() { N("Cable modem") }
sub get_type_icon() { 'cablemodem-24.png' }
sub get_metric { 20 }

sub handles_ifcfg {
    my ($_class, $_ifcfg) = @_;
    0;
}

my $bpalogin_file = '/etc/bpalogin.conf';

sub guess_protocol {
    my ($self) = @_;
    $self->{protocol} = 'dhcp';
}

sub guess_access_settings {
    my ($self) = @_;
    $self->{access}{use_bpalogin} = -e $::prefix . $bpalogin_file;
    if ($self->{access}{use_bpalogin}) {
        foreach (cat_($::prefix . $bpalogin_file)) {
            /^username (.*)/ and $self->{access}{login} = $1;
            /^password (.*)/ and $self->{access}{password} = $1;
        }
    }
}

sub get_access_settings {
    my ($self) = @_;
    my %auth = (
        0 => N("None"),
        1 => N("Use BPALogin (needed for Telstra)"),
    );
    [
        { label => N("Authentication"), type => "list", val => \$self->{access}{use_bpalogin},
          list => [ sort keys %auth ], format => sub { $auth{$_[0]} } },
        { label => N("Account Login (user name)"), val => \$self->{access}{login},
          disabled => sub { !$self->{access}{use_bpalogin} } },
        { label => N("Account Password"),  val => \$self->{access}{password}, hidden => 1,
          disabled => sub { !$self->{access}{use_bpalogin} } },
    ];
}

sub write_settings {
    my ($self, $o_net, $o_modules_conf) = @_;
    if ($self->{access}{use_bpalogin}) {
        substInFile {
            s/username\s+.*\n/username $self->{access}{login}\n/;
            s/password\s+.*\n/password $self->{access}{password}\n/;
        } $::prefix . $bpalogin_file;
    }
    services::set_status("bpalogin", $self->{access}{use_bpalogin});
    $self->SUPER::write_settings($o_net, $o_modules_conf);
}

sub install_packages {
    my ($self, $in) = @_;
    if ($self->{access}{use_bpalogin}) {
        $in->do_pkgs->ensure_is_installed('bpalogin', '/usr/sbin/bpalogin') or return;
    }
    $self->SUPER::install_packages($in);
}

1;