summaryrefslogtreecommitdiffstats
path: root/modules/sysconfig
diff options
context:
space:
mode:
authorSimon Rettberg2014-05-23 20:49:02 +0200
committerSimon Rettberg2014-05-23 20:49:02 +0200
commitfe6ac16498b05d0f0c8ed7fda394273815d3d6da (patch)
treecadf5f103ef3db7ba1b40d59d85937c998aad22f /modules/sysconfig
parentServer Setup page (diff)
downloadslx-admin-fe6ac16498b05d0f0c8ed7fda394273815d3d6da.tar.gz
slx-admin-fe6ac16498b05d0f0c8ed7fda394273815d3d6da.tar.xz
slx-admin-fe6ac16498b05d0f0c8ed7fda394273815d3d6da.zip
Stuff (WIP)
Diffstat (limited to 'modules/sysconfig')
-rw-r--r--modules/sysconfig/addconfig.inc.php220
-rw-r--r--modules/sysconfig/addmodule_ad.inc.php27
-rw-r--r--modules/sysconfig/addmodule_custom.inc.php12
3 files changed, 237 insertions, 22 deletions
diff --git a/modules/sysconfig/addconfig.inc.php b/modules/sysconfig/addconfig.inc.php
new file mode 100644
index 00000000..6f076a12
--- /dev/null
+++ b/modules/sysconfig/addconfig.inc.php
@@ -0,0 +1,220 @@
+<?php
+
+/**
+ * Addconfig subpage base - makes sure
+ * we have the two required methods preprocess and render
+ */
+abstract class AddConfig_Base
+{
+
+ /**
+ *
+ * @var array Known module types
+ */
+ protected static $types = array(
+ 'AD_AUTH' => array(
+ 'unique' => true,
+ 'group' => 'Authentifizierung'
+ ),
+ 'custom' => array(
+ 'unique' => false,
+ 'group' => 'Generisch'
+ )
+ );
+
+ /**
+ * Holds the instance for the currently executing step
+ * @var \AddConfig_Base
+ */
+ private static $instance = false;
+
+ /**
+ *
+ * @param type $step
+ * @return \AddConfig_Base
+ */
+ public static function setStep($step)
+ {
+ if (empty($step) || !class_exists($step) || get_parent_class($step) !== 'AddConfig_Base') {
+ Message::addError('invalid-action', $step);
+ Util::redirect('?do=SysConfig');
+ }
+ self::$instance = new $step();
+ }
+
+ protected function tmError()
+ {
+ Message::addError('taskmanager-error');
+ Util::redirect('?do=SysConfig');
+ }
+
+ protected function taskError($status)
+ {
+ if (isset($status['data']['error'])) {
+ $error = $status['data']['error'];
+ } elseif (isset($status['statusCode'])) {
+ $error = $status['statusCode'];
+ } else {
+ $error = 'Unbekannter Taskmanager-Fehler'; // TODO: No text
+ }
+ Message::addError('task-error', $error);
+ Util::redirect('?do=SysConfig');
+ }
+
+ /**
+ * Called before any HTML rendering happens, so you can
+ * pepare stuff, validate input, and optionally redirect
+ * early if something is wrong, or you received post
+ * data etc.
+ */
+ protected function preprocessInternal()
+ {
+ // void
+ }
+
+ /**
+ * Do page rendering.
+ */
+ protected function renderInternal()
+ {
+ // void
+ }
+
+ /**
+ * Handle ajax stuff
+ */
+ protected function ajaxInternal()
+ {
+ // void
+ }
+
+ public static function preprocess()
+ {
+ if (self::$instance === false) {
+ Util::traceError('No step instance yet');
+ }
+ self::$instance->preprocessInternal();
+ }
+
+ public static function render()
+ {
+ if (self::$instance === false) {
+ Util::traceError('No step instance yet');
+ }
+ self::$instance->renderInternal();
+ }
+
+ public static function ajax()
+ {
+ if (self::$instance === false) {
+ Util::traceError('No step instance yet');
+ }
+ self::$instance->ajaxInternal();
+ }
+
+}
+
+/**
+ * Start dialog for adding config. Ask for title,
+ * show selection of modules.
+ */
+class AddConfig_Start extends AddConfig_Base
+{
+
+ protected function renderInternal()
+ {
+ $res = Database::simpleQuery("SELECT moduleid, title, moduletype, filepath FROM configtgz_module"
+ . " ORDER BY title ASC");
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ if (!isset(self::$types[$row['moduletype']])) {
+ self::$types[$row['moduletype']] = array(
+ 'unique' => false,
+ 'group' => 'Undefined moduletype in addconfig.inc.php'
+ );
+ }
+ if (!isset(self::$types[$row['moduletype']]['modules'])) {
+ self::$types[$row['moduletype']]['modules'] = array();
+ self::$types[$row['moduletype']]['groupid'] = $row['moduletype'];
+ }
+ if (empty($row['filepath']) || !file_exists($row['filepath'])) $row['missing'] = true;
+ self::$types[$row['moduletype']]['modules'][] = $row;
+ }
+ Render::addDialog('Konfiguration zusammenstellen', false, 'sysconfig/cfg-start', array(
+ 'token' => Session::get('token'),
+ 'step' => 'AddConfig_Finish',
+ 'groups' => array_values(self::$types)
+ ));
+ }
+
+}
+
+/**
+ * Start dialog for adding config. Ask for title,
+ * show selection of modules.
+ */
+class AddConfig_Finish extends AddConfig_Base
+{
+ private $task = false;
+ private $destFile = false;
+ private $title = false;
+ private $moduleids = array();
+
+ protected function preprocessInternal()
+ {
+ $modules = Request::post('module');
+ $this->title = Request::post('title');
+ if (!is_array($modules)) {
+ Message::addError('missing-file');
+ Util::redirect('?do=SysConfig&action=addconfig');
+ }
+ if (empty($this->title)) {
+ Message::addError('empty-field');
+ Util::redirect('?do=SysConfig&action=addconfig');
+ }
+ // Get all input modules
+ $moduleids = '0'; // Passed directly in query. Make sure no SQL injection is possible
+ foreach ($modules as $module) {
+ $moduleids .= ',' . (int)$module; // Casting to int should make it safe
+ }
+ $res = Database::simpleQuery("SELECT moduleid, filepath FROM configtgz_module WHERE moduleid IN ($moduleids)");
+ $files = array();
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $files[] = $row['filepath'];
+ $this->moduleids[] = $row['moduleid'];
+ }
+ // Create output file name (config.tgz)
+ do {
+ $this->destFile = CONFIG_TGZ_LIST_DIR . '/config-' . Util::sanitizeFilename($this->title) . '-' . mt_rand() . '.tgz';
+ } while (file_exists($this->destFile));
+ // Hand over to tm
+ $this->task = Taskmanager::submit('RecompressArchive', array(
+ 'inputFiles' => $files,
+ 'outputFile' => $this->destFile
+ ));
+ }
+
+ protected function renderInternal()
+ {
+ if (isset($this->task['statusCode']) && $this->task['statusCode'] === TASK_WAITING) {
+ $this->task = Taskmanager::waitComplete($this->task['id']);
+ }
+ if ($this->task === false) $this->tmError();
+ if (!isset($this->task['statusCode']) || $this->task['statusCode'] !== TASK_FINISHED) $this->taskError($this->task);
+ Database::exec("INSERT INTO configtgz (title, filepath) VALUES (:title, :filepath)", array(
+ 'title' => $this->title,
+ 'filepath' => $this->destFile
+ ));
+ $confid = Database::lastInsertId();
+ foreach ($this->moduleids as $moduleid) {
+ Database::exec("INSERT INTO configtgz_x_module (configid, moduleid) VALUES (:configid, :moduleid)", array(
+ 'configid' => $confid,
+ 'moduleid' => $moduleid
+ ));
+ }
+ Render::addDialog('Konfiguration zusammenstellen', false, 'sysconfig/cfg-finish', array(
+ 'token' => Session::get('token'),
+ 'configid' => $confid
+ ));
+ }
+
+}
diff --git a/modules/sysconfig/addmodule_ad.inc.php b/modules/sysconfig/addmodule_ad.inc.php
index ab897096..ac820bbc 100644
--- a/modules/sysconfig/addmodule_ad.inc.php
+++ b/modules/sysconfig/addmodule_ad.inc.php
@@ -86,23 +86,14 @@ class AdModule_Finish extends AddModule_Base
protected function preprocessInternal()
{
- $data = json_encode(array(
- 'server' => Request::post('server'),
- 'searchbase' => Request::post('searchbase'),
- 'binddn' => Request::post('binddn'),
- 'bindpw' => Request::post('bindpw'),
- ));
- Database::exec("INSERT INTO configtgz_module (title, moduletype, filename, contents) "
- . " VALUES (:title, 'AD_AUTH', '', :content)", array(
- 'title' => 'AD: ' . Request::post('server'),
- 'content' => $data));
- $id = Database::lastInsertId();
- $name = CONFIG_TGZ_LIST_DIR . '/modules/AD_AUTH_id_' . $id . '.' . mt_rand() . '.tgz';
- Database::exec("UPDATE configtgz_module SET filename = :filename WHERE moduleid = :id LIMIT 1", array(
- 'id' => $id,
- 'filename' => $name
- ));
- $tgz = Taskmanager::submit('DummyTask', array());
+ $config = ConfigModule::insertAdConfig('AD: ' . Request::post('server'),
+ Request::post('server'),
+ Request::post('searchbase'),
+ Request::post('binddn'),
+ Request::post('bindpw')
+ );
+ $config['proxyip'] = Property::getServerIp();
+ $tgz = Taskmanager::submit('CreateAdConfig', $config);
if (isset($tgz['id'])) {
$ldadp = Taskmanager::submit('DummyTask', array('parentTask' => $tgz['id']));
}
@@ -111,7 +102,7 @@ class AdModule_Finish extends AddModule_Base
return;
}
$this->taskIds = array(
- 'tm-module' => $tgz['id'],
+ 'tm-config' => $tgz['id'],
'tm-ldadp' => $ldadp['id']
);
}
diff --git a/modules/sysconfig/addmodule_custom.inc.php b/modules/sysconfig/addmodule_custom.inc.php
index ec2c8af7..070c1fd4 100644
--- a/modules/sysconfig/addmodule_custom.inc.php
+++ b/modules/sysconfig/addmodule_custom.inc.php
@@ -20,7 +20,10 @@ class CustomModule_UploadForm extends AddModule_Base
protected function renderInternal()
{
Session::set('mod_temp', false);
- Render::addDialog('Eigenes Modul hinzufügen', false, 'sysconfig/custom-upload', array('step' => 'CustomModule_ProcessUpload'));
+ Render::addDialog('Eigenes Modul hinzufügen', false, 'sysconfig/custom-upload', array(
+ 'token' => Session::get('token'),
+ 'step' => 'CustomModule_ProcessUpload'
+ ));
}
}
@@ -42,7 +45,7 @@ class CustomModule_ProcessUpload extends AddModule_Base
Util::redirect('?do=SysConfig');
}
if ($_FILES['modulefile']['error'] != UPLOAD_ERR_OK) {
- Message::addError('upload-failed', $_FILES['modulefile']['name']);
+ Message::addError('upload-failed', Util::uploadErrorString($_FILES['modulefile']['error']));
Util::redirect('?do=SysConfig');
}
$tempfile = $_FILES['modulefile']['tmp_name'] . '.tmp';
@@ -91,6 +94,7 @@ class CustomModule_ProcessUpload extends AddModule_Base
}
}
Render::addDialog('Eigenes Modul hinzufügen', false, 'sysconfig/custom-fileselect', array(
+ 'token' => Session::get('token'),
'step' => 'CustomModule_CompressModule',
'files' => $list,
));
@@ -114,7 +118,7 @@ class CustomModule_CompressModule extends AddModule_Base
}
// Recompress using task manager
$this->taskId = 'tgzmod' . mt_rand() . '-' . microtime(true);
- $destFile = CONFIG_TGZ_LIST_DIR . '/modules/mod-' . preg_replace('/[^a-z0-9_\-]+/is', '_', $title) . '-' . microtime(true) . '.tgz';
+ $destFile = CONFIG_TGZ_LIST_DIR . '/modules/mod-' . Util::sanitizeFilename($title) . '-' . microtime(true) . '.tgz';
Taskmanager::submit('RecompressArchive', array(
'id' => $this->taskId,
'inputFiles' => array($tempfile),
@@ -129,7 +133,7 @@ class CustomModule_CompressModule extends AddModule_Base
$this->taskError($status);
}
// Seems ok, create entry in DB
- $ret = Database::exec("INSERT INTO configtgz_module (title, moduletype, filename, contents) VALUES (:title, 'custom', :file, '')",
+ $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);