Working on admin interface, as well as Mongoose structure

This commit is contained in:
Jérôme Schneider 2012-03-22 13:49:38 +01:00
parent f878518332
commit 81bb092842
8 changed files with 160 additions and 55 deletions

View file

@ -1,56 +1,50 @@
#!/usr/bin/env bash
PATH_scriptfile=`readlink -f $0`
PATH_scriptdir=`dirname $PATH_scriptfile`"/"
PATH_root=`dirname $(dirname $(dirname $PATH_scriptdir))`"/"
PATH_docroot=$PATH_root"html/"
PATH_SCRIPTFILE=`readlink -f $0`
PATH_SCRIPTDIR=`dirname $PATH_SCRIPTFILE`"/"
PATH_ROOT=`dirname $(dirname $(dirname $PATH_SCRIPTDIR))`"/"
PATH_DOCROOT=$PATH_ROOT"html/"
PATH_specific=$PATH_root"Specific/"
PATH_configfile=$PATH_specific"config.php"
PATH_SPECIFIC=$PATH_ROOT"Specific/"
PATH_CONFIGFILE=$PATH_SPECIFIC"config.php"
MONGOOSE_builds=$PATH_scriptdir"builds/"
MONGOOSE_cgi=$PATH_scriptdir"cgi/"
MONGOOSE_BUILDS=$PATH_SCRIPTDIR"builds/"
MONGOOSE_CGI=$PATH_SCRIPTDIR"cgi/"
function whichPlatform() {
local platform='unknown'
local unamestr=`uname`
function whichOS() {
echo $(uname -s)
}
if [[ "$unamestr" == 'Linux' ]]; then
platform='linux'
elif [[ "$unamestr" == 'FreeBSD' ]]; then
platform='freebsd'
elif [[ "$unamestr" == 'Darwin' ]]; then
platform='osx'
fi
function whichARCH() {
echo $(uname -m)
}
echo "$platform"
function toLowerCase() {
echo $(echo "$1"|tr '[A-Z]' '[a-z]')
}
function whichBINDIST() {
local OS=$(whichOS);
local ARCH=$(whichARCH);
echo $(toLowerCase "$OS""/""$ARCH")
}
function getBaikalConf() {
local conf=$(php -r "require_once('$PATH_configfile'); if(is_bool($1)) { echo intval($1);} else { echo $1;}")
echo $conf
local CONF=$(php -r "require_once('$PATH_CONFIGFILE'); if(is_bool($1)) { echo intval($1);} else { echo $1;}")
echo "$CONF"
}
BAIKAL_standaloneenabled=$(getBaikalConf BAIKAL_STANDALONE_ENABLED)
if [[ "$BAIKAL_standaloneenabled" == '0' ]]; then
BAIKAL_STANDALONE_ALLOWED=$(getBaikalConf BAIKAL_STANDALONE_ALLOWED)
if [[ "$BAIKAL_STANDALONE_ALLOWED" == '0' ]]; then
echo "Baïkal Standalone Server is disabled by config."
exit 0
fi
BAIKAL_standaloneport=$(getBaikalConf BAIKAL_STANDALONE_PORT)
BAIKAL_baseuri=$(getBaikalConf BAIKAL_BASEURI)
BAIKAL_STANDALONE_PORT=$(getBaikalConf BAIKAL_STANDALONE_PORT)
MONGOOSE_BINDIST=$(whichBINDIST)
echo "Serving standalone Baïkal on port $BAIKAL_STANDALONE_PORT ('$PATH_DOCROOT' on $MONGOOSE_BINDIST)"
platform=$(whichPlatform)
echo "Serving standalone Baïkal at $BAIKAL_baseuri:$BAIKAL_standaloneport ('$PATH_docroot' on $platform )"
MONGOOSE_BIN="$MONGOOSE_BUILDS""$MONGOOSE_BINDIST""/mongoose"
MONGOOSE_CGIBIN="$MONGOOSE_CGI""$MONGOOSE_BINDIST""/php-cgi"
if [[ $platform == 'linux' ]]; then
MONGOOSE_bin=$MONGOOSE_builds"ubuntux64/mongoose"
MONGOOSE_cgibin=$MONGOOSE_cgi"ubuntux64/php-cgi"
elif [[ $platform == 'freebsd' ]]; then
echo "FreeBSD !"
elif [[ $platform == 'osx' ]]; then
MONGOOSE_bin=$MONGOOSE_builds"mac/mongoose"
MONGOOSE_cgibin=$MONGOOSE_cgi"mac/php-cgi"
fi
`$MONGOOSE_bin -p $BAIKAL_standaloneport -I $MONGOOSE_cgibin -i index.html,index.php -r $PATH_docroot`
`$MONGOOSE_BIN -d no -p $BAIKAL_STANDALONE_PORT -I $MONGOOSE_CGIBIN -i index.html,index.php -r $PATH_DOCROOT`

View file

@ -0,0 +1,76 @@
#!/usr/bin/env php
<?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!
***************************************************************/
define("BAIKAL_CONTEXT", TRUE);
define("BAIKAL_CONTEXT_CLI", TRUE);
require_once("../Bootstrap.php");
require_once("./inc/functions.php");
require_once(BAIKAL_PATH_WWWROOT . "classes/BaikalAdmin.php");
$sConfigFile = BAIKAL_PATH_SPECIFIC . "config.php";
if(!file_exists($sConfigFile)) {
die("Specific/config.php is does not exist. Aborting, cannot modify admin password.");
}
if(!is_writable($sConfigFile)) {
die("Specific/config.php is not writable. Aborting, cannot modify admin password.");
}
$bFound = FALSE;
if(!defined("BAIKAL_ADMIN_PASSWORDHASH")) {
echo "-- Info: There's currently no admin password set. --\n";
} else {
echo "-- Info: The current admin password hash is '" . BAIKAL_ADMIN_PASSWORDHASH . "'. --\n";
$bFound = TRUE;
}
$sPassword = prompt_silent("New admin password: ");
$sPasswordConfirm = prompt_silent("Confirm new admin password: ");
if($sPassword === "") {
die("Password cannot be empty.\n");
}
if($sPassword !== $sPasswordConfirm) {
die("Passwords don't match; aborting.\n");
}
$sHash = BaikalAdmin::hashAdminPassword($sPassword);
echo ("\nNew password hash:" . $sHash . "\n");
$sFileContents = file_get_contents($sConfigFile);
if($bFound === FALSE) {
$sFileContents .= "\n\n# Baïkal Web interface admin password hash; Set by Core/Scripts/adminpassword.php\ndefine(\"BAIKAL_ADMIN_PASSWORDHASH\", \"" . $sHash . "\");\n";
} else {
die("TODO: implement update using regex");
}
file_put_contents($sConfigFile, $sFileContents);

View file

@ -33,6 +33,7 @@ require_once(BAIKAL_PATH_WWWROOT . "classes/BaikalAdmin.php");
require_once(BAIKAL_PATH_WWWROOT . "classes/BaikalTools.php");
BaikalAdmin::assertEnabled();
BaikalAdmin::assertAuthentified();
echo "<h1>Ba&iuml;kal Admin</h1>";

View file

@ -59,6 +59,43 @@ class BaikalAdmin {
}
}
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.");
}
return TRUE;
}
static function isAuthentified() {
if(array_key_exists("PHP_AUTH_USER", $_SERVER)) {
$sUser = $_SERVER["PHP_AUTH_USER"];
} else {
$sUser = FALSE;
}
if(array_key_exists("PHP_AUTH_PW", $_SERVER)) {
$sPass = $_SERVER["PHP_AUTH_PW"];
} else {
$sPass = FALSE;
}
$sPassHash = self::hashAdminPassword($sPass);
if($sUser === "admin" && $sPassHash === BAIKAL_ADMIN_PASSWORDHASH) {
return TRUE;
}
return FALSE;
}
static function hashAdminPassword($sPassword) {
return md5('admin:' . BAIKAL_AUTH_REALM . ':' . $sPassword);
}
static function displayUsers() {
$aUsers = BaikalTools::getUsers();

View file

@ -32,10 +32,10 @@
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title><?= BAIKAL_BASEURI ?></title>
<title>Baïkal Server</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
</head>
<body>
<h2>Baïkal on <?= BAIKAL_BASEURI ?></h2>
<h2>Baïkal is running allright.</h2>
</body>
</html>

View file

@ -8,24 +8,21 @@
# Timezone of your users, if unsure, check http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
define("BAIKAL_TIMEZONE", "Europe/Paris");
# WEB absolute URI
define("BAIKAL_BASEURI", "http://dav.mydomain.com/");
# WEB absolute URI
define("BAIKAL_ADMIN_ENABLED", TRUE);
##############################################################################
# In this section: Optional configuration: you *may* customize these settings
#
# CardDAV ON/OFF switch
# CardDAV ON/OFF switch; default TRUE
define("BAIKAL_CARD_ENABLED", TRUE);
# CalDAV ON/OFF switch
# CalDAV ON/OFF switch; default TRUE
define("BAIKAL_CAL_ENABLED", TRUE);
# CalDAV ON/OFF switch
define("BAIKAL_STANDALONE_ENABLED", FALSE);
# Baïkal Web Admin interface ON/OFF; default FALSE
define("BAIKAL_ADMIN_ENABLED", FALSE);
# CalDAV ON/OFF switch
# Standalone Server, allowed or not; default FALSE
define("BAIKAL_STANDALONE_ALLOWED", FALSE);
# Standalone Server, port number; default 8888
define("BAIKAL_STANDALONE_PORT", 8888);