Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Apr 4, 2023
1 parent 64555d9 commit ca8c9eb
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## 更新日志

- v1.2.0(2023-04-04)
- 新增:支持域名分组
- 优化:异步操作的前端状态显示
- 优化:优化前端域名列表字段显示

- v1.1.10(2023-04-03)
- 修复:部分域名剩余天数检测失败的问题
- 优化:查询域名之前进行域名优化处理,减少查询请求
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,13 @@ sqlite> .quit
开发计划
- `已完成` 支持企业微信通知
- 支持域名分组
- `已完成` 支持域名分组
- 增加理员权限,权限分级:root 管理员 普通用户
- `已完成` 解决批量导入超时问题,支持1000条数据导入
- `已完成` 支持域名备注
- `已完成` 支持域名到期数据
- `已完成` webhook支持变量
- 异步操作的前端状态显示
- `已完成` 异步操作的前端状态显示
证书测试:[https://badssl.com/](https://badssl.com/)
Expand Down
39 changes: 37 additions & 2 deletions domain_admin/api/domain_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from domain_admin.model.domain_model import DomainModel
from domain_admin.model.group_model import GroupModel
from domain_admin.service import domain_service
from domain_admin.service import domain_service, global_data_service
from domain_admin.service import file_service
from domain_admin.service import async_task_service
from domain_admin.utils import datetime_util
Expand Down Expand Up @@ -136,7 +136,7 @@ def get_domain_list():
]
), lst))

lst = model_util.list_with_relation_one(lst, 'group', GroupModel)
# lst = model_util.list_with_relation_one(lst, 'group', GroupModel)

