From 6ba9c6879f57563f85b73761861d6d3b905d4de4 Mon Sep 17 00:00:00 2001 From: Cyril Date: Mon, 14 Oct 2019 12:21:28 +0200 Subject: [PATCH 01/29] First attempt at switching to symfony/yaml for config files (WIP) --- Core/Frameworks/Baikal/Core/Tools.php | 33 ++-- Core/Frameworks/Baikal/Framework.php | 19 +- Core/Frameworks/Baikal/Model/Config.php | 173 ++---------------- .../Baikal/Model/Config/Database.php | 2 +- .../Baikal/Model/Config/Standard.php | 65 ++----- .../Frameworks/Baikal/Model/Config/System.php | 126 ++----------- Core/Frameworks/Baikal/Model/User.php | 7 +- .../BaikalAdmin/Controller/Dashboard.php | 9 +- .../Controller/Install/Database.php | 9 +- .../Controller/Install/Initialize.php | 4 +- .../Install/UpgradeConfirmation.php | 12 +- .../Controller/Install/VersionUpgrade.php | 2 + .../Controller/Settings/Standard.php | 2 +- .../Controller/Settings/System.php | 11 +- Core/Frameworks/BaikalAdmin/Core/Auth.php | 29 ++- .../BaikalAdmin/WWWRoot/install/index.php | 15 +- Core/Frameworks/Flake/Framework.php | 72 ++++---- html/cal.php | 21 ++- html/card.php | 21 ++- html/dav.php | 18 +- 20 files changed, 222 insertions(+), 428 deletions(-) diff --git a/Core/Frameworks/Baikal/Core/Tools.php b/Core/Frameworks/Baikal/Core/Tools.php index 9c1caae..377a010 100644 --- a/Core/Frameworks/Baikal/Core/Tools.php +++ b/Core/Frameworks/Baikal/Core/Tools.php @@ -73,33 +73,32 @@ class Tools { #} # Asserting config file exists - if (!file_exists(PROJECT_PATH_SPECIFIC . "config.php")) { - throw new \Exception("Specific/config.php does not exist. Please use the Install tool to create it."); + if (!file_exists(PROJECT_PATH_CONFIG . "config.yaml")) { + throw new \Exception("config/config.yaml does not exist. Please use the Install tool to create it or duplicate config.yaml.dist."); } # Asserting config file is readable - if (!is_readable(PROJECT_PATH_SPECIFIC . "config.php")) { - throw new \Exception("Specific/config.php is not readable. Please give read permissions to httpd user on file 'Specific/config.php'."); + if (!is_readable(PROJECT_PATH_CONFIG . "config.yaml")) { + throw new \Exception("config/config.yaml is not readable. Please give read permissions to httpd user on file 'config/config.yaml'."); } # Asserting config file is writable - if (!is_writable(PROJECT_PATH_SPECIFIC . "config.php")) { - throw new \Exception("Specific/config.php is not writable. Please give write permissions to httpd user on file 'Specific/config.php'."); + if (!is_writable(PROJECT_PATH_CONFIG . "config.yaml")) { + throw new \Exception("config/config.yaml is not writable. Please give write permissions to httpd user on file 'config/config.yaml'."); + } + # Asserting config file exists + if (!file_exists(PROJECT_PATH_CONFIG . "system.yaml")) { + throw new \Exception("config/system.yaml does not exist. Please use the Install tool to create it or duplicate system.yaml.dist."); } - # Asserting system config file exists - if (!file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) { - throw new \Exception("Specific/config.system.php does not exist. Please use the Install tool to create it."); + # Asserting config file is readable + if (!is_readable(PROJECT_PATH_CONFIG . "system.yaml")) { + throw new \Exception("config/system.yaml is not readable. Please give read permissions to httpd user on file 'config/system.yaml'."); } - # Asserting system config file is readable - if (!is_readable(PROJECT_PATH_SPECIFIC . "config.system.php")) { - throw new \Exception("Specific/config.system.php is not readable. Please give read permissions to httpd user on file 'Specific/config.system.php'."); - } - - # Asserting system config file is writable - if (!is_writable(PROJECT_PATH_SPECIFIC . "config.system.php")) { - throw new \Exception("Specific/config.system.php is not writable. Please give write permissions to httpd user on file 'Specific/config.system.php'."); + # Asserting config file is writable + if (!is_writable(PROJECT_PATH_CONFIG . "system.yaml")) { + throw new \Exception("config/system.yaml is not writable. Please give write permissions to httpd user on file 'config/system.yaml'."); } } diff --git a/Core/Frameworks/Baikal/Framework.php b/Core/Frameworks/Baikal/Framework.php index c1622be..95825a7 100644 --- a/Core/Frameworks/Baikal/Framework.php +++ b/Core/Frameworks/Baikal/Framework.php @@ -27,6 +27,8 @@ namespace Baikal; +use Symfony\Component\Yaml\Yaml; + class Framework extends \Flake\Core\Framework { static function installTool() { @@ -51,29 +53,30 @@ class Framework extends \Flake\Core\Framework { # Check that a config file exists if ( - !file_exists(PROJECT_PATH_SPECIFIC . "config.php") || - !file_exists(PROJECT_PATH_SPECIFIC . "config.system.php") + !file_exists(PROJECT_PATH_CONFIG . "config.yaml") || + !file_exists(PROJECT_PATH_CONFIG . "system.yaml") ) { self::installTool(); } else { - require_once(PROJECT_PATH_SPECIFIC . "config.php"); - require_once(PROJECT_PATH_SPECIFIC . "config.system.php"); - date_default_timezone_set(PROJECT_TIMEZONE); + + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + date_default_timezone_set($config['parameters']['PROJECT_TIMEZONE']); # Check that Baïkal is already configured - if (!defined("BAIKAL_CONFIGURED_VERSION")) { + if (!isset($configSystem['parameters']['BAIKAL_CONFIGURED_VERSION'])) { self::installTool(); } else { # Check that running version matches configured version - if (version_compare(BAIKAL_VERSION, BAIKAL_CONFIGURED_VERSION) > 0) { + if (version_compare(BAIKAL_VERSION, $configSystem['parameters']['BAIKAL_CONFIGURED_VERSION']) > 0) { self::installTool(); } else { # Check that admin password is set - if (!defined("BAIKAL_ADMIN_PASSWORDHASH")) { + if (!$config['parameters']['BAIKAL_ADMIN_PASSWORDHASH']) { self::installTool(); } diff --git a/Core/Frameworks/Baikal/Model/Config.php b/Core/Frameworks/Baikal/Model/Config.php index 483f9e9..c028d1f 100644 --- a/Core/Frameworks/Baikal/Model/Config.php +++ b/Core/Frameworks/Baikal/Model/Config.php @@ -27,18 +27,25 @@ namespace Baikal\Model; +use Symfony\Component\Yaml\Yaml; + abstract class Config extends \Flake\Core\Model\NoDb { protected $sConfigFilePath = ""; - protected $aConstants = []; protected $aData = []; function __construct($sConfigFilePath) { + # Note: no call to parent::__construct() to avoid erasing $this->aData $this->sConfigFilePath = $sConfigFilePath; - $aConfig = $this->parseConfig( - $this->getConfigAsString() - ); + + try { + $config = Yaml::parseFile($this->sConfigFilePath); + $aConfig = $config['parameters']; + } catch(\Exception $e) { + $aConfig = static::getDefaultConfig(); + } + foreach (array_keys($this->aData) as $sProp) { if (array_key_exists($sProp, $aConfig)) { @@ -49,79 +56,12 @@ abstract class Config extends \Flake\Core\Model\NoDb { protected function getConfigAsString() { if (file_exists($this->sConfigFilePath)) { - $sContent = file_get_contents($this->sConfigFilePath); - return str_replace(LF . CR, LF, $sContent); + return Yaml::parseFile($this->sConfigFilePath); } else { - - $sConfig = "aConstants) as $sConstant) { - $aConstant = $this->aConstants[$sConstant]; - - $aMatches = []; - $sPattern = '/\s*define\(\s*["|\']' . $sConstant . '["|\']\s*\,\s*(.*?)\s*\);\s*/ix'; - - $iNbRes = preg_match_all( - $sPattern, - $sString, - $aMatches - ); - - if ($iNbRes === 1) { - # Exactly one match - # O would be not enough, and > 1, to much to handle properly - - $sValue = $aMatches[1][0]; # first capture (.*?), first occurence (anyway, we asserted that there's only one) - switch ($aConstant["type"]) { - case "string": { - $sValue = substr($sValue, 1, -1); # Strip quotes - break; - } - case "integer": { - $sValue = intval($sValue); # Integer - break; - } - case "boolean": { - if (in_array(strtoupper(trim($sValue)), ["1", "TRUE"])) { - $sValue = true; - } else { - $sValue = false; - } - break; - } - case "litteral": { - $sValue = trim($sValue); - break; - } - default: { - # nothing - break; - } - } - - $aRes[$sConstant] = $sValue; - - } elseif ($iNbRes > 1) { - throw new \Exception("Baikal\Model\Config->parseConfig(): constant '" . $sConstant . "' has been found multiple times in the config file; stopping execution"); - } else { - # $iNbRes === 0 - # We do nothing, to keep the default value (the one already set in $aData) - } - } - - reset($aRes); - return $aRes; - } - function writable() { return ( @file_exists($this->sConfigFilePath) && @@ -147,89 +87,10 @@ abstract class Config extends \Flake\Core\Model\NoDb { } function persist() { - $aLines = explode(LF, $this->getConfigAsString()); - $iLines = count($aLines); - - foreach (array_keys($this->aData) as $prop) { - $sPattern = '/\s*define\(\s*["|\']' . $prop . '["|\']\s*\,\s*(.*?)\s*\);\s*/ix'; - $sValue = $this->aData[$prop]; - - - # We replace value by it's native PHP notation - switch ($this->aConstants[$prop]["type"]) { - case "string": { - $sValue = var_export($sValue, true); # Add quotes, and escape " and all string-termination chars - break; - } - case "integer": { - $sValue = intval($sValue); # Cast as integer - break; - } - case "boolean": { - - if (intval($sValue) === 1) { # Note as a BOOLEAN PHP constant - $sValue = "TRUE"; - } else { - $sValue = "FALSE"; - } - - break; - } - case "litteral": { - $sValue = trim($sValue); - break; - } - default: { - $sValue = "''"; - break; - } - } - - $mFound = false; - for ($k = ($iLines - 1); $k >= 0; $k--) { - if (preg_match($sPattern, $aLines[$k])) { - - # Found the last matching line - $mFound = $k; - break; - } - } - - if ($mFound === false) { - # Adding line at the end of the file - $aLines[] = "\n" . "# " . $this->aConstants[$prop]["comment"] . "\ndefine(\"" . $prop . "\", " . $sValue . ");"; - } else { - $aLines[$mFound] = "define(\"" . $prop . "\", " . $sValue . ");"; - } - } - - $sLines = implode("\n", $aLines); - $sSandboxedCode = str_replace([""], "", $sLines); - $sRand = (string)rand(); - $sCode = "if(0) {" . $sSandboxedCode . "\n}; echo '" . $sRand . "';"; - ob_start(); - eval($sCode); - $sRes = ob_get_contents(); - ob_end_clean(); - - if ($sRes !== $sRand) { - echo "
" . htmlspecialchars($sLines) . "
"; - throw new \Exception("Parse error in new config file. Aborting, nothing has been changed."); - } - - # We asserted that the syntax is OK; - # We now check that all the constants are present, and with the right value - $aNewConfig = $this->parseConfig($sLines); - $aWrittenConfig = $this->aData; - - asort($aNewConfig); - asort($aWrittenConfig); - - if ($aNewConfig != $aWrittenConfig) { - throw new \Exception("New config does not correspond to expected config. Aborting, nothing has been changed."); - } - - file_put_contents($this->sConfigFilePath, $sLines); + $yaml = Yaml::dump([ + 'parameters' => $this->aData + ]); + file_put_contents($this->sConfigFilePath, $yaml); } function destroy() { diff --git a/Core/Frameworks/Baikal/Model/Config/Database.php b/Core/Frameworks/Baikal/Model/Config/Database.php index 8a9bb47..f0de8a6 100644 --- a/Core/Frameworks/Baikal/Model/Config/Database.php +++ b/Core/Frameworks/Baikal/Model/Config/Database.php @@ -58,7 +58,7 @@ class Database extends \Baikal\Model\Config { # Default values protected $aData = [ - "PROJECT_SQLITE_FILE" => 'PROJECT_PATH_SPECIFIC . "db/db.sqlite"', + "PROJECT_SQLITE_FILE" => PROJECT_PATH_SPECIFIC . "db/db.sqlite", "PROJECT_DB_MYSQL" => false, "PROJECT_DB_MYSQL_HOST" => "", "PROJECT_DB_MYSQL_DBNAME" => "", diff --git a/Core/Frameworks/Baikal/Model/Config/Standard.php b/Core/Frameworks/Baikal/Model/Config/Standard.php index daab958..28fdd04 100644 --- a/Core/Frameworks/Baikal/Model/Config/Standard.php +++ b/Core/Frameworks/Baikal/Model/Config/Standard.php @@ -27,6 +27,8 @@ namespace Baikal\Model\Config; +use Symfony\Component\Yaml\Yaml; + class Standard extends \Baikal\Model\Config { protected $aConstants = [ @@ -63,7 +65,8 @@ class Standard extends \Baikal\Model\Config { "BAIKAL_CAL_ENABLED" => true, "BAIKAL_INVITE_FROM" => "", "BAIKAL_DAV_AUTH_TYPE" => "Digest", - "BAIKAL_ADMIN_PASSWORDHASH" => "" + "BAIKAL_ADMIN_PASSWORDHASH" => "", + "BAIKAL_AUTH_REALM" => "BaikalDAV" ]; function formMorphologyForThisModelInstance() { @@ -110,7 +113,11 @@ class Standard extends \Baikal\Model\Config { "validation" => "sameas:BAIKAL_ADMIN_PASSWORDHASH", ])); - if (!defined("BAIKAL_ADMIN_PASSWORDHASH") || trim(BAIKAL_ADMIN_PASSWORDHASH) === "") { + try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + } catch(\Exception $e) {} + + if (!isset($config['parameters']["BAIKAL_ADMIN_PASSWORDHASH"]) || trim($config['parameters']["BAIKAL_ADMIN_PASSWORDHASH"]) === "") { # No password set (Form is used in install tool), so password is required as it has to be defined $oMorpho->element("BAIKAL_ADMIN_PASSWORDHASH")->setOption("validation", "required"); @@ -152,52 +159,16 @@ class Standard extends \Baikal\Model\Config { return parent::get($sProp); } - protected function createDefaultConfigFilesIfNeeded() { - - # Create empty config.php if needed - if (!file_exists(PROJECT_PATH_SPECIFIC . "config.php")) { - @touch(PROJECT_PATH_SPECIFIC . "config.php"); - $sContent = "getDefaultConfig(); - file_put_contents(PROJECT_PATH_SPECIFIC . "config.php", $sContent); - } - - # Create empty config.system.php if needed - if (!file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) { - @touch(PROJECT_PATH_SPECIFIC . "config.system.php"); - $sContent = "getDefaultSystemConfig(); - file_put_contents(PROJECT_PATH_SPECIFIC . "config.system.php", $sContent); - } - } - protected static function getDefaultConfig() { - $sCode = << "Europe/Paris", + "BAIKAL_CARD_ENABLED" => true, + "BAIKAL_CAL_ENABLED" => true, + "BAIKAL_INVITE_FROM" => "noreply@" . $_SERVER['SERVER_NAME'], + "BAIKAL_DAV_AUTH_TYPE" => "Digest", + "BAIKAL_ADMIN_PASSWORDHASH" => "", + "BAIKAL_AUTH_REALM" => "BaikalDAV", + ]; } } diff --git a/Core/Frameworks/Baikal/Model/Config/System.php b/Core/Frameworks/Baikal/Model/Config/System.php index 42feb7e..d73b152 100644 --- a/Core/Frameworks/Baikal/Model/Config/System.php +++ b/Core/Frameworks/Baikal/Model/Config/System.php @@ -30,22 +30,6 @@ namespace Baikal\Model\Config; class System extends \Baikal\Model\Config { protected $aConstants = [ - "BAIKAL_AUTH_REALM" => [ - "type" => "string", - "comment" => "If you change this value, you'll have to re-generate passwords for all your users", - ], - "BAIKAL_CARD_BASEURI" => [ - "type" => "litteral", - "comment" => 'Should begin and end with a "/"', - ], - "BAIKAL_CAL_BASEURI" => [ - "type" => "litteral", - "comment" => 'Should begin and end with a "/"', - ], - "BAIKAL_DAV_BASEURI" => [ - "type" => "litteral", - "comment" => 'Should begin and end with a "/"', - ], "PROJECT_SQLITE_FILE" => [ "type" => "litteral", "comment" => "Define path to Baïkal Database SQLite file", @@ -82,11 +66,7 @@ class System extends \Baikal\Model\Config { # Default values protected $aData = [ - "BAIKAL_AUTH_REALM" => "BaikalDAV", - "BAIKAL_CARD_BASEURI" => 'PROJECT_BASEURI . "card.php/"', - "BAIKAL_CAL_BASEURI" => 'PROJECT_BASEURI . "cal.php/"', - "BAIKAL_DAV_BASEURI" => 'PROJECT_BASEURI . "dav.php/"', - "PROJECT_SQLITE_FILE" => 'PROJECT_PATH_SPECIFIC . "db/db.sqlite"', + "PROJECT_SQLITE_FILE" => "db/db.sqlite", "PROJECT_DB_MYSQL" => false, "PROJECT_DB_MYSQL_HOST" => "", "PROJECT_DB_MYSQL_DBNAME" => "", @@ -99,49 +79,6 @@ class System extends \Baikal\Model\Config { function formMorphologyForThisModelInstance() { $oMorpho = new \Formal\Form\Morphology(); - $oMorpho->add(new \Formal\Element\Text([ - "prop" => "BAIKAL_CAL_BASEURI", - "label" => "CalDAV base URI", - "validation" => "required", - "help" => "The absolute web path to cal.php", - "popover" => [ - "title" => "CalDAV base URI", - "content" => "If Baïkal is hosted in a subfolder, this path should reflect it.
Whatever happens, it should begin and end with a slash.", - ] - ])); - - $oMorpho->add(new \Formal\Element\Text([ - "prop" => "BAIKAL_CARD_BASEURI", - "label" => "CardDAV base URI", - "validation" => "required", - "help" => "The absolute web path to card.php", - "popover" => [ - "title" => "CardDAV base URI", - "content" => "If Baïkal is hosted in a subfolder, this path should reflect it.
Whatever happens, it should begin and end with a slash." - ] - ])); - $oMorpho->add(new \Formal\Element\Text([ - "prop" => "BAIKAL_DAV_BASEURI", - "label" => "CalDAV/CardDAV base URI", - "validation" => "required", - "help" => "The absolute web path to dav.php", - "popover" => [ - "title" => "DAV base URI", - "content" => "If Baïkal is hosted in a subfolder, this path should reflect it.
Whatever happens, it should begin and end with a slash." - ] - ])); - - $oMorpho->add(new \Formal\Element\Text([ - "prop" => "BAIKAL_AUTH_REALM", - "label" => "Auth realm", - "validation" => "required", - "help" => "Token used in authentication process.
If you change this, you'll have to reset all your users passwords.
You'll also loose access to this admin interface.", - "popover" => [ - "title" => "Auth realm", - "content" => "If you change this, you'll loose your access to this interface.
In other words: you should not change this, unless YKWYD." - ] - ])); - $oMorpho->add(new \Formal\Element\Text([ "prop" => "PROJECT_SQLITE_FILE", "label" => "SQLite file path", @@ -187,56 +124,15 @@ class System extends \Baikal\Model\Config { protected static function getDefaultConfig() { - $sBaikalVersion = BAIKAL_VERSION; - - $sCode = << Use MySQL instead of SQLite ? -define("PROJECT_DB_MYSQL", FALSE); - -# MySQL > Host, including ':portnumber' if port is not the default one (3306) -define("PROJECT_DB_MYSQL_HOST", ""); - -# MySQL > Database name -define("PROJECT_DB_MYSQL_DBNAME", ""); - -# MySQL > Username -define("PROJECT_DB_MYSQL_USERNAME", ""); - -# MySQL > Password -define("PROJECT_DB_MYSQL_PASSWORD", ""); - -# A random 32 bytes key that will be used to encrypt data -define("BAIKAL_ENCRYPTION_KEY", ""); - -# The currently configured Baïkal version -define("BAIKAL_CONFIGURED_VERSION", "{$sBaikalVersion}"); - -CODE; - $sCode = trim($sCode); - return $sCode; + return [ + "PROJECT_SQLITE_FILE" => "db/db.sqlite", + "PROJECT_DB_MYSQL" => false, + "PROJECT_DB_MYSQL_HOST" => "", + "PROJECT_DB_MYSQL_DBNAME" => "", + "PROJECT_DB_MYSQL_USERNAME" => "", + "PROJECT_DB_MYSQL_PASSWORD" => "", + "BAIKAL_ENCRYPTION_KEY" => "", + "BAIKAL_CONFIGURED_VERSION" => BAIKAL_VERSION + ]; } } diff --git a/Core/Frameworks/Baikal/Model/User.php b/Core/Frameworks/Baikal/Model/User.php index f744f99..2988622 100644 --- a/Core/Frameworks/Baikal/Model/User.php +++ b/Core/Frameworks/Baikal/Model/User.php @@ -279,6 +279,11 @@ class User extends \Flake\Core\Model\Db { } function getPasswordHashForPassword($sPassword) { - return md5($this->get("username") . ':' . BAIKAL_AUTH_REALM . ':' . $sPassword); + + try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + } catch(\Exception $e) {} + + return md5($this->get("username") . ':' . $config['parameters']['BAIKAL_AUTH_REALM'] . ':' . $sPassword); } } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php b/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php index 9e59da4..a20699d 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php @@ -27,18 +27,23 @@ namespace BaikalAdmin\Controller; +use Symfony\Component\Yaml\Yaml; + class Dashboard extends \Flake\Core\Controller { function execute() { } function render() { + + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $oView = new \BaikalAdmin\View\Dashboard(); $oView->setData("BAIKAL_VERSION", BAIKAL_VERSION); # Services status - $oView->setData("BAIKAL_CAL_ENABLED", BAIKAL_CAL_ENABLED); - $oView->setData("BAIKAL_CARD_ENABLED", BAIKAL_CARD_ENABLED); + $oView->setData("BAIKAL_CAL_ENABLED", $config['parameters']['BAIKAL_CAL_ENABLED']); + $oView->setData("BAIKAL_CARD_ENABLED", $config['parameters']['BAIKAL_CARD_ENABLED']); # Statistics: Users $iNbUsers = \Baikal\Model\User::getBaseRequester()->count(); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php index d16a8fa..418b14e 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php @@ -27,6 +27,8 @@ namespace BaikalAdmin\Controller\Install; +use Symfony\Component\Yaml\Yaml; + class Database extends \Flake\Core\Controller { protected $aMessages = []; @@ -34,7 +36,7 @@ class Database extends \Flake\Core\Controller { protected $oForm; # \Formal\Form function execute() { - $this->oModel = new \Baikal\Model\Config\Database(PROJECT_PATH_SPECIFIC . "config.system.php"); + $this->oModel = new \Baikal\Model\Config\Database(PROJECT_PATH_CONFIG . "system.yaml"); $this->oForm = $this->oModel->formForThisModelInstance([ "close" => false, @@ -198,7 +200,10 @@ class Database extends \Flake\Core\Controller { if ($oForm->submitted()) { $bMySQL = (intval($oForm->postValue("PROJECT_DB_MYSQL")) === 1); } else { - $bMySQL = PROJECT_DB_MYSQL; + try { + $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + } catch (\Exception $e) {} + $bMySQL = $configSystem['parameters']['PROJECT_DB_MYSQL'] ?? true; } if ($bMySQL === true) { diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index 04ec977..cf9fae3 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -45,7 +45,7 @@ class Initialize extends \Flake\Core\Controller { $this->createHtaccessFilesIfNeeded(); - $this->oModel = new \Baikal\Model\Config\Standard(PROJECT_PATH_SPECIFIC . "config.php"); + $this->oModel = new \Baikal\Model\Config\Standard(PROJECT_PATH_CONFIG . "config.yaml"); $this->oForm = $this->oModel->formForThisModelInstance([ "close" => false @@ -57,7 +57,7 @@ class Initialize extends \Flake\Core\Controller { if ($this->oForm->persisted()) { # Creating system config, and initializing BAIKAL_ENCRYPTION_KEY - $oSystemConfig = new \Baikal\Model\Config\System(PROJECT_PATH_SPECIFIC . "config.system.php"); + $oSystemConfig = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); $oSystemConfig->set("BAIKAL_ENCRYPTION_KEY", md5(microtime() . rand())); # Default: PDO::SQLite or PDO::MySQL ? diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php b/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php index d4ce825..5dd20da 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php @@ -27,6 +27,8 @@ namespace BaikalAdmin\Controller\Install; +use Symfony\Component\Yaml\Yaml; + class UpgradeConfirmation extends \Flake\Core\Controller { function execute() { @@ -35,10 +37,14 @@ class UpgradeConfirmation extends \Flake\Core\Controller { function render() { $oView = new \BaikalAdmin\View\Install\UpgradeConfirmation(); - if (BAIKAL_CONFIGURED_VERSION === BAIKAL_VERSION) { - $sMessage = "Your system is configured to use version " . BAIKAL_CONFIGURED_VERSION . ".
There's no upgrade to be done."; + try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + } catch (\Exception $e) {} + + if (isset($config['parameters']['BAIKAL_CONFIGURED_VERSION']) && $config['parameters']['BAIKAL_CONFIGURED_VERSION'] === BAIKAL_VERSION) { + $sMessage = "Your system is configured to use version " . $config['parameters']['BAIKAL_CONFIGURED_VERSION'] . ".
There's no upgrade to be done."; } else { - $sMessage = "Upgrading Baïkal from version " . BAIKAL_CONFIGURED_VERSION . " to version " . BAIKAL_VERSION . ""; + $sMessage = "Upgrading Baïkal from version " . "Unknown" . " to version " . BAIKAL_VERSION . ""; } $oView->setData("message", $sMessage); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php index 79d350f..3669833 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php @@ -27,6 +27,8 @@ namespace BaikalAdmin\Controller\Install; +use Symfony\Component\Yaml\Yaml; + class VersionUpgrade extends \Flake\Core\Controller { protected $aMessages = []; diff --git a/Core/Frameworks/BaikalAdmin/Controller/Settings/Standard.php b/Core/Frameworks/BaikalAdmin/Controller/Settings/Standard.php index d6676d5..beaea48 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Settings/Standard.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Settings/Standard.php @@ -30,7 +30,7 @@ namespace BaikalAdmin\Controller\Settings; class Standard extends \Flake\Core\Controller { function execute() { - $this->oModel = new \Baikal\Model\Config\Standard(PROJECT_PATH_SPECIFIC . "config.php"); + $this->oModel = new \Baikal\Model\Config\Standard(PROJECT_PATH_CONFIG . "config.yaml"); # Assert that config file is writable if (!$this->oModel->writable()) { diff --git a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php index 4069fa1..9f0dc1f 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php @@ -27,14 +27,16 @@ namespace BaikalAdmin\Controller\Settings; +use Symfony\Component\Yaml\Yaml; + class System extends \Flake\Core\Controller { function execute() { - $this->oModel = new \Baikal\Model\Config\System(PROJECT_PATH_SPECIFIC . "config.system.php"); + $this->oModel = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); # Assert that config file is writable if (!$this->oModel->writable()) { - throw new \Exception("System config file is not writable;" . __FILE__ . " > " . __LINE__); + throw new \Exception("Config file is not writable;" . __FILE__ . " > " . __LINE__); } $this->oForm = $this->oModel->formForThisModelInstance([ @@ -66,7 +68,10 @@ class System extends \Flake\Core\Controller { if ($oForm->submitted()) { $bMySQL = (intval($oForm->postValue("PROJECT_DB_MYSQL")) === 1); } else { - $bMySQL = PROJECT_DB_MYSQL; + try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + } catch(\Exception $e) {} + $bMySQL = $config['parameters']['PROJECT_DB_MYSQL'] ?? true; } if ($bMySQL === true) { diff --git a/Core/Frameworks/BaikalAdmin/Core/Auth.php b/Core/Frameworks/BaikalAdmin/Core/Auth.php index 5f4e81c..57b053b 100644 --- a/Core/Frameworks/BaikalAdmin/Core/Auth.php +++ b/Core/Frameworks/BaikalAdmin/Core/Auth.php @@ -27,9 +27,14 @@ namespace BaikalAdmin\Core; +use Symfony\Component\Yaml\Yaml; + class Auth { static function isAuthenticated() { - if (isset($_SESSION["baikaladminauth"]) && $_SESSION["baikaladminauth"] === md5(BAIKAL_ADMIN_PASSWORDHASH)) { + + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + + if (isset($_SESSION["baikaladminauth"]) && $_SESSION["baikaladminauth"] === md5($config['parameters']['BAIKAL_ADMIN_PASSWORDHASH'])) { return true; } @@ -46,9 +51,13 @@ class Auth { $sPass = \Flake\Util\Tools::POST("password"); $sPassHash = self::hashAdminPassword($sPass); - - if ($sUser === "admin" && $sPassHash === BAIKAL_ADMIN_PASSWORDHASH) { - $_SESSION["baikaladminauth"] = md5(BAIKAL_ADMIN_PASSWORDHASH); + try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + } catch (\Exception $e) { + + } + if ($sUser === "admin" && $sPassHash === $config['parameters']['BAIKAL_ADMIN_PASSWORDHASH']) { + $_SESSION["baikaladminauth"] = md5($config['parameters']['BAIKAL_ADMIN_PASSWORDHASH']); return true; } @@ -61,11 +70,13 @@ class Auth { } static function hashAdminPassword($sPassword) { - if (defined("BAIKAL_AUTH_REALM")) { - $sAuthRealm = BAIKAL_AUTH_REALM; - } else { - $sAuthRealm = "BaikalDAV"; # Fallback to default value; useful when initializing App, as all constants are not set yet - } + + try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + } catch (\Exception $e) { } + + # Fallback to default value; useful when initializing App, as all constants are not set yet + $sAuthRealm = $config['parameters']['BAIKAL_AUTH_REALM'] ?? "BaikalDAV"; return md5('admin:' . $sAuthRealm . ':' . $sPassword); } diff --git a/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php b/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php index 371b48c..fd7035e 100644 --- a/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php +++ b/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php @@ -24,6 +24,8 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use Symfony\Component\Yaml\Yaml; + ini_set("session.cookie_httponly", 1); ini_set("log_errors", 1); $maxtime = ini_get('max_execution_time'); @@ -65,15 +67,22 @@ $oPage->setBaseUrl(PROJECT_URI); $oPage->zone("navbar")->addBlock(new \BaikalAdmin\Controller\Navigation\Topbar\Install()); -if (!defined("BAIKAL_CONFIGURED_VERSION")) { +try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); +} catch (\Exception $e) { $config = null; } +try { + $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); +} catch (\Exception $e) { $configSystem = null; } + +if (!$configSystem || !isset($configSystem['parameters']["BAIKAL_CONFIGURED_VERSION"])) { # we have to upgrade Baïkal (existing installation) $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Initialize()); -} elseif (!defined("BAIKAL_ADMIN_PASSWORDHASH")) { +} elseif (!$config || !isset($config['parameters']["BAIKAL_ADMIN_PASSWORDHASH"])) { # we have to set an admin password $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Initialize()); } else { - if (BAIKAL_CONFIGURED_VERSION !== BAIKAL_VERSION) { + if ($configSystem['parameters']["BAIKAL_CONFIGURED_VERSION"] !== BAIKAL_VERSION) { # we have to upgrade Baïkal if (\Flake\Util\Tools::GET("upgradeConfirmed")) { $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\VersionUpgrade()); diff --git a/Core/Frameworks/Flake/Framework.php b/Core/Frameworks/Flake/Framework.php index 50b9c12..e28feaa 100644 --- a/Core/Frameworks/Flake/Framework.php +++ b/Core/Frameworks/Flake/Framework.php @@ -27,6 +27,8 @@ namespace Flake; +use Symfony\Component\Yaml\Yaml; + class Framework extends \Flake\Core\Framework { static function rmBeginSlash($sString) { @@ -150,6 +152,7 @@ class Framework extends \Flake\Core\Framework { define("PROJECT_PATH_CORE", PROJECT_PATH_ROOT . "Core/"); define("PROJECT_PATH_CORERESOURCES", PROJECT_PATH_CORE . "Resources/"); define("PROJECT_PATH_SPECIFIC", PROJECT_PATH_ROOT . "Specific/"); + define("PROJECT_PATH_CONFIG", PROJECT_PATH_ROOT . "config/"); define("PROJECT_PATH_FRAMEWORKS", PROJECT_PATH_CORE . "Frameworks/"); define("PROJECT_PATH_WWWROOT", PROJECT_PATH_CORE . "WWWRoot/"); @@ -206,88 +209,75 @@ class Framework extends \Flake\Core\Framework { define("FLAKE_URIPATH", \Flake\Util\Tools::stripBeginSlash($aUrlInfo["path"])); unset($aUrlInfo); - - # Include Project config - # NOTE: DB initialization and App config files inclusion - # do not break execution if not properly executed, as - # these errors will have to be caught later in the process - # notably by the App install tool, if available; breaking right now - # would forbid such install tool forwarding, for instance - - $sConfigPath = PROJECT_PATH_SPECIFIC . "config.php"; - $sConfigSystemPath = PROJECT_PATH_SPECIFIC . "config.system.php"; - - if (file_exists($sConfigPath)) { - require_once($sConfigPath); - } - - if (file_exists($sConfigSystemPath)) { - require_once($sConfigSystemPath); - } - self::initDb(); } protected static function initDb() { - # Dont init db on install, but in normal mode and when upgrading - if (defined("BAIKAL_CONTEXT_INSTALL") && (!defined('BAIKAL_CONFIGURED_VERSION') || BAIKAL_CONFIGURED_VERSION === BAIKAL_VERSION)) { + + try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + } catch(\Exception $e) { return true; } - if (defined("PROJECT_DB_MYSQL") && PROJECT_DB_MYSQL === true) { - self::initDbMysql(); + # Dont init db on install, but in normal mode and when upgrading + if (defined("BAIKAL_CONTEXT_INSTALL") && (!isset($config['parameters']['BAIKAL_CONFIGURED_VERSION']) || $config['parameters']['BAIKAL_CONFIGURED_VERSION'] === BAIKAL_VERSION)) { + return true; + } + if ($config['parameters']['PROJECT_DB_MYSQL'] === true) { + self::initDbMysql($config); } else { - self::initDbSqlite(); + self::initDbSqlite($config); } } - protected static function initDbSqlite() { + protected static function initDbSqlite(array $config) { # Asserting DB filepath is set - if (!defined("PROJECT_SQLITE_FILE")) { + if (!$config['parameters']['PROJECT_SQLITE_FILE']) { return false; } # Asserting DB file is writable - if (file_exists(PROJECT_SQLITE_FILE) && !is_writable(PROJECT_SQLITE_FILE)) { - die("

DB file is not writable. Please give write permissions on file '" . PROJECT_SQLITE_FILE . "'

"); + if (file_exists($config['parameters']['PROJECT_SQLITE_FILE']) && !is_writable($config['parameters']['PROJECT_SQLITE_FILE'])) { + die("

DB file is not writable. Please give write permissions on file '" . $config['parameters']['PROJECT_SQLITE_FILE'] . "'

"); } # Asserting DB directory is writable - if (!is_writable(dirname(PROJECT_SQLITE_FILE))) { - die("

The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder '" . dirname(PROJECT_SQLITE_FILE) . "'

"); + if (!is_writable(dirname($config['parameters']['PROJECT_SQLITE_FILE']))) { + die("

The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder '" . dirname($config['parameters']['PROJECT_SQLITE_FILE']) . "'

"); } - if (file_exists(PROJECT_SQLITE_FILE) && is_readable(PROJECT_SQLITE_FILE) && !isset($GLOBALS["DB"])) { - $GLOBALS["DB"] = new \Flake\Core\Database\Sqlite(PROJECT_SQLITE_FILE); + if (file_exists($config['parameters']['PROJECT_SQLITE_FILE']) && is_readable($config['parameters']['PROJECT_SQLITE_FILE']) && !isset($GLOBALS["DB"])) { + $GLOBALS["DB"] = new \Flake\Core\Database\Sqlite($config['parameters']['PROJECT_SQLITE_FILE']); return true; } return false; } - protected static function initDbMysql() { + protected static function initDbMysql(array $config) { - if (!defined("PROJECT_DB_MYSQL_HOST")) { + if (!$config['parameters']['PROJECT_DB_MYSQL_HOST']) { die("

The constant PROJECT_DB_MYSQL_HOST, containing the MySQL host name, is not set.
You should set it in Specific/config.system.php

"); } - if (!defined("PROJECT_DB_MYSQL_DBNAME")) { + if (!$config['parameters']['PROJECT_DB_MYSQL_DBNAME']) { die("

The constant PROJECT_DB_MYSQL_DBNAME, containing the MySQL database name, is not set.
You should set it in Specific/config.system.php

"); } - if (!defined("PROJECT_DB_MYSQL_USERNAME")) { + if (!$config['parameters']['PROJECT_DB_MYSQL_USERNAME']) { die("

The constant PROJECT_DB_MYSQL_USERNAME, containing the MySQL database username, is not set.
You should set it in Specific/config.system.php

"); } - if (!defined("PROJECT_DB_MYSQL_PASSWORD")) { + if (!$config['parameters']['PROJECT_DB_MYSQL_PASSWORD']) { die("

The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.
You should set it in Specific/config.system.php

"); } try { $GLOBALS["DB"] = new \Flake\Core\Database\Mysql( - PROJECT_DB_MYSQL_HOST, - PROJECT_DB_MYSQL_DBNAME, - PROJECT_DB_MYSQL_USERNAME, - PROJECT_DB_MYSQL_PASSWORD + $config['parameters']['PROJECT_DB_MYSQL_HOST'], + $config['parameters']['PROJECT_DB_MYSQL_DBNAME'], + $config['parameters']['PROJECT_DB_MYSQL_USERNAME'], + $config['parameters']['PROJECT_DB_MYSQL_PASSWORD'] ); # We now setup t6he connexion to use UTF8 diff --git a/html/cal.php b/html/cal.php index 0992bff..682de32 100644 --- a/html/cal.php +++ b/html/cal.php @@ -24,6 +24,8 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use Symfony\Component\Yaml\Yaml; + ini_set("session.cookie_httponly", 1); ini_set("display_errors", 0); ini_set("log_errors", 1); @@ -47,19 +49,26 @@ require PROJECT_PATH_ROOT . 'vendor/autoload.php'; # Bootstraping Flake \Flake\Framework::bootstrap(); + # Bootstrapping Baïkal \Baikal\Framework::bootstrap(); -if (!defined("BAIKAL_CAL_ENABLED") || BAIKAL_CAL_ENABLED !== true) { +try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); +} catch (\Exception $e) { + die('

Incomplete installation

Baïkal is missing its configuration file, or its configuration file is unreadable.'); +} + +if (!isset($config['parameters']["BAIKAL_CAL_ENABLED"]) || $config['parameters']["BAIKAL_CAL_ENABLED"] !== true) { throw new ErrorException("Baikal CalDAV is disabled.", 0, 255, __FILE__, __LINE__); } $server = new \Baikal\Core\Server( - BAIKAL_CAL_ENABLED, - BAIKAL_CARD_ENABLED, - BAIKAL_DAV_AUTH_TYPE, - BAIKAL_AUTH_REALM, + $config['parameters']["BAIKAL_CAL_ENABLED"], + $config['parameters']["BAIKAL_CARD_ENABLED"], + $config['parameters']["BAIKAL_DAV_AUTH_TYPE"], + $config['parameters']["BAIKAL_AUTH_REALM"], $GLOBALS['DB']->getPDO(), - BAIKAL_CAL_BASEURI + PROJECT_BASEURI . 'cal.php/' ); $server->start(); diff --git a/html/card.php b/html/card.php index 5501ca1..9946066 100644 --- a/html/card.php +++ b/html/card.php @@ -24,6 +24,8 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use Symfony\Component\Yaml\Yaml; + ini_set("session.cookie_httponly", 1); ini_set("display_errors", 0); ini_set("log_errors", 1); @@ -51,16 +53,23 @@ require PROJECT_PATH_ROOT . 'vendor/autoload.php'; # Bootstrapping Baïkal \Baikal\Framework::bootstrap(); -if (!defined("BAIKAL_CARD_ENABLED") || BAIKAL_CARD_ENABLED !== true) { + +try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); +} catch (\Exception $e) { + die('

Incomplete installation

Baïkal is missing its configuration file, or its configuration file is unreadable.'); +} + +if (!isset($config['parameters']["BAIKAL_CARD_ENABLED"]) || $config['parameters']["BAIKAL_CARD_ENABLED"] !== true) { throw new ErrorException("Baikal CardDAV is disabled.", 0, 255, __FILE__, __LINE__); } $server = new \Baikal\Core\Server( - BAIKAL_CAL_ENABLED, - BAIKAL_CARD_ENABLED, - BAIKAL_DAV_AUTH_TYPE, - BAIKAL_AUTH_REALM, + $config['parameters']["BAIKAL_CAL_ENABLED"], + $config['parameters']["BAIKAL_CARD_ENABLED"], + $config['parameters']["BAIKAL_DAV_AUTH_TYPE"], + $config['parameters']["BAIKAL_AUTH_REALM"], $GLOBALS['DB']->getPDO(), - BAIKAL_CARD_BASEURI + PROJECT_BASEURI . 'card.php/' ); $server->start(); diff --git a/html/dav.php b/html/dav.php index 12429e5..dfd43d0 100644 --- a/html/dav.php +++ b/html/dav.php @@ -24,6 +24,8 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use Symfony\Component\Yaml\Yaml; + ini_set("session.cookie_httponly", 1); ini_set("display_errors", 0); ini_set("log_errors", 1); @@ -50,12 +52,18 @@ require PROJECT_PATH_ROOT . 'vendor/autoload.php'; # Bootstrapping Baïkal \Baikal\Framework::bootstrap(); +try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); +} catch (\Exception $e) { + die('

Incomplete installation

Baïkal is missing its configuration file, or its configuration file is unreadable.'); +} + $server = new \Baikal\Core\Server( - BAIKAL_CAL_ENABLED, - BAIKAL_CARD_ENABLED, - BAIKAL_DAV_AUTH_TYPE, - BAIKAL_AUTH_REALM, + $config['parameters']["BAIKAL_CAL_ENABLED"], + $config['parameters']["BAIKAL_CARD_ENABLED"], + $config['parameters']["BAIKAL_DAV_AUTH_TYPE"], + $config['parameters']["BAIKAL_AUTH_REALM"], $GLOBALS['DB']->getPDO(), - BAIKAL_DAV_BASEURI + PROJECT_BASEURI . 'dav.php/' ); $server->start(); From 4ddcb165e0588543ee2d2d62548f535935beca8a Mon Sep 17 00:00:00 2001 From: Cyril Date: Mon, 14 Oct 2019 12:23:50 +0200 Subject: [PATCH 02/29] Add symfony/ymal as a composer dependency --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b19af8e..09a2880 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "require": { "php" : "^7.0", "sabre/dav" : "~4.0.1", - "twig/twig" : "~1.8.0" + "twig/twig" : "~1.8.0", + "symfony/yaml": "^4.3" }, "require-dev" : { "sabre/cs" : "~0.0.6" From 2136a03ca84da7ff28a410198aa5988f1cc5b27c Mon Sep 17 00:00:00 2001 From: Cyril Date: Mon, 14 Oct 2019 12:24:02 +0200 Subject: [PATCH 03/29] Minor fixes in the composer.json file --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 09a2880..7d1aa4f 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fruux/baikal", - "description": "Baïkal is a lightweight CalDAV + CardDAV server based on PHP, SQLite and SabreDAV", + "description": "Baïkal is a lightweight CalDAV + CardDAV server based on PHP, SQLite or MySQLc and SabreDAV", "keywords": ["Framework", "WebDAV", "CalDAV", "CardDAV", "iCalendar"], "homepage": "http://sabre.io/baikal/", "license" : "GPL-3.0", @@ -32,6 +32,6 @@ } }, "support" : { - "source" : "https://github.com/fruux/Baikal" + "source" : "https://github.com/sabre-io/Baikal" } } From 616cf82516adc3fab4d1630dcc9ee46ea4f30ec5 Mon Sep 17 00:00:00 2001 From: Cyril Date: Mon, 14 Oct 2019 12:26:28 +0200 Subject: [PATCH 04/29] Add dist config files, improve .gitignore --- .gitignore | 7 +++++-- config/config.yaml.dist | 8 ++++++++ config/system.yaml.dist | 9 +++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 config/config.yaml.dist create mode 100644 config/system.yaml.dist diff --git a/.gitignore b/.gitignore index 8adf1ca..cc1627e 100755 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,8 @@ logs # Specific -Specific/config.php -Specific/config.system.php +config/config.yaml +config/system.yaml Specific/INSTALL_DISABLED # Composer stuff @@ -15,3 +15,6 @@ vendor # Vim .*.swp + +# Others +.DS_Store diff --git a/config/config.yaml.dist b/config/config.yaml.dist new file mode 100644 index 0000000..314efe1 --- /dev/null +++ b/config/config.yaml.dist @@ -0,0 +1,8 @@ +parameters: + PROJECT_TIMEZONE: 'Europe/Paris' + BAIKAL_CARD_ENABLED: true + BAIKAL_CAL_ENABLED: true + BAIKAL_INVITE_FROM: 'noreply@localhost' + BAIKAL_DAV_AUTH_TYPE: 'Digest' + BAIKAL_ADMIN_PASSWORDHASH: 5fe794627e1f841f8debba065e2c807a + BAIKAL_AUTH_REALM: BaikalDAV \ No newline at end of file diff --git a/config/system.yaml.dist b/config/system.yaml.dist new file mode 100644 index 0000000..36d7d0f --- /dev/null +++ b/config/system.yaml.dist @@ -0,0 +1,9 @@ +parameters: + PROJECT_SQLITE_FILE: "absolute/path/to/Specific/db/db.sqlite" + PROJECT_DB_MYSQL: true + PROJECT_DB_MYSQL_HOST: 'localhost' + PROJECT_DB_MYSQL_DBNAME: 'baikal' + PROJECT_DB_MYSQL_USERNAME: 'baikal' + PROJECT_DB_MYSQL_PASSWORD: 'baikal' + BAIKAL_ENCRYPTION_KEY: '5d3f0fa0192e3058ea70f1bb20924add' + BAIKAL_CONFIGURED_VERSION: '0.6.0' \ No newline at end of file From ba8b16d5ede9f5e678f2fdf10830bbbcdcd91b14 Mon Sep 17 00:00:00 2001 From: Cyril Date: Mon, 14 Oct 2019 12:39:58 +0200 Subject: [PATCH 05/29] Improve some error messages, add missing "use" --- Core/Frameworks/Baikal/Model/User.php | 4 +++- Core/Frameworks/Flake/Framework.php | 8 ++++---- Makefile | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Core/Frameworks/Baikal/Model/User.php b/Core/Frameworks/Baikal/Model/User.php index 2988622..66a5d30 100644 --- a/Core/Frameworks/Baikal/Model/User.php +++ b/Core/Frameworks/Baikal/Model/User.php @@ -27,6 +27,8 @@ namespace Baikal\Model; +use Symfony\Component\Yaml\Yaml; + class User extends \Flake\Core\Model\Db { const DATATABLE = "users"; const PRIMARYKEY = "id"; @@ -281,7 +283,7 @@ class User extends \Flake\Core\Model\Db { function getPasswordHashForPassword($sPassword) { try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); } catch(\Exception $e) {} return md5($this->get("username") . ':' . $config['parameters']['BAIKAL_AUTH_REALM'] . ':' . $sPassword); diff --git a/Core/Frameworks/Flake/Framework.php b/Core/Frameworks/Flake/Framework.php index e28feaa..a2d125d 100644 --- a/Core/Frameworks/Flake/Framework.php +++ b/Core/Frameworks/Flake/Framework.php @@ -257,19 +257,19 @@ class Framework extends \Flake\Core\Framework { protected static function initDbMysql(array $config) { if (!$config['parameters']['PROJECT_DB_MYSQL_HOST']) { - die("

The constant PROJECT_DB_MYSQL_HOST, containing the MySQL host name, is not set.
You should set it in Specific/config.system.php

"); + die("

The constant PROJECT_DB_MYSQL_HOST, containing the MySQL host name, is not set.
You should set it in config/system.yaml

"); } if (!$config['parameters']['PROJECT_DB_MYSQL_DBNAME']) { - die("

The constant PROJECT_DB_MYSQL_DBNAME, containing the MySQL database name, is not set.
You should set it in Specific/config.system.php

"); + die("

The constant PROJECT_DB_MYSQL_DBNAME, containing the MySQL database name, is not set.
You should set it in config/system.yaml

"); } if (!$config['parameters']['PROJECT_DB_MYSQL_USERNAME']) { - die("

The constant PROJECT_DB_MYSQL_USERNAME, containing the MySQL database username, is not set.
You should set it in Specific/config.system.php

"); + die("

The constant PROJECT_DB_MYSQL_USERNAME, containing the MySQL database username, is not set.
You should set it in config/system.yaml

"); } if (!$config['parameters']['PROJECT_DB_MYSQL_PASSWORD']) { - die("

The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.
You should set it in Specific/config.system.php

"); + die("

The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.
You should set it in config/system.yaml

"); } try { diff --git a/Makefile b/Makefile index 2332554..912f73c 100644 --- a/Makefile +++ b/Makefile @@ -31,4 +31,4 @@ composer.lock: composer.json clean: # Wipe out all local data, and go back to a clean install - rm Specific/config.php Specific/config.system.php Specific/db/db.sqlite; true + rm config/config.yaml config/system.yaml Specific/db/db.sqlite; true From 4852f06ed4a594ddd858fba7002d5b21d6d1a721 Mon Sep 17 00:00:00 2001 From: Cyril Date: Mon, 14 Oct 2019 14:46:22 +0200 Subject: [PATCH 06/29] Correct more labels, use System instead of Database for settings --- Core/Frameworks/BaikalAdmin/Controller/Install/Database.php | 4 ++-- Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php | 4 ++-- Core/Frameworks/Flake/Framework.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php index 418b14e..2ceadad 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php @@ -36,7 +36,7 @@ class Database extends \Flake\Core\Controller { protected $oForm; # \Formal\Form function execute() { - $this->oModel = new \Baikal\Model\Config\Database(PROJECT_PATH_CONFIG . "system.yaml"); + $this->oModel = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); $this->oForm = $this->oModel->formForThisModelInstance([ "close" => false, @@ -62,7 +62,7 @@ class Database extends \Flake\Core\Controller { if ($this->oForm->persisted()) { - $sMessage = "

Baïkal is now installed, and it's database properly configured. For security reasons, this installation wizard is now disabled.

"; + $sMessage = "

Baïkal is now installed, and its database properly configured. For security reasons, this installation wizard is now disabled.

"; $sMessage . "

 

"; $sMessage .= "

Start using Baïkal

"; $sForm = ""; diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index cf9fae3..c639631 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -36,9 +36,9 @@ class Initialize extends \Flake\Core\Controller { function execute() { # Assert that /Specific is writable - if (!file_exists(PROJECT_PATH_SPECIFIC) || !is_dir(PROJECT_PATH_SPECIFIC) || !is_writable(PROJECT_PATH_SPECIFIC)) { + if (!file_exists(PROJECT_PATH_SPECIFIC) || !is_dir(PROJECT_PATH_SPECIFIC) || !is_writable(PROJECT_PATH_SPECIFIC) || !file_exists(PROJECT_PATH_CONFIG) || !is_dir(PROJECT_PATH_CONFIG) || !is_writable(PROJECT_PATH_CONFIG)) { $message = "

Error - Insufficient permissions on the Specific/ folder

"; - $message .= "

In order to work properly, Baïkal needs to have write permissions in the Specific/ folder.

"; + $message .= "

In order to work properly, Baïkal needs to have write permissions in the Specific/ and config/ folder.

"; die($message); } diff --git a/Core/Frameworks/Flake/Framework.php b/Core/Frameworks/Flake/Framework.php index a2d125d..00662cc 100644 --- a/Core/Frameworks/Flake/Framework.php +++ b/Core/Frameworks/Flake/Framework.php @@ -283,7 +283,7 @@ class Framework extends \Flake\Core\Framework { # We now setup t6he connexion to use UTF8 $GLOBALS["DB"]->query("SET NAMES UTF8"); } catch (\Exception $e) { - die("

