<?php
ConfigModule::registerModule(
ConfigModule_SshConfig::MODID, // ID
Dictionary::translateFileModule('sysconfig', 'config-module', 'sshconfig_title'), // Title
Dictionary::translateFileModule('sysconfig', 'config-module', 'sshconfig_description'), // Description
Dictionary::translateFileModule('sysconfig', 'config-module', 'group_sshconfig'), // Group
true, // Only one per config?
500
);
class ConfigModule_SshConfig extends ConfigModule
{
const MODID = 'SshConfig';
const VERSION = 1;
protected function generateInternal(string $tgz, ?string $parent)
{
if (!$this->validateConfig())
return false;
$config = $this->moduleData + array(
'filename' => $tgz,
'failOnParentFail' => false,
'parent' => $parent
);
return Taskmanager::submit('SshdConfigGenerator', $config);
}
protected function moduleVersion(): int
{
return self::VERSION;
}
protected function validateConfig(): bool
{
// UPGRADE
if (isset($this->moduleData['allowPasswordLogin']) && !isset($this->moduleData['allowedUsersLogin'])) {
$this->moduleData['allowPasswordLogin'] = strtoupper($this->moduleData['allowPasswordLogin']);
if (!in_array($this->moduleData['allowPasswordLogin'], ['NO', 'USER_ONLY', 'YES'])) {
$this->moduleData['allowPasswordLogin'] = 'NO';
}
$this->moduleData['allowedUsersLogin'] = 'ALL';
}
return isset($this->moduleData['allowPasswordLogin']) && isset($this->moduleData['allowedUsersLogin'])
&& isset($this->moduleData['listenPort']);
}
public function setData(string $key, $value): bool
{
switch ($key) {
case 'publicKey':
if ($value === false) {
error_log('Unsetting publicKey');
unset($this->moduleData[$key]);
return true;
}
return false;
case 'allowPasswordLogin':
if (!in_array($value, ['NO', 'USER_ONLY', 'YES']))
return false;
break;
case 'allowedUsersLogin';
if (!in_array($value, ['ROOT_ONLY', 'USER_ONLY', 'ALL']))
return false;
break;
case 'listenPort':
if (!is_numeric($value) || $value < 1 || $value > 65535)
return false;
$value = (int)$value;
break;
default:
return false;
}
$this->moduleData[$key] = $value;
return true;
}
}