[dnsapi] add MVMNET dns api (#6606)

* feat: add initial version of MVMNET dns api

* fix: adjust shell format with shfmt

* feat: add initial version of MVMNET dns api

* fix: adjust shell format with shfmt

* Change runner from ubuntu-latest to self-hosted

* Revert "Change runner from ubuntu-latest to self-hosted"

This reverts commit 55eb217fa1.

* fix(dns_mvmnet): use configurable API endpoint

* fix(dns_mvmnet): extract records portably

* fix(dns_mvmnet): namespace private helpers

* fix(dns_mvmnet): stop on missing credentials

* fix(dns_mvmnet): reuse normalized subdomain

* fix(dns_mvmnet): reuse validated credentials

* docs(dns_mvmnet): update API and issue links
This commit is contained in:
Matteo Gaggiano authored and GitHub committed 2026-10-12 17:30:59 +08:00
1 parent cf51ad22d1
commit 9d09edcd69
1 file changed
+213
+213
View File
@@ -0,0 +1,213 @@
#!/usr/bin/env sh
# shellcheck disable=SC2034
dns_mvmnet_info='mvmnet.com
Site: mvmnet.com
Docs: https://github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_mvmnet
Api Docs: https://api.mvmnet.com/api/1.0/documentation/
Issues: https://github.com/acmesh-official/acme.sh/issues/7297
Author: Matteo Gaggiano <github.com/marchrius>
Options:
MVMNET_ID application_id
MVMNET_KEY application_key
MVMNET_SEED application_seed
MVMNET_API_URL API base URL (defaults to https://api.mvmnet.com/api/1.0, use https://api.mvmnet.com/ote/1.0 for test)
'
MVMNET_API_URL="${MVMNET_API_URL:-https://api.mvmnet.com/api/1.0}"
######## Public functions #####################
dns_mvmnet_add() {
fulldomain=$1
txtvalue=$2
_mvmnet_retrieve_and_check_variables || return 1
_debug "First detect the root zone"
if ! _mvmnet_get_root "$fulldomain"; then
_err "invalid domain"
return 1
fi
_debug _domain "$_domain"
_debug _subdomain "$_subdomain"
_info "Adding TXT record to ${fulldomain}"
postdata=$(printf '{"domain":"%s","rtype":"TXT","ldata":"%s","rdata":"%s"}' "${_domain}" "${_subdomain}" "${txtvalue}")
_mvmnet_rest POST "dns/zone/record" "$postdata"
if ! _contains "${response}" 'error'; then
return 0
fi
_err "Could not create resource record, check logs"
_err "${response}"
return 1
}
dns_mvmnet_rm() {
fulldomain=$1
txtvalue=$2
_mvmnet_check_variables || return 1
_debug "First detect the root zone"
if ! _mvmnet_get_root "$fulldomain"; then
_err "invalid domain"
return 1
fi
_debug _domain "$_domain"
_debug _subdomain "$_subdomain"
if ! _mvmnet_get_record_id "$_subdomain" "$_domain" "$txtvalue"; then
_warn "Record id for $_subdomain not found, please remove it manually"
return 0
fi
_debug _subdomain_record_id "$_subdomain_record_id"
_info "Deleting resource record $fulldomain ($_subdomain_record_id)"
_mvmnet_rest DELETE "dns/zone/record" "domain=${_domain}&id=${_subdomain_record_id}"
if ! _contains "${response}" 'error'; then
return 0
fi
_err "Could not delete resource record, check logs"
_err "${response}"
return 1
}
#################### Private functions below ##################################
_mvmnet_check_variables() {
MVMNET_ID="${MVMNET_ID:-$(_readaccountconf_mutable MVMNET_ID)}"
MVMNET_KEY="${MVMNET_KEY:-$(_readaccountconf_mutable MVMNET_KEY)}"
MVMNET_SEED="${MVMNET_SEED:-$(_readaccountconf_mutable MVMNET_SEED)}"
if [ -z "$MVMNET_ID" ] || [ -z "$MVMNET_KEY" ] || [ -z "$MVMNET_SEED" ]; then
MVMNET_ID=""
MVMNET_KEY=""
MVMNET_SEED=""
_err "You don't specify application_id, application_key or application_seed."
return 1
fi
}
_mvmnet_retrieve_and_check_variables() {
_mvmnet_check_variables || return 1
_saveaccountconf_mutable MVMNET_ID "$MVMNET_ID"
_saveaccountconf_mutable MVMNET_KEY "$MVMNET_KEY"
_saveaccountconf_mutable MVMNET_SEED "$MVMNET_SEED"
}
#_acme-challenge.www.domain.com
#returns
# _subdomain=_acme-challenge.www
# _domain=domain.com
# _domain_id=123456789
_mvmnet_get_root() {
domain=$1
i=1
p=1
while true; do
h=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
_debug h "$h"
if [ -z "$h" ]; then
#not valid
_debug "not valid $h"
return 1
fi
if ! _mvmnet_rest GET "domain/info" "domain=$h"; then
return 1
fi
if _contains "$response" "\"domain_idn\":\"$h\""; then
_domain_id=$(echo "$response" | _egrep_o ".\"id\": *\"[0-9]*\"" | _head_n 1 | cut -d : -f 2 | tr -d \" | tr -d " ")
if [ "$_domain_id" ]; then
_subdomain=$(printf "%s" "$domain" | cut -d . -f 1-"$p")
_domain=$h
return 0
fi
return 1
fi
p=$i
i=$(_math "$i" + 1)
done
return 1
}
# _acme-challenge.www
# domain.com
# value (Optional)
#returns
# _subdomain_record_id=123456789
_mvmnet_get_record_id() {
subdomain=$1
domain=$2
txtvalue=$3
_debug3 subdomain "$subdomain"
_debug3 domain "$domain"
_debug3 txtvalue "$txtvalue"
hosttofind="${subdomain}.${domain}"
if ! _mvmnet_rest GET "dns/zone" "domain=$domain"; then
return 1
fi
objectbody="$(echo "$response" | _egrep_o '\{[^{}]*\}' | grep -E "\"host\" *: *\"$hosttofind\.\".*\"type\" *: *\"TXT\"|\"type\" *: *\"TXT\".*\"host\" *: *\"$hosttofind\.\"")"
_debug3 objectbody "${objectbody}"
if [ "$txtvalue" != "" ]; then
_info "A value will be searched: $txtvalue"
objectbody="$(echo "$objectbody" | grep "\"value\" *: *\"\\\\\"$txtvalue\\\\\"\"")"
_debug3 objectbody "${objectbody}"
fi
_subdomain_record_id="$(echo "$objectbody" | _egrep_o ".\"id\": *\"[0-9]*\"" | _head_n 1 | cut -d : -f 2 | tr -d \" | tr -d ' ')"
if [ "${_subdomain_record_id}x" = "x" ]; then
_err "error retrieve sub domain record id"
return 1
fi
return 0
}
#returns
# response
_mvmnet_rest() {
m=$1
ep="$2"
data="$3"
_debug "$ep"
signature="$(printf "%s" "${MVMNET_ID}+${MVMNET_KEY}+$m+${MVMNET_SEED}" | _digest "sha1" "hex")"
export _H1="X-Mvm-Application: ${MVMNET_ID}"
export _H2="X-Mvm-Signature: ${signature}"
case "$m" in
POST | PUT)
_debug data "$data"
response="$(_post "$data" "$MVMNET_API_URL/$ep" "" "$m" "application/json")"
;;
DELETE)
response="$(_post "" "$MVMNET_API_URL/$ep?$data" "" "$m")"
;;
GET)
response="$(_get "$MVMNET_API_URL/$ep?$data")"
;;
esac
if [ "$?" != "0" ]; then
_err "error $ep"
return 1
fi
_debug response "${response}"
return 0
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.