def updateZipApi(self): tmp_path = mw.getRootDir() + '/temp' if not os.path.exists(tmp_path): os.makedirs(tmp_path) mw.execShell("rm -rf " + tmp_path + '/*') tmp_file = tmp_path + '/plugin_tmp.zip' from werkzeug.utils import secure_filename from flask import request f = request.files['plugin_zip'] if f.filename[-4:] != '.zip': return mw.returnJson(False, '仅支持zip文件!') f.save(tmp_file) mw.execShell('cd ' + tmp_path + ' && unzip ' + tmp_file) os.remove(tmp_file) p_info = tmp_path + '/info.json' if not os.path.exists(p_info): d_path = None for df in os.walk(tmp_path): if len(df[2]) < 3: continue if not 'info.json' in df[2]: continue if not 'install.sh' in df[2]: continue if not os.path.exists(df[0] + '/info.json'): continue d_path = df[0] if d_path: tmp_path = d_path p_info = tmp_path + '/info.json' try: data = json.loads(mw.readFile(p_info)) data['size'] = mw.getPathSize(tmp_path) if not 'author' in data: data['author'] = '未知' if not 'home' in data: data['home'] = 'https://www.bt.cn/bbs/forum-40-1.html' plugin_path = mw.getPluginDir() + data['name'] + '/info.json' data['old_version'] = '0' data['tmp_path'] = tmp_path if os.path.exists(plugin_path): try: old_info = json.loads(mw.ReadFile(plugin_path)) data['old_version'] = old_info['versions'] except: pass except: mw.execShell("rm -rf " + tmp_path) return mw.returnJson(False, '在压缩包中没有找到插件信息,请检查插件包!') protectPlist = ('openresty', 'mysql', 'php', 'csvn', 'gogs', 'pureftp') if data['name'] in protectPlist: return mw.returnJson(False, '[' + data['name'] + '],重要插件不可修改!') return mw.getJson(data)
def fileApi(self): name = request.args.get('name', '') if name.strip() == '': return '' f = request.args.get('f', '') if f.strip() == '': return '' file = mw.getPluginDir() + '/' + name + '/' + f if not os.path.exists(file): return '' c = open(file, 'rb').read() return c
def inputZipApi(self): plugin_name = request.form.get('plugin_name', '') tmp_path = request.form.get('tmp_path', '') if not os.path.exists(tmp_path): return mw.returnJson(False, '临时文件不存在,请重新上传!') plugin_path = mw.getPluginDir() + '/' + plugin_name if not os.path.exists(plugin_path): print(mw.execShell('mkdir -p ' + plugin_path)) mw.execShell("\cp -rf " + tmp_path + '/* ' + plugin_path + '/') mw.execShell('chmod -R 755 ' + plugin_path) p_info = mw.readFile(plugin_path + '/info.json') if p_info: mw.writeLog('软件管理', '安装第三方插件[%s]' % json.loads(p_info)['title']) return mw.returnJson(True, '安装成功!') mw.execShell("rm -rf " + plugin_path) return mw.returnJson(False, '安装失败!')
def getPluginDir(): return mw.getPluginDir() + '/' + getPluginName()