diff --git a/subiquity/controllers/__init__.py b/subiquity/controllers/__init__.py index 9fa521f7..395bf423 100644 --- a/subiquity/controllers/__init__.py +++ b/subiquity/controllers/__init__.py @@ -23,6 +23,7 @@ from .mirror import MirrorController from subiquitycore.controllers.login import LoginController from subiquitycore.controllers.network import NetworkController from .snaplist import SnapListController +from .ssh import SSHController from .welcome import WelcomeController __all__ = [ 'FilesystemController', @@ -35,5 +36,6 @@ __all__ = [ 'LoginController', 'NetworkController', 'SnapListController', + 'SSHController', 'WelcomeController', ] diff --git a/subiquity/controllers/identity.py b/subiquity/controllers/identity.py index 3d07fe1c..609c0548 100644 --- a/subiquity/controllers/identity.py +++ b/subiquity/controllers/identity.py @@ -122,5 +122,4 @@ class IdentityController(BaseController): safe_spec['password'] = '' log.debug("User input: {}".format(safe_spec)) self.model.add_user(user_spec) - self.signal.emit_signal('installprogress:identity-config-done') self.signal.emit_signal('next-screen') diff --git a/subiquity/controllers/ssh.py b/subiquity/controllers/ssh.py new file mode 100644 index 00000000..8b00745c --- /dev/null +++ b/subiquity/controllers/ssh.py @@ -0,0 +1,44 @@ +# Copyright 2018 Canonical, Ltd. +# +# 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 . + +import logging + +from subiquitycore.controller import BaseController +from subiquity.ui.views.ssh import SSHView + +log = logging.getLogger('subiquity.controllers.ssh') + + +class SSHController(BaseController): + + def __init__(self, common): + super().__init__(common) + self.model = self.base_model.ssh + self.answers = self.all_answers.get('SSH', {}) + + def default(self): + self.ui.set_body(SSHView(self.model, self)) + #if self.answers: + # self.done(self.answers) + + def cancel(self): + self.signal.emit_signal('prev-screen') + + def done(self, result): + #self.model.install_server = result['install_server'] + #self.model.authorized_keys = result['authorized_keys'] + #self.model.pwauth = result['pwauth'] + self.signal.emit_signal('installprogress:identity-config-done') + self.signal.emit_signal('next-screen') diff --git a/subiquity/core.py b/subiquity/core.py index 4a90c022..e53466f0 100644 --- a/subiquity/core.py +++ b/subiquity/core.py @@ -39,6 +39,7 @@ class Subiquity(Application): "Mirror", "Filesystem", "Identity", + "SSH", "SnapList", "InstallProgress", ] diff --git a/subiquity/models/ssh.py b/subiquity/models/ssh.py new file mode 100644 index 00000000..7630d243 --- /dev/null +++ b/subiquity/models/ssh.py @@ -0,0 +1,27 @@ +# Copyright 2018 Canonical, Ltd. +# +# 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 . + +import logging + + +log = logging.getLogger("subiquity.models.ssh") + + +class SSHModel: + + def __init__(self): + self.install_server = False + self.authorized_keys = None + self.pwauth = True diff --git a/subiquity/models/subiquity.py b/subiquity/models/subiquity.py index b8d7d5da..32638043 100644 --- a/subiquity/models/subiquity.py +++ b/subiquity/models/subiquity.py @@ -30,6 +30,7 @@ from .locale import LocaleModel from .proxy import ProxyModel from .mirror import MirrorModel from .snaplist import SnapListModel +from .ssh import SSHModel def setup_yaml(): @@ -65,6 +66,7 @@ class SubiquityModel: self.proxy = ProxyModel() self.mirror = MirrorModel() self.snaplist = SnapListModel() + self.ssh = SSHModel() def get_target_groups(self): command = ['chroot', self.target, 'getent', 'group'] @@ -96,8 +98,8 @@ class SubiquityModel: 'groups': groups, 'lock-passwd': False, } - if user.ssh_keys: - user_info['ssh_authorized_keys'] = user.ssh_keys + if self.ssh.authorized_keys: + user_info['ssh_authorized_keys'] = self.ssh.authorized_keys config = { 'growpart': { 'mode': 'off', @@ -107,6 +109,8 @@ class SubiquityModel: 'resize_rootfs': False, 'users': [user_info], } + if self.ssh.install_server: + config['ssh_pwauth'] = self.ssh.install_server if self.snaplist.to_install: cmds = [] for snap_name, selection in sorted( diff --git a/subiquity/ui/views/ssh.py b/subiquity/ui/views/ssh.py new file mode 100644 index 00000000..746daa46 --- /dev/null +++ b/subiquity/ui/views/ssh.py @@ -0,0 +1,55 @@ +# Copyright 2018 Canonical, Ltd. +# +# 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 . + +import logging +from urwid import connect_signal + +from subiquitycore.view import BaseView +from subiquitycore.ui.form import ( + Form, +) + + +log = logging.getLogger('subiquity.ui.ssh') + + +class SSHForm(Form): + + cancel_label = _("Back") + + +class SSHView(BaseView): + + title = _("SSH Setup") + excerpt = _("You can choose to install the OpenSSH server package to " + "enable secure remote access to your server.") + + def __init__(self, model, controller): + self.model = model + self.controller = controller + + self.form = SSHForm(initial={}) + + connect_signal(self.form, 'submit', self.done) + connect_signal(self.form, 'cancel', self.cancel) + + super().__init__(self.form.as_screen(excerpt=_(self.excerpt))) + + def done(self, sender): + log.debug("User input: {}".format(self.form.as_data())) + self.controller.done(self.form.as_data()) + + def cancel(self, result=None): + self.controller.cancel()