1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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,
'parentTask' => $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;
}
}
|