refactor & build: updated desec-ip-sync, might cause breaking change
Some checks failed
/ desec-script (push) Has been cancelled
forgejo/scripts/pipeline/head This commit looks good

This commit is contained in:
devaine 2026-11-10 22:56:54 -06:00
commit 5964402f81
Signed by: devaine
GPG key ID: 954B1DCAC6FF84EE
17 changed files with 576 additions and 136 deletions

0
.forgejo/workflows/start.yaml Normal file → Executable file
View file

384
.gitignore vendored Normal file → Executable file
View file

@ -1,4 +1,382 @@
# Custom
server/desec-ip-sync/data/currentIP
# From https://github.com/github/gitignore/blob/main/Python.gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
*.lcov
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# Pipfile.lock
# uv
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# uv.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# poetry.lock
# poetry.toml
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
# pdm.lock
# pdm.toml
.pdm-python
.pdm-build/
# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
# pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi/*
!.pixi/config.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule*
celerybeat.pid
# Redis
*.rdb
*.aof
*.pid
# RabbitMQ
mnesia/
rabbitmq/
rabbitmq-data/
# ActiveMQ
activemq-data/
# SageMath parsed files
*.sage.py
# Environments
.env .env
server-scripts/desec/public_ip .envrc
data .venv
venv env/
venv/
ENV/
env.bak/
venv.bak/
# Conda environments
conda-meta/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs/Zensical documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
# .idea/
# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/
# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
# could uncomment the following to ignore the entire vscode folder
# .vscode/
# Temporary file for partial code execution
tempCodeRunnerFile.py
# Ruff stuff:
.ruff_cache/
# PyPI configuration file
.pypirc
# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/
# Streamlit
.streamlit/secrets.toml
# From https://github.com/github/gitignore/blob/main/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.*
!.env.example
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
.output
# NitroJS
.nitro/
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp directory
.temp
# Sveltekit cache directory
.svelte-kit/
# vitepress build output
**/.vitepress/dist
# vitepress cache directory
**/.vitepress/cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# Firebase cache directory
.firebase/
# TernJS port file
.tern-port
# Stores Visual Studio Code versions used for testing Visual Studio Code extensions
.vscode-test
# pnpm
.pnpm-store
# yarn v3
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
# Vite files
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
.vite/
# Astro generated types
.astro/
# Turbo Repo
.turbo

15
Jenkinsfile vendored Normal file
View file

@ -0,0 +1,15 @@
pipeline {
agent any
stages {
stage("Build") {
agent {
docker {
image "node:latest"
}
}
steps {
sh "echo 'IT WORKS LMAO'"
}
}
}
}

0
LICENSE Normal file → Executable file
View file

0
README.md Normal file → Executable file
View file

0
archived/battery-scripts/battery-daemon Normal file → Executable file
View file

0
archived/daemons/battery-daemon.cpp Normal file → Executable file
View file

7
archived/gamma Executable file
View file

@ -0,0 +1,7 @@
#!/bin/bash
if pgrep -x "gammastep" >/dev/null; then
killall gammastep
else
gammastep -O 3000
fi

0
ssgpg → desktop/ssgpg Normal file → Executable file
View file

View file

