From 89650784f5fe5a5ac44531cb1cdcf6940c744c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Schneider?= Date: Tue, 24 Jul 2012 22:35:56 +0200 Subject: [PATCH] Enhancements on common error detection Former-commit-id: ea0bcca35472abc5189101b318e8280490c31cef --- CoreVersions/0.2.0/Distrib.php | 3 +- .../0.2.0/Frameworks/Baikal/Core/Tools.php | 6 +- .../0.2.0/Frameworks/Baikal/Framework.php | 2 +- .../Frameworks/Baikal/Model/Config/System.php | 38 ++++++--- .../Frameworks/Baikal/Scripts/package-flat.sh | 3 + .../Controller/Install/Initialize.php | 25 ++++++ .../0.2.0/Frameworks/Flake/Core/Auth.php | 35 -------- .../0.2.0/Frameworks/Flake/Framework.php | 75 ++++++++++++------ .../0.2.0/Resources/htaccess-documentroot | 16 ++++ .../0.2.0/Resources/htaccess-specific | 2 + Specific/.htaccess | 2 + Specific/db/{.ht.db.sqlite => db.sqlite} | Bin 12 files changed, 131 insertions(+), 76 deletions(-) delete mode 100755 CoreVersions/0.2.0/Frameworks/Flake/Core/Auth.php create mode 100755 CoreVersions/0.2.0/Resources/htaccess-documentroot create mode 100755 CoreVersions/0.2.0/Resources/htaccess-specific create mode 100644 Specific/.htaccess rename Specific/db/{.ht.db.sqlite => db.sqlite} (100%) diff --git a/CoreVersions/0.2.0/Distrib.php b/CoreVersions/0.2.0/Distrib.php index 70e12d6..7643ebd 100755 --- a/CoreVersions/0.2.0/Distrib.php +++ b/CoreVersions/0.2.0/Distrib.php @@ -25,4 +25,5 @@ ################################################################# define("BAIKAL_VERSION", "0.2.0"); -define("BAIKAL_HOMEPAGE", "http://baikal.codr.fr"); \ No newline at end of file +define("BAIKAL_HOMEPAGE", "http://baikal.codr.fr"); +define("PROJECT_PACKAGE", "regular"); \ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/Baikal/Core/Tools.php b/CoreVersions/0.2.0/Frameworks/Baikal/Core/Tools.php index fce5221..0e328fe 100755 --- a/CoreVersions/0.2.0/Frameworks/Baikal/Core/Tools.php +++ b/CoreVersions/0.2.0/Frameworks/Baikal/Core/Tools.php @@ -61,17 +61,17 @@ class Tools { # Asserting DB file exists if(!file_exists(PROJECT_SQLITE_FILE)) { - throw new \Exception("DB file does not exist. To create it, please copy 'Core/Resources/db.empty.sqlite' to 'Specific/db/.ht.db.sqlite'"); + throw new \Exception("DB file does not exist. To create it, please copy 'Core/Resources/db.empty.sqlite' to '" . PROJECT_SQLITE_FILE . "'"); } # Asserting DB file is readable if(!is_readable(PROJECT_SQLITE_FILE)) { - throw new \Exception("DB file is not readable. Please give read permissions to httpd user on file 'Specific/db/.ht.db.sqlite'."); + throw new \Exception("DB file is not readable. Please give read permissions to httpd user on file '" . PROJECT_SQLITE_FILE . "'."); } # Asserting DB file is writable if(!is_writable(PROJECT_SQLITE_FILE)) { - throw new \Exception("DB file is not writable. Please give write permissions to httpd user on file 'Specific/db/.ht.db.sqlite'."); + throw new \Exception("DB file is not writable. Please give write permissions to httpd user on file '" . PROJECT_SQLITE_FILE . "'."); } # Asserting config file exists diff --git a/CoreVersions/0.2.0/Frameworks/Baikal/Framework.php b/CoreVersions/0.2.0/Frameworks/Baikal/Framework.php index 59d1508..2dfa880 100755 --- a/CoreVersions/0.2.0/Frameworks/Baikal/Framework.php +++ b/CoreVersions/0.2.0/Frameworks/Baikal/Framework.php @@ -44,7 +44,7 @@ class Framework extends \Flake\Core\Framework { # Registering Baikal classloader define("BAIKAL_PATH_FRAMEWORKROOT", dirname(__FILE__) . "/"); - require_once(BAIKAL_PATH_FRAMEWORKROOT . '/Core/ClassLoader.php'); + require_once(BAIKAL_PATH_FRAMEWORKROOT . 'Core/ClassLoader.php'); \Baikal\Core\ClassLoader::register(); \Baikal\Core\Tools::assertEnvironmentIsOk(); diff --git a/CoreVersions/0.2.0/Frameworks/Baikal/Model/Config/System.php b/CoreVersions/0.2.0/Frameworks/Baikal/Model/Config/System.php index 4bdcdcc..7e83385 100755 --- a/CoreVersions/0.2.0/Frameworks/Baikal/Model/Config/System.php +++ b/CoreVersions/0.2.0/Frameworks/Baikal/Model/Config/System.php @@ -47,6 +47,9 @@ class System extends \Baikal\Model\Config { "BAIKAL_STANDALONE_PORT" => array( "type" => "integer", ), + "PROJECT_SQLITE_FILE" => array( + "type" => "litteral", + ), ); protected $aData = array( @@ -56,6 +59,7 @@ class System extends \Baikal\Model\Config { "BAIKAL_CAL_BASEURI" => "", "BAIKAL_STANDALONE_ALLOWED" => "", "BAIKAL_STANDALONE_PORT" => "", + "PROJECT_SQLITE_FILE" => "", ); public function formMorphologyForThisModelInstance() { @@ -83,19 +87,6 @@ class System extends \Baikal\Model\Config { ) ))); - $oMorpho->add(new \Formal\Element\Text(array( - "prop" => "BAIKAL_PATH_SABREDAV", - "label" => "Path to SabreDAV", - "validation" => "required", - "inputclass" => "input-xxlarge", - "help" => "The absolute server path to SabreDAV API", - "popover" => array( - "title" => "Path to SabreDAV", - "content" => "If Baïkal is hosted in a subfolder, this path should reflect it.
Whatever happens, it should begin and end with a slash.", - "position" => "top" - ) - ))); - $oMorpho->add(new \Formal\Element\Text(array( "prop" => "BAIKAL_AUTH_REALM", "label" => "Auth realm", @@ -118,6 +109,27 @@ class System extends \Baikal\Model\Config { "label" => "Standalone Baïkal port" ))); } + + $oMorpho->add(new \Formal\Element\Text(array( + "prop" => "BAIKAL_PATH_SABREDAV", + "label" => "Path to SabreDAV", + "validation" => "required", + "inputclass" => "input-xxlarge", + "help" => "The absolute server path to SabreDAV API", + "popover" => array( + "title" => "Path to SabreDAV", + "content" => "If Baïkal is hosted in a subfolder, this path should reflect it.
Whatever happens, it should begin and end with a slash.", + "position" => "top" + ) + ))); + + $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", + ))); return $oMorpho; } diff --git a/CoreVersions/0.2.0/Frameworks/Baikal/Scripts/package-flat.sh b/CoreVersions/0.2.0/Frameworks/Baikal/Scripts/package-flat.sh index 0654dfc..d71c574 100755 --- a/CoreVersions/0.2.0/Frameworks/Baikal/Scripts/package-flat.sh +++ b/CoreVersions/0.2.0/Frameworks/Baikal/Scripts/package-flat.sh @@ -59,5 +59,8 @@ mv html/* . mv html/.htaccess . rm -Rf html +# Tagging Distrib +cat Core/Distrib.php | sed -e "s/\"regular\"/\"flat\"/g" > Core/Distrib.php + # Displaying result echo "# "$TEMPDIR diff --git a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/Initialize.php b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index 54040ae..8100935 100755 --- a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -41,6 +41,8 @@ class Initialize extends \Flake\Core\Controller { } $this->createDefaultConfigFilesIfNeeded(); + $this->createHtaccessFilesIfNeeded(); + $this->oModel = new \Baikal\Model\Config\Standard(PROJECT_PATH_SPECIFIC . "config.php"); # Assert that config file is writable @@ -103,6 +105,25 @@ PHP; file_put_contents(PROJECT_PATH_SPECIFIC . "config.php", $sContent); } + protected function createHtaccessFilesIfNeeded() { + + if(!file_exists(PROJECT_PATH_DOCUMENTROOT . ".htaccess")) { + @copy(PROJECT_PATH_CORERESOURCES . "htaccess-documentroot", PROJECT_PATH_DOCUMENTROOT . ".htaccess"); + } + + if(!file_exists(PROJECT_PATH_DOCUMENTROOT . ".htaccess")) { + throw new \Exception("Unable to create " . PROJECT_PATH_DOCUMENTROOT . ".htaccess; you may try to create it manually by copying " . PROJECT_PATH_CORERESOURCES . "htaccess-documentroot"); + } + + if(!file_exists(PROJECT_PATH_SPECIFIC . ".htaccess")) { + @copy(PROJECT_PATH_CORERESOURCES . "htaccess-specific", PROJECT_PATH_SPECIFIC . ".htaccess"); + } + + if(!file_exists(PROJECT_PATH_SPECIFIC . ".htaccess")) { + throw new \Exception("Unable to create " . PROJECT_PATH_SPECIFIC . ".htaccess; you may try to create it manually by copying " . PROJECT_PATH_CORERESOURCES . "htaccess-specific"); + } + } + protected function createDefaultConfigFilesIfNeeded() { # Create empty config.php if needed @@ -180,6 +201,10 @@ define("BAIKAL_CARD_BASEURI", PROJECT_BASEURI . "card.php/"); # Should begin and end with a "/" define("BAIKAL_CAL_BASEURI", PROJECT_BASEURI . "cal.php/"); + +# Define path to Baïkal Database SQLite file +define("PROJECT_SQLITE_FILE", PROJECT_PATH_SPECIFIC . "db/db.sqlite"); + CODE; $sCode = trim($sCode); return $sCode; diff --git a/CoreVersions/0.2.0/Frameworks/Flake/Core/Auth.php b/CoreVersions/0.2.0/Frameworks/Flake/Core/Auth.php deleted file mode 100755 index 8381cd2..0000000 --- a/CoreVersions/0.2.0/Frameworks/Flake/Core/Auth.php +++ /dev/null @@ -1,35 +0,0 @@ - -# All rights reserved -# -# http://flake.codr.fr -# -# This script is part of the Flake project. The Flake -# 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 Flake\Core; - -class Auth extends \Flake\Core\FLObject { - public static function isAdmin() { - $sUrl = \Flake\Util\Tools::getCurrentUrl(); - $aParts = explode("/", $sUrl); - return in_array("edit", $aParts); - } -} \ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/Flake/Framework.php b/CoreVersions/0.2.0/Frameworks/Flake/Framework.php index 488c3d0..16dc5b5 100755 --- a/CoreVersions/0.2.0/Frameworks/Flake/Framework.php +++ b/CoreVersions/0.2.0/Frameworks/Flake/Framework.php @@ -101,33 +101,24 @@ class Framework extends \Flake\Core\Framework { # not using realpath here to avoid symlinks resolution 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_FRAMEWORKS", PROJECT_PATH_CORE . "Frameworks/"); define("PROJECT_PATH_WWWROOT", PROJECT_PATH_CORE . "WWWRoot/"); - # Define path to Baïkal SQLite file - define("PROJECT_SQLITE_FILE", PROJECT_PATH_SPECIFIC . "db/.ht.db.sqlite"); - # Activate Flake class loader require_once(FLAKE_PATH_ROOT . 'Core/ClassLoader.php'); \Flake\Core\ClassLoader::register(); - - # Asserting DB file exists - if(!file_exists(PROJECT_SQLITE_FILE)) { - die("

DB file does not exist. To create it, please copy 'Core/Resources/db.empty.sqlite' to 'Specific/db/.ht.db.sqlite'

"); - } - - # Asserting DB file is readable - if(!is_readable(PROJECT_SQLITE_FILE)) { - die("

DB file is not readable. Please give read permissions on file 'Specific/db/.ht.db.sqlite'

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

DB file is not writable. Please give write permissions on file 'Specific/db/.ht.db.sqlite'

"); - } require_once(PROJECT_PATH_CORE . "Distrib.php"); + + if(PROJECT_PACKAGE === "regular") { + define("PROJECT_PATH_DOCUMENTROOT", PROJECT_PATH_ROOT . "html/"); + } elseif(PROJECT_PACKAGE === "flat") { + define("PROJECT_PATH_DOCUMENTROOT", PROJECT_PATH_ROOT); + } else { + throw new \Exception("Unrecognized PROJECT_PACKAGE value."); + } # Determine PROJECT_URI $sScript = substr($_SERVER["SCRIPT_FILENAME"], strlen($_SERVER["DOCUMENT_ROOT"])); @@ -156,16 +147,54 @@ class Framework extends \Flake\Core\Framework { setlocale(LC_ALL, FLAKE_LOCALE); date_default_timezone_set(FLAKE_TIMEZONE); - - if(file_exists(PROJECT_SQLITE_FILE) && is_readable(PROJECT_SQLITE_FILE) && !isset($GLOBALS["DB"])) { - $GLOBALS["DB"] = new \Flake\Core\Database\Sqlite(PROJECT_SQLITE_FILE); - } - + $GLOBALS["TEMPLATESTACK"] = array(); $aUrlInfo = parse_url(PROJECT_URI); define("FLAKE_DOMAIN", $_SERVER["HTTP_HOST"]); define("FLAKE_URIPATH", \Flake\Util\Tools::stripBeginSlash($aUrlInfo["path"])); unset($aUrlInfo); + + + # Include Project config + $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() { + + # Asserting DB filepath is set + if(!defined("PROJECT_SQLITE_FILE")) { + return; + } + + # Asserting DB file exists + if(!file_exists(PROJECT_SQLITE_FILE)) { + die("

DB file does not exist. To create it, please copy 'Core/Resources/db.empty.sqlite' to '" . PROJECT_SQLITE_FILE . "'

"); + } + + # Asserting DB file is readable + if(!is_readable(PROJECT_SQLITE_FILE)) { + die("

DB file is not readable. Please give read permissions on file '" . PROJECT_SQLITE_FILE . "'

"); + } + + # Asserting DB file is writable + if(!is_writable(PROJECT_SQLITE_FILE)) { + die("

DB file is not writable. Please give write permissions on file '" . 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); + } } } \ No newline at end of file diff --git a/CoreVersions/0.2.0/Resources/htaccess-documentroot b/CoreVersions/0.2.0/Resources/htaccess-documentroot new file mode 100755 index 0000000..30a175c --- /dev/null +++ b/CoreVersions/0.2.0/Resources/htaccess-documentroot @@ -0,0 +1,16 @@ +# Disabling cache management +# that could cause problems with DAV requests +# Useful only for Apache servers, with AllowOverride All +# (ie, .htaccess files enabled) + +# Allow HTTP headers with Apache/FastCGI +# See http://code.google.com/p/sabredav/wiki/Authentication#Apache_+_(Fast)CGI + + + RewriteEngine On + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] + + + + ExpiresActive Off + diff --git a/CoreVersions/0.2.0/Resources/htaccess-specific b/CoreVersions/0.2.0/Resources/htaccess-specific new file mode 100755 index 0000000..cb24fd7 --- /dev/null +++ b/CoreVersions/0.2.0/Resources/htaccess-specific @@ -0,0 +1,2 @@ +Order allow,deny +Deny from all diff --git a/Specific/.htaccess b/Specific/.htaccess new file mode 100644 index 0000000..cb24fd7 --- /dev/null +++ b/Specific/.htaccess @@ -0,0 +1,2 @@ +Order allow,deny +Deny from all diff --git a/Specific/db/.ht.db.sqlite b/Specific/db/db.sqlite similarity index 100% rename from Specific/db/.ht.db.sqlite rename to Specific/db/db.sqlite