diff --git a/applications/common/script/admin.py b/applications/common/script/admin.py index fec84ab..b49920d 100644 --- a/applications/common/script/admin.py +++ b/applications/common/script/admin.py @@ -602,58 +602,6 @@ powerdata = [ create_time=now_time, enable=1, - ), Power( - id=60, - name='拓展插件', - type='0', - code='', - url='', - open_type='', - parent_id='0', - icon='layui-icon layui-icon-senior', - sort=2, - create_time=now_time, - enable=1, - - ), Power( - id=61, - name='插件管理', - type='1', - code='admin:plugin:main', - url='/plugin', - open_type='_iframe', - parent_id='60', - icon='layui-icon layui-icon', - sort=2, - create_time=now_time, - enable=1, - - ), Power( - id=62, - name='启禁插件', - type='2', - code='admin:plugin:enable', - url='', - open_type='', - parent_id='61', - icon='layui-icon layui-icon', - sort=1, - create_time=now_time, - enable=1, - - ), Power( - id=63, - name='删除插件', - type='2', - code='admin:plugin:remove', - url='', - open_type='', - parent_id='61', - icon='layui-icon layui-icon', - sort=2, - create_time=now_time, - enable=1, - ) ] diff --git a/applications/config.py b/applications/config.py index 6495986..d8703e2 100644 --- a/applications/config.py +++ b/applications/config.py @@ -46,8 +46,8 @@ class BaseConfig: REDIS_PORT = 6379 # mysql 配置 - MYSQL_USERNAME = "root" - MYSQL_PASSWORD = "123456" + MYSQL_USERNAME = "PearAdminFlask" + MYSQL_PASSWORD = "hcCNtYR5GFtRwMab" MYSQL_HOST = "127.0.0.1" MYSQL_PORT = 3306 MYSQL_DATABASE = "PearAdminFlask" diff --git a/applications/view/__init__.py b/applications/view/__init__.py index ef00903..6b5cf78 100644 --- a/applications/view/__init__.py +++ b/applications/view/__init__.py @@ -11,4 +11,4 @@ def init_view(app): register_rights_view(app) register_passport_views(app) register_dept_views(app) - # register_plugin_views(app) + register_plugin_views(app) diff --git a/applications/view/plugin/__init__.py b/applications/view/plugin/__init__.py index 4eb6c34..ec94ef5 100644 --- a/applications/view/plugin/__init__.py +++ b/applications/view/plugin/__init__.py @@ -18,7 +18,7 @@ def register_plugin_views(app: Flask): app.register_blueprint(plugin_bp) # 载入插件过程 # plugin_folder 配置的是插件的文件夹名 - PLUGIN_ENABLE_FOLDERS = json.loads(app.config['PLUGIN_ENABLE_FOLDERS']) + PLUGIN_ENABLE_FOLDERS = app.config['PLUGIN_ENABLE_FOLDERS'] for plugin_folder in PLUGIN_ENABLE_FOLDERS: plugin_info = {} try: @@ -39,124 +39,3 @@ def register_plugin_views(app: Flask): info += 'repr(e):\t' + repr(e) + "\n" info += 'traceback.format_exc():\n%s' + traceback.format_exc() print(info) - - -@plugin_bp.get('/') -@authorize("admin:plugin:main", log=True) -def main(): - """此处渲染管理模板""" - return render_template('admin/plugin/main.html') - - -@plugin_bp.get('/data') -@authorize("admin:plugin:main", log=True) -def data(): - """请求插件数据""" - plugin_name = escape(request.args.get("plugin_name")) - all_plugins = [] - count = 0 - for filename in os.listdir("plugins"): - try: - with open("plugins/" + filename + "/__init__.json", "r", encoding='utf-8') as f: - info = json.loads(f.read()) - - if plugin_name is None: - if info['plugin_name'].find(plugin_name) == -1: - continue - - all_plugins.append( - { - "plugin_name": info["plugin_name"], - "plugin_version": info["plugin_version"], - "plugin_description": info["plugin_description"], - "plugin_folder_name": filename, - "enable": "1" if filename in PLUGIN_ENABLE_FOLDERS else "0" - } - ) - count += 1 - except BaseException as error: - print(filename, error) - continue - return table_api(data=all_plugins, count=count) - - -@plugin_bp.put('/enable') -@authorize("admin:plugin:enable", log=True) -def enable(): - """启用插件""" - plugin_folder_name = request.get_json(force=True).get('plugin_folder_name') - if plugin_folder_name: - try: - if plugin_folder_name not in PLUGIN_ENABLE_FOLDERS: - PLUGIN_ENABLE_FOLDERS.append(plugin_folder_name) - with open(".flaskenv", "r", encoding='utf-8') as f: - flaskenv = f.read() # type: str - pos1 = flaskenv.find("PLUGIN_ENABLE_FOLDERS") - pos2 = flaskenv.find("\n", pos1) - with open(".flaskenv", "w", encoding='utf-8') as f: - if pos2 == -1: - f.write(flaskenv[:pos1] + "PLUGIN_ENABLE_FOLDERS = " + json.dumps(PLUGIN_ENABLE_FOLDERS)) - else: - f.write( - flaskenv[:pos1] + "PLUGIN_ENABLE_FOLDERS = " + json.dumps(PLUGIN_ENABLE_FOLDERS) + flaskenv[ - pos2:]) - # 启用插件事件 - try: - getattr(importlib.import_module('plugins.' + plugin_folder_name), "event_enable")() - except AttributeError: # 没有插件启用事件就不调用 - pass - except BaseException as error: - return fail_api(msg="Crash a error! Info: " + str(error)) - - except BaseException as error: - return fail_api(msg="Crash a error! Info: " + str(error)) - return success_api(msg="启用成功,要使修改生效需要重启程序。") - return fail_api(msg="数据错误") - - -@plugin_bp.put('/disable') -@authorize("admin:plugin:enable", log=True) -def disable(): - """禁用插件""" - plugin_folder_name = request.get_json(force=True).get('plugin_folder_name') - if plugin_folder_name: - try: - if plugin_folder_name in PLUGIN_ENABLE_FOLDERS: - PLUGIN_ENABLE_FOLDERS.remove(plugin_folder_name) - with open(".flaskenv", "r", encoding='utf-8') as f: - flaskenv = f.read() # type: str - pos1 = flaskenv.find("PLUGIN_ENABLE_FOLDERS") - pos2 = flaskenv.find("\n", pos1) - with open(".flaskenv", "w", encoding='utf-8') as f: - if pos2 == -1: - f.write(flaskenv[:pos1] + "PLUGIN_ENABLE_FOLDERS = " + json.dumps(PLUGIN_ENABLE_FOLDERS)) - else: - f.write( - flaskenv[:pos1] + "PLUGIN_ENABLE_FOLDERS = " + json.dumps(PLUGIN_ENABLE_FOLDERS) + flaskenv[ - pos2:]) - - # 禁用插件事件 - try: - getattr(importlib.import_module('plugins.' + plugin_folder_name), "event_disable")() - except AttributeError: # 没有插件禁用事件就不调用 - pass - except BaseException as error: - return fail_api(msg="Crash a error! Info: " + str(error)) - - except BaseException as error: - return fail_api(msg="Crash a error! Info: " + str(error)) - return success_api(msg="禁用成功,要使修改生效需要重启程序。") - return fail_api(msg="数据错误") - - -# 删除 -@plugin_bp.delete('/remove/') -@authorize("admin:mail:remove", log=True) -def delete(plugin_folder_name): - if plugin_folder_name in PLUGIN_ENABLE_FOLDERS: - return fail_api(msg="您必须先禁用插件!") - try: - shutil.rmtree(os.path.abspath("plugins/" + plugin_folder_name)) - return success_api(msg="删除成功") - except BaseException as error: - return fail_api(msg="删除失败!原因:" + str(error)) diff --git a/templates/admin/plugin/main.html b/templates/admin/plugin/main.html deleted file mode 100644 index b0e4f18..0000000 --- a/templates/admin/plugin/main.html +++ /dev/null @@ -1,288 +0,0 @@ - - - - 插件管理 - {% include 'admin/common/header.html' %} - - - -{# 查询表单 #} -
-
-
-
- -
- -
- - -
-
-
-
-{# 用户表格 #} -
-
-
-
-
-
-
- -{# 表格操作 #} - - -{# 用户修改操作 #} - - -{# 启动与禁用 #} - - -{# 用户注册时间 #} - - -{% include 'admin/common/footer.html' %} - - - \ No newline at end of file