#!/usr/bin/env php * 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"); $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 = prompt_silent("Password (empty to leave untouched): "); $sHash = ""; $sEmail = ""; $sDisplayName = ""; if($sPassword !== "") { $sPasswordConfirm = prompt_silent("Confirm password: "); if($sPassword !== $sPasswordConfirm) { die("Passwords don't match; aborting.\n"); } $sHash = md5($sUsername . ':' . BAIKAL_AUTH_REALM . ':' . $sPassword); } $sEmail = prompt("Email (empty to leave untouched): "); $sDisplayName = prompt("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);