summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/vyos/config.py6
-rw-r--r--python/vyos/migrator.py36
-rw-r--r--python/vyos/util.py6
-rwxr-xr-xsrc/conf_mode/accel_pppoe.py6
-rwxr-xr-xsrc/conf_mode/host_name.py6
-rwxr-xr-xsrc/migration-scripts/l2tp/0-to-119
-rwxr-xr-xsrc/op_mode/show_openvpn.py2
-rwxr-xr-xsrc/services/vyos-hostsd16
-rwxr-xr-xsrc/services/vyos-http-api-server2
-rwxr-xr-xsrc/system/on-dhcp-event.sh2
10 files changed, 75 insertions, 26 deletions
diff --git a/python/vyos/config.py b/python/vyos/config.py
index 13b2c107e..e6a41a92d 100644
--- a/python/vyos/config.py
+++ b/python/vyos/config.py
@@ -69,6 +69,7 @@ import json
import subprocess
import vyos.configtree
+import vyos.util
class VyOSError(Exception):
@@ -111,6 +112,11 @@ class Config(object):
else:
session_config_text = running_config_text
+ # The output of showConfig does not escape backslashes, as is expected
+ # by ConfigTree().
+ session_config_text = vyos.util.escape_backslash(session_config_text)
+ running_config_text = vyos.util.escape_backslash(running_config_text)
+
self._session_config = vyos.configtree.ConfigTree(session_config_text)
self._running_config = vyos.configtree.ConfigTree(running_config_text)
diff --git a/python/vyos/migrator.py b/python/vyos/migrator.py
index 59d68f0f7..86e1af183 100644
--- a/python/vyos/migrator.py
+++ b/python/vyos/migrator.py
@@ -30,6 +30,7 @@ class Migrator(object):
self._force = force
self._set_vintage = set_vintage
self._config_file_vintage = None
+ self._log_file = None
self._changed = False
def read_config_file_versions(self):
@@ -71,11 +72,30 @@ class Migrator(object):
else:
return True
+ def open_log_file(self):
+ """
+ Open log file for migration, catching any error.
+ Note that, on boot, migration takes place before the canonical log
+ directory is created, hence write to the config file directory.
+ """
+ self._log_file = os.path.join(vyos.defaults.directories['config'],
+ 'vyos-migrate.log')
+ try:
+ log = open('{0}'.format(self._log_file), 'w')
+ log.write("List of executed migration scripts:\n")
+ except Exception as e:
+ print("Logging error: {0}".format(e))
+ return None
+
+ return log
+
def run_migration_scripts(self, config_file_versions, system_versions):
"""
Run migration scripts iteratively, until config file version equals
system component version.
"""
+ log = self.open_log_file()
+
cfg_versions = config_file_versions
sys_versions = system_versions
@@ -101,18 +121,28 @@ class Migrator(object):
'{}-to-{}'.format(cfg_ver, next_ver))
try:
- subprocess.check_output([migrate_script,
+ subprocess.check_call([migrate_script,
self._config_file])
except FileNotFoundError:
pass
- except subprocess.CalledProcessError as err:
- print("Called process error: {}.".format(err))
+ except Exception as err:
+ print("\nMigration script error: {0}: {1}."
+ "".format(migrate_script, err))
sys.exit(1)
+ if log:
+ try:
+ log.write('{0}\n'.format(migrate_script))
+ except Exception as e:
+ print("Error writing log: {0}".format(e))
+
cfg_ver = next_ver
rev_versions[key] = cfg_ver
+ if log:
+ log.close()
+
return rev_versions
def write_config_file_versions(self, cfg_versions):
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 67a602f7a..659a702fd 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -199,3 +199,9 @@ def is_admin() -> bool:
current_user = getpass.getuser()
(_, _, _, admin_group_members) = grp.getgrnam('sudo')
return current_user in admin_group_members
+
+def escape_backslash(string: str) -> str:
+ """Escape single backslashes in string that are not in escape sequence"""
+ p = re.compile(r'(?<!\\)[\\](?!b|f|n|r|t|\\[^bfnrt])')
+ result = p.sub(r'\\\\', string)
+ return result
diff --git a/src/conf_mode/accel_pppoe.py b/src/conf_mode/accel_pppoe.py
index 9c879502a..6aec9be98 100755
--- a/src/conf_mode/accel_pppoe.py
+++ b/src/conf_mode/accel_pppoe.py
@@ -44,6 +44,9 @@ pppoe_config = '''
[modules]
log_syslog
pppoe
+{% if authentication['mode'] == 'radius' %}
+radius
+{% endif %}
ippool
{% if client_ipv6_pool %}
ipv6pool
@@ -63,9 +66,6 @@ net-snmp
{% if limits %}
connlimit
{% endif %}
-{% if authentication['mode'] == 'radius' %}
-radius
-{% endif %}
[core]
thread-count={{thread_cnt}}
diff --git a/src/conf_mode/host_name.py b/src/conf_mode/host_name.py
index bb1ec9597..47cf232e9 100755
--- a/src/conf_mode/host_name.py
+++ b/src/conf_mode/host_name.py
@@ -66,7 +66,7 @@ def get_config():
hosts['nameserver'] = conf.return_values("system name-server")
if conf.exists("system disable-dhcp-nameservers"):
- hosts['no_dhcp_ns'] = conf.exists('system disable-dhcp-nameservers')
+ hosts['no_dhcp_ns'] = True
# system static-host-mapping
hosts['static_host_mapping'] = []
@@ -135,6 +135,10 @@ def apply(config):
try:
client = vyos.hostsd_client.Client()
+ # Check if disable-dhcp-nameservers is configured, and if yes - delete DNS servers added by DHCP
+ if config['no_dhcp_ns']:
+ client.delete_name_servers('dhcp-.+')
+
client.set_host_name(config['hostname'], config['domain_name'], config['domain_search'])
client.delete_name_servers(tag)
diff --git a/src/migration-scripts/l2tp/0-to-1 b/src/migration-scripts/l2tp/0-to-1
index f6c716df1..686ebc655 100755
--- a/src/migration-scripts/l2tp/0-to-1
+++ b/src/migration-scripts/l2tp/0-to-1
@@ -35,17 +35,18 @@ else:
# Migrate "vpn l2tp authentication radius-server" tag node to new
# "vpn l2tp authentication radius server" tag node
- for server in config.list_nodes(cfg_base + ['radius-server']):
- base_server = cfg_base + ['radius-server', server]
- key = config.return_value(base_server + ['key'])
+ if config.exists(cfg_base + ['radius-server']):
+ for server in config.list_nodes(cfg_base + ['radius-server']):
+ base_server = cfg_base + ['radius-server', server]
+ key = config.return_value(base_server + ['key'])
- # delete old configuration node
- config.delete(base_server)
- # write new configuration node
- config.set(cfg_base + ['radius', 'server', server, 'key'], value=key)
+ # delete old configuration node
+ config.delete(base_server)
+ # write new configuration node
+ config.set(cfg_base + ['radius', 'server', server, 'key'], value=key)
- # format as tag node
- config.set_tag(cfg_base + ['radius', 'server'])
+ # format as tag node
+ config.set_tag(cfg_base + ['radius', 'server'])
# delete top level tag node
if config.exists(cfg_base + ['radius-server']):
diff --git a/src/op_mode/show_openvpn.py b/src/op_mode/show_openvpn.py
index 577ed7eb7..06b90296f 100755
--- a/src/op_mode/show_openvpn.py
+++ b/src/op_mode/show_openvpn.py
@@ -28,7 +28,7 @@ OpenVPN status on {{ intf }}
Client CN Remote Host Local Host TX bytes RX bytes Connected Since
--------- ----------- ---------- -------- -------- ---------------
{%- for c in clients %}
-{{ "%-15s"|format(c.name) }} {{ "%-21s"|format(c.remote) }} {{ "%-21s"|format(local) }} {{ "%-9s"|format(c.tx_bytes) }} {{ "%-9s"|format(c.tx_bytes) }} {{ c.online_since }}
+{{ "%-15s"|format(c.name) }} {{ "%-21s"|format(c.remote) }} {{ "%-21s"|format(local) }} {{ "%-9s"|format(c.tx_bytes) }} {{ "%-9s"|format(c.rx_bytes) }} {{ c.online_since }}
{%- endfor %}
{% endif %}
"""
diff --git a/src/services/vyos-hostsd b/src/services/vyos-hostsd
index 5c2ea71c8..5fb7a68ab 100755
--- a/src/services/vyos-hostsd
+++ b/src/services/vyos-hostsd
@@ -22,6 +22,7 @@ import time
import json
import signal
import traceback
+import re
import zmq
@@ -154,14 +155,10 @@ def add_name_servers(data, entries, tag):
def delete_name_servers(data, tag):
name_servers = data['name_servers']
- keys_for_deletion = []
-
- for ns in name_servers:
- if name_servers[ns]['tag'] == tag:
- keys_for_deletion.append(ns)
-
- for k in keys_for_deletion:
- del name_servers[k]
+ regex_filter = re.compile(tag)
+ for ns in list(name_servers.keys()):
+ if regex_filter.match(name_servers[ns]['tag']):
+ del name_servers[ns]
def set_host_name(state, data):
if data['host_name']:
@@ -174,8 +171,9 @@ def set_host_name(state, data):
def get_name_servers(state, tag):
ns = []
data = state['name_servers']
+ regex_filter = re.compile(tag)
for n in data:
- if data[n]['tag'] == tag:
+ if regex_filter.match(data[n]['tag']):
ns.append(n)
return ns
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server
index 1abaed873..9b6d7e979 100755
--- a/src/services/vyos-http-api-server
+++ b/src/services/vyos-http-api-server
@@ -24,6 +24,7 @@ import traceback
import threading
import vyos.config
+import vyos.util
import bottle
@@ -212,6 +213,7 @@ def get_value():
config_format = command['configFormat']
res = session.show_config(path=command['path'])
+ res = vyos.util.escape_backslash(res)
if config_format == 'json':
config_tree = vyos.configtree.ConfigTree(res)
res = json.loads(config_tree.to_json())
diff --git a/src/system/on-dhcp-event.sh b/src/system/on-dhcp-event.sh
index 70a563d4c..5046912a6 100755
--- a/src/system/on-dhcp-event.sh
+++ b/src/system/on-dhcp-event.sh
@@ -44,11 +44,13 @@ case "$action" in
fi
# add host
/usr/bin/vyos-hostsd-client --add-hosts --tag "DHCP-$client_ip" --host "$client_fqdn_name,$client_ip"
+ ((changes++))
;;
release) # delete mapping for released address
# delete host
/usr/bin/vyos-hostsd-client --delete-hosts --tag "DHCP-$client_ip"
+ ((changes++))
;;
*)