Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Jun 4, 2023
1 parent f310558 commit ad733fe
Show file tree
Hide file tree
Showing 24 changed files with 941 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 更新日志
- v1.3.1(2023-06-03)
- 新增 支持一个域名解析到多主机ip地址的SSL证书查询
- 优化 优化前端界面显示

- v1.2.23(2023-06-01)
- 新增 实验室tab,增加查询whois原始信息功能

Expand Down
163 changes: 163 additions & 0 deletions domain_admin/api/address_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# -*- coding: utf-8 -*-

"""
address_api.py
"""
from flask import request, g
from peewee import fn
from playhouse.shortcuts import model_to_dict

from domain_admin.model.address_model import AddressModel
from domain_admin.model.domain_model import DomainModel
from domain_admin.model.group_model import GroupModel
from domain_admin.service import async_task_service
from domain_admin.service import domain_service, global_data_service
from domain_admin.service import file_service
from domain_admin.utils import datetime_util
from domain_admin.utils.flask_ext.app_exception import AppException


def get_address_list_by_domain_id():
"""
通过域名id获取关联的主机地址列表
:return:
@since v1.3.1
"""

current_user_id = g.user_id

domain_id = request.json['domain_id']

rows = AddressModel.select().where(
AddressModel.domain_id == domain_id
)

lst = list(map(lambda m: model_to_dict(
model=m,
extra_attrs=[
'ssl_start_date',
'ssl_expire_date',
'real_time_ssl_expire_days',
'ssl_check_time_label',
]
), rows))

return {
"list": lst,
"total": len(lst)
}


def add_address():
"""
添加主机地址
:return:
@since v1.3.1
"""

current_user_id = g.user_id

domain_id = request.json['domain_id']
host = request.json['host']
ssl_start_time = request.json.get('ssl_start_time')
ssl_expire_time = request.json.get('ssl_expire_time')
ssl_auto_update = request.json.get('ssl_auto_update', True)
ssl_expire_monitor = request.json.get('ssl_expire_monitor', True)

address_row = AddressModel.create(
domain_id=domain_id,
host=host,
ssl_start_time=ssl_start_time,
ssl_expire_time=ssl_expire_time,
ssl_auto_update=ssl_auto_update,
ssl_expire_monitor=ssl_expire_monitor,
)

domain_service.update_address_row_info_with_sync_domain_row(address_row.address_id)


def delete_address_by_id():
"""
删除主机地址
:return:
@since v1.3.1
"""

current_user_id = g.user_id

address_id = request.json['address_id']

AddressModel.delete().where(
AddressModel.id == address_id
).execute()


def get_address_by_id():
"""
获取主机地址
:return:
@since v1.3.1
"""

current_user_id = g.user_id

address_id = request.json['address_id']

return AddressModel.get_by_id(address_id)


def update_address_by_id():
"""
更新主机地址
:return:
@since v1.3.1
"""

current_user_id = g.user_id

address_id = request.json['address_id']
host = request.json['host']
ssl_start_time = request.json.get('ssl_start_time')
ssl_expire_time = request.json.get('ssl_expire_time')
ssl_auto_update = request.json.get('ssl_auto_update', True)
ssl_expire_monitor = request.json.get('ssl_expire_monitor', True)

AddressModel.update(
host=host,
ssl_start_time=ssl_start_time,
ssl_expire_time=ssl_expire_time,
ssl_auto_update=ssl_auto_update,
ssl_expire_monitor=ssl_expire_monitor,
).where(
AddressModel.id == address_id
).execute()

domain_service.update_address_row_info_with_sync_domain_row(address_id)


def update_address_list_info_by_domain_id():
"""
更新主机地址信息
:return:
@since v1.3.1
"""

current_user_id = g.user_id

domain_id = request.json['domain_id']
domain_row = DomainModel.get_by_id(domain_id)
domain_service.update_domain_address_info(domain_row)

def update_address_row_info_by_id():
"""
更新主机地址信息
:return:
@since v1.3.1
"""

current_user_id = g.user_id

address_id = request.json['address_id']

domain_service.update_address_row_info_with_sync_domain_row(address_id)

54 changes: 49 additions & 5 deletions domain_admin/api/domain_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from peewee import fn
from playhouse.shortcuts import model_to_dict

from domain_admin.model.address_model import AddressModel
from domain_admin.model.domain_model import DomainModel
from domain_admin.model.group_model import GroupModel
from domain_admin.service import async_task_service
from domain_admin.service import domain_service, global_data_service
from domain_admin.service import file_service
from domain_admin.utils import datetime_util
from domain_admin.utils.cert_util import cert_consts
from domain_admin.utils.flask_ext.app_exception import AppException


Expand All @@ -28,11 +30,13 @@ def add_domain():

alias = request.json.get('alias', '')
group_id = request.json.get('group_id') or 0
port = request.json.get('port') or cert_consts.SSL_DEFAULT_PORT

