From 161180cdf4e915526bc8d62c0301a09130fbf59e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 6 Feb 2015 16:12:45 +0100 Subject: Add sshd config module --- inc/configmodule.inc.php | 21 +++++++++--- inc/configmodule/adauth.inc.php | 7 ---- inc/configmodule/customodule.inc.php | 4 +-- inc/configmodule/sshconfig.inc.php | 63 ++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 inc/configmodule/sshconfig.inc.php (limited to 'inc') diff --git a/inc/configmodule.inc.php b/inc/configmodule.inc.php index 31c19953..4dd7c951 100644 --- a/inc/configmodule.inc.php +++ b/inc/configmodule.inc.php @@ -165,12 +165,20 @@ abstract class ConfigModule public abstract function setData($key, $value); /** - * Get module specific data + * Get module specific data. + * Can be overridden by modules. * - * @param string $key key, name or id of data to get + * @param string $key key, name or id of data to get, or false to get the raw moduleData array * @return mixed Module specific data */ - public abstract function getData($key); + public function getData($key) + { + if ($key === false) + return $this->moduleData; + if (!is_array($this->moduleData) || !isset($this->moduleData[$key])) + return false; + return $this->moduleData[$key]; + } /** * Module specific version of generate. @@ -275,16 +283,19 @@ abstract class ConfigModule * * @return boolean true on success, false otherwise */ - public final function update() + public final function update($title) { if ($this->moduleId === 0) Util::traceError('ConfigModule::update called when moduleId == 0'); + if (empty($title)) + $title = $this->moduleTitle; if (!$this->validateConfig()) return false; // Update - Database::exec("UPDATE configtgz_module SET contents = :contents, status = :status " + Database::exec("UPDATE configtgz_module SET title = :title, contents = :contents, status = :status " . " WHERE moduleid = :moduleid LIMIT 1", array( 'moduleid' => $this->moduleId, + 'title' => $title, 'contents' => json_encode($this->moduleData), 'status' => 'OUTDATED' )); diff --git a/inc/configmodule/adauth.inc.php b/inc/configmodule/adauth.inc.php index 11087286..828469c3 100644 --- a/inc/configmodule/adauth.inc.php +++ b/inc/configmodule/adauth.inc.php @@ -47,13 +47,6 @@ class ConfigModule_AdAuth extends ConfigModule return true; } - public function getData($key) - { - if (!is_array($this->moduleData) || !isset($this->moduleData[$key])) - return false; - return $this->moduleData[$key]; - } - // ############## Callbacks ############################# /** diff --git a/inc/configmodule/customodule.inc.php b/inc/configmodule/customodule.inc.php index 89f63549..31796e9c 100644 --- a/inc/configmodule/customodule.inc.php +++ b/inc/configmodule/customodule.inc.php @@ -19,9 +19,7 @@ class ConfigModule_CustomModule extends ConfigModule protected function generateInternal($tgz, $parent) { if (!$this->validateConfig()) { - if ($this->archive() !== false && file_exists($this->archive())) - return true; // No new temp file given, old archive still exists, pretend it worked... - return false; + return $this->archive() !== false && file_exists($this->archive()); // No new temp file given, old archive still exists, pretend it worked... } $task = Taskmanager::submit('MoveFile', array( 'source' => $this->tmpFile, diff --git a/inc/configmodule/sshconfig.inc.php b/inc/configmodule/sshconfig.inc.php new file mode 100644 index 00000000..853acf6a --- /dev/null +++ b/inc/configmodule/sshconfig.inc.php @@ -0,0 +1,63 @@ +validateConfig()) + return false; + $config = $this->moduleData + array( + 'filename' => $tgz, + 'failOnParentFail' => false, + 'parent' => $parent + ); + // Create config module, which will also check if the pubkey is valid + return Taskmanager::submit('SshdConfigGenerator', $config); + } + + protected function moduleVersion() + { + return self::VERSION; + } + + protected function validateConfig() + { + return isset($this->moduleData['publicKey']) && isset($this->moduleData['allowPasswordLogin']) && isset($this->moduleData['listenPort']); + } + + public function setData($key, $value) + { + switch ($key) { + case 'publicKey': + break; + case 'allowPasswordLogin': + if ($value === true || $value === 'yes') + $value = 'yes'; + elseif ($value === false || $value === 'no') + $value = 'no'; + else + return false; + break; + case 'listenPort': + if (!is_numeric($value) || $value < 1 || $value > 65535) + return false; + break; + default: + return false; + } + $this->moduleData[$key] = $value; + return true; + } + +} -- cgit v1.2.3-55-g7522