Merge pull request #979 from benbz/fix-legacy-migration
Fixes for migrating from legacy version
This commit is contained in:
commit
ef80df9508
5 changed files with 31 additions and 32 deletions
|
@ -38,6 +38,8 @@ class Standard extends \Baikal\Model\Config {
|
||||||
"cal_enabled" => true,
|
"cal_enabled" => true,
|
||||||
"dav_auth_type" => "Digest",
|
"dav_auth_type" => "Digest",
|
||||||
"admin_passwordhash" => "",
|
"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",
|
"auth_realm" => "BaikalDAV",
|
||||||
"base_uri" => ""
|
"base_uri" => ""
|
||||||
];
|
];
|
||||||
|
@ -119,7 +121,7 @@ class Standard extends \Baikal\Model\Config {
|
||||||
if ($sProp === "admin_passwordhash" && $sValue !== "") {
|
if ($sProp === "admin_passwordhash" && $sValue !== "") {
|
||||||
parent::set(
|
parent::set(
|
||||||
"admin_passwordhash",
|
"admin_passwordhash",
|
||||||
\BaikalAdmin\Core\Auth::hashAdminPassword($sValue)
|
\BaikalAdmin\Core\Auth::hashAdminPassword($sValue, $this->aData["auth_realm"])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
|
|
||||||
namespace BaikalAdmin\Controller\Install;
|
namespace BaikalAdmin\Controller\Install;
|
||||||
|
|
||||||
use Symfony\Component\Yaml\Yaml;
|
|
||||||
|
|
||||||
class Database extends \Flake\Core\Controller {
|
class Database extends \Flake\Core\Controller {
|
||||||
protected $aMessages = [];
|
protected $aMessages = [];
|
||||||
protected $oModel;
|
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_username', PROJECT_DB_MYSQL_USERNAME);
|
||||||
$this->oModel->set('mysql_password', PROJECT_DB_MYSQL_PASSWORD);
|
$this->oModel->set('mysql_password', PROJECT_DB_MYSQL_PASSWORD);
|
||||||
$this->oModel->set('encryption_key', BAIKAL_ENCRYPTION_KEY);
|
$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([
|
$this->oForm = $this->oModel->formForThisModelInstance([
|
||||||
|
@ -68,6 +60,18 @@ class Database extends \Flake\Core\Controller {
|
||||||
@unlink(PROJECT_PATH_SPECIFIC . "config.system.php");
|
@unlink(PROJECT_PATH_SPECIFIC . "config.system.php");
|
||||||
}
|
}
|
||||||
touch(PROJECT_PATH_SPECIFIC . '/INSTALL_DISABLED');
|
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()) {
|
if ($oForm->submitted()) {
|
||||||
$bMySQL = (intval($oForm->postValue("mysql")) === 1);
|
$bMySQL = (intval($oForm->postValue("mysql")) === 1);
|
||||||
} else {
|
} else {
|
||||||
try {
|
// oMorpho won't have the values from the model set on it yet
|
||||||
$configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
$bMySQL = $this->oModel->get("mysql");
|
||||||
} catch (\Exception $e) {
|
|
||||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
$bMySQL = $configSystem['database']['mysql'] ?? true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bMySQL === true) {
|
if ($bMySQL === true) {
|
||||||
|
|
|
@ -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('invite_from', defined("BAIKAL_INVITE_FROM") ? BAIKAL_INVITE_FROM : "");
|
||||||
$this->oModel->set('dav_auth_type', BAIKAL_DAV_AUTH_TYPE);
|
$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([
|
$this->oForm = $this->oModel->formForThisModelInstance([
|
||||||
"close" => false
|
"close" => false
|
||||||
|
|
|
@ -65,7 +65,7 @@ class VersionUpgrade extends \Flake\Core\Controller {
|
||||||
HTML;
|
HTML;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$bSuccess = $this->upgrade($config['system']['configured_version'], BAIKAL_VERSION);
|
$bSuccess = $this->upgrade($config['database'], $config['system']['configured_version'], BAIKAL_VERSION);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$bSuccess = false;
|
$bSuccess = false;
|
||||||
$this->aErrors[] = 'Uncaught exception during upgrade: ' . (string) $e;
|
$this->aErrors[] = 'Uncaught exception during upgrade: ' . (string) $e;
|
||||||
|
@ -88,7 +88,7 @@ HTML;
|
||||||
return $sHtml;
|
return $sHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function upgrade($sVersionFrom, $sVersionTo) {
|
protected function upgrade($databaseConfig, $sVersionFrom, $sVersionTo) {
|
||||||
if (version_compare($sVersionFrom, '0.2.3', '<=')) {
|
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.');
|
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', '<')) {
|
if (version_compare($sVersionFrom, '0.3.0', '<')) {
|
||||||
// Upgrading from sabre/dav 1.8 schema to 3.1 schema.
|
// 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
|
// MySQL upgrade
|
||||||
|
|
||||||
// sabre/dav 2.0 changes
|
// sabre/dav 2.0 changes
|
||||||
|
@ -313,7 +313,7 @@ HTML;
|
||||||
// The sqlite schema had issues with both the calendar and
|
// The sqlite schema had issues with both the calendar and
|
||||||
// addressbooks tables. The tables didn't have a DEFAULT '1' for
|
// addressbooks tables. The tables didn't have a DEFAULT '1' for
|
||||||
// the synctoken column. So we're adding it now.
|
// 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');
|
$pdo->exec('UPDATE calendars SET synctoken = 1 WHERE synctoken IS NULL');
|
||||||
|
|
||||||
$tmpTable = '_' . time();
|
$tmpTable = '_' . time();
|
||||||
|
@ -343,7 +343,7 @@ CREATE TABLE calendars (
|
||||||
// Similar to upgrading from older than 0.4.5, there were still
|
// Similar to upgrading from older than 0.4.5, there were still
|
||||||
// issues with a missing DEFAULT 1 for sthe synctoken field in the
|
// issues with a missing DEFAULT 1 for sthe synctoken field in the
|
||||||
// addressbook.
|
// 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');
|
$pdo->exec('UPDATE addressbooks SET synctoken = 1 WHERE synctoken IS NULL');
|
||||||
|
|
||||||
$tmpTable = '_' . time();
|
$tmpTable = '_' . time();
|
||||||
|
@ -365,7 +365,7 @@ CREATE TABLE addressbooks (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (version_compare($sVersionFrom, '0.5.1', '<')) {
|
if (version_compare($sVersionFrom, '0.5.1', '<')) {
|
||||||
if (!defined("PROJECT_DB_MYSQL") || PROJECT_DB_MYSQL === false) {
|
if ($databaseConfig['mysql'] === false) {
|
||||||
$pdo->exec(<<<SQL
|
$pdo->exec(<<<SQL
|
||||||
CREATE TABLE calendarinstances (
|
CREATE TABLE calendarinstances (
|
||||||
id integer primary key asc NOT NULL,
|
id integer primary key asc NOT NULL,
|
||||||
|
|
|
@ -48,12 +48,14 @@ class Auth {
|
||||||
$sUser = \Flake\Util\Tools::POST("login");
|
$sUser = \Flake\Util\Tools::POST("login");
|
||||||
$sPass = \Flake\Util\Tools::POST("password");
|
$sPass = \Flake\Util\Tools::POST("password");
|
||||||
|
|
||||||
$sPassHash = self::hashAdminPassword($sPass);
|
|
||||||
try {
|
try {
|
||||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
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']) {
|
if ($sUser === "admin" && $sPassHash === $config['system']['admin_passwordhash']) {
|
||||||
$_SESSION["baikaladminauth"] = md5($config['system']['admin_passwordhash']);
|
$_SESSION["baikaladminauth"] = md5($config['system']['admin_passwordhash']);
|
||||||
|
|
||||||
|
@ -67,16 +69,7 @@ class Auth {
|
||||||
unset($_SESSION["baikaladminauth"]);
|
unset($_SESSION["baikaladminauth"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function hashAdminPassword($sPassword) {
|
static function hashAdminPassword($sPassword, $sAuthRealm) {
|
||||||
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";
|
|
||||||
|
|
||||||
return hash('sha256', 'admin:' . $sAuthRealm . ':' . $sPassword);
|
return hash('sha256', 'admin:' . $sAuthRealm . ':' . $sPassword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue