58 lines
2.2 KiB
Python
58 lines
2.2 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, get_whois_expiration
|
|
|
|
domain_bp = Blueprint('domain', __name__)
|
|
|
|
@domain_bp.route('/')
|
|
def home():
|
|
return render_template('home.html')
|
|
|
|
@domain_bp.route('/domains')
|
|
def domains():
|
|
# Only show domains that were added normally (ssl_only is False)
|
|
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():
|
|
# WHOIS lookup
|
|
whois_exp_date_str = get_whois_expiration(domain_name)
|
|
# SSL lookup
|
|
ssl_exp_date_str = get_ssl_expiration(domain_name)
|
|
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()
|
|
return redirect(url_for('domain.domains'))
|
|
|
|
@domain_bp.route('/domains/refresh')
|
|
def refresh_domains():
|
|
# Refresh only non-SSL-only domains
|
|
domains_list = Domain.query.filter_by(ssl_only=False).all()
|
|
for d in domains_list:
|
|
d.expiration_date = get_whois_expiration(d.domain)
|
|
# Optionally update SSL expiration as well if desired:
|
|
d.ssl_expiration_date = get_ssl_expiration(d.domain)
|
|
db.session.commit()
|
|
return redirect(url_for('domain.domains'))
|