From 2b31cd58c12f8e6856435445cbfb61a130c37f7a Mon Sep 17 00:00:00 2001 From: uvok cheetah Date: Sun, 2 Feb 2025 14:59:12 +0100 Subject: Various desec stuff --- other_scripts/desec.py | 26 ++++++++++++++++++++++++++ other_scripts/desec.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 other_scripts/desec.py create mode 100755 other_scripts/desec.sh diff --git a/other_scripts/desec.py b/other_scripts/desec.py new file mode 100644 index 0000000..ac7b9c4 --- /dev/null +++ b/other_scripts/desec.py @@ -0,0 +1,26 @@ +import requests + +url = "https://desec.io/api/v1/domains/" +response = requests.get(url, headers={"Authorization": "Token "}) +data = response.json() + +domains = [item['name'] for item in data] + +print("| Counter | Name |") +print("| ------- | ---- |") +for i, name in enumerate(domains): + print(f"| {i+1} | {name} |") + +query = input("Enter a counter or a name: ") +seldomain = None + +try: + query = int(query) + if query < 1 or query > len(domains): + raise ValueError + seldomain = domains[query-1] +except ValueError: + if query not in domains: + print("The name is not present in the table.") + continue + seldomain = query diff --git a/other_scripts/desec.sh b/other_scripts/desec.sh new file mode 100755 index 0000000..dccbdfe --- /dev/null +++ b/other_scripts/desec.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +domain="dyn.uvok.de" + +[[ -z ${1} ]] && { echo "Must provide arg" >&2 ; exit 1; } + +if type -p pass >/dev/null 2>&1; then + tokid=$(pass desec/dyndns/user) + toksec=$(pass desec/dyndns/pass) +else + read -r -p "Enter token ID: " tokid + read -r -s -p "Enter token secret: " toksec +fi + +url="https://desec.io/api/v1/auth/tokens/${tokid}/policies/domain/" +authhdr="Authorization: Token ${toksec}" +echo + +case "$1" in + create) + curl -X POST "$url" --header "$authhdr" --header "Content-Type: application/json" --data @- <<< '{"domain": null}' + echo + # fall-through + ;& + update) + curl -X POST "$url" --header "$authhdr" --header "Content-Type: application/json" --data @- <<< '{"domain": "'"$domain"'", "perm_dyndns": true}' + echo + ;; + check) + curl -X GET "$url" --header "$authhdr" + echo + ;; + *) + echo "Invalid parameter. Please enter one of 'create', 'update', 'check'." + ;; +esac + -- cgit v1.2.3