From 0653c0cb5a1f11a822cd5fcc546de6c0f4bd5eb6 Mon Sep 17 00:00:00 2001 From: Axel Hahn <ax2002@gmx.net> Date: Mon, 25 Jul 2022 22:23:52 +0200 Subject: [PATCH] handle first run --- config/inc_projects_config.php | 13 ++++--- config/inc_roles.php | 1 + public_html/deployment/classes/user.class.php | 12 +++++- public_html/deployment/index.php | 9 ++++- .../deployment/pages/act_installer.php | 38 +++++++++++++++++++ 5 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 public_html/deployment/pages/act_installer.php diff --git a/config/inc_projects_config.php b/config/inc_projects_config.php index 8344d440..83c949ba 100644 --- a/config/inc_projects_config.php +++ b/config/inc_projects_config.php @@ -1,9 +1,12 @@ <?php -$aConfig = array_replace_recursive( - include('config_defaults.php'), - include('config_custom.php') -) -; + +$aConfig = include('config_defaults.php'); +if (file_exists('config_custom.php')){ + $aConfig = array_replace_recursive( + $aConfig, + include('config_custom.php') + ); +} // ---------------------------------------------------------------------- // generate some vars diff --git a/config/inc_roles.php b/config/inc_roles.php index 58188673..018c7205 100644 --- a/config/inc_roles.php +++ b/config/inc_roles.php @@ -46,6 +46,7 @@ return [ "page_deploy", "page_doc", "page_htmltest", + "page_installer", "page_phase", "page_setup", "page_checkssh", diff --git a/public_html/deployment/classes/user.class.php b/public_html/deployment/classes/user.class.php index a3517828..33ac0c66 100644 --- a/public_html/deployment/classes/user.class.php +++ b/public_html/deployment/classes/user.class.php @@ -72,11 +72,19 @@ class user { // UNUSED SO FAR private function _getUser2Projects(){ - return require(__DIR__ . '/../../../config/inc_user2projects.php'); + $sFile=__DIR__ . '/../../../config/inc_user2projects.php'; + return file_exists($sFile) + ? require $sFile + : [] + ; } private function _getUser2Roles(){ - return require(__DIR__ . '/../../../config/inc_user2roles.php'); + $sFile=__DIR__ . '/../../../config/inc_user2roles.php'; + return file_exists($sFile) + ? require $sFile + : ['admin'=>['admin']] + ; } /** * TODO: reimplement diff --git a/public_html/deployment/index.php b/public_html/deployment/index.php index 4a45b7f1..82384c6b 100644 --- a/public_html/deployment/index.php +++ b/public_html/deployment/index.php @@ -23,6 +23,10 @@ ini_set('display_startup_errors', 1); error_reporting(E_ALL); require_once("./classes/page.class.php"); + +// detect first run +$bFirstRun=!file_exists("../../config/config_custom.php") || !file_exists("../../config/inc_user2roles.php"); + require_once("../../config/inc_projects_config.php"); require_once("./classes/logger.class.php"); require_once("./classes/user.class.php"); @@ -52,7 +56,10 @@ $oCLog->add("parsing params " . '<pre>aParams: '.print_r($aParams, true).'</pre>' ); - +if($bFirstRun){ + $sAction='installer'; +} + // ------ Ausgabe $sHeader = '<style>'; foreach ($aConfig["phases"] as $sPhase => $aData) { diff --git a/public_html/deployment/pages/act_installer.php b/public_html/deployment/pages/act_installer.php new file mode 100644 index 00000000..8b0c5326 --- /dev/null +++ b/public_html/deployment/pages/act_installer.php @@ -0,0 +1,38 @@ +<?php + +/* ###################################################################### + + IML DEPLOYMENT + + INSTALLER + + --------------------------------------------------------------------- + 2022-07-25 Axel <axel.hahn@iml.unibe.ch> + ###################################################################### */ + +require_once("./inc_functions.php"); +$sOut = '' +.' + +<h2>Welcome to the IML CI SERVER!</h2> + +<p> + This page appears on the first run. Or better: as long no configuration exists.<br> + + <br> + <br> + Go to the directory <code>'.dirname($_SERVER['DOCUMENT_ROOT']).'/config/</code>.<br> + <br> + Copy 2 <code>*.dist</code> files <code>config_custom.php</code> and <code>inc_user2roles.php</code>.<br> + <br> + <a href="?" class="btn btn-default">Reload</a><br> + <br> +</p> +<script> + window.setTimeout("location.reload()", 5000); +</script> +' +; + +// -- Ausgabe +echo $sOut; -- GitLab