Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Core/Frameworks/Baikal/Model/Config/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Database extends \Baikal\Model\Config {
"mysql_dbname" => "",
"mysql_username" => "",
"mysql_password" => "",
"mysql_ca_cert" => "",
"encryption_key" => "",
"pgsql_host" => "",
"pgsql_dbname" => "",
Expand Down Expand Up @@ -87,6 +88,11 @@ function formMorphologyForThisModelInstance() {
"label" => "MySQL password",
]));

$oMorpho->add(new \Formal\Element\Text([
"prop" => "mysql_ca_cert",
"label" => "MySQL CA Certificate",
]));

$oMorpho->add(new \Formal\Element\Text([
"prop" => "pgsql_host",
"label" => "PostgreSQL host",
Expand Down
7 changes: 6 additions & 1 deletion Core/Frameworks/BaikalAdmin/Controller/Install/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function execute() {
$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('mysql_ca_cert', PROJECT_DB_MYSQL_CA_CERT);
$this->oModel->set('pgsql_host', PROJECT_DB_PGSQL_HOST);
$this->oModel->set('pgsql_dbname', PROJECT_DB_PGSQL_DBNAME);
$this->oModel->set('pgsql_username', PROJECT_DB_PGSQL_USERNAME);
Expand Down Expand Up @@ -170,13 +171,15 @@ function validateMySQLConnection($oForm, $oMorpho) {
$sDbname = $oMorpho->element("mysql_dbname")->value();
$sUsername = $oMorpho->element("mysql_username")->value();
$sPassword = $oMorpho->element("mysql_password")->value();
$sCaCert = $oMorpho->element("mysql_ca_cert")->value();

try {
$oDb = new \Flake\Core\Database\Mysql(
$sHost,
$sDbname,
$sUsername,
$sPassword
$sPassword,
$sCaCert
);

if (($aMissingTables = \Baikal\Core\Tools::isDBStructurallyComplete($oDb)) !== true) {
Expand Down Expand Up @@ -208,6 +211,7 @@ function validateMySQLConnection($oForm, $oMorpho) {
$oForm->declareError($oMorpho->element("mysql_dbname"));
$oForm->declareError($oMorpho->element("mysql_username"));
$oForm->declareError($oMorpho->element("mysql_password"));
$oForm->declareError($oMorpho->element("mysql_ca_cert"));
}
}

Expand Down Expand Up @@ -302,6 +306,7 @@ public function hideSqlFieldWhenNeeded(\Formal\Form $oForm, \Formal\Form\Morphol
$oMorpho->remove("mysql_dbname");
$oMorpho->remove("mysql_username");
$oMorpho->remove("mysql_password");
$oMorpho->remove("mysql_ca_cert");
}

if ($backend != 'pgsql') {
Expand Down
6 changes: 5 additions & 1 deletion Core/Frameworks/BaikalAdmin/Controller/Settings/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function morphologyHook(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) {
$oMorpho->remove("mysql_dbname");
$oMorpho->remove("mysql_username");
$oMorpho->remove("mysql_password");
$oMorpho->remove("mysql_ca_cert");
}

if (!$bPgSQL) {
Expand All @@ -127,6 +128,7 @@ function validationHook(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) {
$sDbName = $oForm->modelInstance()->get("{$dbBackendPrefix}_dbname");
$sUsername = $oForm->modelInstance()->get("{$dbBackendPrefix}_username");
$sPassword = $oForm->modelInstance()->get("{$dbBackendPrefix}_password");
$sCaCert = $oForm->modelInstance()->get("{$dbBackendPrefix}_ca_cert");

try {
$oDB = (($oForm->modelInstance()->get("backend")) == 'pgsql'
Expand All @@ -139,7 +141,8 @@ function validationHook(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) {
$sHost,
$sDbName,
$sUsername,
$sPassword
$sPassword,
$sCaCert
);
} catch (\Exception $e) {
$sMessage = "<strong>{$dbBackendName} error:</strong> " . $e->getMessage();
Expand All @@ -148,6 +151,7 @@ function validationHook(\Formal\Form $oForm, \Formal\Form\Morphology $oMorpho) {
$oForm->declareError($oMorpho->element("{$dbBackendPrefix}_dbname"));
$oForm->declareError($oMorpho->element("{$dbBackendPrefix}_username"));
$oForm->declareError($oMorpho->element("{$dbBackendPrefix}_password"));
$oForm->declareError($oMorpho->element("{$dbBackendPrefix}_ca_cert"));

return;
}
Expand Down
16 changes: 13 additions & 3 deletions Core/Frameworks/Flake/Core/Database/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,29 @@ class Mysql extends \Flake\Core\Database {
protected $sDbName = "";
protected $sUsername = "";
protected $sPassword = "";
protected $sCaCert = "";

function __construct($sHost, $sDbName, $sUsername, $sPassword) {
function __construct($sHost, $sDbName, $sUsername, $sPassword, $sCaCert = "") {
$this->sHost = $sHost;
$this->sDbName = $sDbName;
$this->sUsername = $sUsername;
$this->sPassword = $sPassword;
$this->sCaCert = $sCaCert;

$options = [
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
];

if ($this->sCaCert !== "") {
$options[\PDO::MYSQL_ATTR_SSL_CA] = $this->sCaCert;
}

$this->oDb = new \PDO(
'mysql:host=' . $this->sHost . ';dbname=' . $this->sDbName,
$this->sUsername,
$this->sPassword
$this->sPassword,
$options
);
$this->oDb->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
}

function tables() {
Expand Down
3 changes: 2 additions & 1 deletion Core/Frameworks/Flake/Framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ protected static function initDbMysql(array $config) {
$config['database']['mysql_host'],
$config['database']['mysql_dbname'],
$config['database']['mysql_username'],
$config['database']['mysql_password']
$config['database']['mysql_password'],
$config['database']['mysql_ca_cert']
);

# We now setup t6he connexion to use UTF8
Expand Down
1 change: 1 addition & 0 deletions config/baikal.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ database:
mysql_dbname: 'baikal'
mysql_username: 'baikal'
mysql_password: 'baikal'
mysql_ca_cert: '/path/to/sqlca.pem'
pgsql_host: 'localhost'
pgsql_dbname: 'baikal'
pgsql_username: 'baikal'
Expand Down