summaryrefslogtreecommitdiff
path: root/src/migration-scripts/l2tp/5-to-6
blob: cc9f948a68078f4f773d62ebf8cc4f91ce8592e5 (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
# Copyright 2023-2024 VyOS maintainers and contributors <maintainers@vyos.io>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library.  If not, see <http://www.gnu.org/licenses/>.

from vyos.configtree import ConfigTree

base = ['vpn', 'l2tp', 'remote-access']

def migrate(config: ConfigTree) -> None:
    if not config.exists(base):
        return

    #migrate idle to ppp option lcp-echo-timeout
    idle_path = base + ['idle']
    if config.exists(idle_path):
        config.set(base + ['ppp-options', 'lcp-echo-timeout'],
                   value=config.return_value(idle_path))
        config.delete(idle_path)

    #migrate mppe from authentication to ppp-otion
    mppe_path = base + ['authentication', 'mppe']
    if config.exists(mppe_path):
        config.set(base + ['ppp-options', 'mppe'],
                   value=config.return_value(mppe_path))
        config.delete(mppe_path)

    #migrate require to protocol
    require_path = base + ['authentication', 'require']
    if config.exists(require_path):
        protocols = list(config.return_values(require_path))
        for protocol in protocols:
            config.set(base + ['authentication', 'protocols'], value=protocol,
                       replace=False)
        config.delete(require_path)
    else:
        config.set(base + ['authentication', 'protocols'], value='mschap-v2')

    #migrate default gateway if not exist
    if not config.exists(base + ['gateway-address']):
        config.set(base + ['gateway-address'], value='10.255.255.0')

    #migrate authentication radius timeout
    rad_timeout_path = base + ['authentication', 'radius', 'timeout']
    if config.exists(rad_timeout_path):
        if int(config.return_value(rad_timeout_path)) > 60:
            config.set(rad_timeout_path, value=60)

    #migrate authentication radius acct timeout
    rad_acct_timeout_path = base + ['authentication', 'radius', 'acct-timeout']
    if config.exists(rad_acct_timeout_path):
        if int(config.return_value(rad_acct_timeout_path)) > 60:
            config.set(rad_acct_timeout_path,value=60)

    #migrate authentication radius max-try
    rad_max_try_path = base + ['authentication', 'radius', 'max-try']
    if config.exists(rad_max_try_path):
        if int(config.return_value(rad_max_try_path)) > 20:
            config.set(rad_max_try_path, value=20)

    #migrate dae-server to dynamic-author
    dae_path_old = base + ['authentication', 'radius', 'dae-server']
    dae_path_new = base + ['authentication', 'radius', 'dynamic-author']

    if config.exists(dae_path_old + ['ip-address']):
        config.set(dae_path_new + ['server'],
                   value=config.return_value(dae_path_old + ['ip-address']))

    if config.exists(dae_path_old + ['port']):
        config.set(dae_path_new + ['port'],
                   value=config.return_value(dae_path_old + ['port']))

    if config.exists(dae_path_old + ['secret']):
        config.set(dae_path_new + ['key'],
                   value=config.return_value(dae_path_old + ['secret']))

    if config.exists(dae_path_old):
        config.delete(dae_path_old)