Commit 9f63870d authored by Roman Ondráček's avatar Roman Ondráček

Gateway: add SSH daemon service manager (fix #227)

Signed-off-by: Roman Ondráček's avatarRoman Ondráček <ondracek.roman@centrum.cz>
parent 9e0ce948
Pipeline #2342 passed with stages
in 14 minutes and 33 seconds
<?php
/**
* Copyright 2017 MICRORISC s.r.o.
* Copyright 2017-2019 IQRF Tech s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare(strict_types = 1);
namespace App\GatewayModule\Models;
use App\ServiceModule\Enums\ServiceStates;
use App\ServiceModule\Models\SystemDManager;
/**
* SSH daemon manager
*/
class SshManager {
/**
* @var SystemDManager SystemD service manager
*/
private $serviceManager;
/**
* Constructor
* @param SystemDManager $serviceManager SystemD service manager
*/
public function __construct(SystemDManager $serviceManager) {
$this->serviceManager = $serviceManager;
}
/**
* Disables and stops the SSH daemon service
*/
public function disableService(): void {
$this->serviceManager->disable();
}
/**
* Enables and starts the SSH daemon service
*/
public function enableService(): void {
$this->serviceManager->enable();
}
/**
* Returns the SSH daemon service status
*/
public function getServiceStatus(): ServiceStates {
return $this->serviceManager->isEnabled();
}
}
<?php
/**
* Copyright 2017 MICRORISC s.r.o.
* Copyright 2017-2019 IQRF Tech s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare(strict_types = 1);
namespace App\GatewayModule\Presenters;
use App\CoreModule\Presenters\ProtectedPresenter;
use App\CoreModule\Traits\TPresenterFlashMessage;
use App\GatewayModule\Models\SshManager;
/**
* SSH daemon manager presenter
*/
class SshPresenter extends ProtectedPresenter {
use TPresenterFlashMessage;
/**
* @var SshManager SSH daemon manager
*/
private $manager;
/**
* Constructor
* @param SshManager $manager SSH daemon manager
*/
public function __construct(SshManager $manager) {
$this->manager = $manager;
parent::__construct();
}
/**
* Disables and stops SSH daemon
*/
public function handleDisable(): void {
$this->manager->disableService();
$this->flashSuccess('gateway.unattendedUpgrades.messages.disable');
}
/**
* Enables and starts SSH daemon
*/
public function handleEnable(): void {
$this->manager->enableService();
$this->flashSuccess('gateway.unattendedUpgrades.messages.enable');
}
/**
* Renders SSH daemon control panel
*/
public function renderDefault(): void {
$this->template->status = $this->manager->getServiceStatus();
$this->redrawControl('status');
}
/**
* Checks if the SSH daemon is enabled
*/
protected function startup(): void {
parent::startup();
if (!$this->context->parameters['features']['ssh']) {
$this->flashError('gateway.ssh.messages.disabled');
$this->redirect('Homepage:default');
}
}
}
......@@ -4,6 +4,8 @@ services:
- App\GatewayModule\Models\LogManager(%daemon.logDir%)
- App\GatewayModule\Models\NetworkManager
- App\GatewayModule\Models\PowerManager
ssh.serviceManager: App\ServiceModule\Models\SystemDManager(@commandManager, 'sshd')
ssh.manager: App\GatewayModule\Models\SshManager(@ssh.serviceManager)
- App\GatewayModule\Models\UnattendedUpgradesManager(@upgrade.serviceManager)
- App\GatewayModule\Models\UpdaterManager
- App\GatewayModule\Models\VersionManager
......
......@@ -34,6 +34,10 @@
<header class='list-group-item-heading'>{_service.title}</header>
<p class='list-group-item-text'>{_service.description}</p>
</a>
<a n:if='$features["ssh"]' n:href='Ssh:default' class='list-group-item'>
<header class='list-group-item-heading'>{_gateway.ssh.title}</header>
<p class='list-group-item-text'>{_gateway.ssh.description}</p>
</a>
<a n:if='$features["unattendedUpgrades"]' n:href='UnattendedUpgrades:default' class='list-group-item'>
<header class='list-group-item-heading'>{_gateway.unattendedUpgrades.title}</header>
<p class='list-group-item-text'>{_gateway.unattendedUpgrades.description}</p>
......
{**
* Copyright 2017 MICRORISC s.r.o.
* Copyright 2017-2019 IQRF Tech s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*}
{block title}{_gateway.ssh.title}{/block}
{block content}
<div class='panel panel-default'>
<div n:snippet='status' class='panel-body'>
<table class='table table-striped'>
<tr>
<th>{_gateway.ssh.status}</th>
<td>{_gateway.ssh.statuses.$status}</td>
</tr>
</table>
{if $status !== ''}
<a class='ajax btn btn-success' n:href='enable!' role='button'>{_gateway.ssh.enable}</a>
<a class='ajax btn btn-danger' n:href='disable!' role='button'>{_gateway.ssh.disable}</a>
{/if}
</div>
</div>
......@@ -11,6 +11,8 @@ parameters:
pixla: false
# Network manager
networkManager: false
# SSH daemon manager
ssh: false
# Supervisord dashboard
supervisord: false
# System updater
......
......@@ -77,6 +77,21 @@ power:
button: Perform reboot
success: Your device has been restarted successfully.
ssh:
title: SSH daemon control
description: Controls the SSH daemon service.
status: Service status
statuses:
enabled: Enabled
disabled: Disabled
'': Missing
enable: Enable service
disable: Disable service
messages:
disabled: SSH daemon manager is disabled.
disable: SSH daemon service has been disabled.
enable: SSH daemon service has been enabled.
unattendedUpgrades:
title: Automatic upgrades
description: Controls the automatic unattended upgrades service.
......
......@@ -37,6 +37,9 @@
<li n:class='isLinkCurrent(":Service:Control:*") ? "active"'>
<a n:href=':Service:Control:default'>{_service.title}</a>
</li>
<li n:if='$features["ssh"]' n:class='isLinkCurrent(":Gateway:Ssh:*") ? "active"'>
<a n:href=':Gateway:Ssh:default'>{_gateway.ssh.title}</a>
</li>
<li n:if='$features["unattendedUpgrades"]' n:class='isLinkCurrent(":Gateway:UnattendedUpgrades:*") ? "active"'>
<a n:href=':Gateway:UnattendedUpgrades:default'>{_gateway.unattendedUpgrades.title}</a>
</li>
......
--- a/app/config/features.neon
+++ b/app/config/features.neon
@@ -1,14 +1,14 @@
@@ -1,21 +1,21 @@
parameters:
- docs: https://docs.iqrf.org/iqrf-gateway/
+ docs: https://docs.iqrf.org/iqd-gw-01/
......@@ -17,8 +17,11 @@
+ pixla: true
# Network manager
networkManager: false
# SSH daemon manager
- ssh: false
+ ssh: true
# Supervisord dashboard
@@ -16,4 +16,4 @@
supervisord: false
# System updater
updater: false
# Unattended upgrades
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment