61 lines
2.3 KiB
Python
61 lines
2.3 KiB
Python
from flask import Blueprint, render_template, request, redirect, url_for
|
|
import whois
|
|
from app.models import Domain
|
|
from app import db
|
|
from app.utils import get_ssl_expiration
|
|
|
|
domain_bp = Blueprint('domain', __name__)
|
|
|
|
@domain_bp.route('/')
|
|
def home():
|
|
return render_template('home.html')
|
|
|
|
@domain_bp.route('/domains')
|
|
def domains():
|
|
# Show only non-ssl_only domains on the normal Domains page.
|
|
domains_list = Domain.query.filter_by(ssl_only=False).all()
|
|
return render_template('domains.html', domains=domains_list)
|
|
|
|
@domain_bp.route('/add', methods=['GET', 'POST'])
|
|
def add_domain():
|
|
if request.method == 'POST':
|
|
domain_list = request.form.getlist('domain')
|
|
for domain_name in domain_list:
|
|
if domain_name.strip():
|
|
# Perform WHOIS lookup
|
|
try:
|
|
w = whois.whois(domain_name)
|
|
exp_date = w.expiration_date
|
|
if isinstance(exp_date, list):
|
|
exp_date = exp_date[0]
|
|
if exp_date and hasattr(exp_date, "strftime"):
|
|
whois_exp_date_str = exp_date.strftime("%m/%d/%Y")
|
|
else:
|
|
whois_exp_date_str = str(exp_date)
|
|
except Exception as e:
|
|
whois_exp_date_str = f"Error: {e}"
|
|
|
|
# Perform SSL lookup using our utility function
|
|
ssl_exp_date_str = get_ssl_expiration(domain_name)
|
|
|
|
# Only add if not already present.
|
|
if not Domain.query.filter_by(domain=domain_name).first():
|
|
new_domain = Domain(
|
|
domain=domain_name,
|
|
expiration_date=whois_exp_date_str,
|
|
ssl_expiration_date=ssl_exp_date_str,
|
|
ssl_only=False
|
|
)
|
|
db.session.add(new_domain)
|
|
db.session.commit()
|
|
return redirect(url_for('domain.domains'))
|
|
return render_template('add_domain.html')
|
|
|
|
@domain_bp.route('/delete/<int:domain_id>', methods=['GET'])
|
|
def delete_domain(domain_id):
|
|
domain_to_delete = Domain.query.get_or_404(domain_id)
|
|
db.session.delete(domain_to_delete)
|
|
db.session.commit()
|
|
# Redirect back to the Domains page (or SSL page if needed)
|
|
return redirect(url_for('domain.domains'))
|