security/acme-client: Add DNSAPI for Wix.com
Open
Nobody has claimed this yet.
upstream
- Dominant language
- PHP
- Stars
- 1.2k
- Forks
- 863
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 10
Description
Important notices
Before you add a new report, we ask you kindly to acknowledge the following:
- I have read the contributing guide lines at https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md
- I have searched the existing issues, open and closed, and I'm convinced that mine is new.
- When the request is meant for an existing plugin, I've added its name to the title.
Is your feature request related to a problem? Please describe.
Please add DNSAPI support for Wix.com
Describe the solution you'd like
Use the code provided here, filename dns_wix.sh :
#!/bin/bash
# shellcheck disable=SC2034
dns_wix_info='WIX
Site: wix.com
Options:
WIX_API_TOKEN API Token
WIX_API_ID API ID
'
# DNS API DEV-Guide: https://github-wiki-see.page/m/acmesh-official/acme.sh/wiki/DNS-API-Dev-Guide
# WIX API DEV-Guide: https://dev.wix.com/docs/api-reference/account-level/domains/domain-dns/get-dns-zone
WIX_API="https://www.wixapis.com/domains/v1"
# Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
# Used to add txt record
dns_wix_add()
{
# Step 1: Get full domain and the txt record
FULLDOMAIN=$1
TXTVALUE=$2
# Step 2: The credentials such as username, password, api key or api token etc,
# must be saved so that acme.sh can renew the cert automatically in future.
# It will reuse the credentials automatically.
WIX_API_ID="${WIX_API_ID:-$(_readaccountconf_mutable WIX_API_ID)}"
WIX_API_TOKEN="${WIX_API_TOKEN:-$(_readaccountconf_mutable WIX_API_TOKEN)}"
if [ -z "${WIX_API_ID}" ] || [ -z "${WIX_API_TOKEN}" ]; then
WIX_API_ID=""
WIX_API_TOKEN=""
_err "You don't specify wix api key and email yet."
_err "Please create your key and try again."
return 1
fi
# save the credentials to the account conf file.
_saveaccountconf_mutable WIX_API_ID "${WIX_API_ID}"
_saveaccountconf_mutable WIX_API_TOKEN "${WIX_API_TOKEN}"
# Step 3: Detect which part is my root zone
_debug "dns_wix_add: First detect the root zone"
if ! _get_root "${FULLDOMAIN}"; then
_err "invalid domain"
return 1
fi
_debug _domain_id "${_domain_id}"
_debug _sub_domain "${_sub_domain}"
_debug _domain "${_domain}"
_debug "Getting txt records"
_wix_rest GET "dns-zones/${_domain_id}"
if test "$?" != "0" -o -z "${RESPONSE}"; then
_err "Error"
return 1
fi
# Step 4: Call your dns api to add txt record
# For wildcard cert, the main root domain and the wildcard domain have the same txt subdomain name, so
# we can not use updating anymore.
_info "Adding record"
if _wix_rest PATCH "dns-zones/${_domain_id}" "{\"domainName\": \"${_domain_id}\", \"additions\": [{\"type\":\"TXT\",\"hostName\":\"${FULLDOMAIN}\",\"values\":[\"${TXTVALUE}\"],\"ttl\":120}]}"; then
if _contains "${RESPONSE}" "${TXTVALUE}"; then
_info "Added, OK"
return 0
elif _contains "${RESPONSE}" "resource already exists"; then
_info "Already exists, OK"
return 0
elif _contains "${RESPONSE}" "domainName is not a valid hostname"; then
_err "invalid request, response \"${RESPONSE}\"."
return 1
else
_err "Add txt record error, response \"${RESPONSE}\"."
return 1
fi
fi
_err "Add txt record error, http request failed."
return 1
}
# Usage: fulldomain txtvalue
# Used to remove the txt record after validation
# fulldomain txtvalue
dns_wix_rm()
{
# Step 1: Get full domain and the txt record
FULLDOMAIN=$1
TXTVALUE=$2
# Step 2: The credentials such as username, password, api key or api token etc
WIX_API_ID="${WIX_API_ID:-$(_readaccountconf_mutable WIX_API_ID)}"
WIX_API_TOKEN="${WIX_API_TOKEN:-$(_readaccountconf_mutable WIX_API_TOKEN)}"
# Step 3: Detect which part is my root zone
_debug "dns_wix_rm: First detect the root zone"
if ! _get_root "${FULLDOMAIN}"; then
_err "invalid domain"
return 1
fi
_debug _domain_id "${_domain_id}"
_debug _sub_domain "${_sub_domain}"
_debug _domain "${_domain}"
_debug "Getting txt records"
_wix_rest GET "dns-zones/${_domain}"
if test "$?" != "0" -o -z "${RESPONSE}"; then
_err "Error"
return 1
fi
_debug response "${RESPONSE}"
# Step 5: Call dns api to delete txt record
if _wix_rest PATCH "dns-zones/${_domain_id}" "{\"domainName\": \"${_domain_id}\", \"deletions\": [{\"type\":\"TXT\",\"hostName\":\"${FULLDOMAIN}\",\"values\":[\"${TXTVALUE}\"]}]}"; then
if _contains "${RESPONSE}" "domainName is not a valid hostname"; then
_err "domainName is not a valid hostname"
return 1
fi
_info "TXT record removed."
return 0
fi
_err "Delete txt record error, http request failed, response \"${RESPONSE}\"."
return 1
}
#################### Private functions below ##################################
# Detect which part is your root zone
# The full domain could be in either one of the following formats:
#
# _acme-challenge.www.example.com
# _acme-challenge.example.com
# _acme-challenge.example.co.uk
# _acme-challenge.www.example.co.uk
# _acme-challenge.sub1.sub2.www.example.co.uk
# sub1.sub2.example.co.uk
#
#_acme-challenge.www.domain.com
#returns
# _domain_id=domain.com from "id":"domain.com"
# _sub_domain=www.domain.com
# _domain=domain.com
#
_get_root()
{
DOMAIN=$1
i=1
p=1
_debug2 "wix: _get_root"
while true; do
HOST=$(printf "%s" "${DOMAIN}" | cut -d . -f "$i"-100)
_debug HOST "${HOST}"
if test -z "${HOST}"; then
# not valid
_err "_get_root: empty host not valid"
return 1
fi
if ! _wix_rest GET "dns-zones/${HOST}"; then
_err "_get_root: no response"
return 1
fi
_debug2 _get_root: response "${RESPONSE}"
if _contains "${RESPONSE}" "\"domainName\":\"${HOST}\""; then
_domain_id=$(echo "${RESPONSE}" | _egrep_o "\"id\": *\"[^\"]*\"" | cut -d : -f 2 | tr -d \" | tr -d " ")
_sub_domain=$(printf "%s" "${HOST}" | cut -d . -f 1-"$p")
_domain=${HOST}
return 0
fi
p=$i
i=$(_math "$i" + 1)
done
return 1
}
_wix_rest()
{
METHOD=$1
ENDPOINT="$2"
DATA="$3"
_debug "${ENDPOINT}"
#export _H1="Content-Type: application/json"
export _H1="wix-account-id: ${WIX_API_ID}"
export _H2="Authorization: ${WIX_API_TOKEN}"
if test "${METHOD}" != "GET"; then
_debug data "${DATA}"
RESPONSE="$(_post "${DATA}" "${WIX_API}/${ENDPOINT}" "" "${METHOD}" application/json)"
else
RESPONSE="$(_get "${WIX_API}/${ENDPOINT}")"
fi
if test "$?" != "0"; then
_err "error ${ENDPOINT}"
return 1
fi
_debug2 response "${RESPONSE}"
return 0
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the acme-client plugin and use the supplied dns_wix.sh as the implementation reference. Verify that Wix API credentials, DNS TXT-record addition, root-zone discovery, and removal work through the existing plugin flow; done means the Wix DNSAPI is integrated and can complete certificate validation cleanup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- security
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100