feat: Add acme server for HNSDoH
All checks were successful
Build Docker / Build Image (push) Successful in 47s
All checks were successful
Build Docker / Build Image (push) Successful in 47s
This commit is contained in:
parent
d67da4ad06
commit
9305442c4b
@ -2,3 +2,4 @@ flask
|
||||
python-dotenv
|
||||
gunicorn
|
||||
requests
|
||||
cloudflare
|
34
server.py
34
server.py
@ -2,6 +2,7 @@ from flask import Flask, make_response, redirect, request, jsonify, render_templ
|
||||
import os
|
||||
import dotenv
|
||||
import requests
|
||||
import CloudFlare
|
||||
|
||||
app = Flask(__name__)
|
||||
dotenv.load_dotenv()
|
||||
@ -152,6 +153,39 @@ def getAddress():
|
||||
return address
|
||||
|
||||
|
||||
@app.route('/hnsdoh-acme', methods=['POST'])
|
||||
def hnsdoh_acme():
|
||||
# Get the TXT record from the request
|
||||
if not request.json:
|
||||
return jsonify({'status': 'error', 'error': 'No JSON data provided'})
|
||||
if 'txt' not in request.json or 'auth' not in request.json:
|
||||
return jsonify({'status': 'error', 'error': 'Missing required data'})
|
||||
|
||||
txt = request.json['txt']
|
||||
auth = request.json['auth']
|
||||
if auth != os.getenv('CF_AUTH'):
|
||||
return jsonify({'status': 'error', 'error': 'Invalid auth'})
|
||||
|
||||
cf = CloudFlare.CloudFlare(token=os.getenv('CF_TOKEN'))
|
||||
zone = cf.zones.get(params={'name': 'hnsdoh.com'})
|
||||
zone_id = zone[0]['id']
|
||||
existing_records = cf.zones.dns_records.get(zone_id, params={'type': 'TXT', 'name': '_acme-challenge.hnsdoh.com'})
|
||||
|
||||
# Delete existing TXT records
|
||||
for record in existing_records:
|
||||
print(record)
|
||||
record_id = record['id']
|
||||
cf.zones.dns_records.delete(zone_id, record_id)
|
||||
|
||||
|
||||
|
||||
|
||||
record = cf.zones.dns_records.post(zone_id, data={'type': 'TXT', 'name': '_acme-challenge', 'content': txt})
|
||||
print(record)
|
||||
return jsonify({'status': 'success'})
|
||||
|
||||
|
||||
|
||||
# 404 catch all
|
||||
@app.errorhandler(404)
|
||||
def not_found(e):
|
||||
|
Loading…
Reference in New Issue
Block a user