diff --git a/debian/changelog b/debian/changelog index b8e9022c0..783080a92 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,108 +1,102 @@ -vyos-1x (1.2.0-10) unstable; urgency=low - - * T1178: Scheduled script breaks ability to modify configuration - - -- hagbard <vyosdev@derith.de> Mon, 21 Jan 2019 12:54:45 -0800 - vyos-1x (1.2.0-9) unstable; urgency=low * T1168: Upgrade: 1,1,7 -> 1.2.0-epa2 - keyword change in config -- hagbard <vyosdev@derith.de> Mon, 07 Jan 2019 11:42:49 -0800 vyos-1x (1.2.0-8) unstable; urgency=low * T1162: WireGuard: Unable to modify tunnels - KeyError: 'state' -- hagbard <vyosdev@derith.de> Sun, 06 Jan 2019 15:58:40 -0800 vyos-1x (1.2.0-7) unstable; urgency=low * T1061: Wireguard: Missing option to administrativly shutdown interface -- hagbard <vyosdev@derith.de> Fri, 30 Nov 2018 10:22:41 -0800 vyos-1x (1.2.0-6) unstable; urgency=medium * adding vyos-accel-ppp-ipoe-kmod for T989 -- hagbard <vyosdev@derith.de> Thu, 22 Nov 2018 10:56:15 -0800 vyos-1x (1.2.0-5) unstable; urgency=medium * T835: accel-ppp: pppoe implementation -- hagbard <vyosdev@derith.de> Fri, 09 Nov 2018 10:49:48 -0800 vyos-1x (1.2.0-4) unstable; urgency=medium * T240 adds feature system integrity check -- hagbard <vyosdev@derith.de> Mon, 29 Oct 2018 11:10:18 -0700 vyos-1x (1.2.0-3) unstable; urgency=medium * T933: adding vmac_xmit_base if use_vmac has been chosen to avoid split-brain -- hagbard <vyosdev@derith.de> Thu, 25 Oct 2018 11:14:44 -0700 vyos-1x (1.2.0-2) unstable; urgency=medium * T773: adding wireguard support -- hagbard <vyosdev@derith.de> Sat, 11 Aug 2018 15:51:34 -0700 vyos-1x (1.2.0-1) unstable; urgency=medium * T666, T616: new implementation of the VRRP CLI. -- Daniil Baturin <daniil@baturin.org> Fri, 27 Jul 2018 10:25:52 +0200 vyos-1x (1.0.6) unstable; urgency=medium * T736: Rewrite remote logging (syslog) to XML/Python -- hagbard <vyosdev@derith.de> Tue, 24 Jul 2018 10:59:25 -0700 vyos-1x (1.0.5) unstable; urgency=medium * T606: Error in DNS Forwarder listen-on * T608: Cannot configure broadcast-relay service -- Christian Poessinger <christian@poessinger.com> Thu, 19 Apr 2018 21:16:28 +0200 vyos-1x (1.0.4) unstable; urgency=medium * T560: dns-forwarding: replace dnsmasq with pdns-recursor * T588: Rewrite 'service dns forwarding' in new XML style format -- Christian Poessinger <christian@poessinger.com> Sun, 15 Apr 2018 16:13:32 +0200 vyos-1x (1.0.3) unstable; urgency=medium * T379: Add UDP broadcast relay support * mdns repeater scripts - remove python subprocess * Support setting optional 'type' node in command templates -- Christian Poessinger <christian@poessinger.com> Sat, 06 Jan 2018 13:18:30 +0100 vyos-1x (1.0.2) unstable; urgency=low * Added mdns-repeater configuration nodes -- Christian Poessinger <christian@poessinger.com> Sat, 09 Dec 2017 10:39:35 +0100 vyos-1x (1.0.1) unstable; urgency=low * Added the Python library for reading VyOS configs -- Daniil Baturin <daniil@baturin.org> Thu, 17 Aug 2017 22:22:17 -0400 vyos-1x (1.0.0) unstable; urgency=low * Created the package -- Daniil Baturin <daniil@baturin.org> Thu, 17 Aug 2017 20:17:04 -0400 diff --git a/src/conf_mode/task_scheduler.py b/src/conf_mode/task_scheduler.py index 0391d3edb..285afe2b5 100755 --- a/src/conf_mode/task_scheduler.py +++ b/src/conf_mode/task_scheduler.py @@ -1,148 +1,148 @@ #!/usr/bin/env python3 # # Copyright (C) 2017 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/>. # # import os import re import sys from vyos.config import Config from vyos import ConfigError crontab_file = "/etc/cron.d/vyos-crontab" -def format_task(minute="*", hour="*", day="*", dayofweek="*", month="*", user="vyos", rawspec=None, command=""): +def format_task(minute="*", hour="*", day="*", dayofweek="*", month="*", user="root", rawspec=None, command=""): fmt_full = "{minute} {hour} {day} {month} {dayofweek} {user} {command}\n" fmt_raw = "{spec} {user} {command}\n" if rawspec is None: s = fmt_full.format(minute=minute, hour=hour, day=day, dayofweek=dayofweek, month=month, command=command, user=user) else: s = fmt_raw.format(spec=rawspec, user=user, command=command) return s def split_interval(s): result = re.search(r"(\d+)([mdh]?)", s) value = int(result.group(1)) suffix = result.group(2) return( (value, suffix) ) def make_command(executable, arguments): if arguments: return("sg vyattacfg \"{0} {1}\"".format(executable, arguments)) else: return(executable) def get_config(): conf = Config() conf.set_level("system task-scheduler task") task_names = conf.list_nodes("") tasks = [] for name in task_names: interval = conf.return_value("{0} interval".format(name)) spec = conf.return_value("{0} crontab-spec".format(name)) executable = conf.return_value("{0} executable path".format(name)) args = conf.return_value("{0} executable arguments".format(name)) task = { "name": name, "interval": interval, "spec": spec, "executable": executable, "args": args } tasks.append(task) return tasks def verify(tasks): for task in tasks: if not task["interval"] and not task["spec"]: raise ConfigError("Invalid task {0}: must define either interval or crontab-spec".format(task["name"])) if task["interval"]: if task["spec"]: raise ConfigError("Invalid task {0}: cannot use interval and crontab-spec at the same time".format(task["name"])) if not re.match(r"^\d+[mdh]?$", task["interval"]): raise(ConfigError("Invalid interval {0} in task {1}: interval should be a number optionally followed by m, h, or d".format(task["name"], task["interval"]))) else: # Check if values are within allowed range value, suffix = split_interval(task["interval"]) if not suffix or suffix == "m": if value > 60: raise ConfigError("Invalid task {0}: interval in minutes must not exceed 60".format(task["name"])) elif suffix == "h": if value > 24: raise ConfigError("Invalid task {0}: interval in hours must not exceed 24".format(task["name"])) elif suffix == "d": if value > 31: raise ConfigError("Invalid task {0}: interval in days must not exceed 31".format(task["name"])) if not task["executable"]: raise ConfigError("Invalid task {0}: executable is not defined".format(task["name"])) else: # Check if executable exists and is executable if not (os.path.isfile(task["executable"]) and os.access(task["executable"], os.X_OK)): raise ConfigError("Invalid task {0}: file {1} does not exist or is not executable".format(task["name"], task["executable"])) def generate(tasks): crontab_header = "### Generated by vyos-update-crontab.py ###\n" if len(tasks) == 0: if os.path.exists(crontab_file): os.remove(crontab_file) else: pass else: crontab_lines = [] for task in tasks: command = make_command(task["executable"], task["args"]) if task["spec"]: line = format_task(command=command, rawspec=task["spec"]) else: value, suffix = split_interval(task["interval"]) if not suffix or suffix == "m": line = format_task(command=command, minute="*/{0}".format(value)) elif suffix == "h": line = format_task(command=command, minute="0", hour="*/{0}".format(value)) elif suffix == "d": line = format_task(command=command, minute="0", hour="0", day="*/{0}".format(value)) crontab_lines.append(line) with open(crontab_file, 'w') as f: f.write(crontab_header) f.writelines(crontab_lines) def apply(config): # No daemon restarts etc. needed for cron pass if __name__ == '__main__': try: c = get_config() verify(c) generate(c) apply(c) except ConfigError as e: print(e) sys.exit(1)