summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/inc/configmodule
diff options
context:
space:
mode:
authorSimon Rettberg2016-05-11 19:00:30 +0200
committerSimon Rettberg2016-05-11 19:00:30 +0200
commit1cc1c2ed092c46eb35893c1d85accb24cf43d7f9 (patch)
tree95c1302f4a1ae441e174a1dca64133e2873f8297 /modules-available/sysconfig/inc/configmodule
parentAdd PhpStorm prefs (diff)
downloadslx-admin-1cc1c2ed092c46eb35893c1d85accb24cf43d7f9.tar.gz
slx-admin-1cc1c2ed092c46eb35893c1d85accb24cf43d7f9.tar.xz
slx-admin-1cc1c2ed092c46eb35893c1d85accb24cf43d7f9.zip
Still working in modularization cleanup and refinement
Diffstat (limited to 'modules-available/sysconfig/inc/configmodule')
-rw-r--r--modules-available/sysconfig/inc/configmodule/adauth.inc.php75
-rw-r--r--modules-available/sysconfig/inc/configmodule/branding.inc.php56
-rw-r--r--modules-available/sysconfig/inc/configmodule/customodule.inc.php56
-rw-r--r--modules-available/sysconfig/inc/configmodule/ldapauth.inc.php77
-rw-r--r--modules-available/sysconfig/inc/configmodule/sshconfig.inc.php63
5 files changed, 327 insertions, 0 deletions
diff --git a/modules-available/sysconfig/inc/configmodule/adauth.inc.php b/modules-available/sysconfig/inc/configmodule/adauth.inc.php
new file mode 100644
index 00000000..a03be43c
--- /dev/null
+++ b/modules-available/sysconfig/inc/configmodule/adauth.inc.php
@@ -0,0 +1,75 @@
+<?php
+
+ConfigModule::registerModule(
+ ConfigModule_AdAuth::MODID, // ID
+ Dictionary::translateFile('config-module', 'adAuth_title'), // Title
+ Dictionary::translateFile('config-module', 'adAuth_description'), // Description
+ Dictionary::translateFile('config-module', 'group_authentication'), // Group
+ true // Only one per config?
+);
+
+class ConfigModule_AdAuth extends ConfigModule
+{
+
+ const MODID = 'AdAuth';
+ const VERSION = 1;
+
+ private static $REQUIRED_FIELDS = array('server', 'searchbase', 'binddn');
+ private static $OPTIONAL_FIELDS = array('bindpw', 'home', 'ssl', 'fingerprint', 'certificate', 'homeattr');
+
+ protected function generateInternal($tgz, $parent)
+ {
+ Trigger::ldadp($this->id(), $parent);
+ $config = $this->moduleData;
+ if (isset($config['certificate']) && !is_string($config['certificate'])) {
+ unset($config['certificate']);
+ }
+ if (preg_match('/^([^\:]+)\:(\d+)$/', $config['server'], $out)) {
+ $config['server'] = $out[1];
+ $config['adport'] = $out[2];
+ } else {
+ if (isset($config['certificate'])) {
+ $config['adport'] = 636;
+ } else {
+ $config['adport'] = 389;
+ }
+ }
+ $config['parentTask'] = $parent;
+ $config['failOnParentFail'] = false;
+ $config['proxyip'] = Property::getServerIp();
+ $config['proxyport'] = 3100 + $this->id();
+ $config['filename'] = $tgz;
+ $config['moduleid'] = $this->id();
+ return Taskmanager::submit('CreateLdapConfig', $config);
+ }
+
+ protected function moduleVersion()
+ {
+ return self::VERSION;
+ }
+
+ protected function validateConfig()
+ {
+ // Check if required fields are filled
+ return Util::hasAllKeys($this->moduleData, self::$REQUIRED_FIELDS);
+ }
+
+ public function setData($key, $value)
+ {
+ if (!in_array($key, self::$REQUIRED_FIELDS) && !in_array($key, self::$OPTIONAL_FIELDS))
+ return false;
+ $this->moduleData[$key] = $value;
+ return true;
+ }
+
+ // ############## Callbacks #############################
+
+ /**
+ * Server IP changed - rebuild all AD modules.
+ */
+ public function event_serverIpChanged()
+ {
+ $this->generate(false);
+ }
+
+}
diff --git a/modules-available/sysconfig/inc/configmodule/branding.inc.php b/modules-available/sysconfig/inc/configmodule/branding.inc.php
new file mode 100644
index 00000000..479b406c
--- /dev/null
+++ b/modules-available/sysconfig/inc/configmodule/branding.inc.php
@@ -0,0 +1,56 @@
+<?php
+
+ConfigModule::registerModule(
+ ConfigModule_Branding::MODID, // ID
+ Dictionary::translateFile('config-module', 'branding_title'), // Title
+ Dictionary::translateFile('config-module', 'branding_description'), // Description
+ Dictionary::translateFile('config-module', 'group_branding'), // Group
+ true // Only one per config?
+);
+
+class ConfigModule_Branding extends ConfigModule
+{
+
+ const MODID = 'Branding';
+ const VERSION = 1;
+
+ private $tmpFile = false;
+
+ protected function generateInternal($tgz, $parent)
+ {
+ if (!$this->validateConfig()) {
+ 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,
+ 'destination' => $tgz,
+ 'parentTask' => $parent,
+ 'failOnParentFail' => false
+ ));
+ return $task;
+ }
+
+ protected function moduleVersion()
+ {
+ return self::VERSION;
+ }
+
+ protected function validateConfig()
+ {
+ return $this->tmpFile !== false && file_exists($this->tmpFile);
+ }
+
+ public function setData($key, $value)
+ {
+ if ($key !== 'tmpFile' || !is_string($value) || !file_exists($value))
+ return false;
+ $this->tmpFile = $value;
+ return true;
+ }
+
+ public function getData($key)
+ {
+ return false;
+ }
+
+}
diff --git a/modules-available/sysconfig/inc/configmodule/customodule.inc.php b/modules-available/sysconfig/inc/configmodule/customodule.inc.php
new file mode 100644
index 00000000..09b621cc
--- /dev/null
+++ b/modules-available/sysconfig/inc/configmodule/customodule.inc.php
@@ -0,0 +1,56 @@
+<?php
+
+ConfigModule::registerModule(
+ ConfigModule_CustomModule::MODID, // ID
+ Dictionary::translateFile('config-module', 'custom_title'), // Title
+ Dictionary::translateFile('config-module', 'custom_description'), // Description
+ Dictionary::translateFile('config-module', 'group_generic'), // Group
+ false, // Only one per config?
+ 100 // Sort order
+);
+
+class ConfigModule_CustomModule extends ConfigModule
+{
+ const MODID = 'CustomModule';
+ const VERSION = 1;
+
+ private $tmpFile = false;
+
+ protected function generateInternal($tgz, $parent)
+ {
+ if (!$this->validateConfig()) {
+ 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,
+ 'destination' => $tgz,
+ 'parentTask' => $parent,
+ 'failOnParentFail' => false
+ ));
+ return $task;
+ }
+
+ protected function moduleVersion()
+ {
+ return self::VERSION;
+ }
+
+ protected function validateConfig()
+ {
+ return $this->tmpFile !== false && file_exists($this->tmpFile);
+ }
+
+ public function setData($key, $value)
+ {
+ if ($key !== 'tmpFile' || !file_exists($value))
+ return false;
+ $this->tmpFile = $value;
+ return true;
+ }
+
+ public function getData($key)
+ {
+ return false;
+ }
+
+}
diff --git a/modules-available/sysconfig/inc/configmodule/ldapauth.inc.php b/modules-available/sysconfig/inc/configmodule/ldapauth.inc.php
new file mode 100644
index 00000000..0f386033
--- /dev/null
+++ b/modules-available/sysconfig/inc/configmodule/ldapauth.inc.php
@@ -0,0 +1,77 @@
+<?php
+
+ConfigModule::registerModule(
+ ConfigModule_LdapAuth::MODID, // ID
+ Dictionary::translateFile('config-module', 'ldapAuth_title'), // Title
+ Dictionary::translateFile('config-module', 'ldapAuth_description'), // Description
+ Dictionary::translateFile('config-module', 'group_authentication'), // Group
+ true // Only one per config?
+);
+
+class ConfigModule_LdapAuth extends ConfigModule
+{
+
+ const MODID = 'LdapAuth';
+ const VERSION = 1;
+
+ private static $REQUIRED_FIELDS = array('server', 'searchbase');
+ private static $OPTIONAL_FIELDS = array('binddn', 'bindpw', 'home', 'ssl', 'fingerprint', 'certificate');
+
+ protected function generateInternal($tgz, $parent)
+ {
+ Trigger::ldadp($this->id(), $parent);
+ $config = $this->moduleData;
+ if (isset($config['certificate']) && !is_string($config['certificate'])) {
+ unset($config['certificate']);
+ }
+ if (preg_match('/^([^\:]+)\:(\d+)$/', $config['server'], $out)) {
+ $config['server'] = $out[1];
+ $config['adport'] = $out[2]; // sic!
+ } else {
+ if (isset($config['certificate'])) {
+ $config['adport'] = 636;
+ } else {
+ $config['adport'] = 389;
+ }
+ }
+ $config['parentTask'] = $parent;
+ $config['failOnParentFail'] = false;
+ $config['proxyip'] = Property::getServerIp();
+ $config['proxyport'] = 3100 + $this->id();
+ $config['filename'] = $tgz;
+ $config['moduleid'] = $this->id();
+ $config['plainldap'] = true;
+ return Taskmanager::submit('CreateLdapConfig', $config);
+ }
+
+ protected function moduleVersion()
+ {
+ return self::VERSION;
+ }
+
+ protected function validateConfig()
+ {
+ // Check if required fields are filled
+ return Util::hasAllKeys($this->moduleData, self::$REQUIRED_FIELDS);
+ }
+
+ public function setData($key, $value)
+ {
+ if (!in_array($key, self::$REQUIRED_FIELDS) && !in_array($key, self::$OPTIONAL_FIELDS))
+ return false;
+ $this->moduleData[$key] = $value;
+ return true;
+ }
+
+ // ############## Callbacks #############################
+
+ /**
+ * Server IP changed - rebuild all LDAP modules.
+ */
+ public function event_serverIpChanged()
+ {
+ error_log('Calling generate on ' . $this->title());
+ $this->generate(false);
+ }
+
+}
diff --git a/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php b/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php
new file mode 100644
index 00000000..b1d58153
--- /dev/null
+++ b/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php
@@ -0,0 +1,63 @@
+<?php
+
+ConfigModule::registerModule(
+ ConfigModule_SshConfig::MODID, // ID
+ Dictionary::translateFile('config-module', 'sshconfig_title'), // Title
+ Dictionary::translateFile('config-module', 'sshconfig_description'), // Description
+ Dictionary::translateFile('config-module', 'group_sshconfig'), // Group
+ true // Only one per config?
+);
+
+class ConfigModule_SshConfig extends ConfigModule
+{
+ const MODID = 'SshConfig';
+ const VERSION = 1;
+
+ protected function generateInternal($tgz, $parent)
+ {
+ if (!$this->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;
+ }
+
+}