From 2494c55493cb0d097e0e1d8a048785c88c29ab09 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Fri, 22 Mar 2019 10:31:25 +0100 Subject: [PATCH] Enable SSH only if any keys exist --- usr/lib/python3.6/vmmgr/remote.py | 7 +++++++ usr/share/vmmgr/templates/setup-remote.html | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/usr/lib/python3.6/vmmgr/remote.py b/usr/lib/python3.6/vmmgr/remote.py index 5d5208b..bb304e1 100644 --- a/usr/lib/python3.6/vmmgr/remote.py +++ b/usr/lib/python3.6/vmmgr/remote.py @@ -18,6 +18,13 @@ def set_authorized_keys(keys): # Saves content of root's authorized_files with open(AUTHORIZED_KEYS, 'w') as f: f.write(keys) + # Enable or disable SSH service + if keys.strip(): + subprocess.run(['/sbin/rc-update', 'add', 'sshd', 'boot']) + subprocess.run(['/sbin/service', 'sshd', 'start']) + else: + subprocess.run(['/sbin/service', 'sshd', 'stop']) + subprocess.run(['/sbin/rc-update', 'del', 'sshd', 'boot']) def is_wireguard_running(): # Returns status of wg0 interface (inferred from existence of its config file) diff --git a/usr/share/vmmgr/templates/setup-remote.html b/usr/share/vmmgr/templates/setup-remote.html index 78eac54..7893322 100644 --- a/usr/share/vmmgr/templates/setup-remote.html +++ b/usr/share/vmmgr/templates/setup-remote.html @@ -3,7 +3,7 @@ {% block body %}

SSH klíče

-

Obsah souboru authorized_hosts uživatele root.

+

Obsah souboru authorized_keys uživatele root.