diff --git a/CoreVersions/0.2.0/Frameworks/Baikal/Core/Tools.php b/CoreVersions/0.2.0/Frameworks/Baikal/Core/Tools.php index 096602b..4a778d6 100755 --- a/CoreVersions/0.2.0/Frameworks/Baikal/Core/Tools.php +++ b/CoreVersions/0.2.0/Frameworks/Baikal/Core/Tools.php @@ -53,8 +53,8 @@ class Tools { ini_set("error_reporting", E_ALL); } - function handleException($exception) { - echo $exception; + public static function handleException($exception) { + echo "
" . $exception . "
";
 	}
 	
 	public static function assertBaikalIsOk() {
diff --git a/CoreVersions/0.2.0/Frameworks/Baikal/Framework.php b/CoreVersions/0.2.0/Frameworks/Baikal/Framework.php
index 5959680..c4a5fad 100755
--- a/CoreVersions/0.2.0/Frameworks/Baikal/Framework.php
+++ b/CoreVersions/0.2.0/Frameworks/Baikal/Framework.php
@@ -30,8 +30,10 @@ class Framework extends \Flake\Core\Framework {
 	
 	public static function installTool() {	
 		if(defined("BAIKAL_CONTEXT_INSTALL") && BAIKAL_CONTEXT_INSTALL === TRUE) {
+			# Install tool has been launched and we're already on the install page
 			return;
 		} else {
+			# Install tool has been launched; redirecting user
 			$sInstallToolUrl = PROJECT_URI . "admin/install/";
 			header("Location: " . $sInstallToolUrl);
 			exit(0);
@@ -79,9 +81,7 @@ class Framework extends \Flake\Core\Framework {
 					\Baikal\Core\Tools::assertBaikalIsOk();
 
 					set_error_handler("\Baikal\Framework::exception_error_handler");
-
-					unset($bShouldCheckEnv);
-
+					
 					# SabreDAV Autoloader 
 					require_once(BAIKAL_PATH_SABREDAV . 'autoload.php');
 				}
@@ -91,7 +91,7 @@ class Framework extends \Flake\Core\Framework {
 	}
 	
 	# Mapping PHP errors to exceptions; needed by SabreDAV
-	function exception_error_handler($errno, $errstr, $errfile, $errline) {
+	public static function exception_error_handler($errno, $errstr, $errfile, $errline) {
 		throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
 	}
 }
\ No newline at end of file
diff --git a/CoreVersions/0.2.0/Frameworks/Baikal/Model/Config/Standard.php b/CoreVersions/0.2.0/Frameworks/Baikal/Model/Config/Standard.php
index 8b91cf5..f1058ff 100755
--- a/CoreVersions/0.2.0/Frameworks/Baikal/Model/Config/Standard.php
+++ b/CoreVersions/0.2.0/Frameworks/Baikal/Model/Config/Standard.php
@@ -32,13 +32,13 @@ class Standard extends \Baikal\Model\Config {
 		"BAIKAL_TIMEZONE" => array(
 			"type" => "string",
 		),
-		"BAIKAL_CARD_ENABLED" => array(
+		"BAIKAL_ADMIN_ENABLED" => array(
 			"type" => "boolean",
 		),
 		"BAIKAL_CAL_ENABLED" => array(
 			"type" => "boolean",
 		),
-		"BAIKAL_ADMIN_ENABLED" => array(
+		"BAIKAL_CARD_ENABLED" => array(
 			"type" => "boolean",
 		),
 		"BAIKAL_ADMIN_PASSWORDHASH" => array(
@@ -69,8 +69,12 @@ class Standard extends \Baikal\Model\Config {
 		)));
 		
 		$oMorpho->add(new \Formal\Element\Checkbox(array(
-			"prop" => "BAIKAL_CARD_ENABLED",
-			"label" => "Enable CardDAV"
+			"prop" => "BAIKAL_ADMIN_ENABLED",
+			"label" => "Enable Web Admin",
+			"popover" => array(
+				"title" => "Warning !",
+				"content" => "If disabled, you'll lose access to this very admin interface !",
+			),
 		)));
 		
 		$oMorpho->add(new \Formal\Element\Checkbox(array(
@@ -79,12 +83,8 @@ class Standard extends \Baikal\Model\Config {
 		)));
 		
 		$oMorpho->add(new \Formal\Element\Checkbox(array(
-			"prop" => "BAIKAL_ADMIN_ENABLED",
-			"label" => "Enable Web Admin",
-			"popover" => array(
-				"title" => "Warning !",
-				"content" => "If disabled, you'll lose access to this very admin interface !",
-			),
+			"prop" => "BAIKAL_CARD_ENABLED",
+			"label" => "Enable CardDAV"
 		)));
 		
 		$oMorpho->add(new \Formal\Element\Password(array(
diff --git a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Dashboard.php b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Dashboard.php
index 9a42c37..b21807c 100755
--- a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Dashboard.php
+++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Dashboard.php
@@ -32,17 +32,47 @@ class Dashboard extends \Flake\Core\Controller {
 	}
 	
 	public function render() {
-		$sLinkUsers = \BaikalAdmin\Controller\Users::link();
+		$oView = new \BaikalAdmin\View\Dashboard();
+		$oView->setData("BAIKAL_VERSION", BAIKAL_VERSION);
 		
-		$sMessage =<<
-* Nombre d'utilisateurs
-* Nombre de calendriers
-* Nombre d'évènements
-* Version + Mise à jour de baikal
-* Lien vers liste des utilisateurs
-* Lien vers paramétrage
-MESSAGE; - return $sMessage; + # Services status + $oView->setData("BAIKAL_CAL_ENABLED", BAIKAL_CAL_ENABLED); + $oView->setData("BAIKAL_CARD_ENABLED", BAIKAL_CARD_ENABLED); + + # Statistics: Users + $iNbUsers = \Baikal\Model\User::getBaseRequester()->count(); + $oView->setData("nbusers", $iNbUsers); + + # Statistics: CalDAV + $iNbCalendars = \Baikal\Model\Calendar::getBaseRequester()->count(); + $oView->setData("nbcalendars", $iNbCalendars); + + $iNbEvents = \Baikal\Model\Calendar\Event::getBaseRequester()->count(); + $oView->setData("nbevents", $iNbEvents); + + if($iNbCalendars > 0) { + $fEventsPerCalendarAvg = $iNbEvents / $iNbCalendars; + } else { + $fEventsPerCalendarAvg = 0; + } + + $oView->setData("eventspercalendaravg", $fEventsPerCalendarAvg); + + # Statistics: CardDAV + $iNbBooks = \Baikal\Model\AddressBook::getBaseRequester()->count(); + $oView->setData("nbbooks", $iNbBooks); + + $iNbContacts = \Baikal\Model\AddressBook\Contact::getBaseRequester()->count(); + $oView->setData("nbcontacts", $iNbEvents); + + if($iNbBooks > 0) { + $fContactsPerBookAvg = $iNbContacts / $iNbBooks; + } else { + $fContactsPerBookAvg = 0; + } + + $oView->setData("contactsperbookavg", $fContactsPerBookAvg); + + return $oView->render(); } } \ No newline at end of file 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 2dc0192..29e33ec 100755 --- a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/Initialize.php +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/Initialize.php @@ -79,7 +79,7 @@ PHP; } public function render() { - $sBigIcon = \BaikalAdmin\Model\Install::bigicon(); + $sBigIcon = "glyph2x-magic"; $sBaikalVersion = BAIKAL_VERSION; $sHtml = << HTML; -/* $sHtml .= <<What is this ? -

- This is the Baïkal Install Tool.
- It's displayed because you just installed or upgraded your Baïkal installation.
- Baïkal requires some maintenance in order to ensure everything works as expected. -

-HTML; -*/ return $sHtml; } } \ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/AdminPassword.php b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Login.php similarity index 52% rename from CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/AdminPassword.php rename to CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Login.php index ef2a39a..f0a60c4 100755 --- a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Install/AdminPassword.php +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Login.php @@ -24,48 +24,48 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ -namespace BaikalAdmin\Controller\Install; +namespace BaikalAdmin\Controller; -class AdminPassword 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(); - } - }*/ +class Login extends \Flake\Core\Controller { public function execute() { } - + public function render() { - $sBigIcon = \BaikalAdmin\Model\Install::bigicon(); - $sBaikalVersion = BAIKAL_VERSION; + $sActionUrl = \Flake\Util\Tools::getCurrentUrl(); + $sSubmittedFlagName = "auth"; + $sLogin = htmlspecialchars(\Flake\Util\Tools::POST("login")); + $sPassword = htmlspecialchars(\Flake\Util\Tools::POST("password")); + if(trim($sLogin) === "") { + $sLogin = "admin"; + } + + $sForm =<<
-

Baïkal maintainance wizard

-

Maintaining Baïkal {$sBaikalVersion}

+

Authentication

+

Please authenticate to access Baïkal Web Admin.

-HTML; - $sHtml .= <<You have to set a password for the admin user.

-HTML; + + +
+

+ + +

- return $sHtml; +

+ + +

+ +
+ +
+
+
+FORM; + return $sForm; } } \ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Navigation/Topbar.php b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Navigation/Topbar.php index 17744df..1ab1b08 100755 --- a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Navigation/Topbar.php +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Navigation/Topbar.php @@ -73,7 +73,7 @@ class Topbar extends \Flake\Core\Controller { Baïkal Web Admin +HTML; + return $sHtml; } } \ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Settings/Standard.php b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Settings/Standard.php index c6271d1..4c04e69 100755 --- a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Settings/Standard.php +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Settings/Standard.php @@ -49,6 +49,12 @@ class Standard extends \Flake\Core\Controller { } public function render() { - return $this->oForm->render(); + + $sHeader =<<
+

Baïkal settings

+ +FORM; + return $sHeader . $this->oForm->render(); } } \ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Settings/System.php b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Settings/System.php index dd0f887..4c91955 100755 --- a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Settings/System.php +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Controller/Settings/System.php @@ -49,11 +49,18 @@ class System extends \Flake\Core\Controller { } public function render() { + + $sHeader =<< +

Baïkal system settings

+ +FORM; + $sMessage = \Formal\Core\Message::notice( "Do not change anything on this page unless you really know what you are doing.
You might break Baïkal if you misconfigure something here.", "Warning !", FALSE ); - return $sMessage . $this->oForm->render(); + return $sHeader . $sMessage . $this->oForm->render(); } } \ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Core/Auth.php b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Core/Auth.php index e23d88e..bc6facc 100755 --- a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Core/Auth.php +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Core/Auth.php @@ -27,7 +27,7 @@ namespace BaikalAdmin\Core; class Auth { - static function assertEnabled() { + public static function assertEnabled() { if(!defined("BAIKAL_ADMIN_ENABLED") || BAIKAL_ADMIN_ENABLED !== TRUE) { die("

Baïkal Admin is disabled.

To enable it, set BAIKAL_ADMIN_ENABLED to TRUE in Specific/config.php"); } @@ -35,7 +35,7 @@ class Auth { self::assertUnlocked(); } - static function assertUnlocked() { + public static function assertUnlocked() { if(defined("BAIKAL_CONTEXT_INSTALL") && BAIKAL_CONTEXT_INSTALL === TRUE) { $sToolName = "Baïkal Install Tool"; @@ -68,41 +68,30 @@ class Auth { die("

" . $sToolName . " is locked.

To unlock it, create an empty file named ENABLE_ADMIN in Specific/"); } } - - static function assertAuthentified() { - if(!self::isAuthentified()) { - header(utf8_decode('WWW-Authenticate: Basic realm="Baïkal admin"')); - header('HTTP/1.0 401 Unauthorized'); - die("Please authenticate."); + + public static function isAuthenticated() { + if(isset($_SESSION["baikaladminauth"]) && $_SESSION["baikaladminauth"] === md5(BAIKAL_ADMIN_PASSWORDHASH)) { + return TRUE; } - - return TRUE; - } - - static function isAuthentified() { - - if(array_key_exists("PHP_AUTH_USER", $_SERVER)) { - $sUser = $_SERVER["PHP_AUTH_USER"]; - } else { - $sUser = FALSE; + + if(intval(\Flake\Util\Tools::POST("auth")) !== 1) { + return FALSE; } - - if(array_key_exists("PHP_AUTH_PW", $_SERVER)) { - $sPass = $_SERVER["PHP_AUTH_PW"]; - } else { - $sPass = FALSE; - } - + + $sUser = \Flake\Util\Tools::POST("login"); + $sPass = \Flake\Util\Tools::POST("password"); + $sPassHash = self::hashAdminPassword($sPass); - + if($sUser === "admin" && $sPassHash === BAIKAL_ADMIN_PASSWORDHASH) { + $_SESSION["baikaladminauth"] = md5(BAIKAL_ADMIN_PASSWORDHASH); return TRUE; } return FALSE; } - static function hashAdminPassword($sPassword) { + public static function hashAdminPassword($sPassword) { return md5('admin:' . BAIKAL_AUTH_REALM . ':' . $sPassword); } } \ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html new file mode 100755 index 0000000..4acbb08 --- /dev/null +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/Resources/Templates/Dashboard.html @@ -0,0 +1,119 @@ +
+

Dashboard

+
+ +
+ +
+
+

Version

+

This systems runs Baïkal

+
+
+

Services

+ + + + + + + + + + + + + + + + +
Web adminOn

CalDAV
CardDAV
+
+
+

License and credits

+ +

Baïkal is open source software, and released under the terms of the GNU GPL v3.

+

Baïkal is developped by Jérôme Schneider. You can contact him at mail@jeromeschneider.fr.

+

Baïkal is based upon other open source projects. Read the README.md file to learn about that.

+

+
+
+
+ +
+ +
+
+

Users

+ + + + + + + +
Registered users
+
+
+

CalDAV

+ + + + + + + + + + + + + + + +
Number of calendars
Number of events
Events per calendar avg.
+
+
+

CardDAV

+ + + + + + + + + + + + + + + +
Number of address books
Number of contacts
Contacts per book avg.
+
+
+
\ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/View/Dashboard.php b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/View/Dashboard.php new file mode 100755 index 0000000..790bbbb --- /dev/null +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/View/Dashboard.php @@ -0,0 +1,31 @@ + +* 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\View; + +class Dashboard extends \BaikalAdmin\Core\View { + +} \ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/WWWRoot/index.php b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/WWWRoot/index.php index e099170..460212e 100755 --- a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/WWWRoot/index.php +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/WWWRoot/index.php @@ -37,9 +37,8 @@ require_once(dirname(dirname(dirname(__FILE__))) . "/Flake/Core/Bootstrap.php"); # Bootstrap BaikalAdmin \BaikalAdmin\Framework::bootstrap(); -# Evaluate assertions +# Assert that BaikalAdmin is enabled \BaikalAdmin\Core\Auth::assertEnabled(); -\BaikalAdmin\Core\Auth::assertAuthentified(); # Create and setup a page object $oPage = new \Flake\Controller\Page(BAIKALADMIN_PATH_TEMPLATES . "Page/index.html"); @@ -47,10 +46,16 @@ $oPage->injectHTTPHeaders(); $oPage->setTitle("Baïkal Web Admin"); $oPage->setBaseUrl(PROJECT_URI); -$oPage->zone("navbar")->addBlock(new \BaikalAdmin\Controller\Navigation\Topbar()); +# Authentication +if(\BaikalAdmin\Core\Auth::isAuthenticated() === FALSE) { + $oPage->zone("navbar")->addBlock(new \BaikalAdmin\Controller\Navigation\Topbar\Anonymous()); + $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Login()); +} else { + $oPage->zone("navbar")->addBlock(new \BaikalAdmin\Controller\Navigation\Topbar()); -# Route the request -$GLOBALS["ROUTER"]::route($oPage); + # Route the request + $GLOBALS["ROUTER"]::route($oPage); +} # Render the page echo $oPage->render(); \ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/WWWRoot/install/index.php b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/WWWRoot/install/index.php index a610846..12c5a81 100755 --- a/CoreVersions/0.2.0/Frameworks/BaikalAdmin/WWWRoot/install/index.php +++ b/CoreVersions/0.2.0/Frameworks/BaikalAdmin/WWWRoot/install/index.php @@ -54,8 +54,7 @@ if(!defined("BAIKAL_CONFIGURED_VERSION")) { } elseif(!defined("BAIKAL_ADMIN_PASSWORDHASH")) { # we have to set an admin password - $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\AdminPassword()); - + $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Initialize()); } else { # we have to initialize Baïkal (new installation) $oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\VersionUpgrade()); diff --git a/CoreVersions/0.2.0/Frameworks/Flake/Core/Requester.php b/CoreVersions/0.2.0/Frameworks/Flake/Core/Requester.php index a4416cb..7cdeb5c 100755 --- a/CoreVersions/0.2.0/Frameworks/Flake/Core/Requester.php +++ b/CoreVersions/0.2.0/Frameworks/Flake/Core/Requester.php @@ -45,4 +45,5 @@ abstract class Requester extends \Flake\Core\FLObject { } public abstract function execute(); + public abstract function count(); } \ No newline at end of file diff --git a/CoreVersions/0.2.0/Frameworks/Flake/Core/Requester/Sql.php b/CoreVersions/0.2.0/Frameworks/Flake/Core/Requester/Sql.php index 769f95c..62e5ffc 100755 --- a/CoreVersions/0.2.0/Frameworks/Flake/Core/Requester/Sql.php +++ b/CoreVersions/0.2.0/Frameworks/Flake/Core/Requester/Sql.php @@ -170,7 +170,7 @@ class Sql extends \Flake\Core\FLObject { return $this->bHasBeenExecuted; } - public function getQuery() { + public function getQuery($sFields = "*") { $sWhere = "1=1"; $sOrderBy = ""; $sLimit = ""; @@ -194,7 +194,7 @@ class Sql extends \Flake\Core\FLObject { } return $GLOBALS["DB"]->SELECTquery( - "*", + $sFields, $this->sDataTable, $sWhere, "", @@ -202,6 +202,10 @@ class Sql extends \Flake\Core\FLObject { $sLimit ); } + + public function getCountQuery() { + return $this->getQuery("count(*) as nbitems"); + } public function execute() { $oCollection = new \Flake\Core\CollectionTyped($this->sModelClass); @@ -218,4 +222,15 @@ class Sql extends \Flake\Core\FLObject { return $oCollection; } + + public function count() { + $sSql = $this->getCountQuery(); + + $rSql = $GLOBALS["DB"]->query($sSql); + if(($aRs = $rSql->fetch()) !== FALSE) { + return intval($aRs["nbitems"]); + } + + return 0; + } } \ No newline at end of file diff --git a/Specific/db/baikal.sqlite b/Specific/db/baikal.sqlite index a272785..169db6b 100755 Binary files a/Specific/db/baikal.sqlite and b/Specific/db/baikal.sqlite differ