modify dns in config
This commit is contained in:
parent
125e42e501
commit
4303f568b3
@ -3,6 +3,7 @@ from flask import Flask, jsonify
|
||||
from dotenv import load_dotenv
|
||||
from ktvmanager.config import DevelopmentConfig, ProductionConfig
|
||||
from routes.api import api_blueprint
|
||||
from routes.dns import dns_bp
|
||||
from ktvmanager.lib.database import initialize_db_pool
|
||||
from ktvmanager.account_checker import send_expiry_notifications
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
@ -27,6 +28,7 @@ def create_app():
|
||||
|
||||
# Register blueprints
|
||||
app.register_blueprint(api_blueprint)
|
||||
app.register_blueprint(dns_bp)
|
||||
|
||||
@app.route('/check-expiry', methods=['POST'])
|
||||
def check_expiry():
|
||||
|
47
ktvmanager/routes/dns.py
Normal file
47
ktvmanager/routes/dns.py
Normal file
@ -0,0 +1,47 @@
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, flash
|
||||
import os
|
||||
|
||||
dns_bp = Blueprint('dns', __name__)
|
||||
|
||||
DNS_FILE = os.path.join(os.path.dirname(__file__), '..', 'lib', 'DNS_list.txt')
|
||||
|
||||
def read_dns_list():
|
||||
if not os.path.exists(DNS_FILE):
|
||||
return []
|
||||
with open(DNS_FILE, 'r') as f:
|
||||
return [line.strip() for line in f.readlines()]
|
||||
|
||||
def write_dns_list(dns_list):
|
||||
with open(DNS_FILE, 'w') as f:
|
||||
for item in dns_list:
|
||||
f.write(f"{item}\n")
|
||||
|
||||
@dns_bp.route('/add_dns', methods=['POST'])
|
||||
def add_dns():
|
||||
dns_entry = request.form.get('dns_entry')
|
||||
if dns_entry:
|
||||
dns_list = read_dns_list()
|
||||
if dns_entry not in dns_list:
|
||||
dns_list.append(dns_entry)
|
||||
write_dns_list(dns_list)
|
||||
flash('DNS entry added successfully.', 'success')
|
||||
else:
|
||||
flash('DNS entry already exists.', 'info')
|
||||
else:
|
||||
flash('DNS entry cannot be empty.', 'danger')
|
||||
return redirect(url_for('config_dashboard'))
|
||||
|
||||
@dns_bp.route('/remove_dns', methods=['POST'])
|
||||
def remove_dns():
|
||||
dns_entry = request.form.get('dns_entry')
|
||||
if dns_entry:
|
||||
dns_list = read_dns_list()
|
||||
if dns_entry in dns_list:
|
||||
dns_list.remove(dns_entry)
|
||||
write_dns_list(dns_list)
|
||||
flash('DNS entry removed successfully.', 'success')
|
||||
else:
|
||||
flash('DNS entry not found.', 'info')
|
||||
else:
|
||||
flash('DNS entry cannot be empty.', 'danger')
|
||||
return redirect(url_for('config_dashboard'))
|
Loading…
x
Reference in New Issue
Block a user