Skip to content

Commit

Permalink
修复 手动编辑域名或证书到期时间,天数筛选不匹配的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Mar 26, 2024
1 parent ec0b415 commit 35acdb7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Domain Admin是一个轻量级监控方案,占用系统资源较少。同时,Domain Admin也可以作为一个Flask 和 Vue.js前后端分离的项目模板

- 功能描述
- 核心功能:`域名``SSL证书` 的过期监控,到期提醒
- 核心功能:`域名``SSL证书``托管证书文件` 的过期监控,到期提醒
- 支持证书:单域名证书、多域名证书、通配符证书、IP证书、自签名证书
- 证书部署: 单一主机部署、多主机部署、动态主机部署
- 通知渠道:支持邮件、Webhook、企业微信、钉钉、飞书等通知方式
Expand Down
1 change: 1 addition & 0 deletions doc/source/manual/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- 2024-02-23 漫跑的小兔 [用Docker部署Domain Admin](https://mp.weixin.qq.com/s/sie9zDP86Ez93FqvJlnU6Q)
- 2024-03-16 ITBLOG [Domain Admin:域名和SSL证书监测系统](https://mp.weixin.qq.com/s/yZ01dMUYcvN2Ms1CsnExhg)
- 2024-03-19 ITBLOG [pip安装Domain-Admin](https://mp.weixin.qq.com/s/cxklXTktXBRzlDxnN5T5tQ)
- 2024-03-23 开源技术小栈 [开源域名SSL证书监测平台 Domain Admin](https://mp.weixin.qq.com/s/DY65JI1jLj42YM1E6-LUGw)

## 参考文章

Expand Down
6 changes: 5 additions & 1 deletion domain_admin/api/domain_info_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ def update_domain_info_by_id():
if is_auto_update is False:
data['domain_start_time'] = domain_start_time
data['domain_expire_time'] = domain_expire_time
data['domain_expire_days'] = time_util.get_diff_days(datetime.now(), domain_expire_time)

if domain_expire_time:
data['domain_expire_days'] = time_util.get_diff_days(datetime.now(), time_util.parse_time(domain_expire_time))
else:
data['domain_expire_days'] = 0

if user_id:
data['user_id'] = user_id
Expand Down
14 changes: 11 additions & 3 deletions domain_admin/service/domain_info_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,20 @@ def get_domain_info_query(keyword, group_ids, domain_expire_days, role, user_id)

if domain_expire_days is not None and len(domain_expire_days) == 2:
if domain_expire_days[0] is None:
query = query.where(DomainInfoModel.domain_expire_days <= domain_expire_days[1])
max_expire_time = datetime.now() + timedelta(days=domain_expire_days[1])
query = query.where(
(DomainInfoModel.domain_expire_time <= max_expire_time)
| (DomainInfoModel.domain_expire_time.is_null(True))
)
elif domain_expire_days[1] is None:
query = query.where(DomainInfoModel.domain_expire_days >= domain_expire_days[0])
min_expire_time = datetime.now() + timedelta(days=domain_expire_days[0])
query = query.where(DomainInfoModel.domain_expire_time >= min_expire_time)
else:
min_expire_time = datetime.now() + timedelta(days=domain_expire_days[0])
max_expire_time = datetime.now() + timedelta(days=domain_expire_days[1])

query = query.where(
DomainInfoModel.domain_expire_days.between(domain_expire_days[0], domain_expire_days[1]))
DomainInfoModel.domain_expire_time.between(min_expire_time, max_expire_time))

return query

Expand Down
16 changes: 12 additions & 4 deletions domain_admin/service/domain_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import io
import traceback
from datetime import datetime
from datetime import datetime, timedelta

from peewee import chunked, fn
from playhouse.shortcuts import model_to_dict
Expand Down Expand Up @@ -532,11 +532,19 @@ def get_domain_list_query(keyword, group_id, group_ids, expire_days, user_id, ro

if expire_days is not None:
if expire_days[0] is None:
query = query.where(DomainModel.expire_days <= expire_days[1])
max_expire_time = datetime.now() + timedelta(days=expire_days[1])
query = query.where(
(DomainModel.expire_time <= max_expire_time)
| (DomainModel.expire_time.is_null(True))
)
elif expire_days[1] is None:
query = query.where(DomainModel.expire_days >= expire_days[0])
min_expire_time = datetime.now() + timedelta(days=expire_days[0])
query = query.where(DomainModel.expire_time >= min_expire_time)
else:
query = query.where(DomainModel.expire_days.between(expire_days[0], expire_days[1]))
min_expire_time = datetime.now() + timedelta(days=expire_days[0])
max_expire_time = datetime.now() + timedelta(days=expire_days[1])

query = query.where(DomainModel.expire_time.between(min_expire_time, max_expire_time))

return query

Expand Down

0 comments on commit 35acdb7

Please sign in to comment.