Skip to content

Commit 0742ff3

Browse files
author
Marcin Łojewski
committed
Merge branch 'develop' of github.com:nextcloud/user_sql into develop
2 parents 4975730 + 43d4088 commit 0742ff3

7 files changed

Lines changed: 53 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Name | Description | Details
4040
**Database** | The name of the database. | Mandatory.
4141
**Username** | The name of the user for the connection. | Optional.
4242
**Password** | The password of the user for the connection. | Optional.
43+
**SSL CA** | The file path to the SSL certificate authority (relative to Nextcloud serverroot) | Optional.<br/>Requires: SQL driver *mysql*.
44+
**SSL Certificate** | The file path to the SSL certificate (relative to Nextcloud serverroot) | Optional.<br/>Requires: SQL driver *mysql*.
45+
**SSL Key** | The file path to the SSL key (relative to Nextcloud serverroot) | Optional.<br/>Requires: SQL driver *mysql*.
4346
**System wide values** | Place where database connection parameters are stored.<br/>- *true* - config.php (System wide values).<br/>- *false* - database (App values). | Optional.<br/>Default: *false*.
4447

4548
#### Options

js/settings.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,21 @@ user_sql.adminSettingsUI = function () {
127127
cryptoChanged();
128128
};
129129

130+
$("#db-driver").change(function () {
131+
var ssl_ca = $("#db-ssl_ca").parent().parent();
132+
var ssl_cert = $("#db-ssl_cert").parent().parent();
133+
var ssl_key = $("#db-ssl_key").parent().parent();
134+
if ($("#db-driver").val() === 'mysql') {
135+
ssl_ca.show();
136+
ssl_cert.show();
137+
ssl_key.show();
138+
} else {
139+
ssl_ca.hide();
140+
ssl_cert.hide();
141+
ssl_key.hide();
142+
}
143+
});
144+
130145
$("#user_sql-db_connection_verify").click(function (event) {
131146
return click(event, "/apps/user_sql/settings/db/verify");
132147
});

lib/Constant/DB.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ final class DB
3232
const DRIVER = "db.driver";
3333
const HOSTNAME = "db.hostname";
3434
const PASSWORD = "db.password";
35+
const SSL_CA = "db.ssl_ca";
36+
const SSL_CERT = "db.ssl_cert";
37+
const SSL_KEY = "db.ssl_key";
3538
const USERNAME = "db.username";
3639

3740
const GROUP_TABLE = "db.table.group";

lib/Controller/SettingsController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ private function getConnection()
146146
$dbDatabase = $this->request->getParam("db-database");
147147
$dbUsername = $this->request->getParam("db-username");
148148
$dbPassword = $this->request->getParam("db-password");
149+
$dbSSL_ca = $this->request->getParam("db-ssl_ca");
150+
$dbSSL_cert = $this->request->getParam("db-ssl_cert");
151+
$dbSSL_key = $this->request->getParam("db-ssl_key");
149152

150153
if (empty($dbDriver)) {
151154
throw new DatabaseException("No database driver specified.");
@@ -160,9 +163,19 @@ private function getConnection()
160163
"password" => $dbPassword,
161164
"user" => $dbUsername,
162165
"dbname" => $dbDatabase,
163-
"tablePrefix" => ""
166+
"tablePrefix" => "",
167+
"driverOptions" => array()
164168
];
165169

170+
if ($dbDriver == 'mysql') {
171+
if ($dbSSL_ca)
172+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CA] = \OC::$SERVERROOT.'/'.$dbSSL_ca;
173+
if ($dbSSL_cert)
174+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CERT] = \OC::$SERVERROOT.'/'.$dbSSL_cert;
175+
if ($dbSSL_key)
176+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_KEY] = \OC::$SERVERROOT.'/'.$dbSSL_key;
177+
}
178+
166179
$connection = $connectionFactory->getConnection($dbDriver, $parameters);
167180
$connection->executeQuery("SELECT 'user_sql'");
168181

@@ -216,6 +229,9 @@ public function saveProperties()
216229
unset($this->properties[DB::PASSWORD]);
217230
unset($this->properties[DB::USERNAME]);
218231
unset($this->properties[DB::DATABASE]);
232+
unset($this->properties[DB::SSL_CA]);
233+
unset($this->properties[DB::SSL_CERT]);
234+
unset($this->properties[DB::SSL_KEY]);
219235
$this->properties[Opt::SAFE_STORE] = $safeStore;
220236
}
221237

lib/Properties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private function getParameterArray()
160160
*/
161161
private function isSystemValue($param)
162162
{
163-
return $this->safeStore && in_array($param, array(DB::HOSTNAME, DB::PASSWORD, DB::USERNAME, DB::DATABASE));
163+
return $this->safeStore && in_array($param, array(DB::HOSTNAME, DB::PASSWORD, DB::USERNAME, DB::DATABASE, DB::SSL_CA, DB::SSL_CERT, DB::SSL_KEY));
164164
}
165165

166166
/**

lib/Query/DataQuery.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,19 @@ private function connectToDatabase()
145145
"password" => $this->properties[DB::PASSWORD],
146146
"user" => $this->properties[DB::USERNAME],
147147
"dbname" => $this->properties[DB::DATABASE],
148-
"tablePrefix" => ""
148+
"tablePrefix" => "",
149+
"driverOptions" => array()
149150
);
150151

152+
if ($this->properties[DB::DRIVER] == 'mysql') {
153+
if ($this->properties[DB::SSL_CA])
154+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CA] = \OC::$SERVERROOT.'/'.$this->properties[DB::SSL_CA];
155+
if ($this->properties[DB::SSL_CERT])
156+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CERT] = \OC::$SERVERROOT.'/'.$this->properties[DB::SSL_CERT];
157+
if ($this->properties[DB::SSL_KEY])
158+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_KEY] = \OC::$SERVERROOT.'/'.$this->properties[DB::SSL_KEY];
159+
}
160+
151161
$this->connection = $connectionFactory->getConnection(
152162
$this->properties[DB::DRIVER], $parameters
153163
);

templates/admin.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ function print_select_options(
100100
print_text_input($l, "db-database", "Database", $_["db.database"]);
101101
print_text_input($l, "db-username", "Username", $_["db.username"]);
102102
print_text_input($l, "db-password", "Password", $_["db.password"], "password");
103+
print_text_input($l, "db-ssl_ca", "SSL CA", $_["db.ssl_ca"]);
104+
print_text_input($l, "db-ssl_cert", "SSL Certificate", $_["db.ssl_cert"]);
105+
print_text_input($l, "db-ssl_key", "SSL Key", $_["db.ssl_key"]);
103106
print_checkbox_input($l, "opt-safe_store", "System wide values", $_["opt.safe_store"]); ?>
104107
<div class="button-right">
105108
<input type="submit" id="user_sql-db_connection_verify" value="<?php p($l->t("Verify settings")); ?>">

0 commit comments

Comments
 (0)