diff --git a/app.py b/app.py index 7f11430..9df1b11 100644 --- a/app.py +++ b/app.py @@ -1400,9 +1400,11 @@ def create_ca_view(): from datetime import timedelta # 确保顶部已导入 + @app.route('/cas/') @login_required def ca_detail(ca_id): + page = request.args.get('page', 1, type=int) ca = get_ca_by_id(ca_id) if not ca: flash('CA不存在', 'danger') @@ -1413,16 +1415,28 @@ def ca_detail(ca_id): flash('无权访问此CA', 'danger') return redirect(url_for('ca_list')) - # 获取该CA颁发的证书 + # 获取该CA颁发的证书(分页) conn = get_db_connection() if conn: try: cursor = conn.cursor(dictionary=True) + + # 获取证书总数 + cursor.execute(""" + SELECT COUNT(*) as total FROM certificates + WHERE ca_id = %s + """, (ca_id,)) + total = cursor.fetchone()['total'] + total_pages = ceil(total / PER_PAGE) + + # 获取分页数据 + offset = (page - 1) * PER_PAGE cursor.execute(""" SELECT * FROM certificates WHERE ca_id = %s ORDER BY created_at DESC - """, (ca_id,)) + LIMIT %s OFFSET %s + """, (ca_id, PER_PAGE, offset)) certificates = cursor.fetchall() # 获取CRL信息 @@ -1437,8 +1451,11 @@ def ca_detail(ca_id): ca=ca, certificates=certificates, crl=crl, - timedelta=timedelta, # 传递timedelta到模板 - get_username=get_username # 确保这个函数已定义 + page=page, + total_pages=total_pages, + total=total, + timedelta=timedelta, + get_username=get_username ) except Error as e: print(f"Database error: {e}") diff --git a/templates/base.html b/templates/base.html index 470a737..12f4976 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,7 +3,7 @@ - 证书管理系统 - {% block title %}{% endblock %} + 自签证书管理系统 - {% block title %}{% endblock %} diff --git a/templates/ca_detail.html b/templates/ca_detail.html index 1b597a4..7a3e01e 100644 --- a/templates/ca_detail.html +++ b/templates/ca_detail.html @@ -112,11 +112,12 @@ +
颁发的证书 - {{ certificates|length }} + {{ total }}
{{ cert.expires_at.strftime('%Y-%m-%d') }} {{ cert.created_at.strftime('%Y-%m-%d') }} - - + {% endfor %}
+ + {% if total_pages > 1 %} + + {% endif %} + {% else %}