Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mouday committed Apr 22, 2023
1 parent 27e1c73 commit 1fadf79
Show file tree
Hide file tree
Showing 18 changed files with 368 additions and 114 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 更新日志

- v1.2.12(2023-04-22)
- 优化:修改域名信息和证书信息更新缓存机制,避免频繁更新导致请求失败
- 修复:没有设置邮件导致webhook失效的问题

- v1.2.11(2023-04-20)
- 更新whois-servers.txt,感谢[@poctopus](https://github.com/poctopus)贡献代码

Expand Down
64 changes: 40 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@

支持平台:macOS、Linux、Windows

- 项目地址:https://github.com/mouday/domain-admin
- 国内镜像:https://gitee.com/mouday/domain-admin
- pypi:https://pypi.org/project/domain-admin
- docker:https://hub.docker.com/r/mouday/domain-admin

## 项目截图

网页版:

![](https://raw.githubusercontent.com/mouday/domain-admin/master/image/screencapture.png)

桌面端:

![](https://raw.githubusercontent.com/mouday/domain-admin/master/image/screencapture-desktop.png)

## 安装

### 方式一:pip安装
Expand Down Expand Up @@ -88,22 +103,6 @@ make dev

## 项目简介

- 项目地址:https://github.com/mouday/domain-admin
- 国内镜像:https://gitee.com/mouday/domain-admin
- pypi:https://pypi.org/project/domain-admin
- docker:https://hub.docker.com/r/mouday/domain-admin

项目截图


网页版:

![](https://raw.githubusercontent.com/mouday/domain-admin/master/image/screencapture.png)

桌面端:

![](https://raw.githubusercontent.com/mouday/domain-admin/master/image/screencapture-desktop.png)

功能:

- 权限
Expand Down Expand Up @@ -198,13 +197,13 @@ git push -u gitee master
后端选型

- Python3.7.0
- Flask https://flask.palletsprojects.com/en/2.2.x/
- jinja2 https://jinja.palletsprojects.com/en/3.1.x/
- peewee(sqlite) http://docs.peewee-orm.com/en/latest/index.html#
- apscheduler https://apscheduler.readthedocs.io/en/3.x/
- supervisord http://supervisord.org/index.html
- gunicorn https://docs.gunicorn.org/

- [Flask](https://flask.palletsprojects.com/en/2.2.x/)
- [jinja2](https://jinja.palletsprojects.com/en/3.1.x/)
- [peewee(sqlite)](http://docs.peewee-orm.com/en/latest/index.html#)
- [apscheduler](https://apscheduler.readthedocs.io/en/3.x/)
- [supervisord](http://supervisord.org/index.html) 部署推荐
- [gunicorn](https://docs.gunicorn.org/) mac/linux 推荐
- [waitress](https://github.com/Pylons/waitress) windows 推荐

## 问题

Expand Down Expand Up @@ -282,6 +281,22 @@ sqlite> .quit
可尝试更换端口25或465
### 6、webhook模板
可以参考接口文档:[更新用户通知配置](docs/notify/updateNotifyOfUser.md)
### 7、监控域名非443的端口
域名格式
```
域名:端口
eg:
www.baidu.com:8080
```
## 问题反馈交流
群号:731742868
Expand All @@ -299,8 +314,9 @@ sqlite> .quit
- `已完成` 支持域名备注
- `已完成` 支持域名到期数据
- `已完成` webhook支持变量
- `已完成` 异步操作的前端状态显示
- `已完成` 异步操作的前端状态显示
- 暗黑模式
- 支持内网用户自己设置过期时间
证书测试:[https://badssl.com/](https://badssl.com/)
Expand Down
2 changes: 2 additions & 0 deletions docs/notify/updateNotifyOfUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ webhook方式提交的body参数支持[jinja2模板语法](http://doc.yonyouclou
}
```

模板变量同 [获取域名列表](/domain/getDomainList.md)

6、返回示例

```json
Expand Down
28 changes: 28 additions & 0 deletions domain_admin/enums/version_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,31 @@ class VersionEnum(object):
Version_106 = '1.0.6'

Version_110 = '1.1.0'

Version_111 = '1.1.1'

Version_112 = '1.1.2'

Version_113 = '1.1.3'

Version_114 = '1.1.4'

Version_115 = '1.1.5'
Version_116 = '1.1.6'
Version_117 = '1.1.7'
Version_118 = '1.1.8'
Version_119 = '1.1.9'
Version_1110 = '1.1.10'

Version_120 = '1.2.0'
Version_121 = '1.2.1'
Version_122 = '1.2.2'
Version_123 = '1.2.3'
Version_124 = '1.2.4'

Version_128 = '1.2.8'
Version_129 = '1.2.9'
Version_1210 = '1.2.10'
Version_1211 = '1.2.11'

Version_1212 = '1.2.12'
19 changes: 0 additions & 19 deletions domain_admin/migrate.py

This file was deleted.

26 changes: 26 additions & 0 deletions domain_admin/migrate/migrate_110_to_1212.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""
@File : migrate_110_to_1212.py
@Date : 2023-02-06
cmd:
$ python domain_admin/migrate/migrate_110_to_1212.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.1.0 => 1.2.12
:return:
"""
migrator = SqliteMigrator(db)

migrate(
migrator.add_column(DomainModel._meta.table_name, DomainModel.domain_check_time.name, DomainModel.domain_check_time),
migrator.add_column(DomainModel._meta.table_name, DomainModel.ip_check_time.name, DomainModel.ip_check_time),
)
54 changes: 54 additions & 0 deletions domain_admin/model/cache_domain_info_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
from datetime import datetime

from peewee import CharField, IntegerField, DateTimeField

from domain_admin.model.base_model import BaseModel


class CacheDomainInfoModel(BaseModel):
"""
域名信息缓存表
@since 1.2.12
"""
id = IntegerField(primary_key=True)

# 域名
domain = CharField(unique=True)

# 域名注册时间
domain_start_time = DateTimeField(default=None, null=True)

# 域名过期时间
domain_expire_time = DateTimeField(default=None, null=True)

# 缓存过期时间
expire_time = DateTimeField(default=None, null=True)

# 创建时间
create_time = DateTimeField(default=datetime.now)

# 更新时间
update_time = DateTimeField(default=datetime.now)

class Meta:
table_name = 'cache_domain_info'

@property
def is_expired(self) -> [bool, None]:
"""
过期时间
:return:
"""
if self.expire_time:
return (self.expire_time - datetime.now()).seconds <= 0
else:
return None

@property
def domain_expire_days(self) -> [int, None]:
"""域名过期天数"""
if self.domain_expire_time:
return (self.domain_expire_time - datetime.now()).days
else:
return None
3 changes: 3 additions & 0 deletions domain_admin/model/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from domain_admin.model import log_scheduler_model
from domain_admin.model import notify_model
from domain_admin.model import version_model
from domain_admin.model import cache_domain_info_model


# 需要查询初始数据操作的表放前面
tables = [
Expand All @@ -20,6 +22,7 @@
(group_model.GroupModel, None),
(domain_model.DomainModel, None),
(notify_model.NotifyModel, None),
(cache_domain_info_model.CacheDomainInfoModel, None),
]


Expand Down
30 changes: 19 additions & 11 deletions domain_admin/model/domain_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ class DomainModel(BaseModel):
"""域名"""
id = IntegerField(primary_key=True)

# 域名
domain = CharField()

# 用户id
user_id = IntegerField(default=0)

# 域名
domain = CharField()

# 别名/备注
alias = CharField(default="")

# ip
ip = CharField(default="")

# ip信息检查时间 @since 1.2.12
ip_check_time = DateTimeField(default=None, null=True)

# 分组
group_id = IntegerField(default=0, null=False)

Expand All @@ -37,28 +40,36 @@ class DomainModel(BaseModel):
# 域名过期剩余天数,仅用于排序 @since 1.1.0
domain_expire_days = IntegerField(default=0, null=False)

# 域名信息检查时间 @since 1.2.12
domain_check_time = DateTimeField(default=None, null=True)

# SSL签发时间
start_time = DateTimeField(default=None, null=True)

# SSL过期时间
expire_time = DateTimeField(default=None, null=True)

# 连接状态
connect_status = BooleanField(default=None, null=True)

# SSL过期剩余天数,仅用于排序
expire_days = IntegerField(default=0, null=False)

# 最后检查时间
check_time = DateTimeField(default=None, null=True)

# 连接状态
connect_status = BooleanField(default=None, null=True)

# 有效期总天数
total_days = IntegerField(default=0, null=False)

# 通知状态
notify_status = BooleanField(default=True)

# 最后检查时间
check_time = DateTimeField(default=None, null=True)
# 是否监测 @since 1.0.3
is_monitor = BooleanField(default=True)


# 详细信息
# @Deprecated
detail_raw = TextField(default=None, null=True)

# 创建时间
Expand All @@ -67,9 +78,6 @@ class DomainModel(BaseModel):
# 更新时间
update_time = DateTimeField(default=datetime.now)

# 是否监测 @since 1.0.3
is_monitor = BooleanField(default=True)

class Meta:

table_name = 'tb_domain'
Expand Down
40 changes: 40 additions & 0 deletions domain_admin/service/cache_domain_info_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
"""
@File : cache_domain_info_service.py
@Date : 2023-04-22
"""
from datetime import datetime, timedelta

from domain_admin.model.cache_domain_info_model import CacheDomainInfoModel
from domain_admin.utils import domain_util
from domain_admin.utils import domain_util
from domain_admin.utils.whois_util import whois_util


def get_domain_info(domain: str) -> CacheDomainInfoModel:
"""
加一个缓存获取域名信息
:param domain:
:return:
"""
root_domain = domain_util.get_root_domain(domain)

row = CacheDomainInfoModel.select().where(
CacheDomainInfoModel.domain == root_domain
).get_or_none()

# 不存在或者已过期,重新获取
if not row or row.is_expired is True:
domain_whois = whois_util.get_domain_whois(root_domain)

if domain_whois is None:
raise Exception("域名信息获取失败")

row = CacheDomainInfoModel.create(
domain=root_domain,
domain_start_time=domain_whois['start_time'],
domain_expire_time=domain_whois['expire_time'],
expire_time=datetime.now() + timedelta(hours=1)
)

return row
Loading

0 comments on commit 1fadf79

Please sign in to comment.