summaryrefslogtreecommitdiffstats
path: root/lib/network/vpn/vpnc.pm
blob: f0c8369a06e8c1e109a1e98f877b26e365e5af00 (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
package network::vpn::vpnc;

use base qw(network::vpn);

use strict;
use common;

sub get_type { 'vpnc' }
sub get_description { N("Cisco VPN Concentrator") }
sub get_packages { 'vpnc' }

sub read_config {
    my ($connection) = @_;
    my @fields = group_by2(list_fields($connection));
    foreach (cat_($connection->get_config_path)) {
        foreach my $field (@fields) {
            # all strings start exactly one space after the keyword string
            /^$field->[0] (.*)/ and ${$field->[1]{val}} = $1;
        }
    }
}

sub write_config {
    my ($connection) = @_;
    output_with_perm($connection->get_config_path, 0600, map {
        if_(${$_->[1]{val}}, $_->[0], ' ', ${$_->[1]{val}}, "\n");
    } group_by2(list_fields($connection)));
}

sub get_settings {
    my ($connection) = @_;
    second(list2kv(list_fields($connection)));
}

sub list_fields {
    my ($connection) = @_;
    (
        'IPSec gateway' => {
            label => N("Gateway"),
            val => \$connection->{gateway},
        },
        'IPSec ID' => {
            label => N("Group name"),
            val => \$connection->{id},
        },
        'IPSec secret' => {
            label => N("Group secret"),
            val => \$connection->{secret},
            hidden => 1,
        },
        'Xauth username' => {
            label => N("Username"),
            val => \$connection->{username},
        },
        'Xauth password' => {
            label => N("Password"),
            val => \$connection->{password},
            hidden => 1,
        },
        'UDP Encapsulate' => {
            text => N("Use Cisco-UDP encapsulation"),
            type => 'bool',
            val => \$connection->{udp},
            advanced => 1,
        },
        'UDP Encapsulation Port' => {
            label => N("Use specific UDP port"),
            val => \$connection->{udp_port},
            advanced => 1,
        },
    );
}

1;