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.

110 lines
3.1 KiB

  1. #!/usr/bin/env bash
  2. # Here is a script to deploy cert to Ruckus Zone Director/Unleashed.
  3. #
  4. # Adapted from:
  5. # https://ms264556.net/pages/PfSenseLetsEncryptToRuckus
  6. #
  7. # ```sh
  8. # acme.sh --deploy -d ruckus.example.com --deploy-hook ruckus
  9. # ```
  10. #
  11. # Then you need to set the environment variables for the
  12. # deploy script to work.
  13. #
  14. # ```sh
  15. # export RUCKUS_HOST=ruckus.example.com
  16. # export RUCKUS_USER=myruckususername
  17. # export RUCKUS_PASS=myruckuspassword
  18. #
  19. # acme.sh --deploy -d ruckus.example.com --deploy-hook ruckus
  20. # ```
  21. #
  22. # returns 0 means success, otherwise error.
  23. ######## Public functions #####################
  24. #domain keyfile certfile cafile fullchain
  25. ruckus_deploy() {
  26. _cdomain="$1"
  27. _ckey="$2"
  28. _ccert="$3"
  29. _cca="$4"
  30. _cfullchain="$5"
  31. _err_code=0
  32. _debug _cdomain "$_cdomain"
  33. _debug _ckey "$_ckey"
  34. _debug _ccert "$_ccert"
  35. _debug _cca "$_cca"
  36. _debug _cfullchain "$_cfullchain"
  37. _getdeployconf RUCKUS_HOST
  38. _getdeployconf RUCKUS_USER
  39. _getdeployconf RUCKUS_PASS
  40. if [ -z "$RUCKUS_HOST" ]; then
  41. _debug "Using _cdomain as RUCKUS_HOST, please set if not correct."
  42. RUCKUS_HOST="$_cdomain"
  43. fi
  44. if [ -z "$RUCKUS_USER" ]; then
  45. _err "Need to set the env variable RUCKUS_USER"
  46. return 1
  47. fi
  48. if [ -z "$RUCKUS_PASS" ]; then
  49. _err "Need to set the env variable RUCKUS_PASS"
  50. return 1
  51. fi
  52. _savedeployconf RUCKUS_HOST "$RUCKUS_HOST"
  53. _savedeployconf RUCKUS_USER "$RUCKUS_USER"
  54. _savedeployconf RUCKUS_PASS "$RUCKUS_PASS"
  55. _debug RUCKUS_HOST "$RUCKUS_HOST"
  56. _debug RUCKUS_USER "$RUCKUS_USER"
  57. _debug RUCKUS_PASS "$RUCKUS_PASS"
  58. COOKIE_JAR=$(mktemp)
  59. cleanup() {
  60. rm $COOKIE_JAR
  61. }
  62. trap cleanup EXIT
  63. LOGIN_URL=$(curl https://$RUCKUS_HOST -ksSLo /dev/null -w '%{url_effective}')
  64. _debug LOGIN_URL "$LOGIN_URL"
  65. XSS=$(curl -ksSic $COOKIE_JAR $LOGIN_URL -d username=$RUCKUS_USER -d password="$RUCKUS_PASS" -d ok='Log In' | awk '/^HTTP_X_CSRF_TOKEN:/ { print $2 }' | tr -d '\040\011\012\015')
  66. _debug XSS "$XSS"
  67. if [ -n "$XSS" ]; then
  68. _info "Authentication successful"
  69. else
  70. _err "Authentication failed"
  71. return 1
  72. fi
  73. BASE_URL=$(dirname $LOGIN_URL)
  74. CONF_ARGS="-ksSo /dev/null -b $COOKIE_JAR -c $COOKIE_JAR"
  75. UPLOAD="$CONF_ARGS $BASE_URL/_upload.jsp?request_type=xhr"
  76. CMD="$CONF_ARGS $BASE_URL/_cmdstat.jsp"
  77. REPLACE_CERT_AJAX='<ajax-request action="docmd" comp="system" updater="rid.0.5" xcmd="replace-cert" checkAbility="6" timeout="-1"><xcmd cmd="replace-cert" cn="'$RUCKUS_HOST'"/></ajax-request>'
  78. CERT_REBOOT_AJAX='<ajax-request action="docmd" comp="worker" updater="rid.0.5" xcmd="cert-reboot" checkAbility="6"><xcmd cmd="cert-reboot" action="undefined"/></ajax-request>'
  79. _info "Uploading certificate"
  80. curl $UPLOAD -H "X-CSRF-Token: $XSS" -F "u=@$_ccert" -F action=uploadcert -F callback=uploader_uploadcert || return 1
  81. _info "Uploading private key"
  82. curl $UPLOAD -H "X-CSRF-Token: $XSS" -F "u=@$_ckey" -F action=uploadprivatekey -F callback=uploader_uploadprivatekey || return 1
  83. _info "Replacing certificate"
  84. curl $CMD -H "X-CSRF-Token: $XSS" --data-raw "$REPLACE_CERT_AJAX" || return 1
  85. _info "Rebooting"
  86. curl $CMD -H "X-CSRF-Token: $XSS" --data-raw "$CERT_REBOOT_AJAX" || return 1
  87. return 0
  88. }