Use a single config file
This commit is contained in:
parent
183086ee95
commit
d263037d06
26 changed files with 281 additions and 304 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,8 +2,7 @@
|
|||
logs
|
||||
|
||||
# Specific
|
||||
config/config.yaml
|
||||
config/system.yaml
|
||||
config/baikal.yaml
|
||||
Specific/INSTALL_DISABLED
|
||||
|
||||
# Composer stuff
|
||||
|
|
|
@ -133,9 +133,9 @@ class Server {
|
|||
protected function initServer() {
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error reading config.yaml file : ' . $e->getMessage());
|
||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if ($this->authType === 'Basic') {
|
||||
|
@ -178,8 +178,8 @@ class Server {
|
|||
$this->server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin());
|
||||
$this->server->addPlugin(new \Sabre\DAV\Sharing\Plugin());
|
||||
$this->server->addPlugin(new \Sabre\CalDAV\SharingPlugin());
|
||||
if (isset($config['parameters']["baikal_invite_from"]) && $config['parameters']["baikal_invite_from"] !== "") {
|
||||
$this->server->addPlugin(new \Sabre\CalDAV\Schedule\IMipPlugin($config['parameters']["baikal_invite_from"]));
|
||||
if (isset($config['system']["invite_from"]) && $config['system']["invite_from"] !== "") {
|
||||
$this->server->addPlugin(new \Sabre\CalDAV\Schedule\IMipPlugin($config['system']["invite_from"]));
|
||||
}
|
||||
}
|
||||
if ($this->enableCardDAV) {
|
||||
|
|
|
@ -73,32 +73,18 @@ class Tools {
|
|||
#}
|
||||
|
||||
# Asserting config file exists
|
||||
if (!file_exists(PROJECT_PATH_CONFIG . "config.yaml")) {
|
||||
throw new \Exception("config/config.yaml does not exist. Please use the Install tool to create it or duplicate config.yaml.dist.");
|
||||
if (!file_exists(PROJECT_PATH_CONFIG . "baikal.yaml")) {
|
||||
throw new \Exception("config/baikal.yaml does not exist. Please use the Install tool to create it or duplicate baikal.yaml.dist.");
|
||||
}
|
||||
|
||||
# Asserting config file is readable
|
||||
if (!is_readable(PROJECT_PATH_CONFIG . "config.yaml")) {
|
||||
throw new \Exception("config/config.yaml is not readable. Please give read permissions to httpd user on file 'config/config.yaml'.");
|
||||
if (!is_readable(PROJECT_PATH_CONFIG . "baikal.yaml")) {
|
||||
throw new \Exception("config/baikal.yaml is not readable. Please give read permissions to httpd user on file 'config/baikal.yaml'.");
|
||||
}
|
||||
|
||||
# Asserting config file is writable
|
||||
if (!is_writable(PROJECT_PATH_CONFIG . "config.yaml")) {
|
||||
throw new \Exception("config/config.yaml is not writable. Please give write permissions to httpd user on file 'config/config.yaml'.");
|
||||
}
|
||||
# Asserting config file exists
|
||||
if (!file_exists(PROJECT_PATH_CONFIG . "system.yaml")) {
|
||||
throw new \Exception("config/system.yaml does not exist. Please use the Install tool to create it or duplicate system.yaml.dist.");
|
||||
}
|
||||
|
||||
# Asserting config file is readable
|
||||
if (!is_readable(PROJECT_PATH_CONFIG . "system.yaml")) {
|
||||
throw new \Exception("config/system.yaml is not readable. Please give read permissions to httpd user on file 'config/system.yaml'.");
|
||||
}
|
||||
|
||||
# Asserting config file is writable
|
||||
if (!is_writable(PROJECT_PATH_CONFIG . "system.yaml")) {
|
||||
throw new \Exception("config/system.yaml is not writable. Please give write permissions to httpd user on file 'config/system.yaml'.");
|
||||
if (!is_writable(PROJECT_PATH_CONFIG . "baikal.yaml")) {
|
||||
throw new \Exception("config/baikal.yaml is not writable. Please give write permissions to httpd user on file 'config/baikal.yaml'.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,31 +52,24 @@ class Framework extends \Flake\Core\Framework {
|
|||
\Baikal\Core\Tools::configureEnvironment();
|
||||
|
||||
# Check that a config file exists
|
||||
if (
|
||||
!file_exists(PROJECT_PATH_CONFIG . "config.yaml") ||
|
||||
!file_exists(PROJECT_PATH_CONFIG . "system.yaml")
|
||||
) {
|
||||
if (!file_exists(PROJECT_PATH_CONFIG . "baikal.yaml")) {
|
||||
self::installTool();
|
||||
} else {
|
||||
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml");
|
||||
date_default_timezone_set($config['parameters']['project_timezone']);
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
date_default_timezone_set($config['system']['timezone']);
|
||||
|
||||
# Check that Baïkal is already configured
|
||||
if (!isset($configSystem['parameters']['baikal_configured_version'])) {
|
||||
if (!isset($config['system']['configured_version'])) {
|
||||
self::installTool();
|
||||
|
||||
} else {
|
||||
|
||||
# Check that running version matches configured version
|
||||
if (version_compare(BAIKAL_VERSION, $configSystem['parameters']['baikal_configured_version']) > 0) {
|
||||
if (version_compare(BAIKAL_VERSION, $config['system']['configured_version']) > 0) {
|
||||
self::installTool();
|
||||
|
||||
} else {
|
||||
|
||||
# Check that admin password is set
|
||||
if (!$config['parameters']['baikal_admin_passwordhash']) {
|
||||
if (!$config['system']['admin_passwordhash']) {
|
||||
self::installTool();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,19 +31,18 @@ use Symfony\Component\Yaml\Yaml;
|
|||
|
||||
abstract class Config extends \Flake\Core\Model\NoDb {
|
||||
|
||||
protected $sConfigFilePath = "";
|
||||
protected $sConfigFileSection = "";
|
||||
protected $aData = [];
|
||||
|
||||
function __construct($sConfigFilePath) {
|
||||
|
||||
function __construct($sConfigFileSection) {
|
||||
# Note: no call to parent::__construct() to avoid erasing $this->aData
|
||||
$this->sConfigFilePath = $sConfigFilePath;
|
||||
$this->sConfigFileSection = $sConfigFileSection;
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile($this->sConfigFilePath);
|
||||
$aConfig = $config['parameters'];
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
$aConfig = $config[$sConfigFileSection];
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error reading "' . $this->sConfigFilePath . '" file : ' . $e->getMessage());
|
||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
||||
$aConfig = static::getDefaultConfig();
|
||||
}
|
||||
|
||||
|
@ -56,8 +55,8 @@ abstract class Config extends \Flake\Core\Model\NoDb {
|
|||
}
|
||||
|
||||
protected function getConfigAsString() {
|
||||
if (file_exists($this->sConfigFilePath)) {
|
||||
return Yaml::parseFile($this->sConfigFilePath);
|
||||
if (file_exists(PROJECT_PATH_CONFIG . "baikal.yaml")) {
|
||||
return Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml")[$this->sConfigFileSection];
|
||||
} else {
|
||||
return static::getDefaultConfig();
|
||||
}
|
||||
|
@ -65,9 +64,9 @@ abstract class Config extends \Flake\Core\Model\NoDb {
|
|||
|
||||
function writable() {
|
||||
return (
|
||||
@file_exists($this->sConfigFilePath) &&
|
||||
@is_file($this->sConfigFilePath) &&
|
||||
@is_writable($this->sConfigFilePath)
|
||||
@file_exists(PROJECT_PATH_CONFIG . "baikal.yaml") &&
|
||||
@is_file(PROJECT_PATH_CONFIG . "baikal.yaml") &&
|
||||
@is_writable(PROJECT_PATH_CONFIG . "baikal.yaml")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -88,10 +87,10 @@ abstract class Config extends \Flake\Core\Model\NoDb {
|
|||
}
|
||||
|
||||
function persist() {
|
||||
$yaml = Yaml::dump([
|
||||
'parameters' => $this->aData
|
||||
]);
|
||||
file_put_contents($this->sConfigFilePath, $yaml);
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
$config[$this->sConfigFileSection] = $this->aData;
|
||||
$yaml = Yaml::dump($config);
|
||||
file_put_contents(PROJECT_PATH_CONFIG . "baikal.yaml", $yaml);
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
|
|
|
@ -30,27 +30,27 @@ namespace Baikal\Model\Config;
|
|||
class Database extends \Baikal\Model\Config {
|
||||
|
||||
protected $aConstants = [
|
||||
"project_sqlite_file" => [
|
||||
"sqlite_file" => [
|
||||
"type" => "litteral",
|
||||
"comment" => "Define path to Baïkal Database SQLite file",
|
||||
],
|
||||
"project_db_mysql" => [
|
||||
"mysql" => [
|
||||
"type" => "boolean",
|
||||
"comment" => "MySQL > Use MySQL instead of SQLite ?",
|
||||
],
|
||||
"project_db_mysql_host" => [
|
||||
"mysql_host" => [
|
||||
"type" => "string",
|
||||
"comment" => "MySQL > Host, including ':portnumber' if port is not the default one (3306)",
|
||||
],
|
||||
"project_db_mysql_dbname" => [
|
||||
"mysql_dbname" => [
|
||||
"type" => "string",
|
||||
"comment" => "MySQL > Database name",
|
||||
],
|
||||
"project_db_mysql_username" => [
|
||||
"mysql_username" => [
|
||||
"type" => "string",
|
||||
"comment" => "MySQL > Username",
|
||||
],
|
||||
"project_db_mysql_password" => [
|
||||
"mysql_password" => [
|
||||
"type" => "string",
|
||||
"comment" => "MySQL > Password",
|
||||
],
|
||||
|
@ -58,19 +58,23 @@ class Database extends \Baikal\Model\Config {
|
|||
|
||||
# Default values
|
||||
protected $aData = [
|
||||
"project_sqlite_file" => PROJECT_PATH_SPECIFIC . "db/db.sqlite",
|
||||
"project_db_mysql" => false,
|
||||
"project_db_mysql_host" => "",
|
||||
"project_db_mysql_dbname" => "",
|
||||
"project_db_mysql_username" => "",
|
||||
"project_db_mysql_password" => "",
|
||||
"sqlite_file" => PROJECT_PATH_SPECIFIC . "db/db.sqlite",
|
||||
"mysql" => false,
|
||||
"mysql_host" => "",
|
||||
"mysql_dbname" => "",
|
||||
"mysql_username" => "",
|
||||
"mysql_password" => "",
|
||||
];
|
||||
|
||||
function __construct() {
|
||||
parent::__construct("database");
|
||||
}
|
||||
|
||||
function formMorphologyForThisModelInstance() {
|
||||
$oMorpho = new \Formal\Form\Morphology();
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Text([
|
||||
"prop" => "project_sqlite_file",
|
||||
"prop" => "sqlite_file",
|
||||
"label" => "SQLite file path",
|
||||
"validation" => "required",
|
||||
"inputclass" => "input-xxlarge",
|
||||
|
@ -78,30 +82,30 @@ class Database extends \Baikal\Model\Config {
|
|||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Checkbox([
|
||||
"prop" => "project_db_mysql",
|
||||
"prop" => "mysql",
|
||||
"label" => "Use MySQL",
|
||||
"help" => "If checked, Baïkal will use MySQL instead of SQLite.",
|
||||
"refreshonchange" => true,
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Text([
|
||||
"prop" => "project_db_mysql_host",
|
||||
"prop" => "mysql_host",
|
||||
"label" => "MySQL host",
|
||||
"help" => "Host ip or name, including <strong>':portnumber'</strong> if port is not the default one (3306)"
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Text([
|
||||
"prop" => "project_db_mysql_dbname",
|
||||
"prop" => "mysql_dbname",
|
||||
"label" => "MySQL database name",
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Text([
|
||||
"prop" => "project_db_mysql_username",
|
||||
"prop" => "mysql_username",
|
||||
"label" => "MySQL username",
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Password([
|
||||
"prop" => "project_db_mysql_password",
|
||||
"prop" => "mysql_password",
|
||||
"label" => "MySQL password",
|
||||
]));
|
||||
|
||||
|
|
|
@ -32,27 +32,27 @@ use Symfony\Component\Yaml\Yaml;
|
|||
class Standard extends \Baikal\Model\Config {
|
||||
|
||||
protected $aConstants = [
|
||||
"project_timezone" => [
|
||||
"timezone" => [
|
||||
"type" => "string",
|
||||
"comment" => "Timezone of the server; if unsure, check http://en.wikipedia.org/wiki/List_of_tz_database_time_zones",
|
||||
],
|
||||
"baikal_card_enabled" => [
|
||||
"card_enabled" => [
|
||||
"type" => "boolean",
|
||||
"comment" => "CardDAV ON/OFF switch; default TRUE",
|
||||
],
|
||||
"baikal_cal_enabled" => [
|
||||
"cal_enabled" => [
|
||||
"type" => "boolean",
|
||||
"comment" => "CalDAV ON/OFF switch; default TRUE",
|
||||
],
|
||||
"baikal_invite_from" => [
|
||||
"invite_from" => [
|
||||
"type" => "string",
|
||||
"comment" => "CalDAV invite From: mail address (comment or leave blank to disable notifications)",
|
||||
],
|
||||
"baikal_dav_auth_type" => [
|
||||
"dav_auth_type" => [
|
||||
"type" => "string",
|
||||
"comment" => "HTTP authentication type for WebDAV; default Digest"
|
||||
],
|
||||
"baikal_admin_passwordhash" => [
|
||||
"admin_passwordhash" => [
|
||||
"type" => "string",
|
||||
"comment" => "Baïkal Web admin password hash; Set via Baïkal Web Admin",
|
||||
]
|
||||
|
@ -60,20 +60,25 @@ class Standard extends \Baikal\Model\Config {
|
|||
|
||||
# Default values
|
||||
protected $aData = [
|
||||
"project_timezone" => "Europe/Paris",
|
||||
"baikal_card_enabled" => true,
|
||||
"baikal_cal_enabled" => true,
|
||||
"baikal_invite_from" => "",
|
||||
"baikal_dav_auth_type" => "Digest",
|
||||
"baikal_admin_passwordhash" => "",
|
||||
"baikal_auth_realm" => "BaikalDAV"
|
||||
"configured_version" => BAIKAL_VERSION,
|
||||
"timezone" => "Europe/Paris",
|
||||
"card_enabled" => true,
|
||||
"cal_enabled" => true,
|
||||
"invite_from" => "",
|
||||
"dav_auth_type" => "Digest",
|
||||
"admin_passwordhash" => "",
|
||||
"auth_realm" => "BaikalDAV"
|
||||
];
|
||||
|
||||
function __construct() {
|
||||
parent::__construct("system");
|
||||
}
|
||||
|
||||
function formMorphologyForThisModelInstance() {
|
||||
$oMorpho = new \Formal\Form\Morphology();
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Listbox([
|
||||
"prop" => "project_timezone",
|
||||
"prop" => "timezone",
|
||||
"label" => "Server Time zone",
|
||||
"validation" => "required",
|
||||
"options" => \Baikal\Core\Tools::timezones(),
|
||||
|
@ -81,52 +86,52 @@ class Standard extends \Baikal\Model\Config {
|
|||
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Checkbox([
|
||||
"prop" => "baikal_card_enabled",
|
||||
"prop" => "card_enabled",
|
||||
"label" => "Enable CardDAV"
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Checkbox([
|
||||
"prop" => "baikal_cal_enabled",
|
||||
"prop" => "cal_enabled",
|
||||
"label" => "Enable CalDAV"
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Text([
|
||||
"prop" => "baikal_invite_from",
|
||||
"prop" => "invite_from",
|
||||
"label" => "Email invite sender address",
|
||||
"help" => "Leave empty to disable sending invite emails"
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Listbox([
|
||||
"prop" => "baikal_dav_auth_type",
|
||||
"prop" => "dav_auth_type",
|
||||
"label" => "WebDAV authentication type",
|
||||
"options" => ["Digest", "Basic"]
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Password([
|
||||
"prop" => "baikal_admin_passwordhash",
|
||||
"prop" => "admin_passwordhash",
|
||||
"label" => "Admin password",
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Password([
|
||||
"prop" => "baikal_admin_passwordhash_confirm",
|
||||
"prop" => "admin_passwordhash_confirm",
|
||||
"label" => "Admin password, confirmation",
|
||||
"validation" => "sameas:baikal_admin_passwordhash",
|
||||
"validation" => "sameas:admin_passwordhash",
|
||||
]));
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error reading system.yaml file : ' . $e->getMessage());
|
||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (!isset($config['parameters']["baikal_admin_passwordhash"]) || trim($config['parameters']["baikal_admin_passwordhash"]) === "") {
|
||||
if (!isset($config['parameters']["admin_passwordhash"]) || trim($config['system']["admin_passwordhash"]) === "") {
|
||||
|
||||
# No password set (Form is used in install tool), so password is required as it has to be defined
|
||||
$oMorpho->element("baikal_admin_passwordhash")->setOption("validation", "required");
|
||||
$oMorpho->element("admin_passwordhash")->setOption("validation", "required");
|
||||
} else {
|
||||
$sNotice = "-- Leave empty to keep current password --";
|
||||
$oMorpho->element("baikal_admin_passwordhash")->setOption("placeholder", $sNotice);
|
||||
$oMorpho->element("baikal_admin_passwordhash_confirm")->setOption("placeholder", $sNotice);
|
||||
$oMorpho->element("admin_passwordhash")->setOption("placeholder", $sNotice);
|
||||
$oMorpho->element("admin_passwordhash_confirm")->setOption("placeholder", $sNotice);
|
||||
}
|
||||
|
||||
return $oMorpho;
|
||||
|
@ -137,12 +142,12 @@ class Standard extends \Baikal\Model\Config {
|
|||
}
|
||||
|
||||
function set($sProp, $sValue) {
|
||||
if ($sProp === "baikal_admin_passwordhash" || $sProp === "baikal_admin_passwordhash_confirm") {
|
||||
if ($sProp === "admin_passwordhash" || $sProp === "admin_passwordhash_confirm") {
|
||||
# Special handling for password and passwordconfirm
|
||||
|
||||
if ($sProp === "baikal_admin_passwordhash" && $sValue !== "") {
|
||||
if ($sProp === "admin_passwordhash" && $sValue !== "") {
|
||||
parent::set(
|
||||
"baikal_admin_passwordhash",
|
||||
"admin_passwordhash",
|
||||
\BaikalAdmin\Core\Auth::hashAdminPassword($sValue)
|
||||
);
|
||||
}
|
||||
|
@ -154,7 +159,7 @@ class Standard extends \Baikal\Model\Config {
|
|||
}
|
||||
|
||||
function get($sProp) {
|
||||
if ($sProp === "baikal_admin_passwordhash" || $sProp === "baikal_admin_passwordhash_confirm") {
|
||||
if ($sProp === "admin_passwordhash" || $sProp === "admin_passwordhash_confirm") {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -164,13 +169,14 @@ class Standard extends \Baikal\Model\Config {
|
|||
protected static function getDefaultConfig() {
|
||||
|
||||
return [
|
||||
"project_timezone" => "Europe/Paris",
|
||||
"baikal_card_enabled" => true,
|
||||
"baikal_cal_enabled" => true,
|
||||
"baikal_invite_from" => "noreply@" . $_SERVER['SERVER_NAME'],
|
||||
"baikal_dav_auth_type" => "Digest",
|
||||
"baikal_admin_passwordhash" => "",
|
||||
"baikal_auth_realm" => "BaikalDAV",
|
||||
"timezone" => "Europe/Paris",
|
||||
"card_enabled" => true,
|
||||
"cal_enabled" => true,
|
||||
"invite_from" => "noreply@" . $_SERVER['SERVER_NAME'],
|
||||
"dav_auth_type" => "Digest",
|
||||
"admin_passwordhash" => "",
|
||||
"auth_realm" => "BaikalDAV",
|
||||
"configured_version" => BAIKAL_VERSION
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,27 +30,27 @@ namespace Baikal\Model\Config;
|
|||
class System extends \Baikal\Model\Config {
|
||||
|
||||
protected $aConstants = [
|
||||
"project_sqlite_file" => [
|
||||
"sqlite_file" => [
|
||||
"type" => "litteral",
|
||||
"comment" => "Define path to Baïkal Database SQLite file",
|
||||
],
|
||||
"project_db_mysql" => [
|
||||
"mysql" => [
|
||||
"type" => "boolean",
|
||||
"comment" => "MySQL > Use MySQL instead of SQLite ?",
|
||||
],
|
||||
"project_db_mysql_host" => [
|
||||
"mysql_host" => [
|
||||
"type" => "string",
|
||||
"comment" => "MySQL > Host, including ':portnumber' if port is not the default one (3306)",
|
||||
],
|
||||
"project_db_mysql_dbname" => [
|
||||
"mysql_dbname" => [
|
||||
"type" => "string",
|
||||
"comment" => "MySQL > Database name",
|
||||
],
|
||||
"project_db_mysql_username" => [
|
||||
"mysql_username" => [
|
||||
"type" => "string",
|
||||
"comment" => "MySQL > Username",
|
||||
],
|
||||
"project_db_mysql_password" => [
|
||||
"mysql_password" => [
|
||||
"type" => "string",
|
||||
"comment" => "MySQL > Password",
|
||||
],
|
||||
|
@ -66,21 +66,25 @@ class System extends \Baikal\Model\Config {
|
|||
|
||||
# Default values
|
||||
protected $aData = [
|
||||
"project_sqlite_file" => "db/db.sqlite",
|
||||
"project_db_mysql" => false,
|
||||
"project_db_mysql_host" => "",
|
||||
"project_db_mysql_dbname" => "",
|
||||
"project_db_mysql_username" => "",
|
||||
"project_db_mysql_password" => "",
|
||||
"baikal_encryption_key" => "",
|
||||
"baikal_configured_version" => "",
|
||||
"sqlite_file" => "db/db.sqlite",
|
||||
"mysql" => false,
|
||||
"mysql_host" => "",
|
||||
"mysql_dbname" => "",
|
||||
"mysql_username" => "",
|
||||
"mysql_password" => "",
|
||||
"encryption_key" => "",
|
||||
"configured_version" => "",
|
||||
];
|
||||
|
||||
function __construct() {
|
||||
parent::__construct("database");
|
||||
}
|
||||
|
||||
function formMorphologyForThisModelInstance() {
|
||||
$oMorpho = new \Formal\Form\Morphology();
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Text([
|
||||
"prop" => "project_sqlite_file",
|
||||
"prop" => "sqlite_file",
|
||||
"label" => "SQLite file path",
|
||||
"validation" => "required",
|
||||
"inputclass" => "input-xxlarge",
|
||||
|
@ -88,30 +92,30 @@ class System extends \Baikal\Model\Config {
|
|||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Checkbox([
|
||||
"prop" => "project_db_mysql",
|
||||
"prop" => "mysql",
|
||||
"label" => "Use MySQL",
|
||||
"help" => "If checked, Baïkal will use MySQL instead of SQLite.",
|
||||
"refreshonchange" => true,
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Text([
|
||||
"prop" => "project_db_mysql_host",
|
||||
"prop" => "mysql_host",
|
||||
"label" => "MySQL host",
|
||||
"help" => "Host ip or name, including ':portnumber' if port is not the default one (3306)"
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Text([
|
||||
"prop" => "project_db_mysql_dbname",
|
||||
"prop" => "mysql_dbname",
|
||||
"label" => "MySQL database name",
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Text([
|
||||
"prop" => "project_db_mysql_username",
|
||||
"prop" => "mysql_username",
|
||||
"label" => "MySQL username",
|
||||
]));
|
||||
|
||||
$oMorpho->add(new \Formal\Element\Password([
|
||||
"prop" => "project_db_mysql_password",
|
||||
"prop" => "mysql_password",
|
||||
"label" => "MySQL password",
|
||||
]));
|
||||
|
||||
|
@ -125,14 +129,13 @@ class System extends \Baikal\Model\Config {
|
|||
protected static function getDefaultConfig() {
|
||||
|
||||
return [
|
||||
"project_sqlite_file" => "db/db.sqlite",
|
||||
"project_db_mysql" => false,
|
||||
"project_db_mysql_host" => "",
|
||||
"project_db_mysql_dbname" => "",
|
||||
"project_db_mysql_username" => "",
|
||||
"project_db_mysql_password" => "",
|
||||
"baikal_encryption_key" => "",
|
||||
"baikal_configured_version" => BAIKAL_VERSION
|
||||
"sqlite_file" => "db/db.sqlite",
|
||||
"mysql" => false,
|
||||
"mysql_host" => "",
|
||||
"mysql_dbname" => "",
|
||||
"mysql_username" => "",
|
||||
"mysql_password" => "",
|
||||
"encryption_key" => ""
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -283,11 +283,11 @@ class User extends \Flake\Core\Model\Db {
|
|||
function getPasswordHashForPassword($sPassword) {
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error reading config.yaml file : ' . $e->getMessage());
|
||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return md5($this->get("username") . ':' . $config['parameters']['baikal_auth_realm'] . ':' . $sPassword);
|
||||
return md5($this->get("username") . ':' . $config['system']['auth_realm'] . ':' . $sPassword);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,14 +36,14 @@ class Dashboard extends \Flake\Core\Controller {
|
|||
|
||||
function render() {
|
||||
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
|
||||
$oView = new \BaikalAdmin\View\Dashboard();
|
||||
$oView->setData("BAIKAL_VERSION", BAIKAL_VERSION);
|
||||
|
||||
# Services status
|
||||
$oView->setData("baikal_cal_enabled", $config['parameters']['baikal_cal_enabled']);
|
||||
$oView->setData("baikal_card_enabled", $config['parameters']['baikal_card_enabled']);
|
||||
$oView->setData("baikal_cal_enabled", $config['system']['cal_enabled']);
|
||||
$oView->setData("baikal_card_enabled", $config['system']['card_enabled']);
|
||||
|
||||
# Statistics: Users
|
||||
$iNbUsers = \Baikal\Model\User::getBaseRequester()->count();
|
||||
|
|
|
@ -40,13 +40,13 @@ class Database extends \Flake\Core\Controller {
|
|||
|
||||
if (file_exists(PROJECT_PATH_SPECIFIC . "config.system.php")) {
|
||||
require_once(PROJECT_PATH_SPECIFIC . "config.system.php");
|
||||
$this->oModel->set('project_sqlite_file', PROJECT_SQLITE_FILE);
|
||||
$this->oModel->set('project_db_mysql', PROJECT_DB_MYSQL);
|
||||
$this->oModel->set('project_db_mysql_host', PROJECT_DB_MYSQL_HOST);
|
||||
$this->oModel->set('project_db_mysql_dbname', PROJECT_DB_MYSQL_DBNAME);
|
||||
$this->oModel->set('project_db_mysql_username', PROJECT_DB_MYSQL_USERNAME);
|
||||
$this->oModel->set('project_db_mysql_password', PROJECT_DB_MYSQL_PASSWORD);
|
||||
$this->oModel->set('baikal_encryption_key', BAIKAL_ENCRYPTION_KEY);
|
||||
$this->oModel->set('sqlite_file', PROJECT_SQLITE_FILE);
|
||||
$this->oModel->set('mysql', PROJECT_DB_MYSQL);
|
||||
$this->oModel->set('mysql_host', PROJECT_DB_MYSQL_HOST);
|
||||
$this->oModel->set('mysql_dbname', PROJECT_DB_MYSQL_DBNAME);
|
||||
$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);
|
||||
}
|
||||
|
||||
$this->oForm = $this->oModel->formForThisModelInstance([
|
||||
|
@ -95,14 +95,14 @@ class Database extends \Flake\Core\Controller {
|
|||
if ($oForm->refreshed()){
|
||||
return true;
|
||||
}
|
||||
$bMySQLEnabled = $oMorpho->element("project_db_mysql")->value();
|
||||
$bMySQLEnabled = $oMorpho->element("mysql")->value();
|
||||
|
||||
if ($bMySQLEnabled) {
|
||||
|
||||
$sHost = $oMorpho->element("project_db_mysql_host")->value();
|
||||
$sDbname = $oMorpho->element("project_db_mysql_dbname")->value();
|
||||
$sUsername = $oMorpho->element("project_db_mysql_username")->value();
|
||||
$sPassword = $oMorpho->element("project_db_mysql_password")->value();
|
||||
$sHost = $oMorpho->element("mysql_host")->value();
|
||||
$sDbname = $oMorpho->element("mysql_dbname")->value();
|
||||
$sUsername = $oMorpho->element("mysql_username")->value();
|
||||
$sPassword = $oMorpho->element("mysql_password")->value();
|
||||
|
||||
try {
|
||||
$oDb = new \Flake\Core\Database\Mysql(
|
||||
|
@ -123,7 +123,7 @@ class Database extends \Flake\Core\Controller {
|
|||
$sMessage .= "<br /><p>Nothing has been saved. <strong>Please, add these tables to the database before pursuing Baïkal initialization.</strong></p>";
|
||||
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("project_db_mysql"),
|
||||
$oMorpho->element("mysql"),
|
||||
$sMessage
|
||||
);
|
||||
} else {
|
||||
|
@ -136,29 +136,29 @@ class Database extends \Flake\Core\Controller {
|
|||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$oForm->declareError($oMorpho->element("project_db_mysql"),
|
||||
$oForm->declareError($oMorpho->element("mysql"),
|
||||
"Baïkal was not able to establish a connexion to the MySQL database as configured.<br />MySQL says: " . $e->getMessage());
|
||||
$oForm->declareError($oMorpho->element("project_db_mysql_host"));
|
||||
$oForm->declareError($oMorpho->element("project_db_mysql_dbname"));
|
||||
$oForm->declareError($oMorpho->element("project_db_mysql_username"));
|
||||
$oForm->declareError($oMorpho->element("project_db_mysql_password"));
|
||||
$oForm->declareError($oMorpho->element("mysql_host"));
|
||||
$oForm->declareError($oMorpho->element("mysql_dbname"));
|
||||
$oForm->declareError($oMorpho->element("mysql_username"));
|
||||
$oForm->declareError($oMorpho->element("mysql_password"));
|
||||
}
|
||||
} else {
|
||||
|
||||
$sFile = $oMorpho->element("project_sqlite_file")->value();
|
||||
$sFile = $oMorpho->element("sqlite_file")->value();
|
||||
|
||||
try {
|
||||
|
||||
# Asserting DB file is writable
|
||||
if (file_exists($sFile) && !is_writable($sFile)) {
|
||||
$sMessage = "DB file is not writable. Please give write permissions on file <span style='font-family: monospace'>" . $sFile . "</span>";
|
||||
$oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage);
|
||||
$oForm->declareError($oMorpho->element("sqlite_file"), $sMessage);
|
||||
return false;
|
||||
}
|
||||
# Asserting DB directory is writable
|
||||
if (!is_writable(dirname($sFile))) {
|
||||
$sMessage = "The <em>FOLDER</em> containing the DB file is not writable, and it has to.<br />Please give write permissions on folder <span style='font-family: monospace'>" . dirname($sFile) . "</span>";
|
||||
$oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage);
|
||||
$oForm->declareError($oMorpho->element("sqlite_file"), $sMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ class Database extends \Flake\Core\Controller {
|
|||
$sMessage .= "<br /><p>Nothing has been saved. <strong>Please, add these tables to the database before pursuing Baïkal initialization.</strong></p>";
|
||||
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("project_sqlite_file"),
|
||||
$oMorpho->element("sqlite_file"),
|
||||
$sMessage
|
||||
);
|
||||
} else {
|
||||
|
@ -195,7 +195,7 @@ class Database extends \Flake\Core\Controller {
|
|||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("project_sqlite_file"),
|
||||
$oMorpho->element("sqlite_file"),
|
||||
"Baïkal was not able to establish a connexion to the SQLite database as configured.<br />SQLite says: " . $e->getMessage() . (string)$e
|
||||
);
|
||||
}
|
||||
|
@ -206,24 +206,24 @@ class Database extends \Flake\Core\Controller {
|
|||
function hideMySQLFieldWhenNeeded(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) {
|
||||
|
||||
if ($oForm->submitted()) {
|
||||
$bMySQL = (intval($oForm->postValue("project_db_mysql")) === 1);
|
||||
$bMySQL = (intval($oForm->postValue("mysql")) === 1);
|
||||
} else {
|
||||
try {
|
||||
$configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml");
|
||||
$configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error reading system.yaml file : ' . $e->getMessage());
|
||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
||||
}
|
||||
$bMySQL = $configSystem['parameters']['project_db_mysql'] ?? true;
|
||||
$bMySQL = $configSystem['database']['mysql'] ?? true;
|
||||
}
|
||||
|
||||
if ($bMySQL === true) {
|
||||
$oMorpho->remove("project_sqlite_file");
|
||||
$oMorpho->remove("sqlite_file");
|
||||
} else {
|
||||
|
||||
$oMorpho->remove("project_db_mysql_host");
|
||||
$oMorpho->remove("project_db_mysql_dbname");
|
||||
$oMorpho->remove("project_db_mysql_username");
|
||||
$oMorpho->remove("project_db_mysql_password");
|
||||
$oMorpho->remove("mysql_host");
|
||||
$oMorpho->remove("mysql_dbname");
|
||||
$oMorpho->remove("mysql_username");
|
||||
$oMorpho->remove("mysql_password");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,11 +50,11 @@ class Initialize extends \Flake\Core\Controller {
|
|||
// If we come from pre-0.7.0, we need to get the values from the config.php and config.system.php files
|
||||
if (file_exists(PROJECT_PATH_SPECIFIC . "config.php")) {
|
||||
require_once(PROJECT_PATH_SPECIFIC . "config.php");
|
||||
$this->oModel->set('project_timezone', PROJECT_TIMEZONE);
|
||||
$this->oModel->set('baikal_card_enabled', BAIKAL_CARD_ENABLED);
|
||||
$this->oModel->set('baikal_cal_enabled', BAIKAL_CAL_ENABLED);
|
||||
$this->oModel->set('baikal_invite_from', BAIKAL_INVITE_FROM);
|
||||
$this->oModel->set('baikal_dav_auth_type', BAIKAL_DAV_AUTH_TYPE);
|
||||
$this->oModel->set('timezone', PROJECT_TIMEZONE);
|
||||
$this->oModel->set('card_enabled', BAIKAL_CARD_ENABLED);
|
||||
$this->oModel->set('cal_enabled', BAIKAL_CAL_ENABLED);
|
||||
$this->oModel->set('invite_from', BAIKAL_INVITE_FROM);
|
||||
$this->oModel->set('dav_auth_type', BAIKAL_DAV_AUTH_TYPE);
|
||||
}
|
||||
|
||||
$this->oForm = $this->oModel->formForThisModelInstance([
|
||||
|
@ -75,13 +75,13 @@ class Initialize extends \Flake\Core\Controller {
|
|||
}
|
||||
|
||||
# Creating system config, and initializing BAIKAL_ENCRYPTION_KEY
|
||||
$oSystemConfig = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml");
|
||||
$oSystemConfig->set("baikal_encryption_key", md5(microtime() . rand()));
|
||||
$oSystemConfig = new \Baikal\Model\Config\System("system");
|
||||
$oSystemConfig->set("encryption_key", md5(microtime() . rand()));
|
||||
|
||||
# Default: PDO::SQLite or PDO::MySQL ?
|
||||
$aPDODrivers = \PDO::getAvailableDrivers();
|
||||
if (!in_array('sqlite', $aPDODrivers)) { # PDO::MySQL is already asserted in \Baikal\Core\Tools::assertEnvironmentIsOk()
|
||||
$oSystemConfig->set("project_db_mysql", true);
|
||||
$oSystemConfig->set("mysql", true);
|
||||
}
|
||||
|
||||
$oSystemConfig->persist();
|
||||
|
|
|
@ -38,13 +38,13 @@ class UpgradeConfirmation extends \Flake\Core\Controller {
|
|||
$oView = new \BaikalAdmin\View\Install\UpgradeConfirmation();
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error reading config.yaml file : ' . $e->getMessage());
|
||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (isset($config['parameters']['baikal_configured_version']) && $config['parameters']['baikal_configured_version'] === BAIKAL_VERSION) {
|
||||
$sMessage = "Your system is configured to use version <strong>" . $config['parameters']['baikal_configured_version'] . "</strong>.<br />There's no upgrade to be done.";
|
||||
if (isset($config['system']['configured_version']) && $config['system']['configured_version'] === BAIKAL_VERSION) {
|
||||
$sMessage = "Your system is configured to use version <strong>" . $config['system']['configured_version'] . "</strong>.<br />There's no upgrade to be done.";
|
||||
} else {
|
||||
$sMessage = "Upgrading Baïkal from version <strong>" . "Unknown" . "</strong> to version <strong>" . BAIKAL_VERSION . "</strong>";
|
||||
}
|
||||
|
|
|
@ -44,16 +44,16 @@ class VersionUpgrade extends \Flake\Core\Controller {
|
|||
function render() {
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error reading system.yaml file : ' . $e->getMessage());
|
||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
$sBigIcon = "glyph2x-magic";
|
||||
$sBaikalVersion = BAIKAL_VERSION;
|
||||
$sBaikalConfiguredVersion = $config['parameters']['baikal_configured_version'];
|
||||
$sBaikalConfiguredVersion = $config['system']['configured_version'];
|
||||
|
||||
if ($config['parameters']['baikal_configured_version'] === BAIKAL_VERSION) {
|
||||
if ($config['system']['configured_version'] === BAIKAL_VERSION) {
|
||||
$sMessage = "Your system is configured to use version <strong>" . $sBaikalConfiguredVersion . "</strong>.<br />There's no upgrade to be done.";
|
||||
} else {
|
||||
$sMessage = "Upgrading Baïkal from version <strong>" . $sBaikalConfiguredVersion . "</strong> to version <strong>" . $sBaikalVersion . "</strong>";
|
||||
|
@ -67,7 +67,7 @@ class VersionUpgrade extends \Flake\Core\Controller {
|
|||
HTML;
|
||||
|
||||
try {
|
||||
$bSuccess = $this->upgrade($config['parameters']['baikal_configured_version'], BAIKAL_VERSION);
|
||||
$bSuccess = $this->upgrade($config['system']['configured_version'], BAIKAL_VERSION);
|
||||
} catch (\Exception $e) {
|
||||
$bSuccess = false;
|
||||
$this->aErrors[] = 'Uncaught exception during upgrade: ' . (string)$e;
|
||||
|
@ -532,11 +532,11 @@ SQL
|
|||
protected function updateConfiguredVersion($sVersionTo) {
|
||||
|
||||
# Create new settings
|
||||
$oConfig = new \Baikal\Model\Config\Standard(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$oConfig = new \Baikal\Model\Config\Standard("config");
|
||||
$oConfig->persist();
|
||||
|
||||
# Update BAIKAL_CONFIGURED_VERSION
|
||||
$oConfig = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml");
|
||||
$oConfig = new \Baikal\Model\Config\System("system");
|
||||
$oConfig->set("baikal_configured_version", $sVersionTo);
|
||||
$oConfig->persist();
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class Standard extends \Flake\Core\Controller {
|
|||
private $oForm;
|
||||
|
||||
function execute() {
|
||||
$this->oModel = new \Baikal\Model\Config\Standard(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$this->oModel = new \Baikal\Model\Config\Standard();
|
||||
|
||||
# Assert that config file is writable
|
||||
if (!$this->oModel->writable()) {
|
||||
|
|
|
@ -42,7 +42,7 @@ class System extends \Flake\Core\Controller {
|
|||
private $oForm;
|
||||
|
||||
function execute() {
|
||||
$this->oModel = new \Baikal\Model\Config\System(PROJECT_PATH_CONFIG . "system.yaml");
|
||||
$this->oModel = new \Baikal\Model\Config\System();
|
||||
|
||||
# Assert that config file is writable
|
||||
if (!$this->oModel->writable()) {
|
||||
|
@ -76,24 +76,24 @@ class System extends \Flake\Core\Controller {
|
|||
|
||||
function morphologyHook(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) {
|
||||
if ($oForm->submitted()) {
|
||||
$bMySQL = (intval($oForm->postValue("project_db_mysql")) === 1);
|
||||
$bMySQL = (intval($oForm->postValue("mysql")) === 1);
|
||||
} else {
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error reading system.yaml file : ' . $e->getMessage());
|
||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
||||
}
|
||||
$bMySQL = $config['parameters']['project_db_mysql'] ?? true;
|
||||
$bMySQL = $config['database']['mysql'] ?? true;
|
||||
}
|
||||
|
||||
if ($bMySQL === true) {
|
||||
$oMorpho->remove("project_sqlite_file");
|
||||
$oMorpho->remove("sqlite_file");
|
||||
} else {
|
||||
|
||||
$oMorpho->remove("project_db_mysql_host");
|
||||
$oMorpho->remove("project_db_mysql_dbname");
|
||||
$oMorpho->remove("project_db_mysql_username");
|
||||
$oMorpho->remove("project_db_mysql_password");
|
||||
$oMorpho->remove("mysql_host");
|
||||
$oMorpho->remove("mysql_dbname");
|
||||
$oMorpho->remove("mysql_username");
|
||||
$oMorpho->remove("mysql_password");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,13 +101,13 @@ class System extends \Flake\Core\Controller {
|
|||
if ($oForm->refreshed()){
|
||||
return true;
|
||||
}
|
||||
if (intval($oForm->modelInstance()->get("project_db_mysql")) === 1) {
|
||||
if (intval($oForm->modelInstance()->get("mysql")) === 1) {
|
||||
|
||||
# We have to check the MySQL connection
|
||||
$sHost = $oForm->modelInstance()->get("project_db_mysql_host");
|
||||
$sDbName = $oForm->modelInstance()->get("project_db_mysql_dbname");
|
||||
$sUsername = $oForm->modelInstance()->get("project_db_mysql_username");
|
||||
$sPassword = $oForm->modelInstance()->get("project_db_mysql_password");
|
||||
$sHost = $oForm->modelInstance()->get("mysql_host");
|
||||
$sDbName = $oForm->modelInstance()->get("mysql_dbname");
|
||||
$sUsername = $oForm->modelInstance()->get("mysql_username");
|
||||
$sPassword = $oForm->modelInstance()->get("mysql_password");
|
||||
|
||||
try {
|
||||
$oDB = new \Flake\Core\Database\Mysql(
|
||||
|
@ -119,10 +119,10 @@ class System extends \Flake\Core\Controller {
|
|||
} catch (\Exception $e) {
|
||||
$sMessage = "<strong>MySQL error:</strong> " . $e->getMessage();
|
||||
$sMessage .= "<br /><strong>Nothing has been saved</strong>";
|
||||
$oForm->declareError($oMorpho->element("project_db_mysql_host"), $sMessage);
|
||||
$oForm->declareError($oMorpho->element("project_db_mysql_dbname"));
|
||||
$oForm->declareError($oMorpho->element("project_db_mysql_username"));
|
||||
$oForm->declareError($oMorpho->element("project_db_mysql_password"));
|
||||
$oForm->declareError($oMorpho->element("mysql_host"), $sMessage);
|
||||
$oForm->declareError($oMorpho->element("mysql_dbname"));
|
||||
$oForm->declareError($oMorpho->element("mysql_username"));
|
||||
$oForm->declareError($oMorpho->element("mysql_password"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -131,31 +131,24 @@ class System extends \Flake\Core\Controller {
|
|||
$sMessage .= "You may want create these tables using the file <strong>Core/Resources/Db/MySQL/db.sql</strong>";
|
||||
$sMessage .= "<br /><br /><strong>Nothing has been saved</strong>";
|
||||
|
||||
$oForm->declareError($oMorpho->element("project_db_mysql"), $sMessage);
|
||||
$oForm->declareError($oMorpho->element("mysql"), $sMessage);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
$sFile = $oMorpho->element("project_sqlite_file")->value();
|
||||
$sFile = $oMorpho->element("sqlite_file")->value();
|
||||
|
||||
try {
|
||||
|
||||
// not sure yet how to better address this
|
||||
// yup! this is mental, but even if we don't use eval, effectively these
|
||||
// config settings are eval'ed because they are written as raw php files.
|
||||
// We'll have to clean this up later.
|
||||
$sFile = eval('return ' . $sFile . ';');
|
||||
|
||||
# Asserting DB file is writable
|
||||
if (file_exists($sFile) && !is_writable($sFile)) {
|
||||
$sMessage = "DB file is not writable. Please give write permissions on file <span style='font-family: monospace'>" . $sFile . "</span>";
|
||||
$oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage);
|
||||
$oForm->declareError($oMorpho->element("sqlite_file"), $sMessage);
|
||||
return;
|
||||
}
|
||||
# Asserting DB directory is writable
|
||||
if (!is_writable(dirname($sFile))) {
|
||||
$sMessage = "The <em>FOLDER</em> containing the DB file is not writable, and it has to.<br />Please give write permissions on folder <span style='font-family: monospace'>" . dirname($sFile) . "</span>";
|
||||
$oForm->declareError($oMorpho->element("project_sqlite_file"), $sMessage);
|
||||
$oForm->declareError($oMorpho->element("sqlite_file"), $sMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -171,14 +164,14 @@ class System extends \Flake\Core\Controller {
|
|||
$sMessage .= "<br /><p>Nothing has been saved. <strong>Please, add these tables to the database before pursuing Baïkal initialization.</strong></p>";
|
||||
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("project_sqlite_file"),
|
||||
$oMorpho->element("sqlite_file"),
|
||||
$sMessage
|
||||
);
|
||||
}
|
||||
return;
|
||||
} catch (\Exception $e) {
|
||||
$oForm->declareError(
|
||||
$oMorpho->element("project_sqlite_file"),
|
||||
$oMorpho->element("sqlite_file"),
|
||||
"Baïkal was not able to establish a connexion to the SQLite database as configured.<br />SQLite says: " . $e->getMessage() . (string)$e
|
||||
);
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ use Symfony\Component\Yaml\Yaml;
|
|||
class Auth {
|
||||
static function isAuthenticated() {
|
||||
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
|
||||
if (isset($_SESSION["baikaladminauth"]) && $_SESSION["baikaladminauth"] === md5($config['parameters']['baikal_admin_passwordhash'])) {
|
||||
if (isset($_SESSION["baikaladminauth"]) && $_SESSION["baikaladminauth"] === md5($config['system']['admin_passwordhash'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -52,12 +52,12 @@ class Auth {
|
|||
|
||||
$sPassHash = self::hashAdminPassword($sPass);
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error reading config.yaml file : ' . $e->getMessage());
|
||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
||||
}
|
||||
if ($sUser === "admin" && $sPassHash === $config['parameters']['baikal_admin_passwordhash']) {
|
||||
$_SESSION["baikaladminauth"] = md5($config['parameters']['baikal_admin_passwordhash']);
|
||||
if ($sUser === "admin" && $sPassHash === $config['system']['admin_passwordhash']) {
|
||||
$_SESSION["baikaladminauth"] = md5($config['system']['admin_passwordhash']);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -72,13 +72,13 @@ class Auth {
|
|||
static function hashAdminPassword($sPassword) {
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error reading config.yaml file : ' . $e->getMessage());
|
||||
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['parameters']['baikal_auth_realm'] ?? "BaikalDAV";
|
||||
$sAuthRealm = $config['system']['auth_realm'] ?? "BaikalDAV";
|
||||
|
||||
return hash('sha256', 'admin:' . $sAuthRealm . ':' . $sPassword);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
</div>
|
||||
<div class="span3">
|
||||
<h2>Services</h2>
|
||||
{% if baikal_cal_enabled %}
|
||||
{% if cal_enabled %}
|
||||
{% set caldavclass = 'label-success' %}
|
||||
{% set caldavtext = 'On' %}
|
||||
{% else %}
|
||||
|
@ -46,7 +46,7 @@
|
|||
{% set caldavtext = 'Off' %}
|
||||
{% endif %}
|
||||
|
||||
{% if baikal_card_enabled %}
|
||||
{% if card_enabled %}
|
||||
{% set carddavclass = 'label-success' %}
|
||||
{% set carddavtext = 'On' %}
|
||||
{% else %}
|
||||
|
|
|
@ -68,27 +68,21 @@ $oPage->setBaseUrl(PROJECT_URI);
|
|||
$oPage->zone("navbar")->addBlock(new \BaikalAdmin\Controller\Navigation\Topbar\Install());
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
$config = null;
|
||||
error_log('Error reading config.yaml file : ' . $e->getMessage());
|
||||
}
|
||||
try {
|
||||
$configSystem = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml");
|
||||
} catch (\Exception $e) {
|
||||
$configSystem = null;
|
||||
error_log('Error reading system.yaml file : ' . $e->getMessage());
|
||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (!$configSystem || !isset($configSystem['parameters']["baikal_configured_version"])) {
|
||||
if (!$config || !isset($config['system']["configured_version"])) {
|
||||
# we have to upgrade Baïkal (existing installation)
|
||||
$oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Initialize());
|
||||
|
||||
} elseif (!$config || !isset($config['parameters']["baikal_admin_passwordhash"])) {
|
||||
} elseif (!isset($config['system']["admin_passwordhash"])) {
|
||||
# we have to set an admin password
|
||||
$oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\Initialize());
|
||||
} else {
|
||||
if ($configSystem['parameters']["baikal_configured_version"] !== BAIKAL_VERSION) {
|
||||
if ($config['system']["configured_version"] !== BAIKAL_VERSION) {
|
||||
# we have to upgrade Baïkal
|
||||
if (\Flake\Util\Tools::GET("upgradeConfirmed")) {
|
||||
$oPage->zone("Payload")->addBlock(new \BaikalAdmin\Controller\Install\VersionUpgrade());
|
||||
|
|
|
@ -215,16 +215,16 @@ class Framework extends \Flake\Core\Framework {
|
|||
protected static function initDb() {
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "system.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
error_log('Error reading system.yaml file : ' . $e->getMessage());
|
||||
error_log('Error reading baikal.yaml file : ' . $e->getMessage());
|
||||
return true;
|
||||
}
|
||||
# Dont init db on install, but in normal mode and when upgrading
|
||||
if (defined("BAIKAL_CONTEXT_INSTALL") && (!isset($config['parameters']['baikal_configured_version']) || $config['parameters']['baikal_configured_version'] === BAIKAL_VERSION)) {
|
||||
if (defined("BAIKAL_CONTEXT_INSTALL") && (!isset($config['system']['configured_version']) || $config['system']['configured_version'] === BAIKAL_VERSION)) {
|
||||
return true;
|
||||
}
|
||||
if ($config['parameters']['project_db_mysql'] === true) {
|
||||
if ($config['database']['mysql'] === true) {
|
||||
self::initDbMysql($config);
|
||||
} else {
|
||||
self::initDbSqlite($config);
|
||||
|
@ -233,22 +233,22 @@ class Framework extends \Flake\Core\Framework {
|
|||
|
||||
protected static function initDbSqlite(array $config) {
|
||||
# Asserting DB filepath is set
|
||||
if (!$config['parameters']['project_sqlite_file']) {
|
||||
if (!$config['database']['sqlite_file']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
# Asserting DB file is writable
|
||||
if (file_exists($config['parameters']['project_sqlite_file']) && !is_writable($config['parameters']['project_sqlite_file'])) {
|
||||
die("<h3>DB file is not writable. Please give write permissions on file '<span style='font-family: monospace; background: yellow;'>" . $config['parameters']['project_sqlite_file'] . "</span>'</h3>");
|
||||
if (file_exists($config['database']['sqlite_file']) && !is_writable($config['database']['sqlite_file'])) {
|
||||
die("<h3>DB file is not writable. Please give write permissions on file '<span style='font-family: monospace; background: yellow;'>" . $config['database']['sqlite_file'] . "</span>'</h3>");
|
||||
}
|
||||
|
||||
# Asserting DB directory is writable
|
||||
if (!is_writable(dirname($config['parameters']['project_sqlite_file']))) {
|
||||
die("<h3>The <em>FOLDER</em> containing the DB file is not writable, and it has to.<br />Please give write permissions on folder '<span style='font-family: monospace; background: yellow;'>" . dirname($config['parameters']['project_sqlite_file']) . "</span>'</h3>");
|
||||
if (!is_writable(dirname($config['database']['sqlite_file']))) {
|
||||
die("<h3>The <em>FOLDER</em> containing the DB file is not writable, and it has to.<br />Please give write permissions on folder '<span style='font-family: monospace; background: yellow;'>" . dirname($config['database']['sqlite_file']) . "</span>'</h3>");
|
||||
}
|
||||
|
||||
if (file_exists($config['parameters']['project_sqlite_file']) && is_readable($config['parameters']['project_sqlite_file']) && !isset($GLOBALS["DB"])) {
|
||||
$GLOBALS["DB"] = new \Flake\Core\Database\Sqlite($config['parameters']['project_sqlite_file']);
|
||||
if (file_exists($config['database']['sqlite_file']) && is_readable($config['database']['sqlite_file']) && !isset($GLOBALS["DB"])) {
|
||||
$GLOBALS["DB"] = new \Flake\Core\Database\Sqlite($config['database']['sqlite_file']);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -257,28 +257,28 @@ class Framework extends \Flake\Core\Framework {
|
|||
|
||||
protected static function initDbMysql(array $config) {
|
||||
|
||||
if (!$config['parameters']['project_db_mysql_host']) {
|
||||
if (!$config['database']['mysql_host']) {
|
||||
die("<h3>The constant PROJECT_DB_MYSQL_HOST, containing the MySQL host name, is not set.<br />You should set it in config/system.yaml</h3>");
|
||||
}
|
||||
|
||||
if (!$config['parameters']['project_db_mysql_dbname']) {
|
||||
if (!$config['database']['mysql_dbname']) {
|
||||
die("<h3>The constant PROJECT_DB_MYSQL_DBNAME, containing the MySQL database name, is not set.<br />You should set it in config/system.yaml</h3>");
|
||||
}
|
||||
|
||||
if (!$config['parameters']['project_db_mysql_username']) {
|
||||
if (!$config['database']['mysql_username']) {
|
||||
die("<h3>The constant PROJECT_DB_MYSQL_USERNAME, containing the MySQL database username, is not set.<br />You should set it in config/system.yaml</h3>");
|
||||
}
|
||||
|
||||
if (!$config['parameters']['project_db_mysql_password']) {
|
||||
if (!$config['database']['mysql_password']) {
|
||||
die("<h3>The constant PROJECT_DB_MYSQL_PASSWORD, containing the MySQL database password, is not set.<br />You should set it in config/system.yaml</h3>");
|
||||
}
|
||||
|
||||
try {
|
||||
$GLOBALS["DB"] = new \Flake\Core\Database\Mysql(
|
||||
$config['parameters']['project_db_mysql_host'],
|
||||
$config['parameters']['project_db_mysql_dbname'],
|
||||
$config['parameters']['project_db_mysql_username'],
|
||||
$config['parameters']['project_db_mysql_password']
|
||||
$config['database']['mysql_host'],
|
||||
$config['database']['mysql_dbname'],
|
||||
$config['database']['mysql_username'],
|
||||
$config['database']['mysql_password']
|
||||
);
|
||||
|
||||
# We now setup t6he connexion to use UTF8
|
||||
|
|
17
config/baikal.yaml.dist
Normal file
17
config/baikal.yaml.dist
Normal file
|
@ -0,0 +1,17 @@
|
|||
system:
|
||||
configured_version: '0.7.0'
|
||||
timezone: 'Europe/Paris'
|
||||
card_enabled: true
|
||||
cal_enabled: true
|
||||
invite_from: 'noreply@localhost'
|
||||
dav_auth_type: 'Digest'
|
||||
admin_passwordhash: 5fe794627e1f841f8debba065e2c807a
|
||||
auth_realm: BaikalDAV
|
||||
database:
|
||||
encryption_key: 5d3f0fa0192e3058ea70f1bb20924add
|
||||
sqlite_file: "absolute/path/to/Specific/db/db.sqlite"
|
||||
mysql: true
|
||||
mysql_host: 'localhost'
|
||||
mysql_dbname: 'baikal'
|
||||
mysql_username: 'baikal'
|
||||
mysql_password: 'baikal'
|
|
@ -1,8 +0,0 @@
|
|||
parameters:
|
||||
project_timezone: 'Europe/Paris'
|
||||
baikal_card_enabled: true
|
||||
baikal_cal_enabled: true
|
||||
baikal_invite_from: 'noreply@localhost'
|
||||
baikal_dav_auth_type: 'Digest'
|
||||
baikal_admin_passwordhash: 5fe794627e1f841f8debba065e2c807a
|
||||
baikal_auth_realm: BaikalDAV
|
|
@ -1,9 +0,0 @@
|
|||
parameters:
|
||||
project_sqlite_file: "absolute/path/to/Specific/db/db.sqlite"
|
||||
project_db_mysql: true
|
||||
project_db_mysql_host: 'localhost'
|
||||
project_db_mysql_dbname: 'baikal'
|
||||
project_db_mysql_username: 'baikal'
|
||||
project_db_mysql_password: 'baikal'
|
||||
baikal_encryption_key: '5d3f0fa0192e3058ea70f1bb20924add'
|
||||
baikal_configured_version: '0.7.0'
|
12
html/cal.php
12
html/cal.php
|
@ -54,20 +54,20 @@ require PROJECT_PATH_ROOT . 'vendor/autoload.php';
|
|||
\Baikal\Framework::bootstrap();
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
die('<h1>Incomplete installation</h1><p>Baïkal is missing its configuration file, or its configuration file is unreadable.');
|
||||
}
|
||||
|
||||
if (!isset($config['parameters']["baikal_cal_enabled"]) || $config['parameters']["baikal_cal_enabled"] !== true) {
|
||||
if (!isset($config['system']["cal_enabled"]) || $config['system']["cal_enabled"] !== true) {
|
||||
throw new ErrorException("Baikal CalDAV is disabled.", 0, 255, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
$server = new \Baikal\Core\Server(
|
||||
$config['parameters']["baikal_cal_enabled"],
|
||||
$config['parameters']["baikal_card_enabled"],
|
||||
$config['parameters']["baikal_dav_auth_type"],
|
||||
$config['parameters']["baikal_auth_realm"],
|
||||
$config['system']["cal_enabled"],
|
||||
$config['system']["card_enabled"],
|
||||
$config['system']["dav_auth_type"],
|
||||
$config['system']["auth_realm"],
|
||||
$GLOBALS['DB']->getPDO(),
|
||||
PROJECT_BASEURI . 'cal.php/'
|
||||
);
|
||||
|
|
|
@ -55,20 +55,20 @@ require PROJECT_PATH_ROOT . 'vendor/autoload.php';
|
|||
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
die('<h1>Incomplete installation</h1><p>Baïkal is missing its configuration file, or its configuration file is unreadable.');
|
||||
}
|
||||
|
||||
if (!isset($config['parameters']["baikal_card_enabled"]) || $config['parameters']["baikal_card_enabled"] !== true) {
|
||||
if (!isset($config['system']["card_enabled"]) || $config['parameters']["card_enabled"] !== true) {
|
||||
throw new ErrorException("Baikal CardDAV is disabled.", 0, 255, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
$server = new \Baikal\Core\Server(
|
||||
$config['parameters']["baikal_cal_enabled"],
|
||||
$config['parameters']["baikal_card_enabled"],
|
||||
$config['parameters']["baikal_dav_auth_type"],
|
||||
$config['parameters']["baikal_auth_realm"],
|
||||
$config['system']["cal_enabled"],
|
||||
$config['system']["card_enabled"],
|
||||
$config['system']["dav_auth_type"],
|
||||
$config['system']["auth_realm"],
|
||||
$GLOBALS['DB']->getPDO(),
|
||||
PROJECT_BASEURI . 'card.php/'
|
||||
);
|
||||
|
|
10
html/dav.php
10
html/dav.php
|
@ -53,16 +53,16 @@ require PROJECT_PATH_ROOT . 'vendor/autoload.php';
|
|||
\Baikal\Framework::bootstrap();
|
||||
|
||||
try {
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "config.yaml");
|
||||
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
|
||||
} catch (\Exception $e) {
|
||||
die('<h1>Incomplete installation</h1><p>Baïkal is missing its configuration file, or its configuration file is unreadable.');
|
||||
}
|
||||
|
||||
$server = new \Baikal\Core\Server(
|
||||
$config['parameters']["baikal_cal_enabled"],
|
||||
$config['parameters']["baikal_card_enabled"],
|
||||
$config['parameters']["baikal_dav_auth_type"],
|
||||
$config['parameters']["baikal_auth_realm"],
|
||||
$config['system']["cal_enabled"],
|
||||
$config['system']["card_enabled"],
|
||||
$config['system']["dav_auth_type"],
|
||||
$config['system']["auth_realm"],
|
||||
$GLOBALS['DB']->getPDO(),
|
||||
PROJECT_BASEURI . 'dav.php/'
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue