Flat installation doesn't progress past initialization - Flake woes #98

Closed
JasonSpatola opened this Issue Jul 11, 2013 · 20 comments
@JasonSpatola

A. I did a flat installation on a local server. No problems; works perfectly with multiple accounts accessing it from various apps. Yay!

B. Tried a similar fresh flat install on a shared web host and it's generating errors. Boo! The Baïkal initialization wizard page displays fine; however, upon pressing "Save changes" (after populating the proper fields), I'm returned to the page with two items of note:

1.

"Validation error, Admin password is required."

This applies no matter what settings are entered, and yes, I've definitely entered passwords in the appropriate fields.

2.

Warning: stripslashes() expects parameter 1 to be string, array given in /home/servername/public_html/url.com/baikal-flat/Core/Frameworks/Flake/Framework.php on line 117

Warning: stripslashes() expects parameter 1 to be string, array given in /home/servername/public_html/url.com/baikal-flat/Core/Frameworks/Flake/Framework.php on line 117

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/servername/public_html/url.com/baikal-flat/Core/Frameworks/Flake/Framework.php:117) in /home/servername/public_html/url.com/baikal-flat/Core/Frameworks/Flake/Framework.php on line 183

Warning: Cannot modify header information - headers already sent by (output started at /home/servername/public_html/url.com/baikal-flat/Core/Frameworks/Flake/Framework.php:117) in /home/servername/public_html/url.com/baikal-flat/Core/Frameworks/Flake/Controller/Page.php on line 75

Re-entering passwords and attempting to save again results in the same error messages.

This is actually my second attempt at installing it on this hosting account - the first was on a subdomain, and exhibited identical behavior.

The Apache/PHP installation fits all the listed requirements, but if you'd like to take a look at my php.ini I'll post a link.

Anything to narrow down why this is happening would be appreciated. Thanks.

@FNKsMM

I have the same issue, although i only get the first two warnings

Warning: stripslashes() expects parameter 1 to be string, array given in /home/.sites/184/site834/web/baikal/Core/Frameworks/Flake/Framework.php on line 117

Warning: stripslashes() expects parameter 1 to be string, array given in /home/.sites/184/site834/web/baikal/Core/Frameworks/Flake/Framework.php on line 117

The same problem goes through most other form-submits within the baikal webadmin.

@meru

I have the same issue here:

Warning: stripslashes() expects parameter 1 to be string, array given in /home/www/xxx/html/cloud/Core/Frameworks/Flake/Framework.php on line 117

Warning: stripslashes() expects parameter 1 to be string, array given in /home/www/xxx/html/cloud/Core/Frameworks/Flake/Framework.php on line 117

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/www/xxx/html/cloud/Core/Frameworks/Flake/Framework.php:117) in /home/www/xxx/html/cloud/Core/Frameworks/Flake/Framework.php on line 183

Warning: Cannot modify header information - headers already sent by (output started at /home/www/xxx/html/cloud/Core/Frameworks/Flake/Framework.php:117) in /home/www/xxx/html/cloud/Core/Frameworks/Flake/Controller/Page.php on line 75

@JasonSpatola

Hey guys - I'm on the run so I haven't had time to fully test and dig into the details, but (1) turning off magic quotes and (2) turning on output buffering got it working splendidly.

I'll look into it more when I have a chance, but there's an avenue to try if you're stuck.

@meru

Thx,

magic quotes = off
output_buffering=4096 per php.ini in same directory

still same problem

@JasonSpatola

I've never used the directory-specific php.ini method before. An alternate method would be to add this to your .htaccess file:

php_flag magic_quotes_gpc   Off
php_flag output_buffering   On
@cidious

as a temporary solution, you can remove those lines in the file
Core/Frameworks/Flake/Framework.php:116

if(in_array(strtolower(ini_get('magic_quotes_gpc')), array('1', 'on'))) {
    $_POST = array_map('stripslashes', $_POST);
    $_GET = array_map('stripslashes', $_GET);
    $_COOKIE = array_map('stripslashes', $_COOKIE);
}
@meru

