neil
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 455 additions and 23 deletions
-
211.github/workflows/DNS.yml
-
17.github/workflows/LetsEncrypt.yml
-
40README.md
-
9dnsapi/dns_duckdns.sh
-
199dnsapi/dns_infomaniak.sh
-
2dnsapi/dns_ovh.sh
@ -0,0 +1,211 @@ |
|||
name: DNS |
|||
on: |
|||
push: |
|||
paths: |
|||
- 'dnsapi/*.sh' |
|||
- '.github/workflows/DNS.yml' |
|||
pull_request: |
|||
branches: |
|||
- 'dev' |
|||
paths: |
|||
- 'dnsapi/*.sh' |
|||
- '.github/workflows/DNS.yml' |
|||
|
|||
|
|||
jobs: |
|||
CheckToken: |
|||
runs-on: ubuntu-latest |
|||
outputs: |
|||
hasToken: ${{ steps.step_one.outputs.hasToken }} |
|||
steps: |
|||
- name: Set the value |
|||
id: step_one |
|||
run: | |
|||
if [ "${{secrets.TokenName1}}" ] ; then |
|||
echo "::set-output name=hasToken::true" |
|||
else |
|||
echo "::set-output name=hasToken::false" |
|||
fi |
|||
- name: Check the value |
|||
run: echo ${{ steps.step_one.outputs.hasToken }} |
|||
|
|||
Fail: |
|||
runs-on: ubuntu-latest |
|||
needs: CheckToken |
|||
if: "contains(needs.CheckToken.outputs.hasToken, 'false')" |
|||
steps: |
|||
- name: "Read this: https://github.com/acmesh-official/acme.sh/wiki/DNS-API-Test" |
|||
run: | |
|||
echo "Read this: https://github.com/acmesh-official/acme.sh/wiki/DNS-API-Test" |
|||
if [ "${{github.actor}}" != "Neilpang" ]; then |
|||
false |
|||
fi |
|||
|
|||
Docker: |
|||
runs-on: ubuntu-latest |
|||
needs: CheckToken |
|||
if: "contains(needs.CheckToken.outputs.hasToken, 'true')" |
|||
env: |
|||
TEST_DNS : ${{ secrets.TEST_DNS }} |
|||
TestingDomain: ${{ secrets.TestingDomain }} |
|||
TEST_DNS_NO_WILDCARD: ${{ secrets.TEST_DNS_NO_WILDCARD }} |
|||
TEST_DNS_SLEEP: ${{ secrets.TEST_DNS_SLEEP }} |
|||
CASE: le_test_dnsapi |
|||
TEST_LOCAL: 1 |
|||
DEBUG: 1 |
|||
steps: |
|||
- uses: actions/checkout@v2 |
|||
- name: Clone acmetest |
|||
run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/ |
|||
- name: Set env file |
|||
run: | |
|||
cd ../acmetest |
|||
if [ "${{ secrets.TokenName1}}" ] ; then |
|||
echo "${{ secrets.TokenName1}}=${{ secrets.TokenValue1}}" >> env.list |
|||
fi |
|||
if [ "${{ secrets.TokenName2}}" ] ; then |
|||
echo "${{ secrets.TokenName2}}=${{ secrets.TokenValue2}}" >> env.list |
|||
fi |
|||
if [ "${{ secrets.TokenName3}}" ] ; then |
|||
echo "${{ secrets.TokenName3}}=${{ secrets.TokenValue3}}" >> env.list |
|||
fi |
|||
if [ "${{ secrets.TokenName4}}" ] ; then |
|||
echo "${{ secrets.TokenName4}}=${{ secrets.TokenValue4}}" >> env.list |
|||
fi |
|||
if [ "${{ secrets.TokenName5}}" ] ; then |
|||
echo "${{ secrets.TokenName5}}=${{ secrets.TokenValue5}}" >> env.list |
|||
fi |
|||
echo "TEST_DNS_NO_WILDCARD" >> env.list |
|||
echo "TEST_DNS_SLEEP" >> env.list |
|||
- name: Run acmetest |
|||
run: cd ../acmetest && ./rundocker.sh testall |
|||
|
|||
MacOS: |
|||
runs-on: macos-latest |
|||
needs: Docker |
|||
env: |
|||
TEST_DNS : ${{ secrets.TEST_DNS }} |
|||
TestingDomain: ${{ secrets.TestingDomain }} |
|||
TEST_DNS_NO_WILDCARD: ${{ secrets.TEST_DNS_NO_WILDCARD }} |
|||
TEST_DNS_SLEEP: ${{ secrets.TEST_DNS_SLEEP }} |
|||
CASE: le_test_dnsapi |
|||
TEST_LOCAL: 1 |
|||
DEBUG: 1 |
|||
steps: |
|||
- uses: actions/checkout@v2 |
|||
- name: Install tools |
|||
run: brew update && brew install socat; |
|||
- name: Clone acmetest |
|||
run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/ |
|||
- name: Run acmetest |
|||
run: | |
|||
if [ "${{ secrets.TokenName1}}" ] ; then |
|||
export ${{ secrets.TokenName1}}=${{ secrets.TokenValue1}} |
|||
fi |
|||
if [ "${{ secrets.TokenName2}}" ] ; then |
|||
export ${{ secrets.TokenName2}}=${{ secrets.TokenValue2}} |
|||
fi |
|||
if [ "${{ secrets.TokenName3}}" ] ; then |
|||
export ${{ secrets.TokenName3}}=${{ secrets.TokenValue3}} |
|||
fi |
|||
if [ "${{ secrets.TokenName4}}" ] ; then |
|||
export ${{ secrets.TokenName4}}=${{ secrets.TokenValue4}} |
|||
fi |
|||
if [ "${{ secrets.TokenName5}}" ] ; then |
|||
export ${{ secrets.TokenName5}}=${{ secrets.TokenValue5}} |
|||
fi |
|||
cd ../acmetest |
|||
./letest.sh |
|||
|
|||
Windows: |
|||
runs-on: windows-latest |
|||
needs: MacOS |
|||
env: |
|||
TEST_DNS : ${{ secrets.TEST_DNS }} |
|||
TestingDomain: ${{ secrets.TestingDomain }} |
|||
TEST_DNS_NO_WILDCARD: ${{ secrets.TEST_DNS_NO_WILDCARD }} |
|||
TEST_DNS_SLEEP: ${{ secrets.TEST_DNS_SLEEP }} |
|||
CASE: le_test_dnsapi |
|||
TEST_LOCAL: 1 |
|||
DEBUG: 1 |
|||
steps: |
|||
- name: Set git to use LF |
|||
run: | |
|||
git config --global core.autocrlf false |
|||
- uses: actions/checkout@v2 |
|||
- name: Install cygwin base packages with chocolatey |
|||
run: | |
|||
choco config get cacheLocation |
|||
choco install --no-progress cygwin |
|||
shell: cmd |
|||
- name: Install cygwin additional packages |
|||
run: | |
|||
C:\tools\cygwin\cygwinsetup.exe -qgnNdO -R C:/tools/cygwin -s http://mirrors.kernel.org/sourceware/cygwin/ -P socat,curl,cron,unzip,git |
|||
shell: cmd |
|||
- name: Set ENV |
|||
run: | |
|||
echo '::set-env name=PATH::C:\tools\cygwin\bin;C:\tools\cygwin\usr\bin' |
|||
- name: Clone acmetest |
|||
run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/ |
|||
- name: Run acmetest |
|||
shell: bash |
|||
run: | |
|||
if [ "${{ secrets.TokenName1}}" ] ; then |
|||
export ${{ secrets.TokenName1}}=${{ secrets.TokenValue1}} |
|||
fi |
|||
if [ "${{ secrets.TokenName2}}" ] ; then |
|||
export ${{ secrets.TokenName2}}=${{ secrets.TokenValue2}} |
|||
fi |
|||
if [ "${{ secrets.TokenName3}}" ] ; then |
|||
export ${{ secrets.TokenName3}}=${{ secrets.TokenValue3}} |
|||
fi |
|||
if [ "${{ secrets.TokenName4}}" ] ; then |
|||
export ${{ secrets.TokenName4}}=${{ secrets.TokenValue4}} |
|||
fi |
|||
if [ "${{ secrets.TokenName5}}" ] ; then |
|||
export ${{ secrets.TokenName5}}=${{ secrets.TokenValue5}} |
|||
fi |
|||
cd ../acmetest |
|||
./letest.sh |
|||
|
|||
FreeBSD: |
|||
runs-on: macos-latest |
|||
needs: Windows |
|||
env: |
|||
TEST_DNS : ${{ secrets.TEST_DNS }} |
|||
TestingDomain: ${{ secrets.TestingDomain }} |
|||
TEST_DNS_NO_WILDCARD: ${{ secrets.TEST_DNS_NO_WILDCARD }} |
|||
TEST_DNS_SLEEP: ${{ secrets.TEST_DNS_SLEEP }} |
|||
CASE: le_test_dnsapi |
|||
TEST_LOCAL: 1 |
|||
DEBUG: 1 |
|||
steps: |
|||
- uses: actions/checkout@v2 |
|||
- name: Clone acmetest |
|||
run: cd .. && git clone https://github.com/acmesh-official/acmetest.git && cp -r acme.sh acmetest/ |
|||
- uses: vmactions/freebsd-vm@v0.0.7 |
|||
with: |
|||
envs: 'TEST_DNS TestingDomain TEST_DNS_NO_WILDCARD TEST_DNS_SLEEP CASE TEST_LOCAL DEBUG ${{ secrets.TokenName1}} ${{ secrets.TokenName2}} ${{ secrets.TokenName3}} ${{ secrets.TokenName4}} ${{ secrets.TokenName5}}' |
|||
prepare: pkg install -y socat curl |
|||
usesh: true |
|||
run: | |
|||
if [ "${{ secrets.TokenName1}}" ] ; then |
|||
export ${{ secrets.TokenName1}}=${{ secrets.TokenValue1}} |
|||
fi |
|||
if [ "${{ secrets.TokenName2}}" ] ; then |
|||
export ${{ secrets.TokenName2}}=${{ secrets.TokenValue2}} |
|||
fi |
|||
if [ "${{ secrets.TokenName3}}" ] ; then |
|||
export ${{ secrets.TokenName3}}=${{ secrets.TokenValue3}} |
|||
fi |
|||
if [ "${{ secrets.TokenName4}}" ] ; then |
|||
export ${{ secrets.TokenName4}}=${{ secrets.TokenValue4}} |
|||
fi |
|||
if [ "${{ secrets.TokenName5}}" ] ; then |
|||
export ${{ secrets.TokenName5}}=${{ secrets.TokenValue5}} |
|||
fi |
|||
cd ../acmetest |
|||
./letest.sh |
|||
|
|||
|
|||
|
@ -0,0 +1,199 @@ |
|||
#!/usr/bin/env sh |
|||
|
|||
############################################################################### |
|||
# Infomaniak API integration |
|||
# |
|||
# To use this API you need visit the API dashboard of your account |
|||
# once logged into https://manager.infomaniak.com add /api/dashboard to the URL |
|||
# |
|||
# Please report bugs to |
|||
# https://github.com/acmesh-official/acme.sh/issues/3188 |
|||
# |
|||
# Note: the URL looks like this: |
|||
# https://manager.infomaniak.com/v3/<account_id>/api/dashboard |
|||
# Then generate a token with the scope Domain |
|||
# this is given as an environment variable INFOMANIAK_API_TOKEN |
|||
############################################################################### |
|||
|
|||
# base variables |
|||
|
|||
DEFAULT_INFOMANIAK_API_URL="https://api.infomaniak.com" |
|||
DEFAULT_INFOMANIAK_TTL=300 |
|||
|
|||
######## Public functions ##################### |
|||
|
|||
#Usage: dns_infomaniak_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
|||
dns_infomaniak_add() { |
|||
|
|||
INFOMANIAK_API_TOKEN="${INFOMANIAK_API_TOKEN:-$(_readaccountconf_mutable INFOMANIAK_API_TOKEN)}" |
|||
INFOMANIAK_API_URL="${INFOMANIAK_API_URL:-$(_readaccountconf_mutable INFOMANIAK_API_URL)}" |
|||
INFOMANIAK_TTL="${INFOMANIAK_TTL:-$(_readaccountconf_mutable INFOMANIAK_TTL)}" |
|||
|
|||
if [ -z "$INFOMANIAK_API_TOKEN" ]; then |
|||
INFOMANIAK_API_TOKEN="" |
|||
_err "Please provide a valid Infomaniak API token in variable INFOMANIAK_API_TOKEN" |
|||
return 1 |
|||
fi |
|||
|
|||
if [ -z "$INFOMANIAK_API_URL" ]; then |
|||
INFOMANIAK_API_URL="$DEFAULT_INFOMANIAK_API_URL" |
|||
fi |
|||
|
|||
if [ -z "$INFOMANIAK_TTL" ]; then |
|||
INFOMANIAK_TTL="$DEFAULT_INFOMANIAK_TTL" |
|||
fi |
|||
|
|||
#save the token to the account conf file. |
|||
_saveaccountconf_mutable INFOMANIAK_API_TOKEN "$INFOMANIAK_API_TOKEN" |
|||
|
|||
if [ "$INFOMANIAK_API_URL" != "$DEFAULT_INFOMANIAK_API_URL" ]; then |
|||
_saveaccountconf_mutable INFOMANIAK_API_URL "$INFOMANIAK_API_URL" |
|||
fi |
|||
|
|||
if [ "$INFOMANIAK_TTL" != "$DEFAULT_INFOMANIAK_TTL" ]; then |
|||
_saveaccountconf_mutable INFOMANIAK_TTL "$INFOMANIAK_TTL" |
|||
fi |
|||
|
|||
export _H1="Authorization: Bearer $INFOMANIAK_API_TOKEN" |
|||
export _H2="Content-Type: application/json" |
|||
|
|||
fulldomain="$1" |
|||
txtvalue="$2" |
|||
|
|||
_info "Infomaniak DNS API" |
|||
_debug fulldomain "$fulldomain" |
|||
_debug txtvalue "$txtvalue" |
|||
|
|||
fqdn=${fulldomain#_acme-challenge.} |
|||
|
|||
# guess which base domain to add record to |
|||
zone_and_id=$(_find_zone "$fqdn") |
|||
if [ -z "$zone_and_id" ]; then |
|||
_err "cannot find zone to modify" |
|||
return 1 |
|||
fi |
|||
zone=${zone_and_id% *} |
|||
domain_id=${zone_and_id#* } |
|||
|
|||
# extract first part of domain |
|||
key=${fulldomain%.$zone} |
|||
|
|||
_debug "zone:$zone id:$domain_id key:$key" |
|||
|
|||
# payload |
|||
data="{\"type\": \"TXT\", \"source\": \"$key\", \"target\": \"$txtvalue\", \"ttl\": $INFOMANIAK_TTL}" |
|||
|
|||
# API call |
|||
response=$(_post "$data" "${INFOMANIAK_API_URL}/1/domain/$domain_id/dns/record") |
|||
if [ -n "$response" ] && echo "$response" | _contains '"result":"success"'; then |
|||
_info "Record added" |
|||
_debug "Response: $response" |
|||
return 0 |
|||
fi |
|||
_err "could not create record" |
|||
_debug "Response: $response" |
|||
return 1 |
|||
} |
|||
|
|||
#Usage: fulldomain txtvalue |
|||
#Remove the txt record after validation. |
|||
dns_infomaniak_rm() { |
|||
|
|||
INFOMANIAK_API_TOKEN="${INFOMANIAK_API_TOKEN:-$(_readaccountconf_mutable INFOMANIAK_API_TOKEN)}" |
|||
INFOMANIAK_API_URL="${INFOMANIAK_API_URL:-$(_readaccountconf_mutable INFOMANIAK_API_URL)}" |
|||
INFOMANIAK_TTL="${INFOMANIAK_TTL:-$(_readaccountconf_mutable INFOMANIAK_TTL)}" |
|||
|
|||
if [ -z "$INFOMANIAK_API_TOKEN" ]; then |
|||
INFOMANIAK_API_TOKEN="" |
|||
_err "Please provide a valid Infomaniak API token in variable INFOMANIAK_API_TOKEN" |
|||
return 1 |
|||
fi |
|||
|
|||
if [ -z "$INFOMANIAK_API_URL" ]; then |
|||
INFOMANIAK_API_URL="$DEFAULT_INFOMANIAK_API_URL" |
|||
fi |
|||
|
|||
if [ -z "$INFOMANIAK_TTL" ]; then |
|||
INFOMANIAK_TTL="$DEFAULT_INFOMANIAK_TTL" |
|||
fi |
|||
|
|||
#save the token to the account conf file. |
|||
_saveaccountconf_mutable INFOMANIAK_API_TOKEN "$INFOMANIAK_API_TOKEN" |
|||
|
|||
if [ "$INFOMANIAK_API_URL" != "$DEFAULT_INFOMANIAK_API_URL" ]; then |
|||
_saveaccountconf_mutable INFOMANIAK_API_URL "$INFOMANIAK_API_URL" |
|||
fi |
|||
|
|||
if [ "$INFOMANIAK_TTL" != "$DEFAULT_INFOMANIAK_TTL" ]; then |
|||
_saveaccountconf_mutable INFOMANIAK_TTL "$INFOMANIAK_TTL" |
|||
fi |
|||
|
|||
export _H1="Authorization: Bearer $INFOMANIAK_API_TOKEN" |
|||
export _H2="ContentType: application/json" |
|||
|
|||
fulldomain=$1 |
|||
txtvalue=$2 |
|||
_info "Infomaniak DNS API" |
|||
_debug fulldomain "$fulldomain" |
|||
_debug txtvalue "$txtvalue" |
|||
|
|||
fqdn=${fulldomain#_acme-challenge.} |
|||
|
|||
# guess which base domain to add record to |
|||
zone_and_id=$(_find_zone "$fqdn") |
|||
if [ -z "$zone_and_id" ]; then |
|||
_err "cannot find zone to modify" |
|||
return 1 |
|||
fi |
|||
zone=${zone_and_id% *} |
|||
domain_id=${zone_and_id#* } |
|||
|
|||
# extract first part of domain |
|||
key=${fulldomain%.$zone} |
|||
|
|||
_debug "zone:$zone id:$domain_id key:$key" |
|||
|
|||
# find previous record |
|||
# shellcheck disable=SC1004 |
|||
record_id=$(_get "${INFOMANIAK_API_URL}/1/domain/$domain_id/dns/record" | sed 's/.*"data":\[\(.*\)\]}/\1/; s/},{/}\ |
|||
{/g' | sed -n 's/.*"id":"*\([0-9]*\)"*.*"source_idn":"'"$fulldomain"'".*"target_idn":"'"$txtvalue"'".*/\1/p') |
|||
if [ -z "$record_id" ]; then |
|||
_err "could not find record to delete" |
|||
return 1 |
|||
fi |
|||
_debug "record_id: $record_id" |
|||
|
|||
# API call |
|||
response=$(_post "" "${INFOMANIAK_API_URL}/1/domain/$domain_id/dns/record/$record_id" "" DELETE) |
|||
if [ -n "$response" ] && echo "$response" | _contains '"result":"success"'; then |
|||
_info "Record deleted" |
|||
return 0 |
|||
fi |
|||
_err "could not delete record" |
|||
return 1 |
|||
} |
|||
|
|||
#################### Private functions below ################################## |
|||
|
|||
_get_domain_id() { |
|||
domain="$1" |
|||
|
|||
# shellcheck disable=SC1004 |
|||
_get "${INFOMANIAK_API_URL}/1/product?service_name=domain&customer_name=$domain" | sed 's/.*"data":\[{\(.*\)}\]}/\1/; s/,/\ |
|||
/g' | sed -n 's/^"id":\(.*\)/\1/p' |
|||
} |
|||
|
|||
_find_zone() { |
|||
zone="$1" |
|||
|
|||
# find domain in list, removing . parts sequentialy |
|||
while _contains "$zone" '\.'; do |
|||
_debug "testing $zone" |
|||
id=$(_get_domain_id "$zone") |
|||
if [ -n "$id" ]; then |
|||
echo "$zone $id" |
|||
return |
|||
fi |
|||
zone=${zone#*.} |
|||
done |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue