From d263037d0651a97e3e3e91703601787347413651 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Thu, 5 Mar 2020 14:35:37 +0100 Subject: [PATCH] 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/' );