Thx for help to all:
cidious code help me for start using Baikal

mfg Meru

@rthurn

I could not turn off magic quotes as I'm on a shared hosting package.

I fixed the problem with a patch:

Add the following function to ... baikal-flat/Core/Frameworks/Flake/Framework.php after the namespace entry and then replace all occurences of 'stripslashes' with 'stripslashes_deep'

...

namespace Flake;

function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('\Flake\stripslashes_deep', $value) :
stripslashes($value);

return $value;

}
...

@rsrsrsrs

i also have this probelm:

Warning: array_map() expects parameter 1 to be a valid callback, function 'stripslashes_deep' not found or invalid function name in /home/reinhard-schneider-de/htdocs/baikal/Core/Frameworks/Flake/Framework.php on line 126

Warning: array_map() expects parameter 1 to be a valid callback, function 'stripslashes_deep' not found or invalid function name in /home/reinhard-schneider-de/htdocs/baikal/Core/Frameworks/Flake/Framework.php on line 127

Warning: array_map() expects parameter 1 to be a valid callback, function 'stripslashes_deep' not found or invalid function name in /home/reinhard-schneider-de/htdocs/baikal/Core/Frameworks/Flake/Framework.php on line 128

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/reinhard-schneider-de/htdocs/baikal/Core/Frameworks/Flake/Framework.php:126) in /home/reinhard-schneider-de/htdocs/baikal/Core/Frameworks/Flake/Framework.php on line 192

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/reinhard-schneider-de/htdocs/baikal/Core/Frameworks/Flake/Framework.php:126) in /home/reinhard-schneider-de/htdocs/baikal/Core/Frameworks/Flake/Framework.php on line 192

Notice: session_start() [function.session-start]: ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) in /home/reinhard-schneider-de/htdocs/baikal/Core/Frameworks/Flake/Framework.php on line 192

Warning: Cannot modify header information - headers already sent by (output started at /home/reinhard-schneider-de/htdocs/baikal/Core/Frameworks/Flake/Framework.php:126) in /home/reinhard-schneider-de/htdocs/baikal/Core/Frameworks/Flake/Controller/Page.php on line 75

but i rewrite the php file

namespace Flake;

function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);

return $value;

}

