summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/inc/configmodule/sshkey.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/sysconfig/inc/configmodule/sshkey.inc.php')
-rw-r--r--modules-available/sysconfig/inc/configmodule/sshkey.inc.php55
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..2d212d25
--- /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($tgz, $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()
+ {
+ return self::VERSION;
+ }
+
+ protected function validateConfig()
+ {
+ return isset($this->moduleData['publicKey']);
+ }
+
+ public function setData($key, $value)
+ {
+ switch ($key) {
+ case 'publicKey':
+ break;
+ default:
+ return false;
+ }
+ $this->moduleData[$key] = $value;
+ return true;
+ }
+
+}