Refresh Button
parent
58496200ca
commit
0bb24856c4
|
|
@ -2,7 +2,7 @@ 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
|
||||
from app.utils import get_ssl_expiration, get_whois_expiration
|
||||
|
||||
domain_bp = Blueprint('domain', __name__)
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ def home():
|
|||
|
||||
@domain_bp.route('/domains')
|
||||
def domains():
|
||||
# Show only non-ssl_only domains on the normal Domains page.
|
||||
# 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)
|
||||
|
||||
|
|
@ -22,23 +22,10 @@ def add_domain():
|
|||
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
|
||||
# WHOIS lookup
|
||||
whois_exp_date_str = get_whois_expiration(domain_name)
|
||||
# SSL lookup
|
||||
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,
|
||||
|
|
@ -56,5 +43,15 @@ 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'))
|
||||
|
||||
@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'))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
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
|
||||
from app.utils import get_ssl_expiration, get_whois_expiration
|
||||
|
||||
ssl_bp = Blueprint('ssl', __name__)
|
||||
|
||||
|
|
@ -9,12 +9,6 @@ ssl_bp = Blueprint('ssl', __name__)
|
|||
def ssl_page():
|
||||
# Get all domains (both normal and ssl_only)
|
||||
domains = Domain.query.all()
|
||||
# Update each domain's SSL expiration (optional, to refresh if needed)
|
||||
for d in domains:
|
||||
current_ssl_exp = get_ssl_expiration(d.domain)
|
||||
if d.ssl_expiration_date != current_ssl_exp:
|
||||
d.ssl_expiration_date = current_ssl_exp
|
||||
db.session.commit()
|
||||
return render_template('ssl.html', domains=domains)
|
||||
|
||||
@ssl_bp.route('/ssl/add', methods=['GET', 'POST'])
|
||||
|
|
@ -23,21 +17,8 @@ def add_ssl_domain():
|
|||
domain_list = request.form.getlist('domain')
|
||||
for domain_name in domain_list:
|
||||
if domain_name.strip():
|
||||
# Both lookups are performed when adding an SSL-only domain.
|
||||
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}"
|
||||
|
||||
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,
|
||||
|
|
@ -49,3 +30,13 @@ def add_ssl_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'))
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Domains{% endblock %}
|
||||
{% block content %}
|
||||
<h1>Domains List</h1>
|
||||
<h1>Domain List</h1>
|
||||
<button onclick="window.location.href='{{ url_for('domain.refresh_domains') }}'">Refresh Domains</button>
|
||||
<table border="1" cellpadding="5" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Domain</th>
|
||||
<th>Expiration Date</th>
|
||||
<th>Domain Expiration</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
{% block title %}SSL Certificates{% endblock %}
|
||||
{% block content %}
|
||||
<h1>SSL Certificates</h1>
|
||||
<button onclick="window.location.href='{{ url_for('ssl.refresh_ssl') }}'">Refresh SSL</button>
|
||||
<table border="1" cellpadding="5" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
|||
15
app/utils.py
15
app/utils.py
|
|
@ -1,4 +1,5 @@
|
|||
import socket, ssl, datetime
|
||||
import whois
|
||||
|
||||
def get_ssl_expiration(domain, port=443):
|
||||
try:
|
||||
|
|
@ -8,9 +9,21 @@ def get_ssl_expiration(domain, port=443):
|
|||
cert = ssock.getpeercert()
|
||||
notAfter = cert.get('notAfter')
|
||||
if notAfter:
|
||||
# Example certificate expiry format: "Jun 1 12:00:00 2025 GMT"
|
||||
# Example format: "Jun 1 12:00:00 2025 GMT"
|
||||
exp_date = datetime.datetime.strptime(notAfter, '%b %d %H:%M:%S %Y %Z')
|
||||
return exp_date.strftime("%m/%d/%Y")
|
||||
return "NO SSL"
|
||||
except Exception:
|
||||
return "NO SSL"
|
||||
|
||||
def get_whois_expiration(domain):
|
||||
try:
|
||||
w = whois.whois(domain)
|
||||
exp_date = w.expiration_date
|
||||
if isinstance(exp_date, list):
|
||||
exp_date = exp_date[0]
|
||||
if exp_date and hasattr(exp_date, "strftime"):
|
||||
return exp_date.strftime("%m/%d/%Y")
|
||||
return str(exp_date)
|
||||
except Exception:
|
||||
return "Error"
|
||||
|
|
|
|||
Loading…
Reference in New Issue