Working on web admin

Former-commit-id: 4cbea964b0
This commit is contained in:
Jérôme Schneider 2012-05-12 00:51:31 +02:00
parent b4c20d42d1
commit e1ce562880
5 changed files with 0 additions and 445 deletions

View file

@ -1,88 +0,0 @@
#!/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);
# Bootstraping Baikal
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/Core/Frameworks/Baikal/Core/Bootstrap.php"); # ../../../
$pdo = $GLOBALS["DB"]->getPDO();
$sUsername = @trim($argv[1]);
if($sUsername === "") {
die("You have to provide a username; aborting.\n");
}
$stmt = $pdo->prepare("SELECT * FROM users WHERE username=?");
$stmt->bindParam(1, $sUsername);
$stmt->execute();
if(($user = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST)) === FALSE) {
die("User not found; aborting.\n");
}
$sCalendarID = \Baikal\Core\Tools::bashPrompt("Calendar Key (a unique, lower-case, alphanum token, like 'perso' or 'sailing'): ");
if($sCalendarID === "") {
die("Calendar Key cannot be empty.\n");
}
$sCalendarID = strtolower($sCalendarID);
if(!preg_match("/[a-zA-Z0-9]+/", $sCalendarID)) {
die("Calendar Key should contain only letters and numbers.\n");
}
# Fetching calendar
$sPrincipalUri = 'principals/' . $sUsername;
$stmt = $pdo->prepare("SELECT * FROM calendars where LOWER(principaluri)=LOWER(?) AND LOWER(uri)=LOWER(?)");
$stmt->bindParam(1, $sPrincipalUri);
$stmt->bindParam(2, $sCalendarID);
$stmt->execute();
if(($cal = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST)) !== FALSE) {
die("This Calendar Key is already in use for this user; aborting.\n");
}
$sCalendarName = \Baikal\Core\Tools::bashPrompt("Calendar Display Name: ");
if($sCalendarName === "") {
die("Calendar Display Name cannot be empty.\n");
}
try {
$stmt = $pdo->prepare("INSERT INTO calendars (principaluri, displayname, uri, description, components, ctag) VALUES (?,?,?,'','VEVENT,VTODO','1')");
$stmt->bindParam(1, $sPrincipalUri);
$stmt->bindParam(2, $sCalendarName);
$stmt->bindParam(3, $sCalendarID);
$stmt->execute();
echo "Calendar has been added.\n";
exit(0);
} catch(PDOException $e) {
echo "Fatal error. Calendar has not been added. Details follow.\n";
die($e->getMessage());
}

View file

@ -1,103 +0,0 @@
#!/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);
# Bootstraping Baikal
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/Core/Frameworks/Baikal/Core/Bootstrap.php"); # ../../../
$pdo = $GLOBALS["DB"]->getPDO();
$sUsername = @trim($argv[1]);
if($sUsername === "") {
die("You have to provide a username; aborting.\n");
}
$sPassword = \Baikal\Core\Tools::bashPromptSilent("Password: ");
$sPasswordConfirm = \Baikal\Core\Tools::bashPromptSilent("Confirm password: ");
if($sPassword === "") {
die("Password cannot be empty.\n");
}
if($sPassword !== $sPasswordConfirm) {
die("Passwords don't match; aborting.\n");
}
$sHash = md5($sUsername . ':' . BAIKAL_AUTH_REALM . ':' . $sPassword);
$sEmail = \Baikal\Core\Tools::bashPrompt("Email: ");
$sDisplayName = \Baikal\Core\Tools::bashPrompt("Display name: ");
try {
$stmt = $pdo->prepare("INSERT INTO users (username, digesta1) VALUES (?, ?)");
$stmt->bindParam(1, $sUsername);
$stmt->bindParam(2, $sHash);
$stmt->execute();
$sPath = 'principals/' . $sUsername;
$stmt = $pdo->prepare("INSERT INTO calendars (principaluri, displayname, uri, description, components, ctag) VALUES (?,'default calendar','default','','VEVENT,VTODO','1')");
$stmt->bindParam(1, $sPath);
$stmt->execute();
# INSERT INTO principals (uri,email,displayname) VALUES ('principals/admin', 'admin@example.org','Adminstrator');
$sPath = 'principals/' . $sUsername;
$stmt = $pdo->prepare("INSERT INTO principals (uri,email,displayname) VALUES (?, ?, ?)");
$stmt->bindParam(1, $sPath);
$stmt->bindParam(2, $sEmail);
$stmt->bindParam(3, $sDisplayName);
$stmt->execute();
# INSERT INTO principals (uri,email,displayname) VALUES ('principals/admin/calendar-proxy-read', null, null);
$sPath = 'principals/' . $sUsername . "/calendar-proxy-read";
$mNull = null;
$stmt->bindParam(1, $sPath);
$stmt->bindParam(2, $mNull);
$stmt->bindParam(3, $mNull);
$stmt->execute();
# INSERT INTO principals (uri,email,displayname) VALUES ('principals/admin/calendar-proxy-write', null, null);
$sPath = 'principals/' . $sUsername . "/calendar-proxy-write";
$stmt->bindParam(1, $sPath);
$stmt->bindParam(2, $mNull);
$stmt->bindParam(3, $mNull);
$stmt->execute();
# INSERT INTO addressbooks (principaluri, displayname, uri, description, ctag) VALUES ('principals/admin','default calendar','default','','1');
$sPath = 'principals/' . $sUsername;
$stmt = $pdo->prepare("INSERT INTO addressbooks (principaluri, displayname, uri, description, ctag) VALUES (?,'default addressbook','default','','1')");
$stmt->bindParam(1, $sPath);
$stmt->execute();
echo "User has been added.\n";
exit(0);
} catch(PDOException $e) {
echo "Fatal error. User has not been added. Details follow.\n";
die($e->getMessage());
}

