From 60be103f689e95105da6fe25267ec59544795ec2 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Jan 2022 00:36:18 +0700 Subject: [PATCH] 1984DNS : init --- 1984DNS/.env | 2 ++ 1984DNS/README | 10 +++++++ 1984DNS/after.py | 53 ++++++++++++++++++++++++++++++++++ 1984DNS/after.sh | 2 ++ 1984DNS/before.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1984DNS/before.sh | 4 +++ 6 files changed, 143 insertions(+) create mode 100644 1984DNS/.env create mode 100644 1984DNS/README create mode 100644 1984DNS/after.py create mode 100644 1984DNS/after.sh create mode 100644 1984DNS/before.py create mode 100644 1984DNS/before.sh diff --git a/1984DNS/.env b/1984DNS/.env new file mode 100644 index 0000000..d981da3 --- /dev/null +++ b/1984DNS/.env @@ -0,0 +1,2 @@ +AUTH_USERNAME= +AUTH_PASSWORD= \ No newline at end of file diff --git a/1984DNS/README b/1984DNS/README new file mode 100644 index 0000000..9db9002 --- /dev/null +++ b/1984DNS/README @@ -0,0 +1,10 @@ +This was my attempted to make automatic Certbot renewal script of 1984.is FreeDNS . + +But acme.sh officially support 1984.is FreeDNS : https://github.com/acmesh-official/acme.sh/wiki/dnsapi#104-use-1984hosting-domain-api +and i found that after my script was finished . + +so, this script is a Certbot renewal script that's not maintained anymore, unless i returned to certbot . + +certbot certonly --manual --manual-auth-hook before.sh --manual-cleanup-hook after.sh -d secure.example.com + +Command Above should still working , i guess... \ No newline at end of file diff --git a/1984DNS/after.py b/1984DNS/after.py new file mode 100644 index 0000000..4aa6157 --- /dev/null +++ b/1984DNS/after.py @@ -0,0 +1,53 @@ +import sys +import logging +import re +from bs4 import BeautifulSoup +from dotenv import load_dotenv +from requests import Session +import os + +LOGGER = logging.getLogger(__name__) + +domain_id = None +session = None +session = Session() +session.get("https://umsjon.1984.is/accounts/login/?next=/") +load_dotenv() +auth_username = os.getenv('AUTH_USERNAME') +auth_password = os.getenv('AUTH_PASSWORD') +rtype="TXT" + + +# Hit the login page with authentication info to login the session +login_response = session.post( + "https://umsjon.1984.is/accounts/checkuserauth/", + data={ + "username": auth_username or "", + "password": auth_password or "", + }, + ) + +cookie = session.cookies +for token in cookie: + if token.name == "csrftoken": + csrftoken = token.value + elif token.name == "sessionid": + sessionid = token.value + +payload = { + "Host": "umsjon.1984.is", + "Referer": "https://umsjon.1984.is", + "X-CSRFToken": csrftoken, + "Cookie": "csrftoken="+csrftoken+"; sessionid="+sessionid +} + +file1 = open('entry.txt', 'r') +file = file1.read().split('\n') +for zone_id in file: + delete_response = session.post( + "https://umsjon.1984.is/domains/delentry/", + data={ + "entry": zone_id, + }, headers=payload, + ) +print(delete_response.text) \ No newline at end of file diff --git a/1984DNS/after.sh b/1984DNS/after.sh new file mode 100644 index 0000000..73115c6 --- /dev/null +++ b/1984DNS/after.sh @@ -0,0 +1,2 @@ +python3 after.py +rm entry.txt \ No newline at end of file diff --git a/1984DNS/before.py b/1984DNS/before.py new file mode 100644 index 0000000..cda817b --- /dev/null +++ b/1984DNS/before.py @@ -0,0 +1,72 @@ +import sys +import logging +import json +import re +from dotenv import load_dotenv +from requests import Session +import requests +import os +from bs4 import BeautifulSoup + +LOGGER = logging.getLogger(__name__) + +CERTBOT_DOMAIN = '1w1.one' +CERTBOT_ZONE = '1w1.one' +CERTBOT_VALIDATION = '12345' + +CERTBOT_DOMAIN = sys.argv[1] +CERTBOT_ZONE = sys.argv[2] +CERTBOT_VALIDATION = sys.argv[3] +domain = CERTBOT_ZONE +load_dotenv() +auth_username = os.getenv('AUTH_USERNAME') +auth_password = os.getenv('AUTH_PASSWORD') + +domain_id = None +session = None +session = Session() +session.get("https://umsjon.1984.is/accounts/login/?next=/") + +# Hit the login page with authentication info to login the session +login_response = session.post( + "https://umsjon.1984.is/accounts/checkuserauth/", + data={ + "username": auth_username or "", + "password": auth_password or "", +}, + ) + +cookie = session.cookies +for token in cookie: + if token.name == "csrftoken": + csrftoken = token.value + elif token.name == "sessionid": + sessionid = token.value + +CERTBOT_HOST="_acme-challenge."+CERTBOT_DOMAIN +name=CERTBOT_HOST +rtype="txt" + +# Pull a list of records and check for ours +payload = { + "Host": "umsjon.1984.is", + "Referer": "https://umsjon.1984.is", + "X-CSRFToken": csrftoken, + "Cookie": "csrftoken="+csrftoken+"; sessionid="+sessionid +} +data = { + "entry": "new", + "zone": CERTBOT_ZONE, + "type": "txt", + "host": CERTBOT_HOST, + "ttl": 900, + "priority": "", + "rdata": CERTBOT_VALIDATION, + } +risk = session.post("https://umsjon.1984.is/domains/entry/", data=data, headers=payload) +s = re.findall('"id": "..*\d"', risk.text) +s = str(s) +s = re.sub('(\[|\"|\'|:|]| |id)', "", s) +file1 = open('entry.txt', 'w') +file1.write(str(s)) +exit() \ No newline at end of file diff --git a/1984DNS/before.sh b/1984DNS/before.sh new file mode 100644 index 0000000..d5e3624 --- /dev/null +++ b/1984DNS/before.sh @@ -0,0 +1,4 @@ +CERTBOT_ZONE=1w1.one +python3 before.py "$CERTBOT_DOMAIN" "$CERTBOT_ZONE" "$CERTBOT_VALIDATION" +echo "Please wait for 15 minutes, before certbot continues . This is for updating reasons" +sleep 900 \ No newline at end of file