From e05c51576cb12b49645e9edda40ab7cc8a0999b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sun, 9 Oct 2022 16:22:51 -0300 Subject: [PATCH 1/2] Extract setup entry points into controllers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../Controllers/Setup/MainController.php | 79 +++++++++++++++++++ .../Setup/ShowConfigController.php | 50 ++++++++++++ .../Controllers/Setup/ValidateController.php | 44 +++++++++++ psalm-baseline.xml | 24 +++--- setup/config.php | 39 +-------- setup/index.php | 68 +--------------- setup/validate.php | 28 +------ 7 files changed, 191 insertions(+), 141 deletions(-) create mode 100644 libraries/classes/Controllers/Setup/MainController.php create mode 100644 libraries/classes/Controllers/Setup/ShowConfigController.php create mode 100644 libraries/classes/Controllers/Setup/ValidateController.php diff --git a/libraries/classes/Controllers/Setup/MainController.php b/libraries/classes/Controllers/Setup/MainController.php new file mode 100644 index 0000000000..a4ad7ad459 --- /dev/null +++ b/libraries/classes/Controllers/Setup/MainController.php @@ -0,0 +1,79 @@ +sendHttpHeaders(); + + if ($page === 'form') { + echo (new FormController($GLOBALS['ConfigFile'], new Template()))([ + 'formset' => $_GET['formset'] ?? null, + ]); + + return; + } + + if ($page === 'config') { + echo (new ConfigController($GLOBALS['ConfigFile'], new Template()))([ + 'formset' => $_GET['formset'] ?? null, + 'eol' => $_GET['eol'] ?? null, + ]); + + return; + } + + if ($page === 'servers') { + $controller = new ServersController($GLOBALS['ConfigFile'], new Template()); + if ( + isset($_GET['mode']) && $_GET['mode'] === 'remove' && ($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST' + ) { + $controller->destroy([ + 'id' => $_GET['id'] ?? null, + ]); + header('Location: index.php' . Url::getCommonRaw()); + + return; + } + + echo $controller->index([ + 'formset' => $_GET['formset'] ?? null, + 'mode' => $_GET['mode'] ?? null, + 'id' => $_GET['id'] ?? null, + ]); + + return; + } + + echo (new HomeController($GLOBALS['ConfigFile'], new Template()))([ + 'formset' => $_GET['formset'] ?? null, + 'version_check' => $_GET['version_check'] ?? null, + ]); + } +} diff --git a/libraries/classes/Controllers/Setup/ShowConfigController.php b/libraries/classes/Controllers/Setup/ShowConfigController.php new file mode 100644 index 0000000000..40b73b789e --- /dev/null +++ b/libraries/classes/Controllers/Setup/ShowConfigController.php @@ -0,0 +1,50 @@ +save('Config'); + + $response = ResponseRenderer::getInstance(); + $response->disable(); + + if (isset($_POST['eol'])) { + $_SESSION['eol'] = $_POST['eol'] === 'unix' ? 'unix' : 'win'; + } + + if (isset($_POST['submit_clear']) && is_scalar($_POST['submit_clear']) ? $_POST['submit_clear'] : '') { + // Clear current config and return to main page + $GLOBALS['ConfigFile']->resetConfigData(); + // drop post data + $response->generateHeader303('index.php' . Url::getCommonRaw()); + + return; + } + + if (isset($_POST['submit_download']) && is_scalar($_POST['submit_download']) ? $_POST['submit_download'] : '') { + // Output generated config file + Core::downloadHeader('config.inc.php', 'text/plain'); + $response->disable(); + echo ConfigGenerator::getConfigFile($GLOBALS['ConfigFile']); + + return; + } + + // Show generated config file in a