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,6 +1,4 @@
VERSION="4.0.0"
from support import d
from .init_main import Framework
frame = Framework.get_instance()
@@ -14,8 +12,8 @@ socketio = frame.socketio
path_app_root = frame.path_app_root
path_data = frame.path_data
get_logger = frame.get_logger
from flask_login import login_required
from support import d
from .init_declare import User, check_api
from .scheduler import Job

View File

@@ -45,7 +45,7 @@ class CustomFormatter(logging.Formatter):
green = "\x1B[32m"
# pathname filename
#format = "[%(asctime)s|%(name)s|%(levelname)s - %(message)s (%(filename)s:%(lineno)d)"
format = '[{yellow}%(asctime)s{reset}|{color}%(levelname)s{reset}|{green}%(name)s{reset}|%(pathname)s:%(lineno)s] {color}%(message)s{reset}'
format = '[{yellow}%(asctime)s{reset}|{color}%(levelname)s{reset}|{green}%(name)s{reset} %(pathname)s:%(lineno)s] {color}%(message)s{reset}'
FORMATS = {
logging.DEBUG: format.format(color=grey, reset=reset, yellow=yellow, green=green),
@@ -86,7 +86,7 @@ class User:
return str(r)
def can_login(self, passwd_hash):
from support.base.aes import SupportAES
from support import SupportAES
tmp = SupportAES.decrypt(self.passwd_hash)
return passwd_hash == tmp

View File

@@ -56,6 +56,7 @@ class Framework:
def __initialize(self):
os.environ['FF'] = "true"
self.__config_initialize("first")
self.__make_default_dir()
@@ -155,13 +156,13 @@ class Framework:
self.logger.error('CRITICAL db.create_all()!!!')
self.logger.error(f'Exception:{str(e)}')
self.logger.error(traceback.format_exc())
self.SystemModelSetting = SystemInstance.ModelSetting
SystemInstance.plugin_load()
self.app.register_blueprint(SystemInstance.blueprint)
self.config['flag_system_loading'] = True
self.__config_initialize('member')
self.__config_initialize('system_loading_after')
self.SystemModelSetting = SystemInstance.ModelSetting
def initialize_plugin(self):
from system.setup import P as SP
@@ -222,6 +223,7 @@ class Framework:
self.__load_config()
self.__init_define()
self.config['menu_yaml_filepath'] = os.path.join(self.config['path_data'], 'db', 'menu.yaml')
self.config['notify_yaml_filepath'] = os.path.join(self.config['path_data'], 'db', 'notify.yaml')
elif mode == "flask":
self.app.secret_key = os.urandom(24)
#self.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data/db/system.db?check_same_thread=False'

View File

@@ -1,7 +1,7 @@
import os
import shutil
from support.base.yaml import SupportYaml
from support import SupportYaml
from framework import F

View File

@@ -1,7 +1,13 @@
import os
import platform
import shutil
import sys
import threading
import traceback
import zipfile
import requests
from support import SupportFile, SupportSubprocess, SupportYaml
from framework import F
@@ -139,7 +145,7 @@ class PluginManager:
#logger.error(traceback.format_exc())
#mod_plugin_info = getattr(mod, 'setup')
F.logger.warning(f'[!] PLUGIN_INFO not exist : [{plugin_name}]')
F.logger.info(f'[!] PLUGIN_INFO not exist : [{plugin_name}] - is FF')
if mod_plugin_info == None:
try:
mod = __import__(f'{plugin_name}.setup', fromlist=['setup'])
@@ -296,3 +302,96 @@ class PluginManager:
except Exception as e:
F.logger.error(f'Exception:{str(e)}')
F.logger.error(traceback.format_exc())
@classmethod
def plugin_install(cls, plugin_git, zip_url=None, zip_filename=None):
is_git = True if plugin_git != None and plugin_git != '' else False
ret = {}
try:
if is_git:
name = plugin_git.split('/')[-1]
else:
name = zip_filename.split('.')[0]
plugin_all_path = os.path.join(F.config['path_data'], 'plugins')
plugin_path = os.path.join(plugin_all_path, name)
plugin_info = None
if os.path.exists(plugin_path):
ret['ret'] = 'danger'
ret['msg'] = '이미 설치되어 있습니다.'
ret['status'] = 'already_exist'
return ret
if plugin_git and plugin_git.startswith('http'):
for tag in ['main', 'master']:
try:
info_url = plugin_git.replace('github.com', 'raw.githubusercontent.com') + f'/{tag}/info.yaml'
plugin_info = requests.get(info_url).json()
if plugin_info is not None:
break
except:
pass
if zip_filename and zip_filename != '':
zip_filepath = os.path.join(F.config['path_data'], 'tmp', zip_filename)
extract_filepath = os.path.join(F.config['path_data'], 'tmp', name)
if SupportFile.download(zip_url, zip_filepath):
with zipfile.ZipFile(zip_filepath, 'r') as zip_ref:
zip_ref.extractall(extract_filepath)
plugin_info_filepath = os.path.join(extract_filepath, 'info.yaml')
if os.path.exists(plugin_info_filepath):
plugin_info = SupportYaml.read_yaml(plugin_info_filepath)
if plugin_info == None:
plugin_info = {}
flag = True
tmp = plugin_info.get('require_os', '')
if tmp != '' and type(tmp) == type([]) and platform.system() not in tmp:
ret['ret'] = 'danger'
ret['msg'] = '설치 가능한 OS가 아닙니다.'
ret['status'] = 'not_support_os'
flag = False
tmp = plugin_info.get('require_running_type', '')
if tmp != '' and type(tmp) == type([]) and F.config['running_type'] not in tmp:
ret['ret'] = 'danger'
ret['msg'] = '설치 가능한 실행타입이 아닙니다.'
ret['status'] = 'not_support_running_type'
flag = False
if flag:
if plugin_git and plugin_git.startswith('http'):
command = ['git', '-C', plugin_all_path, 'clone', plugin_git + '.git', '--depth', '1']
log = SupportSubprocess.execute_command_return(command)
if zip_filename and zip_filename != '':
if os.path.exists(plugin_path) == False:
shutil.move(extract_filepath, plugin_path)
else:
for tmp in os.listdir(extract_filepath):
shutil.move(os.path.join(extract_filepath, tmp), plugin_path)
log = ''
# 2021-12-31
tmp = plugin_info.get('require_plugin', '')
if tmp != '' and type(tmp) == type([]) and len(tmp) > 0:
for need_plugin in plugin_info['require_plugin']:
if need_plugin['package_name'] in cls.plugin_init:
F.logger.debug(f"Dependency 설치 - 이미 설치됨 : {need_plugin['package_name']}")
continue
else:
F.logger.debug(f"Dependency 설치 : {need_plugin['package_name']}")
cls.plugin_install(need_plugin['home'], None, None)
ret['ret'] = 'success'
ret['msg'] = ['정상적으로 설치하였습니다. 재시작시 적용됩니다.', log]
ret['msg'] = '<br>'.join(log)
except Exception as e:
F.logger.error(f'Exception:{str(e)}')
F.logger.error(traceback.format_exc())
ret['ret'] = 'danger'
ret['msg'] = str(e)
return ret

View File

@@ -4,7 +4,7 @@ import time
import traceback
from flask import request
from support.base.util import SingletonClass
from support import SingletonClass
from framework import F

View File

@@ -6,7 +6,6 @@ from random import randint
from apscheduler.jobstores.base import JobLookupError
from apscheduler.triggers.cron import CronTrigger
from pytz import timezone
from support.base.util import pt
class Scheduler(object):
@@ -27,7 +26,6 @@ class Scheduler(object):
self.sched.start()
self.logger.info('SCHEDULER start..')
@pt
def first_run_check_thread_function(self):
try:
#time.sleep(60)

View File

@@ -128,7 +128,7 @@ $("body").on('click', '#globalEditBtn', function(e) {
///////////////////////////////////////
function globalSendCommand(command, arg1, arg2, arg3, modal_title, callback) {
console.log("globalSendCommand [" + command + '] [' + arg1 + '] [' + arg2 + '] [' + arg3 + '] [' + modal_title + '] [' + callback);
console.log("globalSendCommand [" + command + '] [' + arg1 + '] [' + arg2 + '] [' + arg3 + '] [' + modal_title + '] [' + callback + ']');
console.log('/' + PACKAGE_NAME + '/ajax/' + MODULE_NAME + '/command');
$.ajax({