From 97a0f7dcfdcf4a5263c1cc6c19160a0868abb5f2 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 12 Dec 2014 18:28:38 +0100 Subject: Rework config module class structure. Still some TODOs though.... --- modules/sysconfig/addconfig.inc.php | 2 +- modules/sysconfig/addmodule.inc.php | 2 +- modules/sysconfig/addmodule_ad.inc.php | 142 ---------------------- modules/sysconfig/addmodule_adauth.inc.php | 145 +++++++++++++++++++++++ modules/sysconfig/addmodule_branding.inc.php | 4 +- modules/sysconfig/addmodule_custom.inc.php | 140 ---------------------- modules/sysconfig/addmodule_custommodule.inc.php | 136 +++++++++++++++++++++ 7 files changed, 284 insertions(+), 287 deletions(-) delete mode 100644 modules/sysconfig/addmodule_ad.inc.php create mode 100644 modules/sysconfig/addmodule_adauth.inc.php delete mode 100644 modules/sysconfig/addmodule_custom.inc.php create mode 100644 modules/sysconfig/addmodule_custommodule.inc.php (limited to 'modules/sysconfig') diff --git a/modules/sysconfig/addconfig.inc.php b/modules/sysconfig/addconfig.inc.php index 1e2e870a..0f35095f 100644 --- a/modules/sysconfig/addconfig.inc.php +++ b/modules/sysconfig/addconfig.inc.php @@ -108,7 +108,7 @@ class AddConfig_Start extends AddConfig_Base protected function renderInternal() { - $mods = Page_SysConfig::getModuleTypes(); + $mods = ConfigModules::getList(); $res = Database::simpleQuery("SELECT moduleid, title, moduletype, filepath FROM configtgz_module" . " ORDER BY title ASC"); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { diff --git a/modules/sysconfig/addmodule.inc.php b/modules/sysconfig/addmodule.inc.php index 1191570d..7fa5b5b9 100644 --- a/modules/sysconfig/addmodule.inc.php +++ b/modules/sysconfig/addmodule.inc.php @@ -109,7 +109,7 @@ class AddModule_Start extends AddModule_Base protected function renderInternal() { $title = $order = array(); - $mods = Page_SysConfig::getModuleTypes(); + $mods = ConfigModules::getList(); foreach ($mods as $module) { $title[] = $module['title']; $order[] = $module['sortOrder']; diff --git a/modules/sysconfig/addmodule_ad.inc.php b/modules/sysconfig/addmodule_ad.inc.php deleted file mode 100644 index d43c9129..00000000 --- a/modules/sysconfig/addmodule_ad.inc.php +++ /dev/null @@ -1,142 +0,0 @@ - 'AdModule_CheckConnection', - 'title' => Request::post('title'), - 'server' => Request::post('server'), - 'searchbase' => Request::post('searchbase'), - 'binddn' => Request::post('binddn'), - 'bindpw' => Request::post('bindpw'), - 'home' => Request::post('home') - )); - } - -} - -class AdModule_CheckConnection extends AddModule_Base -{ - - private $taskIds; - private $originalBindDn; - - protected function preprocessInternal() - { - $server = Request::post('server'); - $searchbase = Request::post('searchbase', ''); - $binddn = Request::post('binddn'); - $bindpw = Request::post('bindpw'); - if (empty($server) || empty($binddn)) { - Message::addError('empty-field'); - AddModule_Base::setStep('AdModule_Start'); // Continues with AdModule_Start for render() - return; - } - $parent = null; - $this->originalBindDn = ''; - if (preg_match('#^\w+[/\\\\](\w+)$#', $binddn, $out)) { - $user = $out[1]; - $this->originalBindDn = str_replace('/', '\\', $binddn); - $selfSearch = Taskmanager::submit('LdapSearch', array( - 'server' => $server, - 'searchbase' => $searchbase, - 'binddn' => $this->originalBindDn, - 'bindpw' => $bindpw, - 'username' => $user - )); - if (!isset($selfSearch['id'])) { - AddModule_Base::setStep('AdModule_Start'); // Continues with AdModule_Start for render() - return; - } - $parent = $selfSearch['id']; - } - $ldapSearch = Taskmanager::submit('LdapSearch', array( - 'parentTask' => $parent, - 'server' => $server, - 'searchbase' => $searchbase, - 'binddn' => $binddn, - 'bindpw' => $bindpw - )); - if (!isset($ldapSearch['id'])) { - AddModule_Base::setStep('AdModule_Start'); // Continues with AdModule_Start for render() - return; - } - $this->taskIds = array( - 'tm-search' => $ldapSearch['id'] - ); - if (isset($selfSearch['id'])) - $this->taskIds['self-search'] = $selfSearch['id']; - } - - protected function renderInternal() - { - Render::addDialog(Dictionary::translate('lang_adAuthentication'), false, 'sysconfig/ad-checkconnection', array_merge($this->taskIds, array( - 'title' => Request::post('title'), - 'server' => Request::post('server'), - 'searchbase' => Request::post('searchbase'), - 'binddn' => Request::post('binddn'), - 'bindpw' => Request::post('bindpw'), - 'home' => Request::post('home'), - 'originalbinddn' => $this->originalBindDn, - 'step' => 'AdModule_Finish' - )) - ); - } - -} - -class AdModule_Finish extends AddModule_Base -{ - - private $taskIds; - - protected function preprocessInternal() - { - $binddn = Request::post('binddn'); - $searchbase = Request::post('searchbase'); - if (empty($searchbase)) { - $originalBindDn = str_replace('\\', '/', trim(Request::post('originalbinddn'))); - if (!preg_match('#^([^/]+)/[^/]+$#', $originalBindDn, $out)) { - Message::addError('value-invalid', 'binddn', $originalBindDn); - Util::redirect('?do=SysConfig&action=addmodule&step=AdModule_Start'); - } - $i = mb_stripos($binddn, '=' . $out[1] . ','); - if ($i === false) { - Message::addError('value-invalid', 'binddn', $out[1]); - Util::redirect('?do=SysConfig&action=addmodule&step=AdModule_Start'); - } - $searchbase = mb_substr($binddn, $i + 1); - } - $title = Request::post('title'); - if (empty($title)) - $title = 'AD: ' . Request::post('server'); - $config = ConfigModule::insertAdConfig($title, Request::post('server'), $searchbase, $binddn, Request::post('bindpw', ''), Request::post('home', '')); - $config['proxyip'] = Property::getServerIp(); - $tgz = Taskmanager::submit('CreateAdConfig', $config); - if (!isset($tgz['id'])) { - AddModule_Base::setStep('AdModule_Start'); // Continues with AdModule_Start for render() - return; - } - $this->taskIds = array( - 'tm-config' => $tgz['id'], - ); - } - - protected function renderInternal() - { - Render::addDialog(Dictionary::translate('lang_adAuthentication'), false, 'sysconfig/ad-finish', $this->taskIds); - } - -} diff --git a/modules/sysconfig/addmodule_adauth.inc.php b/modules/sysconfig/addmodule_adauth.inc.php new file mode 100644 index 00000000..4873d505 --- /dev/null +++ b/modules/sysconfig/addmodule_adauth.inc.php @@ -0,0 +1,145 @@ + 'AdAuth_CheckConnection', + 'title' => Request::post('title'), + 'server' => Request::post('server'), + 'searchbase' => Request::post('searchbase'), + 'binddn' => Request::post('binddn'), + 'bindpw' => Request::post('bindpw'), + 'home' => Request::post('home') + )); + } + +} + +class AdAuth_CheckConnection extends AddModule_Base +{ + + private $taskIds; + private $originalBindDn; + + protected function preprocessInternal() + { + $server = Request::post('server'); + $searchbase = Request::post('searchbase', ''); + $binddn = Request::post('binddn'); + $bindpw = Request::post('bindpw'); + if (empty($server) || empty($binddn)) { + Message::addError('empty-field'); + AddModule_Base::setStep('AdAuth_Start'); // Continues with AdAuth_Start for render() + return; + } + $parent = null; + $this->originalBindDn = ''; + if (preg_match('#^\w+[/\\\\](\w+)$#', $binddn, $out)) { + $user = $out[1]; + $this->originalBindDn = str_replace('/', '\\', $binddn); + $selfSearch = Taskmanager::submit('LdapSearch', array( + 'server' => $server, + 'searchbase' => $searchbase, + 'binddn' => $this->originalBindDn, + 'bindpw' => $bindpw, + 'username' => $user + )); + if (!isset($selfSearch['id'])) { + AddModule_Base::setStep('AdAuth_Start'); // Continues with AdAuth_Start for render() + return; + } + $parent = $selfSearch['id']; + } + $ldapSearch = Taskmanager::submit('LdapSearch', array( + 'parentTask' => $parent, + 'server' => $server, + 'searchbase' => $searchbase, + 'binddn' => $binddn, + 'bindpw' => $bindpw + )); + if (!isset($ldapSearch['id'])) { + AddModule_Base::setStep('AdAuth_Start'); // Continues with AdAuth_Start for render() + return; + } + $this->taskIds = array( + 'tm-search' => $ldapSearch['id'] + ); + if (isset($selfSearch['id'])) + $this->taskIds['self-search'] = $selfSearch['id']; + } + + protected function renderInternal() + { + Render::addDialog(Dictionary::translate('lang_adAuthentication'), false, 'sysconfig/ad-checkconnection', array_merge($this->taskIds, array( + 'title' => Request::post('title'), + 'server' => Request::post('server'), + 'searchbase' => Request::post('searchbase'), + 'binddn' => Request::post('binddn'), + 'bindpw' => Request::post('bindpw'), + 'home' => Request::post('home'), + 'originalbinddn' => $this->originalBindDn, + 'step' => 'AdAuth_Finish' + )) + ); + } + +} + +class AdAuth_Finish extends AddModule_Base +{ + + private $taskIds; + + protected function preprocessInternal() + { + $binddn = Request::post('binddn'); + $searchbase = Request::post('searchbase'); + if (empty($searchbase)) { + // If no search base was given, determine it from the dn + $originalBindDn = str_replace('\\', '/', trim(Request::post('originalbinddn'))); + if (!preg_match('#^([^/]+)/[^/]+$#', $originalBindDn, $out)) { + Message::addError('value-invalid', 'binddn', $originalBindDn); + Util::redirect('?do=SysConfig&action=addmodule&step=AdAuth_Start'); + } // $out[1] is the domain + // Find the domain in the dn + $i = mb_stripos($binddn, '=' . $out[1] . ','); + if ($i === false) { + Message::addError('value-invalid', 'binddn', $out[1]); + Util::redirect('?do=SysConfig&action=addmodule&step=AdAuth_Start'); + } + // Now find ',' before it so we get the key + $i = mb_strrpos(mb_substr($binddn, 0, $i), ','); + if ($i === false) + $i = -1; + $searchbase = mb_substr($binddn, $i + 1); + } + $title = Request::post('title'); + if (empty($title)) + $title = 'AD: ' . Request::post('server'); + $config = ConfigModule_AdAuth::insert($title, Request::post('server'), $searchbase, $binddn, Request::post('bindpw', ''), Request::post('home', '')); + $config['proxyip'] = Property::getServerIp(); + $tgz = Taskmanager::submit('CreateAdConfig', $config); + if (!isset($tgz['id'])) { + AddModule_Base::setStep('AdAuth_Start'); // Continues with AdAuth_Start for render() + return; + } + $this->taskIds = array( + 'tm-config' => $tgz['id'], + ); + } + + protected function renderInternal() + { + Render::addDialog(Dictionary::translate('lang_adAuthentication'), false, 'sysconfig/ad-finish', $this->taskIds); + } + +} diff --git a/modules/sysconfig/addmodule_branding.inc.php b/modules/sysconfig/addmodule_branding.inc.php index 9612bedb..a6c16d9d 100644 --- a/modules/sysconfig/addmodule_branding.inc.php +++ b/modules/sysconfig/addmodule_branding.inc.php @@ -4,8 +4,6 @@ * Wizard for including a branding logo. */ -Page_SysConfig::addModule('BRANDING', 'Branding_Start', Dictionary::translate('lang_institutionLogo'), Dictionary::translate('lang_institutionLogo'), 'Branding', true); - class Branding_Start extends AddModule_Base { @@ -199,7 +197,7 @@ class Branding_Finish extends AddModule_Base Message::addError('missing-file'); Util::redirect('?do=SysConfig&action=addmodule&step=Branding_Start'); } - if (!ConfigModule::insertBrandingModule($title, $tgz)) + if (!ConfigModule_Branding::insert($title, $tgz)) Util::redirect('?do=SysConfig&action=addmodule&step=Branding_Start'); Session::set('logo_tgz', false); Session::save(); diff --git a/modules/sysconfig/addmodule_custom.inc.php b/modules/sysconfig/addmodule_custom.inc.php deleted file mode 100644 index f79313e8..00000000 --- a/modules/sysconfig/addmodule_custom.inc.php +++ /dev/null @@ -1,140 +0,0 @@ - 'CustomModule_ProcessUpload' - )); - } - -} - -/** - * Some file has just been uploaded. Try to store it, then try to unpack/analyze it. - * If this succeeds, we proceed to the next step where we present the user our findings - * and ask what to do with this. - */ -class CustomModule_ProcessUpload extends AddModule_Base -{ - - private $taskId = false; - - protected function preprocessInternal() - { - if (!isset($_FILES['modulefile'])) { - Message::addError('missing-file'); - Util::redirect('?do=SysConfig'); - } - if ($_FILES['modulefile']['error'] != UPLOAD_ERR_OK) { - Message::addError('upload-failed', Util::uploadErrorString($_FILES['modulefile']['error'])); - Util::redirect('?do=SysConfig'); - } - $tempfile = '/tmp/bwlp-' . mt_rand(1, 100000) . '-' . crc32($_SERVER['REMOTE_HOST']) . '.tmp'; - if (!move_uploaded_file($_FILES['modulefile']['tmp_name'], $tempfile)) { - Message::addError('error-write', $tempfile); - Util::redirect('?do=SysConfig'); - } - $this->taskId = 'tgzmod' . mt_rand() . '-' . microtime(true); - Taskmanager::submit('ListArchive', array( - 'id' => $this->taskId, - 'file' => $tempfile - ), true); - Session::set('mod_temp', $tempfile); - } - - protected function renderInternal() - { - $status = Taskmanager::waitComplete($this->taskId); - Taskmanager::release($this->taskId); - $tempfile = Session::get('mod_temp'); - if (!isset($status['statusCode'])) { - unlink($tempfile); - $this->tmError(); - } - if ($status['statusCode'] != TASK_FINISHED) { - unlink($tempfile); - $this->taskError($status); - } - // Sort files for better display - $dirs = array(); - foreach ($status['data']['entries'] as $file) { - if ($file['isdir']) continue; - $dirs[dirname($file['name'])][] = $file; - } - ksort($dirs); - $list = array(); - foreach ($dirs as $dir => $files) { - $list[] = array( - 'name' => $dir, - 'isdir' => true - ); - sort($files); - foreach ($files as $file) { - $file['size'] = Util::readableFileSize($file['size']); - $list[] = $file; - } - } - Render::addDialog(Dictionary::translate('lang_addCustomModule'), false, 'sysconfig/custom-fileselect', array( - 'step' => 'CustomModule_CompressModule', - 'files' => $list, - )); - Session::save(); - } - -} - -class CustomModule_CompressModule extends AddModule_Base -{ - - private $taskId = false; - - protected function preprocessInternal() - { - $title = Request::post('title'); - $tempfile = Session::get('mod_temp'); - if (empty($title) || empty($tempfile) || !file_exists($tempfile)) { - Message::addError('empty-field'); - return; - } - // Recompress using task manager - $this->taskId = 'tgzmod' . mt_rand() . '-' . microtime(true); - $destFile = CONFIG_TGZ_LIST_DIR . '/modules/mod-' . Util::sanitizeFilename($title) . '-' . microtime(true) . '.tgz'; - Taskmanager::submit('RecompressArchive', array( - 'id' => $this->taskId, - 'inputFiles' => array($tempfile), - 'outputFile' => $destFile - ), true); - $status = Taskmanager::waitComplete($this->taskId); - unlink($tempfile); - if (!isset($status['statusCode'])) { - $this->tmError(); - } - if ($status['statusCode'] != TASK_FINISHED) { - $this->taskError($status); - } - // Seems ok, create entry in DB - $ret = Database::exec("INSERT INTO configtgz_module (title, moduletype, filepath, contents) VALUES (:title, 'custom', :file, '')", - array('title' => $title, 'file' => $destFile)); - if ($ret === false) { - unlink($destFile); - Util::traceError("Could not insert module into Database"); - } - Message::addSuccess('module-added'); - Util::redirect('?do=SysConfig'); - } - -} diff --git a/modules/sysconfig/addmodule_custommodule.inc.php b/modules/sysconfig/addmodule_custommodule.inc.php new file mode 100644 index 00000000..66ba33a5 --- /dev/null +++ b/modules/sysconfig/addmodule_custommodule.inc.php @@ -0,0 +1,136 @@ + 'CustomModule_ProcessUpload' + )); + } + +} + +/** + * Some file has just been uploaded. Try to store it, then try to unpack/analyze it. + * If this succeeds, we proceed to the next step where we present the user our findings + * and ask what to do with this. + */ +class CustomModule_ProcessUpload extends AddModule_Base +{ + + private $taskId = false; + + protected function preprocessInternal() + { + if (!isset($_FILES['modulefile'])) { + Message::addError('missing-file'); + Util::redirect('?do=SysConfig'); + } + if ($_FILES['modulefile']['error'] != UPLOAD_ERR_OK) { + Message::addError('upload-failed', Util::uploadErrorString($_FILES['modulefile']['error'])); + Util::redirect('?do=SysConfig'); + } + $tempfile = '/tmp/bwlp-' . mt_rand(1, 100000) . '-' . crc32($_SERVER['REMOTE_HOST']) . '.tmp'; + if (!move_uploaded_file($_FILES['modulefile']['tmp_name'], $tempfile)) { + Message::addError('error-write', $tempfile); + Util::redirect('?do=SysConfig'); + } + $this->taskId = 'tgzmod' . mt_rand() . '-' . microtime(true); + Taskmanager::submit('ListArchive', array( + 'id' => $this->taskId, + 'file' => $tempfile + ), true); + Session::set('mod_temp', $tempfile); + } + + protected function renderInternal() + { + $status = Taskmanager::waitComplete($this->taskId); + Taskmanager::release($this->taskId); + $tempfile = Session::get('mod_temp'); + if (!isset($status['statusCode'])) { + unlink($tempfile); + $this->tmError(); + } + if ($status['statusCode'] != TASK_FINISHED) { + unlink($tempfile); + $this->taskError($status); + } + // Sort files for better display + $dirs = array(); + foreach ($status['data']['entries'] as $file) { + if ($file['isdir']) continue; + $dirs[dirname($file['name'])][] = $file; + } + ksort($dirs); + $list = array(); + foreach ($dirs as $dir => $files) { + $list[] = array( + 'name' => $dir, + 'isdir' => true + ); + sort($files); + foreach ($files as $file) { + $file['size'] = Util::readableFileSize($file['size']); + $list[] = $file; + } + } + Render::addDialog(Dictionary::translate('lang_addCustomModule'), false, 'sysconfig/custom-fileselect', array( + 'step' => 'CustomModule_CompressModule', + 'files' => $list, + )); + Session::save(); + } + +} + +class CustomModule_CompressModule extends AddModule_Base +{ + + private $taskId = false; + + protected function preprocessInternal() + { + $title = Request::post('title'); + $tempfile = Session::get('mod_temp'); + if (empty($title) || empty($tempfile) || !file_exists($tempfile)) { + Message::addError('empty-field'); + return; + } + // Recompress using task manager + $this->taskId = 'tgzmod' . mt_rand() . '-' . microtime(true); + $destFile = CONFIG_TGZ_LIST_DIR . '/modules/mod-' . Util::sanitizeFilename($title) . '-' . microtime(true) . '.tgz'; + Taskmanager::submit('RecompressArchive', array( + 'id' => $this->taskId, + 'inputFiles' => array($tempfile), + 'outputFile' => $destFile + ), true); + $status = Taskmanager::waitComplete($this->taskId); + unlink($tempfile); + if (!isset($status['statusCode'])) { + $this->tmError(); + } + if ($status['statusCode'] != TASK_FINISHED) { + $this->taskError($status); + } + // Seems ok, create entry in DB + $ret = Database::exec("INSERT INTO configtgz_module (title, moduletype, filepath, contents) VALUES (:title, 'custom', :file, '')", + array('title' => $title, 'file' => $destFile)); + if ($ret === false) { + unlink($destFile); + Util::traceError("Could not insert module into Database"); + } + Message::addSuccess('module-added'); + Util::redirect('?do=SysConfig'); + } + +} -- cgit v1.2.3-55-g7522