From 57a79879328e800346a374cb04df76266c7079c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Schneider?= Date: Wed, 7 Nov 2012 14:47:50 +0100 Subject: [PATCH] =?UTF-8?q?Ba=C3=AFkal=20can=20be=20configured=20to=20use?= =?UTF-8?q?=20MySQL=20right=20at=20initialization.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Frameworks/Baikal/Core/Tools.php | 18 +- Core/Frameworks/Baikal/Model/Config.php | 17 +- .../Baikal/Model/Config/Database.php | 117 +++++++++++++ .../Baikal/Model/Config/Standard.php | 93 +++++++--- .../Frameworks/Baikal/Model/Config/System.php | 79 ++++++--- .../Controller/Install/Database.php | 165 ++++++++++++++++++ .../Controller/Install/Initialize.php | 148 ++-------------- Core/Frameworks/BaikalAdmin/Core/Auth.php | 35 +++- .../Resources/Templates/Dashboard.html | 6 +- .../Resources/Templates/Install/Database.html | 11 ++ .../Install.php => View/Install/Database.php} | 8 +- .../BaikalAdmin/WWWRoot/install/index.php | 8 +- Core/Frameworks/BaikalAdmin/config.php | 1 - Core/Frameworks/Flake | 2 +- Core/Frameworks/Formal | 2 +- Specific/ENABLE_INSTALL | 0 16 files changed, 503 insertions(+), 207 deletions(-) create mode 100644 Core/Frameworks/Baikal/Model/Config/Database.php create mode 100644 Core/Frameworks/BaikalAdmin/Controller/Install/Database.php create mode 100644 Core/Frameworks/BaikalAdmin/Resources/Templates/Install/Database.html rename Core/Frameworks/BaikalAdmin/{Route/Install.php => View/Install/Database.php} (80%) mode change 100755 => 100644 create mode 100644 Specific/ENABLE_INSTALL diff --git a/Core/Frameworks/Baikal/Core/Tools.php b/Core/Frameworks/Baikal/Core/Tools.php index 8092f78..7c8569f 100755 --- a/Core/Frameworks/Baikal/Core/Tools.php +++ b/Core/Frameworks/Baikal/Core/Tools.php @@ -67,9 +67,9 @@ class Tools { } # Asserting that the database is structurally complete - if(($aMissingTables = self::isDBStructurallyComplete($GLOBALS["DB"])) !== TRUE) { - throw new \Exception("Fatal error: Database is not structurally complete; missing tables are: " . implode(", ", $aMissingTables) . ""); - } + #if(($aMissingTables = self::isDBStructurallyComplete($GLOBALS["DB"])) !== TRUE) { + # throw new \Exception("Fatal error: Database is not structurally complete; missing tables are: " . implode(", ", $aMissingTables) . ""); + #} # Asserting config file exists if(!file_exists(PROJECT_PATH_SPECIFIC . "config.php")) { @@ -101,10 +101,9 @@ class Tools { throw new \Exception("Specific/config.system.php is not writable. Please give write permissions to httpd user on file 'Specific/config.system.php'."); } } - - public static function isDBStructurallyComplete(\Flake\Core\Database $oDB) { - - $aRequiredTables = array( + + public static function getRequiredTablesList() { + return array( "addressbooks", "calendarobjects", "calendars", @@ -114,8 +113,13 @@ class Tools { "principals", "users", ); + } + + public static function isDBStructurallyComplete(\Flake\Core\Database $oDB) { + $aRequiredTables = self::getRequiredTablesList(); $aPresentTables = $oDB->tables(); + $aIntersect = array_intersect($aRequiredTables, $aPresentTables); if(count($aIntersect) !== count($aRequiredTables)) { return array_diff($aRequiredTables, $aIntersect); diff --git a/Core/Frameworks/Baikal/Model/Config.php b/Core/Frameworks/Baikal/Model/Config.php index 3e7fb52..65a3657 100755 --- a/Core/Frameworks/Baikal/Model/Config.php +++ b/Core/Frameworks/Baikal/Model/Config.php @@ -47,8 +47,16 @@ abstract class Config extends \Flake\Core\Model\NoDb { } protected function getConfigAsString() { - $sContent = file_get_contents($this->sConfigFilePath); - return str_replace(LF . CR, LF, $sContent); + if(file_exists($this->sConfigFilePath)) { + $sContent = file_get_contents($this->sConfigFilePath); + return str_replace(LF . CR, LF, $sContent); + } else { + + $sConfig = "sConfigFilePath, $sLines); } - + public function destroy() { } + + protected static function getDefaultConfig() { + } } \ No newline at end of file diff --git a/Core/Frameworks/Baikal/Model/Config/Database.php b/Core/Frameworks/Baikal/Model/Config/Database.php new file mode 100644 index 0000000..eb6b509 --- /dev/null +++ b/Core/Frameworks/Baikal/Model/Config/Database.php @@ -0,0 +1,117 @@ + +# All rights reserved +# +# http://baikal.codr.fr +# +# This script is part of the Baïkal Server project. The Baïkal +# Server project is free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# The GNU General Public License can be found at +# http://www.gnu.org/copyleft/gpl.html. +# +# This script is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# This copyright notice MUST APPEAR in all copies of the script! +################################################################# + +namespace Baikal\Model\Config; + +class Database extends \Baikal\Model\Config { + + protected $aConstants = array( + "PROJECT_SQLITE_FILE" => array( + "type" => "litteral", + "comment" => "Define path to Baïkal Database SQLite file", + ), + "PROJECT_DB_MYSQL" => array( + "type" => "boolean", + "comment" => "MySQL > Use MySQL instead of SQLite ?", + ), + "PROJECT_DB_MYSQL_HOST" => array( + "type" => "string", + "comment" => "MySQL > Host, including ':portnumber' if port is not the default one (3306)", + ), + "PROJECT_DB_MYSQL_DBNAME" => array( + "type" => "string", + "comment" => "MySQL > Database name", + ), + "PROJECT_DB_MYSQL_USERNAME" => array( + "type" => "string", + "comment" => "MySQL > Username", + ), + "PROJECT_DB_MYSQL_PASSWORD" => array( + "type" => "string", + "comment" => "MySQL > Password", + ), + ); + + # Default values + protected $aData = array( + "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" => "", + ); + + public function formMorphologyForThisModelInstance() { + $oMorpho = new \Formal\Form\Morphology(); + + $oMorpho->add(new \Formal\Element\Text(array( + "prop" => "PROJECT_SQLITE_FILE", + "label" => "SQLite file path", + "validation" => "required", + "inputclass" => "input-xxlarge", + "help" => "The absolute server path to the SQLite file", + ))); + + $oMorpho->add(new \Formal\Element\Checkbox(array( + "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(array( + "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(array( + "prop" => "PROJECT_DB_MYSQL_DBNAME", + "label" => "MySQL database name", + ))); + + $oMorpho->add(new \Formal\Element\Text(array( + "prop" => "PROJECT_DB_MYSQL_USERNAME", + "label" => "MySQL username", + ))); + + $oMorpho->add(new \Formal\Element\Password(array( + "prop" => "PROJECT_DB_MYSQL_PASSWORD", + "label" => "MySQL password", + ))); + + return $oMorpho; + } + + public function label() { + return "Baïkal Database Settings"; + } + + protected static function getDefaultConfig() { + throw new \Exception("Should never reach getDefaultConfig() on \Baikal\Model\Config\Database"); + } +} \ No newline at end of file diff --git a/Core/Frameworks/Baikal/Model/Config/Standard.php b/Core/Frameworks/Baikal/Model/Config/Standard.php index 8d8b130..53dc2eb 100755 --- a/Core/Frameworks/Baikal/Model/Config/Standard.php +++ b/Core/Frameworks/Baikal/Model/Config/Standard.php @@ -31,7 +31,7 @@ class Standard extends \Baikal\Model\Config { protected $aConstants = array( "PROJECT_TIMEZONE" => array( "type" => "string", - "comment" => "Timezone of your users, if unsure, check http://en.wikipedia.org/wiki/List_of_tz_database_time_zones", + "comment" => "Timezone of the server; if unsure, check http://en.wikipedia.org/wiki/List_of_tz_database_time_zones", ), "BAIKAL_CARD_ENABLED" => array( "type" => "boolean", @@ -70,29 +70,11 @@ class Standard extends \Baikal\Model\Config { $oMorpho->add(new \Formal\Element\Listbox(array( "prop" => "PROJECT_TIMEZONE", - "label" => "Time zone", + "label" => "Server Time zone", "validation" => "required", "options" => \Baikal\Core\Tools::timezones(), - "help" => "Time zone of the server" ))); - $oMorpho->add(new \Formal\Element\Checkbox(array( - "prop" => "BAIKAL_ADMIN_ENABLED", - "label" => "Enable Web Admin", - "popover" => array( - "title" => "Warning !", - "content" => "If disabled, you'll lose access to this very admin interface !", - ), - ))); - - $oMorpho->add(new \Formal\Element\Checkbox(array( - "prop" => "BAIKAL_ADMIN_AUTOLOCKENABLED", - "label" => "Enable Web Admin autolock", - "popover" => array( - "title" => "Web admin autolock", - "content" => "If enabled, you'll have to create a file named ENABLE_ADMIN in Specific/ prior to every admin use." - ) - ))); $oMorpho->add(new \Formal\Element\Checkbox(array( "prop" => "BAIKAL_CAL_ENABLED", @@ -106,12 +88,12 @@ class Standard extends \Baikal\Model\Config { $oMorpho->add(new \Formal\Element\Password(array( "prop" => "BAIKAL_ADMIN_PASSWORDHASH", - "label" => "Web admin password", + "label" => "Admin password", ))); $oMorpho->add(new \Formal\Element\Password(array( "prop" => "BAIKAL_ADMIN_PASSWORDHASH_CONFIRM", - "label" => "Web admin password confirmation", + "label" => "Admin password, confirmation", "validation" => "sameas:BAIKAL_ADMIN_PASSWORDHASH", ))); @@ -124,6 +106,24 @@ class Standard extends \Baikal\Model\Config { $oMorpho->element("BAIKAL_ADMIN_PASSWORDHASH")->setOption("placeholder", $sNotice); $oMorpho->element("BAIKAL_ADMIN_PASSWORDHASH_CONFIRM")->setOption("placeholder", $sNotice); } + + $oMorpho->add(new \Formal\Element\Checkbox(array( + "prop" => "BAIKAL_ADMIN_ENABLED", + "label" => "Enable Web interface (recommended)", + "popover" => array( + "title" => "Warning !", + "content" => "If disabled, you'll lose access to this very admin interface !", + ), + ))); + + $oMorpho->add(new \Formal\Element\Checkbox(array( + "prop" => "BAIKAL_ADMIN_AUTOLOCKENABLED", + "label" => "Web interface autolock", + "popover" => array( + "title" => "Web admin autolock", + "content" => "If enabled, you'll have to create a file named ENABLE_ADMIN in the folder Specific/ prior to every admin use.

