Working on web admin

Former-commit-id: 81b7ca0614
This commit is contained in:
Jérôme Schneider 2012-04-24 21:09:44 +02:00
parent 46a3de7109
commit 6a951b4bd1
11 changed files with 152 additions and 219 deletions

View file

@ -61,7 +61,7 @@ function installTool() {
if(defined("BAIKAL_CONTEXT_INSTALL") && BAIKAL_CONTEXT_INSTALL === TRUE) {
return;
} else {
$sInstallToolUrl = prependSlash($sBaseUrl . "admin/install/");
$sInstallToolUrl = BAIKAL_URI . "admin/install/";
header("Location: " . $sInstallToolUrl);
exit(0);
}
@ -101,7 +101,6 @@ define("BAIKAL_PATH_WWWROOT", BAIKAL_PATH_CORE . "WWWRoot/");
require_once(BAIKAL_PATH_CORE . "Distrib.php");
# Determine BAIKAL_URI
#print_r($_SERVER);
$sScript = substr($_SERVER["SCRIPT_FILENAME"], strlen($_SERVER["DOCUMENT_ROOT"]));
$sDirName = appendSlash(dirname($sScript));
$sBaseUrl = appendSlash(substr($sDirName, 0, -1 * strlen(BAIKAL_CONTEXT_BASEURI)));
@ -120,36 +119,50 @@ if(
require_once(BAIKAL_PATH_SPECIFIC . "config.php");
require_once(BAIKAL_PATH_SPECIFIC . "config.system.php");
date_default_timezone_set(BAIKAL_TIMEZONE);
if(version_compare(BAIKAL_VERSION, BAIKAL_CONFIGURED_VERSION) > 0) {
# Check that Baïkal is already configured
if(!defined("BAIKAL_CONFIGURED_VERSION")) {
installTool();
} else {
# Check if DB exists
if(!file_exists(BAIKAL_SQLITE_FILE)) {
die("DB file does not exist.<br />To create it, please copy '<b>Core/Resources/baikal.empty.sqlite</b>' to '<b>Specific/db/baikal.sqlite</b>'.<br /><span style='color: red; font-weight: bold'>Please note the change in the file name while doing so</span> (from 'baikal.empty.sqlite' to 'baikal.sqlite').");
}
# Check that running version matches configured version
if(version_compare(BAIKAL_VERSION, BAIKAL_CONFIGURED_VERSION) > 0) {
installTool();
} else {
# Database
$pdo = new PDO('sqlite:' . BAIKAL_SQLITE_FILE);
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$bShouldCheckEnv = ((!defined("BAIKAL_CONTEXT_CLI") || BAIKAL_CONTEXT_CLI === FALSE) && (!defined("BAIKAL_CONTEXT_ADMIN") || BAIKAL_CONTEXT_ADMIN === FALSE));
if($bShouldCheckEnv === TRUE) {
# Mapping PHP errors to exceptions
function exception_error_handler($errno, $errstr, $errfile, $errline) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
# Check that admin password is set
if(!defined("BAIKAL_ADMIN_PASSWORDHASH")) {
installTool();
}
set_error_handler("exception_error_handler");
} else {
error_reporting(E_ALL ^ E_NOTICE);
# Check that DB exists
if(!file_exists(BAIKAL_SQLITE_FILE)) {
die("DB file does not exist.<br />To create it, please copy '<b>Core/Resources/baikal.empty.sqlite</b>' to '<b>Specific/db/baikal.sqlite</b>'.<br /><span style='color: red; font-weight: bold'>Please note the change in the file name while doing so</span> (from 'baikal.empty.sqlite' to 'baikal.sqlite').");
}
# Database
$pdo = new PDO('sqlite:' . BAIKAL_SQLITE_FILE);
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$bShouldCheckEnv = ((!defined("BAIKAL_CONTEXT_CLI") || BAIKAL_CONTEXT_CLI === FALSE) && (!defined("BAIKAL_CONTEXT_ADMIN") || BAIKAL_CONTEXT_ADMIN === FALSE));
if($bShouldCheckEnv === TRUE) {
# Mapping PHP errors to exceptions
function exception_error_handler($errno, $errstr, $errfile, $errline) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");
} else {
error_reporting(E_ALL ^ E_NOTICE);
}
unset($bShouldCheckEnv);
// Autoloader
require_once(BAIKAL_PATH_SABREDAV . 'autoload.php');
}
unset($bShouldCheckEnv);
// Autoloader
require_once(BAIKAL_PATH_SABREDAV . 'autoload.php');
}
}

View file

@ -71,6 +71,59 @@ class Tools {
return $password;
}
public static function getCopyrightNotice($sLinePrefixChar = "#", $sLineSuffixChar = "", $sOpening = FALSE, $sClosing = FALSE) {
if($sOpening === FALSE) {
$sOpening = str_repeat("#", 78);
}
if($sClosing === FALSE) {
$sClosing = str_repeat("#", 78);
}
$iYear = date("Y");
$sCode =<<<CODE
Copyright notice
(c) {$iYear} Jérôme Schneider <mail@jeromeschneider.fr>
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!
CODE;
$sCode = "\n" . trim($sCode) . "\n";
$aCode = explode("\n", $sCode);
foreach(array_keys($aCode) as $iLineNum) {
$aCode[$iLineNum] = trim($sLinePrefixChar . "\t" . $aCode[$iLineNum]);
}
if(trim($sOpening) !== "") {
array_unshift($aCode, $sOpening);
}
if(trim($sClosing) !== "") {
$aCode[] = $sClosing;
}
return implode("\n", $aCode);
}
public static function timezones() {
$aZones = array(
"Africa/Abidjan",

View file

@ -101,7 +101,7 @@ abstract class Config extends \Flake\Core\Model\NoDb {
$aRes[$sConstant] = $sValue;
} elseif($iNbRes === 0) {
throw new \Exception("Baikal\Model\Config->parseConfig(): Unable to find constant '" . $prop . "' in config file");
throw new \Exception("Baikal\Model\Config->parseConfig(): Unable to find constant '" . $sConstant . "' in config file");
}
}

View file

@ -41,12 +41,6 @@ class Standard extends \Baikal\Model\Config {
"BAIKAL_ADMIN_ENABLED" => array(
"type" => "boolean",
),
"BAIKAL_STANDALONE_ALLOWED" => array(
"type" => "boolean",
),
"BAIKAL_STANDALONE_PORT" => array(
"type" => "integer",
),
"BAIKAL_ADMIN_PASSWORDHASH" => array(
"type" => "string",
)
@ -60,8 +54,6 @@ class Standard extends \Baikal\Model\Config {
"BAIKAL_CARD_ENABLED" => "",
"BAIKAL_CAL_ENABLED" => "",
"BAIKAL_ADMIN_ENABLED" => "",
"BAIKAL_STANDALONE_ALLOWED" => "",
"BAIKAL_STANDALONE_PORT" => "",
"BAIKAL_ADMIN_PASSWORDHASH" => ""
);
@ -95,30 +87,26 @@ class Standard extends \Baikal\Model\Config {
),
)));
$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"
)));
$sNotice = "-- Leave empty to keep current password --";
$oMorpho->add(new \Formal\Element\Password(array(
"prop" => "BAIKAL_ADMIN_PASSWORDHASH",
"label" => "Web admin password",
"placeholder" => $sNotice,
)));
$oMorpho->add(new \Formal\Element\Password(array(
"prop" => "BAIKAL_ADMIN_PASSWORDHASH_CONFIRM",
"label" => "Web admin password confirmation",
"placeholder" => $sNotice,
"validation" => "sameas:BAIKAL_ADMIN_PASSWORDHASH",
)));
if(!defined("BAIKAL_ADMIN_PASSWORDHASH") || trim(BAIKAL_ADMIN_PASSWORDHASH) === "") {
# No password set (Form is used in install tool), so password is required as it has to be defined
$oMorpho->element("BAIKAL_ADMIN_PASSWORDHASH")->setOption("validation", "required");
} else {
$sNotice = "-- Leave empty to keep current password --";
$oMorpho->element("BAIKAL_ADMIN_PASSWORDHASH")->setOption("placeholder", $sNotice);
$oMorpho->element("BAIKAL_ADMIN_PASSWORDHASH_CONFIRM")->setOption("placeholder", $sNotice);
}
return $oMorpho;
}

