39
39
# ###############################################################################
40
40
# Dependencies:
41
41
# - curl
42
- # - synouser & synogroup (When available and SYNO_USE_TEMP_ADMIN is set )
42
+ # - synouser & synogroup & synosetkeyvalue (Required for SYNO_USE_TEMP_ADMIN=1 )
43
43
# ###############################################################################
44
44
# Return value:
45
45
# 0 means success, otherwise error.
@@ -66,14 +66,18 @@ synology_dsm_deploy() {
66
66
_getdeployconf SYNO_DEVICE_NAME
67
67
68
68
# Prepare to use temp admin if SYNO_USE_TEMP_ADMIN is set
69
- _debug2 SYNO_USE_TEMP_ADMIN " $SYNO_USE_TEMP_ADMIN "
70
69
_getdeployconf SYNO_USE_TEMP_ADMIN
71
70
_check2cleardeployconfexp SYNO_USE_TEMP_ADMIN
72
71
_debug2 SYNO_USE_TEMP_ADMIN " $SYNO_USE_TEMP_ADMIN "
73
72
74
73
if [ -n " $SYNO_USE_TEMP_ADMIN " ]; then
75
- if ! _exists synouser || ! _exists synogroup; then
76
- _err " Tools are missing for creating temp admin user, please set SYNO_USERNAME and SYNO_PASSWORD instead."
74
+ if ! _exists synouser || ! _exists synogroup || ! _exists synosetkeyvalue; then
75
+ _err " Missing required tools to creat temp admin user, please set SYNO_USERNAME and SYNO_PASSWORD instead."
76
+ _err " Notice: temp admin user authorization method only supports local deployment on DSM."
77
+ return 1
78
+ fi
79
+ if synouser --help 2>&1 | grep -q ' Permission denied' ; then
80
+ _err " For creating temp admin user, the deploy script must be run as root."
77
81
return 1
78
82
fi
79
83
@@ -169,7 +173,7 @@ synology_dsm_deploy() {
169
173
_debug3 H1 " ${_H1} "
170
174
fi
171
175
172
- response=$( _post " method=login&account=$encoded_username &passwd=$encoded_password &api=SYNO.API.Auth&version=$api_version &enable_syno_token=yes&otp_code=$DEPRECATED_otp_code &device_name=certrenewal&device_id=$SYNO_DEVICE_ID " " $_base_url /webapi/auth.cgi ?enable_syno_token=yes" )
176
+ response=$( _post " method=login&account=$encoded_username &passwd=$encoded_password &api=SYNO.API.Auth&version=$api_version &enable_syno_token=yes&otp_code=$DEPRECATED_otp_code &device_name=certrenewal&device_id=$SYNO_DEVICE_ID " " $_base_url /webapi/$api_path ?enable_syno_token=yes" )
173
177
_debug3 response " $response "
174
178
# ## END ## - DEPRECATED, for backward compatibility
175
179
# If SYNO_DEVICE_ID or SYNO_OTP_CODE is set, we treat current account enabled 2FA-OTP.
@@ -184,7 +188,7 @@ synology_dsm_deploy() {
184
188
_debug SYNO_LOCAL_HOSTNAME " ${SYNO_LOCAL_HOSTNAME:- } "
185
189
if [ " $SYNO_LOCAL_HOSTNAME " != " 1" ] && [ " $SYNO_LOCAL_HOSTNAME " == " $SYNO_HOSTNAME " ]; then
186
190
if [ " $SYNO_HOSTNAME " != " localhost" ] && [ " $SYNO_HOSTNAME " != " 127.0.0.1" ]; then
187
- _err " SYNO_USE_TEMP_ADMIN=1 Only support locally deployment, if you are sure that hostname $SYNO_HOSTNAME is targeting to your **current local machine**, execute 'export SYNO_LOCAL_HOSTNAME=1' then rerun."
191
+ _err " SYNO_USE_TEMP_ADMIN=1 only support local deployment, though if you are sure that the hostname $SYNO_HOSTNAME is targeting to your **current local machine**, execute 'export SYNO_LOCAL_HOSTNAME=1' then rerun."
188
192
return 1
189
193
fi
190
194
fi
@@ -201,24 +205,27 @@ synology_dsm_deploy() {
201
205
# shellcheck disable=SC2086
202
206
synogroup --member administrators $cur_admins $SYNO_USERNAME > /dev/null
203
207
else
204
- _err " Tool synogroup may be broken, please set SYNO_USERNAME and SYNO_PASSWORD instead."
208
+ _err " The tool synogroup may be broken, please set SYNO_USERNAME and SYNO_PASSWORD instead."
205
209
return 1
206
210
fi
207
211
else
208
212
_err " Unsupported synogroup tool detected, please set SYNO_USERNAME and SYNO_PASSWORD instead."
209
213
return 1
210
214
fi
211
- # havig a workaround to temporary disable enforce 2FA-OTP
215
+ # havig a workaround to temporary disable enforce 2FA-OTP, will restore
216
+ # it soon (after a single request), though if any accident occurs like
217
+ # unexpected interruption, this setting can be easily reverted manually.
212
218
otp_enforce_option=$( synogetkeyvalue /etc/synoinfo.conf otp_enforce_option)
213
219
if [ -n " $otp_enforce_option " ] && [ " ${otp_enforce_option:- " none" } " != " none" ]; then
214
220
synosetkeyvalue /etc/synoinfo.conf otp_enforce_option none
215
- _info " Temporary disabled enforce 2FA-OTP to complete authentication."
221
+ _info " Enforcing 2FA-OTP has been disabled to complete temp admin authentication."
222
+ _info " Notice: it will be restored soon, if not, you can restore it manually via Control Panel."
216
223
_info " previous_otp_enforce_option" " $otp_enforce_option "
217
224
else
218
225
otp_enforce_option=" "
219
226
fi
220
227
fi
221
- response=$( _get " $_base_url /webapi/entry.cgi ?api=SYNO.API.Auth&version=$api_version &method=login&format=sid&account=$encoded_username &passwd=$encoded_password &enable_syno_token=yes" )
228
+ response=$( _get " $_base_url /webapi/$api_path ?api=SYNO.API.Auth&version=$api_version &method=login&format=sid&account=$encoded_username &passwd=$encoded_password &enable_syno_token=yes" )
222
229
if [ -n " $SYNO_USE_TEMP_ADMIN " ] && [ -n " $otp_enforce_option " ]; then
223
230
synosetkeyvalue /etc/synoinfo.conf otp_enforce_option " $otp_enforce_option "
224
231
_info " Restored previous enforce 2FA-OTP option."
@@ -230,7 +237,7 @@ synology_dsm_deploy() {
230
237
error_code=$( echo " $response " | grep ' "error":' | grep -o ' "code":[0-9]*' | grep -o ' [0-9]*' )
231
238
_debug2 error_code " $error_code "
232
239
# Account has 2FA-OTP enabled, since error 403 reported.
233
- # https://global.download.synology.com/download/Document/Software/DeveloperGuide/Firmware /DSM/All/enu/Synology_DiskStation_Administration_CLI_Guide .pdf
240
+ # https://global.download.synology.com/download/Document/Software/DeveloperGuide/Os /DSM/All/enu/DSM_Login_Web_API_Guide_enu .pdf
234
241
if [ " $error_code " == " 403" ]; then
235
242
if [ -z " $SYNO_DEVICE_NAME " ]; then
236
243
printf " Enter device name or leave empty for default (CertRenewal): "
@@ -274,12 +281,16 @@ synology_dsm_deploy() {
274
281
_err " Failed to authenticate with provided 2FA-OTP code, please try again in a new terminal window."
275
282
elif [ " $error_code " == " 406" ]; then
276
283
if [ -n " $SYNO_USE_TEMP_ADMIN " ]; then
277
- _err " SYNO_USE_TEMP_ADMIN=1 is not supported if enforce auth with 2FA-OTP is enabled ."
284
+ _err " Failed with unexcepted error, please report this by providing full log with '--debug 3' ."
278
285
else
279
286
_err " Enforce auth with 2FA-OTP enabled, please configure the user to enable 2FA-OTP to continue."
280
287
fi
281
- elif [ " $error_code " == " 400" ] || [ " $error_code " == " 401" ] || [ " $error_code " == " 408" ] || [ " $error_code " == " 409" ] || [ " $error_code " == " 410" ]; then
282
- _err " Failed to authenticate with a non-existent or disabled account, or the account password is incorrect or has expired."
288
+ elif [ " $error_code " == " 400" ]; then
289
+ _err " Failed to authenticate, no such account or incorrect password."
290
+ elif [ " $error_code " == " 401" ]; then
291
+ _err " Failed to authenticate with a non-existent account."
292
+ elif [ " $error_code " == " 408" ] || [ " $error_code " == " 409" ] || [ " $error_code " == " 410" ]; then
293
+ _err " Failed to authenticate, the account password has expired or must be changed."
283
294
else
284
295
_err " Failed to authenticate with error: $error_code ."
285
296
fi
@@ -293,7 +304,7 @@ synology_dsm_deploy() {
293
304
_debug SynoToken " $token "
294
305
if [ -z " $sid " ] || [ -z " $token " ]; then
295
306
# Still can't get necessary info even got no errors, may Synology have API updated?
296
- _err " Unable to authenticate to $_base_url , you may report the full log to the community ."
307
+ _err " Unable to authenticate to $_base_url , you may report this by providing full log with '--debug 3' ."
297
308
_temp_admin_cleanup " $SYNO_USE_TEMP_ADMIN " " $SYNO_USERNAME "
298
309
return 1
299
310
fi
@@ -331,7 +342,7 @@ synology_dsm_deploy() {
331
342
if [ " $error_code " -eq 105 ]; then
332
343
_err " Current user is not administrator and does not have sufficient permission for deploying."
333
344
else
334
- _err " Failed to fetch certificate info with error : $error_code , please try again or contact Synology to learn more."
345
+ _err " Failed to fetch certificate info: $error_code , please try again or contact Synology to learn more."
335
346
fi
336
347
_temp_admin_cleanup " $SYNO_USE_TEMP_ADMIN " " $SYNO_USERNAME "
337
348
return 1
0 commit comments