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.

431 lines
19 KiB

9 months ago
9 months ago
9 months ago
5 years ago
9 months ago
9 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 -oP '(?<="code":)\d+')
  211. # Account has 2FA-OTP enabled, since error 403 reported.
  212. # https://global.download.synology.com/download/Document/Software/DeveloperGuide/Firmware/DSM/All/enu/Synology_DiskStation_Administration_CLI_Guide.pdf
  213. if [ "$error_code" == "403" ]; then
  214. if [ -z "$SYNO_DEVICE_NAME" ]; then
  215. printf "Enter device name or leave empty for default (CertRenewal): "
  216. read -r SYNO_DEVICE_NAME
  217. [ -n "$SYNO_DEVICE_NAME" ] || SYNO_DEVICE_NAME="CertRenewal"
  218. fi
  219. if [ -n "$SYNO_DEVICE_ID" ]; then
  220. # Omit OTP code with SYNO_DEVICE_ID.
  221. 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")
  222. _secure_debug3 response "$response"
  223. else
  224. # Require the OTP code if still unset.
  225. if [ -z "$SYNO_OTP_CODE" ]; then
  226. printf "Enter OTP code for user '%s': " "$SYNO_USERNAME"
  227. read -r SYNO_OTP_CODE
  228. fi
  229. _secure_debug SYNO_OTP_CODE "${SYNO_OTP_CODE:-}"
  230. if [ -z "$SYNO_OTP_CODE" ]; then
  231. response='{"error":{"code":404}}'
  232. else
  233. 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")
  234. _secure_debug3 response "$response"
  235. id_property='device_id'
  236. [ "${api_version}" -gt '6' ] || id_property='did'
  237. SYNO_DEVICE_ID=$(echo "$response" | grep "$id_property" | sed -n 's/.*"'$id_property'" *: *"\([^"]*\).*/\1/p')
  238. _secure_debug2 SYNO_DEVICE_ID "$SYNO_DEVICE_ID"
  239. fi
  240. fi
  241. error_code=$(echo "$response" | grep '"error"' | grep -oP '(?<="code":)\d+')
  242. fi
  243. if [ -n "$error_code" ]; then
  244. if [ "$error_code" == "403" ] && [ -n "$SYNO_DEVICE_ID" ]; then
  245. _cleardeployconf SYNO_DEVICE_ID
  246. _err "Failed to authenticate with SYNO_DEVICE_ID (may expired or invalid), please try again in a new terminal window."
  247. elif [ "$error_code" == "404" ]; then
  248. _err "Failed to authenticate with provided 2FA-OTP code, please try again in a new terminal window."
  249. elif [ "$error_code" == "406" ]; then
  250. if [ -n "$SYNO_USE_TEMP_ADMIN" ]; then
  251. _err "SYNO_USE_TEMP_ADMIN=1 is not supported if enforce auth with 2FA-OTP is enabled."
  252. else
  253. _err "Enforce auth with 2FA-OTP enabled, please configure the user to enable 2FA-OTP to continue."
  254. fi
  255. elif [ "$error_code" == "400" ] || [ "$error_code" == "401" ] || [ "$error_code" == "408" ] || [ "$error_code" == "409" ] || [ "$error_code" == "410" ]; then
  256. _err "Failed to authenticate with a non-existent or disabled account, or the account password is incorrect or has expired."
  257. else
  258. _err "Failed to authenticate with error: $error_code."
  259. fi
  260. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  261. return 1
  262. fi
  263. sid=$(echo "$response" | grep "sid" | sed -n 's/.*"sid" *: *"\([^"]*\).*/\1/p')
  264. token=$(echo "$response" | grep "synotoken" | sed -n 's/.*"synotoken" *: *"\([^"]*\).*/\1/p')
  265. _debug "Session ID" "$sid"
  266. _debug SynoToken "$token"
  267. if [ -z "$sid" ] || [ -z "$token" ]; then
  268. # Still can't get necessary info even got no errors, may Synology have API updated?
  269. _err "Unable to authenticate to $_base_url, you may report the full log to the community."
  270. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  271. return 1
  272. fi
  273. _H1="X-SYNO-TOKEN: $token"
  274. export _H1
  275. _debug2 H1 "${_H1}"
  276. # Now that we know the username and password are good, save them if not in temp admin mode.
  277. if [ -n "$SYNO_USE_TEMP_ADMIN" ]; then
  278. _cleardeployconf SYNO_USERNAME
  279. _cleardeployconf SYNO_PASSWORD
  280. _cleardeployconf SYNO_DEVICE_ID
  281. _cleardeployconf SYNO_DEVICE_NAME
  282. _savedeployconf SYNO_USE_TEMP_ADMIN "$SYNO_USE_TEMP_ADMIN"
  283. _savedeployconf SYNO_LOCAL_HOSTNAME "$SYNO_HOSTNAME"
  284. else
  285. _savedeployconf SYNO_USERNAME "$SYNO_USERNAME"
  286. _savedeployconf SYNO_PASSWORD "$SYNO_PASSWORD"
  287. _savedeployconf SYNO_DEVICE_ID "$SYNO_DEVICE_ID"
  288. _savedeployconf SYNO_DEVICE_NAME "$SYNO_DEVICE_NAME"
  289. fi
  290. _info "Getting certificates in Synology DSM..."
  291. response=$(_post "api=SYNO.Core.Certificate.CRT&method=list&version=1&_sid=$sid" "$_base_url/webapi/entry.cgi")
  292. _debug3 response "$response"
  293. escaped_certificate="$(printf "%s" "$SYNO_CERTIFICATE" | sed 's/\([].*^$[]\)/\\\1/g;s/"/\\\\"/g')"
  294. _debug escaped_certificate "$escaped_certificate"
  295. id=$(echo "$response" | sed -n "s/.*\"desc\":\"$escaped_certificate\",\"id\":\"\([^\"]*\).*/\1/p")
  296. _debug2 id "$id"
  297. error_code=$(echo "$response" | grep '"error"' | grep -oP '(?<="code":)\d+')
  298. if [ -n "$error_code" ]; then
  299. if [ "$error_code" -eq 105 ]; then
  300. _err "Current user is not administrator and does not have sufficient permission for deploying."
  301. else
  302. _err "Failed to fetch certificate info with error: $error_code, please try again or contact Synology to learn more."
  303. fi
  304. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  305. return 1
  306. fi
  307. _migratedeployconf SYNO_Create SYNO_CREATE
  308. _getdeployconf SYNO_CREATE
  309. _debug2 SYNO_CREATE "$SYNO_CREATE"
  310. if [ -z "$id" ] && [ -z "$SYNO_CREATE" ]; then
  311. _err "Unable to find certificate: $SYNO_CERTIFICATE and $SYNO_CREATE is not set."
  312. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  313. return 1
  314. fi
  315. # We've verified this certificate description is a thing, so save it
  316. _savedeployconf SYNO_CERTIFICATE "$SYNO_CERTIFICATE" "base64"
  317. _info "Generating form POST request..."
  318. nl="\0015\0012"
  319. delim="--------------------------$(_utc_date | tr -d -- '-: ')"
  320. content="--$delim${nl}Content-Disposition: form-data; name=\"key\"; filename=\"$(basename "$_ckey")\"${nl}Content-Type: application/octet-stream${nl}${nl}$(cat "$_ckey")\0012"
  321. 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"
  322. 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"
  323. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"id\"${nl}${nl}$id"
  324. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"desc\"${nl}${nl}${SYNO_CERTIFICATE}"
  325. if echo "$response" | sed -n "s/.*\"desc\":\"$escaped_certificate\",\([^{]*\).*/\1/p" | grep -- 'is_default":true' >/dev/null; then
  326. _debug2 default "This is the default certificate"
  327. content="$content${nl}--$delim${nl}Content-Disposition: form-data; name=\"as_default\"${nl}${nl}true"
  328. else
  329. _debug2 default "This is NOT the default certificate"
  330. fi
  331. content="$content${nl}--$delim--${nl}"
  332. content="$(printf "%b_" "$content")"
  333. content="${content%_}" # protect trailing \n
  334. _info "Upload certificate to the Synology DSM."
  335. 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}")
  336. _debug3 response "$response"
  337. if ! echo "$response" | grep '"error":' >/dev/null; then
  338. if echo "$response" | grep '"restart_httpd":true' >/dev/null; then
  339. _info "Restart HTTP services succeeded."
  340. else
  341. _info "Restart HTTP services failed."
  342. fi
  343. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  344. _logout
  345. return 0
  346. else
  347. _temp_admin_cleanup "$SYNO_USE_TEMP_ADMIN" "$SYNO_USERNAME"
  348. _err "Unable to update certificate, got error response: $response."
  349. _logout
  350. return 1
  351. fi
  352. }
  353. #################### Private functions below ##################################
  354. _logout() {
  355. # Logout CERT user only to not occupy a permanent session, e.g. in DSM's "Connected Users" widget (based on previous variables)
  356. response=$(_get "$_base_url/webapi/$api_path?api=SYNO.API.Auth&version=$api_version&method=logout&_sid=$sid")
  357. _debug3 response "$response"
  358. }
  359. _temp_admin_create() {
  360. _username="$1"
  361. _password="$2"
  362. synouser --del "$_username" >/dev/null 2>/dev/null
  363. synouser --add "$_username" "$_password" "" 0 "scruelt@hotmail.com" 0 >/dev/null
  364. }
  365. _temp_admin_cleanup() {
  366. _flag=$1
  367. _username=$2
  368. if [ -n "${_flag}" ]; then
  369. _debug "Cleanuping temp admin info..."
  370. synouser --del "$_username" >/dev/null
  371. fi
  372. }
  373. #_cleardeployconf key
  374. _cleardeployconf() {
  375. _cleardomainconf "SAVED_$1"
  376. }
  377. # key
  378. _check2cleardeployconfexp() {
  379. _key="$1"
  380. _clear_key="CLEAR_$_key"
  381. # Clear saved settings if explicitly requested
  382. if [ -n "$(eval echo \$"$_clear_key")" ]; then
  383. _debug2 "$_key: value cleared from config, exported value will be ignored."
  384. _cleardeployconf "$_key"
  385. eval "$_key"=
  386. export "$_key"=
  387. eval SAVED_"$_key"=
  388. export SAVED_"$_key"=
  389. fi
  390. }