View file

@ -1,78 +0,0 @@
#!/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);
# Bootstraping Baikal
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/Core/Frameworks/Baikal/Core/Bootstrap.php"); # ../../../
# Bootstraping BaikalAdmin
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/Core/Frameworks/BaikalAdmin/Core/Bootstrap.php"); # ../../../
$sConfigFile = PROJECT_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 = \Baikal\Core\Tools::bashPromptSilent("New admin password: ");
$sPasswordConfirm = \Baikal\Core\Tools::bashPromptSilent("Confirm new admin password: ");
if($sPassword === "") {
die("Password cannot be empty.\n");
}
if($sPassword !== $sPasswordConfirm) {
die("Passwords don't match; aborting.\n");
}
$sHash = \BaikalAdmin\Core\Auth::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

@ -1,69 +0,0 @@
#!/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);
# Bootstraping Baikal
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/Core/Frameworks/Baikal/Core/Bootstrap.php"); # ../../../
$pdo = $GLOBALS["DB"]->getPDO();
$sUsername = @trim($argv[1]);
if($sUsername === "") {
die("You have to provide a username; aborting.\n");
}
$stmt = $pdo->prepare("SELECT * FROM users WHERE username=?");
$stmt->bindParam(1, $sUsername);
$stmt->execute();
if(($user = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST)) === FALSE) {
die("User not found; aborting.\n");
}
$sCalendarID = \Baikal\Core\Tools::bashPrompt("Calendar Key: ");
if($sCalendarID === "") {
die("Calendar Key cannot be empty.\n");
}
$sCalendarID = strtolower($sCalendarID);
if(!preg_match("/[a-zA-Z0-9]+/", $sCalendarID)) {
die("Calendar Key should contain only letters and numbers.\n");
}
# Fetching calendar
$sPrincipalUri = 'principals/' . $sUsername;
$stmt = $pdo->prepare("SELECT * FROM calendars where LOWER(principaluri)=LOWER(?) AND LOWER(uri)=LOWER(?)");
$stmt->bindParam(1, $sPrincipalUri);
$stmt->bindParam(2, $sCalendarID);
$stmt->execute();
if(($cal = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST)) === FALSE) {
die("This Calendar Key is not found for this user; aborting.\n");
}
echo "Found calendar '" . $sCalendarID . "' for user '" . $sUsername . "':\n";

View file

@ -1,107 +0,0 @@
#!/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);
# Bootstraping Baikal
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/Core/Frameworks/Baikal/Core/Bootstrap.php"); # ../../../
$pdo = $GLOBALS["DB"]->getPDO();
$sUsername = isset($argv[1]) ? trim($argv[1]) : "";
if($sUsername === "") {
die("You have to provide a username; aborting.\n");
}
# Fetching user
$stmt = $pdo->prepare("SELECT * FROM users WHERE username=?");
$stmt->bindParam(1, $sUsername);
$stmt->execute();
if(($user = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST)) === FALSE) {
die("User not found; aborting.\n");
}
# Fetching principal
$sUri = "principals/" . $sUsername;
$stmt = $pdo->prepare("SELECT * FROM principals WHERE uri=?");
$stmt->bindParam(1, $sUri);
$stmt->execute();
if(($principal = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST)) === FALSE) {
die("Principal not found for user; aborting.\n");
}
echo "--User found--\nid:\t\t" . $user["id"] . "\nemail:\t\t" . $principal["email"] . "\ndisplayname:\t" . $principal["displayname"] . "\n";
echo "\n--Please enter new values--\n";
$sPassword = \Baikal\Core\Tools::bashPromptSilent("Password (empty to leave untouched): ");
$sHash = "";
$sEmail = "";
$sDisplayName = "";
if($sPassword !== "") {
$sPasswordConfirm = \Baikal\Core\Tools::bashPromptSilent("Confirm password: ");
if($sPassword !== $sPasswordConfirm) {
die("Passwords don't match; aborting.\n");
}
$sHash = md5($sUsername . ':' . BAIKAL_AUTH_REALM . ':' . $sPassword);
}
$sEmail = \Baikal\Core\Tools::bashPrompt("Email (empty to leave untouched): ");
$sDisplayName = \Baikal\Core\Tools::bashPrompt("Display name (empty to leave untouched): ");
if($sHash === "" && $sEmail === "" && $sDisplayName === "") {
echo ("\nNothing to do. User is left untouched.\n");
exit(0);
}
if($sHash !== "") {
$stmt = $pdo->prepare("UPDATE users set digesta1=? WHERE id=?");
$stmt->bindParam(1, $sHash);
$stmt->bindParam(2, $user["id"]);
$stmt->execute();
}
if($sEmail !== "") {
$stmt = $pdo->prepare("UPDATE principals set email=? WHERE id=?");
$stmt->bindParam(1, $sEmail);
$stmt->bindParam(2, $principal["id"]);
$stmt->execute();
}
if($sDisplayName !== "") {
$stmt = $pdo->prepare("UPDATE principals set displayname=? WHERE id=?");
$stmt->bindParam(1, $sDisplayName);
$stmt->bindParam(2, $principal["id"]);
$stmt->execute();
}
echo ("\nUser is updated.\n");
exit(0);