pull/628/head
Mr Chen 7 months ago
parent 37ace1226b
commit 81de116417
  1. 9
      class/core/mw.py
  2. 67
      web/core/mw.py
  3. 72
      web/utils/mwplugin.py

@ -716,11 +716,9 @@ def enPunycode(domain):
newdomain += dkey + '.' newdomain += dkey + '.'
else: else:
if sys.version_info[0] == 2: if sys.version_info[0] == 2:
newdomain += 'xn--' + \ newdomain += 'xn--' + dkey.decode('utf-8').encode('punycode') + '.'
dkey.decode('utf-8').encode('punycode') + '.'
else: else:
newdomain += 'xn--' + \ newdomain += 'xn--' + dkey.encode('punycode').decode('utf-8') + '.'
dkey.encode('punycode').decode('utf-8') + '.'
if tmp[0] == '*': if tmp[0] == '*':
newdomain = "*." + newdomain newdomain = "*." + newdomain
return newdomain[0:-1] return newdomain[0:-1]
@ -732,8 +730,7 @@ def dePunycode(domain):
newdomain = '' newdomain = ''
for dkey in tmp: for dkey in tmp:
if dkey.find('xn--') >= 0: if dkey.find('xn--') >= 0:
newdomain += dkey.replace('xn--', newdomain += dkey.replace('xn--','').encode('utf-8').decode('punycode') + '.'
'').encode('utf-8').decode('punycode') + '.'
else: else:
newdomain += dkey + '.' newdomain += dkey + '.'
return newdomain[0:-1] return newdomain[0:-1]

@ -61,12 +61,75 @@ def execShell(cmdstring, cwd=None, timeout=None, shell=True):
def getTracebackInfo(): def getTracebackInfo():
import traceback import traceback
errorMsg = traceback.format_exc() return traceback.format_exc()
return errorMsg
def getRunDir(): def getRunDir():
return os.getcwd() return os.getcwd()
def getRootDir():
return os.path.dirname(getRunDir())
def getPluginDir():
return getRootDir() + '/plugins'
def getPanelDataDir():
return getRootDir() + '/data'
def getMWLogs():
return getRootDir() + '/logs'
def getPanelTmp():
return getRootDir() + '/tmp'
def getServerDir():
return getRunDir() + '/server'
def getLogsDir():
return getRunDir() + '/wwwlogs'
def getRandomString(length):
# 取随机字符串
rnd_str = ''
chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
chrlen = len(chars) - 1
random = Random()
for i in range(length):
rnd_str += chars[random.randint(0, chrlen)]
return rnd_str
def getUniqueId():
"""
根据时间生成唯一ID
:return:
"""
current_time = datetime.datetime.now()
str_time = current_time.strftime('%Y%m%d%H%M%S%f')[:-3]
unique_id = "{0}".format(str_time)
return unique_id
def readFile(filename):
# 读文件内容
try:
fp = open(filename, 'r')
fBody = fp.read()
fp.close()
return fBody
except Exception as e:
# print(e)
return False
def writeFile(filename, content, mode='w+'):
# 写文件内容
try:
fp = open(filename, mode)
fp.write(content)
fp.close()
return True
except Exception as e:
return False
def dbSqitePrefix(): def dbSqitePrefix():
WIN = sys.platform.startswith('win') WIN = sys.platform.startswith('win')
if WIN: # 如果是 Windows 系统,使用三个斜线 if WIN: # 如果是 Windows 系统,使用三个斜线

@ -8,7 +8,10 @@
# Author: midoks <midoks@163.com> # Author: midoks <midoks@163.com>
# --------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------
import os
import threading import threading
import json
import core.mw as mw
class MwPlugin(object): class MwPlugin(object):
@ -55,12 +58,14 @@ class MwPlugin(object):
} }
] ]
__plugin_dir = 'plugins'
# lock # lock
_instance_lock = threading.Lock() _instance_lock = threading.Lock()
"""docstring for MwPlugin""" """插件类初始化"""
def __init__(self): def __init__(self):
pass self.__plugin_dir = mw.getPluginDir()
@classmethod @classmethod
def instance(cls, *args, **kwargs): def instance(cls, *args, **kwargs):
@ -70,6 +75,66 @@ class MwPlugin(object):
MwPlugin._instance = MwPlugin(*args, **kwargs) MwPlugin._instance = MwPlugin(*args, **kwargs)
return MwPlugin._instance return MwPlugin._instance
# 插件搜索匹配
def searchKey(self, info, keyword):
try:
if info['title'].lower().find(keyword) > -1:
return True
if info['ps'].lower().find(keyword) > -1:
return True
if info['name'].lower().find(keyword) > -1:
return True
except Exception as e:
return False
# 对多版本共存进行处理
def makeCoexistList(self):
plugins_info = []
return plugins_info
def getPluginInfo(self, name,
keyword: str | None = None,
type: str | None = None,
):
info = []
path = self.__plugin_dir + '/' + name
info_path = path + '/info.json'
if not os.path.exists(info_path):
return info
try:
data = json.loads(mw.readFile(info_path))
except Exception as e:
return info
# 判断是否搜索
if keyword != '' and not self.searchKey(data, keyword):
return info
tmp_plugin_info = self.makeCoexistList(data, type)
print(tmp_plugin_info)
return info
def getAllPluginList(
self,
type: str | None = None,
keyword: str | None = None,
page: str | None = 1,
size: str | None = 10,
):
plugins_info = []
# print(mw.getPluginDir())
for name in os.listdir(self.__plugin_dir):
if name.startswith('.'):
continue
plugin_list = self.getPluginInfo(name,keyword,type=type)
# print(dirinfo)
return plugins_info
def getList( def getList(
self, self,
@ -81,6 +146,9 @@ class MwPlugin(object):
rdata = {} rdata = {}
rdata['type'] = self.def_plugin_type rdata['type'] = self.def_plugin_type
# print(type,keyword,page,size) # print(type,keyword,page,size)
self.getAllPluginList(type,keyword, page, size)
return rdata return rdata

Loading…
Cancel
Save