From aa5f4da1a18eeec1dba9bed3c1d7896605ac51ee Mon Sep 17 00:00:00 2001 From: hagbard Date: Fri, 17 Aug 2018 17:51:56 +0000 Subject: change xml name for op mode, since it will support non key-management related commands in the future as well --- op-mode-definitions/wireguard-keys.xml | 42 ---------------------------------- op-mode-definitions/wireguard.xml | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 42 deletions(-) delete mode 100644 op-mode-definitions/wireguard-keys.xml create mode 100644 op-mode-definitions/wireguard.xml (limited to 'op-mode-definitions') diff --git a/op-mode-definitions/wireguard-keys.xml b/op-mode-definitions/wireguard-keys.xml deleted file mode 100644 index 29fce33b6..000000000 --- a/op-mode-definitions/wireguard-keys.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - wireguard key generation utility - - - - - generate a wireguard keypair - - ${vyos_op_scripts_dir}/wireguard_key.py --genkey - - - - - - - - - - - - show wireguard public key - - ${vyos_op_scripts_dir}/wireguard_key.py --showpub - - - - show wireguard private key - - ${vyos_op_scripts_dir}/wireguard_key.py --showpriv - - - - - - - diff --git a/op-mode-definitions/wireguard.xml b/op-mode-definitions/wireguard.xml new file mode 100644 index 000000000..29fce33b6 --- /dev/null +++ b/op-mode-definitions/wireguard.xml @@ -0,0 +1,42 @@ + + + + + + + + wireguard key generation utility + + + + + generate a wireguard keypair + + ${vyos_op_scripts_dir}/wireguard_key.py --genkey + + + + + + + + + + + + show wireguard public key + + ${vyos_op_scripts_dir}/wireguard_key.py --showpub + + + + show wireguard private key + + ${vyos_op_scripts_dir}/wireguard_key.py --showpriv + + + + + + + -- cgit v1.2.3 From 7a27726e0e1e1de47f8abfb64e9c28eadb34c55b Mon Sep 17 00:00:00 2001 From: Dmytro Aleksandrov Date: Sat, 18 Aug 2018 00:43:12 +0300 Subject: T784: Added update dns dynamic operation --- Makefile | 1 - op-mode-definitions/dns-forwarding.xml | 3 ++ op-mode-definitions/dynamic-dns.xml | 25 ++++++++- src/op_mode/dynamic_dns.py | 92 ++++++++++++++++++++++++++++++++++ src/op_mode/dynamic_dns_status.py | 67 ------------------------- 5 files changed, 119 insertions(+), 69 deletions(-) create mode 100755 src/op_mode/dynamic_dns.py delete mode 100755 src/op_mode/dynamic_dns_status.py (limited to 'op-mode-definitions') diff --git a/Makefile b/Makefile index 823637e84..70101181d 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,6 @@ op_mode_definitions: # XXX: delete top level op mode node.def's that now live in other packages rm -f $(OP_TMPL_DIR)/set/node.def rm -f $(OP_TMPL_DIR)/show/node.def - rm -f $(OP_TMPL_DIR)/show/dns/node.def rm -f $(OP_TMPL_DIR)/reset/node.def rm -f $(OP_TMPL_DIR)/restart/node.def rm -f $(OP_TMPL_DIR)/monitor/node.def diff --git a/op-mode-definitions/dns-forwarding.xml b/op-mode-definitions/dns-forwarding.xml index e789f4aee..be71302cd 100644 --- a/op-mode-definitions/dns-forwarding.xml +++ b/op-mode-definitions/dns-forwarding.xml @@ -4,6 +4,9 @@ + + Show DNS information + diff --git a/op-mode-definitions/dynamic-dns.xml b/op-mode-definitions/dynamic-dns.xml index c67769a83..76c473fd7 100644 --- a/op-mode-definitions/dynamic-dns.xml +++ b/op-mode-definitions/dynamic-dns.xml @@ -4,6 +4,9 @@ + + Show DNS information + @@ -14,7 +17,7 @@ Show Dynamic DNS status - sudo ${vyos_op_scripts_dir}/dynamic_dns_status.py + sudo ${vyos_op_scripts_dir}/dynamic_dns.py --status @@ -22,4 +25,24 @@ + + + Update data for a service + + + + + Update DNS information + + + + + Update Dynamic DNS information + + sudo ${vyos_op_scripts_dir}/dynamic_dns.py --update + + + + + diff --git a/src/op_mode/dynamic_dns.py b/src/op_mode/dynamic_dns.py new file mode 100755 index 000000000..7ac3dfe9f --- /dev/null +++ b/src/op_mode/dynamic_dns.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +import os +import argparse +import jinja2 +import sys +import time + +from vyos.config import Config + +cache_file = r'/var/cache/ddclient/ddclient.cache' + +OUT_TMPL_SRC = """ +{%- for entry in hosts -%} +ip address : {{ entry.ip }} +host-name : {{ entry.host }} +last update : {{ entry.time }} +update-status: {{ entry.status }} + +{% endfor -%} +""" + + +def show_status(): + # Do nothing if service is not configured + c = Config() + if not c.exists_effective('service dns dynamic'): + print("Dynamic DNS not configured") + sys.exit(0) + + data = { + 'hosts': [] + } + + with open(cache_file, 'r') as f: + for line in f: + if line.startswith('#'): + continue + + outp = { + 'host': '', + 'ip': '', + 'time': '' + } + + if 'host=' in line: + host = line.split('host=')[1] + if host: + outp['host'] = host.split(',')[0] + + if 'ip=' in line: + ip = line.split('ip=')[1] + if ip: + outp['ip'] = ip.split(',')[0] + + if 'atime=' in line: + atime = line.split('atime=')[1] + if atime: + tmp = atime.split(',')[0] + outp['time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(int(tmp, base=10))) + + if 'status=' in line: + status = line.split('status=')[1] + if status: + outp['status'] = status.split(',')[0] + + data['hosts'].append(outp) + + tmpl = jinja2.Template(OUT_TMPL_SRC) + print(tmpl.render(data)) + + +def update_ddns(): + os.system('systemctl stop ddclient') + os.remove(cache_file) + os.system('systemctl start ddclient') + + +def main(): + parser = argparse.ArgumentParser() + group = parser.add_mutually_exclusive_group() + group.add_argument("--status", help="Show DDNS status", action="store_true") + group.add_argument("--update", help="Update DDNS on a given interface", action="store_true") + args = parser.parse_args() + + if args.status: + show_status() + elif args.update: + update_ddns() + + +if __name__ == '__main__': + main() diff --git a/src/op_mode/dynamic_dns_status.py b/src/op_mode/dynamic_dns_status.py deleted file mode 100755 index bbff01f49..000000000 --- a/src/op_mode/dynamic_dns_status.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env python3 - -import jinja2 -import sys -import time - -from vyos.config import Config - -cache_file = r'/var/cache/ddclient/ddclient.cache' - -OUT_TMPL_SRC = """ -{%- for entry in hosts -%} -ip address : {{ entry.ip }} -host-name : {{ entry.host }} -last update : {{ entry.time }} -update-status: {{ entry.status }} - -{% endfor -%} -""" - -if __name__ == '__main__': - # Do nothing if service is not configured - c = Config() - if not c.exists_effective('service dns dynamic'): - print("Dynamic DNS not configured") - sys.exit(0) - - data = { - 'hosts': [] - } - - with open(cache_file, 'r') as f: - for line in f: - if line.startswith('#'): - continue - - outp = { - 'host': '', - 'ip': '', - 'time': '' - } - - if 'host=' in line: - host = line.split('host=')[1] - if host: - outp['host'] = host.split(',')[0] - - if 'ip=' in line: - ip = line.split('ip=')[1] - if ip: - outp['ip'] = ip.split(',')[0] - - if 'atime=' in line: - atime = line.split('atime=')[1] - if atime: - tmp = atime.split(',')[0] - outp['time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(int(tmp, base=10))) - - if 'status=' in line: - status = line.split('status=')[1] - if status: - outp['status'] = status.split(',')[0] - - data['hosts'].append(outp) - - tmpl = jinja2.Template(OUT_TMPL_SRC) - print(tmpl.render(data)) -- cgit v1.2.3 From 55ee5d903817e3a80fb6272d790dcce1044f8a9b Mon Sep 17 00:00:00 2001 From: Runar Borge Date: Sun, 19 Aug 2018 22:25:34 +0200 Subject: T689: Reboot/Poweroff now not working after last changes --- op-mode-definitions/poweroff.xml | 4 ++-- op-mode-definitions/reboot.xml | 4 ++-- src/op_mode/powerctrl.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'op-mode-definitions') diff --git a/op-mode-definitions/poweroff.xml b/op-mode-definitions/poweroff.xml index ff27f4f4d..e2483fefc 100644 --- a/op-mode-definitions/poweroff.xml +++ b/op-mode-definitions/poweroff.xml @@ -4,14 +4,14 @@ Poweroff the system - sudo ${vyos_op_scripts_dir}/powerctrl.py --poweroff now + sudo ${vyos_op_scripts_dir}/powerctrl.py --poweroff Poweroff the system without confirmation - sudo ${vyos_op_scripts_dir}/powerctrl.py --yes --poweroff now + sudo ${vyos_op_scripts_dir}/powerctrl.py --yes --poweroff diff --git a/op-mode-definitions/reboot.xml b/op-mode-definitions/reboot.xml index 340c8ca82..affdffd98 100644 --- a/op-mode-definitions/reboot.xml +++ b/op-mode-definitions/reboot.xml @@ -4,14 +4,14 @@ Reboot the system - sudo ${vyos_op_scripts_dir}/powerctrl.py --reboot now + sudo ${vyos_op_scripts_dir}/powerctrl.py --reboot Reboot the system without confirmation - sudo ${vyos_op_scripts_dir}/powerctrl.py --yes --reboot now + sudo ${vyos_op_scripts_dir}/powerctrl.py --yes --reboot diff --git a/src/op_mode/powerctrl.py b/src/op_mode/powerctrl.py index f73d6c005..8a66b3afd 100755 --- a/src/op_mode/powerctrl.py +++ b/src/op_mode/powerctrl.py @@ -126,9 +126,9 @@ def main(): args = parser.parse_args() try: - if args.reboot: + if args.reboot is not None: execute_shutdown(args.reboot, reboot=True, ask=args.yes) - if args.poweroff: + if args.poweroff is not None: execute_shutdown(args.poweroff, reboot=False,ask=args.yes) if args.cancel: cancel_shutdown() -- cgit v1.2.3 From b3892fe872202b97d8ed58a60d15d7d0efa7a22f Mon Sep 17 00:00:00 2001 From: hagbard Date: Mon, 20 Aug 2018 21:39:06 +0000 Subject: T790: wireguard: add status commands --- Makefile | 2 +- op-mode-definitions/wireguard.xml | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'op-mode-definitions') diff --git a/Makefile b/Makefile index 17ae34a18..b626bbd8b 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ clean: .PHONY: test test: -# PYTHONPATH=python/ python3 -m "nose" --with-xunit src --with-coverage --cover-erase --cover-xml --cover-package src/conf_mode,src/op_mode,src/completion,src/helpers,src/validators --verbose + PYTHONPATH=python/ python3 -m "nose" --with-xunit src --with-coverage --cover-erase --cover-xml --cover-package src/conf_mode,src/op_mode,src/completion,src/helpers,src/validators --verbose .PHONY: sonar sonar: diff --git a/op-mode-definitions/wireguard.xml b/op-mode-definitions/wireguard.xml index 29fce33b6..a7e156d8d 100644 --- a/op-mode-definitions/wireguard.xml +++ b/op-mode-definitions/wireguard.xml @@ -36,6 +36,40 @@ + + + + + show wireguard interface information + + + + + sudo wg show "$4" + + + + show all allowed-ips for the specified interface + + sudo wg show "$4" allowed-ips + + + + show all endpoints for the specified interface + + sudo wg show "$4" endpoints + + + + show all peer IDs for the specified interface + + sudo wg show "$4" peers + + + + + + -- cgit v1.2.3 From a91a95031cb3956deed986a5ea0211edcd95c119 Mon Sep 17 00:00:00 2001 From: Dmytro Aleksandrov Date: Tue, 21 Aug 2018 08:46:48 +0300 Subject: T689: Moved force arp ops from vyatta-op --- op-mode-definitions/force-arp.xml | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 op-mode-definitions/force-arp.xml (limited to 'op-mode-definitions') diff --git a/op-mode-definitions/force-arp.xml b/op-mode-definitions/force-arp.xml new file mode 100644 index 000000000..3eadabf0a --- /dev/null +++ b/op-mode-definitions/force-arp.xml @@ -0,0 +1,79 @@ + + + + + Force an operation + + + + + Send gratuitous ARP request or reply + + + + + Send gratuitous ARP reply + + + + + Send gratuitous ARP reply on specified interface + + + + + + + + Send gratuitous ARP reply for specified address + + sudo arping -I $5 -c 1 -A $7 + + + + Send specified number of ARP replies + + sudo arping -I $5 -c $9 -A $7 + + + + + + + + + + Send gratuitous ARP request + + + + + Send gratuitous ARP request on specified interface + + + + + + + + Send gratuitous ARP request for specified address + + sudo arping -I $5 -c 1 -U $7 + + + + Send specified number of ARP requests + + sudo arping -I $5 -c $9 -U $7 + + + + + + + + + + + + -- cgit v1.2.3