mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
ssh: New application to manage SSH server
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
2e55acb465
commit
07c062aef3
@ -28,12 +28,16 @@ import stat
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from plinth import action_utils
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
"""Return parsed command line arguments as dictionary."""
|
"""Return parsed command line arguments as dictionary."""
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||||
|
|
||||||
|
subparsers.add_parser('setup', help='Setup SSH server')
|
||||||
|
|
||||||
get_keys = subparsers.add_parser('get-keys',
|
get_keys = subparsers.add_parser('get-keys',
|
||||||
help='Get SSH authorized keys')
|
help='Get SSH authorized keys')
|
||||||
get_keys.add_argument('--username')
|
get_keys.add_argument('--username')
|
||||||
@ -47,6 +51,11 @@ def parse_arguments():
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def subcommand_setup(arguments):
|
||||||
|
"""Setup Open SSH server."""
|
||||||
|
action_utils.dpkg_reconfigure('openssh-server', {})
|
||||||
|
|
||||||
|
|
||||||
def get_user_homedir(username):
|
def get_user_homedir(username):
|
||||||
"""Return the home dir of a user by looking up in password database."""
|
"""Return the home dir of a user by looking up in password database."""
|
||||||
try:
|
try:
|
||||||
|
|||||||
1
data/etc/plinth/modules-enabled/ssh
Normal file
1
data/etc/plinth/modules-enabled/ssh
Normal file
@ -0,0 +1 @@
|
|||||||
|
plinth.modules.ssh
|
||||||
66
plinth/modules/ssh/__init__.py
Normal file
66
plinth/modules/ssh/__init__.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# 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 Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Plinth module for OpenSSH server.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from plinth import actions
|
||||||
|
from plinth import service as service_module
|
||||||
|
from plinth.menu import main_menu
|
||||||
|
from plinth.views import ServiceView
|
||||||
|
|
||||||
|
version = 1
|
||||||
|
|
||||||
|
is_essential = True
|
||||||
|
|
||||||
|
managed_services = ['ssh']
|
||||||
|
|
||||||
|
managed_packages = ['openssh-server']
|
||||||
|
|
||||||
|
name = _('Secure Shell (SSH) Server')
|
||||||
|
|
||||||
|
description = [
|
||||||
|
_('A Secure Shell server uses the secure shell protocol to accept '
|
||||||
|
'connections from remote computers. An authorized remote computer '
|
||||||
|
'can perform administration tasks, copy files or run other services '
|
||||||
|
'using such connections.')
|
||||||
|
]
|
||||||
|
|
||||||
|
service = None
|
||||||
|
|
||||||
|
|
||||||
|
def init():
|
||||||
|
"""Intialize the ssh module."""
|
||||||
|
menu = main_menu.get('system')
|
||||||
|
menu.add_urlname(name, 'glyphicon-console', 'ssh:index')
|
||||||
|
|
||||||
|
global service
|
||||||
|
service = service_module.Service(
|
||||||
|
managed_services[0], name, ports=['ssh'], is_external=True)
|
||||||
|
|
||||||
|
|
||||||
|
def setup(helper, old_version=False):
|
||||||
|
"""Configure the module."""
|
||||||
|
actions.superuser_run('ssh', ['setup'])
|
||||||
|
|
||||||
|
|
||||||
|
class SshServiceView(ServiceView):
|
||||||
|
service_id = managed_services[0]
|
||||||
|
description = description
|
||||||
0
plinth/modules/ssh/tests/__init__.py
Normal file
0
plinth/modules/ssh/tests/__init__.py
Normal file
29
plinth/modules/ssh/urls.py
Normal file
29
plinth/modules/ssh/urls.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# 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 Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
URLs for the Secure Shell Server module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.conf.urls import url
|
||||||
|
|
||||||
|
from plinth.modules.ssh import SshServiceView
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url(r'^sys/ssh/$', SshServiceView.as_view(), name='index'),
|
||||||
|
]
|
||||||
@ -113,13 +113,10 @@ class Service(object):
|
|||||||
|
|
||||||
def init():
|
def init():
|
||||||
"""Register some misc. services that don't fit elsewhere."""
|
"""Register some misc. services that don't fit elsewhere."""
|
||||||
|
|
||||||
Service('http', _('Web Server'), ports=['http'], is_external=True,
|
Service('http', _('Web Server'), ports=['http'], is_external=True,
|
||||||
is_enabled=True)
|
is_enabled=True)
|
||||||
Service('https', _('Web Server over Secure Socket Layer'), ports=['https'],
|
Service('https', _('Web Server over Secure Socket Layer'), ports=['https'],
|
||||||
is_external=True, is_enabled=True)
|
is_external=True, is_enabled=True)
|
||||||
Service('ssh', _('Secure Shell (SSH) Server'), ports=['ssh'],
|
|
||||||
is_external=True, is_enabled=True)
|
|
||||||
Service('plinth', format_lazy(_('{box_name} Web Interface (Plinth)'),
|
Service('plinth', format_lazy(_('{box_name} Web Interface (Plinth)'),
|
||||||
box_name=_(cfg.box_name)),
|
box_name=_(cfg.box_name)),
|
||||||
ports=['https'], is_external=True, is_enabled=True)
|
ports=['https'], is_external=True, is_enabled=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user