Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Jun 23, 2023
1 parent fffff19 commit b453c3f
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 228 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 更新日志
- v1.4.6(2023-06-23)
- v1.4.7(2023-06-23)
- 优化 获取证书支持:IP证书、多域名证书、通配符证书
- 优化 移除未使用的域名信息缓存表`cache_domain_info`

- v1.4.6(2023-06-22)
- 新增 通知方式增加备注字段
- 新增 通知方式新增钉钉、飞书渠道

Expand Down
30 changes: 16 additions & 14 deletions domain_admin/api/domain_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,22 @@ def add_domain():
domain_service.update_domain_row(row)

# 顺带添加到域名监测列表
first_domain_info_row = DomainInfoModel.select(
DomainInfoModel.id
).where(
DomainInfoModel.domain == data['root_domain'],
DomainInfoModel.user_id == current_user_id
).first()

if not first_domain_info_row:
domain_info_service.add_domain_info(
domain=domain_util.get_root_domain(domain),
comment=alias,
group_id=group_id,
user_id=current_user_id,
)
if not domain_util.is_ipv4(domain):

first_domain_info_row = DomainInfoModel.select(
DomainInfoModel.id
).where(
DomainInfoModel.domain == data['root_domain'],
DomainInfoModel.user_id == current_user_id
).first()

if not first_domain_info_row:
domain_info_service.add_domain_info(
domain=domain_util.get_root_domain(domain),
comment=alias,
group_id=group_id,
user_id=current_user_id,
)

return {'id': row.id}

Expand Down
6 changes: 5 additions & 1 deletion domain_admin/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
logger = logging.getLogger('domain-admin')

# 单个日志文件最大为1M
handler = RotatingFileHandler(resolve_log_file("domain-admin.log"), maxBytes=1024 * 1024 * 1, encoding='utf-8')
handler = RotatingFileHandler(
filename=resolve_log_file("domain-admin.log"),
maxBytes=1024 * 1024 * 1,
encoding='utf-8'
)

# 设置日志格式
formatter = logging.Formatter(
Expand Down
53 changes: 0 additions & 53 deletions domain_admin/model/cache_domain_info_model.py

This file was deleted.

2 changes: 1 addition & 1 deletion domain_admin/model/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
(group_model.GroupModel, None),
(domain_model.DomainModel, None),
(notify_model.NotifyModel, None),
(cache_domain_info_model.CacheDomainInfoModel, None),
# (cache_domain_info_model.CacheDomainInfoModel, None),
(address_model.AddressModel, None),
(domain_info_model.DomainInfoModel, None),
]
Expand Down
46 changes: 0 additions & 46 deletions domain_admin/service/cache_domain_info_service.py

This file was deleted.

9 changes: 8 additions & 1 deletion domain_admin/service/domain_info_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"""
domain_info_service.py
"""
import random
import time
import traceback
from datetime import datetime
from typing import List
Expand Down Expand Up @@ -62,7 +64,12 @@ def update_domain_info_row(row: DomainInfoModel) -> [str, None]:
try:
domain_whois = whois_util.get_domain_info(row.domain)
except Exception as e:
pass
# 增加容错
try:
time.sleep(3)
domain_whois = whois_util.get_domain_info(row.domain)
except Exception as e:
pass

update_row = DomainInfoModel()

Expand Down
78 changes: 6 additions & 72 deletions domain_admin/service/domain_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""
domain_service.py
"""
import time
import traceback
import warnings
from datetime import datetime
Expand All @@ -15,84 +14,17 @@
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.model.log_scheduler_model import LogSchedulerModel
from domain_admin.model.user_model import UserModel
from domain_admin.service import email_service, render_service, global_data_service, cache_domain_info_service
from domain_admin.service import email_service, render_service
from domain_admin.service import file_service
from domain_admin.service import notify_service
from domain_admin.service import system_service
from domain_admin.utils import datetime_util, cert_util, whois_util, file_util, time_util
from domain_admin.utils import datetime_util, cert_util, whois_util
from domain_admin.utils import domain_util
from domain_admin.utils.cert_util import cert_common, cert_socket_v2
from domain_admin.utils.cert_util import cert_common, cert_socket_v2, cert_openssl_v2
from domain_admin.utils.flask_ext.app_exception import AppException, ForbiddenAppException


def update_domain_info(domain_row: DomainModel):
"""
更新域名信息
:param row:
:return:
"""
# logger.info("%s", model_to_dict(domain_row))

# 获取域名信息
domain_info = None

err = ''

try:
domain_info = cache_domain_info_service.get_domain_info(domain_row.domain)
except Exception as e:
err = e.__str__()
pass

update_data = {
'domain_start_time': None,
"domain_expire_time": None,
'domain_expire_days': 0,
}

if domain_info:
update_data = {
'domain_start_time': domain_info.domain_start_time,
"domain_expire_time": domain_info.domain_expire_time,
'domain_expire_days': domain_info.domain_expire_days,
}

DomainModel.update(
**update_data,
domain_check_time=datetime_util.get_datetime(),
update_time=datetime_util.get_datetime(),
).where(
DomainModel.id == domain_row.id
).execute()

return err


def update_ip_info(row: DomainModel):
"""
更新ip信息
:param row:
:return:
"""
# 获取ip地址
domain_ip = ''

try:
domain_ip = cert_common.get_domain_ip(row.domain)
except Exception as e:
pass

DomainModel.update(
ip=domain_ip,
ip_check_time=datetime_util.get_datetime(),
update_time=datetime_util.get_datetime(),
).where(
DomainModel.id == row.id
).execute()


def update_domain_host_list(domain_row: DomainModel):
"""
更新ip信息
Expand Down Expand Up @@ -153,7 +85,7 @@ def update_address_row_info(address_row, domain_row):

err = ''
try:
cert_info = cert_socket_v2.get_ssl_cert_info(
cert_info = cert_openssl_v2.get_ssl_cert_by_openssl(
domain=domain_row.domain,
host=address_row.host,
port=domain_row.port
Expand Down Expand Up @@ -543,6 +475,8 @@ def send_domain_list_email(user_id, rows: List[DomainModel]):
to_addresses=email_list,
content_type='html'
)


def check_permission_and_get_row(domain_id, user_id):
"""
权限检查
Expand Down
Loading

0 comments on commit b453c3f

Please sign in to comment.