return {
'list': lst,
Expand Down Expand Up @@ -187,9 +187,41 @@ def update_all_domain_cert_info_of_user():
current_user_id = g.user_id
# domain_service.update_all_domain_cert_info_of_user(current_user_id)
# 异步更新
key = f'update_domain_status:{current_user_id}'
global_data_service.set_value(key, True)
async_task_service.submit_task(fn=domain_service.update_all_domain_cert_info_of_user, user_id=current_user_id)


def get_update_domain_status_of_user():
"""
获取域名信息更新状态
true:正在更新
false:更新完毕
:return:
"""
current_user_id = g.user_id
key = f'update_domain_status:{current_user_id}'

return {
'status': global_data_service.get_value(key)
}


def get_check_domain_status_of_user():
"""
获取证书检查状态
true:正在更新
false:更新完毕
:return:
"""
current_user_id = g.user_id
key = f'check_domain_status:{current_user_id}'

return {
'status': global_data_service.get_value(key)
}


def update_domain_cert_info_by_id():
"""
更新域名证书信息
Expand Down Expand Up @@ -221,6 +253,9 @@ def check_domain_cert():
"""
current_user_id = g.user_id

key = f'check_domain_status:{current_user_id}'
global_data_service.set_value(key, True)

# # 先更新,再检查
# domain_service.update_all_domain_cert_info_of_user(current_user_id)
#
Expand Down
25 changes: 14 additions & 11 deletions domain_admin/api/group_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ def update_group_by_id():
current_user_id = g.user_id

group_id = request.json['id']
name = request.json.get('name')

group_service.check_group_permission(group_id, current_user_id)

name = request.json.get('name')

GroupModel.update(
name=name,
).where(
Expand All @@ -63,21 +62,25 @@ def get_group_list():
获取域名列表
:return:
"""
# page = request.json.get('page', 1)
# size = request.json.get('size', 10)
page = request.json.get('page', 1)
size = request.json.get('size', 10)
keyword = request.json.get('keyword')

current_user_id = g.user_id

lst = GroupModel.select().where(
query = GroupModel.select().where(
GroupModel.user_id == current_user_id
).order_by(
GroupModel.create_time.asc(),
GroupModel.id.asc()
)

total = GroupModel.select().where(
GroupModel.user_id == current_user_id
).count()
if keyword:
query = query.where(GroupModel.name.contains(keyword))

total = query.count()

lst = query.order_by(
GroupModel.create_time.asc(),
GroupModel.id.asc()
).paginate(page, size)

return {
'list': lst,
Expand Down
3 changes: 2 additions & 1 deletion domain_admin/router/api_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"/api/checkDomainCert": domain_api.check_domain_cert,
"/api/importDomainFromFile": domain_api.import_domain_from_file,
"/api/getAllDomainListOfUser": domain_api.get_all_domain_list_of_user,
"/api/getUpdateDomainStatusOfUser": domain_api.get_update_domain_status_of_user,
"/api/getCheckDomainStatusOfUser": domain_api.get_check_domain_status_of_user,

# 分组管理
"/api/addGroup": group_api.add_group,
Expand Down Expand Up @@ -58,7 +60,6 @@
'/api/updateUserStatus': user_api.update_user_status,
'/api/deleteUser': user_api.delete_user,


# 获取ip信息
'/api/getIpInfo': ip_api.get_ip_info,

Expand Down
22 changes: 17 additions & 5 deletions domain_admin/service/domain_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from domain_admin.model.domain_model import DomainModel
from domain_admin.model.log_scheduler_model import LogSchedulerModel
from domain_admin.model.user_model import UserModel
from domain_admin.service import email_service, render_service
from domain_admin.service import email_service, render_service, global_data_service
from domain_admin.service import file_service
from domain_admin.service import notify_service
from domain_admin.service import system_service
Expand Down Expand Up @@ -47,16 +47,17 @@ def add_domain(data):
return row


def update_domain_cert_info(row, cache=None):
def update_domain_cert_info(row):
"""
更新域名和证书信息
:param cache:
:param row:
:return:
"""
logger.info('update_domain_cert_info: %s', row.domain)

# 获取域名信息
domain_info = get_domain_info(row.domain, cache)
domain_info = get_domain_info(row.domain)

# 获取证书信息
cert_info = get_cert_info(row.domain)
Expand Down Expand Up @@ -113,14 +114,16 @@ def get_cert_info(domain: str):
}


def get_domain_info(domain: str, cache=None):
def get_domain_info(domain: str):
"""
获取域名注册信息
:param domain: 域名
:param cache: 查询缓存字典
:return:
"""

cache = global_data_service.get_value('update_domain_list_info_cache')

now = datetime.now()

# 获取域名信息
Expand Down Expand Up @@ -173,13 +176,16 @@ def update_domain_list_info(rows):
"""
# 增加缓存,提升查询效率
cache = {}
global_data_service.set_value('update_domain_list_info_cache', cache)

for row in rows:
update_domain_cert_info(row, cache)
update_domain_cert_info(row)
# bugfix: ConnectionResetError: [Errno 104] Connection reset by peer
# 请求过于频繁
time.sleep(0.5)

global_data_service.remove_value('update_domain_list_info_cache')


def update_all_domain_cert_info_of_user(user_id):
"""
Expand All @@ -192,6 +198,9 @@ def update_all_domain_cert_info_of_user(user_id):

update_domain_list_info(lst)

key = f'update_domain_status:{user_id}'
global_data_service.set_value(key, False)


def get_domain_info_list(user_id=None):
query = DomainModel.select()
Expand Down Expand Up @@ -420,3 +429,6 @@ def update_and_check_domain_cert(user_id):
update_all_domain_cert_info_of_user(user_id)

check_domain_cert(user_id)

key = f'check_domain_status:{user_id}'
global_data_service.set_value(key, False)
22 changes: 22 additions & 0 deletions domain_admin/service/global_data_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
"""
@File : global_data_service.py
@Date : 2023-04-04
APP全局数据
"""

GLOBAL_DATA = {}


def get_value(key):
return GLOBAL_DATA.get(key)


def set_value(key, value):
GLOBAL_DATA[key] = value


def remove_value(key):
if key in GLOBAL_DATA:
GLOBAL_DATA.pop(key)
2 changes: 1 addition & 1 deletion domain_admin/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"""
版本号
"""
VERSION = '1.1.10'
VERSION = '1.2.0'

0 comments on commit ca8c9eb

Please sign in to comment.