@ -1,127 +0,0 @@
#!/usr/bin/env python
import os
from time import sleep
from dotenv import load_dotenv
import requests
load_dotenv()
# Constants
DOMAIN = os.getenv("CURRENT_DOMAIN")
DESEC_TOKEN = os.getenv("DESEC_TOKEN")
IGNORED_SUBDOMAINS_PREFIXES = ["mail._domainkey.mail", "mail", "_dmarc.mail", "skyguy"]
TIMEOUT = 1800 # In seconds, 600 = 10min, 900 = 15m, 1800 = 30min
# Credits:
# https://desec.readthedocs.io/en/latest/dns/rrsets.html#modifying-an-rrset
# for documentation
def getSubDomains():
subDomainsLink = "https://desec.io/api/v1/domains/" + DOMAIN + "/rrsets/"
subDomainsHeader = {"Authorization": "Token " + DESEC_TOKEN}
subDomainsRequest = requests.get(subDomainsLink, headers=subDomainsHeader)
subDomainsJSON = subDomainsRequest.json()
return subDomainsJSON
def filterRecords():
filtered_prefixes = []
getRequestIP = requests.get("https://ifconfig.me")
requestIP = getRequestIP.text
IGNORED_SUBDOMAINS = []
for i in range(len(IGNORED_SUBDOMAINS_PREFIXES)):
IGNORED_SUBDOMAINS.append(IGNORED_SUBDOMAINS_PREFIXES[i] + "." + DOMAIN + ".")
for rrset in getSubDomains():
IS_NOT_IGNORED = rrset["name"] not in IGNORED_SUBDOMAINS
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:
filtered_prefixes.append(rrset["subname"])
if len(filtered_prefixes) > 0:
return filtered_prefixes
def changeRecords():
prefixes = filterRecords()
# If there are no outdated subdomains...
if prefixes is None:
print("No available subdomains to change")
return
getRequestIP = requests.get("https://ifconfig.me")
requestIP = getRequestIP.text
for prefix in prefixes:
subDomainsLink = (
"https://desec.io/api/v1/domains/" + DOMAIN + "/rrsets/" + prefix + "/A/"
)
subDomainsHeader = {
"Authorization": "Token " + DESEC_TOKEN,
"Content-Type": "application/json",
}
subDomainsData = {
"subname": prefix,
"type": "A",
"records": [requestIP],
"ttl": 3600,
}
changeSubDomainRequest = requests.put(
subDomainsLink, json=subDomainsData, headers=subDomainsHeader
)
print("for prefix: " + prefix)
print(changeSubDomainRequest.text)
sleep(3)
def checkIP():
if not os.path.exists("data"):
os.mknod("data")
dataFile = open("data", "r")
getRequestIP = requests.get("https://ifconfig.me")
requestIP = getRequestIP.text
dataFileIP = dataFile.readline().replace("\n", "")
if requestIP != dataFileIP:
changeRecords()
with open("data", "w") as dataFile:
dataFile.write(requestIP)
def checkInternet():
print("Checking Connection...")
try:
testRequest = requests.get("https://ifconfig.me", timeout=15)
except (requests.Timeout, requests.ConnectionError) as exception:
print("Connection Failed!\nReason: " + exception)
checkInternet()
if testRequest.text is not None:
return True
def main():
print("Starting Script")
while checkInternet():
checkIP()
sleep(TIMEOUT)
if __name__ == "__main__":
main()

View file

@ -2,7 +2,7 @@ FROM node:latest
COPY . /desec COPY . /desec
WORKDIR /desec/server-scripts/desec-ip-sync/ WORKDIR /desec/server/desec-ip-sync/
SHELL ["bash", "-c"] SHELL ["bash", "-c"]
@ -10,7 +10,7 @@ RUN apt update && apt install python3.11-venv -y
RUN bash run.bash RUN bash run.bash
ENV PATH="/desec/server-scripts/desec-ip-sync/venv/bin:$PATH" ENV PATH="/desec/server/desec-ip-sync/venv/bin:$PATH"
CMD ["python3", "main.py"] CMD ["python3", "main.py"]

View file

@ -0,0 +1,4 @@
mail._domainkey.mail
mail
_dmarc.mail
skyguy

162
server/desec-ip-sync/main.py Executable file
View file

@ -0,0 +1,162 @@
#!/usr/bin/env python
# TODO: Figure out a way to update the text file using a bash script that the program can read whilst running
# for the IGNORED_SUBDOMAINS_PREFIXES variable
import os
import sys
import argparse
from time import sleep
from dotenv import load_dotenv
import requests
load_dotenv()
# Constants
DOMAIN = os.getenv("CURRENT_DOMAIN")
DESEC_TOKEN = os.getenv("DESEC_TOKEN")
#IGNORED_SUBDOMAINS_PREFIXES = ["mail._domainkey.mail", "mail", "_dmarc.mail", "skyguy"]
TIMEOUT = 1800 # In seconds, 600 = 10min, 900 = 15m, 1800 = 30min
DESEC_TIMEOUT = 5 # Timeout for the API Queries
# Credits:
# https://desec.readthedocs.io/en/latest/dns/rrsets.html#modifying-an-rrset
# for documentation
def getSubDomains():
subDomainsLink = "https://desec.io/api/v1/domains/" + DOMAIN + "/rrsets/"
subDomainsHeader = {"Authorization": "Token " + DESEC_TOKEN}
subDomainsRequest = requests.get(subDomainsLink, headers=subDomainsHeader)
subDomainsJSON = subDomainsRequest.json()
return subDomainsJSON
# TODO: Make a file out of the subdomains you'd want ignored
def filterRecords():
ignoredSubdomains = []
filteredSubdomains = []
if not os.path.exists("data/ignoredSubdomains"):
with open("data/ignoredSubdomains", "w") as file:
file.close()
with open("data/ignoredSubdomains", "r") as ignoredSubdomainsFile:
for subdomain in ignoredSubdomainsFile:
ignoredSubdomains.append(subdomain)
for rrset in getSubDomains():
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"])
if len(filteredSubdomains) > 0:
return filteredSubdomains
else:
return None
def changeRecords():
subdomains = filterRecords()
# If there are no outdated subdomains...
if subdomains is None:
print("No available subdomains to change")
return
for subdomain in subdomains:
subDomainsLink = (
"https://desec.io/api/v1/domains/" + DOMAIN + "/rrsets/" + subdomain + "/A/"
)
subDomainsHeader = {
"Authorization": "Token " + DESEC_TOKEN,
"Content-Type": "application/json",
}
subDomainsData = {
"subname": subdomain,
"type": "A",
"records": [requestIP],
"ttl": 3600,
}
changeSubDomainRequest = requests.put(
subDomainsLink, json=subDomainsData, headers=subDomainsHeader
)
print("DEBUG: For subdomain: " + subdomains)
print(changeSubDomainRequest.text)
sleep(DESEC_TIMEOUT)
def checkIP():
if not os.path.exists("data"):
os.mkdir("data")
with open("data/currentIP", "w") as file:
file.close()
# Request IP from website
global requestIP
getRequestIP = requests.get("https://ifconfig.me")
requestIP = getRequestIP.text
# Grab file data and close for data safety.
currentIPFile = open("data/currentIP", "r")
currentIP = currentIPFile.readline().replace("\n", "")
currentIPFile.close()
# If both IP's are differnet (New external IP!)
if requestIP != currentIP:
changeRecords()
with open("data/currentIP", "w") as currentIPFile:
currentIPFile.write(requestIP)
currentIPFile.close()
print("All IP's Changed!")
else:
print("DEBUG: No new IP found!")
print(f"DEBUG: New IP={requestIP}")
print(f"DEBUG: Current IP={currentIP}")
# NOTE: This function will always run even without internet available.
def checkInternet():
print("DEBUG: Checking Connection...")
try:
testRequest = requests.get("https://ifconfig.me", timeout=15)
except (requests.Timeout, requests.ConnectionError) as exception:
if (exception):
print("DEBUG: Connection failed!")
checkInternet()
if testRequest.text is not None:
return True
def appendSubdomain(args: list):
with open("data/ignoredSubdomains", "a") as ignoredSubdomainsFile:
for subdomain in args:
ignoredSubdomainsFile.write(subdomain + "\n")
print("Added subdomain: " + subdomain)
def main():
parser = argparse.ArgumentParser(prog="main.py")
parser.add_argument("-a", "--append", nargs="+")
if parser.parse_args().append is not None:
appendSubdomain(parser.parse_args().append)
sys.exit(1)
print("Starting Script")
while checkInternet():
checkIP()
sleep(TIMEOUT)
if __name__ == "__main__":
main()

View file

@ -1,2 +1,3 @@
python-dotenv python-dotenv
requests requests
jedi

View file

@ -6,11 +6,11 @@ if [ ! -f .env ]; then
fi fi
# If virtual environment does exist.. # If virtual environment does exist..
if [ ! -d venv ]; then if [ ! -d .venv ]; then
python3 -m venv venv python3 -m venv .venv
source venv/bin/activate source .venv/bin/activate
pip install -U -r requirements.txt pip install -U -r requirements.txt
pip install -U pip # Update pip to the latest version pip install -U pip # Update pip to the latest version
else else
source venv/bin/activate source .venv/bin/activate
fi fi