Merge pull request #4262 from acmesh-official/dev

sync
This commit is contained in:
neil 2022-08-22 21:17:19 +08:00 committed by GitHub
commit fc1df9f9a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 899 additions and 562 deletions

View File

@ -11,6 +11,9 @@ on:
- 'dnsapi/*.sh' - 'dnsapi/*.sh'
- '.github/workflows/DNS.yml' - '.github/workflows/DNS.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
CheckToken: CheckToken:
@ -84,13 +87,7 @@ jobs:
- name: Run acmetest - name: Run acmetest
run: cd ../acmetest && ./rundocker.sh testall run: cd ../acmetest && ./rundocker.sh testall
- uses: actions/upload-artifact@v1
if: failure()
with:
name: Docker-logs
path: |
../acmetest/*.log
../acmetest/logs
MacOS: MacOS:
@ -133,12 +130,6 @@ jobs:
cd ../acmetest cd ../acmetest
./letest.sh ./letest.sh
- uses: actions/upload-artifact@v1
if: failure()
with:
name: MacOS-logs
path: |
../acmetest/*.log
@ -197,12 +188,7 @@ jobs:
cd ../acmetest cd ../acmetest
./letest.sh ./letest.sh
- uses: actions/upload-artifact@v1
if: failure()
with:
name: Windows-logs
path: |
../acmetest/*.log
FreeBSD: FreeBSD:
runs-on: macos-12 runs-on: macos-12
@ -247,12 +233,7 @@ jobs:
cd ../acmetest cd ../acmetest
./letest.sh ./letest.sh
- uses: actions/upload-artifact@v1
if: failure()
with:
name: FreeBSD-logs
path: |
../acmetest/*.log
Solaris: Solaris:
@ -299,12 +280,7 @@ jobs:
cd ../acmetest cd ../acmetest
./letest.sh ./letest.sh
- uses: actions/upload-artifact@v1
if: failure()
with:
name: Solaris-logs
path: |
../acmetest/*.log
OpenBSD: OpenBSD:
@ -350,12 +326,7 @@ jobs:
cd ../acmetest cd ../acmetest
./letest.sh ./letest.sh
- uses: actions/upload-artifact@v1
if: failure()
with:
name: OpenBSD-logs
path: |
../acmetest/*.log
NetBSD: NetBSD:
@ -402,12 +373,7 @@ jobs:
cd ../acmetest cd ../acmetest
./letest.sh ./letest.sh
- uses: actions/upload-artifact@v1
if: failure()
with:
name: NetBSD-logs
path: |
../acmetest/*.log
DragonFlyBSD: DragonFlyBSD:
@ -454,13 +420,6 @@ jobs:
cd ../acmetest cd ../acmetest
./letest.sh ./letest.sh
- uses: actions/upload-artifact@v1
if: failure()
with:
name: DragonFlyBSD-logs
path: |
../acmetest/*.log

View File

@ -14,6 +14,12 @@ on:
- '*.sh' - '*.sh'
- '.github/workflows/DragonFlyBSD.yml' - '.github/workflows/DragonFlyBSD.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
DragonFlyBSD: DragonFlyBSD:

View File

@ -14,6 +14,11 @@ on:
- '*.sh' - '*.sh'
- '.github/workflows/FreeBSD.yml' - '.github/workflows/FreeBSD.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
FreeBSD: FreeBSD:
@ -25,6 +30,12 @@ jobs:
CA: "" CA: ""
CA_EMAIL: "" CA_EMAIL: ""
TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1 TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1
- TEST_ACME_Server: "LetsEncrypt.org_test"
CA_ECDSA: ""
CA: ""
CA_EMAIL: ""
TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1
ACME_USE_WGET: 1
#- TEST_ACME_Server: "ZeroSSL.com" #- TEST_ACME_Server: "ZeroSSL.com"
# CA_ECDSA: "ZeroSSL ECC Domain Secure Site CA" # CA_ECDSA: "ZeroSSL ECC Domain Secure Site CA"
# CA: "ZeroSSL RSA Domain Secure Site CA" # CA: "ZeroSSL RSA Domain Secure Site CA"
@ -38,6 +49,7 @@ jobs:
CA: ${{ matrix.CA }} CA: ${{ matrix.CA }}
CA_EMAIL: ${{ matrix.CA_EMAIL }} CA_EMAIL: ${{ matrix.CA_EMAIL }}
TEST_PREFERRED_CHAIN: ${{ matrix.TEST_PREFERRED_CHAIN }} TEST_PREFERRED_CHAIN: ${{ matrix.TEST_PREFERRED_CHAIN }}
ACME_USE_WGET: ${{ matrix.ACME_USE_WGET }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: vmactions/cf-tunnel@v0.0.3 - uses: vmactions/cf-tunnel@v0.0.3
@ -51,10 +63,10 @@ jobs:
run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/ run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/
- uses: vmactions/freebsd-vm@v0 - uses: vmactions/freebsd-vm@v0
with: with:
envs: 'TEST_LOCAL TestingDomain TEST_ACME_Server CA_ECDSA CA CA_EMAIL TEST_PREFERRED_CHAIN' envs: 'TEST_LOCAL TestingDomain TEST_ACME_Server CA_ECDSA CA CA_EMAIL TEST_PREFERRED_CHAIN ACME_USE_WGET'
nat: | nat: |
"8080": "80" "8080": "80"
prepare: pkg install -y socat curl prepare: pkg install -y socat curl wget
usesh: true usesh: true
copyback: false copyback: false
run: | run: |

View File

@ -15,6 +15,12 @@ on:
- '.github/workflows/Linux.yml' - '.github/workflows/Linux.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
Linux: Linux:

View File

@ -14,6 +14,11 @@ on:
- '*.sh' - '*.sh'
- '.github/workflows/MacOS.yml' - '.github/workflows/MacOS.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
MacOS: MacOS:

View File

@ -14,6 +14,12 @@ on:
- '*.sh' - '*.sh'
- '.github/workflows/NetBSD.yml' - '.github/workflows/NetBSD.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
NetBSD: NetBSD:

View File

@ -14,6 +14,11 @@ on:
- '*.sh' - '*.sh'
- '.github/workflows/OpenBSD.yml' - '.github/workflows/OpenBSD.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
OpenBSD: OpenBSD:
@ -25,6 +30,12 @@ jobs:
CA: "" CA: ""
CA_EMAIL: "" CA_EMAIL: ""
TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1 TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1
- TEST_ACME_Server: "LetsEncrypt.org_test"
CA_ECDSA: ""
CA: ""
CA_EMAIL: ""
TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1
ACME_USE_WGET: 1
#- TEST_ACME_Server: "ZeroSSL.com" #- TEST_ACME_Server: "ZeroSSL.com"
# CA_ECDSA: "ZeroSSL ECC Domain Secure Site CA" # CA_ECDSA: "ZeroSSL ECC Domain Secure Site CA"
# CA: "ZeroSSL RSA Domain Secure Site CA" # CA: "ZeroSSL RSA Domain Secure Site CA"
@ -38,6 +49,7 @@ jobs:
CA: ${{ matrix.CA }} CA: ${{ matrix.CA }}
CA_EMAIL: ${{ matrix.CA_EMAIL }} CA_EMAIL: ${{ matrix.CA_EMAIL }}
TEST_PREFERRED_CHAIN: ${{ matrix.TEST_PREFERRED_CHAIN }} TEST_PREFERRED_CHAIN: ${{ matrix.TEST_PREFERRED_CHAIN }}
ACME_USE_WGET: ${{ matrix.ACME_USE_WGET }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: vmactions/cf-tunnel@v0.0.3 - uses: vmactions/cf-tunnel@v0.0.3
@ -51,10 +63,10 @@ jobs:
run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/ run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/
- uses: vmactions/openbsd-vm@v0 - uses: vmactions/openbsd-vm@v0
with: with:
envs: 'TEST_LOCAL TestingDomain TEST_ACME_Server CA_ECDSA CA CA_EMAIL TEST_PREFERRED_CHAIN' envs: 'TEST_LOCAL TestingDomain TEST_ACME_Server CA_ECDSA CA CA_EMAIL TEST_PREFERRED_CHAIN ACME_USE_WGET'
nat: | nat: |
"8080": "80" "8080": "80"
prepare: pkg_add socat curl prepare: pkg_add socat curl wget
usesh: true usesh: true
copyback: false copyback: false
run: | run: |

View File

@ -13,6 +13,13 @@ on:
- '*.sh' - '*.sh'
- '.github/workflows/PebbleStrict.yml' - '.github/workflows/PebbleStrict.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
PebbleStrict: PebbleStrict:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -15,6 +15,11 @@ on:
- '.github/workflows/Solaris.yml' - '.github/workflows/Solaris.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
Solaris: Solaris:
strategy: strategy:
@ -25,6 +30,12 @@ jobs:
CA: "" CA: ""
CA_EMAIL: "" CA_EMAIL: ""
TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1 TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1
- TEST_ACME_Server: "LetsEncrypt.org_test"
CA_ECDSA: ""
CA: ""
CA_EMAIL: ""
TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1
ACME_USE_WGET: 1
#- TEST_ACME_Server: "ZeroSSL.com" #- TEST_ACME_Server: "ZeroSSL.com"
# CA_ECDSA: "ZeroSSL ECC Domain Secure Site CA" # CA_ECDSA: "ZeroSSL ECC Domain Secure Site CA"
# CA: "ZeroSSL RSA Domain Secure Site CA" # CA: "ZeroSSL RSA Domain Secure Site CA"
@ -38,6 +49,7 @@ jobs:
CA: ${{ matrix.CA }} CA: ${{ matrix.CA }}
CA_EMAIL: ${{ matrix.CA_EMAIL }} CA_EMAIL: ${{ matrix.CA_EMAIL }}
TEST_PREFERRED_CHAIN: ${{ matrix.TEST_PREFERRED_CHAIN }} TEST_PREFERRED_CHAIN: ${{ matrix.TEST_PREFERRED_CHAIN }}
ACME_USE_WGET: ${{ matrix.ACME_USE_WGET }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: vmactions/cf-tunnel@v0.0.3 - uses: vmactions/cf-tunnel@v0.0.3
@ -51,11 +63,11 @@ jobs:
run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/ run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/
- uses: vmactions/solaris-vm@v0 - uses: vmactions/solaris-vm@v0
with: with:
envs: 'TEST_LOCAL TestingDomain TEST_ACME_Server CA_ECDSA CA CA_EMAIL TEST_PREFERRED_CHAIN' envs: 'TEST_LOCAL TestingDomain TEST_ACME_Server CA_ECDSA CA CA_EMAIL TEST_PREFERRED_CHAIN ACME_USE_WGET'
copyback: "false" copyback: "false"
nat: | nat: |
"8080": "80" "8080": "80"
prepare: pkgutil -y -i socat curl prepare: pkgutil -y -i socat curl wget
run: | run: |
cd ../acmetest \ cd ../acmetest \
&& ./letest.sh && ./letest.sh

View File

@ -14,6 +14,11 @@ on:
- '*.sh' - '*.sh'
- '.github/workflows/Ubuntu.yml' - '.github/workflows/Ubuntu.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
Ubuntu: Ubuntu:
@ -25,6 +30,12 @@ jobs:
CA: "" CA: ""
CA_EMAIL: "" CA_EMAIL: ""
TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1 TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1
- TEST_ACME_Server: "LetsEncrypt.org_test"
CA_ECDSA: ""
CA: ""
CA_EMAIL: ""
TEST_PREFERRED_CHAIN: (STAGING) Pretend Pear X1
ACME_USE_WGET: 1
- TEST_ACME_Server: "ZeroSSL.com" - TEST_ACME_Server: "ZeroSSL.com"
CA_ECDSA: "ZeroSSL ECC Domain Secure Site CA" CA_ECDSA: "ZeroSSL ECC Domain Secure Site CA"
CA: "ZeroSSL RSA Domain Secure Site CA" CA: "ZeroSSL RSA Domain Secure Site CA"
@ -57,10 +68,11 @@ jobs:
NO_REVOKE: ${{ matrix.NO_REVOKE }} NO_REVOKE: ${{ matrix.NO_REVOKE }}
TEST_IPCERT: ${{ matrix.TEST_IPCERT }} TEST_IPCERT: ${{ matrix.TEST_IPCERT }}
TestingDomain: ${{ matrix.TestingDomain }} TestingDomain: ${{ matrix.TestingDomain }}
ACME_USE_WGET: ${{ matrix.ACME_USE_WGET }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Install tools - name: Install tools
run: sudo apt-get install -y socat run: sudo apt-get install -y socat wget
- name: Start StepCA - name: Start StepCA
if: ${{ matrix.TEST_ACME_Server=='https://localhost:9000/acme/acme/directory' }} if: ${{ matrix.TEST_ACME_Server=='https://localhost:9000/acme/acme/directory' }}
run: | run: |

View File

@ -15,6 +15,11 @@ on:
- '.github/workflows/Windows.yml' - '.github/workflows/Windows.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
Windows: Windows:
strategy: strategy:

View File

@ -11,6 +11,10 @@ on:
- "Dockerfile" - "Dockerfile"
- '.github/workflows/dockerhub.yml' - '.github/workflows/dockerhub.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
CheckToken: CheckToken:

View File

@ -14,11 +14,6 @@ jobs:
issue_number: context.issue.number, issue_number: context.issue.number,
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
body: ' body: 'Please upgrade to the latest code and try again first. Maybe it's already fixed. ```acme.sh --upgrade``` If it's still not working, please provide the log with `--debug 2`, otherwise, nobody can help you.'
Please upgrade to the latest code and try again first. Maybe it's already fixed.
`acme.sh --upgrade`
If it's still not working, please provode the log with `--debug 2`, otherwise, nobody can help you.'
}) })

30
.github/workflows/pr_notify.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: Check dns api
on:
pull_request_target:
types:
- opened
branches:
- 'dev'
paths:
- 'notify/*.sh'
jobs:
welcome:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `**Welcome**
Please make sure you're read our [Code-of-conduct](../wiki/Code-of-conduct) and add the usage here: [notify](../wiki/notify).
Then reply on this message, otherwise, your code will not be reviewed or merged.
We look forward to reviewing your Pull request shortly ✨
`
})

View File

@ -13,6 +13,11 @@ on:
- '**.sh' - '**.sh'
- '.github/workflows/shellcheck.yml' - '.github/workflows/shellcheck.yml'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs: jobs:
ShellCheck: ShellCheck:
runs-on: ubuntu-latest runs-on: ubuntu-latest

20
acme.sh
View File

@ -5200,11 +5200,25 @@ $_authorizations_map"
_info "The domain is set to be valid to: $_valid_to" _info "The domain is set to be valid to: $_valid_to"
_info "It can not be renewed automatically" _info "It can not be renewed automatically"
_info "See: $_VALIDITY_WIKI" _info "See: $_VALIDITY_WIKI"
else
_now=$(_time)
_debug2 "_now" "$_now"
_lifetime=$(_math $Le_NextRenewTime - $_now)
_debug2 "_lifetime" "$_lifetime"
if [ $_lifetime -gt 86400 ]; then
#if lifetime is logner than one day, it will renew one day before
Le_NextRenewTime=$(_math $Le_NextRenewTime - 86400)
Le_NextRenewTimeStr=$(_time2str "$Le_NextRenewTime")
else
#if lifetime is less than 24 hours, it will renew one hour before
Le_NextRenewTime=$(_math $Le_NextRenewTime - 3600)
Le_NextRenewTimeStr=$(_time2str "$Le_NextRenewTime")
fi
fi fi
else else
Le_NextRenewTime=$(_math "$Le_CertCreateTime" + "$Le_RenewalDays" \* 24 \* 60 \* 60) Le_NextRenewTime=$(_math "$Le_CertCreateTime" + "$Le_RenewalDays" \* 24 \* 60 \* 60)
Le_NextRenewTimeStr=$(_time2str "$Le_NextRenewTime")
Le_NextRenewTime=$(_math "$Le_NextRenewTime" - 86400) Le_NextRenewTime=$(_math "$Le_NextRenewTime" - 86400)
Le_NextRenewTimeStr=$(_time2str "$Le_NextRenewTime")
fi fi
_savedomainconf "Le_NextRenewTimeStr" "$Le_NextRenewTimeStr" _savedomainconf "Le_NextRenewTimeStr" "$Le_NextRenewTimeStr"
_savedomainconf "Le_NextRenewTime" "$Le_NextRenewTime" _savedomainconf "Le_NextRenewTime" "$Le_NextRenewTime"
@ -6038,6 +6052,8 @@ revoke() {
if [ -z "$response" ]; then if [ -z "$response" ]; then
_info "Revoke success." _info "Revoke success."
rm -f "$CERT_PATH" rm -f "$CERT_PATH"
cat "$CERT_KEY_PATH" >"$CERT_KEY_PATH.revoked"
cat "$CSR_PATH" >"$CSR_PATH.revoked"
return 0 return 0
else else
_err "Revoke error by domain key." _err "Revoke error by domain key."
@ -6054,6 +6070,8 @@ revoke() {
if [ -z "$response" ]; then if [ -z "$response" ]; then
_info "Revoke success." _info "Revoke success."
rm -f "$CERT_PATH" rm -f "$CERT_PATH"
cat "$CERT_KEY_PATH" >"$CERT_KEY_PATH.revoked"
cat "$CSR_PATH" >"$CSR_PATH.revoked"
return 0 return 0
else else
_err "Revoke error." _err "Revoke error."

View File

@ -1,10 +1,12 @@
#!/usr/bin/env sh #!/usr/bin/env sh
#Godaddy domain api #Godaddy domain api
# Get API key and secret from https://developer.godaddy.com/
# #
# GD_Key="sdfsdfsdfljlbjkljlkjsdfoiwje" # GD_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
#
# GD_Secret="asdfsdfsfsdfsdfdfsdf" # GD_Secret="asdfsdfsfsdfsdfdfsdf"
#
# Ex.: acme.sh --issue --staging --dns dns_gd -d "*.s.example.com" -d "s.example.com"
GD_Api="https://api.godaddy.com/v1" GD_Api="https://api.godaddy.com/v1"
@ -51,7 +53,8 @@ dns_gd_add() {
_add_data="{\"data\":\"$txtvalue\"}" _add_data="{\"data\":\"$txtvalue\"}"
for t in $(echo "$response" | tr '{' "\n" | grep "\"name\":\"$_sub_domain\"" | tr ',' "\n" | grep '"data"' | cut -d : -f 2); do for t in $(echo "$response" | tr '{' "\n" | grep "\"name\":\"$_sub_domain\"" | tr ',' "\n" | grep '"data"' | cut -d : -f 2); do
_debug2 t "$t" _debug2 t "$t"
if [ "$t" ]; then # ignore empty (previously removed) records, to prevent useless _acme-challenge TXT entries
if [ "$t" ] && [ "$t" != '""' ]; then
_add_data="$_add_data,{\"data\":$t}" _add_data="$_add_data,{\"data\":$t}"
fi fi
done done
@ -59,13 +62,25 @@ dns_gd_add() {
_info "Adding record" _info "Adding record"
if _gd_rest PUT "domains/$_domain/records/TXT/$_sub_domain" "[$_add_data]"; then if _gd_rest PUT "domains/$_domain/records/TXT/$_sub_domain" "[$_add_data]"; then
_info "Added, sleeping 10 seconds" _debug "Checking updated records of '${fulldomain}'"
_sleep 10
#todo: check if the record takes effect if ! _gd_rest GET "domains/$_domain/records/TXT/$_sub_domain"; then
return 0 _err "Validating TXT record for '${fulldomain}' with rest error [$?]." "$response"
fi
_err "Add txt record error."
return 1 return 1
fi
if ! _contains "$response" "$txtvalue"; then
_err "TXT record '${txtvalue}' for '${fulldomain}', value wasn't set!"
return 1
fi
else
_err "Add txt record error, value '${txtvalue}' for '${fulldomain}' was not set."
return 1
fi
_sleep 10
_info "Added TXT record '${txtvalue}' for '${fulldomain}'."
return 0
} }
#fulldomain #fulldomain
@ -107,11 +122,20 @@ dns_gd_rm() {
fi fi
done done
if [ -z "$_add_data" ]; then if [ -z "$_add_data" ]; then
_add_data="{\"data\":\"\"}" # delete empty record
_debug "Delete last record for '${fulldomain}'"
if ! _gd_rest DELETE "domains/$_domain/records/TXT/$_sub_domain"; then
_err "Cannot delete empty TXT record for '$fulldomain'"
return 1
fi fi
else
# remove specific TXT value, keeping other entries
_debug2 _add_data "$_add_data" _debug2 _add_data "$_add_data"
if ! _gd_rest PUT "domains/$_domain/records/TXT/$_sub_domain" "[$_add_data]"; then
_gd_rest PUT "domains/$_domain/records/TXT/$_sub_domain" "[$_add_data]" _err "Cannot update TXT record for '$fulldomain'"
return 1
fi
fi
} }
#################### Private functions below ################################## #################### Private functions below ##################################
@ -156,15 +180,15 @@ _gd_rest() {
export _H1="Authorization: sso-key $GD_Key:$GD_Secret" export _H1="Authorization: sso-key $GD_Key:$GD_Secret"
export _H2="Content-Type: application/json" export _H2="Content-Type: application/json"
if [ "$data" ]; then if [ "$data" ] || [ "$m" = "DELETE" ]; then
_debug data "$data" _debug "data ($m): " "$data"
response="$(_post "$data" "$GD_Api/$ep" "" "$m")" response="$(_post "$data" "$GD_Api/$ep" "" "$m")"
else else
response="$(_get "$GD_Api/$ep")" response="$(_get "$GD_Api/$ep")"
fi fi
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then
_err "error $ep" _err "error on rest call ($m): $ep"
return 1 return 1
fi fi
_debug2 response "$response" _debug2 response "$response"

View File

@ -5,55 +5,81 @@
# Environment variables: # Environment variables:
# #
# - $KAS_Login (Kasserver API login name) # - $KAS_Login (Kasserver API login name)
# - $KAS_Authtype (Kasserver API auth type. Default: sha1) # - $KAS_Authtype (Kasserver API auth type. Default: plain)
# - $KAS_Authdata (Kasserver API auth data.) # - $KAS_Authdata (Kasserver API auth data.)
# #
# Author: Martin Kammerlander, Phlegx Systems OG <martin.kammerlander@phlegx.com> # Author: squared GmbH <github@squaredgmbh.de>
# Updated by: Marc-Oliver Lange <git@die-lang.es> # Credits:
# Credits: Inspired by dns_he.sh. Thanks a lot man! # Inspired by dns_he.sh. Thanks a lot man!
# Git repo: https://github.com/phlegx/acme.sh # Previous version by Martin Kammerlander, Phlegx Systems OG <martin.kammerlander@phlegx.com>
# TODO: Better Error handling # Previous update by Marc-Oliver Lange <git@die-lang.es>
# KASAPI SOAP guideline by https://github.com/o1oo11oo/kasapi.sh
######################################################################## ########################################################################
KAS_Api="https://kasapi.kasserver.com/soap/KasApi.php" KAS_Api_GET="$(_get "https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl")"
KAS_Auth="https://kasapi.kasserver.com/soap/KasAuth.php" KAS_Api="$(echo "$KAS_Api_GET" | tr -d ' ' | grep -i "<soap:addresslocation=" | sed "s/='/\n/g" | grep -i "http" | sed "s/'\/>//g")"
_info "[KAS] -> API URL $KAS_Api"
KAS_Auth_GET="$(_get "https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl")"
KAS_Auth="$(echo "$KAS_Auth_GET" | tr -d ' ' | grep -i "<soap:addresslocation=" | sed "s/='/\n/g" | grep -i "http" | sed "s/'\/>//g")"
_info "[KAS] -> AUTH URL $KAS_Auth"
KAS_default_ratelimit=5 # TODO - Every response delivers a ratelimit (seconds) where KASAPI is blocking a request.
######## Public functions ##################### ######## Public functions #####################
dns_kas_add() { dns_kas_add() {
_fulldomain=$1 _fulldomain=$1
_txtvalue=$2 _txtvalue=$2
_info "### -> Using DNS-01 All-inkl/Kasserver hook" _info "[KAS] -> Using DNS-01 All-inkl/Kasserver hook"
_info "### -> Adding $_fulldomain DNS TXT entry on All-inkl/Kasserver" _info "[KAS] -> Adding $_fulldomain DNS TXT entry on all-inkl.com/Kasserver"
_info "### -> Retriving Credential Token" _info "[KAS] -> Retriving Credential Token"
_get_credential_token _get_credential_token
_info "### -> Check and Save Props" _info "[KAS] -> Check and Save Props"
_check_and_save _check_and_save
_info "### -> Checking Zone and Record_Name" _info "[KAS] -> Checking Zone and Record_Name"
_get_zone_and_record_name "$_fulldomain" _get_zone_and_record_name "$_fulldomain"
_info "### -> Checking for existing Record entries" _info "[KAS] -> Checking for existing Record entries"
_get_record_id _get_record_id
# If there is a record_id, delete the entry # If there is a record_id, delete the entry
if [ -n "$_record_id" ]; then if [ -n "$_record_id" ]; then
_info "Existing records found. Now deleting old entries" _info "[KAS] -> Existing records found. Now deleting old entries"
for i in $_record_id; do for i in $_record_id; do
_delete_RecordByID "$i" _delete_RecordByID "$i"
done done
else else
_info "No record found." _info "[KAS] -> No record found."
fi fi
_info "### -> Creating TXT DNS record" _info "[KAS] -> Creating TXT DNS record"
action="add_dns_settings" action="add_dns_settings"
kasReqParam="{\"record_name\":\"$_record_name\",\"record_type\":\"TXT\",\"record_data\":\"$_txtvalue\",\"record_aux\":\"0\",\"zone_host\":\"$_zone\"}" kasReqParam="\"record_name\":\"$_record_name\""
kasReqParam="$kasReqParam,\"record_type\":\"TXT\""
kasReqParam="$kasReqParam,\"record_data\":\"$_txtvalue\""
kasReqParam="$kasReqParam,\"record_aux\":\"0\""
kasReqParam="$kasReqParam,\"zone_host\":\"$_zone\""
response="$(_callAPI "$action" "$kasReqParam")" response="$(_callAPI "$action" "$kasReqParam")"
_debug2 "[KAS] -> Response" "$response"
_debug2 "Response" "$response" if [ -z "$response" ]; then
_info "[KAS] -> Response was empty, please check manually."
if ! _contains "$response" "TRUE"; then return 1
_err "An unkown error occurred, please check manually." elif _contains "$response" "<SOAP-ENV:Fault>"; then
faultstring="$(echo "$response" | tr -d '\n\r' | sed "s/<faultstring>/\n=> /g" | sed "s/<\/faultstring>/\n/g" | grep "=>" | sed "s/=> //g")"
case "${faultstring}" in
"record_already_exists")
_info "[KAS] -> The record already exists, which must not be a problem. Please check manually."
;;
*)
_err "[KAS] -> An error =>$faultstring<= occurred, please check manually."
return 1
;;
esac
elif ! _contains "$response" "<item><key xsi:type=\"xsd:string\">ReturnString</key><value xsi:type=\"xsd:string\">TRUE</value></item>"; then
_err "[KAS] -> An unknown error occurred, please check manually."
return 1 return 1
fi fi
return 0 return 0
@ -63,29 +89,29 @@ dns_kas_rm() {
_fulldomain=$1 _fulldomain=$1
_txtvalue=$2 _txtvalue=$2
_info "### -> Using DNS-01 All-inkl/Kasserver hook" _info "[KAS] -> Using DNS-01 All-inkl/Kasserver hook"
_info "### -> Cleaning up after All-inkl/Kasserver hook" _info "[KAS] -> Cleaning up after All-inkl/Kasserver hook"
_info "### -> Removing $_fulldomain DNS TXT entry on All-inkl/Kasserver" _info "[KAS] -> Removing $_fulldomain DNS TXT entry on All-inkl/Kasserver"
_info "### -> Retriving Credential Token" _info "[KAS] -> Retriving Credential Token"
_get_credential_token _get_credential_token
_info "### -> Check and Save Props" _info "[KAS] -> Check and Save Props"
_check_and_save _check_and_save
_info "### -> Checking Zone and Record_Name" _info "[KAS] -> Checking Zone and Record_Name"
_get_zone_and_record_name "$_fulldomain" _get_zone_and_record_name "$_fulldomain"
_info "### -> Getting Record ID" _info "[KAS] -> Getting Record ID"
_get_record_id _get_record_id
_info "### -> Removing entries with ID: $_record_id" _info "[KAS] -> Removing entries with ID: $_record_id"
# If there is a record_id, delete the entry # If there is a record_id, delete the entry
if [ -n "$_record_id" ]; then if [ -n "$_record_id" ]; then
for i in $_record_id; do for i in $_record_id; do
_delete_RecordByID "$i" _delete_RecordByID "$i"
done done
else # Cannot delete or unkown error else # Cannot delete or unkown error
_info "No record_id found that can be deleted. Please check manually." _info "[KAS] -> No record_id found that can be deleted. Please check manually."
fi fi
return 0 return 0
} }
@ -95,11 +121,27 @@ dns_kas_rm() {
_delete_RecordByID() { _delete_RecordByID() {
recId=$1 recId=$1
action="delete_dns_settings" action="delete_dns_settings"
kasReqParam="{\"record_id\":\"$recId\"}" kasReqParam="\"record_id\":\"$recId\""
response="$(_callAPI "$action" "$kasReqParam")" response="$(_callAPI "$action" "$kasReqParam")"
_debug2 "Response" "$response" _debug2 "[KAS] -> Response" "$response"
if ! _contains "$response" "TRUE"; then
_info "Either the txt record is not found or another error occurred, please check manually." if [ -z "$response" ]; then
_info "[KAS] -> Response was empty, please check manually."
return 1
elif _contains "$response" "<SOAP-ENV:Fault>"; then
faultstring="$(echo "$response" | tr -d '\n\r' | sed "s/<faultstring>/\n=> /g" | sed "s/<\/faultstring>/\n/g" | grep "=>" | sed "s/=> //g")"
case "${faultstring}" in
"record_id_not_found")
_info "[KAS] -> The record was not found, which perhaps is not a problem. Please check manually."
;;
*)
_err "[KAS] -> An error =>$faultstring<= occurred, please check manually."
return 1
;;
esac
elif ! _contains "$response" "<item><key xsi:type=\"xsd:string\">ReturnString</key><value xsi:type=\"xsd:string\">TRUE</value></item>"; then
_err "[KAS] -> An unknown error occurred, please check manually."
return 1
fi fi
} }
# Checks for the ENV variables and saves them # Checks for the ENV variables and saves them
@ -112,7 +154,7 @@ _check_and_save() {
KAS_Login= KAS_Login=
KAS_Authtype= KAS_Authtype=
KAS_Authdata= KAS_Authdata=
_err "No auth details provided. Please set user credentials using the \$KAS_Login, \$KAS_Authtype, and \$KAS_Authdata environment variables." _err "[KAS] -> No auth details provided. Please set user credentials using the \$KAS_Login, \$KAS_Authtype, and \$KAS_Authdata environment variables."
return 1 return 1
fi fi
_saveaccountconf_mutable KAS_Login "$KAS_Login" _saveaccountconf_mutable KAS_Login "$KAS_Login"
@ -125,9 +167,18 @@ _check_and_save() {
# See: https://github.com/Neilpang/acme.sh/wiki/DNS-API-Dev-Guide # See: https://github.com/Neilpang/acme.sh/wiki/DNS-API-Dev-Guide
_get_zone_and_record_name() { _get_zone_and_record_name() {
action="get_domains" action="get_domains"
kasReqParam="[]" response="$(_callAPI "$action")"
response="$(_callAPI "$action" "$kasReqParam")" _debug2 "[KAS] -> Response" "$response"
_debug2 "Response" "$response"
if [ -z "$response" ]; then
_info "[KAS] -> Response was empty, please check manually."
return 1
elif _contains "$response" "<SOAP-ENV:Fault>"; then
faultstring="$(echo "$response" | tr -d '\n\r' | sed "s/<faultstring>/\n=> /g" | sed "s/<\/faultstring>/\n/g" | grep "=>" | sed "s/=> //g")"
_err "[KAS] -> Either no domains were found or another error =>$faultstring<= occurred, please check manually."
return 1
fi
zonen="$(echo "$response" | sed 's/<item>/\n/g' | sed -r 's/(.*<key xsi:type="xsd:string">domain_name<\/key><value xsi:type="xsd:string">)(.*)(<\/value.*)/\2/' | sed '/^</d')" zonen="$(echo "$response" | sed 's/<item>/\n/g' | sed -r 's/(.*<key xsi:type="xsd:string">domain_name<\/key><value xsi:type="xsd:string">)(.*)(<\/value.*)/\2/' | sed '/^</d')"
domain="$1" domain="$1"
temp_domain="$(echo "$1" | sed 's/\.$//')" temp_domain="$(echo "$1" | sed 's/\.$//')"
@ -142,59 +193,80 @@ _get_zone_and_record_name() {
_zone="${rootzone}." _zone="${rootzone}."
temp_record_name="$(echo "$temp_domain" | sed "s/$rootzone//g")" temp_record_name="$(echo "$temp_domain" | sed "s/$rootzone//g")"
_record_name="$(echo "$temp_record_name" | sed 's/\.$//')" _record_name="$(echo "$temp_record_name" | sed 's/\.$//')"
_debug "Zone:" "$_zone" _debug "[KAS] -> Zone:" "$_zone"
_debug "Domain:" "$domain" _debug "[KAS] -> Domain:" "$domain"
_debug "Record_Name:" "$_record_name" _debug "[KAS] -> Record_Name:" "$_record_name"
return 0 return 0
} }
# Retrieve the DNS record ID # Retrieve the DNS record ID
_get_record_id() { _get_record_id() {
action="get_dns_settings" action="get_dns_settings"
kasReqParam="{\"zone_host\":\"$_zone\",\"nameserver\":\"ns5.kasserver.com\"}" kasReqParam="\"zone_host\":\"$_zone\""
response="$(_callAPI "$action" "$kasReqParam")" response="$(_callAPI "$action" "$kasReqParam")"
_debug2 "[KAS] -> Response" "$response"
_debug2 "Response" "$response" if [ -z "$response" ]; then
_record_id="$(echo "$response" | sed 's/<item xsi:type="ns2:Map">/\n/g' | sed -n -e "/^.*$_record_name.*/Ip" | sed -n -e "/^.*$_txtvalue.*/Ip" | sed -r 's/(.*record_id<\/key><value xsi:type="xsd:string">)([0-9]+)(<\/value.*)/\2/')" _info "[KAS] -> Response was empty, please check manually."
_debug "Record Id: " "$_record_id" return 1
elif _contains "$response" "<SOAP-ENV:Fault>"; then
faultstring="$(echo "$response" | tr -d '\n\r' | sed "s/<faultstring>/\n=> /g" | sed "s/<\/faultstring>/\n/g" | grep "=>" | sed "s/=> //g")"
_err "[KAS] -> Either no domains were found or another error =>$faultstring<= occurred, please check manually."
return 1
fi
_record_id="$(echo "$response" | tr -d '\n\r' | sed "s/<item xsi:type=\"ns2:Map\">/\n/g" | grep -i "$_record_name" | grep -i ">TXT<" | sed "s/<item><key xsi:type=\"xsd:string\">record_id<\/key><value xsi:type=\"xsd:string\">/=>/g" | sed "s/<\/value><\/item>/\n/g" | grep "=>" | sed "s/=>//g")"
_debug "[KAS] -> Record Id: " "$_record_id"
return 0 return 0
} }
# Retrieve credential token # Retrieve credential token
_get_credential_token() { _get_credential_token() {
data="<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"urn:xmethodsKasApiAuthentication\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><SOAP-ENV:Body><ns1:KasAuth>" baseParamAuth="\"kas_login\":\"$KAS_Login\""
data="$data<Params xsi:type=\"xsd:string\">{\"kas_login\":\"$KAS_Login\",\"kas_auth_type\":\"$KAS_Authtype\",\"kas_auth_data\":\"$KAS_Authdata\",\"session_lifetime\":600,\"session_update_lifetime\":\"Y\",\"session_2fa\":123456}</Params>" baseParamAuth="$baseParamAuth,\"kas_auth_type\":\"$KAS_Authtype\""
data="$data</ns1:KasAuth></SOAP-ENV:Body></SOAP-ENV:Envelope>" baseParamAuth="$baseParamAuth,\"kas_auth_data\":\"$KAS_Authdata\""
baseParamAuth="$baseParamAuth,\"session_lifetime\":600"
baseParamAuth="$baseParamAuth,\"session_update_lifetime\":\"Y\""
_debug "Be frindly and wait 10 seconds by default before calling KAS API." data='<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:xmethodsKasApiAuthentication" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:KasAuth><Params xsi:type="xsd:string">{'
_sleep 10 data="$data$baseParamAuth}</Params></ns1:KasAuth></SOAP-ENV:Body></SOAP-ENV:Envelope>"
_debug "[KAS] -> Be friendly and wait $KAS_default_ratelimit seconds by default before calling KAS API."
_sleep $KAS_default_ratelimit
contentType="text/xml" contentType="text/xml"
export _H1="SOAPAction: ns1:KasAuth" export _H1="SOAPAction: urn:xmethodsKasApiAuthentication#KasAuth"
response="$(_post "$data" "$KAS_Auth" "" "POST" "$contentType")" response="$(_post "$data" "$KAS_Auth" "" "POST" "$contentType")"
_debug2 "Response" "$response" _debug2 "[KAS] -> Response" "$response"
_credential_token="$(echo "$response" | tr '\n' ' ' | sed 's/.*return xsi:type="xsd:string">\(.*\)<\/return>/\1/' | sed 's/<\/ns1:KasAuthResponse\(.*\)Envelope>.*//')" _credential_token="$(echo "$response" | tr '\n' ' ' | sed 's/.*return xsi:type="xsd:string">\(.*\)<\/return>/\1/' | sed 's/<\/ns1:KasAuthResponse\(.*\)Envelope>.*//')"
_debug "Credential Token: " "$_credential_token" _debug "[KAS] -> Credential Token: " "$_credential_token"
return 0 return 0
} }
_callAPI() { _callAPI() {
kasaction=$1 kasaction=$1
kasReqParams=$2 kasReqParams=$2
baseParam="<Params xsi:type=\"xsd:string\">{\"kas_login\":\"$KAS_Login\",\"kas_auth_type\":\"session\",\"kas_auth_data\":\"$_credential_token\",\"kas_action\":\"$kasaction\",\"KasRequestParams\":$kasReqParams"
baseParamClosing="}</Params>"
data="<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"urn:xmethodsKasApi\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><SOAP-ENV:Body><ns1:KasApi>"
data="$data$baseParam$baseParamClosing"
data="$data</ns1:KasApi></SOAP-ENV:Body></SOAP-ENV:Envelope>"
_debug2 "Request" "$data"
_debug "Be frindly and wait 10 seconds by default before calling KAS API." baseParamAuth="\"kas_login\":\"$KAS_Login\""
_sleep 10 baseParamAuth="$baseParamAuth,\"kas_auth_type\":\"session\""
baseParamAuth="$baseParamAuth,\"kas_auth_data\":\"$_credential_token\""
data='<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:xmethodsKasApi" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:KasApi><Params xsi:type="xsd:string">{'
data="$data$baseParamAuth,\"kas_action\":\"$kasaction\""
if [ -n "$kasReqParams" ]; then
data="$data,\"KasRequestParams\":{$kasReqParams}"
fi
data="$data}</Params></ns1:KasApi></SOAP-ENV:Body></SOAP-ENV:Envelope>"
_debug2 "[KAS] -> Request" "$data"
_debug "[KAS] -> Be friendly and wait $KAS_default_ratelimit seconds by default before calling KAS API."
_sleep $KAS_default_ratelimit
contentType="text/xml" contentType="text/xml"
export _H1="SOAPAction: ns1:KasApi" export _H1="SOAPAction: urn:xmethodsKasApi#KasApi"
response="$(_post "$data" "$KAS_Api" "" "POST" "$contentType")" response="$(_post "$data" "$KAS_Api" "" "POST" "$contentType")"
_debug2 "Response" "$response" _debug2 "[KAS] -> Response" "$response"
echo "$response" echo "$response"
} }

