From 5494b7e27366b37ec4a32ed1695824c4b1864c54 Mon Sep 17 00:00:00 2001 From: devaine Date: Thu, 12 Nov 2026 20:50:26 -0600 Subject: [PATCH] feat: updated checks for files --- .forgejo/workflows/start.yaml | 41 ----------------------------------- server/desec-ip-sync/main.py | 28 +++++++++++++++--------- 2 files changed, 18 insertions(+), 51 deletions(-) delete mode 100755 .forgejo/workflows/start.yaml diff --git a/.forgejo/workflows/start.yaml b/.forgejo/workflows/start.yaml deleted file mode 100755 index 99985e1..0000000 --- a/.forgejo/workflows/start.yaml +++ /dev/null @@ -1,41 +0,0 @@ -on: [push] -jobs: - desec-script: - runs-on: docker - container: - image: node:latest - steps: - - run: | - curl -fsSL https://get.docker.com -o get-docker.sh - sh get-docker.sh - - - name: Checkout repo - uses: actions/checkout@v6 - - - name: Login to Forgejo Container Registry - uses: docker/login-action@v4 - with: - registry: git.devdoes.work - username: devaine - password: ${{ secrets.USER_TOKEN }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 - - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: git.devdoes.work/devaine/scripts:desec - file: server-scripts/desec-ip-sync/Dockerfile - - - #- run: | - # ls -la - # echo "test" - diff --git a/server/desec-ip-sync/main.py b/server/desec-ip-sync/main.py index 6684df2..56571c7 100755 --- a/server/desec-ip-sync/main.py +++ b/server/desec-ip-sync/main.py @@ -9,7 +9,7 @@ import argparse from time import sleep from dotenv import load_dotenv import requests -import json +from collections import Counter load_dotenv() @@ -36,7 +36,16 @@ def getSubDomains(): return subDomainsJSON -# TODO: Make a file out of the subdomains you'd want ignored +def getCurrentIP(): + rrsetList = [] + for rrset in getSubDomains(): + rrsetList.append(rrset["records"][0]) + + value, count = Counter(rrsetList).most_common(1)[0] + + return value + + def filterRecords(): ignoredSubdomains = [] filteredSubdomains = [] @@ -52,10 +61,9 @@ def filterRecords(): ignoredSubdomains.append(subdomain) for rrset in getSubDomains(): - rrset_loaded = json.loads(rrset) - IS_NOT_IGNORED = rrset_loaded["name"] not in ignoredSubdomains - CONTAINS_A_RECORD = rrset_loaded["type"] == "A" - NOT_CURRENT_IP = rrset_loaded["records"][0] != requestIP + IS_NOT_IGNORED = rrset["name"] not in ignoredSubdomains + CONTAINS_A_RECORD = rrset["type"] == "A" + NOT_CURRENT_IP = rrset["records"][0] != requestIP if IS_NOT_IGNORED and CONTAINS_A_RECORD and NOT_CURRENT_IP: filteredSubdomains.append(rrset["subname"]) @@ -100,11 +108,11 @@ def changeRecords(): def checkIP(): - if not os.path.exists("data"): - os.mkdir("data") - + # Grab the current IP from the desec API if not os.path.isfile("./data/currentIP"): - open(os.path.join("./data/", "currentIP"), "x").close() + with open(os.path.join("./data/", "currentIP"), "w") as currentIPFile: + currentIPFile.write(getCurrentIP()) + currentIPFile.close() # Request IP from website global requestIP