From 4384a2973993b8b0f572912026f45e9ee910e3ec Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 23 May 2020 20:14:41 +0200 Subject: console-server: T2490: initial support --- src/systemd/ser2net.service | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/systemd/ser2net.service (limited to 'src/systemd') diff --git a/src/systemd/ser2net.service b/src/systemd/ser2net.service new file mode 100644 index 000000000..a5b4243af --- /dev/null +++ b/src/systemd/ser2net.service @@ -0,0 +1,13 @@ +[Unit] +Description=Serial to Network Proxy +ConditionPathExists=/run/ser2net/ser2net.conf +After=vyos-router.service + +[Service] +WorkingDirectory=/run/ser2net +PIDFile=/run/ser2net/ser2net.pid +ExecStart=/usr/sbin/ser2net -n -c /run/ser2net/ser2net.conf -P /run/ser2net/ser2net.pid -p localhost,2000 +Restart=always + +[Install] +WantedBy=multi-user.target -- cgit v1.2.3 From a1ba7bae02673aca63a7006cf683ad5d541a5054 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 17 Jun 2020 22:52:08 +0200 Subject: console-server: T2490: replace ser2net with conserver --- debian/control | 3 ++- src/systemd/ser2net.service | 13 ------------- 2 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 src/systemd/ser2net.service (limited to 'src/systemd') diff --git a/debian/control b/debian/control index aa1e87e23..42d0475e3 100644 --- a/debian/control +++ b/debian/control @@ -59,7 +59,8 @@ Depends: python3, iputils-arping, libvyosconfig0, beep, - ser2net, + conserver-server, + conserver-client, isc-dhcp-server, isc-dhcp-relay, keepalived (>=2.0.5), diff --git a/src/systemd/ser2net.service b/src/systemd/ser2net.service deleted file mode 100644 index a5b4243af..000000000 --- a/src/systemd/ser2net.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Serial to Network Proxy -ConditionPathExists=/run/ser2net/ser2net.conf -After=vyos-router.service - -[Service] -WorkingDirectory=/run/ser2net -PIDFile=/run/ser2net/ser2net.pid -ExecStart=/usr/sbin/ser2net -n -c /run/ser2net/ser2net.conf -P /run/ser2net/ser2net.pid -p localhost,2000 -Restart=always - -[Install] -WantedBy=multi-user.target -- cgit v1.2.3 From e59da2923cbbb21258cc9769b6a152d6af78abe6 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Thu, 18 Jun 2020 23:04:46 +0200 Subject: console-server: T2490: add SSH support A user can define a port under the SSH node per device. WHen connecting to that port and authenticating using regular credentials we will immediately drop to the serial console. This is the same as executing "connect serial-proxy ". --- debian/control | 1 + interface-definitions/service_serial-proxy.xml.in | 8 ++++++++ src/conf_mode/service_serial-proxy.py | 17 ++++++++++++----- src/systemd/dropbear@.service | 14 ++++++++++++++ src/systemd/dropbearkey.service | 11 +++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/systemd/dropbear@.service create mode 100644 src/systemd/dropbearkey.service (limited to 'src/systemd') diff --git a/debian/control b/debian/control index 42d0475e3..bf330c35c 100644 --- a/debian/control +++ b/debian/control @@ -59,6 +59,7 @@ Depends: python3, iputils-arping, libvyosconfig0, beep, + dropbear, conserver-server, conserver-client, isc-dhcp-server, diff --git a/interface-definitions/service_serial-proxy.xml.in b/interface-definitions/service_serial-proxy.xml.in index ca93fcac3..917af0122 100644 --- a/interface-definitions/service_serial-proxy.xml.in +++ b/interface-definitions/service_serial-proxy.xml.in @@ -73,6 +73,14 @@ + + + SSH remote access to this console + + + #include + + diff --git a/src/conf_mode/service_serial-proxy.py b/src/conf_mode/service_serial-proxy.py index 0dd1cfc6d..5f510d311 100755 --- a/src/conf_mode/service_serial-proxy.py +++ b/src/conf_mode/service_serial-proxy.py @@ -65,11 +65,11 @@ def verify(proxy): for tmp in proxy['device']: device = proxy['device'][tmp] if not device['speed']: - raise ConfigError(f'Speed must be defined!') + raise ConfigError(f'Serial port speed must be defined for "{tmp}"!') - if device['ssh']: - if not device['ssh']['port']: - raise ConfigError(f'SSH port must be defined!') + if 'ssh' in device.keys(): + if 'port' not in device['ssh'].keys(): + raise ConfigError(f'SSH port must be defined for "{tmp}"!') return None @@ -81,13 +81,20 @@ def generate(proxy): return None def apply(proxy): + call('systemctl stop conserver-server.service') + call('systemctl stop dropbear@*.service') + if not proxy: - call('systemctl stop conserver-server.service') if os.path.isfile(config_file): os.unlink(config_file) return None call('systemctl restart conserver-server.service') + + for device in proxy['device']: + if 'ssh' in proxy['device'][device].keys(): + call('systemctl restart dropbear@{device}.service') + return None if __name__ == '__main__': diff --git a/src/systemd/dropbear@.service b/src/systemd/dropbear@.service new file mode 100644 index 000000000..a4df6ad41 --- /dev/null +++ b/src/systemd/dropbear@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Dropbear SSH per-connection server +Requires=dropbearkey.service +Wants=conserver-server.service +After=mongodb.service +After=dropbearkey.service vyos-router.service conserver-server.service + +[Service] +Type=forking +ExecStartPre=/usr/bin/bash -c '/usr/bin/systemctl set-environment PORT=$(cli-shell-api returnValue service serial-proxy device "%I" ssh port)' +ExecStart=-/usr/sbin/dropbear -w -j -k -r /etc/dropbear/dropbear_rsa_host_key -c "/usr/bin/console %I" -P /run/conserver/dropbear.%I.pid -p ${PORT} +PIDFile=/run/conserver/dropbear.%I.pid +KillMode=process + diff --git a/src/systemd/dropbearkey.service b/src/systemd/dropbearkey.service new file mode 100644 index 000000000..770641c8b --- /dev/null +++ b/src/systemd/dropbearkey.service @@ -0,0 +1,11 @@ +[Unit] +Description=Dropbear SSH Key Generation +ConditionPathExists=|!/etc/dropbear/dropbear_rsa_host_key + +[Service] +ExecStart=/usr/bin/dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target + -- cgit v1.2.3 From b509bbf0c0bf33f39e67f0aa8df481ef15d6bae9 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Thu, 18 Jun 2020 23:09:58 +0200 Subject: console-server: T2490: rename CLI to console-server --- data/templates/conserver/conserver.conf.tmpl | 2 +- .../service_console-server.xml.in | 90 +++++++++++++++++ interface-definitions/service_serial-proxy.xml.in | 90 ----------------- op-mode-definitions/connect-disconnect.xml | 6 +- src/conf_mode/service_console-server.py | 108 +++++++++++++++++++++ src/conf_mode/service_serial-proxy.py | 108 --------------------- src/systemd/dropbear@.service | 2 +- 7 files changed, 203 insertions(+), 203 deletions(-) create mode 100644 interface-definitions/service_console-server.xml.in delete mode 100644 interface-definitions/service_serial-proxy.xml.in create mode 100755 src/conf_mode/service_console-server.py delete mode 100755 src/conf_mode/service_serial-proxy.py (limited to 'src/systemd') diff --git a/data/templates/conserver/conserver.conf.tmpl b/data/templates/conserver/conserver.conf.tmpl index 329a9b4ae..5fffaf31e 100644 --- a/data/templates/conserver/conserver.conf.tmpl +++ b/data/templates/conserver/conserver.conf.tmpl @@ -1,4 +1,4 @@ -### Autogenerated by service_serial-proxy.py ### +### Autogenerated by service_console-server.py ### # See https://www.conserver.com/docs/conserver.cf.man.html for additional options diff --git a/interface-definitions/service_console-server.xml.in b/interface-definitions/service_console-server.xml.in new file mode 100644 index 000000000..679ea32a2 --- /dev/null +++ b/interface-definitions/service_console-server.xml.in @@ -0,0 +1,90 @@ + + + + + + + Serial Console Server + + + + + System serial interface name (ttyS or ttyUSB) + + + + + + ttySxxx + Regular serial interface + + + usbxbxpx + USB based serial interface + + + ^(ttyS\d+|usb\d+b.*p.*)$ + + + + #include + #include + + + Serial port baud rate + + 300 1200 2400 4800 9600 19200 38400 57600 115200 + + + (300|1200|2400|4800|9600|19200|38400|57600|115200) + + + + + + Serial port data bits (default: 8) + + 7 8 + + + (7|8) + + + + + + Serial port stop bits (default: 1) + + 1 2 + + + (1|2) + + + + + + Parity setting (default: none) + + even odd none + + + (even|odd|none) + + + + + + SSH remote access to this console + + + #include + + + + + + + + + diff --git a/interface-definitions/service_serial-proxy.xml.in b/interface-definitions/service_serial-proxy.xml.in deleted file mode 100644 index 917af0122..000000000 --- a/interface-definitions/service_serial-proxy.xml.in +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - Serial to Network - - - - - System serial interface name (ttyS or ttyUSB) - - - - - - ttySxxx - Regular serial interface - - - usbxbxpx - USB based serial interface - - - ^(ttyS\d+|usb\d+b.*p.*)$ - - - - #include - #include - - - Serial port baud rate - - 300 1200 2400 4800 9600 19200 38400 57600 115200 - - - (300|1200|2400|4800|9600|19200|38400|57600|115200) - - - - - - Serial port data bits (default: 8) - - 7 8 - - - (7|8) - - - - - - Serial port stop bits (default: 1) - - 1 2 - - - (1|2) - - - - - - Parity setting (default: none) - - even odd none - - - (even|odd|none) - - - - - - SSH remote access to this console - - - #include - - - - - - - - - diff --git a/op-mode-definitions/connect-disconnect.xml b/op-mode-definitions/connect-disconnect.xml index a394e9b91..69afe6db0 100644 --- a/op-mode-definitions/connect-disconnect.xml +++ b/op-mode-definitions/connect-disconnect.xml @@ -15,11 +15,11 @@ sudo ${vyos_op_scripts_dir}/connect_disconnect.py --connect "$3" - + - Connect to serial proxy port + Connect to port of serial console server - service serial-proxy device + service console-server device /usr/bin/console "$3" diff --git a/src/conf_mode/service_console-server.py b/src/conf_mode/service_console-server.py new file mode 100755 index 000000000..087b13c04 --- /dev/null +++ b/src/conf_mode/service_console-server.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2018-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 . + +import os + +from sys import exit + +from vyos.config import Config +from vyos.configdict import dict_merge +from vyos.template import render +from vyos.util import call +from vyos import ConfigError + +config_file = r'/run/conserver/conserver.cf' + +# Default values are necessary until the implementation of T2588 is completed +default_values = { + 'data_bits': '8', + 'parity': 'none', + 'stop_bits': '1' +} + +def get_config(): + conf = Config() + base = ['service', 'console-server'] + + if not conf.exists(base): + return None + + # Retrieve CLI representation as dictionary + proxy = conf.get_config_dict(base, key_mangling=('-', '_')) + # The retrieved dictionary will look something like this: + # + # {'device': {'usb0b2.4p1.0': {'speed': '9600'}, + # 'usb0b2.4p1.1': {'data_bits': '8', + # 'parity': 'none', + # 'speed': '115200', + # 'stop_bits': '2'}}} + + # We have gathered the dict representation of the CLI, but there are default + # options which we need to update into the dictionary retrived. + for device in proxy['device'].keys(): + tmp = dict_merge(default_values, proxy['device'][device]) + proxy['device'][device] = tmp + + return proxy + +def verify(proxy): + if not proxy: + return None + + for tmp in proxy['device']: + device = proxy['device'][tmp] + if not device['speed']: + raise ConfigError(f'Serial port speed must be defined for "{tmp}"!') + + if 'ssh' in device.keys(): + if 'port' not in device['ssh'].keys(): + raise ConfigError(f'SSH port must be defined for "{tmp}"!') + + return None + +def generate(proxy): + if not proxy: + return None + + render(config_file, 'conserver/conserver.conf.tmpl', proxy) + return None + +def apply(proxy): + call('systemctl stop conserver-server.service') + call('systemctl stop dropbear@*.service') + + if not proxy: + if os.path.isfile(config_file): + os.unlink(config_file) + return None + + call('systemctl restart conserver-server.service') + + for device in proxy['device']: + if 'ssh' in proxy['device'][device].keys(): + call('systemctl restart dropbear@{device}.service') + + return None + +if __name__ == '__main__': + try: + c = get_config() + verify(c) + generate(c) + apply(c) + except ConfigError as e: + print(e) + exit(1) diff --git a/src/conf_mode/service_serial-proxy.py b/src/conf_mode/service_serial-proxy.py deleted file mode 100755 index 5f510d311..000000000 --- a/src/conf_mode/service_serial-proxy.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (C) 2018-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 . - -import os - -from sys import exit - -from vyos.config import Config -from vyos.configdict import dict_merge -from vyos.template import render -from vyos.util import call -from vyos import ConfigError - -config_file = r'/run/conserver/conserver.cf' - -# Default values are necessary until the implementation of T2588 is completed -default_values = { - 'data_bits': '8', - 'parity': 'none', - 'stop_bits': '1' -} - -def get_config(): - conf = Config() - base = ['service', 'serial-proxy'] - - if not conf.exists(base): - return None - - # Retrieve CLI representation as dictionary - proxy = conf.get_config_dict(base, key_mangling=('-', '_')) - # The retrieved dictionary will look something like this: - # - # {'device': {'usb0b2.4p1.0': {'speed': '9600'}, - # 'usb0b2.4p1.1': {'data_bits': '8', - # 'parity': 'none', - # 'speed': '115200', - # 'stop_bits': '2'}}} - - # We have gathered the dict representation of the CLI, but there are default - # options which we need to update into the dictionary retrived. - for device in proxy['device'].keys(): - tmp = dict_merge(default_values, proxy['device'][device]) - proxy['device'][device] = tmp - - return proxy - -def verify(proxy): - if not proxy: - return None - - for tmp in proxy['device']: - device = proxy['device'][tmp] - if not device['speed']: - raise ConfigError(f'Serial port speed must be defined for "{tmp}"!') - - if 'ssh' in device.keys(): - if 'port' not in device['ssh'].keys(): - raise ConfigError(f'SSH port must be defined for "{tmp}"!') - - return None - -def generate(proxy): - if not proxy: - return None - - render(config_file, 'conserver/conserver.conf.tmpl', proxy) - return None - -def apply(proxy): - call('systemctl stop conserver-server.service') - call('systemctl stop dropbear@*.service') - - if not proxy: - if os.path.isfile(config_file): - os.unlink(config_file) - return None - - call('systemctl restart conserver-server.service') - - for device in proxy['device']: - if 'ssh' in proxy['device'][device].keys(): - call('systemctl restart dropbear@{device}.service') - - return None - -if __name__ == '__main__': - try: - c = get_config() - verify(c) - generate(c) - apply(c) - except ConfigError as e: - print(e) - exit(1) diff --git a/src/systemd/dropbear@.service b/src/systemd/dropbear@.service index a4df6ad41..a7057ffe1 100644 --- a/src/systemd/dropbear@.service +++ b/src/systemd/dropbear@.service @@ -7,7 +7,7 @@ After=dropbearkey.service vyos-router.service conserver-server.service [Service] Type=forking -ExecStartPre=/usr/bin/bash -c '/usr/bin/systemctl set-environment PORT=$(cli-shell-api returnValue service serial-proxy device "%I" ssh port)' +ExecStartPre=/usr/bin/bash -c '/usr/bin/systemctl set-environment PORT=$(cli-shell-api returnValue service console-server device "%I" ssh port)' ExecStart=-/usr/sbin/dropbear -w -j -k -r /etc/dropbear/dropbear_rsa_host_key -c "/usr/bin/console %I" -P /run/conserver/dropbear.%I.pid -p ${PORT} PIDFile=/run/conserver/dropbear.%I.pid KillMode=process -- cgit v1.2.3 From 587416ef606827c5cbf6ac49834fc65283794fbb Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 19 Jun 2020 16:12:27 +0200 Subject: console-server: T2490: add SSH support for direct device access --- src/conf_mode/service_console-server.py | 17 +++++++++-------- .../system/conserver-server.service.d/override.conf | 3 ++- src/systemd/dropbear@.service | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'src/systemd') diff --git a/src/conf_mode/service_console-server.py b/src/conf_mode/service_console-server.py index 087b13c04..7f6967983 100755 --- a/src/conf_mode/service_console-server.py +++ b/src/conf_mode/service_console-server.py @@ -62,13 +62,14 @@ def verify(proxy): if not proxy: return None - for tmp in proxy['device']: - device = proxy['device'][tmp] - if not device['speed']: + for device in proxy['device']: + keys = proxy['device'][device].keys() + if 'speed' not in keys: raise ConfigError(f'Serial port speed must be defined for "{tmp}"!') - if 'ssh' in device.keys(): - if 'port' not in device['ssh'].keys(): + if 'ssh' in keys: + ssh_keys = proxy['device'][device]['ssh'].keys() + if 'port' not in ssh_keys: raise ConfigError(f'SSH port must be defined for "{tmp}"!') return None @@ -81,8 +82,7 @@ def generate(proxy): return None def apply(proxy): - call('systemctl stop conserver-server.service') - call('systemctl stop dropbear@*.service') + call('systemctl stop dropbear@*.service conserver-server.service') if not proxy: if os.path.isfile(config_file): @@ -93,7 +93,8 @@ def apply(proxy): for device in proxy['device']: if 'ssh' in proxy['device'][device].keys(): - call('systemctl restart dropbear@{device}.service') + port = proxy['device'][device]['ssh']['port'] + call(f'systemctl restart dropbear@{device}.service') return None diff --git a/src/etc/systemd/system/conserver-server.service.d/override.conf b/src/etc/systemd/system/conserver-server.service.d/override.conf index 5301b38ce..828d0bc4b 100644 --- a/src/etc/systemd/system/conserver-server.service.d/override.conf +++ b/src/etc/systemd/system/conserver-server.service.d/override.conf @@ -1,9 +1,10 @@ [Unit] After= After=vyos-router.service +ConditionPathExists=/run/conserver/conserver.cf [Service] Type=simple ExecStart= ExecStart=/usr/sbin/conserver -C /run/conserver/conserver.cf - +Restart=on-failure diff --git a/src/systemd/dropbear@.service b/src/systemd/dropbear@.service index a7057ffe1..606a7ea6d 100644 --- a/src/systemd/dropbear@.service +++ b/src/systemd/dropbear@.service @@ -2,13 +2,13 @@ Description=Dropbear SSH per-connection server Requires=dropbearkey.service Wants=conserver-server.service -After=mongodb.service +ConditionPathExists=/run/conserver/conserver.cf After=dropbearkey.service vyos-router.service conserver-server.service [Service] Type=forking -ExecStartPre=/usr/bin/bash -c '/usr/bin/systemctl set-environment PORT=$(cli-shell-api returnValue service console-server device "%I" ssh port)' +ExecStartPre=/usr/bin/bash -c '/usr/bin/systemctl set-environment PORT=$(cli-shell-api returnActiveValue service console-server device "%I" ssh port)' ExecStart=-/usr/sbin/dropbear -w -j -k -r /etc/dropbear/dropbear_rsa_host_key -c "/usr/bin/console %I" -P /run/conserver/dropbear.%I.pid -p ${PORT} PIDFile=/run/conserver/dropbear.%I.pid KillMode=process - +Restart=on-failure -- cgit v1.2.3