summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-22 17:55:30 +0200
committerChristian Poessinger <christian@poessinger.com>2020-04-22 18:27:49 +0200
commitf9fbda14a2559794999f3391e420c70b31e6a343 (patch)
treeb47695b788938677a5343e6ad6e712af5c9782b9 /src
parentcc87303aad1f5b9140ddcd82a9a75df1979b087c (diff)
downloadvyos-1x-f9fbda14a2559794999f3391e420c70b31e6a343.tar.gz
vyos-1x-f9fbda14a2559794999f3391e420c70b31e6a343.zip
vpn: pptp: T2351: migrate to common name-server, wins-server nodes
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/vpn_pptp.py15
-rwxr-xr-xsrc/migration-scripts/pptp/1-to-265
2 files changed, 72 insertions, 8 deletions
diff --git a/src/conf_mode/vpn_pptp.py b/src/conf_mode/vpn_pptp.py
index 653b21161..841c1b375 100755
--- a/src/conf_mode/vpn_pptp.py
+++ b/src/conf_mode/vpn_pptp.py
@@ -62,15 +62,11 @@ def get_config():
pptp = deepcopy(default_pptp)
conf.set_level(base_path)
- for server in ['server-1', 'server-2']:
- if conf.exists(['dns-servers', server]):
- tmp = conf.return_value(['dns-servers', server])
- pptp['dnsv4'].append(tmp)
+ if conf.exists(['name-server']):
+ pptp['dnsv4'] = conf.return_values(['name-server'])
- for server in ['server-1', 'server-2']:
- if conf.exists(['wins-servers', server]):
- tmp = conf.return_value(['wins-servers', server])
- pptp['wins'].append(tmp)
+ if conf.exists(['wins-server']):
+ pptp['wins'] = conf.return_values(['wins-server'])
if conf.exists(['outside-address']):
pptp['outside_addr'] = conf.return_value(['outside-address'])
@@ -243,6 +239,9 @@ def verify(pptp):
if len(pptp['dnsv4']) > 2:
raise ConfigError('Not more then two IPv4 DNS name-servers can be configured')
+ if len(pptp['wins']) > 2:
+ raise ConfigError('Not more then two IPv4 WINS name-servers can be configured')
+
def generate(pptp):
if not pptp:
diff --git a/src/migration-scripts/pptp/1-to-2 b/src/migration-scripts/pptp/1-to-2
new file mode 100755
index 000000000..605081f1c
--- /dev/null
+++ b/src/migration-scripts/pptp/1-to-2
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2020 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# - migrate dns-servers node to common name-servers
+
+from sys import argv, exit
+
+from vyos.configtree import ConfigTree
+
+if (len(argv) < 1):
+ print("Must specify file name!")
+ exit(1)
+
+file_name = argv[1]
+
+with open(file_name, 'r') as f:
+ config_file = f.read()
+
+config = ConfigTree(config_file)
+base = ['vpn', 'pptp', 'remote-access']
+if not config.exists(base):
+ # Nothing to do
+ exit(0)
+else:
+ # Migrate IPv4 DNS servers
+ dns_base = base + ['dns-servers']
+ if config.exists(dns_base):
+ for server in ['server-1', 'server-2']:
+ if config.exists(dns_base + [server]):
+ dns = config.return_value(dns_base + [server])
+ config.set(base + ['name-server'], value=dns, replace=False)
+
+ config.delete(dns_base)
+
+ # Migrate IPv4 WINS servers
+ wins_base = base + ['wins-servers']
+ if config.exists(wins_base):
+ for server in ['server-1', 'server-2']:
+ if config.exists(wins_base + [server]):
+ wins = config.return_value(wins_base + [server])
+ config.set(base + ['wins-server'], value=wins, replace=False)
+
+ config.delete(wins_base)
+
+
+
+ try:
+ with open(file_name, 'w') as f:
+ f.write(config.to_string())
+ except OSError as e:
+ print("Failed to save the modified config: {}".format(e))
+ exit(1)