mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-18 23:45:52 +08:00
update
This commit is contained in:
+3
-6
@@ -716,11 +716,9 @@ def enPunycode(domain):
|
||||
newdomain += dkey + '.'
|
||||
else:
|
||||
if sys.version_info[0] == 2:
|
||||
newdomain += 'xn--' + \
|
||||
dkey.decode('utf-8').encode('punycode') + '.'
|
||||
newdomain += 'xn--' + dkey.decode('utf-8').encode('punycode') + '.'
|
||||
else:
|
||||
newdomain += 'xn--' + \
|
||||
dkey.encode('punycode').decode('utf-8') + '.'
|
||||
newdomain += 'xn--' + dkey.encode('punycode').decode('utf-8') + '.'
|
||||
if tmp[0] == '*':
|
||||
newdomain = "*." + newdomain
|
||||
return newdomain[0:-1]
|
||||
@@ -732,8 +730,7 @@ def dePunycode(domain):
|
||||
newdomain = ''
|
||||
for dkey in tmp:
|
||||
if dkey.find('xn--') >= 0:
|
||||
newdomain += dkey.replace('xn--',
|
||||
'').encode('utf-8').decode('punycode') + '.'
|
||||
newdomain += dkey.replace('xn--','').encode('utf-8').decode('punycode') + '.'
|
||||
else:
|
||||
newdomain += dkey + '.'
|
||||
return newdomain[0:-1]
|
||||
|
||||
+65
-2
@@ -61,12 +61,75 @@ def execShell(cmdstring, cwd=None, timeout=None, shell=True):
|
||||
|
||||
def getTracebackInfo():
|
||||
import traceback
|
||||
errorMsg = traceback.format_exc()
|
||||
return errorMsg
|
||||
return traceback.format_exc()
|
||||
|
||||
def getRunDir():
|
||||
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():
|
||||
WIN = sys.platform.startswith('win')
|
||||
if WIN: # 如果是 Windows 系统,使用三个斜线
|
||||
|
||||
+70
-2
@@ -8,7 +8,10 @@
|
||||
# Author: midoks <midoks@163.com>
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
import os
|
||||
import threading
|
||||
import json
|
||||
import core.mw as mw
|
||||
|
||||
class MwPlugin(object):
|
||||
|
||||
@@ -55,12 +58,14 @@ class MwPlugin(object):
|
||||
}
|
||||
]
|
||||
|
||||
__plugin_dir = 'plugins'
|
||||
|
||||
# lock
|
||||
_instance_lock = threading.Lock()
|
||||
|
||||
"""docstring for MwPlugin"""
|
||||
"""插件类初始化"""
|
||||
def __init__(self):
|
||||
pass
|
||||
self.__plugin_dir = mw.getPluginDir()
|
||||
|
||||
@classmethod
|
||||
def instance(cls, *args, **kwargs):
|
||||
@@ -70,6 +75,66 @@ class MwPlugin(object):
|
||||
MwPlugin._instance = MwPlugin(*args, **kwargs)
|
||||
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(
|
||||
self,
|
||||
@@ -81,6 +146,9 @@ class MwPlugin(object):
|
||||
rdata = {}
|
||||
rdata['type'] = self.def_plugin_type
|
||||
# print(type,keyword,page,size)
|
||||
|
||||
self.getAllPluginList(type,keyword, page, size)
|
||||
|
||||
return rdata
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user