Merge pull request #979 from benbz/fix-legacy-migration

Fixes for migrating from legacy version
This commit is contained in:
H. Lehmann 2020-10-18 13:04:11 +02:00 committed by GitHub
commit ef80df9508
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 32 deletions

View file

@ -38,6 +38,8 @@ class Standard extends \Baikal\Model\Config {
"cal_enabled" => true,
"dav_auth_type" => "Digest",
"admin_passwordhash" => "",
// While not editable as will change admin & any existing user passwords,
// could be set to different value when migrating from legacy config
"auth_realm" => "BaikalDAV",
"base_uri" => ""
];
@ -119,7 +121,7 @@ class Standard extends \Baikal\Model\Config {
if ($sProp === "admin_passwordhash" && $sValue !== "") {
parent::set(
"admin_passwordhash",
\BaikalAdmin\Core\Auth::hashAdminPassword($sValue)
\BaikalAdmin\Core\Auth::hashAdminPassword($sValue, $this->aData["auth_realm"])
);
}

View file

@ -27,8 +27,6 @@
namespace BaikalAdmin\Controller\Install;
use Symfony\Component\Yaml\Yaml;
class Database extends \Flake\Core\Controller {
protected $aMessages = [];
protected $oModel;
@ -46,12 +44,6 @@ class Database extends \Flake\Core\Controller {
$this->oModel->set('mysql_username', PROJECT_DB_MYSQL_USERNAME);
$this->oModel->set('mysql_password', PROJECT_DB_MYSQL_PASSWORD);
$this->oModel->set('encryption_key', BAIKAL_ENCRYPTION_KEY);
if (defined("BAIKAL_CONFIGURED_VERSION")) {
$oStandardConfig = new \Baikal\Model\Config\Standard();
$oStandardConfig->set("configured_version", BAIKAL_CONFIGURED_VERSION);
$oStandardConfig->persist();
}
}
$this->oForm = $this->oModel->formForThisModelInstance([
@ -68,6 +60,18 @@ class Database extends \Flake\Core\Controller {
@unlink(PROJECT_PATH_SPECIFIC . "config.system.php");
}
touch(PROJECT_PATH_SPECIFIC . '/INSTALL_DISABLED');
if (defined("BAIKAL_CONFIGURED_VERSION")) {
$oStandardConfig = new \Baikal\Model\Config\Standard();
$oStandardConfig->set("configured_version", BAIKAL_CONFIGURED_VERSION);
$oStandardConfig->persist();
# We've just rolled back the configured version, so reload so that we get to the
# version upgrade page rather than the database is configured message in render below
$sLink = PROJECT_URI . "admin/install/?/database";
\Flake\Util\Tools::redirect($sLink);
exit(0);
}
}
}
}
@ -209,12 +213,8 @@ class Database extends \Flake\Core\Controller {
if ($oForm->submitted()) {
$bMySQL = (intval($oForm->postValue("mysql")) === 1);
} else {
try {
$configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
} catch (\Exception $e) {
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
}
$bMySQL = $configSystem['database']['mysql'] ?? true;
// oMorpho won't have the values from the model set on it yet
$bMySQL = $this->oModel->get("mysql");
}
if ($bMySQL === true) {

View file

@ -55,6 +55,10 @@ class Initialize extends \Flake\Core\Controller {
$this->oModel->set('invite_from', defined("BAIKAL_INVITE_FROM") ? BAIKAL_INVITE_FROM : "");
$this->oModel->set('dav_auth_type', BAIKAL_DAV_AUTH_TYPE);
}
if (file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) {
require_once PROJECT_PATH_SPECIFIC . "config.system.php";
$this->oModel->set('auth_realm', BAIKAL_AUTH_REALM);
}
$this->oForm = $this->oModel->formForThisModelInstance([
"close" => false

View file

@ -65,7 +65,7 @@ class VersionUpgrade extends \Flake\Core\Controller {
HTML;
try {
$bSuccess = $this->upgrade($config['system']['configured_version'], BAIKAL_VERSION);
$bSuccess = $this->upgrade($config['database'], $config['system']['configured_version'], BAIKAL_VERSION);
} catch (\Exception $e) {
$bSuccess = false;
$this->aErrors[] = 'Uncaught exception during upgrade: ' . (string) $e;
@ -88,7 +88,7 @@ HTML;
return $sHtml;
}
protected function upgrade($sVersionFrom, $sVersionTo) {
protected function upgrade($databaseConfig, $sVersionFrom, $sVersionTo) {
if (version_compare($sVersionFrom, '0.2.3', '<=')) {
throw new \Exception('This version of Baikal does not support upgrading from version 0.2.3 and older. Please request help on Github if this is a problem.');
}
@ -99,7 +99,7 @@ HTML;
if (version_compare($sVersionFrom, '0.3.0', '<')) {
// Upgrading from sabre/dav 1.8 schema to 3.1 schema.
if (defined("PROJECT_DB_MYSQL") && PROJECT_DB_MYSQL === true) {
if ($databaseConfig['mysql'] === true) {
// MySQL upgrade
// sabre/dav 2.0 changes
@ -313,7 +313,7 @@ HTML;
// The sqlite schema had issues with both the calendar and
// addressbooks tables. The tables didn't have a DEFAULT '1' for
// the synctoken column. So we're adding it now.
if (!defined("PROJECT_DB_MYSQL") || PROJECT_DB_MYSQL === false) {
if ($databaseConfig['mysql'] === false) {
$pdo->exec('UPDATE calendars SET synctoken = 1 WHERE synctoken IS NULL');
$tmpTable = '_' . time();
@ -343,7 +343,7 @@ CREATE TABLE calendars (
// Similar to upgrading from older than 0.4.5, there were still
// issues with a missing DEFAULT 1 for sthe synctoken field in the
// addressbook.
if (!defined("PROJECT_DB_MYSQL") || PROJECT_DB_MYSQL === false) {
if ($databaseConfig['mysql'] === false) {
$pdo->exec('UPDATE addressbooks SET synctoken = 1 WHERE synctoken IS NULL');
$tmpTable = '_' . time();
@ -365,7 +365,7 @@ CREATE TABLE addressbooks (
}
}
if (version_compare($sVersionFrom, '0.5.1', '<')) {
if (!defined("PROJECT_DB_MYSQL") || PROJECT_DB_MYSQL === false) {
if ($databaseConfig['mysql'] === false) {
$pdo->exec(<<<SQL
CREATE TABLE calendarinstances (
id integer primary key asc NOT NULL,

View file

@ -48,12 +48,14 @@ class Auth {
$sUser = \Flake\Util\Tools::POST("login");
$sPass = \Flake\Util\Tools::POST("password");
$sPassHash = self::hashAdminPassword($sPass);
try {
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
} catch (\Exception $e) {
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
return false;
}
$sPassHash = self::hashAdminPassword($sPass, $config['system']['auth_realm']);
if ($sUser === "admin" && $sPassHash === $config['system']['admin_passwordhash']) {
$_SESSION["baikaladminauth"] = md5($config['system']['admin_passwordhash']);
@ -67,16 +69,7 @@ class Auth {
unset($_SESSION["baikaladminauth"]);
}
static function hashAdminPassword($sPassword) {
try {
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
} catch (\Exception $e) {
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
}
# Fallback to default value; useful when initializing App, as all constants are not set yet
$sAuthRealm = $config['system']['auth_realm'] ?? "BaikalDAV";
static function hashAdminPassword($sPassword, $sAuthRealm) {
return hash('sha256', 'admin:' . $sAuthRealm . ':' . $sPassword);
}
}