Skip to content

Commit 880416a

Browse files
committed
Merge branch 'release/v4.0.0'
2 parents b1b1ffb + 4be294e commit 880416a

63 files changed

Lines changed: 1000 additions & 190 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,36 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## [v4.0.0-rc2]
7+
## [4.0.0] - 2018-08-11
8+
### Added
9+
- SHA512 Whirlpool hash algorithm
10+
- WoltLab Community Framework 2.x hash algorithm
11+
- phpass hash implementation
12+
- Support for salt column
13+
- User quota synchronization
14+
15+
### Changed
16+
- Example SQL script in README file
17+
- Fixed misspelling
18+
19+
### Changed
20+
- Support for Nextcloud 14 only
21+
- Group backend implementation
22+
- User backend implementation
23+
24+
### Fixed
25+
- Table and column autocomplete in settings panel
26+
27+
## [4.0.0-rc2] - 2018-06-14
828
### Added
929
- User active column
1030

1131
### Changed
1232
- Fixed "Use of undefined constant" error for Argon2 Crypt with PHP below 7.2.
1333

14-
## [4.0.0-rc1]
34+
## [4.0.0-rc1] - 2018-06-13
1535
### Added
16-
- New hashing algorithms: Argon2 Crypt (PHP 7.2 and above), Blowfish Crypt, Courier base64-encoded MD5, Courier base64-encoded SHA1,
17-
Courier base64-encoded SHA256, Courier hexadecimal MD5, Extended DES Crypt, SHA256 Crypt,
18-
SHA512 Crypt, SSHA512, Standard DES Crypt
36+
- New hash algorithms: Argon2 Crypt (PHP 7.2 and above), Blowfish Crypt, Courier base64-encoded MD5, Courier base64-encoded SHA1, Courier base64-encoded SHA256, Courier hexadecimal MD5, Extended DES Crypt, SHA256 Crypt, SHA512 Crypt, SSHA512, Standard DES Crypt
1937
- Option to allow users to change their display names
2038
- Option to allow user to change its avatar
2139
- Database query results cache
@@ -26,10 +44,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2644
- The whole core implementation, which is NOT COMPATIBLE with the previous versions.
2745
- Minimum supported PHP version - 7.0
2846

29-
## Removed
30-
- MySQL ENCRYPT() hashing implementation - Function is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release.
31-
- MySQL PASSWORD() hashing implementation - Function is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release.
32-
- Redmine hashing implementation - Cannot implement in new core system.
47+
### Removed
48+
- MySQL ENCRYPT() hash implementation - Function is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release.
49+
- MySQL PASSWORD() hash implementation - Function is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release.
50+
- Redmine hash implementation - Cannot implement in new core system.
3351
- User active column - Use database view instead
3452
- Domain support
3553

@@ -65,6 +83,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6583
### Changed
6684
- Supported version of ownCloud, Nextcloud: ownCloud 10, Nextcloud 12
6785

68-
[v4.0.0-rc2]: https://github.com/nextcloud/user_sql/compare/v4.0.0-rc1...v4.0.0-rc2
86+
[4.0.0]: https://github.com/nextcloud/user_sql/compare/v4.0.0-rc2...v4.0.0
87+
[4.0.0-rc2]: https://github.com/nextcloud/user_sql/compare/v4.0.0-rc1...v4.0.0-rc2
6988
[4.0.0-rc1]: https://github.com/nextcloud/user_sql/compare/v3.1.0...v4.0.0-rc1
7089
[3.1.0]: https://github.com/nextcloud/user_sql/compare/v2.4.0...v3.1.0

