45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
|
from django.shortcuts import HttpResponse
|
|||
|
from apps.api import models as m_api
|
|||
|
from django.views.decorators.http import require_http_methods, require_POST, require_GET
|
|||
|
from apps.api.common import CaesarCypherClass, Base64CypherClass
|
|||
|
from apps.api.config import Config
|
|||
|
|
|||
|
config = Config()
|
|||
|
caesar = CaesarCypherClass()
|
|||
|
base64 = Base64CypherClass()
|
|||
|
|
|||
|
|
|||
|
# Create your views here.
|
|||
|
@require_POST
|
|||
|
def get_config(request):
|
|||
|
"""
|
|||
|
获取系统配置的接口,通过identity标识字段查询param参数并返回,如果使用加密版数据库则根据加密方式进行解密后返回
|
|||
|
:param request: identity标识字段
|
|||
|
:return: 获取到的参数param
|
|||
|
"""
|
|||
|
try:
|
|||
|
identity = request.POST.get("param")
|
|||
|
if config.getconfig("isCypher"): # 启用加密数据库
|
|||
|
param_base64 = m_api.SysConfig.objects.using("cypher").filter(identity=identity).first().param
|
|||
|
if config.getconfig("CypherMethod") == "caesar": # 加密方式为Caesar
|
|||
|
param = caesar.caesar_decode(param_base64)
|
|||
|
return HttpResponse(param)
|
|||
|
else: # 加密方式为Base64
|
|||
|
param = base64.base64_decode_str(base64, param_base64)
|
|||
|
return HttpResponse(param)
|
|||
|
else: # 不加密的数据库
|
|||
|
param = m_api.SysConfig.objects.using("default").filter(identity=identity).first().param
|
|||
|
return HttpResponse(param)
|
|||
|
except Exception as e:
|
|||
|
print(f"报错了:{e}")
|
|||
|
return HttpResponse(f"报错了:{e}")
|
|||
|
|
|||
|
|
|||
|
@require_POST
|
|||
|
def add_config(request):
|
|||
|
try:
|
|||
|
pass
|
|||
|
except Exception as e:
|
|||
|
print(f"报错了:{e}")
|
|||
|
return HttpResponse(f"报错了:{e}")
|