Enhancements on common error detection

Former-commit-id: ea0bcca354
This commit is contained in:
Jérôme Schneider 2012-07-24 22:35:56 +02:00
parent 9e5af08f7e
commit 89650784f5
12 changed files with 131 additions and 76 deletions

View file

@ -25,4 +25,5 @@
#################################################################
define("BAIKAL_VERSION", "0.2.0");
define("BAIKAL_HOMEPAGE", "http://baikal.codr.fr");
define("BAIKAL_HOMEPAGE", "http://baikal.codr.fr");
define("PROJECT_PACKAGE", "regular");

View file

@ -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

View file

@ -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();

View file

@ -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.<br /><strong>Whatever happens, it should begin and end with a slash.</strong>",
"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.<br /><strong>Whatever happens, it should begin and end with a slash.</strong>",
"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;
}

View file

@ -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

View file

@ -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;

View file

@ -1,35 +0,0 @@
<?php
#################################################################
# Copyright notice
#
# (c) 2012 Jérôme Schneider <mail@jeromeschneider.fr>
# 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);
}
}

View file

@ -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("<h3>DB file does not exist. To create it, please copy '<span style='font-family: monospace; background: yellow;'>Core/Resources/db.empty.sqlite</span>' to '<span style='font-family: monospace;background: yellow;'>Specific/db/.ht.db.sqlite</span>'</h3>");
}
# Asserting DB file is readable
if(!is_readable(PROJECT_SQLITE_FILE)) {
die("<h3>DB file is not readable. Please give read permissions on file '<span style='font-family: monospace; background: yellow;'>Specific/db/.ht.db.sqlite</span>'</h3>");
}
# Asserting DB file is writable
if(!is_writable(PROJECT_SQLITE_FILE)) {
die("<h3>DB file is not writable. Please give write permissions on file '<span style='font-family: monospace; background: yellow;'>Specific/db/.ht.db.sqlite</span>'</h3>");
}
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("<h3>DB file does not exist. To create it, please copy '<span style='font-family: monospace; background: yellow;'>Core/Resources/db.empty.sqlite</span>' to '<span style='font-family: monospace;background: yellow;'>" . PROJECT_SQLITE_FILE . "</span>'</h3>");
}
# Asserting DB file is readable
if(!is_readable(PROJECT_SQLITE_FILE)) {
die("<h3>DB file is not readable. Please give read permissions on file '<span style='font-family: monospace; background: yellow;'>" . PROJECT_SQLITE_FILE . "</span>'</h3>");
}
# Asserting DB file is writable
if(!is_writable(PROJECT_SQLITE_FILE)) {
die("<h3>DB file is not writable. Please give write permissions on file '<span style='font-family: monospace; background: yellow;'>" . PROJECT_SQLITE_FILE . "</span>'</h3>");
}
if(file_exists(PROJECT_SQLITE_FILE) && is_readable(PROJECT_SQLITE_FILE) && !isset($GLOBALS["DB"])) {
$GLOBALS["DB"] = new \Flake\Core\Database\Sqlite(PROJECT_SQLITE_FILE);
}
}
}

View file

@ -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
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
<IfModule mod_expires.c>
ExpiresActive Off
</IfModule>

View file

@ -0,0 +1,2 @@
Order allow,deny
Deny from all

2
Specific/.htaccess Normal file
View file

@ -0,0 +1,2 @@
Order allow,deny
Deny from all