summaryrefslogtreecommitdiffstats
path: root/inc/configmodule/adauth.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2015-01-20 18:07:24 +0100
committerSimon Rettberg2015-01-20 18:07:24 +0100
commit1ff2bc4f3c694b7c76df8e57056c51ca39a23a34 (patch)
tree0eb19164af66b3d4e8bf639a710f323b631d23ee /inc/configmodule/adauth.inc.php
parentRework config module class structure. Still some TODOs though.... (diff)
downloadslx-admin-1ff2bc4f3c694b7c76df8e57056c51ca39a23a34.tar.gz
slx-admin-1ff2bc4f3c694b7c76df8e57056c51ca39a23a34.tar.xz
slx-admin-1ff2bc4f3c694b7c76df8e57056c51ca39a23a34.zip
config module structure completed. Many other fixes. Hidden pw field support.
Diffstat (limited to 'inc/configmodule/adauth.inc.php')
-rw-r--r--inc/configmodule/adauth.inc.php130
1 files changed, 33 insertions, 97 deletions
diff --git a/inc/configmodule/adauth.inc.php b/inc/configmodule/adauth.inc.php
index c0d4860c..06ac5460 100644
--- a/inc/configmodule/adauth.inc.php
+++ b/inc/configmodule/adauth.inc.php
@@ -1,7 +1,7 @@
<?php
-ConfigModules::registerModule(
- ConfigModule_AdAuth::MODID, // ID
+ConfigModule::registerModule(
+ 'AdAuth', // ID
Dictionary::translate('config-module', 'adAuth_title'), // Title
Dictionary::translate('config-module', 'adAuth_description'), // Description
Dictionary::translate('config-module', 'group_authentication'), // Group
@@ -10,115 +10,51 @@ ConfigModules::registerModule(
class ConfigModule_AdAuth extends ConfigModule
{
- const MODID = 'AdAuth';
- public static function insert($title, $server, $searchbase, $binddn, $bindpw, $home)
+ const VERSION = 1;
+
+ private static $REQUIRED_FIELDS = array('server', 'searchbase', 'binddn');
+ private static $OPTIONAL_FIELDS = array('bindpw', 'home');
+
+ protected function generateInternal($tgz, $parent)
{
- Database::exec("LOCK TABLE configtgz_module WRITE");
- Database::exec("INSERT INTO configtgz_module (title, moduletype, filepath, contents) "
- . " VALUES (:title, :modid, '', '')", array('title' => $title, 'modid' => self::MODID));
- $id = Database::lastInsertId();
- if (!is_numeric($id)) Util::traceError('Inserting new AD config to DB did not yield a numeric insert id');
- // Entry created, now try to get a free port for the proxy
- $res = Database::simpleQuery("SELECT moduleid, contents FROM configtgz_module WHERE moduletype = :modid", array(
- 'modid' => self::MODID
- ));
- $ports = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- if ($row['moduleid'] == $id) {
- // ...
- } else {
- $data = json_decode($row['contents'], true);
- if (isset($data['proxyport'])) $ports[] = $data['proxyport'];
- }
- }
- $port = 3300;
- while (in_array($port, $ports)) {
- $port++;
- }
- // Port determined, carry on...
- $ownEntry = array(
- 'server' => $server,
- 'searchbase' => $searchbase,
- 'binddn' => $binddn,
- 'bindpw' => $bindpw,
- 'home' => $home,
- 'proxyport' => $port
- );
- $data = json_encode($ownEntry);
- if ($data === false) Util::traceError('Serializing the AD data failed.');
- $moduleTgz = CONFIG_TGZ_LIST_DIR . '/modules/AD_AUTH_id_' . $id . '.' . mt_rand() . '.tgz';
- Database::exec("UPDATE configtgz_module SET filepath = :filename, contents = :contents WHERE moduleid = :id LIMIT 1", array(
- 'id' => $id,
- 'filename' => $moduleTgz,
- 'contents' => $data
- ));
- Database::exec("UNLOCK TABLES");
- // Add archive file name to array before returning it
- $ownEntry['moduleid'] = $id;
- $ownEntry['filename'] = $moduleTgz;
- return $ownEntry;
+ $config = $this->moduleData;
+ $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('CreateAdConfig', $config);
}
- /**
- * To be called if the server ip changes, as it's embedded in the AD module configs.
- * This will then recreate all AD tgz modules.
- */
- private static function rebuildAll($parent = NULL)
+ protected function moduleVersion()
{
- // Stop all running instances of ldadp
- $task = Taskmanager::submit('LdadpLauncher', array(
- 'parentTask' => $parent,
- 'failOnParentFail' => false,
- 'ids' => array()
- ));
- $ads = self::getAll();
- if (empty($ads)) // Nothing to do
- return false;
+ return self::VERSION;
+ }
- if (isset($task['id']))
- $parent = $task['id'];
- foreach ($ads as $ad) {
- $ad['parentTask'] = $parent;
- $ad['failOnParentFail'] = false;
- $ad['proxyip'] = Property::getServerIp();
- $task = Taskmanager::submit('CreateAdConfig', $ad);
- if (isset($task['id']))
- $parent = $task['id'];
- }
- Trigger::ldadp($parent);
- return $parent;
+ protected function validateConfig()
+ {
+ // Check if required fields are filled
+ return Util::hasAllKeys($this->moduleData, self::$REQUIRED_FIELDS);
}
-
- /**
- * Get all existing AD proxy configs.
- *
- * @return array array of ad configs in DB with fields:
- * moduleid, filename, server, searchbase, binddn, bindpw, home, proxyport
- */
- public static function getAll()
+
+ public function setData($key, $value)
{
- $res = Database::simpleQuery("SELECT moduleid, filepath, contents FROM configtgz_module WHERE moduletype = :modid", array(
- 'modid' => self::MODID
- ));
- $mods = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- $data = json_decode($row['contents'], true);
- $data['moduleid'] = $row['moduleid'];
- $data['filename'] = $row['filepath'];
- $mods[] = $data;
- }
- return $mods;
+ 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()
{
- self::rebuildAll();
+ $this->generate(false);
}
-
+
}