-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deploy hook for Ruckus ZoneDirector / Unleashed #4832
Open
kchiem
wants to merge
11
commits into
acmesh-official:dev
Choose a base branch
from
kchiem:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+172
−0
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ed72b09
deploy hook for Ruckus ZoneDirector / Unleashed
b6a77e0
Ruckus - use _get() and _post()
ms264556 7178026
remove dead code
ms264556 d7bafa6
Merge pull request #1 from ms264556/dev
kchiem 0cc74b7
fix insecure password debug and _info typo
ms264556 5f7ad72
Merge pull request #2 from ms264556/dev
kchiem e98e7a2
Fix info logging
ms264556 b665014
Merge pull request #3 from ms264556/dev
kchiem 38c41b7
fix acme.sh PR shfmt failure
ms264556 2bb5fbd
Remove HTTPS_INSECURE
ms264556 412e14a
Merge pull request #4 from ms264556/dev
kchiem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Here is a script to deploy cert to Ruckus Zone Director/Unleashed. | ||
# | ||
# Adapted from: | ||
# https://ms264556.net/pages/PfSenseLetsEncryptToRuckus | ||
# | ||
# ```sh | ||
# acme.sh --deploy -d ruckus.example.com --deploy-hook ruckus | ||
# ``` | ||
# | ||
# Then you need to set the environment variables for the | ||
# deploy script to work. | ||
# | ||
# ```sh | ||
# export RUCKUS_HOST=ruckus.example.com | ||
# export RUCKUS_USER=myruckususername | ||
# export RUCKUS_PASS=myruckuspassword | ||
# | ||
# acme.sh --deploy -d ruckus.example.com --deploy-hook ruckus | ||
# ``` | ||
# | ||
# returns 0 means success, otherwise error. | ||
|
||
######## Public functions ##################### | ||
|
||
#domain keyfile certfile cafile fullchain | ||
ruckus_deploy() { | ||
_cdomain="$1" | ||
_ckey="$2" | ||
_ccert="$3" | ||
_cca="$4" | ||
_cfullchain="$5" | ||
_err_code=0 | ||
|
||
_debug _cdomain "$_cdomain" | ||
_debug _ckey "$_ckey" | ||
_debug _ccert "$_ccert" | ||
_debug _cca "$_cca" | ||
_debug _cfullchain "$_cfullchain" | ||
|
||
_getdeployconf RUCKUS_HOST | ||
_getdeployconf RUCKUS_USER | ||
_getdeployconf RUCKUS_PASS | ||
|
||
if [ -z "$RUCKUS_HOST" ]; then | ||
_debug "Using _cdomain as RUCKUS_HOST, please set if not correct." | ||
RUCKUS_HOST="$_cdomain" | ||
fi | ||
|
||
if [ -z "$RUCKUS_USER" ]; then | ||
_err "Need to set the env variable RUCKUS_USER" | ||
return 1 | ||
fi | ||
|
||
if [ -z "$RUCKUS_PASS" ]; then | ||
_err "Need to set the env variable RUCKUS_PASS" | ||
return 1 | ||
fi | ||
|
||
_savedeployconf RUCKUS_HOST "$RUCKUS_HOST" | ||
_savedeployconf RUCKUS_USER "$RUCKUS_USER" | ||
_savedeployconf RUCKUS_PASS "$RUCKUS_PASS" | ||
|
||
_debug RUCKUS_HOST "$RUCKUS_HOST" | ||
_debug RUCKUS_USER "$RUCKUS_USER" | ||
_debug RUCKUS_PASS "$RUCKUS_PASS" | ||
|
||
COOKIE_JAR=$(mktemp) | ||
cleanup() { | ||
rm $COOKIE_JAR | ||
} | ||
trap cleanup EXIT | ||
|
||
LOGIN_URL=$(curl https://$RUCKUS_HOST -ksSLo /dev/null -w '%{url_effective}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My reimplemention using _get() and post() has been pushed to this PR now |
||
_debug LOGIN_URL "$LOGIN_URL" | ||
|
||
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') | ||
_debug XSS "$XSS" | ||
|
||
if [ -n "$XSS" ]; then | ||
_info "Authentication successful" | ||
else | ||
_err "Authentication failed" | ||
return 1 | ||
fi | ||
|
||
BASE_URL=$(dirname $LOGIN_URL) | ||
CONF_ARGS="-ksSo /dev/null -b $COOKIE_JAR -c $COOKIE_JAR" | ||
UPLOAD="$CONF_ARGS $BASE_URL/_upload.jsp?request_type=xhr" | ||
CMD="$CONF_ARGS $BASE_URL/_cmdstat.jsp" | ||
|
||
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>' | ||
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>' | ||
|
||
_info "Uploading certificate" | ||
curl $UPLOAD -H "X-CSRF-Token: $XSS" -F "u=@$_ccert" -F action=uploadcert -F callback=uploader_uploadcert || return 1 | ||
|
||
_info "Uploading private key" | ||
curl $UPLOAD -H "X-CSRF-Token: $XSS" -F "u=@$_ckey" -F action=uploadprivatekey -F callback=uploader_uploadprivatekey || return 1 | ||
|
||
_info "Replacing certificate" | ||
curl $CMD -H "X-CSRF-Token: $XSS" --data-raw "$REPLACE_CERT_AJAX" || return 1 | ||
|
||
_info "Rebooting" | ||
curl $CMD -H "X-CSRF-Token: $XSS" --data-raw "$CERT_REBOOT_AJAX" || return 1 | ||
|
||
return 0 | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
_secure_debug
for password, so that you won't leak it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed