diff --git a/app/routes/domain.py b/app/routes/domain.py index 7d40fe3..3f340fa 100644 --- a/app/routes/domain.py +++ b/app/routes/domain.py @@ -3,12 +3,45 @@ import whois from app.models import Domain from app import db from app.utils import get_ssl_expiration, get_whois_expiration +from datetime import datetime domain_bp = Blueprint('domain', __name__) @domain_bp.route('/') def home(): - return render_template('home.html') + current_year = datetime.now().year + all_domains = Domain.query.all() + domains_expiring = [] + certs_expiring = [] + + for d in all_domains: + # Filter and sort by WHOIS expiration date (expected format: mm/dd/yyyy) + try: + dt_whois = datetime.strptime(d.expiration_date, "%m/%d/%Y") + if dt_whois.year == current_year: + domains_expiring.append((dt_whois, d)) + except Exception: + pass + + # Filter and sort by SSL expiration date (expected format: mm/dd/yyyy) + try: + dt_ssl = datetime.strptime(d.ssl_expiration_date, "%m/%d/%Y") + if dt_ssl.year == current_year: + certs_expiring.append((dt_ssl, d)) + except Exception: + pass + + # Sort the lists in ascending order by the date + domains_expiring.sort(key=lambda x: x[0]) + certs_expiring.sort(key=lambda x: x[0]) + + # Extract the domain objects from the sorted tuples + domains_expiring = [item[1] for item in domains_expiring] + certs_expiring = [item[1] for item in certs_expiring] + + return render_template('home.html', + domains_expiring=domains_expiring, + certs_expiring=certs_expiring) @domain_bp.route('/domains') def domains(): diff --git a/app/templates/home.html b/app/templates/home.html index 7a5a558..1feaf01 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -1,6 +1,47 @@ {% extends "base.html" %} {% block title %}Home{% endblock %} {% block content %} -

Welcome to the Domain App

-

Use the navigation bar to view your domains or add new ones.

+

Domains Expiring this Year

+{% if domains_expiring and domains_expiring|length > 0 %} + + + + + + + + + {% for d in domains_expiring %} + + + + + {% endfor %} + +
DomainWHOIS Expiration
{{ d.domain }}{{ d.expiration_date }}
+{% else %} +

No domains expiring this year.

+{% endif %} + +

Certs Expiring this Year

+{% if certs_expiring and certs_expiring|length > 0 %} + + + + + + + + + {% for d in certs_expiring %} + + + + + {% endfor %} + +
DomainSSL Expiration
{{ d.domain }}{{ d.ssl_expiration_date }}
+{% else %} +

No certificates expiring this year.

+{% endif %} {% endblock %}