Skip to content

Commit

Permalink
Merge pull request #389 from midoks/dev
Browse files Browse the repository at this point in the history
OP防火墙优化
  • Loading branch information
midoks authored Mar 5, 2023
2 parents 04e43e0 + c696742 commit d38e9f7
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 9 deletions.
31 changes: 31 additions & 0 deletions class/core/mw.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import shlex
import datetime
import subprocess
import glob

import re
import db
from random import Random
Expand Down Expand Up @@ -555,6 +557,35 @@ def writeLog(stype, msg, args=()):
return writeDbLog(stype, msg, args, uid)


def writeFileLog(msg, path=None, limit_size=50 * 1024 * 1024, save_limit=3):
log_file = getServerDir() + '/mdserver-web/logs/debug.log'
if path != None:
log_file = path

if os.path.exists(log_file):
size = os.path.getsize(log_file)
if size > limit_size:
log_file_rename = log_file + "_" + \
time.strftime("%Y-%m-%d_%H%M%S") + '.log'
os.rename(log_file, log_file_rename)
logs = sorted(glob.glob(log_file + "_*"))
count = len(logs)
save_limit = count - save_limit
for i in range(count):
if i > save_limit:
break
os.remove(logs[i])
# print('|---多余日志[' + logs[i] + ']已删除!')

f = open(log_file, 'ab+')
msg += "\n"
if __name__ == '__main__':
print(msg)
f.write(msg.encode('utf-8'))
f.close()
return True


def writeDbLog(stype, msg, args=(), uid=1):
try:
import time
Expand Down
3 changes: 2 additions & 1 deletion plugins/mysql-apt/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,8 @@ def doFullSyncUser(version=''):

if not os.path.exists(bak_file):
dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
port + " -u" + user + " -p" + apass + " " + sync_db + " > " + bak_file
port + " -u" + user + " -p" + apass + \
" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
mw.execShell(dump_sql_data)

writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
Expand Down
3 changes: 2 additions & 1 deletion plugins/mysql-yum/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,8 @@ def doFullSyncUser(version=''):

if not os.path.exists(bak_file):
dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
port + " -u" + user + " -p" + apass + " " + sync_db + " > " + bak_file
port + " -u" + user + " -p" + apass + \
" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
mw.execShell(dump_sql_data)

writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
Expand Down
2 changes: 1 addition & 1 deletion plugins/mysql/conf/my8.0.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ log_replica_updates = 1
# Prevent replication from starting automatically with MySQL
#skip_replica_start = 1
#replicate-do-db
slave_skip_errors=1062
replica_skip_errors=1062
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = mysql
Expand Down
6 changes: 4 additions & 2 deletions plugins/mysql/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2665,8 +2665,10 @@ def doFullSyncUser(version=''):
writeDbSyncStatus({'code': 1, 'msg': '远程导出数据...', 'progress': 20})

if not os.path.exists(bak_file):
dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
port + " -u" + user + " -p\"" + apass + "\" " + sync_db + " > " + bak_file
dump_sql_data = getServerDir() + "/bin/mysqldump " + dmp_option + " --force --opt --default-character-set=utf8 --single-transaction -h" + ip + " -P" + \
port + " -u" + user + " -p\"" + apass + \
"\" --ssl-mode=DISABLED " + sync_db + " > " + bak_file
# print(dump_sql_data)
mw.execShell(dump_sql_data)

writeDbSyncStatus({'code': 2, 'msg': '本地导入数据...', 'progress': 40})
Expand Down
11 changes: 10 additions & 1 deletion plugins/op_waf/waf/lua/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,22 @@ local function waf_cc_increase()
local make_uri = "/"..make_uri_str

if params['uri_request_args']['token'] then
ngx.header.content_type = "application/json"
local args_token = params['uri_request_args']['token']
if args_token == make_token then
ngx.shared.waf_limit:set(cache_token, 1, config['safe_verify']['time'])
ngx.shared.waf_limit:set(cache_token, 1, tonumber(config['safe_verify']['time']))
local data = get_return_state(0, "ok")
ngx.say(json.encode(data))
ngx.exit(200)
end

-- C:D("debug[args]:"..tostring(params['uri_request_args']['debug']))
-- if params['uri_request_args']['debug'] == 'ok' then
-- ngx.header.content_type = "application/json"
-- local data = get_return_state(0, "ok")
-- ngx.say(json.encode(data))
-- ngx.exit(200)
-- end
end

local cc_html = ngx.re.gsub(cc_safe_js_html, "{uri}", make_uri_str)
Expand Down
5 changes: 3 additions & 2 deletions plugins/supervisor/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,9 @@ def restartJob():
name = args['name']
status = args['status']

action = "启动"
cmd = supCtl + " restart " + name
cmd = supCtl + " stop " + name
data = mw.execShell(cmd)
cmd = supCtl + " start " + name
data = mw.execShell(cmd)

if data[1] != '':
Expand Down
2 changes: 1 addition & 1 deletion scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ CP_CMD=/usr/bin/cp
if [ -f /bin/cp ];then
CP_CMD=/bin/cp
fi
$CP_CMD -rf /tmp/mdserver-web-dev/* /www/server/mdserver-web
$CP_CMD -rf /tmp/mdserver-web-master/* /www/server/mdserver-web

rm -rf /tmp/master.zip
rm -rf /tmp/mdserver-web-master
Expand Down

0 comments on commit d38e9f7

Please sign in to comment.