README.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ Name | Description | Details
5050
**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.
5151
**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.
5252
**Use cache** | Use database query results cache. The cache can be cleared any time with the *Clear cache* button click. | Optional.<br/>Default: false.
53-
**Hashing algorithm** | How users passwords are stored in the database. See [Hash algorithms](#hash-algorithms). | Mandatory.
54-
**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 storage 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 storage. | Optional.<br/>Default: *None*.<br/>Requires: user *Email* column.
55-
**Home mode** | User storage path.<br/>- *Default* - Let the Nextcloud manage this. The default option.<br/>- *Query* - Use location from the user table pointed by the *home* column.<br/>- *Static* - Use static location. The `%u` variable is replaced with the username of the user. | Optional<br/>Default: *Default*.
56-
**Home Location** | User storage path for the `static` *home mode*. | Mandatory if the *Home mode* is set to `Static`.
53+
**Hash algorithm** | How users passwords are stored in the database. See [Hash algorithms](#hash-algorithms). | Mandatory.
54+
**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.
55+
**Quota sync** | Sync user quota with the Nextcloud.<br/>- *None* - Disables this feature. This is the default option.<br/>- *Synchronise only once* - Copy the user quota to the Nextcloud preferences if its not set.<br/>- *Nextcloud always wins* - Always copy the user quota to the database. This updates the user table.<br/>- *SQL always wins* - Always copy the user quota to the Nextcloud preferences. | Optional.<br/>Default: *None*.<br/>Requires: user *Quota* column.
56+
**Home mode** | User storage path.<br/>- *Default* - Let the Nextcloud manage this. The default option.<br/>- *Query* - Use location from the user table pointed by the *home* column.<br/>- *Static* - Use static location pointed by the *Home Location* option. | Optional<br/>Default: *Default*.
57+
**Home Location** | User storage path for the `Static` *Home mode*. The `%u` variable is replaced with the username of the user. | Mandatory if the *Home mode* is set to `Static`.
5758

5859
#### User table
5960

@@ -64,11 +65,13 @@ Name | Description | Details
6465
**Table name** | The table name. | Mandatory for user backend.
6566
**Username** | Username column. | Mandatory for user backend.
6667
**Email** | E-mail column. | Mandatory for *Email sync* option.
68+
**Quota** | Quota column. | Mandatory for *Quota sync* option.
6769
**Home** | Home path column. | Mandatory for `Query` *Home sync* option.
6870
**Password** | Password hash column. | Mandatory for user backend.
6971
**Display name** | Display name column. | Optional.
7072
**Active** | Flag indicating if user can log in. | Optional.<br/>Default: true.
71-
**Can change avatar** | Flag indicating if user can change its avatar. | Optional.<br/>Default: false.
73+
**Provide avatar** | Flag indicating if user can change its avatar. | Optional.<br/>Default: false.
74+
**Salt** | Salt which is appended to password when checking or changing the password. | Optional.
7275

7376
#### Group table
7477

@@ -105,36 +108,34 @@ but be aware that some functionalities requires data changes (update queries).
105108

106109
If you don't have any database model yet you can use below tables (MySQL):
107110
```
108-
CREATE TABLE sql_users
111+
CREATE TABLE sql_user
109112
(
110-
id INT AUTO_INCREMENT PRIMARY KEY,
111-
username VARCHAR(16) NOT NULL,
112-
display_name TEXT NULL,
113-
email TEXT NULL,
114-
home TEXT NULL,
115-
password TEXT NOT NULL,
116-
active TINYINT(1) NOT NULL DEFAULT '1',
117-
can_change_avatar BOOLEAN NOT NULL DEFAULT FALSE,
118-
CONSTRAINT users_username_uindex UNIQUE (username)
113+
username VARCHAR(16) PRIMARY KEY,
114+
display_name TEXT NULL,
115+
email TEXT NULL,
116+
quota TEXT NULL,
117+
home TEXT NULL,
118+
password TEXT NOT NULL,
119+
active TINYINT(1) NOT NULL DEFAULT '1',
120+
provide_avatar BOOLEAN NOT NULL DEFAULT FALSE
119121
);
120122
121123
CREATE TABLE sql_group
122124
(
123-
id INT AUTO_INCREMENT PRIMARY KEY,
124-
name VARCHAR(16) NOT NULL,
125+
name VARCHAR(16) PRIMARY KEY,
125126
display_name TEXT NULL,
126-
admin BOOLEAN NOT NULL DEFAULT FALSE,
127-
CONSTRAINT group_name_uindex UNIQUE (name)
127+
admin BOOLEAN NOT NULL DEFAULT FALSE
128128
);
129129
130130
CREATE TABLE sql_user_group
131131
(
132-
id INT AUTO_INCREMENT PRIMARY KEY,
133-
group_name VARCHAR(16) NOT NULL,
134132
username VARCHAR(16) NOT NULL,
135-
CONSTRAINT user_group_group_name_username_uindex UNIQUE (group_name, username),
136-
INDEX user_group_group_name_index (group_name),
137-
INDEX user_group_username_index (username)
133+
group_name VARCHAR(16) NOT NULL,
134+
PRIMARY KEY (username, group_name),
135+
FOREIGN KEY (username) REFERENCES sql_user (username),
136+
FOREIGN KEY (group_name) REFERENCES sql_group (name),
137+
INDEX sql_user_group_username_idx (username),
138+
INDEX sql_user_group_group_name_idx (group_name)
138139
);
139140
```
140141

@@ -148,7 +149,7 @@ User table: wp_users
148149
Username column: user_login
149150
Password column: user_pass
150151
151-
Hashing algorithm: Unix (Crypt)
152+
Hash algorithm: Unix (Crypt) or Portable PHP password
152153
```
153154

154155
#### JHipster
@@ -165,7 +166,7 @@ Password column: password_hash
165166
Email column: email
166167
Active column: activated
167168
168-
Hashing algorithm: Unix (Crypt)
169+
Hash algorithm: Unix (Crypt)
169170
```
170171

171172
## Hash algorithms
@@ -190,9 +191,12 @@ SHA512 (Crypt) | Generates hash with 5000 rounds. | $6$rounds=5000$yH.Q0OL4qbCOU
190191
Standard DES (Crypt) | | yTBnb7ab/N072
191192
Joomla MD5 Encryption | Generates 32 chars salt. | 14d21b49b0f13e2acba962b6b0039edd:haJK0yTvBXTNMh76xwEw5RYEVpJsN8us
192193
MD5 | No salt supported. | 5f4dcc3b5aa765d61d8327deb882cf99
194+
Portable PHP password | See [phpass](http://www.openwall.com/phpass/). | $P$BxrwraqNTi4as0EI.IpiA/K.muk9ke/
193195
SHA1 | No salt supported. | 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
196+
SHA512 Whirlpool | No salt supported. | a96b16ebb691dbe968b0d66d0d924cff5cf5de5e0885181d00761d87f295b2bf3d3c66187c050fc01c196ff3acaa48d3561ffd170413346e934a32280d632f2e
194197
SSHA256 | Generates 32 chars salt. | {SSHA256}+WxTB3JxprNteeovsuSYtgI+UkVPA9lfwGoYkz3Ff7hjd1FSdmlTMkNsSExyR21KM3NvNTZ5V0p4WXJMUjFzUg==
195198
SSHA512 | Generates 32 chars salt. | {SSHA512}It+v1kAEUBbhMJYJ2swAtz+RLE6ispv/FB6G/ALhK/YWwEmrloY+0jzrWIfmu+rWUXp8u0Tg4jLXypC5oXAW00IyYnRVdEZJbE9wak96bkNRVWFCYmlJNWxrdTA0QmhL
199+
WoltLab Community Framework 2.x | Double salted bcrypt. | $2a$08$XEQDKNU/Vbootwxv5Gp7gujxFX/RUFsZLvQPYM435Dd3/p17fto02
196200

197201
## Development
198202

@@ -202,7 +206,7 @@ Add a new class in the `OCA\UserSQL\Platform` namespace which extends the `Abstr
202206
Add this driver in `admin.php` template to `$drivers` variable and in method `getPlatform(Connection $connection)`
203207
of `PlatformFactory` class.
204208

205-
#### New hashing algorithm support
209+
#### New hash algorithm support
206210

207211
Create a new class in `OCA\UserSQL\Crypto` namespace which implements `IPasswordAlgorithm` interface.
208212
Do not forget to write unit tests.

appinfo/info.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
Retrieve the users and groups info. Allow the users to change their passwords.
99
Sync the users' email addresses with the addresses stored by Nextcloud.
1010
</description>
11-
<version>4.0.0-rc2</version>
11+
<version>4.0.0</version>
1212
<licence>agpl</licence>
13-
<author>Andreas Böhler &lt;dev (at) aboehler (dot) at&gt;</author>
14-
<author>Marcin Łojewski &lt;dev@mlojewski.me&gt;</author>
13+
<author>Marcin Łojewski</author>
14+
<author>Andreas Böhler</author>
1515
<namespace>UserSQL</namespace>
1616
<bugs>https://github.com/nextcloud/user_sql/issues</bugs>
1717
<repository>https://github.com/nextcloud/user_sql</repository>
@@ -22,7 +22,7 @@
2222
<category>auth</category>
2323
<dependencies>
2424
<php min-version="7.0"/>
25-
<nextcloud min-version="13" max-version="13"/>
25+
<nextcloud min-version="14" max-version="14"/>
2626
</dependencies>
2727
<settings>
2828
<admin>\OCA\UserSQL\Settings\Admin</admin>

img/screenshot.png

1.71 KB
Loading

js/settings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ user_sql.adminSettingsUI = function () {
4141
$(ids).autocomplete({
4242
source: function (request, response) {
4343
var post = $(form_id).serializeArray();
44+
post.push({name: "input", value: request["term"]});
4445
$.post(OC.generateUrl(path), post, response, "json");
4546
},
4647
minLength: 0,
@@ -75,7 +76,7 @@ user_sql.adminSettingsUI = function () {
7576
);
7677

7778
autocomplete(
78-
"#db-table-user-column-uid, #db-table-user-column-email, #db-table-user-column-home, #db-table-user-column-password, #db-table-user-column-name, #db-table-user-column-active, #db-table-user-column-avatar",
79+
"#db-table-user-column-uid, #db-table-user-column-email, #db-table-user-column-quota, #db-table-user-column-home, #db-table-user-column-password, #db-table-user-column-name, #db-table-user-column-active, #db-table-user-column-avatar, #db-table-user-column-salt",
7980
"/apps/user_sql/settings/autocomplete/table/user"
8081
);
8182

lib/Action/EmailSync.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function doAction(User $user)
9494
$result = false;
9595

9696
switch ($this->properties[Opt::EMAIL_SYNC]) {
97-
case App::EMAIL_INITIAL:
97+
case App::SYNC_INITIAL:
9898
if (empty($ncMail) && !empty($user->email)) {
9999
$this->config->setUserValue(
100100
$user->uid, "settings", "email", $user->email
@@ -103,7 +103,7 @@ public function doAction(User $user)
103103

104104
$result = true;
105105
break;
106-
case App::EMAIL_FORCE_NC:
106+
case App::SYNC_FORCE_NC:
107107
if (!empty($ncMail) && $user->email !== $ncMail) {
108108
$user = $this->userRepository->findByUid($user->uid);
109109
if (!($user instanceof User)) {
@@ -115,7 +115,7 @@ public function doAction(User $user)
115115
}
116116

117117
break;
118-
case App::EMAIL_FORCE_SQL:
118+
case App::SYNC_FORCE_SQL:
119119
if (!empty($user->email) && $user->email !== $ncMail) {
120120
$this->config->setUserValue(
121121
$user->uid, "settings", "email", $user->email

lib/Action/QuotaSync.php

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
/**
3+
* Nextcloud - user_sql
4+
*
5+
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
6+
* @author Marcin Łojewski <dev@mlojewski.me>
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
namespace OCA\UserSQL\Action;
23+
24+
use OCA\UserSQL\Constant\App;
25+
use OCA\UserSQL\Constant\Opt;
26+
use OCA\UserSQL\Model\User;
27+
use OCA\UserSQL\Properties;
28+
use OCA\UserSQL\Repository\UserRepository;
29+
use OCP\IConfig;
30+
use OCP\ILogger;
31+
32+
/**
33+
* Synchronizes the user quota.
34+
*
35+
* @author Marcin Łojewski <dev@mlojewski.me>
36+
*/
37+
class QuotaSync implements IUserAction
38+
{
39+
/**
40+
* @var string The application name.
41+
*/
42+
private $appName;
43+
/**
44+
* @var ILogger The logger instance.
45+
*/
46+
private $logger;
47+
/**
48+
* @var Properties The properties array.
49+
*/
50+
private $properties;
51+
/**
52+
* @var IConfig The config instance.
53+
*/
54+
private $config;
55+
/**
56+
* @var UserRepository The user repository.
57+
*/
58+
private $userRepository;
59+
60+
/**
61+
* The default constructor.
62+
*
63+
* @param string $appName The application name.
64+
* @param ILogger $logger The logger instance.
65+
* @param Properties $properties The properties array.
66+
* @param IConfig $config The config instance.
67+
* @param UserRepository $userRepository The user repository.
68+
*/
69+
public function __construct(
70+
$appName, ILogger $logger, Properties $properties, IConfig $config,
71+
UserRepository $userRepository
72+
) {
73+
$this->appName = $appName;
74+
$this->logger = $logger;
75+
$this->properties = $properties;
76+
$this->config = $config;
77+
$this->userRepository = $userRepository;
78+
}
79+
80+
/**
81+
* @inheritdoc
82+
* @throws \OCP\PreConditionNotMetException
83+
*/
84+
public function doAction(User $user)
85+
{
86+
$this->logger->debug(
87+
"Entering QuotaSync#doAction($user->uid)", ["app" => $this->appName]
88+
);
89+
90+
$ncQuota = $this->config->getUserValue(
91+
$user->uid, "files", "quota", ""
92+
);
93+
94+
$result = false;
95+
96+
switch ($this->properties[Opt::QUOTA_SYNC]) {
97+
case App::SYNC_INITIAL:
98+
if (empty($ncQuota) && !empty($user->quota)) {
99+
$this->config->setUserValue(
100+
$user->uid, "files", "quota", $user->quota
101+
);
102+
}
103+
104+
$result = true;
105+
break;
106+
case App::SYNC_FORCE_NC:
107+
if (!empty($ncQuota) && $user->quota !== $ncQuota) {
108+
$user = $this->userRepository->findByUid($user->uid);
109+
if (!($user instanceof User)) {
110+
break;
111+
}
112+
113+
$user->quota = $ncQuota;
114+
$result = $this->userRepository->save($user);
115+
}
116+
117+
break;
118+
case App::SYNC_FORCE_SQL:
119+
if (!empty($user->quota) && $user->quota !== $ncQuota) {
120+
$this->config->setUserValue(
121+
$user->uid, "files", "quota", $user->quota
122+
);
123+
}
124+
125+
$result = true;
126+
break;
127+
}
128+
129+
$this->logger->debug(
130+
"Returning QuotaSync#doAction($user->uid): " . ($result ? "true"
131+
: "false"),
132+
["app" => $this->appName]
133+
);
134+
135+
return $result;
136+
}
137+
}

0 commit comments

Comments
 (0)