'+s+'',
- 'pre': lambda s,e: ''+s+''} - - return _apply_entities(text, entities, escapes, formatters) diff --git a/lib/system/logic_auth.py b/lib/system/logic_auth.py index f680e61..3411b0a 100644 --- a/lib/system/logic_auth.py +++ b/lib/system/logic_auth.py @@ -1,25 +1,27 @@ # -*- coding: utf-8 -*- ######################################################### # python -import os -import traceback -import random -import json -import string import codecs +import json +import os +import random +import string +import traceback # third-party import requests -from flask import Blueprint, request, Response, send_file, render_template, redirect, jsonify +from flask import (Blueprint, Response, jsonify, redirect, render_template, + request, send_file) +from framework import app, frame, path_app_root +from framework.util import Util + +from .model import ModelSetting +# 패키지 +from .plugin import logger, package_name # sjva 공용 -from framework import frame, path_app_root, app -from framework.util import Util -# 패키지 -from .plugin import package_name, logger -from .model import ModelSetting class SystemLogicAuth(object): @staticmethod @@ -78,7 +80,7 @@ class SystemLogicAuth(object): @staticmethod def check_auth_status(value=None): try: - from support.base.aes import SupportAES + from support import SupportAES mykey=(codecs.encode(SystemLogicAuth.get_ip().encode(), 'hex').decode() + codecs.encode(ModelSetting.get('auth_apikey').encode(), 'hex').decode()).zfill(32)[:32].encode() logger.debug(mykey) tmp = SupportAES.decrypt(value, mykey=mykey) diff --git a/lib/system/logic_env.py b/lib/system/logic_env.py index 27bd71a..16877a6 100644 --- a/lib/system/logic_env.py +++ b/lib/system/logic_env.py @@ -1,30 +1,31 @@ # -*- coding: utf-8 -*- ######################################################### # python -import os -import traceback import logging +import os import platform -import time import threading +import time +import traceback # third-party -from flask import Blueprint, request, Response, send_file, render_template, redirect, jsonify +from flask import (Blueprint, Response, jsonify, redirect, render_template, + request, send_file) +from framework import F, app, celery, path_app_root, path_data +from .model import ModelSetting +# 패키지 +from .plugin import logger, package_name # sjva 공용 -from framework import F, path_app_root, path_data, celery, app -# 패키지 -from .plugin import logger, package_name -from .model import ModelSetting class SystemLogicEnv(object): @staticmethod def load_export(): try: - from support.base.file import SupportFile + from support import SupportFile f = os.path.join(path_app_root, 'export.sh') if os.path.exists(f): return SupportFile.read_file(f) @@ -89,7 +90,7 @@ class SystemLogicEnv(object): def celery_test(): if F.config['use_celery']: from celery import Celery - from celery.exceptions import TimeoutError, NotRegistered + from celery.exceptions import NotRegistered, TimeoutError data = {} try: @@ -126,4 +127,4 @@ class SystemLogicEnv(object): return data except Exception as exception: logger.error('Exception:%s', exception) - logger.error(traceback.format_exc()) \ No newline at end of file + logger.error(traceback.format_exc()) diff --git a/lib/system/logic_plugin.py b/lib/system/logic_plugin.py index 664f2a6..d0f1231 100644 --- a/lib/system/logic_plugin.py +++ b/lib/system/logic_plugin.py @@ -14,7 +14,7 @@ import requests # sjva 공용 from framework import app, frame, logger, path_data from framework.util import Util -from support.base.process import SupportProcess +from support import SupportProcess import system diff --git a/lib/system/mod_home.py b/lib/system/mod_home.py index c8d77fb..496eead 100644 --- a/lib/system/mod_home.py +++ b/lib/system/mod_home.py @@ -1,6 +1,6 @@ import platform -from support.base.util import SupportUtil +from support import SupportUtil from .setup import * diff --git a/lib/system/mod_plugin.py b/lib/system/mod_plugin.py new file mode 100644 index 0000000..42a331e --- /dev/null +++ b/lib/system/mod_plugin.py @@ -0,0 +1,42 @@ +from support import SupportFile + +from .setup import * + +name = 'plugin' + +class ModulePlugin(PluginModuleBase): + db_default = { + 'plugin_dev_path': os.path.join(F.config['path_data'], 'dev'), + } + + def __init__(self, P): + super(ModulePlugin, self).__init__(P, name=name, first_menu='list') + + + def process_menu(self, page, req): + arg = P.ModelSetting.to_dict() + try: + 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 == 'plugin_install': + ret = F.PluginManager.plugin_install(arg1) + + return jsonify(ret) + + + def plugin_load(self): + try: + pass + except Exception as e: + P.logger.error(f'Exception:{str(e)}') + P.logger.error(traceback.format_exc()) + + + \ No newline at end of file diff --git a/lib/system/mod_setting.py b/lib/system/mod_setting.py index f15aa3f..18bbd8c 100644 --- a/lib/system/mod_setting.py +++ b/lib/system/mod_setting.py @@ -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) - diff --git a/lib/system/plugin.py b/lib/system/plugin.py index 8f872fd..5c6db16 100644 --- a/lib/system/plugin.py +++ b/lib/system/plugin.py @@ -1,21 +1,23 @@ # -*- coding: utf-8 -*- ######################################################### # python -import os, platform -import traceback +import json import logging +import os +import platform import threading import time -import json +import traceback # third-party import requests -from flask import Blueprint, request, Response, send_file, render_template, redirect, jsonify, stream_with_context - -# sjva 공용 -from framework import frame, app, scheduler, socketio, check_api, path_app_root, path_data, get_logger#, celery -from support.base.util import SingletonClass +from flask import (Blueprint, Response, jsonify, redirect, render_template, + request, send_file, stream_with_context) from flask_login import login_required +# sjva 공용 +from framework import (app, check_api, frame, get_logger, # , celery + path_app_root, path_data, scheduler, socketio) +from support import SingletonClass # 로그 package_name = __name__.split('.')[0] @@ -23,19 +25,19 @@ logger = get_logger(__package__) # 패키지 from .logic import SystemLogic -from .model import ModelSetting -from .logic_plugin import LogicPlugin -from .logic_selenium import SystemLogicSelenium +from .logic_auth import SystemLogicAuth from .logic_command import SystemLogicCommand from .logic_command2 import SystemLogicCommand2 -from .logic_notify import SystemLogicNotify -from .logic_telegram_bot import SystemLogicTelegramBot -from .logic_auth import SystemLogicAuth -from .logic_tool_crypt import SystemLogicToolDecrypt -from .logic_terminal import SystemLogicTerminal # celery 때문에 import from .logic_env import SystemLogicEnv +from .logic_notify import SystemLogicNotify +from .logic_plugin import LogicPlugin +from .logic_selenium import SystemLogicSelenium from .logic_site import SystemLogicSite +from .logic_telegram_bot import SystemLogicTelegramBot +from .logic_terminal import SystemLogicTerminal +from .logic_tool_crypt import SystemLogicToolDecrypt +from .model import ModelSetting ######################################################### diff --git a/lib/system/setup.py b/lib/system/setup.py index 0d94bc3..927f3ca 100644 --- a/lib/system/setup.py +++ b/lib/system/setup.py @@ -16,7 +16,15 @@ __menu = { ], }, - {'uri': 'plugin', 'name': '플러그인'}, + { + 'uri': 'plugin', + 'name': '플러그인', + 'list': [ + {'uri': 'setting', 'name': '개발 설정'}, + {'uri': 'list', 'name': '플러그인 목록'}, + ], + }, + { 'uri': 'tool', 'name': '시스템 툴', @@ -25,6 +33,7 @@ __menu = { {'uri': 'python', 'name': 'Python'}, {'uri': 'db', 'name': 'DB'}, {'uri': 'crypt', 'name': '암호화'}, + {'uri': 'upload', 'name': '업로드'}, ] }, { @@ -64,10 +73,11 @@ try: SystemModelSetting = P.ModelSetting from .mod_home import ModuleHome + from .mod_plugin import ModulePlugin from .mod_route import ModuleRoute from .mod_setting import ModuleSetting - P.set_module_list([ModuleSetting, ModuleHome, ModuleRoute]) + P.set_module_list([ModuleSetting, ModuleHome, ModuleRoute, ModulePlugin]) except Exception as e: P.logger.error(f'Exception:{str(e)}') diff --git a/lib/system/templates/system_plugin.html b/lib/system/templates/system_plugin_list.html similarity index 100% rename from lib/system/templates/system_plugin.html rename to lib/system/templates/system_plugin_list.html diff --git a/lib/system/templates/system_plugin_setting.html b/lib/system/templates/system_plugin_setting.html new file mode 100644 index 0000000..2838e82 --- /dev/null +++ b/lib/system/templates/system_plugin_setting.html @@ -0,0 +1,30 @@ +{% extends "base.html" %} +{% block content %} + +