View file

@ -44,6 +44,12 @@ class System extends \Baikal\Model\Config {
"BAIKAL_SQLITE_FILE" => array(
"type" => "litteral",
),
"BAIKAL_STANDALONE_ALLOWED" => array(
"type" => "boolean",
),
"BAIKAL_STANDALONE_PORT" => array(
"type" => "integer",
),
);
protected $aData = array(
@ -52,6 +58,8 @@ class System extends \Baikal\Model\Config {
"BAIKAL_CARD_BASEURI" => "",
"BAIKAL_CAL_BASEURI" => "",
"BAIKAL_SQLITE_FILE" => "",
"BAIKAL_STANDALONE_ALLOWED" => "",
"BAIKAL_STANDALONE_PORT" => "",
);
public function formMorphologyForThisModelInstance() {
@ -111,6 +119,16 @@ class System extends \Baikal\Model\Config {
)
)));
$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"
)));
return $oMorpho;
}

View file

@ -1,108 +0,0 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Jérôme Schneider <mail@jeromeschneider.fr>
* 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;
class Install extends \Flake\Core\Controller {
protected $aMessages = array();
protected $oModel; # \BaikalAdmin\Model\Install
protected $oForm; # \Formal\Form
public function __construct() {
parent::__construct();
$this->oModel = new \BaikalAdmin\Model\Install();
$this->oForm = $this->oModel->formForThisModelInstance(array(
"close" => FALSE
));
}
public function execute() {
if($this->oForm->submitted()) {
$this->oForm->execute();
}
}
public function render() {
# Determine in which case we are
# A- Baïkal is not configured yet; new installation
# B- Baïkal is configured, but maintenance tasks have to be achieved; upgrade
if(defined("BAIKAL_CONFIGURED_VERSION")) {
# we have to upgrade Baïkal (existing installation)
$sHtml = $this->render_upgradeInstall();
} else {
# we have to initialize Baïkal (new installation)
$sHtml = $this->render_newInstall();
}
return $sHtml;
}
protected function render_newInstall() {
$sBigIcon = \BaikalAdmin\Model\Install::bigicon();
$sBaikalVersion = BAIKAL_VERSION;
$sHtml = <<<HTML
<header class="jumbotron subhead" id="overview">
<h1><i class="{$sBigIcon}"></i>Baïkal initialization (version {$sBaikalVersion})</h1>
<p class="lead">Configure your new Baïkal installation.</p>
</header>
HTML;
$sHtml .= $this->oForm->render();
return $sHtml;
}
protected function render_upgradeInstall() {
$sBigIcon = \BaikalAdmin\Model\Install::bigicon();
$sBaikalVersion = BAIKAL_VERSION;
$sBaikalConfiguredVersion = BAIKAL_CONFIGURED_VERSION;
$sHtml = <<<HTML
<header class="jumbotron subhead" id="overview">
<h1><i class="{$sBigIcon}"></i>Baïkal upgrade wizard</h1>
<p class="lead">Upgrading Baïkal from version <strong>{$sBaikalConfiguredVersion}</strong> to version <strong>{$sBaikalVersion}</strong>.</p>
</header>
HTML;
/* $sHtml .= <<<HTML
<h2>What is this ?</h2>
<p>
This is the Baïkal Install Tool.<br />
It's displayed because you just installed or upgraded your Baïkal installation.<br />
<strong>Baïkal requires some maintenance in order to ensure everything works as expected.</strong>
</p>
HTML;
*/
return $sHtml;
}
}