Baïkal was not able to establish a connexion to the configured MySQL database (as configured in Specific/config.system.php).

"); + die("

Baïkal was not able to establish a connexion to the configured MySQL database (as configured in config/system.yaml).

"); } return true; From 0d3f4969cf6747165e4009cfc25c085d670b6a87 Mon Sep 17 00:00:00 2001 From: Cyril Date: Mon, 14 Oct 2019 15:33:06 +0200 Subject: [PATCH 07/29] Coin version 0.7.0, improve upgrade path --- Core/Distrib.php | 2 +- .../Controller/Install/Database.php | 12 ++++++++++++ .../Controller/Install/Initialize.php | 18 ++++++++++++++++++ .../Controller/Install/VersionUpgrade.php | 12 ++++++------ config/system.yaml.dist | 2 +- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Core/Distrib.php b/Core/Distrib.php index 18af561..125aeff 100644 --- a/Core/Distrib.php +++ b/Core/Distrib.php @@ -24,5 +24,5 @@ # This copyright notice MUST APPEAR in all copies of the script! ################################################################# -define("BAIKAL_VERSION", "0.6.0"); +define("BAIKAL_VERSION", "0.7.0"); define("BAIKAL_HOMEPAGE", "http://sabre.io/baikal/"); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php index 2ceadad..728a13c 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php @@ -38,6 +38,17 @@ class Database extends \Flake\Core\Controller { function execute() { $this->oModel = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); + if (file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) { + require_once(PROJECT_PATH_SPECIFIC . "config.system.php"); + $this->oModel->set('PROJECT_SQLITE_FILE',PROJECT_SQLITE_FILE); + $this->oModel->set('PROJECT_DB_MYSQL',PROJECT_DB_MYSQL); + $this->oModel->set('PROJECT_DB_MYSQL_HOST',PROJECT_DB_MYSQL_HOST); + $this->oModel->set('PROJECT_DB_MYSQL_DBNAME',PROJECT_DB_MYSQL_DBNAME); + $this->oModel->set('PROJECT_DB_MYSQL_USERNAME',PROJECT_DB_MYSQL_USERNAME); + $this->oModel->set('PROJECT_DB_MYSQL_PASSWORD',PROJECT_DB_MYSQL_PASSWORD); + $this->oModel->set('BAIKAL_ENCRYPTION_KEY',BAIKAL_ENCRYPTION_KEY); + } + $this->oForm = $this->oModel->formForThisModelInstance([ "close" => false, "hook.validation" => [$this, "validateConnection"], @@ -48,6 +59,7 @@ class Database extends \Flake\Core\Controller { $this->oForm->execute(); if ($this->oForm->persisted()) { + unlink(PROJECT_PATH_SPECIFIC . "config.system.php"); touch(PROJECT_PATH_SPECIFIC . '/INSTALL_DISABLED'); } } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index c639631..becc1ca 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -47,6 +47,16 @@ class Initialize extends \Flake\Core\Controller { $this->oModel = new \Baikal\Model\Config\Standard(PROJECT_PATH_CONFIG . "config.yaml"); + // If we come from pre-0.7.0, we need to get the values from the config.php and config.system.php files + if (file_exists(PROJECT_PATH_SPECIFIC . "config.php")) { + require_once(PROJECT_PATH_SPECIFIC . "config.php"); + $this->oModel->set('PROJECT_TIMEZONE', PROJECT_TIMEZONE); + $this->oModel->set('BAIKAL_CARD_ENABLED', BAIKAL_CARD_ENABLED); + $this->oModel->set('BAIKAL_CAL_ENABLED', BAIKAL_CAL_ENABLED); + $this->oModel->set('BAIKAL_INVITE_FROM', BAIKAL_INVITE_FROM); + $this->oModel->set('BAIKAL_DAV_AUTH_TYPE', BAIKAL_DAV_AUTH_TYPE); + } + $this->oForm = $this->oModel->formForThisModelInstance([ "close" => false ]); @@ -56,6 +66,14 @@ class Initialize extends \Flake\Core\Controller { if ($this->oForm->persisted()) { + // If we come from pre-0.7.0, we need to remove the INSTALL_DISABLED file so we go to the next step + if (file_exists(PROJECT_PATH_SPECIFIC . '/INSTALL_DISABLED')) { + unlink(PROJECT_PATH_SPECIFIC . '/INSTALL_DISABLED'); + } + if (file_exists(PROJECT_PATH_SPECIFIC . "config.php")) { + unlink(PROJECT_PATH_SPECIFIC . "config.php"); + } + # Creating system config, and initializing BAIKAL_ENCRYPTION_KEY $oSystemConfig = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); $oSystemConfig->set("BAIKAL_ENCRYPTION_KEY", md5(microtime() . rand())); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php index 3669833..05920ea 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php @@ -525,24 +525,24 @@ SQL protected function updateConfiguredVersion($sVersionTo) { # Create new settings - $oConfig = new \Baikal\Model\Config\Standard(PROJECT_PATH_SPECIFIC . "config.php"); + $oConfig = new \Baikal\Model\Config\Standard(PROJECT_PATH_CONFIG . "config.yaml"); $oConfig->persist(); # Update BAIKAL_CONFIGURED_VERSION - $oConfig = new \Baikal\Model\Config\System(PROJECT_PATH_SPECIFIC . "config.system.php"); + $oConfig = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); $oConfig->set("BAIKAL_CONFIGURED_VERSION", $sVersionTo); $oConfig->persist(); } protected function assertConfigWritable() { # Parsing the config also makes sure that it is not malformed - $oConfig = new \Baikal\Model\Config\Standard(PROJECT_PATH_SPECIFIC . "config.php"); + $oConfig = new \Baikal\Model\Config\Standard(PROJECT_PATH_CONFIG . "config.yaml"); if ($oConfig->writable() === false) { - throw new \Exception(PROJECT_PATH_SPECIFIC . "config.php is not writable"); + throw new \Exception(PROJECT_PATH_CONFIG . "config.yaml is not writable"); } - $oConfig = new \Baikal\Model\Config\System(PROJECT_PATH_SPECIFIC . "config.system.php"); + $oConfig = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); if ($oConfig->writable() === false) { - throw new \Exception(PROJECT_PATH_SPECIFIC . "config.system.php is not writable"); + throw new \Exception(PROJECT_PATH_CONFIG . "system.yaml is not writable"); } } } diff --git a/config/system.yaml.dist b/config/system.yaml.dist index 36d7d0f..a03b7db 100644 --- a/config/system.yaml.dist +++ b/config/system.yaml.dist @@ -6,4 +6,4 @@ parameters: PROJECT_DB_MYSQL_USERNAME: 'baikal' PROJECT_DB_MYSQL_PASSWORD: 'baikal' BAIKAL_ENCRYPTION_KEY: '5d3f0fa0192e3058ea70f1bb20924add' - BAIKAL_CONFIGURED_VERSION: '0.6.0' \ No newline at end of file + BAIKAL_CONFIGURED_VERSION: '0.7.0' \ No newline at end of file From 0b3ecbaf0b1df5fb18c11866e588c571acb052a8 Mon Sep 17 00:00:00 2001 From: Cyril Date: Mon, 14 Oct 2019 15:38:32 +0200 Subject: [PATCH 08/29] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f9e378..f18eb7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ ChangeLog ========= +0.7.0 (2019-10-14) +------------------ + +* Changed to YAML configuration files +* Minor configuration improvements + 0.6.0 (2019-08-25) ------------------ From 80f272af251a7496e8c45ee3324091769f291ddf Mon Sep 17 00:00:00 2001 From: Cyril Date: Mon, 14 Oct 2019 16:05:49 +0200 Subject: [PATCH 09/29] Use config in Server.php file --- Core/Frameworks/Baikal/Core/Server.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Core/Frameworks/Baikal/Core/Server.php b/Core/Frameworks/Baikal/Core/Server.php index b62d0aa..22ae7fe 100644 --- a/Core/Frameworks/Baikal/Core/Server.php +++ b/Core/Frameworks/Baikal/Core/Server.php @@ -28,6 +28,7 @@ namespace Baikal\Core; use PDO; +use Symfony\Component\Yaml\Yaml; /** * The Baikal Server @@ -131,6 +132,10 @@ class Server { */ protected function initServer() { + try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + } catch (\Exception $e) {} + if ($this->authType === 'Basic') { $authBackend = new \Baikal\Core\PDOBasicAuth($this->pdo, $this->authRealm); } else { @@ -171,8 +176,8 @@ class Server { $this->server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin()); $this->server->addPlugin(new \Sabre\DAV\Sharing\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\SharingPlugin()); - if (defined("BAIKAL_INVITE_FROM") && BAIKAL_INVITE_FROM !== "") { - $this->server->addPlugin(new \Sabre\CalDAV\Schedule\IMipPlugin(BAIKAL_INVITE_FROM)); + if (isset($config['parameters']["BAIKAL_INVITE_FROM"]) && $config['parameters']["BAIKAL_INVITE_FROM"] !== "") { + $this->server->addPlugin(new \Sabre\CalDAV\Schedule\IMipPlugin($config['parameters']["BAIKAL_INVITE_FROM"])); } } if ($this->enableCardDAV) { From edbc8171c347581399ead843c963baa9b9b9d14f Mon Sep 17 00:00:00 2001 From: Cyril Date: Mon, 14 Oct 2019 16:06:58 +0200 Subject: [PATCH 10/29] Fix typo --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7d1aa4f..c1897b8 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fruux/baikal", - "description": "Baïkal is a lightweight CalDAV + CardDAV server based on PHP, SQLite or MySQLc and SabreDAV", + "description": "Baïkal is a lightweight CalDAV + CardDAV server based on PHP, SQLite or MySQL, and SabreDAV", "keywords": ["Framework", "WebDAV", "CalDAV", "CardDAV", "iCalendar"], "homepage": "http://sabre.io/baikal/", "license" : "GPL-3.0", From befb2b69ca2a9652a9b5a015ac550f6937f5e98a Mon Sep 17 00:00:00 2001 From: Cyril Date: Tue, 15 Oct 2019 10:03:57 +0200 Subject: [PATCH 11/29] Fix style with sabre/cs --- Core/Frameworks/Baikal/Model/Config.php | 2 +- Core/Frameworks/Baikal/Model/Config/Standard.php | 14 +++++++------- Core/Frameworks/Baikal/Model/Config/System.php | 10 +++++----- Core/Frameworks/Baikal/Model/User.php | 2 +- .../BaikalAdmin/Controller/Install/Database.php | 14 +++++++------- .../BaikalAdmin/Controller/Settings/System.php | 2 +- Core/Frameworks/Flake/Framework.php | 2 +- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Core/Frameworks/Baikal/Model/Config.php b/Core/Frameworks/Baikal/Model/Config.php index c028d1f..4509410 100644 --- a/Core/Frameworks/Baikal/Model/Config.php +++ b/Core/Frameworks/Baikal/Model/Config.php @@ -42,7 +42,7 @@ abstract class Config extends \Flake\Core\Model\NoDb { try { $config = Yaml::parseFile($this->sConfigFilePath); $aConfig = $config['parameters']; - } catch(\Exception $e) { + } catch (\Exception $e) { $aConfig = static::getDefaultConfig(); } diff --git a/Core/Frameworks/Baikal/Model/Config/Standard.php b/Core/Frameworks/Baikal/Model/Config/Standard.php index 28fdd04..bf764ed 100644 --- a/Core/Frameworks/Baikal/Model/Config/Standard.php +++ b/Core/Frameworks/Baikal/Model/Config/Standard.php @@ -115,7 +115,7 @@ class Standard extends \Baikal\Model\Config { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); - } catch(\Exception $e) {} + } catch (\Exception $e) {} if (!isset($config['parameters']["BAIKAL_ADMIN_PASSWORDHASH"]) || trim($config['parameters']["BAIKAL_ADMIN_PASSWORDHASH"]) === "") { @@ -162,13 +162,13 @@ class Standard extends \Baikal\Model\Config { protected static function getDefaultConfig() { return [ - "PROJECT_TIMEZONE" => "Europe/Paris", - "BAIKAL_CARD_ENABLED" => true, - "BAIKAL_CAL_ENABLED" => true, - "BAIKAL_INVITE_FROM" => "noreply@" . $_SERVER['SERVER_NAME'], - "BAIKAL_DAV_AUTH_TYPE" => "Digest", + "PROJECT_TIMEZONE" => "Europe/Paris", + "BAIKAL_CARD_ENABLED" => true, + "BAIKAL_CAL_ENABLED" => true, + "BAIKAL_INVITE_FROM" => "noreply@" . $_SERVER['SERVER_NAME'], + "BAIKAL_DAV_AUTH_TYPE" => "Digest", "BAIKAL_ADMIN_PASSWORDHASH" => "", - "BAIKAL_AUTH_REALM" => "BaikalDAV", + "BAIKAL_AUTH_REALM" => "BaikalDAV", ]; } } diff --git a/Core/Frameworks/Baikal/Model/Config/System.php b/Core/Frameworks/Baikal/Model/Config/System.php index d73b152..55c07b6 100644 --- a/Core/Frameworks/Baikal/Model/Config/System.php +++ b/Core/Frameworks/Baikal/Model/Config/System.php @@ -125,13 +125,13 @@ class System extends \Baikal\Model\Config { protected static function getDefaultConfig() { return [ - "PROJECT_SQLITE_FILE" => "db/db.sqlite", - "PROJECT_DB_MYSQL" => false, - "PROJECT_DB_MYSQL_HOST" => "", - "PROJECT_DB_MYSQL_DBNAME" => "", + "PROJECT_SQLITE_FILE" => "db/db.sqlite", + "PROJECT_DB_MYSQL" => false, + "PROJECT_DB_MYSQL_HOST" => "", + "PROJECT_DB_MYSQL_DBNAME" => "", "PROJECT_DB_MYSQL_USERNAME" => "", "PROJECT_DB_MYSQL_PASSWORD" => "", - "BAIKAL_ENCRYPTION_KEY" => "", + "BAIKAL_ENCRYPTION_KEY" => "", "BAIKAL_CONFIGURED_VERSION" => BAIKAL_VERSION ]; } diff --git a/Core/Frameworks/Baikal/Model/User.php b/Core/Frameworks/Baikal/Model/User.php index 66a5d30..df91ea8 100644 --- a/Core/Frameworks/Baikal/Model/User.php +++ b/Core/Frameworks/Baikal/Model/User.php @@ -284,7 +284,7 @@ class User extends \Flake\Core\Model\Db { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); - } catch(\Exception $e) {} + } catch (\Exception $e) {} return md5($this->get("username") . ':' . $config['parameters']['BAIKAL_AUTH_REALM'] . ':' . $sPassword); } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php index 728a13c..97d169b 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php @@ -40,13 +40,13 @@ class Database extends \Flake\Core\Controller { if (file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) { require_once(PROJECT_PATH_SPECIFIC . "config.system.php"); - $this->oModel->set('PROJECT_SQLITE_FILE',PROJECT_SQLITE_FILE); - $this->oModel->set('PROJECT_DB_MYSQL',PROJECT_DB_MYSQL); - $this->oModel->set('PROJECT_DB_MYSQL_HOST',PROJECT_DB_MYSQL_HOST); - $this->oModel->set('PROJECT_DB_MYSQL_DBNAME',PROJECT_DB_MYSQL_DBNAME); - $this->oModel->set('PROJECT_DB_MYSQL_USERNAME',PROJECT_DB_MYSQL_USERNAME); - $this->oModel->set('PROJECT_DB_MYSQL_PASSWORD',PROJECT_DB_MYSQL_PASSWORD); - $this->oModel->set('BAIKAL_ENCRYPTION_KEY',BAIKAL_ENCRYPTION_KEY); + $this->oModel->set('PROJECT_SQLITE_FILE', PROJECT_SQLITE_FILE); + $this->oModel->set('PROJECT_DB_MYSQL', PROJECT_DB_MYSQL); + $this->oModel->set('PROJECT_DB_MYSQL_HOST', PROJECT_DB_MYSQL_HOST); + $this->oModel->set('PROJECT_DB_MYSQL_DBNAME', PROJECT_DB_MYSQL_DBNAME); + $this->oModel->set('PROJECT_DB_MYSQL_USERNAME', PROJECT_DB_MYSQL_USERNAME); + $this->oModel->set('PROJECT_DB_MYSQL_PASSWORD', PROJECT_DB_MYSQL_PASSWORD); + $this->oModel->set('BAIKAL_ENCRYPTION_KEY', BAIKAL_ENCRYPTION_KEY); } $this->oForm = $this->oModel->formForThisModelInstance([ diff --git a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php index 9f0dc1f..031d61e 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php @@ -70,7 +70,7 @@ class System extends \Flake\Core\Controller { } else { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); - } catch(\Exception $e) {} + } catch (\Exception $e) {} $bMySQL = $config['parameters']['PROJECT_DB_MYSQL'] ?? true; } diff --git a/Core/Frameworks/Flake/Framework.php b/Core/Frameworks/Flake/Framework.php index 00662cc..10ca51e 100644 --- a/Core/Frameworks/Flake/Framework.php +++ b/Core/Frameworks/Flake/Framework.php @@ -216,7 +216,7 @@ class Framework extends \Flake\Core\Framework { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); - } catch(\Exception $e) { + } catch (\Exception $e) { return true; } # Dont init db on install, but in normal mode and when upgrading From 94304207f825782b932b732737b4728987389a44 Mon Sep 17 00:00:00 2001 From: Cyril Date: Tue, 15 Oct 2019 10:13:50 +0200 Subject: [PATCH 12/29] Use symfony/yaml 3.4 for PHP 7.0.8, update dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c1897b8..3573c52 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "php" : "^7.0", "sabre/dav" : "~4.0.1", "twig/twig" : "~1.8.0", - "symfony/yaml": "^4.3" + "symfony/yaml" : "^3.4" }, "require-dev" : { "sabre/cs" : "~0.0.6" From 6fc334a75d9dae7f1e1f713da23ed9917976aee6 Mon Sep 17 00:00:00 2001 From: Cyril Date: Tue, 15 Oct 2019 12:09:55 +0200 Subject: [PATCH 13/29] Use lowercase for YAML configuration keys --- Core/Frameworks/Baikal/Model/User.php | 2 +- .../BaikalAdmin/Controller/Dashboard.php | 4 +-- .../Install/UpgradeConfirmation.php | 4 +-- .../Controller/Settings/System.php | 2 +- Core/Frameworks/BaikalAdmin/Core/Auth.php | 8 ++--- .../BaikalAdmin/WWWRoot/install/index.php | 6 ++-- Core/Frameworks/Flake/Framework.php | 34 +++++++++---------- config/config.yaml.dist | 14 ++++---- config/system.yaml.dist | 16 ++++----- html/cal.php | 10 +++--- html/card.php | 10 +++--- html/dav.php | 8 ++--- 12 files changed, 59 insertions(+), 59 deletions(-) diff --git a/Core/Frameworks/Baikal/Model/User.php b/Core/Frameworks/Baikal/Model/User.php index df91ea8..5e7649e 100644 --- a/Core/Frameworks/Baikal/Model/User.php +++ b/Core/Frameworks/Baikal/Model/User.php @@ -286,6 +286,6 @@ class User extends \Flake\Core\Model\Db { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); } catch (\Exception $e) {} - return md5($this->get("username") . ':' . $config['parameters']['BAIKAL_AUTH_REALM'] . ':' . $sPassword); + return md5($this->get("username") . ':' . $config['parameters']['baikal_auth_realm'] . ':' . $sPassword); } } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php b/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php index a20699d..7ac2ca7 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php @@ -42,8 +42,8 @@ class Dashboard extends \Flake\Core\Controller { $oView->setData("BAIKAL_VERSION", BAIKAL_VERSION); # Services status - $oView->setData("BAIKAL_CAL_ENABLED", $config['parameters']['BAIKAL_CAL_ENABLED']); - $oView->setData("BAIKAL_CARD_ENABLED", $config['parameters']['BAIKAL_CARD_ENABLED']); + $oView->setData("BAIKAL_CAL_ENABLED", $config['parameters']['baikal_cal_enabled']); + $oView->setData("BAIKAL_CARD_ENABLED", $config['parameters']['baikal_card_enabled']); # Statistics: Users $iNbUsers = \Baikal\Model\User::getBaseRequester()->count(); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php b/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php index 5dd20da..d0c26d7 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php @@ -41,8 +41,8 @@ class UpgradeConfirmation extends \Flake\Core\Controller { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); } catch (\Exception $e) {} - if (isset($config['parameters']['BAIKAL_CONFIGURED_VERSION']) && $config['parameters']['BAIKAL_CONFIGURED_VERSION'] === BAIKAL_VERSION) { - $sMessage = "Your system is configured to use version " . $config['parameters']['BAIKAL_CONFIGURED_VERSION'] . ".
There's no upgrade to be done."; + if (isset($config['parameters']['baikal_configured_version']) && $config['parameters']['baikal_configured_version'] === BAIKAL_VERSION) { + $sMessage = "Your system is configured to use version " . $config['parameters']['baikal_configured_version'] . ".
There's no upgrade to be done."; } else { $sMessage = "Upgrading Baïkal from version " . "Unknown" . " to version " . BAIKAL_VERSION . ""; } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php index 031d61e..e23445b 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php @@ -71,7 +71,7 @@ class System extends \Flake\Core\Controller { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); } catch (\Exception $e) {} - $bMySQL = $config['parameters']['PROJECT_DB_MYSQL'] ?? true; + $bMySQL = $config['parameters']['project_db_mysql'] ?? true; } if ($bMySQL === true) { diff --git a/Core/Frameworks/BaikalAdmin/Core/Auth.php b/Core/Frameworks/BaikalAdmin/Core/Auth.php index 57b053b..1eb1f08 100644 --- a/Core/Frameworks/BaikalAdmin/Core/Auth.php +++ b/Core/Frameworks/BaikalAdmin/Core/Auth.php @@ -34,7 +34,7 @@ class Auth { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); - if (isset($_SESSION["baikaladminauth"]) && $_SESSION["baikaladminauth"] === md5($config['parameters']['BAIKAL_ADMIN_PASSWORDHASH'])) { + if (isset($_SESSION["baikaladminauth"]) && $_SESSION["baikaladminauth"] === md5($config['parameters']['baikal_admin_passwordhash'])) { return true; } @@ -56,8 +56,8 @@ class Auth { } catch (\Exception $e) { } - if ($sUser === "admin" && $sPassHash === $config['parameters']['BAIKAL_ADMIN_PASSWORDHASH']) { - $_SESSION["baikaladminauth"] = md5($config['parameters']['BAIKAL_ADMIN_PASSWORDHASH']); + if ($sUser === "admin" && $sPassHash === $config['parameters']['baikal_admin_passwordhash']) { + $_SESSION["baikaladminauth"] = md5($config['parameters']['baikal_admin_passwordhash']); return true; } @@ -76,7 +76,7 @@ class Auth { } catch (\Exception $e) { } # Fallback to default value; useful when initializing App, as all constants are not set yet - $sAuthRealm = $config['parameters']['BAIKAL_AUTH_REALM'] ?? "BaikalDAV"; + $sAuthRealm = $config['parameters']['baikal_auth_realm'] ?? "BaikalDAV"; return md5('admin:' . $sAuthRealm . ':' . $sPassword); } diff --git a/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php b/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php index fd7035e..c87ce46 100644 --- a/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php +++ b/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php @@ -74,15 +74,15 @@ try { $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); } catch (\Exception $e) { $configSystem = null; } -if (!$configSystem || !isset($configSystem['parameters']["BAIKAL_CONFIGURED_VERSION"])) { +if (!$configSystem || !isset($configSystem['parameters']["baikal_configured_version"])) { # we have to upgrade Baïkal (existing installation) $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Initialize()); -} elseif (!$config || !isset($config['parameters']["BAIKAL_ADMIN_PASSWORDHASH"])) { +} elseif (!$config || !isset($config['parameters']["baikal_admin_passwordhash"])) { # we have to set an admin password $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Initialize()); } else { - if ($configSystem['parameters']["BAIKAL_CONFIGURED_VERSION"] !== BAIKAL_VERSION) { + if ($configSystem['parameters']["baikal_configured_version"] !== BAIKAL_VERSION) { # we have to upgrade Baïkal if (\Flake\Util\Tools::GET("upgradeConfirmed")) { $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\VersionUpgrade()); diff --git a/Core/Frameworks/Flake/Framework.php b/Core/Frameworks/Flake/Framework.php index 10ca51e..33ab054 100644 --- a/Core/Frameworks/Flake/Framework.php +++ b/Core/Frameworks/Flake/Framework.php @@ -220,10 +220,10 @@ class Framework extends \Flake\Core\Framework { return true; } # Dont init db on install, but in normal mode and when upgrading - if (defined("BAIKAL_CONTEXT_INSTALL") && (!isset($config['parameters']['BAIKAL_CONFIGURED_VERSION']) || $config['parameters']['BAIKAL_CONFIGURED_VERSION'] === BAIKAL_VERSION)) { + if (defined("BAIKAL_CONTEXT_INSTALL") && (!isset($config['parameters']['baikal_configured_version']) || $config['parameters']['baikal_configured_version'] === BAIKAL_VERSION)) { return true; } - if ($config['parameters']['PROJECT_DB_MYSQL'] === true) { + if ($config['parameters']['project_db_mysql'] === true) { self::initDbMysql($config); } else { self::initDbSqlite($config); @@ -232,22 +232,22 @@ class Framework extends \Flake\Core\Framework { protected static function initDbSqlite(array $config) { # Asserting DB filepath is set - if (!$config['parameters']['PROJECT_SQLITE_FILE']) { + if (!$config['parameters']['project_sqlite_file']) { return false; } # Asserting DB file is writable - if (file_exists($config['parameters']['PROJECT_SQLITE_FILE']) && !is_writable($config['parameters']['PROJECT_SQLITE_FILE'])) { - die("

DB file is not writable. Please give write permissions on file '" . $config['parameters']['PROJECT_SQLITE_FILE'] . "'

"); + if (file_exists($config['parameters']['project_sqlite_file']) && !is_writable($config['parameters']['project_sqlite_file'])) { + die("

DB file is not writable. Please give write permissions on file '" . $config['parameters']['project_sqlite_file'] . "'

"); } # Asserting DB directory is writable - if (!is_writable(dirname($config['parameters']['PROJECT_SQLITE_FILE']))) { - die("

The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder '" . dirname($config['parameters']['PROJECT_SQLITE_FILE']) . "'

"); + if (!is_writable(dirname($config['parameters']['project_sqlite_file']))) { + die("

The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder '" . dirname($config['parameters']['project_sqlite_file']) . "'

"); } - if (file_exists($config['parameters']['PROJECT_SQLITE_FILE']) && is_readable($config['parameters']['PROJECT_SQLITE_FILE']) && !isset($GLOBALS["DB"])) { - $GLOBALS["DB"] = new \Flake\Core\Database\Sqlite($config['parameters']['PROJECT_SQLITE_FILE']); + if (file_exists($config['parameters']['project_sqlite_file']) && is_readable($config['parameters']['project_sqlite_file']) && !isset($GLOBALS["DB"])) { + $GLOBALS["DB"] = new \Flake\Core\Database\Sqlite($config['parameters']['project_sqlite_file']); return true; } @@ -256,28 +256,28 @@ class Framework extends \Flake\Core\Framework { protected static function initDbMysql(array $config) { - if (!$config['parameters']['PROJECT_DB_MYSQL_HOST']) { + if (!$config['parameters']['project_db_mysql_host']) { die("

The constant PROJECT_DB_MYSQL_HOST, containing the MySQL host name, is not set.
You should set it in config/system.yaml

"); } - if (!$config['parameters']['PROJECT_DB_MYSQL_DBNAME']) { + if (!$config['parameters']['project_db_mysql_dbname']) { die("

The constant PROJECT_DB_MYSQL_DBNAME, containing the MySQL database name, is not set.
You should set it in config/system.yaml

"); } - if (!$config['parameters']['PROJECT_DB_MYSQL_USERNAME']) { + if (!$config['parameters']['project_db_mysql_username']) { die("

The constant PROJECT_DB_MYSQL_USERNAME, containing the MySQL database username, is not set.
You should set it in config/system.yaml

"); } - if (!$config['parameters']['PROJECT_DB_MYSQL_PASSWORD']) { + if (!$config['parameters']['project_db_mysql_password']) { die("

The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.
You should set it in config/system.yaml

"); } try { $GLOBALS["DB"] = new \Flake\Core\Database\Mysql( - $config['parameters']['PROJECT_DB_MYSQL_HOST'], - $config['parameters']['PROJECT_DB_MYSQL_DBNAME'], - $config['parameters']['PROJECT_DB_MYSQL_USERNAME'], - $config['parameters']['PROJECT_DB_MYSQL_PASSWORD'] + $config['parameters']['project_db_mysql_host'], + $config['parameters']['project_db_mysql_dbname'], + $config['parameters']['project_db_mysql_username'], + $config['parameters']['project_db_mysql_password'] ); # We now setup t6he connexion to use UTF8 diff --git a/config/config.yaml.dist b/config/config.yaml.dist index 314efe1..e71b59f 100644 --- a/config/config.yaml.dist +++ b/config/config.yaml.dist @@ -1,8 +1,8 @@ parameters: - PROJECT_TIMEZONE: 'Europe/Paris' - BAIKAL_CARD_ENABLED: true - BAIKAL_CAL_ENABLED: true - BAIKAL_INVITE_FROM: 'noreply@localhost' - BAIKAL_DAV_AUTH_TYPE: 'Digest' - BAIKAL_ADMIN_PASSWORDHASH: 5fe794627e1f841f8debba065e2c807a - BAIKAL_AUTH_REALM: BaikalDAV \ No newline at end of file + project_timezone: 'Europe/Paris' + baikal_card_enabled: true + baikal_cal_enabled: true + baikal_invite_from: 'noreply@localhost' + baikal_dav_auth_type: 'Digest' + baikal_admin_passwordhash: 5fe794627e1f841f8debba065e2c807a + baikal_auth_realm: BaikalDAV \ No newline at end of file diff --git a/config/system.yaml.dist b/config/system.yaml.dist index a03b7db..0ce1b68 100644 --- a/config/system.yaml.dist +++ b/config/system.yaml.dist @@ -1,9 +1,9 @@ parameters: - PROJECT_SQLITE_FILE: "absolute/path/to/Specific/db/db.sqlite" - PROJECT_DB_MYSQL: true - PROJECT_DB_MYSQL_HOST: 'localhost' - PROJECT_DB_MYSQL_DBNAME: 'baikal' - PROJECT_DB_MYSQL_USERNAME: 'baikal' - PROJECT_DB_MYSQL_PASSWORD: 'baikal' - BAIKAL_ENCRYPTION_KEY: '5d3f0fa0192e3058ea70f1bb20924add' - BAIKAL_CONFIGURED_VERSION: '0.7.0' \ No newline at end of file + project_sqlite_file: "absolute/path/to/Specific/db/db.sqlite" + project_db_mysql: true + project_db_mysql_host: 'localhost' + project_db_mysql_dbname: 'baikal' + project_db_mysql_username: 'baikal' + project_db_mysql_password: 'baikal' + baikal_encryption_key: '5d3f0fa0192e3058ea70f1bb20924add' + baikal_configured_version: '0.7.0' \ No newline at end of file diff --git a/html/cal.php b/html/cal.php index 682de32..1f818b4 100644 --- a/html/cal.php +++ b/html/cal.php @@ -59,15 +59,15 @@ try { die('

Incomplete installation

Baïkal is missing its configuration file, or its configuration file is unreadable.'); } -if (!isset($config['parameters']["BAIKAL_CAL_ENABLED"]) || $config['parameters']["BAIKAL_CAL_ENABLED"] !== true) { +if (!isset($config['parameters']["baikal_cal_enabled"]) || $config['parameters']["baikal_cal_enabled"] !== true) { throw new ErrorException("Baikal CalDAV is disabled.", 0, 255, __FILE__, __LINE__); } $server = new \Baikal\Core\Server( - $config['parameters']["BAIKAL_CAL_ENABLED"], - $config['parameters']["BAIKAL_CARD_ENABLED"], - $config['parameters']["BAIKAL_DAV_AUTH_TYPE"], - $config['parameters']["BAIKAL_AUTH_REALM"], + $config['parameters']["baikal_cal_enabled"], + $config['parameters']["baikal_card_enabled"], + $config['parameters']["baikal_dav_auth_type"], + $config['parameters']["baikal_auth_realm"], $GLOBALS['DB']->getPDO(), PROJECT_BASEURI . 'cal.php/' ); diff --git a/html/card.php b/html/card.php index 9946066..ae55ece 100644 --- a/html/card.php +++ b/html/card.php @@ -60,15 +60,15 @@ try { die('

Incomplete installation

Baïkal is missing its configuration file, or its configuration file is unreadable.'); } -if (!isset($config['parameters']["BAIKAL_CARD_ENABLED"]) || $config['parameters']["BAIKAL_CARD_ENABLED"] !== true) { +if (!isset($config['parameters']["baikal_card_enabled"]) || $config['parameters']["baikal_card_enabled"] !== true) { throw new ErrorException("Baikal CardDAV is disabled.", 0, 255, __FILE__, __LINE__); } $server = new \Baikal\Core\Server( - $config['parameters']["BAIKAL_CAL_ENABLED"], - $config['parameters']["BAIKAL_CARD_ENABLED"], - $config['parameters']["BAIKAL_DAV_AUTH_TYPE"], - $config['parameters']["BAIKAL_AUTH_REALM"], + $config['parameters']["baikal_cal_enabled"], + $config['parameters']["baikal_card_enabled"], + $config['parameters']["baikal_dav_auth_type"], + $config['parameters']["baikal_auth_realm"], $GLOBALS['DB']->getPDO(), PROJECT_BASEURI . 'card.php/' ); diff --git a/html/dav.php b/html/dav.php index dfd43d0..b6f8a9d 100644 --- a/html/dav.php +++ b/html/dav.php @@ -59,10 +59,10 @@ try { } $server = new \Baikal\Core\Server( - $config['parameters']["BAIKAL_CAL_ENABLED"], - $config['parameters']["BAIKAL_CARD_ENABLED"], - $config['parameters']["BAIKAL_DAV_AUTH_TYPE"], - $config['parameters']["BAIKAL_AUTH_REALM"], + $config['parameters']["baikal_cal_enabled"], + $config['parameters']["baikal_card_enabled"], + $config['parameters']["baikal_dav_auth_type"], + $config['parameters']["baikal_auth_realm"], $GLOBALS['DB']->getPDO(), PROJECT_BASEURI . 'dav.php/' ); From 21879678482d3bacdbbc9f3c267a99b3ee18ab79 Mon Sep 17 00:00:00 2001 From: Cyril Date: Tue, 15 Oct 2019 14:26:39 +0200 Subject: [PATCH 14/29] More lowercase --- Core/Frameworks/Baikal/Framework.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/Frameworks/Baikal/Framework.php b/Core/Frameworks/Baikal/Framework.php index 95825a7..a15465d 100644 --- a/Core/Frameworks/Baikal/Framework.php +++ b/Core/Frameworks/Baikal/Framework.php @@ -61,22 +61,22 @@ class Framework extends \Flake\Core\Framework { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); - date_default_timezone_set($config['parameters']['PROJECT_TIMEZONE']); + date_default_timezone_set($config['parameters']['project_timezone']); # Check that Baïkal is already configured - if (!isset($configSystem['parameters']['BAIKAL_CONFIGURED_VERSION'])) { + if (!isset($configSystem['parameters']['baikal_configured_version'])) { self::installTool(); } else { # Check that running version matches configured version - if (version_compare(BAIKAL_VERSION, $configSystem['parameters']['BAIKAL_CONFIGURED_VERSION']) > 0) { + if (version_compare(BAIKAL_VERSION, $configSystem['parameters']['baikal_configured_version']) > 0) { self::installTool(); } else { # Check that admin password is set - if (!$config['parameters']['BAIKAL_ADMIN_PASSWORDHASH']) { + if (!$config['parameters']['baikal_admin_passwordhash']) { self::installTool(); } From 9764b93eeebc5703e07ef740ff500d29d8be83ad Mon Sep 17 00:00:00 2001 From: Cyril Date: Wed, 16 Oct 2019 10:40:22 +0200 Subject: [PATCH 15/29] Add error_log() when YAML files throw an exception --- Core/Frameworks/Baikal/Core/Server.php | 4 +++- Core/Frameworks/Baikal/Model/Config.php | 1 + Core/Frameworks/Baikal/Model/Config/Standard.php | 4 +++- Core/Frameworks/Baikal/Model/User.php | 4 +++- .../BaikalAdmin/Controller/Install/Database.php | 4 +++- .../Controller/Install/UpgradeConfirmation.php | 4 +++- .../BaikalAdmin/Controller/Settings/System.php | 4 +++- Core/Frameworks/BaikalAdmin/Core/Auth.php | 6 ++++-- Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php | 10 ++++++++-- Core/Frameworks/Flake/Framework.php | 1 + 10 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Core/Frameworks/Baikal/Core/Server.php b/Core/Frameworks/Baikal/Core/Server.php index 22ae7fe..5ed14c2 100644 --- a/Core/Frameworks/Baikal/Core/Server.php +++ b/Core/Frameworks/Baikal/Core/Server.php @@ -134,7 +134,9 @@ class Server { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); - } catch (\Exception $e) {} + } catch (\Exception $e) { + error_log('Error reading config.yaml file : ' . $e->getMessage()); + } if ($this->authType === 'Basic') { $authBackend = new \Baikal\Core\PDOBasicAuth($this->pdo, $this->authRealm); diff --git a/Core/Frameworks/Baikal/Model/Config.php b/Core/Frameworks/Baikal/Model/Config.php index 4509410..12a1f05 100644 --- a/Core/Frameworks/Baikal/Model/Config.php +++ b/Core/Frameworks/Baikal/Model/Config.php @@ -43,6 +43,7 @@ abstract class Config extends \Flake\Core\Model\NoDb { $config = Yaml::parseFile($this->sConfigFilePath); $aConfig = $config['parameters']; } catch (\Exception $e) { + error_log('Error reading "' . $this->sConfigFilePath . '" file : ' . $e->getMessage()); $aConfig = static::getDefaultConfig(); } diff --git a/Core/Frameworks/Baikal/Model/Config/Standard.php b/Core/Frameworks/Baikal/Model/Config/Standard.php index bf764ed..dbf6212 100644 --- a/Core/Frameworks/Baikal/Model/Config/Standard.php +++ b/Core/Frameworks/Baikal/Model/Config/Standard.php @@ -115,7 +115,9 @@ class Standard extends \Baikal\Model\Config { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); - } catch (\Exception $e) {} + } catch (\Exception $e) { + error_log('Error reading system.yaml file : ' . $e->getMessage()); + } if (!isset($config['parameters']["BAIKAL_ADMIN_PASSWORDHASH"]) || trim($config['parameters']["BAIKAL_ADMIN_PASSWORDHASH"]) === "") { diff --git a/Core/Frameworks/Baikal/Model/User.php b/Core/Frameworks/Baikal/Model/User.php index 5e7649e..f240794 100644 --- a/Core/Frameworks/Baikal/Model/User.php +++ b/Core/Frameworks/Baikal/Model/User.php @@ -284,7 +284,9 @@ class User extends \Flake\Core\Model\Db { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); - } catch (\Exception $e) {} + } catch (\Exception $e) { + error_log('Error reading config.yaml file : ' . $e->getMessage()); + } return md5($this->get("username") . ':' . $config['parameters']['baikal_auth_realm'] . ':' . $sPassword); } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php index 97d169b..d926fac 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php @@ -214,7 +214,9 @@ class Database extends \Flake\Core\Controller { } else { try { $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); - } catch (\Exception $e) {} + } catch (\Exception $e) { + error_log('Error reading system.yaml file : ' . $e->getMessage()); + } $bMySQL = $configSystem['parameters']['PROJECT_DB_MYSQL'] ?? true; } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php b/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php index d0c26d7..d1154d6 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php @@ -39,7 +39,9 @@ class UpgradeConfirmation extends \Flake\Core\Controller { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); - } catch (\Exception $e) {} + } catch (\Exception $e) { + error_log('Error reading config.yaml file : ' . $e->getMessage()); + } if (isset($config['parameters']['baikal_configured_version']) && $config['parameters']['baikal_configured_version'] === BAIKAL_VERSION) { $sMessage = "Your system is configured to use version " . $config['parameters']['baikal_configured_version'] . ".
There's no upgrade to be done."; diff --git a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php index e23445b..d866d0f 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php @@ -70,7 +70,9 @@ class System extends \Flake\Core\Controller { } else { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); - } catch (\Exception $e) {} + } catch (\Exception $e) { + error_log('Error reading system.yaml file : ' . $e->getMessage()); + } $bMySQL = $config['parameters']['project_db_mysql'] ?? true; } diff --git a/Core/Frameworks/BaikalAdmin/Core/Auth.php b/Core/Frameworks/BaikalAdmin/Core/Auth.php index 1eb1f08..e624aba 100644 --- a/Core/Frameworks/BaikalAdmin/Core/Auth.php +++ b/Core/Frameworks/BaikalAdmin/Core/Auth.php @@ -54,7 +54,7 @@ class Auth { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); } catch (\Exception $e) { - + error_log('Error reading config.yaml file : ' . $e->getMessage()); } if ($sUser === "admin" && $sPassHash === $config['parameters']['baikal_admin_passwordhash']) { $_SESSION["baikaladminauth"] = md5($config['parameters']['baikal_admin_passwordhash']); @@ -73,7 +73,9 @@ class Auth { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); - } catch (\Exception $e) { } + } catch (\Exception $e) { + error_log('Error reading config.yaml file : ' . $e->getMessage()); + } # Fallback to default value; useful when initializing App, as all constants are not set yet $sAuthRealm = $config['parameters']['baikal_auth_realm'] ?? "BaikalDAV"; diff --git a/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php b/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php index c87ce46..344b61b 100644 --- a/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php +++ b/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php @@ -69,10 +69,16 @@ $oPage->zone("navbar")->addBlock(new \BaikalAdmin\Controller\Navigation\Topbar\I try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); -} catch (\Exception $e) { $config = null; } +} catch (\Exception $e) { + $config = null; + error_log('Error reading config.yaml file : ' . $e->getMessage()); +} try { $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); -} catch (\Exception $e) { $configSystem = null; } +} catch (\Exception $e) { + $configSystem = null; + error_log('Error reading system.yaml file : ' . $e->getMessage()); +} if (!$configSystem || !isset($configSystem['parameters']["baikal_configured_version"])) { # we have to upgrade Baïkal (existing installation) diff --git a/Core/Frameworks/Flake/Framework.php b/Core/Frameworks/Flake/Framework.php index 33ab054..9fa76ce 100644 --- a/Core/Frameworks/Flake/Framework.php +++ b/Core/Frameworks/Flake/Framework.php @@ -217,6 +217,7 @@ class Framework extends \Flake\Core\Framework { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); } catch (\Exception $e) { + error_log('Error reading system.yaml file : ' . $e->getMessage()); return true; } # Dont init db on install, but in normal mode and when upgrading From 92b690611f2e2083772a26e4be9fadabc1d0916b Mon Sep 17 00:00:00 2001 From: Cyril Date: Mon, 28 Oct 2019 10:00:42 +0100 Subject: [PATCH 16/29] Fix uppercase config parameters in various files --- Core/Frameworks/Baikal/Core/Server.php | 4 +- .../Baikal/Model/Config/Database.php | 36 +++++----- .../Baikal/Model/Config/Standard.php | 72 +++++++++---------- .../Frameworks/Baikal/Model/Config/System.php | 60 ++++++++-------- .../BaikalAdmin/Controller/Dashboard.php | 4 +- .../Controller/Install/Database.php | 60 ++++++++-------- .../Controller/Install/Initialize.php | 14 ++-- .../Controller/Install/VersionUpgrade.php | 15 ++-- .../Resources/Templates/Dashboard.html | 4 +- 9 files changed, 138 insertions(+), 131 deletions(-) diff --git a/Core/Frameworks/Baikal/Core/Server.php b/Core/Frameworks/Baikal/Core/Server.php index 5ed14c2..f4f9fb7 100644 --- a/Core/Frameworks/Baikal/Core/Server.php +++ b/Core/Frameworks/Baikal/Core/Server.php @@ -178,8 +178,8 @@ class Server { $this->server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin()); $this->server->addPlugin(new \Sabre\DAV\Sharing\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\SharingPlugin()); - if (isset($config['parameters']["BAIKAL_INVITE_FROM"]) && $config['parameters']["BAIKAL_INVITE_FROM"] !== "") { - $this->server->addPlugin(new \Sabre\CalDAV\Schedule\IMipPlugin($config['parameters']["BAIKAL_INVITE_FROM"])); + if (isset($config['parameters']["baikal_invite_from"]) && $config['parameters']["baikal_invite_from"] !== "") { + $this->server->addPlugin(new \Sabre\CalDAV\Schedule\IMipPlugin($config['parameters']["baikal_invite_from"])); } } if ($this->enableCardDAV) { diff --git a/Core/Frameworks/Baikal/Model/Config/Database.php b/Core/Frameworks/Baikal/Model/Config/Database.php index f0de8a6..9090c2a 100644 --- a/Core/Frameworks/Baikal/Model/Config/Database.php +++ b/Core/Frameworks/Baikal/Model/Config/Database.php @@ -30,27 +30,27 @@ namespace Baikal\Model\Config; class Database extends \Baikal\Model\Config { protected $aConstants = [ - "PROJECT_SQLITE_FILE" => [ + "project_sqlite_file" => [ "type" => "litteral", "comment" => "Define path to Baïkal Database SQLite file", ], - "PROJECT_DB_MYSQL" => [ + "project_db_mysql" => [ "type" => "boolean", "comment" => "MySQL > Use MySQL instead of SQLite ?", ], - "PROJECT_DB_MYSQL_HOST" => [ + "project_db_mysql_host" => [ "type" => "string", "comment" => "MySQL > Host, including ':portnumber' if port is not the default one (3306)", ], - "PROJECT_DB_MYSQL_DBNAME" => [ + "project_db_mysql_dbname" => [ "type" => "string", "comment" => "MySQL > Database name", ], - "PROJECT_DB_MYSQL_USERNAME" => [ + "project_db_mysql_username" => [ "type" => "string", "comment" => "MySQL > Username", ], - "PROJECT_DB_MYSQL_PASSWORD" => [ + "project_db_mysql_password" => [ "type" => "string", "comment" => "MySQL > Password", ], @@ -58,19 +58,19 @@ class Database extends \Baikal\Model\Config { # Default values protected $aData = [ - "PROJECT_SQLITE_FILE" => PROJECT_PATH_SPECIFIC . "db/db.sqlite", - "PROJECT_DB_MYSQL" => false, - "PROJECT_DB_MYSQL_HOST" => "", - "PROJECT_DB_MYSQL_DBNAME" => "", - "PROJECT_DB_MYSQL_USERNAME" => "", - "PROJECT_DB_MYSQL_PASSWORD" => "", + "project_sqlite_file" => PROJECT_PATH_SPECIFIC . "db/db.sqlite", + "project_db_mysql" => false, + "project_db_mysql_host" => "", + "project_db_mysql_dbname" => "", + "project_db_mysql_username" => "", + "project_db_mysql_password" => "", ]; function formMorphologyForThisModelInstance() { $oMorpho = new \Formal\Form\Morphology(); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "PROJECT_SQLITE_FILE", + "prop" => "project_sqlite_file", "label" => "SQLite file path", "validation" => "required", "inputclass" => "input-xxlarge", @@ -78,30 +78,30 @@ class Database extends \Baikal\Model\Config { ])); $oMorpho->add(new \Formal\Element\Checkbox([ - "prop" => "PROJECT_DB_MYSQL", + "prop" => "project_db_mysql", "label" => "Use MySQL", "help" => "If checked, Baïkal will use MySQL instead of SQLite.", "refreshonchange" => true, ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "PROJECT_DB_MYSQL_HOST", + "prop" => "project_db_mysql_host", "label" => "MySQL host", "help" => "Host ip or name, including ':portnumber' if port is not the default one (3306)" ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "PROJECT_DB_MYSQL_DBNAME", + "prop" => "project_db_mysql_dbname", "label" => "MySQL database name", ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "PROJECT_DB_MYSQL_USERNAME", + "prop" => "project_db_mysql_username", "label" => "MySQL username", ])); $oMorpho->add(new \Formal\Element\Password([ - "prop" => "PROJECT_DB_MYSQL_PASSWORD", + "prop" => "project_db_mysql_password", "label" => "MySQL password", ])); diff --git a/Core/Frameworks/Baikal/Model/Config/Standard.php b/Core/Frameworks/Baikal/Model/Config/Standard.php index dbf6212..661abca 100644 --- a/Core/Frameworks/Baikal/Model/Config/Standard.php +++ b/Core/Frameworks/Baikal/Model/Config/Standard.php @@ -32,27 +32,27 @@ use Symfony\Component\Yaml\Yaml; class Standard extends \Baikal\Model\Config { protected $aConstants = [ - "PROJECT_TIMEZONE" => [ + "project_timezone" => [ "type" => "string", "comment" => "Timezone of the server; if unsure, check http://en.wikipedia.org/wiki/List_of_tz_database_time_zones", ], - "BAIKAL_CARD_ENABLED" => [ + "baikal_card_enabled" => [ "type" => "boolean", "comment" => "CardDAV ON/OFF switch; default TRUE", ], - "BAIKAL_CAL_ENABLED" => [ + "baikal_cal_enabled" => [ "type" => "boolean", "comment" => "CalDAV ON/OFF switch; default TRUE", ], - "BAIKAL_INVITE_FROM" => [ + "baikal_invite_from" => [ "type" => "string", "comment" => "CalDAV invite From: mail address (comment or leave blank to disable notifications)", ], - "BAIKAL_DAV_AUTH_TYPE" => [ + "baikal_dav_auth_type" => [ "type" => "string", "comment" => "HTTP authentication type for WebDAV; default Digest" ], - "BAIKAL_ADMIN_PASSWORDHASH" => [ + "baikal_admin_passwordhash" => [ "type" => "string", "comment" => "Baïkal Web admin password hash; Set via Baïkal Web Admin", ] @@ -60,20 +60,20 @@ class Standard extends \Baikal\Model\Config { # Default values protected $aData = [ - "PROJECT_TIMEZONE" => "Europe/Paris", - "BAIKAL_CARD_ENABLED" => true, - "BAIKAL_CAL_ENABLED" => true, - "BAIKAL_INVITE_FROM" => "", - "BAIKAL_DAV_AUTH_TYPE" => "Digest", - "BAIKAL_ADMIN_PASSWORDHASH" => "", - "BAIKAL_AUTH_REALM" => "BaikalDAV" + "project_timezone" => "Europe/Paris", + "baikal_card_enabled" => true, + "baikal_cal_enabled" => true, + "baikal_invite_from" => "", + "baikal_dav_auth_type" => "Digest", + "baikal_admin_passwordhash" => "", + "baikal_auth_realm" => "BaikalDAV" ]; function formMorphologyForThisModelInstance() { $oMorpho = new \Formal\Form\Morphology(); $oMorpho->add(new \Formal\Element\Listbox([ - "prop" => "PROJECT_TIMEZONE", + "prop" => "project_timezone", "label" => "Server Time zone", "validation" => "required", "options" => \Baikal\Core\Tools::timezones(), @@ -81,36 +81,36 @@ class Standard extends \Baikal\Model\Config { $oMorpho->add(new \Formal\Element\Checkbox([ - "prop" => "BAIKAL_CARD_ENABLED", + "prop" => "baikal_card_enabled", "label" => "Enable CardDAV" ])); $oMorpho->add(new \Formal\Element\Checkbox([ - "prop" => "BAIKAL_CAL_ENABLED", + "prop" => "baikal_cal_enabled", "label" => "Enable CalDAV" ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "BAIKAL_INVITE_FROM", + "prop" => "baikal_invite_from", "label" => "Email invite sender address", "help" => "Leave empty to disable sending invite emails" ])); $oMorpho->add(new \Formal\Element\Listbox([ - "prop" => "BAIKAL_DAV_AUTH_TYPE", + "prop" => "baikal_dav_auth_type", "label" => "WebDAV authentication type", "options" => ["Digest", "Basic"] ])); $oMorpho->add(new \Formal\Element\Password([ - "prop" => "BAIKAL_ADMIN_PASSWORDHASH", + "prop" => "baikal_admin_passwordhash", "label" => "Admin password", ])); $oMorpho->add(new \Formal\Element\Password([ - "prop" => "BAIKAL_ADMIN_PASSWORDHASH_CONFIRM", + "prop" => "baikal_admin_passwordhash_confirm", "label" => "Admin password, confirmation", - "validation" => "sameas:BAIKAL_ADMIN_PASSWORDHASH", + "validation" => "sameas:baikal_admin_passwordhash", ])); try { @@ -119,14 +119,14 @@ class Standard extends \Baikal\Model\Config { error_log('Error reading system.yaml file : ' . $e->getMessage()); } - if (!isset($config['parameters']["BAIKAL_ADMIN_PASSWORDHASH"]) || trim($config['parameters']["BAIKAL_ADMIN_PASSWORDHASH"]) === "") { + if (!isset($config['parameters']["baikal_admin_passwordhash"]) || trim($config['parameters']["baikal_admin_passwordhash"]) === "") { # No password set (Form is used in install tool), so password is required as it has to be defined - $oMorpho->element("BAIKAL_ADMIN_PASSWORDHASH")->setOption("validation", "required"); + $oMorpho->element("baikal_admin_passwordhash")->setOption("validation", "required"); } else { $sNotice = "-- Leave empty to keep current password --"; - $oMorpho->element("BAIKAL_ADMIN_PASSWORDHASH")->setOption("placeholder", $sNotice); - $oMorpho->element("BAIKAL_ADMIN_PASSWORDHASH_CONFIRM")->setOption("placeholder", $sNotice); + $oMorpho->element("baikal_admin_passwordhash")->setOption("placeholder", $sNotice); + $oMorpho->element("baikal_admin_passwordhash_confirm")->setOption("placeholder", $sNotice); } return $oMorpho; @@ -137,12 +137,12 @@ class Standard extends \Baikal\Model\Config { } function set($sProp, $sValue) { - if ($sProp === "BAIKAL_ADMIN_PASSWORDHASH" || $sProp === "BAIKAL_ADMIN_PASSWORDHASH_CONFIRM") { + if ($sProp === "baikal_admin_passwordhash" || $sProp === "baikal_admin_passwordhash_confirm") { # Special handling for password and passwordconfirm - if ($sProp === "BAIKAL_ADMIN_PASSWORDHASH" && $sValue !== "") { + if ($sProp === "baikal_admin_passwordhash" && $sValue !== "") { parent::set( - "BAIKAL_ADMIN_PASSWORDHASH", + "baikal_admin_passwordhash", \BaikalAdmin\Core\Auth::hashAdminPassword($sValue) ); } @@ -154,7 +154,7 @@ class Standard extends \Baikal\Model\Config { } function get($sProp) { - if ($sProp === "BAIKAL_ADMIN_PASSWORDHASH" || $sProp === "BAIKAL_ADMIN_PASSWORDHASH_CONFIRM") { + if ($sProp === "baikal_admin_passwordhash" || $sProp === "baikal_admin_passwordhash_confirm") { return ""; } @@ -164,13 +164,13 @@ class Standard extends \Baikal\Model\Config { protected static function getDefaultConfig() { return [ - "PROJECT_TIMEZONE" => "Europe/Paris", - "BAIKAL_CARD_ENABLED" => true, - "BAIKAL_CAL_ENABLED" => true, - "BAIKAL_INVITE_FROM" => "noreply@" . $_SERVER['SERVER_NAME'], - "BAIKAL_DAV_AUTH_TYPE" => "Digest", - "BAIKAL_ADMIN_PASSWORDHASH" => "", - "BAIKAL_AUTH_REALM" => "BaikalDAV", + "project_timezone" => "Europe/Paris", + "baikal_card_enabled" => true, + "baikal_cal_enabled" => true, + "baikal_invite_from" => "noreply@" . $_SERVER['SERVER_NAME'], + "baikal_dav_auth_type" => "Digest", + "baikal_admin_passwordhash" => "", + "baikal_auth_realm" => "BaikalDAV", ]; } } diff --git a/Core/Frameworks/Baikal/Model/Config/System.php b/Core/Frameworks/Baikal/Model/Config/System.php index 55c07b6..8018dbd 100644 --- a/Core/Frameworks/Baikal/Model/Config/System.php +++ b/Core/Frameworks/Baikal/Model/Config/System.php @@ -30,35 +30,35 @@ namespace Baikal\Model\Config; class System extends \Baikal\Model\Config { protected $aConstants = [ - "PROJECT_SQLITE_FILE" => [ + "project_sqlite_file" => [ "type" => "litteral", "comment" => "Define path to Baïkal Database SQLite file", ], - "PROJECT_DB_MYSQL" => [ + "project_db_mysql" => [ "type" => "boolean", "comment" => "MySQL > Use MySQL instead of SQLite ?", ], - "PROJECT_DB_MYSQL_HOST" => [ + "project_db_mysql_host" => [ "type" => "string", "comment" => "MySQL > Host, including ':portnumber' if port is not the default one (3306)", ], - "PROJECT_DB_MYSQL_DBNAME" => [ + "project_db_mysql_dbname" => [ "type" => "string", "comment" => "MySQL > Database name", ], - "PROJECT_DB_MYSQL_USERNAME" => [ + "project_db_mysql_username" => [ "type" => "string", "comment" => "MySQL > Username", ], - "PROJECT_DB_MYSQL_PASSWORD" => [ + "project_db_mysql_password" => [ "type" => "string", "comment" => "MySQL > Password", ], - "BAIKAL_ENCRYPTION_KEY" => [ + "baikal_encryption_key" => [ "type" => "string", "comment" => "A random 32 bytes key that will be used to encrypt data", ], - "BAIKAL_CONFIGURED_VERSION" => [ + "baikal_configured_version" => [ "type" => "string", "comment" => "The currently configured Baïkal version", ], @@ -66,21 +66,21 @@ class System extends \Baikal\Model\Config { # Default values protected $aData = [ - "PROJECT_SQLITE_FILE" => "db/db.sqlite", - "PROJECT_DB_MYSQL" => false, - "PROJECT_DB_MYSQL_HOST" => "", - "PROJECT_DB_MYSQL_DBNAME" => "", - "PROJECT_DB_MYSQL_USERNAME" => "", - "PROJECT_DB_MYSQL_PASSWORD" => "", - "BAIKAL_ENCRYPTION_KEY" => "", - "BAIKAL_CONFIGURED_VERSION" => "", + "project_sqlite_file" => "db/db.sqlite", + "project_db_mysql" => false, + "project_db_mysql_host" => "", + "project_db_mysql_dbname" => "", + "project_db_mysql_username" => "", + "project_db_mysql_password" => "", + "baikal_encryption_key" => "", + "baikal_configured_version" => "", ]; function formMorphologyForThisModelInstance() { $oMorpho = new \Formal\Form\Morphology(); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "PROJECT_SQLITE_FILE", + "prop" => "project_sqlite_file", "label" => "SQLite file path", "validation" => "required", "inputclass" => "input-xxlarge", @@ -88,30 +88,30 @@ class System extends \Baikal\Model\Config { ])); $oMorpho->add(new \Formal\Element\Checkbox([ - "prop" => "PROJECT_DB_MYSQL", + "prop" => "project_db_mysql", "label" => "Use MySQL", "help" => "If checked, Baïkal will use MySQL instead of SQLite.", "refreshonchange" => true, ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "PROJECT_DB_MYSQL_HOST", + "prop" => "project_db_mysql_host", "label" => "MySQL host", "help" => "Host ip or name, including ':portnumber' if port is not the default one (3306)" ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "PROJECT_DB_MYSQL_DBNAME", + "prop" => "project_db_mysql_dbname", "label" => "MySQL database name", ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "PROJECT_DB_MYSQL_USERNAME", + "prop" => "project_db_mysql_username", "label" => "MySQL username", ])); $oMorpho->add(new \Formal\Element\Password([ - "prop" => "PROJECT_DB_MYSQL_PASSWORD", + "prop" => "project_db_mysql_password", "label" => "MySQL password", ])); @@ -125,14 +125,14 @@ class System extends \Baikal\Model\Config { protected static function getDefaultConfig() { return [ - "PROJECT_SQLITE_FILE" => "db/db.sqlite", - "PROJECT_DB_MYSQL" => false, - "PROJECT_DB_MYSQL_HOST" => "", - "PROJECT_DB_MYSQL_DBNAME" => "", - "PROJECT_DB_MYSQL_USERNAME" => "", - "PROJECT_DB_MYSQL_PASSWORD" => "", - "BAIKAL_ENCRYPTION_KEY" => "", - "BAIKAL_CONFIGURED_VERSION" => BAIKAL_VERSION + "project_sqlite_file" => "db/db.sqlite", + "project_db_mysql" => false, + "project_db_mysql_host" => "", + "project_db_mysql_dbname" => "", + "project_db_mysql_username" => "", + "project_db_mysql_password" => "", + "baikal_encryption_key" => "", + "baikal_configured_version" => BAIKAL_VERSION ]; } } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php b/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php index 7ac2ca7..8e4626d 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php @@ -42,8 +42,8 @@ class Dashboard extends \Flake\Core\Controller { $oView->setData("BAIKAL_VERSION", BAIKAL_VERSION); # Services status - $oView->setData("BAIKAL_CAL_ENABLED", $config['parameters']['baikal_cal_enabled']); - $oView->setData("BAIKAL_CARD_ENABLED", $config['parameters']['baikal_card_enabled']); + $oView->setData("baikal_cal_enabled", $config['parameters']['baikal_cal_enabled']); + $oView->setData("baikal_card_enabled", $config['parameters']['baikal_card_enabled']); # Statistics: Users $iNbUsers = \Baikal\Model\User::getBaseRequester()->count(); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php index d926fac..dbb683c 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php @@ -40,13 +40,13 @@ class Database extends \Flake\Core\Controller { if (file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) { require_once(PROJECT_PATH_SPECIFIC . "config.system.php"); - $this->oModel->set('PROJECT_SQLITE_FILE', PROJECT_SQLITE_FILE); - $this->oModel->set('PROJECT_DB_MYSQL', PROJECT_DB_MYSQL); - $this->oModel->set('PROJECT_DB_MYSQL_HOST', PROJECT_DB_MYSQL_HOST); - $this->oModel->set('PROJECT_DB_MYSQL_DBNAME', PROJECT_DB_MYSQL_DBNAME); - $this->oModel->set('PROJECT_DB_MYSQL_USERNAME', PROJECT_DB_MYSQL_USERNAME); - $this->oModel->set('PROJECT_DB_MYSQL_PASSWORD', PROJECT_DB_MYSQL_PASSWORD); - $this->oModel->set('BAIKAL_ENCRYPTION_KEY', BAIKAL_ENCRYPTION_KEY); + $this->oModel->set('project_sqlite_file', PROJECT_SQLITE_FILE); + $this->oModel->set('project_db_mysql', PROJECT_DB_MYSQL); + $this->oModel->set('project_db_mysql_host', PROJECT_DB_MYSQL_HOST); + $this->oModel->set('project_db_mysql_dbname', PROJECT_DB_MYSQL_DBNAME); + $this->oModel->set('project_db_mysql_username', PROJECT_DB_MYSQL_USERNAME); + $this->oModel->set('project_db_mysql_password', PROJECT_DB_MYSQL_PASSWORD); + $this->oModel->set('baikal_encryption_key', BAIKAL_ENCRYPTION_KEY); } $this->oForm = $this->oModel->formForThisModelInstance([ @@ -93,14 +93,14 @@ class Database extends \Flake\Core\Controller { if ($oForm->refreshed()){ return true; } - $bMySQLEnabled = $oMorpho->element("PROJECT_DB_MYSQL")->value(); + $bMySQLEnabled = $oMorpho->element("project_db_mysql")->value(); if ($bMySQLEnabled) { - $sHost = $oMorpho->element("PROJECT_DB_MYSQL_HOST")->value(); - $sDbname = $oMorpho->element("PROJECT_DB_MYSQL_DBNAME")->value(); - $sUsername = $oMorpho->element("PROJECT_DB_MYSQL_USERNAME")->value(); - $sPassword = $oMorpho->element("PROJECT_DB_MYSQL_PASSWORD")->value(); + $sHost = $oMorpho->element("project_db_mysql_host")->value(); + $sDbname = $oMorpho->element("project_db_mysql_dbname")->value(); + $sUsername = $oMorpho->element("project_db_mysql_username")->value(); + $sPassword = $oMorpho->element("project_db_mysql_password")->value(); try { $oDb = new \Flake\Core\Database\Mysql( @@ -121,7 +121,7 @@ class Database extends \Flake\Core\Controller { $sMessage .= "

Nothing has been saved. Please, add these tables to the database before pursuing Baïkal initialization.

"; $oForm->declareError( - $oMorpho->element("PROJECT_DB_MYSQL"), + $oMorpho->element("project_db_mysql"), $sMessage ); } else { @@ -134,16 +134,16 @@ class Database extends \Flake\Core\Controller { return true; } catch (\Exception $e) { - $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL"), + $oForm->declareError($oMorpho->element("project_db_mysql"), "Baïkal was not able to establish a connexion to the MySQL database as configured.
MySQL says: " . $e->getMessage()); - $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_HOST")); - $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_DBNAME")); - $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_USERNAME")); - $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_PASSWORD")); + $oForm->declareError($oMorpho->element("project_db_mysql_host")); + $oForm->declareError($oMorpho->element("project_db_mysql_dbname")); + $oForm->declareError($oMorpho->element("project_db_mysql_username")); + $oForm->declareError($oMorpho->element("project_db_mysql_password")); } } else { - $sFile = $oMorpho->element("PROJECT_SQLITE_FILE")->value(); + $sFile = $oMorpho->element("project_sqlite_file")->value(); try { @@ -156,13 +156,13 @@ class Database extends \Flake\Core\Controller { # Asserting DB file is writable if (file_exists($sFile) && !is_writable($sFile)) { $sMessage = "DB file is not writable. Please give write permissions on file " . $sFile . ""; - $oForm->declareError($oMorpho->element("PROJECT_SQLITE_FILE"), $sMessage); + $oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage); return false; } # Asserting DB directory is writable if (!is_writable(dirname($sFile))) { $sMessage = "The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder " . dirname($sFile) . ""; - $oForm->declareError($oMorpho->element("PROJECT_SQLITE_FILE"), $sMessage); + $oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage); return false; } @@ -182,7 +182,7 @@ class Database extends \Flake\Core\Controller { $sMessage .= "

Nothing has been saved. Please, add these tables to the database before pursuing Baïkal initialization.

"; $oForm->declareError( - $oMorpho->element("PROJECT_SQLITE_FILE"), + $oMorpho->element("project_sqlite_file"), $sMessage ); } else { @@ -199,7 +199,7 @@ class Database extends \Flake\Core\Controller { return true; } catch (\Exception $e) { $oForm->declareError( - $oMorpho->element("PROJECT_SQLITE_FILE"), + $oMorpho->element("project_sqlite_file"), "Baïkal was not able to establish a connexion to the SQLite database as configured.
SQLite says: " . $e->getMessage() . (string)$e ); } @@ -210,24 +210,24 @@ class Database extends \Flake\Core\Controller { function hideMySQLFieldWhenNeeded(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) { if ($oForm->submitted()) { - $bMySQL = (intval($oForm->postValue("PROJECT_DB_MYSQL")) === 1); + $bMySQL = (intval($oForm->postValue("project_db_mysql")) === 1); } else { try { $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); } catch (\Exception $e) { error_log('Error reading system.yaml file : ' . $e->getMessage()); } - $bMySQL = $configSystem['parameters']['PROJECT_DB_MYSQL'] ?? true; + $bMySQL = $configSystem['parameters']['project_db_mysql'] ?? true; } if ($bMySQL === true) { - $oMorpho->remove("PROJECT_SQLITE_FILE"); + $oMorpho->remove("project_sqlite_file"); } else { - $oMorpho->remove("PROJECT_DB_MYSQL_HOST"); - $oMorpho->remove("PROJECT_DB_MYSQL_DBNAME"); - $oMorpho->remove("PROJECT_DB_MYSQL_USERNAME"); - $oMorpho->remove("PROJECT_DB_MYSQL_PASSWORD"); + $oMorpho->remove("project_db_mysql_host"); + $oMorpho->remove("project_db_mysql_dbname"); + $oMorpho->remove("project_db_mysql_username"); + $oMorpho->remove("project_db_mysql_password"); } } } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index becc1ca..5e071a2 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -50,11 +50,11 @@ class Initialize extends \Flake\Core\Controller { // If we come from pre-0.7.0, we need to get the values from the config.php and config.system.php files if (file_exists(PROJECT_PATH_SPECIFIC . "config.php")) { require_once(PROJECT_PATH_SPECIFIC . "config.php"); - $this->oModel->set('PROJECT_TIMEZONE', PROJECT_TIMEZONE); - $this->oModel->set('BAIKAL_CARD_ENABLED', BAIKAL_CARD_ENABLED); - $this->oModel->set('BAIKAL_CAL_ENABLED', BAIKAL_CAL_ENABLED); - $this->oModel->set('BAIKAL_INVITE_FROM', BAIKAL_INVITE_FROM); - $this->oModel->set('BAIKAL_DAV_AUTH_TYPE', BAIKAL_DAV_AUTH_TYPE); + $this->oModel->set('project_timezone', PROJECT_TIMEZONE); + $this->oModel->set('baikal_card_enabled', BAIKAL_CARD_ENABLED); + $this->oModel->set('baikal_cal_enabled', BAIKAL_CAL_ENABLED); + $this->oModel->set('baikal_invite_from', BAIKAL_INVITE_FROM); + $this->oModel->set('baikal_dav_auth_type', BAIKAL_DAV_AUTH_TYPE); } $this->oForm = $this->oModel->formForThisModelInstance([ @@ -76,12 +76,12 @@ class Initialize extends \Flake\Core\Controller { # Creating system config, and initializing BAIKAL_ENCRYPTION_KEY $oSystemConfig = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); - $oSystemConfig->set("BAIKAL_ENCRYPTION_KEY", md5(microtime() . rand())); + $oSystemConfig->set("baikal_encryption_key", md5(microtime() . rand())); # Default: PDO::SQLite or PDO::MySQL ? $aPDODrivers = \PDO::getAvailableDrivers(); if (!in_array('sqlite', $aPDODrivers)) { # PDO::MySQL is already asserted in \Baikal\Core\Tools::assertEnvironmentIsOk() - $oSystemConfig->set("PROJECT_DB_MYSQL", true); + $oSystemConfig->set("project_db_mysql", true); } $oSystemConfig->persist(); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php index 05920ea..3a44da7 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php @@ -42,11 +42,18 @@ class VersionUpgrade extends \Flake\Core\Controller { } function render() { + + try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + } catch (\Exception $e) { + error_log('Error reading system.yaml file : ' . $e->getMessage()); + } + $sBigIcon = "glyph2x-magic"; $sBaikalVersion = BAIKAL_VERSION; - $sBaikalConfiguredVersion = BAIKAL_CONFIGURED_VERSION; + $sBaikalConfiguredVersion = $config['parameters']['baikal_configured_version']; - if (BAIKAL_CONFIGURED_VERSION === BAIKAL_VERSION) { + if ($config['parameters']['baikal_configured_version'] === BAIKAL_VERSION) { $sMessage = "Your system is configured to use version " . $sBaikalConfiguredVersion . ".
There's no upgrade to be done."; } else { $sMessage = "Upgrading Baïkal from version " . $sBaikalConfiguredVersion . " to version " . $sBaikalVersion . ""; @@ -60,7 +67,7 @@ class VersionUpgrade extends \Flake\Core\Controller { HTML; try { - $bSuccess = $this->upgrade(BAIKAL_CONFIGURED_VERSION, BAIKAL_VERSION); + $bSuccess = $this->upgrade($config['parameters']['baikal_configured_version'], BAIKAL_VERSION); } catch (\Exception $e) { $bSuccess = false; $this->aErrors[] = 'Uncaught exception during upgrade: ' . (string)$e; @@ -530,7 +537,7 @@ SQL # Update BAIKAL_CONFIGURED_VERSION $oConfig = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); - $oConfig->set("BAIKAL_CONFIGURED_VERSION", $sVersionTo); + $oConfig->set("baikal_configured_version", $sVersionTo); $oConfig->persist(); } diff --git a/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html b/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html index c8ccbda..05daca2 100644 --- a/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html +++ b/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html @@ -38,7 +38,7 @@

Services

- {% if BAIKAL_CAL_ENABLED %} + {% if baikal_cal_enabled %} {% set caldavclass = 'label-success' %} {% set caldavtext = 'On' %} {% else %} @@ -46,7 +46,7 @@ {% set caldavtext = 'Off' %} {% endif %} - {% if BAIKAL_CARD_ENABLED %} + {% if baikal_card_enabled %} {% set carddavclass = 'label-success' %} {% set carddavtext = 'On' %} {% else %} From 44127a2b65801e90f5a02cd64c63902ba009094d Mon Sep 17 00:00:00 2001 From: Cyril Date: Tue, 29 Oct 2019 21:05:03 +0100 Subject: [PATCH 17/29] More fixup on lowercase --- .../Controller/Settings/System.php | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php index d866d0f..84c7ad1 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php @@ -66,7 +66,7 @@ class System extends \Flake\Core\Controller { function morphologyHook(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) { if ($oForm->submitted()) { - $bMySQL = (intval($oForm->postValue("PROJECT_DB_MYSQL")) === 1); + $bMySQL = (intval($oForm->postValue("project_db_mysql")) === 1); } else { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); @@ -77,13 +77,13 @@ class System extends \Flake\Core\Controller { } if ($bMySQL === true) { - $oMorpho->remove("PROJECT_SQLITE_FILE"); + $oMorpho->remove("project_sqlite_file"); } else { - $oMorpho->remove("PROJECT_DB_MYSQL_HOST"); - $oMorpho->remove("PROJECT_DB_MYSQL_DBNAME"); - $oMorpho->remove("PROJECT_DB_MYSQL_USERNAME"); - $oMorpho->remove("PROJECT_DB_MYSQL_PASSWORD"); + $oMorpho->remove("project_db_mysql_host"); + $oMorpho->remove("project_db_mysql_dbname"); + $oMorpho->remove("project_db_mysql_username"); + $oMorpho->remove("project_db_mysql_password"); } } @@ -91,13 +91,13 @@ class System extends \Flake\Core\Controller { if ($oForm->refreshed()){ return true; } - if (intval($oForm->modelInstance()->get("PROJECT_DB_MYSQL")) === 1) { + if (intval($oForm->modelInstance()->get("project_db_mysql")) === 1) { # We have to check the MySQL connection - $sHost = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_HOST"); - $sDbName = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_DBNAME"); - $sUsername = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_USERNAME"); - $sPassword = $oForm->modelInstance()->get("PROJECT_DB_MYSQL_PASSWORD"); + $sHost = $oForm->modelInstance()->get("project_db_mysql_host"); + $sDbName = $oForm->modelInstance()->get("project_db_mysql_dbname"); + $sUsername = $oForm->modelInstance()->get("project_db_mysql_username"); + $sPassword = $oForm->modelInstance()->get("project_db_mysql_password"); try { $oDB = new \Flake\Core\Database\Mysql( @@ -109,10 +109,10 @@ class System extends \Flake\Core\Controller { } catch (\Exception $e) { $sMessage = "MySQL error: " . $e->getMessage(); $sMessage .= "
Nothing has been saved"; - $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_HOST"), $sMessage); - $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_DBNAME")); - $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_USERNAME")); - $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL_PASSWORD")); + $oForm->declareError($oMorpho->element("project_db_mysql_host"), $sMessage); + $oForm->declareError($oMorpho->element("project_db_mysql_dbname")); + $oForm->declareError($oMorpho->element("project_db_mysql_username")); + $oForm->declareError($oMorpho->element("project_db_mysql_password")); return; } @@ -121,12 +121,12 @@ class System extends \Flake\Core\Controller { $sMessage .= "You may want create these tables using the file Core/Resources/Db/MySQL/db.sql"; $sMessage .= "

Nothing has been saved"; - $oForm->declareError($oMorpho->element("PROJECT_DB_MYSQL"), $sMessage); + $oForm->declareError($oMorpho->element("project_db_mysql"), $sMessage); return; } } else { - $sFile = $oMorpho->element("PROJECT_SQLITE_FILE")->value(); + $sFile = $oMorpho->element("project_sqlite_file")->value(); try { @@ -139,13 +139,13 @@ class System extends \Flake\Core\Controller { # Asserting DB file is writable if (file_exists($sFile) && !is_writable($sFile)) { $sMessage = "DB file is not writable. Please give write permissions on file " . $sFile . ""; - $oForm->declareError($oMorpho->element("PROJECT_SQLITE_FILE"), $sMessage); + $oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage); return; } # Asserting DB directory is writable if (!is_writable(dirname($sFile))) { $sMessage = "The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder " . dirname($sFile) . ""; - $oForm->declareError($oMorpho->element("PROJECT_SQLITE_FILE"), $sMessage); + $oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage); return; } @@ -161,14 +161,14 @@ class System extends \Flake\Core\Controller { $sMessage .= "

Nothing has been saved. Please, add these tables to the database before pursuing Baïkal initialization.

"; $oForm->declareError( - $oMorpho->element("PROJECT_SQLITE_FILE"), + $oMorpho->element("project_sqlite_file"), $sMessage ); } return; } catch (\Exception $e) { $oForm->declareError( - $oMorpho->element("PROJECT_SQLITE_FILE"), + $oMorpho->element("project_sqlite_file"), "Baïkal was not able to establish a connexion to the SQLite database as configured.
SQLite says: " . $e->getMessage() . (string)$e ); } From b28261fa0e6f97723c32cfc2586f6d7e1f91739f Mon Sep 17 00:00:00 2001 From: tchapi Date: Sat, 23 Nov 2019 23:08:25 +0100 Subject: [PATCH 18/29] Change hashing algorithm from md5 to sha256 --- Core/Frameworks/Baikal/Core/PDOBasicAuth.php | 2 +- Core/Frameworks/Baikal/Model/User.php | 2 +- Core/Frameworks/BaikalAdmin/Core/Auth.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/Frameworks/Baikal/Core/PDOBasicAuth.php b/Core/Frameworks/Baikal/Core/PDOBasicAuth.php index 9270194..14ab6b5 100644 --- a/Core/Frameworks/Baikal/Core/PDOBasicAuth.php +++ b/Core/Frameworks/Baikal/Core/PDOBasicAuth.php @@ -68,7 +68,7 @@ class PDOBasicAuth extends \Sabre\DAV\Auth\Backend\AbstractBasic { if (!count($result)) return false; - $hash = md5($username . ':' . $this->authRealm . ':' . $password); + $hash = hash("sha256", $username . ':' . $this->authRealm . ':' . $password); if ($result[0]['digesta1'] === $hash) { $this->currentUser = $username; diff --git a/Core/Frameworks/Baikal/Model/User.php b/Core/Frameworks/Baikal/Model/User.php index f240794..3d58430 100644 --- a/Core/Frameworks/Baikal/Model/User.php +++ b/Core/Frameworks/Baikal/Model/User.php @@ -288,6 +288,6 @@ class User extends \Flake\Core\Model\Db { error_log('Error reading config.yaml file : ' . $e->getMessage()); } - return md5($this->get("username") . ':' . $config['parameters']['baikal_auth_realm'] . ':' . $sPassword); + return hash("sha256", $this->get("username") . ':' . $config['parameters']['baikal_auth_realm'] . ':' . $sPassword); } } diff --git a/Core/Frameworks/BaikalAdmin/Core/Auth.php b/Core/Frameworks/BaikalAdmin/Core/Auth.php index e624aba..96a8c02 100644 --- a/Core/Frameworks/BaikalAdmin/Core/Auth.php +++ b/Core/Frameworks/BaikalAdmin/Core/Auth.php @@ -80,7 +80,7 @@ class Auth { # Fallback to default value; useful when initializing App, as all constants are not set yet $sAuthRealm = $config['parameters']['baikal_auth_realm'] ?? "BaikalDAV"; - return md5('admin:' . $sAuthRealm . ':' . $sPassword); + return hash("sha256", 'admin:' . $sAuthRealm . ':' . $sPassword); } } From 2285e5ae4a9a4a16004bd44be226a02eda0b1d02 Mon Sep 17 00:00:00 2001 From: tchapi Date: Sat, 23 Nov 2019 23:09:16 +0100 Subject: [PATCH 19/29] Prevent "Resource Unavailable" errors and other exceptions --- Core/Frameworks/BaikalAdmin/Controller/Install/Database.php | 4 +++- Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php index dbb683c..894305a 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php @@ -59,7 +59,9 @@ class Database extends \Flake\Core\Controller { $this->oForm->execute(); if ($this->oForm->persisted()) { - unlink(PROJECT_PATH_SPECIFIC . "config.system.php"); + if (file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) { + @unlink(PROJECT_PATH_SPECIFIC . "config.system.php"); + } touch(PROJECT_PATH_SPECIFIC . '/INSTALL_DISABLED'); } } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index 5e071a2..4d88306 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -68,10 +68,10 @@ class Initialize extends \Flake\Core\Controller { // If we come from pre-0.7.0, we need to remove the INSTALL_DISABLED file so we go to the next step if (file_exists(PROJECT_PATH_SPECIFIC . '/INSTALL_DISABLED')) { - unlink(PROJECT_PATH_SPECIFIC . '/INSTALL_DISABLED'); + @unlink(PROJECT_PATH_SPECIFIC . '/INSTALL_DISABLED'); } if (file_exists(PROJECT_PATH_SPECIFIC . "config.php")) { - unlink(PROJECT_PATH_SPECIFIC . "config.php"); + @unlink(PROJECT_PATH_SPECIFIC . "config.php"); } # Creating system config, and initializing BAIKAL_ENCRYPTION_KEY From 143df6fd0c66b83489b544ff67890676525b2bc7 Mon Sep 17 00:00:00 2001 From: tchapi Date: Sat, 23 Nov 2019 23:09:57 +0100 Subject: [PATCH 20/29] Add a reassuring message when transitionning to 0.7.0 --- .../BaikalAdmin/Controller/Install/Initialize.php | 5 +++++ .../Resources/Templates/Install/Initialize.html | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index 4d88306..400ad46 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -97,6 +97,11 @@ class Initialize extends \Flake\Core\Controller { $oView = new \BaikalAdmin\View\Install\Initialize(); $oView->setData("baikalversion", BAIKAL_VERSION); + // If we come from pre-0.7.0 (old config files are still present), + // we need to tell the installer page to show a warning message. + $oView->setData("oldConfigSystem", file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")); + + if ($this->oForm->persisted()) { $sLink = PROJECT_URI . "admin/install/?/database"; \Flake\Util\Tools::redirect($sLink); diff --git a/Core/Frameworks/BaikalAdmin/Resources/Templates/Install/Initialize.html b/Core/Frameworks/BaikalAdmin/Resources/Templates/Install/Initialize.html index 72791e3..38369d2 100644 --- a/Core/Frameworks/BaikalAdmin/Resources/Templates/Install/Initialize.html +++ b/Core/Frameworks/BaikalAdmin/Resources/Templates/Install/Initialize.html @@ -2,6 +2,15 @@

Baïkal initialization wizard

Configure your new Baïkal {{ baikalversion }} installation.

+ + {% if oldConfigSystem %} +
+ With the 0.7.0 release, our configuration format was updated to use YAML files.
+ You need to go through this installer again but we pre-filled most values with the ones from your old installation.
+ As we updated our hashing algorithm for the admin interface password, you need to enter it again.
+ The database with your contacts and events stays untouched. We still recommend that you make a full backup of your data before proceeding, as a safety measure. +
+ {% endif %}
From 476f0e3c48d5a42b6e25e311bee7a4bf444aae7f Mon Sep 17 00:00:00 2001 From: tchapi Date: Sat, 23 Nov 2019 23:10:16 +0100 Subject: [PATCH 21/29] Remove evil eval --- Core/Frameworks/BaikalAdmin/Controller/Install/Database.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php index 894305a..6c0f7eb 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php @@ -149,12 +149,6 @@ class Database extends \Flake\Core\Controller { try { - // not sure yet how to better address this - // yup! this is mental, but even if we don't use eval, effectively these - // config settings are eval'ed because they are written as raw php files. - // We'll have to clean this up later. - $sFile = eval('return ' . $sFile . ';'); - # Asserting DB file is writable if (file_exists($sFile) && !is_writable($sFile)) { $sMessage = "DB file is not writable. Please give write permissions on file " . $sFile . ""; From 4f10dc3c7248909d82cb9b44f33ab985f040fe2a Mon Sep 17 00:00:00 2001 From: tchapi Date: Sun, 24 Nov 2019 10:17:32 +0100 Subject: [PATCH 22/29] Revert "Change hashing algorithm from md5 to sha256" This reverts commit b28261fa0e6f97723c32cfc2586f6d7e1f91739f. --- Core/Frameworks/Baikal/Core/PDOBasicAuth.php | 2 +- Core/Frameworks/Baikal/Model/User.php | 2 +- Core/Frameworks/BaikalAdmin/Core/Auth.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/Frameworks/Baikal/Core/PDOBasicAuth.php b/Core/Frameworks/Baikal/Core/PDOBasicAuth.php index 14ab6b5..9270194 100644 --- a/Core/Frameworks/Baikal/Core/PDOBasicAuth.php +++ b/Core/Frameworks/Baikal/Core/PDOBasicAuth.php @@ -68,7 +68,7 @@ class PDOBasicAuth extends \Sabre\DAV\Auth\Backend\AbstractBasic { if (!count($result)) return false; - $hash = hash("sha256", $username . ':' . $this->authRealm . ':' . $password); + $hash = md5($username . ':' . $this->authRealm . ':' . $password); if ($result[0]['digesta1'] === $hash) { $this->currentUser = $username; diff --git a/Core/Frameworks/Baikal/Model/User.php b/Core/Frameworks/Baikal/Model/User.php index 3d58430..f240794 100644 --- a/Core/Frameworks/Baikal/Model/User.php +++ b/Core/Frameworks/Baikal/Model/User.php @@ -288,6 +288,6 @@ class User extends \Flake\Core\Model\Db { error_log('Error reading config.yaml file : ' . $e->getMessage()); } - return hash("sha256", $this->get("username") . ':' . $config['parameters']['baikal_auth_realm'] . ':' . $sPassword); + return md5($this->get("username") . ':' . $config['parameters']['baikal_auth_realm'] . ':' . $sPassword); } } diff --git a/Core/Frameworks/BaikalAdmin/Core/Auth.php b/Core/Frameworks/BaikalAdmin/Core/Auth.php index 96a8c02..e624aba 100644 --- a/Core/Frameworks/BaikalAdmin/Core/Auth.php +++ b/Core/Frameworks/BaikalAdmin/Core/Auth.php @@ -80,7 +80,7 @@ class Auth { # Fallback to default value; useful when initializing App, as all constants are not set yet $sAuthRealm = $config['parameters']['baikal_auth_realm'] ?? "BaikalDAV"; - return hash("sha256", 'admin:' . $sAuthRealm . ':' . $sPassword); + return md5('admin:' . $sAuthRealm . ':' . $sPassword); } } From 46c274449b85c87836b853e1feb4b413da93d84c Mon Sep 17 00:00:00 2001 From: tchapi Date: Sun, 24 Nov 2019 10:18:12 +0100 Subject: [PATCH 23/29] Change hashing algorithm for admin interface _only_ --- Core/Frameworks/BaikalAdmin/Core/Auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Frameworks/BaikalAdmin/Core/Auth.php b/Core/Frameworks/BaikalAdmin/Core/Auth.php index e624aba..c4b6213 100644 --- a/Core/Frameworks/BaikalAdmin/Core/Auth.php +++ b/Core/Frameworks/BaikalAdmin/Core/Auth.php @@ -80,7 +80,7 @@ class Auth { # Fallback to default value; useful when initializing App, as all constants are not set yet $sAuthRealm = $config['parameters']['baikal_auth_realm'] ?? "BaikalDAV"; - return md5('admin:' . $sAuthRealm . ':' . $sPassword); + return hash('sha256', 'admin:' . $sAuthRealm . ':' . $sPassword); } } From d263037d0651a97e3e3e91703601787347413651 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Thu, 5 Mar 2020 14:35:37 +0100 Subject: [PATCH 24/29] Use a single config file --- .gitignore | 3 +- Core/Frameworks/Baikal/Core/Server.php | 8 +- Core/Frameworks/Baikal/Core/Tools.php | 26 ++---- Core/Frameworks/Baikal/Framework.php | 19 ++--- Core/Frameworks/Baikal/Model/Config.php | 31 ++++--- .../Baikal/Model/Config/Database.php | 40 +++++---- .../Baikal/Model/Config/Standard.php | 82 ++++++++++--------- .../Frameworks/Baikal/Model/Config/System.php | 59 ++++++------- Core/Frameworks/Baikal/Model/User.php | 6 +- .../BaikalAdmin/Controller/Dashboard.php | 6 +- .../Controller/Install/Database.php | 64 +++++++-------- .../Controller/Install/Initialize.php | 16 ++-- .../Install/UpgradeConfirmation.php | 8 +- .../Controller/Install/VersionUpgrade.php | 14 ++-- .../Controller/Settings/Standard.php | 2 +- .../Controller/Settings/System.php | 57 ++++++------- Core/Frameworks/BaikalAdmin/Core/Auth.php | 18 ++-- .../Resources/Templates/Dashboard.html | 4 +- .../BaikalAdmin/WWWRoot/install/index.php | 16 ++-- Core/Frameworks/Flake/Framework.php | 38 ++++----- config/baikal.yaml.dist | 17 ++++ config/config.yaml.dist | 8 -- config/system.yaml.dist | 9 -- html/cal.php | 12 +-- html/card.php | 12 +-- html/dav.php | 10 +-- 26 files changed, 281 insertions(+), 304 deletions(-) create mode 100644 config/baikal.yaml.dist delete mode 100644 config/config.yaml.dist delete mode 100644 config/system.yaml.dist diff --git a/.gitignore b/.gitignore index cc1627e..8c7f057 100755 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,7 @@ logs # Specific -config/config.yaml -config/system.yaml +config/baikal.yaml Specific/INSTALL_DISABLED # Composer stuff diff --git a/Core/Frameworks/Baikal/Core/Server.php b/Core/Frameworks/Baikal/Core/Server.php index 2e35eed..46a8f0c 100644 --- a/Core/Frameworks/Baikal/Core/Server.php +++ b/Core/Frameworks/Baikal/Core/Server.php @@ -133,9 +133,9 @@ class Server { protected function initServer() { try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { - error_log('Error reading config.yaml file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); } if ($this->authType === 'Basic') { @@ -178,8 +178,8 @@ class Server { $this->server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin()); $this->server->addPlugin(new \Sabre\DAV\Sharing\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\SharingPlugin()); - if (isset($config['parameters']["baikal_invite_from"]) && $config['parameters']["baikal_invite_from"] !== "") { - $this->server->addPlugin(new \Sabre\CalDAV\Schedule\IMipPlugin($config['parameters']["baikal_invite_from"])); + if (isset($config['system']["invite_from"]) && $config['system']["invite_from"] !== "") { + $this->server->addPlugin(new \Sabre\CalDAV\Schedule\IMipPlugin($config['system']["invite_from"])); } } if ($this->enableCardDAV) { diff --git a/Core/Frameworks/Baikal/Core/Tools.php b/Core/Frameworks/Baikal/Core/Tools.php index 377a010..cc4a610 100644 --- a/Core/Frameworks/Baikal/Core/Tools.php +++ b/Core/Frameworks/Baikal/Core/Tools.php @@ -73,32 +73,18 @@ class Tools { #} # Asserting config file exists - if (!file_exists(PROJECT_PATH_CONFIG . "config.yaml")) { - throw new \Exception("config/config.yaml does not exist. Please use the Install tool to create it or duplicate config.yaml.dist."); + if (!file_exists(PROJECT_PATH_CONFIG . "baikal.yaml")) { + throw new \Exception("config/baikal.yaml does not exist. Please use the Install tool to create it or duplicate baikal.yaml.dist."); } # Asserting config file is readable - if (!is_readable(PROJECT_PATH_CONFIG . "config.yaml")) { - throw new \Exception("config/config.yaml is not readable. Please give read permissions to httpd user on file 'config/config.yaml'."); + if (!is_readable(PROJECT_PATH_CONFIG . "baikal.yaml")) { + throw new \Exception("config/baikal.yaml is not readable. Please give read permissions to httpd user on file 'config/baikal.yaml'."); } # Asserting config file is writable - if (!is_writable(PROJECT_PATH_CONFIG . "config.yaml")) { - throw new \Exception("config/config.yaml is not writable. Please give write permissions to httpd user on file 'config/config.yaml'."); - } - # Asserting config file exists - if (!file_exists(PROJECT_PATH_CONFIG . "system.yaml")) { - throw new \Exception("config/system.yaml does not exist. Please use the Install tool to create it or duplicate system.yaml.dist."); - } - - # Asserting config file is readable - if (!is_readable(PROJECT_PATH_CONFIG . "system.yaml")) { - throw new \Exception("config/system.yaml is not readable. Please give read permissions to httpd user on file 'config/system.yaml'."); - } - - # Asserting config file is writable - if (!is_writable(PROJECT_PATH_CONFIG . "system.yaml")) { - throw new \Exception("config/system.yaml is not writable. Please give write permissions to httpd user on file 'config/system.yaml'."); + if (!is_writable(PROJECT_PATH_CONFIG . "baikal.yaml")) { + throw new \Exception("config/baikal.yaml is not writable. Please give write permissions to httpd user on file 'config/baikal.yaml'."); } } diff --git a/Core/Frameworks/Baikal/Framework.php b/Core/Frameworks/Baikal/Framework.php index a15465d..5fd7ca3 100644 --- a/Core/Frameworks/Baikal/Framework.php +++ b/Core/Frameworks/Baikal/Framework.php @@ -52,31 +52,24 @@ class Framework extends \Flake\Core\Framework { \Baikal\Core\Tools::configureEnvironment(); # Check that a config file exists - if ( - !file_exists(PROJECT_PATH_CONFIG . "config.yaml") || - !file_exists(PROJECT_PATH_CONFIG . "system.yaml") - ) { + if (!file_exists(PROJECT_PATH_CONFIG . "baikal.yaml")) { self::installTool(); } else { - - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); - $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); - date_default_timezone_set($config['parameters']['project_timezone']); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); + date_default_timezone_set($config['system']['timezone']); # Check that Baïkal is already configured - if (!isset($configSystem['parameters']['baikal_configured_version'])) { + if (!isset($config['system']['configured_version'])) { self::installTool(); - } else { # Check that running version matches configured version - if (version_compare(BAIKAL_VERSION, $configSystem['parameters']['baikal_configured_version']) > 0) { + if (version_compare(BAIKAL_VERSION, $config['system']['configured_version']) > 0) { self::installTool(); - } else { # Check that admin password is set - if (!$config['parameters']['baikal_admin_passwordhash']) { + if (!$config['system']['admin_passwordhash']) { self::installTool(); } diff --git a/Core/Frameworks/Baikal/Model/Config.php b/Core/Frameworks/Baikal/Model/Config.php index 12a1f05..27dc0be 100644 --- a/Core/Frameworks/Baikal/Model/Config.php +++ b/Core/Frameworks/Baikal/Model/Config.php @@ -31,19 +31,18 @@ use Symfony\Component\Yaml\Yaml; abstract class Config extends \Flake\Core\Model\NoDb { - protected $sConfigFilePath = ""; + protected $sConfigFileSection = ""; protected $aData = []; - function __construct($sConfigFilePath) { - + function __construct($sConfigFileSection) { # Note: no call to parent::__construct() to avoid erasing $this->aData - $this->sConfigFilePath = $sConfigFilePath; + $this->sConfigFileSection = $sConfigFileSection; try { - $config = Yaml::parseFile($this->sConfigFilePath); - $aConfig = $config['parameters']; + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); + $aConfig = $config[$sConfigFileSection]; } catch (\Exception $e) { - error_log('Error reading "' . $this->sConfigFilePath . '" file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); $aConfig = static::getDefaultConfig(); } @@ -56,8 +55,8 @@ abstract class Config extends \Flake\Core\Model\NoDb { } protected function getConfigAsString() { - if (file_exists($this->sConfigFilePath)) { - return Yaml::parseFile($this->sConfigFilePath); + if (file_exists(PROJECT_PATH_CONFIG . "baikal.yaml")) { + return Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml")[$this->sConfigFileSection]; } else { return static::getDefaultConfig(); } @@ -65,9 +64,9 @@ abstract class Config extends \Flake\Core\Model\NoDb { function writable() { return ( - @file_exists($this->sConfigFilePath) && - @is_file($this->sConfigFilePath) && - @is_writable($this->sConfigFilePath) + @file_exists(PROJECT_PATH_CONFIG . "baikal.yaml") && + @is_file(PROJECT_PATH_CONFIG . "baikal.yaml") && + @is_writable(PROJECT_PATH_CONFIG . "baikal.yaml") ); } @@ -88,10 +87,10 @@ abstract class Config extends \Flake\Core\Model\NoDb { } function persist() { - $yaml = Yaml::dump([ - 'parameters' => $this->aData - ]); - file_put_contents($this->sConfigFilePath, $yaml); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); + $config[$this->sConfigFileSection] = $this->aData; + $yaml = Yaml::dump($config); + file_put_contents(PROJECT_PATH_CONFIG . "baikal.yaml", $yaml); } function destroy() { diff --git a/Core/Frameworks/Baikal/Model/Config/Database.php b/Core/Frameworks/Baikal/Model/Config/Database.php index 9090c2a..6a01743 100644 --- a/Core/Frameworks/Baikal/Model/Config/Database.php +++ b/Core/Frameworks/Baikal/Model/Config/Database.php @@ -30,27 +30,27 @@ namespace Baikal\Model\Config; class Database extends \Baikal\Model\Config { protected $aConstants = [ - "project_sqlite_file" => [ + "sqlite_file" => [ "type" => "litteral", "comment" => "Define path to Baïkal Database SQLite file", ], - "project_db_mysql" => [ + "mysql" => [ "type" => "boolean", "comment" => "MySQL > Use MySQL instead of SQLite ?", ], - "project_db_mysql_host" => [ + "mysql_host" => [ "type" => "string", "comment" => "MySQL > Host, including ':portnumber' if port is not the default one (3306)", ], - "project_db_mysql_dbname" => [ + "mysql_dbname" => [ "type" => "string", "comment" => "MySQL > Database name", ], - "project_db_mysql_username" => [ + "mysql_username" => [ "type" => "string", "comment" => "MySQL > Username", ], - "project_db_mysql_password" => [ + "mysql_password" => [ "type" => "string", "comment" => "MySQL > Password", ], @@ -58,19 +58,23 @@ class Database extends \Baikal\Model\Config { # Default values protected $aData = [ - "project_sqlite_file" => PROJECT_PATH_SPECIFIC . "db/db.sqlite", - "project_db_mysql" => false, - "project_db_mysql_host" => "", - "project_db_mysql_dbname" => "", - "project_db_mysql_username" => "", - "project_db_mysql_password" => "", + "sqlite_file" => PROJECT_PATH_SPECIFIC . "db/db.sqlite", + "mysql" => false, + "mysql_host" => "", + "mysql_dbname" => "", + "mysql_username" => "", + "mysql_password" => "", ]; + function __construct() { + parent::__construct("database"); + } + function formMorphologyForThisModelInstance() { $oMorpho = new \Formal\Form\Morphology(); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "project_sqlite_file", + "prop" => "sqlite_file", "label" => "SQLite file path", "validation" => "required", "inputclass" => "input-xxlarge", @@ -78,30 +82,30 @@ class Database extends \Baikal\Model\Config { ])); $oMorpho->add(new \Formal\Element\Checkbox([ - "prop" => "project_db_mysql", + "prop" => "mysql", "label" => "Use MySQL", "help" => "If checked, Baïkal will use MySQL instead of SQLite.", "refreshonchange" => true, ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "project_db_mysql_host", + "prop" => "mysql_host", "label" => "MySQL host", "help" => "Host ip or name, including ':portnumber' if port is not the default one (3306)" ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "project_db_mysql_dbname", + "prop" => "mysql_dbname", "label" => "MySQL database name", ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "project_db_mysql_username", + "prop" => "mysql_username", "label" => "MySQL username", ])); $oMorpho->add(new \Formal\Element\Password([ - "prop" => "project_db_mysql_password", + "prop" => "mysql_password", "label" => "MySQL password", ])); diff --git a/Core/Frameworks/Baikal/Model/Config/Standard.php b/Core/Frameworks/Baikal/Model/Config/Standard.php index 661abca..65b79d3 100644 --- a/Core/Frameworks/Baikal/Model/Config/Standard.php +++ b/Core/Frameworks/Baikal/Model/Config/Standard.php @@ -32,27 +32,27 @@ use Symfony\Component\Yaml\Yaml; class Standard extends \Baikal\Model\Config { protected $aConstants = [ - "project_timezone" => [ + "timezone" => [ "type" => "string", "comment" => "Timezone of the server; if unsure, check http://en.wikipedia.org/wiki/List_of_tz_database_time_zones", ], - "baikal_card_enabled" => [ + "card_enabled" => [ "type" => "boolean", "comment" => "CardDAV ON/OFF switch; default TRUE", ], - "baikal_cal_enabled" => [ + "cal_enabled" => [ "type" => "boolean", "comment" => "CalDAV ON/OFF switch; default TRUE", ], - "baikal_invite_from" => [ + "invite_from" => [ "type" => "string", "comment" => "CalDAV invite From: mail address (comment or leave blank to disable notifications)", ], - "baikal_dav_auth_type" => [ + "dav_auth_type" => [ "type" => "string", "comment" => "HTTP authentication type for WebDAV; default Digest" ], - "baikal_admin_passwordhash" => [ + "admin_passwordhash" => [ "type" => "string", "comment" => "Baïkal Web admin password hash; Set via Baïkal Web Admin", ] @@ -60,20 +60,25 @@ class Standard extends \Baikal\Model\Config { # Default values protected $aData = [ - "project_timezone" => "Europe/Paris", - "baikal_card_enabled" => true, - "baikal_cal_enabled" => true, - "baikal_invite_from" => "", - "baikal_dav_auth_type" => "Digest", - "baikal_admin_passwordhash" => "", - "baikal_auth_realm" => "BaikalDAV" + "configured_version" => BAIKAL_VERSION, + "timezone" => "Europe/Paris", + "card_enabled" => true, + "cal_enabled" => true, + "invite_from" => "", + "dav_auth_type" => "Digest", + "admin_passwordhash" => "", + "auth_realm" => "BaikalDAV" ]; + function __construct() { + parent::__construct("system"); + } + function formMorphologyForThisModelInstance() { $oMorpho = new \Formal\Form\Morphology(); $oMorpho->add(new \Formal\Element\Listbox([ - "prop" => "project_timezone", + "prop" => "timezone", "label" => "Server Time zone", "validation" => "required", "options" => \Baikal\Core\Tools::timezones(), @@ -81,52 +86,52 @@ class Standard extends \Baikal\Model\Config { $oMorpho->add(new \Formal\Element\Checkbox([ - "prop" => "baikal_card_enabled", + "prop" => "card_enabled", "label" => "Enable CardDAV" ])); $oMorpho->add(new \Formal\Element\Checkbox([ - "prop" => "baikal_cal_enabled", + "prop" => "cal_enabled", "label" => "Enable CalDAV" ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "baikal_invite_from", + "prop" => "invite_from", "label" => "Email invite sender address", "help" => "Leave empty to disable sending invite emails" ])); $oMorpho->add(new \Formal\Element\Listbox([ - "prop" => "baikal_dav_auth_type", + "prop" => "dav_auth_type", "label" => "WebDAV authentication type", "options" => ["Digest", "Basic"] ])); $oMorpho->add(new \Formal\Element\Password([ - "prop" => "baikal_admin_passwordhash", + "prop" => "admin_passwordhash", "label" => "Admin password", ])); $oMorpho->add(new \Formal\Element\Password([ - "prop" => "baikal_admin_passwordhash_confirm", + "prop" => "admin_passwordhash_confirm", "label" => "Admin password, confirmation", - "validation" => "sameas:baikal_admin_passwordhash", + "validation" => "sameas:admin_passwordhash", ])); try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { - error_log('Error reading system.yaml file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); } - if (!isset($config['parameters']["baikal_admin_passwordhash"]) || trim($config['parameters']["baikal_admin_passwordhash"]) === "") { + if (!isset($config['parameters']["admin_passwordhash"]) || trim($config['system']["admin_passwordhash"]) === "") { # No password set (Form is used in install tool), so password is required as it has to be defined - $oMorpho->element("baikal_admin_passwordhash")->setOption("validation", "required"); + $oMorpho->element("admin_passwordhash")->setOption("validation", "required"); } else { $sNotice = "-- Leave empty to keep current password --"; - $oMorpho->element("baikal_admin_passwordhash")->setOption("placeholder", $sNotice); - $oMorpho->element("baikal_admin_passwordhash_confirm")->setOption("placeholder", $sNotice); + $oMorpho->element("admin_passwordhash")->setOption("placeholder", $sNotice); + $oMorpho->element("admin_passwordhash_confirm")->setOption("placeholder", $sNotice); } return $oMorpho; @@ -137,12 +142,12 @@ class Standard extends \Baikal\Model\Config { } function set($sProp, $sValue) { - if ($sProp === "baikal_admin_passwordhash" || $sProp === "baikal_admin_passwordhash_confirm") { + if ($sProp === "admin_passwordhash" || $sProp === "admin_passwordhash_confirm") { # Special handling for password and passwordconfirm - if ($sProp === "baikal_admin_passwordhash" && $sValue !== "") { + if ($sProp === "admin_passwordhash" && $sValue !== "") { parent::set( - "baikal_admin_passwordhash", + "admin_passwordhash", \BaikalAdmin\Core\Auth::hashAdminPassword($sValue) ); } @@ -154,7 +159,7 @@ class Standard extends \Baikal\Model\Config { } function get($sProp) { - if ($sProp === "baikal_admin_passwordhash" || $sProp === "baikal_admin_passwordhash_confirm") { + if ($sProp === "admin_passwordhash" || $sProp === "admin_passwordhash_confirm") { return ""; } @@ -164,13 +169,14 @@ class Standard extends \Baikal\Model\Config { protected static function getDefaultConfig() { return [ - "project_timezone" => "Europe/Paris", - "baikal_card_enabled" => true, - "baikal_cal_enabled" => true, - "baikal_invite_from" => "noreply@" . $_SERVER['SERVER_NAME'], - "baikal_dav_auth_type" => "Digest", - "baikal_admin_passwordhash" => "", - "baikal_auth_realm" => "BaikalDAV", + "timezone" => "Europe/Paris", + "card_enabled" => true, + "cal_enabled" => true, + "invite_from" => "noreply@" . $_SERVER['SERVER_NAME'], + "dav_auth_type" => "Digest", + "admin_passwordhash" => "", + "auth_realm" => "BaikalDAV", + "configured_version" => BAIKAL_VERSION ]; } } diff --git a/Core/Frameworks/Baikal/Model/Config/System.php b/Core/Frameworks/Baikal/Model/Config/System.php index 8018dbd..c03a439 100644 --- a/Core/Frameworks/Baikal/Model/Config/System.php +++ b/Core/Frameworks/Baikal/Model/Config/System.php @@ -30,27 +30,27 @@ namespace Baikal\Model\Config; class System extends \Baikal\Model\Config { protected $aConstants = [ - "project_sqlite_file" => [ + "sqlite_file" => [ "type" => "litteral", "comment" => "Define path to Baïkal Database SQLite file", ], - "project_db_mysql" => [ + "mysql" => [ "type" => "boolean", "comment" => "MySQL > Use MySQL instead of SQLite ?", ], - "project_db_mysql_host" => [ + "mysql_host" => [ "type" => "string", "comment" => "MySQL > Host, including ':portnumber' if port is not the default one (3306)", ], - "project_db_mysql_dbname" => [ + "mysql_dbname" => [ "type" => "string", "comment" => "MySQL > Database name", ], - "project_db_mysql_username" => [ + "mysql_username" => [ "type" => "string", "comment" => "MySQL > Username", ], - "project_db_mysql_password" => [ + "mysql_password" => [ "type" => "string", "comment" => "MySQL > Password", ], @@ -66,21 +66,25 @@ class System extends \Baikal\Model\Config { # Default values protected $aData = [ - "project_sqlite_file" => "db/db.sqlite", - "project_db_mysql" => false, - "project_db_mysql_host" => "", - "project_db_mysql_dbname" => "", - "project_db_mysql_username" => "", - "project_db_mysql_password" => "", - "baikal_encryption_key" => "", - "baikal_configured_version" => "", + "sqlite_file" => "db/db.sqlite", + "mysql" => false, + "mysql_host" => "", + "mysql_dbname" => "", + "mysql_username" => "", + "mysql_password" => "", + "encryption_key" => "", + "configured_version" => "", ]; + function __construct() { + parent::__construct("database"); + } + function formMorphologyForThisModelInstance() { $oMorpho = new \Formal\Form\Morphology(); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "project_sqlite_file", + "prop" => "sqlite_file", "label" => "SQLite file path", "validation" => "required", "inputclass" => "input-xxlarge", @@ -88,30 +92,30 @@ class System extends \Baikal\Model\Config { ])); $oMorpho->add(new \Formal\Element\Checkbox([ - "prop" => "project_db_mysql", + "prop" => "mysql", "label" => "Use MySQL", "help" => "If checked, Baïkal will use MySQL instead of SQLite.", "refreshonchange" => true, ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "project_db_mysql_host", + "prop" => "mysql_host", "label" => "MySQL host", "help" => "Host ip or name, including ':portnumber' if port is not the default one (3306)" ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "project_db_mysql_dbname", + "prop" => "mysql_dbname", "label" => "MySQL database name", ])); $oMorpho->add(new \Formal\Element\Text([ - "prop" => "project_db_mysql_username", + "prop" => "mysql_username", "label" => "MySQL username", ])); $oMorpho->add(new \Formal\Element\Password([ - "prop" => "project_db_mysql_password", + "prop" => "mysql_password", "label" => "MySQL password", ])); @@ -125,14 +129,13 @@ class System extends \Baikal\Model\Config { protected static function getDefaultConfig() { return [ - "project_sqlite_file" => "db/db.sqlite", - "project_db_mysql" => false, - "project_db_mysql_host" => "", - "project_db_mysql_dbname" => "", - "project_db_mysql_username" => "", - "project_db_mysql_password" => "", - "baikal_encryption_key" => "", - "baikal_configured_version" => BAIKAL_VERSION + "sqlite_file" => "db/db.sqlite", + "mysql" => false, + "mysql_host" => "", + "mysql_dbname" => "", + "mysql_username" => "", + "mysql_password" => "", + "encryption_key" => "" ]; } } diff --git a/Core/Frameworks/Baikal/Model/User.php b/Core/Frameworks/Baikal/Model/User.php index f240794..9a63898 100644 --- a/Core/Frameworks/Baikal/Model/User.php +++ b/Core/Frameworks/Baikal/Model/User.php @@ -283,11 +283,11 @@ class User extends \Flake\Core\Model\Db { function getPasswordHashForPassword($sPassword) { try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { - error_log('Error reading config.yaml file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); } - return md5($this->get("username") . ':' . $config['parameters']['baikal_auth_realm'] . ':' . $sPassword); + return md5($this->get("username") . ':' . $config['system']['auth_realm'] . ':' . $sPassword); } } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php b/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php index 8e4626d..0988f22 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Dashboard.php @@ -36,14 +36,14 @@ class Dashboard extends \Flake\Core\Controller { function render() { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); $oView = new \BaikalAdmin\View\Dashboard(); $oView->setData("BAIKAL_VERSION", BAIKAL_VERSION); # Services status - $oView->setData("baikal_cal_enabled", $config['parameters']['baikal_cal_enabled']); - $oView->setData("baikal_card_enabled", $config['parameters']['baikal_card_enabled']); + $oView->setData("baikal_cal_enabled", $config['system']['cal_enabled']); + $oView->setData("baikal_card_enabled", $config['system']['card_enabled']); # Statistics: Users $iNbUsers = \Baikal\Model\User::getBaseRequester()->count(); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php index 6c0f7eb..b500fc7 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php @@ -40,13 +40,13 @@ class Database extends \Flake\Core\Controller { if (file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) { require_once(PROJECT_PATH_SPECIFIC . "config.system.php"); - $this->oModel->set('project_sqlite_file', PROJECT_SQLITE_FILE); - $this->oModel->set('project_db_mysql', PROJECT_DB_MYSQL); - $this->oModel->set('project_db_mysql_host', PROJECT_DB_MYSQL_HOST); - $this->oModel->set('project_db_mysql_dbname', PROJECT_DB_MYSQL_DBNAME); - $this->oModel->set('project_db_mysql_username', PROJECT_DB_MYSQL_USERNAME); - $this->oModel->set('project_db_mysql_password', PROJECT_DB_MYSQL_PASSWORD); - $this->oModel->set('baikal_encryption_key', BAIKAL_ENCRYPTION_KEY); + $this->oModel->set('sqlite_file', PROJECT_SQLITE_FILE); + $this->oModel->set('mysql', PROJECT_DB_MYSQL); + $this->oModel->set('mysql_host', PROJECT_DB_MYSQL_HOST); + $this->oModel->set('mysql_dbname', PROJECT_DB_MYSQL_DBNAME); + $this->oModel->set('mysql_username', PROJECT_DB_MYSQL_USERNAME); + $this->oModel->set('mysql_password', PROJECT_DB_MYSQL_PASSWORD); + $this->oModel->set('encryption_key', BAIKAL_ENCRYPTION_KEY); } $this->oForm = $this->oModel->formForThisModelInstance([ @@ -95,14 +95,14 @@ class Database extends \Flake\Core\Controller { if ($oForm->refreshed()){ return true; } - $bMySQLEnabled = $oMorpho->element("project_db_mysql")->value(); + $bMySQLEnabled = $oMorpho->element("mysql")->value(); if ($bMySQLEnabled) { - $sHost = $oMorpho->element("project_db_mysql_host")->value(); - $sDbname = $oMorpho->element("project_db_mysql_dbname")->value(); - $sUsername = $oMorpho->element("project_db_mysql_username")->value(); - $sPassword = $oMorpho->element("project_db_mysql_password")->value(); + $sHost = $oMorpho->element("mysql_host")->value(); + $sDbname = $oMorpho->element("mysql_dbname")->value(); + $sUsername = $oMorpho->element("mysql_username")->value(); + $sPassword = $oMorpho->element("mysql_password")->value(); try { $oDb = new \Flake\Core\Database\Mysql( @@ -123,7 +123,7 @@ class Database extends \Flake\Core\Controller { $sMessage .= "

Nothing has been saved. Please, add these tables to the database before pursuing Baïkal initialization.

"; $oForm->declareError( - $oMorpho->element("project_db_mysql"), + $oMorpho->element("mysql"), $sMessage ); } else { @@ -136,29 +136,29 @@ class Database extends \Flake\Core\Controller { return true; } catch (\Exception $e) { - $oForm->declareError($oMorpho->element("project_db_mysql"), + $oForm->declareError($oMorpho->element("mysql"), "Baïkal was not able to establish a connexion to the MySQL database as configured.
MySQL says: " . $e->getMessage()); - $oForm->declareError($oMorpho->element("project_db_mysql_host")); - $oForm->declareError($oMorpho->element("project_db_mysql_dbname")); - $oForm->declareError($oMorpho->element("project_db_mysql_username")); - $oForm->declareError($oMorpho->element("project_db_mysql_password")); + $oForm->declareError($oMorpho->element("mysql_host")); + $oForm->declareError($oMorpho->element("mysql_dbname")); + $oForm->declareError($oMorpho->element("mysql_username")); + $oForm->declareError($oMorpho->element("mysql_password")); } } else { - $sFile = $oMorpho->element("project_sqlite_file")->value(); + $sFile = $oMorpho->element("sqlite_file")->value(); try { # Asserting DB file is writable if (file_exists($sFile) && !is_writable($sFile)) { $sMessage = "DB file is not writable. Please give write permissions on file " . $sFile . ""; - $oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage); + $oForm->declareError($oMorpho->element("sqlite_file"), $sMessage); return false; } # Asserting DB directory is writable if (!is_writable(dirname($sFile))) { $sMessage = "The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder " . dirname($sFile) . ""; - $oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage); + $oForm->declareError($oMorpho->element("sqlite_file"), $sMessage); return false; } @@ -178,7 +178,7 @@ class Database extends \Flake\Core\Controller { $sMessage .= "

Nothing has been saved. Please, add these tables to the database before pursuing Baïkal initialization.

"; $oForm->declareError( - $oMorpho->element("project_sqlite_file"), + $oMorpho->element("sqlite_file"), $sMessage ); } else { @@ -195,7 +195,7 @@ class Database extends \Flake\Core\Controller { return true; } catch (\Exception $e) { $oForm->declareError( - $oMorpho->element("project_sqlite_file"), + $oMorpho->element("sqlite_file"), "Baïkal was not able to establish a connexion to the SQLite database as configured.
SQLite says: " . $e->getMessage() . (string)$e ); } @@ -206,24 +206,24 @@ class Database extends \Flake\Core\Controller { function hideMySQLFieldWhenNeeded(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) { if ($oForm->submitted()) { - $bMySQL = (intval($oForm->postValue("project_db_mysql")) === 1); + $bMySQL = (intval($oForm->postValue("mysql")) === 1); } else { try { - $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { - error_log('Error reading system.yaml file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); } - $bMySQL = $configSystem['parameters']['project_db_mysql'] ?? true; + $bMySQL = $configSystem['database']['mysql'] ?? true; } if ($bMySQL === true) { - $oMorpho->remove("project_sqlite_file"); + $oMorpho->remove("sqlite_file"); } else { - $oMorpho->remove("project_db_mysql_host"); - $oMorpho->remove("project_db_mysql_dbname"); - $oMorpho->remove("project_db_mysql_username"); - $oMorpho->remove("project_db_mysql_password"); + $oMorpho->remove("mysql_host"); + $oMorpho->remove("mysql_dbname"); + $oMorpho->remove("mysql_username"); + $oMorpho->remove("mysql_password"); } } } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index 400ad46..edb4f85 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -50,11 +50,11 @@ class Initialize extends \Flake\Core\Controller { // If we come from pre-0.7.0, we need to get the values from the config.php and config.system.php files if (file_exists(PROJECT_PATH_SPECIFIC . "config.php")) { require_once(PROJECT_PATH_SPECIFIC . "config.php"); - $this->oModel->set('project_timezone', PROJECT_TIMEZONE); - $this->oModel->set('baikal_card_enabled', BAIKAL_CARD_ENABLED); - $this->oModel->set('baikal_cal_enabled', BAIKAL_CAL_ENABLED); - $this->oModel->set('baikal_invite_from', BAIKAL_INVITE_FROM); - $this->oModel->set('baikal_dav_auth_type', BAIKAL_DAV_AUTH_TYPE); + $this->oModel->set('timezone', PROJECT_TIMEZONE); + $this->oModel->set('card_enabled', BAIKAL_CARD_ENABLED); + $this->oModel->set('cal_enabled', BAIKAL_CAL_ENABLED); + $this->oModel->set('invite_from', BAIKAL_INVITE_FROM); + $this->oModel->set('dav_auth_type', BAIKAL_DAV_AUTH_TYPE); } $this->oForm = $this->oModel->formForThisModelInstance([ @@ -75,13 +75,13 @@ class Initialize extends \Flake\Core\Controller { } # Creating system config, and initializing BAIKAL_ENCRYPTION_KEY - $oSystemConfig = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); - $oSystemConfig->set("baikal_encryption_key", md5(microtime() . rand())); + $oSystemConfig = new \Baikal\Model\Config\System("system"); + $oSystemConfig->set("encryption_key", md5(microtime() . rand())); # Default: PDO::SQLite or PDO::MySQL ? $aPDODrivers = \PDO::getAvailableDrivers(); if (!in_array('sqlite', $aPDODrivers)) { # PDO::MySQL is already asserted in \Baikal\Core\Tools::assertEnvironmentIsOk() - $oSystemConfig->set("project_db_mysql", true); + $oSystemConfig->set("mysql", true); } $oSystemConfig->persist(); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php b/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php index d1154d6..822df29 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/UpgradeConfirmation.php @@ -38,13 +38,13 @@ class UpgradeConfirmation extends \Flake\Core\Controller { $oView = new \BaikalAdmin\View\Install\UpgradeConfirmation(); try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { - error_log('Error reading config.yaml file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); } - if (isset($config['parameters']['baikal_configured_version']) && $config['parameters']['baikal_configured_version'] === BAIKAL_VERSION) { - $sMessage = "Your system is configured to use version " . $config['parameters']['baikal_configured_version'] . ".
There's no upgrade to be done."; + if (isset($config['system']['configured_version']) && $config['system']['configured_version'] === BAIKAL_VERSION) { + $sMessage = "Your system is configured to use version " . $config['system']['configured_version'] . ".
There's no upgrade to be done."; } else { $sMessage = "Upgrading Baïkal from version " . "Unknown" . " to version " . BAIKAL_VERSION . ""; } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php index 3a44da7..005460b 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php @@ -44,16 +44,16 @@ class VersionUpgrade extends \Flake\Core\Controller { function render() { try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { - error_log('Error reading system.yaml file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); } $sBigIcon = "glyph2x-magic"; $sBaikalVersion = BAIKAL_VERSION; - $sBaikalConfiguredVersion = $config['parameters']['baikal_configured_version']; + $sBaikalConfiguredVersion = $config['system']['configured_version']; - if ($config['parameters']['baikal_configured_version'] === BAIKAL_VERSION) { + if ($config['system']['configured_version'] === BAIKAL_VERSION) { $sMessage = "Your system is configured to use version " . $sBaikalConfiguredVersion . ".
There's no upgrade to be done."; } else { $sMessage = "Upgrading Baïkal from version " . $sBaikalConfiguredVersion . " to version " . $sBaikalVersion . ""; @@ -67,7 +67,7 @@ class VersionUpgrade extends \Flake\Core\Controller { HTML; try { - $bSuccess = $this->upgrade($config['parameters']['baikal_configured_version'], BAIKAL_VERSION); + $bSuccess = $this->upgrade($config['system']['configured_version'], BAIKAL_VERSION); } catch (\Exception $e) { $bSuccess = false; $this->aErrors[] = 'Uncaught exception during upgrade: ' . (string)$e; @@ -532,11 +532,11 @@ SQL protected function updateConfiguredVersion($sVersionTo) { # Create new settings - $oConfig = new \Baikal\Model\Config\Standard(PROJECT_PATH_CONFIG . "config.yaml"); + $oConfig = new \Baikal\Model\Config\Standard("config"); $oConfig->persist(); # Update BAIKAL_CONFIGURED_VERSION - $oConfig = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); + $oConfig = new \Baikal\Model\Config\System("system"); $oConfig->set("baikal_configured_version", $sVersionTo); $oConfig->persist(); } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Settings/Standard.php b/Core/Frameworks/BaikalAdmin/Controller/Settings/Standard.php index d308afa..8782a5a 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Settings/Standard.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Settings/Standard.php @@ -40,7 +40,7 @@ class Standard extends \Flake\Core\Controller { private $oForm; function execute() { - $this->oModel = new \Baikal\Model\Config\Standard(PROJECT_PATH_CONFIG . "config.yaml"); + $this->oModel = new \Baikal\Model\Config\Standard(); # Assert that config file is writable if (!$this->oModel->writable()) { diff --git a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php index ad462f2..9f2c4a3 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Settings/System.php @@ -42,7 +42,7 @@ class System extends \Flake\Core\Controller { private $oForm; function execute() { - $this->oModel = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); + $this->oModel = new \Baikal\Model\Config\System(); # Assert that config file is writable if (!$this->oModel->writable()) { @@ -76,24 +76,24 @@ class System extends \Flake\Core\Controller { function morphologyHook(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) { if ($oForm->submitted()) { - $bMySQL = (intval($oForm->postValue("project_db_mysql")) === 1); + $bMySQL = (intval($oForm->postValue("mysql")) === 1); } else { try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { - error_log('Error reading system.yaml file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); } - $bMySQL = $config['parameters']['project_db_mysql'] ?? true; + $bMySQL = $config['database']['mysql'] ?? true; } if ($bMySQL === true) { - $oMorpho->remove("project_sqlite_file"); + $oMorpho->remove("sqlite_file"); } else { - $oMorpho->remove("project_db_mysql_host"); - $oMorpho->remove("project_db_mysql_dbname"); - $oMorpho->remove("project_db_mysql_username"); - $oMorpho->remove("project_db_mysql_password"); + $oMorpho->remove("mysql_host"); + $oMorpho->remove("mysql_dbname"); + $oMorpho->remove("mysql_username"); + $oMorpho->remove("mysql_password"); } } @@ -101,13 +101,13 @@ class System extends \Flake\Core\Controller { if ($oForm->refreshed()){ return true; } - if (intval($oForm->modelInstance()->get("project_db_mysql")) === 1) { + if (intval($oForm->modelInstance()->get("mysql")) === 1) { # We have to check the MySQL connection - $sHost = $oForm->modelInstance()->get("project_db_mysql_host"); - $sDbName = $oForm->modelInstance()->get("project_db_mysql_dbname"); - $sUsername = $oForm->modelInstance()->get("project_db_mysql_username"); - $sPassword = $oForm->modelInstance()->get("project_db_mysql_password"); + $sHost = $oForm->modelInstance()->get("mysql_host"); + $sDbName = $oForm->modelInstance()->get("mysql_dbname"); + $sUsername = $oForm->modelInstance()->get("mysql_username"); + $sPassword = $oForm->modelInstance()->get("mysql_password"); try { $oDB = new \Flake\Core\Database\Mysql( @@ -119,10 +119,10 @@ class System extends \Flake\Core\Controller { } catch (\Exception $e) { $sMessage = "MySQL error: " . $e->getMessage(); $sMessage .= "
Nothing has been saved"; - $oForm->declareError($oMorpho->element("project_db_mysql_host"), $sMessage); - $oForm->declareError($oMorpho->element("project_db_mysql_dbname")); - $oForm->declareError($oMorpho->element("project_db_mysql_username")); - $oForm->declareError($oMorpho->element("project_db_mysql_password")); + $oForm->declareError($oMorpho->element("mysql_host"), $sMessage); + $oForm->declareError($oMorpho->element("mysql_dbname")); + $oForm->declareError($oMorpho->element("mysql_username")); + $oForm->declareError($oMorpho->element("mysql_password")); return; } @@ -131,31 +131,24 @@ class System extends \Flake\Core\Controller { $sMessage .= "You may want create these tables using the file Core/Resources/Db/MySQL/db.sql"; $sMessage .= "

Nothing has been saved"; - $oForm->declareError($oMorpho->element("project_db_mysql"), $sMessage); + $oForm->declareError($oMorpho->element("mysql"), $sMessage); return; } } else { - $sFile = $oMorpho->element("project_sqlite_file")->value(); + $sFile = $oMorpho->element("sqlite_file")->value(); try { - - // not sure yet how to better address this - // yup! this is mental, but even if we don't use eval, effectively these - // config settings are eval'ed because they are written as raw php files. - // We'll have to clean this up later. - $sFile = eval('return ' . $sFile . ';'); - # Asserting DB file is writable if (file_exists($sFile) && !is_writable($sFile)) { $sMessage = "DB file is not writable. Please give write permissions on file " . $sFile . ""; - $oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage); + $oForm->declareError($oMorpho->element("sqlite_file"), $sMessage); return; } # Asserting DB directory is writable if (!is_writable(dirname($sFile))) { $sMessage = "The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder " . dirname($sFile) . ""; - $oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage); + $oForm->declareError($oMorpho->element("sqlite_file"), $sMessage); return; } @@ -171,14 +164,14 @@ class System extends \Flake\Core\Controller { $sMessage .= "

Nothing has been saved. Please, add these tables to the database before pursuing Baïkal initialization.

"; $oForm->declareError( - $oMorpho->element("project_sqlite_file"), + $oMorpho->element("sqlite_file"), $sMessage ); } return; } catch (\Exception $e) { $oForm->declareError( - $oMorpho->element("project_sqlite_file"), + $oMorpho->element("sqlite_file"), "Baïkal was not able to establish a connexion to the SQLite database as configured.
SQLite says: " . $e->getMessage() . (string)$e ); } diff --git a/Core/Frameworks/BaikalAdmin/Core/Auth.php b/Core/Frameworks/BaikalAdmin/Core/Auth.php index c4b6213..78b303f 100644 --- a/Core/Frameworks/BaikalAdmin/Core/Auth.php +++ b/Core/Frameworks/BaikalAdmin/Core/Auth.php @@ -32,9 +32,9 @@ use Symfony\Component\Yaml\Yaml; class Auth { static function isAuthenticated() { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); - if (isset($_SESSION["baikaladminauth"]) && $_SESSION["baikaladminauth"] === md5($config['parameters']['baikal_admin_passwordhash'])) { + if (isset($_SESSION["baikaladminauth"]) && $_SESSION["baikaladminauth"] === md5($config['system']['admin_passwordhash'])) { return true; } @@ -52,12 +52,12 @@ class Auth { $sPassHash = self::hashAdminPassword($sPass); try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { - error_log('Error reading config.yaml file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); } - if ($sUser === "admin" && $sPassHash === $config['parameters']['baikal_admin_passwordhash']) { - $_SESSION["baikaladminauth"] = md5($config['parameters']['baikal_admin_passwordhash']); + if ($sUser === "admin" && $sPassHash === $config['system']['admin_passwordhash']) { + $_SESSION["baikaladminauth"] = md5($config['system']['admin_passwordhash']); return true; } @@ -72,13 +72,13 @@ class Auth { static function hashAdminPassword($sPassword) { try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { - error_log('Error reading config.yaml file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); } # Fallback to default value; useful when initializing App, as all constants are not set yet - $sAuthRealm = $config['parameters']['baikal_auth_realm'] ?? "BaikalDAV"; + $sAuthRealm = $config['system']['auth_realm'] ?? "BaikalDAV"; return hash('sha256', 'admin:' . $sAuthRealm . ':' . $sPassword); } diff --git a/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html b/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html index 05daca2..a426df4 100644 --- a/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html +++ b/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html @@ -38,7 +38,7 @@

Services

- {% if baikal_cal_enabled %} + {% if cal_enabled %} {% set caldavclass = 'label-success' %} {% set caldavtext = 'On' %} {% else %} @@ -46,7 +46,7 @@ {% set caldavtext = 'Off' %} {% endif %} - {% if baikal_card_enabled %} + {% if card_enabled %} {% set carddavclass = 'label-success' %} {% set carddavtext = 'On' %} {% else %} diff --git a/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php b/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php index 344b61b..6a757bb 100644 --- a/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php +++ b/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php @@ -68,27 +68,21 @@ $oPage->setBaseUrl(PROJECT_URI); $oPage->zone("navbar")->addBlock(new \BaikalAdmin\Controller\Navigation\Topbar\Install()); try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { $config = null; - error_log('Error reading config.yaml file : ' . $e->getMessage()); -} -try { - $configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); -} catch (\Exception $e) { - $configSystem = null; - error_log('Error reading system.yaml file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); } -if (!$configSystem || !isset($configSystem['parameters']["baikal_configured_version"])) { +if (!$config || !isset($config['system']["configured_version"])) { # we have to upgrade Baïkal (existing installation) $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Initialize()); -} elseif (!$config || !isset($config['parameters']["baikal_admin_passwordhash"])) { +} elseif (!isset($config['system']["admin_passwordhash"])) { # we have to set an admin password $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Initialize()); } else { - if ($configSystem['parameters']["baikal_configured_version"] !== BAIKAL_VERSION) { + if ($config['system']["configured_version"] !== BAIKAL_VERSION) { # we have to upgrade Baïkal if (\Flake\Util\Tools::GET("upgradeConfirmed")) { $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\VersionUpgrade()); diff --git a/Core/Frameworks/Flake/Framework.php b/Core/Frameworks/Flake/Framework.php index 9fa76ce..cade4e4 100644 --- a/Core/Frameworks/Flake/Framework.php +++ b/Core/Frameworks/Flake/Framework.php @@ -215,16 +215,16 @@ class Framework extends \Flake\Core\Framework { protected static function initDb() { try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { - error_log('Error reading system.yaml file : ' . $e->getMessage()); + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); return true; } # Dont init db on install, but in normal mode and when upgrading - if (defined("BAIKAL_CONTEXT_INSTALL") && (!isset($config['parameters']['baikal_configured_version']) || $config['parameters']['baikal_configured_version'] === BAIKAL_VERSION)) { + if (defined("BAIKAL_CONTEXT_INSTALL") && (!isset($config['system']['configured_version']) || $config['system']['configured_version'] === BAIKAL_VERSION)) { return true; } - if ($config['parameters']['project_db_mysql'] === true) { + if ($config['database']['mysql'] === true) { self::initDbMysql($config); } else { self::initDbSqlite($config); @@ -233,22 +233,22 @@ class Framework extends \Flake\Core\Framework { protected static function initDbSqlite(array $config) { # Asserting DB filepath is set - if (!$config['parameters']['project_sqlite_file']) { + if (!$config['database']['sqlite_file']) { return false; } # Asserting DB file is writable - if (file_exists($config['parameters']['project_sqlite_file']) && !is_writable($config['parameters']['project_sqlite_file'])) { - die("

DB file is not writable. Please give write permissions on file '" . $config['parameters']['project_sqlite_file'] . "'

"); + if (file_exists($config['database']['sqlite_file']) && !is_writable($config['database']['sqlite_file'])) { + die("

DB file is not writable. Please give write permissions on file '" . $config['database']['sqlite_file'] . "'

"); } # Asserting DB directory is writable - if (!is_writable(dirname($config['parameters']['project_sqlite_file']))) { - die("

The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder '" . dirname($config['parameters']['project_sqlite_file']) . "'

"); + if (!is_writable(dirname($config['database']['sqlite_file']))) { + die("

The FOLDER containing the DB file is not writable, and it has to.
Please give write permissions on folder '" . dirname($config['database']['sqlite_file']) . "'

"); } - if (file_exists($config['parameters']['project_sqlite_file']) && is_readable($config['parameters']['project_sqlite_file']) && !isset($GLOBALS["DB"])) { - $GLOBALS["DB"] = new \Flake\Core\Database\Sqlite($config['parameters']['project_sqlite_file']); + if (file_exists($config['database']['sqlite_file']) && is_readable($config['database']['sqlite_file']) && !isset($GLOBALS["DB"])) { + $GLOBALS["DB"] = new \Flake\Core\Database\Sqlite($config['database']['sqlite_file']); return true; } @@ -257,28 +257,28 @@ class Framework extends \Flake\Core\Framework { protected static function initDbMysql(array $config) { - if (!$config['parameters']['project_db_mysql_host']) { + if (!$config['database']['mysql_host']) { die("

The constant PROJECT_DB_MYSQL_HOST, containing the MySQL host name, is not set.
You should set it in config/system.yaml

"); } - if (!$config['parameters']['project_db_mysql_dbname']) { + if (!$config['database']['mysql_dbname']) { die("

The constant PROJECT_DB_MYSQL_DBNAME, containing the MySQL database name, is not set.
You should set it in config/system.yaml

"); } - if (!$config['parameters']['project_db_mysql_username']) { + if (!$config['database']['mysql_username']) { die("

The constant PROJECT_DB_MYSQL_USERNAME, containing the MySQL database username, is not set.
You should set it in config/system.yaml

"); } - if (!$config['parameters']['project_db_mysql_password']) { + if (!$config['database']['mysql_password']) { die("

The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.
You should set it in config/system.yaml

"); } try { $GLOBALS["DB"] = new \Flake\Core\Database\Mysql( - $config['parameters']['project_db_mysql_host'], - $config['parameters']['project_db_mysql_dbname'], - $config['parameters']['project_db_mysql_username'], - $config['parameters']['project_db_mysql_password'] + $config['database']['mysql_host'], + $config['database']['mysql_dbname'], + $config['database']['mysql_username'], + $config['database']['mysql_password'] ); # We now setup t6he connexion to use UTF8 diff --git a/config/baikal.yaml.dist b/config/baikal.yaml.dist new file mode 100644 index 0000000..cc2c01b --- /dev/null +++ b/config/baikal.yaml.dist @@ -0,0 +1,17 @@ +system: + configured_version: '0.7.0' + timezone: 'Europe/Paris' + card_enabled: true + cal_enabled: true + invite_from: 'noreply@localhost' + dav_auth_type: 'Digest' + admin_passwordhash: 5fe794627e1f841f8debba065e2c807a + auth_realm: BaikalDAV +database: + encryption_key: 5d3f0fa0192e3058ea70f1bb20924add + sqlite_file: "absolute/path/to/Specific/db/db.sqlite" + mysql: true + mysql_host: 'localhost' + mysql_dbname: 'baikal' + mysql_username: 'baikal' + mysql_password: 'baikal' diff --git a/config/config.yaml.dist b/config/config.yaml.dist deleted file mode 100644 index e71b59f..0000000 --- a/config/config.yaml.dist +++ /dev/null @@ -1,8 +0,0 @@ -parameters: - project_timezone: 'Europe/Paris' - baikal_card_enabled: true - baikal_cal_enabled: true - baikal_invite_from: 'noreply@localhost' - baikal_dav_auth_type: 'Digest' - baikal_admin_passwordhash: 5fe794627e1f841f8debba065e2c807a - baikal_auth_realm: BaikalDAV \ No newline at end of file diff --git a/config/system.yaml.dist b/config/system.yaml.dist deleted file mode 100644 index 0ce1b68..0000000 --- a/config/system.yaml.dist +++ /dev/null @@ -1,9 +0,0 @@ -parameters: - project_sqlite_file: "absolute/path/to/Specific/db/db.sqlite" - project_db_mysql: true - project_db_mysql_host: 'localhost' - project_db_mysql_dbname: 'baikal' - project_db_mysql_username: 'baikal' - project_db_mysql_password: 'baikal' - baikal_encryption_key: '5d3f0fa0192e3058ea70f1bb20924add' - baikal_configured_version: '0.7.0' \ No newline at end of file diff --git a/html/cal.php b/html/cal.php index 1f818b4..6efbef2 100644 --- a/html/cal.php +++ b/html/cal.php @@ -54,20 +54,20 @@ require PROJECT_PATH_ROOT . 'vendor/autoload.php'; \Baikal\Framework::bootstrap(); try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { die('

Incomplete installation

Baïkal is missing its configuration file, or its configuration file is unreadable.'); } -if (!isset($config['parameters']["baikal_cal_enabled"]) || $config['parameters']["baikal_cal_enabled"] !== true) { +if (!isset($config['system']["cal_enabled"]) || $config['system']["cal_enabled"] !== true) { throw new ErrorException("Baikal CalDAV is disabled.", 0, 255, __FILE__, __LINE__); } $server = new \Baikal\Core\Server( - $config['parameters']["baikal_cal_enabled"], - $config['parameters']["baikal_card_enabled"], - $config['parameters']["baikal_dav_auth_type"], - $config['parameters']["baikal_auth_realm"], + $config['system']["cal_enabled"], + $config['system']["card_enabled"], + $config['system']["dav_auth_type"], + $config['system']["auth_realm"], $GLOBALS['DB']->getPDO(), PROJECT_BASEURI . 'cal.php/' ); diff --git a/html/card.php b/html/card.php index ae55ece..ef69b5b 100644 --- a/html/card.php +++ b/html/card.php @@ -55,20 +55,20 @@ require PROJECT_PATH_ROOT . 'vendor/autoload.php'; try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { die('

Incomplete installation

Baïkal is missing its configuration file, or its configuration file is unreadable.'); } -if (!isset($config['parameters']["baikal_card_enabled"]) || $config['parameters']["baikal_card_enabled"] !== true) { +if (!isset($config['system']["card_enabled"]) || $config['parameters']["card_enabled"] !== true) { throw new ErrorException("Baikal CardDAV is disabled.", 0, 255, __FILE__, __LINE__); } $server = new \Baikal\Core\Server( - $config['parameters']["baikal_cal_enabled"], - $config['parameters']["baikal_card_enabled"], - $config['parameters']["baikal_dav_auth_type"], - $config['parameters']["baikal_auth_realm"], + $config['system']["cal_enabled"], + $config['system']["card_enabled"], + $config['system']["dav_auth_type"], + $config['system']["auth_realm"], $GLOBALS['DB']->getPDO(), PROJECT_BASEURI . 'card.php/' ); diff --git a/html/dav.php b/html/dav.php index b6f8a9d..aea37c8 100644 --- a/html/dav.php +++ b/html/dav.php @@ -53,16 +53,16 @@ require PROJECT_PATH_ROOT . 'vendor/autoload.php'; \Baikal\Framework::bootstrap(); try { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml"); + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); } catch (\Exception $e) { die('

Incomplete installation

Baïkal is missing its configuration file, or its configuration file is unreadable.'); } $server = new \Baikal\Core\Server( - $config['parameters']["baikal_cal_enabled"], - $config['parameters']["baikal_card_enabled"], - $config['parameters']["baikal_dav_auth_type"], - $config['parameters']["baikal_auth_realm"], + $config['system']["cal_enabled"], + $config['system']["card_enabled"], + $config['system']["dav_auth_type"], + $config['system']["auth_realm"], $GLOBALS['DB']->getPDO(), PROJECT_BASEURI . 'dav.php/' ); From 71ea5fa03d833d28d8290bed8348a5ccde487800 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 22 Mar 2020 17:33:13 +0100 Subject: [PATCH 25/29] Added missing migrations to a single config file --- .gitignore | 3 +++ Core/Frameworks/Baikal/Model/Calendar.php | 14 +++++++++++++- Core/Frameworks/Baikal/Model/Config/Standard.php | 2 +- html/card.php | 2 +- phpstan.neon | 3 --- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 8c7f057..0897e1f 100755 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ vendor # Others .DS_Store + +# IDE +nbproject diff --git a/Core/Frameworks/Baikal/Model/Calendar.php b/Core/Frameworks/Baikal/Model/Calendar.php index 064c062..8ddca09 100644 --- a/Core/Frameworks/Baikal/Model/Calendar.php +++ b/Core/Frameworks/Baikal/Model/Calendar.php @@ -27,6 +27,8 @@ namespace Baikal\Model; +use Symfony\Component\Yaml\Yaml; + class Calendar extends \Flake\Core\Model\Db { const DATATABLE = "calendarinstances"; const PRIMARYKEY = "id"; @@ -39,11 +41,21 @@ class Calendar extends \Flake\Core\Model\Db { "description" => "", "calendarorder" => 0, "calendarcolor" => "", - "timezone" => PROJECT_TIMEZONE, + "timezone" => null, "calendarid" => 0 ]; protected $oCalendar; # Baikal\Model\Calendar\Calendar + function __construct($sPrimary = false) { + parent::__construct($sPrimary); + try { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); + $this->set("timezone", $config['system']["timezone"]); + } catch (\Exception $e) { + error_log('Error reading baikal.yaml file : ' . $e->getMessage()); + } + } + protected function initFloating() { parent::initFloating(); $this->oCalendar = new Calendar\Calendar(); diff --git a/Core/Frameworks/Baikal/Model/Config/Standard.php b/Core/Frameworks/Baikal/Model/Config/Standard.php index 65b79d3..a654630 100644 --- a/Core/Frameworks/Baikal/Model/Config/Standard.php +++ b/Core/Frameworks/Baikal/Model/Config/Standard.php @@ -124,7 +124,7 @@ class Standard extends \Baikal\Model\Config { error_log('Error reading baikal.yaml file : ' . $e->getMessage()); } - if (!isset($config['parameters']["admin_passwordhash"]) || trim($config['system']["admin_passwordhash"]) === "") { + if (!isset($config['system']["admin_passwordhash"]) || trim($config['system']["admin_passwordhash"]) === "") { # No password set (Form is used in install tool), so password is required as it has to be defined $oMorpho->element("admin_passwordhash")->setOption("validation", "required"); diff --git a/html/card.php b/html/card.php index 4c36852..a617214 100644 --- a/html/card.php +++ b/html/card.php @@ -60,7 +60,7 @@ try { die('

Incomplete installation

Baïkal is missing its configuration file, or its configuration file is unreadable.'); } -if (!isset($config['system']["card_enabled"]) || $config['parameters']["card_enabled"] !== true) { +if (!isset($config['system']["card_enabled"]) || $config['system']["card_enabled"] !== true) { throw new ErrorException("Baikal CardDAV is disabled.", 0, 255, __FILE__, __LINE__); } diff --git a/phpstan.neon b/phpstan.neon index 14a75c4..8adde37 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,9 +8,6 @@ parameters: - message: '#Instantiated class Flake\\Core\\Exception not found.#' path: Core/Frameworks/Flake/Util/Frameworks.php - - - message: '#Call to an undefined method Baikal\\Model\\Config\\Standard::getDefaultSystemConfig\(\).#' - path: Core/Frameworks/Baikal/Model/Config/Standard.php - message: '#Call to static method compileCss\(\) on an unknown class Frameworks\\LessPHP\\Delegate.#' path: Core/Frameworks/Flake/Controller/Page.php From afb6d86d3c0a2c8797f921712f4f06b14ee694d7 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 22 Mar 2020 20:30:37 +0100 Subject: [PATCH 26/29] Fixed installation --- Core/Frameworks/Baikal/Model/Config.php | 26 +++++++++---------- .../Baikal/Model/Config/Database.php | 4 --- .../Baikal/Model/Config/Standard.php | 18 ++----------- .../Frameworks/Baikal/Model/Config/System.php | 15 +---------- .../Controller/Install/Initialize.php | 2 +- 5 files changed, 17 insertions(+), 48 deletions(-) diff --git a/Core/Frameworks/Baikal/Model/Config.php b/Core/Frameworks/Baikal/Model/Config.php index 27dc0be..978ee9a 100644 --- a/Core/Frameworks/Baikal/Model/Config.php +++ b/Core/Frameworks/Baikal/Model/Config.php @@ -41,16 +41,14 @@ abstract class Config extends \Flake\Core\Model\NoDb { try { $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); $aConfig = $config[$sConfigFileSection]; + foreach (array_keys($this->aData) as $sProp) { + if (array_key_exists($sProp, $aConfig)) { + $this->aData[$sProp] = $aConfig[$sProp]; + } + } } catch (\Exception $e) { error_log('Error reading baikal.yaml file : ' . $e->getMessage()); - $aConfig = static::getDefaultConfig(); - } - - - foreach (array_keys($this->aData) as $sProp) { - if (array_key_exists($sProp, $aConfig)) { - $this->aData[$sProp] = $aConfig[$sProp]; - } + // Keep default values in $aData } } @@ -58,7 +56,7 @@ abstract class Config extends \Flake\Core\Model\NoDb { if (file_exists(PROJECT_PATH_CONFIG . "baikal.yaml")) { return Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml")[$this->sConfigFileSection]; } else { - return static::getDefaultConfig(); + return $this->aData; } } @@ -87,7 +85,12 @@ abstract class Config extends \Flake\Core\Model\NoDb { } function persist() { - $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); + if (file_exists(PROJECT_PATH_CONFIG . "baikal.yaml")) { + $config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml"); + } else { + $config = []; + + } $config[$this->sConfigFileSection] = $this->aData; $yaml = Yaml::dump($config); file_put_contents(PROJECT_PATH_CONFIG . "baikal.yaml", $yaml); @@ -96,7 +99,4 @@ abstract class Config extends \Flake\Core\Model\NoDb { function destroy() { } - - protected static function getDefaultConfig() { - } } diff --git a/Core/Frameworks/Baikal/Model/Config/Database.php b/Core/Frameworks/Baikal/Model/Config/Database.php index 6a01743..0eb0404 100644 --- a/Core/Frameworks/Baikal/Model/Config/Database.php +++ b/Core/Frameworks/Baikal/Model/Config/Database.php @@ -115,8 +115,4 @@ class Database extends \Baikal\Model\Config { function label() { return "Baïkal Database Settings"; } - - protected static function getDefaultConfig() { - throw new \Exception("Should never reach getDefaultConfig() on \Baikal\Model\Config\Database"); - } } diff --git a/Core/Frameworks/Baikal/Model/Config/Standard.php b/Core/Frameworks/Baikal/Model/Config/Standard.php index a654630..5507870 100644 --- a/Core/Frameworks/Baikal/Model/Config/Standard.php +++ b/Core/Frameworks/Baikal/Model/Config/Standard.php @@ -64,13 +64,13 @@ class Standard extends \Baikal\Model\Config { "timezone" => "Europe/Paris", "card_enabled" => true, "cal_enabled" => true, - "invite_from" => "", "dav_auth_type" => "Digest", "admin_passwordhash" => "", "auth_realm" => "BaikalDAV" - ]; +]; function __construct() { + $this->aData["invite_from"] = "noreply@" . $_SERVER['SERVER_NAME']; // Default value parent::__construct("system"); } @@ -165,18 +165,4 @@ class Standard extends \Baikal\Model\Config { return parent::get($sProp); } - - protected static function getDefaultConfig() { - - return [ - "timezone" => "Europe/Paris", - "card_enabled" => true, - "cal_enabled" => true, - "invite_from" => "noreply@" . $_SERVER['SERVER_NAME'], - "dav_auth_type" => "Digest", - "admin_passwordhash" => "", - "auth_realm" => "BaikalDAV", - "configured_version" => BAIKAL_VERSION - ]; - } } diff --git a/Core/Frameworks/Baikal/Model/Config/System.php b/Core/Frameworks/Baikal/Model/Config/System.php index c03a439..980c19f 100644 --- a/Core/Frameworks/Baikal/Model/Config/System.php +++ b/Core/Frameworks/Baikal/Model/Config/System.php @@ -66,7 +66,7 @@ class System extends \Baikal\Model\Config { # Default values protected $aData = [ - "sqlite_file" => "db/db.sqlite", + "sqlite_file" => PROJECT_PATH_SPECIFIC . "db/db.sqlite", "mysql" => false, "mysql_host" => "", "mysql_dbname" => "", @@ -125,17 +125,4 @@ class System extends \Baikal\Model\Config { function label() { return "Baïkal Settings"; } - - protected static function getDefaultConfig() { - - return [ - "sqlite_file" => "db/db.sqlite", - "mysql" => false, - "mysql_host" => "", - "mysql_dbname" => "", - "mysql_username" => "", - "mysql_password" => "", - "encryption_key" => "" - ]; - } } diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index edb4f85..66d35f9 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -37,7 +37,7 @@ class Initialize extends \Flake\Core\Controller { # Assert that /Specific is writable if (!file_exists(PROJECT_PATH_SPECIFIC) || !is_dir(PROJECT_PATH_SPECIFIC) || !is_writable(PROJECT_PATH_SPECIFIC) || !file_exists(PROJECT_PATH_CONFIG) || !is_dir(PROJECT_PATH_CONFIG) || !is_writable(PROJECT_PATH_CONFIG)) { - $message = "

Error - Insufficient permissions on the Specific/ folder

"; + $message = "

Error - Insufficient permissions on the configuration folders

"; $message .= "

In order to work properly, Baïkal needs to have write permissions in the Specific/ and config/ folder.

"; die($message); From 6af1b1456177276c6d0718b73853892887389d8f Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 22 Mar 2020 20:56:59 +0100 Subject: [PATCH 27/29] Ensure that release zip has a config folder --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 912f73c..ba08717 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,9 @@ VERSION=$(shell php -r "include 'Core/Distrib.php'; echo BAIKAL_VERSION;") dist: vendor/autoload.php # Building Baikal $(VERSION) rm -r $(BUILD_DIR); true - mkdir -p $(BUILD_DIR) $(BUILD_DIR)/Specific $(BUILD_DIR)/Specific/db + mkdir -p $(BUILD_DIR) $(BUILD_DIR)/Specific $(BUILD_DIR)/Specific/db $(BUILD_DIR)/config touch $(BUILD_DIR)/Specific/db/.empty + touch $(BUILD_DIR)/config/.empty rsync -av \ $(BUILD_FILES) \ --exclude="*.swp" \ @@ -31,4 +32,4 @@ composer.lock: composer.json clean: # Wipe out all local data, and go back to a clean install - rm config/config.yaml config/system.yaml Specific/db/db.sqlite; true + rm config/baikal.yaml Specific/db/db.sqlite; true From 28c2ade603c6017b9e6f82c1b4ce62bcefff3ce2 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Tue, 24 Mar 2020 00:18:17 +0100 Subject: [PATCH 28/29] Fixed merge --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4d361e7..1f1a12c 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require": { "php" : "^7.1", "sabre/dav" : "~4.1.0", - "twig/twig" : "~1.8.0" + "twig/twig" : "~1.8.0", "symfony/yaml" : "^3.4" }, "require-dev" : { From 97360514856f25e4d1ebbe226cdaa828cebe05ea Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Tue, 24 Mar 2020 13:36:52 +0100 Subject: [PATCH 29/29] Fixed leftovers from migration --- .../BaikalAdmin/Controller/Install/Database.php | 2 +- .../BaikalAdmin/Controller/Install/Initialize.php | 4 ++-- .../Controller/Install/VersionUpgrade.php | 15 +++------------ Core/Frameworks/Flake/Framework.php | 10 +++++----- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php index b500fc7..76a4800 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php @@ -36,7 +36,7 @@ class Database extends \Flake\Core\Controller { protected $oForm; # \Formal\Form function execute() { - $this->oModel = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); + $this->oModel = new \Baikal\Model\Config\System(); if (file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) { require_once(PROJECT_PATH_SPECIFIC . "config.system.php"); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index 66d35f9..47c1c79 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -45,9 +45,9 @@ class Initialize extends \Flake\Core\Controller { $this->createHtaccessFilesIfNeeded(); - $this->oModel = new \Baikal\Model\Config\Standard(PROJECT_PATH_CONFIG . "config.yaml"); + $this->oModel = new \Baikal\Model\Config\Standard(); - // If we come from pre-0.7.0, we need to get the values from the config.php and config.system.php files + // If we come from pre-0.7.0, we need to get the values from the config.php and config.system.php files if (file_exists(PROJECT_PATH_SPECIFIC . "config.php")) { require_once(PROJECT_PATH_SPECIFIC . "config.php"); $this->oModel->set('timezone', PROJECT_TIMEZONE); diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php index 005460b..2083615 100644 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/VersionUpgrade.php @@ -530,26 +530,17 @@ SQL } protected function updateConfiguredVersion($sVersionTo) { - - # Create new settings - $oConfig = new \Baikal\Model\Config\Standard("config"); - $oConfig->persist(); - # Update BAIKAL_CONFIGURED_VERSION - $oConfig = new \Baikal\Model\Config\System("system"); + $oConfig = new \Baikal\Model\Config\System(); $oConfig->set("baikal_configured_version", $sVersionTo); $oConfig->persist(); } protected function assertConfigWritable() { # Parsing the config also makes sure that it is not malformed - $oConfig = new \Baikal\Model\Config\Standard(PROJECT_PATH_CONFIG . "config.yaml"); + $oConfig = new \Baikal\Model\Config\System(); if ($oConfig->writable() === false) { - throw new \Exception(PROJECT_PATH_CONFIG . "config.yaml is not writable"); - } - $oConfig = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml"); - if ($oConfig->writable() === false) { - throw new \Exception(PROJECT_PATH_CONFIG . "system.yaml is not writable"); + throw new \Exception(PROJECT_PATH_CONFIG . "baikal.yaml is not writable"); } } } diff --git a/Core/Frameworks/Flake/Framework.php b/Core/Frameworks/Flake/Framework.php index cade4e4..4b9ca24 100644 --- a/Core/Frameworks/Flake/Framework.php +++ b/Core/Frameworks/Flake/Framework.php @@ -258,19 +258,19 @@ class Framework extends \Flake\Core\Framework { protected static function initDbMysql(array $config) { if (!$config['database']['mysql_host']) { - die("

The constant PROJECT_DB_MYSQL_HOST, containing the MySQL host name, is not set.
You should set it in config/system.yaml

"); + die("

The constant PROJECT_DB_MYSQL_HOST, containing the MySQL host name, is not set.
You should set it in config/baikal.yaml

"); } if (!$config['database']['mysql_dbname']) { - die("

The constant PROJECT_DB_MYSQL_DBNAME, containing the MySQL database name, is not set.
You should set it in config/system.yaml

"); + die("

The constant PROJECT_DB_MYSQL_DBNAME, containing the MySQL database name, is not set.
You should set it in config/baikal.yaml

"); } if (!$config['database']['mysql_username']) { - die("

The constant PROJECT_DB_MYSQL_USERNAME, containing the MySQL database username, is not set.
You should set it in config/system.yaml

"); + die("

The constant PROJECT_DB_MYSQL_USERNAME, containing the MySQL database username, is not set.
You should set it in config/baikal.yaml

"); } if (!$config['database']['mysql_password']) { - die("

The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.
You should set it in config/system.yaml

"); + die("

The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.
You should set it in config/baikal.yaml

"); } try { @@ -284,7 +284,7 @@ class Framework extends \Flake\Core\Framework { # We now setup t6he connexion to use UTF8 $GLOBALS["DB"]->query("SET NAMES UTF8"); } catch (\Exception $e) { - die("

Baïkal was not able to establish a connexion to the configured MySQL database (as configured in config/system.yaml).

"); + die("

Baïkal was not able to establish a connexion to the configured MySQL database (as configured in config/baikal.yaml).

"); } return true;