diff options
Diffstat (limited to 'modules-available/sysconfig/inc/configmodule/sshkey.inc.php')
-rw-r--r-- | modules-available/sysconfig/inc/configmodule/sshkey.inc.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/modules-available/sysconfig/inc/configmodule/sshkey.inc.php b/modules-available/sysconfig/inc/configmodule/sshkey.inc.php new file mode 100644 index 00000000..e4a55ad7 --- /dev/null +++ b/modules-available/sysconfig/inc/configmodule/sshkey.inc.php @@ -0,0 +1,55 @@ +<?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; + } + +} |