Skip to content

Commit fe265eb

Browse files
authored
Merge branch 'develop' into develop-14
2 parents 657e5a7 + 4d48a58 commit fe265eb

58 files changed

Lines changed: 504 additions & 75 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: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88
### Added
9-
- SHA512 Whirlpool hashing algorithm
10-
- phpass hashing implementation
9+
- SHA512 Whirlpool hash algorithm
10+
- WoltLab Community Framework 2.x hash algorithm
11+
- phpass hash implementation
1112
- Support for salt column
13+
- User quota synchronization
14+
15+
### Changed
16+
- Example SQL script in README file
17+
- Fixed misspelling
1218

1319
### Changed
1420
- Support for Nextcloud 14 only
@@ -18,18 +24,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1824
### Fixed
1925
- Table and column autocomplete in settings panel
2026

21-
## [4.0.0-rc2]
27+
## [4.0.0-rc2] - 2018-06-14
2228
### Added
2329
- User active column
2430

2531
### Changed
2632
- Fixed "Use of undefined constant" error for Argon2 Crypt with PHP below 7.2.
2733

28-
## [4.0.0-rc1]
34+
## [4.0.0-rc1] - 2018-06-13
2935
### Added
30-
- New hashing algorithms: Argon2 Crypt (PHP 7.2 and above), Blowfish Crypt, Courier base64-encoded MD5, Courier base64-encoded SHA1,
31-
Courier base64-encoded SHA256, Courier hexadecimal MD5, Extended DES Crypt, SHA256 Crypt,
32-
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
3337
- Option to allow users to change their display names
3438
- Option to allow user to change its avatar
3539
- Database query results cache
@@ -40,10 +44,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4044
- The whole core implementation, which is NOT COMPATIBLE with the previous versions.
4145
- Minimum supported PHP version - 7.0
4246

43-
## Removed
44-
- MySQL ENCRYPT() hashing implementation - Function is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release.
45-
- MySQL PASSWORD() hashing implementation - Function is deprecated as of MySQL 5.7.6 and will be removed in a future MySQL release.
46-
- 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.
4751
- User active column - Use database view instead
4852
- Domain support
4953

README.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ 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.
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.
5556
**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*.
5657
**Home Location** | User storage path for the `static` *home mode*. | Mandatory if the *Home mode* is set to `Static`.
5758

@@ -64,11 +65,12 @@ 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.
7274
**Salt** | Salt which is appended to password when checking or changing the password. | Optional.
7375

7476
#### Group table
@@ -106,36 +108,34 @@ but be aware that some functionalities requires data changes (update queries).
106108

107109
If you don't have any database model yet you can use below tables (MySQL):
108110
```
109-
CREATE TABLE sql_users
111+
CREATE TABLE sql_user
110112
(
111-
id INT AUTO_INCREMENT PRIMARY KEY,
112-
username VARCHAR(16) NOT NULL,
113-
display_name TEXT NULL,
114-
email TEXT NULL,
115-
home TEXT NULL,
116-
password TEXT NOT NULL,
117-
active TINYINT(1) NOT NULL DEFAULT '1',
118-
can_change_avatar BOOLEAN NOT NULL DEFAULT FALSE,
119-
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
120121
);
121122
122123
CREATE TABLE sql_group
123124
(
124-
id INT AUTO_INCREMENT PRIMARY KEY,
125-
name VARCHAR(16) NOT NULL,
125+
name VARCHAR(16) PRIMARY KEY,
126126
display_name TEXT NULL,
127-
admin BOOLEAN NOT NULL DEFAULT FALSE,
128-
CONSTRAINT group_name_uindex UNIQUE (name)
127+
admin BOOLEAN NOT NULL DEFAULT FALSE
129128
);
130129
131130
CREATE TABLE sql_user_group
132131
(
133-
id INT AUTO_INCREMENT PRIMARY KEY,
134-
group_name VARCHAR(16) NOT NULL,
135132
username VARCHAR(16) NOT NULL,
136-
CONSTRAINT user_group_group_name_username_uindex UNIQUE (group_name, username),
137-
INDEX user_group_group_name_index (group_name),
138-
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)
139139
);
140140
```
141141

