diff --git a/fir_client/src/components/user/FirSuperSignBase.vue b/fir_client/src/components/user/FirSuperSignBase.vue
index 4251666..860d9bc 100644
--- a/fir_client/src/components/user/FirSuperSignBase.vue
+++ b/fir_client/src/components/user/FirSuperSignBase.vue
@@ -133,7 +133,7 @@
active-color="#13ce66"
inactive-color="#ff4949">
- 开启之后,每天凌晨自动检测该开发者状态和设备使用状态,默认关闭
+ 开启之后,每天凌晨自动检测该开发者和设备使用状态,默认关闭
diff --git a/fir_ser/api/utils/sysconfig.py b/fir_ser/api/utils/sysconfig.py
index e18cc78..c3f9e0f 100644
--- a/fir_ser/api/utils/sysconfig.py
+++ b/fir_ser/api/utils/sysconfig.py
@@ -6,8 +6,10 @@
import json
import logging
+import re
from django.template import Context, Template
+from django.template.base import VariableNode
from rest_framework import serializers
from api.models import SystemConfig
@@ -26,6 +28,11 @@ class SystemConfigSerializer(serializers.ModelSerializer):
def get_render_context(tmp: str, context: dict) -> str:
template = Template(tmp)
+ for node in template.nodelist:
+ if isinstance(node, VariableNode):
+ v_key = re.findall(r'', str(node))
+ if v_key and v_key[0].isupper():
+ context[v_key[0]] = getattr(Config, v_key[0])
context = Context(context)
return template.render(context)
@@ -34,30 +41,33 @@ def invalid_config_cache(key='*'):
SystemConfigCache(key).del_many()
-def get_value_from_db(key):
- context_dict = {}
- for sys_obj_dict in SystemConfig.objects.values().all():
- context_dict[sys_obj_dict['key']] = sys_obj_dict['value']
- data = SystemConfigSerializer(SystemConfig.objects.filter(key=key).first()).data
- value = data.get('value', '')
+def get_render_value(value):
if value:
try:
- r_text = get_render_context(value, context_dict)
- data['value'] = r_text
- try:
- data['value'] = json.loads(r_text)
- except Exception as e:
- logger.warning(f"db config - json loads failed {e}")
+ context_dict = {}
+ for sys_obj_dict in SystemConfig.objects.values().all():
+ if re.findall('{{.*%s.*}}' % sys_obj_dict['key'], sys_obj_dict['value']):
+ logger.warning(f"get same render key. so continue")
+ continue
+ context_dict[sys_obj_dict['key']] = sys_obj_dict['value']
+
+ value = get_render_context(value, context_dict)
except Exception as e:
logger.warning(f"db config - render failed {e}")
-
- return data
+ return value
class ConfigCacheBase(object):
def __init__(self, px=''):
self.px = px
+ def get_value_from_db(self, key):
+ data = SystemConfigSerializer(SystemConfig.objects.filter(key=key).first()).data
+ if re.findall('{{.*%s.*}}' % data['key'], data['value']):
+ logger.warning(f"get same render key. so get default value")
+ data['key'] = ''
+ return data
+
def get_value(self, key, data=None):
if data is None:
data = {}
@@ -65,11 +75,16 @@ class ConfigCacheBase(object):
cache_data = cache.get_storage_cache()
if cache_data is not None and cache_data.get('key', '') == key:
return cache_data.get('value')
- db_data = get_value_from_db(key)
+ db_data = self.get_value_from_db(key)
d_key = db_data.get('key', '')
if d_key != key and data is not None:
- db_data['value'] = data
+ db_data['value'] = json.dumps(data)
db_data['key'] = key
+ db_data['value'] = get_render_value(db_data['value'])
+ try:
+ db_data['value'] = json.loads(db_data['value'])
+ except Exception as e:
+ logger.warning(f"db config - json loads failed {e}")
cache.set_storage_cache(db_data, timeout=60 * 60 * 24 * 30)
return db_data.get('value')
@@ -106,6 +121,10 @@ class ConfigCacheBase(object):
def FILE_UPLOAD_DOMAIN(self):
return self.get_value('FILE_UPLOAD_DOMAIN', self.API_DOMAIN)
+ @property
+ def CAN_RENDER_KEY(self):
+ return self.get_value('CAN_RENDER_KEY', [])
+
class BaseConfCache(ConfigCacheBase):
def __init__(self):
diff --git a/fir_ser/config.py b/fir_ser/config.py
index 731afab..64c0566 100644
--- a/fir_ser/config.py
+++ b/fir_ser/config.py
@@ -258,13 +258,13 @@ class IPACONF(object):
# 默认描述文件路径或者下载路径,用户企业签名或者超级签名 跳转 [设置 - 通用 - 描述文件|设备管理] 页面
# 如果配置了path路径,则走路径,如果配置了url,则走URL,path 优先级大于url优先级
'enterprise': {
- 'url': MOBILEPROVISION,
+ 'url': '{{MOBILEPROVISION}}',
# 'path': os.path.join(BASE_DIR,'files', 'embedded.mobileprovision'),
},
'supersign': {
# 超级签名,如果self 为True,则默认用自己的描述文件,否则同企业配置顺序一致,自己的配置文件有时候有问题
'self': False,
- 'url': MOBILEPROVISION,
+ 'url': '{{MOBILEPROVISION}}',
# 'path': os.path.join(BASE_DIR,'files', 'embedded.mobileprovision'),
}
}