22 changed files with 1025 additions and 526 deletions
-
40.github/auto-comment.yml
-
65acme.sh
-
24deploy/panos.sh
-
32deploy/qiniu.sh
-
128deploy/ssh.sh
-
5deploy/synology_dsm.sh
-
254dnsapi/dns_1984hosting.sh
-
163dnsapi/dns_arvan.sh
-
19dnsapi/dns_aws.sh
-
3dnsapi/dns_cf.sh
-
4dnsapi/dns_constellix.sh
-
2dnsapi/dns_ddnss.sh
-
14dnsapi/dns_dp.sh
-
5dnsapi/dns_easydns.sh
-
2dnsapi/dns_he.sh
-
70dnsapi/dns_inwx.sh
-
129dnsapi/dns_joker.sh
-
2dnsapi/dns_me.sh
-
92dnsapi/dns_nm.sh
-
170dnsapi/dns_one.sh
-
277dnsapi/dns_opnsense.sh
-
51notify/mail.sh
@ -0,0 +1,40 @@ |
|||||
|
# Comment to a new issue. |
||||
|
issuesOpened: > |
||||
|
If this is a bug report, please upgrade to the latest code and try again: |
||||
|
|
||||
|
如果有 bug, 请先更新到最新版试试: |
||||
|
|
||||
|
``` |
||||
|
acme.sh --upgrade |
||||
|
``` |
||||
|
|
||||
|
please also provide the log with `--debug 2`. |
||||
|
|
||||
|
同时请提供调试输出 `--debug 2` |
||||
|
|
||||
|
see: https://github.com/acmesh-official/acme.sh/wiki/How-to-debug-acme.sh |
||||
|
|
||||
|
Without `--debug 2` log, your issue will NEVER get replied. |
||||
|
|
||||
|
没有调试输出, 你的 issue 不会得到任何解答. |
||||
|
|
||||
|
|
||||
|
pullRequestOpened: > |
||||
|
First, NEVER send a PR to `master` branch, it will NEVER be accepted. Please send to the `dev` branch instead. |
||||
|
|
||||
|
If this is a PR to support new DNS API or new notification API, please read this guide first: |
||||
|
https://github.com/acmesh-official/acme.sh/wiki/DNS-API-Dev-Guide |
||||
|
|
||||
|
Please check the guide items one by one. |
||||
|
|
||||
|
Then add your usage here: |
||||
|
https://github.com/acmesh-official/acme.sh/wiki/dnsapi |
||||
|
|
||||
|
Or some other wiki pages: |
||||
|
|
||||
|
https://github.com/acmesh-official/acme.sh/wiki/deployhooks |
||||
|
|
||||
|
https://github.com/acmesh-official/acme.sh/wiki/notify |
||||
|
|
||||
|
|
||||
|
|
||||
@ -0,0 +1,254 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
#This file name is "dns_1984hosting.sh" |
||||
|
#So, here must be a method dns_1984hosting_add() |
||||
|
#Which will be called by acme.sh to add the txt record to your api system. |
||||
|
#returns 0 means success, otherwise error. |
||||
|
# |
||||
|
#Author: Adrian Fedoreanu |
||||
|
#Report Bugs here: https://github.com/acmesh-official/acme.sh |
||||
|
# or here... https://github.com/acmesh-official/acme.sh/issues/2851 |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
# Export 1984HOSTING username and password in following variables |
||||
|
# |
||||
|
# One984HOSTING_Username=username |
||||
|
# One984HOSTING_Password=password |
||||
|
# |
||||
|
# sessionid cookie is saved in ~/.acme.sh/account.conf |
||||
|
# username/password need to be set only when changed. |
||||
|
|
||||
|
#Usage: dns_1984hosting_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_1984hosting_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_info "Add TXT record using 1984Hosting" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
if ! _1984hosting_login; then |
||||
|
_err "1984Hosting login failed for user $One984HOSTING_Username. Check $HTTP_HEADER file" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" "$fulldomain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_1984hosting_add_txt_record "$_domain" "$_sub_domain" "$txtvalue" |
||||
|
return $? |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_1984hosting_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
_info "Delete TXT record using 1984Hosting" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
if ! _1984hosting_login; then |
||||
|
_err "1984Hosting login failed for user $One984HOSTING_Username. Check $HTTP_HEADER file" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_debug "First detect the root zone" |
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "invalid domain" "$fulldomain" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug _sub_domain "$_sub_domain" |
||||
|
_debug _domain "$_domain" |
||||
|
|
||||
|
_1984hosting_delete_txt_record "$_domain" "$_sub_domain" |
||||
|
return $? |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
# usage _1984hosting_add_txt_record domain subdomain value |
||||
|
# returns 0 success |
||||
|
_1984hosting_add_txt_record() { |
||||
|
_debug "Add TXT record $1 with value '$3'" |
||||
|
domain="$1" |
||||
|
subdomain="$2" |
||||
|
value="$(printf '%s' "$3" | _url_encode)" |
||||
|
url="https://management.1984hosting.com/domains/entry/" |
||||
|
|
||||
|
postdata="entry=new" |
||||
|
postdata="$postdata&type=TXT" |
||||
|
postdata="$postdata&ttl=3600" |
||||
|
postdata="$postdata&zone=$domain" |
||||
|
postdata="$postdata&host=$subdomain" |
||||
|
postdata="$postdata&rdata=%22$value%22" |
||||
|
_debug2 postdata "$postdata" |
||||
|
|
||||
|
_authpost "$postdata" "$url" |
||||
|
response="$(echo "$_response" | _normalizeJson)" |
||||
|
_debug2 response "$response" |
||||
|
|
||||
|
if _contains "$response" '"haserrors": true'; then |
||||
|
_err "1984Hosting failed to add TXT record for $subdomain bad RC from _post" |
||||
|
return 1 |
||||
|
elif _contains "$response" "<html>"; then |
||||
|
_err "1984Hosting failed to add TXT record for $subdomain. Check $HTTP_HEADER file" |
||||
|
return 1 |
||||
|
elif [ "$response" = '{"auth": false, "ok": false}' ]; then |
||||
|
_err "1984Hosting failed to add TXT record for $subdomain. Invalid or expired cookie" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Added acme challenge TXT record for $fulldomain at 1984Hosting" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
# usage _1984hosting_delete_txt_record entry_id |
||||
|
# returns 0 success |
||||
|
_1984hosting_delete_txt_record() { |
||||
|
_debug "Delete $fulldomain TXT record" |
||||
|
domain="$1" |
||||
|
subdomain="$2" |
||||
|
url="https://management.1984hosting.com/domains" |
||||
|
|
||||
|
_htmlget "$url" "$domain" |
||||
|
_debug2 _response "$_response" |
||||
|
zone_id="$(echo "$_response" | _egrep_o 'zone\/[0-9]+')" |
||||
|
_debug2 zone_id "$zone_id" |
||||
|
if [ -z "$zone_id" ]; then |
||||
|
_err "Error getting zone_id for $1" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_htmlget "$url/$zone_id" "$subdomain" |
||||
|
_debug2 _response "$_response" |
||||
|
entry_id="$(echo "$_response" | _egrep_o 'entry_[0-9]+' | sed 's/entry_//')" |
||||
|
_debug2 entry_id "$entry_id" |
||||
|
if [ -z "$entry_id" ]; then |
||||
|
_err "Error getting TXT entry_id for $1" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_authpost "entry=$entry_id" "$url/delentry/" |
||||
|
response="$(echo "$_response" | _normalizeJson)" |
||||
|
_debug2 response "$response" |
||||
|
|
||||
|
if ! _contains "$response" '"ok": true'; then |
||||
|
_err "1984Hosting failed to delete TXT record for $entry_id bad RC from _post" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Deleted acme challenge TXT record for $fulldomain at 1984Hosting" |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
# usage: _1984hosting_login username password |
||||
|
# returns 0 success |
||||
|
_1984hosting_login() { |
||||
|
if ! _check_credentials; then return 1; fi |
||||
|
|
||||
|
if _check_cookie; then |
||||
|
_debug "Already logged in" |
||||
|
return 0 |
||||
|
fi |
||||
|
|
||||
|
_debug "Login to 1984Hosting as user $One984HOSTING_Username" |
||||
|
username=$(printf '%s' "$One984HOSTING_Username" | _url_encode) |
||||
|
password=$(printf '%s' "$One984HOSTING_Password" | _url_encode) |
||||
|
url="https://management.1984hosting.com/accounts/checkuserauth/" |
||||
|
|
||||
|
response="$(_post "username=$username&password=$password&otpkey=" "$url")" |
||||
|
response="$(echo "$response" | _normalizeJson)" |
||||
|
_debug2 response "$response" |
||||
|
|
||||
|
if [ "$response" = '{"loggedin": true, "ok": true}' ]; then |
||||
|
One984HOSTING_COOKIE="$(grep '^Set-Cookie:' "$HTTP_HEADER" | _tail_n 1 | _egrep_o 'sessionid=[^;]*;' | tr -d ';')" |
||||
|
export One984HOSTING_COOKIE |
||||
|
_saveaccountconf_mutable One984HOSTING_COOKIE "$One984HOSTING_COOKIE" |
||||
|
return 0 |
||||
|
fi |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_check_credentials() { |
||||
|
if [ -z "$One984HOSTING_Username" ] || [ -z "$One984HOSTING_Password" ]; then |
||||
|
One984HOSTING_Username="" |
||||
|
One984HOSTING_Password="" |
||||
|
_err "You haven't specified 1984Hosting username or password yet." |
||||
|
_err "Please export as One984HOSTING_Username / One984HOSTING_Password and try again." |
||||
|
return 1 |
||||
|
fi |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
_check_cookie() { |
||||
|
One984HOSTING_COOKIE="${One984HOSTING_COOKIE:-$(_readaccountconf_mutable One984HOSTING_COOKIE)}" |
||||
|
if [ -z "$One984HOSTING_COOKIE" ]; then |
||||
|
_debug "No cached cookie found" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_authget "https://management.1984hosting.com/accounts/loginstatus/" |
||||
|
response="$(echo "$_response" | _normalizeJson)" |
||||
|
if [ "$_response" = '{"ok": true}' ]; then |
||||
|
_debug "Cached cookie still valid" |
||||
|
return 0 |
||||
|
fi |
||||
|
_debug "Cached cookie no longer valid" |
||||
|
One984HOSTING_COOKIE="" |
||||
|
_saveaccountconf_mutable One984HOSTING_COOKIE "$One984HOSTING_COOKIE" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
domain="$1" |
||||
|
i=2 |
||||
|
p=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
||||
|
|
||||
|
if [ -z "$h" ]; then |
||||
|
#not valid |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_authget "https://management.1984hosting.com/domains/soacheck/?zone=$h&nameserver=ns0.1984.is." |
||||
|
if _contains "$_response" "serial"; then |
||||
|
_sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
||||
|
_domain="$h" |
||||
|
return 0 |
||||
|
fi |
||||
|
p=$i |
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
# add extra headers to request |
||||
|
_authget() { |
||||
|
export _H1="Cookie: $One984HOSTING_COOKIE" |
||||
|
_response=$(_get "$1") |
||||
|
} |
||||
|
|
||||
|
# truncate huge HTML response |
||||
|
# echo: Argument list too long |
||||
|
_htmlget() { |
||||
|
export _H1="Cookie: $One984HOSTING_COOKIE" |
||||
|
_response=$(_get "$1" | grep "$2" | _head_n 1) |
||||
|
} |
||||
|
|
||||
|
# add extra headers to request |
||||
|
_authpost() { |
||||
|
export _H1="Cookie: $One984HOSTING_COOKIE" |
||||
|
_response=$(_post "$1" "$2") |
||||
|
} |
||||
@ -0,0 +1,163 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
#Arvan_Token="xxxx" |
||||
|
|
||||
|
ARVAN_API_URL="https://napi.arvancloud.com/cdn/4.0/domains" |
||||
|
|
||||
|
#Author: Ehsan Aliakbar |
||||
|
#Report Bugs here: https://github.com/Neilpang/acme.sh |
||||
|
# |
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_arvan_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_arvan_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using Arvan" |
||||
|
|
||||
|
Arvan_Token="${Arvan_Token:-$(_readaccountconf_mutable Arvan_Token)}" |
||||
|
|
||||
|
if [ -z "$Arvan_Token" ]; then |
||||
|
_err "You didn't specify \"Arvan_Token\" token yet." |
||||
|
_err "You can get yours from here https://npanel.arvancloud.com/profile/api-keys" |
||||
|
return 1 |
||||
|
fi |
||||
|
#save the api token to the account conf file. |
||||
|
_saveaccountconf_mutable Arvan_Token "$Arvan_Token" |
||||
|
|
||||
|
_debug "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" |
||||
|
|
||||
|
_info "Adding record" |
||||
|
if _arvan_rest POST "$_domain/dns-records" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"value\":{\"text\":\"$txtvalue\"},\"ttl\":120}"; then |
||||
|
if _contains "$response" "$txtvalue"; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
elif _contains "$response" "Record Data is Duplicated"; then |
||||
|
_info "Already exists, OK" |
||||
|
return 0 |
||||
|
else |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Add txt record error." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#Usage: fulldomain txtvalue |
||||
|
#Remove the txt record after validation. |
||||
|
dns_arvan_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
_info "Using Arvan" |
||||
|
_debug fulldomain "$fulldomain" |
||||
|
_debug txtvalue "$txtvalue" |
||||
|
|
||||
|
Arvan_Token="${Arvan_Token:-$(_readaccountconf_mutable Arvan_Token)}" |
||||
|
|
||||
|
_debug "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" |
||||
|
shorted_txtvalue=$(printf "%s" "$txtvalue" | cut -d "-" -d "_" -f1) |
||||
|
_arvan_rest GET "${_domain}/dns-records?search=$shorted_txtvalue" |
||||
|
|
||||
|
if ! printf "%s" "$response" | grep \"current_page\":1 >/dev/null; then |
||||
|
_err "Error on Arvan Api" |
||||
|
_err "Please create a github issue with debbug log" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
count=$(printf "%s\n" "$response" | _egrep_o "\"total\":[^,]*" | cut -d : -f 2) |
||||
|
_debug count "$count" |
||||
|
if [ "$count" = "0" ]; then |
||||
|
_info "Don't need to remove." |
||||
|
else |
||||
|
record_id=$(printf "%s\n" "$response" | _egrep_o "\"id\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \" | head -n 1) |
||||
|
_debug "record_id" "$record_id" |
||||
|
if [ -z "$record_id" ]; then |
||||
|
_err "Can not get record id to remove." |
||||
|
return 1 |
||||
|
fi |
||||
|
if ! _arvan_rest "DELETE" "${_domain}/dns-records/$record_id"; then |
||||
|
_err "Delete record error." |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug "$response" |
||||
|
_contains "$response" 'dns record deleted' |
||||
|
fi |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
|
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
# _domain_id=sdjkglgdfewsdfg |
||||
|
_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 |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if ! _arvan_rest GET "?search=$h"; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
if _contains "$response" "\"domain\":\"$h\"" || _contains "$response" '"total":1'; then |
||||
|
_domain_id=$(echo "$response" | _egrep_o "\[.\"id\":\"[^\"]*\"" | _head_n 1 | cut -d : -f 2 | tr -d \") |
||||
|
if [ "$_domain_id" ]; then |
||||
|
_sub_domain=$(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 |
||||
|
} |
||||
|
|
||||
|
_arvan_rest() { |
||||
|
mtd="$1" |
||||
|
ep="$2" |
||||
|
data="$3" |
||||
|
|
||||
|
token_trimmed=$(echo "$Arvan_Token" | tr -d '"') |
||||
|
|
||||
|
export _H1="Authorization: $token_trimmed" |
||||
|
|
||||
|
if [ "$mtd" = "DELETE" ]; then |
||||
|
#DELETE Request shouldn't have Content-Type |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$ARVAN_API_URL/$ep" "" "$mtd")" |
||||
|
elif [ "$mtd" = "POST" ]; then |
||||
|
export _H2="Content-Type: application/json" |
||||
|
_debug data "$data" |
||||
|
response="$(_post "$data" "$ARVAN_API_URL/$ep" "" "$mtd")" |
||||
|
else |
||||
|
response="$(_get "$ARVAN_API_URL/$ep$data")" |
||||
|
fi |
||||
|
} |
||||
@ -0,0 +1,129 @@ |
|||||
|
#!/usr/bin/env sh |
||||
|
|
||||
|
# Joker.com API for acme.sh |
||||
|
# |
||||
|
# This script adds the necessary TXT record to a domain in Joker.com. |
||||
|
# |
||||
|
# You must activate Dynamic DNS in Joker.com DNS configuration first. |
||||
|
# Username and password below refer to Dynamic DNS authentication, |
||||
|
# not your Joker.com login credentials. |
||||
|
# See: https://joker.com/faq/content/11/427/en/what-is-dynamic-dns-dyndns.html |
||||
|
# |
||||
|
# NOTE: This script does not support wildcard certificates, because |
||||
|
# Joker.com API does not support adding two TXT records with the same |
||||
|
# subdomain. Adding the second record will overwrite the first one. |
||||
|
# See: https://joker.com/faq/content/6/496/en/let_s-encrypt-support.html |
||||
|
# "... this request will replace all TXT records for the specified |
||||
|
# label by the provided content" |
||||
|
# |
||||
|
# Author: aattww (https://github.com/aattww/) |
||||
|
# |
||||
|
# Report bugs to https://github.com/acmesh-official/acme.sh/issues/2840 |
||||
|
# |
||||
|
# JOKER_USERNAME="xxxx" |
||||
|
# JOKER_PASSWORD="xxxx" |
||||
|
|
||||
|
JOKER_API="https://svc.joker.com/nic/replace" |
||||
|
|
||||
|
######## Public functions ##################### |
||||
|
|
||||
|
#Usage: dns_joker_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
||||
|
dns_joker_add() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
JOKER_USERNAME="${JOKER_USERNAME:-$(_readaccountconf_mutable JOKER_USERNAME)}" |
||||
|
JOKER_PASSWORD="${JOKER_PASSWORD:-$(_readaccountconf_mutable JOKER_PASSWORD)}" |
||||
|
|
||||
|
if [ -z "$JOKER_USERNAME" ] || [ -z "$JOKER_PASSWORD" ]; then |
||||
|
_err "No Joker.com username and password specified." |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_saveaccountconf_mutable JOKER_USERNAME "$JOKER_USERNAME" |
||||
|
_saveaccountconf_mutable JOKER_PASSWORD "$JOKER_PASSWORD" |
||||
|
|
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "Invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Adding TXT record" |
||||
|
if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$_domain&label=$_sub_domain&type=TXT&value=$txtvalue"; then |
||||
|
if _startswith "$response" "OK"; then |
||||
|
_info "Added, OK" |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Error adding TXT record." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#fulldomain txtvalue |
||||
|
dns_joker_rm() { |
||||
|
fulldomain=$1 |
||||
|
txtvalue=$2 |
||||
|
|
||||
|
JOKER_USERNAME="${JOKER_USERNAME:-$(_readaccountconf_mutable JOKER_USERNAME)}" |
||||
|
JOKER_PASSWORD="${JOKER_PASSWORD:-$(_readaccountconf_mutable JOKER_PASSWORD)}" |
||||
|
|
||||
|
if ! _get_root "$fulldomain"; then |
||||
|
_err "Invalid domain" |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
_info "Removing TXT record" |
||||
|
# TXT record is removed by setting its value to empty. |
||||
|
if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$_domain&label=$_sub_domain&type=TXT&value="; then |
||||
|
if _startswith "$response" "OK"; then |
||||
|
_info "Removed, OK" |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
_err "Error removing TXT record." |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
#################### Private functions below ################################## |
||||
|
#_acme-challenge.www.domain.com |
||||
|
#returns |
||||
|
# _sub_domain=_acme-challenge.www |
||||
|
# _domain=domain.com |
||||
|
_get_root() { |
||||
|
fulldomain=$1 |
||||
|
i=1 |
||||
|
while true; do |
||||
|
h=$(printf "%s" "$fulldomain" | cut -d . -f $i-100) |
||||
|
_debug h "$h" |
||||
|
if [ -z "$h" ]; then |
||||
|
return 1 |
||||
|
fi |
||||
|
|
||||
|
# Try to remove a test record. With correct root domain, username and password this will return "OK: ..." regardless |
||||
|
# of record in question existing or not. |
||||
|
if _joker_rest "username=$JOKER_USERNAME&password=$JOKER_PASSWORD&zone=$h&label=jokerTXTUpdateTest&type=TXT&value="; then |
||||
|
if _startswith "$response" "OK"; then |
||||
|
_sub_domain="$(echo "$fulldomain" | sed "s/\\.$h\$//")" |
||||
|
_domain=$h |
||||
|
return 0 |
||||
|
fi |
||||
|
fi |
||||
|
|
||||
|
i=$(_math "$i" + 1) |
||||
|
done |
||||
|
|
||||
|
_debug "Root domain not found" |
||||
|
return 1 |
||||
|
} |
||||
|
|
||||
|
_joker_rest() { |
||||
|
data="$1" |
||||
|
_debug data "$data" |
||||
|
|
||||
|
if ! response="$(_post "$data" "$JOKER_API" "" "POST")"; then |
||||
|
_err "Error POSTing" |
||||
|
return 1 |
||||
|
fi |
||||
|
_debug response "$response" |
||||
|
return 0 |
||||
|
} |
||||
@ -1,92 +0,0 @@ |
|||||
#!/usr/bin/env sh |
|
||||
|
|
||||
######################################################################## |
|
||||
# https://namemaster.de hook script for acme.sh |
|
||||
# |
|
||||
# Environment variables: |
|
||||
# |
|
||||
# - $NM_user (your namemaster.de API username) |
|
||||
# - $NM_md5 (your namemaster.de API password_as_md5hash) |
|
||||
# |
|
||||
# Author: Thilo Gass <thilo.gass@gmail.com> |
|
||||
# Git repo: https://github.com/ThiloGa/acme.sh |
|
||||
|
|
||||
#-- dns_nm_add() - Add TXT record -------------------------------------- |
|
||||
# Usage: dns_nm_add _acme-challenge.subdomain.domain.com "XyZ123..." |
|
||||
|
|
||||
dns_nm_add() { |
|
||||
fulldomain=$1 |
|
||||
txt_value=$2 |
|
||||
_info "Using DNS-01 namemaster hook" |
|
||||
|
|
||||
NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}" |
|
||||
NM_md5="${NM_md5:-$(_readaccountconf_mutable NM_md5)}" |
|
||||
if [ -z "$NM_user" ] || [ -z "$NM_md5" ]; then |
|
||||
NM_user="" |
|
||||
NM_md5="" |
|
||||
_err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_md5 environment variables." |
|
||||
return 1 |
|
||||
fi |
|
||||
#save the api user and md5 password to the account conf file. |
|
||||
_debug "Save user and hash" |
|
||||
_saveaccountconf_mutable NM_user "$NM_user" |
|
||||
_saveaccountconf_mutable NM_md5 "$NM_md5" |
|
||||
|
|
||||
zone="$(echo $fulldomain | _egrep_o "[^.]+.[^.]+$")" |
|
||||
get="https://namemaster.de/api/api.php?User=$NM_user&Password=$NM_md5&Antwort=csv&Int=0&Typ=ACME&Zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Auto&Lifetime=3600" |
|
||||
erg="$(_get "$get")" |
|
||||
|
|
||||
exit_code="$?" |
|
||||
if [ "$exit_code" != 0 ]; then |
|
||||
_err "error Ading $zone TXT: $txt_value" |
|
||||
_err "Error $exit_code" |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
if _contains "$erg" "Success"; then |
|
||||
_info "Success, TXT Added, OK" |
|
||||
else |
|
||||
_err "error Adding $zone TXT: $txt_value erg: $erg" |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
_debug "ok Auto $zone TXT: $txt_value erg: $erg" |
|
||||
return 0 |
|
||||
} |
|
||||
|
|
||||
dns_nm_rm() { |
|
||||
|
|
||||
fulldomain=$1 |
|
||||
txt_value=$2 |
|
||||
|
|
||||
NM_user="${NM_user:-$(_readaccountconf_mutable NM_user)}" |
|
||||
NM_md5="${NM_md5:-$(_readaccountconf_mutable NM_md5)}" |
|
||||
if [ -z "$NM_user" ] || [ -z "$NM_md5" ]; then |
|
||||
NM_user="" |
|
||||
NM_md5="" |
|
||||
_err "No auth details provided. Please set user credentials using the \$NM_user and \$NM_md5 environment variables." |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
zone="$(echo $fulldomain | _egrep_o "[^.]+.[^.]+$")" |
|
||||
get="https://namemaster.de/api/api.php?User=$NM_user&Password=$NM_md5&Antwort=csv&Int=0&Typ=TXT&Zone=$zone&hostname=$fulldomain&TXT=$txt_value&Action=Delete_IN&TTL=0" |
|
||||
erg="$(_get "$get")" |
|
||||
|
|
||||
exit_code="$?" |
|
||||
if [ "$exit_code" != "0" ]; then |
|
||||
_err "error Deleting $zone TXT: $txt_value" |
|
||||
_err "Error $exit_code" |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
if _contains "$erg" "Success"; then |
|
||||
_info "Success, TXT removed, OK" |
|
||||
else |
|
||||
_err "error Auto $zone TXT: $txt_value erg: $erg" |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
_debug "ok Auto $zone TXT: $txt_value erg: $erg" |
|
||||
return 0 |
|
||||
|
|
||||
} |
|
||||
@ -1,277 +0,0 @@ |
|||||
#!/usr/bin/env sh |
|
||||
|
|
||||
#OPNsense Bind API |
|
||||
#https://docs.opnsense.org/development/api.html |
|
||||
# |
|
||||
#OPNs_Host="opnsense.example.com" |
|
||||
#OPNs_Port="443" |
|
||||
# optional, defaults to 443 if unset |
|
||||
#OPNs_Key="qocfU9RSbt8vTIBcnW8bPqCrpfAHMDvj5OzadE7Str+rbjyCyk7u6yMrSCHtBXabgDDXx/dY0POUp7ZA" |
|
||||
#OPNs_Token="pZEQ+3ce8dDlfBBdg3N8EpqpF5I1MhFqdxX06le6Gl8YzyQvYCfCzNaFX9O9+IOSyAs7X71fwdRiZ+Lv" |
|
||||
#OPNs_Api_Insecure=0 |
|
||||
# optional, defaults to 0 if unset |
|
||||
# Set 1 for insecure and 0 for secure -> difference is whether ssl cert is checked for validity (0) or whether it is just accepted (1) |
|
||||
|
|
||||
######## Public functions ##################### |
|
||||
#Usage: add _acme-challenge.www.domain.com "123456789ABCDEF0000000000000000000000000000000000000" |
|
||||
#fulldomain |
|
||||
#txtvalue |
|
||||
OPNs_DefaultPort=443 |
|
||||
OPNs_DefaultApi_Insecure=0 |
|
||||
|
|
||||
dns_opnsense_add() { |
|
||||
fulldomain=$1 |
|
||||
txtvalue=$2 |
|
||||
|
|
||||
_opns_check_auth || return 1 |
|
||||
|
|
||||
if ! set_record "$fulldomain" "$txtvalue"; then |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
return 0 |
|
||||
} |
|
||||
|
|
||||
#fulldomain |
|
||||
dns_opnsense_rm() { |
|
||||
fulldomain=$1 |
|
||||
txtvalue=$2 |
|
||||
|
|
||||
_opns_check_auth || return 1 |
|
||||
|
|
||||
if ! rm_record "$fulldomain" "$txtvalue"; then |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
return 0 |
|
||||
} |
|
||||
|
|
||||
set_record() { |
|
||||
fulldomain=$1 |
|
||||
new_challenge=$2 |
|
||||
_info "Adding record $fulldomain with challenge: $new_challenge" |
|
||||
|
|
||||
_debug "Detect root zone" |
|
||||
if ! _get_root "$fulldomain"; then |
|
||||
_err "invalid domain" |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
_debug _domain "$_domain" |
|
||||
_debug _host "$_host" |
|
||||
_debug _domainid "$_domainid" |
|
||||
_return_str="" |
|
||||
_record_string="" |
|
||||
_build_record_string "$_domainid" "$_host" "$new_challenge" |
|
||||
_uuid="" |
|
||||
if _existingchallenge "$_domain" "$_host" "$new_challenge"; then |
|
||||
# Update |
|
||||
if _opns_rest "POST" "/record/setRecord/${_uuid}" "$_record_string"; then |
|
||||
_return_str="$response" |
|
||||
else |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
else |
|
||||
#create |
|
||||
if _opns_rest "POST" "/record/addRecord" "$_record_string"; then |
|
||||
_return_str="$response" |
|
||||
else |
|
||||
return 1 |
|
||||
fi |
|
||||
fi |
|
||||
|
|
||||
if echo "$_return_str" | _egrep_o "\"result\":\"saved\"" >/dev/null; then |
|
||||
_opns_rest "POST" "/service/reconfigure" "{}" |
|
||||
_debug "Record created" |
|
||||
else |
|
||||
_err "Error creating record $_record_string" |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
return 0 |
|
||||
} |
|
||||
|
|
||||
rm_record() { |
|
||||
fulldomain=$1 |
|
||||
new_challenge="$2" |
|
||||
_info "Remove record $fulldomain with challenge: $new_challenge" |
|
||||
|
|
||||
_debug "Detect root zone" |
|
||||
if ! _get_root "$fulldomain"; then |
|
||||
_err "invalid domain" |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
_debug _domain "$_domain" |
|
||||
_debug _host "$_host" |
|
||||
_debug _domainid "$_domainid" |
|
||||
_uuid="" |
|
||||
if _existingchallenge "$_domain" "$_host" "$new_challenge"; then |
|
||||
# Delete |
|
||||
if _opns_rest "POST" "/record/delRecord/${_uuid}" "\{\}"; then |
|
||||
if echo "$_return_str" | _egrep_o "\"result\":\"deleted\"" >/dev/null; then |
|
||||
_opns_rest "POST" "/service/reconfigure" "{}" |
|
||||
_debug "Record deleted" |
|
||||
else |
|
||||
_err "Error deleting record $_host from domain $fulldomain" |
|
||||
return 1 |
|
||||
fi |
|
||||
else |
|
||||
_err "Error deleting record $_host from domain $fulldomain" |
|
||||
return 1 |
|
||||
fi |
|
||||
else |
|
||||
_info "Record not found, nothing to remove" |
|
||||
fi |
|
||||
|
|
||||
return 0 |
|
||||
} |
|
||||
|
|
||||
#################### Private functions below ################################## |
|
||||
#_acme-challenge.www.domain.com |
|
||||
#returns |
|
||||
# _domainid=domid |
|
||||
#_domain=domain.com |
|
||||
_get_root() { |
|
||||
domain=$1 |
|
||||
i=2 |
|
||||
p=1 |
|
||||
if _opns_rest "GET" "/domain/get"; then |
|
||||
_domain_response="$response" |
|
||||
else |
|
||||
return 1 |
|
||||
fi |
|
||||
|
|
||||
while true; do |
|
||||
h=$(printf "%s" "$domain" | cut -d . -f $i-100) |
|
||||
if [ -z "$h" ]; then |
|
||||
#not valid |
|
||||
return 1 |
|
||||
fi |
|
||||
_debug h "$h" |
|
||||
<<<<<<< HEAD |
|
||||
id=$(echo "$_domain_response" | _egrep_o "\"[^\"]*\":{\"enabled\":\"1\",\"type\":{\"master\":{\"value\":\"master\",\"selected\":1},\"slave\":{\"value\":\"slave\",\"selected\":0}},\"masterip\":\"[^\"]*\",\"domainname\":\"${h}\"" | cut -d ':' -f 1 | cut -d '"' -f 2) |
|
||||
======= |
|
||||
id=$(echo "$_domain_response" | _egrep_o "\"[^\"]*\":{\"enabled\":\"1\",\"type\":{\"master\":{\"value\":\"master\",\"selected\":1},\"slave\":{\"value\":\"slave\",\"selected\":0}},\"masterip\":\"[^\"]*\"(,\"allownotifyslave\":{\"\":{[^}]*}},|,)\"domainname\":\"${h}\"" | cut -d ':' -f 1 | cut -d '"' -f 2) |
|
||||
>>>>>>> Allow old and new API response |
|
||||
|
|
||||
if [ -n "$id" ]; then |
|
||||
_debug id "$id" |
|
||||
_host=$(printf "%s" "$domain" | cut -d . -f 1-$p) |
|
||||
_domain="${h}" |
|
||||
_domainid="${id}" |
|
||||
return 0 |
|
||||
fi |
|
||||
p=$i |
|
||||
i=$(_math $i + 1) |
|
||||
done |
|
||||
_debug "$domain not found" |
|
||||
|
|
||||
return 1 |
|
||||
} |
|
||||
|
|
||||
_opns_rest() { |
|
||||
method=$1 |
|
||||
ep=$2 |
|
||||
data=$3 |
|
||||
#Percent encode user and token |
|
||||
key=$(echo "$OPNs_Key" | tr -d "\n\r" | _url_encode) |
|
||||
token=$(echo "$OPNs_Token" | tr -d "\n\r" | _url_encode) |
|
||||
|
|
||||
opnsense_url="https://${key}:${token}@${OPNs_Host}:${OPNs_Port:-$OPNs_DefaultPort}/api/bind${ep}" |
|
||||
export _H1="Content-Type: application/json" |
|
||||
_debug2 "Try to call api: https://${OPNs_Host}:${OPNs_Port:-$OPNs_DefaultPort}/api/bind${ep}" |
|
||||
if [ ! "$method" = "GET" ]; then |
|
||||
_debug data "$data" |
|
||||
export _H1="Content-Type: application/json" |
|
||||
response="$(_post "$data" "$opnsense_url" "" "$method")" |
|
||||
else |
|
||||
export _H1="" |
|
||||
response="$(_get "$opnsense_url")" |
|
||||
fi |
|
||||
|
|
||||
if [ "$?" != "0" ]; then |
|
||||
_err "error $ep" |
|
||||
return 1 |
|
||||
fi |
|
||||
_debug2 response "$response" |
|
||||
|
|
||||
return 0 |
|
||||
} |
|
||||
|
|
||||
_build_record_string() { |
|
||||
_record_string="{\"record\":{\"enabled\":\"1\",\"domain\":\"$1\",\"name\":\"$2\",\"type\":\"TXT\",\"value\":\"$3\"}}" |
|
||||
} |
|
||||
|
|
||||
_existingchallenge() { |
|
||||
if _opns_rest "GET" "/record/searchRecord"; then |
|
||||
_record_response="$response" |
|
||||
else |
|
||||
return 1 |
|
||||
fi |
|
||||
_uuid="" |
|
||||
_uuid=$(echo "$_record_response" | _egrep_o "\"uuid\":\"[^\"]*\",\"enabled\":\"[01]\",\"domain\":\"$1\",\"name\":\"$2\",\"type\":\"TXT\",\"value\":\"$3\"" | cut -d ':' -f 2 | cut -d '"' -f 2) |
|
||||
|
|
||||
if [ -n "$_uuid" ]; then |
|
||||
_debug uuid "$_uuid" |
|
||||
return 0 |
|
||||
fi |
|
||||
_debug "${2}.$1{1} record not found" |
|
||||
|
|
||||
return 1 |
|
||||
} |
|
||||
|
|
||||
_opns_check_auth() { |
|
||||
OPNs_Host="${OPNs_Host:-$(_readaccountconf_mutable OPNs_Host)}" |
|
||||
OPNs_Port="${OPNs_Port:-$(_readaccountconf_mutable OPNs_Port)}" |
|
||||
OPNs_Key="${OPNs_Key:-$(_readaccountconf_mutable OPNs_Key)}" |
|
||||
OPNs_Token="${OPNs_Token:-$(_readaccountconf_mutable OPNs_Token)}" |
|
||||
OPNs_Api_Insecure="${OPNs_Api_Insecure:-$(_readaccountconf_mutable OPNs_Api_Insecure)}" |
|
||||
|
|
||||
if [ -z "$OPNs_Host" ]; then |
|
||||
_err "You don't specify OPNsense address." |
|
||||
return 1 |
|
||||
else |
|
||||
_saveaccountconf_mutable OPNs_Host "$OPNs_Host" |
|
||||
fi |
|
||||
|
|
||||
if ! printf '%s' "$OPNs_Port" | grep '^[0-9]*$' >/dev/null; then |
|
||||
_err 'OPNs_Port specified but not numeric value' |
|
||||
return 1 |
|
||||
elif [ -z "$OPNs_Port" ]; then |
|
||||
_info "OPNSense port not specified. Defaulting to using port $OPNs_DefaultPort" |
|
||||
else |
|
||||
_saveaccountconf_mutable OPNs_Port "$OPNs_Port" |
|
||||
fi |
|
||||
|
|
||||
if ! printf '%s' "$OPNs_Api_Insecure" | grep '^[01]$' >/dev/null; then |
|
||||
_err 'OPNs_Api_Insecure specified but not 0/1 value' |
|
||||
return 1 |
|
||||
elif [ -n "$OPNs_Api_Insecure" ]; then |
|
||||
_saveaccountconf_mutable OPNs_Api_Insecure "$OPNs_Api_Insecure" |
|
||||
fi |
|
||||
export HTTPS_INSECURE="${OPNs_Api_Insecure:-$OPNs_DefaultApi_Insecure}" |
|
||||
|
|
||||
if [ -z "$OPNs_Key" ]; then |
|
||||
_err "you have not specified your OPNsense api key id." |
|
||||
_err "Please set OPNs_Key and try again." |
|
||||
return 1 |
|
||||
else |
|
||||
_saveaccountconf_mutable OPNs_Key "$OPNs_Key" |
|
||||
fi |
|
||||
|
|
||||
if [ -z "$OPNs_Token" ]; then |
|
||||
_err "you have not specified your OPNsense token." |
|
||||
_err "Please create OPNs_Token and try again." |
|
||||
return 1 |
|
||||
else |
|
||||
_saveaccountconf_mutable OPNs_Token "$OPNs_Token" |
|
||||
fi |
|
||||
|
|
||||
if ! _opns_rest "GET" "/general/get"; then |
|
||||
_err "Call to OPNsense API interface failed. Unable to access OPNsense API." |
|
||||
return 1 |
|
||||
fi |
|
||||
return 0 |
|
||||
} |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue