diff --git a/.forgejo/workflows/start.yaml b/.forgejo/workflows/start.yaml old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index fb09f0e..66d02cc --- a/.gitignore +++ b/.gitignore @@ -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 -server-scripts/desec/public_ip -data -venv +.envrc +.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 + diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..b9837a8 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,15 @@ +pipeline { + agent any + stages { + stage("Build") { + agent { + docker { + image "node:latest" + } + } + steps { + sh "echo 'IT WORKS LMAO'" + } + } + } +} diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/archived/battery-scripts/battery-daemon b/archived/battery-scripts/battery-daemon old mode 100644 new mode 100755 diff --git a/archived/daemons/battery-daemon.cpp b/archived/daemons/battery-daemon.cpp old mode 100644 new mode 100755 diff --git a/archived/gamma b/archived/gamma new file mode 100755 index 0000000..65667c3 --- /dev/null +++ b/archived/gamma @@ -0,0 +1,7 @@ +#!/bin/bash + +if pgrep -x "gammastep" >/dev/null; then + killall gammastep +else + gammastep -O 3000 +fi diff --git a/ssgpg b/desktop/ssgpg old mode 100644 new mode 100755 similarity index 100% rename from ssgpg rename to desktop/ssgpg diff --git a/server-scripts/desec-ip-sync/main.py b/server-scripts/desec-ip-sync/main.py deleted file mode 100755 index c977e7a..0000000 --- a/server-scripts/desec-ip-sync/main.py +++ /dev/null @@ -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() diff --git a/server-scripts/desec-ip-sync/Dockerfile b/server/desec-ip-sync/Dockerfile old mode 100644 new mode 100755 similarity index 59% rename from server-scripts/desec-ip-sync/Dockerfile rename to server/desec-ip-sync/Dockerfile index 36358c6..75288f1 --- a/server-scripts/desec-ip-sync/Dockerfile +++ b/server/desec-ip-sync/Dockerfile @@ -2,7 +2,7 @@ FROM node:latest COPY . /desec -WORKDIR /desec/server-scripts/desec-ip-sync/ +WORKDIR /desec/server/desec-ip-sync/ SHELL ["bash", "-c"] @@ -10,7 +10,7 @@ RUN apt update && apt install python3.11-venv -y 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"] diff --git a/server-scripts/desec-ip-sync/README.md b/server/desec-ip-sync/README.md old mode 100644 new mode 100755 similarity index 100% rename from server-scripts/desec-ip-sync/README.md rename to server/desec-ip-sync/README.md diff --git a/server/desec-ip-sync/data/ignoredSubdomains b/server/desec-ip-sync/data/ignoredSubdomains new file mode 100644 index 0000000..f156f74 --- /dev/null +++ b/server/desec-ip-sync/data/ignoredSubdomains @@ -0,0 +1,4 @@ +mail._domainkey.mail +mail +_dmarc.mail +skyguy diff --git a/server-scripts/desec-ip-sync/docker-compose.yml b/server/desec-ip-sync/docker-compose.yml old mode 100644 new mode 100755 similarity index 100% rename from server-scripts/desec-ip-sync/docker-compose.yml rename to server/desec-ip-sync/docker-compose.yml diff --git a/server/desec-ip-sync/main.py b/server/desec-ip-sync/main.py new file mode 100755 index 0000000..8fb2dad --- /dev/null +++ b/server/desec-ip-sync/main.py @@ -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() diff --git a/server-scripts/desec-ip-sync/requirements.txt b/server/desec-ip-sync/requirements.txt old mode 100644 new mode 100755 similarity index 82% rename from server-scripts/desec-ip-sync/requirements.txt rename to server/desec-ip-sync/requirements.txt index a830e70..107198e --- a/server-scripts/desec-ip-sync/requirements.txt +++ b/server/desec-ip-sync/requirements.txt @@ -1,2 +1,3 @@ python-dotenv requests +jedi diff --git a/server-scripts/desec-ip-sync/run.bash b/server/desec-ip-sync/run.bash similarity index 70% rename from server-scripts/desec-ip-sync/run.bash rename to server/desec-ip-sync/run.bash index 7372638..37df242 100755 --- a/server-scripts/desec-ip-sync/run.bash +++ b/server/desec-ip-sync/run.bash @@ -6,11 +6,11 @@ if [ ! -f .env ]; then fi # If virtual environment does exist.. -if [ ! -d venv ]; then - python3 -m venv venv - source venv/bin/activate +if [ ! -d .venv ]; then + python3 -m venv .venv + source .venv/bin/activate pip install -U -r requirements.txt pip install -U pip # Update pip to the latest version else - source venv/bin/activate + source .venv/bin/activate fi