-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
941 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) |
Oops, something went wrong.