blob: e4a55ad7e7b6e98d497cbefdd88f9001102e6b78 (
plain) (
tree)
|
|
<?php
ConfigModule::registerModule(
ConfigModule_SshKey::MODID, // ID
Dictionary::translateFileModule('sysconfig', 'config-module', 'sshkey_title'), // Title
Dictionary::translateFileModule('sysconfig', 'config-module', 'sshkey_description'), // Description
Dictionary::translateFileModule('sysconfig', 'config-module', 'group_sshkey'), // Group
false, // Only one per config?
510
);
class ConfigModule_SshKey extends ConfigModule
{
const MODID = 'SshKey';
const VERSION = 1;
protected function generateInternal(string $tgz, ?string $parent)
{
if (!$this->validateConfig())
return false;
$config = array(
'files' => [
'/root/.ssh/authorized_keys.d/sshkey_' . $this->id() . '_' . Util::sanitizeFilename($this->title()) . '.pub'
=> $this->moduleData['publicKey']],
'destination' => $tgz,
'failOnParentFail' => false,
'parent' => $parent
);
// Create config module, which will also check if the pubkey is valid
return Taskmanager::submit('MakeTarball', $config);
}
protected function moduleVersion(): int
{
return self::VERSION;
}
protected function validateConfig(): bool
{
return isset($this->moduleData['publicKey']);
}
public function setData(string $key, $value): bool
{
switch ($key) {
case 'publicKey':
break;
default:
return false;
}
$this->moduleData[$key] = $value;
return true;
}
}
|