mirror of
https://github.com/N4S4/synology-api.git
synced 2025-07-24 10:00:37 +00:00
Delete duplicated in core_sys_info.py:
- imports - users_info(), pasword_policy(), password_expiry() --> now in core_user.py Move password_confirm() from core_sys_info.py to core_user.py Update README.md Update requirements.txt --> Added cryptography module
This commit is contained in:
26
README.md
26
README.md
@ -272,6 +272,7 @@ This wrapper cover the following APIs for now:
|
||||
| SYNO.Core.User.Group |
|
||||
| SYNO.Core.User.PasswordPolicy |
|
||||
| SYNO.Core.User.PasswordExpiry |
|
||||
| SYNO.Core.User.PasswordConfirm|
|
||||
|
||||
| Snapshot Replication |
|
||||
|--------------------------|
|
||||
@ -538,10 +539,6 @@ DS info with below functions:
|
||||
| `ws_transfer_info()` |
|
||||
| `ref_link_copy_info()` |
|
||||
| `bonjour_service_info()` |
|
||||
| `users_info()` |
|
||||
| `password_policy()` |
|
||||
| `password_expiry()` |
|
||||
| `password_confirm()` |
|
||||
| `personal_photo_enable()` |
|
||||
| `ftp_chroot_user()` |
|
||||
| `server_pair()` |
|
||||
@ -594,16 +591,17 @@ DS info with below functions:
|
||||
### core_user (DSM User Settings)
|
||||
| Functions | Description |
|
||||
|----------------------------|-----------------------------------------------------------------|
|
||||
| `get_users()` | Retrieve groups information |
|
||||
| `create_user()` | Create a new user |
|
||||
| `modify_user()` | Modify a user |
|
||||
| `delete_user()` | Delete a user |
|
||||
| `affect_groups()` | Affect or disaffect groups to a user |
|
||||
| `affect_groups_status()` | Get the status of a join task |
|
||||
| `get_password_policy()` | Get the password policy |
|
||||
| `set_password_policy()` | Set the password policy |
|
||||
| `get_password_expiry()` | Get the password expiry |
|
||||
| `set_password_expiry()` | Set the password expiry |
|
||||
| `get_users()` | Retrieve groups information |
|
||||
| `create_user()` | Create a new user |
|
||||
| `modify_user()` | Modify a user |
|
||||
| `delete_user()` | Delete a user |
|
||||
| `affect_groups()` | Affect or disaffect groups to a user |
|
||||
| `affect_groups_status()` | Get the status of a join task |
|
||||
| `get_password_policy()` | Get the password policy |
|
||||
| `set_password_policy()` | Set the password policy |
|
||||
| `get_password_expiry()` | Get the password expiry |
|
||||
| `set_password_expiry()` | Set the password expiry |
|
||||
| `password_confirm()` | Confirm password match with current logged user |
|
||||
|
||||
### Virtualization
|
||||
| Functions |
|
||||
|
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@ -1,9 +1,6 @@
|
||||
from __future__ import annotations
|
||||
from typing import Optional
|
||||
from . import base_api
|
||||
from __future__ import annotations
|
||||
from typing import Optional
|
||||
from . import base_api
|
||||
|
||||
|
||||
class SysInfo(base_api.BaseApi):
|
||||
@ -774,62 +771,6 @@ class SysInfo(base_api.BaseApi):
|
||||
|
||||
return self.request_data(api_name, api_path, req_param)
|
||||
|
||||
def users_info(self, offset: int = 0, limit: int = -1) -> dict[str, object] | str:
|
||||
api_name = 'SYNO.Core.User'
|
||||
info = self.core_list[api_name]
|
||||
api_path = info['path']
|
||||
req_param = {'version': info['maxVersion'], 'method': 'list', 'type': 'local', 'offset': offset, 'limit': limit}
|
||||
|
||||
return self.request_data(api_name, api_path, req_param)
|
||||
|
||||
def password_policy(self) -> dict[str, object] | str:
|
||||
api_name = 'SYNO.Core.User.PasswordPolicy'
|
||||
info = self.core_list[api_name]
|
||||
api_path = info['path']
|
||||
req_param = {'version': info['maxVersion'], 'method': 'get'}
|
||||
|
||||
return self.request_data(api_name, api_path, req_param)
|
||||
|
||||
def password_expiry(self) -> dict[str, object] | str:
|
||||
api_name = 'SYNO.Core.User.PasswordExpiry'
|
||||
info = self.core_list[api_name]
|
||||
api_path = info['path']
|
||||
req_param = {'version': info['maxVersion'], 'method': 'get'}
|
||||
|
||||
return self.request_data(api_name, api_path, req_param)
|
||||
|
||||
def password_confirm(self, password: str) -> dict[str, object] | str:
|
||||
"""Issues a passowrd/session comparison to ensure the given password matches the auth of the current session.
|
||||
|
||||
This is needed by some APIs as a confirmation method, for example, when creating/modifying a scheduled task with root permissions.
|
||||
Please note that the password will be sent in plain text, just like in the base auth method.
|
||||
|
||||
Args:
|
||||
password (str):
|
||||
The password with which the session was initiated.
|
||||
|
||||
Returns:
|
||||
dict|str:
|
||||
A dictionary containing a `SynoConfirmPWToken`, or an error message.
|
||||
|
||||
Example return:
|
||||
{
|
||||
"data": {
|
||||
"SynoConfirmPWToken": "xxxxx"
|
||||
},
|
||||
"success": true
|
||||
}
|
||||
"""
|
||||
# There is a way to send the password encrypted, but could not figure out how the NAS wants the data to be encrypted.
|
||||
# It wants an AES and RSA key sent to it under the field "__cIpHeRtExT", tried some ways of implementing it,
|
||||
# but kept getting decryption errors in /var/log/synoscgi.log, so just went through with the plain text password.
|
||||
api_name = 'SYNO.Core.User.PasswordConfirm'
|
||||
info = self.core_list[api_name]
|
||||
api_path = info['path']
|
||||
req_param = {'version': 2, 'method': 'auth', 'password': password}
|
||||
|
||||
return self.request_data(api_name, api_path, req_param)
|
||||
|
||||
def personal_photo_enable(self) -> dict[str, object] | str:
|
||||
api_name = 'SYNO.Core.User.Home'
|
||||
info = self.core_list[api_name]
|
||||
|
@ -558,4 +558,40 @@ class User(base_api.BaseApi):
|
||||
"enable_mail_notification": enable_mail_notification,
|
||||
"never_expired_list": json.dumps(never_expired_list)
|
||||
}
|
||||
return self.request_data(api_name, api_path, req_param)
|
||||
return self.request_data(api_name, api_path, req_param)
|
||||
|
||||
|
||||
def password_confirm(self, password: str) -> dict[str, object] | str:
|
||||
"""Issues a passowrd/session comparison to ensure the given password matches the auth of the current session.
|
||||
|
||||
This is needed by some APIs as a confirmation method, for example, when creating/modifying a scheduled task with root permissions.
|
||||
Please note that the password will be sent in plain text, just like in the base auth method.
|
||||
|
||||
Args:
|
||||
password (str):
|
||||
The password with which the session was initiated.
|
||||
|
||||
Returns:
|
||||
dict|str:
|
||||
A dictionary containing a `SynoConfirmPWToken`, or an error message.
|
||||
|
||||
Example return:
|
||||
{
|
||||
"data": {
|
||||
"SynoConfirmPWToken": "xxxxx"
|
||||
},
|
||||
"success": true
|
||||
}
|
||||
"""
|
||||
api_name = 'SYNO.Core.User.PasswordConfirm'
|
||||
info = self.core_list[api_name]
|
||||
api_path = info['path']
|
||||
req_param = {'version': info['maxVersion'], 'method': 'auth'}
|
||||
# Using https
|
||||
if self.session._secure:
|
||||
req_param.update({"password": password})
|
||||
# Using http and self encrypted
|
||||
else:
|
||||
req_param.update(self.session.encrypt_params({"password": password}))
|
||||
|
||||
return self.request_data(api_name, api_path, req_param, method="post")
|
Reference in New Issue
Block a user