Skip to content

Commit 94714ae

Browse files
committed
issue#99 database password in config.php
1 parent 9644bce commit 94714ae

6 files changed

Lines changed: 70 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
### Added
99
- Support for Nextcloud 19
1010
- Argon2id support
11+
- System wide values option
1112

1213
## [4.4.1] - 2020-02-02
1314
### Fixed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,20 @@ 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+
**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*.
4344

4445
#### Options
4546

4647
Here are all currently supported options.
4748

4849
Name | Description | Details
4950
--- | --- | ---
50-
**Allow display name change** | With this option enabled user can change its display name. The display name change is propagated to the database. | Optional.<br/>Default: false.<br/>Requires: user *Display name* column.
51-
**Allow password change** | Can user change its password. The password change is propagated to the database. See [Hash algorithms](#hash-algorithms). | Optional.<br/>Default: false.
52-
**Allow providing avatar** | Can user provide its avatar. The value is used when column *Provide avatar* is not set. | Optional.<br/>Default: false.
53-
**Case-insensitive username** | Whether user query should be case-sensitive or case-insensitive. | Optional.<br/>Default: false.
54-
**Reverse active column** | Reverse value of active column in user table. | Optional.<br/>Default: false.
55-
**Use cache** | Use database query results cache. The cache can be cleared any time with the *Clear cache* button click. | Optional.<br/>Default: false.
51+
**Allow display name change** | With this option enabled user can change its display name. The display name change is propagated to the database. | Optional.<br/>Default: *false*.<br/>Requires: user *Display name* column.
52+
**Allow password change** | Can user change its password. The password change is propagated to the database. See [Hash algorithms](#hash-algorithms). | Optional.<br/>Default: *false*.
53+
**Allow providing avatar** | Can user provide its avatar. The value is used when column *Provide avatar* is not set. | Optional.<br/>Default: *false*.
54+
**Case-insensitive username** | Whether user query should be case-sensitive or case-insensitive. | Optional.<br/>Default: *false*.
55+
**Reverse active column** | Reverse value of active column in user table. | Optional.<br/>Default: *false*.
56+
**Use cache** | Use database query results cache. The cache can be cleared any time with the *Clear cache* button click. | Optional.<br/>Default: *false*.
5657
**Hash algorithm** | How users passwords are stored in the database. See [Hash algorithms](#hash-algorithms). | Mandatory.
5758
**Name sync** | Sync display name with the Nextcloud.<br/>- *None* - Disables this feature. This is the default option.<br/>- *Synchronise only once* - Copy the display name to the Nextcloud preferences if its not set.<br/>- *Nextcloud always wins* - Always copy the display name to the database. This updates the user table.<br/>- *SQL always wins* - Always copy the display name to the Nextcloud preferences. | Optional.<br/>Default: *None*.<br/>Requires: user *Display name* column.
5859
**Email sync** | Sync e-mail address with the Nextcloud.<br/>- *None* - Disables this feature. This is the default option.<br/>- *Synchronise only once* - Copy the e-mail address to the Nextcloud preferences if its not set.<br/>- *Nextcloud always wins* - Always copy the e-mail address to the database. This updates the user table.<br/>- *SQL always wins* - Always copy the e-mail address to the Nextcloud preferences. | Optional.<br/>Default: *None*.<br/>Requires: user *Email* column.
@@ -74,11 +75,11 @@ Name | Description | Details
7475
**Password** | Password hash column. | Mandatory for user backend.
7576
**Display name** | Display name column. | Optional.
7677
**Active** | Flag indicating if user can log in. | Optional.<br/>Default: true.
77-
**Disabled** | Flag indicating if user should not be visible (not included in searches). | Optional.<br/>Default: false.
78-
**Provide avatar** | Flag indicating if user can change its avatar. | Optional.<br/>Default: false.
78+
**Disabled** | Flag indicating if user should not be visible (not included in searches). | Optional.<br/>Default: *false*.
79+
**Provide avatar** | Flag indicating if user can change its avatar. | Optional.<br/>Default: *false*.
7980
**Salt** | Salt which is appended to password when checking or changing the password. | Optional.
80-
**Append salt** | Append a salt to the password. | Optional.<br/>Default: false.
81-
**Prepend salt** | Prepend a salt to the password. | Optional.<br/>Default: false.
81+
**Append salt** | Append a salt to the password. | Optional.<br/>Default: *false*.
82+
**Prepend salt** | Prepend a salt to the password. | Optional.<br/>Default: *false*.
8283

8384
#### Group table
8485

lib/Constant/Opt.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Nextcloud - user_sql
44
*
5-
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
5+
* @copyright 2020 Marcin Łojewski <dev@mlojewski.me>
66
* @author Marcin Łojewski <dev@mlojewski.me>
77
*
88
* This program is free software: you can redistribute it and/or modify
@@ -44,5 +44,6 @@ final class Opt
4444
const PROVIDE_AVATAR = "opt.provide_avatar";
4545
const QUOTA_SYNC = "opt.quota_sync";
4646
const REVERSE_ACTIVE = "opt.reverse_active";
47+
const SAFE_STORE = "opt.safe_store";
4748
const USE_CACHE = "opt.use_cache";
4849
}

lib/Controller/SettingsController.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Nextcloud - user_sql
44
*
5-
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
5+
* @copyright 2020 Marcin Łojewski <dev@mlojewski.me>
66
* @author Marcin Łojewski <dev@mlojewski.me>
77
*
88
* This program is free software: you can redistribute it and/or modify
@@ -28,6 +28,7 @@
2828
use OC\DB\ConnectionFactory;
2929
use OCA\UserSQL\Cache;
3030
use OCA\UserSQL\Constant\App;
31+
use OCA\UserSQL\Constant\DB;
3132
use OCA\UserSQL\Constant\Opt;
3233
use OCA\UserSQL\Crypto\IPasswordAlgorithm;
3334
use OCA\UserSQL\Platform\PlatformFactory;
@@ -208,6 +209,15 @@ public function saveProperties()
208209
];
209210
}
210211