View file

@ -36,6 +36,13 @@ class Auth {
}
static function assertUnlocked() {
if(defined("BAIKAL_CONTEXT_INSTALL") || BAIKAL_CONTEXT_INSTALL !== TRUE) {
$sToolName = "Ba&iuml;kal Install Tool";
} else {
$sToolName = "Ba&iuml;kal Admin";
}
$bLocked = TRUE;
$sEnableFile = BAIKAL_PATH_SPECIFIC . "ENABLE_ADMIN";
if(file_exists($sEnableFile)) {
@ -52,13 +59,13 @@ class Auth {
// file has been created more than an hour ago
// delete and declare locked
if(!@unlink($sEnableFile)) {
die("<h1>Ba&iuml;kal Admin is locked.</h1>To unlock it, delete and re-create an empty file named ENABLE_ADMIN in <b>Specific/config.php</b>");
die("<h1>" . $sToolName . " is locked.</h1>To unlock it, delete and re-create an empty file named ENABLE_ADMIN in <b>Specific/config.php</b>");
}
}
}
if($bLocked) {
die("<h1>Ba&iuml;kal Admin is locked.</h1>To unlock it, create an empty file named ENABLE_ADMIN in <b>Specific/</b>");
die("<h1>" . $sToolName . " is locked.</h1>To unlock it, create an empty file named ENABLE_ADMIN in <b>Specific/</b>");
}
}

View file

@ -40,11 +40,24 @@ require_once(dirname(dirname(dirname(__FILE__))) . "/Core/Bootstrap.php"); # ../
# Create and setup a page object
$oPage = new \Flake\Controller\Page(BAIKALADMIN_PATH_TEMPLATES . "Page/index.html");
$oPage->injectHTTPHeaders();
$oPage->setTitle("Baïkal Install Tool");
$oPage->setTitle("Baïkal Maintainance");
$oPage->setBaseUrl(BAIKAL_URI);
$oPage->zone("navbar")->addBlock(new \BaikalAdmin\Controller\Navigation\Topbar\Install());
$oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install());
if(!defined("BAIKAL_CONFIGURED_VERSION")) {
# we have to upgrade Baïkal (existing installation)
$oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Initialize());
} elseif(!defined("BAIKAL_ADMIN_PASSWORDHASH")) {
# we have to set an admin password
$oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\AdminPassword());
} else {
# we have to initialize Baïkal (new installation)
$oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\VersionUpgrade());
}
# Route the request
//$GLOBALS["ROUTER"]::route($oPage);

View file

@ -205,11 +205,15 @@ class Form {
}
public function persisted() {
if(is_null($this->bPersisted)) {
throw new \Exception("\Formal\Form->persisted(): information is not available yet. This method may only be called after execute()");
if($this->submitted()) {
if(is_null($this->bPersisted)) {
throw new \Exception("\Formal\Form->persisted(): information is not available yet. This method may only be called after execute()");
}
return $this->bPersisted;
}
return $this->bPersisted;
return FALSE;
}
public function validateRequired($sValue, \Formal\Form\Morphology $oMorpho, \Formal\Element $oElement) {

View file

@ -1,55 +0,0 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Jérôme Schneider <mail@jeromeschneider.fr>
* 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!
***************************************************************/
##############################################################################
# In this section: Required configuration: you *have* to customize
# these settings for Baïkal to run properly
#
# Timezone of your users, if unsure, check http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
define("BAIKAL_TIMEZONE", "Europe/Paris");
##############################################################################
# In this section: Optional configuration: you *may* customize these settings
#
# CardDAV ON/OFF switch; default TRUE
define("BAIKAL_CARD_ENABLED", TRUE);
# CalDAV ON/OFF switch; default TRUE
define("BAIKAL_CAL_ENABLED", TRUE);
# Baïkal Web Admin interface ON/OFF; default FALSE
define("BAIKAL_ADMIN_ENABLED", TRUE);
# Standalone Server, allowed or not; default FALSE
define("BAIKAL_STANDALONE_ALLOWED", TRUE);
# Standalone Server, port number; default 8888
define("BAIKAL_STANDALONE_PORT", 8888);
# Baïkal Web interface admin password hash; Set by Core/Scripts/adminpassword.php
define("BAIKAL_ADMIN_PASSWORDHASH", "5746d6eb0ff2968c494e5d904b8ef4b6");

Binary file not shown.