From 79b2264ff586c40d3b49de321543e320326bd1fe Mon Sep 17 00:00:00 2001 From: Lizzy Hunt Date: Tue, 2 Apr 2024 09:23:21 -0600 Subject: [PATCH] init --- .gitignore | 1 + records.json | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ script.py | 38 +++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 .gitignore create mode 100644 records.json create mode 100644 script.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bceb371 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.secret diff --git a/records.json b/records.json new file mode 100644 index 0000000..0eaf4e1 --- /dev/null +++ b/records.json @@ -0,0 +1,79 @@ +[ + { + "type": "A", + "name": "johan.internal.simponic.xyz", + "content": "100.64.0.5", + "ttl": "43200", + "internal": "on" + }, + { + "type": "A", + "name": "europa.internal.simponic.xyz", + "content": "100.64.0.8", + "ttl": "43200", + "internal": "on" + }, + { + "type": "CNAME", + "name": "vaultwarden.internal.simponic.xyz", + "content": "johan.internal.simponic.xyz", + "ttl": "43200", + "internal": "on" + }, + { + "type": "CNAME", + "name": "lldap.internal.simponic.xyz", + "content": "johan.internal.simponic.xyz", + "ttl": "43200", + "internal": "on" + }, + { + "type": "CNAME", + "name": "ca.internal.simponic.xyz", + "content": "johan.internal.simponic.xyz", + "ttl": "43200", + "internal": "on" + }, + { + "type": "CNAME", + "name": "pihole.internal.simponic.xyz", + "content": "johan.internal.simponic.xyz", + "ttl": "43200", + "internal": "on" + }, + { + "type": "CNAME", + "name": "owncloud.internal.simponic.xyz", + "content": "europa.internal.simponic.xyz", + "ttl": "43200", + "internal": "on" + }, + { + "type": "CNAME", + "name": "jellyfin.internal.simponic.xyz", + "content": "europa.internal.simponic.xyz", + "ttl": "43200", + "internal": "on" + }, + { + "type": "CNAME", + "name": "drone.internal.simponic.xyz", + "content": "europa.internal.simponic.xyz", + "ttl": "43200", + "internal": "on" + }, + { + "type": "CNAME", + "name": "scurvy.internal.simponic.xyz", + "content": "europa.internal.simponic.xyz", + "ttl": "43200", + "internal": "on" + }, + { + "type": "CNAME", + "name": "roundcube.internal.simponic.xyz", + "content": "europa.internal.simponic.xyz", + "ttl": "43200", + "internal": "on" + } +] diff --git a/script.py b/script.py new file mode 100644 index 0000000..ed97e8e --- /dev/null +++ b/script.py @@ -0,0 +1,38 @@ +import json +import requests +import time +import logging + +RECORDS_FILE = "records.json" +ENDPOINT = "https://hatecomputers.club" +API_KEY = open('apikey.secret', 'r').read().strip() + +class HatecomputersDNSAdapter: + def __init__(self, endpoint, api_key): + self.endpoint = endpoint + self.session = requests.Session() + self.headers = {'Authorization': 'Bearer ' + api_key} + self.session = requests.Session() + + def post_record(self, record): + endpoint = self.endpoint + "/dns" + logging.info("adding", record, "at", endpoint) + + self.session.post(endpoint, headers=self.headers, data=record) + + def post_records(self, dns_entries, sleep_time=300): + for record in dns_entries: + self.post_record(record) + + logging.info("sleeping", sleep_time) + time.sleep(sleep_time) + +if __name__ == "__main__": + logging.basicConfig() + logging.root.setLevel(logging.NOTSET) + + records_file = open(RECORDS_FILE, 'r') + dns_records = json.load(records_file) + + adapter = HatecomputersDNSAdapter(ENDPOINT, API_KEY) + adapter.post_records(dns_records)