43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
from flask import Blueprint, render_template, request, redirect, url_for
|
|
from app.models import Domain
|
|
from app import db
|
|
from app.utils import get_ssl_expiration, get_whois_expiration
|
|
|
|
ssl_bp = Blueprint('ssl', __name__)
|
|
|
|
@ssl_bp.route('/ssl')
|
|
def ssl_page():
|
|
# Get all domains (both normal and ssl_only)
|
|
domains = Domain.query.all()
|
|
return render_template('ssl.html', domains=domains)
|
|
|
|
@ssl_bp.route('/ssl/add', methods=['GET', 'POST'])
|
|
def add_ssl_domain():
|
|
if request.method == 'POST':
|
|
domain_list = request.form.getlist('domain')
|
|
for domain_name in domain_list:
|
|
if domain_name.strip():
|
|
whois_exp_date_str = get_whois_expiration(domain_name)
|
|
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=True
|
|
)
|
|
db.session.add(new_domain)
|
|
db.session.commit()
|
|
return redirect(url_for('ssl.ssl_page'))
|
|
return render_template('add_ssl_domain.html')
|
|
|
|
@ssl_bp.route('/ssl/refresh')
|
|
def refresh_ssl():
|
|
# Refresh all domains (both normal and ssl_only)
|
|
domains = Domain.query.all()
|
|
for d in domains:
|
|
d.expiration_date = get_whois_expiration(d.domain)
|
|
d.ssl_expiration_date = get_ssl_expiration(d.domain)
|
|
db.session.commit()
|
|
return redirect(url_for('ssl.ssl_page'))
|