diff options
author | Simon Rettberg | 2014-05-19 15:30:59 +0200 |
---|---|---|
committer | Simon Rettberg | 2014-05-19 15:30:59 +0200 |
commit | f6ceaa03052e6878afd53a4bbb7f4429849fe25a (patch) | |
tree | 9f5582c8c275494728f6d6dcf656479714688934 /modules/sysconfig.inc.php | |
parent | Working on config.tgz composition through config modules (diff) | |
download | slx-admin-f6ceaa03052e6878afd53a4bbb7f4429849fe25a.tar.gz slx-admin-f6ceaa03052e6878afd53a4bbb7f4429849fe25a.tar.xz slx-admin-f6ceaa03052e6878afd53a4bbb7f4429849fe25a.zip |
OO style modules
Diffstat (limited to 'modules/sysconfig.inc.php')
-rw-r--r-- | modules/sysconfig.inc.php | 168 |
1 files changed, 74 insertions, 94 deletions
diff --git a/modules/sysconfig.inc.php b/modules/sysconfig.inc.php index faa26787..28fc6a50 100644 --- a/modules/sysconfig.inc.php +++ b/modules/sysconfig.inc.php @@ -1,107 +1,87 @@ <?php -/* -@include_once('Archive/Tar.php'); -if (!class_exists('Archive_Tar')) { - Message::addError('Broken php installation: pear extension Archive_Tar missing!'); - Util::redirect('?do=main'); -} - */ +class Page_SysConfig extends Page +{ -User::load(); + protected function doPreprocess() + { + User::load(); -// Read request vars -$action = Request::any('action', 'list'); -$step = Request::any('step', 0); -$nextStep = $step + 1; + // Read request vars + $action = Request::any('action', 'list'); + $step = Request::any('step', 0); -// Action: "addmodule" (upload new module) -if ($action === 'addmodule') { - require_once 'modules/sysconfig/addmodule.inc.php'; - $handler = AddModule_Base::get($step); - $handler->preprocess(); -} + // Action: "addmodule" (upload new module) + if ($action === 'addmodule') { + if ($step === 0) $step = 'AddModule_Start'; + require_once 'modules/sysconfig/addmodule.inc.php'; + foreach (glob('modules/sysconfig/addmodule_*.inc.php') as $file) { + require_once $file; + } + AddModule_Base::setStep($step); + AddModule_Base::preprocess(); + } -// Action "activate" (set sysconfig as active) -if ($action === 'activate') { - if (!User::hasPermission('superadmin')) { - Message::addError('no-permission'); - Util::redirect('?do=sysconfig'); - } - if (!isset($_REQUEST['file'])) { - Message::addError('missing-file'); - Util::redirect('?do=sysconfig'); + // Action "activate" (set sysconfig as active) + if ($action === 'activate') { + if (!User::hasPermission('superadmin')) { + Message::addError('no-permission'); + Util::redirect('?do=SysConfig'); + } + if (!isset($_REQUEST['file'])) { + Message::addError('missing-file'); + Util::redirect('?do=SysConfig'); + } + $file = preg_replace('/[^a-z0-9\-_\.]/', '', $_REQUEST['file']); + $path = CONFIG_TGZ_LIST_DIR . '/' . $file; + if (!file_exists($path)) { + Message::addError('invalid-file', $file); + Util::redirect('?do=SysConfig'); + } + mkdir(CONFIG_HTTP_DIR . '/default', 0755, true); + $linkname = CONFIG_HTTP_DIR . '/default/config.tgz'; + @unlink($linkname); + if (file_exists($linkname)) Util::traceError('Could not delete old config.tgz link!'); + if (!symlink($path, $linkname)) Util::traceError("Could not symlink to $path at $linkname!"); + Message::addSuccess('config-activated'); + Util::redirect('?do=SysConfig'); + } } - $file = preg_replace('/[^a-z0-9\-_\.]/', '', $_REQUEST['file']); - $path = CONFIG_TGZ_LIST_DIR . '/' . $file; - if (!file_exists($path)) { - Message::addError('invalid-file', $file); - Util::redirect('?do=sysconfig'); - } - mkdir(CONFIG_HTTP_DIR . '/default', 0755, true); - $linkname = CONFIG_HTTP_DIR . '/default/config.tgz'; - @unlink($linkname); - if (file_exists($linkname)) Util::traceError('Could not delete old config.tgz link!'); - if (!symlink($path, $linkname)) Util::traceError("Could not symlink to $path at $linkname!"); - Message::addSuccess('config-activated'); - Util::redirect('?do=sysconfig'); -} -/** - * Render module; called by main script when this module page should render - * its content. - */ -function render_module() -{ - global $action, $handler; - switch ($action) { - case 'addmodule': - $handler->render(); - break; - case 'list': - rr_list_configs(); - break; - default: - Message::addError('invalid-action', $_REQUEST['action']); - break; + /** + * Render module; called by main script when this module page should render + * its content. + */ + protected function doRender() + { + $action = Request::any('action', 'list'); + switch ($action) { + case 'addmodule': + AddModule_Base::render(); + break; + case 'list': + $this->rr_list_configs(); + break; + default: + Message::addError('invalid-action', $action); + break; + } } -} -function rr_list_configs() -{ - if (!User::hasPermission('superadmin')) { - Message::addError('no-permission'); - return; - } - $res = Database::simpleQuery("SELECT title FROM configtgz_module ORDER BY title ASC"); - $modules = array(); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $modules[] = array( - 'module' => $row['title'] - ); + private function rr_list_configs() + { + if (!User::hasPermission('superadmin')) { + Message::addError('no-permission'); + return; + } + $res = Database::simpleQuery("SELECT title FROM configtgz_module ORDER BY title ASC"); + $modules = array(); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $modules[] = array( + 'module' => $row['title'] + ); + } + Render::addTemplate('page-sysconfig-main', array('modules' => $modules, 'token' => Session::get('token'))); } - Render::addTemplate('page-sysconfig-main', array('modules' => $modules, 'token' => Session::get('token'))); -} -function rr_list_remote_configs() -{ - if (!User::hasPermission('superadmin')) { - Message::addError('no-permission'); - return; - } - $data = Util::download(CONFIG_REMOTE_TGZ . '/list.php', 4, $code); - if ($code !== 200) { - Message::addError('remote-timeout', CONFIG_REMOTE_TGZ . '/list.php', $code); - return; - } - $list = json_decode($data, true); - if (!is_array($list)) { - Message::addError('remote-parse-failed', $data); - return; - } - $id = 0; - foreach ($list as &$item) { - $item['id'] = 'download' . (++$id); - } - Render::addTemplate('page-remote-tgz-list', array('files' => $list)); } |