From 63ab02f5b5b6c6d39a8d050b8a38e10e29bd3226 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 12 Jan 2013 11:28:43 +0000 Subject: [PATCH] better config check --- lam/lib/checkEnvironment.inc | 8 ++++++++ lam/lib/config.inc | 9 +++++++++ lam/templates/config/profmanage.php | 13 +++++++++++-- lam/templates/login.php | 6 ++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lam/lib/checkEnvironment.inc b/lam/lib/checkEnvironment.inc index 8cf5d545..98105187 100644 --- a/lam/lib/checkEnvironment.inc +++ b/lam/lib/checkEnvironment.inc @@ -33,6 +33,9 @@ $Id$ /** status messages */ include_once("../lib/status.inc"); +/** config */ +include_once("../lib/config.inc"); + // check if PHP >= 5.2.4 if (version_compare(phpversion(), '5.2.4') < 0) { echo "\n\n"; @@ -107,6 +110,11 @@ if (!@preg_match('/^\p{L}+$/u', "abc")) { if (!extension_loaded('zip')) { $criticalErrors[] = array("ERROR", "Your PHP has no ZIP support.", "Please install the ZIP extension for PHP."); } +// check for main config +$mainConfig = new LAMCfgMain(); +if (!$mainConfig->isConfigFileExisting()) { + $criticalErrors[] = array("ERROR", "The main config file (config.cfg) does not exist.", "Please see the manual for installation instructions."); +} // stop login if critical errors occured if (sizeof($criticalErrors) > 0) { echo "\n\n"; diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 90b91cc8..c70f7075 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -1521,6 +1521,15 @@ class LAMCfgMain { return is_writeable($this->conffile); } + /** + * Returns if the configuration file is existing. + * + * @return boolean exists + */ + public function isConfigFileExisting() { + return file_exists($this->conffile); + } + } ?> diff --git a/lam/templates/config/profmanage.php b/lam/templates/config/profmanage.php index 3dbbd4ea..cfbc3bb7 100644 --- a/lam/templates/config/profmanage.php +++ b/lam/templates/config/profmanage.php @@ -45,6 +45,8 @@ setlanguage(); $cfg = new LAMCfgMain(); +$files = getConfigProfiles(); + // check if submit button was pressed if (isset($_POST['action'])) { // check master password @@ -108,6 +110,15 @@ if (isset($_POST['action'])) { elseif ($_POST['action'] == "delete") { if (deleteConfigProfile($_POST['delfilename']) == null) { $msg = _("Profile deleted."); + // update default profile setting if needed + if ($cfg->default == $_POST['delfilename']) { + $filesNew = array_delete(array($_POST['delfilename']), $files); + if (sizeof($filesNew) > 0) { + sort($filesNew); + $cfg->default = $filesNew[0]; + $cfg->save(); + } + } } else $error = _("Unable to delete profile!"); } @@ -226,8 +237,6 @@ if (!isset($cfg->default)) {
0) { // use first profile as fallback $_SESSION["config"] = new LAMConfig($profiles[0]); } +else { + $_SESSION["config"] = null; +} if (!isset($default_Config->default) || !in_array($default_Config->default, $profiles)) { $error_message = _('No default profile set. Please set it in the server profile configuration.'); @@ -278,6 +281,9 @@ function display_LoginPage($config_object) { } } } + else { + StatusMessage('WARN', _('Please enter the configuration and create a server profile.')); + } // check if session expired if (isset($_GET['expired'])) { StatusMessage("ERROR", _("Your session expired, please log in again."));