data = {
# 基本信息
'user_id': current_user_id,
'domain': domain,
'port': port,
'alias': alias,
'group_id': group_id,
}
Expand All @@ -59,12 +63,14 @@ def update_domain_setting():
'domain_start_time': request.json.get('domain_start_time'),
'domain_expire_time': request.json.get('domain_expire_time'),
'domain_auto_update': request.json.get('domain_auto_update'),
'domain_expire_monitor': request.json.get('domain_expire_monitor'),

# 证书信息
'start_time': request.json.get('start_time'),
'expire_time': request.json.get('expire_time'),
'auto_update': request.json.get('auto_update'),
# 'start_time': request.json.get('start_time'),
# 'expire_time': request.json.get('expire_time'),
# 'auto_update': request.json.get('auto_update'),

'domain_check_time': datetime_util.get_datetime(),
'update_time': datetime_util.get_datetime()
}

Expand Down Expand Up @@ -111,6 +117,11 @@ def delete_domain_by_id():

DomainModel.delete_by_id(domain_id)

# 同时移除主机信息
AddressModel.delete().where(
AddressModel.domain_id == domain_id
).execute()


def delete_domain_by_ids():
"""
Expand All @@ -127,6 +138,11 @@ def delete_domain_by_ids():
DomainModel.user_id == current_user_id
).execute()

# 同时移除主机信息
AddressModel.delete().where(
AddressModel.domain_id.in_(domain_ids)
).execute()


def get_domain_list():
"""
Expand Down Expand Up @@ -217,6 +233,8 @@ def get_domain_list():
'create_time_label',
'check_time_label',
'real_time_expire_days',
'real_time_ssl_total_days',
'real_time_ssl_expire_days',
'real_time_domain_expire_days',
'domain_url',
'update_time_label',
Expand Down Expand Up @@ -253,6 +271,7 @@ def get_domain_by_id():
'detail',
'group',
'domain_url',
'domain_check_time_label',
]
)

Expand Down Expand Up @@ -316,7 +335,25 @@ def update_domain_cert_info_by_id():
"""
current_user_id = g.user_id

domain_id = request.json['id']
# @since v1.2.24 支持参数 domain_id
domain_id = request.json.get('domain_id') or request.json['id']

row = domain_service.check_permission_and_get_row(domain_id, current_user_id)

# domain_service.update_domain_row(row)
domain_service.update_domain_info(row)


def update_domain_row_info_by_id():
"""
更新域名信息及其关联的证书信息
:return:
@since v1.3.1
"""
current_user_id = g.user_id

# @since v1.2.24 支持参数 domain_id
domain_id = request.json.get('domain_id') or request.json['id']

row = domain_service.check_permission_and_get_row(domain_id, current_user_id)

Expand Down Expand Up @@ -384,8 +421,15 @@ def import_domain_from_file():

filename = file_service.save_temp_file(update_file)

# 导入数据
domain_service.add_domain_from_file(filename, current_user_id)

# 异步导入
async_task_service.submit_task(fn=domain_service.add_domain_from_file, filename=filename, user_id=current_user_id)
# async_task_service.submit_task(fn=domain_service.add_domain_from_file, filename=filename, user_id=current_user_id)

# 异步查询
async_task_service.submit_task(fn=domain_service.update_all_domain_cert_info_of_user, user_id=current_user_id)



def export_domain_file():
Expand Down
10 changes: 10 additions & 0 deletions domain_admin/enums/version_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ class VersionEnum(object):
Version_1213 = '1.2.13'

Version_1214 = '1.2.14'

Version_1215 = '1.2.15'
Version_1216 = '1.2.16'
Version_1217 = '1.2.17'
Version_1218 = '1.2.18'
Version_1221 = '1.2.21'
Version_1222 = '1.2.22'
Version_1223 = '1.2.23'

Version_131 = '1.3.1'
6 changes: 6 additions & 0 deletions domain_admin/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
# 单个日志文件最大为1M
handler = RotatingFileHandler(resolve_log_file("domain-admin.log"), maxBytes=1024 * 1024 * 1, encoding='utf-8')

# 设置日志格式
formatter = logging.Formatter(
fmt='%(asctime)s [%(levelname)s] %(filename)s/%(funcName)s:\n%(message)s\n',
datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)

# logger.addHandler(logging.FileHandler(resolve_log_file("domain-admin.log")))
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
26 changes: 26 additions & 0 deletions domain_admin/migrate/migrate_1213_to_131.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""
@File : migrate_1213_to_131.py
@Date : 2023-06-03
cmd:
$ python domain_admin/migrate/migrate_1213_to_131.py
"""

from playhouse.migrate import SqliteMigrator, migrate

from domain_admin.model.base_model import db
from domain_admin.model.domain_model import DomainModel


def execute_migrate():
"""
版本升级 1.2.13 => 1.3.1
:return:
"""
migrator = SqliteMigrator(db)

migrate(
migrator.add_column(DomainModel._meta.table_name, DomainModel.port.name, DomainModel.port),
migrator.add_column(DomainModel._meta.table_name, DomainModel.domain_expire_monitor.name, DomainModel.domain_expire_monitor),
)
Loading

0 comments on commit ad733fe

Please sign in to comment.