This commit is contained in:
flaskfarm
2022-10-07 01:48:42 +09:00
parent 4b72b7dc65
commit cde69d4d8a
55 changed files with 523 additions and 7703 deletions

View File

@@ -1,7 +1,7 @@
import random
import string
from support.base.file import SupportFile
from support import SupportDiscord, SupportFile, SupportTelegram
from .setup import *
@@ -19,9 +19,9 @@ class ModuleSetting(PluginModuleBase):
'use_apikey': 'False',
'apikey': ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)),
f'restart_interval': f'{random.randint(0,59)} {random.randint(1,23)} * * *',
'restart_notify': 'False',
'theme' : 'Cerulean',
'log_level' : '20',
'plugin_dev_path': os.path.join(F.config['path_data'], 'dev'),
'system_start_time': '',
# notify
'notify_telegram_use' : 'False',
@@ -31,6 +31,7 @@ class ModuleSetting(PluginModuleBase):
'notify_discord_use' : 'False',
'notify_discord_webhook' : '',
'notify_advaned_use' : 'False',
'notify.yaml': '', #직접 사용하지 않으나 저장 편의상.
}
def __init__(self, P):
@@ -52,12 +53,17 @@ class ModuleSetting(PluginModuleBase):
elif page == 'menu':
arg['menu_yaml_filepath'] = F.config['menu_yaml_filepath']
arg['menu.yaml'] = SupportFile.read_file(arg['menu_yaml_filepath'])
elif page == 'notify':
arg['notify_yaml_filepath'] = F.config['notify_yaml_filepath']
arg['notify.yaml'] = SupportFile.read_file(arg['notify_yaml_filepath'])
return render_template(f'{__package__}_{name}_{page}.html', arg=arg)
except Exception as e:
P.logger.error(f'Exception:{str(e)}')
P.logger.error(traceback.format_exc())
return render_template('sample.html', title=f"{__package__}/{name}/{page}")
def process_command(self, command, arg1, arg2, arg3, req):
ret = {'ret':'success'}
if command == 'apikey_generate':
@@ -80,11 +86,34 @@ class ModuleSetting(PluginModuleBase):
F.socketio.emit("refresh", {}, namespace='/framework', broadcast=True)
elif command == 'notify_test':
if arg1 == 'telegram':
pass
token, chatid, sound, text = arg2.split('||')
sound = True if sound == 'true' else False
SupportTelegram.send_telegram_message(text, image_url=None, bot_token=token, chat_id=chatid, disable_notification=sound)
ret['msg'] = '메시지를 전송했습니다.'
elif arg1 == 'discord':
SupportDiscord.send_discord_message(arg3, webhook_url=arg2)
ret['msg'] = '메시지를 전송했습니다.'
elif arg1 == 'advanced':
from tool import ToolNotify
ToolNotify.send_advanced_message(arg3, message_id=arg2)
ret['msg'] = '메시지를 전송했습니다.'
elif command == 'ddns_test':
try:
import requests
url = arg1 + '/version'
res = requests.get(url)
data = res.text
ret['msg'] = f"버전: {data}"
except Exception as e:
P.logger.error(f'Exception:{str(e)}')
P.logger.error(traceback.format_exc())
ret['msg'] = str(e)
ret['type'] = 'warning'
elif command == 'command_run':
ret['msg'] = arg1
pass
return jsonify(ret)
def plugin_load(self):
try:
@@ -99,18 +128,29 @@ class ModuleSetting(PluginModuleBase):
self.__set_scheduler_check_scheduler()
F.get_recent_version()
notify_yaml_filepath = os.path.join(F.config['path_data'], 'db', 'notify.yaml')
if os.path.exists(notify_yaml_filepath) == False:
import shutil
shutil.copy(
os.path.join(F.config['path_app'], 'files', 'notify.yaml.template'),
notify_yaml_filepath
)
if SystemModelSetting.get_bool('restart_notify'):
from tool import ToolNotify
msg = f"시스템이 시작되었습니다.\n재시작: {F.config['arg_repeat']}"
ToolNotify.send_message(msg, message_id='system_start')
except Exception as e:
P.logger.error(f'Exception:{str(e)}')
P.logger.error(traceback.format_exc())
def setting_save_after(self, change_list):
if 'theme' in change_list:
F.socketio.emit("refresh", {}, namespace='/framework', broadcast=True)
elif 'notify.yaml' in change_list:
SupportFile.write_file(F.config['notify_yaml_filepath'], SystemModelSetting.get('notify.yaml'))
def __set_restart_scheduler(self):
name = f'{__package__}_restart'
if F.scheduler.is_include(name):
@@ -132,4 +172,3 @@ class ModuleSetting(PluginModuleBase):
scheduler.add_job_instance(job_instance, run=False)