Enable SSH only if any keys exist

This commit is contained in:
Disassembler 2019-03-22 10:31:25 +01:00
parent 81d9bb74ee
commit 2494c55493
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
2 changed files with 8 additions and 1 deletions

View File

@ -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)

View File

@ -3,7 +3,7 @@
{% block body %}
<div class="setup-box">
<h2>SSH klíče</h2>
<p>Obsah souboru <em>authorized_hosts</em> uživatele root.</p>
<p>Obsah souboru <em>authorized_keys</em> uživatele root.</p>
<form id="update-ssh-keys" action="/update-ssh-keys" method="post">
<textarea name="ssh-keys" id="ssh-keys">{{ authorized_keys }}</textarea>
<input type="submit" value="Nastavit klíče">