def start(): initDreplace() path = getConf() conf = mw.readFile(path) conf = conf.replace('#include luawaf.conf;', "include luawaf.conf;") mw.writeFile(path, conf) mw.restartWeb() return 'ok'
def checkPhpinfoFile(v): if mw.isInstalledWeb(): sdir = mw.getServerDir() dfile = sdir + '/openresty/nginx/conf/php_status/phpinfo_' + v + '.conf' if not os.path.exists(dfile): tpl = getPluginDir() + '/conf/phpinfo.conf' content = mw.readFile(tpl) content = contentReplace(content, v) mw.writeFile(dfile, content) mw.restartWeb()
def start(): file_tpl = getPluginDir() + '/conf/xhprof.conf' file_run = getConf() if not os.path.exists(file_run): centent = mw.readFile(file_tpl) centent = contentReplace(centent) mw.writeFile(file_run, centent) mw.restartWeb() return 'ok'
def stop(): path = mw.getServerDir() + "/openresty/nginx/conf/waf" if os.path.exists(path): cmd = 'rm -rf ' + path mw.execShell(cmd) path = getConf() conf = mw.readFile(path) conf = conf.replace('include luawaf.conf;', "#include luawaf.conf;") mw.writeFile(path, conf) mw.restartWeb() return 'ok'
def setXhPort(): args = getArgs() if not 'port' in args: return mw.returnJson(False, 'port missing!') port = args['port'] if port == '80': return mw.returnJson(False, '80端不能使用!') file = getConf() if not os.path.exists(file): return mw.returnJson(False, '插件未启动!') content = mw.readFile(file) rep = 'listen\s*(.*);' content = re.sub(rep, "listen " + port + ';', content) mw.writeFile(file, content) mw.restartWeb() return mw.returnJson(True, '修改成功!')
def start(): file_tpl = getPluginDir() + '/conf/phpmyadmin.conf' file_run = getConf() if not os.path.exists(file_run): centent = mw.readFile(file_tpl) centent = contentReplace(centent) mw.writeFile(file_run, centent) conf_run = getServerDir() + '/phpmyadmin/config.inc.php' if not os.path.exists(conf_run): conf_tpl = getPluginDir() + '/conf/config.inc.php' centent = mw.readFile(conf_tpl) # centent = contentReplace(centent) print mw.writeFile(conf_run, centent) mw.restartWeb() return 'ok'
def setPhpVer(): args = getArgs() if not 'phpver' in args: return 'phpver missing' cacheFile = getServerDir() + '/php.pl' mw.writeFile(cacheFile, args['phpver']) file_tpl = getPluginDir() + '/conf/xhprof.conf' file_run = getConf() centent = mw.readFile(file_tpl) centent = contentReplacePHP(centent, args['phpver']) mw.writeFile(file_run, centent) mw.restartWeb() return 'ok'
def saveBody(self, path, data, encoding='utf-8'): if not os.path.exists(path): return mw.returnJson(False, '文件不存在') try: if encoding == 'ascii': encoding = 'utf-8' if sys.version_info[0] == 2: data = data.encode(encoding, errors='ignore') fp = open(path, 'w+') else: data = data.encode(encoding, errors='ignore').decode(encoding) fp = open(path, 'w+', encoding=encoding) fp.write(data) fp.close() if path.find("web_conf") > 0: mw.restartWeb() mw.writeLog('文件管理', '文件保存成功', (path, )) return mw.returnJson(True, '文件保存成功') except Exception as ex: return mw.returnJson(False, 'FILE_SAVE_ERR:' + str(ex))
def makeOpenrestyConf(): phpversions = [ '00', '52', '53', '54', '55', '56', '70', '71', '72', '73', '74', '80', '81' ] if mw.isInstalledWeb(): sdir = mw.getServerDir() d_pathinfo = sdir + '/openresty/nginx/conf/pathinfo.conf' if not os.path.exists(d_pathinfo): s_pathinfo = getPluginDir() + '/conf/pathinfo.conf' shutil.copyfile(s_pathinfo, d_pathinfo) info = getPluginDir() + '/info.json' content = mw.readFile(info) content = json.loads(content) versions = content['versions'] tpl = getPluginDir() + '/conf/enable-php.conf' tpl_content = mw.readFile(tpl) for x in phpversions: dfile = sdir + '/openresty/nginx/conf/enable-php-' + x + '.conf' if not os.path.exists(dfile): if x == '00': mw.writeFile(dfile, '') else: w_content = contentReplace(tpl_content, x) mw.writeFile(dfile, w_content) # php-fpm status for version in phpversions: dfile = sdir + '/openresty/nginx/conf/php_status/phpfpm_status_' + version + '.conf' tpl = getPluginDir() + '/conf/phpfpm_status.conf' if not os.path.exists(dfile): content = mw.readFile(tpl) content = contentReplace(content, version) mw.writeFile(dfile, content) mw.restartWeb()
def stop(): conf = getConf() if os.path.exists(conf): os.remove(conf) mw.restartWeb() return 'ok'
def restart(): mw.restartWeb() return 'ok'