summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorSimon Rettberg2015-01-26 20:28:49 +0100
committerSimon Rettberg2015-01-26 20:28:49 +0100
commit5347ecd5ddb1803ec1c43240bafc84f5c427f855 (patch)
tree7a852cdaa44599dab5f4c98b9daa7c6443d81024 /modules
parentFix stupid bug in update query, check DB version before handling callbacks (diff)
downloadslx-admin-5347ecd5ddb1803ec1c43240bafc84f5c427f855.tar.gz
slx-admin-5347ecd5ddb1803ec1c43240bafc84f5c427f855.tar.xz
slx-admin-5347ecd5ddb1803ec1c43240bafc84f5c427f855.zip
Add configtgz class. Fix dozens of bugs
Diffstat (limited to 'modules')
-rw-r--r--modules/sysconfig.inc.php83
-rw-r--r--modules/sysconfig/addconfig.inc.php52
-rw-r--r--modules/sysconfig/addmodule_adauth.inc.php6
-rw-r--r--modules/sysconfig/addmodule_branding.inc.php6
-rw-r--r--modules/sysconfig/addmodule_custommodule.inc.php4
5 files changed, 93 insertions, 58 deletions
diff --git a/modules/sysconfig.inc.php b/modules/sysconfig.inc.php
index 0da58767..94e2455a 100644
--- a/modules/sysconfig.inc.php
+++ b/modules/sysconfig.inc.php
@@ -25,6 +25,12 @@ class Page_SysConfig extends Page
if (Request::post('del', 'no') !== 'no') {
$this->delModule();
}
+ if (Request::post('download', 'no') !== 'no') {
+ $this->downloadModule();
+ }
+ if (Request::post('rebuild', 'no') !== 'no') {
+ $this->rebuildModule();
+ }
}
// Action: "addconfig" (compose config from one or more modules)
@@ -42,6 +48,10 @@ class Page_SysConfig extends Page
if (Request::post('activate', 'no') !== 'no') {
$this->activateConfig();
}
+ // Action "rebuild" (rebuild config.tgz from its modules)
+ if (Request::post('rebuild', 'no') !== 'no') {
+ $this->rebuildConfig();
+ }
}
}
@@ -88,7 +98,7 @@ class Page_SysConfig extends Page
private function listConfigs()
{
// Configs
- $res = Database::simpleQuery("SELECT configtgz.configid, configtgz.title, configtgz.filepath, GROUP_CONCAT(configtgz_x_module.moduleid) AS modlist"
+ $res = Database::simpleQuery("SELECT configtgz.configid, configtgz.title, configtgz.filepath, configtgz.status, GROUP_CONCAT(configtgz_x_module.moduleid) AS modlist"
. " FROM configtgz"
. " INNER JOIN configtgz_x_module USING (configid)"
. " GROUP BY configid"
@@ -99,22 +109,31 @@ class Page_SysConfig extends Page
'configid' => $row['configid'],
'config' => $row['title'],
'modlist' => $row['modlist'],
- 'current' => readlink(CONFIG_HTTP_DIR . '/default/config.tgz') === $row['filepath']
+ 'current' => readlink(CONFIG_HTTP_DIR . '/default/config.tgz') === $row['filepath'],
+ 'needrebuild' => ($row['status'] !== 'OK')
);
}
// Config modules
- $res = Database::simpleQuery("SELECT moduleid, title FROM configtgz_module ORDER BY title ASC");
+ $res = Database::simpleQuery("SELECT moduleid, title, moduletype, status FROM configtgz_module ORDER BY title ASC");
$modules = array();
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$modules[] = array(
'moduleid' => $row['moduleid'],
- 'module' => $row['title']
+ 'moduletype' => $row['moduletype'],
+ 'module' => $row['title'],
+ 'iscustom' => ($row['moduletype'] === 'CustomModule' || $row['moduletype'] === 'Branding'),
+ 'needrebuild' => ($row['status'] !== 'OK')
);
}
Render::addTemplate('sysconfig/_page', array(
'configs' => $configs,
'modules' => $modules
));
+ Render::addScriptTop('custom');
+ Render::addFooter('<script> $(window).load(function (e) {
+ forceTable($("#modtable"));
+ forceTable($("#conftable"));
+ }); // </script>');
}
private function listModuleContents($moduleid)
@@ -216,6 +235,25 @@ class Page_SysConfig extends Page
Util::redirect('?do=SysConfig');
}
+ private function rebuildConfig()
+ {
+ $configid = Request::post('rebuild', 'MISSING');
+ $config = ConfigTgz::get($configid);
+ if ($config === false) {
+ Message::addError('config-invalid', $configid);
+ Util::redirect('?do=SysConfig');
+ }
+ //$ret = $config->generate(false, 350); // TODO
+ $ret = $config->generate(false, 350) === 'OK'; // TODO
+ if ($ret === true)
+ Message::addSuccess('module-rebuilt', $config->title());
+ elseif ($ret === false)
+ Message::addError('module-rebuild-failed', $config->title());
+ else
+ Message::addInfo('module-rebuilding', $config->title());
+ Util::redirect('?do=SysConfig');
+ }
+
private function delModule()
{
$moduleid = Request::post('del', 'MISSING');
@@ -246,15 +284,46 @@ class Page_SysConfig extends Page
Util::redirect('?do=SysConfig');
}
+ private function downloadModule()
+ {
+ $moduleid = Request::post('download', 'MISSING');
+ $row = Database::queryFirst("SELECT title, filepath FROM configtgz_module WHERE moduleid = :moduleid LIMIT 1", array('moduleid' => $moduleid));
+ if ($row === false) {
+ Message::addError('config-invalid', $moduleid);
+ Util::redirect('?do=SysConfig');
+ }
+ if (!Util::sendFile($row['filepath'], $row['title'] . '.tgz'))
+ Util::redirect('?do=SysConfig');
+ exit(0);
+ }
+
+ private function rebuildModule()
+ {
+ $moduleid = Request::post('rebuild', 'MISSING');
+ $module = ConfigModule::get($moduleid);
+ if ($module === false) {
+ Message::addError('config-invalid', $moduleid);
+ Util::redirect('?do=SysConfig');
+ }
+ $ret = $module->generate(false, 250);
+ if ($ret === true)
+ Message::addSuccess('module-rebuilt', $module->title());
+ elseif ($ret === false)
+ Message::addError('module-rebuild-failed', $module->title());
+ else
+ Message::addInfo('module-rebuilding', $module->title());
+ Util::redirect('?do=SysConfig');
+ }
+
private function delConfig()
{
$configid = Request::post('del', 'MISSING');
- $module = ConfigModule::get($configid);
- if ($module === false) {
+ $config = ConfigTgz::get($configid);
+ if ($config === false) {
Message::addError('config-invalid', $configid);
Util::redirect('?do=SysConfig');
}
- $module->delete();
+ $config->delete();
Util::redirect('?do=SysConfig');
}
diff --git a/modules/sysconfig/addconfig.inc.php b/modules/sysconfig/addconfig.inc.php
index 4949539e..55194069 100644
--- a/modules/sysconfig/addconfig.inc.php
+++ b/modules/sysconfig/addconfig.inc.php
@@ -138,65 +138,31 @@ class AddConfig_Start extends AddConfig_Base
*/
class AddConfig_Finish extends AddConfig_Base
{
- private $task = false;
- private $destFile = false;
- private $title = false;
- private $moduleids = array();
+ private $config = false;
protected function preprocessInternal()
{
$modules = Request::post('module');
- $this->title = Request::post('title');
+ $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');
+ if (empty($title)) {
+ Message::addError('missing-title');
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'];
+ $this->config = ConfigTgz::insert($title, $modules);
+ if ($this->config === false || $this->config->generate() !== 'OK') {
+ Message::addError('unsuccessful-action');
+ Util::redirect('?do=SysConfig&action=addconfig');
}
- // 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['statusCode'] === TASK_PROCESSING)) {
- $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(Dictionary::translate('lang_configurationCompilation'), false, 'sysconfig/cfg-finish', array(
- 'configid' => $confid
+ 'configid' => $this->config->id()
));
}
diff --git a/modules/sysconfig/addmodule_adauth.inc.php b/modules/sysconfig/addmodule_adauth.inc.php
index baa705b2..2418916e 100644
--- a/modules/sysconfig/addmodule_adauth.inc.php
+++ b/modules/sysconfig/addmodule_adauth.inc.php
@@ -11,7 +11,7 @@ class AdAuth_Start extends AddModule_Base
{
Session::set('ad_check', false);
Session::save();
- Render::addDialog(Dictionary::translate('lang_adAuthentication'), false, 'sysconfig/ad-start', array(
+ Render::addDialog(Dictionary::translate('config-module', 'adAuth_title'), false, 'sysconfig/ad-start', array(
'step' => 'AdAuth_CheckConnection',
'title' => Request::post('title'),
'server' => Request::post('server'),
@@ -79,7 +79,7 @@ class AdAuth_CheckConnection extends AddModule_Base
protected function renderInternal()
{
- Render::addDialog(Dictionary::translate('lang_adAuthentication'), false, 'sysconfig/ad-checkconnection', array_merge($this->taskIds, array(
+ Render::addDialog(Dictionary::translate('config-module', 'adAuth_title'), false, 'sysconfig/ad-checkconnection', array_merge($this->taskIds, array(
'title' => Request::post('title'),
'server' => Request::post('server'),
'searchbase' => Request::post('searchbase'),
@@ -148,7 +148,7 @@ class AdAuth_Finish extends AddModule_Base
protected function renderInternal()
{
- Render::addDialog(Dictionary::translate('lang_adAuthentication'), false, 'sysconfig/ad-finish', $this->taskIds);
+ Render::addDialog(Dictionary::translate('config-module', 'adAuth_title'), false, 'sysconfig/ad-finish', $this->taskIds);
}
}
diff --git a/modules/sysconfig/addmodule_branding.inc.php b/modules/sysconfig/addmodule_branding.inc.php
index 8bcc10a1..7b7dace9 100644
--- a/modules/sysconfig/addmodule_branding.inc.php
+++ b/modules/sysconfig/addmodule_branding.inc.php
@@ -9,7 +9,7 @@ class Branding_Start extends AddModule_Base
protected function renderInternal()
{
- Render::addDialog(Dictionary::translate('lang_specificLogo'), false, 'sysconfig/branding-start', array(
+ Render::addDialog(Dictionary::translate('config-module', 'branding_title'), false, 'sysconfig/branding-start', array(
'step' => 'Branding_ProcessFile',
));
}
@@ -74,7 +74,7 @@ class Branding_ProcessFile extends AddModule_Base
$png = base64_encode(file_get_contents($this->task['data']['pngFile']));
if (filesize($this->svgFile) < 1000000)
$svg = base64_encode(file_get_contents($this->svgFile));
- Render::addDialog(Dictionary::translate('lang_specificLogo'), false, 'sysconfig/branding-check', array(
+ Render::addDialog(Dictionary::translate('config-module', 'branding_title'), false, 'sysconfig/branding-check', array(
'png' => $png,
'svg' => $svg,
'error' => $this->task['data']['error'],
@@ -114,7 +114,7 @@ class Branding_ProcessFile extends AddModule_Base
// [wikipedia] Try to be nice and detect links that might give a hint where the svg can be found
if (preg_match_all('#href="([^"]*upload.wikimedia.org/[^"]*/[^"]*/[^"]*\.svg|[^"]+/[^"]+:[^"]+\.svg[^"]*)"#', $content, $out, PREG_PATTERN_ORDER)) {
if ($title === false && preg_match('#<title>([^<]*)</title>#i', $content, $tout))
- $title = trim($tout[1]);
+ $title = trim(preg_replace('/\W*Wikipedia.*/', '', $tout[1]));
foreach ($out[1] as $res) {
if (strpos($res, 'action=edit') !== false)
continue;
diff --git a/modules/sysconfig/addmodule_custommodule.inc.php b/modules/sysconfig/addmodule_custommodule.inc.php
index c42453db..1be9c10f 100644
--- a/modules/sysconfig/addmodule_custommodule.inc.php
+++ b/modules/sysconfig/addmodule_custommodule.inc.php
@@ -12,7 +12,7 @@ class CustomModule_Start extends AddModule_Base
protected function renderInternal()
{
Session::set('mod_temp', false);
- Render::addDialog(Dictionary::translate('lang_addCustomModule'), false, 'sysconfig/custom-upload', array(
+ Render::addDialog(Dictionary::translate('config-module', 'custom_title'), false, 'sysconfig/custom-upload', array(
'step' => 'CustomModule_ProcessUpload'
));
}
@@ -84,7 +84,7 @@ class CustomModule_ProcessUpload extends AddModule_Base
$list[] = $file;
}
}
- Render::addDialog(Dictionary::translate('lang_addCustomModule'), false, 'sysconfig/custom-fileselect', array(
+ Render::addDialog(Dictionary::translate('config-module', 'custom_title'), false, 'sysconfig/custom-fileselect', array(
'step' => 'CustomModule_CompressModule',
'files' => $list,
));