212+
$safeStore = $this->request->getParam(str_replace(".", "-", Opt::SAFE_STORE), App::FALSE_VALUE);
213+
if ($safeStore !== $this->properties[Opt::SAFE_STORE]) {
214+
unset($this->properties[DB::HOSTNAME]);
215+
unset($this->properties[DB::PASSWORD]);
216+
unset($this->properties[DB::USERNAME]);
217+
unset($this->properties[DB::DATABASE]);
218+
$this->properties[Opt::SAFE_STORE] = $safeStore;
219+
}
220+
211221
foreach ($properties as $key => $value) {
212222
$reqValue = $this->request->getParam(str_replace(".", "-", $key));
213223
$appValue = $this->properties[$key];

lib/Properties.php

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Nextcloud - user_sql
44
*
5-
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
5+
* @copyright 2020 Marcin Łojewski <dev@mlojewski.me>
66
* @author Marcin Łojewski <dev@mlojewski.me>
77
*
88
* This program is free software: you can redistribute it and/or modify
@@ -59,6 +59,10 @@ class Properties implements \ArrayAccess
5959
* @var array The properties array.
6060
*/
6161
private $data;
62+
/**
63+
* @var boolean Store confidential data in file.
64+
*/
65+
private $safeStore;
6266

6367
/**
6468
* The default constructor.
@@ -95,9 +99,15 @@ private function loadProperties()
9599

96100
$params = $this->getParameterArray();
97101
$this->data = [];
102+
$this->safeStore
103+
= $this->config->getAppValue($this->appName, Opt::SAFE_STORE, App::FALSE_VALUE) === App::TRUE_VALUE;
98104

99105
foreach ($params as $param) {
100-
$value = $this->config->getAppValue($this->appName, $param, null);
106+
if ($this->isSystemValue($param)) {
107+
$value = $this->config->getSystemValue("user_sql." . $param, null);
108+
} else {
109+
$value = $this->config->getAppValue($this->appName, $param, null);
110+
}
101111

102112
if ($this->isBooleanParam($param)) {
103113
if ($value === App::FALSE_VALUE) {
@@ -143,6 +153,16 @@ private function getParameterArray()
143153
return $params;
144154
}
145155

156+
/**
157+
* @param $param string Parameter name.
158+
*
159+
* @return bool TRUE if this is a system wide parameter FALSE otherwise.
160+
*/
161+
private function isSystemValue($param)
162+
{
163+
return $this->safeStore && in_array($param, array(DB::HOSTNAME, DB::PASSWORD, DB::USERNAME, DB::DATABASE));
164+
}
165+
146166
/**
147167
* Is given parameter a boolean parameter.
148168
*
@@ -156,7 +176,8 @@ private function isBooleanParam($param)
156176
$param, [
157177
Opt::APPEND_SALT, Opt::CASE_INSENSITIVE_USERNAME,
158178
Opt::NAME_CHANGE, Opt::PASSWORD_CHANGE, Opt::PREPEND_SALT,
159-
Opt::PROVIDE_AVATAR, Opt::REVERSE_ACTIVE, Opt::USE_CACHE
179+
Opt::PROVIDE_AVATAR, Opt::REVERSE_ACTIVE, Opt::SAFE_STORE,
180+
Opt::USE_CACHE
160181
]
161182
);
162183
}
@@ -204,7 +225,15 @@ public function offsetGet($offset)
204225
*/
205226
public function offsetSet($offset, $value)
206227
{
207-
$this->config->setAppValue($this->appName, $offset, $value);
228+
if ($offset == Opt::SAFE_STORE) {
229+
$this->safeStore = ($value === App::TRUE_VALUE);
230+
}
231+
232+
if ($this->isSystemValue($offset)) {
233+
$this->config->setSystemValue("user_sql." . $offset, $value);
234+
} else {
235+
$this->config->setAppValue($this->appName, $offset, $value);
236+
}
208237

209238
if ($this->isBooleanParam($offset)) {
210239
if ($value === App::FALSE_VALUE) {
@@ -228,7 +257,15 @@ public function offsetSet($offset, $value)
228257
*/
229258
public function offsetUnset($offset)
230259
{
231-
$this->config->deleteAppValue($this->appName, $offset);
260+
if ($offset == Opt::SAFE_STORE) {
261+
$this->safeStore = App::FALSE_VALUE;
262+
}
263+
264+
if ($this->isSystemValue($offset)) {
265+
$this->config->deleteSystemValue("user_sql." . $offset);
266+
} else {
267+
$this->config->deleteAppValue($this->appName, $offset);
268+
}
232269
unset($this->data[$offset]);
233270
}
234271
}

templates/admin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Nextcloud - user_sql
44
*
5-
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
5+
* @copyright 2020 Marcin Łojewski <dev@mlojewski.me>
66
* @author Marcin Łojewski <dev@mlojewski.me>
77
*
88
* This program is free software: you can redistribute it and/or modify
@@ -98,7 +98,8 @@ function print_select_options(
9898
print_text_input($l, "db-hostname", "Hostname", $_["db.hostname"]);
9999
print_text_input($l, "db-database", "Database", $_["db.database"]);
100100
print_text_input($l, "db-username", "Username", $_["db.username"]);
101-
print_text_input($l, "db-password", "Password", $_["db.password"], "password"); ?>
101+
print_text_input($l, "db-password", "Password", $_["db.password"], "password");
102+
print_checkbox_input($l, "opt-safe_store", "System wide values", $_["opt.safe_store"]); ?>
102103
<div class="button-right">
103104
<input type="submit" id="user_sql-db_connection_verify" value="<?php p($l->t("Verify settings")); ?>">
104105
</div>

0 commit comments

Comments
 (0)