From 0fc430a4ca2d9c25a7172877ddb759af64fc16f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Schneider?= Date: Tue, 24 Jul 2012 09:08:25 +0200 Subject: [PATCH] Enhancements to prevent many FTP hosting problems Former-commit-id: 88622cac549d21123f51dfb589c419e9a784c3c1 --- .../0.2.0/Frameworks/Baikal/Core/Tools.php | 6 +- .../0.2.0/Frameworks/Baikal/Framework.php | 2 +- .../Frameworks/Baikal/Model/Config/System.php | 38 ++++++---- .../Controller/Install/Initialize.php | 4 ++ .../0.2.0/Frameworks/Flake/Framework.php | 66 ++++++++++++------ Specific/db/{.ht.db.sqlite => db.sqlite} | Bin html/.htaccess | 5 ++ 7 files changed, 81 insertions(+), 40 deletions(-) rename Specific/db/{.ht.db.sqlite => db.sqlite} (100%) 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/BaikalAdmin/Controller/Install/Initialize.php b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/Initialize.php index 54040ae..3add11e 100755 --- a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -180,6 +180,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/Framework.php b/CoreVersions/0.2.0/Frameworks/Flake/Framework.php index 488c3d0..eb3d91a 100755 --- a/CoreVersions/0.2.0/Frameworks/Flake/Framework.php +++ b/CoreVersions/0.2.0/Frameworks/Flake/Framework.php @@ -105,27 +105,9 @@ class Framework extends \Flake\Core\Framework { 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"); @@ -156,16 +138,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/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 diff --git a/html/.htaccess b/html/.htaccess index 30a175c..6179137 100755 --- a/html/.htaccess +++ b/html/.htaccess @@ -14,3 +14,8 @@ ExpiresActive Off + + + Order allow,deny + Deny from all +