Skip to content

Commit

Permalink
Merge pull request #391 from midoks/dev
Browse files Browse the repository at this point in the history
0.13.2
  • Loading branch information
midoks authored Mar 8, 2023
2 parents 704b256 + a6dc15f commit d6c6ae5
Show file tree
Hide file tree
Showing 29 changed files with 1,411 additions and 114 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ data/system.db-journal
data/hook_*.json
data/letsencrypt.json
data/basic_auth.json
data/notify.json
data/api.json
data/bind_domain.pl
data/unauthorized_status.pl

plugins/vip_*
plugins/own_*
Expand All @@ -176,4 +178,5 @@ plugins/file_search
debug.out


data/unauthorized_status.pl


16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443:
```


### 版本更新 0.13.1

* 关闭issue,建立bbs.midoks.me。问题集中处理,发挥群众的力量。
* 添加站操作回调钩子site_cb。 网站统计和OP防火墙不再手动重载配置
* 修复ubuntu20 pureftp 安装时,端口没有加入安全里
* 增加global_static hook关键字,并优化menu的文件加载hook
* 各种细节优化。
### 版本更新 0.13.2

* supervisor添加重启功能。
* 加入滚动写入日志 mw.writeFileLog方法。
* mysql导出优化优化。
* 添加tgbot插件[仅测试]
* TelegramBot机器人通知-加入配置。
* mariadb更新版本。
* 在线文件编辑优化。

### JSDelivr安装地址

Expand Down
66 changes: 65 additions & 1 deletion class/core/config_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class config_api:

__version = '0.13.1'
__version = '0.13.2'
__api_addr = 'data/api.json'

def __init__(self):
Expand Down Expand Up @@ -661,6 +661,60 @@ def setStatusCodeApi(self):
mw.writeLog('面板设置', '将未授权响应状态码设置为:{}'.format(status_code))
return mw.returnJson(True, '设置成功!')

def getNotifyApi(self):
# 获取
data = mw.getNotifyData(True)
return mw.returnData(True, 'ok', data)

def setNotifyApi(self):
tag = request.form.get('tag', '').strip()
data = request.form.get('data', '').strip()

cfg = mw.getNotifyData(False)

crypt_data = mw.enDoubleCrypt(tag, data)
if tag in cfg:
cfg[tag]['cfg'] = crypt_data
else:
t = {'cfg': crypt_data}
cfg[tag] = t

mw.writeNotify(cfg)
return mw.returnData(True, '设置成功')

def setNotifyTestApi(self):
# 异步通知验证
tag = request.form.get('tag', '').strip()
tag_data = request.form.get('data', '').strip()

if tag == 'tgbot':
t = json.loads(tag_data)
test_bool = mw.tgbotNotifyTest(t['app_token'], t['chat_id'])
if test_bool:
return mw.returnData(True, '验证成功')
return mw.returnData(False, '验证失败')

return mw.returnData(False, '暂时未支持该验证')

def setNotifyEnableApi(self):
# 异步通知验证
tag = request.form.get('tag', '').strip()
tag_enable = request.form.get('enable', '').strip()

data = mw.getNotifyData(False)
op_enable = True
op_action = '开启'
if tag_enable != 'true':
op_enable = False
op_action = '关闭'

if tag in data:
data[tag]['enable'] = op_enable

mw.writeNotify(data)

return mw.returnData(True, op_action + '成功')

def getPanelTokenApi(self):
api_file = self.__api_addr
tmp = mw.readFile(api_file)
Expand Down Expand Up @@ -853,4 +907,14 @@ def get(self):
else:
data['hook_global_static'] = []

# notiy config
notify_data = mw.getNotifyData(True)
notify_tag_list = ['tgbot', 'email']
for tag in notify_tag_list:
new_tag = 'notify_' + tag + '_enable'
data[new_tag] = ''
if tag in notify_data and 'enable' in notify_data[tag]:
if notify_data[tag]['enable']:
data[new_tag] = 'checked'

return data
159 changes: 153 additions & 6 deletions class/core/mw.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def getPanelDataDir():
return getRunDir() + '/data'


def getPanelTmp():
return getRunDir() + '/tmp'


def getServerDir():
return getRootDir() + '/server'

Expand Down Expand Up @@ -538,6 +542,14 @@ def getDate():
return time.strftime('%Y-%m-%d %X', time.localtime())


def getDateFromNow(tf_format="%Y-%m-%d %H:%M:%S", time_zone="Asia/Shanghai"):
# 取格式时间
import time
os.environ['TZ'] = time_zone
time.tzset()
return time.strftime(tf_format, time.localtime())


def getDataFromInt(val):
time_format = '%Y-%m-%d %H:%M:%S'
time_str = time.localtime(val)
Expand All @@ -553,7 +565,7 @@ def writeLog(stype, msg, args=()):
uid = session['uid']
except Exception as e:
pass
# print(getTracebackInfo())
# writeFileLog(getTracebackInfo())
return writeDbLog(stype, msg, args, uid)


Expand Down Expand Up @@ -704,7 +716,7 @@ def enCrypt(key, strings):
result = f.encrypt(strings)
return result.decode('utf-8')
except:
print(getTracebackInfo())
writeFileLog(getTracebackInfo())
return strings


Expand All @@ -723,7 +735,7 @@ def deCrypt(key, strings):
result = f.decrypt(strings).decode('utf-8')
return result
except:
print(getTracebackInfo())
writeFileLog(getTracebackInfo())
return strings


Expand All @@ -742,7 +754,7 @@ def enDoubleCrypt(key, strings):
result = f.encrypt(strings)
return result.decode('utf-8')
except:
print(getTracebackInfo())
writeFileLog(getTracebackInfo())
return strings


Expand All @@ -760,7 +772,7 @@ def deDoubleCrypt(key, strings):
result = f.decrypt(strings).decode('utf-8')
return result
except:
print(getTracebackInfo())
writeFileLog(getTracebackInfo())
return strings


Expand Down Expand Up @@ -1564,7 +1576,7 @@ def getCertName(certPath):
result['notAfter'], "%Y-%m-%d")) - time.time()) / 86400)
return result
except Exception as e:
# print(getTracebackInfo())
writeFileLog(getTracebackInfo())
return None


Expand Down Expand Up @@ -1662,6 +1674,141 @@ def getMyORMDb():
o = ormDb.ORM()
return o

##################### notify start #########################################


def initNotifyConfig():
p = getNotifyPath()
if not os.path.exists(p):
writeFile(p, '{}')
return True


def getNotifyPath():
path = 'data/notify.json'
return path


def getNotifyData(is_parse=False):
initNotifyConfig()
notify_file = getNotifyPath()
notify_data = readFile(notify_file)

data = json.loads(notify_data)

if is_parse:
tag_list = ['tgbot']
for t in tag_list:
if t in data and 'cfg' in data[t]:
data[t]['data'] = json.loads(deDoubleCrypt(t, data[t]['cfg']))
return data


def writeNotify(data):
p = getNotifyPath()
return writeFile(p, json.dumps(data))


def tgbotNotifyChatID():
data = getNotifyData(True)
if 'tgbot' in data and 'enable' in data['tgbot']:
if data['tgbot']['enable']:
t = data['tgbot']['data']
return t['chat_id']
return ''


def tgbotNotifyObject():
data = getNotifyData(True)
if 'tgbot' in data and 'enable' in data['tgbot']:
if data['tgbot']['enable']:
t = data['tgbot']['data']
import telebot
bot = telebot.TeleBot(app_token)
return True, bot
return False, None


def tgbotNotifyMessage(app_token, chat_id, msg):
import telebot
bot = telebot.TeleBot(app_token)
try:
data = bot.send_message(chat_id, msg)
return True
except Exception as e:
writeFileLog(str(e))
return False


def tgbotNotifyHttpPost(app_token, chat_id, msg):
try:
url = 'https://api.telegram.org/bot' + app_token + '/sendMessage'
post_data = {
'chat_id': chat_id,
'text': msg,
}
rdata = httpPost(url, post_data)
return True
except Exception as e:
writeFileLog(str(e))
return False


def tgbotNotifyTest(app_token, chat_id):
msg = 'MW-通知验证测试OK'
return tgbotNotifyHttpPost(app_token, chat_id, msg)


def notifyMessageTry(msg, stype='common', trigger_time=300, is_write_log=True):

lock_file = getPanelTmp() + '/notify_lock.json'
if not os.path.exists(lock_file):
writeFile(lock_file, '{}')

lock_data = json.loads(readFile(lock_file))
if stype in lock_data:
diff_time = time.time() - lock_data[stype]['do_time']
if diff_time >= trigger_time:
lock_data[stype]['do_time'] = time.time()
else:
return False
else:
lock_data[stype] = {'do_time': time.time()}

writeFile(lock_file, json.dumps(lock_data))

if is_write_log:
writeLog("通知管理[" + stype + "]", msg)

data = getNotifyData(True)
# tag_list = ['tgbot', 'email']
# tagbot
do_notify = False
if 'tgbot' in data and 'enable' in data['tgbot']:
if data['tgbot']['enable']:
t = data['tgbot']['data']
i = sys.version_info

# telebot 在python小于3.7无法使用
if i[0] < 3 or i[1] < 7:
do_notify = tgbotNotifyHttpPost(
t['app_token'], t['chat_id'], msg)
else:
do_notify = tgbotNotifyMessage(
t['app_token'], t['chat_id'], msg)
return do_notify


def notifyMessage(msg, stype='common', trigger_time=300, is_write_log=True):
try:
return notifyMessageTry(msg, stype, trigger_time, is_write_log)
except Exception as e:
writeFileLog(getTracebackInfo())
return False


##################### notify end #########################################


##################### ssh start #########################################
def getSshDir():
Expand Down
2 changes: 1 addition & 1 deletion plugins/mariadb/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"uninstall_pre_inspection":true,
"checks": "server/mariadb",
"path": "server/mariadb",
"versions":["10.6","10.7","10.8","10.9"],
"versions":["10.6","10.7","10.8","10.9","10.11","11.0"],
"shell":"install.sh",
"checks":"server/mariadb",
"path":"server/mariadb",
Expand Down
Loading

0 comments on commit d6c6ae5

Please sign in to comment.