You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

434 lines
20 KiB

10 months ago
10 months ago
10 months ago
5 years ago
10 months ago
10 months ago
  1. #!/bin/bash
  2. ################################################################################
  3. # ACME.sh 3rd party deploy plugin for Synology DSM
  4. ################################################################################
  5. # Authors: Brian Hartvigsen (creator), https://github.com/tresni
  6. # Martin Arndt (contributor), https://troublezone.net/
  7. # Updated: 2023-07-03
  8. # Issues: https://github.com/acmesh-official/acme.sh/issues/2727
  9. ################################################################################
  10. # Usage (shown values are the examples):
  11. # 1. Set required environment variables:
  12. # - use automatically created temp admin user to authenticate
  13. # export SYNO_USE_TEMP_ADMIN=1
  14. # - or provide your own admin user credential to authenticate
  15. # 1. export SYNO_USERNAME="adminUser"
  16. # 2. export SYNO_PASSWORD="adminPassword"
  17. # 2. Set optional environment variables
  18. # - common optional variables
  19. # - export SYNO_SCHEME="http" - defaults to "http"
  20. # - export SYNO_HOSTNAME="localhost" - defaults to "localhost"
  21. # - export SYNO_PORT="5000" - defaults to "5000"
  22. # - export SYNO_CREATE=1 - to allow creating the cert if it doesn't exist
  23. # - export SYNO_CERTIFICATE="" - to replace a specific cert by its
  24. # description
  25. # - temp admin optional variables
  26. # - export SYNO_LOCAL_HOSTNAME=1 - if set to 1, force to treat hostname is
  27. # targeting current local machine (since
  28. # this method only locally supported)
  29. # - exsiting admin 2FA-OTP optional variables
  30. # - export SYNO_OTP_CODE="XXXXXX" - if set, script won't require to
  31. # interactive input the OTP code
  32. # - export SYNO_DEVICE_NAME="CertRenewal" - if set, script won't require to
  33. # interactive input the device name
  34. # - export SYNO_DEVICE_ID="" - (deprecated, auth with OTP code instead)
  35. # required for omitting 2FA-OTP
  36. # 3. Run command:
  37. # acme.sh --deploy --deploy-hook synology_dsm -d example.com
  38. ################################################################################
  39. # Dependencies:
  40. # - curl
  41. # - synouser & synogroup (When available and SYNO_USE_TEMP_ADMIN is set)
  42. ################################################################################
  43. # Return value:
  44. # 0 means success, otherwise error.
  45. ################################################################################
  46. ########## Public functions ####################################################
  47. #domain keyfile certfile cafile fullchain
  48. synology_dsm_deploy() {
  49. _cdomain="$1"
  50. _ckey="$2"
  51. _ccert="$3"
  52. _cca="$4"
  53. _debug _cdomain "$_cdomain"
  54. # Get username and password, but don't save until we authenticated successfully
  55. _migratedeployconf SYNO_Username SYNO_USERNAME
  56. _migratedeployconf SYNO_Password SYNO_PASSWORD
  57. _migratedeployconf SYNO_Device_ID SYNO_DEVICE_ID
  58. _migratedeployconf SYNO_Device_Name SYNO_DEVICE_NAME
  59. _getdeployconf SYNO_USERNAME
  60. _getdeployconf SYNO_PASSWORD
  61. _getdeployconf SYNO_DEVICE_ID
  62. _getdeployconf SYNO_DEVICE_NAME
  63. # Prepare to use temp admin if SYNO_USE_TEMP_ADMIN is set
  64. _debug2 SYNO_USE_TEMP_ADMIN "$SYNO_USE_TEMP_ADMIN"
  65. _getdeployconf SYNO_USE_TEMP_ADMIN
  66. _check2cleardeployconfexp SYNO_USE_TEMP_ADMIN
  67. _debug2 SYNO_USE_TEMP_ADMIN "$SYNO_USE_TEMP_ADMIN"
  68. if [ -n "$SYNO_USE_TEMP_ADMIN" ]; then
  69. if ! _exists synouser || ! _exists synogroup; then
  70. _err "Tools are missing for creating temp admin user, please set SYNO_USERNAME and SYNO_PASSWORD instead."
  71. return 1
  72. fi
  73. [ -n "$SYNO_USERNAME" ] || _savedeployconf SYNO_USERNAME ""
  74. [ -n "$SYNO_PASSWORD" ] || _savedeployconf SYNO_PASSWORD ""
  75. _debug "Setting temp admin user credential..."
  76. SYNO_USERNAME=sc-acmesh-tmp
  77. SYNO_PASSWORD=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16)
  78. # Set 2FA-OTP settings to empty consider they won't be needed.
  79. SYNO_DEVICE_ID=
  80. SYNO_DEVICE_NAME=
  81. SYNO_OTP_CODE=
  82. else
  83. _debug2 SYNO_USERNAME "$SYNO_USERNAME"
  84. _secure_debug2 SYNO_PASSWORD "$SYNO_PASSWORD"
  85. _debug2 SYNO_DEVICE_NAME "$SYNO_DEVICE_NAME"
  86. _secure_debug2 SYNO_DEVICE_ID "$SYNO_DEVICE_ID"
  87. fi
  88. if [ -z "$SYNO_USERNAME" ] || [ -z "$SYNO_PASSWORD" ]; then
  89. _err "You must set either SYNO_USE_TEMP_ADMIN, or set both SYNO_USERNAME and SYNO_PASSWORD."
  90. return 1
  91. fi
  92. # Optional scheme, hostname and port for Synology DSM
  93. _migratedeployconf SYNO_Scheme SYNO_SCHEME
  94. _migratedeployconf SYNO_Hostname SYNO_HOSTNAME
  95. _migratedeployconf SYNO_Port SYNO_PORT
  96. _getdeployconf SYNO_SCHEME
  97. _getdeployconf SYNO_HOSTNAME
  98. _getdeployconf SYNO_PORT
  99. # Default values for scheme, hostname and port
  100. # Defaulting to localhost and http, because it's localhost…
  101. [ -n "$SYNO_SCHEME" ] || SYNO_SCHEME="http"
  102. [ -n "$SYNO_HOSTNAME" ] || SYNO_HOSTNAME="localhost"
  103. [ -n "$SYNO_PORT" ] || SYNO_PORT="5000"
  104. _savedeployconf SYNO_SCHEME "$SYNO_SCHEME"
  105. _savedeployconf SYNO_HOSTNAME "$SYNO_HOSTNAME"
  106. _savedeployconf SYNO_PORT "$SYNO_PORT"
  107. _debug2 SYNO_SCHEME "$SYNO_SCHEME"
  108. _debug2 SYNO_HOSTNAME "$SYNO_HOSTNAME"
  109. _debug2 SYNO_PORT "$SYNO_PORT"
  110. # Get the certificate description, but don't save it until we verify it's real
  111. _migratedeployconf SYNO_Certificate SYNO_CERTIFICATE "base64"
  112. _getdeployconf SYNO_CERTIFICATE
  113. _check2cleardeployconfexp SYNO_CERTIFICATE
  114. _debug SYNO_CERTIFICATE "${SYNO_CERTIFICATE:-}"
  115. # shellcheck disable=SC1003 # We are not trying to escape a single quote
  116. if printf "%s" "$SYNO_CERTIFICATE" | grep '\\'; then
  117. _err "Do not use a backslash (\) in your certificate description"
  118. return 1
  119. fi
  120. _debug "Getting API version..."
  121. _base_url="$SYNO_SCHEME://$SYNO_HOSTNAME:$SYNO_PORT"
  122. _debug _base_url "$_base_url"
  123. response=$(_get "$_base_url/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query&query=SYNO.API.Auth")
  124. api_path=$(echo "$response" | grep "SYNO.API.Auth" | sed -n 's/.*"path" *: *"\([^"]*\)".*/\1/p')
  125. api_version=$(echo "$response" | grep "SYNO.API.Auth" | sed -n 's/.*"maxVersion" *: *\([0-9]*\).*/\1/p')
  126. _debug3 response "$response"
  127. _debug3 api_path "$api_path"
  128. _debug3 api_version "$api_version"
  129. # Login, get the session ID and SynoToken from JSON
  130. _info "Logging into $SYNO_HOSTNAME:$SYNO_PORT..."
  131. encoded_username="$(printf "%s" "$SYNO_USERNAME" | _url_encode)"
  132. encoded_password="$(printf "%s" "$SYNO_PASSWORD" | _url_encode)"
  133. # ## START ## - DEPRECATED, for backward compatibility
  134. _getdeployconf SYNO_TOTP_SECRET
  135. if [ -n "$SYNO_TOTP_SECRET" ]; then
  136. _info "WARNING: Usage of SYNO_TOTP_SECRET is deprecated!"
  137. _info " See synology_dsm.sh script or ACME.sh Wiki page for details:"
  138. _info " https://github.com/acmesh-official/acme.sh/wiki/Synology-NAS-Guide"
  139. if ! _exists oathtool; then
  140. _err "oathtool could not be found, install oathtool to use SYNO_TOTP_SECRET"
  141. return 1
  142. fi
  143. DEPRECATED_otp_code="$(oathtool --base32 --totp "$SYNO_TOTP_SECRET" 2>/dev/null)"
  144. if [ -z "$SYNO_DEVICE_ID" ]; then
  145. _getdeployconf SYNO_DID
  146. [ -n "$SYNO_DID" ] || SYNO_DEVICE_ID="$SYNO_DID"
  147. fi
  148. if [ -n "$SYNO_DEVICE_ID" ]; then
  149. _H1="Cookie: did=$SYNO_DEVICE_ID"
  150. export _H1
  151. _debug3 H1 "${_H1}"
  152. fi
  153. 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")
  154. _debug3 response "$response"
  155. # ## END ## - DEPRECATED, for backward compatibility
  156. # If SYNO_DEVICE_ID or SYNO_OTP_CODE is set, we treat current account enabled 2FA-OTP.
  157. # Notice that if SYNO_USE_TEMP_ADMIN=1, both variables will be unset
  158. else
  159. if [ -n "$SYNO_DEVICE_ID" ] || [ -n "$SYNO_OTP_CODE" ]; then
  160. response='{"error":{"code":403}}'
  161. # Assume the current account disabled 2FA-OTP, try to log in right away.
  162. else
  163. if [ -n "$SYNO_USE_TEMP_ADMIN" ]; then
  164. _getdeployconf SYNO_LOCAL_HOSTNAME
  165. _debug SYNO_LOCAL_HOSTNAME "${SYNO_LOCAL_HOSTNAME:-}"
  166. if [ "$SYNO_LOCAL_HOSTNAME" != "1" ] && [ "$SYNO_LOCAL_HOSTNAME" == "$SYNO_HOSTNAME" ]; then
  167. if [ "$SYNO_HOSTNAME" != "localhost" ] && [ "$SYNO_HOSTNAME" != "127.0.0.1" ]; then
  168. _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."
  169. return 1
  170. fi
  171. fi
  172. _debug "Creating temp admin user in Synology DSM..."
  173. if synogroup --help | grep -q '\-\-memberadd '; then
  174. _temp_admin_create "$SYNO_USERNAME" "$SYNO_PASSWORD"
  175. synogroup --memberadd administrators "$SYNO_USERNAME" >/dev/null
  176. elif synogroup --help | grep -q '\-\-member '; then
  177. # For supporting DSM 6.x which only has `--member` parameter.
  178. cur_admins=$(synogroup --get administrators | awk -F '[][]' '/Group Members/,0{if(NF>1)printf "%s ", $2}')
  179. if [ -n "$cur_admins" ]; then
  180. _temp_admin_create "$SYNO_USERNAME" "$SYNO_PASSWORD"
  181. _secure_debug3 admin_users "$cur_admins$SYNO_USERNAME"
  182. # shellcheck disable=SC2086
  183. synogroup --member administrators $cur_admins $SYNO_USERNAME >/dev/null
  184. else
  185. _err "Tool synogroup may be broken, please set SYNO_USERNAME and SYNO_PASSWORD instead."
  186. return 1
  187. fi
  188. else
  189. _err "Unsupported synogroup tool detected, please set SYNO_USERNAME and SYNO_PASSWORD instead."
  190. return 1
  191. fi
  192. # havig a workaround to temporary disable enforce 2FA-OTP
  193. otp_enforce_option=$(synogetkeyvalue /etc/synoinfo.conf otp_enforce_option)
  194. if [ -n "$otp_enforce_option" ] && [ "${otp_enforce_option:-"none"}" != "none" ]; then
  195. synosetkeyvalue /etc/synoinfo.conf otp_enforce_option none
  196. _info "Temporary disabled enforce 2FA-OTP to complete authentication."
  197. _info "previous_otp_enforce_option" "$otp_enforce_option"
  198. else
  199. otp_enforce_option=""
  200. fi
  201. fi
  202. 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")
  203. if [ -n "$SYNO_USE_TEMP_ADMIN" ] && [ -n "$otp_enforce_option" ]; then
  204. synosetkeyvalue /etc/synoinfo.conf otp_enforce_option "$otp_enforce_option"
  205. _info "Restored previous enforce 2FA-OTP option."
  206. fi
  207. _debug3 response "$response"
  208. fi
  209. fi
  210. error_code=$(echo "$response" | grep '"error":' | grep -o '"code":[0-9]*' | grep -o '[0-9]*')
  211. _debug2 error_code "$error_code"
  212. # Account has 2FA-OTP enabled, since error 403 reported.
  213. # https://global.download.synology.com/download/Document/Software/DeveloperGuide/Firmware/DSM/All/enu/Synology_DiskStation_Administration_CLI_Guide.pdf
  214. if [ "$error_code" == "403" ]; then
  215. if [ -z "$SYNO_DEVICE_NAME" ]; then
  216. printf "Enter device name or leave empty for default (CertRenewal): "
  217. read -r SYNO_DEVICE_NAME
  218. [ -n "$SYNO_DEVICE_NAME" ] || SYNO_DEVICE_NAME="CertRenewal"
  219. fi
  220. if [ -n "$SYNO_DEVICE_ID" ]; then
  221. # Omit OTP code with SYNO_DEVICE_ID.
  222. 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&device_name=$SYNO_DEVICE_NAME&device_id=$SYNO_DEVICE_ID")
  223. _secure_debug3 response "$response"
  224. else
  225. # Require the OTP code if still unset.
  226. if [ -z "$SYNO_OTP_CODE" ]; then
  227. printf "Enter OTP code for user '%s': " "$SYNO_USERNAME"
  228. read -r SYNO_OTP_CODE
  229. fi
  230. _secure_debug SYNO_OTP_CODE "${SYNO_OTP_CODE:-}"
  231. if [ -z "$SYNO_OTP_CODE" ]; then
  232. response='{"error":{"code":404}}'
  233. else
  234. 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&enable_device_token=yes&device_name=$SYNO_DEVICE_NAME&otp_code=$SYNO_OTP_CODE")
  235. _secure_debug3 response "$response"
  236. id_property='device_id'
  237. [ "${api_version}" -gt '6' ] || id_property='did'
  238. SYNO_DEVICE_ID=$(echo "$response" | grep "$id_property" | sed -n 's/.*"'$id_property'" *: *"\([^"]*\).*/\1/p')
  239. _secure_debug2 SYNO_DEVICE_ID "$SYNO_DEVICE_ID"
  240. fi
  241. fi
  242. error_code=$(echo "$response" | grep '"error":' | grep -o '"code":[0-9]*' | grep -o '[0-9]*')
  243. _debug2 error_code "$error_code"
  244. fi
  245. if [ -n "$error_code" ]; then
  246. if [ "$error_code" == "403" ] && [ -n "$SYNO_DEVICE_ID" ]; then
  247. _cleardeployconf SYNO_DEVICE_ID
  248. _err "Failed to authenticate with SYNO_DEVICE_ID (may expired or invalid), please try again in a new terminal window."
  249. elif [ "$error_code" == "404" ]; then
  250. _err "Failed to authenticate with provided 2FA-OTP code, please try again in a new terminal window."
  251. elif [ "$error_code" == "406" ]; then
  252. if [ -n "$SYNO_USE_TEMP_ADMIN" ]; then
  253. _err "SYNO_USE_TEMP_ADMIN=1 is not supported if enforce auth with 2FA-OTP is enabled."
  254. else
  255. _err "Enforce auth with 2FA-OTP enabled, please configure the user to enable 2FA-OTP to continue."
  256. fi
  257. elif [ "$error_code" == "400" ] || [ "$error_code" == "401" ] || [ "$error_code" == "408" ] || [ "$error_code" == "409" ] || [ "$error_code" == "410" ]; then
  258. _err "Failed to authenticate with a non-existent or disabled account, or the account password is incorrect or has expired."
  259. else
  260. _err "Failed to authenticate with error: $error_code."
  261. fi
  262. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  263. return 1
  264. fi
  265. sid=$(echo "$response" | grep "sid" | sed -n 's/.*"sid" *: *"\([^"]*\).*/\1/p')
  266. token=$(echo "$response" | grep "synotoken" | sed -n 's/.*"synotoken" *: *"\([^"]*\).*/\1/p')
  267. _debug "Session ID" "$sid"
  268. _debug SynoToken "$token"
  269. if [ -z "$sid" ] || [ -z "$token" ]; then
  270. # Still can't get necessary info even got no errors, may Synology have API updated?
  271. _err "Unable to authenticate to $_base_url, you may report the full log to the community."
  272. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  273. return 1
  274. fi
  275. _H1="X-SYNO-TOKEN: $token"
  276. export _H1
  277. _debug2 H1 "${_H1}"
  278. # Now that we know the username and password are good, save them if not in temp admin mode.
  279. if [ -n "$SYNO_USE_TEMP_ADMIN" ]; then
  280. _cleardeployconf SYNO_USERNAME
  281. _cleardeployconf SYNO_PASSWORD
  282. _cleardeployconf SYNO_DEVICE_ID
  283. _cleardeployconf SYNO_DEVICE_NAME
  284. _savedeployconf SYNO_USE_TEMP_ADMIN "$SYNO_USE_TEMP_ADMIN"
  285. _savedeployconf SYNO_LOCAL_HOSTNAME "$SYNO_HOSTNAME"
  286. else
  287. _savedeployconf SYNO_USERNAME "$SYNO_USERNAME"
  288. _savedeployconf SYNO_PASSWORD "$SYNO_PASSWORD"
  289. _savedeployconf SYNO_DEVICE_ID "$SYNO_DEVICE_ID"
  290. _savedeployconf SYNO_DEVICE_NAME "$SYNO_DEVICE_NAME"
  291. fi
  292. _info "Getting certificates in Synology DSM..."
  293. response=$(_post "api=SYNO.Core.Certificate.CRT&method=list&version=1&_sid=$sid" "$_base_url/webapi/entry.cgi")
  294. _debug3 response "$response"
  295. escaped_certificate="$(printf "%s" "$SYNO_CERTIFICATE" | sed 's/\([].*^$[]\)/\\\1/g;s/"/\\\\"/g')"
  296. _debug escaped_certificate "$escaped_certificate"
  297. id=$(echo "$response" | sed -n "s/.*\"desc\":\"$escaped_certificate\",\"id\":\"\([^\"]*\).*/\1/p")
  298. _debug2 id "$id"
  299. error_code=$(echo "$response" | grep '"error":' | grep -o '"code":[0-9]*' | grep -o '[0-9]*')
  300. _debug2 error_code "$error_code"
  301. if [ -n "$error_code" ]; then
  302. if [ "$error_code" -eq 105 ]; then
  303. _err "Current user is not administrator and does not have sufficient permission for deploying."
  304. else
  305. _err "Failed to fetch certificate info with error: $error_code, please try again or contact Synology to learn more."
  306. fi
  307. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  308. return 1
  309. fi
  310. _migratedeployconf SYNO_Create SYNO_CREATE
  311. _getdeployconf SYNO_CREATE
  312. _debug2 SYNO_CREATE "$SYNO_CREATE"
  313. if [ -z "$id" ] && [ -z "$SYNO_CREATE" ]; then
  314. _err "Unable to find certificate: $SYNO_CERTIFICATE and $SYNO_CREATE is not set."
  315. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  316. return 1
  317. fi
  318. # We've verified this certificate description is a thing, so save it
  319. _savedeployconf SYNO_CERTIFICATE "$SYNO_CERTIFICATE" "base64"
  320. _info "Generating form POST request..."
  321. nl="\0015\0012"
  322. delim="--------------------------$(_utc_date | tr -d -- '-: ')"
  323. content="--$delim${nl}Content-Disposition: form-data; name=\"key\"; filename=\"$(basename "$_ckey")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_ckey")\0012"
  324. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"cert\"; filename=\"$(basename "$_ccert")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_ccert")\0012"
  325. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"inter_cert\"; filename=\"$(basename "$_cca")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_cca")\0012"
  326. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"id\"${nl}${nl}$id"
  327. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"desc\"${nl}${nl}${SYNO_CERTIFICATE}"
  328. if echo "$response" | sed -n "s/.*\"desc\":\"$escaped_certificate\",\([^{]*\).*/\1/p" | grep -- 'is_default":true' >/dev/null; then
  329. _debug2 default "This is the default certificate"
  330. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"as_default\"${nl}${nl}true"
  331. else
  332. _debug2 default "This is NOT the default certificate"
  333. fi
  334. content="$content${nl}--$delim--${nl}"
  335. content="$(printf "%b_" "$content")"
  336. content="${content%_}" # protect trailing \n
  337. _info "Upload certificate to the Synology DSM."
  338. response=$(_post "$content" "$_base_url/webapi/entry.cgi?api=SYNO.Core.Certificate&method=import&version=1&SynoToken=$token&_sid=$sid" "" "POST" "multipart/form-data; boundary=${delim}")
  339. _debug3 response "$response"
  340. if ! echo "$response" | grep '"error":' >/dev/null; then
  341. if echo "$response" | grep '"restart_httpd":true' >/dev/null; then
  342. _info "Restart HTTP services succeeded."
  343. else
  344. _info "Restart HTTP services failed."
  345. fi
  346. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  347. _logout
  348. return 0
  349. else
  350. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  351. _err "Unable to update certificate, got error response: $response."
  352. _logout
  353. return 1
  354. fi
  355. }
  356. #################### Private functions below ##################################
  357. _logout() {
  358. # Logout CERT user only to not occupy a permanent session, e.g. in DSM's "Connected Users" widget (based on previous variables)
  359. response=$(_get "$_base_url/webapi/$api_path?api=SYNO.API.Auth&version=$api_version&method=logout&_sid=$sid")
  360. _debug3 response "$response"
  361. }
  362. _temp_admin_create() {
  363. _username="$1"
  364. _password="$2"
  365. synouser --del "$_username" >/dev/null 2>/dev/null
  366. synouser --add "$_username" "$_password" "" 0 "scruelt@hotmail.com" 0 >/dev/null
  367. }
  368. _temp_admin_cleanup() {
  369. _flag=$1
  370. _username=$2
  371. if [ -n "${_flag}" ]; then
  372. _debug "Cleanuping temp admin info..."
  373. synouser --del "$_username" >/dev/null
  374. fi
  375. }
  376. #_cleardeployconf key
  377. _cleardeployconf() {
  378. _cleardomainconf "SAVED_$1"
  379. }
  380. # key
  381. _check2cleardeployconfexp() {
  382. _key="$1"
  383. _clear_key="CLEAR_$_key"
  384. # Clear saved settings if explicitly requested
  385. if [ -n "$(eval echo \$"$_clear_key")" ]; then
  386. _debug2 "$_key: value cleared from config, exported value will be ignored."
  387. _cleardeployconf "$_key"
  388. eval "$_key"=
  389. export "$_key"=
  390. eval SAVED_"$_key"=
  391. export SAVED_"$_key"=
  392. fi
  393. }