mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-11 09:49:25 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6f7334f5e | ||
|
|
27b77f8570 | ||
|
|
3d888961bc | ||
|
|
5edc4fb713 | ||
|
|
214954b298 | ||
|
|
13b0b2752e | ||
|
|
a2918e651f | ||
|
|
55dd1d7d5a | ||
|
|
df50eceeed | ||
|
|
e1de6dd514 | ||
|
|
08328bbb86 | ||
|
|
6abc5b365b | ||
|
|
6cc1279729 | ||
|
|
aeafaa2832 | ||
|
|
e74a511763 | ||
|
|
f86159eeac | ||
|
|
8097164475 | ||
|
|
4ebb44e4c0 | ||
|
|
584f93461a | ||
|
|
e21f0a53e5 | ||
|
|
1d31a0eae0 | ||
|
|
ded33ed6b4 | ||
|
|
b703758d0e | ||
|
|
33493ac03c | ||
|
|
74e63c5bbd | ||
|
|
f2d34e5551 | ||
|
|
89c529f44c | ||
|
|
56b728601b | ||
|
|
bf1d2daeaa | ||
|
|
cac45b3732 | ||
|
|
ee498b7094 | ||
|
|
385113fe4d | ||
|
|
5dbfc5bd51 | ||
|
|
b76e0f606a | ||
|
|
047702f26d | ||
|
|
eb219caada | ||
|
|
78b2046f19 | ||
|
|
5fe85730e6 | ||
|
|
adb72ef33b | ||
|
|
d9c8a46031 | ||
|
|
24f520bdc9 | ||
|
|
7492756997 | ||
|
|
616af16635 | ||
|
|
916d39e205 | ||
|
|
017958b6b0 | ||
|
|
d403c4c4ad | ||
|
|
9f1481db07 | ||
|
|
47e0ec5fae | ||
|
|
a2377d960e | ||
|
|
60f1ce2575 | ||
|
|
0e368f7157 | ||
|
|
3cf5c5b190 | ||
|
|
4ed07beca3 | ||
|
|
cee9619883 | ||
|
|
5db4a96fc9 | ||
|
|
2e6b7bf5cd | ||
|
|
f404caa763 | ||
|
|
062a518492 | ||
|
|
0310cab3ae | ||
|
|
4a0b8df57f | ||
|
|
63e427b488 | ||
|
|
c688c692f9 | ||
|
|
c9f074b319 | ||
|
|
38b4042c5a | ||
|
|
bf32390f0e | ||
|
|
91a9be4cc0 | ||
|
|
be5f438f84 | ||
|
|
2705fd7ba2 | ||
|
|
4de7e72f0a | ||
|
|
da668c723c | ||
|
|
20624217bf | ||
|
|
2403af08c6 | ||
|
|
2350b73896 | ||
|
|
464fa9cc0f | ||
|
|
9a79f0b728 | ||
|
|
52cfff7038 | ||
|
|
8d42f8137c | ||
|
|
41fb9759a3 | ||
|
|
7d3833b2ef | ||
|
|
0badb053e0 | ||
|
|
80b9e7cbf7 | ||
|
|
94df21192f | ||
|
|
346d687368 | ||
|
|
46ec655365 | ||
|
|
e852020c38 | ||
|
|
d06e83676b | ||
|
|
7a511f8217 | ||
|
|
8c5021b9dc | ||
|
|
b7d50540ac | ||
|
|
2a95fcc59a | ||
|
|
2b04cb3947 | ||
|
|
7f0ad25342 | ||
|
|
09f7e6f5b5 | ||
|
|
17a7ffa0b4 | ||
|
|
ba6dcabd04 | ||
|
|
0ff5c170d3 | ||
|
|
b78e020993 | ||
|
|
9586eeda07 | ||
|
|
ea462aa51d | ||
|
|
aaac8b5239 | ||
|
|
2b86c375b0 | ||
|
|
600e2688f9 | ||
|
|
3537bc520f | ||
|
|
9ffdffadd6 | ||
|
|
3942f2fbf5 | ||
|
|
8ff2f217b3 | ||
|
|
480bd154c6 | ||
|
|
5eb3ed4524 | ||
|
|
50e78ae6f6 | ||
|
|
0ec9b31c2f | ||
|
|
191b54821e | ||
|
|
c2188a2c7e | ||
|
|
d23b64a92c | ||
|
|
3ae97e1c75 | ||
|
|
f0e7361436 | ||
|
|
5f85d41352 | ||
|
|
6fc8803446 | ||
|
|
b3120f3435 | ||
|
|
f9f1b1a113 | ||
|
|
2645297cee | ||
|
|
7f171f5986 | ||
|
|
c3b3e3b01c | ||
|
|
3824b394ad | ||
|
|
270660fb53 | ||
|
|
c4171a9506 | ||
|
|
222943e312 | ||
|
|
92f8a4e949 | ||
|
|
eff1f55a21 | ||
|
|
0b54da9747 | ||
|
|
0bec57937f | ||
|
|
6c64f8ee5e | ||
|
|
b65ad9de80 | ||
|
|
07be263d81 | ||
|
|
bf9cb52fec | ||
|
|
f7135a6ded | ||
|
|
7b98dde1aa | ||
|
|
b51f3fdd68 | ||
|
|
e02c52df49 | ||
|
|
730bc7171b | ||
|
|
c065eabb48 | ||
|
|
1ad1e3326d | ||
|
|
d4346a51bc | ||
|
|
8260cc5f4a | ||
|
|
021b299b7d | ||
|
|
a767e7e578 | ||
|
|
57da2aef27 | ||
|
|
5b43438cb1 | ||
|
|
7ab88a1bea | ||
|
|
31291a13c7 | ||
|
|
43d0b75d98 | ||
|
|
5490197b8a | ||
|
|
8f03574bce | ||
|
|
94487e0b3d | ||
|
|
45cc0159af | ||
|
|
504a618eb1 | ||
|
|
5e25849464 | ||
|
|
9bb59a1559 | ||
|
|
6883316efc | ||
|
|
de7ea503e5 | ||
|
|
4fcad95c79 | ||
|
|
75dc1bd70d | ||
|
|
44758e3e55 | ||
|
|
140624e62f | ||
|
|
65f90b473c | ||
|
|
0a089fcedf | ||
|
|
010624023f | ||
|
|
9399a14a92 | ||
|
|
2875b40e62 | ||
|
|
78c3686091 | ||
|
|
d7447197ec | ||
|
|
9b64ec5c6d | ||
|
|
dad51dad77 | ||
|
|
d89751f733 | ||
|
|
1dc486711b | ||
|
|
60a2f85f02 | ||
|
|
830d387ddb | ||
|
|
ae225780f9 | ||
|
|
e0a0a82d68 | ||
|
|
0b23c5f330 | ||
|
|
fb01c68f5a | ||
|
|
5755121fa5 | ||
|
|
3d1c613864 | ||
|
|
9590c4bb7d | ||
|
|
32c0bdf093 | ||
|
|
4f5424a746 | ||
|
|
81ba3bce9d | ||
|
|
22b3a1bc42 | ||
|
|
df9a34aa31 | ||
|
|
2400213533 | ||
|
|
465eb118a9 | ||
|
|
7e81aa109f | ||
|
|
b23b41c7a7 | ||
|
|
724a77ae81 | ||
|
|
3499ed74ee | ||
|
|
52997049e2 | ||
|
|
a96a36b087 | ||
|
|
5926f688a6 | ||
|
|
1b754f5c43 | ||
|
|
c4c20de520 | ||
|
|
616895785f | ||
|
|
29d6c8740a | ||
|
|
64aa9a9d01 | ||
|
|
ffbe8ba6d4 | ||
|
|
ed39c5d243 | ||
|
|
4bb2115040 | ||
|
|
6b0cf8129d | ||
|
|
ab7bbe942b | ||
|
|
a8a3fa1754 | ||
|
|
e343f33b47 | ||
|
|
f55367ab5e | ||
|
|
050bd158c1 | ||
|
|
d35a680fec | ||
|
|
4a4ddeaabe | ||
|
|
0e74b0cccf | ||
|
|
806e29577e | ||
|
|
75923f5363 | ||
|
|
834196883c | ||
|
|
341826c641 | ||
|
|
1bd1ce5b31 | ||
|
|
eef504e172 | ||
|
|
a0434ef7d6 | ||
|
|
893bbb8ea7 | ||
|
|
92e3e277cc | ||
|
|
58e48bf013 | ||
|
|
644760d5b0 | ||
|
|
d6ccd81def | ||
|
|
d32e71b2d9 | ||
|
|
ae9e56c56c | ||
|
|
d7c0285bbf | ||
|
|
5cc0957ffd | ||
|
|
1e44d64ace | ||
|
|
907851c413 | ||
|
|
0faafc654b | ||
|
|
4cdc399b77 | ||
|
|
a085e5b1ea | ||
|
|
bdbf4dddc6 | ||
|
|
5cee2f2b6d |
+2
-3
@@ -163,7 +163,6 @@ plugins/l2tp
|
||||
plugins/openlitespeed
|
||||
plugins/tamper_proof
|
||||
plugins/cryptocurrency_trade
|
||||
plugins/gdrive
|
||||
plugins/mtproxy
|
||||
plugins/zimg
|
||||
plugins/bk_demo
|
||||
@@ -177,5 +176,5 @@ debug.out
|
||||
|
||||
|
||||
|
||||
mdioks.session-journal
|
||||
*.session
|
||||
mdioks.session-journal
|
||||
*.session
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
简单的Linux面板,感谢BT.CN写出如此好的web管理软件。我一看到,就知道这是我一直想要的页面化管理方式。
|
||||
复制了后台管理界面,按照自己想要的方式写了一版。
|
||||
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
@@ -100,12 +100,14 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443:
|
||||
```
|
||||
|
||||
|
||||
### 版本更新 0.15.4
|
||||
### 版本更新 0.16.1
|
||||
|
||||
* OP防火墙-验证优化[cf缓存问题解决]。
|
||||
* OP防火墙-加入地区限制(最好卸载重装)。
|
||||
* 在aarch64架构下低于PHP70的版本[安装/扩展安装]优化。
|
||||
* Mongodb安装优化。
|
||||
* 给防盗链增加禁止空来源。
|
||||
* OpenResty安装兼容。
|
||||
* Debian10安装优化。
|
||||
* 安装时默认监控开启。
|
||||
* MySQL/MYSQL-YUM/MySQL-APT添加重置master功能。
|
||||
* 支持华为欧拉系统。
|
||||
|
||||
### JSDelivr安装地址
|
||||
|
||||
|
||||
+12
-8
@@ -1496,8 +1496,9 @@ fullchain.pem 粘贴到证书输入框
|
||||
'cert_timeout'] = int(time.time())
|
||||
|
||||
if self.__config['orders'][i]['cert_timeout'] > start_time:
|
||||
writeLog(
|
||||
"|-本次跳过域名: {},未过期!".format(self.__config['orders'][i]['domains'][0]))
|
||||
msg = "|-本次跳过域名: {},未过期!".format(
|
||||
self.__config['orders'][i]['domains'][0])
|
||||
writeLog(msg)
|
||||
continue
|
||||
|
||||
# 已删除的网站直接跳过续签
|
||||
@@ -1514,8 +1515,9 @@ fullchain.pem 粘贴到证书输入框
|
||||
break
|
||||
if not mw.M('domain').where("name=?", (domain,)).count() and not mw.M('binding').where("domain=?", domain).count():
|
||||
auth_to = None
|
||||
writeLog(
|
||||
"|-跳过被删除的域名: {}".format(self.__config['orders'][i]['domains']))
|
||||
msg = "|-跳过被删除的域名: {}".format(
|
||||
self.__config['orders'][i]['domains'])
|
||||
writeLog(msg)
|
||||
if not auth_to:
|
||||
continue
|
||||
|
||||
@@ -1526,15 +1528,17 @@ fullchain.pem 粘贴到证书输入框
|
||||
timeout = self.__config['orders'][i][
|
||||
'next_retry_time'] - int(time.time())
|
||||
if timeout > 0:
|
||||
writeLog('|-本次跳过域名:{},因第上次续签失败,还需要等待{}小时后再重试'.format(
|
||||
self.__config['orders'][i]['domains'], int(timeout / 60 / 60)))
|
||||
msg = '|-本次跳过域名:{},因第上次续签失败,还需要等待{}小时后再重试'.format(
|
||||
self.__config['orders'][i]['domains'], int(timeout / 60 / 60))
|
||||
writeLog(msg)
|
||||
continue
|
||||
|
||||
# 是否到了最大重试次数
|
||||
if 'retry_count' in self.__config['orders'][i]:
|
||||
if self.__config['orders'][i]['retry_count'] >= 5:
|
||||
writeLog('|-本次跳过域名:{},因连续5次续签失败,不再续签此证书(可尝试手动续签此证书,成功后错误次数将被重置)'.format(
|
||||
self.__config['orders'][i]['domains']))
|
||||
msg = '|-本次跳过域名:{},因连续5次续签失败,不再续签此证书(可尝试手动续签此证书,成功后错误次数将被重置)'.format(
|
||||
self.__config['orders'][i]['domains'])
|
||||
writeLog(msg)
|
||||
continue
|
||||
|
||||
# 加入到续签订单
|
||||
|
||||
@@ -32,6 +32,7 @@ from flask import redirect
|
||||
|
||||
|
||||
def init():
|
||||
initSystemControl()
|
||||
initDB()
|
||||
initDBSshPort()
|
||||
initUserInfo()
|
||||
@@ -145,10 +146,22 @@ def initInitTask():
|
||||
api.createCertCron()
|
||||
|
||||
|
||||
def initSystemControl():
|
||||
path = 'data/default.db'
|
||||
if os.path.exists(path):
|
||||
return False
|
||||
|
||||
import system_api
|
||||
sapi = system_api.system_api()
|
||||
r = sapi.setControl(1, 30)
|
||||
print(r)
|
||||
|
||||
|
||||
def initUserInfo():
|
||||
|
||||
data = mw.M('users').where('id=?', (1,)).getField('password')
|
||||
if data == '21232f297a57a5a743894a0e4a801fc3':
|
||||
|
||||
pwd = mw.getRandomString(8).lower()
|
||||
file_pw = mw.getRunDir() + '/data/default.pl'
|
||||
mw.writeFile(file_pw, pwd)
|
||||
|
||||
@@ -27,7 +27,7 @@ from flask import request
|
||||
|
||||
class config_api:
|
||||
|
||||
__version = '0.15.4'
|
||||
__version = '0.16.1'
|
||||
__api_addr = 'data/api.json'
|
||||
|
||||
def __init__(self):
|
||||
|
||||
@@ -602,20 +602,22 @@ echo "--------------------------------------------------------------------------
|
||||
|
||||
# 将Shell脚本写到文件
|
||||
def writeShell(self, config):
|
||||
u_file = '/var/spool/cron/crontabs/root'
|
||||
if not os.path.exists(u_file):
|
||||
file = '/var/spool/cron/crontabs/root'
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
file = '/etc/crontab'
|
||||
elif current_os.startswith("freebsd"):
|
||||
file = '/var/cron/tabs/root'
|
||||
|
||||
if not os.path.exists(file):
|
||||
file = '/var/spool/cron/root'
|
||||
if mw.isAppleSystem():
|
||||
file = '/etc/crontab'
|
||||
else:
|
||||
file = u_file
|
||||
|
||||
if not os.path.exists(file):
|
||||
mw.writeFile(file, '')
|
||||
conf = mw.readFile(file)
|
||||
conf += str(config) + "\n"
|
||||
if mw.writeFile(file, conf):
|
||||
if not os.path.exists(u_file):
|
||||
if not os.path.exists(file):
|
||||
mw.execShell("chmod 600 '" + file +
|
||||
"' && chown root.root " + file)
|
||||
else:
|
||||
|
||||
@@ -64,8 +64,13 @@ class files_api:
|
||||
filename = request.args.get('filename', '')
|
||||
if not os.path.exists(filename):
|
||||
return ''
|
||||
|
||||
is_attachment = True
|
||||
if filename.endswith(".svg"):
|
||||
is_attachment = False
|
||||
|
||||
response = make_response(send_from_directory(
|
||||
os.path.dirname(filename), os.path.basename(filename), as_attachment=True))
|
||||
os.path.dirname(filename), os.path.basename(filename), as_attachment=is_attachment))
|
||||
return response
|
||||
|
||||
def zipApi(self):
|
||||
@@ -708,10 +713,7 @@ class files_api:
|
||||
return not path in nDirs
|
||||
|
||||
def getDirSize(self, path):
|
||||
if mw.isAppleSystem():
|
||||
tmp = mw.execShell('du -sh ' + path)
|
||||
else:
|
||||
tmp = mw.execShell('du -sbh ' + path)
|
||||
tmp = mw.execShell('du -sh ' + path)
|
||||
return tmp
|
||||
|
||||
def checkFileName(self, filename):
|
||||
|
||||
@@ -178,12 +178,6 @@ class firewall_api:
|
||||
limit = request.form.get('limit', '10').strip()
|
||||
return self.getList(int(p), int(limit))
|
||||
|
||||
def getLogListApi(self):
|
||||
p = request.form.get('p', '1').strip()
|
||||
limit = request.form.get('limit', '10').strip()
|
||||
search = request.form.get('search', '').strip()
|
||||
return self.getLogList(int(p), int(limit), search)
|
||||
|
||||
def getSshInfoApi(self):
|
||||
data = {}
|
||||
|
||||
@@ -389,11 +383,6 @@ class firewall_api:
|
||||
|
||||
return mw.returnData(True, '设置成功!')
|
||||
|
||||
def delPanelLogsApi(self):
|
||||
mw.M('logs').where('id>?', (0,)).delete()
|
||||
mw.writeLog('面板设置', '面板操作日志已清空!')
|
||||
return mw.returnJson(True, '面板操作日志已清空!')
|
||||
|
||||
##### ----- start ----- ###
|
||||
|
||||
def getList(self, page, limit):
|
||||
@@ -414,28 +403,6 @@ class firewall_api:
|
||||
data['page'] = mw.getPage(_page)
|
||||
return mw.getJson(data)
|
||||
|
||||
def getLogList(self, page, limit, search=''):
|
||||
find_search = ''
|
||||
if search != '':
|
||||
find_search = "type like '%" + search + "%' or log like '%" + \
|
||||
search + "%' or addtime like '%" + search + "%'"
|
||||
|
||||
start = (page - 1) * limit
|
||||
|
||||
_list = mw.M('logs').where(find_search, ()).field(
|
||||
'id,type,log,addtime').limit(str(start) + ',' + str(limit)).order('id desc').select()
|
||||
data = {}
|
||||
data['data'] = _list
|
||||
|
||||
count = mw.M('logs').where(find_search, ()).count()
|
||||
_page = {}
|
||||
_page['count'] = count
|
||||
_page['tojs'] = 'getLogs'
|
||||
_page['p'] = page
|
||||
|
||||
data['page'] = mw.getPage(_page)
|
||||
return mw.getJson(data)
|
||||
|
||||
def addAcceptPort(self, port):
|
||||
if self.__isUfw:
|
||||
mw.execShell('ufw allow ' + port + '/tcp')
|
||||
|
||||
@@ -0,0 +1,352 @@
|
||||
# coding: utf-8
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# MW-Linux面板
|
||||
# ---------------------------------------------------------------------------------
|
||||
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
|
||||
# ---------------------------------------------------------------------------------
|
||||
# Author: midoks <midoks@163.com>
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# 日志类操作
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
import psutil
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
import mw
|
||||
import re
|
||||
import json
|
||||
import pwd
|
||||
|
||||
from datetime import datetime
|
||||
from flask import request
|
||||
|
||||
|
||||
class logs_api:
|
||||
|
||||
__months = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06',
|
||||
'Jul': '07', 'Aug': '08', 'Sep': '09', 'Sept': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'}
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def delPanelLogsApi(self):
|
||||
mw.M('logs').where('id>?', (0,)).delete()
|
||||
mw.writeLog('面板设置', '面板操作日志已清空!')
|
||||
return mw.returnJson(True, '面板操作日志已清空!')
|
||||
|
||||
def getLogListApi(self):
|
||||
p = request.form.get('p', '1').strip()
|
||||
limit = request.form.get('limit', '10').strip()
|
||||
search = request.form.get('search', '').strip()
|
||||
return self.getLogList(int(p), int(limit), search)
|
||||
|
||||
def getLogList(self, page, limit, search=''):
|
||||
find_search = ''
|
||||
if search != '':
|
||||
find_search = "type like '%" + search + "%' or log like '%" + \
|
||||
search + "%' or addtime like '%" + search + "%'"
|
||||
|
||||
start = (page - 1) * limit
|
||||
|
||||
_list = mw.M('logs').where(find_search, ()).field(
|
||||
'id,type,log,addtime').limit(str(start) + ',' + str(limit)).order('id desc').select()
|
||||
data = {}
|
||||
data['data'] = _list
|
||||
|
||||
count = mw.M('logs').where(find_search, ()).count()
|
||||
_page = {}
|
||||
_page['count'] = count
|
||||
_page['tojs'] = 'getLogs'
|
||||
_page['p'] = page
|
||||
|
||||
data['page'] = mw.getPage(_page)
|
||||
return mw.getJson(data)
|
||||
|
||||
def getLogsTitle(self, log_name):
|
||||
log_name = log_name.replace('.1', '')
|
||||
if log_name in ['mw-update.log']:
|
||||
return '面板更新日志'
|
||||
if log_name in ['mw-install.log']:
|
||||
return '面板安装日志'
|
||||
if log_name in ['auth.log', 'secure'] or log_name.find('auth.') == 0:
|
||||
return '授权日志'
|
||||
if log_name in ['dmesg'] or log_name.find('dmesg') == 0:
|
||||
return '内核缓冲区日志'
|
||||
if log_name in ['syslog'] or log_name.find('syslog') == 0:
|
||||
return '系统警告/错误日志'
|
||||
if log_name in ['btmp']:
|
||||
return '失败的登录记录'
|
||||
if log_name in ['utmp', 'wtmp']:
|
||||
return '登录和重启记录'
|
||||
if log_name in ['lastlog']:
|
||||
return '用户最后登录'
|
||||
if log_name in ['yum.log']:
|
||||
return 'yum包管理器日志'
|
||||
if log_name in ['anaconda.log']:
|
||||
return 'Anaconda日志'
|
||||
if log_name in ['dpkg.log']:
|
||||
return 'dpkg日志'
|
||||
if log_name in ['daemon.log']:
|
||||
return '系统后台守护进程日志'
|
||||
if log_name in ['boot.log']:
|
||||
return '启动日志'
|
||||
if log_name in ['kern.log']:
|
||||
return '内核日志'
|
||||
if log_name in ['maillog', 'mail.log']:
|
||||
return '邮件日志'
|
||||
if log_name.find('Xorg') == 0:
|
||||
return 'Xorg日志'
|
||||
if log_name in ['cron.log']:
|
||||
return '定时任务日志'
|
||||
if log_name in ['alternatives.log']:
|
||||
return '更新替代信息'
|
||||
if log_name in ['debug']:
|
||||
return '调试信息'
|
||||
if log_name.find('apt') == 0:
|
||||
return 'apt-get相关日志'
|
||||
if log_name.find('installer') == 0:
|
||||
return '系统安装相关日志'
|
||||
if log_name in ['messages']:
|
||||
return '综合日志'
|
||||
return '{}日志'.format(log_name.split('.')[0])
|
||||
|
||||
def getAuditLogsFilesApi(self):
|
||||
log_dir = '/var/log'
|
||||
log_files = []
|
||||
for log_file in os.listdir(log_dir):
|
||||
log_suffix = log_file.split('.')[-1:]
|
||||
if log_suffix[0] in ['gz', 'xz', 'bz2', 'asl']:
|
||||
continue
|
||||
|
||||
if log_file in ['.', '..', 'faillog', 'fontconfig.log', 'unattended-upgrades', 'tallylog']:
|
||||
continue
|
||||
|
||||
filename = os.path.join(log_dir, log_file)
|
||||
if os.path.isfile(filename):
|
||||
file_size = os.path.getsize(filename)
|
||||
if not file_size:
|
||||
continue
|
||||
|
||||
tmp = {
|
||||
'name': log_file,
|
||||
'size': file_size,
|
||||
'log_file': filename,
|
||||
'title': self.getLogsTitle(log_file),
|
||||
'uptime': os.path.getmtime(filename)
|
||||
}
|
||||
|
||||
log_files.append(tmp)
|
||||
else:
|
||||
for next_name in os.listdir(filename):
|
||||
if next_name[-3:] in ['.gz', '.xz']:
|
||||
continue
|
||||
next_file = os.path.join(filename, next_name)
|
||||
if not os.path.isfile(next_file):
|
||||
continue
|
||||
file_size = os.path.getsize(next_file)
|
||||
if not file_size:
|
||||
continue
|
||||
log_name = '{}/{}'.format(log_file, next_name)
|
||||
tmp = {
|
||||
'name': log_name,
|
||||
'size': file_size,
|
||||
'log_file': next_file,
|
||||
'title': self.getLogsTitle(log_name),
|
||||
'uptime': os.path.getmtime(next_file)
|
||||
}
|
||||
log_files.append(tmp)
|
||||
log_files = sorted(log_files, key=lambda x: x['name'], reverse=True)
|
||||
return mw.getJson(log_files)
|
||||
|
||||
def getAuditFileApi(self):
|
||||
log_name = request.form.get('log_name', '').strip()
|
||||
return self.getAuditLogsName(log_name)
|
||||
|
||||
def __to_date2(self, date_str):
|
||||
tmp = date_str.split()
|
||||
s_date = str(tmp[-1]) + '-' + self.__months.get(tmp[1],
|
||||
tmp[1]) + '-' + tmp[2] + ' ' + tmp[3]
|
||||
return s_date
|
||||
|
||||
def __to_date3(self, date_str):
|
||||
tmp = date_str.split()
|
||||
s_date = str(datetime.now().year) + '-' + \
|
||||
self.__months.get(tmp[1], tmp[1]) + '-' + tmp[2] + ' ' + tmp[3]
|
||||
return s_date
|
||||
|
||||
def __to_date4(self, date_str):
|
||||
tmp = date_str.split()
|
||||
s_date = str(datetime.now().year) + '-' + \
|
||||
self.__months.get(tmp[0], tmp[0]) + '-' + tmp[1] + ' ' + tmp[2]
|
||||
return s_date
|
||||
|
||||
def getAuditLast(self, log_name):
|
||||
# 获取日志
|
||||
cmd = '''LANG=en_US.UTF-8 last -n 200 -x -f {} |grep -v 127.0.0.1|grep -v " begins"'''.format(
|
||||
'/var/log/' + log_name)
|
||||
result = mw.execShell(cmd)
|
||||
lastlog_list = []
|
||||
for _line in result[0].split("\n"):
|
||||
if not _line:
|
||||
continue
|
||||
tmp = {}
|
||||
sp_arr = _line.split()
|
||||
tmp['用户'] = sp_arr[0]
|
||||
if sp_arr[0] == 'runlevel':
|
||||
tmp['来源'] = sp_arr[4]
|
||||
tmp['端口'] = ' '.join(sp_arr[1:4])
|
||||
tmp['时间'] = self.__to_date3(
|
||||
' '.join(sp_arr[5:])) + ' ' + ' '.join(sp_arr[-2:])
|
||||
elif sp_arr[0] in ['reboot', 'shutdown']:
|
||||
tmp['来源'] = sp_arr[3]
|
||||
tmp['端口'] = ' '.join(sp_arr[1:3])
|
||||
if sp_arr[-3] == '-':
|
||||
tmp['时间'] = self.__to_date3(
|
||||
' '.join(sp_arr[4:])) + ' ' + ' '.join(sp_arr[-3:])
|
||||
else:
|
||||
tmp['时间'] = self.__to_date3(
|
||||
' '.join(sp_arr[4:])) + ' ' + ' '.join(sp_arr[-2:])
|
||||
elif sp_arr[1] in ['tty1', 'tty', 'tty2', 'tty3', 'hvc0', 'hvc1', 'hvc2'] or len(sp_arr) == 9:
|
||||
tmp['来源'] = ''
|
||||
tmp['端口'] = sp_arr[1]
|
||||
tmp['时间'] = self.__to_date3(
|
||||
' '.join(sp_arr[2:])) + ' ' + ' '.join(sp_arr[-3:])
|
||||
else:
|
||||
tmp['来源'] = sp_arr[2]
|
||||
tmp['端口'] = sp_arr[1]
|
||||
tmp['时间'] = self.__to_date3(
|
||||
' '.join(sp_arr[3:])) + ' ' + ' '.join(sp_arr[-3:])
|
||||
|
||||
# tmp['_line'] = _line
|
||||
lastlog_list.append(tmp)
|
||||
# lastlog_list = sorted(lastlog_list,key=lambda x:x['时间'],reverse=True)
|
||||
return mw.returnData(True, 'ok!', lastlog_list)
|
||||
|
||||
def getAuditLastLog(self):
|
||||
cmd = '''LANG=en_US.UTF-8 lastlog|grep -v Username'''
|
||||
result = mw.execShell(cmd)
|
||||
lastlog_list = []
|
||||
for _line in result[0].split("\n"):
|
||||
if not _line:
|
||||
continue
|
||||
tmp = {}
|
||||
sp_arr = _line.split()
|
||||
tmp['用户'] = sp_arr[0]
|
||||
# tmp['_line'] = _line
|
||||
if _line.find('Never logged in') != -1:
|
||||
tmp['最后登录时间'] = '0'
|
||||
tmp['最后登录来源'] = '-'
|
||||
tmp['最后登录端口'] = '-'
|
||||
lastlog_list.append(tmp)
|
||||
continue
|
||||
tmp['最后登录来源'] = sp_arr[2]
|
||||
tmp['最后登录端口'] = sp_arr[1]
|
||||
tmp['最后登录时间'] = self.__to_date2(' '.join(sp_arr[3:]))
|
||||
|
||||
lastlog_list.append(tmp)
|
||||
lastlog_list = sorted(lastlog_list, key=lambda x: x[
|
||||
'最后登录时间'], reverse=True)
|
||||
for i in range(len(lastlog_list)):
|
||||
if lastlog_list[i]['最后登录时间'] == '0':
|
||||
lastlog_list[i]['最后登录时间'] = '从未登录过'
|
||||
return mw.returnData(True, 'ok!', lastlog_list)
|
||||
|
||||
def parseAuditFile(self, log_name, result):
|
||||
log_list = []
|
||||
is_string = True
|
||||
for _line in result.split("\n"):
|
||||
if not _line.strip():
|
||||
continue
|
||||
if log_name.find('sa/sa') == -1:
|
||||
if _line[:3] in self.__months:
|
||||
_msg = _line[16:]
|
||||
_tmp = _msg.split(": ")
|
||||
_act = ''
|
||||
if len(_tmp) > 1:
|
||||
_act = _tmp[0]
|
||||
_msg = _tmp[1]
|
||||
else:
|
||||
_msg = _tmp[0]
|
||||
_line = {
|
||||
"时间": self.__to_date4(_line[:16].strip()),
|
||||
"角色": _act,
|
||||
"事件": _msg
|
||||
}
|
||||
is_string = False
|
||||
elif _line[:2] in ['19', '20', '21', '22', '23', '24']:
|
||||
_msg = _line[19:]
|
||||
_tmp = _msg.split(" ")
|
||||
_act = _tmp[1]
|
||||
_msg = ' '.join(_tmp[2:])
|
||||
_line = {
|
||||
"时间": _line[:19].strip(),
|
||||
"角色": _act,
|
||||
"事件": _msg
|
||||
}
|
||||
is_string = False
|
||||
elif log_name.find('alternatives') == 0:
|
||||
_tmp = _line.split(": ")
|
||||
_last = _tmp[0].split(" ")
|
||||
_act = _last[0]
|
||||
_msg = ' '.join(_tmp[1:])
|
||||
_line = {
|
||||
"时间": ' '.join(_last[1:]).strip(),
|
||||
"角色": _act,
|
||||
"事件": _msg
|
||||
}
|
||||
is_string = False
|
||||
else:
|
||||
if not is_string:
|
||||
if type(_line) != dict:
|
||||
continue
|
||||
|
||||
log_list.append(_line)
|
||||
|
||||
return log_list
|
||||
|
||||
def getAuditLogsName(self, log_name):
|
||||
# print(log_name)
|
||||
if log_name in ['wtmp', 'btmp', 'utmp'] or log_name.find('wtmp') == 0 or log_name.find('btmp') == 0 or log_name.find('utmp') == 0:
|
||||
return self.getAuditLast(log_name)
|
||||
|
||||
if log_name.find('lastlog') == 0:
|
||||
return self.getAuditLastLog()
|
||||
|
||||
if log_name.find('sa/sa') == 0:
|
||||
if log_name.find('sa/sar') == -1:
|
||||
return mw.execShell("sar -f /var/log/{}".format(log_name))[0]
|
||||
log_dir = '/var/log'
|
||||
log_file = log_dir + '/' + log_name
|
||||
if not os.path.exists(log_file):
|
||||
return mw.returnData(False, '日志文件不存在!')
|
||||
result = mw.getLastLine(log_file, 100)
|
||||
try:
|
||||
log_list = self.parseAuditFile(log_name, result)
|
||||
_string = []
|
||||
_dict = []
|
||||
_list = []
|
||||
for _line in log_list:
|
||||
if isinstance(_line, str):
|
||||
_string.append(_line.strip())
|
||||
elif isinstance(_line, dict):
|
||||
_dict.append(_line)
|
||||
elif isinstance(_line, list):
|
||||
_list.append(_line)
|
||||
else:
|
||||
continue
|
||||
_str_len = len(_string)
|
||||
_dict_len = len(_dict)
|
||||
_list_len = len(_list)
|
||||
if _str_len > _dict_len + _list_len:
|
||||
return "\n".join(_string)
|
||||
elif _dict_len > _str_len + _list_len:
|
||||
return mw.returnData(True, 'ok!', _dict)
|
||||
else:
|
||||
return mw.returnData(True, 'ok!', _list)
|
||||
|
||||
except:
|
||||
return mw.returnData(True, 'ok!', result)
|
||||
+13
-6
@@ -349,7 +349,8 @@ def restartMw():
|
||||
|
||||
def checkWebConfig():
|
||||
op_dir = getServerDir() + '/openresty/nginx'
|
||||
cmd = "ulimit -n 10240 && " + op_dir + \
|
||||
# "ulimit -n 10240 && " +
|
||||
cmd = op_dir + \
|
||||
"/sbin/nginx -t -c " + op_dir + "/conf/nginx.conf"
|
||||
result = execShell(cmd)
|
||||
searchStr = 'test is successful'
|
||||
@@ -1355,6 +1356,12 @@ def getCpuType():
|
||||
cpuinfo = execShell(cmd)
|
||||
return cpuinfo[0].strip()
|
||||
|
||||
current_os = getOs()
|
||||
if current_os.startswith('freebsd'):
|
||||
cmd = "sysctl -a | egrep -i 'hw.model' | awk -F ':' '{print $2}'"
|
||||
cpuinfo = execShell(cmd)
|
||||
return cpuinfo[0].strip()
|
||||
|
||||
# 取CPU类型
|
||||
cpuinfo = open('/proc/cpuinfo', 'r').read()
|
||||
rep = "model\s+name\s+:\s+(.+)"
|
||||
@@ -1411,7 +1418,7 @@ def makeConf():
|
||||
file = getRunDir() + '/data/json/config.json'
|
||||
if not os.path.exists(file):
|
||||
c = {}
|
||||
c['title'] = '金灵面板'
|
||||
c['title'] = '老子面板'
|
||||
c['home'] = 'http://github/midoks/mdserver-web'
|
||||
c['recycle_bin'] = True
|
||||
c['template'] = 'default'
|
||||
@@ -2099,15 +2106,15 @@ done
|
||||
|
||||
|
||||
def echoStart(tag):
|
||||
print("=" * 90)
|
||||
print("=" * 89)
|
||||
print("★开始{}[{}]".format(tag, formatDate()))
|
||||
print("=" * 90)
|
||||
print("=" * 89)
|
||||
|
||||
|
||||
def echoEnd(tag):
|
||||
print("=" * 90)
|
||||
print("=" * 89)
|
||||
print("☆{}完成[{}]".format(tag, formatDate()))
|
||||
print("=" * 90)
|
||||
print("=" * 89)
|
||||
print("\n")
|
||||
|
||||
|
||||
|
||||
+36
-8
@@ -1149,8 +1149,9 @@ class site_api:
|
||||
domains = request.form.get('domains', '')
|
||||
status = request.form.get('status', '')
|
||||
name = request.form.get('name', '')
|
||||
none = request.form.get('none', '')
|
||||
sid = request.form.get('id', '')
|
||||
return self.setSecurity(sid, name, fix, domains, status)
|
||||
return self.setSecurity(sid, name, fix, domains, status, none)
|
||||
|
||||
def getLogsApi(self):
|
||||
siteName = request.form.get('siteName', '')
|
||||
@@ -2430,9 +2431,28 @@ location ^~ {from} {\n\
|
||||
tmp = re.search(rep, conf).group()
|
||||
data['fix'] = re.search(
|
||||
"\(.+\)\$", tmp).group().replace('(', '').replace(')$', '').replace('|', ',')
|
||||
data['domains'] = ','.join(re.search(
|
||||
"valid_referers\s+none\s+blocked\s+(.+);\n", tmp).groups()[0].split())
|
||||
data['status'] = True
|
||||
|
||||
data['status'] = False
|
||||
data['none'] = False
|
||||
|
||||
valid_referers = re.search(
|
||||
"valid_referers\s+(.+);\n", tmp)
|
||||
valid_referers_none = re.search(
|
||||
"valid_referers\s+none\s+blocked\s+(.+);\n", tmp)
|
||||
|
||||
if valid_referers or valid_referers_none:
|
||||
data['status'] = True
|
||||
|
||||
if valid_referers_none:
|
||||
domain_t = valid_referers_none.groups()[0].split()
|
||||
data['domains'] = ','.join(domain_t)
|
||||
data['none'] = True
|
||||
elif valid_referers:
|
||||
domain_t = valid_referers.groups()[0].split()
|
||||
data['domains'] = ','.join(domain_t)
|
||||
data['none'] = False
|
||||
|
||||
# print(data)
|
||||
else:
|
||||
data['fix'] = 'jpg,jpeg,gif,png,js,css'
|
||||
domains = mw.M('domain').where(
|
||||
@@ -2442,19 +2462,27 @@ location ^~ {from} {\n\
|
||||
tmp.append(domain['name'])
|
||||
data['domains'] = ','.join(tmp)
|
||||
data['status'] = False
|
||||
data['none'] = False
|
||||
return mw.getJson(data)
|
||||
|
||||
def setSecurity(self, sid, name, fix, domains, status):
|
||||
def setSecurity(self, sid, name, fix, domains, status, none=''):
|
||||
if len(fix) < 2:
|
||||
return mw.returnJson(False, 'URL后缀不能为空!')
|
||||
file = self.getHostConf(name)
|
||||
if os.path.exists(file):
|
||||
conf = mw.readFile(file)
|
||||
if conf.find('SECURITY-START') != -1:
|
||||
if status == 'false':
|
||||
rep = "\s{0,4}#SECURITY-START(\n|.){1,500}#SECURITY-END\n?"
|
||||
conf = re.sub(rep, '', conf)
|
||||
mw.writeLog('网站管理', '站点[' + name + ']已关闭防盗链设置!')
|
||||
else:
|
||||
rep = "\s{0,4}#SECURITY-START(\n|.){1,500}#SECURITY-END\n?"
|
||||
conf = re.sub(rep, '', conf)
|
||||
|
||||
valid_referers = domains.strip().replace(',', ' ')
|
||||
if none == 'true':
|
||||
valid_referers = 'none blocked ' + valid_referers
|
||||
|
||||
pre_path = self.setupPath + "/php/conf"
|
||||
re_path = "include\s+" + pre_path + "/enable-php-"
|
||||
rconf = '''#SECURITY-START 防盗链配置
|
||||
@@ -2462,13 +2490,13 @@ location ^~ {from} {\n\
|
||||
{
|
||||
expires 30d;
|
||||
access_log /dev/null;
|
||||
valid_referers none blocked %s;
|
||||
valid_referers %s;
|
||||
if ($invalid_referer){
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
#SECURITY-END
|
||||
include %s/enable-php-''' % (fix.strip().replace(',', '|'), domains.strip().replace(',', ' '), pre_path)
|
||||
include %s/enable-php-''' % (fix.strip().replace(',', '|'), valid_referers, pre_path)
|
||||
conf = re.sub(re_path, rconf, conf)
|
||||
mw.writeLog('网站管理', '站点[' + name + ']已开启防盗链!')
|
||||
mw.writeFile(file, conf)
|
||||
|
||||
@@ -274,26 +274,43 @@ class system_api:
|
||||
return title
|
||||
|
||||
def getSystemVersion(self):
|
||||
#
|
||||
# 取操作系统版本
|
||||
if mw.getOs() == 'darwin':
|
||||
current_os = mw.getOs()
|
||||
# mac
|
||||
if current_os == 'darwin':
|
||||
data = mw.execShell('sw_vers')[0]
|
||||
data_list = data.strip().split("\n")
|
||||
mac_version = ''
|
||||
for x in data_list:
|
||||
mac_version += x.split("\t")[1] + ' '
|
||||
return mac_version
|
||||
|
||||
arch_ver = mw.execShell("arch")
|
||||
return mac_version + " (" + arch_ver[0].strip() + ")"
|
||||
|
||||
# freebsd
|
||||
if current_os.startswith('freebsd'):
|
||||
version = mw.execShell(
|
||||
"cat /etc/*-release | grep PRETTY_NAME | awk -F = '{print $2}' | awk -F '\"' '{print $2}'")
|
||||
arch_ver = mw.execShell(
|
||||
"sysctl -a | egrep -i 'hw.machine_arch' | awk -F ':' '{print $2}'")
|
||||
return version[0].strip() + " (" + arch_ver[0].strip() + ")"
|
||||
|
||||
redhat_series = '/etc/redhat-release'
|
||||
if os.path.exists(redhat_series):
|
||||
version = mw.readFile('/etc/redhat-release')
|
||||
version = version.replace('release ', '').strip()
|
||||
return version
|
||||
|
||||
arch_ver = mw.execShell("arch")
|
||||
return version + " (" + arch_ver[0].strip() + ")"
|
||||
|
||||
os_series = '/etc/os-release'
|
||||
if os.path.exists(os_series):
|
||||
version = mw.execShell(
|
||||
"cat /etc/*-release | grep PRETTY_NAME | awk -F = '{print $2}' | awk -F '\"' '{print $2}'")
|
||||
return version[0].strip()
|
||||
|
||||
arch_ver = mw.execShell("arch")
|
||||
return version[0].strip() + " (" + arch_ver[0].strip() + ")"
|
||||
|
||||
return '未识别系统信息'
|
||||
|
||||
@@ -318,7 +335,7 @@ class system_api:
|
||||
cpuCount = psutil.cpu_count()
|
||||
cpuLogicalNum = psutil.cpu_count(logical=False)
|
||||
used = psutil.cpu_percent(interval=interval)
|
||||
|
||||
cpuLogicalNum = 0
|
||||
if os.path.exists('/proc/cpuinfo'):
|
||||
c_tmp = mw.readFile('/proc/cpuinfo')
|
||||
d_tmp = re.findall("physical id.+", c_tmp)
|
||||
|
||||
@@ -7,6 +7,10 @@ MDIR=$(dirname "$DIR")
|
||||
PATH=$PATH:$DIR/bin
|
||||
if [ -f bin/activate ];then
|
||||
source bin/activate
|
||||
|
||||
if [ "$?" != "0" ];then
|
||||
echo "load local python env fail!"
|
||||
fi
|
||||
fi
|
||||
|
||||
export LC_ALL="en_US.UTF-8"
|
||||
|
||||
@@ -14,6 +14,7 @@ if sys.platform != "darwin":
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
import db
|
||||
|
||||
_ver = sys.version_info
|
||||
is_py2 = (_ver[0] == 2)
|
||||
@@ -185,6 +186,35 @@ def backupAllFunc(stype):
|
||||
"path": "path",
|
||||
}
|
||||
|
||||
backups = []
|
||||
sql = db.Sql()
|
||||
|
||||
# print("stype:", stype)
|
||||
# 提前获取-清理多余备份
|
||||
if stype == 'site':
|
||||
pid = sql.table('sites').where('name=?', (name,)).getField('id')
|
||||
backups = sql.table('backup').where(
|
||||
'type=? and pid=?', ('0', pid)).field('id,filename').select()
|
||||
if stype == 'database':
|
||||
db_path = mw.getServerDir() + '/mysql'
|
||||
pid = mw.M('databases').dbPos(db_path, 'mysql').where(
|
||||
'name=?', (name,)).getField('id')
|
||||
backups = sql.table('backup').where(
|
||||
'type=? and pid=?', ('1', pid)).field('id,filename').select()
|
||||
if stype == 'path':
|
||||
backup_path = backup_dir + '/path'
|
||||
_name = 'path_{}'.format(os.path.basename(name))
|
||||
backups = findPathName(backup_path, _name)
|
||||
|
||||
# 其他类型关系性数据库(mysql类的)
|
||||
if stype.find('database_') > -1:
|
||||
plugin_name = stype.replace('database_', '')
|
||||
db_path = mw.getServerDir() + '/' + plugin_name
|
||||
pid = mw.M('databases').dbPos(db_path, 'mysql').where(
|
||||
'name=?', (name,)).getField('id')
|
||||
backups = sql.table('backup').where(
|
||||
'type=? and pid=?', ('1', pid)).field('id,filename').select()
|
||||
|
||||
args = stype + " " + name + " " + num
|
||||
cmd = 'python3 ' + mw.getRunDir() + '/scripts/backup.py ' + args
|
||||
if stype.find('database_') > -1:
|
||||
@@ -213,19 +243,31 @@ def backupAllFunc(stype):
|
||||
filename = mw.execShell(find_new_file)[0].strip()
|
||||
if filename == "":
|
||||
mw.echoInfo("not find upload file!")
|
||||
return False
|
||||
return ''
|
||||
|
||||
print("|-准备上传文件 {}".format(filename))
|
||||
ftp = FtpPSClient()
|
||||
ftp.uploadFile(filename, stype)
|
||||
|
||||
# print(backups)
|
||||
backups = sorted(backups, key=lambda x: x['filename'], reverse=False)
|
||||
mw.echoStart('开始删除远程备份')
|
||||
num = int(num)
|
||||
sep = len(backups) - num
|
||||
if sep > -1:
|
||||
for backup in backups:
|
||||
fn = os.path.basename(backup['filename'])
|
||||
object_name = ftp.buildDirName(stype, fn)
|
||||
ftp.deleteFile(object_name)
|
||||
mw.echoInfo("---已清理远程过期备份文件:" + object_name)
|
||||
sep -= 1
|
||||
if sep < 0:
|
||||
break
|
||||
mw.echoEnd('结束删除远程备份')
|
||||
|
||||
return ''
|
||||
|
||||
|
||||
def backupSite():
|
||||
# 备份站点
|
||||
pass
|
||||
|
||||
|
||||
def in_array(name, arr=[]):
|
||||
for x in arr:
|
||||
if name == x:
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Executable
+19
@@ -0,0 +1,19 @@
|
||||
<div class="bt-form">
|
||||
<div class='plugin_version'></div>
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('dynamic-tracking');">服务</p>
|
||||
<p onclick="pluginInitD('dynamic-tracking');">自启动</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
resetPluginWinHeight(300);
|
||||
resetPluginWinWidth(500);
|
||||
$.getScript( "/plugins/file?name=dynamic-tracking&f=static/js/dynamic-tracking.js", function(){
|
||||
pluginService('dynamic-tracking', $('.plugin_version').attr('version'));
|
||||
});
|
||||
</script>
|
||||
Executable
+228
@@ -0,0 +1,228 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'dynamic-tracking'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDTpl():
|
||||
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
|
||||
return path
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
if t.strip() == '':
|
||||
tmp = []
|
||||
else:
|
||||
t = t.split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
return tmp
|
||||
|
||||
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
dir_path = getServerDir() + '/trace'
|
||||
if not os.path.exists(dir_path):
|
||||
os.mkdir(dir_path)
|
||||
return 'start'
|
||||
|
||||
|
||||
def dtOp(method):
|
||||
return 'ok'
|
||||
|
||||
|
||||
def start():
|
||||
return dtOp('start')
|
||||
|
||||
|
||||
def stop():
|
||||
return dtOp('stop')
|
||||
|
||||
|
||||
def restart():
|
||||
status = dtOp('restart')
|
||||
return status
|
||||
|
||||
|
||||
def reload():
|
||||
return dtOp('reload')
|
||||
|
||||
|
||||
def initdStatus():
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdInstall():
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
return 'ok'
|
||||
|
||||
|
||||
def get_file(args):
|
||||
dir_path = getServerDir() + '/trace'
|
||||
|
||||
path = dir_path + '/' + args['file'] + '/main.svg'
|
||||
|
||||
if os.path.exists(path):
|
||||
d = mw.readFile(path)
|
||||
return mw.returnData(True, 'ok', d)
|
||||
else:
|
||||
return mw.returnData(False, '无效目录')
|
||||
|
||||
|
||||
def get_file_path(args):
|
||||
dir_path = getServerDir() + '/trace'
|
||||
path = dir_path + '/' + args['file'] + '/main.svg'
|
||||
if os.path.exists(path):
|
||||
return mw.returnData(True, 'ok', path)
|
||||
else:
|
||||
return mw.returnData(False, '无效目录')
|
||||
|
||||
|
||||
def dtGetFilePath():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['file'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
dir_path = getServerDir() + '/trace'
|
||||
path = dir_path + '/' + args['file'] + '/main.svg'
|
||||
if os.path.exists(path):
|
||||
return mw.returnJson(True, 'ok', path)
|
||||
else:
|
||||
return mw.returnJson(False, '无效目录')
|
||||
|
||||
|
||||
def dtRemoveFilePath():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['file'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
dir_path = getServerDir() + '/trace'
|
||||
path = dir_path + '/' + args['file']
|
||||
if os.path.exists(path):
|
||||
mw.execShell('rm -rf ' + path)
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
def dtFileList():
|
||||
dir_path = getServerDir() + '/trace'
|
||||
if not os.path.exists(dir_path):
|
||||
os.mkdir(dir_path)
|
||||
|
||||
file_info = []
|
||||
for name in os.listdir(dir_path):
|
||||
if name == ".DS_Store":
|
||||
continue
|
||||
|
||||
# print(name)
|
||||
info = {}
|
||||
try:
|
||||
info['name'] = name
|
||||
info['abs_path'] = dir_path + '/' + name + '/main.svg'
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, str(e))
|
||||
|
||||
file_info.append(info)
|
||||
|
||||
file_info = sorted(file_info, key=lambda x: x['name'], reverse=False)
|
||||
return mw.returnJson(True, 'ok!', file_info)
|
||||
|
||||
|
||||
def dtSimpleTrace():
|
||||
if mw.isAppleSystem():
|
||||
return mw.returnJson(False, 'macosx只能手动执行!')
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['pid'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
plugins_shell = getPluginDir() + '/shell/simple_trace.sh'
|
||||
cmd = plugins_shell + ' "' + args['pid'] + '"'
|
||||
|
||||
data = mw.execShell("bash " + cmd + " &")
|
||||
return mw.returnJson(True, '执行成功!')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
if func == 'status':
|
||||
print(status())
|
||||
elif func == 'start':
|
||||
print(start())
|
||||
elif func == 'stop':
|
||||
print(stop())
|
||||
elif func == 'restart':
|
||||
print(restart())
|
||||
elif func == 'reload':
|
||||
print(reload())
|
||||
elif func == 'initd_status':
|
||||
print(initdStatus())
|
||||
elif func == 'initd_install':
|
||||
print(initdInstall())
|
||||
elif func == 'initd_uninstall':
|
||||
print(initdUinstall())
|
||||
elif func == 'run_info':
|
||||
print(runInfo())
|
||||
elif func == 'conf':
|
||||
print(getConf())
|
||||
elif func == 'run_log':
|
||||
print(runLog())
|
||||
elif func == 'file_list':
|
||||
print(dtFileList())
|
||||
elif func == 'get_file_path':
|
||||
print(dtGetFilePath())
|
||||
elif func == 'remove_file_path':
|
||||
print(dtRemoveFilePath())
|
||||
elif func == 'simple_trace':
|
||||
print(dtSimpleTrace())
|
||||
else:
|
||||
print('error')
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"hook":[
|
||||
{
|
||||
"tag":"menu",
|
||||
"menu": {
|
||||
"title":"动态追踪",
|
||||
"name":"dynamic-tracking",
|
||||
"path":"static/html/index.html",
|
||||
"css_path":"static/css/dynamic-tracking.css",
|
||||
"js_path":"static/js/dynamic-tracking.js"
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag":"global_static",
|
||||
"global_static": {
|
||||
"title":"动态追踪",
|
||||
"name":"dynamic-tracking",
|
||||
"css_path":"static/css/ico.css"
|
||||
}
|
||||
}
|
||||
],
|
||||
"sort": 7,
|
||||
"ps": "专业使用,动态追踪调试程序<无侵入>![<span style='color:red;'>潜龙勿用|实验</span>]",
|
||||
"name": "dynamic-tracking",
|
||||
"title": "动态追踪",
|
||||
"shell": "install.sh",
|
||||
"versions":["0.1"],
|
||||
"tip": "soft",
|
||||
"checks": "server/dynamic-tracking",
|
||||
"path": "server/dynamic-tracking",
|
||||
"display": 1,
|
||||
"author": "midoks",
|
||||
"date": "2023-08-17",
|
||||
"type": 0,
|
||||
"pid": "4"
|
||||
}
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
# cd /www/server/mdserver-web/plugins/dynamic-tracking && /bin/bash install.sh uninstall 1.0
|
||||
# cd /www/server/mdserver-web/plugins/dynamic-tracking && /bin/bash install.sh install 1.0
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
VERSION=$2
|
||||
|
||||
if [ -f ${rootPath}/bin/activate ];then
|
||||
source ${rootPath}/bin/activate
|
||||
fi
|
||||
|
||||
|
||||
OSNAME=`bash ${rootPath}/scripts/getos.sh`
|
||||
|
||||
if [ "" == "$OSNAME" ];then
|
||||
OSNAME=`cat ${rootPath}/data/osname.pl`
|
||||
fi
|
||||
|
||||
if [ "macos" != "$OSNAME" ];then
|
||||
SYS_VERSION_ID=`cat /etc/*-release | grep VERSION_ID | awk -F = '{print $2}' | awk -F "\"" '{print $2}'`
|
||||
fi
|
||||
|
||||
Install_App()
|
||||
{
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
mkdir -p $serverPath/source
|
||||
mkdir -p $serverPath/dynamic-tracking
|
||||
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
HTTP_PREFIX="https://"
|
||||
if [ ! -z "$cn" ];then
|
||||
HTTP_PREFIX="https://ghproxy.com/"
|
||||
fi
|
||||
|
||||
# FlameGraph start
|
||||
if [ ! -d $serverPath/dynamic-tracking/FlameGraph ];then
|
||||
if [ ! -f $serverPath/source/FlameGraph.zip ]; then
|
||||
wget --no-check-certificate -O $serverPath/source/FlameGraph.zip ${HTTP_PREFIX}github.com/brendangregg/FlameGraph/archive/refs/heads/master.zip
|
||||
fi
|
||||
|
||||
cd $serverPath/source && unzip $serverPath/source/FlameGraph.zip
|
||||
mv $serverPath/source/FlameGraph-master $serverPath/dynamic-tracking/FlameGraph
|
||||
fi
|
||||
# FlameGraph end
|
||||
|
||||
|
||||
|
||||
shell_file=${curPath}/versions/${OSNAME}.sh
|
||||
echo $shell_file
|
||||
if [ ! -f $shell_file ];then
|
||||
echo '不支持...' > $install_tmp
|
||||
exit 1
|
||||
fi
|
||||
|
||||
bash -x $shell_file
|
||||
|
||||
echo "cp -rf ${curPath}/shell $serverPath/dynamic-tracking"
|
||||
cp -rf ${curPath}/shell $serverPath/dynamic-tracking
|
||||
|
||||
echo "${VERSION}" > $serverPath/dynamic-tracking/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/dynamic-tracking/index.py start
|
||||
# cd ${rootPath} && python3 ${rootPath}/plugins/dynamic-tracking/index.py initd_install
|
||||
|
||||
}
|
||||
|
||||
Uninstall_App()
|
||||
{
|
||||
rm -rf $serverPath/dynamic-tracking
|
||||
echo "Uninstall_App" > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_App
|
||||
else
|
||||
Uninstall_App
|
||||
fi
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
|
||||
# debug
|
||||
# cd /www/server/mdserver-web
|
||||
# bash /www/server/mdserver-web/plugins/dynamic-tracking/shell/simple_macosx_trace.sh "22431"
|
||||
|
||||
# cd /Users/midoks/Desktop/mwdev/server/mdserver-web
|
||||
# bash /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/dynamic-tracking/shell/simple_macosx_trace.sh "22431"
|
||||
|
||||
# dtrace -x ustackframes=100 -n 'pid$target::mach_msg_trap:entry { @[ustack()] = count(); } tick-30s { exit(0); }' -p 18572 -o out.SystemUIServer_stacks
|
||||
# /Users/midoks/Desktop/mwdev/server/dynamic-tracking/FlameGraph/stackcollapse.pl out.SystemUIServer_stacks > kernel.cbt
|
||||
# /Users/midoks/Desktop/mwdev/server/dynamic-tracking/FlameGraph/flamegraph.pl kernel.cbt > kernel.svg
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
sysName=`uname`
|
||||
PID=$1
|
||||
|
||||
echo $rootPath # /Users/midoks/Desktop/mwdev/server
|
||||
echo $curPath # /Users/midoks/Desktop/mwdev/server/mdserver-web
|
||||
|
||||
APP_DIR=${rootPath}/dynamic-tracking
|
||||
DST_FILE_DIR=${APP_DIR}/trace/PID_${PID}
|
||||
mkdir -p $DST_FILE_DIR
|
||||
|
||||
DST_FILE=${DST_FILE_DIR}/out.SystemUIServer_stacks
|
||||
|
||||
if [ ! -f $DST_FILE ];then
|
||||
sudo dtrace -x ustackframes=100 -n 'pid$target::mach_msg_trap:entry { @[ustack()] = count(); } tick-30s { exit(0); }' -p "$PID" -o $DST_FILE
|
||||
fi
|
||||
|
||||
${APP_DIR}/FlameGraph/stackcollapse.pl $DST_FILE > ${DST_FILE_DIR}/kernel.cbt
|
||||
${APP_DIR}/FlameGraph/flamegraph.pl ${DST_FILE_DIR}/kernel.cbt > ${DST_FILE_DIR}/main.svg
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
|
||||
# debug
|
||||
# cd /www/server/mdserver-web
|
||||
# bash /www/server/mdserver-web/plugins/dynamic-tracking/shell/simple_trace.sh "2401699"
|
||||
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
sysName=`uname`
|
||||
PID=$1
|
||||
|
||||
echo $rootPath # /Users/midoks/Desktop/mwdev/server
|
||||
echo $curPath # /Users/midoks/Desktop/mwdev/server/mdserver-web
|
||||
|
||||
APP_DIR=/www/server/dynamic-tracking
|
||||
DST_FILE_DIR=${APP_DIR}/trace/PID_${PID}
|
||||
mkdir -p $DST_FILE_DIR
|
||||
|
||||
# DST_FILE=${DST_FILE_DIR}/main.strace
|
||||
|
||||
# perf record -F 99 -p 335584 -g -- sleep 30
|
||||
|
||||
cd ${DST_FILE_DIR}
|
||||
perf record -F 99 -p ${PID} -g -- sleep 30
|
||||
|
||||
perf script > out.perf
|
||||
${APP_DIR}/FlameGraph/stackcollapse-perf.pl ${DST_FILE_DIR}/out.perf > ${DST_FILE_DIR}/out.folded
|
||||
${APP_DIR}/FlameGraph/flamegraph.pl ${DST_FILE_DIR}/out.folded > ${DST_FILE_DIR}/main.svg
|
||||
|
||||
# perf record -F 99 -p 2401699 -g -- sleep 30
|
||||
# perf script > out.perf
|
||||
# /www/server/dynamic-tracking/FlameGraph/stackcollapse-perf.pl out.perf > out.folded
|
||||
# /www/server/dynamic-tracking/FlameGraph/flamegraph.pl out.folded > php-zend-flame-graph.svg
|
||||
|
||||
# ${APP_DIR}/FlameGraph/stackcollapse.pl $DST_FILE > ${DST_FILE_DIR}/kernel.cbt
|
||||
# ${APP_DIR}/FlameGraph/flamegraph.pl ${DST_FILE_DIR}/kernel.cbt > ${DST_FILE_DIR}/main.svg
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
.screen-all {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.s-right .panel-default{
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.s-left .panel-default{
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
|
||||
.data-collect {
|
||||
width: 45px;
|
||||
height: 30px;
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
margin-right: 2px;
|
||||
margin-top: 10px;
|
||||
color: #fff;
|
||||
background-color: #20a53a;
|
||||
border-color: #20a53a;
|
||||
}
|
||||
|
||||
|
||||
#file_list .list {
|
||||
list-style: none;
|
||||
border-top: none;
|
||||
border: 1px solid #ececec;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#file_list .list li.active {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
#file_list .tab-con{
|
||||
padding: 0px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
#file_list .list li>span {
|
||||
vertical-align: top;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#file_list .list li {
|
||||
display: inline-block;
|
||||
height: 38px;
|
||||
line-height: 38px;
|
||||
color: #444;
|
||||
border-bottom: 1px solid #ececec;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#file_list .file {
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
#file_list .list li .tootls{
|
||||
width: 70px;
|
||||
text-align: right;
|
||||
padding-right: 10px;
|
||||
/* display: none; */
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
}
|
||||
|
||||
/*.tab-con .tab-block.on {
|
||||
display: inline-block;
|
||||
}*/
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
/* menu start */
|
||||
.menu .current .menu_dynamic-tracking:hover {
|
||||
background-image: url("/plugins/file?name=dynamic-tracking&f=ico.png");
|
||||
}
|
||||
|
||||
.menu .menu_plugin_dynamic-tracking {
|
||||
background-image: url("/plugins/file?name=dynamic-tracking&f=ico.png");
|
||||
}
|
||||
|
||||
/* menu end */
|
||||
@@ -0,0 +1,81 @@
|
||||
<style>
|
||||
.weblog{
|
||||
font-size: 12px;
|
||||
display:inline-block;
|
||||
line-height:30px;
|
||||
}
|
||||
.weblog em{
|
||||
font-style:normal;
|
||||
color:#666;
|
||||
margin: 0 30px;
|
||||
}
|
||||
.weblog span{
|
||||
margin-right:5px;
|
||||
}
|
||||
.weblog a{
|
||||
color:#20a53a;
|
||||
}
|
||||
.firewall-port-box{
|
||||
margin-bottom:15px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="container-fluid">
|
||||
<div class="pos-box bgw mtb15">
|
||||
<div class="position f14 c9 pull-left">
|
||||
<a class="plr10 c4" href="/">首页</a>/<span class="plr10 c4">动态追踪</span>
|
||||
</div>
|
||||
|
||||
<div class="search pull-right">
|
||||
<form target="hid" onsubmit='return false;'>
|
||||
<input type="text" id="searchValue" class="ser-text pull-left" placeholder="进程ID" />
|
||||
<button type="button" class="data-collect pull-left">采样</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- //// -->
|
||||
<div class="safe bgw pd15 mtb15" id="ff_box">
|
||||
|
||||
<div id="file_list" style="float:left;width:300px;">
|
||||
<div class="tab-nav">
|
||||
<span class="on">文件列表</span>
|
||||
</div>
|
||||
|
||||
<div class="tab-con">
|
||||
<div class="tab-block on">
|
||||
<ul class="list" style="display: block; height: 94px;"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="flame_graph" style="float:left;">
|
||||
<div class="tab-nav">
|
||||
<span class="on">火焰图</span>
|
||||
</div>
|
||||
|
||||
<div class="tab-con">
|
||||
<iframe class="tab-block on" width="100%" height="100%"
|
||||
src=""
|
||||
frameborder="0"
|
||||
border="0"
|
||||
marginwidth="0"
|
||||
marginheight="0"
|
||||
scrolling="yes"
|
||||
noresize=""
|
||||
allowfullscreen="allowfullscreen"
|
||||
mozallowfullscreen="mozallowfullscreen"
|
||||
msallowfullscreen="msallowfullscreen"
|
||||
oallowfullscreen="oallowfullscreen"
|
||||
webkitallowfullscreen="webkitallowfullscreen"
|
||||
allowfullscreen="true"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- //// -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
function changeDivH(){
|
||||
var l = $(window).height();
|
||||
var w = $(window).width();
|
||||
|
||||
$('#ff_box').css('height',l-80-60);
|
||||
|
||||
$('#file_list').css('height',l-80-60);
|
||||
$('#file_list .tab-con .list').css('height', l-80-60-70);
|
||||
|
||||
|
||||
$('#flame_graph').css('height',l-80-60).css('width',w-300-200-40);
|
||||
$('#flame_graph iframe').css('height',l-80-60-70);
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function(){
|
||||
var tag = $.getUrlParam('tag');
|
||||
if(tag == 'dynamic-tracking'){
|
||||
dynamicTrackingLoad();
|
||||
}
|
||||
});
|
||||
|
||||
function dynamicTrackingLoad(){
|
||||
changeDivH();
|
||||
$(window).resize(function(){
|
||||
changeDivH();
|
||||
});
|
||||
|
||||
//加载采样数据列表
|
||||
dtFileList();
|
||||
}
|
||||
|
||||
|
||||
$('.data-collect').click(function(){
|
||||
layer.msg('开始采样',{icon:0,time:2000});
|
||||
var pid = $('#searchValue').val();
|
||||
|
||||
dtPost('simple_trace', '', {pid:pid}, function(rdata){
|
||||
// console.log(rdata);
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
layer.msg(rdata['msg'],{icon:rdata['status']?1:2,time:2000,shade: [0.3, '#000']});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function dtPost(method, version, args,callback){
|
||||
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
var req_data = {};
|
||||
req_data['name'] = 'dynamic-tracking';
|
||||
req_data['func'] = method;
|
||||
req_data['version'] = version;
|
||||
|
||||
if (typeof(args) == 'string'){
|
||||
req_data['args'] = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
req_data['args'] = JSON.stringify(args);
|
||||
}
|
||||
|
||||
$.post('/plugins/run', req_data, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
//错误展示10S
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [10, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
function dtPostCb(method, version, args,callback){
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
|
||||
var pdata = {};
|
||||
pdata['name'] = 'dynamic-tracking';
|
||||
pdata['func'] = method;
|
||||
args['version'] = version;
|
||||
|
||||
if (typeof(args) == 'string'){
|
||||
pdata['args'] = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
pdata['args'] = JSON.stringify(args);
|
||||
}
|
||||
|
||||
$.post('/plugins/callback', pdata, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
|
||||
function dtFileList(){
|
||||
dtPost('file_list', '', {}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var alist = rdata.data;
|
||||
|
||||
if (alist.length == 0){
|
||||
var em ='<li class="data-file-list" style="text-align: center;">无数据</li>';
|
||||
$('#file_list .list').html(em);
|
||||
return;
|
||||
}
|
||||
|
||||
var tli = '';
|
||||
for (var i = 0; i < alist.length; i++) {
|
||||
if (i==0){
|
||||
tli +='<li title="双击打开浏览" class="data-file-list active" data-index="'+i+'" data-file="'+alist[i]['name']+'">\
|
||||
<span class="file">'+alist[i]['name']+'</span>\
|
||||
<span class="tootls">\
|
||||
<span class="glyphicon glyphicon-link" aria-hidden="true" title="外部连接"></span>\
|
||||
<span class="glyphicon glyphicon-trash" aria-hidden="true" title="删除"></span>\
|
||||
</span>\
|
||||
</li>';
|
||||
} else{
|
||||
tli +='<li class="data-file-list" data-index="'+i+'" data-file="'+alist[i]['name']+'">\
|
||||
<span class="file">'+alist[i]['name']+'</span>\
|
||||
<span class="tootls">\
|
||||
<span class="glyphicon glyphicon-link" aria-hidden="true" title="外部连接"></span>\
|
||||
<span class="glyphicon glyphicon-trash" aria-hidden="true" title="删除"></span>\
|
||||
</span>\
|
||||
</li>';
|
||||
}
|
||||
}
|
||||
|
||||
$('#file_list .list').html(tli);
|
||||
|
||||
dtGetFile(alist[0]['name']);
|
||||
$('#file_list li .file').click(function(){
|
||||
$('#file_list li').removeClass('active');
|
||||
$(this).parent().addClass('active');
|
||||
var i = $(this).parent().data('index');
|
||||
dtGetFile(alist[i]['name']);
|
||||
});
|
||||
|
||||
|
||||
$('#file_list li .glyphicon-link').click(function(){
|
||||
var i = $(this).parent().parent().data('index');
|
||||
var abs_p = alist[i]['abs_path'];
|
||||
|
||||
var durl = '/files/download?filename='+abs_p;
|
||||
window.open(durl);
|
||||
});
|
||||
|
||||
$('#file_list li .glyphicon-trash').click(function(){
|
||||
var i = $(this).parent().parent().data('index');
|
||||
var f = alist[i]['name'];
|
||||
dtPost('remove_file_path', '',{file:f}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
layer.msg(rdata['msg'],{icon:rdata['status']?1:2,time:2000});
|
||||
if (rdata.status){
|
||||
dtFileList();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function dtGetFile(file){
|
||||
dtPost('get_file_path', '', {file:file}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
// console.log(rdata);
|
||||
if (!rdata.status){
|
||||
layer.msg(rdata.msg,{icon:0,time:2000,shade: [2, '#000']});
|
||||
return;
|
||||
}
|
||||
var durl = '/files/download?filename='+rdata.data;
|
||||
$('#flame_graph .tab-con .tab-block').attr('src',durl);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
SYS_ARCH=`arch`
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
# apt-get install linux-perf
|
||||
# apt-get update -y
|
||||
# strace -p $(ps -ef|grep "pool www" | awk '{print $2}' | grep -v grep | tr '\n' ',' )
|
||||
|
||||
# perf record -F 99 -p 2401699 -g -- sleep 30
|
||||
# perf script > out.perf
|
||||
# /www/server/dynamic-tracking/FlameGraph/stackcollapse-perf.pl out.perf > out.folded
|
||||
# /www/server/dynamic-tracking/FlameGraph/flamegraph.pl out.folded > php-zend-flame-graph.svg
|
||||
|
||||
# WWW_PID=$(ps -ef|grep "pool www" | awk '{print $2}' | grep -v grep | tr '\n' ',')
|
||||
# WWW_PID=${WWW_PID//,/}
|
||||
# WWW_PID=${var%,}
|
||||
# perf record -F 99 -p "1037,1038,1039,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1127,1128,1129,1130,1131,1473,1768,2848,2962,21582,35891" \
|
||||
# -g -- sleep 30
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
SYS_ARCH=`arch`
|
||||
|
||||
# 关于macosx使用dtrace
|
||||
|
||||
# https://groups.google.com/g/openresty/c/MswlH_8DDHA
|
||||
# http://dtrace.org/blogs/brendan/2012/11/14/dtracing-in-anger/
|
||||
|
||||
|
||||
# dtrace -x ustackframes=100 -n 'pid$target::mach_msg_trap:entry { @[ustack()] = count(); } tick-30s { exit(0); }' -p 18572 -o out.SystemUIServer_stacks
|
||||
# /Users/midoks/Desktop/mwdev/server/dynamic-tracking/FlameGraph/stackcollapse.pl out.SystemUIServer_stacks > kernel.cbt
|
||||
# /Users/midoks/Desktop/mwdev/server/dynamic-tracking/FlameGraph/flamegraph.pl kernel.cbt > kernel.svg
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
SYS_ARCH=`arch`
|
||||
@@ -0,0 +1,365 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
import io
|
||||
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
# -----------------------------
|
||||
import google.oauth2.credentials
|
||||
import google_auth_oauthlib.flow
|
||||
from googleapiclient.discovery import build
|
||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
||||
from google.auth.transport.requests import Request
|
||||
from googleapiclient.http import MediaFileUpload
|
||||
from googleapiclient.http import MediaIoBaseDownload
|
||||
|
||||
|
||||
class gdriveclient():
|
||||
__plugin_dir = ''
|
||||
__server_dir = ''
|
||||
|
||||
__credentials = "/root/credentials.json"
|
||||
__backup_dir_name = "backup"
|
||||
__creds = None
|
||||
__exclude = ""
|
||||
__scpos = ['https://www.googleapis.com/auth/drive.file']
|
||||
_title = 'Google Drive'
|
||||
_name = 'Google Drive'
|
||||
__debug = False
|
||||
|
||||
_DEFAULT_AUTH_PROMPT_MESSAGE = (
|
||||
'Please visit this URL to authorize this application: {url}')
|
||||
"""str: The message to display when prompting the user for
|
||||
authorization."""
|
||||
_DEFAULT_AUTH_CODE_MESSAGE = (
|
||||
'Enter the authorization code: ')
|
||||
"""str: The message to display when prompting the user for the
|
||||
authorization code. Used only by the console strategy."""
|
||||
|
||||
_DEFAULT_WEB_SUCCESS_MESSAGE = (
|
||||
'The authentication flow has completed, you may close this window.')
|
||||
|
||||
def __init__(self, plugin_dir, server_dir):
|
||||
self.__plugin_dir = plugin_dir
|
||||
self.__server_dir = server_dir
|
||||
self.set_creds()
|
||||
|
||||
# self.get_exclode()
|
||||
|
||||
def setDebug(self, d=False):
|
||||
self.__debug = d
|
||||
|
||||
def D(self, msg=''):
|
||||
if self.__debug:
|
||||
print(msg)
|
||||
|
||||
# 检查gdrive连接
|
||||
def _check_connect(self):
|
||||
try:
|
||||
service = build('drive', 'v3', credentials=self.__creds)
|
||||
results = service.files().list(
|
||||
pageSize=10, fields="nextPageToken, files(id, name)").execute()
|
||||
results.get('files', [])
|
||||
except:
|
||||
return False
|
||||
return True
|
||||
|
||||
# 设置creds
|
||||
def set_creds(self):
|
||||
token_file = self.__server_dir + '/token.json'
|
||||
if os.path.exists(token_file):
|
||||
with open(token_file, 'rb') as token:
|
||||
tmp_data = json.load(token)['credentials']
|
||||
self.__creds = google.oauth2.credentials.Credentials(
|
||||
tmp_data['token'],
|
||||
tmp_data['refresh_token'],
|
||||
tmp_data['id_token'],
|
||||
tmp_data['token_uri'],
|
||||
tmp_data['client_id'],
|
||||
tmp_data['client_secret'],
|
||||
tmp_data['scopes'])
|
||||
# if not self._check_connect():
|
||||
# return False
|
||||
# else:
|
||||
# return True
|
||||
|
||||
def get_sign_in_url(self):
|
||||
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
|
||||
self.__plugin_dir + '/credentials.json',
|
||||
scopes=self.__scpos)
|
||||
# flow.redirect_uri = 'https://drive.aapanel.com'
|
||||
flow.redirect_uri = 'https://drive.aapanel.com'
|
||||
auth_url, state = flow.authorization_url(
|
||||
access_type='offline',
|
||||
prompt='consent',
|
||||
include_granted_scopes='false')
|
||||
return auth_url, state
|
||||
|
||||
def set_auth_url(self, url):
|
||||
token_file = self.__server_dir + '/token.json'
|
||||
if os.path.exists(token_file):
|
||||
return mw.returnJson(True, "验证成功")
|
||||
|
||||
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
|
||||
self.__plugin_dir + '/credentials.json',
|
||||
scopes=self.__scpos,
|
||||
state=url.split('state=')[1].split('&code=')[0])
|
||||
# flow.redirect_uri = 'https://localhost'
|
||||
flow.redirect_uri = 'https://drive.aapanel.com'
|
||||
flow.fetch_token(authorization_response=url)
|
||||
credentials = flow.credentials
|
||||
|
||||
credentials_data = {}
|
||||
credentials_data['credentials'] = {
|
||||
'token': credentials.token,
|
||||
'id_token': credentials.id_token,
|
||||
'refresh_token': credentials.refresh_token,
|
||||
'token_uri': credentials.token_uri,
|
||||
'client_id': credentials.client_id,
|
||||
'client_secret': credentials.client_secret,
|
||||
'scopes': credentials.scopes}
|
||||
with open(token_file, 'w') as token:
|
||||
json.dump(credentials_data, token)
|
||||
if not self.set_creds():
|
||||
return mw.returnJson(False, "验证失败,请根据页面1 2 3 步骤完成验证")
|
||||
return mw.returnJson(True, "验证成功")
|
||||
|
||||
# 获取token
|
||||
def get_token(self, get):
|
||||
token_file = self.__server_dir + '/token.json'
|
||||
import requests
|
||||
try:
|
||||
respone = requests.get("https://www.google.com", timeout=2)
|
||||
except:
|
||||
return mw.returnJson(False, "连接谷歌失败")
|
||||
if respone.status_code != 200:
|
||||
return mw.returnJson(False, "连接谷歌失败")
|
||||
if not self.set_creds():
|
||||
return mw.returnJson(False, "验证失败,请根据页面1 2 3 步骤完成验证")
|
||||
if not os.path.exists(token_file):
|
||||
return mw.returnJson(False, "验证失败,请根据页面1 2 3 步骤完成验证")
|
||||
return mw.returnJson(True, "验证成功")
|
||||
|
||||
# 获取auth_url
|
||||
def get_auth_url(self, get):
|
||||
self.get_sign_in_url()
|
||||
if os.path.exists("/tmp/auth_url"):
|
||||
return mw.readFile("/tmp/auth_url")
|
||||
|
||||
# 检查连接
|
||||
def check_connect(self, get):
|
||||
token_file = self.__server_dir + '/token.json'
|
||||
if os.path.exists(token_file):
|
||||
with open(token_file, 'rb') as token:
|
||||
self.set_creds()
|
||||
else:
|
||||
self.D("Failed to get Google token, please verify before use")
|
||||
return mw.returnJson(True, "Failed to get Google token, please verify before use")
|
||||
service = build('drive', 'v3', credentials=self.__creds)
|
||||
results = service.files().list(
|
||||
pageSize=10, fields="nextPageToken, files(id, name)").execute()
|
||||
try:
|
||||
results.get('files', [])
|
||||
return mw.returnJson(False, "验证失败,请根据页面1 2 3 步骤完成验证")
|
||||
return mw.returnJson(True, "验证成功")
|
||||
except:
|
||||
return mw.returnJson(False, "验证失败,请根据页面1 2 3 步骤完成验证")
|
||||
|
||||
def _get_filename(self, filename):
|
||||
l = filename.split("/")
|
||||
return l[-1]
|
||||
|
||||
def _create_folder_cycle(self, filepath):
|
||||
l = filepath.split("/")
|
||||
fid_list = []
|
||||
for i in l:
|
||||
if not i:
|
||||
continue
|
||||
fid = self.__get_folder_id(i)
|
||||
if fid:
|
||||
fid_list.append(fid)
|
||||
continue
|
||||
if not fid_list:
|
||||
fid_list.append("")
|
||||
fid_list.append(self.create_folder(i, fid_list[-1]))
|
||||
return fid_list[-1]
|
||||
|
||||
def build_object_name(self, data_type, file_name):
|
||||
"""根据数据类型构建对象存储名称
|
||||
|
||||
:param data_type:
|
||||
:param file_name:
|
||||
:return:
|
||||
"""
|
||||
|
||||
import re
|
||||
prefix_dict = {
|
||||
"site": "web",
|
||||
"database": "db",
|
||||
"path": "path",
|
||||
}
|
||||
|
||||
if not prefix_dict.get(data_type):
|
||||
print("data_type 类型错误!!!")
|
||||
exit(1)
|
||||
|
||||
file_regx = prefix_dict.get(data_type) + "_(.+)_20\d+_\d+\."
|
||||
sub_search = re.search(file_regx.lower(), file_name)
|
||||
sub_path_name = ""
|
||||
if sub_search:
|
||||
sub_path_name = sub_search.groups()[0]
|
||||
sub_path_name += '/'
|
||||
# 构建OS存储路径
|
||||
object_name = self.__backup_dir_name + \
|
||||
'/{}/{}'.format(data_type, sub_path_name)
|
||||
|
||||
if object_name[:1] == "/":
|
||||
object_name = object_name[1:]
|
||||
return object_name
|
||||
|
||||
# 上传文件
|
||||
def upload_file(self, filename, data_type=None):
|
||||
"""
|
||||
get.filename 上传后的文件名
|
||||
get.filepath 上传文件路径
|
||||
被面板新版计划任务调用时
|
||||
get表示file_name
|
||||
:param get:
|
||||
:return:
|
||||
"""
|
||||
# filename = filename
|
||||
filepath = self.build_object_name(data_type, filename)
|
||||
_filename = self._get_filename(filename)
|
||||
self.D(filepath)
|
||||
self.D(filename)
|
||||
|
||||
parents = self._create_folder_cycle(filepath)
|
||||
self.D(parents)
|
||||
drive_service = build('drive', 'v3', credentials=self.__creds)
|
||||
file_metadata = {'name': _filename, 'parents': [parents]}
|
||||
media = MediaFileUpload(filename, resumable=True)
|
||||
file = drive_service.files().create(
|
||||
body=file_metadata, media_body=media, fields='id').execute()
|
||||
self.D('Upload Success ,File ID: %s' % file.get('id'))
|
||||
return True
|
||||
|
||||
def _get_file_id(self, filename):
|
||||
service = build('drive', 'v3', credentials=self.__creds)
|
||||
results = service.files().list(pageSize=10, q="name='{}'".format(
|
||||
filename), fields="nextPageToken, files(id, name)").execute()
|
||||
items = results.get('files', [])
|
||||
if not items:
|
||||
return []
|
||||
else:
|
||||
for item in items:
|
||||
return item["id"]
|
||||
|
||||
def delete_file(self, filename=None, data_type=None):
|
||||
file_id = self._get_file_id(filename)
|
||||
self.delete_file_by_id(file_id)
|
||||
return True
|
||||
|
||||
def delete_file_by_id(self, file_id):
|
||||
self.D("delete id:{}".format(file_id))
|
||||
try:
|
||||
drive_service = build('drive', 'v3', credentials=self.__creds)
|
||||
drive_service.files().delete(fileId=file_id).execute()
|
||||
return True
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
# 创建目录
|
||||
def create_folder(self, folder_name, parents=""):
|
||||
self.D(self.__creds)
|
||||
self.D("folder_name: {}".format(folder_name))
|
||||
self.D("parents: {}".format(parents))
|
||||
service = build('drive', 'v3', credentials=self.__creds)
|
||||
file_metadata = {
|
||||
'name': folder_name,
|
||||
'mimeType': 'application/vnd.google-apps.folder'
|
||||
}
|
||||
if parents:
|
||||
file_metadata['parents'] = [parents]
|
||||
folder = service.files().create(body=file_metadata, fields='id').execute()
|
||||
self.D('Create Folder ID: %s' % folder.get('id'))
|
||||
return folder.get('id')
|
||||
|
||||
def get_rootdir_id(self, folder_name='backup'):
|
||||
service = build('drive', 'v3', credentials=self.__creds)
|
||||
results = service.files().list(pageSize=10, q="name='{}' and mimeType='application/vnd.google-apps.folder'".format(folder_name),
|
||||
fields="nextPageToken, files(id, name,size,parents,webViewLink)").execute()
|
||||
items = results.get('files', [])
|
||||
if len(items) == 0:
|
||||
self.create_folder(folder_name)
|
||||
return self.get_rootdir_id(folder_name)
|
||||
|
||||
return items[0]['parents'][0]
|
||||
|
||||
# 获取目录id
|
||||
def __get_folder_id(self, floder_name):
|
||||
service = build('drive', 'v3', credentials=self.__creds)
|
||||
results = service.files().list(pageSize=10, q="name='{}' and mimeType='application/vnd.google-apps.folder'".format(floder_name),
|
||||
fields="nextPageToken, files(id, name)").execute()
|
||||
items = results.get('files', [])
|
||||
if not items:
|
||||
return []
|
||||
else:
|
||||
for item in items:
|
||||
return item["id"]
|
||||
|
||||
def get_res_info(self, rid):
|
||||
service = build('drive', 'v3', credentials=self.__creds)
|
||||
results = service.files().get(fileId='{}'.format(rid)).execute()
|
||||
return results
|
||||
|
||||
def get_id_list(self, driveId=''):
|
||||
service = build('drive', 'v3', credentials=self.__creds)
|
||||
results = service.files().list(pageSize=10, driveId="{}".format(driveId),
|
||||
fields="nextPageToken, files(id, name,size,parents)").execute()
|
||||
items = results.get('files', [])
|
||||
return items
|
||||
|
||||
def get_list(self, dir_id='', next_page_token=''):
|
||||
if dir_id == '':
|
||||
dir_id = self.get_rootdir_id(self.__backup_dir_name)
|
||||
|
||||
service = build('drive', 'v3', credentials=self.__creds)
|
||||
cmd_query = "trashed=false and '{}' in parents".format(dir_id)
|
||||
results = service.files().list(pageSize=10, q=cmd_query, orderBy='folder asc',
|
||||
fields="nextPageToken, files(id, name,size,createdTime,parents,webViewLink)").execute()
|
||||
items = results.get('files', [])
|
||||
nextPageToken = results.get('nextPageToken', [])
|
||||
# print(items)
|
||||
# print(nextPageToken)
|
||||
return items
|
||||
|
||||
def get_exclode(self, exclude=[]):
|
||||
if not exclude:
|
||||
tmp_exclude = os.getenv('MW_EXCLUDE')
|
||||
if tmp_exclude:
|
||||
exclude = tmp_exclude.split(',')
|
||||
if not exclude:
|
||||
return ""
|
||||
for ex in exclude:
|
||||
self.__exclude += " --exclude=\"" + ex + "\""
|
||||
self.__exclude += " "
|
||||
return self.__exclude
|
||||
|
||||
def download_file(self, filename):
|
||||
file_id = self._get_file_id(filename)
|
||||
service = build('drive', 'v3', credentials=self.__creds)
|
||||
request = service.files().get_media(fileId=file_id)
|
||||
with open('/tmp/{}'.format(filename), 'wb') as fh:
|
||||
downloader = MediaIoBaseDownload(fh, request)
|
||||
done = False
|
||||
while done is False:
|
||||
status, done = downloader.next_chunk()
|
||||
print("Download %d%%." % int(status.progress() * 100))
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"web": {
|
||||
"client_id": "226011946234-d3e1vashgag64utjedu1ljt9u39ncrpq.apps.googleusercontent.com",
|
||||
"project_id": "light-willow-341609",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_secret": "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",
|
||||
"redirect_uris": [
|
||||
"https://drive.aapanel.com"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"web": {
|
||||
"client_id": "540181629246-1horo9i4htamdbhiqar9rcbq33bqe2ob.apps.googleusercontent.com",
|
||||
"project_id": "plated-inn-369901",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_secret": "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",
|
||||
"redirect_uris": ["https://drive.aapanel.com"]
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
@@ -0,0 +1,310 @@
|
||||
<style>
|
||||
.upyunCon {
|
||||
height: 428px;
|
||||
}
|
||||
|
||||
.up-place {
|
||||
height: 62px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.up-place .btn {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.up-place .place-input {
|
||||
background-color: #f3f3f3;
|
||||
border: 1px solid #ccc;
|
||||
height: 30px;
|
||||
line-height: 28px;
|
||||
overflow: hidden;
|
||||
margin: 1px 0 0 -1px;
|
||||
width: 340px;
|
||||
}
|
||||
|
||||
.place-input ul {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.place-input ul li {
|
||||
background: url("/static/img/ico/ico-ltr.png") no-repeat right center;
|
||||
float: left;
|
||||
padding-left: 10px;
|
||||
padding-right: 18px;
|
||||
}
|
||||
|
||||
.place-input ul li a {
|
||||
height: 28px;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.upyunlist {
|
||||
height: 516px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.up-bottom {
|
||||
background-color: #fafafa;
|
||||
border-top: 1px solid #eee;
|
||||
bottom: 0;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.up-use {
|
||||
line-height: 50px
|
||||
}
|
||||
|
||||
.list-list .cursor span {
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
.btn-title {
|
||||
margin-top: 1px
|
||||
}
|
||||
|
||||
.tip {
|
||||
font-size: 10px;
|
||||
font-style: oblique;
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
<div class="upyunCon">
|
||||
<div class="up-place pd15">
|
||||
<button id="backBtn" class="btn btn-default btn-sm glyphicon glyphicon-arrow-left pull-left" title="后退"></button>
|
||||
<input id="myPath" type="hidden" value="">
|
||||
<input id="curPath" type="hidden" value="">
|
||||
<div class="place-input pull-left">
|
||||
<div style="width:1400px;height:28px"><ul></ul></div>
|
||||
</div>
|
||||
<button class="refreshBtn btn btn-default btn-sm glyphicon glyphicon-refresh pull-left mr20" title="刷新" style="margin-left:-1px;"></button>
|
||||
<button class="btn btn-default btn-sm pull-right btn-title" onclick="authApi()">授权</button>
|
||||
<button class="btn btn-default btn-sm pull-right mr20 btn-title" onclick="createDir()">新建文件夹</button>
|
||||
</div>
|
||||
|
||||
<div class="upyunlist pd15">
|
||||
<div class="divtable" style="margin-bottom:15px">
|
||||
<table class="table table-hover">
|
||||
<thead><tr><th>名称</th><th>大小</th><th>更新时间</th><th class="text-right">操作</th></tr></thead>
|
||||
<tbody class="list-list"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style type="text/css">
|
||||
.check_api {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.up-place {
|
||||
height: 62px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.up-place .btn {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.up-place .place-input {
|
||||
background-color: #f3f3f3;
|
||||
border: 1px solid #ccc;
|
||||
height: 30px;
|
||||
line-height: 28px;
|
||||
overflow: hidden;
|
||||
margin: 1px 0 0 -1px;
|
||||
width: 340px;
|
||||
}
|
||||
|
||||
.place-input ul {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.place-input ul li {
|
||||
background: url("/static/img/ico/ico-ltr.png") no-repeat right center;
|
||||
float: left;
|
||||
padding-left: 10px;
|
||||
padding-right: 18px;
|
||||
}
|
||||
|
||||
.place-input ul li a {
|
||||
height: 28px;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.upyunlist {
|
||||
height: 546px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.up-bottom {
|
||||
background-color: #fafafa;
|
||||
border-top: 1px solid #eee;
|
||||
bottom: 0;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.up-use {
|
||||
line-height: 50px
|
||||
}
|
||||
|
||||
.list-list .cursor span {
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
.btn-title {
|
||||
margin-top: 1px
|
||||
}
|
||||
|
||||
.step_item{
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.step_item .serial_box{
|
||||
display: inline-block;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.step_item .serial{
|
||||
width: 70px;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
float: left;
|
||||
}
|
||||
.step_item .serial span{
|
||||
display: inline-block;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
text-align: center;
|
||||
line-height: 28px;
|
||||
font-size: 11px;
|
||||
border-radius: 50%;
|
||||
color: #20a53a;
|
||||
border: 2px solid #20a53a;
|
||||
}
|
||||
.step_item .serial_title{
|
||||
margin-bottom: 10px;
|
||||
font-size: 15px;
|
||||
line-height: 30px;
|
||||
color: #666;
|
||||
}
|
||||
.step_two_url{
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
width: 380px;
|
||||
/*text-overflow: ellipsis;*/
|
||||
white-space: nowrap;
|
||||
height: 35px;
|
||||
line-height: 35px;
|
||||
margin-right: 15px;
|
||||
border-radius: 2px;
|
||||
padding: 0 10px;
|
||||
float: left;
|
||||
width:360px;
|
||||
padding-right: 35px;
|
||||
}
|
||||
.btn_btlink{
|
||||
display: inline-block;
|
||||
padding: 5px 10px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
border-radius: 3px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
cursor: pointer;
|
||||
border: 1px solid #20a53a;
|
||||
color: #fff;
|
||||
background-color: #20a53a;
|
||||
margin-right:10px;
|
||||
}
|
||||
.btn_btlink:hover{
|
||||
color: #fff;
|
||||
background-color: #10952a;
|
||||
border-color: #398439;
|
||||
}
|
||||
.btn_btlink a:visited{
|
||||
color: #fff;
|
||||
background-color: #10952a;
|
||||
border-color: #398439;
|
||||
}
|
||||
.view_video{
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.view_video ul li{
|
||||
line-height: 20px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.setp_one i{
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
left: 25px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
}
|
||||
.google_drive{
|
||||
width:465px;
|
||||
height:100px;
|
||||
margin-bottom:10px;
|
||||
}
|
||||
</style>
|
||||
<script type="text/html" id="check_api">
|
||||
<div class="check_api">
|
||||
<div class="step_two">
|
||||
<div class="step_item">
|
||||
<div class="serial"><span>1</span></div>
|
||||
<div class="serial_box">
|
||||
<div class="serial_title">阅读简易操作教程:如何获取Google Drive授权?</div>
|
||||
<div class="serial_conter">
|
||||
<div class="view_video">
|
||||
<ul>
|
||||
<li>1. 点击下面第<div class="serial" style="float: none;width: 45px;"><span>2</span></div>步中的 打开授权链接。<li>
|
||||
<li>2. 在新窗口页面上登录Google Drive账号。阅读授权权限,并同意。<li>
|
||||
<li>3. 页面跳转后,将浏览器的地址栏地址复制到第<div class="serial" style="float: none;width: 45px;"><span>3</span></div>步的文本框中。<li>
|
||||
<li>4. 点击 获取授权,随即完成授权。<li>
|
||||
</ul>
|
||||
</div>
|
||||
<hr/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="step_item pb15">
|
||||
<div class="serial"><span>2</span></div>
|
||||
<div class="serial_box">
|
||||
<div class="serial_title">操作1:👇打开授权链接,根据网页提示对插件进行授权。</div>
|
||||
<div class="serial_conter step_two" style="width: 500px;">
|
||||
<input class="bt-input-text mr5 step_two_url" type="text" disabled>
|
||||
<span class="ico-copy mr10" data-copy="" style="vertical-align: middle;cursor: pointer;margin-left: -37px;margin-right: 20px;"></span>
|
||||
<a href="" class="btn_btlink open_btlink" target="_blank" style="padding: 7px 10px;">打开授权链接</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="step_item">
|
||||
<div class="serial"><span>3</span></div>
|
||||
<div class="serial_box">
|
||||
<div class="serial_title">操作2:复制回浏览器跳转后的地址:</div>
|
||||
<div class="serial_conter">
|
||||
<textarea row="3" placeholder="验证URL地址" class="bt-input-text google_drive" style="resize: none;"/></br>
|
||||
<button type="button" class="btn btn-success btn-sm set_auth_btn">获取授权</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/javascript" src="/plugins/file?name=gdrive&f=js/gdrive.js"></script>
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=gdrive&f=js/gdrive.js", function(){
|
||||
gdList('');
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,338 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
|
||||
|
||||
# print(sys.platform)
|
||||
if sys.platform != "darwin":
|
||||
os.chdir("/www/server/mdserver-web")
|
||||
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
import db
|
||||
|
||||
_ver = sys.version_info
|
||||
is_py2 = (_ver[0] == 2)
|
||||
is_py3 = (_ver[0] == 3)
|
||||
|
||||
DEBUG = False
|
||||
|
||||
if is_py2:
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf-8')
|
||||
|
||||
app_debug = False
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'gdrive'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def in_array(name, arr=[]):
|
||||
for x in arr:
|
||||
if name == x:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
from gdriveclient import gdriveclient
|
||||
|
||||
|
||||
gd = gdriveclient(getPluginDir(), getServerDir())
|
||||
gd.setDebug(False)
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
if t.strip() == '':
|
||||
tmp = []
|
||||
else:
|
||||
t = t.split(':', 1)
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':', 1)
|
||||
tmp[t[0]] = t[1]
|
||||
return tmp
|
||||
|
||||
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
return 'start'
|
||||
|
||||
|
||||
def isAuthApi():
|
||||
cfg = getServerDir() + "/token.json"
|
||||
if os.path.exists(cfg):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def getConf():
|
||||
if not isAuthApi():
|
||||
sign_in_url, state = gd.get_sign_in_url()
|
||||
return mw.returnJson(False, "未授权!", {'auth_url': sign_in_url})
|
||||
return mw.returnJson(True, "OK")
|
||||
|
||||
|
||||
def setAuthUrl():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['url'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
url = args['url']
|
||||
|
||||
try:
|
||||
if url.startswith("http://"):
|
||||
url = url.replace("http://", "https://")
|
||||
token = gd.set_auth_url(url)
|
||||
# gd.store_token(token)
|
||||
# gd.store_user()
|
||||
return mw.returnJson(True, "授权成功!")
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, "授权失败2!:" + str(e))
|
||||
return mw.returnJson(False, "授权失败!:" + str(e))
|
||||
|
||||
|
||||
def clearAuth():
|
||||
token = getServerDir() + "/token.json"
|
||||
if os.path.exists(token):
|
||||
os.remove(token)
|
||||
return mw.returnJson(True, "清空授权成功!")
|
||||
|
||||
|
||||
def getList():
|
||||
if not isAuthApi():
|
||||
return mw.returnJson(False, "未配置,请点击`授权`", [])
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['file_id'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
try:
|
||||
flist = gd.get_list(args['file_id'])
|
||||
return mw.returnJson(True, "ok", flist)
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, str(e), [])
|
||||
|
||||
|
||||
def createDir():
|
||||
if not isAuthApi():
|
||||
return mw.returnJson(False, "未配置,请点击`授权`", [])
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['parents', 'name'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
isok = gd.create_folder(args['name'], args['parents'])
|
||||
if isok:
|
||||
return mw.returnJson(True, "创建成功")
|
||||
return mw.returnJson(False, "创建失败")
|
||||
|
||||
|
||||
def deleteDir():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['dir_name', 'path'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
isok = gd.delete_file_by_id(args['dir_name'])
|
||||
if isok:
|
||||
return mw.returnJson(True, "删除成功")
|
||||
return mw.returnJson(False, "文件不为空,删除失败!")
|
||||
|
||||
|
||||
def deleteFile():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['path', 'filename'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
isok = gd.delete_file(args['filename'])
|
||||
if isok:
|
||||
return mw.returnJson(True, "删除成功")
|
||||
return mw.returnJson(False, "删除失败")
|
||||
|
||||
|
||||
def findPathName(path, filename):
|
||||
f = os.scandir(path)
|
||||
l = []
|
||||
for ff in f:
|
||||
t = {}
|
||||
if ff.name.find(filename) > -1:
|
||||
t['filename'] = path + '/' + ff.name
|
||||
l.append(t)
|
||||
return l
|
||||
|
||||
|
||||
def backupAllFunc(stype):
|
||||
if not isAuthApi():
|
||||
mw.echoInfo("未授权API,无法使用!!!")
|
||||
return ''
|
||||
|
||||
os.chdir(mw.getRunDir())
|
||||
backup_dir = mw.getBackupDir()
|
||||
run_dir = mw.getRunDir()
|
||||
|
||||
stype = sys.argv[1]
|
||||
name = sys.argv[2]
|
||||
num = sys.argv[3]
|
||||
|
||||
prefix_dict = {
|
||||
"site": "web",
|
||||
"database": "db",
|
||||
"path": "path",
|
||||
}
|
||||
|
||||
backups = []
|
||||
sql = db.Sql()
|
||||
|
||||
# print("stype:", stype)
|
||||
# 提前获取-清理多余备份
|
||||
if stype == 'site':
|
||||
pid = sql.table('sites').where('name=?', (name,)).getField('id')
|
||||
backups = sql.table('backup').where(
|
||||
'type=? and pid=?', ('0', pid)).field('id,filename').select()
|
||||
if stype == 'database':
|
||||
db_path = mw.getServerDir() + '/mysql'
|
||||
pid = mw.M('databases').dbPos(db_path, 'mysql').where(
|
||||
'name=?', (name,)).getField('id')
|
||||
backups = sql.table('backup').where(
|
||||
'type=? and pid=?', ('1', pid)).field('id,filename').select()
|
||||
if stype == 'path':
|
||||
backup_path = backup_dir + '/path'
|
||||
_name = 'path_{}'.format(os.path.basename(name))
|
||||
backups = findPathName(backup_path, _name)
|
||||
|
||||
# 其他类型关系性数据库(mysql类的)
|
||||
if stype.find('database_') > -1:
|
||||
plugin_name = stype.replace('database_', '')
|
||||
db_path = mw.getServerDir() + '/' + plugin_name
|
||||
pid = mw.M('databases').dbPos(db_path, 'mysql').where(
|
||||
'name=?', (name,)).getField('id')
|
||||
backups = sql.table('backup').where(
|
||||
'type=? and pid=?', ('1', pid)).field('id,filename').select()
|
||||
|
||||
args = stype + " " + name + " " + num
|
||||
cmd = 'python3 ' + run_dir + '/scripts/backup.py ' + args
|
||||
if stype.find('database_') > -1:
|
||||
plugin_name = stype.replace('database_', '')
|
||||
args = "database " + name + " " + num
|
||||
cmd = 'python3 ' + run_dir + '/plugins/' + \
|
||||
plugin_name + '/scripts/backup.py ' + args
|
||||
|
||||
if stype == 'path':
|
||||
name = os.path.basename(name)
|
||||
|
||||
# print("cmd:", cmd)
|
||||
os.system(cmd)
|
||||
|
||||
# 开始执行上传信息.
|
||||
if stype.find('database_') > -1:
|
||||
bk_name = 'database'
|
||||
plugin_name = stype.replace('database_', '')
|
||||
bk_prefix = plugin_name + '/db'
|
||||
stype = 'database'
|
||||
else:
|
||||
bk_prefix = prefix_dict[stype]
|
||||
bk_name = stype
|
||||
|
||||
find_path = backup_dir + '/' + bk_name + '/' + bk_prefix + '_' + name
|
||||
find_new_file = "ls " + find_path + \
|
||||
"_* | grep '.gz' | cut -d \ -f 1 | awk 'END {print}'"
|
||||
|
||||
# print(find_new_file)
|
||||
|
||||
filename = mw.execShell(find_new_file)[0].strip()
|
||||
if filename == "":
|
||||
mw.echoInfo("not find upload file!")
|
||||
return False
|
||||
|
||||
mw.echoInfo("准备上传文件 {}".format(filename))
|
||||
mw.echoStart('开始上传')
|
||||
# gd.setDebug(False)
|
||||
gd.upload_file(filename, stype)
|
||||
mw.echoEnd('上传成功')
|
||||
|
||||
# print(backups)
|
||||
backups = sorted(backups, key=lambda x: x['filename'], reverse=False)
|
||||
mw.echoStart('开始删除远程备份')
|
||||
num = int(num)
|
||||
sep = len(backups) - num
|
||||
if sep > -1:
|
||||
for backup in backups:
|
||||
fn = os.path.basename(backup['filename'])
|
||||
gd.delete_file(fn, stype)
|
||||
mw.echoInfo("---已清理远程过期备份文件:" + fn)
|
||||
sep -= 1
|
||||
if sep < 0:
|
||||
break
|
||||
mw.echoEnd('结束删除远程备份')
|
||||
|
||||
return ''
|
||||
|
||||
|
||||
def installPreInspection():
|
||||
return 'ok'
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
if func == 'status':
|
||||
print(status())
|
||||
elif func == 'start':
|
||||
print(start())
|
||||
elif func == 'stop':
|
||||
print(stop())
|
||||
elif func == 'restart':
|
||||
print(restart())
|
||||
elif func == 'reload':
|
||||
print(reload())
|
||||
elif func == 'install_pre_inspection':
|
||||
print(installPreInspection())
|
||||
elif func == 'conf':
|
||||
print(getConf())
|
||||
elif func == 'set_auth_url':
|
||||
print(setAuthUrl())
|
||||
elif func == 'clear_auth':
|
||||
print(clearAuth())
|
||||
elif func == "get_list":
|
||||
print(getList())
|
||||
elif func == "create_dir":
|
||||
print(createDir())
|
||||
elif func == "delete_dir":
|
||||
print(deleteDir())
|
||||
elif func == 'delete_file':
|
||||
print(deleteFile())
|
||||
elif in_array(func, ['site', 'database', 'path']) or func.find('database_') > -1:
|
||||
print(backupAllFunc(func))
|
||||
else:
|
||||
print('error')
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"hook":["backup"],
|
||||
"id":998,
|
||||
"title":"谷歌云网盘",
|
||||
"tip":"lib",
|
||||
"name":"gdrive",
|
||||
"type":"扩展",
|
||||
"ps":"备份你的数据到谷歌云网盘",
|
||||
"versions":"2.0",
|
||||
"shell":"install.sh",
|
||||
"checks": "server/gdrive",
|
||||
"path":"server/gdrive",
|
||||
"author":"google",
|
||||
"home":"https://drive.google.com/",
|
||||
"api_doc":"https://developers.google.com/drive/api/guides/about-sdk?hl=zh_CN",
|
||||
"api_doc2":"https://developers.google.cn/drive/api/reference/rest/v3/comments/list?hl=zh-cn",
|
||||
"date":"2022-06-26",
|
||||
"pid":"4"
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
# cd /www/server/mdserver-web/plugins/gdrive && /bin/bash install.sh install 2.0
|
||||
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
PATH=$PATH:${rootPath}/bin
|
||||
export PATH
|
||||
|
||||
if [ -f ${rootPath}/bin/activate ];then
|
||||
source ${rootPath}/bin/activate
|
||||
fi
|
||||
|
||||
VERSION=$2
|
||||
|
||||
Install_App()
|
||||
{
|
||||
tmp_ping=`ping -c 1 google.com 2>&1`
|
||||
echo $tmp_ping
|
||||
if [ $? -eq 0 ];then
|
||||
tmp=`python -V 2>&1|awk '{print $2}'`
|
||||
pVersion=${tmp:0:3}
|
||||
|
||||
|
||||
which pip
|
||||
if [ "$?" -eq "0" ];then
|
||||
tmp=$(pip list|grep google-api-python-client|awk '{print $2}')
|
||||
if [ "$tmp" != '2.39.0' ];then
|
||||
pip install --upgrade google-api-python-client
|
||||
# pip uninstall google-api-python-client -y
|
||||
pip install -I google-api-python-client==2.39.0 -i https://pypi.Python.org/simple
|
||||
fi
|
||||
tmp=$(pip list|grep google-auth-httplib2|awk '{print $2}')
|
||||
if [ "$tmp" != '0.1.0' ];then
|
||||
pip uninstall google-auth-httplib2 -y
|
||||
pip install -I google-auth-httplib2==0.1.0 -i https://pypi.Python.org/simple
|
||||
fi
|
||||
tmp=$(pip list|grep google-auth-oauthlib|awk '{print $2}')
|
||||
if [ "$tmp" != '0.5.0' ];then
|
||||
# pip uninstall google-auth-oauthlib -y
|
||||
pip install -I google-auth-oauthlib==0.5.0 -i https://pypi.Python.org/simple
|
||||
fi
|
||||
tmp=$(pip list|grep -E '^httplib2'|awk '{print $2}')
|
||||
if [ "$tmp" != '0.18.1' ];then
|
||||
# pip uninstall httplib2 -y
|
||||
pip install -I httplib2==0.18.1 -i https://pypi.Python.org/simple
|
||||
fi
|
||||
else
|
||||
pip install -I pyOpenSSL
|
||||
pip install -I google-api-python-client==2.39.0 google-auth-httplib2==0.1.0 google-auth-oauthlib==0.5.0 -i https://pypi.Python.org/simple
|
||||
pip install -I httplib2==0.18.1 -i https://pypi.Python.org/simple
|
||||
fi
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
mkdir -p $serverPath/gdrive
|
||||
echo "${VERSION}" > $serverPath/gdrive/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
else
|
||||
echo '服务器连接不上谷歌云!安装失败!' > $install_tmp
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
Uninstall_App()
|
||||
{
|
||||
rm -rf $serverPath/gdrive
|
||||
echo '卸载完成' > $install_tmp
|
||||
}
|
||||
|
||||
|
||||
action=$1
|
||||
type=$2
|
||||
|
||||
echo $action $type
|
||||
if [ "${action}" == 'install' ];then
|
||||
Install_App
|
||||
else
|
||||
Uninstall_App
|
||||
fi
|
||||
@@ -0,0 +1,260 @@
|
||||
|
||||
function gdPost(method,args,callback){
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'gdrive', func:method, args:_args}, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
|
||||
function createDir(){
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: "400px",
|
||||
title: "创建目录",
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: false,
|
||||
btn: ['确定','取消'],
|
||||
content:'<div class="bingfa bt-form c6" style="padding-bottom: 10px;">\
|
||||
<p>\
|
||||
<span class="span_tit">目录名称:</span>\
|
||||
<input style="width: 200px;" type="text" name="newPath" value="">\
|
||||
</p>\
|
||||
</div>',
|
||||
success:function(){
|
||||
$("input[name='newPath']").focus().keyup(function(e){
|
||||
if(e.keyCode == 13) $(".layui-layer-btn0").click();
|
||||
});
|
||||
},
|
||||
yes:function(index,layero){
|
||||
var name = $("input[name='newPath']").val();
|
||||
if(name == ''){
|
||||
layer.msg('目录名称不能为空!',{icon:2});
|
||||
return;
|
||||
}
|
||||
var parents = $("#myPath").val();
|
||||
var cur_file_id = $('#curPath').val();
|
||||
if (cur_file_id!=''){
|
||||
parents = cur_file_id;
|
||||
}
|
||||
|
||||
var dirname = name;
|
||||
var loadT = layer.msg('正在创建目录['+dirname+']...',{icon:16,time:0,shade: [0.3, '#000']});
|
||||
gdPost('create_dir', {parents:parents,name:dirname}, function(data){
|
||||
layer.close(loadT);
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if(rdata.status) {
|
||||
showMsg(rdata.msg, function(){
|
||||
layer.close(index);
|
||||
var file_id = $('#myPath').val();
|
||||
if (cur_file_id!=''){
|
||||
file_id = cur_file_id;
|
||||
}
|
||||
gdList(file_id);
|
||||
} ,{icon:1}, 2000);
|
||||
} else{
|
||||
layer.msg(rdata.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//设置API
|
||||
function authApi(){
|
||||
|
||||
gdPost('conf', {}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
|
||||
// console.log(rdata);
|
||||
// console.log(rdata.data.auth_url);
|
||||
var apicon = '';
|
||||
if (rdata.status){
|
||||
|
||||
var html = '';
|
||||
html += '<button id="clear_auth" onclick="clearAuth();" class="btn btn-default btn-sm">清空配置</button>';
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '已授权',
|
||||
area: '240px',
|
||||
content:'<div class="change-default pd20">'+html+'</div>',
|
||||
success: function(){
|
||||
$('#clear_auth').click(function(){
|
||||
gdPost('clear_auth', {}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
layer.close(loadOpen);
|
||||
gdList('');
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
||||
} else{
|
||||
apicon = '<div class="new_form">'+$("#check_api").html()+'</div>';
|
||||
}
|
||||
|
||||
var layer_auth = layer.open({
|
||||
type: 1,
|
||||
area: "620px",
|
||||
title: "Google Drive 授权",
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: false,
|
||||
content:apicon,
|
||||
success:function(layero,index){
|
||||
// console.log(layero,index);
|
||||
if (!rdata.status){
|
||||
$('.check_api .step_two_url').val(rdata.data['auth_url']);
|
||||
$('.check_api .open_btlink').attr('href',rdata.data['auth_url']);
|
||||
|
||||
$('.check_api .ico-copy').click(function(){
|
||||
copyPass(rdata.data['auth_url']);
|
||||
});
|
||||
|
||||
$('.check_api .set_auth_btn').click(function(){
|
||||
|
||||
var url = $('.check_api .google_drive').val();
|
||||
if ( url == ''){
|
||||
layer.msg("验证URL不能为空",{icon:2});
|
||||
return;
|
||||
}
|
||||
// console.log(url);
|
||||
gdPost('set_auth_url', {url:url}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
var show_time = 2000;
|
||||
if (!rdata.status){
|
||||
show_time = 10000;
|
||||
}
|
||||
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
layer.close(layer_auth);
|
||||
gdList('');
|
||||
}
|
||||
},{icon:rdata.status?1:2},show_time);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//计算当前目录偏移
|
||||
function upPathLeft(){
|
||||
var UlWidth = $(".place-input ul").width();
|
||||
var SpanPathWidth = $(".place-input").width() - 20;
|
||||
var Ml = UlWidth - SpanPathWidth;
|
||||
if(UlWidth > SpanPathWidth ){
|
||||
$(".place-input ul").css("left",-Ml)
|
||||
}
|
||||
else{
|
||||
$(".place-input ul").css("left",0)
|
||||
}
|
||||
}
|
||||
|
||||
function getGDTime(a) {
|
||||
return new Date(a).format("yyyy/MM/dd hh:mm:ss")
|
||||
}
|
||||
|
||||
function gdList(file_id){
|
||||
$('#curPath').val(file_id);
|
||||
gdPost('get_list', {file_id:file_id}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
console.log(rdata);
|
||||
if(rdata.status === false){
|
||||
showMsg(rdata.msg,function(){
|
||||
authApi();
|
||||
},{icon:2},2000);
|
||||
return;
|
||||
}
|
||||
|
||||
var mlist = rdata.data;
|
||||
var listBody = '';
|
||||
var listFiles = '';
|
||||
for(var i=0;i<mlist.length;i++){
|
||||
if(mlist[i].size == null){
|
||||
listFiles += '<tr><td class="cursor" onclick="gdList(\''+(mlist[i].id).replace('//','/')+'\')"><span class="ico ico-folder"></span>\<span>'+mlist[i].name+'</span></td>\
|
||||
<td>-</td>\
|
||||
<td>-</td>\
|
||||
<td class="text-right"><a class="btlink" onclick="deleteFile(\''+mlist[i].id+'\', true)">删除</a></td></tr>'
|
||||
}else{
|
||||
listFiles += '<tr><td class="cursor"><span class="ico ico-file"></span><span>'+mlist[i].name+'</span></td>\
|
||||
<td>'+toSize(mlist[i].size)+'</td>\
|
||||
<td>'+getGDTime(mlist[i].createdTime)+'</td>\
|
||||
<td class="text-right"><a target="_blank" href="'+mlist[i].webViewLink+'" class="btlink">下载</a> | <a class="btlink" onclick="deleteFile(\''+mlist[i].name+'\', false)">删除</a></td></tr>'
|
||||
}
|
||||
}
|
||||
listBody += listFiles;
|
||||
var pathLi = '<li><a title="根目录" onclick="gdList(\'\')">根目录</a></li>';
|
||||
|
||||
if (mlist.length>0){
|
||||
$('#myPath').val(mlist[0]['parents'][0]);
|
||||
}
|
||||
|
||||
$(".upyunCon .place-input ul").html(pathLi);
|
||||
$(".upyunlist .list-list").html(listBody);
|
||||
|
||||
$('#backBtn').unbind().click(function() {
|
||||
gdList('');
|
||||
});
|
||||
|
||||
$('.upyunCon .refreshBtn').unbind().click(function(){
|
||||
var file_id = $('#myPath').val();
|
||||
gdList(file_id);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//删除文件
|
||||
function deleteFile(name, is_dir){
|
||||
if (is_dir === false){
|
||||
safeMessage('删除文件','删除后将无法恢复,真的要删除['+name+']吗?',function(){
|
||||
var path = $("#myPath").val();
|
||||
var filename = name;
|
||||
gdPost('delete_file', {filename:filename,path:path}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
var file_id = $('#myPath').val();
|
||||
gdList(file_id);
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
safeMessage('删除文件夹','删除后将无法恢复,真的要删除文件资源['+name+']吗?',function(){
|
||||
var path = $("#myPath").val();
|
||||
gdPost('delete_dir', {dir_name:name,path:path}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
var file_id = $('#myPath').val();
|
||||
gdList(file_id);
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/python
|
||||
# coding: utf-8
|
||||
|
||||
# python3 plugins/gdrive/t/test.py
|
||||
# https://console.cloud.google.com/apis/credentials/consent?project=plated-inn-369901
|
||||
|
||||
# https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=226011946234-d3e1vashgag64utjedu1ljt9u39ncrpq.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fdrive.aapanel.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.file&state=I2da4aZUwqgmikrgrqAwwSjyoEHVs1&access_type=offline&prompt=consent&include_granted_scopes=false
|
||||
|
||||
|
||||
# https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/~/Overview/appId/08125e6b-6502-4ac9-9548-ad682f00848d/objectId/62b1d655-9828-47ed-be99-65eb18c3a929/isMSAApp~/false/defaultBlade/Overview/appSignInAudience/AzureADandPersonalMicrosoftAccount/servicePrincipalCreated~/true
|
||||
|
||||
# 0WA8Q~sZkZFZKv50ryP4ux~.fpVtbHw7BuTZmbQB
|
||||
# client_id:d9878fac-8526-4ff6-8036-e1c92dd9dd80
|
||||
|
||||
# 08125e6b-6502-4ac9-9548-ad682f00848d
|
||||
|
||||
|
||||
# /drive/v2internal/files?openDrive=false&reason=102&syncType=0&errorRecovery=false&q=trashed = false and '1-z6gUXseXmlxmntvkLzOe_tYFT5tdhM9' in parents&fields=kind,nextPageToken,items(kind,modifiedDate,hasVisitorPermissions,containsUnsubscribedChildren,modifiedByMeDate,lastViewedByMeDate,alternateLink,fileSize,owners(kind,permissionId,emailAddressFromAccount,id),lastModifyingUser(kind,permissionId,emailAddressFromAccount,id),customerId,ancestorHasAugmentedPermissions,hasThumbnail,thumbnailVersion,title,id,resourceKey,abuseIsAppealable,abuseNoticeReason,shared,accessRequestsCount,sharedWithMeDate,userPermission(role),explicitlyTrashed,mimeType,quotaBytesUsed,copyable,subscribed,folderColor,hasChildFolders,fileExtension,primarySyncParentId,sharingUser(kind,permissionId,emailAddressFromAccount,id),flaggedForAbuse,folderFeatures,spaces,sourceAppId,recency,recencyReason,version,actionItems,teamDriveId,hasAugmentedPermissions,createdDate,primaryDomainName,organizationDisplayName,passivelySubscribed,trashingUser(kind,permissionId,emailAddressFromAccount,id),trashedDate,parents(id),capabilities(canMoveItemIntoTeamDrive,canUntrash,canModifyContentRestriction,canMoveItemWithinTeamDrive,canMoveItemOutOfTeamDrive,canDeleteChildren,canTrashChildren,canRequestApproval,canReadCategoryMetadata,canEditCategoryMetadata,canAddMyDriveParent,canRemoveMyDriveParent,canShareChildFiles,canShareChildFolders,canRead,canMoveItemWithinDrive,canMoveChildrenWithinDrive,canAddFolderFromAnotherDrive,canChangeSecurityUpdateEnabled,canBlockOwner,canReportSpamOrAbuse,canCopy,canDownload,canEdit,canAddChildren,canDelete,canRemoveChildren,canShare,canTrash,canRename,canReadTeamDrive,canMoveTeamDriveItem),contentRestrictions(readOnly),approvalMetadata(approvalVersion,approvalSummaries,hasIncomingApproval),shortcutDetails(targetId,targetMimeType,targetLookupStatus,targetFile,canRequestAccessToTarget),spamMetadata(markedAsSpamDate,inSpamView),labels(starred,trashed,restricted,viewed)),incompleteSearch&appDataFilter=NO_APP_DATA&spaces=drive&maxResults=200&supportsTeamDrives=true&includeItemsFromAllDrives=true&corpora=default&orderBy=folder,title_natural asc&retryCount=0&key=AIzaSyD_InbmSFufIEps5UAt2NmB_3LvBH3Sz_8 HTTP/1.1
|
||||
|
||||
# http://localhost/?code=M.C106_BAY.2.3e12c859-6107-0c5b-9ef4-14b3fb8269ba&state=JzHdzHXmA7x6zl7Be6cJ6uOlf9Bg69
|
||||
|
||||
|
||||
# python3 /www/mdserver-web/plugins/gdrive/index.py site bbs.midoks.me 3
|
||||
# python3 /www/mdserver-web/plugins/gdrive/index.py database t1 3
|
||||
# python3 /www/server/mdserver-web/plugins/msonedrive/index.py path
|
||||
# /Users/midoks/Desktop/dev/python 3
|
||||
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'gdrive'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
# print(getPluginDir())
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
from gdriveclient import gdriveclient
|
||||
|
||||
|
||||
gd = gdriveclient(getPluginDir(), getServerDir())
|
||||
gd.setDebug(True)
|
||||
# sign_in_url, state = gd.get_sign_in_url()
|
||||
# print(sign_in_url)
|
||||
|
||||
# url = 'https://localhost/?state=GH2YZ1VeytzVB1BqJJpQZIBk2GGAub&code=4/0Adeu5BXnD2dQvXx8Sg0WPn1XiMpihcRBNaG1yaFKIo86gUiG7q65KU1MaNCxrj_f2bjkwQ&scope=https://www.googleapis.com/auth/drive.file'
|
||||
# t = gd.set_auth_url(url)
|
||||
# print(t)
|
||||
|
||||
# def set_auth_url(url):
|
||||
# try:
|
||||
# if url.startswith("http://"):
|
||||
# url = url.replace("http://", "https://")
|
||||
# token = msodc.get_token_from_authorized_url(
|
||||
# authorized_url=url)
|
||||
# msodc.store_token(token)
|
||||
# msodc.store_user()
|
||||
# return mw.returnJson(True, "授权成功!")
|
||||
# except Exception as e:
|
||||
# print(e)
|
||||
# return mw.returnJson(False, "授权失败2!:" + str(e))
|
||||
# return mw.returnJson(False, "授权失败!:" + str(e))
|
||||
|
||||
# url = 'http://localhost/?code=M.C106_BAY.2.310112f3-a158-c400-9667-d158cbd1de6c&state=jEJz0ucR9bpZYD9PGxp2GgRDotrzO6'
|
||||
# token = set_auth_url(url)
|
||||
# print(token)
|
||||
|
||||
# token = msodc.get_token()
|
||||
# print("token:", token)
|
||||
|
||||
# t = gd.get_list('')
|
||||
# print(t)
|
||||
|
||||
# t = gd.get_id_list('1u7LjXGj1KoN-ltAdTRaib7IZJpsEnPdz')
|
||||
# print(t)
|
||||
|
||||
# t = gd.create_folder('backup_demo')
|
||||
# print(t)
|
||||
|
||||
# t = msodc.delete_object('backup')
|
||||
# print(t)
|
||||
|
||||
|
||||
# t = gd.upload_file('web_t1.cn_20230830_134549.tar.gz', 'site')
|
||||
# print(t)
|
||||
# print(gd.error_msg)
|
||||
|
||||
# /Users/midoks/Desktop/mwdev/server/mdserver-web/paramiko.log
|
||||
# backup/site/paramiko.log
|
||||
# |-正在上传到 backup/site/paramiko.log...
|
||||
# True
|
||||
|
||||
|
||||
t = gd.upload_file(
|
||||
'db_zzzvps_20230830_210727.sql.gz', 'datebase')
|
||||
print(t)
|
||||
@@ -2,7 +2,7 @@
|
||||
"ps": "Gogs是一款极易搭建的自助Git服务",
|
||||
"name": "gogs",
|
||||
"title": "Gogs",
|
||||
"versions": ["0.11.86","0.12.9"],
|
||||
"versions": ["0.11.86","0.12.9","0.13.0"],
|
||||
"tip": "soft",
|
||||
"checks": "server/gogs",
|
||||
"path":"server/gogs",
|
||||
|
||||
@@ -9,6 +9,10 @@ serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
if [ -f ${rootPath}/bin/activate ];then
|
||||
source ${rootPath}/bin/activate
|
||||
fi
|
||||
|
||||
|
||||
GOGS_DOWNLOAD='https://dl.gogs.io'
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ class backupTools:
|
||||
pid = mw.M('databases').dbPos(db_path, db_name).where(
|
||||
'name=?', (name,)).getField('id')
|
||||
|
||||
mw.M('backup').add('type,name,pid,filename,addtime,size', (1, os.path.basename(
|
||||
mw.M('backup').add('type,name,pid,filename,addtime,size', (3, os.path.basename(
|
||||
filename), pid, filename, endDate, os.path.getsize(filename)))
|
||||
log = "数据库[" + name + "]备份成功,用时[" + str(round(outTime, 2)) + "]秒"
|
||||
mw.writeLog('计划任务', log)
|
||||
@@ -97,7 +97,7 @@ class backupTools:
|
||||
|
||||
# 清理多余备份
|
||||
backups = mw.M('backup').where(
|
||||
'type=? and pid=?', ('1', pid)).field('id,filename').select()
|
||||
'type=? and pid=?', ('3', pid)).field('id,filename').select()
|
||||
|
||||
num = len(backups) - int(count)
|
||||
if num > 0:
|
||||
|
||||
+46
-11
@@ -31,8 +31,13 @@ def getServerDir():
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return '/tmp/' + getPluginName()
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
return '/etc/rc.d/' + getPluginName()
|
||||
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
@@ -88,7 +93,7 @@ def checkArgs(data, ck=[]):
|
||||
|
||||
def status():
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
"ps aux|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
@@ -113,8 +118,8 @@ def initDreplace():
|
||||
# systemd
|
||||
systemDir = mw.systemdCfgDir()
|
||||
systemService = systemDir + '/memcached.service'
|
||||
systemServiceTpl = getPluginDir() + '/init.d/memcached.service.tpl'
|
||||
if os.path.exists(systemDir) and not os.path.exists(systemService):
|
||||
systemServiceTpl = getPluginDir() + '/init.d/memcached.service.tpl'
|
||||
service_path = mw.getServerDir()
|
||||
se_content = mw.readFile(systemServiceTpl)
|
||||
se_content = se_content.replace('{$SERVER_PATH}', service_path)
|
||||
@@ -137,13 +142,20 @@ def initDreplace():
|
||||
def memOp(method):
|
||||
file = initDreplace()
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
data = mw.execShell('systemctl ' + method + ' ' + getPluginName())
|
||||
current_os = mw.getOs()
|
||||
if current_os == "darwin":
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if current_os.startswith("freebsd"):
|
||||
data = mw.execShell('service ' + getPluginName() + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
data = mw.execShell('systemctl ' + method + ' ' + getPluginName())
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -226,9 +238,15 @@ def saveConf():
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
return 'ok'
|
||||
|
||||
shell_cmd = 'systemctl status ' + \
|
||||
getPluginName() + ' | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(shell_cmd)
|
||||
@@ -238,17 +256,34 @@ def initdStatus():
|
||||
|
||||
|
||||
def initdInstall():
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
# freebsd initd install
|
||||
if current_os.startswith('freebsd'):
|
||||
import shutil
|
||||
source_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="YES"')
|
||||
return 'ok'
|
||||
|
||||
mw.execShell('systemctl enable ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="NO"')
|
||||
return 'ok'
|
||||
|
||||
mw.execShell('systemctl disable ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"title": "Memcached",
|
||||
"shell": "install.sh",
|
||||
"versions":["1.6"],
|
||||
"updates":["1.6.15"],
|
||||
"updates":["1.6.21"],
|
||||
"tip": "soft",
|
||||
"checks": "server/memcached",
|
||||
"path":"server/memcached",
|
||||
|
||||
@@ -30,7 +30,7 @@ app_start(){
|
||||
|
||||
echo "Starting mongodb server..."
|
||||
echo $EXEC -f $CONF
|
||||
$EXEC -f $CONF >> {$SERVER_PATH}/mongodb/logs.pl 2>&1 &
|
||||
$EXEC -f $CONF >> {$SERVER_PATH}/mongodb/logs.pl 1>&1 2>&1 &
|
||||
}
|
||||
|
||||
app_stop(){
|
||||
|
||||
@@ -19,17 +19,31 @@ if [ "$SYS_NAME_LEN" == "1" ];then
|
||||
SYS_NAME=${SYS_NAME}0
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -gt "82" ];then
|
||||
SYS_NAME="82"
|
||||
if [ "$SYS_ARCH" == "aarch64" ];then
|
||||
if [ "$SYS_NAME" -gt "82" ];then
|
||||
SYS_NAME="82"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "62" ];then
|
||||
SYS_NAME="62"
|
||||
fi
|
||||
else
|
||||
|
||||
if [ "$SYS_NAME" -gt "80" ];then
|
||||
SYS_NAME="80"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "70" ];then
|
||||
SYS_NAME="70"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "62" ];then
|
||||
SYS_NAME="62"
|
||||
fi
|
||||
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-rhel82-4.4.23.tgz
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.23.tgz
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-4.4.23.tgz
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-rhel82-4.4.23.tgz
|
||||
# https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-4.4.23.tgz
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
mkdir -p $MG_DIR
|
||||
|
||||
@@ -19,12 +19,17 @@ if [ "$SYS_NAME_LEN" == "1" ];then
|
||||
SYS_NAME=${SYS_NAME}0
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -gt "82" ];then
|
||||
if [ "$SYS_ARCH" == "aarch64" ];then
|
||||
SYS_NAME="82"
|
||||
fi
|
||||
else
|
||||
|
||||
if [ "$SYS_NAME" -lt "70" ];then
|
||||
SYS_NAME="70"
|
||||
if [ "$SYS_NAME" -gt "80" ];then
|
||||
SYS_NAME="80"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "70" ];then
|
||||
SYS_NAME="70"
|
||||
fi
|
||||
fi
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
|
||||
@@ -19,12 +19,23 @@ if [ "$SYS_NAME_LEN" == "1" ];then
|
||||
SYS_NAME=${SYS_NAME}0
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -gt "90" ];then
|
||||
SYS_NAME="82"
|
||||
fi
|
||||
if [ "$SYS_ARCH" == "aarch64" ];then
|
||||
if [ "$SYS_NAME" -gt "90" ];then
|
||||
SYS_NAME="90"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "70" ];then
|
||||
SYS_NAME="70"
|
||||
if [ "$SYS_NAME" -lt "82" ];then
|
||||
SYS_NAME="82"
|
||||
fi
|
||||
else
|
||||
|
||||
if [ "$SYS_NAME" -gt "90" ];then
|
||||
SYS_NAME="90"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "70" ];then
|
||||
SYS_NAME="70"
|
||||
fi
|
||||
fi
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
|
||||
@@ -19,12 +19,23 @@ if [ "$SYS_NAME_LEN" == "1" ];then
|
||||
SYS_NAME=${SYS_NAME}0
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -gt "90" ];then
|
||||
SYS_NAME="82"
|
||||
fi
|
||||
if [ "$SYS_ARCH" == "aarch64" ];then
|
||||
if [ "$SYS_NAME" -gt "90" ];then
|
||||
SYS_NAME="90"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "70" ];then
|
||||
SYS_NAME="70"
|
||||
if [ "$SYS_NAME" -lt "82" ];then
|
||||
SYS_NAME="82"
|
||||
fi
|
||||
else
|
||||
|
||||
if [ "$SYS_NAME" -gt "90" ];then
|
||||
SYS_NAME="90"
|
||||
fi
|
||||
|
||||
if [ "$SYS_NAME" -lt "70" ];then
|
||||
SYS_NAME="70"
|
||||
fi
|
||||
fi
|
||||
|
||||
MG_DIR=$serverPath/source/mongodb
|
||||
|
||||
@@ -0,0 +1,825 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
import io
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
import oauthlib
|
||||
import requests
|
||||
import datetime
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
DEBUG = False
|
||||
|
||||
|
||||
def setDebug(d=False):
|
||||
DEBUG = d
|
||||
|
||||
|
||||
class UnauthorizedError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ObjectNotFoundError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class msodclient:
|
||||
|
||||
plugin_dir = ''
|
||||
server_dir = ''
|
||||
credential_file = 'credentials.json'
|
||||
user_conf = "user.conf"
|
||||
token_file = 'token.pickle'
|
||||
|
||||
def __init__(self, plugin_dir, server_dir):
|
||||
self.plugin_dir = plugin_dir
|
||||
self.server_dir = server_dir
|
||||
self.load()
|
||||
|
||||
def setDebug(self, d=False):
|
||||
DEBUG = d
|
||||
|
||||
def load(self):
|
||||
credential_path = os.path.join(self.plugin_dir, self.credential_file)
|
||||
credential = json.loads(mw.readFile(credential_path))
|
||||
# print(credential)
|
||||
self.credential = credential["onedrive-international"]
|
||||
|
||||
self.authorize_url = '{0}{1}'.format(
|
||||
self.credential['authority'],
|
||||
self.credential['authorize_endpoint'])
|
||||
self.token_url = '{0}{1}'.format(
|
||||
self.credential['authority'],
|
||||
self.credential['token_endpoint'])
|
||||
|
||||
self.token_path = os.path.join(self.server_dir, self.token_file)
|
||||
self.root_uri = self.credential["api_uri"] + "/me/drive/root"
|
||||
|
||||
self.backup_path = 'backup'
|
||||
|
||||
def store_token(self, token):
|
||||
"""存储token"""
|
||||
enstr = mw.enDoubleCrypt('msodc', json.dumps(token))
|
||||
mw.writeFile(self.token_path, enstr)
|
||||
return True
|
||||
|
||||
def get_store_token(self):
|
||||
rdata = mw.readFile(self.token_path)
|
||||
destr = mw.deDoubleCrypt('msodc', rdata)
|
||||
return json.loads(destr)
|
||||
|
||||
def clear_token(self):
|
||||
"""清除token记录"""
|
||||
try:
|
||||
if os.path.isfile(self.token_path):
|
||||
os.remove(self.token_path)
|
||||
except:
|
||||
if DEBUG:
|
||||
print("清除token失败。")
|
||||
|
||||
def refresh_token(self, origin_token):
|
||||
"""刷新token"""
|
||||
|
||||
os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1'
|
||||
os.environ['OAUTHLIB_IGNORE_SCOPE_CHANGE'] = '1'
|
||||
refresh_token = origin_token["refresh_token"]
|
||||
aad_auth = OAuth2Session(
|
||||
self.credential["client_id"],
|
||||
scope=self.credential["scopes"],
|
||||
redirect_uri=self.credential["redirect_uri"])
|
||||
|
||||
new_token = aad_auth.refresh_token(
|
||||
self.token_url,
|
||||
refresh_token=refresh_token,
|
||||
client_id=self.credential["client_id"],
|
||||
client_secret=self.credential["client_secret"])
|
||||
return new_token
|
||||
|
||||
def get_token_from_authorized_url(self, authorized_url, expected_state=None):
|
||||
"""通过授权编码获取访问token"""
|
||||
|
||||
# 忽略token scope与已请求的scope不一致
|
||||
os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1'
|
||||
os.environ['OAUTHLIB_IGNORE_SCOPE_CHANGE'] = '1'
|
||||
aad_auth = OAuth2Session(self.credential["client_id"],
|
||||
state=expected_state,
|
||||
scope=self.credential['scopes'],
|
||||
redirect_uri=self.credential['redirect_uri'])
|
||||
|
||||
token = aad_auth.fetch_token(
|
||||
self.token_url,
|
||||
client_secret=self.credential["client_secret"],
|
||||
authorization_response=authorized_url)
|
||||
|
||||
return token
|
||||
|
||||
def get_token(self):
|
||||
token = self.get_store_token()
|
||||
now = time.time()
|
||||
|
||||
expire_time = token["expires_at"] - 300
|
||||
if now >= expire_time:
|
||||
new_token = self.refresh_token(token)
|
||||
self.store_token(new_token)
|
||||
return new_token
|
||||
|
||||
return token
|
||||
|
||||
def get_sign_in_url(self):
|
||||
"""生成签名地址"""
|
||||
|
||||
# Initialize the OAuth client
|
||||
aad_auth = OAuth2Session(self.credential["client_id"],
|
||||
scope=self.credential['scopes'],
|
||||
redirect_uri=self.credential['redirect_uri'])
|
||||
|
||||
sign_in_url, state = aad_auth.authorization_url(self.authorize_url,
|
||||
prompt='login')
|
||||
|
||||
return sign_in_url, state
|
||||
|
||||
def get_authorized_header(self):
|
||||
token_obj = self.get_token()
|
||||
token = token_obj["access_token"]
|
||||
header = {
|
||||
"Authorization": "Bearer " + token,
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '
|
||||
'AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||
'Chrome/67.0.3396.99 Safari/537.36'
|
||||
}
|
||||
return header
|
||||
|
||||
def get_user_from_ms(self):
|
||||
"""查询用户信息"""
|
||||
try:
|
||||
headers = self.get_authorized_header()
|
||||
user_api_base = self.credential["api_uri"] + "/me"
|
||||
# select_user_info_uri = self.build_uri(base=user_api_base)
|
||||
response = requests.get(user_api_base, headers=headers)
|
||||
if DEBUG:
|
||||
print("Debug get user:")
|
||||
print(response.status_code)
|
||||
print(response.text)
|
||||
if response.status_code == 200:
|
||||
response_data = response.json()
|
||||
user_principal_name = response_data["userPrincipalName"]
|
||||
return user_principal_name
|
||||
except oauthlib.oauth2.rfc6749.errors.InvalidGrantError:
|
||||
self.clear_auth()
|
||||
if DEBUG:
|
||||
print("用户授权已过期。")
|
||||
return None
|
||||
|
||||
def clear_auth(self):
|
||||
self.clear_token()
|
||||
self.clear_user()
|
||||
|
||||
def clear_user(self):
|
||||
try:
|
||||
# 清空user
|
||||
path = os.path.join(self.server_dir, self.user_conf)
|
||||
if os.path.isfile(path):
|
||||
os.remove(path)
|
||||
except:
|
||||
if DEBUG:
|
||||
print("清除user失败。")
|
||||
|
||||
def store_user(self):
|
||||
"""更新并存储用户信息"""
|
||||
user = self.get_user_from_ms()
|
||||
if user:
|
||||
path = os.path.join(self.server_dir, self.user_conf)
|
||||
mw.writeFile(path, user)
|
||||
else:
|
||||
raise RuntimeError("无法获取用户信息。")
|
||||
|
||||
# --------------------- 文件操作功能 ----------------------
|
||||
|
||||
# 取目录路径
|
||||
def get_path(self, path):
|
||||
sep = ":"
|
||||
if path == '/':
|
||||
path = ''
|
||||
if path[-1:] == '/':
|
||||
path = path[:-1]
|
||||
if path[:1] != "/" and path[:1] != sep:
|
||||
path = "/" + path
|
||||
if path == '/':
|
||||
path = ''
|
||||
# if path[:1] != sep:
|
||||
# path = sep + path
|
||||
try:
|
||||
from urllib.parse import quote
|
||||
except:
|
||||
from urllib import quote
|
||||
# path = quote(path)
|
||||
|
||||
return path.replace('//', '/')
|
||||
|
||||
def build_uri(self, path="", operate=None, base=None):
|
||||
"""构建请求URL
|
||||
|
||||
API请求URI格式参考:
|
||||
https://graph.microsoft.com/v1.0/me/drive/root:/bt_backup/:content
|
||||
--------------------------------------------- ---------- --------
|
||||
base path operate
|
||||
各部分之间用“:”连接。
|
||||
:param path 子资源路径
|
||||
:param operate 对文件进行的操作,比如content,children
|
||||
:return 请求url
|
||||
"""
|
||||
|
||||
if base is None:
|
||||
base = self.root_uri
|
||||
path = self.get_path(path)
|
||||
sep = ":"
|
||||
if operate:
|
||||
if operate[:1] != "/":
|
||||
operate = "/" + operate
|
||||
|
||||
if path:
|
||||
uri = base + sep + path
|
||||
if operate:
|
||||
uri += sep + operate
|
||||
else:
|
||||
uri = base
|
||||
if operate:
|
||||
uri += operate
|
||||
|
||||
return uri
|
||||
|
||||
def get_list(self, path="/"):
|
||||
"""获取存储空间中的所有文件对象"""
|
||||
|
||||
list_uri = self.build_uri(path, operate="/children")
|
||||
if DEBUG:
|
||||
print("List uri:")
|
||||
print(list_uri)
|
||||
|
||||
data = []
|
||||
response = requests.get(list_uri, headers=self.get_authorized_header())
|
||||
status_code = response.status_code
|
||||
if status_code == 200:
|
||||
if DEBUG:
|
||||
print("DEBUG:")
|
||||
print(response.json())
|
||||
response_data = response.json()
|
||||
drive_items = response_data["value"]
|
||||
|
||||
for item in drive_items:
|
||||
tmp = {}
|
||||
tmp['name'] = item["name"]
|
||||
tmp['size'] = item["size"]
|
||||
if "folder" in item:
|
||||
# print("{} is folder:".format(item["name"]))
|
||||
# print(item["folder"])
|
||||
tmp["type"] = None
|
||||
tmp['download'] = ""
|
||||
if "file" in item:
|
||||
tmp["type"] = "File"
|
||||
tmp['download'] = item["@microsoft.graph.downloadUrl"]
|
||||
# print("{} is file:".format(item["name"]))
|
||||
# print(item["file"])
|
||||
|
||||
formats = ["%Y-%m-%dT%H:%M:%S.%fZ", "%Y-%m-%dT%H:%M:%SZ"]
|
||||
t = None
|
||||
for time_format in formats:
|
||||
try:
|
||||
t = datetime.datetime.strptime(
|
||||
item["lastModifiedDateTime"], time_format)
|
||||
break
|
||||
except:
|
||||
continue
|
||||
t += datetime.timedelta(hours=8)
|
||||
ts = int(
|
||||
(time.mktime(t.timetuple()) + t.microsecond / 1000000.0))
|
||||
tmp['time'] = ts
|
||||
data.append(tmp)
|
||||
|
||||
mlist = {'path': path, 'list': data}
|
||||
return mlist
|
||||
|
||||
def get_object(self, object_name):
|
||||
"""查询对象信息"""
|
||||
try:
|
||||
get_uri = self.build_uri(path=object_name)
|
||||
if DEBUG:
|
||||
print("Get uri:")
|
||||
print(get_uri)
|
||||
response = requests.get(get_uri,
|
||||
headers=self.get_authorized_header())
|
||||
if response.status_code in [200]:
|
||||
response_data = response.json()
|
||||
if DEBUG:
|
||||
print("Object info:")
|
||||
print(response_data)
|
||||
return response_data
|
||||
if response.status_code == 404:
|
||||
if DEBUG:
|
||||
print("对象不存在。")
|
||||
if DEBUG:
|
||||
print("Get Object debug:")
|
||||
print(response.status_code)
|
||||
print(response.text)
|
||||
except Exception as e:
|
||||
if DEBUG:
|
||||
print("Get object has excepiton:")
|
||||
print(e)
|
||||
return None
|
||||
|
||||
def is_folder(self, obj):
|
||||
if "folder" in obj:
|
||||
return True
|
||||
return False
|
||||
|
||||
def delete_object_by_os(self, object_name):
|
||||
"""删除对象
|
||||
|
||||
:param object_name:
|
||||
:return: True 删除成功
|
||||
其他 删除失败
|
||||
"""
|
||||
obj = self.get_object(object_name)
|
||||
if obj is None:
|
||||
if DEBUG:
|
||||
print("对象不存在,删除操作未执行。")
|
||||
return True
|
||||
if self.is_folder(obj):
|
||||
child_count = obj["folder"]["childCount"]
|
||||
if child_count > 0:
|
||||
if DEBUG:
|
||||
print("文件夹不是空文件夹无法删除。")
|
||||
return False
|
||||
|
||||
headers = self.get_authorized_header()
|
||||
delete_uri = self.build_uri(object_name)
|
||||
response = requests.delete(delete_uri, headers=headers)
|
||||
if response.status_code == 204:
|
||||
if DEBUG:
|
||||
print("对象: {} 已被删除。".format(object_name))
|
||||
return True
|
||||
return False
|
||||
|
||||
def delete_object(self, object_name, retries=2):
|
||||
"""删除对象
|
||||
|
||||
:param object_name:
|
||||
:param retries: 重试次数,默认2次
|
||||
:return: True 删除成功
|
||||
其他 删除失败
|
||||
"""
|
||||
|
||||
try:
|
||||
return self.delete_object_by_os(object_name)
|
||||
except Exception as e:
|
||||
print("删除文件异常:")
|
||||
print(e)
|
||||
|
||||
# 重试
|
||||
if retries > 0:
|
||||
print("重新尝试删除文件{}...".format(object_name))
|
||||
return self.delete_object(
|
||||
object_name,
|
||||
retries=retries - 1)
|
||||
return False
|
||||
|
||||
def build_object_name(self, data_type, file_name):
|
||||
"""根据数据类型构建对象存储名称
|
||||
|
||||
:param data_type:
|
||||
:param file_name:
|
||||
:return:
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
prefix_dict = {
|
||||
"site": "web",
|
||||
"database": "db",
|
||||
"path": "path",
|
||||
}
|
||||
|
||||
if not prefix_dict.get(data_type):
|
||||
print("data_type 类型错误!!!")
|
||||
exit(1)
|
||||
|
||||
file_regx = prefix_dict.get(data_type) + "_(.+)_20\d+_\d+(?:\.|_)"
|
||||
sub_search = re.search(file_regx, file_name)
|
||||
sub_path_name = ""
|
||||
if sub_search:
|
||||
sub_path_name = sub_search.groups()[0]
|
||||
sub_path_name += '/'
|
||||
|
||||
# 构建OS存储路径
|
||||
object_name = self.backup_path + '/' + \
|
||||
data_type + '/' + \
|
||||
sub_path_name + \
|
||||
file_name
|
||||
|
||||
if object_name[:1] == "/":
|
||||
object_name = object_name[1:]
|
||||
|
||||
return object_name
|
||||
|
||||
def delete_file(self, file_name, data_type=None):
|
||||
"""删除文件
|
||||
|
||||
根据传入的文件名称和文件数据类型构建对象名称,再删除
|
||||
:param file_name:
|
||||
:param data_type: 数据类型 site/database/path
|
||||
:return: True 删除成功
|
||||
其他 删除失败
|
||||
"""
|
||||
|
||||
object_name = self.build_object_name(data_type, file_name)
|
||||
return self.delete_object(object_name)
|
||||
|
||||
def create_dir_by_step(self, parent_folder, sub_folder):
|
||||
create_uri = self.build_uri(path=parent_folder, operate="/children")
|
||||
|
||||
if DEBUG:
|
||||
print("Create dir uri:")
|
||||
print(create_uri)
|
||||
post_data = {
|
||||
"name": sub_folder,
|
||||
"folder": {"@odata.type": "microsoft.graph.folder"},
|
||||
"@microsoft.graph.conflictBehavior": "fail"
|
||||
}
|
||||
|
||||
headers = self.get_authorized_header()
|
||||
headers.update({"Content-type": "application/json"})
|
||||
response = requests.post(create_uri, headers=headers, json=post_data)
|
||||
if response.status_code in [201, 409]:
|
||||
if DEBUG:
|
||||
if response.status_code == 409:
|
||||
print("目录:{} 已经存在。".format(sub_folder))
|
||||
return True
|
||||
else:
|
||||
if DEBUG:
|
||||
print("目录:{} 创建失败:".format(sub_folder))
|
||||
print(response.status_code)
|
||||
print(response.text)
|
||||
return False
|
||||
|
||||
def create_dir(self, dir_name):
|
||||
"""创建远程目录
|
||||
|
||||
# API 请求结构
|
||||
# POST /me/drive/root/children
|
||||
# or
|
||||
# POST /me/drive/root:/bt_backup/:/children
|
||||
# Content - Type: application / json
|
||||
|
||||
# {
|
||||
# "name": "New Folder",
|
||||
# "folder": {},
|
||||
# "@microsoft.graph.conflictBehavior": "rename"
|
||||
# }
|
||||
|
||||
# Response: status code == 201 新创建/ 409 已存在
|
||||
# @microsoft.graph.conflictBehavior: fail/rename/replace
|
||||
|
||||
:param dir_name: 目录名称
|
||||
:param parent_id: 父目录ID
|
||||
:return: True/False
|
||||
"""
|
||||
|
||||
dir_name = self.get_path(dir_name.strip())
|
||||
onedrive_business_reserved = r"[\*<>?:|#%]"
|
||||
if re.search(onedrive_business_reserved, dir_name) \
|
||||
or dir_name[-1] == "." or dir_name[:1] == "~":
|
||||
if DEBUG:
|
||||
print("文件夹名称包含非法字符。")
|
||||
return False
|
||||
|
||||
parent_folder = self.get_path(os.path.split(dir_name)[0])
|
||||
sub_folder = os.path.split(dir_name)[1]
|
||||
|
||||
# print("create_dir:", dir_name)
|
||||
obj = self.get_object(dir_name)
|
||||
# 判断对象是否存在
|
||||
if obj is None:
|
||||
if not self.create_dir_by_step(parent_folder, sub_folder):
|
||||
|
||||
# 兼容OneDrive 商业版文件夹创建
|
||||
folder_array = dir_name.split("/")
|
||||
parent_folder = self.get_path(folder_array[0])
|
||||
for i in range(1, len(folder_array)):
|
||||
sub_folder = folder_array[i]
|
||||
if DEBUG:
|
||||
print("Parent folder: {}".format(parent_folder))
|
||||
print("Sub folder: {}".format(sub_folder))
|
||||
if self.create_dir_by_step(parent_folder, sub_folder):
|
||||
parent_folder += "/" + folder_array[i]
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
else:
|
||||
if self.is_folder(obj):
|
||||
if DEBUG:
|
||||
print("文件夹已存在。")
|
||||
return True
|
||||
|
||||
def resumable_upload(self,
|
||||
local_file_name,
|
||||
object_name=None,
|
||||
progress_callback=None,
|
||||
progress_file_name=None,
|
||||
multipart_threshold=1024 * 1024 * 2,
|
||||
part_size=1024 * 1024 * 5,
|
||||
store_dir="/tmp",
|
||||
auto_cancel=True,
|
||||
retries=5,
|
||||
):
|
||||
"""断点续传
|
||||
|
||||
:param local_file_name: 本地文件名称
|
||||
:param object_name: 指定OS中存储的对象名称
|
||||
:param part_size: 指定分片上传的每个分片的大小。必须是320*1024的整数倍。
|
||||
:param multipart_threshold: 文件长度大于该值时,则用分片上传。
|
||||
:param progress_callback: 进度回调函数,默认是把进度信息输出到标准输出。
|
||||
:param progress_file_name: 进度信息保存文件,进度格式参见[report_progress]
|
||||
:param store_dir: 上传分片存储目录, 默认/tmp。
|
||||
:param auto_cancel: 当备份失败是否自动取消上传记录
|
||||
:param retries: 上传重试次数
|
||||
:return: True上传成功/False or None上传失败
|
||||
"""
|
||||
|
||||
try:
|
||||
file_size_separation_value = 4 * 1024 * 1024
|
||||
if part_size % 320 != 0:
|
||||
if DEBUG:
|
||||
print("Part size 必须是320的整数倍。")
|
||||
return False
|
||||
|
||||
if object_name is None:
|
||||
temp_file_name = os.path.split(local_file_name)[1]
|
||||
object_name = os.path.join(self.backup_path, temp_file_name)
|
||||
|
||||
# if progress_file_name:
|
||||
# os.environ[PROGRESS_FILE_NAME] = progress_file_name
|
||||
# progress_callback = report_progress
|
||||
|
||||
print("|-正在上传到 {}...".format(object_name))
|
||||
dir_name = os.path.split(object_name)[0]
|
||||
if not self.create_dir(dir_name):
|
||||
if DEBUG:
|
||||
print("目录创建失败!")
|
||||
return False
|
||||
|
||||
local_file_size = os.path.getsize(local_file_name)
|
||||
# if local_file_size < file_size_separation_value:
|
||||
if False:
|
||||
# 小文件上传
|
||||
upload_uri = self.build_uri(path=object_name,
|
||||
operate="/content")
|
||||
if DEBUG:
|
||||
print("Upload uri:")
|
||||
print(upload_uri)
|
||||
headers = self.get_authorized_header()
|
||||
# headers.update({
|
||||
# "Content-Type": "application/octet-stream"
|
||||
# })
|
||||
# files = {"file": (object_name, open(local_file_name, "rb"))}
|
||||
file_data = open(local_file_name, "rb")
|
||||
response = requests.put(upload_uri,
|
||||
headers=headers,
|
||||
data=file_data)
|
||||
if DEBUG:
|
||||
print("status code:")
|
||||
print(response.status_code)
|
||||
# print(response.text)
|
||||
if response.status_code in [201, 200]:
|
||||
if DEBUG:
|
||||
print("文件上传成功!")
|
||||
return True
|
||||
else:
|
||||
# 大文件上传
|
||||
|
||||
# 1. 创建上传session
|
||||
create_session_uri = self.build_uri(
|
||||
path=object_name,
|
||||
operate="createUploadSession")
|
||||
headers = self.get_authorized_header()
|
||||
response = requests.post(create_session_uri, headers=headers)
|
||||
if response.status_code == 200:
|
||||
response_data = response.json()
|
||||
upload_url = response_data["uploadUrl"]
|
||||
expiration_date_time = response_data["expirationDateTime"]
|
||||
|
||||
if DEBUG:
|
||||
print("上传session已建立。")
|
||||
print("Upload url: {}".format(upload_url))
|
||||
print("Expiration datetime: {}".format(
|
||||
expiration_date_time))
|
||||
|
||||
# 2. 分片上传文件
|
||||
requests.adapters.DEFAULT_RETRIES = 1
|
||||
session = requests.session()
|
||||
session.keep_alive = False
|
||||
|
||||
# 开始分片上传
|
||||
import math
|
||||
parts = int(math.ceil(local_file_size / part_size))
|
||||
for i in range(parts):
|
||||
if DEBUG:
|
||||
if i == parts - 1:
|
||||
num = "最后"
|
||||
else:
|
||||
num = "第{}".format(i + 1)
|
||||
print("正在上传{}部分...".format(num))
|
||||
|
||||
upload_range_start = i * part_size
|
||||
upload_range_end = min(upload_range_start + part_size,
|
||||
local_file_size)
|
||||
content_length = upload_range_end - upload_range_start
|
||||
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '
|
||||
'AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||
'Chrome/67.0.3396.99 Safari/537.36'
|
||||
}
|
||||
# 开发记录
|
||||
# Content-Range和标准的http请求头中的Range作用有所不同
|
||||
# Content-Range是OneDrive自定义的分片上传标识,格式也不一样
|
||||
headers.update({
|
||||
"Content-Length": repr(content_length),
|
||||
"Content-Range": "bytes {}-{}/{}".format(
|
||||
upload_range_start,
|
||||
upload_range_end - 1,
|
||||
local_file_size),
|
||||
"Content-Type": "application/octet-stream"
|
||||
})
|
||||
|
||||
if DEBUG:
|
||||
print("Headers:")
|
||||
print(headers)
|
||||
|
||||
'''# TODO 优化read的读取占用内存'''
|
||||
f = io.open(local_file_name, "rb")
|
||||
f.seek(upload_range_start)
|
||||
upload_data = f.read(content_length)
|
||||
sub_response = session.put(upload_url,
|
||||
headers=headers,
|
||||
data=upload_data)
|
||||
|
||||
expected_status_code = [200, 201, 202]
|
||||
if sub_response.status_code in expected_status_code:
|
||||
if DEBUG:
|
||||
print("Response status code: {}, "
|
||||
"bytes {}-{} 已上传成功。".format(
|
||||
sub_response.status_code,
|
||||
upload_range_start,
|
||||
upload_range_end - 1)
|
||||
)
|
||||
print(sub_response.text)
|
||||
if sub_response.status_code in [200, 201]:
|
||||
if DEBUG:
|
||||
print("文件 {} 上传成功。".format(object_name))
|
||||
return True
|
||||
else:
|
||||
print(sub_response.status_code)
|
||||
print(sub_response.text)
|
||||
_error_msg = "Bytes {}-{} 分片上传失败。".format(
|
||||
upload_range_start,
|
||||
upload_range_end
|
||||
)
|
||||
if self.error_msg:
|
||||
self.error_msg += r"\n"
|
||||
self.error_msg += _error_msg
|
||||
raise RuntimeError(_error_msg)
|
||||
|
||||
time.sleep(0.5)
|
||||
else:
|
||||
raise RuntimeError("session创建失败。")
|
||||
|
||||
except UnauthorizedError as e:
|
||||
_error_msg = str(e)
|
||||
if self.error_msg:
|
||||
self.error_msg += r"\n"
|
||||
self.error_msg += _error_msg
|
||||
print(_error_msg)
|
||||
return False
|
||||
except Exception as e:
|
||||
print("文件上传出现错误:")
|
||||
print(e)
|
||||
|
||||
if self.error_msg:
|
||||
self.error_msg += r"\n"
|
||||
self.error_msg += "文件{}上传出现错误:{}".format(object_name, str(e))
|
||||
|
||||
try:
|
||||
if upload_url:
|
||||
if DEBUG:
|
||||
print("正在清理上传session.")
|
||||
session.delete(upload_url)
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
try:
|
||||
f.close()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
session.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
# 重试断点续传
|
||||
if retries > 0:
|
||||
print("重试上传文件....")
|
||||
return self.resumable_upload(
|
||||
local_file_name,
|
||||
object_name=object_name,
|
||||
store_dir=store_dir,
|
||||
part_size=part_size,
|
||||
multipart_threshold=multipart_threshold,
|
||||
progress_callback=progress_callback,
|
||||
progress_file_name=progress_file_name,
|
||||
retries=retries - 1,
|
||||
)
|
||||
else:
|
||||
if self.error_msg:
|
||||
self.error_msg += r"\n"
|
||||
self.error_msg += "文件{}上传失败。".format(object_name)
|
||||
return False
|
||||
|
||||
def upload_abs_file(self, file_name, remote_dir, *args, **kwargs):
|
||||
"""按照数据类型上传文件
|
||||
|
||||
:param file_name: 上传文件名称
|
||||
:param data_type: 数据类型 site/database/path
|
||||
:return: True/False
|
||||
"""
|
||||
try:
|
||||
import re
|
||||
# 根据数据类型提取子分类名称
|
||||
# 比如data_type=database,子分类名称是数据库的名称。
|
||||
# 提取方式是从file_name中利用正则规则去提取。
|
||||
self.error_msg = ""
|
||||
|
||||
file_name = os.path.abspath(file_name)
|
||||
temp_name = os.path.split(file_name)[1]
|
||||
object_name = 'backup/' + temp_name
|
||||
|
||||
print(file_name)
|
||||
print(object_name)
|
||||
|
||||
return self.resumable_upload(file_name,
|
||||
object_name=object_name,
|
||||
*args,
|
||||
**kwargs)
|
||||
except Exception as e:
|
||||
if self.error_msg:
|
||||
self.error_msg += r"\n"
|
||||
self.error_msg += "文件上传出现错误:{}".format(str(e))
|
||||
return False
|
||||
|
||||
def upload_file(self, file_name, data_type, *args, **kwargs):
|
||||
"""按照数据类型上传文件
|
||||
|
||||
:param file_name: 上传文件名称
|
||||
:param data_type: 数据类型 site/database/path
|
||||
:return: True/False
|
||||
"""
|
||||
try:
|
||||
import re
|
||||
# 根据数据类型提取子分类名称
|
||||
# 比如data_type=database,子分类名称是数据库的名称。
|
||||
# 提取方式是从file_name中利用正则规则去提取。
|
||||
self.error_msg = ""
|
||||
|
||||
if not file_name or not data_type:
|
||||
_error_msg = "文件参数错误。"
|
||||
print(_error_msg)
|
||||
self.error_msg = _error_msg
|
||||
return False
|
||||
|
||||
file_name = os.path.abspath(file_name)
|
||||
temp_name = os.path.split(file_name)[1]
|
||||
object_name = self.build_object_name(data_type, temp_name)
|
||||
|
||||
# dir_name = os.path.dirname(object_name)
|
||||
# self.create_dir(dir_name)
|
||||
if DEBUG:
|
||||
print(file_name)
|
||||
print(object_name)
|
||||
print(dir_name)
|
||||
|
||||
return self.resumable_upload(file_name,
|
||||
object_name=object_name,
|
||||
*args,
|
||||
**kwargs)
|
||||
except Exception as e:
|
||||
if self.error_msg:
|
||||
self.error_msg += r"\n"
|
||||
self.error_msg += "文件上传出现错误:{}".format(str(e))
|
||||
return False
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"onedrive-international": {
|
||||
"client_id": "08125e6b-6502-4ac9-9548-ad682f00848d",
|
||||
"client_secret": "0WA8Q~sZkZFZKv50ryP4ux~.fpVtbHw7BuTZmbQB",
|
||||
"authority": "https://login.microsoftonline.com/common",
|
||||
"token_endpoint": "/oauth2/v2.0/token",
|
||||
"authorize_endpoint": "/oauth2/v2.0/authorize",
|
||||
"scopes": "offline_access Files.ReadWrite.All User.Read",
|
||||
"redirect_uri": "http://localhost",
|
||||
"api_uri": "https://graph.microsoft.com/v1.0"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,310 @@
|
||||
<style>
|
||||
.upyunCon {
|
||||
height: 428px;
|
||||
}
|
||||
|
||||
.up-place {
|
||||
height: 62px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.up-place .btn {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.up-place .place-input {
|
||||
background-color: #f3f3f3;
|
||||
border: 1px solid #ccc;
|
||||
height: 30px;
|
||||
line-height: 28px;
|
||||
overflow: hidden;
|
||||
margin: 1px 0 0 -1px;
|
||||
width: 340px;
|
||||
}
|
||||
|
||||
.place-input ul {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.place-input ul li {
|
||||
background: url("/static/img/ico/ico-ltr.png") no-repeat right center;
|
||||
float: left;
|
||||
padding-left: 10px;
|
||||
padding-right: 18px;
|
||||
}
|
||||
|
||||
.place-input ul li a {
|
||||
height: 28px;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.upyunlist {
|
||||
height: 516px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.up-bottom {
|
||||
background-color: #fafafa;
|
||||
border-top: 1px solid #eee;
|
||||
bottom: 0;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.up-use {
|
||||
line-height: 50px
|
||||
}
|
||||
|
||||
.list-list .cursor span {
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
.btn-title {
|
||||
margin-top: 1px
|
||||
}
|
||||
|
||||
.tip {
|
||||
font-size: 10px;
|
||||
font-style: oblique;
|
||||
color: green;
|
||||
}
|
||||
</style>
|
||||
<div class="upyunCon">
|
||||
<div class="up-place pd15">
|
||||
<button id="backBtn" class="btn btn-default btn-sm glyphicon glyphicon-arrow-left pull-left" title="后退"></button>
|
||||
<input id="myPath" style="display:none;" type="text" value="">
|
||||
<div class="place-input pull-left">
|
||||
<div style="width:1400px;height:28px"><ul></ul></div>
|
||||
</div>
|
||||
<button class="refreshBtn btn btn-default btn-sm glyphicon glyphicon-refresh pull-left mr20" title="刷新" style="margin-left:-1px;"></button>
|
||||
<button class="btn btn-default btn-sm pull-right btn-title" onclick="authApi()">授权</button>
|
||||
<button class="btn btn-default btn-sm pull-right mr20 btn-title" onclick="createDir()">新建文件夹</button>
|
||||
</div>
|
||||
|
||||
<div class="upyunlist pd15">
|
||||
<div class="divtable" style="margin-bottom:15px">
|
||||
<table class="table table-hover">
|
||||
<thead><tr><th>名称</th><th>大小</th><th>更新时间</th><th class="text-right">操作</th></tr></thead>
|
||||
<tbody class="list-list"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style type="text/css">
|
||||
.check_api {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.up-place {
|
||||
height: 62px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.up-place .btn {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.up-place .place-input {
|
||||
background-color: #f3f3f3;
|
||||
border: 1px solid #ccc;
|
||||
height: 30px;
|
||||
line-height: 28px;
|
||||
overflow: hidden;
|
||||
margin: 1px 0 0 -1px;
|
||||
width: 340px;
|
||||
}
|
||||
|
||||
.place-input ul {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.place-input ul li {
|
||||
background: url("/static/img/ico/ico-ltr.png") no-repeat right center;
|
||||
float: left;
|
||||
padding-left: 10px;
|
||||
padding-right: 18px;
|
||||
}
|
||||
|
||||
.place-input ul li a {
|
||||
height: 28px;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.upyunlist {
|
||||
height: 546px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.up-bottom {
|
||||
background-color: #fafafa;
|
||||
border-top: 1px solid #eee;
|
||||
bottom: 0;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.up-use {
|
||||
line-height: 50px
|
||||
}
|
||||
|
||||
.list-list .cursor span {
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
.btn-title {
|
||||
margin-top: 1px
|
||||
}
|
||||
|
||||
.step_item{
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.step_item .serial_box{
|
||||
display: inline-block;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.step_item .serial{
|
||||
width: 70px;
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
float: left;
|
||||
}
|
||||
.step_item .serial span{
|
||||
display: inline-block;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
text-align: center;
|
||||
line-height: 28px;
|
||||
font-size: 11px;
|
||||
border-radius: 50%;
|
||||
color: #20a53a;
|
||||
border: 2px solid #20a53a;
|
||||
}
|
||||
.step_item .serial_title{
|
||||
margin-bottom: 10px;
|
||||
font-size: 15px;
|
||||
line-height: 30px;
|
||||
color: #666;
|
||||
}
|
||||
.step_two_url{
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
width: 380px;
|
||||
/*text-overflow: ellipsis;*/
|
||||
white-space: nowrap;
|
||||
height: 35px;
|
||||
line-height: 35px;
|
||||
margin-right: 15px;
|
||||
border-radius: 2px;
|
||||
padding: 0 10px;
|
||||
float: left;
|
||||
width:360px;
|
||||
padding-right: 35px;
|
||||
}
|
||||
.btn_btlink{
|
||||
display: inline-block;
|
||||
padding: 5px 10px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
border-radius: 3px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
cursor: pointer;
|
||||
border: 1px solid #20a53a;
|
||||
color: #fff;
|
||||
background-color: #20a53a;
|
||||
margin-right:10px;
|
||||
}
|
||||
.btn_btlink:hover{
|
||||
color: #fff;
|
||||
background-color: #10952a;
|
||||
border-color: #398439;
|
||||
}
|
||||
.btn_btlink a:visited{
|
||||
color: #fff;
|
||||
background-color: #10952a;
|
||||
border-color: #398439;
|
||||
}
|
||||
.view_video{
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.view_video ul li{
|
||||
line-height: 20px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.setp_one i{
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
left: 25px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
}
|
||||
.OneDrive{
|
||||
width:465px;
|
||||
height:100px;
|
||||
margin-bottom:10px;
|
||||
}
|
||||
</style>
|
||||
<script type="text/html" id="check_api">
|
||||
<div class="check_api">
|
||||
<div class="step_two">
|
||||
<div class="step_item">
|
||||
<div class="serial"><span>1</span></div>
|
||||
<div class="serial_box">
|
||||
<div class="serial_title">阅读简易操作教程:如何获取Microsoft OneDrive授权?</div>
|
||||
<div class="serial_conter">
|
||||
<div class="view_video">
|
||||
<ul>
|
||||
<li>1. 点击下面第<div class="serial" style="float: none;width: 45px;"><span>2</span></div>步中的 打开授权链接。<li>
|
||||
<li>2. 在新窗口页面上登录Microsoft账号。阅读授权权限,并同意。<li>
|
||||
<li>3. 页面跳转后,将浏览器的地址栏地址复制到第<div class="serial" style="float: none;width: 45px;"><span>3</span></div>步的文本框中。<li>
|
||||
<li>4. 点击 获取授权,随即完成授权。<li>
|
||||
</ul>
|
||||
</div>
|
||||
<hr/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="step_item pb15">
|
||||
<div class="serial"><span>2</span></div>
|
||||
<div class="serial_box">
|
||||
<div class="serial_title">操作1:👇打开授权链接,根据网页提示对插件进行授权。</div>
|
||||
<div class="serial_conter step_two" style="width: 500px;">
|
||||
<input class="bt-input-text mr5 step_two_url" type="text" disabled>
|
||||
<span class="ico-copy mr10" data-copy="" style="vertical-align: middle;cursor: pointer;margin-left: -37px;margin-right: 20px;"></span>
|
||||
<a href="" class="btn_btlink open_btlink" target="_blank" style="padding: 7px 10px;">打开授权链接</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="step_item">
|
||||
<div class="serial"><span>3</span></div>
|
||||
<div class="serial_box">
|
||||
<div class="serial_title">操作2:复制回浏览器跳转后的地址:</div>
|
||||
<div class="serial_conter">
|
||||
<textarea row="3" placeholder="验证URL地址" class="bt-input-text OneDrive" style="resize: none;"/></br>
|
||||
<button type="button" class="btn btn-success btn-sm set_auth_btn">获取授权</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- <script type="text/javascript" src="/plugins/file?name=msonedrive&f=js/msonedrive.js"></script> -->
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=msonedrive&f=js/msonedrive.js", function(){
|
||||
odList('/');
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,351 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
|
||||
|
||||
# print(sys.platform)
|
||||
if sys.platform != "darwin":
|
||||
os.chdir("/www/server/mdserver-web")
|
||||
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
import db
|
||||
|
||||
_ver = sys.version_info
|
||||
is_py2 = (_ver[0] == 2)
|
||||
is_py3 = (_ver[0] == 3)
|
||||
|
||||
DEBUG = False
|
||||
|
||||
if is_py2:
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf-8')
|
||||
|
||||
app_debug = False
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'msonedrive'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def in_array(name, arr=[]):
|
||||
for x in arr:
|
||||
if name == x:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
from msodclient import msodclient
|
||||
|
||||
|
||||
msodc = msodclient(getPluginDir(), getServerDir())
|
||||
msodc.setDebug(False)
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
if t.strip() == '':
|
||||
tmp = []
|
||||
else:
|
||||
t = t.split(':', 1)
|
||||
tmp[t[0]] = t[1]
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':', 1)
|
||||
tmp[t[0]] = t[1]
|
||||
return tmp
|
||||
|
||||
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
return 'start'
|
||||
|
||||
|
||||
def isAuthApi():
|
||||
cfg = getServerDir() + "/user.conf"
|
||||
if os.path.exists(cfg):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def getConf():
|
||||
if not isAuthApi():
|
||||
sign_in_url, state = msodc.get_sign_in_url()
|
||||
return mw.returnJson(False, "未授权!", {'auth_url': sign_in_url})
|
||||
return mw.returnJson(True, "OK")
|
||||
|
||||
|
||||
def setAuthUrl():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['url'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
url = args['url']
|
||||
|
||||
try:
|
||||
if url.startswith("http://"):
|
||||
url = url.replace("http://", "https://")
|
||||
token = msodc.get_token_from_authorized_url(authorized_url=url)
|
||||
msodc.store_token(token)
|
||||
msodc.store_user()
|
||||
return mw.returnJson(True, "授权成功!")
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, "授权失败2!:" + str(e))
|
||||
return mw.returnJson(False, "授权失败!:" + str(e))
|
||||
|
||||
|
||||
def clearAuth():
|
||||
cfg = getServerDir() + "/user.conf"
|
||||
if os.path.exists(cfg):
|
||||
os.remove(cfg)
|
||||
|
||||
token = getServerDir() + "/token.pickle"
|
||||
if os.path.exists(token):
|
||||
os.remove(token)
|
||||
|
||||
return mw.returnJson(True, "清空授权成功!")
|
||||
|
||||
|
||||
def getList():
|
||||
cfg = getServerDir() + "/user.conf"
|
||||
if not os.path.exists(cfg):
|
||||
return mw.returnJson(False, "未配置,请点击`授权`", [])
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['path'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
try:
|
||||
flist = msodc.get_list(args['path'])
|
||||
return mw.returnJson(True, "ok", flist)
|
||||
except Exception as e:
|
||||
return mw.returnJson(False, str(e), [])
|
||||
|
||||
|
||||
def createDir():
|
||||
cfg = getServerDir() + "/user.conf"
|
||||
if not os.path.exists(cfg):
|
||||
return mw.returnJson(False, "未配置OneDrive,请点击`授权`", [])
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['path', 'name'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
file = args['path'] + "/" + args['name']
|
||||
isok = msodc.create_dir(file)
|
||||
if isok:
|
||||
return mw.returnJson(True, "创建成功")
|
||||
return mw.returnJson(False, "创建失败")
|
||||
|
||||
|
||||
def deleteDir():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['dir_name', 'path'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
file = args['path'] + "/" + args['dir_name']
|
||||
file = file.strip('/')
|
||||
isok = msodc.delete_object(file)
|
||||
if isok:
|
||||
return mw.returnJson(True, "删除成功")
|
||||
return mw.returnJson(False, "文件不为空,删除失败!")
|
||||
|
||||
|
||||
def deleteFile():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['path', 'filename'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
file = args['path'] + "/" + args['filename']
|
||||
file = file.strip('/')
|
||||
isok = msodc.delete_object(file)
|
||||
if isok:
|
||||
return mw.returnJson(True, "删除成功")
|
||||
return mw.returnJson(False, "删除失败")
|
||||
|
||||
|
||||
def findPathName(path, filename):
|
||||
f = os.scandir(path)
|
||||
l = []
|
||||
for ff in f:
|
||||
t = {}
|
||||
if ff.name.find(filename) > -1:
|
||||
t['filename'] = path + '/' + ff.name
|
||||
l.append(t)
|
||||
return l
|
||||
|
||||
|
||||
def backupAllFunc(stype):
|
||||
if not isAuthApi():
|
||||
mw.echoInfo("未授权API,无法使用!!!")
|
||||
return ''
|
||||
|
||||
os.chdir(mw.getRunDir())
|
||||
backup_dir = mw.getBackupDir()
|
||||
run_dir = mw.getRunDir()
|
||||
|
||||
stype = sys.argv[1]
|
||||
name = sys.argv[2]
|
||||
num = sys.argv[3]
|
||||
|
||||
prefix_dict = {
|
||||
"site": "web",
|
||||
"database": "db",
|
||||
"path": "path",
|
||||
}
|
||||
|
||||
backups = []
|
||||
sql = db.Sql()
|
||||
|
||||
# print("stype:", stype)
|
||||
# 提前获取-清理多余备份
|
||||
if stype == 'site':
|
||||
pid = sql.table('sites').where('name=?', (name,)).getField('id')
|
||||
backups = sql.table('backup').where(
|
||||
'type=? and pid=?', ('0', pid)).field('id,filename').select()
|
||||
if stype == 'database':
|
||||
db_path = mw.getServerDir() + '/mysql'
|
||||
pid = mw.M('databases').dbPos(db_path, 'mysql').where(
|
||||
'name=?', (name,)).getField('id')
|
||||
backups = sql.table('backup').where(
|
||||
'type=? and pid=?', ('1', pid)).field('id,filename').select()
|
||||
if stype == 'path':
|
||||
backup_path = backup_dir + '/path'
|
||||
_name = 'path_{}'.format(os.path.basename(name))
|
||||
backups = findPathName(backup_path, _name)
|
||||
|
||||
# 其他类型关系性数据库(mysql类的)
|
||||
if stype.find('database_') > -1:
|
||||
plugin_name = stype.replace('database_', '')
|
||||
db_path = mw.getServerDir() + '/' + plugin_name
|
||||
pid = mw.M('databases').dbPos(db_path, 'mysql').where(
|
||||
'name=?', (name,)).getField('id')
|
||||
backups = sql.table('backup').where(
|
||||
'type=? and pid=?', ('1', pid)).field('id,filename').select()
|
||||
|
||||
args = stype + " " + name + " " + num
|
||||
cmd = 'python3 ' + run_dir + '/scripts/backup.py ' + args
|
||||
if stype.find('database_') > -1:
|
||||
plugin_name = stype.replace('database_', '')
|
||||
args = "database " + name + " " + num
|
||||
cmd = 'python3 ' + run_dir + '/plugins/' + \
|
||||
plugin_name + '/scripts/backup.py ' + args
|
||||
|
||||
if stype == 'path':
|
||||
name = os.path.basename(name)
|
||||
|
||||
# print("cmd:", cmd)
|
||||
os.system(cmd)
|
||||
|
||||
# 开始执行上传信息.
|
||||
if stype.find('database_') > -1:
|
||||
bk_name = 'database'
|
||||
plugin_name = stype.replace('database_', '')
|
||||
bk_prefix = plugin_name + '/db'
|
||||
stype = 'database'
|
||||
else:
|
||||
bk_prefix = prefix_dict[stype]
|
||||
bk_name = stype
|
||||
|
||||
find_path = backup_dir + '/' + bk_name + '/' + bk_prefix + '_' + name
|
||||
find_new_file = "ls " + find_path + \
|
||||
"_* | grep '.gz' | cut -d \ -f 1 | awk 'END {print}'"
|
||||
|
||||
# print(find_new_file)
|
||||
|
||||
filename = mw.execShell(find_new_file)[0].strip()
|
||||
if filename == "":
|
||||
mw.echoInfo("not find upload file!")
|
||||
return False
|
||||
|
||||
mw.echoInfo("准备上传文件 {}".format(filename))
|
||||
mw.echoStart('开始上传')
|
||||
msodc.upload_file(filename, stype)
|
||||
mw.echoEnd('上传成功')
|
||||
|
||||
# print(backups)
|
||||
backups = sorted(backups, key=lambda x: x['filename'], reverse=False)
|
||||
mw.echoStart('开始删除远程备份')
|
||||
num = int(num)
|
||||
sep = len(backups) - num
|
||||
if sep > -1:
|
||||
for backup in backups:
|
||||
fn = os.path.basename(backup['filename'])
|
||||
msodc.delete_file(fn, stype)
|
||||
mw.echoInfo("---已清理远程过期备份文件:" + fn)
|
||||
sep -= 1
|
||||
if sep < 0:
|
||||
break
|
||||
mw.echoEnd('结束删除远程备份')
|
||||
|
||||
return ''
|
||||
|
||||
|
||||
def installPreInspection():
|
||||
return 'ok'
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
if func == 'status':
|
||||
print(status())
|
||||
elif func == 'start':
|
||||
print(start())
|
||||
elif func == 'stop':
|
||||
print(stop())
|
||||
elif func == 'restart':
|
||||
print(restart())
|
||||
elif func == 'reload':
|
||||
print(reload())
|
||||
elif func == 'install_pre_inspection':
|
||||
print(installPreInspection())
|
||||
elif func == 'conf':
|
||||
print(getConf())
|
||||
elif func == 'set_auth_url':
|
||||
print(setAuthUrl())
|
||||
elif func == 'clear_auth':
|
||||
print(clearAuth())
|
||||
elif func == "get_list":
|
||||
print(getList())
|
||||
elif func == "create_dir":
|
||||
print(createDir())
|
||||
elif func == "delete_dir":
|
||||
print(deleteDir())
|
||||
elif func == 'delete_file':
|
||||
print(deleteFile())
|
||||
elif in_array(func, ['site', 'database', 'path']) or func.find('database_') > -1:
|
||||
print(backupAllFunc(func))
|
||||
else:
|
||||
print('error')
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"hook":["backup"],
|
||||
"title": "OneDrive",
|
||||
"tip": "lib",
|
||||
"name": "msonedrive",
|
||||
"type": "sort",
|
||||
"ps": "微软家的云网盘服务。",
|
||||
"versions": "1.0",
|
||||
"shell": "install.sh",
|
||||
"checks": "server/msonedrive",
|
||||
"author": "midoks",
|
||||
"date": "2023-8-18",
|
||||
"pid": "4"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
PATH=/www/server/panel/pyenv/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
VERSION=$2
|
||||
|
||||
if [ -f ${rootPath}/bin/activate ];then
|
||||
source ${rootPath}/bin/activate
|
||||
fi
|
||||
|
||||
Install_App()
|
||||
{
|
||||
pip install requests-oauthlib==1.3.0
|
||||
mkdir -p $serverPath/msonedrive
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
echo "${VERSION}" > $serverPath/msonedrive/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
|
||||
echo "Successify"
|
||||
}
|
||||
|
||||
|
||||
Uninstall_App()
|
||||
{
|
||||
rm -rf $serverPath/msonedrive
|
||||
}
|
||||
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_App
|
||||
elif [ "${1}" == 'uninstall' ];then
|
||||
Uninstall_App
|
||||
else
|
||||
echo 'Error!';
|
||||
fi
|
||||
@@ -0,0 +1,258 @@
|
||||
|
||||
function msodPost(method,args,callback){
|
||||
var _args = null;
|
||||
if (typeof(args) == 'string'){
|
||||
_args = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
_args = JSON.stringify(args);
|
||||
}
|
||||
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'msonedrive', func:method, args:_args}, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
|
||||
function createDir(){
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: "400px",
|
||||
title: "创建目录",
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: false,
|
||||
btn: ['确定','取消'],
|
||||
content:'<div class="bingfa bt-form c6" style="padding-bottom: 10px;">\
|
||||
<p>\
|
||||
<span class="span_tit">目录名称:</span>\
|
||||
<input style="width: 200px;" type="text" name="newPath" value="">\
|
||||
</p>\
|
||||
</div>',
|
||||
success:function(){
|
||||
$("input[name='newPath']").focus().keyup(function(e){
|
||||
if(e.keyCode == 13) $(".layui-layer-btn0").click();
|
||||
});
|
||||
},
|
||||
yes:function(index,layero){
|
||||
var name = $("input[name='newPath']").val();
|
||||
if(name == ''){
|
||||
layer.msg('目录名称不能为空!',{icon:2});
|
||||
return;
|
||||
}
|
||||
var path = $("#myPath").val();
|
||||
var dirname = name;
|
||||
var loadT = layer.msg('正在创建目录['+dirname+']...',{icon:16,time:0,shade: [0.3, '#000']});
|
||||
msodPost('create_dir', {path:path,name:dirname}, function(data){
|
||||
layer.close(loadT);
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if(rdata.status) {
|
||||
showMsg(rdata.msg, function(){
|
||||
layer.close(index);
|
||||
odList(path);
|
||||
} ,{icon:1}, 2000);
|
||||
} else{
|
||||
layer.msg(rdata.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//设置API
|
||||
function authApi(){
|
||||
|
||||
msodPost('conf', {}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
|
||||
// console.log(rdata);
|
||||
// console.log(rdata.data.auth_url);
|
||||
var apicon = '';
|
||||
if (rdata.status){
|
||||
|
||||
var html = '';
|
||||
html += '<button id="clear_auth" onclick="clearAuth();" class="btn btn-default btn-sm">清空配置</button>';
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '已授权',
|
||||
area: '240px',
|
||||
content:'<div class="change-default pd20">'+html+'</div>',
|
||||
success: function(){
|
||||
$('#clear_auth').click(function(){
|
||||
msodPost('clear_auth', {}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
layer.close(loadOpen);
|
||||
odList('/');
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
||||
} else{
|
||||
apicon = '<div class="new_form">'+$("#check_api").html()+'</div>';
|
||||
}
|
||||
|
||||
var layer_auth = layer.open({
|
||||
type: 1,
|
||||
area: "620px",
|
||||
title: "OneDrive授权",
|
||||
closeBtn: 1,
|
||||
shift: 5,
|
||||
shadeClose: false,
|
||||
content:apicon,
|
||||
success:function(layero,index){
|
||||
// console.log(layero,index);
|
||||
if (!rdata.status){
|
||||
$('.check_api .step_two_url').val(rdata.data['auth_url']);
|
||||
$('.check_api .open_btlink').attr('href',rdata.data['auth_url']);
|
||||
|
||||
$('.check_api .ico-copy').click(function(){
|
||||
copyPass(rdata.data['auth_url']);
|
||||
});
|
||||
|
||||
$('.check_api .set_auth_btn').click(function(){
|
||||
|
||||
var url = $('.check_api .OneDrive').val();
|
||||
if ( url == ''){
|
||||
layer.msg("验证URL不能为空",{icon:2});
|
||||
return;
|
||||
}
|
||||
// console.log(url);
|
||||
msodPost('set_auth_url', {url:url}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
var show_time = 2000;
|
||||
if (!rdata.status){
|
||||
show_time = 10000;
|
||||
}
|
||||
|
||||
showMsg(rdata.msg,function(){
|
||||
if (rdata.status){
|
||||
layer.close(layer_auth);
|
||||
odList('/');
|
||||
}
|
||||
},{icon:rdata.status?1:2},show_time);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//计算当前目录偏移
|
||||
function upPathLeft(){
|
||||
var UlWidth = $(".place-input ul").width();
|
||||
var SpanPathWidth = $(".place-input").width() - 20;
|
||||
var Ml = UlWidth - SpanPathWidth;
|
||||
if(UlWidth > SpanPathWidth ){
|
||||
$(".place-input ul").css("left",-Ml)
|
||||
}
|
||||
else{
|
||||
$(".place-input ul").css("left",0)
|
||||
}
|
||||
}
|
||||
|
||||
function odList(path){
|
||||
msodPost('get_list', {path:path}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
if(rdata.status === false){
|
||||
showMsg(rdata.msg,function(){
|
||||
authApi();
|
||||
},{icon:2},2000);
|
||||
return;
|
||||
}
|
||||
|
||||
var mlist = rdata.data;
|
||||
var listBody = ''
|
||||
var listFiles = ''
|
||||
for(var i=0;i<mlist.list.length;i++){
|
||||
if(mlist.list[i].type == null){
|
||||
listBody += '<tr><td class="cursor" onclick="odList(\''+(path+'/'+mlist.list[i].name).replace('//','/')+'\')"><span class="ico ico-folder"></span>\<span>'+mlist.list[i].name+'</span></td>\
|
||||
<td>-</td>\
|
||||
<td>-</td>\
|
||||
<td class="text-right"><a class="btlink" onclick="deleteFile(\''+mlist.list[i].name+'\', true)">删除</a></td></tr>'
|
||||
}else{
|
||||
listFiles += '<tr><td class="cursor"><span class="ico ico-file"></span>\<span>'+mlist.list[i].name+'</span></td>\
|
||||
<td>'+toSize(mlist.list[i].size)+'</td>\
|
||||
<td>'+getLocalTime(mlist.list[i].time)+'</td>\
|
||||
<td class="text-right"><a target="_blank" href="'+mlist.list[i].download+'" class="btlink">下载</a> | <a class="btlink" onclick="deleteFile(\''+mlist.list[i].name+'\', false)">删除</a></td></tr>'
|
||||
}
|
||||
}
|
||||
listBody += listFiles;
|
||||
|
||||
var pathLi='';
|
||||
var tmp = path.split('/')
|
||||
var pathname = '';
|
||||
var n = 0;
|
||||
for(var i=0;i<tmp.length;i++){
|
||||
if(n > 0 && tmp[i] == '') continue;
|
||||
var dirname = tmp[i];
|
||||
if(dirname == '') {
|
||||
dirname = '根目录';
|
||||
n++;
|
||||
}
|
||||
pathname += '/' + tmp[i];
|
||||
pathname = pathname.replace('//','/');
|
||||
pathLi += '<li><a title="'+pathname+'" onclick="odList(\''+pathname+'\')">'+dirname+'</a></li>';
|
||||
}
|
||||
var um = 1;
|
||||
if(tmp[tmp.length-1] == '') um = 2;
|
||||
var backPath = tmp.slice(0,tmp.length-um).join('/') || '/';
|
||||
$('#myPath').val(path);
|
||||
$(".upyunCon .place-input ul").html(pathLi);
|
||||
$(".upyunlist .list-list").html(listBody);
|
||||
|
||||
upPathLeft();
|
||||
|
||||
$('#backBtn').unbind().click(function() {
|
||||
odList(backPath);
|
||||
});
|
||||
|
||||
$('.upyunCon .refreshBtn').unbind().click(function(){
|
||||
odList(path);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//删除文件
|
||||
function deleteFile(name, is_dir){
|
||||
if (is_dir === false){
|
||||
safeMessage('删除文件','删除后将无法恢复,真的要删除['+name+']吗?',function(){
|
||||
var path = $("#myPath").val();
|
||||
var filename = name;
|
||||
msodPost('delete_file', {filename:filename,path:path}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
odList(path);
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
safeMessage('删除文件夹','删除后将无法恢复,真的要删除['+name+']吗?',function(){
|
||||
var path = $("#myPath").val();
|
||||
msodPost('delete_dir', {dir_name:name,path:path}, function(rdata){
|
||||
var rdata = $.parseJSON(rdata.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
odList(path);
|
||||
},{icon:rdata.status?1:2},2000);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
#!/usr/bin/python
|
||||
# coding: utf-8
|
||||
|
||||
# python3 plugins/msonedrive/t/test.py
|
||||
|
||||
|
||||
# https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/~/Overview/appId/08125e6b-6502-4ac9-9548-ad682f00848d/objectId/62b1d655-9828-47ed-be99-65eb18c3a929/isMSAApp~/false/defaultBlade/Overview/appSignInAudience/AzureADandPersonalMicrosoftAccount/servicePrincipalCreated~/true
|
||||
|
||||
# 0WA8Q~sZkZFZKv50ryP4ux~.fpVtbHw7BuTZmbQB
|
||||
# client_id:d9878fac-8526-4ff6-8036-e1c92dd9dd80
|
||||
|
||||
# 08125e6b-6502-4ac9-9548-ad682f00848d
|
||||
|
||||
|
||||
# https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&client_id=d9878fac-8526-4ff6-8036-e1c92dd9dd80&redirect_uri=http://localhost&scope=offline_access+Files.ReadWrite.All+User.Read&state=cwopMdHiPIkze4MvgFL6WfSl8LdYAl&prompt=login
|
||||
|
||||
|
||||
# http://localhost/?code=M.C106_BAY.2.3e12c859-6107-0c5b-9ef4-14b3fb8269ba&state=JzHdzHXmA7x6zl7Be6cJ6uOlf9Bg69
|
||||
|
||||
|
||||
# python3 /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/msonedrive/index.py site t1.cn 3
|
||||
# python3 /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/msonedrive/index.py database t1 3
|
||||
# python3
|
||||
# /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/msonedrive/index.py
|
||||
# path /Users/midoks/Desktop/dev/python 3
|
||||
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
|
||||
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'msonedrive'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
from msodclient import msodclient
|
||||
|
||||
msodclient.setDebug(True)
|
||||
msodc = msodclient(getPluginDir(), getServerDir())
|
||||
|
||||
|
||||
# sign_in_url, state = msodc.get_sign_in_url()
|
||||
# print(sign_in_url)
|
||||
|
||||
|
||||
def set_auth_url(url):
|
||||
try:
|
||||
if url.startswith("http://"):
|
||||
url = url.replace("http://", "https://")
|
||||
token = msodc.get_token_from_authorized_url(
|
||||
authorized_url=url)
|
||||
msodc.store_token(token)
|
||||
msodc.store_user()
|
||||
return mw.returnJson(True, "授权成功!")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return mw.returnJson(False, "授权失败2!:" + str(e))
|
||||
return mw.returnJson(False, "授权失败!:" + str(e))
|
||||
|
||||
# url = 'http://localhost/?code=M.C106_BAY.2.310112f3-a158-c400-9667-d158cbd1de6c&state=jEJz0ucR9bpZYD9PGxp2GgRDotrzO6'
|
||||
# token = set_auth_url(url)
|
||||
# print(token)
|
||||
|
||||
# token = msodc.get_token()
|
||||
# print("token:", token)
|
||||
|
||||
# t = msodc.get_list('/backup')
|
||||
# print(t)
|
||||
|
||||
# t = msodc.create_dir('backup')
|
||||
# print(t)
|
||||
|
||||
# t = msodc.delete_object('backup')
|
||||
# print(t)
|
||||
|
||||
|
||||
t = msodc.upload_file('web_t1.cn_20230830_134549.tar.gz', 'site')
|
||||
print(t)
|
||||
# print(msodc.error_msg)
|
||||
|
||||
# /Users/midoks/Desktop/mwdev/server/mdserver-web/paramiko.log
|
||||
# backup/site/paramiko.log
|
||||
# |-正在上传到 backup/site/paramiko.log...
|
||||
# True
|
||||
|
||||
|
||||
# t = msodc.upload_abs_file(
|
||||
# 'web_t1.cn_20230830_134549.tar.gz', 'site')
|
||||
# print(t)
|
||||
# print(msodc.error_msg)
|
||||
+20
-38
@@ -55,19 +55,20 @@ def is_number(s):
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
if t.strip() == '':
|
||||
tmp = []
|
||||
else:
|
||||
t = t.split(':', 1)
|
||||
tmp[t[0]] = t[1]
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
t = args[i].split(':', 1)
|
||||
tmp[t[0]] = t[1]
|
||||
|
||||
return tmp
|
||||
|
||||
|
||||
@@ -1595,6 +1596,15 @@ def setDbMasterAccess():
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def resetMaster(version=''):
|
||||
pdb = pMysqlDb()
|
||||
r = pdb.execute('reset master')
|
||||
isError = isSqlError(r)
|
||||
if isError != None:
|
||||
return isError
|
||||
return mw.returnJson(True, '重置成功!')
|
||||
|
||||
|
||||
def getMasterDbList(version=''):
|
||||
try:
|
||||
args = getArgs()
|
||||
@@ -2195,40 +2205,10 @@ def updateSlaveSSH(version=''):
|
||||
|
||||
|
||||
def getSlaveList(version=''):
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
ret = []
|
||||
for x in range(0, len(dlist)):
|
||||
tmp = {}
|
||||
tmp['Master_User'] = dlist[x]["Master_User"]
|
||||
tmp['Master_Host'] = dlist[x]["Master_Host"]
|
||||
tmp['Master_Port'] = dlist[x]["Master_Port"]
|
||||
tmp['Master_Log_File'] = dlist[x]["Master_Log_File"]
|
||||
tmp['Slave_IO_Running'] = dlist[x]["Slave_IO_Running"]
|
||||
tmp['Slave_SQL_Running'] = dlist[x]["Slave_SQL_Running"]
|
||||
tmp['Last_Error'] = dlist[x]["Last_Error"]
|
||||
tmp['Last_IO_Error'] = dlist[x]["Last_IO_Error"]
|
||||
tmp['Last_SQL_Error'] = dlist[x]["Last_SQL_Error"]
|
||||
tmp['Slave_SQL_Running_State'] = dlist[x]["Slave_SQL_Running_State"]
|
||||
|
||||
tmp['Error'] = ''
|
||||
if tmp['Last_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_Error']
|
||||
|
||||
if tmp['Last_IO_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_IO_Error']
|
||||
|
||||
if tmp['Last_SQL_Error'] != '':
|
||||
tmp['Error'] = tmp['Last_SQL_Error']
|
||||
|
||||
if tmp['Error'] == '':
|
||||
tmp['Error'] = tmp['Slave_SQL_Running_State']
|
||||
|
||||
ret.append(tmp)
|
||||
data = {}
|
||||
data['data'] = ret
|
||||
|
||||
data['data'] = dlist
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
@@ -2751,8 +2731,8 @@ def installPreInspection(version):
|
||||
if not sysName in ('debian', 'ubuntu'):
|
||||
return '仅支持debian,ubuntu'
|
||||
|
||||
if (sysName == 'debian' and not sysId in('11', '10')):
|
||||
return 'debian支持10,11'
|
||||
if (sysName == 'debian' and not sysId in('12', '11', '10')):
|
||||
return 'debian支持10,11,12'
|
||||
|
||||
if (sysName == 'ubuntu' and version == '5.7' and not sysId in ('18.04')):
|
||||
return "Ubuntu Apt MySQL[" + version + "] 仅支持18.04"
|
||||
@@ -2879,6 +2859,8 @@ if __name__ == "__main__":
|
||||
print(getDbrunMode(version))
|
||||
elif func == 'set_dbrun_mode':
|
||||
print(setDbrunMode(version))
|
||||
elif func == 'reset_master':
|
||||
print(resetMaster(version))
|
||||
elif func == 'get_masterdb_list':
|
||||
print(getMasterDbList(version))
|
||||
elif func == 'get_master_status':
|
||||
|
||||
@@ -1601,6 +1601,14 @@ function setDbMasterAccess(username){
|
||||
});
|
||||
}
|
||||
|
||||
function resetMaster(){
|
||||
myPost('reset_master', '', function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
},{icon: rdata.status ? 1 : 2});
|
||||
},'正在执行重置master命令[reset master]');
|
||||
}
|
||||
|
||||
function getMasterRepSlaveList(){
|
||||
var _data = {};
|
||||
if (typeof(page) =='undefined'){
|
||||
@@ -2446,6 +2454,7 @@ function masterOrSlaveConf(version=''){
|
||||
<p class="conf_p">\
|
||||
<span class="f14 c6 mr20">Master[主]配置</span><span class="f14 c6 mr20"></span>\
|
||||
<button class="btn '+(!rdata.status ? 'btn-danger' : 'btn-success')+' btn-xs btn-master">'+(!rdata.status ? '未开启' : '已开启') +'</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="resetMaster()" >重置</button>\
|
||||
</p>\
|
||||
<hr/>\
|
||||
<!-- master list -->\
|
||||
|
||||
@@ -46,19 +46,20 @@ def getServerDir():
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
if t.strip() == '':
|
||||
tmp = []
|
||||
else:
|
||||
t = t.split(':', 1)
|
||||
tmp[t[0]] = t[1]
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
t = args[i].split(':', 1)
|
||||
tmp[t[0]] = t[1]
|
||||
|
||||
return tmp
|
||||
|
||||
|
||||
@@ -1576,6 +1577,15 @@ def setDbMasterAccess():
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def resetMaster(version=''):
|
||||
pdb = pMysqlDb()
|
||||
r = pdb.execute('reset master')
|
||||
isError = isSqlError(r)
|
||||
if isError != None:
|
||||
return isError
|
||||
return mw.returnJson(True, '重置成功!')
|
||||
|
||||
|
||||
def getMasterDbList(version=''):
|
||||
try:
|
||||
args = getArgs()
|
||||
@@ -2826,6 +2836,8 @@ if __name__ == "__main__":
|
||||
print(getDbrunMode(version))
|
||||
elif func == 'set_dbrun_mode':
|
||||
print(setDbrunMode(version))
|
||||
elif func == 'reset_master':
|
||||
print(resetMaster(version))
|
||||
elif func == 'get_masterdb_list':
|
||||
print(getMasterDbList(version))
|
||||
elif func == 'get_master_status':
|
||||
|
||||
@@ -1601,6 +1601,14 @@ function setDbMasterAccess(username){
|
||||
});
|
||||
}
|
||||
|
||||
function resetMaster(){
|
||||
myPost('reset_master', '', function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
},{icon: rdata.status ? 1 : 2});
|
||||
},'正在执行重置master命令[reset master]');
|
||||
}
|
||||
|
||||
function getMasterRepSlaveList(){
|
||||
var _data = {};
|
||||
if (typeof(page) =='undefined'){
|
||||
@@ -2446,6 +2454,7 @@ function masterOrSlaveConf(version=''){
|
||||
<p class="conf_p">\
|
||||
<span class="f14 c6 mr20">Master[主]配置</span><span class="f14 c6 mr20"></span>\
|
||||
<button class="btn '+(!rdata.status ? 'btn-danger' : 'btn-success')+' btn-xs btn-master">'+(!rdata.status ? '未开启' : '已开启') +'</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="resetMaster()" >重置</button>\
|
||||
</p>\
|
||||
<hr/>\
|
||||
<!-- master list -->\
|
||||
|
||||
+67
-6
@@ -45,8 +45,12 @@ def getServerDir():
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return '/tmp/' + getPluginName()
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
return '/etc/rc.d/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
@@ -524,12 +528,26 @@ def initMysql8Pwd():
|
||||
def myOp(version, method):
|
||||
# import commands
|
||||
init_file = initDreplace(version)
|
||||
current_os = mw.getOs()
|
||||
try:
|
||||
isInited = initMysqlData()
|
||||
if not isInited:
|
||||
mw.execShell('systemctl start mysql')
|
||||
|
||||
if current_os.startswith("freebsd"):
|
||||
mw.execShell('service ' + getPluginName() + ' start')
|
||||
else:
|
||||
mw.execShell('systemctl start mysql')
|
||||
|
||||
initMysqlPwd()
|
||||
mw.execShell('systemctl stop mysql')
|
||||
|
||||
if current_os.startswith("freebsd"):
|
||||
mw.execShell('service ' + getPluginName() + ' stop')
|
||||
else:
|
||||
mw.execShell('systemctl stop mysql')
|
||||
|
||||
if current_os.startswith("freebsd"):
|
||||
data = mw.execShell('service ' + getPluginName() + ' ' + method)
|
||||
return 'ok'
|
||||
|
||||
mw.execShell('systemctl ' + method + ' mysql')
|
||||
return 'ok'
|
||||
@@ -610,9 +628,15 @@ def reload(version=''):
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
return 'ok'
|
||||
|
||||
shell_cmd = 'systemctl status mysql | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
@@ -621,17 +645,34 @@ def initdStatus():
|
||||
|
||||
|
||||
def initdInstall():
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
import shutil
|
||||
source_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="YES"')
|
||||
return 'ok'
|
||||
|
||||
mw.execShell('systemctl enable mysql')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="NO"')
|
||||
return 'ok'
|
||||
|
||||
mw.execShell('systemctl disable mysql')
|
||||
return 'ok'
|
||||
|
||||
@@ -748,6 +789,9 @@ def runInfo(version):
|
||||
|
||||
|
||||
def myDbStatus(version):
|
||||
if status(version) == 'stop':
|
||||
return mw.returnJson(False, 'MySQL未启动', [])
|
||||
|
||||
result = {}
|
||||
db = pMysqlDb()
|
||||
data = db.query('show variables')
|
||||
@@ -1767,6 +1811,15 @@ def setDbMasterAccess():
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def resetMaster(version=''):
|
||||
pdb = pMysqlDb()
|
||||
r = pdb.execute('reset master')
|
||||
isError = isSqlError(r)
|
||||
if isError != None:
|
||||
return isError
|
||||
return mw.returnJson(True, '重置成功!')
|
||||
|
||||
|
||||
def getMasterDbList(version=''):
|
||||
try:
|
||||
args = getArgs()
|
||||
@@ -2368,6 +2421,9 @@ def updateSlaveSSH(version=''):
|
||||
|
||||
|
||||
def getSlaveList(version=''):
|
||||
if status(version) == 'stop':
|
||||
return mw.returnJson(False, 'MySQL未启动', [])
|
||||
|
||||
db = pMysqlDb()
|
||||
dlist = db.query('show slave status')
|
||||
data = {}
|
||||
@@ -2383,6 +2439,9 @@ def getSlaveSyncCmd(version=''):
|
||||
|
||||
|
||||
def initSlaveStatus(version=''):
|
||||
if status(version) == 'stop':
|
||||
return mw.returnJson(False, 'MySQL未启动', [])
|
||||
|
||||
mode_file = getSyncModeFile()
|
||||
if not os.path.exists(mode_file):
|
||||
return mw.returnJson(False, '需要先设置同步配置')
|
||||
@@ -3023,6 +3082,8 @@ if __name__ == "__main__":
|
||||
print(getDbrunMode(version))
|
||||
elif func == 'set_dbrun_mode':
|
||||
print(setDbrunMode(version))
|
||||
elif func == 'reset_master':
|
||||
print(resetMaster(version))
|
||||
elif func == 'get_masterdb_list':
|
||||
print(getMasterDbList(version))
|
||||
elif func == 'get_master_status':
|
||||
|
||||
@@ -1601,6 +1601,15 @@ function setDbMasterAccess(username){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function resetMaster(){
|
||||
myPost('reset_master', '', function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.msg,function(){
|
||||
},{icon: rdata.status ? 1 : 2});
|
||||
},'正在执行重置master命令[reset master]');
|
||||
}
|
||||
|
||||
function getMasterRepSlaveList(){
|
||||
var _data = {};
|
||||
if (typeof(page) =='undefined'){
|
||||
@@ -2446,6 +2455,7 @@ function masterOrSlaveConf(version=''){
|
||||
<p class="conf_p">\
|
||||
<span class="f14 c6 mr20">Master[主]配置</span><span class="f14 c6 mr20"></span>\
|
||||
<button class="btn '+(!rdata.status ? 'btn-danger' : 'btn-success')+' btn-xs btn-master">'+(!rdata.status ? '未开启' : '已开启') +'</button>\
|
||||
<button class="btn btn-success btn-xs" onclick="resetMaster()" >重置</button>\
|
||||
</p>\
|
||||
<hr/>\
|
||||
<!-- master list -->\
|
||||
|
||||
@@ -66,6 +66,15 @@ Install_mysql()
|
||||
cd ${mysqlDir} && tar -zxvf ${mysqlDir}/mysql-5.5.62.tar.gz
|
||||
fi
|
||||
|
||||
WHERE_DIR_GCC=/usr/bin/gcc
|
||||
WHERE_DIR_GPP=/usr/bin/g++
|
||||
if [ ! -f $WHERE_DIR_GCC ];then
|
||||
WHERE_DIR_GCC=`which gcc`
|
||||
fi
|
||||
|
||||
if [ ! -f $WHERE_DIR_GPP ];then
|
||||
WHERE_DIR_GPP=`which g++`
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mysql ];then
|
||||
cd ${mysqlDir}/mysql-5.5.62 && cmake \
|
||||
@@ -81,8 +90,8 @@ Install_mysql()
|
||||
-DEXTRA_CHARSETS=all \
|
||||
-DDEFAULT_CHARSET=utf8mb4 \
|
||||
-DDEFAULT_COLLATION=utf8mb4_general_ci \
|
||||
-DCMAKE_C_COMPILER=/usr/bin/gcc \
|
||||
-DCMAKE_CXX_COMPILER=/usr/bin/g++
|
||||
-DCMAKE_C_COMPILER=$WHERE_DIR_GCC \
|
||||
-DCMAKE_CXX_COMPILER=$WHERE_DIR_GPP
|
||||
make -j${cpuCore} && make install && make clean
|
||||
|
||||
if [ -d $serverPath/mysql ];then
|
||||
|
||||
@@ -76,9 +76,9 @@ Install_mysql()
|
||||
OPENSSL_VERSION=`openssl version|awk '{print $2}'|awk -F '.' '{print $1}'`
|
||||
if [ "${OPENSSL_VERSION}" -ge "3" ];then
|
||||
#openssl version to high
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash openssl.sh
|
||||
export PKG_CONFIG_PATH=$serverPath/lib/openssl/lib/pkgconfig
|
||||
OPTIONS="-DWITH_SSL=${serverPath}/lib/openssl"
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash openssl10.sh
|
||||
export PKG_CONFIG_PATH=$serverPath/lib/openssl10/lib/pkgconfig
|
||||
OPTIONS="-DWITH_SSL=${serverPath}/lib/openssl10"
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mysql ];then
|
||||
|
||||
@@ -91,9 +91,9 @@ Install_mysql()
|
||||
OPENSSL_VERSION=`openssl version|awk '{print $2}'|awk -F '.' '{print $1}'`
|
||||
if [ "${OPENSSL_VERSION}" -ge "3" ];then
|
||||
#openssl version to high
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash openssl.sh
|
||||
export PKG_CONFIG_PATH=$serverPath/lib/openssl/lib/pkgconfig
|
||||
OPTIONS="-DWITH_SSL=${serverPath}/lib/openssl"
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash openssl_11.sh
|
||||
export PKG_CONFIG_PATH=$serverPath/lib/openssl11/lib/pkgconfig
|
||||
OPTIONS="-DWITH_SSL=${serverPath}/lib/openssl11"
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/mysql ];then
|
||||
|
||||
@@ -1434,13 +1434,13 @@ def testRun():
|
||||
# if not data[0]:
|
||||
# return data[1]
|
||||
|
||||
conf_json = getServerDir() + "/waf/default.json"
|
||||
data = mw.readFile(conf_json)
|
||||
pdata = json.loads(data)
|
||||
default_site = pdata['default']
|
||||
|
||||
default_path = getServerDir() + "/waf/default.pl"
|
||||
default_site = mw.readFile(default_path)
|
||||
url = "http://" + default_site + '/?t=../etc/passwd'
|
||||
returnData = mw.httpGet(url, 10)
|
||||
|
||||
# url = "https://" + default_site + '/?t=../etc/passwd'
|
||||
# returnData = mw.httpGet(url, 3)
|
||||
return mw.returnJson(True, '测试运行成功!', returnData)
|
||||
|
||||
|
||||
|
||||
@@ -484,7 +484,7 @@ function scanRule() {
|
||||
var tmp = $.parseJSON(data.data);
|
||||
var rdata = $.parseJSON(tmp.data);
|
||||
|
||||
create_l = ({
|
||||
create_l = layer.open({
|
||||
type: 1,
|
||||
title: "常用扫描器过滤规则",
|
||||
area: '650px',
|
||||
|
||||
@@ -309,14 +309,16 @@ local function is_open_waf_cc_increase()
|
||||
end
|
||||
|
||||
-- C:D("waf config:"..json.encode(config))
|
||||
if cpu_percent >= config['safe_verify']['cpu'] then
|
||||
return true
|
||||
end
|
||||
|
||||
if site_config[server_name] and site_config[server_name]['safe_verify']['open'] then
|
||||
if cpu_percent >= site_config[server_name]['safe_verify']['cpu'] then
|
||||
if config['safe_verify']['auto'] then
|
||||
if cpu_percent >= config['safe_verify']['cpu'] then
|
||||
return true
|
||||
end
|
||||
|
||||
if site_config[server_name] and site_config[server_name]['safe_verify']['open'] then
|
||||
if cpu_percent >= site_config[server_name]['safe_verify']['cpu'] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
|
||||
+69
-18
@@ -11,9 +11,7 @@ import re
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import mw
|
||||
|
||||
|
||||
app_debug = False
|
||||
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
@@ -31,8 +29,13 @@ def getServerDir():
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return '/tmp/' + getPluginName()
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
return '/etc/rc.d/' + getPluginName()
|
||||
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
@@ -95,6 +98,14 @@ def getInitDTpl():
|
||||
return path
|
||||
|
||||
|
||||
def getPidFile():
|
||||
file = getConf()
|
||||
content = mw.readFile(file)
|
||||
rep = 'pid\s*(.*);'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
|
||||
def getFileOwner(filename):
|
||||
import pwd
|
||||
stat = os.lstat(filename)
|
||||
@@ -118,13 +129,16 @@ def confReplace():
|
||||
user = 'www'
|
||||
user_group = 'www'
|
||||
|
||||
if mw.getOs() == 'darwin':
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
# macosx do
|
||||
user = mw.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
# user = 'root'
|
||||
user_group = 'staff'
|
||||
content = content.replace('{$EVENT_MODEL}', 'kqueue')
|
||||
elif current_os.startswith('freebsd'):
|
||||
content = content.replace('{$EVENT_MODEL}', 'kqueue')
|
||||
else:
|
||||
content = content.replace('{$EVENT_MODEL}', 'epoll')
|
||||
|
||||
@@ -222,8 +236,8 @@ def initDreplace():
|
||||
# /usr/lib/systemd/system
|
||||
systemDir = mw.systemdCfgDir()
|
||||
systemService = systemDir + '/openresty.service'
|
||||
systemServiceTpl = getPluginDir() + '/init.d/openresty.service.tpl'
|
||||
if os.path.exists(systemDir) and not os.path.exists(systemService):
|
||||
systemServiceTpl = getPluginDir() + '/init.d/openresty.service.tpl'
|
||||
se_content = mw.readFile(systemServiceTpl)
|
||||
se_content = se_content.replace('{$SERVER_PATH}', service_path)
|
||||
mw.writeFile(systemService, se_content)
|
||||
@@ -233,9 +247,8 @@ def initDreplace():
|
||||
|
||||
|
||||
def status():
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep openresty |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
pid_file = getPidFile()
|
||||
if not os.path.exists(pid_file):
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
@@ -249,20 +262,33 @@ def restyOp(method):
|
||||
if not check_data[1].find('test is successful') > -1:
|
||||
return check_data[1]
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
data = mw.execShell('systemctl ' + method + ' openresty')
|
||||
current_os = mw.getOs()
|
||||
if current_os == "darwin":
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if current_os.startswith("freebsd"):
|
||||
data = mw.execShell('service openresty ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
data = mw.execShell('systemctl ' + method + ' openresty')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def op_submit_systemctl_restart():
|
||||
current_os = mw.getOs()
|
||||
if current_os.startswith("freebsd"):
|
||||
mw.execShell('service openresty restart')
|
||||
return True
|
||||
|
||||
mw.execShell('systemctl restart openresty')
|
||||
return True
|
||||
|
||||
|
||||
def op_submit_init_restart(file):
|
||||
@@ -280,11 +306,9 @@ def restyOp_restart():
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
threading.Timer(2, op_submit_systemctl_restart, args=()).start()
|
||||
# submit_restart1()
|
||||
return 'ok'
|
||||
|
||||
threading.Timer(2, op_submit_init_restart, args=(file,)).start()
|
||||
# submit_restart2(file)
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -293,7 +317,11 @@ def start():
|
||||
|
||||
|
||||
def stop():
|
||||
return restyOp('stop')
|
||||
r = restyOp('stop')
|
||||
pid_file = getPidFile()
|
||||
if os.path.exists(pid_file):
|
||||
os.remove(pid_file)
|
||||
return r
|
||||
|
||||
|
||||
def restart():
|
||||
@@ -306,10 +334,15 @@ def reload():
|
||||
|
||||
|
||||
def initdStatus():
|
||||
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
return 'ok'
|
||||
|
||||
shell_cmd = 'systemctl status openresty | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
@@ -318,17 +351,35 @@ def initdStatus():
|
||||
|
||||
|
||||
def initdInstall():
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
# freebsd initd install
|
||||
if current_os.startswith('freebsd'):
|
||||
import shutil
|
||||
source_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="YES"')
|
||||
return 'ok'
|
||||
|
||||
mw.execShell('systemctl enable openresty')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="NO"')
|
||||
return 'ok'
|
||||
|
||||
mw.execShell('systemctl disable openresty')
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
# cd /www/server/mdserver-web/plugins/openresty && bash install.sh install 1.21.4.1
|
||||
# cd /www/server/mdserver-web/plugins/openresty && bash install.sh install 1.21.4.2
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
@@ -72,15 +72,20 @@ Install_openresty()
|
||||
|
||||
# Last Download Method
|
||||
if [ ! -f ${openrestyDir}/openresty-${VERSION}.tar.gz ];then
|
||||
wget --no-check-certificate -O ${openrestyDir}/openresty-${VERSION}.tar.gz https://dl.midoks.me/soft/openresty/openresty-${VERSION}.tar.gz -T 3
|
||||
wget --no-check-certificate -O ${openrestyDir}/openresty-${VERSION}.tar.gz http://dl.midoks.me/soft/openresty/openresty-${VERSION}.tar.gz -T 3
|
||||
fi
|
||||
|
||||
cd ${openrestyDir} && tar -zxvf openresty-${VERSION}.tar.gz
|
||||
|
||||
OPTIONS=''
|
||||
if [ "$VERSION" == "1.19.3.1" ]; then
|
||||
OPTIONS=" ${OPTIONS} --with-ipv6 "
|
||||
fi
|
||||
|
||||
# --with-openssl=$serverPath/source/lib/openssl-1.0.2q
|
||||
cd ${openrestyDir}/openresty-${VERSION} && ./configure \
|
||||
--prefix=$serverPath/openresty \
|
||||
--with-ipv6 \
|
||||
$OPTIONS \
|
||||
--with-stream \
|
||||
--with-http_v2_module \
|
||||
--with-http_ssl_module \
|
||||
@@ -92,7 +97,12 @@ Install_openresty()
|
||||
# --with-debug
|
||||
# 用于调式
|
||||
|
||||
make -j${cpuCore} && make install && make clean
|
||||
CMD_MAKE=`which gmake`
|
||||
if [ "$?" == "0" ];then
|
||||
gmake -j${cpuCore} && gmake install && gmake clean
|
||||
else
|
||||
make -j${cpuCore} && make install && make clean
|
||||
fi
|
||||
|
||||
if [ -d $serverPath/openresty ];then
|
||||
echo "${VERSION}" > $serverPath/openresty/version.pl
|
||||
|
||||
@@ -62,10 +62,6 @@ cd ${curPath} && sh -x $curPath/versions/$2/install.sh $1
|
||||
|
||||
if [ "${action}" == "install" ] && [ -d ${serverPath}/php-yum/${type} ];then
|
||||
|
||||
#初始化
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/php-yum/index.py start ${type}
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/php-yum/index.py initd_install ${type}
|
||||
|
||||
# 安装通用扩展
|
||||
echo "install PHP-YUM[${type}] extend start"
|
||||
cd ${rootPath}/plugins/php-yum/versions && bash common.sh ${type} install mysqlnd
|
||||
@@ -82,6 +78,10 @@ if [ "${action}" == "install" ] && [ -d ${serverPath}/php-yum/${type} ];then
|
||||
cd ${rootPath}/plugins/php-yum/versions && bash common.sh ${type} install mbstring
|
||||
echo "install PHP-YUM[${type}] extend end"
|
||||
|
||||
#初始化
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/php-yum/index.py start ${type}
|
||||
cd ${rootPath} && python3 ${rootPath}/plugins/php-yum/index.py initd_install ${type}
|
||||
|
||||
if [ ! -f /usr/local/bin/composer ];then
|
||||
cd /tmp
|
||||
curl -sS https://getcomposer.org/installer | /opt/remi/php${type}/root/usr/bin/php
|
||||
|
||||
+64
-20
@@ -12,8 +12,6 @@ import shutil
|
||||
# sys.setdefaultencoding('utf8')
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
# sys.path.append("/usr/local/lib/python3.6/site-packages")
|
||||
|
||||
import mw
|
||||
|
||||
if mw.isAppleSystem():
|
||||
@@ -40,8 +38,12 @@ def getServerDir():
|
||||
|
||||
|
||||
def getInitDFile(version):
|
||||
if app_debug:
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return '/tmp/' + getPluginName()
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
return '/etc/rc.d/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName() + version
|
||||
|
||||
|
||||
@@ -52,13 +54,16 @@ def getArgs():
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
if t.strip() == '':
|
||||
tmp = []
|
||||
else:
|
||||
t = t.split(':', 1)
|
||||
tmp[t[0]] = t[1]
|
||||
tmp[t[0]] = t[1]
|
||||
elif args_len > 1:
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
|
||||
return tmp
|
||||
|
||||
|
||||
@@ -80,7 +85,7 @@ def getFpmConfFile(version):
|
||||
|
||||
def status_progress(version):
|
||||
# ps -ef|grep 'php/81' |grep -v grep | grep -v python | awk '{print $2}
|
||||
cmd = "ps -ef|grep 'php/" + version + \
|
||||
cmd = "ps aux|grep 'php/" + version + \
|
||||
"' |grep -v grep | grep -v python | awk '{print $2}'"
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
@@ -147,7 +152,7 @@ def contentReplace(content, version):
|
||||
|
||||
def makeOpenrestyConf():
|
||||
phpversions = ['00', '52', '53', '54', '55', '56',
|
||||
'70', '71', '72', '73', '74', '80', '81', '82']
|
||||
'70', '71', '72', '73', '74', '80', '81', '82', '83']
|
||||
|
||||
sdir = mw.getServerDir()
|
||||
|
||||
@@ -277,11 +282,11 @@ def initReplace(version):
|
||||
# systemd
|
||||
systemDir = mw.systemdCfgDir()
|
||||
systemService = systemDir + '/php' + version + '.service'
|
||||
systemServiceTpl = getPluginDir() + '/init.d/php.service.tpl'
|
||||
if version == '52':
|
||||
systemServiceTpl = getPluginDir() + '/init.d/php.service.52.tpl'
|
||||
|
||||
if os.path.exists(systemDir) and not os.path.exists(systemService):
|
||||
systemServiceTpl = getPluginDir() + '/init.d/php.service.tpl'
|
||||
if version == '52':
|
||||
systemServiceTpl = getPluginDir() + '/init.d/php.service.52.tpl'
|
||||
service_path = mw.getServerDir()
|
||||
se_content = mw.readFile(systemServiceTpl)
|
||||
se_content = se_content.replace('{$VERSION}', version)
|
||||
@@ -295,16 +300,23 @@ def initReplace(version):
|
||||
def phpOp(version, method):
|
||||
file = initReplace(version)
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
if method == 'stop' or method == 'restart':
|
||||
mw.execShell(file + ' ' + 'stop')
|
||||
|
||||
data = mw.execShell('systemctl ' + method + ' php' + version)
|
||||
current_os = mw.getOs()
|
||||
if current_os == "darwin":
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if current_os.startswith("freebsd"):
|
||||
data = mw.execShell('service php' + version + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
if method == 'stop' or method == 'restart':
|
||||
mw.execShell(file + ' ' + 'stop')
|
||||
|
||||
data = mw.execShell('systemctl ' + method + ' php' + version)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -336,9 +348,15 @@ def reload(version):
|
||||
|
||||
|
||||
def initdStatus(version):
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
initd_bin = getInitDFile(version)
|
||||
if os.path.exists(initd_bin):
|
||||
return 'ok'
|
||||
|
||||
shell_cmd = 'systemctl status php' + version + ' | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
@@ -347,17 +365,32 @@ def initdStatus(version):
|
||||
|
||||
|
||||
def initdInstall(version):
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
import shutil
|
||||
source_bin = initReplace(version)
|
||||
initd_bin = getInitDFile(version)
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
return 'ok'
|
||||
|
||||
mw.execShell('systemctl enable php' + version)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall(version):
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
initd_bin = getInitDFile(version)
|
||||
os.remove(initd_bin)
|
||||
return 'ok'
|
||||
|
||||
mw.execShell('systemctl disable php' + version)
|
||||
return 'ok'
|
||||
|
||||
@@ -857,7 +890,7 @@ def get_php_info(args):
|
||||
return getPhpinfo(args['version'])
|
||||
|
||||
|
||||
def getLibConf(version):
|
||||
def libConfCommon(version):
|
||||
fname = getConf(version)
|
||||
if not os.path.exists(fname):
|
||||
return mw.returnJson(False, '指定PHP版本不存在!')
|
||||
@@ -886,6 +919,17 @@ def getLibConf(version):
|
||||
else:
|
||||
lib['status'] = True
|
||||
libs.append(lib)
|
||||
return libs
|
||||
|
||||
|
||||
def get_lib_conf(data):
|
||||
libs = libConfCommon(data['version'])
|
||||
# print(libs)
|
||||
return mw.returnData(True, 'OK!', libs)
|
||||
|
||||
|
||||
def getLibConf(version):
|
||||
libs = libConfCommon(version)
|
||||
return mw.returnJson(True, 'OK!', libs)
|
||||
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
"name": "php",
|
||||
"title": "PHP",
|
||||
"coexist": true,
|
||||
"versions": ["53","54","55","56","70","71","72","73","74","80","81","82"],
|
||||
"updates": ["5.3.29","5.4.45","5.6.36","7.0.30","7.1.33","7.2.32","7.3.20","7.4.30","8.0.30","8.1.8","8.2.0"],
|
||||
"versions": ["53","54","55","56","70","71","72","73","74","80","81","82","83"],
|
||||
"updates": ["5.3.29","5.4.45","5.6.36","7.0.30","7.1.33","7.2.32","7.3.20","7.4.30","8.0.30","8.1.8","8.2.9","8.3.0"],
|
||||
"tip": "soft",
|
||||
"install_pre_inspection":true,
|
||||
"checks": "server/php/VERSION/bin/php",
|
||||
|
||||
@@ -34,7 +34,7 @@ function phpPostCallbak(method, version, args,callback){
|
||||
req_data['func'] = method;
|
||||
args['version'] = version;
|
||||
|
||||
if (typeof(args) == 'string'){
|
||||
if (typeof(args) == 'string' && args == ''){
|
||||
req_data['args'] = JSON.stringify(toArrayObject(args));
|
||||
} else {
|
||||
req_data['args'] = JSON.stringify(args);
|
||||
@@ -582,9 +582,13 @@ function getPHPInfo(version) {
|
||||
|
||||
|
||||
function phpLibConfig(version){
|
||||
|
||||
// phpPost('get_lib_conf', version, {}, function(rdata){
|
||||
// var rdata = $.parseJSON(rdata.data);
|
||||
// });
|
||||
|
||||
phpPost('get_lib_conf', version, '', function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
phpPostCallbak('get_lib_conf', version, {}, function(rdata){
|
||||
var rdata = rdata.data;
|
||||
|
||||
if (!rdata.status){
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
|
||||
@@ -13,9 +13,9 @@ rootPath=$(dirname "$rootPath")
|
||||
SERVER_ROOT=$rootPath/lib
|
||||
SOURCE_ROOT=$rootPath/source/lib
|
||||
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
HTTP_PREFIX="https://"
|
||||
if [ ! -z "$cn" ];then
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
if [ ! -z "$cn" ] || [ "$?" != "0" ] ;then
|
||||
HTTP_PREFIX="https://ghproxy.com/"
|
||||
fi
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ rootPath=$(dirname "$rootPath")
|
||||
SERVER_ROOT=$rootPath/lib
|
||||
SOURCE_ROOT=$rootPath/source/lib
|
||||
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
HTTP_PREFIX="https://"
|
||||
if [ ! -z "$cn" ];then
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
if [ ! -z "$cn" ] || [ "$?" != "0" ] ;then
|
||||
HTTP_PREFIX="https://ghproxy.com/"
|
||||
fi
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ SERVER_ROOT=$rootPath/lib
|
||||
SOURCE_ROOT=$rootPath/source/lib
|
||||
|
||||
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
HTTP_PREFIX="https://"
|
||||
if [ ! -z "$cn" ];then
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
if [ ! -z "$cn" ] || [ "$?" != "0" ] ;then
|
||||
HTTP_PREFIX="https://ghproxy.com/"
|
||||
fi
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ rootPath=$(dirname "$rootPath")
|
||||
SERVER_ROOT=$rootPath/lib
|
||||
SOURCE_ROOT=$rootPath/source/lib
|
||||
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
HTTP_PREFIX="https://"
|
||||
if [ ! -z "$cn" ];then
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
if [ ! -z "$cn" ] || [ "$?" != "0" ] ;then
|
||||
HTTP_PREFIX="https://ghproxy.com/"
|
||||
fi
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ rootPath=$(dirname "$rootPath")
|
||||
SERVER_ROOT=$rootPath/lib
|
||||
SOURCE_ROOT=$rootPath/source/lib
|
||||
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
HTTP_PREFIX="https://"
|
||||
if [ ! -z "$cn" ];then
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
if [ ! -z "$cn" ] || [ "$?" != "0" ] ;then
|
||||
HTTP_PREFIX="https://ghproxy.com/"
|
||||
fi
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
opensslVersion="1.1.1p"
|
||||
# echo $rootPath
|
||||
|
||||
SERVER_ROOT=$rootPath/lib
|
||||
SOURCE_ROOT=$rootPath/source/lib
|
||||
mkdir -p $SOURCE_ROOT
|
||||
|
||||
if [ ! -d ${SERVER_ROOT}/openssl11 ];then
|
||||
cd ${SOURCE_ROOT}
|
||||
if [ ! -f ${SOURCE_ROOT}/openssl-${opensslVersion}.tar.gz ];then
|
||||
wget --no-check-certificate -O ${SOURCE_ROOT}/openssl-${opensslVersion}.tar.gz https://www.openssl.org/source/openssl-${opensslVersion}.tar.gz
|
||||
fi
|
||||
tar -zxvf openssl-${opensslVersion}.tar.gz
|
||||
cd openssl-${opensslVersion}
|
||||
./config --prefix=${SERVER_ROOT}/openssl11 zlib-dynamic shared
|
||||
make && make install
|
||||
fi
|
||||
|
||||
@@ -13,9 +13,9 @@ rootPath=$(dirname "$rootPath")
|
||||
SERVER_ROOT=$rootPath/lib
|
||||
SOURCE_ROOT=$rootPath/source/lib
|
||||
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
HTTP_PREFIX="https://"
|
||||
if [ ! -z "$cn" ];then
|
||||
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
if [ ! -z "$cn" ] || [ "$?" != "0" ] ;then
|
||||
HTTP_PREFIX="https://ghproxy.com/"
|
||||
fi
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ if [ ! -d $sourcePath/php/php${PHP_VER} ];then
|
||||
# 中国优化安装
|
||||
cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
LOCAL_ADDR=common
|
||||
if [ ! -z "$cn" ];then
|
||||
if [ ! -z "$cn" ] || [ "$?" != "0" ] ;then
|
||||
LOCAL_ADDR=cn
|
||||
fi
|
||||
|
||||
@@ -70,7 +70,7 @@ fi
|
||||
|
||||
ZIP_OPTION='--enable-zip'
|
||||
libzip_version=`pkg-config libzip --modversion`
|
||||
if version_lt "$libzip_version" "0.11.0" ;then
|
||||
if [ "$?" != "0" ] || version_lt "$libzip_version" "0.11.0" ;then
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash libzip.sh
|
||||
export PKG_CONFIG_PATH=$serverPath/lib/libzip/lib/pkgconfig
|
||||
ZIP_OPTION="--with-libzip=$serverPath/lib/libzip"
|
||||
|
||||
@@ -16,7 +16,7 @@ function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)"
|
||||
function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
|
||||
|
||||
|
||||
version=8.0.29
|
||||
version=8.0.30
|
||||
PHP_VER=80
|
||||
Install_php()
|
||||
{
|
||||
@@ -140,6 +140,7 @@ if [ ! -d $serverPath/php/${PHP_VER} ];then
|
||||
--enable-sysvshm \
|
||||
--disable-intl \
|
||||
--disable-fileinfo \
|
||||
--with-password-argon2 \
|
||||
$OPTIONS \
|
||||
--enable-fpm
|
||||
make clean && make -j${cpuCore} && make install && make clean
|
||||
|
||||
@@ -16,7 +16,7 @@ function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)"
|
||||
function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
|
||||
|
||||
|
||||
version=8.1.20
|
||||
version=8.1.22
|
||||
PHP_VER=81
|
||||
Install_php()
|
||||
{
|
||||
@@ -133,6 +133,7 @@ if [ ! -d $serverPath/php/${PHP_VER} ];then
|
||||
--enable-sysvshm \
|
||||
--disable-intl \
|
||||
--disable-fileinfo \
|
||||
--with-password-argon2 \
|
||||
$OPTIONS \
|
||||
--enable-fpm
|
||||
make clean && make -j${cpuCore} && make install && make clean
|
||||
|
||||
@@ -16,7 +16,7 @@ function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)"
|
||||
function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
|
||||
|
||||
|
||||
version=8.2.8
|
||||
version=8.2.9
|
||||
PHP_VER=82
|
||||
Install_php()
|
||||
{
|
||||
@@ -135,6 +135,7 @@ if [ ! -d $serverPath/php/${PHP_VER} ];then
|
||||
--enable-sysvshm \
|
||||
--disable-intl \
|
||||
--disable-fileinfo \
|
||||
--with-password-argon2 \
|
||||
$OPTIONS \
|
||||
--enable-fpm
|
||||
make clean && make -j${cpuCore} && make install && make clean
|
||||
|
||||
Executable
+157
@@ -0,0 +1,157 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
sourcePath=${serverPath}/source
|
||||
sysName=`uname`
|
||||
install_tmp=${rootPath}/tmp/mw_install.pl
|
||||
|
||||
function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
|
||||
function version_le() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" == "$1"; }
|
||||
function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; }
|
||||
function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }
|
||||
|
||||
version=8.3.0alpha2
|
||||
PHP_VER=83
|
||||
Install_php()
|
||||
{
|
||||
#------------------------ install start ------------------------------------#
|
||||
echo "安装php-${version} ..." > $install_tmp
|
||||
mkdir -p $sourcePath/php
|
||||
mkdir -p $serverPath/php
|
||||
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash freetype_new.sh
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash zlib.sh
|
||||
|
||||
# redat ge 8
|
||||
which yum
|
||||
if [ "$?" == "0" ];then
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash oniguruma.sh
|
||||
fi
|
||||
|
||||
if [ ! -d $sourcePath/php/php${PHP_VER} ];then
|
||||
|
||||
# ----------------------------------------------------------------------- #
|
||||
# 中国优化安装
|
||||
# cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"")
|
||||
# LOCAL_ADDR=common
|
||||
# if [ ! -z "$cn" ];then
|
||||
# LOCAL_ADDR=cn
|
||||
# fi
|
||||
|
||||
# if [ "$LOCAL_ADDR" == "cn" ];then
|
||||
# if [ ! -f $sourcePath/php/php-${version}.tar.xz ];then
|
||||
# wget --no-check-certificate -O $sourcePath/php/php-${version}.tar.xz https://mirrors.sohu.com/php/php-${version}.tar.xz
|
||||
# fi
|
||||
# fi
|
||||
# ----------------------------------------------------------------------- #
|
||||
|
||||
|
||||
if [ ! -f $sourcePath/php/php-${version}.tar.xz ];then
|
||||
wget --no-check-certificate -O $sourcePath/php/php-${version}.tar.xz https://downloads.php.net/~eric/php-${version}.tar.xz
|
||||
fi
|
||||
|
||||
cd $sourcePath/php && tar -Jxf $sourcePath/php/php-${version}.tar.xz
|
||||
mv $sourcePath/php/php-${version} $sourcePath/php/php${PHP_VER}
|
||||
fi
|
||||
|
||||
cd $sourcePath/php/php${PHP_VER}
|
||||
|
||||
OPTIONS=''
|
||||
if [ $sysName == 'Darwin' ]; then
|
||||
OPTIONS='--without-iconv'
|
||||
OPTIONS="${OPTIONS} --with-curl=${serverPath}/lib/curl"
|
||||
else
|
||||
OPTIONS='--without-iconv'
|
||||
OPTIONS="${OPTIONS} --with-curl"
|
||||
fi
|
||||
|
||||
IS_64BIT=`getconf LONG_BIT`
|
||||
if [ "$IS_64BIT" == "64" ];then
|
||||
OPTIONS="${OPTIONS} --with-libdir=lib64"
|
||||
fi
|
||||
|
||||
# ----- cpu start ------
|
||||
if [ -z "${cpuCore}" ]; then
|
||||
cpuCore="1"
|
||||
fi
|
||||
|
||||
if [ -f /proc/cpuinfo ];then
|
||||
cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l`
|
||||
fi
|
||||
|
||||
MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}')
|
||||
if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then
|
||||
if [ "${cpuCore}" -gt "${MEM_INFO}" ];then
|
||||
cpuCore="${MEM_INFO}"
|
||||
fi
|
||||
else
|
||||
cpuCore="1"
|
||||
fi
|
||||
|
||||
if [ "$cpuCore" -gt "2" ];then
|
||||
cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'`
|
||||
else
|
||||
cpuCore="1"
|
||||
fi
|
||||
# ----- cpu end ------
|
||||
|
||||
ZIP_OPTION='--with-zip'
|
||||
libzip_version=`pkg-config libzip --modversion`
|
||||
if version_lt "$libzip_version" "0.11.0" ;then
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash libzip.sh
|
||||
export PKG_CONFIG_PATH=$serverPath/lib/libzip/lib/pkgconfig
|
||||
ZIP_OPTION="--with-zip=$serverPath/lib/libzip"
|
||||
fi
|
||||
|
||||
|
||||
echo "$sourcePath/php/php${PHP_VER}"
|
||||
|
||||
if [ ! -d $serverPath/php/${PHP_VER} ];then
|
||||
cd $sourcePath/php/php${PHP_VER}
|
||||
./buildconf --force
|
||||
./configure \
|
||||
--prefix=$serverPath/php/${PHP_VER} \
|
||||
--exec-prefix=$serverPath/php/${PHP_VER} \
|
||||
--with-config-file-path=$serverPath/php/${PHP_VER}/etc \
|
||||
--enable-mysqlnd \
|
||||
--with-mysqli=mysqlnd \
|
||||
--with-pdo-mysql=mysqlnd \
|
||||
--with-zlib-dir=$serverPath/lib/zlib \
|
||||
$ZIP_OPTION \
|
||||
--enable-mbstring \
|
||||
--enable-ftp \
|
||||
--enable-sockets \
|
||||
--enable-simplexml \
|
||||
--enable-soap \
|
||||
--enable-posix \
|
||||
--enable-sysvmsg \
|
||||
--enable-sysvsem \
|
||||
--enable-sysvshm \
|
||||
--disable-intl \
|
||||
--disable-fileinfo \
|
||||
--with-password-argon2 \
|
||||
$OPTIONS \
|
||||
--enable-fpm
|
||||
make clean && make -j${cpuCore} && make install && make clean
|
||||
fi
|
||||
#------------------------ install end ------------------------------------#
|
||||
}
|
||||
|
||||
Uninstall_php()
|
||||
{
|
||||
$serverPath/php/init.d/php${PHP_VER} stop
|
||||
rm -rf $serverPath/php/${PHP_VER}
|
||||
echo "卸载php-${version}..." > $install_tmp
|
||||
}
|
||||
|
||||
action=${1}
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_php
|
||||
else
|
||||
Uninstall_php
|
||||
fi
|
||||
@@ -26,7 +26,7 @@ ROOT_DIR=$(cd "$(dirname "$0")"; pwd)
|
||||
# echo "php${PHP_VER} -- end"
|
||||
|
||||
|
||||
PHP_VER_LIST=(53 54 55 56 70 71 72 73 74 80 81 82)
|
||||
PHP_VER_LIST=(53 54 55 56 70 71 72 73 74 80 81 82 83)
|
||||
# PHP_VER_LIST=(81)
|
||||
for PHP_VER in ${PHP_VER_LIST[@]}; do
|
||||
echo "php${PHP_VER} -- start"
|
||||
@@ -37,7 +37,7 @@ for PHP_VER in ${PHP_VER_LIST[@]}; do
|
||||
done
|
||||
|
||||
cd $DIR
|
||||
PHP_VER_LIST=(53 54 55 56 70 71 72 73 74 80 81 82)
|
||||
PHP_VER_LIST=(53 54 55 56 70 71 72 73 74 80 81 82 83)
|
||||
# yar
|
||||
PHP_EXT_LIST=(ZendGuardLoader pdo mysqlnd sqlite3 openssl pcntl opcache mcrypt fileinfo \
|
||||
exif gd intl memcache memcached redis imagemagick xdebug \
|
||||
|
||||
@@ -40,6 +40,10 @@ else
|
||||
BAK=''
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/lib/libzip ];then
|
||||
cd ${rootPath}/plugins/php/lib && /bin/bash libzip.sh
|
||||
fi
|
||||
|
||||
export PKG_CONFIG_PATH=/www/server/lib/libzip/lib/pkgconfig
|
||||
|
||||
Install_lib()
|
||||
@@ -51,6 +55,7 @@ Install_lib()
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -f "$extFile" ];then
|
||||
|
||||
if [ ! -d $sourcePath/php${version}/ext ];then
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "脚本解密",
|
||||
"msg": "用于解密SG11加密脚本!",
|
||||
@@ -71,7 +72,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "加密库",
|
||||
"msg": "Sodium加密库的包装器",
|
||||
@@ -88,7 +90,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "运算库",
|
||||
"msg": "一个开源的数学运算库",
|
||||
@@ -109,7 +112,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "缓存器",
|
||||
"msg": "用于加速PHP脚本!",
|
||||
@@ -130,7 +134,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "SSL!",
|
||||
@@ -146,7 +151,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "加密软件!",
|
||||
@@ -167,7 +173,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "高精度计算!",
|
||||
@@ -188,7 +195,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "缓存器",
|
||||
"msg": "用于信号控制!",
|
||||
@@ -210,7 +218,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "编码转换!",
|
||||
@@ -230,7 +239,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "用于FILE!",
|
||||
@@ -250,7 +260,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "用于图像文件格式!",
|
||||
@@ -267,7 +278,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "序列化扩展!",
|
||||
@@ -289,7 +301,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "国际化与本地化!",
|
||||
@@ -311,7 +324,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "通用GD库!",
|
||||
@@ -333,7 +347,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "提供国际化支持",
|
||||
@@ -355,7 +370,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "缓存器",
|
||||
"msg": "强大的内容缓存器,不支持集群",
|
||||
@@ -376,7 +392,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "缓存器",
|
||||
"msg": "强大的内容缓存器,支持集群",
|
||||
@@ -398,7 +415,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "缓存器",
|
||||
"msg": "更强大的内容缓存器,支持集群",
|
||||
@@ -445,7 +463,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "比GD更强大的图形库",
|
||||
@@ -466,7 +485,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "调试器",
|
||||
"msg": "不多说,不了解的不要安装",
|
||||
@@ -488,7 +508,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "性能分析",
|
||||
"msg": "不多说,不了解的不要安装!",
|
||||
@@ -509,7 +530,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "异步、并行、高性能网络通信引擎",
|
||||
@@ -553,7 +575,9 @@
|
||||
"73",
|
||||
"74",
|
||||
"80",
|
||||
"81"
|
||||
"81",
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "框架",
|
||||
"msg": "Yaf是一个C语言编写的PHP框架",
|
||||
@@ -605,7 +629,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "通用扩展",
|
||||
"msg": "Mongodb数据库连接驱动",
|
||||
@@ -622,7 +647,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "缓存器",
|
||||
"msg": "高性能无锁共享内存Cache",
|
||||
@@ -643,7 +669,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "大数据",
|
||||
"msg": "SOLR全文搜索服务",
|
||||
@@ -664,7 +691,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "日志",
|
||||
"msg": "SeasLog高性能日志记录",
|
||||
@@ -678,7 +706,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "压缩",
|
||||
"msg": "压缩组件",
|
||||
@@ -699,7 +728,8 @@
|
||||
"74",
|
||||
"80",
|
||||
"81",
|
||||
"82"
|
||||
"82",
|
||||
"83"
|
||||
],
|
||||
"type": "压缩",
|
||||
"msg": "压缩组件",
|
||||
|
||||
+46
-10
@@ -27,8 +27,13 @@ def getServerDir():
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return '/tmp/' + getPluginName()
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
return '/etc/rc.d/' + getPluginName()
|
||||
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
@@ -69,7 +74,7 @@ def getArgs():
|
||||
|
||||
def status():
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep redis |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'")
|
||||
"ps aux|grep redis |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'")
|
||||
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -113,8 +118,8 @@ def initDreplace():
|
||||
# systemd
|
||||
systemDir = mw.systemdCfgDir()
|
||||
systemService = systemDir + '/redis.service'
|
||||
systemServiceTpl = getPluginDir() + '/init.d/redis.service.tpl'
|
||||
if os.path.exists(systemDir) and not os.path.exists(systemService):
|
||||
systemServiceTpl = getPluginDir() + '/init.d/redis.service.tpl'
|
||||
service_path = mw.getServerDir()
|
||||
se_content = mw.readFile(systemServiceTpl)
|
||||
se_content = se_content.replace('{$SERVER_PATH}', service_path)
|
||||
@@ -127,16 +132,23 @@ def initDreplace():
|
||||
def redisOp(method):
|
||||
file = initDreplace()
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
data = mw.execShell('systemctl ' + method + ' redis')
|
||||
current_os = mw.getOs()
|
||||
if current_os == "darwin":
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
data = mw.execShell(file + ' start')
|
||||
if current_os.startswith("freebsd"):
|
||||
data = mw.execShell('service ' + getPluginName() + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
data = mw.execShell('systemctl ' + method + ' redis')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
return data[1]
|
||||
|
||||
|
||||
def start():
|
||||
@@ -211,9 +223,15 @@ def runInfo():
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
return 'ok'
|
||||
|
||||
shell_cmd = 'systemctl status ' + \
|
||||
getPluginName() + ' | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(shell_cmd)
|
||||
@@ -223,17 +241,35 @@ def initdStatus():
|
||||
|
||||
|
||||
def initdInstall():
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
# freebsd initd install
|
||||
if current_os.startswith('freebsd'):
|
||||
import shutil
|
||||
source_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="YES"')
|
||||
return 'ok'
|
||||
|
||||
mw.execShell('systemctl enable ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if mw.isAppleSystem():
|
||||
current_os = mw.getOs()
|
||||
if current_os == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
if current_os.startswith('freebsd'):
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
mw.execShell('sysrc ' + getPluginName() + '_enable="NO"')
|
||||
return 'ok'
|
||||
|
||||
mw.execShell('systemctl disable ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ Install_redis()
|
||||
|
||||
mkdir -p $serverPath/redis
|
||||
mkdir -p $serverPath/redis/data
|
||||
cd redis-${VERSION} && make PREFIX=$serverPath/redis install
|
||||
cd redis-${VERSION} && gmake PREFIX=$serverPath/redis install
|
||||
sed '/^ *#/d' redis.conf > $serverPath/redis/redis.conf
|
||||
|
||||
if [ -d $serverPath/redis ];then
|
||||
|
||||
@@ -22,6 +22,7 @@ def init(bot):
|
||||
bot.set_my_commands(
|
||||
commands=[
|
||||
telebot.types.BotCommand("start", "查看帮助信息"),
|
||||
telebot.types.BotCommand("faq", "查看bbs帖子主题【?:】"),
|
||||
telebot.types.BotCommand("faq", ""),
|
||||
telebot.types.BotCommand("music", "搜索网易音乐"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -52,9 +52,9 @@ def send_msg(bot, tag='ad', trigger_time=300):
|
||||
|
||||
# https://t.me/gjgzs2022 | 22/m
|
||||
# 高价收量 👑 集团收量 ❤️ 流量变现/支付宝代付 ❤️ 微信代付/实名认证/过人脸🕵️♀️各种账号处理✅ | 28/m
|
||||
# https://zhaoziyuan.la/ | web | 15/m | 2m | next,9/15
|
||||
# https://zhaoziyuan.pw/ | web | 15/m | 2m | next,9/15 | @baleite
|
||||
# 腾云机场 |9/m
|
||||
# 🚀鲲鹏VPN | 13/m
|
||||
# 🚀鲲鹏VPN | 13/m | next,10/10
|
||||
keyboard = [
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
@@ -100,7 +100,7 @@ def send_msg(bot, tag='ad', trigger_time=300):
|
||||
markup = types.InlineKeyboardMarkup(keyboard)
|
||||
|
||||
msg_notice = "由于在解决的问题的时候,不给信息,无法了解情况。以后不再群里回答技术问题。全部去论坛提问。在解决问题的过程中,可能需要面板信息,和SSH信息,如无法提供请不要提问。为了让群里都知晓。轮播一年!\n"
|
||||
msg_notice += "为了不打扰双方,私聊解决问题先转100U,否则无视!\n"
|
||||
msg_notice += "为了不打扰双方,私聊解决问题先转1000U,否则无视!\n"
|
||||
msg = bot.send_message(chat_id, msg_notice, reply_markup=markup)
|
||||
|
||||
# print(msg.message_id)
|
||||
|
||||
@@ -191,20 +191,17 @@ def run(bot, message):
|
||||
# print(text_body)
|
||||
if isThisCmd('/?:', text_body):
|
||||
cmd_text = getReadCmd('/?:', text_body)
|
||||
cmd_text = cmd_text.strip().strip(":")
|
||||
if cmd_text == "":
|
||||
return bot.send_message(message.chat.id, "搜索内容不能为空, 例如:/?: 数据库")
|
||||
return searchFaq(bot, message, cmd_text)
|
||||
|
||||
# if text_body.find('?') > -1 or text_body.find('?') > -1:
|
||||
# return_msg = "你似乎在寻找【" + text_body + "】答案:\n"
|
||||
# return_msg += "/faq:开始寻找你的问题\n"
|
||||
# keyboard = [
|
||||
# [
|
||||
# types.InlineKeyboardButton(
|
||||
# text="如未找到,可以在论坛补充你的提问!", url='https://bbs.midoks.me'),
|
||||
# ]
|
||||
|
||||
# ]
|
||||
# markup = types.InlineKeyboardMarkup(keyboard)
|
||||
# bot.reply_to(message, return_msg, reply_markup=markup)
|
||||
if isThisCmd('/faq', text_body):
|
||||
cmd_text = getReadCmd('/faq', text_body)
|
||||
cmd_text = cmd_text.strip().strip(":")
|
||||
if cmd_text == "":
|
||||
return bot.send_message(message.chat.id, "搜索内容不能为空, 例如:/faq 数据库")
|
||||
return searchFaq(bot, message, cmd_text)
|
||||
|
||||
return bot
|
||||
|
||||
|
||||
@@ -0,0 +1,341 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
import base64
|
||||
import threading
|
||||
|
||||
|
||||
import telebot
|
||||
from telebot import types
|
||||
from telebot.util import quick_markup
|
||||
|
||||
# 网易音乐搜索
|
||||
|
||||
|
||||
def isThisCmd(cmd, msg):
|
||||
clen = len(cmd)
|
||||
msg_len = len(msg)
|
||||
if msg_len < clen:
|
||||
return False
|
||||
|
||||
check_msg = msg[0:clen]
|
||||
if cmd == check_msg:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def getReadCmd(cmd, msg):
|
||||
clen = len(cmd)
|
||||
msg_len = len(msg)
|
||||
real_msg = msg[clen:]
|
||||
return real_msg
|
||||
|
||||
|
||||
def ip2long(ip):
|
||||
import struct
|
||||
import socket
|
||||
return struct.unpack("!L", socket.inet_aton(ip))[0]
|
||||
|
||||
|
||||
def long2ip(longip):
|
||||
import struct
|
||||
import socket
|
||||
return socket.inet_ntoa(struct.pack('!L', longip))
|
||||
|
||||
|
||||
def mt_rand(a, b):
|
||||
import random
|
||||
return random.randint(a, b)
|
||||
|
||||
|
||||
def httpPost(url, data, timeout=10):
|
||||
"""
|
||||
发送POST请求
|
||||
@url 被请求的URL地址(必需)
|
||||
@data POST参数,可以是字符串或字典(必需)
|
||||
@timeout 超时时间默认60秒
|
||||
return string
|
||||
"""
|
||||
try:
|
||||
import urllib.request
|
||||
import ssl
|
||||
try:
|
||||
ssl._create_default_https_context = ssl._create_unverified_context
|
||||
except:
|
||||
pass
|
||||
|
||||
headers = {
|
||||
'Referer': 'https://music.163.com/',
|
||||
'Cookie': 'appver=8.2.30; os=iPhone OS; osver=15.0; EVNSM=1.0.0; buildver=2206; channel=distribution; machineid=iPhone13.3',
|
||||
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 CloudMusic/0.1.1 NeteaseMusic/8.2.30',
|
||||
'X-Real-IP': long2ip(mt_rand(1884815360, 1884890111)),
|
||||
'Accept': '*/*',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
|
||||
'Connection': 'keep-alive',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
}
|
||||
data = urllib.parse.urlencode(data).encode('utf-8')
|
||||
req = urllib.request.Request(url, data, headers=headers)
|
||||
response = urllib.request.urlopen(req, timeout=timeout)
|
||||
result = response.read()
|
||||
if type(result) == bytes:
|
||||
result = result.decode('utf-8')
|
||||
return result
|
||||
except Exception as ex:
|
||||
return str(ex)
|
||||
|
||||
|
||||
def musicSearch(kw, page=1, page_size=5):
|
||||
m_offset = (int(page) - 1) * int(page_size)
|
||||
data = httpPost('http://music.163.com/api/cloudsearch/pc', {
|
||||
's': kw,
|
||||
'type': '1',
|
||||
'total': 'true',
|
||||
'limit': page_size,
|
||||
'offset': m_offset,
|
||||
})
|
||||
# data_a = json.loads(data)
|
||||
# print(data)
|
||||
# exit()
|
||||
return json.loads(data)
|
||||
|
||||
|
||||
def musicSongD(mid):
|
||||
data = httpPost('http://music.163.com/api/v3/song/detail/', {
|
||||
'c': '[{"id":' + str(mid) + ',"v":0}]',
|
||||
})
|
||||
# print(data)
|
||||
return json.loads(data)
|
||||
|
||||
|
||||
def musicSongDataUrl(mid):
|
||||
data = httpPost('http://music.163.com/api/song/enhance/player/url', {
|
||||
'br': 320 * 1000,
|
||||
'ids': [mid],
|
||||
})
|
||||
return json.loads(data)
|
||||
|
||||
|
||||
def writeLog(log_str):
|
||||
if __name__ == "__main__":
|
||||
print(log_str)
|
||||
|
||||
now = mw.getDateFromNow()
|
||||
log_file = mw.getServerDir() + '/tgbot/task.log'
|
||||
mw.writeFileLog(now + ':' + log_str, log_file, limit_size=5 * 1024)
|
||||
return True
|
||||
|
||||
|
||||
def tgSearchMusic_t(cmd_text):
|
||||
data = musicSearch(cmd_text, 1, 5)
|
||||
|
||||
if data['code'] == 200 and len(data['result']['songs']) > 0:
|
||||
slist = data['result']['songs']
|
||||
print(slist)
|
||||
else:
|
||||
keyboard = [
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="论坛", url='https://bbs.midoks.me'),
|
||||
types.InlineKeyboardButton(
|
||||
text="搜索", url='https://bbs.midoks.me/search.php')
|
||||
],
|
||||
[
|
||||
types.InlineKeyboardButton(
|
||||
text="关闭消息", callback_data='bbs_search_close')
|
||||
]
|
||||
|
||||
]
|
||||
markup = types.InlineKeyboardMarkup(keyboard)
|
||||
bot.send_message(
|
||||
message.chat.id, "未找到合适内容,请在官方论坛[bbs.midoks.me]提问!", reply_markup=markup)
|
||||
return True
|
||||
|
||||
|
||||
def tgSearchMusic(bot, message, cmd_text):
|
||||
import math
|
||||
data = musicSearch(cmd_text, 1, 5)
|
||||
if data['code'] == 200 and len(data['result']['songs']) > 0:
|
||||
keyboard = []
|
||||
slist = data['result']['songs']
|
||||
page_total = math.ceil(data['result']['songCount'] / 5)
|
||||
|
||||
for x in slist:
|
||||
author = ''
|
||||
if len(x['ar']) > 0:
|
||||
author = ' - ' + x['ar'][0]['name']
|
||||
keyboard.append([types.InlineKeyboardButton(
|
||||
text=x['name'] + author, callback_data='m163_id:' + str(x['id']))])
|
||||
|
||||
keyboard.append([
|
||||
types.InlineKeyboardButton(
|
||||
text="下一页", callback_data='m163_next_page_2'),
|
||||
types.InlineKeyboardButton(
|
||||
text="第1页,共" + str(page_total) + "页", callback_data='m163_page_total')
|
||||
])
|
||||
|
||||
keyboard.append([types.InlineKeyboardButton(
|
||||
text="关闭消息", callback_data='m163_search_close')])
|
||||
|
||||
# print(keyboard)
|
||||
markup = types.InlineKeyboardMarkup(keyboard)
|
||||
bot.send_message(message.chat.id, "寻找【" +
|
||||
cmd_text.strip() + "】歌曲如下:", reply_markup=markup)
|
||||
else:
|
||||
bot.send_message(message.chat.id, "未找到合适内容")
|
||||
return True
|
||||
|
||||
|
||||
def getFaqKw(cmd):
|
||||
matchObj = re.match(r'寻找【(.*?)】歌曲如下', cmd, re.M | re.I)
|
||||
data = matchObj.groups()
|
||||
if len(data) > 0:
|
||||
return True, data[0]
|
||||
return False, ''
|
||||
|
||||
|
||||
def cleanMusicFileExpire(dir):
|
||||
pass
|
||||
|
||||
|
||||
def downloadAndUpMusic(bot, chat_id, mid, title):
|
||||
import requests
|
||||
murl_data = musicSongDataUrl(int(mid))
|
||||
murl = murl_data['data'][0]['url']
|
||||
def_dir = '/tmp/tgbot_music'
|
||||
if not os.path.exists(def_dir):
|
||||
os.mkdir(def_dir)
|
||||
|
||||
def_abs_path = def_dir + '/' + title + '.mp3'
|
||||
# print('downloadAndUpMusic' + ":" + str(murl))
|
||||
if murl:
|
||||
msg_t = bot.send_message(chat_id, "已经获取资源URL,本地下载中...")
|
||||
response = requests.get(murl)
|
||||
|
||||
with open(def_abs_path, "wb") as f:
|
||||
f.write(response.content)
|
||||
|
||||
bot.edit_message_text(
|
||||
chat_id=chat_id, message_id=msg_t.message_id, text="本地下载完,正在上传中...")
|
||||
|
||||
audio = open(def_abs_path, 'rb')
|
||||
bot.send_audio(chat_id, audio)
|
||||
|
||||
bot.edit_message_text(
|
||||
chat_id=chat_id, message_id=msg_t.message_id, text="上传结束...1s自动删除")
|
||||
|
||||
time.sleep(1)
|
||||
bot.delete_message(chat_id=chat_id, message_id=msg_t.message_id)
|
||||
else:
|
||||
bot.send_message(chat_id, "无效资源")
|
||||
|
||||
if os.path.exists(def_abs_path):
|
||||
os.remove(def_abs_path)
|
||||
|
||||
# cleanMusicFileExpire(def_dir)
|
||||
return True
|
||||
|
||||
|
||||
def answer_callback_query(bot, call):
|
||||
import math
|
||||
keyword = call.data
|
||||
# print(keyword)
|
||||
if keyword == 'm163_search_close':
|
||||
bot.delete_message(chat_id=call.message.chat.id,
|
||||
message_id=call.message.message_id)
|
||||
return
|
||||
|
||||
# 音乐下载
|
||||
if keyword.startswith('m163_id:'):
|
||||
t = keyword.split(":")
|
||||
inline_keyboard = call.json['message'][
|
||||
"reply_markup"]["inline_keyboard"]
|
||||
|
||||
def_file_name = 'demo'
|
||||
for x in inline_keyboard:
|
||||
# print(x)
|
||||
if x[0]['callback_data'] == keyword:
|
||||
def_file_name = x[0]['text']
|
||||
# print(call.message)
|
||||
downloadAndUpMusic(bot, call.message.chat.id, t[1], def_file_name)
|
||||
bot.delete_message(chat_id=call.message.chat.id,
|
||||
message_id=call.message.message_id)
|
||||
return True
|
||||
|
||||
is_m163_page = False
|
||||
p = 1
|
||||
if keyword.startswith('m163_next_page'):
|
||||
is_m163_page = True
|
||||
p = keyword.replace('m163_next_page_', '')
|
||||
|
||||
if keyword.startswith('m163_pre_page'):
|
||||
is_m163_page = True
|
||||
p = keyword.replace('m163_pre_page_', '')
|
||||
|
||||
if is_m163_page:
|
||||
is_match, cmd_text = getFaqKw(call.message.text)
|
||||
if not is_match:
|
||||
bot.edit_message_text(
|
||||
chat_id=call.message.chat.id, message_id=call.message.message_id, text="出现错误!")
|
||||
return
|
||||
|
||||
data = musicSearch(cmd_text, p, 5)
|
||||
|
||||
dlist = data['result']['songs']
|
||||
page_total = math.ceil(data['result']['songCount'] / 5)
|
||||
|
||||
keyboard = []
|
||||
for x in dlist:
|
||||
author = ''
|
||||
if len(x['ar']) > 0:
|
||||
author = ' - ' + x['ar'][0]['name']
|
||||
keyboard.append([types.InlineKeyboardButton(
|
||||
text=x['name'] + author, callback_data='m163_id:' + str(x['id']))])
|
||||
|
||||
page_nav = []
|
||||
if int(p) > 1:
|
||||
page_nav.append(types.InlineKeyboardButton(
|
||||
text="上一页", callback_data='m163_pre_page_' + str(int(p) - 1)))
|
||||
|
||||
if int(p) < page_total:
|
||||
page_nav.append(types.InlineKeyboardButton(
|
||||
text="下一页", callback_data='m163_next_page_' + str(int(p) + 1)))
|
||||
|
||||
page_nav.append(types.InlineKeyboardButton(
|
||||
text="第" + str(p) + "页,共" + str(page_total) + "页", callback_data='m163_page_total'))
|
||||
|
||||
keyboard.append(page_nav)
|
||||
|
||||
keyboard.append([types.InlineKeyboardButton(
|
||||
text="关闭消息", callback_data='m163_search_close')])
|
||||
|
||||
markup = types.InlineKeyboardMarkup(keyboard)
|
||||
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,
|
||||
text=call.message.text, reply_markup=markup)
|
||||
|
||||
|
||||
def run(bot, message):
|
||||
text_body = message.text
|
||||
|
||||
if isThisCmd('/music', text_body):
|
||||
cmd_text = getReadCmd('/music', text_body)
|
||||
cmd_text = cmd_text.strip().strip(":")
|
||||
if cmd_text == "":
|
||||
return bot.send_message(message.chat.id, "搜索内容不能为空, 例如:/music 刀郎")
|
||||
return tgSearchMusic(bot, message, cmd_text)
|
||||
|
||||
return bot
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# cleanMusicFileExpire("/tmp/tgbot_music")
|
||||
# tgSearchMusic_t("一夜泥工")
|
||||
# print(long2ip(mt_rand(1884815360, 1884890111)))
|
||||
t = musicSongDataUrl(2063487880)
|
||||
print(t['data'])
|
||||
print("111")
|
||||
@@ -113,7 +113,7 @@ class App():
|
||||
|
||||
def getSshInfo(self, file):
|
||||
rdata = mw.readFile(file)
|
||||
destr = mw.enDoubleCrypt('mdserver-web', rdata)
|
||||
destr = mw.deDoubleCrypt('mdserver-web', rdata)
|
||||
return json.loads(destr)
|
||||
|
||||
def get_server_by_host(self):
|
||||
@@ -150,15 +150,19 @@ class App():
|
||||
info_file = self.__host_dir + '/' + name + '/info.json'
|
||||
if not os.path.exists(info_file):
|
||||
continue
|
||||
|
||||
host_info = {}
|
||||
try:
|
||||
info_tmp = self.getSshInfo(info_file)
|
||||
host_info = {}
|
||||
|
||||
host_info['host'] = name
|
||||
host_info['port'] = info_tmp['port']
|
||||
host_info['ps'] = info_tmp['ps']
|
||||
# host_info['sort'] = int(info_tmp['sort'])
|
||||
except Exception as e:
|
||||
print(e)
|
||||
# print(e)
|
||||
return mw.returnJson(False, str(e))
|
||||
|
||||
# if os.path.exists(info_file):
|
||||
# os.remove(info_file)
|
||||
# continue
|
||||
|
||||
+4
-3
@@ -481,7 +481,8 @@ def api(reqClass=None, reqAction=None, reqData=None):
|
||||
return mw.returnJson(False, '请指定请求方法')
|
||||
|
||||
classFile = ('config_api', 'crontab_api', 'files_api', 'firewall_api',
|
||||
'plugins_api', 'system_api', 'site_api', 'task_api')
|
||||
'plugins_api', 'system_api', 'site_api', 'task_api',
|
||||
'logs_api')
|
||||
className = reqClass + '_api'
|
||||
if not className in classFile:
|
||||
return mw.returnJson(False, 'external api request error')
|
||||
@@ -513,7 +514,7 @@ def index(reqClass=None, reqAction=None, reqData=None):
|
||||
if reqClass == None:
|
||||
reqClass = 'index'
|
||||
|
||||
pageFile = ('config', 'control', 'crontab', 'files', 'firewall',
|
||||
pageFile = ('config', 'control', 'crontab', 'files', 'logs', 'firewall',
|
||||
'index', 'plugins', 'login', 'system', 'site', 'cert', 'ssl', 'task', 'soft')
|
||||
|
||||
if reqClass == 'login':
|
||||
@@ -553,7 +554,7 @@ def index(reqClass=None, reqAction=None, reqData=None):
|
||||
return 'error request!'
|
||||
|
||||
# API请求
|
||||
classFile = ('config_api', 'crontab_api', 'files_api', 'firewall_api',
|
||||
classFile = ('config_api', 'crontab_api', 'files_api', 'logs_api', 'firewall_api',
|
||||
'plugins_api', 'system_api', 'site_api', 'task_api', 'vip_api')
|
||||
className = reqClass + '_api'
|
||||
if not className in classFile:
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user