summaryrefslogtreecommitdiff
path: root/src/migration-scripts/webproxy/1-to-2
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2018-12-07 20:00:14 +0100
committerChristian Poessinger <christian@poessinger.com>2018-12-07 20:00:14 +0100
commita2ef71b8878f395d4d259a75df3d68695fd7c004 (patch)
tree7c544c9368e140ef2e6363aa7aca7a194ae1a98c /src/migration-scripts/webproxy/1-to-2
parent2189e8eacc3d056a21cba8e8fb8ef32c0660ac09 (diff)
downloadvyos-1x-a2ef71b8878f395d4d259a75df3d68695fd7c004.tar.gz
vyos-1x-a2ef71b8878f395d4d259a75df3d68695fd7c004.zip
T1060: build fix for wrong config-version number
Commit 9d35610c173 ("T1060: add missing version file for webproxy") assumed that there is a webproxy config version of 0 but we already have 1. This lead to duplicate files detected by apt.
Diffstat (limited to 'src/migration-scripts/webproxy/1-to-2')
-rwxr-xr-xsrc/migration-scripts/webproxy/1-to-239
1 files changed, 39 insertions, 0 deletions
diff --git a/src/migration-scripts/webproxy/1-to-2 b/src/migration-scripts/webproxy/1-to-2
new file mode 100755
index 000000000..4acabba3e
--- /dev/null
+++ b/src/migration-scripts/webproxy/1-to-2
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+# migrate old style `webproxy proxy-bypass 1.2.3.4/24`
+# to new style `webproxy whitelist destination-address 1.2.3.4/24`
+
+import sys
+
+from vyos.configtree import ConfigTree
+
+if len(sys.argv) < 1:
+ print("Must specify file name!")
+ sys.exit(1)
+
+file_name = sys.argv[1]
+
+with open(file_name, 'r') as f:
+ config_file = f.read()
+
+config = ConfigTree(config_file)
+
+cfg_webproxy_base = ['service', 'webproxy']
+if not config.exists(cfg_webproxy_base):
+ # Nothing to do
+ sys.exit(0)
+else:
+ bypass_addresses = config.return_values(cfg_webproxy_base + ['proxy-bypass'])
+ # delete old configuration node
+ config.delete(cfg_webproxy_base + ['proxy-bypass'])
+ for bypass_address in bypass_addresses:
+ # add data to new configuration node
+ config.set(cfg_webproxy_base + ['whitelist', 'destination-address'], value=bypass_address, replace=False)
+
+ # save updated configuration
+ 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))
+ sys.exit(1)