2018-03-14 17:32:02 +01:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
#
|
|
|
|
#LOOPIA_User="username"
|
|
|
|
#
|
|
|
|
#LOOPIA_Password="password"
|
2019-03-05 20:56:34 +01:00
|
|
|
#
|
|
|
|
#LOOPIA_Api="https://api.loopia.<TLD>/RPCSERV"
|
2018-03-14 17:32:02 +01:00
|
|
|
|
2019-03-05 20:56:34 +01:00
|
|
|
LOOPIA_Api_Default="https://api.loopia.se/RPCSERV"
|
2018-03-14 17:32:02 +01:00
|
|
|
|
|
|
|
######## Public functions #####################
|
|
|
|
|
|
|
|
#Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
|
|
|
dns_loopia_add() {
|
|
|
|
fulldomain=$1
|
|
|
|
txtvalue=$2
|
|
|
|
|
2019-03-05 20:16:54 +01:00
|
|
|
if ! _loopia_load_config; then
|
2018-03-14 17:32:02 +01:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-03-05 20:21:14 +01:00
|
|
|
_loopia_save_config
|
2018-03-14 17:32:02 +01:00
|
|
|
|
|
|
|
_debug "First detect the root zone"
|
|
|
|
if ! _get_root "$fulldomain"; then
|
|
|
|
_err "invalid domain"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
_debug _sub_domain "$_sub_domain"
|
|
|
|
_debug _domain "$_domain"
|
|
|
|
|
|
|
|
_info "Adding record"
|
|
|
|
|
2019-01-03 11:32:43 +01:00
|
|
|
_loopia_add_sub_domain "$_domain" "$_sub_domain"
|
|
|
|
_loopia_add_record "$_domain" "$_sub_domain" "$txtvalue"
|
2018-03-14 17:32:02 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_loopia_rm() {
|
|
|
|
fulldomain=$1
|
|
|
|
txtvalue=$2
|
|
|
|
|
2019-03-05 20:16:54 +01:00
|
|
|
if ! _loopia_load_config; then
|
2018-03-14 17:32:02 +01:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2019-03-05 20:21:14 +01:00
|
|
|
_loopia_save_config
|
2018-03-14 17:32:02 +01:00
|
|
|
|
|
|
|
_debug "First detect the root zone"
|
|
|
|
if ! _get_root "$fulldomain"; then
|
|
|
|
_err "invalid domain"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<methodCall>
|
|
|
|
<methodName>removeSubdomain</methodName>
|
|
|
|
<params>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
</params>
|
2019-03-28 16:34:13 +01:00
|
|
|
</methodCall>' "$LOOPIA_User" "$LOOPIA_Password" "$_domain" "$_sub_domain")
|
2018-03-14 17:32:02 +01:00
|
|
|
|
|
|
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
|
|
|
|
|
|
|
|
if ! _contains "$response" "OK"; then
|
|
|
|
_err "Error could not get txt records"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#################### Private functions below ##################################
|
|
|
|
|
2019-03-05 20:16:54 +01:00
|
|
|
_loopia_load_config() {
|
2019-03-05 20:56:34 +01:00
|
|
|
LOOPIA_Api="${LOOPIA_Api:-$(_readaccountconf_mutable LOOPIA_Api)}"
|
2019-03-05 20:16:54 +01:00
|
|
|
LOOPIA_User="${LOOPIA_User:-$(_readaccountconf_mutable LOOPIA_User)}"
|
|
|
|
LOOPIA_Password="${LOOPIA_Password:-$(_readaccountconf_mutable LOOPIA_Password)}"
|
|
|
|
|
2019-03-05 20:56:34 +01:00
|
|
|
if [ -z "$LOOPIA_Api" ]; then
|
|
|
|
LOOPIA_Api="$LOOPIA_Api_Default"
|
|
|
|
fi
|
|
|
|
|
2019-03-05 20:16:54 +01:00
|
|
|
if [ -z "$LOOPIA_User" ] || [ -z "$LOOPIA_Password" ]; then
|
|
|
|
LOOPIA_User=""
|
|
|
|
LOOPIA_Password=""
|
|
|
|
|
2019-03-05 21:10:11 +01:00
|
|
|
_err "A valid Loopia API user and password not provided."
|
|
|
|
_err "Please provide a valid API user and try again."
|
2019-03-05 20:16:54 +01:00
|
|
|
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-03-05 20:21:14 +01:00
|
|
|
_loopia_save_config() {
|
2019-03-05 20:56:34 +01:00
|
|
|
if [ "$LOOPIA_Api" != "$LOOPIA_Api_Default" ]; then
|
|
|
|
_saveaccountconf_mutable LOOPIA_Api "$LOOPIA_Api"
|
|
|
|
fi
|
2019-03-05 20:21:14 +01:00
|
|
|
_saveaccountconf_mutable LOOPIA_User "$LOOPIA_User"
|
|
|
|
_saveaccountconf_mutable LOOPIA_Password "$LOOPIA_Password"
|
|
|
|
}
|
|
|
|
|
2019-01-03 11:32:43 +01:00
|
|
|
_loopia_get_records() {
|
|
|
|
domain=$1
|
|
|
|
sub_domain=$2
|
|
|
|
|
|
|
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<methodCall>
|
|
|
|
<methodName>getZoneRecords</methodName>
|
|
|
|
<params>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
</params>
|
|
|
|
</methodCall>' $LOOPIA_User $LOOPIA_Password "$domain" "$sub_domain")
|
|
|
|
|
|
|
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
|
|
|
|
if ! _contains "$response" "<array>"; then
|
|
|
|
_err "Error"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2018-03-14 17:32:02 +01:00
|
|
|
_get_root() {
|
|
|
|
domain=$1
|
|
|
|
_debug "get root"
|
|
|
|
|
|
|
|
domain=$1
|
|
|
|
i=2
|
|
|
|
p=1
|
|
|
|
|
|
|
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<methodCall>
|
|
|
|
<methodName>getDomains</methodName>
|
|
|
|
<params>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
</params>
|
|
|
|
</methodCall>' $LOOPIA_User $LOOPIA_Password)
|
|
|
|
|
|
|
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
|
|
|
|
while true; do
|
2018-03-18 15:00:10 +01:00
|
|
|
h=$(echo "$domain" | cut -d . -f $i-100)
|
2018-03-14 17:32:02 +01:00
|
|
|
if [ -z "$h" ]; then
|
|
|
|
#not valid
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if _contains "$response" "$h"; 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
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-03 11:32:43 +01:00
|
|
|
_loopia_add_record() {
|
2018-03-14 17:32:02 +01:00
|
|
|
domain=$1
|
|
|
|
sub_domain=$2
|
|
|
|
txtval=$3
|
|
|
|
|
|
|
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<methodCall>
|
2019-01-03 11:32:43 +01:00
|
|
|
<methodName>addZoneRecord</methodName>
|
2018-03-14 17:32:02 +01:00
|
|
|
<params>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
2022-03-04 13:38:05 +01:00
|
|
|
<value>
|
|
|
|
<struct>
|
|
|
|
<member>
|
|
|
|
<name>type</name>
|
|
|
|
<value><string>TXT</string></value>
|
|
|
|
</member>
|
|
|
|
<member>
|
|
|
|
<name>priority</name>
|
|
|
|
<value><int>0</int></value>
|
|
|
|
</member>
|
|
|
|
<member>
|
|
|
|
<name>ttl</name>
|
|
|
|
<value><int>300</int></value>
|
|
|
|
</member>
|
|
|
|
<member>
|
|
|
|
<name>rdata</name>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</member>
|
|
|
|
</struct>
|
|
|
|
</value>
|
2018-03-14 17:32:02 +01:00
|
|
|
</param>
|
|
|
|
</params>
|
|
|
|
</methodCall>' $LOOPIA_User $LOOPIA_Password "$domain" "$sub_domain" "$txtval")
|
|
|
|
|
|
|
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
|
|
|
|
|
2018-03-21 16:19:22 +01:00
|
|
|
if ! _contains "$response" "OK"; then
|
2018-03-14 17:32:02 +01:00
|
|
|
_err "Error"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-01-03 11:32:43 +01:00
|
|
|
_sub_domain_exists() {
|
2018-03-14 17:32:02 +01:00
|
|
|
domain=$1
|
|
|
|
sub_domain=$2
|
|
|
|
|
2019-01-03 11:32:43 +01:00
|
|
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<methodCall>
|
|
|
|
<methodName>getSubdomains</methodName>
|
|
|
|
<params>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
</params>
|
|
|
|
</methodCall>' $LOOPIA_User $LOOPIA_Password "$domain")
|
|
|
|
|
|
|
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
|
|
|
|
|
|
|
|
if _contains "$response" "$sub_domain"; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
_loopia_add_sub_domain() {
|
|
|
|
domain=$1
|
|
|
|
sub_domain=$2
|
|
|
|
|
|
|
|
if _sub_domain_exists "$domain" "$sub_domain"; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2018-03-14 17:32:02 +01:00
|
|
|
xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<methodCall>
|
|
|
|
<methodName>addSubdomain</methodName>
|
|
|
|
<params>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
<param>
|
|
|
|
<value><string>%s</string></value>
|
|
|
|
</param>
|
|
|
|
</params>
|
|
|
|
</methodCall>' $LOOPIA_User $LOOPIA_Password "$domain" "$sub_domain")
|
|
|
|
|
|
|
|
response="$(_post "$xml_content" "$LOOPIA_Api" "" "POST")"
|
|
|
|
|
2018-03-21 16:19:22 +01:00
|
|
|
if ! _contains "$response" "OK"; then
|
2018-03-14 17:32:02 +01:00
|
|
|
_err "Error"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|