147
dnsapi/dns_la.sh Normal file
View File

@ -0,0 +1,147 @@
#!/usr/bin/env sh
#LA_Id="test123"
#LA_Key="d1j2fdo4dee3948"
LA_Api="https://api.dns.la/api"
######## Public functions #####################
#Usage: dns_la_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_la_add() {
fulldomain=$1
txtvalue=$2
LA_Id="${LA_Id:-$(_readaccountconf_mutable LA_Id)}"
LA_Key="${LA_Key:-$(_readaccountconf_mutable LA_Key)}"
if [ -z "$LA_Id" ] || [ -z "$LA_Key" ]; then
LA_Id=""
LA_Key=""
_err "You didn't specify a dnsla api id and key yet."
return 1
fi
#save the api key and email to the account conf file.
_saveaccountconf_mutable LA_Id "$LA_Id"
_saveaccountconf_mutable LA_Key "$LA_Key"
_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 _la_rest "record.ashx?cmd=create&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&host=$_sub_domain&recordtype=TXT&recorddata=$txtvalue&recordline="; then
if _contains "$response" '"resultid":'; then
_info "Added, OK"
return 0
elif _contains "$response" '"code":532'; then
_info "Already exists, OK"
return 0
else
_err "Add txt record error."
return 1
fi
fi
_err "Add txt record error."
return 1
}
#fulldomain txtvalue
dns_la_rm() {
fulldomain=$1
txtvalue=$2
LA_Id="${LA_Id:-$(_readaccountconf_mutable LA_Id)}"
LA_Key="${LA_Key:-$(_readaccountconf_mutable LA_Key)}"
_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"
if ! _la_rest "record.ashx?cmd=listn&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&domain=$_domain&host=$_sub_domain&recordtype=TXT&recorddata=$txtvalue"; then
_err "Error"
return 1
fi
if ! _contains "$response" '"recordid":'; then
_info "Don't need to remove."
return 0
fi
record_id=$(printf "%s" "$response" | grep '"recordid":' | cut -d : -f 2 | cut -d , -f 1 | tr -d '\r' | tr -d '\n')
_debug "record_id" "$record_id"
if [ -z "$record_id" ]; then
_err "Can not get record id to remove."
return 1
fi
if ! _la_rest "record.ashx?cmd=remove&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&domain=$_domain&recordid=$record_id"; then
_err "Delete record error."
return 1
fi
_contains "$response" '"code":300'
}
#################### 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)
if [ -z "$h" ]; then
#not valid
return 1
fi
if ! _la_rest "domain.ashx?cmd=get&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domain=$h"; then
return 1
fi
if _contains "$response" '"domainid":'; then
_domain_id=$(printf "%s" "$response" | grep '"domainid":' | cut -d : -f 2 | cut -d , -f 1 | tr -d '\r' | tr -d '\n')
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
}
#Usage: URI
_la_rest() {
url="$LA_Api/$1"
_debug "$url"
if ! response="$(_get "$url" | tr -d ' ' | tr "}" ",")"; then
_err "Error: $url"
return 1
fi
_debug2 response "$response"
return 0
}