class Framework extends \Flake\Core\Framework {

public static function rmBeginSlash($sString) {
    if(substr($sString, 0, 1) === "/") {
        $sString = substr($sString, 1);
    }

    return $sString;
}

public static function rmEndSlash($sString) {
    if(substr($sString, -1) === "/") {
        $sString = substr($sString, 0, -1);
    }

    return $sString;
}

public static function appendSlash($sString) {
    if(substr($sString, -1) !== "/") {
        $sString .= "/";
    }

    return $sString;
}

public static function prependSlash($sString) {
    if(substr($sString, 0, 1) !== "/") {
        $sString = "/" . $sString;
    }

    return $sString;
}

public static function rmQuery($sString) {
    $iStart = strpos($sString, "?");
    return ($iStart === FALSE) ? $sString : substr($sString, 0, $iStart);
}

public static function rmScriptName($sString, $sScriptName) {
    $sScriptBaseName = basename($sScriptName);
    if( self::endswith($sString, $sScriptBaseName) )
        return substr($sString, 0, -strlen($sScriptBaseName));
    return $sString;
}

public static function rmProjectContext($sString) {
    return self::appendSlash(
        substr($sString, 0, -1 * strlen(PROJECT_CONTEXT_BASEURI))
    );
}

public static function endsWith($sString, $sTest) {
    $iTestLen = strlen($sTest);
    if ($iTestLen > strlen($sString)) return false;
    return substr_compare($sString, $sTest, -$iTestLen) === 0;
}

public static function bootstrap() {

    # Asserting PHP 5.3.0+
    if(version_compare(PHP_VERSION, '5.3.0', '<')) {
        die('Flake Fatal Error: Flake requires PHP 5.3.0+ to run properly. Your version is: ' . PHP_VERSION . '.');
    }

    # Define safehash salt
    define("PROJECT_SAFEHASH_SALT", "strong-secret-salt");

    # Define absolute server path to Flake Framework
    define("FLAKE_PATH_ROOT", PROJECT_PATH_ROOT . "Core/Frameworks/Flake/");    # ./

    if(!defined('LF')) {
        define('LF', chr(10));
    }

    if(!defined('CR')) {
        define('CR', chr(13));
    }

    if(array_key_exists("SERVER_NAME", $_SERVER) && $_SERVER["SERVER_NAME"] === "mongoose") {
        define("MONGOOSE_SERVER", TRUE);
    } else {
        define("MONGOOSE_SERVER", FALSE);
    }

    # Undo magic_quotes as this cannot be disabled by .htaccess on PHP ran as CGI
    # Source: http://stackoverflow.com/questions/517008/how-to-turn-off-magic-quotes-on-shared-hosting
    if(in_array(strtolower(ini_get('magic_quotes_gpc')), array('1', 'on'))) {
        $_POST = array_map('stripslashes_deep', $_POST);
        $_GET = array_map('stripslashes_deep', $_GET);
        $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
    }

....

what did do wrong???

thx for help
reinhard

@rsrsrsrs

no one any idea?

or perhaps somebody can upload a Framework.php file ....

please i dont know whatz wrong ....

@rthurn

Sorry you have to replace all 'stripslashes with '\Flake\stripslashes_deep' ... in Framework.php

<?php
#################################################################
#  Copyright notice
#
#  (c) 2013 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;
function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('\Flake\stripslashes_deep', $value) :
                stripslashes($value);

    return $value;
}
class Framework extends \Flake\Core\Framework {

    public static function rmBeginSlash($sString) {
        if(substr($sString, 0, 1) === "/") {
            $sString = substr($sString, 1);
        }

        return $sString;
    }

    public static function rmEndSlash($sString) {
        if(substr($sString, -1) === "/") {
            $sString = substr($sString, 0, -1);
        }

        return $sString;
    }

    public static function appendSlash($sString) {
        if(substr($sString, -1) !== "/") {
            $sString .= "/";
        }

        return $sString;
    }

    public static function prependSlash($sString) {
        if(substr($sString, 0, 1) !== "/") {
            $sString = "/" . $sString;
        }

        return $sString;
    }

    public static function rmQuery($sString) {
        $iStart = strpos($sString, "?");
        return ($iStart === FALSE) ? $sString : substr($sString, 0, $iStart);
    }

    public static function rmScriptName($sString, $sScriptName) {
        $sScriptBaseName = basename($sScriptName);
        if( self::endswith($sString, $sScriptBaseName) )
            return substr($sString, 0, -strlen($sScriptBaseName));
        return $sString;
    }

    public static function rmProjectContext($sString) {
        return self::appendSlash(
            substr($sString, 0, -1 * strlen(PROJECT_CONTEXT_BASEURI))
        );
    }

    public static function endsWith($sString, $sTest) {
        $iTestLen = strlen($sTest);
        if ($iTestLen > strlen($sString)) return false;
        return substr_compare($sString, $sTest, -$iTestLen) === 0;
    }

    public static function bootstrap() {

        # Asserting PHP 5.3.0+
        if(version_compare(PHP_VERSION, '5.3.0', '<')) {
            die('Flake Fatal Error: Flake requires PHP 5.3.0+ to run properly. Your version is: ' . PHP_VERSION . '.');
        }

        # Define safehash salt
        define("PROJECT_SAFEHASH_SALT", "strong-secret-salt");

        # Define absolute server path to Flake Framework
        define("FLAKE_PATH_ROOT", PROJECT_PATH_ROOT . "Core/Frameworks/Flake/");    # ./

        if(!defined('LF')) {
            define('LF', chr(10));
        }

        if(!defined('CR')) {
            define('CR', chr(13));
        }

        if(array_key_exists("SERVER_NAME", $_SERVER) && $_SERVER["SERVER_NAME"] === "mongoose") {
            define("MONGOOSE_SERVER", TRUE);
        } else {
            define("MONGOOSE_SERVER", FALSE);
        }

        # Undo magic_quotes as this cannot be disabled by .htaccess on PHP ran as CGI
        # Source: http://stackoverflow.com/questions/517008/how-to-turn-off-magic-quotes-on-shared-hosting
        if(in_array(strtolower(ini_get('magic_quotes_gpc')), array('1', 'on'))) {
            $_POST = array_map('\Flake\stripslashes_deep', $_POST);
            $_GET = array_map('\Flake\stripslashes_deep', $_GET);
            $_COOKIE = array_map('\Flake\stripslashes_deep', $_COOKIE);
        }

        # Fixing some CGI environments, that prefix HTTP_AUTHORIZATION (forwarded in .htaccess) with "REDIRECT_"
        if(array_key_exists("REDIRECT_HTTP_AUTHORIZATION", $_SERVER)) {
            $_SERVER["HTTP_AUTHORIZATION"] = $_SERVER["REDIRECT_HTTP_AUTHORIZATION"];
        }

        #################################################################################################

        # determine Flake install root path
        # 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/");

        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_BASEURI
        $sScript = substr($_SERVER["SCRIPT_FILENAME"], strlen($_SERVER["DOCUMENT_ROOT"]));
        $sDirName = str_replace("\\", "/", dirname($sScript));  # fix windows backslashes

        if($sDirName !== ".") {
            $sDirName = self::appendSlash($sDirName);
        } else {
            $sDirName = "/";
        }

        $sBaseUrl = self::rmBeginSlash(self::rmProjectContext($sDirName));
        define("PROJECT_BASEURI", self::prependSlash($sBaseUrl));   # SabreDAV needs a "/" at the beginning of BASEURL

        # Determine PROJECT_URI
        $sProtocol = \Flake\Util\Tools::getCurrentProtocol();
        $sHttpBaseUrl = strtolower($_SERVER["REQUEST_URI"]);
        $sHttpBaseUrl = self::rmQuery($sHttpBaseUrl);
        $sHttpBaseUrl = self::rmScriptName($sHttpBaseUrl, $sScript);
        $sHttpBaseUrl = self::rmProjectContext($sHttpBaseUrl);
        define("PROJECT_URI", $sProtocol . "://" . $_SERVER["HTTP_HOST"] . $sHttpBaseUrl);
        unset($sScript); unset($sDirName); unset($sBaseUrl); unset($sProtocol); unset($sHttpBaseUrl);

        #################################################################################################

        require_once(FLAKE_PATH_ROOT . 'Util/Twig/lib/Twig/Autoloader.php');
        \Twig_Autoloader::register();

        # Include Flake Framework config
        require_once(FLAKE_PATH_ROOT . "config.php");

        # Determine Router class
        $GLOBALS["ROUTER"] = \Flake\Util\Tools::router();

        if(!\Flake\Util\Tools::isCliPhp()) {
            ini_set("html_errors", TRUE);
            session_start();
        }

        setlocale(LC_ALL, FLAKE_LOCALE);
        date_default_timezone_set(FLAKE_TIMEZONE);

        $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
        # NOTE: DB initialization and App config files inclusion
        # do not break execution if not properly executed, as
        # these errors will have to be caught later in the process
        # notably by the App install tool, if available; breaking right now
        # would forbid such install tool forwarding, for instance

        $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() {

        if(defined("PROJECT_DB_MYSQL") && PROJECT_DB_MYSQL === TRUE) {
            self::initDbMysql();
        } else {
            self::initDbSqlite();
        }
    }

    protected static function initDbSqlite() {
        # Asserting DB filepath is set
        if(!defined("PROJECT_SQLITE_FILE")) {
            return FALSE;
        }

        # 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/SQLite/db.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>");
        }

        # Asserting DB directory is writable
        if(!is_writable(dirname(PROJECT_SQLITE_FILE))) {
            die("<h3>The <em>FOLDER</em> containing the DB file is not writable, and it has to.<br />Please give write permissions on folder '<span style='font-family: monospace; background: yellow;'>" . dirname(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);
            return TRUE;
        }

        return FALSE;
    }

    protected static function initDbMysql() {

        if(!defined("PROJECT_DB_MYSQL_HOST")) {
            die("<h3>The constant PROJECT_DB_MYSQL_HOST, containing the MySQL host name, is not set.<br />You should set it in Specific/config.system.php</h3>");
        }

        if(!defined("PROJECT_DB_MYSQL_DBNAME")) {
            die("<h3>The constant PROJECT_DB_MYSQL_DBNAME, containing the MySQL database name, is not set.<br />You should set it in Specific/config.system.php</h3>");
        }

        if(!defined("PROJECT_DB_MYSQL_USERNAME")) {
            die("<h3>The constant PROJECT_DB_MYSQL_USERNAME, containing the MySQL database username, is not set.<br />You should set it in Specific/config.system.php</h3>");
        }

        if(!defined("PROJECT_DB_MYSQL_PASSWORD")) {
            die("<h3>The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.<br />You should set it in Specific/config.system.php</h3>");
        }

        try {
            $GLOBALS["DB"] = new \Flake\Core\Database\Mysql(
                PROJECT_DB_MYSQL_HOST,
                PROJECT_DB_MYSQL_DBNAME,
                PROJECT_DB_MYSQL_USERNAME,
                PROJECT_DB_MYSQL_PASSWORD
            );

            # We now setup the connexion to use UTF8
            $GLOBALS["DB"]->query("SET NAMES UTF8");
        } catch(\Exception $e) {
            #die("<h3>Baïkal was not able to establish a connexion to the configured MySQL database (as configured in Specific/config.system.php).</h3>");
        }

        return TRUE;
    }

    public static function isDBInitialized() {
        return isset($GLOBALS["DB"]) && \Flake\Util\Tools::is_a($GLOBALS["DB"], "\Flake\Core\Database");
    }
}
@rsrsrsrs

;-)
thx a lot.

"Copyright notice", i will never forget it again.
sorry

regards
reinhard

@rthurn

Sorry, it was not my intention that the copyright notice is printed so prominent. I just did a copy and paste from my text editor ... no special formatting ... but github forum software probably knows automatically whats important .... :-)
Now the code block is fenced with ``` ....

@rclocher3

Hello to everyone, and thanks for posting the fix. This thread seems like it would be confusing to non-programmers, so I'll summarize the fix.

If you got the "validation error admin password is required" error and also the "stripslashes() expects parameter 1 to be string" warning, then you are probably installing Baïkal on a web site hosted on a shared server, and a search engine brought you here. In other words, you have a small web site you're paying someone else to host. In that case you have no control over php.ini, and there's a good chance you have no clue what turning off magic quotes and turning on output buffering is all about anyway. (It's a PHP thing. PHP is a scripting language used to generate dynamic web pages, which is what Baïkal is made of.) Not to worry, this problem can be easily fixed; all you have to do is edit one file.

Go to the folder on your local computer and find the folder where you unpacked the zip file. Find Core/Frameworks/Flake/Framework.php, and copy it to Framework.php.old in the same folder as a backup. Then edit Framework.php. Near the top, just under the "namespace Flake;" line under the copyright notice, add this code:

function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('\Flake\stripslashes_deep', $value) :
                stripslashes($value);
    return $value;
}

Then, further down in the same file, find these three lines:

$_POST = array_map('\Flake\stripslashes', $_POST);
$_GET = array_map('\Flake\stripslashes', $_GET);
$_COOKIE = array_map('\Flake\stripslashes', $_COOKIE);

and change "stripslashes" to "stripslashes_deep" in all three lines. Compare your results to the complete copy of the modified Framework.php that rthurn posted in this thread. Don't worry about how many blank lines or tab characters there are.

When you're satisfied, save Framework.php and copy the new version up to your web site. That should fix this problem. Good luck.

  • Rob
@TiNNiT

I can confirm that the solution provided by JasonSpatola worked for me, so I did not have to use de stripslashes_deep solution.

Add these two lines to the .htacces-file in the root of your installation, and your good to go:

php_flag magic_quotes_gpc Off
php_flag output_buffering On

@hawkmyarsis

Hi, I came across this issue too when trying to install baikal on a QNAP 112p. I transferred the files by connecting to the qnap via ftp from windows explorer. I tried both solutions suggested in this thread.

First I opened the file "apache2_htaccess.conf" (I hope that's the one which is referred to as .htaccess-file in this thread). It contained the two lines "php_flag magic_quotes_gpc off" and "php_flag output_buffering off". I changed php_flag output_buffering off to php_flag output_buffering on, with no effect.

Then I tried to alter the framework.php as suggested, with the effect that upon hitting "Save Changes" I don't get an error message anymore, but baikal still won't accept anything I entered. It just resets the screen to the standard values as before, just without the error message.

Any hint to what my problem could be is highly appreciated.

My frameworks.php looks like this:

<?php
#################################################################
#  Copyright notice
#
#  (c) 2013 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;
function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('\Flake\stripslashes_deep', $value) :
                stripslashes($value);
    return $value;
}
class Framework extends \Flake\Core\Framework {

    public static function rmBeginSlash($sString) {
        if(substr($sString, 0, 1) === "/") {
            $sString = substr($sString, 1);
        }

        return $sString;
    }

    public static function rmEndSlash($sString) {
        if(substr($sString, -1) === "/") {
            $sString = substr($sString, 0, -1);
        }

        return $sString;
    }

    public static function appendSlash($sString) {
        if(substr($sString, -1) !== "/") {
            $sString .= "/";
        }

        return $sString;
    }

    public static function prependSlash($sString) {
        if(substr($sString, 0, 1) !== "/") {
            $sString = "/" . $sString;
        }

        return $sString;
    }

    public static function rmQuery($sString) {
        $iStart = strpos($sString, "?");
        return ($iStart === FALSE) ? $sString : substr($sString, 0, $iStart);
    }

    public static function rmScriptName($sString, $sScriptName) {
        $sScriptBaseName = basename($sScriptName);
        if( self::endswith($sString, $sScriptBaseName) )
            return substr($sString, 0, -strlen($sScriptBaseName));
        return $sString;
    }

    public static function rmProjectContext($sString) {
        return self::appendSlash(
            substr($sString, 0, -1 * strlen(PROJECT_CONTEXT_BASEURI))
        );
    }

    public static function endsWith($sString, $sTest) {
        $iTestLen = strlen($sTest);
        if ($iTestLen > strlen($sString)) return false;
        return substr_compare($sString, $sTest, -$iTestLen) === 0;
    }

    public static function bootstrap() {

        # Asserting PHP 5.3.0+
        if(version_compare(PHP_VERSION, '5.3.0', '<')) {
            die('Flake Fatal Error: Flake requires PHP 5.3.0+ to run properly. Your version is: ' . PHP_VERSION . '.');
        }

        # Define safehash salt
        define("PROJECT_SAFEHASH_SALT", "strong-secret-salt");

        # Define absolute server path to Flake Framework
        define("FLAKE_PATH_ROOT", PROJECT_PATH_ROOT . "Core/Frameworks/Flake/");    # ./

        if(!defined('LF')) {
            define('LF', chr(10));
        }

        if(!defined('CR')) {
            define('CR', chr(13));
        }

        if(array_key_exists("SERVER_NAME", $_SERVER) && $_SERVER["SERVER_NAME"] === "mongoose") {
            define("MONGOOSE_SERVER", TRUE);
        } else {
            define("MONGOOSE_SERVER", FALSE);
        }

        # Undo magic_quotes as this cannot be disabled by .htaccess on PHP ran as CGI
        # Source: http://stackoverflow.com/questions/517008/how-to-turn-off-magic-quotes-on-shared-hosting
        if(in_array(strtolower(ini_get('magic_quotes_gpc')), array('1', 'on'))) {
            $_POST = array_map('stripslashes_deep', $_POST);
            $_GET = array_map('stripslashes_deep', $_GET);
            $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
        }

        # Fixing some CGI environments, that prefix HTTP_AUTHORIZATION (forwarded in .htaccess) with "REDIRECT_"
        if(array_key_exists("REDIRECT_HTTP_AUTHORIZATION", $_SERVER)) {
            $_SERVER["HTTP_AUTHORIZATION"] = $_SERVER["REDIRECT_HTTP_AUTHORIZATION"];
        }

        #################################################################################################

        # determine Flake install root path
        # 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/");

        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_BASEURI
        $sScript = substr($_SERVER["SCRIPT_FILENAME"], strlen($_SERVER["DOCUMENT_ROOT"]));
        $sDirName = str_replace("\\", "/", dirname($sScript));  # fix windows backslashes

        if($sDirName !== ".") {
            $sDirName = self::appendSlash($sDirName);
        } else {
            $sDirName = "/";
        }

        $sBaseUrl = self::rmBeginSlash(self::rmProjectContext($sDirName));
        define("PROJECT_BASEURI", self::prependSlash($sBaseUrl));   # SabreDAV needs a "/" at the beginning of BASEURL

        # Determine PROJECT_URI
        $sProtocol = \Flake\Util\Tools::getCurrentProtocol();
        $sHttpBaseUrl = strtolower($_SERVER["REQUEST_URI"]);
        $sHttpBaseUrl = self::rmQuery($sHttpBaseUrl);
        $sHttpBaseUrl = self::rmScriptName($sHttpBaseUrl, $sScript);
        $sHttpBaseUrl = self::rmProjectContext($sHttpBaseUrl);
        define("PROJECT_URI", $sProtocol . "://" . $_SERVER["HTTP_HOST"] . $sHttpBaseUrl);
        unset($sScript); unset($sDirName); unset($sBaseUrl); unset($sProtocol); unset($sHttpBaseUrl);

        #################################################################################################

        require_once(FLAKE_PATH_ROOT . 'Util/Twig/lib/Twig/Autoloader.php');
        \Twig_Autoloader::register();

        # Include Flake Framework config
        require_once(FLAKE_PATH_ROOT . "config.php");

        # Determine Router class
        $GLOBALS["ROUTER"] = \Flake\Util\Tools::router();

        if(!\Flake\Util\Tools::isCliPhp()) {
            ini_set("html_errors", TRUE);
            session_start();
        }

        setlocale(LC_ALL, FLAKE_LOCALE);
        date_default_timezone_set(FLAKE_TIMEZONE);

        $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
        # NOTE: DB initialization and App config files inclusion
        # do not break execution if not properly executed, as
        # these errors will have to be caught later in the process
        # notably by the App install tool, if available; breaking right now
        # would forbid such install tool forwarding, for instance

        $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() {

        if(defined("PROJECT_DB_MYSQL") && PROJECT_DB_MYSQL === TRUE) {
            self::initDbMysql();
        } else {
            self::initDbSqlite();
        }
    }

    protected static function initDbSqlite() {
        # Asserting DB filepath is set
        if(!defined("PROJECT_SQLITE_FILE")) {
            return FALSE;
        }

        # 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/SQLite/db.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>");
        }

        # Asserting DB directory is writable
        if(!is_writable(dirname(PROJECT_SQLITE_FILE))) {
            die("<h3>The <em>FOLDER</em> containing the DB file is not writable, and it has to.<br />Please give write permissions on folder '<span style='font-family: monospace; background: yellow;'>" . dirname(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);
            return TRUE;
        }

        return FALSE;
    }

    protected static function initDbMysql() {

        if(!defined("PROJECT_DB_MYSQL_HOST")) {
            die("<h3>The constant PROJECT_DB_MYSQL_HOST, containing the MySQL host name, is not set.<br />You should set it in Specific/config.system.php</h3>");
        }

        if(!defined("PROJECT_DB_MYSQL_DBNAME")) {
            die("<h3>The constant PROJECT_DB_MYSQL_DBNAME, containing the MySQL database name, is not set.<br />You should set it in Specific/config.system.php</h3>");
        }

        if(!defined("PROJECT_DB_MYSQL_USERNAME")) {
            die("<h3>The constant PROJECT_DB_MYSQL_USERNAME, containing the MySQL database username, is not set.<br />You should set it in Specific/config.system.php</h3>");
        }

        if(!defined("PROJECT_DB_MYSQL_PASSWORD")) {
            die("<h3>The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.<br />You should set it in Specific/config.system.php</h3>");
        }

        try {
            $GLOBALS["DB"] = new \Flake\Core\Database\Mysql(
                PROJECT_DB_MYSQL_HOST,
                PROJECT_DB_MYSQL_DBNAME,
                PROJECT_DB_MYSQL_USERNAME,
                PROJECT_DB_MYSQL_PASSWORD
            );

            # We now setup the connexion to use UTF8
            $GLOBALS["DB"]->query("SET NAMES UTF8");
        } catch(\Exception $e) {
            #die("<h3>Baïkal was not able to establish a connexion to the configured MySQL database (as configured in Specific/config.system.php).</h3>");
        }

        return TRUE;
    }

    public static function isDBInitialized() {
        return isset($GLOBALS["DB"]) && \Flake\Util\Tools::is_a($GLOBALS["DB"], "\Flake\Core\Database");
    }
}
@hawkmyarsis

noone?

@HassanMullah

pic20140408_001
Hi hawkmyarsis,
it's cool, i have also a QNAP TS-112p and the same problem.
Now my solution:
1. Webserver on Port 80 and 443 (SSL) an WebDAV is active
2. Virtual Host (over the WebAdmin from QNAP) ist active
3. MySQL is active, also Port 3306
4. Connect to MySQL over phpMyAdmin ist OK. Create a Databasename (create no tables)
5. Copy the baikal-flat-0.2.7 to the virtual host directory
6. Copy the .htaccess with following content to the root of the virtual host directory

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

php_flag magic_quotes_gpc Off
php_flag output_buffering On

  1. now you can give your password. At next page select "MySQL". you get an error, but here you can set the Database credentials.

  2. Now it should run.

Have fun a give a feedback please

@hawkmyarsis

Hi HassanMullah,

thank you very much for your response. Sadly, I'm still not able to install baikal. I followed all your instructions, but still get the "Validation error Admin password is required." message on the initialization screen when I hit save. Since I figure that this should be resolved by the .htaccess tweak I'll write a bit more about what exactly I did, since I wasn't 100% sure what needs to be done.

I opened the file "apache2_htaccess.conf" which I found in folder "\baikal\vendor\sabre\dav\examples\webserver" and changed it according to your instructions. It now looks as follows:

RewriteEngine On
# This makes every request go to server.php
RewriteRule (.*) server.php [L]

# Output buffering needs to be off, to prevent high memory usage
php_flag output_buffering on

# This is also to prevent high memory usage
php_flag always_populate_raw_post_data off

# This is almost a given, but magic quotes is *still* on on some
# linux distributions
php_flag magic_quotes_gpc off

# SabreDAV is not compatible with mbstring function overloading
php_flag mbstring.func_overload off

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
<IfModule>

<IfModule mod_expires.c>
ExpiresActive Off
<IfModule>

Anything else I can try?

@netgusto

The magic quotes problem shoud be fixed in be7f499.

@netgusto netgusto closed this Nov 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment