Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Jun 30, 2023
1 parent 6c381a7 commit 00d08b4
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 133 deletions.
9 changes: 9 additions & 0 deletions domain_admin/enums/version_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ class VersionEnum(object):
Version_144 = '1.4.4'
Version_145 = '1.4.5'
Version_146 = '1.4.6'

Version_147 = '1.4.7'
Version_148 = '1.4.8'
Version_149 = '1.4.9'
Version_1410 = '1.4.10'
Version_1411 = '1.4.11'
Version_1412 = '1.4.12'
Version_1413 = '1.4.13'
Version_1414 = '1.4.14'
28 changes: 28 additions & 0 deletions domain_admin/migrate/migrate_1413_to_1414.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
"""
@File : migrate_1413_to_1414.py
@Date : 2023-06-30
cmd:
$ python domain_admin/migrate/migrate_1413_to_1414.py
"""

from playhouse.migrate import SqliteMigrator, migrate

from domain_admin.migrate import migrate_common
from domain_admin.model.base_model import db
from domain_admin.model.domain_info_model import DomainInfoModel
from domain_admin.model.domain_model import DomainModel


def execute_migrate():
"""
版本升级 1.4.13 => 1.4.14
:return:
"""
migrator = migrate_common.get_migrator(db)

migrate(
migrator.add_column(DomainInfoModel._meta.table_name, DomainInfoModel.domain_registrar.name, DomainInfoModel.domain_registrar),
migrator.add_column(DomainInfoModel._meta.table_name, DomainInfoModel.domain_registrar_url.name, DomainInfoModel.domain_registrar_url),
)
4 changes: 2 additions & 2 deletions domain_admin/service/domain_info_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def update_domain_info_row(row: DomainInfoModel) -> [str, None]:
domain_start_time=update_row.domain_start_time,
domain_expire_time=update_row.domain_expire_time,
domain_expire_days=update_row.real_domain_expire_days,
domain_registrar=domain_whois['registrar'],
domain_registrar_url=domain_whois['registrar_url'],
domain_registrar=update_row.domain_registrar,
domain_registrar_url=update_row.domain_registrar_url,
update_time=datetime_util.get_datetime()
).where(
DomainInfoModel.id == row.id
Expand Down
75 changes: 0 additions & 75 deletions domain_admin/service/domain_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,35 +159,6 @@ def sync_address_info_to_domain_info(domain_row: DomainModel):
).execute()


def update_cert_info(row: DomainModel):
"""
更新证书信息
:param row:
:return:
"""
# 获取证书信息
cert_info = {}

try:
cert_info = get_cert_info(row.domain)
except Exception as e:
pass

DomainModel.update(
start_time=cert_info.get('start_date'),
expire_time=cert_info.get('expire_date'),
expire_days=cert_info.get('expire_days', 0),
total_days=cert_info.get('total_days', 0),
# ip=cert_info.get('ip', ''),
connect_status=cert_info.get('connect_status'),
# detail_raw="",
check_time=datetime_util.get_datetime(),
update_time=datetime_util.get_datetime(),
).where(
DomainModel.id == row.id
).execute()


def update_domain_row(domain_row: DomainModel):
"""
更新域名相关数据
Expand Down Expand Up @@ -250,52 +221,6 @@ def get_cert_info(domain: str):
}


def get_domain_info(domain: str):
"""
获取域名注册信息
:param domain: 域名
:param cache: 查询缓存字典
:return:
"""
warnings.warn("use cache_domain_info_service.get_domain_info", DeprecationWarning)

# cache = global_data_service.get_value('update_domain_list_info_cache')

now = datetime.now()

# 获取域名信息
domain_info = {}
domain_expire_days = 0

# 解析出域名和顶级后缀
extract_result = domain_util.extract_domain(domain)
domain_and_suffix = '.'.join([extract_result.domain, extract_result.suffix])

# if cache:
# domain_info = cache.get(domain_and_suffix)

if not domain_info:
try:
domain_info = whois_util.get_domain_info(domain_and_suffix)
# if cache:
# cache[domain_and_suffix] = domain_info

except Exception:
logger.error(traceback.format_exc())

domain_start_time = domain_info.get('start_time')
domain_expire_time = domain_info.get('expire_time')

if domain_expire_time:
domain_expire_days = (domain_expire_time - now).days

return {
'start_time': domain_start_time,
'expire_time': domain_expire_time,
'expire_days': domain_expire_days
}


def update_all_domain_cert_info():
"""
更新所有域名信息
Expand Down
24 changes: 22 additions & 2 deletions domain_admin/service/version_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
migrate_136_to_140_alpha,
migrate_140_alpha_to_140,
migrate_143_to_144,
migrate_145_to_146
)
migrate_145_to_146,
migrate_1413_to_1414)


