-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All inkl kasserver dns script #1341
Changes from 13 commits
861df49
32d7bd5
8c634d8
cbf0cea
e431df0
11bfb1e
26b5180
cb4a2cf
c34aadf
68f66ca
1ef7fd3
16bfb17
e22c5ea
ec1f984
d87e507
c641b61
953a9b1
3ccac62
239d534
594b83e
99c47dd
a138425
2214507
8dd1df7
58cfc0d
0246196
96180e7
431c53e
fb209cd
6613ae5
1c4b831
7a30cb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,3 @@ DNS api usage: | |
|
||
|
||
https://github.com/Neilpang/acme.sh/wiki/dnsapi | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#!/usr/bin/env sh | ||
######################################################################## | ||
# All-inkl Kasserver hook script for acme.sh | ||
# | ||
# Environment variables: | ||
# | ||
# - $KAS_Login (Kasserver API login name) | ||
# - $KAS_Authtype (Kasserver API auth type. Default: sha1) | ||
# - $KAS_Authdata (Kasserver API auth data.) | ||
# | ||
# Author: Martin Kammerlander, Phlegx Systems OG <[email protected]> | ||
# Credits: Inspired by dns_he.sh. Thanks a lot man! | ||
# Git repo: https://github.com/phlegx/acme.sh | ||
# TODO: Better Error handling | ||
# TODO: Does not work with Domains that have double endings like i.e. 'co.uk' | ||
# => Get all root zones and compare once the provider offers that. | ||
|
||
KAS_Api="https://kasapi.kasserver.com/dokumentation/formular.php" | ||
|
||
######## Public functions ##################### | ||
|
||
dns_kas_add() { | ||
_fulldomain=$1 | ||
_txtvalue=$2 | ||
_info "Using DNS-01 All-inkl/Kasserver hook" | ||
_info "Adding or Updating $_fulldomain DNS TXT entry on All-inkl/Kasserver" | ||
|
||
_check_and_save | ||
_get_zone "$_fulldomain" | ||
_get_record_name "$_fulldomain" | ||
_get_record_id | ||
|
||
_info "Creating TXT DNS record" | ||
params="?kas_login=$KAS_Login" | ||
params="$params&kas_auth_type=$KAS_Authtype" | ||
params="$params&kas_auth_data=$KAS_Authdata" | ||
params="$params&var1=record_name" | ||
params="$params&wert1=$_record_name" | ||
params="$params&var2=record_type" | ||
params="$params&wert2=TXT" | ||
params="$params&var3=record_data" | ||
params="$params&wert3=$_txtvalue" | ||
params="$params&var4=record_aux" | ||
params="$params&wert4=0" | ||
params="$params&kas_action=add_dns_settings" | ||
params="$params&var5=zone_host" | ||
params="$params&wert5=$_zone" | ||
_debug2 "Wait for 10 seconds by default before calling KAS API." | ||
sleep 10 | ||
response="$(_get "$KAS_Api$params")" | ||
_debug2 "response" "$response" | ||
|
||
if ! _contains "$response" "TRUE"; then | ||
_err "An unkown error occurred, please check manually." | ||
return 1 | ||
fi | ||
return 0 | ||
} | ||
|
||
dns_kas_rm() { | ||
_fulldomain=$1 | ||
_txtvalue=$2 | ||
_info "Using DNS-01 All-inkl/Kasserver hook" | ||
_info "Cleaning up after All-inkl/Kasserver hook" | ||
_info "Removing $_fulldomain DNS TXT entry on All-inkl/Kasserver" | ||
|
||
_check_and_save | ||
_get_zone "$_fulldomain" | ||
_get_record_name "$_fulldomain" | ||
_get_record_id | ||
|
||
# If there is a record_id, delete the entry | ||
if [ -n "$_record_id" ]; then | ||
params="?kas_login=$KAS_Login" | ||
params="$params&kas_auth_type=$KAS_Authtype" | ||
params="$params&kas_auth_data=$KAS_Authdata" | ||
params="$params&kas_action=delete_dns_settings" | ||
|
||
# split it into a seperated list, if there where multiples entries made | ||
records=($_record_id) | ||
for i in "${records[@]}" | ||
do | ||
params2="$params&var1=record_id" | ||
params2="$params2&wert1=$i" | ||
_debug2 "Wait for 10 seconds by default before calling KAS API." | ||
sleep 10 | ||
response="$(_get "$KAS_Api$params2")" | ||
_debug2 "response" "$response" | ||
if ! _contains "$response" "TRUE"; then | ||
_err "Either the txt record is not found or another error occurred, please check manually." | ||
return 1 | ||
fi | ||
done | ||
else # Cannot delete or unkown error | ||
_err "No record_id found that can be deleted. Please check manually." | ||
return 1 | ||
fi | ||
return 0 | ||
} | ||
|
||
########################## PRIVATE FUNCTIONS ########################### | ||
|
||
# Checks for the ENV variables and saves them | ||
_check_and_save() { | ||
KAS_Login="${KAS_Login:-$(_readaccountconf_mutable KAS_Login)}" | ||
KAS_Authtype="${KAS_Authtype:-$(_readaccountconf_mutable KAS_Authtype)}" | ||
KAS_Authdata="${KAS_Authdata:-$(_readaccountconf_mutable KAS_Authdata)}" | ||
|
||
if [ -z "$KAS_Login" ] || [ -z "$KAS_Authtype" ] || [ -z "$KAS_Authdata" ]; then | ||
KAS_Login= | ||
KAS_Authtype= | ||
KAS_Authdata= | ||
_err "No auth details provided. Please set user credentials using the \$KAS_Login, \$KAS_Authtype, and \$KAS_Authdata environment variables." | ||
return 1 | ||
fi | ||
_saveaccountconf_mutable KAS_Login "$KAS_Login" | ||
_saveaccountconf_mutable KAS_Authtype "$KAS_Authtype" | ||
_saveaccountconf_mutable KAS_Authdata "$KAS_Authdata" | ||
return 0 | ||
} | ||
|
||
# Gets back the base domain/zone. | ||
# TODO Get a list of all possible root zones and compare (Currently not possible via provider) | ||
# See: https://github.com/Neilpang/acme.sh/wiki/DNS-API-Dev-Guide | ||
_get_zone() { | ||
_zone=$(echo "$1" | rev | cut -d . -f1-2 | rev). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Marco4223 was fixing a few more things (thank you very much Marco) and also he replaced the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the empty lines with spaces? |
||
return 0 | ||
} | ||
|
||
# Removes the domain/subdomain from the entry since kasserver | ||
# cannot handle _fulldomain | ||
# TODO Get a list of all possible root zones and compare (Currently not possible via provider) | ||
# See: https://github.com/Neilpang/acme.sh/wiki/DNS-API-Dev-Guide | ||
_get_record_name() { | ||
_record_name=$(echo "$1" | rev | cut -d"." -f3- | rev) | ||
return 0 | ||
} | ||
|
||
# Retrieve the DNS record ID | ||
_get_record_id() { | ||
params="?kas_login=$KAS_Login" | ||
params="$params&kas_auth_type=$KAS_Authtype" | ||
params="$params&kas_auth_data=$KAS_Authdata" | ||
params="$params&kas_action=get_dns_settings" | ||
params="$params&var1=zone_host" | ||
params="$params&wert1=$_zone" | ||
|
||
_debug2 "Wait for 10 seconds by default before calling KAS API." | ||
sleep 10 | ||
response="$(_get "$KAS_Api$params")" | ||
_debug2 "response" "$response" | ||
|
||
_record_id="$(echo "$response" | grep -A 4 "$_record_name" | grep "record_id" | cut -f2 -d">" | xargs)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Neilpang I think without using They also offer a If you have an idea on how to solve this, let me know. thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, we have removed a lot of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Neilpang see the example gist above. We need to grep for the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Neilpang have you had already a chance to have a look at it? thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guptamp, @Neilpang has a few requirements that I should need to add to this as you can see in this Thread. I'm waiting for the suggestions he has for parsing this "HTML" file properly and according to the acme.sh rules. However my implementation is already working and you could in the meanwhile just use my fork: https://github.com/phlegx/acme.sh I'm using it already in production and I will try to keep it up to date should it fail at some point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, for the delay. I was totally missing this PR. This can grep the correct record id:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @Neilpang! Also bit busy these days and need to see if I can have a look at this again in the next days. @dojo90 fyi! If you like and have time feel free to send me pull request! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I'm confused. As you (@Neilpang) write here
you give us a solution which uses So I think we can use the actual implementation (https://github.com/phlegx/acme.sh/blob/all-inkl-kasserver-dns-script/dnsapi/dns_kas.sh#L153) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dojo90 I mean don't use you can use simple |
||
_debug2 _record_id "$_record_id" | ||
return 0 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use our
_sleep()
function instead.