Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddict committed Mar 4, 2024
2 parents 5a8408e + af5f696 commit c8392ba
Show file tree
Hide file tree
Showing 4 changed files with 542 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.editorconfig
.gitattributes
.vscode/settings.json
72 changes: 34 additions & 38 deletions deploy/directadmin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ _da_get_api() {
data=$2
domain=$3
_debug "$domain; $data"
response=$(_get "$DA_Api/$cmd?$data")

if [ "$?" != "0" ]; then

if ! response=$(_get "$DA_Api/$cmd?$data"); then
_err "error $cmd"
return 1
fi
Expand All @@ -87,7 +86,7 @@ _da_get_api() {
# Usage: _DA_setSSL
# Use the API to set the certificates
_DA_setSSL() {
curData="domain=${_domain}&json=yes"
curData="domain=${_cdomain}&json=yes"
_debug "Calling _da_get_api: '${curData}' '${DA_Api}/CMD_API_SSL'"
_da_get_api CMD_API_SSL "${curData}" "${domain}"
_secure_debug2 "response" "$response"
Expand All @@ -101,10 +100,10 @@ _DA_setSSL() {
ssl_on="$(echo "$cert_response" | jq -r .$name)"
_debug2 "$name" "$ssl_on"

if [ "$ssl_on" == "yes" ]; then
_debug "Domain '${_domain}' has SSL enabled: $(__green "$ssl_on")"
if [ "$ssl_on" = "yes" ]; then
_debug "Domain '${_cdomain}' has SSL enabled: $(__green "$ssl_on")"
else
_err "Domain '${_domain}' does not has SSL enabled: $ssl_on"
_err "Domain '${_cdomain}' does not has SSL enabled: $ssl_on"
if [ -z "$FORCE" ]; then
_info "Add '$(__red '--force')' to force to deploy."
return 1
Expand All @@ -119,20 +118,19 @@ _DA_setSSL() {
server="$(echo "$cert_response" | jq -r .$name)"
_debug "$name" "$server"

if [ "$server" == "no" ]; then
_debug "Domain '${_domain}' is using a custom/pasted certificate."
if [ "$server" = "no" ]; then
_debug "Domain '${_cdomain}' is using a custom/pasted certificate."
else
_err "Domain '${_domain}' is using the server certificate."
_err "Domain '${_cdomain}' is using the server certificate."
if [ -z "$FORCE" ]; then
_info "Add '$(__red '--force')' to force to deploy."
return 1
fi
fi


curData="domain=${_domain}&view=cacert&json=yes"
curData="domain=${_cdomain}&view=cacert&json=yes"
_debug "Calling _DA_da_get_api_getSSL: '${curData}' '${DA_Api}/CMD_API_SSL'"
_da_get_api CMD_API_SSL "${curData}" "${_domain}"
_da_get_api CMD_API_SSL "${curData}" "${_cdomain}"
_secure_debug2 "response" "$response"
cacert_response=$response

Expand All @@ -153,30 +151,29 @@ _DA_setSSL() {

name="cacert"
sameCaCert=1
if [ "$enabled" == "yes" ]; then
_debug "Domain '${_domain}' is using a CA certificate."
if [ "$enabled" = "yes" ]; then
_debug "Domain '${_cdomain}' is using a CA certificate."

cacert="$(echo "$cacert_response" | jq -r .$name)"
cacert_flat="$(echo "$cacert" | tr -d '\r' | tr -d '\n')"
_debug2 "$name" "$cacert"

if [ "$cacert_flat" != "$cca_flat" ]; then
sameCaCert=0
# cat <<< $cacert > ~/cacert.txt
# cat <<< $cca > ~/_cca.txt
_info "Domain '${_domain}' is using $(__red 'a different') CA certificate."
# cat <<< $cacert > ~/cacert.txt
# cat <<< $cca > ~/_cca.txt
_info "Domain '${_cdomain}' is using $(__red 'a different') CA certificate."
else
_info "Domain '${_domain}' is using the same CA certificate."
_info "Domain '${_cdomain}' is using the same CA certificate."
fi
else
_err "Domain '${_domain}' is currently not using a CA certificate."
_err "Domain '${_cdomain}' is currently not using a CA certificate."
if [ -z "$FORCE" ]; then
_info "Add '$(__red '--force')' to force to deploy."
return 1
fi
fi


name="key"
sameKey=1
if _contains "$cert_response" "$name"; then
Expand All @@ -186,11 +183,11 @@ _DA_setSSL() {

if [ "$key_flat" != "$ckey_flat" ]; then
sameKey=0
# cat <<< $key > ~/key.txt
# cat <<< $ckey > ~/_ckey.txt
_info "Domain '${_domain}' is using $(__red 'a different') private key."
# cat <<< $key > ~/key.txt
# cat <<< $ckey > ~/_ckey.txt
_info "Domain '${_cdomain}' is using $(__red 'a different') private key."
else
_info "Domain '${_domain}' is using the same private key."
_info "Domain '${_cdomain}' is using the same private key."
fi
fi

Expand All @@ -200,14 +197,14 @@ _DA_setSSL() {
cert="$(echo "$cert_response" | jq -r .$name)"
cert_flat="$(echo "$cert" | tr -d '\r' | tr -d '\n')"
_debug2 "$name" "$cert"

if [ "$cert_flat" != "$ccert_flat" ]; then
sameCert=0
# cat <<< $cert > ~/cert.txt
# cat <<< $ccert > ~/_ccert.txt
_info "Domain '${_domain}' is using $(__red 'a different') certificate."
# cat <<< $cert > ~/cert.txt
# cat <<< $ccert > ~/_ccert.txt
_info "Domain '${_cdomain}' is using $(__red 'a different') certificate."
else
_info "Domain '${_domain}' is using the same certificate."
_info "Domain '${_cdomain}' is using the same certificate."
fi
fi

Expand All @@ -218,12 +215,12 @@ _DA_setSSL() {

encoded_cacert_value="$(printf "%s" "${cca}" | _url_encode)"
_debug2 encoded_cacert_value "$encoded_cacert_value"
curData="domain=${_domain}&action=save&type=cacert&active=yes&cacert=${encoded_cacert_value}"
curData="domain=${_cdomain}&action=save&type=cacert&active=yes&cacert=${encoded_cacert_value}"
response="$(_post "$curData" "${DA_Api}/CMD_API_SSL")"
if _contains "${response}" 'error=0'; then
_info "$(__green 'Setting the cacert succeeded for domain '${_domain}'.')"
_info "$(__green "Setting the cacert succeeded for domain '${_cdomain}'.")"
else
_err "Setting the cacert failed for domain '${_domain}'. Check response:"
_err "Setting the cacert failed for domain '${_cdomain}'. Check response:"
_err "$response"
return 1
fi
Expand All @@ -235,19 +232,19 @@ _DA_setSSL() {

encoded_keycert_value="$(printf "%s" "${ckey}$'\n'${ccert}" | _url_encode)"
_debug2 encoded_cert_value "$encoded_keycert_value"
curData="domain=${_domain}&action=save&type=paste&request=no&certificate=${encoded_keycert_value}"
curData="domain=${_cdomain}&action=save&type=paste&request=no&certificate=${encoded_keycert_value}"
response="$(_post "$curData" "${DA_Api}/CMD_API_SSL")"
if _contains "${response}" 'error=0'; then
_info "$(__green 'Setting the key and cert succeeded for domain '${_domain}'.')"
_info "$(__green "Setting the key and cert succeeded for domain '${_cdomain}'.")"
else
_err "Setting the key and cert failed for domain '${_domain}'. Check response:"
_err "Setting the key and cert failed for domain '${_cdomain}'. Check response:"
_err "$response"
return 1
fi
fi
else
if [ $sameCaCert -eq 1 ] && [ $sameKey -eq 1 ] && [ $sameCert -eq 1 ]; then
_info "Nothing to do. Domain '${_domain}' $(__green 'has already the same certifcates active.')"
_info "Nothing to do. Domain '${_cdomain}' $(__green 'has already the same certifcates active.')"
if [ -z "$FORCE" ]; then
_info "Add '$(__red '--force')' to force to deploy."
fi
Expand All @@ -256,4 +253,3 @@ _DA_setSSL() {

return 0
}

Loading

0 comments on commit c8392ba

Please sign in to comment.