def get_local_version():
Expand Down Expand Up @@ -185,6 +185,26 @@ def update_version():

local_version = VersionEnum.Version_146

# 2023-06-30
if local_version in [
VersionEnum.Version_146,
VersionEnum.Version_147,
VersionEnum.Version_148,
VersionEnum.Version_149,
VersionEnum.Version_1410,
VersionEnum.Version_1411,
VersionEnum.Version_1412,
VersionEnum.Version_1413,
VersionEnum.Version_1414,

]:
# 1.4.6 => 1.4.14
logger.info('update version: %s => %s', local_version, VersionEnum.Version_1414)

migrate_1413_to_1414.execute_migrate()

local_version = VersionEnum.Version_1414

# 更新版本号
VersionModel.create(
version=current_version
Expand Down
33 changes: 20 additions & 13 deletions domain_admin/utils/whois_util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'registry_time': 'Creation Date', # 注册时间
'expire_time': 'Registry Expiry Date', # 过期时间
'registrar': 'Registrar', # 注册商
'registrar_url': 'Registrar URL', # 注册商
'registrar_url': 'Registrar URL', # 注册商url
}

# https://www.nirsoft.net/whois-servers.txt
Expand All @@ -26,51 +26,58 @@
'whois_server': 'whois.cnnic.cn',
'registry_time': 'Registration Time',
'expire_time': 'Expiration Time',
'registrar': 'Registrar',
'registrar_url': 'Registrar URL',
'registrar': 'Sponsoring Registrar',
},
'hk': {
'whois_server': 'whois.hkirc.hk',
'registry_time': 'Domain Name Commencement Date',
"registry_time_format": '%d-%m-%Y',
'expire_time': 'Expiry Date',
"expire_time_format": '%d-%m-%Y',
'registrar': 'Registrar',
'registrar_url': 'Registrar URL',
},
'sg': {
'whois_server': 'whois.sgnic.sg',
'registry_time': 'Creation Date',
"registry_time_format": '%d-%m-%Y',
'expire_time': 'Expiration Date',
"expire_time_format": '%d-%m-%Y',
'registrar': 'Registrar',
'registrar_url': 'Registrar URL',
},
'jp': {
'whois_server': 'whois.jprs.jp',
'registry_time': '[登録年月日]',
"registry_time_format": '%Y/%m/%d',
'expire_time': '[有効期限]',
"expire_time_format": '%Y/%m/%d',
'registrar': 'Registrar',
'registrar_url': 'Registrar URL',
},

'中国': {
'whois_server': 'cwhois.cnnic.cn',
'registry_time': 'Registration Time',
'expire_time': 'Expiration Time',
'registrar': 'Registrar',
'registrar_url': 'Registrar URL',
},
'tw': {
'whois_server': 'whois.twnic.net',
'registry_time': 'Record created',
"registry_time_format": '%Y-%m-%d %H:%M:%S (UTC+8)',
'expire_time': 'Record expires',
"expire_time_format": '%Y-%m-%d %H:%M:%S (UTC+8)',
'registrar': 'Registrar',
'registrar_url': 'Registrar URL',
}
}

# 国内cn域名注册商
REGISTRAR_CONFIG = [
{
'registrar': '厦门易名科技股份有限公司',
'registrar_url': 'https://www.ename.net/'
},
{
'registrar': '北京中科三方网络技术有限公司',
'registrar_url': 'https://www.sfn.cn/'
}
]

# 国内cn域名注册商map
REGISTRAR_CONFIG_MAP = {
config['registrar']: config
for config in REGISTRAR_CONFIG
}
9 changes: 4 additions & 5 deletions domain_admin/utils/whois_util/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ def parse_whois_raw(whois_raw: str):
"""
data = {}
for row in whois_raw.split("\n"):
if ":" in row:
row_split = row.split(":", maxsplit=1)
else:
row_split = row.split(" ", maxsplit=1)

# tw
if 'Record expires on' in row or 'Record created on' in row:
row_split = row.split("on", maxsplit=1)
elif ":" in row:
row_split = row.split(":", maxsplit=1)
else:
row_split = row.split(" ", maxsplit=1)

if len(row_split) == 2:
key, value = row_split
Expand Down
Loading

0 comments on commit 00d08b4

Please sign in to comment.