|
@ -4,10 +4,10 @@ |
|
|
# https://eu.api.ovh.com/createToken/?GET=/domain*&POST=/domain*&PUT=/domain*&DELETE=/domain* |
|
|
# https://eu.api.ovh.com/createToken/?GET=/domain*&POST=/domain*&PUT=/domain*&DELETE=/domain* |
|
|
|
|
|
|
|
|
function usage { |
|
|
function usage { |
|
|
echo 'usage: <ACTION: list|get|set> <DOMAIN> [CNAME] [destination]' |
|
|
|
|
|
|
|
|
echo 'usage: <ACTION: list|get|set> <DOMAIN> [CNAME] [TARGET]' |
|
|
echo ' - list <DOMAIN>' |
|
|
echo ' - list <DOMAIN>' |
|
|
echo ' - get <DOMAIN> <CNAME>' |
|
|
echo ' - get <DOMAIN> <CNAME>' |
|
|
echo ' - set <DOMAIN> <CNAME> <DESTINATION>' |
|
|
|
|
|
|
|
|
echo ' - set <DOMAIN> <CNAME> <TARGET>' |
|
|
exit 1 |
|
|
exit 1 |
|
|
} |
|
|
} |
|
|
function set_base { |
|
|
function set_base { |
|
@ -33,6 +33,7 @@ function build_url_list_records { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function list_records { |
|
|
function list_records { |
|
|
|
|
|
|
|
|
zone="$1" |
|
|
zone="$1" |
|
|
fieldType="${2:-}" |
|
|
fieldType="${2:-}" |
|
|
subDomain="${3:-}" |
|
|
subDomain="${3:-}" |
|
@ -56,7 +57,7 @@ function list_records { |
|
|
|
|
|
|
|
|
echo "" |
|
|
echo "" |
|
|
echo "output=$output" |
|
|
echo "output=$output" |
|
|
echo "" |
|
|
|
|
|
|
|
|
echo "ERROR" |
|
|
exit 1 |
|
|
exit 1 |
|
|
|
|
|
|
|
|
# echo "$output" | yq .[] # values of array |
|
|
# echo "$output" | yq .[] # values of array |
|
@ -82,6 +83,47 @@ function get_record { |
|
|
"$query" | yq -o=props |
|
|
"$query" | yq -o=props |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function set_record { |
|
|
|
|
|
zone="$1" |
|
|
|
|
|
method="POST" |
|
|
|
|
|
query="${BASE_URL}/domain/zone/$zone/record" |
|
|
|
|
|
body="{\"fieldType\":\"CNAME\",\"subDomain\":\"$CNAME\",\"target\":\"$TARGET\",\"ttl\":0}" |
|
|
|
|
|
tstamp=$(date +%s) |
|
|
|
|
|
sha=$(echo -n "$AS+$CK+$method+$query+$body+$tstamp" | shasum | cut -d ' ' -f 1) |
|
|
|
|
|
signature="\$1\$$sha" |
|
|
|
|
|
|
|
|
|
|
|
curl -s \ |
|
|
|
|
|
-X $method \ |
|
|
|
|
|
-H "Content-type: application/json" \ |
|
|
|
|
|
-H 'Accept: application/json' \ |
|
|
|
|
|
-H "X-Ovh-Application: $AK" \ |
|
|
|
|
|
-H "X-Ovh-Consumer: $CK" \ |
|
|
|
|
|
-H "X-Ovh-Signature: $signature" \ |
|
|
|
|
|
-H "X-Ovh-Timestamp: $tstamp" \ |
|
|
|
|
|
--data-raw "$body" \ |
|
|
|
|
|
"$query" | yq -o=props |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function refresh { |
|
|
|
|
|
zone="$1" |
|
|
|
|
|
method="POST" |
|
|
|
|
|
query="${BASE_URL}/domain/zone/$zone/refresh" |
|
|
|
|
|
body="" |
|
|
|
|
|
tstamp=$(date +%s) |
|
|
|
|
|
sha=$(echo -n "$AS+$CK+$method+$query+$body+$tstamp" | shasum | cut -d ' ' -f 1) |
|
|
|
|
|
signature="\$1\$$sha" |
|
|
|
|
|
|
|
|
|
|
|
curl -s \ |
|
|
|
|
|
-X $method \ |
|
|
|
|
|
-H "Content-type: application/json" \ |
|
|
|
|
|
-H 'Accept: application/json' \ |
|
|
|
|
|
-H "X-Ovh-Application: $AK" \ |
|
|
|
|
|
-H "X-Ovh-Consumer: $CK" \ |
|
|
|
|
|
-H "X-Ovh-Signature: $signature" \ |
|
|
|
|
|
-H "X-Ovh-Timestamp: $tstamp" \ |
|
|
|
|
|
"$query" | yq -o=props |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function action_list { |
|
|
function action_list { |
|
|
for record_id in $(list_records "$DOMAIN" CNAME "$CNAME"); do |
|
|
for record_id in $(list_records "$DOMAIN" CNAME "$CNAME"); do |
|
|
get_record "$DOMAIN" "$record_id" |
|
|
get_record "$DOMAIN" "$record_id" |
|
@ -90,12 +132,28 @@ function action_list { |
|
|
|
|
|
|
|
|
function action_get { |
|
|
function action_get { |
|
|
local record_id |
|
|
local record_id |
|
|
|
|
|
|
|
|
|
|
|
#TODO: to delete after testing... |
|
|
|
|
|
list_records "$DOMAIN" CNAME "$CNAME" |
|
|
|
|
|
|
|
|
record_id=$(list_records "$DOMAIN" CNAME "$CNAME") |
|
|
record_id=$(list_records "$DOMAIN" CNAME "$CNAME") |
|
|
get_record "$DOMAIN" "$record_id" |
|
|
get_record "$DOMAIN" "$record_id" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function append_dot_target { |
|
|
|
|
|
local old_target=$TARGET |
|
|
|
|
|
[[ $TARGET == *\. ]] || TARGET="$TARGET." |
|
|
|
|
|
[[ $old_target != "$TARGET" ]] && echo "TARGET has been suffixed with '.' (the dot symbol)!" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function action_set { |
|
|
function action_set { |
|
|
echo set_record "$DOMAIN" "$CNAME" "$DESTINATION" |
|
|
|
|
|
|
|
|
append_dot_target |
|
|
|
|
|
|
|
|
|
|
|
echo set_record "$DOMAIN" "$CNAME" "$TARGET" |
|
|
|
|
|
set_record "$DOMAIN" "$CNAME" "$TARGET" |
|
|
|
|
|
|
|
|
|
|
|
echo refresh "$DOMAIN" |
|
|
|
|
|
refresh "$DOMAIN" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
##----------- |
|
|
##----------- |
|
@ -109,7 +167,7 @@ function action_set { |
|
|
ACTION="$1" |
|
|
ACTION="$1" |
|
|
DOMAIN="$2" |
|
|
DOMAIN="$2" |
|
|
CNAME="${3:-}" |
|
|
CNAME="${3:-}" |
|
|
DESTINATION="${4:-}" |
|
|
|
|
|
|
|
|
TARGET="${4:-}" |
|
|
|
|
|
|
|
|
set_base |
|
|
set_base |
|
|
|
|
|
|
|
|