This enforces security, but might be uncomfortable if you use the admin frequently." + ) + ))); return $oMorpho; } @@ -156,4 +156,53 @@ 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 =<< array( - "type" => "boolean", - "comment" => "Standalone Server, allowed or not; default FALSE", - ), - "BAIKAL_STANDALONE_PORT" => array( - "type" => "integer", - "comment" => "Standalone Server, port number; default 8888", - ), "BAIKAL_PATH_SABREDAV" => array( "type" => "litteral", "comment" => "PATH to SabreDAV", @@ -59,7 +51,7 @@ class System extends \Baikal\Model\Config { ), "PROJECT_DB_MYSQL" => array( "type" => "boolean", - "comment" => "MySQL > Use mysql instead of SQLite ?", + "comment" => "MySQL > Use MySQL instead of SQLite ?", ), "PROJECT_DB_MYSQL_HOST" => array( "type" => "string", @@ -89,8 +81,6 @@ class System extends \Baikal\Model\Config { # Default values protected $aData = array( - "BAIKAL_STANDALONE_ALLOWED" => FALSE, - "BAIKAL_STANDALONE_PORT" => 8888, "BAIKAL_PATH_SABREDAV" => 'PROJECT_PATH_FRAMEWORKS . "SabreDAV/lib/Sabre/"', "BAIKAL_AUTH_REALM" => "BaikalDAV", "BAIKAL_CARD_BASEURI" => 'PROJECT_BASEURI . "card.php/"', @@ -141,18 +131,6 @@ class System extends \Baikal\Model\Config { ) ))); - if(\Flake\Util\Frameworks::enabled("BaikalStandalone")) { - $oMorpho->add(new \Formal\Element\Checkbox(array( - "prop" => "BAIKAL_STANDALONE_ALLOWED", - "label" => "Allow Standalone Baïkal execution" - ))); - - $oMorpho->add(new \Formal\Element\Text(array( - "prop" => "BAIKAL_STANDALONE_PORT", - "label" => "Standalone Baïkal port" - ))); - } - $oMorpho->add(new \Formal\Element\Text(array( "prop" => "BAIKAL_PATH_SABREDAV", "label" => "Path to SabreDAV", @@ -208,4 +186,59 @@ class System extends \Baikal\Model\Config { public function label() { return "Baïkal Settings"; } + + 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; + } } \ No newline at end of file diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php new file mode 100644 index 0000000..3f87c55 --- /dev/null +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Database.php @@ -0,0 +1,165 @@ + +# All rights reserved +# +# http://baikal.codr.fr +# +# This script is part of the Baïkal Server project. The Baïkal +# Server project is free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# The GNU General Public License can be found at +# http://www.gnu.org/copyleft/gpl.html. +# +# This script is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# This copyright notice MUST APPEAR in all copies of the script! +################################################################# + +namespace BaikalAdmin\Controller\Install; + +class Database extends \Flake\Core\Controller { + + protected $aMessages = array(); + protected $oModel; + protected $oForm; # \Formal\Form + + public function execute() { + $this->oModel = new \Baikal\Model\Config\Database(PROJECT_PATH_SPECIFIC . "config.system.php"); + + $this->oForm = $this->oModel->formForThisModelInstance(array( + "close" => FALSE, + "hook.validation" => array($this, "validateMySQLConnection"), + "hook.morphology" => array($this, "hideMySQLFieldWhenNeeded"), + )); + + if($this->oForm->submitted()) { + $this->oForm->execute(); + + if($this->oForm->persisted()) { + + # nothing here + } + } + } + + public function render() { + $sBigIcon = "glyph2x-magic"; + $sBaikalVersion = BAIKAL_VERSION; + + $oView = new \BaikalAdmin\View\Install\Database(); + $oView->setData("baikalversion", BAIKAL_VERSION); + + if($this->oForm->persisted()) { + + \BaikalAdmin\Core\Auth::lockInstall(); + + $sMessage = "

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

"; + $sMessage . "

 

"; + $sMessage .= "

Start using Baïkal

"; + $sForm = ""; + } else { + $sMessage = ""; + $sForm = $this->oForm->render(); + } + + $oView->setData("message", $sMessage); + $oView->setData("form", $sForm); + + return $oView->render(); + } + + public function validateMySQLConnection($oForm, $oMorpho) { + + $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(); + + try { + $oDb = new \Flake\Core\Database\Mysql( + $sHost, + $sDbname, + $sUsername, + $sPassword + ); + + if(($aMissingTables = \Baikal\Core\Tools::isDBStructurallyComplete($oDb)) !== TRUE) { + + # Checking if all tables are missing + $aRequiredTables = \Baikal\Core\Tools::getRequiredTablesList(); + if(count($aRequiredTables) !== count($aMissingTables)) { + $sMessage = "

Database is not structurally complete.

"; + $sMessage .= "

Missing tables are: " . implode(", ", $aMissingTables) . "

"; + $sMessage .= "

You will find the SQL definition of Baïkal tables in this file: Core/Resources/Db/MySQL/db.sql

"; + $sMessage .= "

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

"; + + $oForm->declareError( + $oMorpho->element("PROJECT_DB_MYSQL"), + $sMessage + ); + } else { + # All tables are missing + # We add these tables ourselves to the database, to initialize Baïkal + $sSqlDefinition = file_get_contents(PROJECT_PATH_CORERESOURCES . "Db/MySQL/db.sql"); + $oDb->query($sSqlDefinition); + } + } + + return TRUE; + } catch(\Exception $e) { + $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") + ); + } + } + } + + public function hideMySQLFieldWhenNeeded(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) { + + if($oForm->submitted()) { + $bMySQL = (intval($oForm->postValue("PROJECT_DB_MYSQL")) === 1); + } else { + $bMySQL = PROJECT_DB_MYSQL; + } + + if($bMySQL === TRUE) { + $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"); + } + } +} \ No newline at end of file diff --git a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index 56b26e1..cd167ba 100755 --- a/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -37,17 +37,11 @@ class Initialize extends \Flake\Core\Controller { if(!file_exists(PROJECT_PATH_SPECIFIC) || !is_dir(PROJECT_PATH_SPECIFIC) || !is_writable(PROJECT_PATH_SPECIFIC)) { throw new \Exception("Specific/ dir is readonly. Baïkal Admin requires write permissions on this dir."); } - - $this->createDefaultConfigFilesIfNeeded(); + $this->createHtaccessFilesIfNeeded(); $this->oModel = new \Baikal\Model\Config\Standard(PROJECT_PATH_SPECIFIC . "config.php"); - # Assert that config file is writable - if(!$this->oModel->writable()) { - throw new \Exception("Config file is not writable;" . __FILE__ . " > " . __LINE__); - } - $this->oForm = $this->oModel->formForThisModelInstance(array( "close" => FALSE )); @@ -56,22 +50,19 @@ class Initialize extends \Flake\Core\Controller { $this->oForm->execute(); if($this->oForm->persisted()) { - $sContent = file_get_contents(PROJECT_PATH_SPECIFIC . "config.system.php"); - - $sBaikalVersion = BAIKAL_VERSION; - $sEncryptionKey = md5(microtime() . rand()); - - # Setting "BAIKAL_CONFIGURED_VERSION" - $sNewConstants =<<set("BAIKAL_ENCRYPTION_KEY", md5(microtime() . rand())); + $oSystemConfig->persist(); + + # Using default PROJECT_SQLITE_FILE + $PROJECT_SQLITE_FILE = PROJECT_PATH_SPECIFIC . "db/db.sqlite"; + + if(!file_exists($PROJECT_SQLITE_FILE)) { + # Installing default sqlite database + @copy(PROJECT_PATH_CORERESOURCES . "Db/SQLite/db.sqlite", $PROJECT_SQLITE_FILE); + } } } } @@ -84,8 +75,12 @@ PHP; $oView->setData("baikalversion", BAIKAL_VERSION); if($this->oForm->persisted()) { - $sMessage = "

Baïkal is now configured. You may now Access the Baïkal admin"; - $sForm = ""; + $sLink = PROJECT_URI . "admin/install/?/database"; + \Flake\Util\Tools::redirect($sLink); + exit(0); + + #$sMessage = "

Baïkal is now configured. You may Access the Baïkal admin

"; + #$sForm = ""; } else { $sMessage = ""; $sForm = $this->oForm->render(); @@ -97,10 +92,6 @@ PHP; return $oView->render(); } - protected function tagConfiguredVersion() { - file_put_contents(PROJECT_PATH_SPECIFIC . "config.php", $sContent); - } - protected function createHtaccessFilesIfNeeded() { if(!file_exists(PROJECT_PATH_DOCUMENTROOT . ".htaccess")) { @@ -119,105 +110,4 @@ PHP; throw new \Exception("Unable to create " . PROJECT_PATH_SPECIFIC . ".htaccess; you may try to create it manually by copying " . PROJECT_PATH_CORERESOURCES . "System/htaccess-specific"); } } - - 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 function getDefaultConfig() { - - $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", ""); - -CODE; - $sCode = trim($sCode); - return $sCode; - } } \ No newline at end of file diff --git a/Core/Frameworks/BaikalAdmin/Core/Auth.php b/Core/Frameworks/BaikalAdmin/Core/Auth.php index db268eb..b97ff00 100755 --- a/Core/Frameworks/BaikalAdmin/Core/Auth.php +++ b/Core/Frameworks/BaikalAdmin/Core/Auth.php @@ -36,19 +36,22 @@ class Auth { } public static function assertUnlocked() { - - if(!defined("BAIKAL_ADMIN_AUTOLOCKENABLED") || BAIKAL_ADMIN_AUTOLOCKENABLED === FALSE) { - return TRUE; - } - + if(defined("BAIKAL_CONTEXT_INSTALL") && BAIKAL_CONTEXT_INSTALL === TRUE) { $sToolName = "Baïkal Install Tool"; + $sFileName = "ENABLE_INSTALL"; } else { + if(!defined("BAIKAL_ADMIN_AUTOLOCKENABLED") || BAIKAL_ADMIN_AUTOLOCKENABLED === FALSE) { + return TRUE; + } + $sToolName = "Baïkal Admin"; + $sFileName = "ENABLE_ADMIN"; } + + $sEnableFile = PROJECT_PATH_SPECIFIC . $sFileName; $bLocked = TRUE; - $sEnableFile = PROJECT_PATH_SPECIFIC . "ENABLE_ADMIN"; if(file_exists($sEnableFile)) { clearstatcache(); @@ -63,13 +66,13 @@ class Auth { // file has been created more than an hour ago // delete and declare locked if(!@unlink($sEnableFile)) { - die("

" . $sToolName . " is locked.

To unlock it, delete and re-create an empty file named ENABLE_ADMIN in Specific/config.php"); + die("

" . $sToolName . " is locked.

To unlock it, create (or re-create if it exists already) an empty file named " . $sFileName . " (uppercase, no file extension) in the Specific/ folder of Baïkal."); } } } if($bLocked) { - die("

" . $sToolName . " is locked.

To unlock it, create an empty file named ENABLE_ADMIN in Specific/"); + die("

" . $sToolName . " is locked.

To unlock it, create (or re-create if it exists already) an empty file named " . $sFileName . " (uppercase, no file extension) in the Specific/ folder of Baïkal."); } } @@ -106,6 +109,20 @@ class Auth { } public static function hashAdminPassword($sPassword) { - return md5('admin:' . BAIKAL_AUTH_REALM . ':' . $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 + } + + return md5('admin:' . $sAuthRealm . ':' . $sPassword); + } + + public static function lockAdmin() { + @unlink(PROJECT_PATH_SPECIFIC . "ENABLE_ADMIN"); + } + + public static function lockInstall() { + @unlink(PROJECT_PATH_SPECIFIC . "ENABLE_INSTALL"); } } \ No newline at end of file diff --git a/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html b/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html index e43248c..1e95dfb 100755 --- a/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html +++ b/Core/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html @@ -54,9 +54,9 @@

License and credits

-

Baïkal is open source software, and released under the terms of the GNU GPL v3.

-

Baïkal is based upon other open source projects. Read the README.md file to learn about that.

-

Baïkal is developed by Base8. We'd love to hear from you at contact@base8.fr

+

Baïkal is open source software licensed under the terms of the GNU GPL v3.

+

Baïkal is based upon other open source projects.
Read the README.md file to learn about that.

+

Baïkal is happily developed by Base8.
We'd love to hear from you at contact@base8.fr

diff --git a/Core/Frameworks/BaikalAdmin/Resources/Templates/Install/Database.html b/Core/Frameworks/BaikalAdmin/Resources/Templates/Install/Database.html new file mode 100644 index 0000000..abd330c --- /dev/null +++ b/Core/Frameworks/BaikalAdmin/Resources/Templates/Install/Database.html @@ -0,0 +1,11 @@ +{% autoescape false %} +
+

Baïkal Database setup

+

Configure Baïkal Database.

+
+ + +{{ message }} +{{ form }} + +{% endautoescape %} \ No newline at end of file diff --git a/Core/Frameworks/BaikalAdmin/Route/Install.php b/Core/Frameworks/BaikalAdmin/View/Install/Database.php old mode 100755 new mode 100644 similarity index 80% rename from Core/Frameworks/BaikalAdmin/Route/Install.php rename to Core/Frameworks/BaikalAdmin/View/Install/Database.php index 5c373f1..70ca1b9 --- a/Core/Frameworks/BaikalAdmin/Route/Install.php +++ b/Core/Frameworks/BaikalAdmin/View/Install/Database.php @@ -24,11 +24,7 @@ # This copyright notice MUST APPEAR in all copies of the script! ################################################################# -namespace BaikalAdmin\Route; +namespace BaikalAdmin\View\Install; -class Install extends \Flake\Core\Route { - - public static function layout(\Flake\Core\Render\Container &$oRenderContainer) { - $oRenderContainer->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install()); - } +class Database extends \BaikalAdmin\Core\View { } \ No newline at end of file diff --git a/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php b/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php index 0e361ea..48911af 100755 --- a/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php +++ b/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php @@ -65,8 +65,12 @@ if(!defined("BAIKAL_CONFIGURED_VERSION")) { # we have to set an admin password $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Initialize()); } else { - # we have to upgrade Baïkal - $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\VersionUpgrade()); + if(BAIKAL_CONFIGURED_VERSION !== BAIKAL_VERSION) { + # we have to upgrade Baïkal + $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\VersionUpgrade()); + } else { + $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Database()); + } } # Render the page diff --git a/Core/Frameworks/BaikalAdmin/config.php b/Core/Frameworks/BaikalAdmin/config.php index d046979..dd6b5b6 100755 --- a/Core/Frameworks/BaikalAdmin/config.php +++ b/Core/Frameworks/BaikalAdmin/config.php @@ -31,7 +31,6 @@ $GLOBALS["ROUTES"] = array( "users" => "\BaikalAdmin\Route\Users", "users/calendars" => "\BaikalAdmin\Route\User\Calendars", "users/addressbooks" => "\BaikalAdmin\Route\User\AddressBooks", - "install" => "\BaikalAdmin\Route\Install", "settings/standard" => "\BaikalAdmin\Route\Settings\Standard", "settings/system" => "\BaikalAdmin\Route\Settings\System", "logout" => "\BaikalAdmin\Route\Logout" diff --git a/Core/Frameworks/Flake b/Core/Frameworks/Flake index 1de6d8d..6c97f96 160000 --- a/Core/Frameworks/Flake +++ b/Core/Frameworks/Flake @@ -1 +1 @@ -Subproject commit 1de6d8dc3d6408619cd23dda28ce7d6284ad63e9 +Subproject commit 6c97f964f10287c4f6b31f7397947b5152b0e948 diff --git a/Core/Frameworks/Formal b/Core/Frameworks/Formal index d83f38d..1663200 160000 --- a/Core/Frameworks/Formal +++ b/Core/Frameworks/Formal @@ -1 +1 @@ -Subproject commit d83f38d3880a82650ea4f93c815a8211245f58fe +Subproject commit 1663200604730cd7bf27795f3d215b226e050431 diff --git a/Specific/ENABLE_INSTALL b/Specific/ENABLE_INSTALL new file mode 100644 index 0000000..e69de29