linkkf 로직수정중
This commit is contained in:
@@ -2,8 +2,8 @@ import random
|
||||
import string
|
||||
import time
|
||||
|
||||
from support import (SupportDiscord, SupportFile, SupportSubprocess,
|
||||
SupportTelegram)
|
||||
from support import (SupportDiscord, SupportFile, SupportSlack,
|
||||
SupportSubprocess, SupportTelegram, SupportYaml)
|
||||
from tool import ToolModalCommand
|
||||
|
||||
from .setup import *
|
||||
@@ -12,7 +12,7 @@ name = 'setting'
|
||||
|
||||
class ModuleSetting(PluginModuleBase):
|
||||
db_default = {
|
||||
'db_version' : '1',
|
||||
'db_version' : '1.1',
|
||||
'port' : '9999',
|
||||
'ddns' : 'http://localhost:9999',
|
||||
'use_login' : 'False',
|
||||
@@ -34,6 +34,8 @@ class ModuleSetting(PluginModuleBase):
|
||||
'notify_telegram_disable_notification' : 'False',
|
||||
'notify_discord_use' : 'False',
|
||||
'notify_discord_webhook' : '',
|
||||
'notify_slack_use' : 'False',
|
||||
'notify_slack_webhook' : '',
|
||||
'notify_advaned_use' : 'False',
|
||||
'notify.yaml': '', #직접 사용하지 않으나 저장 편의상.
|
||||
'command_text': '',
|
||||
@@ -91,10 +93,15 @@ class ModuleSetting(PluginModuleBase):
|
||||
ret['msg'] = 'export.sh 파일이 없습니다.'
|
||||
elif command == 'menu_save':
|
||||
SupportFile.write_file(F.config['menu_yaml_filepath'], arg1 )
|
||||
ret['msg'] = '저장하였습니다.'
|
||||
from framework.init_menu import MenuManager
|
||||
MenuManager.init_menu()
|
||||
F.socketio.emit("refresh", {}, namespace='/framework', broadcast=True)
|
||||
try:
|
||||
SupportYaml.read_yaml(F.config['menu_yaml_filepath'])
|
||||
ret['msg'] = '저장하였습니다.'
|
||||
from framework.init_menu import MenuManager
|
||||
MenuManager.init_menu()
|
||||
F.socketio.emit("refresh", {}, namespace='/framework')
|
||||
except:
|
||||
ret['ret'] = "danger"
|
||||
ret['msg'] = "yaml 형식에 맞지 않습니다"
|
||||
elif command == 'notify_test':
|
||||
if arg1 == 'telegram':
|
||||
token, chatid, sound, text = arg2.split('||')
|
||||
@@ -104,6 +111,9 @@ class ModuleSetting(PluginModuleBase):
|
||||
elif arg1 == 'discord':
|
||||
SupportDiscord.send_discord_message(arg3, webhook_url=arg2)
|
||||
ret['msg'] = '메시지를 전송했습니다.'
|
||||
elif arg1 == 'slack':
|
||||
SupportSlack.send_slack_message(arg3, webhook_url=arg2)
|
||||
ret['msg'] = '메시지를 전송했습니다.'
|
||||
elif arg1 == 'advanced':
|
||||
from tool import ToolNotify
|
||||
ToolNotify.send_advanced_message(arg3, message_id=arg2)
|
||||
@@ -122,7 +132,31 @@ class ModuleSetting(PluginModuleBase):
|
||||
ret['type'] = 'warning'
|
||||
elif command == 'command_run':
|
||||
ret['msg'] = arg1
|
||||
pass
|
||||
SystemModelSetting.set('command_text', arg1)
|
||||
# db이름 set/get key value
|
||||
try:
|
||||
tmp = arg1.strip().split(' ')
|
||||
if tmp[0].startswith('setting'):
|
||||
plugin = F.PluginManager.get_plugin_instance(tmp[1])
|
||||
if len(tmp) == 2 or tmp[2] == 'all':
|
||||
ret['json'] = plugin.ModelSetting.to_dict()
|
||||
ret['ret'] = 'success'
|
||||
elif tmp[2] == 'get':
|
||||
ret['msg'] = plugin.ModelSetting.get(tmp[3])
|
||||
ret['ret'] = 'success'
|
||||
elif tmp[2] == 'set':
|
||||
value = ""
|
||||
if len(tmp) == 5:
|
||||
value = tmp[4]
|
||||
plugin.ModelSetting.set(tmp[3], value)
|
||||
ret['msg'] = f"{tmp[1]} DB에 {tmp[3]}={value} 저장"
|
||||
|
||||
except Exception as e:
|
||||
P.logger.error(f'Exception:{str(e)}')
|
||||
P.logger.error(traceback.format_exc())
|
||||
ret['msg'] = f"실행 실패: {str(e)}"
|
||||
ret['type'] = 'danger'
|
||||
|
||||
elif command == 'celery_execute':
|
||||
self.celery_execute(arg1, mode='foreground')
|
||||
elif command == 'celery_execute_back':
|
||||
@@ -138,8 +172,7 @@ class ModuleSetting(PluginModuleBase):
|
||||
try:
|
||||
if F.config['run_flask'] == False:
|
||||
return
|
||||
if SystemModelSetting.get_bool('celery_start_by_web'):
|
||||
self.celery_execute()
|
||||
|
||||
if F.config['arg_repeat'] == 0 or SystemModelSetting.get('system_start_time') == '':
|
||||
SystemModelSetting.set('system_start_time', datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
||||
SystemModelSetting.set('repeat', str(F.config['arg_repeat']))
|
||||
@@ -162,7 +195,11 @@ class ModuleSetting(PluginModuleBase):
|
||||
from tool import ToolNotify
|
||||
msg = f"시스템이 시작되었습니다.\n재시작: {F.config['arg_repeat']}"
|
||||
ToolNotify.send_message(msg, message_id='system_start')
|
||||
|
||||
if SystemModelSetting.get_bool('celery_start_by_web'):
|
||||
# 2022-11-14 DB는 flask가 만드는데 만들기전 celery를 실행해버림
|
||||
from threading import Timer
|
||||
Timer(10, self.celery_execute).start()
|
||||
#self.celery_execute()
|
||||
|
||||
except Exception as e:
|
||||
P.logger.error(f'Exception:{str(e)}')
|
||||
@@ -173,9 +210,14 @@ class ModuleSetting(PluginModuleBase):
|
||||
|
||||
def setting_save_after(self, change_list):
|
||||
if 'theme' in change_list or 'web_title' in change_list:
|
||||
F.socketio.emit("refresh", {}, namespace='/framework', broadcast=True)
|
||||
F.socketio.emit("refresh", {}, namespace='/framework')
|
||||
elif 'notify.yaml' in change_list:
|
||||
SupportFile.write_file(F.config['notify_yaml_filepath'], SystemModelSetting.get('notify.yaml'))
|
||||
try:
|
||||
SupportFile.write_file(F.config['notify_yaml_filepath'], SystemModelSetting.get('notify.yaml'))
|
||||
SupportYaml.read_yaml(F.config['notify_yaml_filepath'])
|
||||
except:
|
||||
data = {'type':'danger', 'msg' : "알림 정책이 yaml 형식에 맞지 않습니다."}
|
||||
F.socketio.emit("notify", data, namespace='/framework')
|
||||
elif 'web_pw' in change_list:
|
||||
import hashlib
|
||||
enc = hashlib.md5()
|
||||
@@ -185,6 +227,9 @@ class ModuleSetting(PluginModuleBase):
|
||||
if SystemModelSetting.get('restart_interval') == '':
|
||||
SystemModelSetting.set('restart_interval', '0')
|
||||
self.__set_restart_scheduler()
|
||||
elif 'log_level' in change_list:
|
||||
F.set_level(SystemModelSetting.get_int('log_level'))
|
||||
|
||||
|
||||
|
||||
def __set_restart_scheduler(self):
|
||||
@@ -258,6 +303,7 @@ class ModuleSetting(PluginModuleBase):
|
||||
try:
|
||||
time.sleep(1)
|
||||
data = '정상입니다. 이 메시지는 celery 에서 반환됩니다. '
|
||||
P.logger.info(data)
|
||||
return data
|
||||
except Exception as e:
|
||||
P.logger.error(f'Exception:{str(e)}')
|
||||
|
||||
Reference in New Issue
Block a user