@@ -149,7 +149,7 @@ User table: wp_users
149149
Username column: user_login
150150
Password column: user_pass
151151
152-
Hashing algorithm: Unix (Crypt) or Portable PHP password
152+
Hash algorithm: Unix (Crypt) or Portable PHP password
153153
```
154154

155155
#### JHipster
@@ -166,7 +166,7 @@ Password column: password_hash
166166
Email column: email
167167
Active column: activated
168168
169-
Hashing algorithm: Unix (Crypt)
169+
Hash algorithm: Unix (Crypt)
170170
```
171171

172172
## Hash algorithms
@@ -196,6 +196,7 @@ SHA1 | No salt supported. | 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
196196
SHA512 Whirlpool | No salt supported. | a96b16ebb691dbe968b0d66d0d924cff5cf5de5e0885181d00761d87f295b2bf3d3c66187c050fc01c196ff3acaa48d3561ffd170413346e934a32280d632f2e
197197
SSHA256 | Generates 32 chars salt. | {SSHA256}+WxTB3JxprNteeovsuSYtgI+UkVPA9lfwGoYkz3Ff7hjd1FSdmlTMkNsSExyR21KM3NvNTZ5V0p4WXJMUjFzUg==
198198
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
199200

200201
## Development
201202

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

208-
#### New hashing algorithm support
209+
#### New hash algorithm support
209210

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

img/screenshot.png

1.71 KB
Loading

js/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ user_sql.adminSettingsUI = function () {
7676
);
7777

7878
autocomplete(
79-
"#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, #db-table-user-column-salt",
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",
8080
"/apps/user_sql/settings/autocomplete/table/user"
8181
);
8282

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+
}

lib/Backend/UserBackend.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use OCA\UserSQL\Action\EmailSync;
2525
use OCA\UserSQL\Action\IUserAction;
26+
use OCA\UserSQL\Action\QuotaSync;
2627
use OCA\UserSQL\Cache;
2728
use OCA\UserSQL\Constant\App;
2829
use OCA\UserSQL\Constant\DB;
@@ -130,6 +131,14 @@ private function initActions()
130131
$this->userRepository
131132
);
132133
}
134+
if (!empty($this->properties[Opt::QUOTA_SYNC])
135+
&& !empty($this->properties[DB::USER_QUOTA_COLUMN])
136+
) {
137+
$this->actions[] = new QuotaSync(
138+
$this->appName, $this->logger, $this->properties, $this->config,
139+
$this->userRepository
140+
);
141+
}
133142
}
134143

135144
/**

lib/Constant/App.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class App
3434
const HOME_QUERY = "query";
3535
const HOME_STATIC = "static";
3636

37-
const EMAIL_FORCE_NC = "force_nc";
38-
const EMAIL_FORCE_SQL = "force_sql";
39-
const EMAIL_INITIAL = "initial";
37+
const SYNC_FORCE_NC = "force_nc";
38+
const SYNC_FORCE_SQL = "force_sql";
39+
const SYNC_INITIAL = "initial";
4040
}

lib/Constant/DB.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ final class DB
5151
const USER_HOME_COLUMN = "db.table.user.column.home";
5252
const USER_NAME_COLUMN = "db.table.user.column.name";
5353
const USER_PASSWORD_COLUMN = "db.table.user.column.password";
54+
const USER_QUOTA_COLUMN = "db.table.user.column.quota";
5455
const USER_SALT_COLUMN = "db.table.user.column.salt";
5556
const USER_UID_COLUMN = "db.table.user.column.uid";
5657
}

lib/Constant/Opt.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ final class Opt
3434
const HOME_MODE = "opt.home_mode";
3535
const NAME_CHANGE = "opt.name_change";
3636
const PASSWORD_CHANGE = "opt.password_change";
37+
const QUOTA_SYNC = "opt.quota_sync";
3738
const USE_CACHE = "opt.use_cache";
3839
}

0 commit comments

Comments
 (0)