Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9615fb2203 | ||
|
|
49c181c577 | ||
|
|
0fa5e4fb48 | ||
|
|
8e7130c382 | ||
|
|
33c1ac82c8 | ||
|
|
df5aec2e8f | ||
|
|
6c864177ee | ||
|
|
9ee09b0e7d | ||
|
|
b7da91f92b | ||
|
|
17e6703c07 | ||
|
|
a5f77a37f2 | ||
|
|
78fc9fd90f | ||
|
|
700f042033 | ||
|
|
e44768e608 | ||
|
|
2acef86207 | ||
|
|
6256bb02da | ||
|
|
04f5a27492 | ||
|
|
7cd476696a | ||
|
|
2ecaf0e2a3 | ||
|
|
c5d3494a94 | ||
|
|
af0658fd41 | ||
|
|
cccbd88145 | ||
|
|
48aad5b248 | ||
|
|
d843213c39 | ||
|
|
7ad33c5c59 | ||
|
|
ee56cfe5ab | ||
|
|
c6b38aa996 | ||
|
|
c5205c2d55 | ||
|
|
1be07f96ff | ||
|
|
9f4af88c1e | ||
|
|
ebc0559dff | ||
|
|
fe320ecd3b | ||
|
|
02c06e7ff1 | ||
|
|
6d90d6fde5 | ||
|
|
bfc0b9efa3 | ||
|
|
6e4e7bcf68 | ||
|
|
5da505084d | ||
|
|
f19df17ef5 | ||
|
|
d99e89744d | ||
|
|
9695fe4b9b | ||
|
|
5907dc36c5 | ||
|
|
d694af9358 | ||
|
|
4dc2828c59 | ||
|
|
37519b4c92 | ||
|
|
90999c7ae1 | ||
|
|
f16d9ea269 | ||
|
|
86098541e0 | ||
|
|
9ef04a4d9e | ||
|
|
752f8fae5a | ||
|
|
c5fdecf459 | ||
|
|
19284cd5ef | ||
|
|
da92ab1c89 | ||
|
|
18ca47e8b3 | ||
|
|
8b624297ba | ||
|
|
f0d9ff2ae9 | ||
|
|
21b2c17220 | ||
|
|
0df898a7d9 | ||
|
|
cf1f4c8538 | ||
|
|
89ecdcd29a | ||
|
|
0c8fa5e616 | ||
|
|
f9252da1b0 | ||
|
|
e31cbad7dd | ||
|
|
5bed9f0802 | ||
|
|
1ae4b54779 | ||
|
|
2b2a75adf0 | ||
|
|
55184341d7 | ||
|
|
6504decc30 | ||
|
|
843d798b91 | ||
|
|
087a6b4809 | ||
|
|
44438bd9aa | ||
|
|
c33cba0e85 | ||
|
|
cdc3c95367 | ||
|
|
222cebe1b3 | ||
|
|
2fc2eff97e | ||
|
|
79f8baeeb3 | ||
|
|
0399219df6 | ||
|
|
cd0d5ede16 | ||
|
|
1e6d1c6127 | ||
|
|
ff87dbe258 | ||
|
|
7d6ddb40db | ||
|
|
1cb57d3f65 | ||
|
|
9ed434d274 | ||
|
|
f532a376a7 | ||
|
|
4405f7720b | ||
|
|
fbde4aab88 | ||
|
|
864691d357 | ||
|
|
95bf0cb1e8 | ||
|
|
126f2d553d | ||
|
|
2fb88be080 | ||
|
|
fa307cdb49 | ||
|
|
0850b6ed44 | ||
|
|
ec1e99f9ca | ||
|
|
546dc4d7eb | ||
|
|
9b0b4ac305 | ||
|
|
23a1f3936d | ||
|
|
4cb22a1e35 | ||
|
|
3e3cdbe18c | ||
|
|
bdc46d9401 | ||
|
|
64986dd125 | ||
|
|
7ee00ab0b5 | ||
|
|
488d92ba19 | ||
|
|
9cebfb64cb | ||
|
|
7800429f8d | ||
|
|
7954714bb7 | ||
|
|
1d396b73f0 | ||
|
|
5f95a1d56a | ||
|
|
51951a2685 | ||
|
|
737453600d | ||
|
|
17ef460f4c | ||
|
|
38be955738 | ||
|
|
daf5c7c2b0 | ||
|
|
acdb35f395 | ||
|
|
5e8a15c230 | ||
|
|
34bcdd915c | ||
|
|
aa718adfea | ||
|
|
936592661b | ||
|
|
c740b4affb | ||
|
|
042b07efa2 | ||
|
|
6a6d22fd2d | ||
|
|
f99502d2c8 | ||
|
|
1cf41348b7 | ||
|
|
acdb226df9 | ||
|
|
6259f21196 | ||
|
|
6ad1292003 | ||
|
|
a682ba3e43 | ||
|
|
7509b259e7 | ||
|
|
8d170d87e4 | ||
|
|
bc4e5f6a87 | ||
|
|
954f66c8dc | ||
|
|
a7f860de2b | ||
|
|
6e7e291da3 | ||
|
|
2bca78c32d | ||
|
|
fb4311cdbf | ||
|
|
d889bf2cf3 | ||
|
|
511a7ac12b | ||
|
|
03e126cb48 | ||
|
|
2acbe56e21 | ||
|
|
8425aa4942 | ||
|
|
17ad9abe6b | ||
|
|
11166bbab1 | ||
|
|
f5f3f7ded5 | ||
|
|
26bae283be | ||
|
|
bfb12692a6 | ||
|
|
6bc6f17783 | ||
|
|
cd6f86ebfa | ||
|
|
5abb2613a1 | ||
|
|
a08dee242a | ||
|
|
2700b6b67b | ||
|
|
e41148d72d | ||
|
|
9b5c80bc72 | ||
|
|
958755d18d | ||
|
|
9af7e0f95b | ||
|
|
90e86cda0d | ||
|
|
ea2ed9d003 | ||
|
|
67eb3590c7 | ||
|
|
e66afbbb2d | ||
|
|
f959391b85 | ||
|
|
663e95288a | ||
|
|
0af3c7622d | ||
|
|
40e2186a5b | ||
|
|
121c972951 | ||
|
|
229cb977a1 | ||
|
|
ae845a702c | ||
|
|
35b0b1d153 | ||
|
|
4801850373 | ||
|
|
8b3d0cbba4 | ||
|
|
4f580d0427 | ||
|
|
2f794c5b73 | ||
|
|
21cd34d272 | ||
|
|
c58e1f7278 | ||
|
|
5b49f24a8d | ||
|
|
ce89a2a275 | ||
|
|
35f905e94c | ||
|
|
1c431286e4 | ||
|
|
705cef730b | ||
|
|
2a5da5593b | ||
|
|
22692d8ed4 | ||
|
|
5cdae707e9 | ||
|
|
5be9f1ae66 | ||
|
|
ba931a0c2a | ||
|
|
5b87572bff | ||
|
|
d51de312ac | ||
|
|
bcd2e7298b | ||
|
|
a985511b3b | ||
|
|
abb9fb72f0 | ||
|
|
b36ad3a595 | ||
|
|
a118f33f57 | ||
|
|
58b888edcd | ||
|
|
43d906139e | ||
|
|
b91bc040d4 | ||
|
|
c6eba5bbf1 | ||
|
|
1adbf733d8 | ||
|
|
913d483e63 | ||
|
|
9951f7151e | ||
|
|
167a386a0d | ||
|
|
5473ee74cb | ||
|
|
dbeefc06c8 | ||
|
|
444730e553 | ||
|
|
8a2e17198e | ||
|
|
bc41788d49 | ||
|
|
ebd8e93b16 | ||
|
|
a45994c3c7 | ||
|
|
f41f616daf | ||
|
|
da5b9351e2 | ||
|
|
3c080e0264 | ||
|
|
dc62aabfd4 | ||
|
|
c6da2e56ee | ||
|
|
461f3dcb0a | ||
|
|
ee5b9f35ad | ||
|
|
3ad8496daf | ||
|
|
77023263a6 | ||
|
|
6497627931 | ||
|
|
2ae3426c82 | ||
|
|
dbeb919f05 | ||
|
|
2106746f6c | ||
|
|
31d5b90670 | ||
|
|
ceaf9c42db | ||
|
|
9067778bf3 | ||
|
|
99053b67ce | ||
|
|
07b8d91f31 | ||
|
|
e9d4e09049 | ||
|
|
629416760f | ||
|
|
d1ade4355e | ||
|
|
4508e30ea7 | ||
|
|
b1c5c90bef | ||
|
|
e9a7db2c1d | ||
|
|
63e5f26491 | ||
|
|
ed93ccc0ee | ||
|
|
929a50c137 | ||
|
|
fe87092750 | ||
|
|
c144cead18 | ||
|
|
afdc9720fc | ||
|
|
194c7b9d45 | ||
|
|
162557230a | ||
|
|
f4dfe502cb | ||
|
|
7a3d49a9cf | ||
|
|
49f1407c42 | ||
|
|
319f72865d | ||
|
|
0eaa6f38e0 | ||
|
|
eeef8d488c | ||
|
|
4e69f9540a | ||
|
|
a0e8d75af7 | ||
|
|
f54f7d4ce3 | ||
|
|
5f4893c115 | ||
|
|
a48b869fe9 | ||
|
|
266a8cf806 | ||
|
|
13e4dcf8ad | ||
|
|
1ca469518d | ||
|
|
4284a3daf4 | ||
|
|
84995650ee | ||
|
|
fa662d75d6 | ||
|
|
842c0daf70 | ||
|
|
798608287e | ||
|
|
437225374e | ||
|
|
3a442570db | ||
|
|
366c3677c2 | ||
|
|
6dcf1db856 | ||
|
|
b3ca295e51 | ||
|
|
03f06ee384 | ||
|
|
2dc96cd04e | ||
|
|
a875293116 | ||
|
|
8735fb9238 | ||
|
|
58fcf0e8f9 | ||
|
|
fccc30ebb1 | ||
|
|
6b9da57ff2 | ||
|
|
cd6b2ad65e | ||
|
|
60b2834adf | ||
|
|
c74e0428fd | ||
|
|
20d486629e | ||
|
|
f984e4ecc7 | ||
|
|
0bdea14560 | ||
|
|
0c3599facb | ||
|
|
05eb434bf8 | ||
|
|
12dccc1df0 | ||
|
|
11e7316911 |
@@ -14,7 +14,6 @@ dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
@@ -108,5 +107,11 @@ venv.bak/
|
||||
.idea/*.iml
|
||||
tmp/*.pl
|
||||
tmp/*.log
|
||||
data/json/index.json
|
||||
data/system.db
|
||||
*.swp
|
||||
*.zip
|
||||
scripts/init.d/mw
|
||||
logs/*
|
||||
data/*.db
|
||||
data/control.conf
|
||||
data/iplist.txt
|
||||
data/json/index.json
|
||||
|
||||
@@ -3,50 +3,11 @@
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
|
||||
from datetime import timedelta
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import config
|
||||
|
||||
sys.path.append("/class/core/")
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf8')
|
||||
|
||||
import route
|
||||
from flask import Flask
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
app.debug = True
|
||||
|
||||
|
||||
DEFAULT_MODULES = (
|
||||
(route.dashboard, "/"),
|
||||
(route.site, "/site"),
|
||||
(route.files, "/files"),
|
||||
(route.soft, "/soft"),
|
||||
(route.config, "/config"),
|
||||
(route.plugins, "/plugins"),
|
||||
(route.task, "/task"),
|
||||
(route.system, "/system"),
|
||||
(route.database, "/database"),
|
||||
(route.crontab, "/crontab"),
|
||||
(route.firewall, "/firewall"),
|
||||
(route.control, "/control"),
|
||||
)
|
||||
|
||||
|
||||
# print "time.time(): %f " % time.time()
|
||||
app.config.version = "0.0.1" + str(time.time())
|
||||
|
||||
app.config['SECRET_KEY'] = os.urandom(24)
|
||||
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=7)
|
||||
|
||||
|
||||
def setting_modules(app, modules):
|
||||
for module, url_prefix in modules:
|
||||
app.register_blueprint(module, url_prefix=url_prefix)
|
||||
|
||||
setting_modules(app, DEFAULT_MODULES)
|
||||
app = config.config().makeApp(__name__)
|
||||
|
||||
try:
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import shutil
|
||||
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf8')
|
||||
|
||||
from flask import Flask, session
|
||||
from datetime import timedelta
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import db
|
||||
import public
|
||||
|
||||
|
||||
class middleWare:
|
||||
|
||||
def __init__(self, wsgi_app):
|
||||
self.wsgi_app = wsgi_app
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self.wsgi_app(*args, **kwargs)
|
||||
|
||||
|
||||
class config:
|
||||
__version = '0.0.1'
|
||||
__app = None
|
||||
__modules = None
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def makeApp(self, name):
|
||||
app = Flask(name)
|
||||
self.__app = app
|
||||
|
||||
app.config.version = self.__version
|
||||
app.config['SECRET_KEY'] = os.urandom(24)
|
||||
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=7)
|
||||
|
||||
self.initDB()
|
||||
self.initInitD()
|
||||
self.initRoute()
|
||||
# self.startDebug()
|
||||
app.wsgi_app = middleWare(app.wsgi_app)
|
||||
return app
|
||||
|
||||
def startDebug(self):
|
||||
self.__app.debug = True
|
||||
self.__app.config.version = self.__version + str(time.time())
|
||||
|
||||
def initDB(self):
|
||||
try:
|
||||
sql = db.Sql().dbfile('default')
|
||||
csql = public.readFile('data/sql/default.sql')
|
||||
csql_list = csql.split(';')
|
||||
for index in range(len(csql_list)):
|
||||
sql.execute(csql_list[index], ())
|
||||
except Exception, ex:
|
||||
print str(ex)
|
||||
|
||||
def initUser(self):
|
||||
pass
|
||||
|
||||
def initInitD(self):
|
||||
script = public.getRunDir() + '/scripts/init.d/mw.tpl'
|
||||
script_bin = public.getRunDir() + '/scripts/init.d/mw'
|
||||
if os.path.exists(script_bin):
|
||||
return
|
||||
|
||||
content = public.readFile(script)
|
||||
content = content.replace("{$SERVER_PATH}", public.getRunDir())
|
||||
|
||||
public.writeFile(script_bin, content)
|
||||
public.execShell('chmod +x ' + script_bin)
|
||||
|
||||
if public.getOs() != 'darwin':
|
||||
initd_bin = '/etc/init.d/mw'
|
||||
if not os.path.exists(initd_bin):
|
||||
shutil.copyfile(script_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
|
||||
def getVersion(self):
|
||||
return self.__version
|
||||
|
||||
def getApp(self):
|
||||
return self.__app
|
||||
|
||||
def initRoute(self):
|
||||
import route
|
||||
DEFAULT_MODULES = (
|
||||
(route.dashboard, "/"),
|
||||
(route.site, "/site"),
|
||||
(route.files, "/files"),
|
||||
(route.soft, "/soft"),
|
||||
(route.config, "/config"),
|
||||
(route.plugins, "/plugins"),
|
||||
(route.task, "/task"),
|
||||
(route.system, "/system"),
|
||||
(route.database, "/database"),
|
||||
(route.crontab, "/crontab"),
|
||||
(route.firewall, "/firewall"),
|
||||
(route.control, "/control")
|
||||
)
|
||||
self.modules = DEFAULT_MODULES
|
||||
self.settingModules(self.__app, DEFAULT_MODULES)
|
||||
|
||||
def settingModules(self, app, modules):
|
||||
for module, url_prefix in modules:
|
||||
app.register_blueprint(module, url_prefix=url_prefix)
|
||||
@@ -0,0 +1,250 @@
|
||||
# coding: utf-8
|
||||
|
||||
import psutil
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
import public
|
||||
import re
|
||||
import json
|
||||
import pwd
|
||||
|
||||
|
||||
class file_api:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def setFileAccept(self, filename):
|
||||
auth = 'www:www'
|
||||
if public.getOs() == 'darwin':
|
||||
user = public.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
auth = user + ':staff'
|
||||
os.system('chown -R ' + auth + ' ' + filename)
|
||||
os.system('chmod -R 755 ' + filename)
|
||||
|
||||
# 移动到回收站
|
||||
def mvRecycleBin(self, path):
|
||||
rPath = public.getRootDir() + '/recycle_bin/'
|
||||
if not os.path.exists(rPath):
|
||||
os.system('mkdir -p ' + rPath)
|
||||
|
||||
rFile = rPath + path.replace('/', '_mw_') + '_t_' + str(time.time())
|
||||
try:
|
||||
import shutil
|
||||
shutil.move(path, rFile)
|
||||
public.writeLog('TYPE_FILE', public.getInfo(
|
||||
'移动文件[{1}]到回收站成功!', (path)))
|
||||
return True
|
||||
except:
|
||||
public.writeLog('TYPE_FILE', public.getInfo(
|
||||
'移动文件[{1}]到回收站失败!', (path)))
|
||||
return False
|
||||
|
||||
def getBody(self, path):
|
||||
if not os.path.exists(path):
|
||||
return public.returnJson(False, '文件不存在', (path,))
|
||||
|
||||
if os.path.getsize(path) > 2097152:
|
||||
return public.returnJson(False, u'不能在线编辑大于2MB的文件!')
|
||||
|
||||
fp = open(path, 'rb')
|
||||
data = {}
|
||||
data['status'] = True
|
||||
try:
|
||||
if fp:
|
||||
from chardet.universaldetector import UniversalDetector
|
||||
detector = UniversalDetector()
|
||||
srcBody = b""
|
||||
for line in fp.readlines():
|
||||
detector.feed(line)
|
||||
srcBody += line
|
||||
detector.close()
|
||||
char = detector.result
|
||||
data['encoding'] = char['encoding']
|
||||
if char['encoding'] == 'GB2312' or not char['encoding'] or char[
|
||||
'encoding'] == 'TIS-620' or char['encoding'] == 'ISO-8859-9':
|
||||
data['encoding'] = 'GBK'
|
||||
if char['encoding'] == 'ascii' or char[
|
||||
'encoding'] == 'ISO-8859-1':
|
||||
data['encoding'] = 'utf-8'
|
||||
if char['encoding'] == 'Big5':
|
||||
data['encoding'] = 'BIG5'
|
||||
if not char['encoding'] in ['GBK', 'utf-8',
|
||||
'BIG5']:
|
||||
data['encoding'] = 'utf-8'
|
||||
try:
|
||||
if sys.version_info[0] == 2:
|
||||
data['data'] = srcBody.decode(
|
||||
data['encoding']).encode('utf-8', errors='ignore')
|
||||
else:
|
||||
data['data'] = srcBody.decode(data['encoding'])
|
||||
except:
|
||||
data['encoding'] = char['encoding']
|
||||
if sys.version_info[0] == 2:
|
||||
data['data'] = srcBody.decode(
|
||||
data['encoding']).encode('utf-8', errors='ignore')
|
||||
else:
|
||||
data['data'] = srcBody.decode(data['encoding'])
|
||||
else:
|
||||
if sys.version_info[0] == 2:
|
||||
data['data'] = srcBody.decode('utf-8').encode('utf-8')
|
||||
else:
|
||||
data['data'] = srcBody.decode('utf-8')
|
||||
data['encoding'] = u'utf-8'
|
||||
|
||||
return public.returnJson(True, 'OK', data)
|
||||
except Exception as ex:
|
||||
return public.returnJson(False, u'文件编码不被兼容,无法正确读取文件!' + str(ex))
|
||||
|
||||
def saveBody(self, path, data, encoding='utf-8'):
|
||||
if not os.path.exists(path):
|
||||
return public.returnJson(False, '文件不存在')
|
||||
try:
|
||||
if encoding == 'ascii':
|
||||
encoding = 'utf-8'
|
||||
if sys.version_info[0] == 2:
|
||||
data = data.encode(encoding, errors='ignore')
|
||||
fp = open(path, 'w+')
|
||||
else:
|
||||
data = data.encode(
|
||||
encoding, errors='ignore').decode(encoding)
|
||||
fp = open(path, 'w+', encoding=encoding)
|
||||
fp.write(data)
|
||||
fp.close()
|
||||
|
||||
public.writeLog('TYPE_FILE', '文件保存成功', (path,))
|
||||
return public.returnJson(True, '文件保存成功')
|
||||
except Exception as ex:
|
||||
return public.returnJson(False, 'FILE_SAVE_ERR:' + str(ex))
|
||||
|
||||
def zip(self, sfile, dfile, stype, path):
|
||||
if sfile.find(',') == -1:
|
||||
if not os.path.exists(path + '/' + sfile):
|
||||
return public.returnMsg(False, '指定文件不存在!')
|
||||
|
||||
try:
|
||||
tmps = public.getRunDir() + '/tmp/panelExec.log'
|
||||
if stype == 'zip':
|
||||
os.system("cd '" + path + "' && zip '" + dfile +
|
||||
"' -r '" + sfile + "' > " + tmps + " 2>&1")
|
||||
else:
|
||||
sfiles = ''
|
||||
for sfile in sfile.split(','):
|
||||
if not sfile:
|
||||
continue
|
||||
sfiles += " '" + sfile + "'"
|
||||
os.system("cd '" + path + "' && tar -zcvf '" +
|
||||
dfile + "' " + sfiles + " > " + tmps + " 2>&1")
|
||||
self.setFileAccept(dfile)
|
||||
public.writeLog("TYPE_FILE", '文件压缩成功!', (sfile, dfile))
|
||||
return public.returnJson(True, '文件压缩成功!')
|
||||
except:
|
||||
return public.returnJson(False, '文件压缩失败!')
|
||||
|
||||
def delete(self, path):
|
||||
|
||||
if not os.path.exists(path):
|
||||
return public.returnJson(False, '指定文件不存在!')
|
||||
|
||||
# 检查是否为.user.ini
|
||||
if path.find('.user.ini') >= 0:
|
||||
os.system("chattr -i '" + path + "'")
|
||||
|
||||
try:
|
||||
if os.path.exists('data/recycle_bin.pl'):
|
||||
if self.mvRecycleBin(path):
|
||||
return public.returnJson(True, '已将文件移动到回收站!')
|
||||
os.remove(path)
|
||||
public.writeLog('TYPE_FILE', public.getInfo(
|
||||
'删除文件[{1}]成功!', (path)))
|
||||
return public.returnJson(True, '删除文件成功!')
|
||||
except:
|
||||
return public.returnJson(False, '删除文件失败!')
|
||||
|
||||
def getAccess(self, filename):
|
||||
data = {}
|
||||
try:
|
||||
stat = os.stat(filename)
|
||||
data['chmod'] = str(oct(stat.st_mode)[-3:])
|
||||
data['chown'] = pwd.getpwuid(stat.st_uid).pw_name
|
||||
except:
|
||||
data['chmod'] = 755
|
||||
data['chown'] = 'www'
|
||||
return data
|
||||
|
||||
# 计算文件数量
|
||||
def getCount(self, path, search):
|
||||
i = 0
|
||||
for name in os.listdir(path):
|
||||
if search:
|
||||
if name.lower().find(search) == -1:
|
||||
continue
|
||||
# if name[0:1] == '.':
|
||||
# continue
|
||||
i += 1
|
||||
return i
|
||||
|
||||
def getDir(self, path, page=1, page_size=10, search=None):
|
||||
data = {}
|
||||
dirnames = []
|
||||
filenames = []
|
||||
|
||||
info = {}
|
||||
info['count'] = self.getCount(path, search)
|
||||
info['row'] = page_size
|
||||
info['p'] = page
|
||||
info['tojs'] = 'getFiles'
|
||||
pageObj = public.getPageObject(info, '1,2,3,4,5,6,7,8')
|
||||
data['PAGE'] = pageObj[0]
|
||||
|
||||
i = 0
|
||||
n = 0
|
||||
for filename in os.listdir(path):
|
||||
if search:
|
||||
if filename.lower().find(search) == -1:
|
||||
continue
|
||||
i += 1
|
||||
if n >= pageObj[1].ROW:
|
||||
break
|
||||
if i < pageObj[1].SHIFT:
|
||||
continue
|
||||
|
||||
try:
|
||||
filePath = (path + '/' + filename).encode('utf8')
|
||||
link = ''
|
||||
if os.path.islink(filePath):
|
||||
filePath = os.readlink(filePath)
|
||||
link = ' -> ' + filePath
|
||||
if not os.path.exists(filePath):
|
||||
filePath = path + '/' + filePath
|
||||
if not os.path.exists(filePath):
|
||||
continue
|
||||
|
||||
stat = os.stat(filePath)
|
||||
accept = str(oct(stat.st_mode)[-3:])
|
||||
mtime = str(int(stat.st_mtime))
|
||||
user = ''
|
||||
try:
|
||||
user = pwd.getpwuid(stat.st_uid).pw_name
|
||||
except:
|
||||
user = str(stat.st_uid)
|
||||
size = str(stat.st_size)
|
||||
if os.path.isdir(filePath):
|
||||
dirnames.append(filename + ';' + size + ';' +
|
||||
mtime + ';' + accept + ';' + user + ';' + link)
|
||||
else:
|
||||
filenames.append(filename + ';' + size + ';' +
|
||||
mtime + ';' + accept + ';' + user + ';' + link)
|
||||
n += 1
|
||||
except:
|
||||
continue
|
||||
|
||||
data['DIR'] = sorted(dirnames)
|
||||
data['FILES'] = sorted(filenames)
|
||||
if path[0:2] == '//':
|
||||
data['PATH'] = path[1:]
|
||||
else:
|
||||
data['PATH'] = path
|
||||
return public.getJson(data)
|
||||
@@ -0,0 +1,56 @@
|
||||
# coding: utf-8
|
||||
|
||||
import psutil
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
import public
|
||||
import re
|
||||
import json
|
||||
import pwd
|
||||
|
||||
|
||||
class firewall_api:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def getList(self, page, limit):
|
||||
|
||||
start = (page - 1) * limit
|
||||
|
||||
_list = public.M('firewall').field('id,port,ps,addtime').limit(
|
||||
str(start) + ',' + str(limit)).order('id desc').select()
|
||||
data = {}
|
||||
data['data'] = _list
|
||||
|
||||
count = public.M('firewall').count()
|
||||
_page = {}
|
||||
_page['count'] = count
|
||||
_page['tojs'] = 'showAccept'
|
||||
_page['p'] = page
|
||||
|
||||
data['page'] = public.getPage(_page)
|
||||
return public.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 = public.M('logs').where(find_search, ()).field(
|
||||
'id,type,log,addtime').limit(str(start) + ',' + str(limit)).order('id desc').select()
|
||||
data = {}
|
||||
data['data'] = _list
|
||||
|
||||
count = public.M('logs').where(find_search, ()).count()
|
||||
_page = {}
|
||||
_page['count'] = count
|
||||
_page['tojs'] = 'getLogs'
|
||||
_page['p'] = page
|
||||
|
||||
data['page'] = public.getPage(_page)
|
||||
return public.getJson(data)
|
||||
@@ -7,6 +7,25 @@ import public
|
||||
import re
|
||||
import json
|
||||
|
||||
import threading
|
||||
import multiprocessing
|
||||
|
||||
|
||||
class pa_thread(threading.Thread):
|
||||
|
||||
def __init__(self, func, args, name=''):
|
||||
threading.Thread.__init__(self)
|
||||
self.name = name
|
||||
self.func = func
|
||||
self.args = args
|
||||
self.result = self.func(*self.args)
|
||||
|
||||
def getResult(self):
|
||||
try:
|
||||
return self.result
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
class plugin_api:
|
||||
__tasks = None
|
||||
@@ -67,7 +86,46 @@ class plugin_api:
|
||||
return isTask
|
||||
|
||||
def checkStatus(self, info):
|
||||
pass
|
||||
|
||||
if not info['setup']:
|
||||
return False
|
||||
|
||||
data = self.run(info['name'], 'status', info['setup_version'])
|
||||
if data[0] == 'start':
|
||||
return True
|
||||
return False
|
||||
|
||||
def checkStatusProcess(self, info, i, return_dict):
|
||||
|
||||
if not info['setup']:
|
||||
return_dict[i] = False
|
||||
return
|
||||
|
||||
data = self.run(info['name'], 'status', info['setup_version'])
|
||||
if data[0] == 'start':
|
||||
return_dict[i] = True
|
||||
else:
|
||||
return_dict[i] = False
|
||||
|
||||
def checkStatusMProcess(self, plugins_info):
|
||||
manager = multiprocessing.Manager()
|
||||
return_dict = manager.dict()
|
||||
jobs = []
|
||||
ntmp_list = range(len(plugins_info))
|
||||
for i in ntmp_list:
|
||||
p = multiprocessing.Process(
|
||||
target=self.checkStatusProcess, args=(plugins_info[i], i, return_dict))
|
||||
jobs.append(p)
|
||||
p.start()
|
||||
|
||||
for proc in jobs:
|
||||
proc.join()
|
||||
|
||||
returnData = return_dict.values()
|
||||
for i in ntmp_list:
|
||||
plugins_info[i]['status'] = returnData[i]
|
||||
|
||||
return plugins_info
|
||||
|
||||
def checkDisplayIndex(self, name, version):
|
||||
if not os.path.exists(self.__index):
|
||||
@@ -151,8 +209,8 @@ class plugin_api:
|
||||
pluginInfo['setup_version'] = info['versions']
|
||||
else:
|
||||
pluginInfo['setup_version'] = self.getVersion(
|
||||
pluginInfo['path'])
|
||||
# pluginInfo['status'] = os.path.exists(pluginInfo['install_checks'])
|
||||
pluginInfo['install_checks'])
|
||||
# pluginInfo['status'] = self.checkStatus(pluginInfo)
|
||||
return pluginInfo
|
||||
|
||||
def makeCoexist(self, data):
|
||||
@@ -193,10 +251,7 @@ class plugin_api:
|
||||
return plugins_info
|
||||
|
||||
def getAllList(self, sType='0'):
|
||||
ret = {}
|
||||
ret['type'] = json.loads(public.readFile(self.__type))
|
||||
plugins_info = []
|
||||
|
||||
for dirinfo in os.listdir(self.__plugin_dir):
|
||||
if dirinfo[0:1] == '.':
|
||||
continue
|
||||
@@ -213,16 +268,166 @@ class plugin_api:
|
||||
print e
|
||||
return plugins_info
|
||||
|
||||
def getPluginList(self, sType, sPage=1, sPageSize=15):
|
||||
def getAllListPage(self, sType='0', page=1, pageSize=10):
|
||||
plugins_info = []
|
||||
for dirinfo in os.listdir(self.__plugin_dir):
|
||||
if dirinfo[0:1] == '.':
|
||||
continue
|
||||
path = self.__plugin_dir + '/' + dirinfo
|
||||
if os.path.isdir(path):
|
||||
json_file = path + '/info.json'
|
||||
if os.path.exists(json_file):
|
||||
try:
|
||||
data = json.loads(public.readFile(json_file))
|
||||
tmp_data = self.makeList(data, sType)
|
||||
for index in range(len(tmp_data)):
|
||||
plugins_info.append(tmp_data[index])
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
start = (page - 1) * pageSize
|
||||
end = start + pageSize
|
||||
_plugins_info = plugins_info[start:end]
|
||||
|
||||
_plugins_info = self.checkStatusMProcess(_plugins_info)
|
||||
return (_plugins_info, len(plugins_info))
|
||||
|
||||
def makeListThread(self, data, sType='0'):
|
||||
plugins_info = []
|
||||
|
||||
if (data['pid'] == sType):
|
||||
if type(data['versions']) == list and data.has_key('coexist') and data['coexist']:
|
||||
tmp_data = self.makeCoexist(data)
|
||||
for index in range(len(tmp_data)):
|
||||
plugins_info.append(tmp_data[index])
|
||||
else:
|
||||
pg = self.getPluginInfo(data)
|
||||
plugins_info.append(pg)
|
||||
return plugins_info
|
||||
|
||||
if sType == '0':
|
||||
if type(data['versions']) == list and data.has_key('coexist') and data['coexist']:
|
||||
tmp_data = self.makeCoexist(data)
|
||||
for index in range(len(tmp_data)):
|
||||
plugins_info.append(tmp_data[index])
|
||||
else:
|
||||
pg = self.getPluginInfo(data)
|
||||
plugins_info.append(pg)
|
||||
|
||||
# print plugins_info, data
|
||||
return plugins_info
|
||||
|
||||
def getAllListThread(self, sType='0'):
|
||||
plugins_info = []
|
||||
tmp_list = []
|
||||
threads = []
|
||||
for dirinfo in os.listdir(self.__plugin_dir):
|
||||
if dirinfo[0:1] == '.':
|
||||
continue
|
||||
path = self.__plugin_dir + '/' + dirinfo
|
||||
if os.path.isdir(path):
|
||||
json_file = path + '/info.json'
|
||||
if os.path.exists(json_file):
|
||||
data = json.loads(public.readFile(json_file))
|
||||
if sType == '0':
|
||||
tmp_list.append(data)
|
||||
|
||||
if (data['pid'] == sType):
|
||||
tmp_list.append(data)
|
||||
|
||||
ntmp_list = range(len(tmp_list))
|
||||
for i in ntmp_list:
|
||||
t = pa_thread(self.makeListThread, (tmp_list[i], sType))
|
||||
threads.append(t)
|
||||
for i in ntmp_list:
|
||||
threads[i].start()
|
||||
for i in ntmp_list:
|
||||
threads[i].join()
|
||||
|
||||
for i in ntmp_list:
|
||||
t = threads[i].getResult()
|
||||
for index in range(len(t)):
|
||||
plugins_info.append(t[index])
|
||||
|
||||
return plugins_info
|
||||
|
||||
def makeListProcess(self, data, sType, i, return_dict):
|
||||
plugins_info = []
|
||||
|
||||
if (data['pid'] == sType):
|
||||
if type(data['versions']) == list and data.has_key('coexist') and data['coexist']:
|
||||
tmp_data = self.makeCoexist(data)
|
||||
for index in range(len(tmp_data)):
|
||||
plugins_info.append(tmp_data[index])
|
||||
else:
|
||||
pg = self.getPluginInfo(data)
|
||||
plugins_info.append(pg)
|
||||
# return plugins_info
|
||||
|
||||
if sType == '0':
|
||||
if type(data['versions']) == list and data.has_key('coexist') and data['coexist']:
|
||||
tmp_data = self.makeCoexist(data)
|
||||
for index in range(len(tmp_data)):
|
||||
plugins_info.append(tmp_data[index])
|
||||
else:
|
||||
pg = self.getPluginInfo(data)
|
||||
plugins_info.append(pg)
|
||||
|
||||
return_dict[i] = plugins_info
|
||||
# return plugins_info
|
||||
|
||||
def getAllListProcess(self, sType='0'):
|
||||
plugins_info = []
|
||||
tmp_list = []
|
||||
manager = multiprocessing.Manager()
|
||||
return_dict = manager.dict()
|
||||
jobs = []
|
||||
for dirinfo in os.listdir(self.__plugin_dir):
|
||||
if dirinfo[0:1] == '.':
|
||||
continue
|
||||
path = self.__plugin_dir + '/' + dirinfo
|
||||
if os.path.isdir(path):
|
||||
json_file = path + '/info.json'
|
||||
if os.path.exists(json_file):
|
||||
data = json.loads(public.readFile(json_file))
|
||||
if sType == '0':
|
||||
tmp_list.append(data)
|
||||
|
||||
if (data['pid'] == sType):
|
||||
tmp_list.append(data)
|
||||
|
||||
ntmp_list = range(len(tmp_list))
|
||||
for i in ntmp_list:
|
||||
p = multiprocessing.Process(
|
||||
target=self.makeListProcess, args=(tmp_list[i], sType, i, return_dict))
|
||||
jobs.append(p)
|
||||
p.start()
|
||||
|
||||
for proc in jobs:
|
||||
proc.join()
|
||||
|
||||
returnData = return_dict.values()
|
||||
for i in ntmp_list:
|
||||
for index in range(len(returnData[i])):
|
||||
plugins_info.append(returnData[i][index])
|
||||
|
||||
return plugins_info
|
||||
|
||||
def getPluginList(self, sType, sPage=1, sPageSize=10):
|
||||
|
||||
ret = {}
|
||||
ret['type'] = json.loads(public.readFile(self.__type))
|
||||
plugins_info = self.getAllList(sType)
|
||||
args = {}
|
||||
args['count'] = len(plugins_info)
|
||||
args['p1'] = sPage
|
||||
# plugins_info = self.getAllListThread(sType)
|
||||
# plugins_info = self.getAllListProcess(sType)
|
||||
data = self.getAllListPage(sType, sPage, sPageSize)
|
||||
ret['data'] = data[0]
|
||||
|
||||
args = {}
|
||||
args['count'] = data[1]
|
||||
args['p'] = sPage
|
||||
args['tojs'] = 'getSList'
|
||||
args['row'] = sPageSize
|
||||
|
||||
ret['data'] = plugins_info
|
||||
ret['list'] = public.getPage(args)
|
||||
return ret
|
||||
|
||||
@@ -252,6 +457,8 @@ class plugin_api:
|
||||
continue
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
plist = self.checkStatusMProcess(plist)
|
||||
return plist
|
||||
|
||||
def setIndexSort(self, sort):
|
||||
@@ -287,5 +494,19 @@ class plugin_api:
|
||||
public.writeFile(self.__index, json.dumps(indexList))
|
||||
return public.returnJson(True, '删除成功!')
|
||||
|
||||
def run(self):
|
||||
pass
|
||||
def run(self, name, func, version, args='', script='index'):
|
||||
path = public.getRunDir() + '/' + self.__plugin_dir + \
|
||||
'/' + name + '/' + script + '.py'
|
||||
py = 'python ' + path
|
||||
if args == '':
|
||||
py_cmd = py + ' ' + func + ' ' + version
|
||||
else:
|
||||
py_cmd = py + ' ' + func + ' ' + version + ' ' + args
|
||||
|
||||
if not os.path.exists(path):
|
||||
return ('', '')
|
||||
data = public.execShell(py_cmd)
|
||||
|
||||
print py_cmd
|
||||
# print os.path.exists(py_cmd)
|
||||
return (data[0].strip(), data[1].strip())
|
||||
|
||||
@@ -46,17 +46,57 @@ def getRootDir():
|
||||
return os.path.dirname(os.path.dirname(getRunDir()))
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return getRunDir() + '/plugins'
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return getRootDir() + '/server'
|
||||
|
||||
|
||||
def getWwwDir():
|
||||
return getRootDir() + '/wwwroot'
|
||||
|
||||
|
||||
def getLogsDir():
|
||||
return getRootDir() + '/wwwlogs'
|
||||
|
||||
|
||||
def getOs():
|
||||
os = execShell('uname')
|
||||
return os[0].lower().strip()
|
||||
|
||||
|
||||
def isAppleSystem():
|
||||
if getOs() == 'darwin':
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def isInstalledWeb():
|
||||
path = getServerDir() + '/openresty/nginx/sbin/nginx'
|
||||
if os.path.exists(path):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def restartWeb():
|
||||
if isInstalledWeb():
|
||||
initd = getServerDir() + '/openresty/init.d/openresty'
|
||||
execShell(initd + ' ' + 'reload')
|
||||
|
||||
|
||||
def M(table):
|
||||
sql = db.Sql()
|
||||
return sql.table(table)
|
||||
|
||||
|
||||
def getPage(args, result='1,2,3,4,5,8'):
|
||||
data = getPageObject(args, result)
|
||||
return data[0]
|
||||
|
||||
|
||||
def getPageObject(args, result='1,2,3,4,5,8'):
|
||||
# 取分页
|
||||
import page
|
||||
# 实例化分页类
|
||||
@@ -69,7 +109,7 @@ def getPage(args, result='1,2,3,4,5,8'):
|
||||
|
||||
info['row'] = 10
|
||||
if args.has_key('row'):
|
||||
info['row'] = args['row']
|
||||
info['row'] = int(args['row'])
|
||||
|
||||
info['p'] = 1
|
||||
if args.has_key('p'):
|
||||
@@ -79,7 +119,7 @@ def getPage(args, result='1,2,3,4,5,8'):
|
||||
if args.has_key('tojs'):
|
||||
info['return_js'] = args['tojs']
|
||||
|
||||
return page.GetPage(info, result)
|
||||
return (page.GetPage(info, result), page)
|
||||
|
||||
|
||||
def md5(str):
|
||||
@@ -131,8 +171,8 @@ def returnJson(status, msg, args=()):
|
||||
|
||||
def returnMsg(status, msg, args=()):
|
||||
# 取通用字曲返回
|
||||
logMessage = json.loads(
|
||||
readFile('static/language/' + getLanguage() + '/public.json'))
|
||||
pjson = 'static/language/' + getLanguage() + '/public.json'
|
||||
logMessage = json.loads(readFile(pjson))
|
||||
keys = logMessage.keys()
|
||||
|
||||
if msg in keys:
|
||||
@@ -327,27 +367,6 @@ def getLastLine(inputfile, lineNum):
|
||||
return getMsg('TASK_SLEEP')
|
||||
|
||||
|
||||
def serviceReload():
|
||||
# 重载Web服务配置
|
||||
if os.path.exists('/www/server/nginx/sbin/nginx'):
|
||||
result = execShell('/etc/init.d/nginx reload')
|
||||
if result[1].find('nginx.pid') != -1:
|
||||
execShell('pkill -9 nginx && sleep 1')
|
||||
execShell('/etc/init.d/nginx start')
|
||||
else:
|
||||
result = execShell('/etc/init.d/httpd reload')
|
||||
return result
|
||||
|
||||
|
||||
def phpReload(version):
|
||||
# 重载PHP配置
|
||||
import os
|
||||
if os.path.exists('/www/server/php/' + version + '/libphp5.so'):
|
||||
execShell('/etc/init.d/httpd reload')
|
||||
else:
|
||||
execShell('/etc/init.d/php-fpm-' + version + ' reload')
|
||||
|
||||
|
||||
def downloadFile(url, filename):
|
||||
import urllib
|
||||
urllib.urlretrieve(url, filename=filename, reporthook=downloadHook)
|
||||
@@ -359,7 +378,7 @@ def downloadHook(count, blockSize, totalSize):
|
||||
print '%02d%%' % (100.0 * count * blockSize / totalSize)
|
||||
|
||||
|
||||
def GetLocalIp():
|
||||
def getLocalIp():
|
||||
# 取本地外网IP
|
||||
try:
|
||||
import re
|
||||
@@ -376,13 +395,7 @@ def GetLocalIp():
|
||||
ipaddress = re.search('\d+.\d+.\d+.\d+', ipaddress).group(0)
|
||||
return ipaddress
|
||||
except:
|
||||
pass
|
||||
# try:
|
||||
# url = web.ctx.session.home + '/Api/getIpAddress'
|
||||
# opener = urllib2.urlopen(url)
|
||||
# return opener.read()
|
||||
# except:
|
||||
# return web.ctx.host.split(':')[0]
|
||||
return '127.0.0.1'
|
||||
|
||||
|
||||
def inArray(arrays, searchStr):
|
||||
@@ -394,23 +407,6 @@ def inArray(arrays, searchStr):
|
||||
return False
|
||||
|
||||
|
||||
def checkWebConfig():
|
||||
# 检查Web服务器配置文件是否有错误
|
||||
if get_webserver() == 'nginx':
|
||||
result = ExecShell(
|
||||
"ulimit -n 10240 && /www/server/nginx/sbin/nginx -t -c /www/server/nginx/conf/nginx.conf")
|
||||
searchStr = 'successful'
|
||||
else:
|
||||
result = ExecShell(
|
||||
"ulimit -n 10240 && /www/server/apache/bin/apachectl -t")
|
||||
searchStr = 'Syntax OK'
|
||||
|
||||
if result[1].find(searchStr) == -1:
|
||||
WriteLog("TYPE_SOFT", 'CONF_CHECK_ERR', (result[1],))
|
||||
return result[1]
|
||||
return True
|
||||
|
||||
|
||||
def checkIp(ip):
|
||||
# 检查是否为IPv4地址
|
||||
import re
|
||||
@@ -463,33 +459,28 @@ def isRestart():
|
||||
return True
|
||||
|
||||
|
||||
def isUpdateLocalSoft():
|
||||
num = M('tasks').where('status!=?', ('1',)).count()
|
||||
if os.path.exists('mdserver-web.zip'):
|
||||
return True
|
||||
|
||||
if num > 0:
|
||||
data = M('tasks').where('status!=?', ('1',)).field(
|
||||
'id,type,execstr').limit('1').select()
|
||||
argv = data[0]['execstr'].split('|dl|')
|
||||
if data[0]['type'] == 'download' and argv[1] == 'mdserver-web.zip':
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def hasPwd(password):
|
||||
# 加密密码字符
|
||||
import crypt
|
||||
return crypt.crypt(password, password)
|
||||
|
||||
|
||||
def get_url(timeout=0.5):
|
||||
import json
|
||||
try:
|
||||
nodeFile = '/www/server/panel/data/node.json'
|
||||
node_list = json.loads(readFile(nodeFile))
|
||||
mnode = None
|
||||
for node in node_list:
|
||||
node['ping'] = get_timeout(
|
||||
node['protocol'] + node['address'] + ':' + node['port'] + '/check.txt')
|
||||
if not node['ping']:
|
||||
continue
|
||||
if not mnode:
|
||||
mnode = node
|
||||
if node['ping'] < mnode['ping']:
|
||||
mnode = node
|
||||
return mnode['protocol'] + mnode['address'] + ':' + mnode['port']
|
||||
except:
|
||||
return 'http://download.bt.cn'
|
||||
|
||||
|
||||
def get_timeout(url):
|
||||
def getTimeout(url):
|
||||
start = time.time()
|
||||
result = httpGet(url)
|
||||
if result != 'True':
|
||||
@@ -570,14 +561,6 @@ def checkToken(get):
|
||||
return True
|
||||
|
||||
|
||||
def get_webserver():
|
||||
# 获取Web服务器
|
||||
webserver = 'nginx'
|
||||
if not os.path.exists('/www/server/nginx/sbin/nginx'):
|
||||
webserver = 'apache'
|
||||
return webserver
|
||||
|
||||
|
||||
def checkInput(data):
|
||||
# 过滤输入
|
||||
if not data:
|
||||
@@ -682,7 +665,7 @@ def checkCert(certPath='ssl/certificate.pem'):
|
||||
# return result
|
||||
|
||||
|
||||
def to_size(size):
|
||||
def toSize(size):
|
||||
# 字节单位转换
|
||||
d = ('b', 'KB', 'MB', 'GB', 'TB')
|
||||
s = d[0]
|
||||
@@ -694,6 +677,13 @@ def to_size(size):
|
||||
return str(size) + ' ' + b
|
||||
|
||||
|
||||
def getMacAddress():
|
||||
# 获取mac
|
||||
import uuid
|
||||
mac = uuid.UUID(int=uuid.getnode()).hex[-12:]
|
||||
return ":".join([mac[e:e + 2] for e in range(0, 11, 2)])
|
||||
|
||||
|
||||
def get_string(t):
|
||||
if t != -1:
|
||||
max = 126
|
||||
|
||||
@@ -0,0 +1,399 @@
|
||||
# coding: utf-8
|
||||
|
||||
import psutil
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
import public
|
||||
import re
|
||||
import json
|
||||
import pwd
|
||||
|
||||
|
||||
class site_api:
|
||||
siteName = None # 网站名称
|
||||
sitePath = None # 根目录
|
||||
sitePort = None # 端口
|
||||
phpVersion = None # PHP版本
|
||||
setupPath = None # 安装路径
|
||||
isWriteLogs = None # 是否写日志
|
||||
|
||||
def __init__(self):
|
||||
self.setupPath = public.getServerDir()
|
||||
path = self.setupPath + '/openresty/nginx/conf/vhost'
|
||||
if not os.path.exists(path):
|
||||
public.execShell("mkdir -p " + path + " && chmod -R 755 " + path)
|
||||
path = self.setupPath + '/openresty/nginx/conf/rewrite'
|
||||
if not os.path.exists(path):
|
||||
public.execShell("mkdir -p " + path + " && chmod -R 755 " + path)
|
||||
|
||||
# 域名编码转换
|
||||
def toPunycode(self, domain):
|
||||
import re
|
||||
if sys.version_info[0] == 2:
|
||||
domain = domain.encode('utf8')
|
||||
tmp = domain.split('.')
|
||||
newdomain = ''
|
||||
for dkey in tmp:
|
||||
# 匹配非ascii字符
|
||||
match = re.search(u"[\x80-\xff]+", dkey)
|
||||
if not match:
|
||||
newdomain += dkey + '.'
|
||||
else:
|
||||
newdomain += 'xn--' + \
|
||||
dkey.decode('utf-8').encode('punycode') + '.'
|
||||
return newdomain[0:-1]
|
||||
|
||||
# 中文路径处理
|
||||
def toPunycodePath(self, path):
|
||||
if sys.version_info[0] == 2:
|
||||
path = path.encode('utf-8')
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
import re
|
||||
match = re.search(u"[\x80-\xff]+", path)
|
||||
if not match:
|
||||
return path
|
||||
npath = ''
|
||||
for ph in path.split('/'):
|
||||
npath += '/' + self.toPunycode(ph)
|
||||
return npath.replace('//', '/')
|
||||
|
||||
# 路径处理
|
||||
def getPath(self, path):
|
||||
if path[-1] == '/':
|
||||
return path[0:-1]
|
||||
return path
|
||||
|
||||
def getHostConf(self, siteName):
|
||||
return public.getServerDir() + '/openresty/nginx/conf/vhost/' + siteName + '.conf'
|
||||
|
||||
def getRewriteConf(self, siteName):
|
||||
return public.getServerDir() + '/openresty/nginx/conf/rewrite/' + siteName + '.conf'
|
||||
|
||||
def getIndexConf(self):
|
||||
return public.getServerDir() + '/openresty/nginx/conf/nginx.conf'
|
||||
|
||||
def list(self):
|
||||
_list = public.M('sites').where('', ()).field(
|
||||
'id,name,path,status,ps,addtime,edate').limit('0,5').order('id desc').select()
|
||||
_ret = {}
|
||||
_ret['data'] = _list
|
||||
|
||||
count = public.M('sites').where('', ()).count()
|
||||
_page = {}
|
||||
_page['count'] = count
|
||||
_page['tojs'] = 'getWeb'
|
||||
|
||||
_ret['page'] = public.getPage(_page)
|
||||
return public.getJson(_ret)
|
||||
|
||||
def getDomain(self, pid):
|
||||
_list = public.M('domain').where("pid=?", (pid,)).field(
|
||||
'id,pid,name,port,addtime').select()
|
||||
return public.getJson(_list)
|
||||
|
||||
def getLogs(self, siteName):
|
||||
logPath = public.getLogsDir() + '/' + siteName + '.log'
|
||||
if not os.path.exists(logPath):
|
||||
return public.returnJson(False, '日志为空')
|
||||
return public.returnJson(True, public.getNumLines(logPath, 1000))
|
||||
|
||||
def getSitePhpVersion(self, siteName):
|
||||
conf = public.readFile(self.getHostConf(siteName))
|
||||
rep = "enable-php-([0-9]{2,3})\.conf"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
data = {}
|
||||
data['phpversion'] = tmp[0]
|
||||
return public.getJson(data)
|
||||
|
||||
def getIndex(self, sid):
|
||||
print sid
|
||||
siteName = public.M('sites').where("id=?", (sid,)).getField('name')
|
||||
file = self.getHostConf(siteName)
|
||||
conf = public.readFile(file)
|
||||
rep = "\s+index\s+(.+);"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
return tmp[0].replace(' ', ',')
|
||||
|
||||
def setIndex(self, sid, index):
|
||||
if index.find('.') == -1:
|
||||
return public.returnJson(False, '默认文档格式不正确,例:index.html')
|
||||
|
||||
index = index.replace(' ', '')
|
||||
index = index.replace(',,', ',')
|
||||
|
||||
if len(index) < 3:
|
||||
return public.returnJson(False, '默认文档不能为空!')
|
||||
|
||||
siteName = public.M('sites').where("id=?", (sid,)).getField('name')
|
||||
index_l = index.replace(",", " ")
|
||||
file = self.getHostConf(siteName)
|
||||
conf = public.readFile(file)
|
||||
if conf:
|
||||
rep = "\s+index\s+.+;"
|
||||
conf = re.sub(rep, "\n\tindex " + index_l + ";", conf)
|
||||
public.writeFile(file, conf)
|
||||
|
||||
public.writeLog('TYPE_SITE', 'SITE_INDEX_SUCCESS', (siteName, index_l))
|
||||
return public.returnJson(True, '设置成功!')
|
||||
|
||||
def getLimitNet(self, sid):
|
||||
siteName = public.M('sites').where("id=?", (sid,)).getField('name')
|
||||
filename = self.getHostConf(siteName)
|
||||
# 站点总并发
|
||||
data = {}
|
||||
conf = public.readFile(filename)
|
||||
try:
|
||||
rep = "\s+limit_conn\s+perserver\s+([0-9]+);"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
data['perserver'] = int(tmp[0])
|
||||
|
||||
# IP并发限制
|
||||
rep = "\s+limit_conn\s+perip\s+([0-9]+);"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
data['perip'] = int(tmp[0])
|
||||
|
||||
# 请求并发限制
|
||||
rep = "\s+limit_rate\s+([0-9]+)\w+;"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
data['limit_rate'] = int(tmp[0])
|
||||
except:
|
||||
data['perserver'] = 0
|
||||
data['perip'] = 0
|
||||
data['limit_rate'] = 0
|
||||
|
||||
return public.getJson(data)
|
||||
|
||||
def checkIndexConf(self):
|
||||
limit = self.getIndexConf()
|
||||
nginxConf = public.readFile(limit)
|
||||
limitConf = "limit_conn_zone $binary_remote_addr zone=perip:10m;\n\t\tlimit_conn_zone $server_name zone=perserver:10m;"
|
||||
nginxConf = nginxConf.replace(
|
||||
"#limit_conn_zone $binary_remote_addr zone=perip:10m;", limitConf)
|
||||
public.writeFile(limit, nginxConf)
|
||||
|
||||
def saveLimitNet(self, sid, perserver, perip, limit_rate):
|
||||
|
||||
str_perserver = 'limit_conn perserver ' + perserver + ';'
|
||||
str_perip = 'limit_conn perip ' + perip + ';'
|
||||
str_limit_rate = 'limit_rate ' + limit_rate + 'k;'
|
||||
|
||||
siteName = public.M('sites').where("id=?", (sid,)).getField('name')
|
||||
filename = self.getHostConf(siteName)
|
||||
|
||||
conf = public.readFile(filename)
|
||||
if(conf.find('limit_conn perserver') != -1):
|
||||
# 替换总并发
|
||||
rep = "limit_conn\s+perserver\s+([0-9]+);"
|
||||
conf = re.sub(rep, str_perserver, conf)
|
||||
|
||||
# 替换IP并发限制
|
||||
rep = "limit_conn\s+perip\s+([0-9]+);"
|
||||
conf = re.sub(rep, str_perip, conf)
|
||||
|
||||
# 替换请求流量限制
|
||||
rep = "limit_rate\s+([0-9]+)\w+;"
|
||||
conf = re.sub(rep, str_limit_rate, conf)
|
||||
else:
|
||||
conf = conf.replace('#error_page 404/404.html;', "#error_page 404/404.html;\n " +
|
||||
str_perserver + "\n " + str_perip + "\n " + str_limit_rate)
|
||||
|
||||
public.writeFile(filename, conf)
|
||||
public.restartWeb()
|
||||
public.writeLog('TYPE_SITE', 'SITE_NETLIMIT_OPEN_SUCCESS', (siteName,))
|
||||
return public.returnJson(True, '设置成功!')
|
||||
|
||||
def closeLimitNet(self, sid):
|
||||
siteName = public.M('sites').where("id=?", (sid,)).getField('name')
|
||||
filename = self.getHostConf(siteName)
|
||||
conf = public.readFile(filename)
|
||||
# 清理总并发
|
||||
rep = "\s+limit_conn\s+perserver\s+([0-9]+);"
|
||||
conf = re.sub(rep, '', conf)
|
||||
|
||||
# 清理IP并发限制
|
||||
rep = "\s+limit_conn\s+perip\s+([0-9]+);"
|
||||
conf = re.sub(rep, '', conf)
|
||||
|
||||
# 清理请求流量限制
|
||||
rep = "\s+limit_rate\s+([0-9]+)\w+;"
|
||||
conf = re.sub(rep, '', conf)
|
||||
public.writeFile(filename, conf)
|
||||
public.restartWeb()
|
||||
public.writeLog(
|
||||
'TYPE_SITE', 'SITE_NETLIMIT_CLOSE_SUCCESS', (siteName,))
|
||||
return public.returnJson(True, '已关闭流量限制!')
|
||||
|
||||
def getSecurity(self, sid, name):
|
||||
filename = self.getHostConf(name)
|
||||
conf = public.readFile(filename)
|
||||
data = {}
|
||||
if conf.find('SECURITY-START') != -1:
|
||||
rep = "#SECURITY-START(\n|.){1,500}#SECURITY-END"
|
||||
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
|
||||
else:
|
||||
data['fix'] = 'jpg,jpeg,gif,png,js,css'
|
||||
domains = public.M('domain').where(
|
||||
'pid=?', (sid,)).field('name').select()
|
||||
tmp = []
|
||||
for domain in domains:
|
||||
tmp.append(domain['name'])
|
||||
data['domains'] = ','.join(tmp)
|
||||
data['status'] = False
|
||||
return public.getJson(data)
|
||||
|
||||
def setSecurity(self, sid, name, fix, domains, status):
|
||||
if len(fix) < 2:
|
||||
return public.returnJson(False, 'URL后缀不能为空!')
|
||||
file = self.getHostConf(name)
|
||||
if os.path.exists(file):
|
||||
conf = public.readFile(file)
|
||||
if conf.find('SECURITY-START') != -1:
|
||||
rep = "\s{0,4}#SECURITY-START(\n|.){1,500}#SECURITY-END\n?"
|
||||
conf = re.sub(rep, '', conf)
|
||||
public.writeLog('网站管理', '站点[' + name + ']已关闭防盗链设置!')
|
||||
else:
|
||||
rconf = '''#SECURITY-START 防盗链配置
|
||||
location ~ .*\.(%s)$
|
||||
{
|
||||
expires 30d;
|
||||
access_log /dev/null;
|
||||
valid_referers none blocked %s;
|
||||
if ($invalid_referer){
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
#SECURITY-END
|
||||
include enable-php-''' % (fix.strip().replace(',', '|'), domains.strip().replace(',', ' '))
|
||||
conf = re.sub("include\s+enable-php-", rconf, conf)
|
||||
public.writeLog('网站管理', '站点[' + name + ']已开启防盗链!')
|
||||
public.writeFile(file, conf)
|
||||
public.restartWeb()
|
||||
return public.returnJson(True, '设置成功!')
|
||||
|
||||
def getPhpVersion(self):
|
||||
phpVersions = ('00', '52', '53', '54', '55',
|
||||
'56', '70', '71', '72', '73', '74')
|
||||
data = []
|
||||
for val in phpVersions:
|
||||
tmp = {}
|
||||
if val == '00':
|
||||
tmp['name'] = '纯静态'
|
||||
data.append(tmp)
|
||||
|
||||
checkPath = public.getServerDir() + '/php/' + val + '/bin/php'
|
||||
if os.path.exists(checkPath):
|
||||
tmp['version'] = val
|
||||
tmp['name'] = 'PHP-' + val
|
||||
data.append(tmp)
|
||||
|
||||
return public.getJson(data)
|
||||
|
||||
def getRewriteList(self):
|
||||
rewriteList = {}
|
||||
rewriteList['rewrite'] = []
|
||||
rewriteList['rewrite'].append('0.当前')
|
||||
for ds in os.listdir('rewrite/nginx'):
|
||||
rewriteList['rewrite'].append(ds[0:len(ds) - 5])
|
||||
rewriteList['rewrite'] = sorted(rewriteList['rewrite'])
|
||||
return rewriteList
|
||||
|
||||
def createRootDir(self, path):
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
if not public.isAppleSystem():
|
||||
public.execShell('chown -R www:www ' + path)
|
||||
public.execShell('chmod -R 755 ' + path)
|
||||
|
||||
def addDomain(self, domain, webname, pid):
|
||||
pass
|
||||
|
||||
def nginxAddConf(self):
|
||||
source_tpl = public.getRunDir() + '/data/tpl/nginx.conf'
|
||||
vhost_file = self.setupPath + '/openresty/nginx/conf/vhost/' + self.siteName + '.conf'
|
||||
content = public.readFile(source_tpl)
|
||||
|
||||
content = content.replace('{$PORT}', self.sitePort)
|
||||
content = content.replace('{$SERVER_NAME}', self.siteName)
|
||||
content = content.replace('{$ROOT_DIR}', self.sitePath)
|
||||
content = content.replace('{$PHPVER}', self.phpVersion)
|
||||
|
||||
or_rewrite = self.setupPath + '/openresty/nginx/conf/rewrite'
|
||||
content = content.replace('{$OR_REWRITE}', or_rewrite)
|
||||
|
||||
logsPath = public.getLogsDir()
|
||||
content = content.replace('{$LOGPATH}', logsPath)
|
||||
public.writeFile(vhost_file, content)
|
||||
|
||||
rewrite_file = self.setupPath + \
|
||||
'/openresty/nginx/conf/rewrite/' + self.siteName + '.conf'
|
||||
public.writeFile(rewrite_file, '')
|
||||
|
||||
def add(self, webname, port, ps, path, version):
|
||||
|
||||
siteMenu = json.loads(webname)
|
||||
self.siteName = self.toPunycode(
|
||||
siteMenu['domain'].strip().split(':')[0]).strip()
|
||||
self.sitePath = self.toPunycodePath(
|
||||
self.getPath(path.replace(' ', '')))
|
||||
self.sitePort = port.strip().replace(' ', '')
|
||||
self.phpVersion = version
|
||||
|
||||
siteM = public.M('sites')
|
||||
if siteM.where("name=?", (self.siteName,)).count():
|
||||
return public.returnJson(False, '您添加的站点已存在!')
|
||||
|
||||
# 写入数据库
|
||||
pid = siteM.add('name,path,status,ps,edate,addtime',
|
||||
(self.siteName, self.sitePath, '1', ps, '0000-00-00', public.getDate()))
|
||||
opid = public.M('domain').where(
|
||||
"name=?", (self.siteName,)).getField('pid')
|
||||
if opid:
|
||||
if public.M('sites').where('id=?', (opid,)).count():
|
||||
return public.returnJson(False, '您添加的域名已存在!')
|
||||
public.M('domain').where('pid=?', (opid,)).delete()
|
||||
|
||||
# 添加更多域名
|
||||
for domain in siteMenu['domainlist']:
|
||||
sdomain = domain
|
||||
swebname = self.siteName
|
||||
spid = str(get.pid)
|
||||
# self.addDomain(domain, webname, pid)
|
||||
|
||||
public.M('domain').add('pid,name,port,addtime',
|
||||
(pid, self.siteName, self.sitePort, public.getDate()))
|
||||
|
||||
self.createRootDir(self.sitePath)
|
||||
|
||||
self.nginxAddConf()
|
||||
|
||||
data = {}
|
||||
data['siteStatus'] = False
|
||||
public.restartWeb()
|
||||
return public.getJson(data)
|
||||
|
||||
def delete(self, sid, webname):
|
||||
|
||||
confFile = self.setupPath + '/openresty/nginx/conf/vhost/' + webname + '.conf'
|
||||
if os.path.exists(confFile):
|
||||
os.remove(confFile)
|
||||
|
||||
rewriteFile = self.setupPath + '/openresty/nginx/conf/rewrite/' + webname + '.conf'
|
||||
if os.path.exists(rewriteFile):
|
||||
os.remove(rewriteFile)
|
||||
|
||||
public.M('sites').where("id=?", (sid,)).delete()
|
||||
return public.returnJson(True, '站点删除成功!')
|
||||
|
||||
def setEndDate(self, sid, edate):
|
||||
result = public.M('sites').where(
|
||||
'id=?', (sid,)).setField('edate', edate)
|
||||
siteName = public.M('sites').where('id=?', (sid,)).getField('name')
|
||||
public.writeLog('TYPE_SITE', '设置成功,站点到期后将自动停止!', (siteName, edate))
|
||||
return public.returnJson(True, '设置成功,站点到期后将自动停止!')
|
||||
@@ -11,6 +11,7 @@ from flask import Flask, session
|
||||
|
||||
import db
|
||||
import public
|
||||
import config
|
||||
|
||||
|
||||
class system_api:
|
||||
@@ -18,7 +19,7 @@ class system_api:
|
||||
pids = None
|
||||
|
||||
def __init__(self):
|
||||
self.setupPath = '/www/server'
|
||||
self.setupPath = public.getServerDir()
|
||||
|
||||
# 名取PID
|
||||
def getPid(self, pname):
|
||||
@@ -402,7 +403,7 @@ class system_api:
|
||||
return None
|
||||
|
||||
def restartServer(self, get):
|
||||
if not public.IsRestart():
|
||||
if not public.isRestart():
|
||||
return public.returnMsg(False, 'EXEC_ERR_TASK')
|
||||
public.ExecShell("sync && /etc/init.d/bt stop && init 6 &")
|
||||
return public.returnMsg(True, 'SYS_REBOOT')
|
||||
@@ -515,22 +516,120 @@ class system_api:
|
||||
|
||||
return public.returnJson(True, "设置成功!")
|
||||
|
||||
# 更新服务
|
||||
def updateServer(self, stype):
|
||||
def versionDiff(self, old, new):
|
||||
'''
|
||||
test 测试
|
||||
new 有新版本
|
||||
none 没有新版本
|
||||
'''
|
||||
new_list = new.split('.')
|
||||
if len(new_list) > 3:
|
||||
return 'test'
|
||||
|
||||
old_list = old.split('.')
|
||||
|
||||
ret = 'none'
|
||||
for i in range(len(old_list)):
|
||||
tm_new = int(new_list[i])
|
||||
tm_old = int(new_list[i])
|
||||
if tm_new > tm_old:
|
||||
return 'new'
|
||||
return ret
|
||||
|
||||
def getServerInfo(self):
|
||||
|
||||
upAddr = 'https://raw.githubusercontent.com/midoks/mdserver-web/master/version'
|
||||
try:
|
||||
version = public.httpGet(
|
||||
upAddr + '/info.json')
|
||||
version = json.loads(version)
|
||||
return version[0]
|
||||
except Exception as e:
|
||||
print e
|
||||
return {}
|
||||
|
||||
def updateServer(self, stype, version=''):
|
||||
# 更新服务
|
||||
try:
|
||||
|
||||
if public.isUpdateLocalSoft():
|
||||
if stype == 'check' or stype == 'info' or stype == 'update':
|
||||
return public.returnJson(True, '正在安装中...', 'download')
|
||||
if stype == 'update_status':
|
||||
|
||||
data = public.readFile('tmp/panelExec.log')
|
||||
if data == 'done':
|
||||
return public.returnJson(True, '进度!', 100)
|
||||
else:
|
||||
_data = json.loads(data)
|
||||
return public.returnJson(True, '进度!', _data['pre'])
|
||||
|
||||
if os.path.exists('mdserver-web.zip'):
|
||||
return public.returnJson(True, '进度!', 100)
|
||||
|
||||
if not public.isRestart():
|
||||
return public.returnMsg(False, '请等待所有安装任务完成再执行!')
|
||||
return public.returnJson(False, '请等待所有安装任务完成再执行!')
|
||||
if stype == 'check':
|
||||
public.httpGet('')
|
||||
version_now = config.config().getVersion()
|
||||
version_new_info = self.getServerInfo()
|
||||
if not 'version' in version_new_info:
|
||||
return public.returnJson(False, '服务器数据有问题!')
|
||||
|
||||
diff = self.versionDiff(
|
||||
version_now, version_new_info['version'])
|
||||
if diff == 'new':
|
||||
return public.returnJson(True, '有新版本!', version_new_info['version'])
|
||||
elif diff == 'test':
|
||||
return public.returnJson(True, '有测试版本!', version_new_info['version'])
|
||||
else:
|
||||
return public.returnJson(False, '已经是最新,无需更新!')
|
||||
|
||||
if stype == 'info':
|
||||
version_new_info = self.getServerInfo()
|
||||
version_now = config.config().getVersion()
|
||||
|
||||
if not 'version' in version_new_info:
|
||||
return public.returnJson(False, '服务器数据有问题!')
|
||||
diff = self.versionDiff(
|
||||
version_now, version_new_info['version'])
|
||||
return public.returnJson(True, '更新信息!', version_new_info)
|
||||
|
||||
if stype == 'update':
|
||||
if version == '':
|
||||
return public.returnJson(False, '缺少版本信息!')
|
||||
|
||||
v_new_info = self.getServerInfo()
|
||||
if v_new_info['version'] != version:
|
||||
return public.returnJson(False, '更新失败,请重试!')
|
||||
|
||||
if not 'path' in v_new_info or v_new_info['path'] == '':
|
||||
return public.returnJson(False, '下载地址不存在!')
|
||||
|
||||
execstr = v_new_info['path'] + '|dl|mdserver-web.zip'
|
||||
taskAdd = (None, '下载[mdserver-web-' + v_new_info['version'] + ']',
|
||||
'download', '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr)
|
||||
|
||||
public.M('tasks').add(
|
||||
'id,name,type,status,addtime, execstr', taskAdd)
|
||||
return public.returnJson(True, '下载中...')
|
||||
|
||||
if stype == 'update_install':
|
||||
public.execShell('unzip -o mdserver-web.zip -d ./')
|
||||
public.execShell('rm -f mdserver-web.zip')
|
||||
return public.returnJson(True, '安装更新成功!')
|
||||
|
||||
return public.returnJson(False, '已经是最新,无需更新!')
|
||||
except Exception as ex:
|
||||
print ex
|
||||
return public.returnJson(False, "连接服务器失败!")
|
||||
|
||||
# 重启面板
|
||||
def reWeb(self, get):
|
||||
# if not public.IsRestart(): return
|
||||
# public.returnMsg(False,'EXEC_ERR_TASK');
|
||||
if not public.isRestart():
|
||||
public.returnMsg(False, '请等待所有安装任务完成再执行!')
|
||||
|
||||
# public.ExecShell('/etc/init.d/bt restart &')
|
||||
return True
|
||||
public.returnMsg(True, '执行成功!')
|
||||
|
||||
# 修复面板
|
||||
def repPanel(self, get):
|
||||
@@ -542,11 +641,3 @@ class system_api:
|
||||
if hasattr(web.ctx.session, 'getCloudPlugin'):
|
||||
del(web.ctx.session['getCloudPlugin'])
|
||||
return True
|
||||
|
||||
# 升级到专业版
|
||||
def updatePro(self, get):
|
||||
public.ExecShell("wget -O update.sh " + public.get_url() +
|
||||
"/install/update_pro.sh && bash update.sh pro")
|
||||
if hasattr(web.ctx.session, 'getCloudPlugin'):
|
||||
del(web.ctx.session['getCloudPlugin'])
|
||||
return True
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
|
||||
|
||||
|
||||
mw_start(){
|
||||
gunicorn -c setting.py app:app &
|
||||
python task.py &
|
||||
}
|
||||
|
||||
|
||||
mw_start_debug(){
|
||||
# gunicorn -c setting.py app:app
|
||||
python task.py &
|
||||
gunicorn -b :7200 app:app
|
||||
# gunicorn -c setting.py app:app
|
||||
|
||||
}
|
||||
|
||||
mw_stop()
|
||||
{
|
||||
ps -ef|grep app:app |grep -v grep|awk '{print $2}'|xargs kill -9
|
||||
ps -ef|grep task.py |grep -v grep|awk '{print $2}'|xargs kill -9
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
'start') mw_start;;
|
||||
'stop') mw_stop;;
|
||||
'restart')
|
||||
mw_stop
|
||||
mw_start
|
||||
;;
|
||||
'debug')
|
||||
mw_stop
|
||||
mw_start_debug
|
||||
;;
|
||||
esac
|
||||
@@ -1 +0,0 @@
|
||||
30
|
||||
@@ -10,7 +10,7 @@
|
||||
"ps":""
|
||||
},
|
||||
{
|
||||
"title":"缓存软件",
|
||||
"title":"数据软件",
|
||||
"type":2,
|
||||
"ps":""
|
||||
},
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
7200
|
||||
@@ -0,0 +1 @@
|
||||
True
|
||||
@@ -94,6 +94,7 @@ CREATE TABLE IF NOT EXISTS `sites` (
|
||||
`status` TEXT,
|
||||
`index` TEXT,
|
||||
`ps` TEXT,
|
||||
`edate` TEXT,
|
||||
`addtime` TEXT
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
server
|
||||
{
|
||||
listen {$PORT};
|
||||
server_name {$SERVER_NAME};
|
||||
index index.php index.html index.htm default.php default.htm default.html;
|
||||
root {$ROOT_DIR};
|
||||
|
||||
#SSL-START %s
|
||||
#error_page 404/404.html;
|
||||
#SSL-END
|
||||
|
||||
#ERROR-PAGE-START %s
|
||||
error_page 404 /404.html;
|
||||
error_page 502 /502.html;
|
||||
#ERROR-PAGE-END
|
||||
|
||||
#PHP-INFO-START %s
|
||||
include enable-php-{$PHPVER}.conf;
|
||||
#PHP-INFO-END
|
||||
|
||||
#REWRITE-START %s
|
||||
include {$OR_REWRITE}/{$SERVER_NAME}.conf;
|
||||
#REWRITE-END
|
||||
|
||||
#禁止访问的文件或目录
|
||||
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
|
||||
{
|
||||
return 404;
|
||||
}
|
||||
|
||||
#一键申请SSL证书验证目录相关设置
|
||||
location ~ \.well-known{
|
||||
allow all;
|
||||
}
|
||||
|
||||
location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf)$
|
||||
{
|
||||
expires 30d;
|
||||
error_log off;
|
||||
access_log /dev/null;
|
||||
}
|
||||
|
||||
location ~ .*\\.(js|css)?$
|
||||
{
|
||||
expires 12h;
|
||||
error_log off;
|
||||
access_log /dev/null;
|
||||
}
|
||||
|
||||
access_log {$LOGPATH}/{$SERVER_NAME}.log;
|
||||
error_log {$LOGPATH}/{$SERVER_NAME}.error.log;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf ./*.pyc
|
||||
rm -rf ./*/*.pyc
|
||||
|
||||
#open "http://127.0.0.1:7200"
|
||||
|
After Width: | Height: | Size: 181 B |
@@ -0,0 +1,16 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('abkill');">服务</p>
|
||||
<p onclick="pluginInitD('abkill');">自启动</p>
|
||||
<p onclick="pluginConfig('abkill');">黑名单</p>
|
||||
<p onclick="pluginConfig('abkill');">异常日志</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=abkill&f=js/abkill.js");
|
||||
</script>
|
||||
@@ -0,0 +1,172 @@
|
||||
# coding: utf-8
|
||||
|
||||
import time
|
||||
import random
|
||||
import os
|
||||
import urllib
|
||||
import binascii
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
|
||||
|
||||
app_debug = False
|
||||
if public.getOs() == 'darwin':
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'abkill'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
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 initDreplace():
|
||||
initd_file = getInitDFile()
|
||||
|
||||
if not os.path.exists(initd_file):
|
||||
return getServerDir()
|
||||
|
||||
return initd_file
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
"ps -ef|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def csvnOp(method):
|
||||
|
||||
if app_debug:
|
||||
os_name = public.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
_initd_csvn = '/etc/init.d/csvn'
|
||||
_initd_csvn_httpd = '/etc/init.d/csvn-httpd'
|
||||
#_csvn = getServerDir() + '/bin/csvn'
|
||||
#_csvn_httpd = getServerDir() + '/bin/csvn-httpd'
|
||||
|
||||
ret_csvn_httpd = public.execShell(_initd_csvn_httpd + ' ' + method)
|
||||
# ret_csvn = public.execShell(_initd_csvn + ' ' + method)
|
||||
subprocess.Popen(_initd_csvn + ' ' + method,
|
||||
stdout=subprocess.PIPE, shell=True)
|
||||
if ret_csvn_httpd[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def start():
|
||||
return csvnOp('start')
|
||||
|
||||
|
||||
def stop():
|
||||
return csvnOp('stop')
|
||||
|
||||
|
||||
def restart():
|
||||
return csvnOp('restart')
|
||||
|
||||
|
||||
def reload():
|
||||
return csvnOp('reload')
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.getOs() == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
_initd_csvn = '/etc/init.d/csvn'
|
||||
_initd_csvn_httpd = '/etc/init.d/csvn-httpd'
|
||||
|
||||
if os.path.exists(_initd_csvn) and os.path.exists(_initd_csvn_httpd):
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.getOs() == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
_csvn = getServerDir() + '/bin/csvn'
|
||||
_csvn_httpd = getServerDir() + '/bin/csvn-httpd'
|
||||
|
||||
ret_csvn = public.execShell(_csvn + ' install')
|
||||
ret_csvn_httpd = public.execShell(_csvn_httpd + ' install')
|
||||
if ret_csvn[1] == '' and ret_csvn_httpd[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.getOs() == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
_csvn = getServerDir() + '/bin/csvn'
|
||||
_csvn_httpd = getServerDir() + '/bin/csvn-httpd'
|
||||
|
||||
ret_csvn = public.execShell(_csvn + ' remove')
|
||||
ret_csvn_httpd = public.execShell(_csvn_httpd + ' remove')
|
||||
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 == 'initd_status':
|
||||
print initdStatus()
|
||||
elif func == 'initd_install':
|
||||
print initdInstall()
|
||||
elif func == 'initd_uninstall':
|
||||
print initdUinstall()
|
||||
else:
|
||||
print 'fail'
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"sort": 7,
|
||||
"ps": "异常程序监控和KILL",
|
||||
"shell": "install.sh",
|
||||
"name": "abkill",
|
||||
"title": "异常程序监控",
|
||||
"versions": "0.1",
|
||||
"updates":"0.1",
|
||||
"tip": "soft",
|
||||
"checks": "server/abkill",
|
||||
"author": "midoks",
|
||||
"date": "201-04-01",
|
||||
"home": "https://www.collab.net",
|
||||
"type": "异常程序监控和KILL",
|
||||
"pid": "4"
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
|
||||
ak_path={$SERVER_PATH}/abkill
|
||||
|
||||
ak_start(){
|
||||
isStart=$(ps aux |grep 'abkill.py'|grep -v grep|awk '{print $2}')
|
||||
if [ "$isStart" == '' ];then
|
||||
echo -e "Starting abkill... \c"
|
||||
cd $ak_path && nohup python abkill.py >> $ak_path/task.log 2>&1 &
|
||||
sleep 0.3
|
||||
isStart=$(ps aux |grep 'abkill.py'|grep -v grep|awk '{print $2}')
|
||||
if [ "$isStart" == '' ];then
|
||||
echo -e "\033[31mfailed\033[0m"
|
||||
echo '------------------------------------------------------'
|
||||
tail -n 20 $ak_path/task.log
|
||||
echo '------------------------------------------------------'
|
||||
echo -e "\033[31mError: abkill service startup failed.\033[0m"
|
||||
return;
|
||||
fi
|
||||
echo -e "\033[32mdone\033[0m"
|
||||
else
|
||||
echo "Starting abkill(pid $isStart) already running"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
ak_stop()
|
||||
{
|
||||
echo -e "Stopping abkill... \c";
|
||||
pids=$(ps aux | grep 'abkill.py' | grep -v grep|awk '{print $2}')
|
||||
arr=($pids)
|
||||
|
||||
for p in ${arr[@]}
|
||||
do
|
||||
kill -9 $p
|
||||
done
|
||||
echo -e "\033[32mdone\033[0m"
|
||||
|
||||
}
|
||||
|
||||
ak_status()
|
||||
{
|
||||
isStart=$(ps aux|grep 'abkill.py'|grep -v grep|awk '{print $2}')
|
||||
if [ "$isStart" != '' ];then
|
||||
echo -e "\033[32mabkill (pid $(echo $isStart)) already running\033[0m"
|
||||
else
|
||||
echo -e "\033[31mabkill not running\033[0m"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
ak_reload()
|
||||
{
|
||||
isStart=$(ps aux|grep 'abkill.py'|grep -v grep|awk '{print $2}')
|
||||
|
||||
if [ "$isStart" != '' ];then
|
||||
ak_stop
|
||||
ak_start
|
||||
else
|
||||
echo -e "\033[31mmw not running\033[0m"
|
||||
mw_start
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
'start') ak_start;;
|
||||
'stop') ak_stop;;
|
||||
'reload') ak_reload;;
|
||||
'restart')
|
||||
ak_stop
|
||||
sleep 0.3
|
||||
ak_start;;
|
||||
'status') ak_status;;
|
||||
esac
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/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/bt_install.pl
|
||||
|
||||
Install_abkill()
|
||||
{
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
mkdir -p $serverPath/abkill
|
||||
echo '0.1' > $serverPath/abkill/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_abkill()
|
||||
{
|
||||
rm -f $serverPath/abkill
|
||||
echo "卸载完成" > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_abkill
|
||||
else
|
||||
Uninstall_abkill
|
||||
fi
|
||||
@@ -0,0 +1 @@
|
||||
pluginService('abkill');
|
||||
@@ -31,12 +31,12 @@ class btkill:
|
||||
if cputimes.user < 0.1:
|
||||
continue
|
||||
print p
|
||||
percent = p.cpu_percent(interval=0.1)
|
||||
percent = p.cpu_percent(interval=1)
|
||||
vm = p.memory_info().vms
|
||||
if percent > self.__limit or vm > self.__vmsize:
|
||||
log = time.strftime('%Y-%m-%d %X', time.localtime()) + " (PID=" + str(
|
||||
pid) + ", NAME=" + name + ", VMS=" + str(vm) + ", PERCENT=" + str(percent) + "%)"
|
||||
p.kill()
|
||||
# p.kill()
|
||||
num += 1
|
||||
print log + " >> killed\n"
|
||||
except Exception as ex:
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
export LC_ALL=en_US.UTF-8
|
||||
export LC_CTYPE=zh_CN.UTF-8
|
||||
|
||||
|
||||
REPOS="$1"
|
||||
REV="$2"
|
||||
TXN_NAME="$3"
|
||||
|
||||
|
||||
WEB_PATH={$PROJECT_DIR}/wwwroot/$REPOS
|
||||
SVN_PATH=http://127.0.0.1:{$PORT}/svn/$REPOS
|
||||
|
||||
if [ ! -d $WEB_PATH ]; then
|
||||
svn co $SVN_PATH $WEB_PATH \
|
||||
--username={$CSVN_USER} \
|
||||
--password={$CSVN_PWD} \
|
||||
--no-auth-cache \
|
||||
--non-interactive
|
||||
fi
|
||||
|
||||
cd $WEB_PATH && svn update --username={$CSVN_USER} --password={$CSVN_PWD}
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
REPOS="$1"
|
||||
REV="$2"
|
||||
TXN_NAME="$3"
|
||||
|
||||
REPOS_NAME=${REPOS##*/}
|
||||
|
||||
sh -x $REPOS/hooks/commit $REPOS_NAME $REV $TXN_NAME 2>$REPOS/sh.log
|
||||
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.1 KiB |
@@ -1,550 +1,37 @@
|
||||
<style>
|
||||
|
||||
|
||||
/*危险按钮*/
|
||||
.bts-danger:hover{
|
||||
color: #fff;
|
||||
background-color: #c9302c;
|
||||
border-color: #ac2925;
|
||||
}
|
||||
#whiteList a{
|
||||
color: red;
|
||||
}
|
||||
|
||||
/*弹窗*/
|
||||
.Add_view{
|
||||
height: 100px;
|
||||
padding-left: 35px;
|
||||
padding-top: 35px;
|
||||
}
|
||||
.Add_view label{
|
||||
margin-right: 10px;
|
||||
font-size: 15px;
|
||||
font-weight: 100;
|
||||
}
|
||||
.Add_view input{
|
||||
width: 230px;
|
||||
}
|
||||
.Add_view .error{
|
||||
border: 1px solid red;
|
||||
}
|
||||
.Add_view .correct{
|
||||
border: 1px solid #20a53a;
|
||||
}
|
||||
|
||||
/*日志管理*/
|
||||
.btnTitle{
|
||||
font-weight: 100;
|
||||
font-size: 16px;
|
||||
line-height: 34px;
|
||||
height: 34px;
|
||||
margin-right: 15px;
|
||||
position: relative;
|
||||
top: 2px;
|
||||
}
|
||||
.whiteList-table{
|
||||
margin-top: 10px;
|
||||
}
|
||||
/*登录日志表单*/
|
||||
.viewTwo .whiteList-table{
|
||||
overflow-x: hidden;
|
||||
height: 500px;
|
||||
}
|
||||
.maks{
|
||||
background: rgba(39, 39, 39, 0.4);
|
||||
position: absolute;
|
||||
width: 700px;
|
||||
height: 555px;
|
||||
z-index: 999;
|
||||
overflow: hidden;
|
||||
}
|
||||
.boxshow{
|
||||
position: absolute;
|
||||
height: 150px;
|
||||
width: 400px;
|
||||
margin-left: -200px;
|
||||
margin-top: -75px;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
z-index: 1000;
|
||||
background: #fff;
|
||||
padding: 25px 20px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.btPayment {
|
||||
float: left;
|
||||
padding: 8px 10px;
|
||||
width: 190px;
|
||||
height: 100px;
|
||||
line-height: 33px;
|
||||
text-align: center;
|
||||
border-left: 1px solid #ececec;
|
||||
}
|
||||
.btPayment .t2{
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.btPayment .price{
|
||||
color: #20A53A;
|
||||
font-size: 22px;
|
||||
margin: 0 5px;
|
||||
|
||||
}
|
||||
.bt-form{
|
||||
overflow: hidden;
|
||||
}
|
||||
.boxtext{
|
||||
line-height: 32px;
|
||||
margin-top: -17px;
|
||||
text-align: center;
|
||||
border-bottom: #eee 1px solid;
|
||||
height: 39px;
|
||||
font-size: 14px;
|
||||
<style type="text/css">
|
||||
.outline_no {
|
||||
outline:none;
|
||||
}
|
||||
</style>
|
||||
<div class="maks" style="display: none"></div>
|
||||
<div class="boxshow" style="display: none;">
|
||||
<div>
|
||||
<div class="boxtext">
|
||||
<span>未开通此服务,如需使用请开通企业运维版。</span>
|
||||
</div>
|
||||
<div class="btvipinfo" style="width: 170px;padding-left: 20px">
|
||||
<p style="height: 25px">1、一对一运维人员对接</p>
|
||||
<p style="height: 25px">2、提供每月3次运维服务</p>
|
||||
<p style="height: 25px">3、双重安全隔离登录</p>
|
||||
</div>
|
||||
<div class="btPayment">
|
||||
<span class="t2">企业运维版<span class="price">98</span>元/月</span>
|
||||
<button class="btn btn-success btn-sm" style="width:80%" onclick="window.open('https://www.bt.cn/admin/index.html')">立即开通</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw">密钥</p>
|
||||
<p>面板设置</p>
|
||||
<p>面板登录日志</p>
|
||||
<p>SSH设置</p>
|
||||
<p>SSH日志管理</p>
|
||||
<p class="bgw" onclick="pluginService('csvn');">服务</p>
|
||||
<p onclick="pluginInitD('csvn');">自启动</p>
|
||||
<p onclick="csvnEdit();">手动编辑</p>
|
||||
<p onclick="csvnUserList(1);">用户管理</p>
|
||||
<p onclick="csvnProjectList(1);">项目管理</p>
|
||||
<p onclick="csvnReadme();">使用说明</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con viewZoo">
|
||||
<p class="status" style="margin-top:10px;margin-left:10px;height: 80px;margin-bottom:15px;">
|
||||
<span style="float:left;margin-top:-5px">密钥:</span>
|
||||
<textarea class="bt-input-text" name="token" readonly="readonly" style="background-color: #eee;width:400px;height:80px;padding: 8px 15px;" placeholder="密钥已隐藏..."></textarea>
|
||||
</p>
|
||||
<input type="button" class="btn btn-success btn-sm" name="ButtonShow" style="margin-left:52px;width:100px" onclick="sagelogin.tokenShow()" value="显示密钥" />
|
||||
<ul style="margin: 15px 5px;padding-left: 70px;list-style-type: disc;line-height: 25px;">
|
||||
<li>宝塔企业运维后台连接您的服务器需要此密钥,请妥善记录并保存</li>
|
||||
<li>一但密钥丢失,可能导致您无法登录服务器</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="soft-man-con viewOne" style="display: none;">
|
||||
<p class="status">当前状态:
|
||||
<span>开启</span>
|
||||
<span style="color: #20a53a; margin-left: 3px;" class="glyphicon glyphicon glyphicon-play"></span>
|
||||
<span style="color: red; margin-left: 3px; display: none" class="glyphicon glyphicon-pause"></span>
|
||||
</p>
|
||||
<div class="sfm-opt">
|
||||
<button class="btn btn-default btn-sm bts-danger" onclick="sagelogin.Panel_Admin()">清除面板登录限制IP</button>
|
||||
<button class="btn btn-default btn-sm bts-safety" onclick="sagelogin.Add_view('面板白名单',true)">添加白名单</button>
|
||||
</div>
|
||||
<div class="whiteList-table divtable" style="overflow-x: hidden;height: 420px">
|
||||
<table class="table table-hover" style="max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>IP地址</th>
|
||||
<th style="text-align: right;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListOne"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="soft-man-con viewTwo" style="display: none">
|
||||
<div class="whiteList-table divtable">
|
||||
<table class="table table-hover" style=" max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>操作记录</th>
|
||||
<th>操作时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListTwo"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="soft-man-con viewThree" style="display: none">
|
||||
<p class="status">当前状态:
|
||||
<span>开启</span>
|
||||
<span style="color: #20a53a; margin-left: 3px;" class="glyphicon glyphicon glyphicon-play">
|
||||
</span>
|
||||
<span style="color: red; margin-left: 3px; display: none" class="glyphicon glyphicon-pause"></span>
|
||||
</p>
|
||||
<div class="sfm-opt">
|
||||
<button class="btn btn-default btn-sm bts-danger" onclick="sagelogin.Panel_Admin()">清除SSH登录限制IP</button>
|
||||
<button class="btn btn-default btn-sm bts-safety" onclick="sagelogin.Add_view('SSH白名单',false)">添加白名单</button>
|
||||
</div>
|
||||
<div class="whiteList-table divtable" style="overflow-x: hidden;height: 420px">
|
||||
<table class="table table-hover" style="max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>IP地址</th>
|
||||
<th style="text-align: right;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListThree"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="soft-man-con viewFour" style="display: none">
|
||||
<div class="btnclick">
|
||||
<label class="btnTitle">日志分类</label>
|
||||
<div class="btn-group">
|
||||
<input type="submit" name="btnOne" class="btn btn-success" onclick="sagelogin.SSH_Defense_List(0)" value="已防御" />
|
||||
<input type="submit" name="btnTwo" class="btn btn-default" onclick="sagelogin.SSH_Defense_List(1)" value="入侵日志"/>
|
||||
<input type="submit" name="btnThree" class="btn btn-default" onclick="sagelogin.SSH_Defense_List(2)" value="登录日志"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="whiteList-table divtable" style="overflow-x: hidden;height: 470px;">
|
||||
<table class="table table-hover" style="max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>源IP地址</th>
|
||||
<th>用户</th>
|
||||
<th style="text-align: right;">登录时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListFour"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="javascript/text">
|
||||
//宝塔安全登录
|
||||
$(function(){
|
||||
$(".bt-w-menu p").click(function(){
|
||||
$(this).addClass("bgw").siblings().removeClass("bgw");
|
||||
$('.bt-w-con .soft-man-con').hide().eq($(this).index()).show();
|
||||
switch($(this).index()) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
sagelogin.Panel_White_List();
|
||||
break;
|
||||
case 2:
|
||||
sagelogin.Panel_journal();
|
||||
break;
|
||||
case 3:
|
||||
sagelogin.SSH_White_List();
|
||||
break;
|
||||
case 4:
|
||||
sagelogin.SSH_Defense_List(0);
|
||||
break;
|
||||
}
|
||||
});
|
||||
layer.load();
|
||||
$.get('/plugin?action=a&name=safelogin&s=GetServerInfo',function(data) {
|
||||
layer.closeAll('loading');
|
||||
if (data.status) {
|
||||
$('.boxshow').hide();
|
||||
$('.maks').hide();
|
||||
}else{
|
||||
$('.boxshow').show();
|
||||
$('.maks').show();
|
||||
}
|
||||
});
|
||||
});
|
||||
var sagelogin = new Object();
|
||||
sagelogin = {
|
||||
Addview:'',
|
||||
SSHlogList:'',
|
||||
PanelLogList:'',
|
||||
// SSH管理
|
||||
SSH_Admin:function(){
|
||||
var confirm = layer.confirm('确定清除面板登录限制IP地址?',{icon: 1}, {
|
||||
btn: ['确认','取消'],
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=close_ssh_limit',function(data) {
|
||||
if (data.status) {
|
||||
layer.msg(data.msg,{icon:1});
|
||||
sagelogin.SSH_White_List();
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
},
|
||||
tokenShow:function(){
|
||||
var inputPwd = layer.open({
|
||||
type: 1,
|
||||
title: '验证面板密码',
|
||||
shadeClose: true,
|
||||
shade: 0.3,
|
||||
area: ['380px', '190px'],
|
||||
btn:['确定','取消'],
|
||||
content:'<div class="Add_view" style="height:90px"><label>面板密码:</label><input name="panel_pwd" class=" bt-input-text" type="password"></div>',
|
||||
yes:function(){
|
||||
var passwordStr = $("input[name='panel_pwd']").val();
|
||||
var index = layer.load(0, {shade: false});
|
||||
$.post('/plugin?action=a&name=safelogin&s=GetServerToken',{password:passwordStr},function(token) {
|
||||
layer.close(index);
|
||||
if(token.status === false){
|
||||
layer.msg(token.msg,{icon:2});
|
||||
return;
|
||||
}
|
||||
layer.close(inputPwd);
|
||||
$("textarea[name='token']").val(token);
|
||||
});
|
||||
},
|
||||
btn2:function(){
|
||||
layer.close(inputPwd);
|
||||
}
|
||||
});
|
||||
},
|
||||
// SSH白名单——列表
|
||||
SSH_White_List:function(){
|
||||
var index = layer.load(0, {shade: false});
|
||||
$.get('/plugin?action=a&name=safelogin&s=get_ssh_limit','',function(data){
|
||||
$('#whiteListThree').empty();
|
||||
var List = '';
|
||||
if (data.length == 0){
|
||||
$('.viewThree .status span:eq(0)').html('关闭');
|
||||
$('.viewThree .glyphicon-pause').show();
|
||||
$('.viewThree .glyphicon-play').hide();
|
||||
}else {
|
||||
$('.viewThree .status span:eq(0)').html('开启');
|
||||
$('.viewThree .glyphicon-pause').hide();
|
||||
$('.viewThree .glyphicon-play').show();
|
||||
}
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
List = List + '<tr><td>'+ data[i] +'</td><td style="text-align:right;"><a href="javascript:;" ip-val="'+ data[i] +'" onclick="sagelogin.SSH_Del_White_List(event)" style="color:red">删除</a></td></tr>'
|
||||
}
|
||||
$('#whiteListThree').append(List);
|
||||
layer.close(index);
|
||||
});
|
||||
},
|
||||
// SSH白名单——删除
|
||||
SSH_Del_White_List:function(ev){
|
||||
var ip = ev.currentTarget.getAttribute('ip-val');
|
||||
var confirm = layer.confirm('确定删除IP['+ ip +']限制地址?', {
|
||||
btn: ['确认','取消'] //按钮
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=remove_ssh_limit',{ip:ip},function(data){
|
||||
if (data.status) {
|
||||
sagelogin.SSH_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else {
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
},
|
||||
// SSH白名单——添加
|
||||
SSH_Add_White_List:function(ip){
|
||||
$.post('/plugin?action=a&name=safelogin&s=add_ssh_limit',{ip:ip},function(data){
|
||||
layer.close(sagelogin.Addview);
|
||||
if (data.status) {
|
||||
sagelogin.SSH_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
},
|
||||
// SSH日志管理
|
||||
SSH_Defense_List:function(status){
|
||||
$('.btnclick input').removeClass('btn-success').addClass('btn-default');
|
||||
$('.btnclick input').eq(status).addClass('btn-success').removeClass('btn-default');
|
||||
if (sagelogin.SSHlogList == '') {
|
||||
$.get('/plugin?action=a&s=get_ssh_errorlogin&name=safelogin',function(data){
|
||||
sagelogin.SSHlogList = data;
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.defense);
|
||||
});
|
||||
}else{
|
||||
switch(status) {
|
||||
case 0:
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.defense);
|
||||
break;
|
||||
case 1:
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.intrusion);
|
||||
break;
|
||||
case 2:
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.success);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
// SSH日志渲染模板
|
||||
DefenseFor:function(data){
|
||||
var List = '';
|
||||
$('#whiteListFour').empty();
|
||||
for (var i = data.length - 1; i >= 0; i--) {
|
||||
List = List + '<tr><td>'+data[i].address+'</td><td>' + data[i].user + '</td><td style="text-align:right">'+ data[i].date+'</td></tr>'
|
||||
}
|
||||
$('#whiteListFour').append(List);
|
||||
},
|
||||
// 面板管理
|
||||
Panel_Admin:function(){
|
||||
var confirm = layer.confirm('确定清除面板登录限制IP地址?', {
|
||||
btn: ['确认','取消'] //按钮
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=close_panel_limit',function(data) {
|
||||
if (data.status) {
|
||||
layer.msg(data.msg,{icon:1});
|
||||
sagelogin.Panel_White_List();
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
|
||||
},
|
||||
// 面板白名单——列表
|
||||
Panel_White_List:function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=get_panel_limit','',function(data){
|
||||
$('#whiteListOne').empty();
|
||||
var List = '';
|
||||
if (data.length == 0){
|
||||
$('.viewOne .status span:eq(0)').html('关闭');
|
||||
$('.viewOne .glyphicon-pause').show();
|
||||
$('.viewOne .glyphicon-play').hide();
|
||||
}else {
|
||||
$('.viewOne .status span:eq(0)').html('开启');
|
||||
$('.viewOne .glyphicon-pause').hide();
|
||||
$('.viewOne .glyphicon-play').show();
|
||||
}
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
List = List + '<tr><td>'+ data[i] +'</td><td style="text-align:right;"><a href="javascript:;" ip-val="'+ data[i] +'" onclick="sagelogin.Panel_Del_White_List(event)" style="color:red">删除</a></td></tr>'
|
||||
}
|
||||
$('#whiteListOne').append(List);
|
||||
});
|
||||
},
|
||||
// 面板白名单——删除
|
||||
Panel_Del_White_List:function(ev){
|
||||
var ip = ev.currentTarget.getAttribute('ip-val');
|
||||
var confirm = layer.confirm('确定删除IP['+ ip +']限制地址?', {
|
||||
btn: ['确认','取消'] //按钮
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=remove_ssh_limit',{ip:ip},function(data){
|
||||
if (data.status) {
|
||||
sagelogin.Panel_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else {
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
},
|
||||
// 面板白名单——添加
|
||||
Panel_Add_White_List:function(ip){
|
||||
$.post('/plugin?action=a&name=safelogin&s=add_panel_limit', {ip: ip}, function(data) {
|
||||
layer.close(sagelogin.Addview);
|
||||
if (data.status) {
|
||||
sagelogin.Panel_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
},
|
||||
// 面板日志——列表
|
||||
Panel_journal:function(){
|
||||
var index = layer.load(0, {shade: false});
|
||||
$.get('/plugin?action=a&name=safelogin&s=get_login_log',function(data){
|
||||
$('#whiteListTwo').empty();
|
||||
var List = '';
|
||||
sagelogin.PanelLogList = data;
|
||||
for (var i = sagelogin.PanelLogList.length - 1; i >= 0; i--) {
|
||||
List = List + '<tr><td>'+ sagelogin.PanelLogList[i].log +'</td><td style="text-align:right;">'+ sagelogin.PanelLogList[i].addtime +'</tr>';
|
||||
}
|
||||
$('#whiteListTwo').append(List);
|
||||
layer.close(index);
|
||||
});
|
||||
},
|
||||
// IP正则:192.168.1.0/24
|
||||
CheckIP:function(ip) {
|
||||
var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\/\d{1,2})?$/;
|
||||
return reg.test(ip);
|
||||
},
|
||||
CheckIPTwo:function(ip) {
|
||||
var reg = /^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/gi;
|
||||
return reg.test(ip);
|
||||
},
|
||||
// 添加表单效验
|
||||
addViewVul:function(status){
|
||||
var ip = $('.addViewVul');
|
||||
if (status) {
|
||||
console.log(sagelogin.CheckIP(ip.val()));
|
||||
if(sagelogin.CheckIPTwo(ip.val())){
|
||||
ip.addClass('correct').removeClass('error');
|
||||
return true;
|
||||
}else {
|
||||
ip.addClass('error').removeClass('correct');
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
|
||||
if(sagelogin.CheckIP(ip.val())){
|
||||
ip.addClass('correct').removeClass('error');
|
||||
return true;
|
||||
}else {
|
||||
ip.addClass('error').removeClass('correct');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
// 添加界面
|
||||
Add_view:function(title,status){
|
||||
var _this = this;
|
||||
var text = ''
|
||||
var statuss = true;
|
||||
if (status) {
|
||||
text = '';
|
||||
statuss = true;
|
||||
}else{
|
||||
text = '<p style="color:red;margin: 5px 0px 0px 67px;font-size: 14px;">支持IP段,如:192.168.1.0/24</p>';
|
||||
statuss = false;
|
||||
}
|
||||
sagelogin.Addview = layer.open({
|
||||
type: 1,
|
||||
title: title,
|
||||
shadeClose: true,
|
||||
shade: 0.1,
|
||||
area: ['380px', '200px'],
|
||||
btn:['确定','取消'],
|
||||
content:'<div class="Add_view"><label>IP地址:</label><input class="addViewVul bt-input-text" onchange="sagelogin.addViewVul('+ statuss +')" type="text">'+ text +'</div>',
|
||||
yes:function(){
|
||||
if (sagelogin.addViewVul(statuss)) {
|
||||
if(status){
|
||||
sagelogin.Panel_Add_White_List($('.addViewVul').val());
|
||||
}else{
|
||||
sagelogin.SSH_Add_White_List($('.addViewVul').val());
|
||||
}
|
||||
}else{
|
||||
layer.msg('请输入合法的IP地址',{icon:2})
|
||||
}
|
||||
},
|
||||
btn2:function(){
|
||||
layer.close(sagelogin.Addview);
|
||||
}
|
||||
});
|
||||
$('.addViewVul').focus();
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
resetPluginWinWidth(700);
|
||||
|
||||
$.getScript( "/plugins/file?name=csvn&f=js/csvn.js");
|
||||
|
||||
function csvnReadme(){
|
||||
var html = '<p>* 注意:在启动时会比较慢,需要耐心等待一会</p>';
|
||||
html += '<p>* 注意:csvn需要java环境,在安装会自动检查并安装</p>';
|
||||
html += '<p>* 注意:默认后台密码admin:admin,最好马上修改</p>';
|
||||
html += '<p>* 注意:牢记admin的密码,在后csvn的管理后台和这里不同步</p>';
|
||||
html += '<p>* 注意:在这里添加用户和csvn后台并不同步</p>';
|
||||
html += '<p>* 注意:项目管理的地址一般是正确的,但在特殊环境下,地址可能不一致</p>';
|
||||
|
||||
$('.bt-w-main .soft-man-con').html(html);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,20 +1,692 @@
|
||||
# coding: utf-8
|
||||
|
||||
import time
|
||||
import psutil
|
||||
import random
|
||||
import os
|
||||
import urllib
|
||||
import binascii
|
||||
import json
|
||||
import public
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
|
||||
|
||||
app_debug = False
|
||||
if public.getOs() == 'darwin':
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'csvn'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
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 initDreplace():
|
||||
initd_file = getInitDFile()
|
||||
|
||||
if not os.path.exists(initd_file):
|
||||
return getServerDir()
|
||||
|
||||
return initd_file
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
"ps -ef|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def csvnOp(method):
|
||||
|
||||
if app_debug:
|
||||
os_name = public.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
_initd_csvn = '/etc/init.d/csvn'
|
||||
_initd_csvn_httpd = '/etc/init.d/csvn-httpd'
|
||||
#_csvn = getServerDir() + '/bin/csvn'
|
||||
#_csvn_httpd = getServerDir() + '/bin/csvn-httpd'
|
||||
|
||||
ret_csvn_httpd = public.execShell(_initd_csvn_httpd + ' ' + method)
|
||||
# ret_csvn = public.execShell(_initd_csvn + ' ' + method)
|
||||
subprocess.Popen(_initd_csvn + ' ' + method,
|
||||
stdout=subprocess.PIPE, shell=True)
|
||||
if ret_csvn_httpd[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def start():
|
||||
return csvnOp('start')
|
||||
|
||||
|
||||
def stop():
|
||||
return csvnOp('stop')
|
||||
|
||||
|
||||
def restart():
|
||||
return csvnOp('restart')
|
||||
|
||||
|
||||
def reload():
|
||||
return csvnOp('reload')
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.getOs() == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
_initd_csvn = '/etc/init.d/csvn'
|
||||
_initd_csvn_httpd = '/etc/init.d/csvn-httpd'
|
||||
|
||||
if os.path.exists(_initd_csvn) and os.path.exists(_initd_csvn_httpd):
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.getOs() == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
_csvn = getServerDir() + '/bin/csvn'
|
||||
_csvn_httpd = getServerDir() + '/bin/csvn-httpd'
|
||||
|
||||
ret_csvn = public.execShell(_csvn + ' install')
|
||||
ret_csvn_httpd = public.execShell(_csvn_httpd + ' install')
|
||||
if ret_csvn[1] == '' and ret_csvn_httpd[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.getOs() == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
_csvn = getServerDir() + '/bin/csvn'
|
||||
_csvn_httpd = getServerDir() + '/bin/csvn-httpd'
|
||||
|
||||
ret_csvn = public.execShell(_csvn + ' remove')
|
||||
ret_csvn_httpd = public.execShell(_csvn_httpd + ' remove')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def csvnEdit():
|
||||
data = {}
|
||||
data['svn_access_file'] = getServerDir() + '/data/conf/svn_access_file'
|
||||
data['commit_tpl'] = getPluginDir() + '/hook/commit.tpl'
|
||||
data['post_commit_tpl'] = getPluginDir() + '/hook/post-commit.tpl'
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
def userAdd():
|
||||
args = getArgs()
|
||||
if not 'username' in args:
|
||||
return 'name missing'
|
||||
|
||||
if not 'password' in args:
|
||||
return 'password missing'
|
||||
|
||||
htpasswd = getServerDir() + "/bin/htpasswd"
|
||||
svn_auth_file = getServerDir() + "/data/conf/svn_auth_file"
|
||||
cmd = htpasswd + ' -b ' + svn_auth_file + ' ' + \
|
||||
args['username'] + ' ' + args['password']
|
||||
data = public.execShell(cmd)
|
||||
# print data
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def userDel():
|
||||
args = getArgs()
|
||||
if not 'username' in args:
|
||||
return 'name missing'
|
||||
|
||||
htpasswd = getServerDir() + "/bin/htpasswd"
|
||||
svn_auth_file = getServerDir() + "/data/conf/svn_auth_file"
|
||||
cmd = htpasswd + ' -D ' + svn_auth_file + ' ' + args['username']
|
||||
data = public.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def getAllUser(search=''):
|
||||
svn_auth_file = getServerDir() + '/data/conf/svn_auth_file'
|
||||
if not os.path.exists(svn_auth_file):
|
||||
return public.getJson([])
|
||||
auth = public.readFile(svn_auth_file)
|
||||
auth = auth.strip()
|
||||
auth_list = auth.split("\n")
|
||||
|
||||
ulist = []
|
||||
for x in range(len(auth_list)):
|
||||
tmp = auth_list[x].split(':')
|
||||
if search != '':
|
||||
if tmp[0].find(search) != -1:
|
||||
ulist.append(tmp[0])
|
||||
else:
|
||||
ulist.append(tmp[0])
|
||||
return ulist
|
||||
|
||||
|
||||
def userList():
|
||||
import math
|
||||
args = getArgs()
|
||||
|
||||
page = 1
|
||||
page_size = 10
|
||||
search = ''
|
||||
if 'page' in args:
|
||||
page = int(args['page'])
|
||||
|
||||
if 'page_size' in args:
|
||||
page_size = int(args['page_size'])
|
||||
|
||||
if 'search' in args:
|
||||
search = args['search']
|
||||
|
||||
ulist = getAllUser(search)
|
||||
ulist_sum = len(ulist)
|
||||
|
||||
page_info = {'count': ulist_sum, 'p': page,
|
||||
'row': 10, 'tojs': 'csvnUserList'}
|
||||
data = {}
|
||||
data['list'] = public.getPage(page_info)
|
||||
data['page'] = page
|
||||
data['page_size'] = page_size
|
||||
data['page_count'] = int(math.ceil(ulist_sum / page_size))
|
||||
start = (page - 1) * page_size
|
||||
|
||||
data['data'] = ulist[start:start + page_size]
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
def projectAdd():
|
||||
args = getArgs()
|
||||
if not 'name' in args:
|
||||
return 'project name missing'
|
||||
path = getServerDir() + '/bin/svnadmin'
|
||||
dest = getServerDir() + '/data/repositories/' + args['name']
|
||||
cmd = path + ' create ' + dest
|
||||
data = public.execShell(cmd)
|
||||
if data[1] == '':
|
||||
public.execShell('chown -R csvn:csvn ' + dest)
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def projectDel():
|
||||
args = getArgs()
|
||||
if not 'name' in args:
|
||||
return 'project name missing'
|
||||
|
||||
dest = getServerDir() + '/data/repositories/' + args['name']
|
||||
cmd = 'rm -rf ' + dest
|
||||
data = public.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def getHttpPort():
|
||||
http_main_conf = getServerDir() + '/data/conf/csvn_main_httpd.conf'
|
||||
try:
|
||||
if os.path.exists(http_main_conf):
|
||||
content = public.readFile(http_main_conf)
|
||||
return re.search('Listen\s(\d+)', content).groups()[0]
|
||||
except Exception as e:
|
||||
pass # print e
|
||||
return '80'
|
||||
|
||||
|
||||
def getCsvnPort():
|
||||
http_main_conf = getServerDir() + '/data/conf/csvn-wrapper.conf'
|
||||
try:
|
||||
if os.path.exists(http_main_conf):
|
||||
content = public.readFile(http_main_conf)
|
||||
return re.search('wrapper.java.additional.3=-Djetty.port=(\d+)', content).groups()[0]
|
||||
except Exception as e:
|
||||
pass # print e
|
||||
return '3343'
|
||||
|
||||
|
||||
def getALlProjectList(search=''):
|
||||
path = getServerDir() + '/data/repositories'
|
||||
dlist = []
|
||||
if os.path.exists(path):
|
||||
for filename in os.listdir(path):
|
||||
tmp = {}
|
||||
filePath = path + '/' + filename
|
||||
if os.path.isdir(filePath):
|
||||
if search == '':
|
||||
tmp['name'] = filename
|
||||
dlist.append(tmp)
|
||||
else:
|
||||
if filename.find(search) != -1:
|
||||
tmp['name'] = filename
|
||||
dlist.append(tmp)
|
||||
return dlist
|
||||
|
||||
|
||||
def checkProjectListIsHasScript(data):
|
||||
dlen = len(data)
|
||||
for x in range(dlen):
|
||||
path = getServerDir() + '/data/repositories/' + \
|
||||
data[x]['name'] + '/hooks/post-commit'
|
||||
if os.path.exists(path):
|
||||
data[x]['has_hook'] = True
|
||||
else:
|
||||
data[x]['has_hook'] = False
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def projectList():
|
||||
import math
|
||||
args = getArgs()
|
||||
|
||||
page = 1
|
||||
page_size = 10
|
||||
search = ''
|
||||
if 'page' in args:
|
||||
page = int(args['page'])
|
||||
|
||||
if 'page_size' in args:
|
||||
page_size = int(args['page_size'])
|
||||
|
||||
if 'search' in args:
|
||||
search = args['search']
|
||||
|
||||
dlist = getALlProjectList(search)
|
||||
dlist_sum = len(dlist)
|
||||
|
||||
start = (page - 1) * page_size
|
||||
ret_data = dlist[start:start + page_size]
|
||||
ret_data = checkProjectListIsHasScript(ret_data)
|
||||
|
||||
data = {}
|
||||
data['data'] = ret_data
|
||||
data['list'] = public.getPage(
|
||||
{'count': dlist_sum, 'p': page, 'row': 10, 'tojs': 'csvnProjectList'})
|
||||
data['ip'] = public.getLocalIp()
|
||||
data['port'] = getHttpPort()
|
||||
data['csvn_port'] = getCsvnPort()
|
||||
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
def getAllAclList():
|
||||
svn_access_file = getServerDir() + '/data/conf/svn_access_file'
|
||||
aData = public.readFile(svn_access_file)
|
||||
aData = re.sub('#.*', '', aData)
|
||||
aData = aData.strip().split('[')[1:]
|
||||
allAcl = {}
|
||||
for i in range(len(aData)):
|
||||
oData = aData[i].strip().split(']')
|
||||
name = oData[0].strip('/').strip(':')
|
||||
if oData[1] == '':
|
||||
allAcl[name] = []
|
||||
else:
|
||||
user = oData[1].strip().split('\n')
|
||||
userAll = []
|
||||
for iu in range(len(user)):
|
||||
ulist = user[iu].split('=')
|
||||
utmp = {}
|
||||
utmp['user'] = ulist[0].strip()
|
||||
utmp['acl'] = ulist[1].strip()
|
||||
userAll.append(utmp)
|
||||
allAcl[name] = userAll
|
||||
return allAcl
|
||||
|
||||
|
||||
def makeAclFile(content):
|
||||
# print content
|
||||
svn_access_file = getServerDir() + '/data/conf/svn_access_file'
|
||||
tmp = "\n"
|
||||
for k, v in content.items():
|
||||
if k == '':
|
||||
tmp += "[/]\n"
|
||||
else:
|
||||
tmp += "[" + k + ":/]\n"
|
||||
|
||||
for iv in range(len(v)):
|
||||
tmp += v[iv]['user'] + ' = ' + v[iv]['acl'] + "\n"
|
||||
tmp += "\n"
|
||||
# svn_tmp_path = getServerDir() + '/data/conf/svn_access_file.log'
|
||||
return public.writeFile(svn_access_file, tmp)
|
||||
|
||||
|
||||
def projectAclList():
|
||||
args = getArgs()
|
||||
if not 'name' in args:
|
||||
return 'name missing!'
|
||||
name = args['name']
|
||||
acl = getAllAclList()
|
||||
|
||||
if name in acl:
|
||||
return public.getJson(acl[name])
|
||||
else:
|
||||
return 'fail'
|
||||
|
||||
|
||||
def projectAclAdd():
|
||||
args = getArgs()
|
||||
if not 'uname' in args:
|
||||
return 'username missing'
|
||||
if not 'pname' in args:
|
||||
return 'project name missing'
|
||||
uname = args['uname']
|
||||
pname = args['pname']
|
||||
|
||||
ulist = getAllUser()
|
||||
if not uname in ulist:
|
||||
return uname + " user not exists!"
|
||||
|
||||
acl = getAllAclList()
|
||||
|
||||
tmp_acl = {'user': uname, 'acl': 'rw'}
|
||||
if not pname in acl:
|
||||
acl[pname] = [tmp_acl]
|
||||
makeAclFile(acl)
|
||||
return 'ok'
|
||||
|
||||
tmp = acl[pname]
|
||||
tmp_len = len(tmp)
|
||||
|
||||
if tmp_len == 0:
|
||||
acl[pname] = [tmp_acl]
|
||||
else:
|
||||
is_have = False
|
||||
for x in range(tmp_len):
|
||||
if tmp[x]['user'] == uname:
|
||||
is_have = True
|
||||
return uname + ' users already exist!'
|
||||
if not is_have:
|
||||
tmp.append(tmp_acl)
|
||||
acl[pname] = tmp
|
||||
|
||||
makeAclFile(acl)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def projectAclDel():
|
||||
args = getArgs()
|
||||
if not 'uname' in args:
|
||||
return 'username missing'
|
||||
if not 'pname' in args:
|
||||
return 'project name missing'
|
||||
|
||||
uname = args['uname']
|
||||
pname = args['pname']
|
||||
|
||||
ulist = getAllUser()
|
||||
if not uname in ulist:
|
||||
return uname + " user not exists!"
|
||||
|
||||
acl = getAllAclList()
|
||||
|
||||
if not pname in acl:
|
||||
return 'project not exists!'
|
||||
|
||||
tmp = acl[pname]
|
||||
tmp_len = len(tmp)
|
||||
if tmp_len == 0:
|
||||
return 'project no have user:' + uname
|
||||
else:
|
||||
is_have = False
|
||||
rtmp = []
|
||||
for x in range(tmp_len):
|
||||
if tmp[x]['user'] != uname:
|
||||
rtmp.append(tmp[x])
|
||||
acl[pname] = rtmp
|
||||
makeAclFile(acl)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def projectAclSet():
|
||||
args = getArgs()
|
||||
if not 'uname' in args:
|
||||
return 'username missing'
|
||||
if not 'pname' in args:
|
||||
return 'project name missing'
|
||||
if not 'acl' in args:
|
||||
return 'acl missing'
|
||||
|
||||
uname = args['uname']
|
||||
pname = args['pname']
|
||||
up_acl = args['acl']
|
||||
|
||||
ulist = getAllUser()
|
||||
if not uname in ulist:
|
||||
return uname + " user not exists!"
|
||||
|
||||
acl = getAllAclList()
|
||||
|
||||
if not pname in acl:
|
||||
return 'project not exists!'
|
||||
|
||||
tmp = acl[pname]
|
||||
tmp_len = len(tmp)
|
||||
if tmp_len == 0:
|
||||
return 'project no have user:' + uname
|
||||
else:
|
||||
is_have = False
|
||||
for x in range(tmp_len):
|
||||
if tmp[x]['user'] == uname:
|
||||
tmp[x]['acl'] = up_acl
|
||||
acl[pname] = tmp
|
||||
makeAclFile(acl)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def getCsvnUser():
|
||||
user = 'admin_sync'
|
||||
|
||||
acl = getAllAclList()
|
||||
if '' in acl:
|
||||
tmp = acl['']
|
||||
is_has = False
|
||||
for data in tmp:
|
||||
if data['user'] == user:
|
||||
is_has = True
|
||||
if not is_has:
|
||||
tmp.append({'user': user, 'acl': 'r'})
|
||||
acl[''] = tmp
|
||||
makeAclFile(acl)
|
||||
return user
|
||||
|
||||
|
||||
def getCsvnPwd(user):
|
||||
if app_debug:
|
||||
return user + '123'
|
||||
pwd_file = 'data/csvn_sync.pl'
|
||||
|
||||
if os.path.exists(pwd_file):
|
||||
return public.readFile(pwd_file).strip()
|
||||
|
||||
import time
|
||||
cur_time = time.time()
|
||||
rand_pwd = public.md5(str(cur_time))
|
||||
pwd = user + rand_pwd[:5]
|
||||
|
||||
htpasswd = getServerDir() + "/bin/htpasswd"
|
||||
svn_auth_file = getServerDir() + "/data/conf/svn_auth_file"
|
||||
cmd = htpasswd + ' -b ' + svn_auth_file + ' ' + user + ' ' + pwd
|
||||
data = public.execShell(cmd)
|
||||
|
||||
public.writeFile(pwd_file, pwd)
|
||||
return pwd
|
||||
|
||||
|
||||
def projectScriptLoad():
|
||||
|
||||
args = getArgs()
|
||||
if not 'pname' in args:
|
||||
return 'project name missing'
|
||||
|
||||
post_commit_tpl = getPluginDir() + '/hook/post-commit.tpl'
|
||||
hook_path = getServerDir() + '/data/repositories/' + \
|
||||
args['pname'] + '/hooks'
|
||||
post_commit_file = hook_path + '/post-commit'
|
||||
|
||||
pct_content = public.readFile(post_commit_tpl)
|
||||
public.writeFile(post_commit_file, pct_content)
|
||||
public.execShell('chmod 777 ' + post_commit_file)
|
||||
|
||||
commit_tpl = getPluginDir() + '/hook/commit.tpl'
|
||||
commit_file = hook_path + '/commit'
|
||||
|
||||
ct_content = public.readFile(commit_tpl)
|
||||
ct_content = ct_content.replace('{$PROJECT_DIR}', public.getRootDir())
|
||||
ct_content = ct_content.replace('{$PORT}', getHttpPort())
|
||||
ct_content = ct_content.replace('{$CSVN_USER}', getCsvnUser())
|
||||
ct_content = ct_content.replace('{$CSVN_PWD}', getCsvnPwd(getCsvnUser()))
|
||||
|
||||
public.writeFile(commit_file, ct_content)
|
||||
public.execShell('chmod 777 ' + commit_file)
|
||||
|
||||
return 'ok'
|
||||
|
||||
|
||||
def projectScriptUnload():
|
||||
args = getArgs()
|
||||
if not 'pname' in args:
|
||||
return 'project name missing'
|
||||
|
||||
post_commit_file = getServerDir() + '/data/repositories/' + '/' + \
|
||||
args['pname'] + '/hooks/post-commit'
|
||||
public.execShell('rm -f ' + post_commit_file)
|
||||
|
||||
commit_file = getServerDir() + '/data/repositories/' + '/' + \
|
||||
args['pname'] + '/hooks/commit'
|
||||
public.execShell('rm -f ' + commit_file)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def projectScriptEdit():
|
||||
args = getArgs()
|
||||
if not 'pname' in args:
|
||||
return 'project name missing'
|
||||
|
||||
data = {}
|
||||
commit_file = getServerDir() + '/data/repositories/' + \
|
||||
args['pname'] + '/hooks/commit'
|
||||
if os.path.exists(commit_file):
|
||||
data['status'] = True
|
||||
data['path'] = commit_file
|
||||
else:
|
||||
data['status'] = False
|
||||
data['msg'] = 'file does not exist'
|
||||
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
def projectScriptDebug():
|
||||
args = getArgs()
|
||||
if not 'pname' in args:
|
||||
return 'project name missing'
|
||||
|
||||
data = {}
|
||||
commit_log = getServerDir() + '/data/repositories/' + \
|
||||
args['pname'] + '/sh.log'
|
||||
if os.path.exists(commit_log):
|
||||
data['status'] = True
|
||||
data['path'] = commit_log
|
||||
else:
|
||||
data['status'] = False
|
||||
data['msg'] = 'file does not exist'
|
||||
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
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 == 'csvn_edit':
|
||||
print csvnEdit()
|
||||
elif func == 'user_list':
|
||||
print userList()
|
||||
elif func == 'user_add':
|
||||
print userAdd()
|
||||
elif func == 'user_del':
|
||||
print userDel()
|
||||
elif func == 'project_list':
|
||||
print projectList()
|
||||
elif func == 'project_del':
|
||||
print projectDel()
|
||||
elif func == 'project_add':
|
||||
print projectAdd()
|
||||
elif func == 'project_acl_list':
|
||||
print projectAclList()
|
||||
elif func == 'project_acl_add':
|
||||
print projectAclAdd()
|
||||
elif func == 'project_acl_del':
|
||||
print projectAclDel()
|
||||
elif func == 'project_acl_set':
|
||||
print projectAclSet()
|
||||
elif func == 'project_script_load':
|
||||
print projectScriptLoad()
|
||||
elif func == 'project_script_unload':
|
||||
print projectScriptUnload()
|
||||
elif func == 'project_script_edit':
|
||||
print projectScriptEdit()
|
||||
elif func == 'project_script_debug':
|
||||
print projectScriptDebug()
|
||||
else:
|
||||
print 'fail'
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
"shell": "install.sh",
|
||||
"name": "csvn",
|
||||
"title": "CSVN",
|
||||
"versions": ["5.1"],
|
||||
"updates":["5.1.4"],
|
||||
"versions": "5.1",
|
||||
"updates":"5.1.4",
|
||||
"tip": "soft",
|
||||
"checks": "server/csvn",
|
||||
"author": "midoks",
|
||||
|
||||
@@ -14,16 +14,31 @@ CSVN_SOURCE='https://github.com/midoks/mdserver-web/releases/download/init/Colla
|
||||
|
||||
Install_csvn()
|
||||
{
|
||||
mkdir -p $serverPath/tmp
|
||||
mkdir -p $serverPath/source
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
if [ ! -f $serverPath/tmp/csvn.tar.xz ];then
|
||||
wget -O $serverPath/so/csvn.tar.xz ${CSVN_SOURCE}
|
||||
if [ ! -f $serverPath/source/csvn.tar.xz ];then
|
||||
wget -O $serverPath/source/csvn.tar.xz ${CSVN_SOURCE}
|
||||
fi
|
||||
|
||||
cd $serverPath/tmp && tar -Jxf $serverPath/tmp/csvn.tar.xz
|
||||
mv $serverPath/tmp/csvn $serverPath/csvn
|
||||
cd $serverPath/source && tar -Jxf $serverPath/source/csvn.tar.xz
|
||||
mv $serverPath/source/csvn $serverPath/csvn
|
||||
echo '5.1' > $serverPath/csvn/version.pl
|
||||
|
||||
|
||||
if id -u csvn > /dev/null 2>&1; then
|
||||
echo "csvn user exists"
|
||||
else
|
||||
useradd csvn
|
||||
cp /etc/sudoers{,.`date +"%Y-%m-%d_%H-%M-%S"`}
|
||||
echo "csvn ALL=(ALL) ALL" >> /etc/sudoers
|
||||
fi
|
||||
|
||||
chown -R csvn:csvn $serverPath/csvn
|
||||
|
||||
# $serverPath/csvn/bin/csvn install
|
||||
# $serverPath/csvn/bin/csvn-httpd install
|
||||
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
@@ -0,0 +1,504 @@
|
||||
pluginService('csvn');
|
||||
|
||||
function csvnPost(method,args,callback){
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'csvn', func:method, args:JSON.stringify(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 csvnEdit(){
|
||||
|
||||
csvnPost('csvn_edit',{} , function(data){
|
||||
// console.log(data);
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var edit = '<p class="status">通用的手动编辑:</p>';
|
||||
edit +='<div class="sfm-opt">\
|
||||
<button class="btn btn-default btn-sm" onclick="onlineEditFile(0,\''+rdata['svn_access_file']+'\');">权限编辑</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="onlineEditFile(0,\''+rdata['post_commit_tpl']+'\');">post_commit_tpl</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="onlineEditFile(0,\''+rdata['commit_tpl']+'\');">commit_tpl</button>\
|
||||
</div>';
|
||||
$(".soft-man-con").html(edit);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function csvnUserFind(){
|
||||
var search = $('#csvn_find_user').val();
|
||||
if (search==''){
|
||||
layer.msg('搜索字符不能为空!',{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
csvnUserList(1, search);
|
||||
}
|
||||
|
||||
function csvnUserList(page, search) {
|
||||
|
||||
var _data = {};
|
||||
if (typeof(page) =='undefined'){
|
||||
var page = 1;
|
||||
}
|
||||
|
||||
_data['page'] = page;
|
||||
_data['page_size'] = 10;
|
||||
if(typeof(search) != 'undefined'){
|
||||
_data['search'] = search;
|
||||
}
|
||||
|
||||
csvnPost('user_list', _data, function(data){
|
||||
|
||||
var rdata = $.parseJSON(data.data);
|
||||
// console.log(rdata);
|
||||
content = '<div class="finduser"><input class="bt-input-text mr5 outline_no" type="text" placeholder="查找用户名" id="csvn_find_user" style="height: 28px; border-radius: 3px;width: 505px;">';
|
||||
content += '<button class="btn btn-success btn-sm" onclick="csvnUserFind();">查找</button></div>';
|
||||
|
||||
content += '<div class="divtable" style="margin-top:5px;"><table class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0">';
|
||||
content += '<thead><tr>';
|
||||
content += '<th>用户名</th>';
|
||||
content += '<th>操作(<a class="btlink" onclick="csvnAddUser();">添加</a>)</th>';
|
||||
content += '</tr></thead>';
|
||||
|
||||
content += '<tbody>';
|
||||
|
||||
ulist = rdata.data;
|
||||
for (i in ulist){
|
||||
content += '<tr><td>'+ulist[i]+'</td><td>'+
|
||||
'<a class="btlink" onclick="csvnDelUser(\''+ulist[i]+'\')">删除</a> | ' +
|
||||
'<a class="btlink" onclick="csvnModPwdUser(\''+ulist[i]+'\')">改密</a></td></tr>';
|
||||
}
|
||||
|
||||
content += '</tbody>';
|
||||
content += '</table></div>';
|
||||
|
||||
page = '<div class="dataTables_paginate paging_bootstrap pagination" style="margin-top:0px;"><ul id="softPage" class="page"><div>';
|
||||
page += rdata.list;
|
||||
page += '</div></ul></div>';
|
||||
|
||||
content += page;
|
||||
|
||||
$(".soft-man-con").html(content);
|
||||
});
|
||||
}
|
||||
|
||||
function csvnDelUser(name){
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '删除用户',
|
||||
area: '350px',
|
||||
content:"<div class='bt-form pd20 pb70 c6'>\
|
||||
<div class='version line'>你要确认要删除"+ name + "账户?</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' id='csvn_del_close' class='btn btn-danger btn-sm btn-title'>关闭</button>\
|
||||
<button type='button' id='csvn_del_ok' class='btn btn-success btn-sm btn-title bi-btn'>确认</button>\
|
||||
</div>\
|
||||
</div>"
|
||||
});
|
||||
|
||||
$('#csvn_del_close').click(function(){
|
||||
layer.close(loadOpen);
|
||||
});
|
||||
|
||||
$('#csvn_del_ok').click(function(){
|
||||
_data = {};
|
||||
_data['username'] = name;
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'csvn', func:'user_del', args:JSON.stringify(_data)}, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.data !='ok'){
|
||||
layer.msg(data.data,{icon:2,time:2000,shade: [0.3, '#000']});
|
||||
}
|
||||
|
||||
layer.close(loadOpen);
|
||||
layer.msg("删除成功!",{icon:1,time:3000,shade: [0.3, '#000']});
|
||||
|
||||
},'json');
|
||||
});
|
||||
}
|
||||
|
||||
function csvnAddUser(username){
|
||||
|
||||
user_input = ''
|
||||
if (typeof(username) == 'undefined'){
|
||||
user_input = "<div><input class='bt-input-text mr5 outline_no' type='text' id='csvn_username' name='username' style='height: 28px; border-radius: 3px;width: 200px;' placeholder='输入用户名'></div>";
|
||||
} else {
|
||||
user_input = "<div><input value='"+ username +"' class='bt-input-text mr5 outline_no' type='text' id='csvn_username' name='username' style='height: 28px; border-radius: 3px;width: 200px;' disabled='true'></div>";
|
||||
}
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '添加用户',
|
||||
area: '240px',
|
||||
content:"<div class='bt-form pd20 pb70 c6'>\
|
||||
<div class='version line'>\
|
||||
"+user_input+"\
|
||||
<div style='padding-top:3px;'><input class='bt-input-text mr5 outline_no' type='text' id='csvn_password' name='password' style='height: 28px; border-radius: 3px;width: 200px;' placeholder='输入密码'></div>\
|
||||
</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' id='csvn_add_close' class='btn btn-danger btn-sm btn-title'>关闭</button>\
|
||||
<button type='button' id='csvn_add_ok' class='btn btn-success btn-sm btn-title bi-btn'>确认</button>\
|
||||
</div>\
|
||||
</div>"
|
||||
});
|
||||
|
||||
$('#csvn_add_close').click(function(){
|
||||
layer.close(loadOpen);
|
||||
});
|
||||
|
||||
$('#csvn_add_ok').click(function(){
|
||||
_data = {};
|
||||
|
||||
_data['username'] = $('#csvn_username').val();
|
||||
_data['password'] = $('#csvn_password').val();
|
||||
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'csvn', func:'user_add', args:JSON.stringify(_data)}, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.data !='ok'){
|
||||
layer.msg(data.data,{icon:2,time:2000,shade: [0.3, '#000']});
|
||||
}
|
||||
|
||||
csvnUserList();
|
||||
layer.close(loadOpen);
|
||||
layer.msg("操作成功!",{icon:1,time:3000,shade: [0.3, '#000']});
|
||||
},'json');
|
||||
});
|
||||
}
|
||||
|
||||
function csvnModPwdUser(name){
|
||||
csvnAddUser(name);
|
||||
}
|
||||
|
||||
function csvnProjectFind(){
|
||||
var search = $('#csvn_project_find').val();
|
||||
if (search == ''){
|
||||
layer.msg('查找字符不能为空!',{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
csvnProjectList(1, search);
|
||||
}
|
||||
|
||||
function csvnProjectList(page, search){
|
||||
var _data = {};
|
||||
_data['page_size'] = 10;
|
||||
if (typeof(search) != 'undefined'){
|
||||
_data['search'] = search;
|
||||
}
|
||||
|
||||
if (typeof(page) != 'undefined'){
|
||||
_data['page'] = page;
|
||||
setCookie('csvnProjectListPage',page);
|
||||
} else {
|
||||
_data['page'] = 1;
|
||||
cookie_page = getCookie('csvnProjectListPage')
|
||||
if (cookie_page >0){
|
||||
_data['page'] = cookie_page;
|
||||
}
|
||||
}
|
||||
|
||||
csvnPost('project_list', _data, function(data){
|
||||
|
||||
var rdata = $.parseJSON($.trim(data.data));
|
||||
var csvn_mg = project_url = 'http://' +rdata['ip'] +(rdata['csvn_port'] == '80' ? '': ':'+rdata['csvn_port']);
|
||||
|
||||
content = '<div><input class="bt-input-text mr5" type="text" placeholder="查找项目" id="csvn_project_find" style="height: 28px; border-radius: 3px;width: 505px;">';
|
||||
content += '<button class="btn btn-success btn-sm" onclick="csvnProjectFind();">查找</button></div>';
|
||||
|
||||
content += '<div class="divtable" style="margin-top:5px;"><table class="table table-hover" width="100%" cellspacing="0" cellpadding="0" border="0">';
|
||||
content += '<thead><tr>';
|
||||
content += '<th>项目名</th>';
|
||||
content += '<th>地址</th>';
|
||||
content += '<th>操作(<a class="btlink" onclick="csvnAddProject();">添加</a>) | <a class="btlink" target="_blank" href="'+csvn_mg+'">后台管理</a> </th>';
|
||||
content += '</tr></thead>';
|
||||
content += '<tbody>';
|
||||
|
||||
// console.log(rdata);
|
||||
ulist = rdata.data;
|
||||
for (i in ulist){
|
||||
var project_url = 'http://' +rdata['ip'] +(rdata['port'] == '80' ? '': ':'+rdata['port'])+ '/svn/'+ulist[i]['name'];
|
||||
var code_url = 'http://' +rdata['ip'] +(rdata['port'] == '80' ? '': ':'+rdata['port'])+ '/viewvc/'+ulist[i]['name'];
|
||||
content += '<tr><td>'+ulist[i]['name']+'</td>'+
|
||||
'<td>'+project_url+'</td><td>'+
|
||||
'<a class="btlink" onclick="csvnDelProject(\''+ulist[i]['name']+'\')">删除</a> | ' +
|
||||
'<a class="btlink" onclick="csvnAclProject(\''+ulist[i]['name']+'\')">权限</a> | ' +
|
||||
'<a class="btlink" target="_blank" href="' + code_url +'">源码</a> | ' +
|
||||
'<a class="btlink" onclick="csvnProjectScript(\''+ulist[i]['name']+'\','+ ulist[i]['has_hook']+')">脚本</a>' +
|
||||
'</td></tr>';
|
||||
}
|
||||
|
||||
content += '</tbody>';
|
||||
content += '</table></div>';
|
||||
|
||||
page = '<div class="dataTables_paginate paging_bootstrap pagination" style="margin-top:0px;"><ul id="softPage" class="page"><div>';
|
||||
page += rdata.list;
|
||||
page += '</div></ul></div>';
|
||||
|
||||
content += page;
|
||||
$(".soft-man-con").html(content);
|
||||
});
|
||||
}
|
||||
|
||||
function csvnDelProject(name){
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '删除用户',
|
||||
area: '350px',
|
||||
content:"<div class='bt-form pd20 pb70 c6'>\
|
||||
<div class='version line'>你要确认要删除"+ name + "账户?</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' id='csvn_del_close' class='btn btn-danger btn-sm btn-title'>关闭</button>\
|
||||
<button type='button' id='csvn_del_ok' class='btn btn-success btn-sm btn-title bi-btn'>确认</button>\
|
||||
</div>\
|
||||
</div>"
|
||||
});
|
||||
|
||||
$('#csvn_del_close').click(function(){
|
||||
layer.close(loadOpen);
|
||||
});
|
||||
|
||||
$('#csvn_del_ok').click(function(){
|
||||
var _data = {};
|
||||
_data['name'] = name;
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'csvn', func:'project_del', args:JSON.stringify(_data)}, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.data !='ok'){
|
||||
layer.msg(data.data,{icon:2,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
csvnProjectList();
|
||||
layer.close(loadOpen);
|
||||
layer.msg("删除成功!",{icon:1,time:3000,shade: [0.3, '#000']});
|
||||
},'json');
|
||||
});
|
||||
}
|
||||
|
||||
function csvnAddProject(){
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '添加项目',
|
||||
area: '240px',
|
||||
content:"<div class='bt-form pd20 pb70 c6'>\
|
||||
<div class='version line'>\
|
||||
<div><input class='bt-input-text mr5 outline_no' type='text' id='csvn_name' name='username' style='height: 28px; border-radius: 3px;width: 200px;' placeholder='输入项目名'></div>\
|
||||
</div>\
|
||||
<div class='bt-form-submit-btn'>\
|
||||
<button type='button' id='csvn_project_close' class='btn btn-danger btn-sm btn-title'>关闭</button>\
|
||||
<button type='button' id='csvn_project_ok' class='btn btn-success btn-sm btn-title bi-btn'>确认</button>\
|
||||
</div>\
|
||||
</div>"
|
||||
});
|
||||
|
||||
$('#csvn_project_close').click(function(){
|
||||
layer.close(loadOpen);
|
||||
});
|
||||
|
||||
$('#csvn_project_ok').click(function(){
|
||||
var _data = {};
|
||||
_data['name'] = $('#csvn_name').val();
|
||||
|
||||
csvnPost('project_add', _data, function(data){
|
||||
|
||||
if (data.data !='ok'){
|
||||
layer.msg(data.data,{icon:2,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
csvnProjectList();
|
||||
layer.close(loadOpen);
|
||||
layer.msg("操作成功!",{icon:1,time:3000,shade: [0.3, '#000']});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function csvnProjectScript(pnanm, has_hook){
|
||||
|
||||
var html = '';
|
||||
if (has_hook){
|
||||
html += '<button onclick="csvnProjectScriptEdit(\''+pnanm+'\')" class="btn btn-default btn-sm">手动编辑</button>';
|
||||
html += '<button onclick="csvnProjectScriptDebug(\''+pnanm+'\')" class="btn btn-default btn-sm">调试日志</button>';
|
||||
html += '<button onclick="csvnProjectScriptLoad(\''+pnanm+'\')" class="btn btn-default btn-sm">重新加载</button>';
|
||||
html += '<button onclick="csvnProjectScriptUnload(\''+pnanm+'\')" class="btn btn-default btn-sm">卸载脚本</button>';
|
||||
} else {
|
||||
html += '<button onclick="csvnProjectScriptLoad(\''+pnanm+'\')" class="btn btn-default btn-sm">加载脚本</button>';
|
||||
}
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '脚本设置',
|
||||
area: '240px',
|
||||
content:'<div class="change-default pd20">'+html+'</div>'
|
||||
});
|
||||
}
|
||||
|
||||
function csvnProjectScriptLoad(pname){
|
||||
csvnPost('project_script_load', {'pname':pname}, function(data){
|
||||
if (data.data != 'ok'){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
layer.msg('加载成功!',{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
setTimeout(function(){
|
||||
$('.layui-layer-close1').click();
|
||||
csvnProjectList();
|
||||
},2000);
|
||||
});
|
||||
}
|
||||
|
||||
function csvnProjectScriptUnload(pname){
|
||||
csvnPost('project_script_unload', {'pname':pname}, function(data){
|
||||
if (data.data != 'ok'){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
layer.msg('卸载成功!',{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
setTimeout(function(){
|
||||
$('.layui-layer-close1').click();
|
||||
csvnProjectList();
|
||||
},2000);
|
||||
});
|
||||
}
|
||||
|
||||
function csvnProjectScriptEdit(pname){
|
||||
csvnPost('project_script_edit', {'pname':pname}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata['status']){
|
||||
onlineEditFile(0, rdata['path']);
|
||||
$('.layui-layer-close1').click();
|
||||
csvnProjectList();
|
||||
} else {
|
||||
layer.msg(rdata.msg,{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function csvnProjectScriptDebug(pname){
|
||||
csvnPost('project_script_debug', {'pname':pname}, function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (rdata['status']){
|
||||
onlineEditFile(0, rdata['path']);
|
||||
$('.layui-layer-close1').click();
|
||||
csvnProjectList();
|
||||
} else {
|
||||
layer.msg(rdata.msg,{icon:1,time:2000,shade: [0.3, '#000']});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function csvnAclAdd(pname){
|
||||
var uname = $('#csvn_username').val();
|
||||
if (uname == ''){
|
||||
layer.msg('添加用户名不能为空!',{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
csvnPost('project_acl_add', {'pname':pname,'uname':uname}, function(data){
|
||||
if (data.data != 'ok'){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
$('.layui-layer-close1').click();
|
||||
csvnAclProject(pname);
|
||||
});
|
||||
}
|
||||
|
||||
function csvnAclDel(pname, uname){
|
||||
csvnPost('project_acl_del', {'pname':pname,'uname':uname}, function(data){
|
||||
if (data.data != 'ok'){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
$('.layui-layer-close1').click();
|
||||
csvnAclProject(pname);
|
||||
});
|
||||
}
|
||||
|
||||
function csvnAclSet(obj, pname, uname, acl, selected){
|
||||
|
||||
if (selected){
|
||||
$(obj).prop('checked',true);
|
||||
layer.msg('权限没有变化!',{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
csvnPost('project_acl_set', {'pname':pname,'uname':uname, 'acl':acl}, function(data){
|
||||
if (data.data != 'ok'){
|
||||
layer.msg(data.data,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
$('.layui-layer-close1').click();
|
||||
csvnAclProject(pname);
|
||||
});
|
||||
}
|
||||
|
||||
function csvnAclProject(pname){
|
||||
csvnPost('project_acl_list', {'name':pname}, function(data){
|
||||
|
||||
var rdata = [];
|
||||
try {
|
||||
rdata = $.parseJSON(data.data);
|
||||
} catch(e){}
|
||||
|
||||
var list = '';
|
||||
for (i in rdata) {
|
||||
var user = rdata[i]['user'];
|
||||
var acl = '';
|
||||
if (rdata[i]['acl'] == 'r'){
|
||||
acl += '<input type="checkbox" onclick="csvnAclSet(this,\''+pname+'\',\''+user+'\',\'r\',true)" checked="true"> 只读 | <input type="checkbox" onclick="csvnAclSet(this,\''+pname+'\',\''+user+'\',\'rw\', false)"> 读写';
|
||||
} else {
|
||||
acl += '<input type="checkbox" onclick="csvnAclSet(this,\''+pname+'\',\''+user+'\',\'r\',false)"> 只读 | <input type="checkbox" onclick="csvnAclSet(this,\''+pname+'\',\''+user+'\',\'rw\',true)" checked="true"> 读写';
|
||||
}
|
||||
|
||||
list += '<tr><td>'+user+'</td><td>' + acl +'</td>'+
|
||||
'<td><a class="btlink" onclick="csvnAclDel(\''+pname+'\',\''+user+'\')">删除</a></td>'+'</tr>';
|
||||
}
|
||||
|
||||
var loadOpen = layer.open({
|
||||
type: 1,
|
||||
title: '项目('+pname+')权限设置',
|
||||
area: '300px',
|
||||
content:"<div class='bt-form pd20 c6'>\
|
||||
<div>\
|
||||
<div><input class='bt-input-text mr5 outline_no' type='text' id='csvn_username' name='username' style='height: 28px; border-radius: 3px;width: 205px;' placeholder='用户名'>\
|
||||
<button class='btn btn-success btn-sm' onclick='csvnAclAdd(\""+pname+"\");'>添加</button></div>\
|
||||
<div class='divtable' style='margin-top:5px;'><table class='table table-hover'><thead><tr><th>用户</th><th>权限</th><th>操作</th></tr></thead>\
|
||||
<tbody>"+list+"</tbody>\
|
||||
</table></div>\
|
||||
</div>\
|
||||
</div>"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,23 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="readme();">插件说明</p>
|
||||
</div>
|
||||
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
|
||||
function readme() {
|
||||
$('.bt-w-main .soft-man-con').hide();
|
||||
$('.bt-w-main .v0').show();
|
||||
}
|
||||
|
||||
//../google-cloud-sdk/bin/gcloud app deploy << y
|
||||
|
||||
</script>
|
||||
@@ -0,0 +1,20 @@
|
||||
# coding: utf-8
|
||||
|
||||
import time
|
||||
import random
|
||||
import os
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
|
||||
|
||||
def status():
|
||||
return 'start'
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
if func == 'status':
|
||||
print status()
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"title":"GAE",
|
||||
"tip":"soft",
|
||||
"name":"gae",
|
||||
"ps":"GAE 英文全称为 Google App Engine。它是 Google 管理的数据中心中用于 WEB 应用程序的开发和托管的平台",
|
||||
"versions": "0.1",
|
||||
"shell":"install.sh",
|
||||
"checks":"server/gae",
|
||||
"path":"server/gae",
|
||||
"author":"mdserver-web",
|
||||
"home":"https://github.com/midoks/mdserver-web",
|
||||
"date":"2018-11-30",
|
||||
"pid":"5"
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/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/bt_install.pl
|
||||
|
||||
Install_gae()
|
||||
{
|
||||
mkdir -p ${serverPath}/gae
|
||||
mkdir -p ${serverPath}/source/gae
|
||||
|
||||
os=`uname`
|
||||
if [ "Darwin" == "$os" ];then
|
||||
file=google-cloud-sdk-218.0.0-darwin-x86_64.tar.gz
|
||||
else
|
||||
file=google-cloud-sdk-218.0.0-linux-x86_64.tar.gz
|
||||
fi
|
||||
|
||||
if [ ! -f $serverPath/source/gae/$file ];then
|
||||
wget -O $serverPath/source/gae/$file https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/$file
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/source/gae/google-cloud-sdk ];then
|
||||
cd $serverPath/source/gae && tar zxvf $file
|
||||
fi
|
||||
|
||||
cp -r $serverPath/source/gae/google-cloud-sdk ${serverPath}/gae
|
||||
|
||||
|
||||
|
||||
echo "${1}" > ${serverPath}/gae/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_gae()
|
||||
{
|
||||
rm -rf ${serverPath}/gae
|
||||
echo '卸载完成' > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_gae $2
|
||||
else
|
||||
Uninstall_gae $2
|
||||
fi
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
@@ -0,0 +1,17 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('gogs');">服务</p>
|
||||
<p onclick="pluginInitD('gogs');">自启动</p>
|
||||
<p onclick="pluginConfig('gogs',null, 'init_conf');">自启动配置</p>
|
||||
<p onclick="pluginConfig('gogs',null, 'conf');">运行配置</p>
|
||||
<p onclick="pluginLogs('gogs',null,'run_log');">运行日志</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
pluginService('gogs');
|
||||
</script>
|
||||
@@ -0,0 +1,192 @@
|
||||
# coding: utf-8
|
||||
|
||||
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append("/usr/local/lib/python2.7/site-packages")
|
||||
import psutil
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
|
||||
|
||||
app_debug = False
|
||||
if public.getOs() == 'darwin':
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'gogs'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
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 getInitdConf():
|
||||
path = getPluginDir() + "/init.d/gogs.tpl"
|
||||
return path
|
||||
|
||||
|
||||
def getConf():
|
||||
path = getServerDir() + "/custom/conf/app.ini"
|
||||
return path
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
"ps -ef|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def initDreplace():
|
||||
|
||||
file_tpl = getInitdConf()
|
||||
service_path = public.getServerDir()
|
||||
|
||||
initD_path = getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
os.mkdir(initD_path)
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
|
||||
content = public.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
|
||||
log_path = getServerDir() + '/log'
|
||||
if not os.path.exists(log_path):
|
||||
os.mkdir(log_path)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def start():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mem_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(mem_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def runLog():
|
||||
log_path = getServerDir() + '/log/gogs.log'
|
||||
return log_path
|
||||
|
||||
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_log':
|
||||
print runLog()
|
||||
elif func == 'conf':
|
||||
print getConf()
|
||||
elif func == 'init_conf':
|
||||
print getInitdConf()
|
||||
else:
|
||||
print 'fail'
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"ps": "Gogs是一款极易搭建的自助Git服务",
|
||||
"name": "gogs",
|
||||
"title": "Gogs",
|
||||
"versions": ["0.11.79","0.11.66"],
|
||||
"tip": "soft",
|
||||
"checks": "server/gogs",
|
||||
"author": "midoks",
|
||||
"date": "201-04-01",
|
||||
"home": "https://gogs.io",
|
||||
"type": "git服务器",
|
||||
"shell": "install.sh",
|
||||
"pid": "3",
|
||||
"sort": 7
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# /etc/rc.d/init.d/gogs
|
||||
#
|
||||
# Runs the Gogs
|
||||
#
|
||||
#
|
||||
# chkconfig: - 85 15
|
||||
#
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: gogs
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Should-Start: mysql postgresql
|
||||
# Should-Stop: mysql postgresql
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Start gogs at boot time.
|
||||
# Description: Control gogs.
|
||||
### END INIT INFO
|
||||
|
||||
# Source function library.
|
||||
if [ -f /etc/init.d/functions ];then
|
||||
. /etc/init.d/functions
|
||||
fi
|
||||
|
||||
# Default values
|
||||
|
||||
NAME=gogs
|
||||
GOGS_HOME={$SERVER_PATH}/gogs
|
||||
GOGS_PATH=${GOGS_HOME}/$NAME
|
||||
GOGS_USER=midoks
|
||||
SERVICENAME="Gogs"
|
||||
LOCKFILE=/tmp/gogs.lock
|
||||
LOGPATH=${GOGS_HOME}/log
|
||||
LOGFILE=${LOGPATH}/gogs.log
|
||||
RETVAL=0
|
||||
|
||||
|
||||
status(){
|
||||
isStart=`ps -ef|grep 'gogs web' |grep -v grep|awk '{print $2}'`
|
||||
if [ "$isStart" == '' ];then
|
||||
echo "${SERVICENAME} not running"
|
||||
else
|
||||
echo "${SERVICENAME}(pid $(echo $isStart)) already running"
|
||||
fi
|
||||
}
|
||||
|
||||
start() {
|
||||
isStart=`ps -ef|grep 'gogs web' |grep -v grep|awk '{print $2}'`
|
||||
if [ "$isStart" != '' ];then
|
||||
echo "${SERVICENAME}(pid $(echo $isStart)) already running"
|
||||
return $RETVAL
|
||||
fi
|
||||
|
||||
cd ${GOGS_HOME}
|
||||
echo "Starting ${SERVICENAME}: \c"
|
||||
${GOGS_PATH} web > ${LOGFILE} 2>&1 &
|
||||
RETVAL=$?
|
||||
[ $RETVAL = 0 ] && touch ${LOCKFILE} && echo "\033[32mdone\033[0m"
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
stop() {
|
||||
cd ${GOGS_HOME}
|
||||
echo "Shutting down ${SERVICENAME}: \c"
|
||||
pkill ${NAME}
|
||||
RETVAL=$?
|
||||
[ $RETVAL = 0 ] && rm -f ${LOCKFILE} && echo "\033[32mdone\033[0m"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
status)
|
||||
status
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
reload)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: ${NAME} {start|stop|status|restart}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
exit $RETVAL
|
||||
@@ -0,0 +1,67 @@
|
||||
#!/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/bt_install.pl
|
||||
|
||||
|
||||
GOGS_DOWNLOAD='https://dl.gogs.io'
|
||||
|
||||
getOs(){
|
||||
os=`uname`
|
||||
if [ "Darwin" == "$os" ];then
|
||||
echo 'darwin'
|
||||
else
|
||||
echo 'linux'
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
getBit(){
|
||||
echo `getconf LONG_BIT`
|
||||
}
|
||||
|
||||
|
||||
Install_gogs()
|
||||
{
|
||||
mkdir -p $serverPath/source/gogs
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
version=$1
|
||||
os=`getOs`
|
||||
|
||||
if [ "darwin" == "$os" ];then
|
||||
file=gogs_${version}_darwin_amd64.zip
|
||||
else
|
||||
file=gogs_${version}_linux_amd64.zip
|
||||
fi
|
||||
|
||||
if [ ! -f $serverPath/source/gogs/$file ];then
|
||||
wget -O $serverPath/source/gogs/$file ${GOGS_DOWNLOAD}/${version}/${file}
|
||||
fi
|
||||
|
||||
cd $serverPath/source/gogs && unzip -o $file -d gogs_${version}
|
||||
mv $serverPath/source/gogs/gogs_${version}/gogs/ $serverPath/gogs
|
||||
echo $version > $serverPath/gogs/version.pl
|
||||
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_gogs()
|
||||
{
|
||||
rm -rf $serverPath/gogs
|
||||
}
|
||||
|
||||
|
||||
action=$1
|
||||
version=$2
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_gogs $version
|
||||
else
|
||||
Uninstall_gogs $version
|
||||
fi
|
||||
@@ -1,11 +1,11 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="redisService();">服务</p>
|
||||
<p onclick="redisConfig();">配置修改</p>
|
||||
<p onclick="redisConfig();">切换版本</p>
|
||||
<p onclick="redisStatus();">负载状态</p>
|
||||
<p onclick="redisStatus();">性能调整</p>
|
||||
<p class="bgw" onclick="pluginService('memcached');">服务</p>
|
||||
<p onclick="pluginInitD('memcached');">自启动</p>
|
||||
<p onclick="pluginConfig('memcached');">配置修改</p>
|
||||
<p onclick="memcachedStatus();">负载状态</p>
|
||||
<p onclick="memcachedCache();">性能调整</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
@@ -14,5 +14,6 @@
|
||||
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
pluginService('memcached');
|
||||
$.getScript( "/plugins/file?name=memcached&f=js/mem.js");
|
||||
</script>
|
||||
@@ -8,83 +8,200 @@ import time
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
|
||||
app_debug = False
|
||||
if public.getOs() == 'darwin':
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'memcached'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getConf():
|
||||
path = getPluginDir() + "/init.d/memcached.tpl"
|
||||
return path
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
return tmp
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
"ps -ef|grep redis |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
"ps -ef|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def initDreplace():
|
||||
|
||||
file_tpl = getConf()
|
||||
service_path = public.getServerDir()
|
||||
|
||||
initD_path = getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
os.mkdir(initD_path)
|
||||
file_bin = initD_path + '/memcached'
|
||||
|
||||
# if os.path.exists(file_bin):
|
||||
# return file_bin
|
||||
|
||||
content = public.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
return file_bin
|
||||
|
||||
|
||||
def start():
|
||||
path = os.path.dirname(os.getcwd())
|
||||
cmd = path + "/redis/bin/redis-server"
|
||||
cmd = cmd + " " + path + "/redis/redis.conf"
|
||||
data = public.execShell(cmd)
|
||||
if data[0] == '':
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def stop():
|
||||
data = public.execShell(
|
||||
"ps -ef|grep redis |grep -v grep |grep -v python |awk '{print $2}' | xargs kill -9")
|
||||
if data[0] == '':
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def restart():
|
||||
return 'ok'
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def reload():
|
||||
return 'ok'
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def runInfo():
|
||||
path = os.path.dirname(os.getcwd())
|
||||
cmd = path + "/redis/bin/redis-cli info"
|
||||
data = public.execShell(cmd)[0]
|
||||
res = [
|
||||
'tcp_port',
|
||||
'uptime_in_days', # 已运行天数
|
||||
'connected_clients', # 连接的客户端数量
|
||||
'used_memory', # Redis已分配的内存总量
|
||||
'used_memory_rss', # Redis占用的系统内存总量
|
||||
'used_memory_peak', # Redis所用内存的高峰值
|
||||
'mem_fragmentation_ratio', # 内存碎片比率
|
||||
'total_connections_received', # 运行以来连接过的客户端的总数量
|
||||
'total_commands_processed', # 运行以来执行过的命令的总数量
|
||||
'instantaneous_ops_per_sec', # 服务器每秒钟执行的命令数量
|
||||
'keyspace_hits', # 查找数据库键成功的次数
|
||||
'keyspace_misses', # 查找数据库键失败的次数
|
||||
'latest_fork_usec' # 最近一次 fork() 操作耗费的毫秒数
|
||||
]
|
||||
data = data.split("\n")
|
||||
result = {}
|
||||
for d in data:
|
||||
if len(d) < 3:
|
||||
continue
|
||||
t = d.strip().split(':')
|
||||
if not t[0] in res:
|
||||
continue
|
||||
result[t[0]] = t[1]
|
||||
return public.getJson(result)
|
||||
# 获取memcached状态
|
||||
import telnetlib
|
||||
import re
|
||||
|
||||
try:
|
||||
tn = telnetlib.Telnet('127.0.0.1', 11211)
|
||||
tn.write(b"stats\n")
|
||||
tn.write(b"quit\n")
|
||||
data = tn.read_all()
|
||||
if type(data) == bytes:
|
||||
data = data.decode('utf-8')
|
||||
data = data.replace('STAT', '').replace('END', '').split("\n")
|
||||
result = {}
|
||||
res = ['cmd_get', 'get_hits', 'get_misses', 'limit_maxbytes', 'curr_items', 'bytes',
|
||||
'evictions', 'limit_maxbytes', 'bytes_written', 'bytes_read', 'curr_connections']
|
||||
for d in data:
|
||||
if len(d) < 3:
|
||||
continue
|
||||
t = d.split()
|
||||
if not t[0] in res:
|
||||
continue
|
||||
result[t[0]] = int(t[1])
|
||||
result['hit'] = 1
|
||||
if result['get_hits'] > 0 and result['cmd_get'] > 0:
|
||||
result['hit'] = float(result['get_hits']) / \
|
||||
float(result['cmd_get']) * 100
|
||||
|
||||
conf = public.readFile(getConf())
|
||||
result['bind'] = re.search('IP=(.+)', conf).groups()[0]
|
||||
result['port'] = int(re.search('PORT=(\d+)', conf).groups()[0])
|
||||
result['maxconn'] = int(re.search('MAXCONN=(\d+)', conf).groups()[0])
|
||||
result['cachesize'] = int(
|
||||
re.search('CACHESIZE=(\d+)', conf).groups()[0])
|
||||
return public.getJson(result)
|
||||
except Exception, e:
|
||||
return public.getJson({})
|
||||
|
||||
|
||||
def getConf():
|
||||
path = os.path.dirname(os.getcwd()) + "/redis/redis.conf"
|
||||
return path
|
||||
def saveConf():
|
||||
# 设置memcached缓存大小
|
||||
import re
|
||||
confFile = getConf()
|
||||
try:
|
||||
args = getArgs()
|
||||
content = public.readFile(confFile)
|
||||
content = re.sub('IP=.+', 'IP=' + args['ip'], content)
|
||||
content = re.sub('PORT=\d+', 'PORT=' + args['port'], content)
|
||||
content = re.sub('MAXCONN=\d+', 'MAXCONN=' + args['maxconn'], content)
|
||||
content = re.sub('CACHESIZE=\d+', 'CACHESIZE=' +
|
||||
args['cachesize'], content)
|
||||
public.writeFile(confFile, content)
|
||||
reload()
|
||||
return 'ok'
|
||||
except Exception as e:
|
||||
pass
|
||||
return 'fail'
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mem_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(mem_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
return 'ok'
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
if func == 'run_info':
|
||||
print runInfo()
|
||||
elif func == 'conf':
|
||||
print getConf()
|
||||
elif func == 'status':
|
||||
if func == 'status':
|
||||
print status()
|
||||
elif func == 'start':
|
||||
print start()
|
||||
@@ -94,3 +211,17 @@ if __name__ == "__main__":
|
||||
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 == 'save_conf':
|
||||
print saveConf()
|
||||
else:
|
||||
print 'fail'
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
#! /bin/bash
|
||||
#
|
||||
# memcached: MemCached Daemon
|
||||
#
|
||||
# chkconfig: - 90 25
|
||||
# description: MemCached Daemon
|
||||
#
|
||||
### BEGIN INIT INFO
|
||||
# Provides: memcached
|
||||
# Required-Start: $syslog
|
||||
# Required-Stop: $syslog
|
||||
# Should-Start: $local_fs
|
||||
# Should-Stop: $local_fs
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: memcached - Memory caching daemon
|
||||
# Description: memcached - Memory caching daemon
|
||||
### END INIT INFO
|
||||
|
||||
IP=127.0.0.1
|
||||
PORT=11211
|
||||
USER=root
|
||||
MAXCONN=1024
|
||||
CACHESIZE=64
|
||||
OPTIONS=""
|
||||
|
||||
RETVAL=0
|
||||
prog="memcached"
|
||||
|
||||
MEM_PATH={$SERVER_PATH}/memcached
|
||||
|
||||
start () {
|
||||
echo -n $"Starting $prog: "
|
||||
$MEM_PATH/bin/memcached -d -l $IP -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P $MEM_PATH/memcached.pid $OPTIONS
|
||||
if [ "$?" != 0 ] ; then
|
||||
echo " failed"
|
||||
exit 1
|
||||
else
|
||||
echo " done"
|
||||
fi
|
||||
}
|
||||
stop () {
|
||||
echo -n $"Stopping $prog: "
|
||||
if [ ! -e $MEM_PATH/$prog.pid ]; then
|
||||
echo -n $"$prog is not running."
|
||||
exit 1
|
||||
fi
|
||||
kill `cat $MEM_PATH/memcached.pid`
|
||||
if [ "$?" != 0 ] ; then
|
||||
echo " failed"
|
||||
exit 1
|
||||
else
|
||||
rm -f ${MEM_PATH}/memcached.pid
|
||||
echo " done"
|
||||
fi
|
||||
}
|
||||
|
||||
restart () {
|
||||
$0 stop
|
||||
sleep 2
|
||||
$0 start
|
||||
}
|
||||
|
||||
# See how we were called.
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart|reload)
|
||||
restart
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|status|restart|reload}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit $?
|
||||
@@ -13,23 +13,28 @@ install_tmp=${rootPath}/tmp/bt_install.pl
|
||||
|
||||
Install_mem()
|
||||
{
|
||||
mkdir -p $serverPath/tmp
|
||||
mkdir -p $serverPath/source
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
wget -O $serverPath/tmp/memcached.tar.gz http://www.memcached.org/files/memcached-1.5.12.tar.gz
|
||||
cd $serverPath/tmp && tar -zxvf memcached.tar.gz
|
||||
if [ ! -f $serverPath/source/memcached.tar.gz ];then
|
||||
wget -O $serverPath/source/memcached.tar.gz http://www.memcached.org/files/memcached-1.5.12.tar.gz
|
||||
if
|
||||
|
||||
cd $serverPath/source && tar -zxvf memcached.tar.gz
|
||||
|
||||
mkdir -p $serverPath/memcached
|
||||
cd memcached* && ./configure --prefix=$serverPath/memcached && make && make install
|
||||
|
||||
echo '1.5' > $serverPath/memcached/version.pl
|
||||
|
||||
echo '安装完成' > $install_tmp
|
||||
|
||||
#rm -rf $serverPath/tmp
|
||||
}
|
||||
|
||||
Uninstall_mem()
|
||||
{
|
||||
$serverPath/memcached/init.d/memcached stop
|
||||
rm -rf mkdir -p $serverPath/memcached
|
||||
}
|
||||
|
||||
|
||||
@@ -1,188 +1,22 @@
|
||||
function redisOp(a, b) {
|
||||
|
||||
var c = "name=" + a + "&func=" + b;
|
||||
var d = "";
|
||||
|
||||
switch(b) {
|
||||
case "stop":
|
||||
d = '停止';
|
||||
break;
|
||||
case "start":
|
||||
d = '启动';
|
||||
break;
|
||||
case "restart":
|
||||
d = '重启';
|
||||
break;
|
||||
case "reload":
|
||||
d = '重载';
|
||||
break
|
||||
}
|
||||
layer.confirm( '您真的要{1}{2}服务吗?'.replace('{1}', d).replace('{2}', a), {icon:3,closeBtn: 2}, function() {
|
||||
var e = layer.msg('正在{1}{2}服务,请稍候...'.replace('{1}', d).replace('{2}', a), {icon: 16,time: 0});
|
||||
$.post("/plugins/run", c, function(g) {
|
||||
layer.close(e);
|
||||
|
||||
var f = g.data == 'ok' ? '{1}服务已{2}'.replace('{1}', a).replace('{2}', d):'{1}服务{2}失败!'.replace('{1}', a).replace('{2}', d);
|
||||
layer.msg(f, {icon: g.data == 'ok' ? 1 : 2});
|
||||
|
||||
if(b != "reload" && g.data == 'ok') {
|
||||
if (b == 'start') {
|
||||
setRedisService('redis', true);
|
||||
} else if (b=='stop'){
|
||||
setRedisService('redis', false);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
if(g.data != 'ok') {
|
||||
layer.msg(g.data, {icon: 2,time: 0,shade: 0.3,shadeClose: true});
|
||||
}
|
||||
},'json').error(function() {
|
||||
layer.close(e);
|
||||
layer.msg('操作成功!', {icon: 1});
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
//服务
|
||||
function setRedisService(name, status){
|
||||
var serviceCon ='<p class="status">当前状态:<span>'+(status ? '开启' : '关闭' )+
|
||||
'</span><span style="color: '+
|
||||
(status?'#20a53a;':'red;')+
|
||||
' margin-left: 3px;" class="glyphicon ' + (status?'glyphicon glyphicon-play':'glyphicon-pause')+'"></span></p><div class="sfm-opt">\
|
||||
<button class="btn btn-default btn-sm" onclick="redisOp(\''+name+'\',\''+(status?'stop':'start')+'\')">'+(status?'停止':'启动')+'</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="redisOp(\''+name+'\',\'restart\')">重启</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="redisOp(\''+name+'\',\'reload\')">重载配置</button>\
|
||||
</div>';
|
||||
$(".soft-man-con").html(serviceCon);
|
||||
}
|
||||
|
||||
|
||||
//服务
|
||||
function redisService(){
|
||||
|
||||
$.post('/plugins/run', {name:'redis', func:'status'}, function(data) {
|
||||
console.log(data);
|
||||
if(!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:3000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
if (data.data == 'start'){
|
||||
setRedisService('redis', true);
|
||||
} else {
|
||||
setRedisService('redis', false);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
redisService();
|
||||
|
||||
|
||||
//配置修改 --- start
|
||||
function redisConfig(type){
|
||||
|
||||
var con = '<p style="color: #666; margin-bottom: 7px">提示:Ctrl+F 搜索关键字,Ctrl+G 查找下一个,Ctrl+S 保存,Ctrl+Shift+R 查找替换!</p><textarea class="bt-input-text" style="height: 320px; line-height:18px;" id="textBody"></textarea>\
|
||||
<button id="OnlineEditFileBtn" class="btn btn-success btn-sm" style="margin-top:10px;">保存</button>\
|
||||
<ul class="help-info-text c7 ptb15">\
|
||||
<li>此处为redis主配置文件,若您不了解配置规则,请勿随意修改。</li>\
|
||||
</ul>';
|
||||
$(".soft-man-con").html(con);
|
||||
|
||||
var loadT = layer.msg('配置文件路径获取中...',{icon:16,time:0,shade: [0.3, '#000']});
|
||||
$.post('/plugins/run', {name:'redis', func:'conf'},function (data) {
|
||||
layer.close(loadT);
|
||||
|
||||
var loadT2 = layer.msg('文件内容获取中...',{icon:16,time:0,shade: [0.3, '#000']});
|
||||
var fileName = data.data;
|
||||
$.post('/files/get_body', 'path=' + fileName, function(rdata) {
|
||||
layer.close(loadT2);
|
||||
if (!rdata.status){
|
||||
layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
$("#textBody").empty().text(rdata.data.data);
|
||||
$(".CodeMirror").remove();
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("textBody"), {
|
||||
extraKeys: {
|
||||
"Ctrl-Space": "autocomplete",
|
||||
"Ctrl-F": "findPersistent",
|
||||
"Ctrl-H": "replaceAll",
|
||||
"Ctrl-S": function() {
|
||||
redisConfSafe(fileName);
|
||||
}
|
||||
},
|
||||
lineNumbers: true,
|
||||
matchBrackets:true,
|
||||
});
|
||||
editor.focus();
|
||||
$(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0});
|
||||
$("#OnlineEditFileBtn").click(function(){
|
||||
$("#textBody").text(editor.getValue());
|
||||
redisConfSafe(fileName);
|
||||
});
|
||||
},'json');
|
||||
},'json');
|
||||
}
|
||||
|
||||
//配置保存
|
||||
function redisConfSafe(fileName) {
|
||||
var data = encodeURIComponent($("#textBody").val());
|
||||
var encoding = 'utf-8';
|
||||
var loadT = layer.msg('保存中...', {
|
||||
icon: 16,
|
||||
time: 0
|
||||
});
|
||||
$.post('/files/save_body', 'data=' + data + '&path=' + fileName + '&encoding=' + encoding, function(rdata) {
|
||||
layer.close(loadT);
|
||||
layer.msg(rdata.msg, {
|
||||
icon: rdata.status ? 1 : 2
|
||||
});
|
||||
},'json');
|
||||
}
|
||||
//配置修改 --- end
|
||||
|
||||
//redis负载状态 start
|
||||
function redisStatus() {
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'redis', func:'run_info'}, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
var rdata = $.parseJSON(data.data);
|
||||
hit = (parseInt(rdata.keyspace_hits) / (parseInt(rdata.keyspace_hits) + parseInt(rdata.keyspace_misses)) * 100).toFixed(2);
|
||||
var Con = '<div class="divtable">\
|
||||
<table class="table table-hover table-bordered" style="width: 490px;">\
|
||||
<thead><th>字段</th><th>当前值</th><th>说明</th></thead>\
|
||||
<tbody>\
|
||||
<tr><th>uptime_in_days</th><td>' + rdata.uptime_in_days + '</td><td>已运行天数</td></tr>\
|
||||
<tr><th>tcp_port</th><td>' + rdata.tcp_port + '</td><td>当前监听端口</td></tr>\
|
||||
<tr><th>connected_clients</th><td>' + rdata.connected_clients + '</td><td>连接的客户端数量</td></tr>\
|
||||
<tr><th>used_memory_rss</th><td>' + ToSize(rdata.used_memory_rss) + '</td><td>Redis当前占用的系统内存总量</td></tr>\
|
||||
<tr><th>used_memory</th><td>' + ToSize(rdata.used_memory) + '</td><td>Redis当前已分配的内存总量</td></tr>\
|
||||
<tr><th>used_memory_peak</th><td>' + ToSize(rdata.used_memory_peak) + '</td><td>Redis历史分配内存的峰值</td></tr>\
|
||||
<tr><th>mem_fragmentation_ratio</th><td>' + rdata.mem_fragmentation_ratio + '%</td><td>内存碎片比率</td></tr>\
|
||||
<tr><th>total_connections_received</th><td>' + rdata.total_connections_received + '</td><td>运行以来连接过的客户端的总数量</td></tr>\
|
||||
<tr><th>total_commands_processed</th><td>' + rdata.total_commands_processed + '</td><td>运行以来执行过的命令的总数量</td></tr>\
|
||||
<tr><th>instantaneous_ops_per_sec</th><td>' + rdata.instantaneous_ops_per_sec + '</td><td>服务器每秒钟执行的命令数量</td></tr>\
|
||||
<tr><th>keyspace_hits</th><td>' + rdata.keyspace_hits + '</td><td>查找数据库键成功的次数</td></tr>\
|
||||
<tr><th>keyspace_misses</th><td>' + rdata.keyspace_misses + '</td><td>查找数据库键失败的次数</td></tr>\
|
||||
<tr><th>hit</th><td>' + hit + '%</td><td>查找数据库键命中率</td></tr>\
|
||||
<tr><th>latest_fork_usec</th><td>' + rdata.latest_fork_usec + '</td><td>最近一次 fork() 操作耗费的微秒数</td></tr>\
|
||||
<tbody>\
|
||||
</table></div>'
|
||||
$(".soft-man-con").html(Con);
|
||||
},'json');
|
||||
}
|
||||
//redis负载状态 end
|
||||
|
||||
|
||||
//memcached负载状态
|
||||
function MemcachedStatus() {
|
||||
function memcachedStatus() {
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.get('/ajax?action=GetMemcachedStatus', function(rdata) {
|
||||
layer.close(loadT);
|
||||
$.post('/plugins/run', {name:'memcached', func:'run_info'}, function(data) {
|
||||
layer.close(loadT);
|
||||
|
||||
if (!data.status){
|
||||
showMsg(data.msg, function(){}, null,13000);
|
||||
return;
|
||||
}
|
||||
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if ($.isEmptyObject(rdata)){
|
||||
showMsg('memcached服务没有启动!', function(){}, undefined, 3000);
|
||||
return;
|
||||
}
|
||||
var Con = '<div class="divtable">\
|
||||
<table class="table table-hover table-bordered" style="width: 490px;">\
|
||||
<thead><th>字段</th><th>当前值</th><th>说明</th></thead>\
|
||||
@@ -198,33 +32,45 @@ function MemcachedStatus() {
|
||||
<tr><th>hit</th><td>' + rdata.hit.toFixed(2) + '%</td><td>GET命中率</td></tr>\
|
||||
<tr><th>curr_items</th><td>' + rdata.curr_items + '</td><td>当前被缓存的数据行数</td></tr>\
|
||||
<tr><th>evictions</th><td>' + rdata.evictions + '</td><td>因内存不足而被清理的缓存行数</td></tr>\
|
||||
<tr><th>bytes</th><td>' + ToSize(rdata.bytes) + '</td><td>当前已使用内存</td></tr>\
|
||||
<tr><th>bytes_read</th><td>' + ToSize(rdata.bytes_read) + '</td><td>请求总大小</td></tr>\
|
||||
<tr><th>bytes_written</th><td>' + ToSize(rdata.bytes_written) + '</td><td>发送总大小</td></tr>\
|
||||
<tr><th>bytes</th><td>' + toSize(rdata.bytes) + '</td><td>当前已使用内存</td></tr>\
|
||||
<tr><th>bytes_read</th><td>' + toSize(rdata.bytes_read) + '</td><td>请求总大小</td></tr>\
|
||||
<tr><th>bytes_written</th><td>' + toSize(rdata.bytes_written) + '</td><td>发送总大小</td></tr>\
|
||||
<tbody>\
|
||||
</table></div>'
|
||||
$(".soft-man-con").html(Con);
|
||||
});
|
||||
},'json');
|
||||
}
|
||||
|
||||
//memcached性能调整
|
||||
function MemcachedCache() {
|
||||
function memcachedCache() {
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.get('/ajax?action=GetMemcachedStatus', function(rdata) {
|
||||
$.post('/plugins/run', {name:'memcached', func:'run_info'}, function(data) {
|
||||
layer.close(loadT);
|
||||
|
||||
if (!data.status){
|
||||
showMsg(data.msg, function(){}, null,13000);
|
||||
return;
|
||||
}
|
||||
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if ($.isEmptyObject(rdata)){
|
||||
showMsg('memcached服务没有启动!', function(){}, undefined, 3000);
|
||||
return;
|
||||
}
|
||||
|
||||
var memCon = '<div class="conf_p" style="margin-bottom:0">\
|
||||
<p><span>BindIP</span><input style="width: 120px;" class="bt-input-text mr5" name="membind" value="' + rdata.bind + '" type="text" ><font>监听IP,请勿随意修改</font></p>\
|
||||
<p><span>PORT</span><input style="width: 120px;" class="bt-input-text mr5" max="65535" name="memport" value="' + rdata.port + '" type="number" ><font>监听端口,一般无需修改</font></p>\
|
||||
<p><span>CACHESIZE</span><input style="width: 120px;" class="bt-input-text mr5" name="memcachesize" value="' + rdata.cachesize + '" type="number" >MB,<font>缓存大小,建议不要大于512M</font></p>\
|
||||
<p><span>MAXCONN</span><input style="width: 120px;" class="bt-input-text mr5" name="memmaxconn" value="' + rdata.maxconn + '" type="number" ><font>最大连接数,建议不要大于40960</font></p>\
|
||||
<div style="margin-top:10px; padding-right:230px" class="text-right"><button class="btn btn-success btn-sm" onclick="SetMemcachedConf()">' + lan.public.save + '</button></div>\
|
||||
<div style="margin-top:10px; padding-right:230px" class="text-right"><button class="btn btn-success btn-sm" onclick="setMemcachedConf()">保存</button></div>\
|
||||
</div>'
|
||||
$(".soft-man-con").html(memCon);
|
||||
});
|
||||
},'json');
|
||||
}
|
||||
|
||||
//memcached提交配置
|
||||
function SetMemcachedConf() {
|
||||
function setMemcachedConf() {
|
||||
var data = {
|
||||
ip: $("input[name='membind']").val(),
|
||||
port: $("input[name='memport']").val(),
|
||||
@@ -251,9 +97,10 @@ function SetMemcachedConf() {
|
||||
layer.msg('最大连接数过小', { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
var loadT = layer.msg('正在保存...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/ajax?action=SetMemcachedCache', data, function(rdata) {
|
||||
$.post('/plugins/run', {name:'memcached', func:'save_conf',args:JSON.stringify(data) }, function(rdata) {
|
||||
layer.close(loadT);
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
});
|
||||
},'json');
|
||||
}
|
||||
@@ -1,550 +1,16 @@
|
||||
<style>
|
||||
|
||||
|
||||
/*危险按钮*/
|
||||
.bts-danger:hover{
|
||||
color: #fff;
|
||||
background-color: #c9302c;
|
||||
border-color: #ac2925;
|
||||
}
|
||||
#whiteList a{
|
||||
color: red;
|
||||
}
|
||||
|
||||
/*弹窗*/
|
||||
.Add_view{
|
||||
height: 100px;
|
||||
padding-left: 35px;
|
||||
padding-top: 35px;
|
||||
}
|
||||
.Add_view label{
|
||||
margin-right: 10px;
|
||||
font-size: 15px;
|
||||
font-weight: 100;
|
||||
}
|
||||
.Add_view input{
|
||||
width: 230px;
|
||||
}
|
||||
.Add_view .error{
|
||||
border: 1px solid red;
|
||||
}
|
||||
.Add_view .correct{
|
||||
border: 1px solid #20a53a;
|
||||
}
|
||||
|
||||
/*日志管理*/
|
||||
.btnTitle{
|
||||
font-weight: 100;
|
||||
font-size: 16px;
|
||||
line-height: 34px;
|
||||
height: 34px;
|
||||
margin-right: 15px;
|
||||
position: relative;
|
||||
top: 2px;
|
||||
}
|
||||
.whiteList-table{
|
||||
margin-top: 10px;
|
||||
}
|
||||
/*登录日志表单*/
|
||||
.viewTwo .whiteList-table{
|
||||
overflow-x: hidden;
|
||||
height: 500px;
|
||||
}
|
||||
.maks{
|
||||
background: rgba(39, 39, 39, 0.4);
|
||||
position: absolute;
|
||||
width: 700px;
|
||||
height: 555px;
|
||||
z-index: 999;
|
||||
overflow: hidden;
|
||||
}
|
||||
.boxshow{
|
||||
position: absolute;
|
||||
height: 150px;
|
||||
width: 400px;
|
||||
margin-left: -200px;
|
||||
margin-top: -75px;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
z-index: 1000;
|
||||
background: #fff;
|
||||
padding: 25px 20px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.btPayment {
|
||||
float: left;
|
||||
padding: 8px 10px;
|
||||
width: 190px;
|
||||
height: 100px;
|
||||
line-height: 33px;
|
||||
text-align: center;
|
||||
border-left: 1px solid #ececec;
|
||||
}
|
||||
.btPayment .t2{
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.btPayment .price{
|
||||
color: #20A53A;
|
||||
font-size: 22px;
|
||||
margin: 0 5px;
|
||||
|
||||
}
|
||||
.bt-form{
|
||||
overflow: hidden;
|
||||
}
|
||||
.boxtext{
|
||||
line-height: 32px;
|
||||
margin-top: -17px;
|
||||
text-align: center;
|
||||
border-bottom: #eee 1px solid;
|
||||
height: 39px;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
<div class="maks" style="display: none"></div>
|
||||
<div class="boxshow" style="display: none;">
|
||||
<div>
|
||||
<div class="boxtext">
|
||||
<span>未开通此服务,如需使用请开通企业运维版。</span>
|
||||
</div>
|
||||
<div class="btvipinfo" style="width: 170px;padding-left: 20px">
|
||||
<p style="height: 25px">1、一对一运维人员对接</p>
|
||||
<p style="height: 25px">2、提供每月3次运维服务</p>
|
||||
<p style="height: 25px">3、双重安全隔离登录</p>
|
||||
</div>
|
||||
<div class="btPayment">
|
||||
<span class="t2">企业运维版<span class="price">98</span>元/月</span>
|
||||
<button class="btn btn-success btn-sm" style="width:80%" onclick="window.open('https://www.bt.cn/admin/index.html')">立即开通</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw">密钥</p>
|
||||
<p>面板设置</p>
|
||||
<p>面板登录日志</p>
|
||||
<p>SSH设置</p>
|
||||
<p>SSH日志管理</p>
|
||||
<p class="bgw" onclick="pluginService('mysql');">服务</p>
|
||||
<p onclick="indexPy();">自启动</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con viewZoo">
|
||||
<p class="status" style="margin-top:10px;margin-left:10px;height: 80px;margin-bottom:15px;">
|
||||
<span style="float:left;margin-top:-5px">密钥:</span>
|
||||
<textarea class="bt-input-text" name="token" readonly="readonly" style="background-color: #eee;width:400px;height:80px;padding: 8px 15px;" placeholder="密钥已隐藏..."></textarea>
|
||||
</p>
|
||||
<input type="button" class="btn btn-success btn-sm" name="ButtonShow" style="margin-left:52px;width:100px" onclick="sagelogin.tokenShow()" value="显示密钥" />
|
||||
<ul style="margin: 15px 5px;padding-left: 70px;list-style-type: disc;line-height: 25px;">
|
||||
<li>宝塔企业运维后台连接您的服务器需要此密钥,请妥善记录并保存</li>
|
||||
<li>一但密钥丢失,可能导致您无法登录服务器</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="soft-man-con viewOne" style="display: none;">
|
||||
<p class="status">当前状态:
|
||||
<span>开启</span>
|
||||
<span style="color: #20a53a; margin-left: 3px;" class="glyphicon glyphicon glyphicon-play"></span>
|
||||
<span style="color: red; margin-left: 3px; display: none" class="glyphicon glyphicon-pause"></span>
|
||||
</p>
|
||||
<div class="sfm-opt">
|
||||
<button class="btn btn-default btn-sm bts-danger" onclick="sagelogin.Panel_Admin()">清除面板登录限制IP</button>
|
||||
<button class="btn btn-default btn-sm bts-safety" onclick="sagelogin.Add_view('面板白名单',true)">添加白名单</button>
|
||||
</div>
|
||||
<div class="whiteList-table divtable" style="overflow-x: hidden;height: 420px">
|
||||
<table class="table table-hover" style="max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>IP地址</th>
|
||||
<th style="text-align: right;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListOne"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="soft-man-con viewTwo" style="display: none">
|
||||
<div class="whiteList-table divtable">
|
||||
<table class="table table-hover" style=" max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>操作记录</th>
|
||||
<th>操作时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListTwo"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="soft-man-con viewThree" style="display: none">
|
||||
<p class="status">当前状态:
|
||||
<span>开启</span>
|
||||
<span style="color: #20a53a; margin-left: 3px;" class="glyphicon glyphicon glyphicon-play">
|
||||
</span>
|
||||
<span style="color: red; margin-left: 3px; display: none" class="glyphicon glyphicon-pause"></span>
|
||||
</p>
|
||||
<div class="sfm-opt">
|
||||
<button class="btn btn-default btn-sm bts-danger" onclick="sagelogin.Panel_Admin()">清除SSH登录限制IP</button>
|
||||
<button class="btn btn-default btn-sm bts-safety" onclick="sagelogin.Add_view('SSH白名单',false)">添加白名单</button>
|
||||
</div>
|
||||
<div class="whiteList-table divtable" style="overflow-x: hidden;height: 420px">
|
||||
<table class="table table-hover" style="max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>IP地址</th>
|
||||
<th style="text-align: right;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListThree"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="soft-man-con viewFour" style="display: none">
|
||||
<div class="btnclick">
|
||||
<label class="btnTitle">日志分类</label>
|
||||
<div class="btn-group">
|
||||
<input type="submit" name="btnOne" class="btn btn-success" onclick="sagelogin.SSH_Defense_List(0)" value="已防御" />
|
||||
<input type="submit" name="btnTwo" class="btn btn-default" onclick="sagelogin.SSH_Defense_List(1)" value="入侵日志"/>
|
||||
<input type="submit" name="btnThree" class="btn btn-default" onclick="sagelogin.SSH_Defense_List(2)" value="登录日志"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="whiteList-table divtable" style="overflow-x: hidden;height: 470px;">
|
||||
<table class="table table-hover" style="max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>源IP地址</th>
|
||||
<th>用户</th>
|
||||
<th style="text-align: right;">登录时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListFour"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="soft-man-con">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="javascript/text">
|
||||
//宝塔安全登录
|
||||
$(function(){
|
||||
$(".bt-w-menu p").click(function(){
|
||||
$(this).addClass("bgw").siblings().removeClass("bgw");
|
||||
$('.bt-w-con .soft-man-con').hide().eq($(this).index()).show();
|
||||
switch($(this).index()) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
sagelogin.Panel_White_List();
|
||||
break;
|
||||
case 2:
|
||||
sagelogin.Panel_journal();
|
||||
break;
|
||||
case 3:
|
||||
sagelogin.SSH_White_List();
|
||||
break;
|
||||
case 4:
|
||||
sagelogin.SSH_Defense_List(0);
|
||||
break;
|
||||
}
|
||||
});
|
||||
layer.load();
|
||||
$.get('/plugin?action=a&name=safelogin&s=GetServerInfo',function(data) {
|
||||
layer.closeAll('loading');
|
||||
if (data.status) {
|
||||
$('.boxshow').hide();
|
||||
$('.maks').hide();
|
||||
}else{
|
||||
$('.boxshow').show();
|
||||
$('.maks').show();
|
||||
}
|
||||
});
|
||||
});
|
||||
var sagelogin = new Object();
|
||||
sagelogin = {
|
||||
Addview:'',
|
||||
SSHlogList:'',
|
||||
PanelLogList:'',
|
||||
// SSH管理
|
||||
SSH_Admin:function(){
|
||||
var confirm = layer.confirm('确定清除面板登录限制IP地址?',{icon: 1}, {
|
||||
btn: ['确认','取消'],
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=close_ssh_limit',function(data) {
|
||||
if (data.status) {
|
||||
layer.msg(data.msg,{icon:1});
|
||||
sagelogin.SSH_White_List();
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
},
|
||||
tokenShow:function(){
|
||||
var inputPwd = layer.open({
|
||||
type: 1,
|
||||
title: '验证面板密码',
|
||||
shadeClose: true,
|
||||
shade: 0.3,
|
||||
area: ['380px', '190px'],
|
||||
btn:['确定','取消'],
|
||||
content:'<div class="Add_view" style="height:90px"><label>面板密码:</label><input name="panel_pwd" class=" bt-input-text" type="password"></div>',
|
||||
yes:function(){
|
||||
var passwordStr = $("input[name='panel_pwd']").val();
|
||||
var index = layer.load(0, {shade: false});
|
||||
$.post('/plugin?action=a&name=safelogin&s=GetServerToken',{password:passwordStr},function(token) {
|
||||
layer.close(index);
|
||||
if(token.status === false){
|
||||
layer.msg(token.msg,{icon:2});
|
||||
return;
|
||||
}
|
||||
layer.close(inputPwd);
|
||||
$("textarea[name='token']").val(token);
|
||||
});
|
||||
},
|
||||
btn2:function(){
|
||||
layer.close(inputPwd);
|
||||
}
|
||||
});
|
||||
},
|
||||
// SSH白名单——列表
|
||||
SSH_White_List:function(){
|
||||
var index = layer.load(0, {shade: false});
|
||||
$.get('/plugin?action=a&name=safelogin&s=get_ssh_limit','',function(data){
|
||||
$('#whiteListThree').empty();
|
||||
var List = '';
|
||||
if (data.length == 0){
|
||||
$('.viewThree .status span:eq(0)').html('关闭');
|
||||
$('.viewThree .glyphicon-pause').show();
|
||||
$('.viewThree .glyphicon-play').hide();
|
||||
}else {
|
||||
$('.viewThree .status span:eq(0)').html('开启');
|
||||
$('.viewThree .glyphicon-pause').hide();
|
||||
$('.viewThree .glyphicon-play').show();
|
||||
}
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
List = List + '<tr><td>'+ data[i] +'</td><td style="text-align:right;"><a href="javascript:;" ip-val="'+ data[i] +'" onclick="sagelogin.SSH_Del_White_List(event)" style="color:red">删除</a></td></tr>'
|
||||
}
|
||||
$('#whiteListThree').append(List);
|
||||
layer.close(index);
|
||||
});
|
||||
},
|
||||
// SSH白名单——删除
|
||||
SSH_Del_White_List:function(ev){
|
||||
var ip = ev.currentTarget.getAttribute('ip-val');
|
||||
var confirm = layer.confirm('确定删除IP['+ ip +']限制地址?', {
|
||||
btn: ['确认','取消'] //按钮
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=remove_ssh_limit',{ip:ip},function(data){
|
||||
if (data.status) {
|
||||
sagelogin.SSH_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else {
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
},
|
||||
// SSH白名单——添加
|
||||
SSH_Add_White_List:function(ip){
|
||||
$.post('/plugin?action=a&name=safelogin&s=add_ssh_limit',{ip:ip},function(data){
|
||||
layer.close(sagelogin.Addview);
|
||||
if (data.status) {
|
||||
sagelogin.SSH_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
},
|
||||
// SSH日志管理
|
||||
SSH_Defense_List:function(status){
|
||||
$('.btnclick input').removeClass('btn-success').addClass('btn-default');
|
||||
$('.btnclick input').eq(status).addClass('btn-success').removeClass('btn-default');
|
||||
if (sagelogin.SSHlogList == '') {
|
||||
$.get('/plugin?action=a&s=get_ssh_errorlogin&name=safelogin',function(data){
|
||||
sagelogin.SSHlogList = data;
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.defense);
|
||||
});
|
||||
}else{
|
||||
switch(status) {
|
||||
case 0:
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.defense);
|
||||
break;
|
||||
case 1:
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.intrusion);
|
||||
break;
|
||||
case 2:
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.success);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
// SSH日志渲染模板
|
||||
DefenseFor:function(data){
|
||||
var List = '';
|
||||
$('#whiteListFour').empty();
|
||||
for (var i = data.length - 1; i >= 0; i--) {
|
||||
List = List + '<tr><td>'+data[i].address+'</td><td>' + data[i].user + '</td><td style="text-align:right">'+ data[i].date+'</td></tr>'
|
||||
}
|
||||
$('#whiteListFour').append(List);
|
||||
},
|
||||
// 面板管理
|
||||
Panel_Admin:function(){
|
||||
var confirm = layer.confirm('确定清除面板登录限制IP地址?', {
|
||||
btn: ['确认','取消'] //按钮
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=close_panel_limit',function(data) {
|
||||
if (data.status) {
|
||||
layer.msg(data.msg,{icon:1});
|
||||
sagelogin.Panel_White_List();
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
|
||||
},
|
||||
// 面板白名单——列表
|
||||
Panel_White_List:function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=get_panel_limit','',function(data){
|
||||
$('#whiteListOne').empty();
|
||||
var List = '';
|
||||
if (data.length == 0){
|
||||
$('.viewOne .status span:eq(0)').html('关闭');
|
||||
$('.viewOne .glyphicon-pause').show();
|
||||
$('.viewOne .glyphicon-play').hide();
|
||||
}else {
|
||||
$('.viewOne .status span:eq(0)').html('开启');
|
||||
$('.viewOne .glyphicon-pause').hide();
|
||||
$('.viewOne .glyphicon-play').show();
|
||||
}
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
List = List + '<tr><td>'+ data[i] +'</td><td style="text-align:right;"><a href="javascript:;" ip-val="'+ data[i] +'" onclick="sagelogin.Panel_Del_White_List(event)" style="color:red">删除</a></td></tr>'
|
||||
}
|
||||
$('#whiteListOne').append(List);
|
||||
});
|
||||
},
|
||||
// 面板白名单——删除
|
||||
Panel_Del_White_List:function(ev){
|
||||
var ip = ev.currentTarget.getAttribute('ip-val');
|
||||
var confirm = layer.confirm('确定删除IP['+ ip +']限制地址?', {
|
||||
btn: ['确认','取消'] //按钮
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=remove_ssh_limit',{ip:ip},function(data){
|
||||
if (data.status) {
|
||||
sagelogin.Panel_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else {
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
},
|
||||
// 面板白名单——添加
|
||||
Panel_Add_White_List:function(ip){
|
||||
$.post('/plugin?action=a&name=safelogin&s=add_panel_limit', {ip: ip}, function(data) {
|
||||
layer.close(sagelogin.Addview);
|
||||
if (data.status) {
|
||||
sagelogin.Panel_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
},
|
||||
// 面板日志——列表
|
||||
Panel_journal:function(){
|
||||
var index = layer.load(0, {shade: false});
|
||||
$.get('/plugin?action=a&name=safelogin&s=get_login_log',function(data){
|
||||
$('#whiteListTwo').empty();
|
||||
var List = '';
|
||||
sagelogin.PanelLogList = data;
|
||||
for (var i = sagelogin.PanelLogList.length - 1; i >= 0; i--) {
|
||||
List = List + '<tr><td>'+ sagelogin.PanelLogList[i].log +'</td><td style="text-align:right;">'+ sagelogin.PanelLogList[i].addtime +'</tr>';
|
||||
}
|
||||
$('#whiteListTwo').append(List);
|
||||
layer.close(index);
|
||||
});
|
||||
},
|
||||
// IP正则:192.168.1.0/24
|
||||
CheckIP:function(ip) {
|
||||
var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\/\d{1,2})?$/;
|
||||
return reg.test(ip);
|
||||
},
|
||||
CheckIPTwo:function(ip) {
|
||||
var reg = /^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/gi;
|
||||
return reg.test(ip);
|
||||
},
|
||||
// 添加表单效验
|
||||
addViewVul:function(status){
|
||||
var ip = $('.addViewVul');
|
||||
if (status) {
|
||||
console.log(sagelogin.CheckIP(ip.val()));
|
||||
if(sagelogin.CheckIPTwo(ip.val())){
|
||||
ip.addClass('correct').removeClass('error');
|
||||
return true;
|
||||
}else {
|
||||
ip.addClass('error').removeClass('correct');
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
|
||||
if(sagelogin.CheckIP(ip.val())){
|
||||
ip.addClass('correct').removeClass('error');
|
||||
return true;
|
||||
}else {
|
||||
ip.addClass('error').removeClass('correct');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
// 添加界面
|
||||
Add_view:function(title,status){
|
||||
var _this = this;
|
||||
var text = ''
|
||||
var statuss = true;
|
||||
if (status) {
|
||||
text = '';
|
||||
statuss = true;
|
||||
}else{
|
||||
text = '<p style="color:red;margin: 5px 0px 0px 67px;font-size: 14px;">支持IP段,如:192.168.1.0/24</p>';
|
||||
statuss = false;
|
||||
}
|
||||
sagelogin.Addview = layer.open({
|
||||
type: 1,
|
||||
title: title,
|
||||
shadeClose: true,
|
||||
shade: 0.1,
|
||||
area: ['380px', '200px'],
|
||||
btn:['确定','取消'],
|
||||
content:'<div class="Add_view"><label>IP地址:</label><input class="addViewVul bt-input-text" onchange="sagelogin.addViewVul('+ statuss +')" type="text">'+ text +'</div>',
|
||||
yes:function(){
|
||||
if (sagelogin.addViewVul(statuss)) {
|
||||
if(status){
|
||||
sagelogin.Panel_Add_White_List($('.addViewVul').val());
|
||||
}else{
|
||||
sagelogin.SSH_Add_White_List($('.addViewVul').val());
|
||||
}
|
||||
}else{
|
||||
layer.msg('请输入合法的IP地址',{icon:2})
|
||||
}
|
||||
},
|
||||
btn2:function(){
|
||||
layer.close(sagelogin.Addview);
|
||||
}
|
||||
});
|
||||
$('.addViewVul').focus();
|
||||
}
|
||||
}
|
||||
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=mysql&f=js/mysql.js");
|
||||
</script>
|
||||
@@ -144,7 +144,7 @@ MySQL_Opt
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
"ps -ef|grep redis |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
"ps -ef|grep mysqld |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
@@ -4,14 +4,12 @@
|
||||
"name":"mysql",
|
||||
"type":"运行环境",
|
||||
"ps":"MySQL是一种关系数据库管理系统!",
|
||||
"versions":["5.5"],
|
||||
"updates":["5.5"],
|
||||
"versions":["5.5","5.6","5.7","8.0"],
|
||||
"updates":["5.5.62"],
|
||||
"shell":"install.sh",
|
||||
"checks":"/www/server/panel/plugin/safelogin",
|
||||
"checks":"server/mysql",
|
||||
"author":"midoks",
|
||||
"home":"http://www.bt.cn/bbs",
|
||||
"home":"https://dev.mysql.com/downloads/mysql/5.5.html#downloads",
|
||||
"date":"2017-11-24",
|
||||
"default":true,
|
||||
"display":1,
|
||||
"pid": "1"
|
||||
"pid": "2"
|
||||
}
|
||||
@@ -1,40 +1,27 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
install_tmp='/tmp/bt_install.pl'
|
||||
public_file=/www/server/panel/install/public.sh
|
||||
if [ ! -f $public_file ];then
|
||||
wget -O $public_file http://download.bt.cn/install/public.sh -T 5;
|
||||
fi
|
||||
. $public_file
|
||||
|
||||
download_Url=$NODE_URL
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
Install_safelogin()
|
||||
{
|
||||
mkdir -p /www/server/panel/plugin/safelogin
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
wget -O /www/server/panel/plugin/safelogin/safelogin_main.py $download_Url/install/lib/plugin/safelogin/safelogin_main.py -T 5
|
||||
wget -O /www/server/panel/plugin/safelogin/index.html $download_Url/install/lib/plugin/safelogin/index.html -T 5
|
||||
wget -O /www/server/panel/plugin/safelogin/info.json $download_Url/install/lib/plugin/safelogin/info.json -T 5
|
||||
wget -O /www/server/panel/plugin/safelogin/icon.png $download_Url/install/lib/plugin/safelogin/icon.png -T 5
|
||||
echo '安装完成' > $install_tmp
|
||||
|
||||
}
|
||||
|
||||
Uninstall_safelogin()
|
||||
{
|
||||
chattr -i /www/server/panel/plugin/safelogin/token.pl
|
||||
rm -f /www/server/panel/data/limitip.conf
|
||||
sed -i "/ALL/d" /etc/hosts.deny
|
||||
rm -rf /www/server/panel/plugin/safelogin
|
||||
}
|
||||
install_tmp=${rootPath}/tmp/bt_install.pl
|
||||
|
||||
|
||||
action=$1
|
||||
host=$2;
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_safelogin
|
||||
else
|
||||
Uninstall_safelogin
|
||||
type=$2
|
||||
|
||||
if [ "${2}" == "" ];then
|
||||
echo '缺少安装脚本...' > $install_tmp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -d $curPath/versions/$2 ];then
|
||||
echo '缺少安装脚本2...' > $install_tmp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sh -x $curPath/versions/$2/install.sh $1
|
||||
|
||||
@@ -59,24 +59,22 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/static/app/data.js?v={{config.version}}"></script>
|
||||
<script type="text/javascript" src="/static/app/files.js?v={{config.version}}></script>
|
||||
<script type="text/javascript">
|
||||
setCookie('backup_path',"$web.ctx.session.config['backup_path']");
|
||||
</script>
|
||||
<script type="text/javascript" src="/static/js/data.js?date=20180725"></script>
|
||||
<script type="text/javascript" src="/static/js/files.js?date=20180124"></script>
|
||||
<script type="text/javascript">
|
||||
$if not tData['isSetup']:
|
||||
layer.msg('$tData["lan"]["JS1"]<a href="/soft#i" style="color:#20a53a;float: right;">$tData["lan"]["JS2"]</a>',{icon:7,shade: [0.3, '#000'],time:0});
|
||||
$$(".layui-layer-shade").css("margin-left","180px");
|
||||
// $if not tData['isSetup']:
|
||||
// layer.msg('$tData["lan"]["JS1"]<a href="/soft#i" style="color:#20a53a;float: right;">$tData["lan"]["JS2"]</a>',{icon:7,shade: [0.3, '#000'],time:0});
|
||||
// $(".layui-layer-shade").css("margin-left","180px");
|
||||
setTimeout(function(){
|
||||
getData(1);
|
||||
},300);
|
||||
|
||||
$$("#dataRecycle").click(function(){
|
||||
$("#dataRecycle").click(function(){
|
||||
setTimeout(function(){
|
||||
Recycle_bin(6);
|
||||
},1000);
|
||||
});
|
||||
// });
|
||||
</script>
|
||||
<script src="/static/js/upload.js?date=20180124"></script>
|
||||
<script src="/static/app/upload.js?v={{config.version}}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
|
||||
#https://dev.mysql.com/downloads/mysql/5.5.html#downloads
|
||||
#https://dev.mysql.com/downloads/file/?id=480541
|
||||
|
||||
curPath=`pwd`
|
||||
rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
|
||||
install_tmp=${rootPath}/tmp/bt_install.pl
|
||||
mysqlDir=${serverPath}/source/mysql
|
||||
|
||||
Install_mysql()
|
||||
{
|
||||
mkdir -p ${mysqlDir}
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
if [ ! -f ${mysqlDir}/mysql-5.5.62.tar.gz ];then
|
||||
wget -O ${mysqlDir}/mysql-5.5.62.tar.gz https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.62.tar.gz
|
||||
fi
|
||||
|
||||
if [ ! -f ${mysqlDir}/mysql-5.5.62 ];then
|
||||
cd ${mysqlDir} && tar -zxvf ${mysqlDir}/mysql-5.5.62.tar.gz
|
||||
fi
|
||||
|
||||
|
||||
cd ${mysqlDir}/mysql-5.5.62 && cmake \
|
||||
-DCMAKE_INSTALL_PREFIX=$serverPath/mysql \
|
||||
&& make && make install \
|
||||
&& echo '5.5' > $serverPath/mysql/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_mysql()
|
||||
{
|
||||
rm -rf $serverPath/mysql
|
||||
echo '卸载完成' > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_mysql
|
||||
else
|
||||
Uninstall_mysql
|
||||
fi
|
||||
@@ -0,0 +1,73 @@
|
||||
user {$OS_USER} {$OS_USER_GROUP};
|
||||
worker_processes auto;
|
||||
error_log {$SERVER_PATH}/openresty/nginx/logs/error.log crit;
|
||||
pid {$SERVER_PATH}/openresty/nginx/logs/nginx.pid;
|
||||
|
||||
worker_rlimit_nofile 51200;
|
||||
|
||||
events
|
||||
{
|
||||
use {$EVENT_MODEL};
|
||||
worker_connections 51200;
|
||||
multi_accept on;
|
||||
}
|
||||
|
||||
http
|
||||
{
|
||||
include mime.types;
|
||||
#include luawaf.conf;
|
||||
|
||||
#include proxy.conf;
|
||||
|
||||
default_type application/octet-stream;
|
||||
|
||||
server_names_hash_bucket_size 512;
|
||||
client_header_buffer_size 32k;
|
||||
large_client_header_buffers 4 32k;
|
||||
client_max_body_size 50m;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
|
||||
keepalive_timeout 60;
|
||||
|
||||
tcp_nodelay on;
|
||||
|
||||
fastcgi_connect_timeout 300;
|
||||
fastcgi_send_timeout 300;
|
||||
fastcgi_read_timeout 300;
|
||||
fastcgi_buffer_size 64k;
|
||||
fastcgi_buffers 4 64k;
|
||||
fastcgi_busy_buffers_size 128k;
|
||||
fastcgi_temp_file_write_size 256k;
|
||||
fastcgi_intercept_errors on;
|
||||
|
||||
gzip on;
|
||||
gzip_min_length 1k;
|
||||
gzip_buffers 4 16k;
|
||||
gzip_http_version 1.1;
|
||||
gzip_comp_level 2;
|
||||
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
|
||||
gzip_vary on;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_disable "MSIE [1-6]\.";
|
||||
|
||||
limit_conn_zone $binary_remote_addr zone=perip:10m;
|
||||
limit_conn_zone $server_name zone=perserver:10m;
|
||||
|
||||
server_tokens off;
|
||||
access_log off;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name 127.0.0.1;
|
||||
allow 127.0.0.1;
|
||||
location /nginx_status {
|
||||
stub_status on;
|
||||
access_log off;
|
||||
}
|
||||
include {$SERVER_PATH}/openresty/nginx/conf/php_status/*.conf;
|
||||
}
|
||||
include {$SERVER_PATH}/openresty/nginx/conf/vhost/*.conf;
|
||||
}
|
||||
|
||||
@@ -1,550 +1,18 @@
|
||||
<style>
|
||||
|
||||
|
||||
/*危险按钮*/
|
||||
.bts-danger:hover{
|
||||
color: #fff;
|
||||
background-color: #c9302c;
|
||||
border-color: #ac2925;
|
||||
}
|
||||
#whiteList a{
|
||||
color: red;
|
||||
}
|
||||
|
||||
/*弹窗*/
|
||||
.Add_view{
|
||||
height: 100px;
|
||||
padding-left: 35px;
|
||||
padding-top: 35px;
|
||||
}
|
||||
.Add_view label{
|
||||
margin-right: 10px;
|
||||
font-size: 15px;
|
||||
font-weight: 100;
|
||||
}
|
||||
.Add_view input{
|
||||
width: 230px;
|
||||
}
|
||||
.Add_view .error{
|
||||
border: 1px solid red;
|
||||
}
|
||||
.Add_view .correct{
|
||||
border: 1px solid #20a53a;
|
||||
}
|
||||
|
||||
/*日志管理*/
|
||||
.btnTitle{
|
||||
font-weight: 100;
|
||||
font-size: 16px;
|
||||
line-height: 34px;
|
||||
height: 34px;
|
||||
margin-right: 15px;
|
||||
position: relative;
|
||||
top: 2px;
|
||||
}
|
||||
.whiteList-table{
|
||||
margin-top: 10px;
|
||||
}
|
||||
/*登录日志表单*/
|
||||
.viewTwo .whiteList-table{
|
||||
overflow-x: hidden;
|
||||
height: 500px;
|
||||
}
|
||||
.maks{
|
||||
background: rgba(39, 39, 39, 0.4);
|
||||
position: absolute;
|
||||
width: 700px;
|
||||
height: 555px;
|
||||
z-index: 999;
|
||||
overflow: hidden;
|
||||
}
|
||||
.boxshow{
|
||||
position: absolute;
|
||||
height: 150px;
|
||||
width: 400px;
|
||||
margin-left: -200px;
|
||||
margin-top: -75px;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
z-index: 1000;
|
||||
background: #fff;
|
||||
padding: 25px 20px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.btPayment {
|
||||
float: left;
|
||||
padding: 8px 10px;
|
||||
width: 190px;
|
||||
height: 100px;
|
||||
line-height: 33px;
|
||||
text-align: center;
|
||||
border-left: 1px solid #ececec;
|
||||
}
|
||||
.btPayment .t2{
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.btPayment .price{
|
||||
color: #20A53A;
|
||||
font-size: 22px;
|
||||
margin: 0 5px;
|
||||
|
||||
}
|
||||
.bt-form{
|
||||
overflow: hidden;
|
||||
}
|
||||
.boxtext{
|
||||
line-height: 32px;
|
||||
margin-top: -17px;
|
||||
text-align: center;
|
||||
border-bottom: #eee 1px solid;
|
||||
height: 39px;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
<div class="maks" style="display: none"></div>
|
||||
<div class="boxshow" style="display: none;">
|
||||
<div>
|
||||
<div class="boxtext">
|
||||
<span>未开通此服务,如需使用请开通企业运维版。</span>
|
||||
</div>
|
||||
<div class="btvipinfo" style="width: 170px;padding-left: 20px">
|
||||
<p style="height: 25px">1、一对一运维人员对接</p>
|
||||
<p style="height: 25px">2、提供每月3次运维服务</p>
|
||||
<p style="height: 25px">3、双重安全隔离登录</p>
|
||||
</div>
|
||||
<div class="btPayment">
|
||||
<span class="t2">企业运维版<span class="price">98</span>元/月</span>
|
||||
<button class="btn btn-success btn-sm" style="width:80%" onclick="window.open('https://www.bt.cn/admin/index.html')">立即开通</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw">密钥</p>
|
||||
<p>面板设置</p>
|
||||
<p>面板登录日志</p>
|
||||
<p>SSH设置</p>
|
||||
<p>SSH日志管理</p>
|
||||
<p class="bgw" onclick="orPluginService('openresty');">服务</p>
|
||||
<p onclick="pluginInitD('openresty');">自启动</p>
|
||||
<p onclick="pluginConfig('openresty');">配置修改</p>
|
||||
<p onclick="getOpenrestyStatus();">负载状态</p>
|
||||
<p onclick="pluginLogs('openresty');">错误日志</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con viewZoo">
|
||||
<p class="status" style="margin-top:10px;margin-left:10px;height: 80px;margin-bottom:15px;">
|
||||
<span style="float:left;margin-top:-5px">密钥:</span>
|
||||
<textarea class="bt-input-text" name="token" readonly="readonly" style="background-color: #eee;width:400px;height:80px;padding: 8px 15px;" placeholder="密钥已隐藏..."></textarea>
|
||||
</p>
|
||||
<input type="button" class="btn btn-success btn-sm" name="ButtonShow" style="margin-left:52px;width:100px" onclick="sagelogin.tokenShow()" value="显示密钥" />
|
||||
<ul style="margin: 15px 5px;padding-left: 70px;list-style-type: disc;line-height: 25px;">
|
||||
<li>宝塔企业运维后台连接您的服务器需要此密钥,请妥善记录并保存</li>
|
||||
<li>一但密钥丢失,可能导致您无法登录服务器</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="soft-man-con viewOne" style="display: none;">
|
||||
<p class="status">当前状态:
|
||||
<span>开启</span>
|
||||
<span style="color: #20a53a; margin-left: 3px;" class="glyphicon glyphicon glyphicon-play"></span>
|
||||
<span style="color: red; margin-left: 3px; display: none" class="glyphicon glyphicon-pause"></span>
|
||||
</p>
|
||||
<div class="sfm-opt">
|
||||
<button class="btn btn-default btn-sm bts-danger" onclick="sagelogin.Panel_Admin()">清除面板登录限制IP</button>
|
||||
<button class="btn btn-default btn-sm bts-safety" onclick="sagelogin.Add_view('面板白名单',true)">添加白名单</button>
|
||||
</div>
|
||||
<div class="whiteList-table divtable" style="overflow-x: hidden;height: 420px">
|
||||
<table class="table table-hover" style="max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>IP地址</th>
|
||||
<th style="text-align: right;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListOne"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="soft-man-con viewTwo" style="display: none">
|
||||
<div class="whiteList-table divtable">
|
||||
<table class="table table-hover" style=" max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>操作记录</th>
|
||||
<th>操作时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListTwo"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="soft-man-con viewThree" style="display: none">
|
||||
<p class="status">当前状态:
|
||||
<span>开启</span>
|
||||
<span style="color: #20a53a; margin-left: 3px;" class="glyphicon glyphicon glyphicon-play">
|
||||
</span>
|
||||
<span style="color: red; margin-left: 3px; display: none" class="glyphicon glyphicon-pause"></span>
|
||||
</p>
|
||||
<div class="sfm-opt">
|
||||
<button class="btn btn-default btn-sm bts-danger" onclick="sagelogin.Panel_Admin()">清除SSH登录限制IP</button>
|
||||
<button class="btn btn-default btn-sm bts-safety" onclick="sagelogin.Add_view('SSH白名单',false)">添加白名单</button>
|
||||
</div>
|
||||
<div class="whiteList-table divtable" style="overflow-x: hidden;height: 420px">
|
||||
<table class="table table-hover" style="max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>IP地址</th>
|
||||
<th style="text-align: right;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListThree"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="soft-man-con viewFour" style="display: none">
|
||||
<div class="btnclick">
|
||||
<label class="btnTitle">日志分类</label>
|
||||
<div class="btn-group">
|
||||
<input type="submit" name="btnOne" class="btn btn-success" onclick="sagelogin.SSH_Defense_List(0)" value="已防御" />
|
||||
<input type="submit" name="btnTwo" class="btn btn-default" onclick="sagelogin.SSH_Defense_List(1)" value="入侵日志"/>
|
||||
<input type="submit" name="btnThree" class="btn btn-default" onclick="sagelogin.SSH_Defense_List(2)" value="登录日志"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="whiteList-table divtable" style="overflow-x: hidden;height: 470px;">
|
||||
<table class="table table-hover" style="max-height: 380px; overflow: auto;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>源IP地址</th>
|
||||
<th>用户</th>
|
||||
<th style="text-align: right;">登录时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="whiteListFour"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="javascript/text">
|
||||
//宝塔安全登录
|
||||
$(function(){
|
||||
$(".bt-w-menu p").click(function(){
|
||||
$(this).addClass("bgw").siblings().removeClass("bgw");
|
||||
$('.bt-w-con .soft-man-con').hide().eq($(this).index()).show();
|
||||
switch($(this).index()) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
sagelogin.Panel_White_List();
|
||||
break;
|
||||
case 2:
|
||||
sagelogin.Panel_journal();
|
||||
break;
|
||||
case 3:
|
||||
sagelogin.SSH_White_List();
|
||||
break;
|
||||
case 4:
|
||||
sagelogin.SSH_Defense_List(0);
|
||||
break;
|
||||
}
|
||||
});
|
||||
layer.load();
|
||||
$.get('/plugin?action=a&name=safelogin&s=GetServerInfo',function(data) {
|
||||
layer.closeAll('loading');
|
||||
if (data.status) {
|
||||
$('.boxshow').hide();
|
||||
$('.maks').hide();
|
||||
}else{
|
||||
$('.boxshow').show();
|
||||
$('.maks').show();
|
||||
}
|
||||
});
|
||||
});
|
||||
var sagelogin = new Object();
|
||||
sagelogin = {
|
||||
Addview:'',
|
||||
SSHlogList:'',
|
||||
PanelLogList:'',
|
||||
// SSH管理
|
||||
SSH_Admin:function(){
|
||||
var confirm = layer.confirm('确定清除面板登录限制IP地址?',{icon: 1}, {
|
||||
btn: ['确认','取消'],
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=close_ssh_limit',function(data) {
|
||||
if (data.status) {
|
||||
layer.msg(data.msg,{icon:1});
|
||||
sagelogin.SSH_White_List();
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
},
|
||||
tokenShow:function(){
|
||||
var inputPwd = layer.open({
|
||||
type: 1,
|
||||
title: '验证面板密码',
|
||||
shadeClose: true,
|
||||
shade: 0.3,
|
||||
area: ['380px', '190px'],
|
||||
btn:['确定','取消'],
|
||||
content:'<div class="Add_view" style="height:90px"><label>面板密码:</label><input name="panel_pwd" class=" bt-input-text" type="password"></div>',
|
||||
yes:function(){
|
||||
var passwordStr = $("input[name='panel_pwd']").val();
|
||||
var index = layer.load(0, {shade: false});
|
||||
$.post('/plugin?action=a&name=safelogin&s=GetServerToken',{password:passwordStr},function(token) {
|
||||
layer.close(index);
|
||||
if(token.status === false){
|
||||
layer.msg(token.msg,{icon:2});
|
||||
return;
|
||||
}
|
||||
layer.close(inputPwd);
|
||||
$("textarea[name='token']").val(token);
|
||||
});
|
||||
},
|
||||
btn2:function(){
|
||||
layer.close(inputPwd);
|
||||
}
|
||||
});
|
||||
},
|
||||
// SSH白名单——列表
|
||||
SSH_White_List:function(){
|
||||
var index = layer.load(0, {shade: false});
|
||||
$.get('/plugin?action=a&name=safelogin&s=get_ssh_limit','',function(data){
|
||||
$('#whiteListThree').empty();
|
||||
var List = '';
|
||||
if (data.length == 0){
|
||||
$('.viewThree .status span:eq(0)').html('关闭');
|
||||
$('.viewThree .glyphicon-pause').show();
|
||||
$('.viewThree .glyphicon-play').hide();
|
||||
}else {
|
||||
$('.viewThree .status span:eq(0)').html('开启');
|
||||
$('.viewThree .glyphicon-pause').hide();
|
||||
$('.viewThree .glyphicon-play').show();
|
||||
}
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
List = List + '<tr><td>'+ data[i] +'</td><td style="text-align:right;"><a href="javascript:;" ip-val="'+ data[i] +'" onclick="sagelogin.SSH_Del_White_List(event)" style="color:red">删除</a></td></tr>'
|
||||
}
|
||||
$('#whiteListThree').append(List);
|
||||
layer.close(index);
|
||||
});
|
||||
},
|
||||
// SSH白名单——删除
|
||||
SSH_Del_White_List:function(ev){
|
||||
var ip = ev.currentTarget.getAttribute('ip-val');
|
||||
var confirm = layer.confirm('确定删除IP['+ ip +']限制地址?', {
|
||||
btn: ['确认','取消'] //按钮
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=remove_ssh_limit',{ip:ip},function(data){
|
||||
if (data.status) {
|
||||
sagelogin.SSH_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else {
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
},
|
||||
// SSH白名单——添加
|
||||
SSH_Add_White_List:function(ip){
|
||||
$.post('/plugin?action=a&name=safelogin&s=add_ssh_limit',{ip:ip},function(data){
|
||||
layer.close(sagelogin.Addview);
|
||||
if (data.status) {
|
||||
sagelogin.SSH_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
},
|
||||
// SSH日志管理
|
||||
SSH_Defense_List:function(status){
|
||||
$('.btnclick input').removeClass('btn-success').addClass('btn-default');
|
||||
$('.btnclick input').eq(status).addClass('btn-success').removeClass('btn-default');
|
||||
if (sagelogin.SSHlogList == '') {
|
||||
$.get('/plugin?action=a&s=get_ssh_errorlogin&name=safelogin',function(data){
|
||||
sagelogin.SSHlogList = data;
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.defense);
|
||||
});
|
||||
}else{
|
||||
switch(status) {
|
||||
case 0:
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.defense);
|
||||
break;
|
||||
case 1:
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.intrusion);
|
||||
break;
|
||||
case 2:
|
||||
sagelogin.DefenseFor(sagelogin.SSHlogList.success);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
// SSH日志渲染模板
|
||||
DefenseFor:function(data){
|
||||
var List = '';
|
||||
$('#whiteListFour').empty();
|
||||
for (var i = data.length - 1; i >= 0; i--) {
|
||||
List = List + '<tr><td>'+data[i].address+'</td><td>' + data[i].user + '</td><td style="text-align:right">'+ data[i].date+'</td></tr>'
|
||||
}
|
||||
$('#whiteListFour').append(List);
|
||||
},
|
||||
// 面板管理
|
||||
Panel_Admin:function(){
|
||||
var confirm = layer.confirm('确定清除面板登录限制IP地址?', {
|
||||
btn: ['确认','取消'] //按钮
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=close_panel_limit',function(data) {
|
||||
if (data.status) {
|
||||
layer.msg(data.msg,{icon:1});
|
||||
sagelogin.Panel_White_List();
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
|
||||
},
|
||||
// 面板白名单——列表
|
||||
Panel_White_List:function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=get_panel_limit','',function(data){
|
||||
$('#whiteListOne').empty();
|
||||
var List = '';
|
||||
if (data.length == 0){
|
||||
$('.viewOne .status span:eq(0)').html('关闭');
|
||||
$('.viewOne .glyphicon-pause').show();
|
||||
$('.viewOne .glyphicon-play').hide();
|
||||
}else {
|
||||
$('.viewOne .status span:eq(0)').html('开启');
|
||||
$('.viewOne .glyphicon-pause').hide();
|
||||
$('.viewOne .glyphicon-play').show();
|
||||
}
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
List = List + '<tr><td>'+ data[i] +'</td><td style="text-align:right;"><a href="javascript:;" ip-val="'+ data[i] +'" onclick="sagelogin.Panel_Del_White_List(event)" style="color:red">删除</a></td></tr>'
|
||||
}
|
||||
$('#whiteListOne').append(List);
|
||||
});
|
||||
},
|
||||
// 面板白名单——删除
|
||||
Panel_Del_White_List:function(ev){
|
||||
var ip = ev.currentTarget.getAttribute('ip-val');
|
||||
var confirm = layer.confirm('确定删除IP['+ ip +']限制地址?', {
|
||||
btn: ['确认','取消'] //按钮
|
||||
}, function(){
|
||||
$.get('/plugin?action=a&name=safelogin&s=remove_ssh_limit',{ip:ip},function(data){
|
||||
if (data.status) {
|
||||
sagelogin.Panel_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else {
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}, function(){
|
||||
layer.close(confirm);
|
||||
});
|
||||
},
|
||||
// 面板白名单——添加
|
||||
Panel_Add_White_List:function(ip){
|
||||
$.post('/plugin?action=a&name=safelogin&s=add_panel_limit', {ip: ip}, function(data) {
|
||||
layer.close(sagelogin.Addview);
|
||||
if (data.status) {
|
||||
sagelogin.Panel_White_List();
|
||||
layer.msg(data.msg,{icon:1});
|
||||
}else{
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
},
|
||||
// 面板日志——列表
|
||||
Panel_journal:function(){
|
||||
var index = layer.load(0, {shade: false});
|
||||
$.get('/plugin?action=a&name=safelogin&s=get_login_log',function(data){
|
||||
$('#whiteListTwo').empty();
|
||||
var List = '';
|
||||
sagelogin.PanelLogList = data;
|
||||
for (var i = sagelogin.PanelLogList.length - 1; i >= 0; i--) {
|
||||
List = List + '<tr><td>'+ sagelogin.PanelLogList[i].log +'</td><td style="text-align:right;">'+ sagelogin.PanelLogList[i].addtime +'</tr>';
|
||||
}
|
||||
$('#whiteListTwo').append(List);
|
||||
layer.close(index);
|
||||
});
|
||||
},
|
||||
// IP正则:192.168.1.0/24
|
||||
CheckIP:function(ip) {
|
||||
var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\/\d{1,2})?$/;
|
||||
return reg.test(ip);
|
||||
},
|
||||
CheckIPTwo:function(ip) {
|
||||
var reg = /^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/gi;
|
||||
return reg.test(ip);
|
||||
},
|
||||
// 添加表单效验
|
||||
addViewVul:function(status){
|
||||
var ip = $('.addViewVul');
|
||||
if (status) {
|
||||
console.log(sagelogin.CheckIP(ip.val()));
|
||||
if(sagelogin.CheckIPTwo(ip.val())){
|
||||
ip.addClass('correct').removeClass('error');
|
||||
return true;
|
||||
}else {
|
||||
ip.addClass('error').removeClass('correct');
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
|
||||
if(sagelogin.CheckIP(ip.val())){
|
||||
ip.addClass('correct').removeClass('error');
|
||||
return true;
|
||||
}else {
|
||||
ip.addClass('error').removeClass('correct');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
// 添加界面
|
||||
Add_view:function(title,status){
|
||||
var _this = this;
|
||||
var text = ''
|
||||
var statuss = true;
|
||||
if (status) {
|
||||
text = '';
|
||||
statuss = true;
|
||||
}else{
|
||||
text = '<p style="color:red;margin: 5px 0px 0px 67px;font-size: 14px;">支持IP段,如:192.168.1.0/24</p>';
|
||||
statuss = false;
|
||||
}
|
||||
sagelogin.Addview = layer.open({
|
||||
type: 1,
|
||||
title: title,
|
||||
shadeClose: true,
|
||||
shade: 0.1,
|
||||
area: ['380px', '200px'],
|
||||
btn:['确定','取消'],
|
||||
content:'<div class="Add_view"><label>IP地址:</label><input class="addViewVul bt-input-text" onchange="sagelogin.addViewVul('+ statuss +')" type="text">'+ text +'</div>',
|
||||
yes:function(){
|
||||
if (sagelogin.addViewVul(statuss)) {
|
||||
if(status){
|
||||
sagelogin.Panel_Add_White_List($('.addViewVul').val());
|
||||
}else{
|
||||
sagelogin.SSH_Add_White_List($('.addViewVul').val());
|
||||
}
|
||||
}else{
|
||||
layer.msg('请输入合法的IP地址',{icon:2})
|
||||
}
|
||||
},
|
||||
btn2:function(){
|
||||
layer.close(sagelogin.Addview);
|
||||
}
|
||||
});
|
||||
$('.addViewVul').focus();
|
||||
}
|
||||
}
|
||||
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=openresty&f=js/openresty.js");
|
||||
</script>
|
||||
@@ -0,0 +1,293 @@
|
||||
# coding:utf-8
|
||||
|
||||
import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
|
||||
|
||||
app_debug = False
|
||||
|
||||
if public.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'openresty'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
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 clearTemp():
|
||||
path_bin = getServerDir() + "/nginx"
|
||||
public.execShell('rm -rf ' + path_bin + '/client_body_temp')
|
||||
public.execShell('rm -rf ' + path_bin + '/fastcgi_temp')
|
||||
public.execShell('rm -rf ' + path_bin + '/proxy_temp')
|
||||
public.execShell('rm -rf ' + path_bin + '/scgi_temp')
|
||||
public.execShell('rm -rf ' + path_bin + '/uwsgi_temp')
|
||||
|
||||
|
||||
def getConf():
|
||||
path = getPluginDir() + "/conf/nginx.conf"
|
||||
return path
|
||||
|
||||
|
||||
def getOs():
|
||||
data = {}
|
||||
data['os'] = public.getOs()
|
||||
ng_exe_bin = getServerDir() + "/nginx/sbin/nginx"
|
||||
if checkAuthEq(ng_exe_bin, 'root'):
|
||||
data['auth'] = True
|
||||
else:
|
||||
data['auth'] = False
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
def getInitDTpl():
|
||||
path = getPluginDir() + "/init.d/nginx.tpl"
|
||||
return path
|
||||
|
||||
|
||||
def makeConf():
|
||||
vhost = getServerDir() + '/nginx/conf/vhost'
|
||||
if not os.path.exists(vhost):
|
||||
os.mkdir(vhost)
|
||||
php_status = getServerDir() + '/nginx/conf/php_status'
|
||||
if not os.path.exists(php_status):
|
||||
os.mkdir(php_status)
|
||||
|
||||
|
||||
def getFileOwner(filename):
|
||||
import pwd
|
||||
stat = os.lstat(filename)
|
||||
uid = stat.st_uid
|
||||
pw = pwd.getpwuid(uid)
|
||||
return pw.pw_name
|
||||
|
||||
|
||||
def checkAuthEq(file, owner='root'):
|
||||
fowner = getFileOwner(file)
|
||||
if (fowner == owner):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def confReplace():
|
||||
service_path = os.path.dirname(os.getcwd())
|
||||
content = public.readFile(getConf())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
|
||||
user = 'www'
|
||||
user_group = 'www'
|
||||
|
||||
if public.getOs() == 'darwin':
|
||||
# macosx do
|
||||
user = public.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
# user = 'root'
|
||||
user_group = 'staff'
|
||||
content = content.replace('{$EVENT_MODEL}', 'kqueue')
|
||||
else:
|
||||
user = 'www'
|
||||
user_group = 'www'
|
||||
content = content.replace('{$EVENT_MODEL}', 'epoll')
|
||||
|
||||
content = content.replace('{$OS_USER}', user)
|
||||
content = content.replace('{$OS_USER_GROUP}', user_group)
|
||||
|
||||
public.writeFile(getServerDir() + '/nginx/conf/nginx.conf', content)
|
||||
|
||||
# give nginx root permission
|
||||
ng_exe_bin = getServerDir() + "/nginx/sbin/nginx"
|
||||
if not checkAuthEq(ng_exe_bin, 'root'):
|
||||
args = getArgs()
|
||||
sudoPwd = args['pwd']
|
||||
cmd_own = 'chown -R ' + 'root:' + user_group + ' ' + ng_exe_bin
|
||||
os.system('echo %s|sudo -S %s' % (sudoPwd, cmd_own))
|
||||
cmd_mod = 'chmod 755 ' + ng_exe_bin
|
||||
os.system('echo %s|sudo -S %s' % (sudoPwd, cmd_mod))
|
||||
cmd_s = 'chmod u+s ' + ng_exe_bin
|
||||
os.system('echo %s|sudo -S %s' % (sudoPwd, cmd_s))
|
||||
|
||||
|
||||
def initDreplace():
|
||||
|
||||
file_tpl = getInitDTpl()
|
||||
service_path = os.path.dirname(os.getcwd())
|
||||
|
||||
initD_path = getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
os.mkdir(initD_path)
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
|
||||
# initd replace
|
||||
content = public.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
|
||||
# config replace
|
||||
confReplace()
|
||||
|
||||
# make nginx vhost or other
|
||||
makeConf()
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
"ps -ef|grep nginx |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def start():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
clearTemp()
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
source_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def runInfo():
|
||||
# 取Openresty负载状态
|
||||
try:
|
||||
result = public.httpGet('http://127.0.0.1/nginx_status')
|
||||
tmp = result.split()
|
||||
data = {}
|
||||
data['active'] = tmp[2]
|
||||
data['accepts'] = tmp[9]
|
||||
data['handled'] = tmp[7]
|
||||
data['requests'] = tmp[8]
|
||||
data['Reading'] = tmp[11]
|
||||
data['Writing'] = tmp[13]
|
||||
data['Waiting'] = tmp[15]
|
||||
return public.getJson(data)
|
||||
except Exception as e:
|
||||
return 'oprenresty not started'
|
||||
|
||||
|
||||
def errorLogPath():
|
||||
return getServerDir() + '/nginx/logs/error.log'
|
||||
|
||||
|
||||
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 == 'conf':
|
||||
print getConf()
|
||||
elif func == 'get_os':
|
||||
print getOs()
|
||||
elif func == 'run_info':
|
||||
print runInfo()
|
||||
elif func == 'error_log':
|
||||
print errorLogPath()
|
||||
else:
|
||||
print 'error'
|
||||
@@ -0,0 +1,118 @@
|
||||
#! /bin/sh
|
||||
# chkconfig: 2345 55 25
|
||||
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
|
||||
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
|
||||
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: nginx
|
||||
# Required-Start: $all
|
||||
# Required-Stop: $all
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: starts the nginx web server
|
||||
# Description: starts nginx using start-stop-daemon
|
||||
### END INIT INFO
|
||||
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
NAME=nginx
|
||||
NGINX_BIN={$SERVER_PATH}/openresty/bin/openresty
|
||||
CONFIGFILE={$SERVER_PATH}/openresty/nginx/conf/$NAME.conf
|
||||
PIDFILE={$SERVER_PATH}/openresty/nginx/logs/$NAME.pid
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
echo -n "Starting $NAME... "
|
||||
if [ -f $PIDFILE ];then
|
||||
mPID=`cat $PIDFILE`
|
||||
isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"`
|
||||
if [ "$isStart" != '' ];then
|
||||
echo "$NAME (pid `pidof $NAME`) already running."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
$NGINX_BIN -c $CONFIGFILE
|
||||
|
||||
if [ "$?" != 0 ] ; then
|
||||
echo " failed"
|
||||
exit 1
|
||||
else
|
||||
echo " done"
|
||||
fi
|
||||
;;
|
||||
|
||||
stop)
|
||||
echo -n "Stoping $NAME... "
|
||||
if [ -f $PIDFILE ];then
|
||||
mPID=`cat $PIDFILE`
|
||||
isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"`
|
||||
if [ "$isStart" = '' ];then
|
||||
echo "$NAME is not running."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "$NAME is not running."
|
||||
exit 1
|
||||
fi
|
||||
$NGINX_BIN -s stop
|
||||
|
||||
if [ "$?" != 0 ] ; then
|
||||
echo " failed. Use force-quit"
|
||||
exit 1
|
||||
else
|
||||
echo " done"
|
||||
fi
|
||||
;;
|
||||
|
||||
status)
|
||||
if [ -f $PIDFILE ];then
|
||||
mPID=`cat $PIDFILE`
|
||||
isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"`
|
||||
if [ "$isStart" != '' ];then
|
||||
echo "$NAME (pid `pidof $NAME`) already running."
|
||||
exit 1
|
||||
else
|
||||
echo "$NAME is stopped"
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
echo "$NAME is stopped"
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
restart)
|
||||
$0 stop
|
||||
sleep 1
|
||||
$0 start
|
||||
;;
|
||||
|
||||
reload)
|
||||
echo -n "Reload service $NAME... "
|
||||
if [ -f $PIDFILE ];then
|
||||
mPID=`cat $PIDFILE`
|
||||
isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"`
|
||||
if [ "$isStart" != '' ];then
|
||||
$NGINX_BIN -s reload
|
||||
echo " done"
|
||||
else
|
||||
echo "$NAME is not running, can't reload."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "$NAME is not running, can't reload."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
configtest)
|
||||
echo -n "Test $NAME configure files... "
|
||||
$NGINX_BIN -t
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|reload|status|configtest}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -7,36 +7,18 @@ rootPath=$(dirname "$curPath")
|
||||
rootPath=$(dirname "$rootPath")
|
||||
serverPath=$(dirname "$rootPath")
|
||||
|
||||
install_tmp=${rootPath}/tmp/bt_install.pl
|
||||
|
||||
openrestyDir=${serverPath}/source/openresty
|
||||
|
||||
Install_openresty()
|
||||
{
|
||||
mkdir -p ${openrestyDir}
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
if [ ! -f ${openrestyDir}/openresty-1.13.6.2.tar.gz ];then
|
||||
wget -O ${openrestyDir}/openresty-1.13.6.2.tar.gz https://openresty.org/download/openresty-1.13.6.2.tar.gz
|
||||
fi
|
||||
cd ${openrestyDir} && tar -zxvf openresty-1.13.6.2.tar.gz
|
||||
|
||||
cd ${openrestyDir}/openresty* && ./configure --prefix=$serverPath/openresty \
|
||||
--with-openssl=$serverPath/source/lib/openssl-1.0.2q && make && make install
|
||||
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_openresty()
|
||||
{
|
||||
rm -rf $serverPath/openresty
|
||||
echo '卸载完成' > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
host=$2
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_openresty
|
||||
else
|
||||
Uninstall_openresty
|
||||
type=$2
|
||||
|
||||
if [ "${2}" == "" ];then
|
||||
echo '缺少安装脚本...' > $install_tmp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -d $curPath/versions/$2 ];then
|
||||
echo '缺少安装脚本2...' > $install_tmp
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sh -x $curPath/versions/$2/install.sh $1
|
||||
|
||||
@@ -1,3 +1,134 @@
|
||||
orPluginService('openresty');
|
||||
|
||||
|
||||
function orPost(method, args, callback){
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'openresty', func:method, args:JSON.stringify(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 orPluginService(_name, version){
|
||||
var data = {name:_name, func:'status'}
|
||||
if ( typeof(version) != 'undefined' ){
|
||||
data['version'] = version;
|
||||
} else {
|
||||
version = '';
|
||||
}
|
||||
|
||||
orPost('status', data, function(data){
|
||||
if (data.data == 'start'){
|
||||
orPluginSetService(_name, true, version);
|
||||
} else {
|
||||
orPluginSetService(_name, false, version);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function orPluginSetService(_name ,status, version){
|
||||
var serviceCon ='<p class="status">当前状态:<span>'+(status ? '开启' : '关闭' )+
|
||||
'</span><span style="color: '+
|
||||
(status?'#20a53a;':'red;')+
|
||||
' margin-left: 3px;" class="glyphicon ' + (status?'glyphicon glyphicon-play':'glyphicon-pause')+'"></span></p><div class="sfm-opt">\
|
||||
<button class="btn btn-default btn-sm" onclick="orPluginOpService(\''+_name+'\',\''+(status?'stop':'start')+'\',\''+version+'\')">'+(status?'停止':'启动')+'</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="orPluginOpService(\''+_name+'\',\'restart\',\''+version+'\')">重启</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="orPluginOpService(\''+_name+'\',\'reload\',\''+version+'\')">重载配置</button>\
|
||||
</div>';
|
||||
$(".soft-man-con").html(serviceCon);
|
||||
}
|
||||
|
||||
|
||||
function orPluginOpService(a, b, v) {
|
||||
|
||||
var c = "name=" + a + "&func=" + b;
|
||||
if(v != ''){
|
||||
c = c + '&version='+v;
|
||||
}
|
||||
|
||||
var d = "";
|
||||
|
||||
switch(b) {
|
||||
case "stop":d = '停止';break;
|
||||
case "start":d = '启动';break;
|
||||
case "restart":d = '重启';break;
|
||||
case "reload":d = '重载';break;
|
||||
}
|
||||
layer.confirm( msgTpl('您真的要{1}{2}{3}服务吗?', [d,a,v]), {icon:3,closeBtn: 2}, function() {
|
||||
orPost('get_os',{},function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
if (!rdata['auth']){
|
||||
layer.prompt({title: '检查到权限不足,需要输入密码!', formType: 1},function(pwd, index){
|
||||
|
||||
layer.close(index);
|
||||
var data = {'pwd':pwd};
|
||||
c += '&args='+JSON.stringify(data);
|
||||
orPluginOpServiceOp(a,b,c,d,a,v);
|
||||
});
|
||||
} else {
|
||||
orPluginOpServiceOp(a,b,c,d,a,v);
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function orPluginOpServiceOp(a,b,c,d,a,v){
|
||||
var e = layer.msg(msgTpl('正在{1}{2}{3}服务,请稍候...',[d,a,v]), {icon: 16,time: 0});
|
||||
$.post("/plugins/run", c, function(g) {
|
||||
layer.close(e);
|
||||
|
||||
var f = g.data == 'ok' ? msgTpl('{1}{2}服务已{3}',[a,v,d]) : msgTpl('{1}{2}服务{3}失败!',[a,v,d]);
|
||||
layer.msg(f, {icon: g.data == 'ok' ? 1 : 2});
|
||||
|
||||
if( b != "reload" && g.data == 'ok' ) {
|
||||
if ( b == 'start' ) {
|
||||
orPluginSetService(a, true, v);
|
||||
} else if ( b == 'stop' ){
|
||||
orPluginSetService(a, false, v);
|
||||
}
|
||||
}
|
||||
|
||||
if( g.status && g.data != 'ok' ) {
|
||||
layer.msg(g.data, {icon: 2,time: 3000,shade: 0.3,shadeClose: true});
|
||||
}
|
||||
},'json').error(function() {
|
||||
layer.close(e);
|
||||
layer.msg('操作异常!', {icon: 2});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//查看Nginx负载状态
|
||||
function getOpenrestyStatus() {
|
||||
$.post('/plugins/run', {name:'openresty', func:'run_info'}, function(data) {
|
||||
if (!data.status){
|
||||
showMsg(data.msg, function(){}, null,3000);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var con = "<div><table class='table table-hover table-bordered'>\
|
||||
<tr><th>活动连接(Active connections)</th><td>" + rdata.active + "</td></tr>\
|
||||
<tr><th>总连接次数(accepts)</th><td>" + rdata.accepts + "</td></tr>\
|
||||
<tr><th>总握手次数(handled)</th><td>" + rdata.handled + "</td></tr>\
|
||||
<tr><th>总请求数(requests)</th><td>" + rdata.requests + "</td></tr>\
|
||||
<tr><th>请求数(Reading)</th><td>" + rdata.Reading + "</td></tr>\
|
||||
<tr><th>响应数(Writing)</th><td>" + rdata.Writing + "</td></tr>\
|
||||
<tr><th>驻留进程(Waiting)</th><td>" + rdata.Waiting + "</td></tr>\
|
||||
</table></div>";
|
||||
$(".soft-man-con").html(con);
|
||||
}catch(err){
|
||||
showMsg(data.data, function(){}, null,3000);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
//nginx
|
||||
function nginxSoftMain(name, version) {
|
||||
@@ -24,18 +155,18 @@ function nginxSoftMain(name, version) {
|
||||
closeBtn: 2,
|
||||
shift: 0,
|
||||
content: '<div class="bt-w-main" style="width:640px;">\
|
||||
<div class="bt-w-menu">\
|
||||
<p class="bgw" onclick="service(\'' + name + '\',' + nameA.status + ')">' + lan.soft.web_service + '</p>\
|
||||
<p onclick="configChange(\'' + name + '\')">' + lan.soft.config_edit + '</p>\
|
||||
' + waf + '\
|
||||
' + menu + '\
|
||||
' + status + '\
|
||||
<p onclick="showLogs(\'' + logsPath + '\')">错误日志</p>\
|
||||
</div>\
|
||||
<div id="webEdit-con" class="bt-w-con pd15" style="height:555px;overflow:auto">\
|
||||
<div class="soft-man-con"></div>\
|
||||
</div>\
|
||||
</div>'
|
||||
<div class="bt-w-menu">\
|
||||
<p class="bgw" onclick="service(\'' + name + '\',' + nameA.status + ')">' + lan.soft.web_service + '</p>\
|
||||
<p onclick="configChange(\'' + name + '\')">' + lan.soft.config_edit + '</p>\
|
||||
' + waf + '\
|
||||
' + menu + '\
|
||||
' + status + '\
|
||||
<p onclick="showLogs(\'' + logsPath + '\')">错误日志</p>\
|
||||
</div>\
|
||||
<div id="webEdit-con" class="bt-w-con pd15" style="height:555px;overflow:auto">\
|
||||
<div class="soft-man-con"></div>\
|
||||
</div>\
|
||||
</div>'
|
||||
});
|
||||
service(name, nameA.status);
|
||||
$(".bt-w-menu p").click(function() {
|
||||
@@ -83,42 +214,42 @@ function waf() {
|
||||
var cc = rdata.CCrate.split('/')
|
||||
|
||||
var con = "<div class='wafConf'>\
|
||||
<div class='wafConf-btn'>\
|
||||
<span>" + lan.soft.waf_title + "</span><div class='ssh-item'>\
|
||||
<div class='wafConf-btn'>\
|
||||
<span>" + lan.soft.waf_title + "</span><div class='ssh-item'>\
|
||||
<input class='btswitch btswitch-ios' id='closeWaf' type='checkbox' " + (rdata.status == 1 ? 'checked' : '') + ">\
|
||||
<label class='btswitch-btn' for='closeWaf' onclick='CloseWaf()'></label>\
|
||||
</div>\
|
||||
<div class='pull-right'>\
|
||||
<button class='btn btn-default btn-sm' onclick='gzEdit()'>" + lan.soft.waf_edit + "</button>\
|
||||
<button class='btn btn-default btn-sm' onclick='upLimit()'>" + lan.soft.waf_up_title + "</button>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='wafConf_checkbox label-input-group ptb10 relative'>\
|
||||
<input type='checkbox' id='waf_UrlDeny' " + (rdata['UrlDeny'] == 'on' ? 'checked' : '') + " onclick=\"SetWafConfig('UrlDeny','" + (rdata['UrlDeny'] == 'on' ? 'off' : 'on') + "')\" /><label for='waf_UrlDeny'>" + lan.soft.waf_input1 + "</label>\
|
||||
<input type='checkbox' id='waf_CookieMatch' " + (rdata['CookieMatch'] == 'on' ? 'checked' : '') + " onclick=\"SetWafConfig('CookieMatch','" + (rdata['CookieMatch'] == 'on' ? 'off' : 'on') + "')\" /><label for='waf_CookieMatch'>" + lan.soft.waf_input2 + "</label>\
|
||||
<input type='checkbox' id='waf_postMatch' " + (rdata['postMatch'] == 'on' ? 'checked' : '') + " onclick=\"SetWafConfig('postMatch','" + (rdata['postMatch'] == 'on' ? 'off' : 'on') + "')\" /><label for='waf_postMatch'>" + lan.soft.waf_input3 + "</label>\
|
||||
<input type='checkbox' id='waf_CCDeny' " + (rdata['CCDeny'] == 'on' ? 'checked' : '') + " onclick=\"SetWafConfig('CCDeny','" + (rdata['CCDeny'] == 'on' ? 'off' : 'on') + "')\" /><label for='waf_CCDeny'>" + lan.soft.waf_input4 + "</label>\
|
||||
<input type='checkbox' id='waf_attacklog' " + (rdata['attacklog'] == 'on' ? 'checked' : '') + " onclick=\"SetWafConfig('attacklog','" + (rdata['attacklog'] == 'on' ? 'off' : 'on') + "')\" /><label for='waf_attacklog'>" + lan.soft.waf_input5 + "</label>\
|
||||
<span class='glyphicon glyphicon-folder-open' style='position: absolute; right: 10px; top: 12px; color: orange;cursor: pointer' onclick='openPath(\"/www/wwwlogs/waf\")'></span>\
|
||||
</div>\
|
||||
<div class='wafConf_cc'>\
|
||||
<span>" + lan.soft.waf_input6 + "</span><input id='CCrate_1' class='bt-input-text' type='number' value='" + cc[0] + "' style='width:80px;margin-right:30px'/>\
|
||||
<span>" + lan.soft.waf_input7 + "(" + lan.bt.s + ")</span><input id='CCrate_2' class='bt-input-text' type='number' value='" + cc[1] + "' style='width:80px;'/>\
|
||||
<button onclick=\"SetWafConfig('CCrate','')\" class='btn btn-default btn-sm'>" + lan.public.ok + "</button>\
|
||||
</div>\
|
||||
<div class='wafConf_ip'>\
|
||||
<fieldset>\
|
||||
<legend>" + lan.soft.waf_input8 + "</legend>\
|
||||
<input type='text' id='ipWhitelist_val' class='bt-input-text mr5' placeholder='" + lan.soft.waf_ip + "' style='width:175px;' /><button onclick=\"addWafKey('ipWhitelist')\" class='btn btn-default btn-sm'>" + lan.public.add + "</button>\
|
||||
<div class='table-overflow'><table class='table table-hover'>" + whiteList + "</table></div>\
|
||||
</fieldset>\
|
||||
<fieldset>\
|
||||
<legend>" + lan.soft.waf_input9 + "</legend>\
|
||||
<input type='text' id='ipBlocklist_val' class='bt-input-text mr5' placeholder='" + lan.soft.waf_ip + "' style='width:175px;' /><button onclick=\"addWafKey('ipBlocklist')\" class='btn btn-default btn-sm'>" + lan.public.add + "</button>\
|
||||
<div class='table-overflow'><table class='table table-hover'>" + blackList + "</table></div>\
|
||||
</fieldset>\
|
||||
</div>\
|
||||
</div>"
|
||||
</div>\
|
||||
<div class='pull-right'>\
|
||||
<button class='btn btn-default btn-sm' onclick='gzEdit()'>" + lan.soft.waf_edit + "</button>\
|
||||
<button class='btn btn-default btn-sm' onclick='upLimit()'>" + lan.soft.waf_up_title + "</button>\
|
||||
</div>\
|
||||
</div>\
|
||||
<div class='wafConf_checkbox label-input-group ptb10 relative'>\
|
||||
<input type='checkbox' id='waf_UrlDeny' " + (rdata['UrlDeny'] == 'on' ? 'checked' : '') + " onclick=\"SetWafConfig('UrlDeny','" + (rdata['UrlDeny'] == 'on' ? 'off' : 'on') + "')\" /><label for='waf_UrlDeny'>" + lan.soft.waf_input1 + "</label>\
|
||||
<input type='checkbox' id='waf_CookieMatch' " + (rdata['CookieMatch'] == 'on' ? 'checked' : '') + " onclick=\"SetWafConfig('CookieMatch','" + (rdata['CookieMatch'] == 'on' ? 'off' : 'on') + "')\" /><label for='waf_CookieMatch'>" + lan.soft.waf_input2 + "</label>\
|
||||
<input type='checkbox' id='waf_postMatch' " + (rdata['postMatch'] == 'on' ? 'checked' : '') + " onclick=\"SetWafConfig('postMatch','" + (rdata['postMatch'] == 'on' ? 'off' : 'on') + "')\" /><label for='waf_postMatch'>" + lan.soft.waf_input3 + "</label>\
|
||||
<input type='checkbox' id='waf_CCDeny' " + (rdata['CCDeny'] == 'on' ? 'checked' : '') + " onclick=\"SetWafConfig('CCDeny','" + (rdata['CCDeny'] == 'on' ? 'off' : 'on') + "')\" /><label for='waf_CCDeny'>" + lan.soft.waf_input4 + "</label>\
|
||||
<input type='checkbox' id='waf_attacklog' " + (rdata['attacklog'] == 'on' ? 'checked' : '') + " onclick=\"SetWafConfig('attacklog','" + (rdata['attacklog'] == 'on' ? 'off' : 'on') + "')\" /><label for='waf_attacklog'>" + lan.soft.waf_input5 + "</label>\
|
||||
<span class='glyphicon glyphicon-folder-open' style='position: absolute; right: 10px; top: 12px; color: orange;cursor: pointer' onclick='openPath(\"/www/wwwlogs/waf\")'></span>\
|
||||
</div>\
|
||||
<div class='wafConf_cc'>\
|
||||
<span>" + lan.soft.waf_input6 + "</span><input id='CCrate_1' class='bt-input-text' type='number' value='" + cc[0] + "' style='width:80px;margin-right:30px'/>\
|
||||
<span>" + lan.soft.waf_input7 + "(" + lan.bt.s + ")</span><input id='CCrate_2' class='bt-input-text' type='number' value='" + cc[1] + "' style='width:80px;'/>\
|
||||
<button onclick=\"SetWafConfig('CCrate','')\" class='btn btn-default btn-sm'>" + lan.public.ok + "</button>\
|
||||
</div>\
|
||||
<div class='wafConf_ip'>\
|
||||
<fieldset>\
|
||||
<legend>" + lan.soft.waf_input8 + "</legend>\
|
||||
<input type='text' id='ipWhitelist_val' class='bt-input-text mr5' placeholder='" + lan.soft.waf_ip + "' style='width:175px;' /><button onclick=\"addWafKey('ipWhitelist')\" class='btn btn-default btn-sm'>" + lan.public.add + "</button>\
|
||||
<div class='table-overflow'><table class='table table-hover'>" + whiteList + "</table></div>\
|
||||
</fieldset>\
|
||||
<fieldset>\
|
||||
<legend>" + lan.soft.waf_input9 + "</legend>\
|
||||
<input type='text' id='ipBlocklist_val' class='bt-input-text mr5' placeholder='" + lan.soft.waf_ip + "' style='width:175px;' /><button onclick=\"addWafKey('ipBlocklist')\" class='btn btn-default btn-sm'>" + lan.public.add + "</button>\
|
||||
<div class='table-overflow'><table class='table table-hover'>" + blackList + "</table></div>\
|
||||
</fieldset>\
|
||||
</div>\
|
||||
</div>"
|
||||
$(".soft-man-con").html(con);
|
||||
});
|
||||
}
|
||||
@@ -158,7 +289,7 @@ function upLimit() {
|
||||
}
|
||||
|
||||
//设置waf状态
|
||||
function CloseWaf() {
|
||||
function closeWaf() {
|
||||
var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/waf?action=SetStatus', '', function(rdata) {
|
||||
layer.close(loadT)
|
||||
@@ -168,8 +299,8 @@ function CloseWaf() {
|
||||
}
|
||||
|
||||
//取规则文件
|
||||
function GetWafFile(name) {
|
||||
OnlineEditFile(0, '/www/server/panel/vhost/wafconf/' + name);
|
||||
function getWafFile(name) {
|
||||
onlineEditFile(0, '/www/server/panel/vhost/wafconf/' + name);
|
||||
}
|
||||
//规则编辑
|
||||
function gzEdit() {
|
||||
@@ -180,13 +311,13 @@ function gzEdit() {
|
||||
closeBtn: 2,
|
||||
shift: 0,
|
||||
content: "<div class='gzEdit'><button class='btn btn-default btn-sm' onclick=\"GetWafFile('cookie')\">Cookie</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('post')\">POST</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('url')\">URL</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('user-agent')\">User-Agent</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('args')\">Args</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('whiteurl')\">" + lan.soft.waf_url_white + "</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('returnhtml')\">" + lan.soft.waf_index + "</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"updateWaf('returnhtml')\">" + lan.soft.waf_cloud + "</button></div>"
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('post')\">POST</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('url')\">URL</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('user-agent')\">User-Agent</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('args')\">Args</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('whiteurl')\">" + lan.soft.waf_url_white + "</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"GetWafFile('returnhtml')\">" + lan.soft.waf_index + "</button>\
|
||||
<button class='btn btn-default btn-sm' onclick=\"updateWaf('returnhtml')\">" + lan.soft.waf_cloud + "</button></div>"
|
||||
});
|
||||
}
|
||||
|
||||
@@ -200,7 +331,7 @@ function updateWaf() {
|
||||
}
|
||||
|
||||
//设置WAF配置值
|
||||
function SetWafConfig(name, value) {
|
||||
function setWafConfig(name, value) {
|
||||
if (name == 'CCrate') {
|
||||
var CCrate_1 = $("#CCrate_1").val();
|
||||
var CCrate_2 = $("#CCrate_2").val();
|
||||
@@ -242,21 +373,3 @@ function addWafKey(name) {
|
||||
if (name == 'black_fileExt') upLimit();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
//查看Nginx负载状态
|
||||
function GetNginxStatus() {
|
||||
$.post('/ajax?action=GetNginxStatus', '', function(rdata) {
|
||||
var con = "<div><table class='table table-hover table-bordered'>\
|
||||
<tr><th>" + lan.bt.nginx_active + "</th><td>" + rdata.active + "</td></tr>\
|
||||
<tr><th>" + lan.bt.nginx_accepts + "</th><td>" + rdata.accepts + "</td></tr>\
|
||||
<tr><th>" + lan.bt.nginx_handled + "</th><td>" + rdata.handled + "</td></tr>\
|
||||
<tr><th>" + lan.bt.nginx_requests + "</th><td>" + rdata.requests + "</td></tr>\
|
||||
<tr><th>" + lan.bt.nginx_reading + "</th><td>" + rdata.Reading + "</td></tr>\
|
||||
<tr><th>" + lan.bt.nginx_writing + "</th><td>" + rdata.Writing + "</td></tr>\
|
||||
<tr><th>" + lan.bt.nginx_waiting + "</th><td>" + rdata.Waiting + "</td></tr>\
|
||||
</table></div>";
|
||||
$(".soft-man-con").html(con);
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/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/bt_install.pl
|
||||
openrestyDir=${serverPath}/source/openresty
|
||||
|
||||
Install_openresty()
|
||||
{
|
||||
mkdir -p ${openrestyDir}
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
if [ ! -f ${openrestyDir}/openresty-1.11.2.5.tar.gz ];then
|
||||
wget -O ${openrestyDir}/openresty-1.11.2.5.tar.gz https://openresty.org/download/openresty-1.11.2.5.tar.gz
|
||||
fi
|
||||
|
||||
|
||||
cd ${openrestyDir} && tar -zxvf openresty-1.11.2.5.tar.gz
|
||||
|
||||
cd ${openrestyDir}/openresty-1.11.2.5 && ./configure --prefix=$serverPath/openresty \
|
||||
--with-openssl=$serverPath/source/lib/openssl-1.0.2q \
|
||||
--with-http_stub_status_module && make && make install && \
|
||||
echo '1.11.2' > $serverPath/openresty/version.pl
|
||||
|
||||
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_openresty()
|
||||
{
|
||||
rm -rf $serverPath/openresty
|
||||
echo '卸载完成' > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_openresty
|
||||
else
|
||||
Uninstall_openresty
|
||||
fi
|
||||
@@ -19,12 +19,15 @@ Install_openresty()
|
||||
if [ ! -f ${openrestyDir}/openresty-1.13.6.2.tar.gz ];then
|
||||
wget -O ${openrestyDir}/openresty-1.13.6.2.tar.gz https://openresty.org/download/openresty-1.13.6.2.tar.gz
|
||||
fi
|
||||
|
||||
cd ${openrestyDir} && tar -zxvf openresty-1.13.6.2.tar.gz
|
||||
|
||||
cd ${openrestyDir}/openresty* && ./configure --prefix=$serverPath/openresty \
|
||||
--with-openssl=$serverPath/source/lib/openssl-1.0.2q && make && make install
|
||||
cd ${openrestyDir}/openresty-1.13.6.2 && ./configure --prefix=$serverPath/openresty \
|
||||
--with-openssl=$serverPath/source/lib/openssl-1.0.2q \
|
||||
--with-http_stub_status_module \
|
||||
&& make && make install && \
|
||||
echo '1.13.6' > $serverPath/openresty/version.pl
|
||||
|
||||
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
@@ -33,9 +36,7 @@ Uninstall_openresty()
|
||||
rm -rf $serverPath/openresty
|
||||
echo '卸载完成' > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
host=$2
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_openresty
|
||||
else
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
location ~ [^/]\.php(/|$)
|
||||
{
|
||||
try_files $uri =404;
|
||||
fastcgi_pass unix:/tmp/php-cgi-{$PHP_VERSION}.sock;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi.conf;
|
||||
include pathinfo.conf;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
set $real_script_name $fastcgi_script_name;
|
||||
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
|
||||
set $real_script_name $1;
|
||||
set $path_info $2;
|
||||
}
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
|
||||
fastcgi_param SCRIPT_NAME $real_script_name;
|
||||
fastcgi_param PATH_INFO $path_info;
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
[global]
|
||||
include={$SERVER_PATH}/php/{$PHP_VERSION}/etc/php-fpm.d/*.conf
|
||||
;php_value[auto_prepend_file]={$SERVER_PATH}/md_start.php
|
||||
;php_value[auto_append_file]={$SERVER_PATH}/md_end.php
|
||||
@@ -0,0 +1,237 @@
|
||||
[PHP]
|
||||
engine = On
|
||||
short_open_tag = On
|
||||
asp_tags = Off
|
||||
precision = 14
|
||||
output_buffering = 4096
|
||||
zlib.output_compression = Off
|
||||
implicit_flush = Off
|
||||
unserialize_callback_func =
|
||||
serialize_precision = 17
|
||||
zend.enable_gc = On
|
||||
expose_php = On
|
||||
max_execution_time = 30
|
||||
max_input_time = 60
|
||||
memory_limit = 128M
|
||||
error_reporting = E_ALL
|
||||
display_errors = On
|
||||
display_startup_errors = On
|
||||
log_errors = On
|
||||
log_errors_max_len = 1024
|
||||
ignore_repeated_errors = Off
|
||||
ignore_repeated_source = Off
|
||||
report_memleaks = On
|
||||
track_errors = On
|
||||
html_errors = On
|
||||
variables_order = "GPCS"
|
||||
request_order = "GP"
|
||||
register_argc_argv = Off
|
||||
auto_globals_jit = On
|
||||
post_max_size = 8M
|
||||
auto_prepend_file =
|
||||
auto_append_file =
|
||||
default_mimetype = "text/html"
|
||||
doc_root =
|
||||
user_dir =
|
||||
enable_dl = Off
|
||||
|
||||
|
||||
file_uploads = On
|
||||
upload_tmp_dir = "/tmp"
|
||||
upload_max_filesize = 2M
|
||||
max_file_uploads = 20
|
||||
|
||||
allow_url_fopen = On
|
||||
allow_url_include = Off
|
||||
default_socket_timeout = 60
|
||||
|
||||
disable_functions = phpinfo,exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source
|
||||
|
||||
[CLI Server]
|
||||
cli_server.color = On
|
||||
|
||||
[Date]
|
||||
date.timezone = PRC
|
||||
|
||||
[filter]
|
||||
[iconv]
|
||||
iconv.input_encoding = ISO-8859-1
|
||||
iconv.internal_encoding = ISO-8859-1
|
||||
iconv.output_encoding = ISO-8859-1
|
||||
|
||||
[intl]
|
||||
[sqlite]
|
||||
[sqlite3]
|
||||
[Pcre]
|
||||
[Pdo]
|
||||
|
||||
|
||||
[Pdo_mysql]
|
||||
pdo_mysql.cache_size = 2000
|
||||
pdo_mysql.default_socket=
|
||||
|
||||
[Phar]
|
||||
|
||||
[mail function]
|
||||
SMTP = localhost
|
||||
smtp_port = 25
|
||||
mail.add_x_header = On
|
||||
|
||||
|
||||
[SQL]
|
||||
sql.safe_mode = Off
|
||||
|
||||
[ODBC]
|
||||
odbc.allow_persistent = On
|
||||
odbc.check_persistent = On
|
||||
odbc.max_persistent = -1
|
||||
odbc.max_links = -1
|
||||
odbc.defaultlrl = 4096
|
||||
odbc.defaultbinmode = 1
|
||||
|
||||
|
||||
[Interbase]
|
||||
ibase.allow_persistent = 1
|
||||
ibase.max_persistent = -1
|
||||
ibase.max_links = -1
|
||||
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
|
||||
ibase.dateformat = "%Y-%m-%d"
|
||||
ibase.timeformat = "%H:%M:%S"
|
||||
|
||||
[MySQL]
|
||||
mysql.allow_local_infile = On
|
||||
mysql.allow_persistent = On
|
||||
mysql.cache_size = 2000
|
||||
mysql.max_persistent = -1
|
||||
mysql.max_links = -1
|
||||
mysql.default_port =
|
||||
mysql.default_socket =
|
||||
mysql.default_host =
|
||||
mysql.default_user =
|
||||
mysql.default_password =
|
||||
mysql.connect_timeout = 60
|
||||
mysql.trace_mode = Off
|
||||
|
||||
[MySQLi]
|
||||
mysqli.max_persistent = -1
|
||||
mysqli.allow_persistent = On
|
||||
mysqli.max_links = -1
|
||||
mysqli.cache_size = 2000
|
||||
mysqli.default_port = 3306
|
||||
mysqli.default_socket =
|
||||
mysqli.default_host =
|
||||
mysqli.default_user =
|
||||
mysqli.default_pw =
|
||||
mysqli.reconnect = Off
|
||||
|
||||
[mysqlnd]
|
||||
mysqlnd.collect_statistics = On
|
||||
mysqlnd.collect_memory_statistics = On
|
||||
|
||||
[OCI8]
|
||||
|
||||
|
||||
[PostgreSQL]
|
||||
pgsql.allow_persistent = On
|
||||
pgsql.auto_reset_persistent = Off
|
||||
pgsql.max_persistent = -1
|
||||
pgsql.max_links = -1
|
||||
pgsql.ignore_notice = 0
|
||||
pgsql.log_notice = 0
|
||||
|
||||
[Sybase-CT]
|
||||
sybct.allow_persistent = On
|
||||
sybct.max_persistent = -1
|
||||
sybct.max_links = -1
|
||||
sybct.min_server_severity = 10
|
||||
sybct.min_client_severity = 10
|
||||
|
||||
|
||||
[bcmath]
|
||||
bcmath.scale = 0
|
||||
|
||||
[browscap]
|
||||
|
||||
[Session]
|
||||
session.save_handler = files
|
||||
session.save_path = "MD:/bin/tmp/session"
|
||||
session.use_strict_mode = 0
|
||||
session.use_cookies = 1
|
||||
session.use_only_cookies = 1
|
||||
session.name = PHPSESSID
|
||||
session.auto_start = 0
|
||||
session.cookie_lifetime = 0
|
||||
session.cookie_path = /
|
||||
session.cookie_domain =
|
||||
session.cookie_httponly =
|
||||
session.serialize_handler = php
|
||||
session.gc_probability = 1
|
||||
session.gc_divisor = 1000
|
||||
session.gc_maxlifetime = 1440
|
||||
session.referer_check =
|
||||
session.cache_limiter = nocache
|
||||
session.cache_expire = 180
|
||||
session.use_trans_sid = 0
|
||||
session.hash_function = 0
|
||||
session.hash_bits_per_character = 5
|
||||
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
|
||||
|
||||
|
||||
[MSSQL]
|
||||
mssql.allow_persistent = On
|
||||
mssql.max_persistent = -1
|
||||
mssql.max_links = -1
|
||||
mssql.min_error_severity = 10
|
||||
mssql.min_message_severity = 10
|
||||
mssql.compatibility_mode = Off
|
||||
mssql.secure_connection = Off
|
||||
|
||||
[Assertion]
|
||||
[COM]
|
||||
[mbstring]
|
||||
[gd]
|
||||
[exif]
|
||||
[Tidy]
|
||||
|
||||
tidy.clean_output = Off
|
||||
|
||||
[soap]
|
||||
soap.wsdl_cache_enabled=1
|
||||
soap.wsdl_cache_dir="/tmp"
|
||||
soap.wsdl_cache_ttl=86400
|
||||
soap.wsdl_cache_limit = 5
|
||||
|
||||
[sysvshm]
|
||||
|
||||
[ldap]
|
||||
ldap.max_links = -1
|
||||
|
||||
[mcrypt]
|
||||
|
||||
|
||||
[dba]
|
||||
[curl]
|
||||
[Zend Opcache]
|
||||
|
||||
;[xhprof]
|
||||
;extension=md_xhprof.so
|
||||
;xhprof.output_dir="MD:/bin/tmp/xhprof"
|
||||
|
||||
|
||||
;extension=igbinary.so
|
||||
;extension=iconv.so
|
||||
;extension=yaf.so
|
||||
;extension=swoole.so
|
||||
;extension=curl.so
|
||||
;extension=bcmath.so
|
||||
;extension=mcrypt.so
|
||||
;extension=gd.so
|
||||
;extension=openssl.so
|
||||
;extension=intl.so
|
||||
;extension=gettext.so
|
||||
;extension=imagick.so
|
||||
;extension=redis.so
|
||||
;extension=mongodb.so
|
||||
;extension=memcached.so
|
||||
;extension=phalcon.so
|
||||
;extension=opencv.so
|
||||
@@ -0,0 +1,236 @@
|
||||
[PHP]
|
||||
engine = On
|
||||
short_open_tag = On
|
||||
asp_tags = Off
|
||||
precision = 14
|
||||
output_buffering = 4096
|
||||
zlib.output_compression = Off
|
||||
implicit_flush = Off
|
||||
unserialize_callback_func =
|
||||
serialize_precision = 17
|
||||
zend.enable_gc = On
|
||||
expose_php = On
|
||||
max_execution_time = 30
|
||||
max_input_time = 60
|
||||
memory_limit = 128M
|
||||
error_reporting = E_ALL
|
||||
display_errors = On
|
||||
display_startup_errors = On
|
||||
log_errors = On
|
||||
log_errors_max_len = 1024
|
||||
ignore_repeated_errors = Off
|
||||
ignore_repeated_source = Off
|
||||
report_memleaks = On
|
||||
html_errors = On
|
||||
variables_order = "GPCS"
|
||||
request_order = "GP"
|
||||
register_argc_argv = Off
|
||||
auto_globals_jit = On
|
||||
post_max_size = 8M
|
||||
auto_prepend_file =
|
||||
auto_append_file =
|
||||
default_mimetype = "text/html"
|
||||
doc_root =
|
||||
user_dir =
|
||||
enable_dl = Off
|
||||
|
||||
|
||||
file_uploads = On
|
||||
upload_tmp_dir = "MD:/bin/tmp/upload"
|
||||
upload_max_filesize = 2M
|
||||
max_file_uploads = 20
|
||||
|
||||
allow_url_fopen = On
|
||||
allow_url_include = Off
|
||||
default_socket_timeout = 60
|
||||
|
||||
disable_functions = phpinfo,exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source
|
||||
|
||||
[CLI Server]
|
||||
cli_server.color = On
|
||||
|
||||
[Date]
|
||||
date.timezone = PRC
|
||||
|
||||
[filter]
|
||||
[iconv]
|
||||
iconv.input_encoding = ISO-8859-1
|
||||
iconv.internal_encoding = ISO-8859-1
|
||||
iconv.output_encoding = ISO-8859-1
|
||||
|
||||
[intl]
|
||||
[sqlite]
|
||||
[sqlite3]
|
||||
[Pcre]
|
||||
[Pdo]
|
||||
|
||||
|
||||
[Pdo_mysql]
|
||||
pdo_mysql.cache_size = 2000
|
||||
pdo_mysql.default_socket=
|
||||
|
||||
[Phar]
|
||||
|
||||
[mail function]
|
||||
SMTP = localhost
|
||||
smtp_port = 25
|
||||
mail.add_x_header = On
|
||||
|
||||
|
||||
[SQL]
|
||||
sql.safe_mode = Off
|
||||
|
||||
[ODBC]
|
||||
odbc.allow_persistent = On
|
||||
odbc.check_persistent = On
|
||||
odbc.max_persistent = -1
|
||||
odbc.max_links = -1
|
||||
odbc.defaultlrl = 4096
|
||||
odbc.defaultbinmode = 1
|
||||
|
||||
|
||||
[Interbase]
|
||||
ibase.allow_persistent = 1
|
||||
ibase.max_persistent = -1
|
||||
ibase.max_links = -1
|
||||
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
|
||||
ibase.dateformat = "%Y-%m-%d"
|
||||
ibase.timeformat = "%H:%M:%S"
|
||||
|
||||
[MySQL]
|
||||
mysql.allow_local_infile = On
|
||||
mysql.allow_persistent = On
|
||||
mysql.cache_size = 2000
|
||||
mysql.max_persistent = -1
|
||||
mysql.max_links = -1
|
||||
mysql.default_port =
|
||||
mysql.default_socket =
|
||||
mysql.default_host =
|
||||
mysql.default_user =
|
||||
mysql.default_password =
|
||||
mysql.connect_timeout = 60
|
||||
mysql.trace_mode = Off
|
||||
|
||||
[MySQLi]
|
||||
mysqli.max_persistent = -1
|
||||
mysqli.allow_persistent = On
|
||||
mysqli.max_links = -1
|
||||
mysqli.cache_size = 2000
|
||||
mysqli.default_port = 3306
|
||||
mysqli.default_socket =
|
||||
mysqli.default_host =
|
||||
mysqli.default_user =
|
||||
mysqli.default_pw =
|
||||
mysqli.reconnect = Off
|
||||
|
||||
[mysqlnd]
|
||||
mysqlnd.collect_statistics = On
|
||||
mysqlnd.collect_memory_statistics = On
|
||||
|
||||
[OCI8]
|
||||
|
||||
|
||||
[PostgreSQL]
|
||||
pgsql.allow_persistent = On
|
||||
pgsql.auto_reset_persistent = Off
|
||||
pgsql.max_persistent = -1
|
||||
pgsql.max_links = -1
|
||||
pgsql.ignore_notice = 0
|
||||
pgsql.log_notice = 0
|
||||
|
||||
[Sybase-CT]
|
||||
sybct.allow_persistent = On
|
||||
sybct.max_persistent = -1
|
||||
sybct.max_links = -1
|
||||
sybct.min_server_severity = 10
|
||||
sybct.min_client_severity = 10
|
||||
|
||||
|
||||
[bcmath]
|
||||
bcmath.scale = 0
|
||||
|
||||
[browscap]
|
||||
|
||||
[Session]
|
||||
session.save_handler = files
|
||||
session.save_path = "MD:/bin/tmp/session"
|
||||
session.use_strict_mode = 0
|
||||
session.use_cookies = 1
|
||||
session.use_only_cookies = 1
|
||||
session.name = PHPSESSID
|
||||
session.auto_start = 0
|
||||
session.cookie_lifetime = 0
|
||||
session.cookie_path = /
|
||||
session.cookie_domain =
|
||||
session.cookie_httponly =
|
||||
session.serialize_handler = php
|
||||
session.gc_probability = 1
|
||||
session.gc_divisor = 1000
|
||||
session.gc_maxlifetime = 1440
|
||||
session.referer_check =
|
||||
session.cache_limiter = nocache
|
||||
session.cache_expire = 180
|
||||
session.use_trans_sid = 0
|
||||
session.hash_function = 0
|
||||
session.hash_bits_per_character = 5
|
||||
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
|
||||
|
||||
|
||||
[MSSQL]
|
||||
mssql.allow_persistent = On
|
||||
mssql.max_persistent = -1
|
||||
mssql.max_links = -1
|
||||
mssql.min_error_severity = 10
|
||||
mssql.min_message_severity = 10
|
||||
mssql.compatibility_mode = Off
|
||||
mssql.secure_connection = Off
|
||||
|
||||
[Assertion]
|
||||
[COM]
|
||||
[mbstring]
|
||||
[gd]
|
||||
[exif]
|
||||
[Tidy]
|
||||
|
||||
tidy.clean_output = Off
|
||||
|
||||
[soap]
|
||||
soap.wsdl_cache_enabled=1
|
||||
soap.wsdl_cache_dir="/tmp"
|
||||
soap.wsdl_cache_ttl=86400
|
||||
soap.wsdl_cache_limit = 5
|
||||
|
||||
[sysvshm]
|
||||
|
||||
[ldap]
|
||||
ldap.max_links = -1
|
||||
|
||||
[mcrypt]
|
||||
|
||||
|
||||
[dba]
|
||||
[curl]
|
||||
[Zend Opcache]
|
||||
|
||||
;[xhprof]
|
||||
;extension=md_xhprof.so
|
||||
;xhprof.output_dir="MD:/bin/tmp/xhprof"
|
||||
|
||||
|
||||
;extension=igbinary.so
|
||||
;extension=iconv.so
|
||||
;extension=yaf.so
|
||||
;extension=swoole.so
|
||||
;extension=curl.so
|
||||
;extension=bcmath.so
|
||||
;extension=mcrypt.so
|
||||
;extension=gd.so
|
||||
;extension=openssl.so
|
||||
;extension=intl.so
|
||||
;extension=gettext.so
|
||||
;extension=imagick.so
|
||||
;extension=redis.so
|
||||
;extension=mongodb.so
|
||||
;extension=memcached.so
|
||||
;extension=phalcon.so
|
||||
;extension=opencv.so
|
||||
@@ -0,0 +1,5 @@
|
||||
location /phpfpm_status_{$PHP_VERSION} {
|
||||
fastcgi_pass unix:/tmp/php-cgi-{$PHP_VERSION}.sock;
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
location /{$PHP_VERSION} {
|
||||
root {$ROOT_PATH}/phpinfo;
|
||||
include enable-php-{$PHP_VERSION}.conf;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
[www]
|
||||
user = {$PHP_USER}
|
||||
group = {$PHP_GROUP}
|
||||
listen = /tmp/php-cgi-{$PHP_VERSION}.sock
|
||||
pm = dynamic
|
||||
pm.max_children = 5
|
||||
pm.start_servers = 2
|
||||
pm.min_spare_servers = 1
|
||||
pm.max_spare_servers = 3
|
||||
pm.status_path = /phpfpm_status_{$PHP_VERSION}
|
||||
|
||||
|
||||
request_slowlog_timeout = 1
|
||||
slowlog = {$SERVER_PATH}/php/{$PHP_VERSION}/var/log/www-slow.log
|
||||
|
Before Width: | Height: | Size: 987 B After Width: | Height: | Size: 786 B |
@@ -1,18 +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="redisService();">服务</p>
|
||||
<p onclick="redisConfig();">安装扩展</p>
|
||||
<p onclick="redisConfig();">配置修改</p>
|
||||
<p onclick="redisConfig();">上传限制</p>
|
||||
<p onclick="redisStatus();">超时限制</p>
|
||||
<p onclick="redisStatus();">配置文件</p>
|
||||
<p onclick="redisStatus();">禁用函数</p>
|
||||
<p onclick="redisStatus();">性能调整</p>
|
||||
<p onclick="redisStatus();">负载状况</p>
|
||||
<p onclick="redisStatus();">FPM日志</p>
|
||||
<p onclick="redisStatus();">慢日志</p>
|
||||
<p onclick="redisStatus();">PHPIFNO</p>
|
||||
<p class="bgw" onclick="pluginService('php', $('.plugin_version').attr('version'));">服务</p>
|
||||
<p onclick="phpLibConfig($('.plugin_version').attr('version'));">安装扩展</p>
|
||||
<p onclick="phpSetConfig($('.plugin_version').attr('version'));">配置修改</p>
|
||||
<p onclick="phpUploadLimitReq($('.plugin_version').attr('version'));">上传限制</p>
|
||||
<p onclick="phpTimeLimitReq($('.plugin_version').attr('version'));">超时限制</p>
|
||||
<p onclick="pluginConfig('php', $('.plugin_version').attr('version'));">配置文件</p>
|
||||
<p onclick="disableFunc($('.plugin_version').attr('version'));">禁用函数</p>
|
||||
<p onclick="getFpmConfig($('.plugin_version').attr('version'));">性能调整</p>
|
||||
<p onclick="getFpmStatus($('.plugin_version').attr('version'));">负载状况</p>
|
||||
<p onclick="pluginLogs('php',$('.plugin_version').attr('version'),'fpm_log');">FPM日志</p>
|
||||
<p onclick="pluginLogs('php',$('.plugin_version').attr('version'),'fpm_slow_log');">慢日志</p>
|
||||
<p onclick="getPhpinfo($('.plugin_version').attr('version'));">PHPIFNO</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
@@ -21,5 +22,8 @@
|
||||
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=php&f=js/php.js");
|
||||
$.getScript( "/plugins/file?name=php&f=js/php.js", function(){
|
||||
pluginService('php', $('.plugin_version').attr('version'));
|
||||
});
|
||||
|
||||
</script>
|
||||
@@ -4,93 +4,551 @@ import sys
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
import shutil
|
||||
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf8')
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
"ps -ef|grep redis |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
|
||||
def getPluginName():
|
||||
return 'php'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[3:]
|
||||
tmp = {}
|
||||
args_len = len(args)
|
||||
|
||||
if args_len == 1:
|
||||
t = args[0].strip('{').strip('}')
|
||||
t = t.split(':')
|
||||
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 getConf(version):
|
||||
path = getServerDir() + '/' + version + '/etc/php.ini'
|
||||
return path
|
||||
|
||||
|
||||
def status(version):
|
||||
cmd = "ps -ef|grep 'php/" + version + \
|
||||
"' |grep -v grep | grep -v python | awk '{print $2}'"
|
||||
data = public.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def start():
|
||||
path = os.path.dirname(os.getcwd())
|
||||
cmd = path + "/redis/bin/redis-server"
|
||||
cmd = cmd + " " + path + "/redis/redis.conf"
|
||||
data = public.execShell(cmd)
|
||||
if data[0] == '':
|
||||
def contentReplace(content, version):
|
||||
service_path = public.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', public.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$PHP_VERSION}', version)
|
||||
|
||||
if public.isAppleSystem():
|
||||
# user = public.execShell(
|
||||
# "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
content = content.replace('{$PHP_USER}', 'nobody')
|
||||
content = content.replace('{$PHP_GROUP}', 'nobody')
|
||||
|
||||
rep = 'user\s*=\s*(.+)\r?\n'
|
||||
val = ';user = nobody\n'
|
||||
content = re.sub(rep, val, content)
|
||||
|
||||
rep = 'group\s*=\s*(.+)\r?\n'
|
||||
val = ';group = nobody\n'
|
||||
content = re.sub(rep, val, content)
|
||||
else:
|
||||
content = content.replace('{$PHP_USER}', 'www')
|
||||
content = content.replace('{$PHP_GROUP}', 'www')
|
||||
return content
|
||||
|
||||
|
||||
def makeOpenrestyConf():
|
||||
if public.isInstalledWeb():
|
||||
d_pathinfo = public.getServerDir() + '/openresty/nginx/conf/pathinfo.conf'
|
||||
if not os.path.exists(d_pathinfo):
|
||||
s_pathinfo = getPluginDir() + '/conf/pathinfo.conf'
|
||||
shutil.copyfile(s_pathinfo, d_pathinfo)
|
||||
|
||||
info = getPluginDir() + '/info.json'
|
||||
content = public.readFile(info)
|
||||
content = json.loads(content)
|
||||
versions = content['versions']
|
||||
tpl = getPluginDir() + '/conf/enable-php.conf'
|
||||
tpl_content = public.readFile(tpl)
|
||||
for x in range(len(versions)):
|
||||
desc_file = public.getServerDir() + '/openresty/nginx/conf/enable-php-' + \
|
||||
versions[x] + '.conf'
|
||||
if not os.path.exists(desc_file):
|
||||
w_content = contentReplace(tpl_content, versions[x])
|
||||
public.writeFile(desc_file, w_content)
|
||||
|
||||
|
||||
def phpFpmReplace(version):
|
||||
desc_php_fpm = getServerDir() + '/' + version + '/etc/php-fpm.conf'
|
||||
if not os.path.exists(desc_php_fpm):
|
||||
tpl_php_fpm = getPluginDir() + '/conf/php-fpm.conf'
|
||||
content = public.readFile(tpl_php_fpm)
|
||||
content = contentReplace(content, version)
|
||||
public.writeFile(desc_php_fpm, content)
|
||||
|
||||
|
||||
def phpFpmWwwReplace(version):
|
||||
service_php_fpm_dir = getServerDir() + '/' + version + '/etc/php-fpm.d/'
|
||||
|
||||
if not os.path.exists(service_php_fpm_dir):
|
||||
os.mkdir(service_php_fpm_dir)
|
||||
|
||||
service_php_fpmwww = service_php_fpm_dir + '/www.conf'
|
||||
if not os.path.exists(service_php_fpmwww):
|
||||
tpl_php_fpmwww = getPluginDir() + '/conf/www.conf'
|
||||
content = public.readFile(tpl_php_fpmwww)
|
||||
content = contentReplace(content, version)
|
||||
public.writeFile(service_php_fpmwww, content)
|
||||
|
||||
|
||||
def makePhpIni(version):
|
||||
d_ini = public.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
if not os.path.exists(d_ini):
|
||||
s_ini = getPluginDir() + '/conf/php' + version + '.ini'
|
||||
shutil.copyfile(s_ini, d_ini)
|
||||
|
||||
|
||||
def initReplace(version):
|
||||
makeOpenrestyConf()
|
||||
makePhpIni(version)
|
||||
|
||||
initD_path = getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
os.mkdir(initD_path)
|
||||
|
||||
file_bin = initD_path + '/php' + version
|
||||
if not os.path.exists(file_bin):
|
||||
file_tpl = getPluginDir() + '/init.d/php.tpl'
|
||||
|
||||
content = public.readFile(file_tpl)
|
||||
content = contentReplace(content, version)
|
||||
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
|
||||
phpFpmWwwReplace(version)
|
||||
phpFpmReplace(version)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def phpOp(version, method):
|
||||
file = initReplace(version)
|
||||
data = public.execShell(file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
return data[1]
|
||||
|
||||
|
||||
def stop():
|
||||
data = public.execShell(
|
||||
"ps -ef|grep redis |grep -v grep |grep -v python |awk '{print $2}' | xargs kill -9")
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
def start(version):
|
||||
return phpOp(version, 'start')
|
||||
|
||||
|
||||
def restart():
|
||||
return 'ok'
|
||||
def stop(version):
|
||||
return phpOp(version, 'stop')
|
||||
|
||||
|
||||
def reload():
|
||||
return 'ok'
|
||||
def restart(version):
|
||||
return phpOp(version, 'restart')
|
||||
|
||||
|
||||
def runInfo():
|
||||
path = os.path.dirname(os.getcwd())
|
||||
cmd = path + "/redis/bin/redis-cli info"
|
||||
data = public.execShell(cmd)[0]
|
||||
res = [
|
||||
'tcp_port',
|
||||
'uptime_in_days', # 已运行天数
|
||||
'connected_clients', # 连接的客户端数量
|
||||
'used_memory', # Redis已分配的内存总量
|
||||
'used_memory_rss', # Redis占用的系统内存总量
|
||||
'used_memory_peak', # Redis所用内存的高峰值
|
||||
'mem_fragmentation_ratio', # 内存碎片比率
|
||||
'total_connections_received', # 运行以来连接过的客户端的总数量
|
||||
'total_commands_processed', # 运行以来执行过的命令的总数量
|
||||
'instantaneous_ops_per_sec', # 服务器每秒钟执行的命令数量
|
||||
'keyspace_hits', # 查找数据库键成功的次数
|
||||
'keyspace_misses', # 查找数据库键失败的次数
|
||||
'latest_fork_usec' # 最近一次 fork() 操作耗费的毫秒数
|
||||
def reload(version):
|
||||
return phpOp(version, 'reload')
|
||||
|
||||
|
||||
def fpmLog(version):
|
||||
return getServerDir() + '/' + version + '/var/log/php-fpm.log'
|
||||
|
||||
|
||||
def fpmSlowLog(version):
|
||||
return getServerDir() + '/' + version + '/var/log/www-slow.log'
|
||||
|
||||
|
||||
def getPhpConf(version):
|
||||
gets = [
|
||||
{'name': 'short_open_tag', 'type': 1, 'ps': '短标签支持'},
|
||||
{'name': 'asp_tags', 'type': 1, 'ps': 'ASP标签支持'},
|
||||
{'name': 'max_execution_time', 'type': 2, 'ps': '最大脚本运行时间'},
|
||||
{'name': 'max_input_time', 'type': 2, 'ps': '最大输入时间'},
|
||||
{'name': 'memory_limit', 'type': 2, 'ps': '脚本内存限制'},
|
||||
{'name': 'post_max_size', 'type': 2, 'ps': 'POST数据最大尺寸'},
|
||||
{'name': 'file_uploads', 'type': 1, 'ps': '是否允许上传文件'},
|
||||
{'name': 'upload_max_filesize', 'type': 2, 'ps': '允许上传文件的最大尺寸'},
|
||||
{'name': 'max_file_uploads', 'type': 2, 'ps': '允许同时上传文件的最大数量'},
|
||||
{'name': 'default_socket_timeout', 'type': 2, 'ps': 'Socket超时时间'},
|
||||
{'name': 'error_reporting', 'type': 3, 'ps': '错误级别'},
|
||||
{'name': 'display_errors', 'type': 1, 'ps': '是否输出详细错误信息'},
|
||||
{'name': 'cgi.fix_pathinfo', 'type': 0, 'ps': '是否开启pathinfo'},
|
||||
{'name': 'date.timezone', 'type': 3, 'ps': '时区'}
|
||||
]
|
||||
data = data.split("\n")
|
||||
result = {}
|
||||
for d in data:
|
||||
if len(d) < 3:
|
||||
phpini = public.readFile(getServerDir() + '/' + version + '/etc/php.ini')
|
||||
result = []
|
||||
for g in gets:
|
||||
rep = g['name'] + '\s*=\s*([0-9A-Za-z_& ~]+)(\s*;?|\r?\n)'
|
||||
tmp = re.search(rep, phpini)
|
||||
if not tmp:
|
||||
continue
|
||||
t = d.strip().split(':')
|
||||
if not t[0] in res:
|
||||
continue
|
||||
result[t[0]] = t[1]
|
||||
g['value'] = tmp.groups()[0]
|
||||
result.append(g)
|
||||
return public.getJson(result)
|
||||
|
||||
|
||||
def getConf():
|
||||
path = os.path.dirname(os.getcwd()) + "/redis/redis.conf"
|
||||
return path
|
||||
def submitPhpConf(version):
|
||||
gets = ['display_errors', 'cgi.fix_pathinfo', 'date.timezone', 'short_open_tag',
|
||||
'asp_tags', 'max_execution_time', 'max_input_time', 'memory_limit',
|
||||
'post_max_size', 'file_uploads', 'upload_max_filesize', 'max_file_uploads',
|
||||
'default_socket_timeout', 'error_reporting']
|
||||
args = getArgs()
|
||||
filename = getServerDir() + '/' + version + '/etc/php.ini'
|
||||
phpini = public.readFile(filename)
|
||||
for g in gets:
|
||||
if g in args:
|
||||
rep = g + '\s*=\s*(.+)\r?\n'
|
||||
val = g + ' = ' + args[g] + '\n'
|
||||
phpini = re.sub(rep, val, phpini)
|
||||
public.writeFile(filename, phpini)
|
||||
public.execShell(getServerDir() + '/init.d/php' + version + ' reload')
|
||||
return public.returnJson(True, '设置成功')
|
||||
|
||||
|
||||
def getLimitConf(version):
|
||||
fileini = getServerDir() + "/" + version + "/etc/php.ini"
|
||||
phpini = public.readFile(fileini)
|
||||
filefpm = getServerDir() + "/" + version + "/etc/php-fpm.conf"
|
||||
phpfpm = public.readFile(filefpm)
|
||||
|
||||
# print fileini, filefpm
|
||||
data = {}
|
||||
try:
|
||||
rep = "upload_max_filesize\s*=\s*([0-9]+)M"
|
||||
tmp = re.search(rep, phpini).groups()
|
||||
data['max'] = tmp[0]
|
||||
except:
|
||||
data['max'] = '50'
|
||||
|
||||
try:
|
||||
rep = "request_terminate_timeout\s*=\s*([0-9]+)\n"
|
||||
tmp = re.search(rep, phpfpm).groups()
|
||||
data['maxTime'] = tmp[0]
|
||||
except:
|
||||
data['maxTime'] = 0
|
||||
|
||||
try:
|
||||
rep = r"\n;*\s*cgi\.fix_pathinfo\s*=\s*([0-9]+)\s*\n"
|
||||
tmp = re.search(rep, phpini).groups()
|
||||
|
||||
if tmp[0] == '1':
|
||||
data['pathinfo'] = True
|
||||
else:
|
||||
data['pathinfo'] = False
|
||||
except:
|
||||
data['pathinfo'] = False
|
||||
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
def setMaxTime(version):
|
||||
args = getArgs()
|
||||
if not 'time' in args:
|
||||
return 'missing time args!'
|
||||
time = args['time']
|
||||
if int(time) < 30 or int(time) > 86400:
|
||||
return public.returnJson(False, '请填写30-86400间的值!')
|
||||
|
||||
filefpm = getServerDir() + "/" + version + "/etc/php-fpm.conf"
|
||||
conf = public.readFile(filefpm)
|
||||
rep = "request_terminate_timeout\s*=\s*([0-9]+)\n"
|
||||
conf = re.sub(rep, "request_terminate_timeout = " + time + "\n", conf)
|
||||
public.writeFile(filefpm, conf)
|
||||
|
||||
fileini = getServerDir() + "/" + version + "/etc/php.ini"
|
||||
phpini = public.readFile(fileini)
|
||||
rep = "max_execution_time\s*=\s*([0-9]+)\r?\n"
|
||||
phpini = re.sub(rep, "max_execution_time = " + time + "\n", phpini)
|
||||
rep = "max_input_time\s*=\s*([0-9]+)\r?\n"
|
||||
phpini = re.sub(rep, "max_input_time = " + time + "\n", phpini)
|
||||
public.writeFile(fileini, phpini)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setMaxSize(version):
|
||||
args = getArgs()
|
||||
if not 'max' in args:
|
||||
return 'missing time args!'
|
||||
max = args['max']
|
||||
if int(max) < 2:
|
||||
return public.returnJson(False, '上传大小限制不能小于2MB!')
|
||||
|
||||
path = getServerDir() + '/' + version + '/etc/php.ini'
|
||||
conf = public.readFile(path)
|
||||
rep = u"\nupload_max_filesize\s*=\s*[0-9]+M"
|
||||
conf = re.sub(rep, u'\nupload_max_filesize = ' + max + 'M', conf)
|
||||
rep = u"\npost_max_size\s*=\s*[0-9]+M"
|
||||
conf = re.sub(rep, u'\npost_max_size = ' + max + 'M', conf)
|
||||
public.writeFile(path, conf)
|
||||
|
||||
# if public.get_webserver() == 'nginx':
|
||||
# path = web.ctx.session.setupPath + '/nginx/conf/nginx.conf'
|
||||
# conf = public.readFile(path)
|
||||
# rep = "client_max_body_size\s+([0-9]+)m"
|
||||
# tmp = re.search(rep, conf).groups()
|
||||
# if int(tmp[0]) < int(max):
|
||||
# conf = re.sub(rep, 'client_max_body_size ' + max + 'm', conf)
|
||||
# public.writeFile(path, conf)
|
||||
|
||||
public.writeLog("TYPE_PHP", "PHP_UPLOAD_MAX", (version, max))
|
||||
return public.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def getFpmConfig(version):
|
||||
|
||||
filefpm = getServerDir() + '/' + version + '/etc/php-fpm.d/www.conf'
|
||||
conf = public.readFile(filefpm)
|
||||
data = {}
|
||||
rep = "\s*pm.max_children\s*=\s*([0-9]+)\s*"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
data['max_children'] = tmp[0]
|
||||
|
||||
rep = "\s*pm.start_servers\s*=\s*([0-9]+)\s*"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
data['start_servers'] = tmp[0]
|
||||
|
||||
rep = "\s*pm.min_spare_servers\s*=\s*([0-9]+)\s*"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
data['min_spare_servers'] = tmp[0]
|
||||
|
||||
rep = "\s*pm.max_spare_servers \s*=\s*([0-9]+)\s*"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
data['max_spare_servers'] = tmp[0]
|
||||
|
||||
rep = "\s*pm\s*=\s*(\w+)\s*"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
data['pm'] = tmp[0]
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
def setFpmConfig(version):
|
||||
args = getArgs()
|
||||
# if not 'max' in args:
|
||||
# return 'missing time args!'
|
||||
|
||||
version = args['version']
|
||||
max_children = args['max_children']
|
||||
start_servers = args['start_servers']
|
||||
min_spare_servers = args['min_spare_servers']
|
||||
max_spare_servers = args['max_spare_servers']
|
||||
pm = args['pm']
|
||||
|
||||
file = getServerDir() + '/' + version + '/etc/php-fpm.d/www.conf'
|
||||
conf = public.readFile(file)
|
||||
|
||||
rep = "\s*pm.max_children\s*=\s*([0-9]+)\s*"
|
||||
conf = re.sub(rep, "\npm.max_children = " + max_children, conf)
|
||||
|
||||
rep = "\s*pm.start_servers\s*=\s*([0-9]+)\s*"
|
||||
conf = re.sub(rep, "\npm.start_servers = " + start_servers, conf)
|
||||
|
||||
rep = "\s*pm.min_spare_servers\s*=\s*([0-9]+)\s*"
|
||||
conf = re.sub(rep, "\npm.min_spare_servers = " +
|
||||
min_spare_servers, conf)
|
||||
|
||||
rep = "\s*pm.max_spare_servers \s*=\s*([0-9]+)\s*"
|
||||
conf = re.sub(rep, "\npm.max_spare_servers = " +
|
||||
max_spare_servers + "\n", conf)
|
||||
|
||||
rep = "\s*pm\s*=\s*(\w+)\s*"
|
||||
conf = re.sub(rep, "\npm = " + pm + "\n", conf)
|
||||
|
||||
public.writeFile(file, conf)
|
||||
reload(version)
|
||||
public.writeLog("TYPE_PHP", 'PHP_CHILDREN', (version, max_children,
|
||||
start_servers, min_spare_servers, max_spare_servers))
|
||||
return public.returnJson(True, '设置成功')
|
||||
|
||||
|
||||
def checkFpmStatusFile(version):
|
||||
if public.isInstalledWeb():
|
||||
desc_file = public.getServerDir(
|
||||
) + '/openresty/nginx/conf/php_status/phpfpm_status_' + version + '.conf'
|
||||
if not os.path.exists(desc_file):
|
||||
tpl = getPluginDir() + '/conf/phpfpm_status.conf'
|
||||
content = public.readFile(tpl)
|
||||
content = contentReplace(content, version)
|
||||
public.writeFile(desc_file, content)
|
||||
public.restartWeb()
|
||||
|
||||
|
||||
def getFpmStatus(version):
|
||||
checkFpmStatusFile(version)
|
||||
result = public.httpGet(
|
||||
'http://127.0.0.1/phpfpm_status_' + version + '?json')
|
||||
tmp = json.loads(result)
|
||||
fTime = time.localtime(int(tmp['start time']))
|
||||
tmp['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime)
|
||||
return public.getJson(tmp)
|
||||
|
||||
|
||||
def getDisableFunc(version):
|
||||
filename = public.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
if not os.path.exists(filename):
|
||||
return public.returnJson(False, '指定PHP版本不存在!')
|
||||
|
||||
phpini = public.readFile(filename)
|
||||
data = {}
|
||||
rep = "disable_functions\s*=\s{0,1}(.*)\n"
|
||||
tmp = re.search(rep, phpini).groups()
|
||||
data['disable_functions'] = tmp[0]
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
def setDisableFunc(version):
|
||||
filename = public.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
if not os.path.exists(filename):
|
||||
return public.returnJson(False, '指定PHP版本不存在!')
|
||||
|
||||
args = getArgs()
|
||||
disable_functions = args['disable_functions']
|
||||
|
||||
phpini = public.readFile(filename)
|
||||
rep = "disable_functions\s*=\s*.*\n"
|
||||
phpini = re.sub(rep, 'disable_functions = ' +
|
||||
disable_functions + "\n", phpini)
|
||||
public.writeLog('TYPE_PHP', 'PHP_DISABLE_FUNCTION',
|
||||
(version, disable_functions))
|
||||
public.writeFile(filename, phpini)
|
||||
reload(version)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def checkPhpinfoFile(version):
|
||||
if public.isInstalledWeb():
|
||||
desc_file = public.getServerDir(
|
||||
) + '/openresty/nginx/conf/php_status/phpinfo_' + version + '.conf'
|
||||
if not os.path.exists(desc_file):
|
||||
tpl = getPluginDir() + '/conf/phpinfo.conf'
|
||||
content = public.readFile(tpl)
|
||||
content = contentReplace(content, version)
|
||||
public.writeFile(desc_file, content)
|
||||
public.restartWeb()
|
||||
|
||||
|
||||
def getPhpinfo(version):
|
||||
checkPhpinfoFile(version)
|
||||
sPath = public.getRootDir() + '/phpinfo/' + version
|
||||
public.execShell("rm -rf " + public.getRootDir() + '/phpinfo')
|
||||
public.execShell("mkdir -p " + sPath)
|
||||
public.writeFile(sPath + '/phpinfo.php', '<?php phpinfo(); ?>')
|
||||
phpinfo = public.httpGet('http://127.0.0.1/' + version + '/phpinfo.php')
|
||||
os.system("rm -rf " + public.getRootDir() + '/phpinfo')
|
||||
return phpinfo
|
||||
|
||||
|
||||
def getLibConf(version):
|
||||
fname = public.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
if not os.path.exists(filename):
|
||||
return public.returnJson(False, '指定PHP版本不存在!')
|
||||
|
||||
data = {}
|
||||
rep = "disable_functions\s*=\s{0,1}(.*)\n"
|
||||
tmp = re.search(rep, phpini).groups()
|
||||
data['disable_functions'] = tmp[0]
|
||||
|
||||
rep = "upload_max_filesize\s*=\s*([0-9]+)(M|m|K|k)"
|
||||
tmp = re.search(rep, phpini).groups()
|
||||
data['max'] = tmp[0]
|
||||
|
||||
rep = ur"\n;*\s*cgi\.fix_pathinfo\s*=\s*([0-9]+)\s*\n"
|
||||
tmp = re.search(rep, phpini).groups()
|
||||
if tmp[0] == '0':
|
||||
data['pathinfo'] = False
|
||||
else:
|
||||
data['pathinfo'] = True
|
||||
return public.getJson(data)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print 'missing parameters'
|
||||
exit(0)
|
||||
|
||||
func = sys.argv[1]
|
||||
if func == 'run_info':
|
||||
print runInfo()
|
||||
elif func == 'conf':
|
||||
print getConf()
|
||||
elif func == 'status':
|
||||
print status()
|
||||
version = sys.argv[2]
|
||||
|
||||
if func == 'status':
|
||||
print status(version)
|
||||
elif func == 'start':
|
||||
print start()
|
||||
print start(version)
|
||||
elif func == 'stop':
|
||||
print stop()
|
||||
print stop(version)
|
||||
elif func == 'restart':
|
||||
print restart()
|
||||
print restart(version)
|
||||
elif func == 'reload':
|
||||
print reload()
|
||||
print reload(version)
|
||||
elif func == 'fpm_log':
|
||||
print fpmLog(version)
|
||||
elif func == 'fpm_slow_log':
|
||||
print fpmSlowLog(version)
|
||||
elif func == 'conf':
|
||||
print getConf(version)
|
||||
elif func == 'get_php_conf':
|
||||
print getPhpConf(version)
|
||||
elif func == 'submit_php_conf':
|
||||
print submitPhpConf(version)
|
||||
elif func == 'get_limit_conf':
|
||||
print getLimitConf(version)
|
||||
elif func == 'set_max_time':
|
||||
print setMaxTime(version)
|
||||
elif func == 'set_max_size':
|
||||
print setMaxSize(version)
|
||||
elif func == 'get_fpm_conf':
|
||||
print getFpmConfig(version)
|
||||
elif func == 'set_fpm_conf':
|
||||
print setFpmConfig(version)
|
||||
elif func == 'get_fpm_status':
|
||||
print getFpmStatus(version)
|
||||
elif func == 'get_disable_func':
|
||||
print getDisableFunc(version)
|
||||
elif func == 'set_disable_func':
|
||||
print setDisableFunc(version)
|
||||
elif func == 'get_phpinfo':
|
||||
print getPhpinfo(version)
|
||||
elif func == 'get_lib_conf':
|
||||
print getLibConf(version)
|
||||
else:
|
||||
print "fail"
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
#! /bin/sh
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: php-fpm
|
||||
# Required-Start: $remote_fs $network
|
||||
# Required-Stop: $remote_fs $network
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: starts php-fpm
|
||||
# Description: starts the PHP FastCGI Process Manager daemon
|
||||
### END INIT INFO
|
||||
|
||||
prefix={$SERVER_PATH}/php/{$PHP_VERSION}
|
||||
exec_prefix=${prefix}
|
||||
|
||||
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
|
||||
php_fpm_CONF=${prefix}/etc/php-fpm.conf
|
||||
php_fpm_PID=${prefix}/var/run/php-fpm.pid
|
||||
|
||||
|
||||
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
|
||||
|
||||
|
||||
wait_for_pid () {
|
||||
try=0
|
||||
|
||||
while test $try -lt 35 ; do
|
||||
|
||||
case "$1" in
|
||||
'created')
|
||||
if [ -f "$2" ] ; then
|
||||
try=''
|
||||
break
|
||||
fi
|
||||
;;
|
||||
|
||||
'removed')
|
||||
if [ ! -f "$2" ] ; then
|
||||
try=''
|
||||
break
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
echo -n .
|
||||
try=`expr $try + 1`
|
||||
sleep 1
|
||||
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
echo -n "Starting php-fpm "
|
||||
|
||||
$php_fpm_BIN --daemonize $php_opts
|
||||
|
||||
if [ "$?" != 0 ] ; then
|
||||
echo " failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
wait_for_pid created $php_fpm_PID
|
||||
|
||||
if [ -n "$try" ] ; then
|
||||
echo " failed"
|
||||
exit 1
|
||||
else
|
||||
echo " done"
|
||||
fi
|
||||
;;
|
||||
|
||||
stop)
|
||||
echo -n "Gracefully shutting down php-fpm "
|
||||
|
||||
if [ ! -r $php_fpm_PID ] ; then
|
||||
echo "warning, no pid file found - php-fpm is not running ?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -QUIT `cat $php_fpm_PID`
|
||||
|
||||
wait_for_pid removed $php_fpm_PID
|
||||
|
||||
if [ -n "$try" ] ; then
|
||||
echo " failed. Use force-quit"
|
||||
exit 1
|
||||
else
|
||||
echo " done"
|
||||
fi
|
||||
;;
|
||||
|
||||
status)
|
||||
if [ ! -r $php_fpm_PID ] ; then
|
||||
echo "php-fpm is stopped"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
PID=`cat $php_fpm_PID`
|
||||
if ps -p $PID | grep -q $PID; then
|
||||
echo "php-fpm (pid $PID) is running..."
|
||||
else
|
||||
echo "php-fpm dead but pid file exists"
|
||||
fi
|
||||
;;
|
||||
|
||||
force-quit)
|
||||
echo -n "Terminating php-fpm "
|
||||
|
||||
if [ ! -r $php_fpm_PID ] ; then
|
||||
echo "warning, no pid file found - php-fpm is not running ?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -TERM `cat $php_fpm_PID`
|
||||
|
||||
wait_for_pid removed $php_fpm_PID
|
||||
|
||||
if [ -n "$try" ] ; then
|
||||
echo " failed"
|
||||
exit 1
|
||||
else
|
||||
echo " done"
|
||||
fi
|
||||
;;
|
||||
|
||||
restart)
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
|
||||
reload)
|
||||
|
||||
echo -n "Reload service php-fpm "
|
||||
|
||||
if [ ! -r $php_fpm_PID ] ; then
|
||||
echo "warning, no pid file found - php-fpm is not running ?"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kill -USR2 `cat $php_fpm_PID`
|
||||
|
||||
echo " done"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|force-quit|restart|reload|status}"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
@@ -1,115 +1,35 @@
|
||||
//软件管理
|
||||
function phpSoftMain(name, key) {
|
||||
if (!isNaN(name)) {
|
||||
var nametext = "php" + name;
|
||||
name = name.replace(".", "");
|
||||
function phpPost(method,version, args,callback){
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
|
||||
var req_data = {};
|
||||
req_data['name'] = 'php';
|
||||
req_data['func'] = method;
|
||||
req_data['version'] = version;
|
||||
|
||||
if (typeof(args) != 'undefined' && args!=''){
|
||||
req_data['args'] = JSON.stringify(args);
|
||||
}
|
||||
|
||||
var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.get('/plugins?action=getPluginInfo&name=php', function(rdata) {
|
||||
$.post('/plugins/run', req_data, function(data) {
|
||||
layer.close(loadT);
|
||||
nameA = rdata.versions[key];
|
||||
bodys = [
|
||||
'<p class="bgw pstate" data-id="0"><a href="javascript:service(\'' + name + '\',' + nameA.run + ')">' + lan.soft.php_main1 + '</a><span class="spanmove"></span></p>',
|
||||
'<p data-id="1"><a id="phpext" href="javascript:SetPHPConfig(\'' + name + '\',' + nameA.pathinfo + ')">' + lan.soft.php_main5 + '</a><span class="spanmove"></span></p>',
|
||||
'<p data-id="2"><a href="javascript:SetPHPConf(\'' + name + '\')">' + lan.soft.config_edit + '</a><span class="spanmove"></span></p>',
|
||||
'<p data-id="3"><a href="javascript:phpUploadLimit(\'' + name + '\',' + nameA.max + ')">' + lan.soft.php_main2 + '</a><span class="spanmove"></span></p>',
|
||||
'<p class="phphide" data-id="4"><a href="javascript:phpTimeLimit(\'' + name + '\',' + nameA.maxTime + ')">' + lan.soft.php_main3 + '</a><span class="spanmove"></span></p>',
|
||||
'<p data-id="5"><a href="javascript:configChange(\'' + name + '\')">' + lan.soft.php_main4 + '</a><span class="spanmove"></span></p>',
|
||||
'<p data-id="6"><a href="javascript:disFun(\'' + name + '\')">' + lan.soft.php_main6 + '</a><span class="spanmove"></span></p>',
|
||||
'<p class="phphide" data-id="7"><a href="javascript:SetFpmConfig(\'' + name + '\')">' + lan.soft.php_main7 + '</a><span class="spanmove"></span></p>',
|
||||
'<p class="phphide" data-id="8"><a href="javascript:GetPHPStatus(\'' + name + '\')">' + lan.soft.php_main8 + '</a><span class="spanmove"></span></p>',
|
||||
'<p class="phphide" data-id="9"><a href="javascript:GetFpmLogs(\'' + name + '\')">FPM日志</a><span class="spanmove"></span></p>',
|
||||
'<p class="phphide" data-id="10"><a href="javascript:GetFpmSlowLogs(\'' + name + '\')">慢日志</a><span class="spanmove"></span></p>',
|
||||
'<p data-id="11"><a href="javascript:BtPhpinfo(\'' + name + '\')">phpinfo</a><span class="spanmove"></span></p>'
|
||||
]
|
||||
|
||||
var sdata = '';
|
||||
if (rdata.phpSort == false) {
|
||||
rdata.phpSort = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
||||
} else {
|
||||
rdata.phpSort = rdata.phpSort.split('|');
|
||||
}
|
||||
for (var i = 0; i < rdata.phpSort.length; i++) {
|
||||
sdata += bodys[rdata.phpSort[i]];
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: '640px',
|
||||
title: nametext + lan.soft.admin,
|
||||
closeBtn: 2,
|
||||
shift: 0,
|
||||
content: '<div class="bt-w-main" style="width:640px;">\
|
||||
<input name="softMenuSortOrder" type="hidden" />\
|
||||
<div class="bt-w-menu soft-man-menu">\
|
||||
' + sdata + '\
|
||||
</div>\
|
||||
<div id="webEdit-con" class="bt-w-con pd15" style="height:555px;overflow:auto">\
|
||||
<div class="soft-man-con"></div>\
|
||||
</div>\
|
||||
</div>'
|
||||
});
|
||||
if (name == "52") {
|
||||
$(".phphide").hide();
|
||||
if(typeof(callback) == 'function'){
|
||||
callback(data);
|
||||
}
|
||||
|
||||
if (rdata.versions.length < 5) {
|
||||
$(".phphide").hide();
|
||||
$(".pstate").hide();
|
||||
SetPHPConfig(name, nameA.pathinfo);
|
||||
$("p[data-id='4']").addClass('bgw');
|
||||
} else {
|
||||
service(name, nameA.run);
|
||||
}
|
||||
|
||||
$(".bt-w-menu p a").click(function() {
|
||||
var txt = $(this).text();
|
||||
$(this).parent().addClass("bgw").siblings().removeClass("bgw");
|
||||
if (txt != lan.soft.php_menu_ext) $(".soft-man-con").removeAttr("style");
|
||||
});
|
||||
$(".soft-man-menu").dragsort({ dragSelector: ".spanmove", dragEnd: MenusaveOrder });
|
||||
});
|
||||
}
|
||||
|
||||
//FPM日志
|
||||
function GetFpmLogs(phpversion) {
|
||||
var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.get('/ajax?action=GetFpmLogs&version=' + phpversion, function(logs) {
|
||||
layer.close(loadT);
|
||||
if (logs.status !== true) {
|
||||
logs.msg = '';
|
||||
}
|
||||
if (logs.msg == '') logs.msg = '当前没有fpm日志.';
|
||||
var phpCon = '<textarea readonly="" style="margin: 0px;width: 500px;height: 520px;background-color: #333;color:#fff; padding:0 5px" id="error_log">' + logs.msg + '</textarea>';
|
||||
$(".soft-man-con").html(phpCon);
|
||||
var ob = document.getElementById('error_log');
|
||||
ob.scrollTop = ob.scrollHeight;
|
||||
});
|
||||
}
|
||||
|
||||
//FPM-Slow日志
|
||||
function GetFpmSlowLogs(phpversion) {
|
||||
var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.get('/ajax?action=GetFpmSlowLogs&version=' + phpversion, function(logs) {
|
||||
layer.close(loadT);
|
||||
if (logs.status !== true) {
|
||||
logs.msg = '';
|
||||
}
|
||||
if (logs.msg == '') logs.msg = '当前没有慢日志.';
|
||||
var phpCon = '<textarea readonly="" style="margin: 0px;width: 500px;height: 520px;background-color: #333;color:#fff; padding:0 5px" id="error_log">' + logs.msg + '</textarea>';
|
||||
$(".soft-man-con").html(phpCon);
|
||||
var ob = document.getElementById('error_log');
|
||||
ob.scrollTop = ob.scrollHeight;
|
||||
});
|
||||
},'json');
|
||||
}
|
||||
|
||||
|
||||
//配置修改
|
||||
function SetPHPConf(version) {
|
||||
var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/config?action=GetPHPConf', 'version=' + version, function(rdata) {
|
||||
layer.close(loadT);
|
||||
function phpSetConfig(version) {
|
||||
phpPost('get_php_conf', version,'',function(data){
|
||||
// console.log(data);
|
||||
var rdata = $.parseJSON(data.data);
|
||||
// console.log(rdata);
|
||||
var mlist = '';
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
var w = '70'
|
||||
@@ -130,16 +50,16 @@ function SetPHPConf(version) {
|
||||
mlist += '<p><span>' + rdata[i].name + '</span>' + ibody + ', <font>' + rdata[i].ps + '</font></p>'
|
||||
}
|
||||
var phpCon = '<style>.conf_p p{margin-bottom: 2px}</style><div class="conf_p" style="margin-bottom:0">\
|
||||
' + mlist + '\
|
||||
<div style="margin-top:10px; padding-right:15px" class="text-right"><button class="btn btn-success btn-sm mr5" onclick="SetPHPConf(' + version + ')">' + lan.public.fresh + '</button><button class="btn btn-success btn-sm" onclick="SubmitPHPConf(' + version + ')">' + lan.public.save + '</button></div>\
|
||||
</div>'
|
||||
' + mlist + '\
|
||||
<div style="margin-top:10px; padding-right:15px" class="text-right"><button class="btn btn-success btn-sm mr5" onclick="phpSetConfig(' + version + ')">刷新</button><button class="btn btn-success btn-sm" onclick="submitConf(' + version + ')">保存</button></div>\
|
||||
</div>'
|
||||
$(".soft-man-con").html(phpCon);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//提交PHP配置
|
||||
function SubmitPHPConf(version) {
|
||||
function submitConf(version) {
|
||||
var data = {
|
||||
version: version,
|
||||
display_errors: $("select[name='display_errors']").val(),
|
||||
@@ -157,106 +77,316 @@ function SubmitPHPConf(version) {
|
||||
max_file_uploads: $("input[name='max_file_uploads']").val(),
|
||||
default_socket_timeout: $("input[name='default_socket_timeout']").val(),
|
||||
error_reporting: $("input[name='error_reporting']").val() || 'On'
|
||||
}
|
||||
};
|
||||
|
||||
var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/config?action=SetPHPConf', data, function(rdata) {
|
||||
layer.close(loadT);
|
||||
phpPost('submit_php_conf', version, data, function(ret_data){
|
||||
var rdata = $.parseJSON(ret_data.data);
|
||||
// console.log(rdata);
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
//php上传限制
|
||||
function phpUploadLimitReq(version){
|
||||
phpPost('get_limit_conf', version, '', function(ret_data){
|
||||
var rdata = $.parseJSON(ret_data.data);
|
||||
phpUploadLimit(version,rdata['max']);
|
||||
});
|
||||
}
|
||||
|
||||
function phpUploadLimit(version,max){
|
||||
var LimitCon = '<p class="conf_p"><input class="phpUploadLimit bt-input-text mr5" type="number" value="'+
|
||||
max+'" name="max">MB<button class="btn btn-success btn-sm" onclick="setPHPMaxSize(\''+
|
||||
version+'\')" style="margin-left:20px">保存</button></p>';
|
||||
$(".soft-man-con").html(LimitCon);
|
||||
}
|
||||
|
||||
|
||||
//php超时限制
|
||||
function phpTimeLimitReq(version){
|
||||
phpPost('get_limit_conf', version, '', function(ret_data){
|
||||
var rdata = $.parseJSON(ret_data.data);
|
||||
phpTimeLimit(version,rdata['maxTime']);
|
||||
});
|
||||
}
|
||||
|
||||
function phpTimeLimit(version, max) {
|
||||
var LimitCon = '<p class="conf_p"><input class="phpTimeLimit bt-input-text mr5" type="number" value="' + max + '">' + lan.bt.s + '<button class="btn btn-success btn-sm" onclick="SetPHPMaxTime(\'' + version + '\')" style="margin-left:20px">' + lan.public.save + '</button></p>';
|
||||
var LimitCon = '<p class="conf_p"><input class="phpTimeLimit bt-input-text mr5" type="number" value="' + max + '">秒<button class="btn btn-success btn-sm" onclick="setPHPMaxTime(\'' + version + '\')" style="margin-left:20px">保存</button></p>';
|
||||
$(".soft-man-con").html(LimitCon);
|
||||
}
|
||||
|
||||
//设置超时限制
|
||||
function SetPHPMaxTime(version) {
|
||||
function setPHPMaxTime(version) {
|
||||
var max = $(".phpTimeLimit").val();
|
||||
var loadT = layer.msg(lan.soft.the_save, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/config?action=setPHPMaxTime', 'version=' + version + '&time=' + max, function(rdata) {
|
||||
$(".bt-w-menu .active").attr('onclick', "phpTimeLimit('" + version + "'," + max + ")");
|
||||
$(".bt-w-menu .active a").attr('href', "javascript:phpTimeLimit('" + version + "'," + max + ");");
|
||||
layer.close(loadT);
|
||||
phpPost('set_max_time',version,{'time':max},function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
});
|
||||
}
|
||||
//设置PHP上传限制
|
||||
function SetPHPMaxSize(version) {
|
||||
function setPHPMaxSize(version) {
|
||||
max = $(".phpUploadLimit").val();
|
||||
if (max < 2) {
|
||||
alert(max);
|
||||
layer.msg(lan.soft.php_upload_size, { icon: 2 });
|
||||
layer.msg('上传大小限制不能小于2M', { icon: 2 });
|
||||
return;
|
||||
}
|
||||
var loadT = layer.msg(lan.soft.the_save, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/config?action=setPHPMaxSize', '&version=' + version + '&max=' + max, function(rdata) {
|
||||
$(".bt-w-menu .active").attr('onclick', "phpUploadLimit('" + version + "'," + max + ")");
|
||||
$(".bt-w-menu .active a").attr('href', "javascript:phpUploadLimit('" + version + "'," + max + ");");
|
||||
layer.close(loadT);
|
||||
|
||||
phpPost('set_max_size',version,{'max':max},function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
})
|
||||
}
|
||||
//配置修改
|
||||
function configChange(type) {
|
||||
var con = '<p style="color: #666; margin-bottom: 7px">' + lan.bt.edit_ps + '</p><textarea class="bt-input-text" style="height: 320px; line-height:18px;" id="textBody"></textarea>\
|
||||
<button id="OnlineEditFileBtn" class="btn btn-success btn-sm" style="margin-top:10px;">' + lan.public.save + '</button>\
|
||||
<ul class="help-info-text c7 ptb15">\
|
||||
<li>' + lan.get('config_edit_ps', [type]) + '</li>\
|
||||
</ul>';
|
||||
$(".soft-man-con").html(con);
|
||||
var fileName = '';
|
||||
switch (type) {
|
||||
case 'mysqld':
|
||||
fileName = '/etc/my.cnf';
|
||||
break;
|
||||
case 'nginx':
|
||||
fileName = '/www/server/nginx/conf/nginx.conf';
|
||||
break;
|
||||
case 'pure-ftpd':
|
||||
fileName = '/www/server/pure-ftpd/etc/pure-ftpd.conf';
|
||||
break;
|
||||
case 'apache':
|
||||
fileName = '/www/server/apache/conf/httpd.conf';
|
||||
break;
|
||||
case 'tomcat':
|
||||
fileName = '/www/server/tomcat/conf/server.xml';
|
||||
break;
|
||||
case 'memcached':
|
||||
fileName = '/etc/init.d/memcached';
|
||||
break;
|
||||
case 'redis':
|
||||
fileName = '/www/server/redis/redis.conf';
|
||||
break;
|
||||
default:
|
||||
fileName = '/www/server/php/' + type + '/etc/php.ini';
|
||||
break;
|
||||
}
|
||||
var loadT = layer.msg(lan.soft.get, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/files?action=GetFileBody', 'path=' + fileName, function(rdata) {
|
||||
layer.close(loadT);
|
||||
$("#textBody").empty().text(rdata.data);
|
||||
$(".CodeMirror").remove();
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("textBody"), {
|
||||
extraKeys: { "Ctrl-Space": "autocomplete" },
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
});
|
||||
editor.focus();
|
||||
$(".CodeMirror-scroll").css({ "height": "300px", "margin": 0, "padding": 0 });
|
||||
$("#OnlineEditFileBtn").click(function() {
|
||||
$("#textBody").text(editor.getValue());
|
||||
confSafe(fileName);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getFpmConfig(version){
|
||||
phpPost('get_fpm_conf', version, {}, function(data){
|
||||
// console.log(data);
|
||||
var rdata = $.parseJSON(data.data);
|
||||
// console.log(rdata);
|
||||
var limitList = "<option value='0'>自定义</option>" +
|
||||
"<option value='1' " + (rdata.max_children == 30 ? 'selected' : '') + ">30并发</option>" +
|
||||
"<option value='2' " + (rdata.max_children == 50 ? 'selected' : '') + ">50并发</option>" +
|
||||
"<option value='3' " + (rdata.max_children == 100 ? 'selected' : '') + ">100并发</option>" +
|
||||
"<option value='4' " + (rdata.max_children == 200 ? 'selected' : '') + ">200并发</option>" +
|
||||
"<option value='5' " + (rdata.max_children == 300 ? 'selected' : '') + ">300并发</option>" +
|
||||
"<option value='6' " + (rdata.max_children == 500 ? 'selected' : '') + ">500并发</option>"
|
||||
var pms = [{ 'name': 'static', 'title': '静态' }, { 'name': 'dynamic', 'title': '动态' }];
|
||||
var pmList = '';
|
||||
for (var i = 0; i < pms.length; i++) {
|
||||
pmList += '<option value="' + pms[i].name + '" ' + ((pms[i].name == rdata.pm) ? 'selected' : '') + '>' + pms[i].title + '</option>';
|
||||
}
|
||||
var body = "<div class='bingfa'>" +
|
||||
"<p class='line'><span class='span_tit'>并发方案:</span><select class='bt-input-text' name='limit' style='width:100px;'>" + limitList + "</select></p>" +
|
||||
"<p class='line'><span class='span_tit'>运行模式:</span><select class='bt-input-text' name='pm' style='width:100px;'>" + pmList + "</select><span class='c9'>*PHP-FPM运行模式</span></p>" +
|
||||
"<p class='line'><span class='span_tit'>max_children:</span><input class='bt-input-text' type='number' name='max_children' value='" + rdata.max_children + "' /><span class='c9'>*允许创建的最大子进程数</span></p>" +
|
||||
"<p class='line'><span class='span_tit'>start_servers:</span><input class='bt-input-text' type='number' name='start_servers' value='" + rdata.start_servers + "' /> <span class='c9'>*起始进程数(服务启动后初始进程数量)</span></p>" +
|
||||
"<p class='line'><span class='span_tit'>min_spare_servers:</span><input class='bt-input-text' type='number' name='min_spare_servers' value='" + rdata.min_spare_servers + "' /> <span class='c9'>*最小空闲进程数(清理空闲进程后的保留数量)</span></p>" +
|
||||
"<p class='line'><span class='span_tit'>max_spare_servers:</span><input class='bt-input-text' type='number' name='max_spare_servers' value='" + rdata.max_spare_servers + "' /> <span class='c9'>*最大空闲进程数(当空闲进程达到此值时清理)</span></p>" +
|
||||
"<div class='mtb15'><button class='btn btn-success btn-sm' onclick='setFpmConfig(\"" + version + "\",1)'>保存</button></div>" +
|
||||
"</div>";
|
||||
|
||||
$(".soft-man-con").html(body);
|
||||
$("select[name='limit']").change(function() {
|
||||
var type = $(this).val();
|
||||
var max_children = rdata.max_children;
|
||||
var start_servers = rdata.start_servers;
|
||||
var min_spare_servers = rdata.min_spare_servers;
|
||||
var max_spare_servers = rdata.max_spare_servers;
|
||||
switch (type) {
|
||||
case '1':
|
||||
max_children = 30;
|
||||
start_servers = 5;
|
||||
min_spare_servers = 5;
|
||||
max_spare_servers = 20;
|
||||
break;
|
||||
case '2':
|
||||
max_children = 50;
|
||||
start_servers = 15;
|
||||
min_spare_servers = 15;
|
||||
max_spare_servers = 35;
|
||||
break;
|
||||
case '3':
|
||||
max_children = 100;
|
||||
start_servers = 20;
|
||||
min_spare_servers = 20;
|
||||
max_spare_servers = 70;
|
||||
break;
|
||||
case '4':
|
||||
max_children = 200;
|
||||
start_servers = 25;
|
||||
min_spare_servers = 25;
|
||||
max_spare_servers = 150;
|
||||
break;
|
||||
case '5':
|
||||
max_children = 300;
|
||||
start_servers = 30;
|
||||
min_spare_servers = 30;
|
||||
max_spare_servers = 180;
|
||||
break;
|
||||
case '6':
|
||||
max_children = 500;
|
||||
start_servers = 35;
|
||||
min_spare_servers = 35;
|
||||
max_spare_servers = 250;
|
||||
break;
|
||||
}
|
||||
|
||||
$("input[name='max_children']").val(max_children);
|
||||
$("input[name='start_servers']").val(start_servers);
|
||||
$("input[name='min_spare_servers']").val(min_spare_servers);
|
||||
$("input[name='max_spare_servers']").val(max_spare_servers);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function setFpmConfig(version){
|
||||
var max_children = Number($("input[name='max_children']").val());
|
||||
var start_servers = Number($("input[name='start_servers']").val());
|
||||
var min_spare_servers = Number($("input[name='min_spare_servers']").val());
|
||||
var max_spare_servers = Number($("input[name='max_spare_servers']").val());
|
||||
var pm = $("select[name='pm']").val();
|
||||
|
||||
if (max_children < max_spare_servers) {
|
||||
layer.msg('max_spare_servers 不能大于 max_children', { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
if (min_spare_servers > start_servers) {
|
||||
layer.msg('min_spare_servers 不能大于 start_servers', { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
if (max_spare_servers < min_spare_servers) {
|
||||
layer.msg('min_spare_servers 不能大于 max_spare_servers', { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
if (max_children < start_servers) {
|
||||
layer.msg('start_servers 不能大于 max_children', { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
if (max_children < 1 || start_servers < 1 || min_spare_servers < 1 || max_spare_servers < 1) {
|
||||
layer.msg('配置值不能小于1', { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
var data = {
|
||||
version:version,
|
||||
max_children:max_children,
|
||||
start_servers:start_servers,
|
||||
min_spare_servers:min_spare_servers,
|
||||
max_spare_servers:max_spare_servers,
|
||||
pm:pm,
|
||||
};
|
||||
phpPost('set_fpm_conf', version, data, function(ret_data){
|
||||
var rdata = $.parseJSON(ret_data.data);
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getFpmStatus(version){
|
||||
phpPost('get_fpm_status', version, '', function(ret_data){
|
||||
var rdata = $.parseJSON(ret_data.data);
|
||||
var con = "<div style='height:420px;overflow:hidden;'><table class='table table-hover table-bordered GetPHPStatus' style='margin:0;padding:0'>\
|
||||
<tr><th>应用池(pool)</th><td>" + rdata.pool + "</td></tr>\
|
||||
<tr><th>进程管理方式(process manager)</th><td>" + ((rdata['process manager'] == 'dynamic') ? '动态' : '静态') + "</td></tr>\
|
||||
<tr><th>启动日期(start time)</th><td>" + rdata['start time'] + "</td></tr>\
|
||||
<tr><th>请求数(accepted conn)</th><td>" + rdata['accepted conn'] + "</td></tr>\
|
||||
<tr><th>请求队列(listen queue)</th><td>" + rdata['listen queue'] + "</td></tr>\
|
||||
<tr><th>最大等待队列(max listen queue)</th><td>" + rdata['max listen queue'] + "</td></tr>\
|
||||
<tr><th>socket队列长度(listen queue len)</th><td>" + rdata['listen queue len'] + "</td></tr>\
|
||||
<tr><th>空闲进程数量(idle processes)</th><td>" + rdata['idle processes'] + "</td></tr>\
|
||||
<tr><th>活跃进程数量(active processes)</th><td>" + rdata['active processes'] + "</td></tr>\
|
||||
<tr><th>总进程数量(total processes)</th><td>" + rdata['total processes'] + "</td></tr>\
|
||||
<tr><th>最大活跃进程数量(max active processes)</th><td>" + rdata['max active processes'] + "</td></tr>\
|
||||
<tr><th>到达进程上限次数(max children reached)</th><td>" + rdata['max children reached'] + "</td></tr>\
|
||||
<tr><th>慢请求数量(slow requests)</th><td>" + rdata['slow requests'] + "</td></tr>\
|
||||
</table></div>";
|
||||
$(".soft-man-con").html(con);
|
||||
$(".GetPHPStatus td,.GetPHPStatus th").css("padding", "7px");
|
||||
});
|
||||
}
|
||||
|
||||
//禁用函数
|
||||
function disableFunc(version) {
|
||||
phpPost('get_disable_func', version,'',function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
var disable_functions = rdata.disable_functions.split(',');
|
||||
var dbody = ''
|
||||
for (var i = 0; i < disable_functions.length; i++) {
|
||||
if (disable_functions[i] == '') continue;
|
||||
dbody += "<tr><td>" + disable_functions[i] + "</td><td><a style='float:right;' href=\"javascript:setDisableFunc('" + version + "','" + disable_functions[i] + "','" + rdata.disable_functions + "');\">删除</a></td></tr>";
|
||||
}
|
||||
|
||||
var con = "<div class='dirBinding'>" +
|
||||
"<input class='bt-input-text mr5' type='text' placeholder='添加要被禁止的函数名,如: exec' id='disable_function_val' style='height: 28px; border-radius: 3px;width: 410px;' />" +
|
||||
"<button class='btn btn-success btn-sm' onclick=\"setDisableFunc('" + version + "',1,'" + rdata.disable_functions + "')\">添加</button>" +
|
||||
"</div>" +
|
||||
"<div class='divtable mtb15' style='height:350px;overflow:auto'><table class='table table-hover' width='100%' style='margin-bottom:0'>" +
|
||||
"<thead><tr><th>名称</th><th width='100' class='text-right'>操作</th></tr></thead>" +
|
||||
"<tbody id='blacktable'>" + dbody + "</tbody>" +
|
||||
"</table></div>";
|
||||
|
||||
con += '\
|
||||
<ul class="help-info-text">\
|
||||
<li>在此处可以禁用指定函数的调用,以增强环境安全性!</li>\
|
||||
<li>强烈建议禁用如exec,system等危险函数!</li>\
|
||||
</ul>';
|
||||
|
||||
$(".soft-man-con").html(con);
|
||||
});
|
||||
}
|
||||
//设置禁用函数
|
||||
function setDisableFunc(version, act, fs) {
|
||||
var fsArr = fs.split(',');
|
||||
if (act == 1) {
|
||||
var functions = $("#disable_function_val").val();
|
||||
for (var i = 0; i < fsArr.length; i++) {
|
||||
if (functions == fsArr[i]) {
|
||||
layer.msg(lan.soft.fun_msg, { icon: 5 });
|
||||
return;
|
||||
}
|
||||
}
|
||||
fs += ',' + functions;
|
||||
msg = '添加成功';
|
||||
} else {
|
||||
|
||||
fs = '';
|
||||
for (var i = 0; i < fsArr.length; i++) {
|
||||
if (act == fsArr[i]) continue;
|
||||
fs += fsArr[i] + ','
|
||||
}
|
||||
msg = '删除成功';
|
||||
fs = fs.substr(0, fs.length - 1);
|
||||
}
|
||||
|
||||
var data = {
|
||||
'version':version,
|
||||
'disable_functions':fs,
|
||||
};
|
||||
|
||||
phpPost('set_disable_func', version,data,function(data){
|
||||
var rdata = $.parseJSON(data.data);
|
||||
showMsg(rdata.status ? msg : rdata.msg, function(){
|
||||
disableFunc(version);
|
||||
} ,{ icon: rdata.status ? 1 : 2 });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//phpinfo
|
||||
function getPhpinfo(version) {
|
||||
var con = '<button class="btn btn-default btn-sm" onclick="getPHPInfo(\'' + version + '\')">' + lan.soft.phpinfo + '</button>';
|
||||
$(".soft-man-con").html(con);
|
||||
}
|
||||
|
||||
//获取PHPInfo
|
||||
function getPHPInfo(version) {
|
||||
phpPost('get_phpinfo', version, '', function(data){
|
||||
var rdata = data.data;
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: "PHP-" + version + "-PHPINFO",
|
||||
area: ['90%', '90%'],
|
||||
closeBtn: 2,
|
||||
shadeClose: true,
|
||||
content: rdata
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function phpLibConfig(version){
|
||||
|
||||
}
|
||||
|
||||
|
||||
//设置PATHINFO
|
||||
function SetPathInfo(version, type) {
|
||||
function setPathInfo(version, type) {
|
||||
var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/config?action=setPathInfo', 'version=' + version + '&type=' + type, function(rdata) {
|
||||
var pathinfo = (type == 'on') ? true : false;
|
||||
@@ -274,7 +404,7 @@ function SetPathInfo(version, type) {
|
||||
|
||||
|
||||
//PHP扩展配置
|
||||
function SetPHPConfig(version, pathinfo, go) {
|
||||
function setPHPConfig(version, pathinfo, go) {
|
||||
$.get('/ajax?action=GetPHPConfig&version=' + version, function(rdata) {
|
||||
var body = ""
|
||||
var opt = ""
|
||||
@@ -370,247 +500,4 @@ function UninstallPHPLib(version, name, title, pathinfo) {
|
||||
SetPHPConfig(version, pathinfo, true);
|
||||
});
|
||||
});
|
||||
}
|
||||
//禁用函数
|
||||
function disFun(version) {
|
||||
$.get('/ajax?action=GetPHPConfig&version=' + version, function(rdata) {
|
||||
var disable_functions = rdata.disable_functions.split(',');
|
||||
var dbody = ''
|
||||
for (var i = 0; i < disable_functions.length; i++) {
|
||||
if (disable_functions[i] == '') continue;
|
||||
dbody += "<tr><td>" + disable_functions[i] + "</td><td><a style='float:right;' href=\"javascript:disable_functions('" + version + "','" + disable_functions[i] + "','" + rdata.disable_functions + "');\">" + lan.public.del + "</a></td></tr>";
|
||||
}
|
||||
|
||||
var con = "<div class='dirBinding'>" +
|
||||
"<input class='bt-input-text mr5' type='text' placeholder='" + lan.soft.fun_ps1 + "' id='disable_function_val' style='height: 28px; border-radius: 3px;width: 410px;' />" +
|
||||
"<button class='btn btn-success btn-sm' onclick=\"disable_functions('" + version + "',1,'" + rdata.disable_functions + "')\">" + lan.public.add + "</button>" +
|
||||
"</div>" +
|
||||
"<div class='divtable mtb15' style='height:350px;overflow:auto'><table class='table table-hover' width='100%' style='margin-bottom:0'>" +
|
||||
"<thead><tr><th>" + lan.soft.php_ext_name + "</th><th width='100' class='text-right'>" + lan.public.action + "</th></tr></thead>" +
|
||||
"<tbody id='blacktable'>" + dbody + "</tbody>" +
|
||||
"</table></div>";
|
||||
|
||||
con += '\
|
||||
<ul class="help-info-text">\
|
||||
<li>' + lan.soft.fun_ps2 + '</li>\
|
||||
<li>' + lan.soft.fun_ps3 + '</li>\
|
||||
</ul>';
|
||||
|
||||
$(".soft-man-con").html(con);
|
||||
});
|
||||
}
|
||||
//设置禁用函数
|
||||
function disable_functions(version, act, fs) {
|
||||
var fsArr = fs.split(',');
|
||||
if (act == 1) {
|
||||
var functions = $("#disable_function_val").val();
|
||||
for (var i = 0; i < fsArr.length; i++) {
|
||||
if (functions == fsArr[i]) {
|
||||
layer.msg(lan.soft.fun_msg, { icon: 5 });
|
||||
return;
|
||||
}
|
||||
}
|
||||
fs += ',' + functions;
|
||||
msg = lan.public.add_success;
|
||||
} else {
|
||||
|
||||
fs = '';
|
||||
for (var i = 0; i < fsArr.length; i++) {
|
||||
if (act == fsArr[i]) continue;
|
||||
fs += fsArr[i] + ','
|
||||
}
|
||||
msg = lan.public.del_success;
|
||||
fs = fs.substr(0, fs.length - 1);
|
||||
}
|
||||
|
||||
var data = 'version=' + version + '&disable_functions=' + fs;
|
||||
var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/config?action=setPHPDisable', data, function(rdata) {
|
||||
layer.close(loadT);
|
||||
layer.msg(rdata.status ? msg : rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
disFun(version);
|
||||
});
|
||||
}
|
||||
//性能调整
|
||||
function SetFpmConfig(version, action) {
|
||||
if (action == 1) {
|
||||
$.post('/system?action=GetMemInfo', '', function(memInfo) {
|
||||
var limit_children = parseInt(memInfo['memTotal'] / 8);
|
||||
var max_children = Number($("input[name='max_children']").val());
|
||||
var start_servers = Number($("input[name='start_servers']").val());
|
||||
var min_spare_servers = Number($("input[name='min_spare_servers']").val());
|
||||
var max_spare_servers = Number($("input[name='max_spare_servers']").val());
|
||||
var pm = $("select[name='pm']").val();
|
||||
|
||||
if (limit_children < max_children) {
|
||||
layer.msg('当前服务器内存不足,最大允许[' + limit_children + ']个子进程!', { icon: 2 });
|
||||
$("input[name='max_children']").focus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (max_children < max_spare_servers) {
|
||||
layer.msg(lan.soft.php_fpm_err1, { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
if (min_spare_servers > start_servers) {
|
||||
layer.msg(lan.soft.php_fpm_err2, { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
if (max_spare_servers < min_spare_servers) {
|
||||
layer.msg(lan.soft.php_fpm_err3, { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
if (max_children < start_servers) {
|
||||
layer.msg(lan.soft.php_fpm_err4, { icon: 2 });
|
||||
return;
|
||||
}
|
||||
|
||||
if (max_children < 1 || start_servers < 1 || min_spare_servers < 1 || max_spare_servers < 1) {
|
||||
layer.msg(lan.soft.php_fpm_err5, { icon: 2 });
|
||||
return;
|
||||
}
|
||||
var data = 'version=' + version + '&max_children=' + max_children + '&start_servers=' + start_servers + '&min_spare_servers=' + min_spare_servers + '&max_spare_servers=' + max_spare_servers + '&pm=' + pm;
|
||||
var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/config?action=setFpmConfig', data, function(rdata) {
|
||||
layer.close(loadT);
|
||||
var loadT = layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
}).error(function() {
|
||||
layer.close(loadT);
|
||||
layer.msg(lan.public.config_ok, { icon: 1 });
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
$.post('/config?action=getFpmConfig', 'version=' + version, function(rdata) {
|
||||
|
||||
var limitList = "<option value='0'>" + lan.soft.concurrency_m + "</option>" +
|
||||
"<option value='1' " + (rdata.max_children == 30 ? 'selected' : '') + ">30" + lan.soft.concurrency + "</option>" +
|
||||
"<option value='2' " + (rdata.max_children == 50 ? 'selected' : '') + ">50" + lan.soft.concurrency + "</option>" +
|
||||
"<option value='3' " + (rdata.max_children == 100 ? 'selected' : '') + ">100" + lan.soft.concurrency + "</option>" +
|
||||
"<option value='4' " + (rdata.max_children == 200 ? 'selected' : '') + ">200" + lan.soft.concurrency + "</option>" +
|
||||
"<option value='5' " + (rdata.max_children == 300 ? 'selected' : '') + ">300" + lan.soft.concurrency + "</option>" +
|
||||
"<option value='6' " + (rdata.max_children == 500 ? 'selected' : '') + ">500" + lan.soft.concurrency + "</option>"
|
||||
var pms = [{ 'name': 'static', 'title': lan.bt.static }, { 'name': 'dynamic', 'title': lan.bt.dynamic }];
|
||||
var pmList = '';
|
||||
for (var i = 0; i < pms.length; i++) {
|
||||
pmList += '<option value="' + pms[i].name + '" ' + ((pms[i].name == rdata.pm) ? 'selected' : '') + '>' + pms[i].title + '</option>';
|
||||
}
|
||||
var body = "<div class='bingfa'>" +
|
||||
"<p class='line'><span class='span_tit'>" + lan.soft.concurrency_type + ":</span><select class='bt-input-text' name='limit' style='width:100px;'>" + limitList + "</select></p>" +
|
||||
"<p class='line'><span class='span_tit'>" + lan.soft.php_fpm_model + ":</span><select class='bt-input-text' name='pm' style='width:100px;'>" + pmList + "</select><span class='c9'>*" + lan.soft.php_fpm_ps1 + "</span></p>" +
|
||||
"<p class='line'><span class='span_tit'>max_children:</span><input class='bt-input-text' type='number' name='max_children' value='" + rdata.max_children + "' /><span class='c9'>*" + lan.soft.php_fpm_ps2 + "</span></p>" +
|
||||
"<p class='line'><span class='span_tit'>start_servers:</span><input class='bt-input-text' type='number' name='start_servers' value='" + rdata.start_servers + "' /> <span class='c9'>*" + lan.soft.php_fpm_ps3 + "</span></p>" +
|
||||
"<p class='line'><span class='span_tit'>min_spare_servers:</span><input class='bt-input-text' type='number' name='min_spare_servers' value='" + rdata.min_spare_servers + "' /> <span class='c9'>*" + lan.soft.php_fpm_ps4 + "</span></p>" +
|
||||
"<p class='line'><span class='span_tit'>max_spare_servers:</span><input class='bt-input-text' type='number' name='max_spare_servers' value='" + rdata.max_spare_servers + "' /> <span class='c9'>*" + lan.soft.php_fpm_ps5 + "</span></p>" +
|
||||
"<div class='mtb15'><button class='btn btn-success btn-sm' onclick='SetFpmConfig(\"" + version + "\",1)'>" + lan.public.save + "</button></div>" +
|
||||
"</div>"
|
||||
|
||||
$(".soft-man-con").html(body);
|
||||
$("select[name='limit']").change(function() {
|
||||
var type = $(this).val();
|
||||
var max_children = rdata.max_children;
|
||||
var start_servers = rdata.start_servers;
|
||||
var min_spare_servers = rdata.min_spare_servers;
|
||||
var max_spare_servers = rdata.max_spare_servers;
|
||||
switch (type) {
|
||||
case '1':
|
||||
max_children = 30;
|
||||
start_servers = 5;
|
||||
min_spare_servers = 5;
|
||||
max_spare_servers = 20;
|
||||
break;
|
||||
case '2':
|
||||
max_children = 50;
|
||||
start_servers = 15;
|
||||
min_spare_servers = 15;
|
||||
max_spare_servers = 35;
|
||||
break;
|
||||
case '3':
|
||||
max_children = 100;
|
||||
start_servers = 20;
|
||||
min_spare_servers = 20;
|
||||
max_spare_servers = 70;
|
||||
break;
|
||||
case '4':
|
||||
max_children = 200;
|
||||
start_servers = 25;
|
||||
min_spare_servers = 25;
|
||||
max_spare_servers = 150;
|
||||
break;
|
||||
case '5':
|
||||
max_children = 300;
|
||||
start_servers = 30;
|
||||
min_spare_servers = 30;
|
||||
max_spare_servers = 180;
|
||||
break;
|
||||
case '6':
|
||||
max_children = 500;
|
||||
start_servers = 35;
|
||||
min_spare_servers = 35;
|
||||
max_spare_servers = 250;
|
||||
break;
|
||||
}
|
||||
|
||||
$("input[name='max_children']").val(max_children);
|
||||
$("input[name='start_servers']").val(start_servers);
|
||||
$("input[name='min_spare_servers']").val(min_spare_servers);
|
||||
$("input[name='max_spare_servers']").val(max_spare_servers);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//phpinfo
|
||||
function BtPhpinfo(version) {
|
||||
var con = '<button class="btn btn-default btn-sm" onclick="GetPHPInfo(\'' + version + '\')">' + lan.soft.phpinfo + '</button>';
|
||||
$(".soft-man-con").html(con);
|
||||
}
|
||||
//获取PHPInfo
|
||||
function GetPHPInfo(version) {
|
||||
var loadT = layer.msg(lan.soft.get, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.get('/ajax?action=GetPHPInfo&version=' + version, function(rdata) {
|
||||
layer.close(loadT);
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: "PHP-" + version + "-PHPINFO",
|
||||
area: ['70%', '90%'],
|
||||
closeBtn: 2,
|
||||
shadeClose: true,
|
||||
content: rdata.replace('a:link {color: #009; text-decoration: none; background-color: #fff;}', '').replace('a:link {color: #000099; text-decoration: none; background-color: #ffffff;}', '')
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//查看PHP负载状态
|
||||
function GetPHPStatus(version) {
|
||||
$.post('/ajax?action=GetPHPStatus', 'version=' + version, function(rdata) {
|
||||
var con = "<div style='height:420px;overflow:hidden;'><table class='table table-hover table-bordered GetPHPStatus' style='margin:0;padding:0'>\
|
||||
<tr><th>" + lan.bt.php_pool + "</th><td>" + rdata.pool + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_manager + "</th><td>" + ((rdata['process manager'] == 'dynamic') ? lan.bt.dynamic : lan.bt.static) + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_start + "</th><td>" + rdata['start time'] + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_accepted + "</th><td>" + rdata['accepted conn'] + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_queue + "</th><td>" + rdata['listen queue'] + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_max_queue + "</th><td>" + rdata['max listen queue'] + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_len_queue + "</th><td>" + rdata['listen queue len'] + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_idle + "</th><td>" + rdata['idle processes'] + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_active + "</th><td>" + rdata['active processes'] + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_total + "</th><td>" + rdata['total processes'] + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_max_active + "</th><td>" + rdata['max active processes'] + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_max_children + "</th><td>" + rdata['max children reached'] + "</td></tr>\
|
||||
<tr><th>" + lan.bt.php_slow + "</th><td>" + rdata['slow requests'] + "</td></tr>\
|
||||
</table></div>";
|
||||
$(".soft-man-con").html(con);
|
||||
$(".GetPHPStatus td,.GetPHPStatus th").css("padding", "7px");
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//php上传限制
|
||||
function phpUploadLimit(version, max) {
|
||||
var LimitCon = '<p class="conf_p"><input class="phpUploadLimit bt-input-text mr5" type="number" value="' + max + '" name="max">MB<button class="btn btn-success btn-sm" onclick="SetPHPMaxSize(\'' + version + '\')" style="margin-left:20px">' + lan.public.save + '</button></p>';
|
||||
$(".soft-man-con").html(LimitCon);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ cd $sourcePath/php/php-7.2.5 && ./configure \
|
||||
--enable-soap \
|
||||
--enable-posix \
|
||||
--enable-fpm \
|
||||
&& make && make install
|
||||
&& make && make install && make clean
|
||||
|
||||
#------------------------ install end ------------------------------------#
|
||||
}
|
||||
@@ -54,6 +54,7 @@ cd $sourcePath/php/php-7.2.5 && ./configure \
|
||||
|
||||
Uninstall_php()
|
||||
{
|
||||
rm -rf $serverPath/php/72
|
||||
echo "卸载php-7.2.5 ..." > $install_tmp
|
||||
}
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 44 KiB |
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"title":"pureftp",
|
||||
"tip":"soft",
|
||||
"name":"pureftp",
|
||||
"ps":"PureFTPd是一款专注于程序健壮和软件安全的免费FTP服务器软件",
|
||||
"versions": "1.0.47",
|
||||
"shell":"install.sh",
|
||||
"checks":"server/pureftp",
|
||||
"path":"server/pureftp",
|
||||
"author":"mdserver-web",
|
||||
"home":"https://github.com/midoks/mdserver-web",
|
||||
"date":"2018-11-30",
|
||||
"pid":"3"
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#!/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/bt_install.pl
|
||||
|
||||
Install_pureftp()
|
||||
{
|
||||
mkdir -p ${serverPath}/pureftp
|
||||
mkdir -p ${serverPath}/source/pureftp
|
||||
|
||||
VER=$1
|
||||
FILE=pure-ftpd-${VER}.tar.gz
|
||||
DOWNLOAD=https://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-${VER}.tar.gz
|
||||
|
||||
|
||||
if [ ! -f $serverPath/source/pureftp/$FILE ];then
|
||||
wget -O $serverPath/source/pureftp/$FILE $DOWNLOAD
|
||||
fi
|
||||
|
||||
if [ ! -d $serverPath/source/pureftp/$FILE ];then
|
||||
cd $serverPath/source/pureftp && tar zxvf $FILE
|
||||
fi
|
||||
|
||||
cd pure-ftpd-${1} && ./configure --prefix=${serverPath}/pureftp \
|
||||
--without-inetd \
|
||||
--with-altlog \
|
||||
--with-puredb \
|
||||
--with-throttling \
|
||||
--with-peruserlimits \
|
||||
--with-tls && make && make install
|
||||
|
||||
|
||||
|
||||
echo "${1}" > ${serverPath}/pureftp/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_pureftp()
|
||||
{
|
||||
rm -rf ${serverPath}/pureftp
|
||||
echo '卸载完成' > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_pureftp $2
|
||||
else
|
||||
Uninstall_pureftp $2
|
||||
fi
|
||||
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.1 KiB |
@@ -1,10 +1,18 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="infojson();">INFO说明</p>
|
||||
<p class="bgw" onclick="readme();">插件说明</p>
|
||||
<p onclick="infojson();">INFO说明</p>
|
||||
<p onclick="indexPy();">index.py说明</p>
|
||||
</div>
|
||||
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con">
|
||||
<div class="soft-man-con v0">
|
||||
<div><p>在每一个插件中,都必须包含一个info.json文件,格式如下:</p><br/></div>
|
||||
<div>123</div>
|
||||
</div>
|
||||
|
||||
<div class="soft-man-con v1">
|
||||
<div><p>在每一个插件中,都必须包含一个info.json文件,格式如下:</p><br/></div>
|
||||
<div><pre>{
|
||||
"title": "插件开发说明",
|
||||
@@ -21,16 +29,29 @@
|
||||
"date": "2018-11-30",
|
||||
"pid": "5"
|
||||
}</pre></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="soft-man-con v2">
|
||||
<div><p>在每一个插件中,都必须包含一个index.py文件</p><br/></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
// resetPluginWinWidth(700);
|
||||
// $.getScript("/plugins/file?name=readme&f=js/score.js");
|
||||
|
||||
function readme() {
|
||||
$('.bt-w-main .soft-man-con').hide();
|
||||
$('.bt-w-main .v0').show();
|
||||
}
|
||||
|
||||
function infojson() {
|
||||
$('.bt-w-main .soft-man-con').hide();
|
||||
$('.bt-w-main .v1').show();
|
||||
}
|
||||
|
||||
function indexPy() {
|
||||
$('.bt-w-main .soft-man-con').hide();
|
||||
$('.bt-w-main .v2').show();
|
||||
}
|
||||
</script>
|
||||
@@ -1,14 +1,14 @@
|
||||
# coding: utf-8
|
||||
|
||||
import time
|
||||
import psutil
|
||||
import random
|
||||
import os
|
||||
import urllib
|
||||
import binascii
|
||||
import json
|
||||
import public
|
||||
import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
|
||||
|
||||
def status():
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"title":"插件开发说明",
|
||||
"title":"开发说明",
|
||||
"tip":"soft",
|
||||
"name":"readme",
|
||||
"type":"扩展",
|
||||
"ps":"(mdserver-web)插件产开发说明,每个版本可能有所变化!",
|
||||
"ps":"[mdserver-web]插件产开发说明,每个版本可能有所变化!",
|
||||
"versions": "0.1",
|
||||
"shell":"install.sh",
|
||||
"checks":"server/readme",
|
||||
"path":"server/readme",
|
||||
"author":"mdserver-web",
|
||||
"home":"github.com/midoks/mdserver-web",
|
||||
"home":"https://github.com/midoks/mdserver-web",
|
||||
"date":"2018-11-30",
|
||||
"pid":"5"
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
daemonize yes
|
||||
pidfile {$SERVER_PATH}/redis/redis_6379.pid
|
||||
port 6379
|
||||
|
||||
timeout 0
|
||||
tcp-keepalive 0
|
||||
|
||||
loglevel notice
|
||||
|
||||
logfile {$SERVER_PATH}/redis/data/redis.log
|
||||
databases 16
|
||||
|
||||
################################ SNAPSHOTTING #################################
|
||||
|
||||
save 900 1
|
||||
save 300 10
|
||||
save 60 10000
|
||||
stop-writes-on-bgsave-error yes
|
||||
rdbcompression yes
|
||||
rdbchecksum yes
|
||||
dbfilename dump.rdb
|
||||
dir {$SERVER_PATH}/redis/data/
|
||||
|
||||
################################# REPLICATION #################################
|
||||
|
||||
slave-serve-stale-data yes
|
||||
slave-read-only yes
|
||||
|
||||
repl-disable-tcp-nodelay no
|
||||
slave-priority 100
|
||||
|
||||
################################## SECURITY ###################################
|
||||
|
||||
|
||||
################################### LIMITS ####################################
|
||||
maxclients 10000
|
||||
maxmemory-samples 3
|
||||
|
||||
############################## APPEND ONLY MODE ###############################
|
||||
|
||||
|
||||
#appendonly no
|
||||
# appendfsync always
|
||||
#appendfsync everysec
|
||||
# appendfsync no
|
||||
#no-appendfsync-on-rewrite no
|
||||
|
||||
auto-aof-rewrite-percentage 100
|
||||
auto-aof-rewrite-min-size 64mb
|
||||
|
||||
################################ LUA SCRIPTING ###############################
|
||||
|
||||
lua-time-limit 5000
|
||||
|
||||
################################## SLOW LOG ###################################
|
||||
|
||||
|
||||
slowlog-log-slower-than 10000
|
||||
slowlog-max-len 128
|
||||
|
||||
############################### ADVANCED CONFIG ###############################
|
||||
|
||||
hash-max-ziplist-entries 512
|
||||
hash-max-ziplist-value 64
|
||||
|
||||
list-max-ziplist-entries 512
|
||||
list-max-ziplist-value 64
|
||||
|
||||
set-max-intset-entries 512
|
||||
|
||||
zset-max-ziplist-entries 128
|
||||
zset-max-ziplist-value 64
|
||||
|
||||
activerehashing yes
|
||||
|
||||
client-output-buffer-limit normal 0 0 0
|
||||
client-output-buffer-limit slave 256mb 64mb 60
|
||||
client-output-buffer-limit pubsub 32mb 8mb 60
|
||||
|
||||
hz 10
|
||||
|
||||
aof-rewrite-incremental-fsync yes
|
||||
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.4 KiB |
@@ -1,16 +1,53 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="redisService();">服务</p>
|
||||
<p onclick="redisConfig();">配置修改</p>
|
||||
<p class="bgw" onclick="pluginService('redis');">服务</p>
|
||||
<p onclick="pluginInitD('redis');">自启动</p>
|
||||
<p onclick="pluginConfig('redis');">配置修改</p>
|
||||
<p onclick="redisStatus();">负载状态</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
<div class="soft-man-con"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$.getScript( "/plugins/file?name=redis&f=js/redis.js");
|
||||
pluginService('redis');
|
||||
|
||||
//redis负载状态 start
|
||||
function redisStatus() {
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'redis', func:'run_info'}, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
var rdata = $.parseJSON(data.data);
|
||||
hit = (parseInt(rdata.keyspace_hits) / (parseInt(rdata.keyspace_hits) + parseInt(rdata.keyspace_misses)) * 100).toFixed(2);
|
||||
var Con = '<div class="divtable">\
|
||||
<table class="table table-hover table-bordered" style="width: 490px;">\
|
||||
<thead><th>字段</th><th>当前值</th><th>说明</th></thead>\
|
||||
<tbody>\
|
||||
<tr><th>uptime_in_days</th><td>' + rdata.uptime_in_days + '</td><td>已运行天数</td></tr>\
|
||||
<tr><th>tcp_port</th><td>' + rdata.tcp_port + '</td><td>当前监听端口</td></tr>\
|
||||
<tr><th>connected_clients</th><td>' + rdata.connected_clients + '</td><td>连接的客户端数量</td></tr>\
|
||||
<tr><th>used_memory_rss</th><td>' + toSize(rdata.used_memory_rss) + '</td><td>Redis当前占用的系统内存总量</td></tr>\
|
||||
<tr><th>used_memory</th><td>' + toSize(rdata.used_memory) + '</td><td>Redis当前已分配的内存总量</td></tr>\
|
||||
<tr><th>used_memory_peak</th><td>' + toSize(rdata.used_memory_peak) + '</td><td>Redis历史分配内存的峰值</td></tr>\
|
||||
<tr><th>mem_fragmentation_ratio</th><td>' + rdata.mem_fragmentation_ratio + '%</td><td>内存碎片比率</td></tr>\
|
||||
<tr><th>total_connections_received</th><td>' + rdata.total_connections_received + '</td><td>运行以来连接过的客户端的总数量</td></tr>\
|
||||
<tr><th>total_commands_processed</th><td>' + rdata.total_commands_processed + '</td><td>运行以来执行过的命令的总数量</td></tr>\
|
||||
<tr><th>instantaneous_ops_per_sec</th><td>' + rdata.instantaneous_ops_per_sec + '</td><td>服务器每秒钟执行的命令数量</td></tr>\
|
||||
<tr><th>keyspace_hits</th><td>' + rdata.keyspace_hits + '</td><td>查找数据库键成功的次数</td></tr>\
|
||||
<tr><th>keyspace_misses</th><td>' + rdata.keyspace_misses + '</td><td>查找数据库键失败的次数</td></tr>\
|
||||
<tr><th>hit</th><td>' + hit + '%</td><td>查找数据库键命中率</td></tr>\
|
||||
<tr><th>latest_fork_usec</th><td>' + rdata.latest_fork_usec + '</td><td>最近一次 fork() 操作耗费的微秒数</td></tr>\
|
||||
<tbody>\
|
||||
</table></div>'
|
||||
$(".soft-man-con").html(Con);
|
||||
},'json');
|
||||
}
|
||||
//redis负载状态 end
|
||||
</script>
|
||||
@@ -8,6 +8,47 @@ import time
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
|
||||
app_debug = False
|
||||
if public.getOs() == 'darwin':
|
||||
app_debug = True
|
||||
|
||||
|
||||
def getPluginName():
|
||||
return 'redis'
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getConf():
|
||||
path = getPluginDir() + "/config/redis.conf"
|
||||
return path
|
||||
|
||||
|
||||
def getInitDTpl():
|
||||
path = getPluginDir() + "/init.d/redis.tpl"
|
||||
return path
|
||||
|
||||
|
||||
def getArgs():
|
||||
args = sys.argv[2:]
|
||||
tmp = {}
|
||||
for i in range(len(args)):
|
||||
t = args[i].split(':')
|
||||
tmp[t[0]] = t[1]
|
||||
return tmp
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
@@ -17,35 +58,64 @@ def status():
|
||||
return 'start'
|
||||
|
||||
|
||||
def initDreplace():
|
||||
|
||||
file_tpl = getInitDTpl()
|
||||
service_path = os.path.dirname(os.getcwd())
|
||||
|
||||
initD_path = getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
os.mkdir(initD_path)
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
|
||||
# initd replace
|
||||
content = public.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
|
||||
# config replace
|
||||
conf_content = public.readFile(getConf())
|
||||
conf_content = conf_content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(getServerDir() + '/redis.conf', conf_content)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def start():
|
||||
path = os.path.dirname(os.getcwd())
|
||||
cmd = path + "/redis/bin/redis-server"
|
||||
cmd = cmd + " " + path + "/redis/redis.conf"
|
||||
data = public.execShell(cmd)
|
||||
if data[0] == '':
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def stop():
|
||||
data = public.execShell(
|
||||
"ps -ef|grep redis |grep -v grep |grep -v python |awk '{print $2}' | xargs kill -9")
|
||||
if data[0] == '':
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def restart():
|
||||
return 'ok'
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def reload():
|
||||
return 'ok'
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def runInfo():
|
||||
path = os.path.dirname(os.getcwd())
|
||||
cmd = path + "/redis/bin/redis-cli info"
|
||||
cmd = getServerDir() + "/bin/redis-cli info"
|
||||
data = public.execShell(cmd)[0]
|
||||
res = [
|
||||
'tcp_port',
|
||||
@@ -74,17 +144,43 @@ def runInfo():
|
||||
return public.getJson(result)
|
||||
|
||||
|
||||
def getConf():
|
||||
path = os.path.dirname(os.getcwd()) + "/redis/redis.conf"
|
||||
return path
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
source_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
return 'ok'
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
if func == 'run_info':
|
||||
print runInfo()
|
||||
elif func == 'conf':
|
||||
print getConf()
|
||||
elif func == 'status':
|
||||
if func == 'status':
|
||||
print status()
|
||||
elif func == 'start':
|
||||
print start()
|
||||
@@ -94,3 +190,15 @@ if __name__ == "__main__":
|
||||
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()
|
||||
else:
|
||||
print 'error'
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
#!/bin/sh
|
||||
# chkconfig: 2345 55 25
|
||||
# description: Redis Service
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: Redis
|
||||
# Required-Start: $all
|
||||
# Required-Stop: $all
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: starts Redis
|
||||
# Description: starts the MDW-Web
|
||||
### END INIT INFO
|
||||
|
||||
# Simple Redis init.d script conceived to work on Linux systems
|
||||
# as it does use of the /proc filesystem.
|
||||
|
||||
CONF="{$SERVER_PATH}/redis/redis.conf"
|
||||
REDISPORT=$(cat $CONF |grep port|grep -v '#'|awk '{print $2}')
|
||||
REDISPASS=$(cat $CONF |grep requirepass|grep -v '#'|awk '{print $2}')
|
||||
if [ "$REDISPASS" != "" ];then
|
||||
REDISPASS=" -a $REDISPASS"
|
||||
fi
|
||||
EXEC={$SERVER_PATH}/redis/bin/redis-server
|
||||
CLIEXEC="{$SERVER_PATH}/redis/bin/redis-cli -p $REDISPORT$REDISPASS"
|
||||
PIDFILE={$SERVER_PATH}/redis/redis_6379.pid
|
||||
|
||||
mkdir -p {$SERVER_PATH}/redis/data
|
||||
|
||||
redis_start(){
|
||||
if [ -f $PIDFILE ]
|
||||
then
|
||||
echo "$PIDFILE exists, process is already running or crashed"
|
||||
else
|
||||
echo "Starting Redis server..."
|
||||
nohup $EXEC $CONF >> {$SERVER_PATH}/redis/logs.pl 2>&1 &
|
||||
fi
|
||||
}
|
||||
redis_stop(){
|
||||
if [ ! -f $PIDFILE ]
|
||||
then
|
||||
echo "$PIDFILE does not exist, process is not running"
|
||||
else
|
||||
PID=$(cat $PIDFILE)
|
||||
echo "Stopping ..."
|
||||
$CLIEXEC shutdown
|
||||
while [ -x /proc/${PID} ]
|
||||
do
|
||||
echo "Waiting for Redis to shutdown ..."
|
||||
sleep 1
|
||||
done
|
||||
echo "Redis stopped"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
redis_start
|
||||
;;
|
||||
stop)
|
||||
redis_stop
|
||||
;;
|
||||
restart|reload)
|
||||
redis_stop
|
||||
sleep 0.3
|
||||
redis_start
|
||||
;;
|
||||
*)
|
||||
echo "Please use start or stop as first argument"
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -16,24 +16,24 @@ Install_redis()
|
||||
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
wget -O $serverPath/tmp/redis.tar.gz http://download.redis.io/releases/redis-4.0.11.tar.gz
|
||||
cd $serverPath/tmp && tar -zxvf redis.tar.gz
|
||||
wget -O $serverPath/source/redis.tar.gz http://download.redis.io/releases/redis-4.0.11.tar.gz
|
||||
cd $serverPath/source && tar -zxvf redis.tar.gz
|
||||
|
||||
mkdir -p $serverPath/redis
|
||||
cd redis* && make PREFIX=$serverPath/redis install
|
||||
sed '/^ *#/d' redis.conf > $serverPath/redis/redis.conf
|
||||
|
||||
echo '安装完成' > $install_tmp
|
||||
echo '4.0' > $serverPath/redis/version.pl
|
||||
|
||||
rm -rf $serverPath/tmp
|
||||
echo '安装完成' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_redis()
|
||||
{
|
||||
echo "Uninstall_redis"
|
||||
rm -rf $serverPath/redis
|
||||
echo "Uninstall_redis" > $install_tmp
|
||||
}
|
||||
|
||||
|
||||
action=$1
|
||||
if [ "${1}" == 'install' ];then
|
||||
Install_redis
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
function redisOp(a, b) {
|
||||
|
||||
var c = "name=" + a + "&func=" + b;
|
||||
var d = "";
|
||||
|
||||
switch(b) {
|
||||
case "stop":d = '停止';break;
|
||||
case "start":d = '启动';break;
|
||||
case "restart":d = '重启';break;
|
||||
case "reload":d = '重载';break;
|
||||
}
|
||||
layer.confirm( '您真的要{1}{2}服务吗?'.replace('{1}', d).replace('{2}', a), {icon:3,closeBtn: 2}, function() {
|
||||
var e = layer.msg('正在{1}{2}服务,请稍候...'.replace('{1}', d).replace('{2}', a), {icon: 16,time: 0});
|
||||
$.post("/plugins/run", c, function(g) {
|
||||
layer.close(e);
|
||||
|
||||
var f = g.data == 'ok' ? '{1}服务已{2}'.replace('{1}', a).replace('{2}', d):'{1}服务{2}失败!'.replace('{1}', a).replace('{2}', d);
|
||||
layer.msg(f, {icon: g.data == 'ok' ? 1 : 2});
|
||||
|
||||
if(b != "reload" && g.data == 'ok') {
|
||||
if (b == 'start') {
|
||||
setRedisService('redis', true);
|
||||
} else if (b=='stop'){
|
||||
setRedisService('redis', false);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
if(g.data != 'ok') {
|
||||
layer.msg(g.data, {icon: 2,time: 0,shade: 0.3,shadeClose: true});
|
||||
}
|
||||
},'json').error(function() {
|
||||
layer.close(e);
|
||||
layer.msg('操作成功!', {icon: 1});
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
//服务
|
||||
function setRedisService(name, status){
|
||||
var serviceCon ='<p class="status">当前状态:<span>'+(status ? '开启' : '关闭' )+
|
||||
'</span><span style="color: '+
|
||||
(status?'#20a53a;':'red;')+
|
||||
' margin-left: 3px;" class="glyphicon ' + (status?'glyphicon glyphicon-play':'glyphicon-pause')+'"></span></p><div class="sfm-opt">\
|
||||
<button class="btn btn-default btn-sm" onclick="redisOp(\''+name+'\',\''+(status?'stop':'start')+'\')">'+(status?'停止':'启动')+'</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="redisOp(\''+name+'\',\'restart\')">重启</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="redisOp(\''+name+'\',\'reload\')">重载配置</button>\
|
||||
</div>';
|
||||
$(".soft-man-con").html(serviceCon);
|
||||
}
|
||||
|
||||
|
||||
//服务
|
||||
function redisService(){
|
||||
|
||||
$.post('/plugins/run', {name:'redis', func:'status'}, function(data) {
|
||||
console.log(data);
|
||||
if(!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:3000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
if (data.data == 'start'){
|
||||
setRedisService('redis', true);
|
||||
} else {
|
||||
setRedisService('redis', false);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
redisService();
|
||||
|
||||
|
||||
//配置修改 --- start
|
||||
function redisConfig(type){
|
||||
|
||||
var con = '<p style="color: #666; margin-bottom: 7px">提示:Ctrl+F 搜索关键字,Ctrl+G 查找下一个,Ctrl+S 保存,Ctrl+Shift+R 查找替换!</p><textarea class="bt-input-text" style="height: 320px; line-height:18px;" id="textBody"></textarea>\
|
||||
<button id="OnlineEditFileBtn" class="btn btn-success btn-sm" style="margin-top:10px;">保存</button>\
|
||||
<ul class="help-info-text c7 ptb15">\
|
||||
<li>此处为redis主配置文件,若您不了解配置规则,请勿随意修改。</li>\
|
||||
</ul>';
|
||||
$(".soft-man-con").html(con);
|
||||
|
||||
var loadT = layer.msg('配置文件路径获取中...',{icon:16,time:0,shade: [0.3, '#000']});
|
||||
$.post('/plugins/run', {name:'redis', func:'conf'},function (data) {
|
||||
layer.close(loadT);
|
||||
|
||||
var loadT2 = layer.msg('文件内容获取中...',{icon:16,time:0,shade: [0.3, '#000']});
|
||||
var fileName = data.data;
|
||||
$.post('/files/get_body', 'path=' + fileName, function(rdata) {
|
||||
layer.close(loadT2);
|
||||
if (!rdata.status){
|
||||
layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
$("#textBody").empty().text(rdata.data.data);
|
||||
$(".CodeMirror").remove();
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("textBody"), {
|
||||
extraKeys: {
|
||||
"Ctrl-Space": "autocomplete",
|
||||
"Ctrl-F": "findPersistent",
|
||||
"Ctrl-H": "replaceAll",
|
||||
"Ctrl-S": function() {
|
||||
redisConfSafe(fileName);
|
||||
}
|
||||
},
|
||||
lineNumbers: true,
|
||||
matchBrackets:true,
|
||||
});
|
||||
editor.focus();
|
||||
$(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0});
|
||||
$("#OnlineEditFileBtn").click(function(){
|
||||
$("#textBody").text(editor.getValue());
|
||||
redisConfSafe(fileName);
|
||||
});
|
||||
},'json');
|
||||
},'json');
|
||||
}
|
||||
|
||||
//配置保存
|
||||
function redisConfSafe(fileName) {
|
||||
var data = encodeURIComponent($("#textBody").val());
|
||||
var encoding = 'utf-8';
|
||||
var loadT = layer.msg('保存中...', {
|
||||
icon: 16,
|
||||
time: 0
|
||||
});
|
||||
$.post('/files/save_body', 'data=' + data + '&path=' + fileName + '&encoding=' + encoding, function(rdata) {
|
||||
layer.close(loadT);
|
||||
layer.msg(rdata.msg, {
|
||||
icon: rdata.status ? 1 : 2
|
||||
});
|
||||
},'json');
|
||||
}
|
||||
//配置修改 --- end
|
||||
|
||||
//redis负载状态 start
|
||||
function redisStatus() {
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', {name:'redis', func:'run_info'}, function(data) {
|
||||
layer.close(loadT);
|
||||
if (!data.status){
|
||||
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']});
|
||||
return;
|
||||
}
|
||||
|
||||
var rdata = $.parseJSON(data.data);
|
||||
hit = (parseInt(rdata.keyspace_hits) / (parseInt(rdata.keyspace_hits) + parseInt(rdata.keyspace_misses)) * 100).toFixed(2);
|
||||
var Con = '<div class="divtable">\
|
||||
<table class="table table-hover table-bordered" style="width: 490px;">\
|
||||
<thead><th>字段</th><th>当前值</th><th>说明</th></thead>\
|
||||
<tbody>\
|
||||
<tr><th>uptime_in_days</th><td>' + rdata.uptime_in_days + '</td><td>已运行天数</td></tr>\
|
||||
<tr><th>tcp_port</th><td>' + rdata.tcp_port + '</td><td>当前监听端口</td></tr>\
|
||||
<tr><th>connected_clients</th><td>' + rdata.connected_clients + '</td><td>连接的客户端数量</td></tr>\
|
||||
<tr><th>used_memory_rss</th><td>' + toSize(rdata.used_memory_rss) + '</td><td>Redis当前占用的系统内存总量</td></tr>\
|
||||
<tr><th>used_memory</th><td>' + toSize(rdata.used_memory) + '</td><td>Redis当前已分配的内存总量</td></tr>\
|
||||
<tr><th>used_memory_peak</th><td>' + toSize(rdata.used_memory_peak) + '</td><td>Redis历史分配内存的峰值</td></tr>\
|
||||
<tr><th>mem_fragmentation_ratio</th><td>' + rdata.mem_fragmentation_ratio + '%</td><td>内存碎片比率</td></tr>\
|
||||
<tr><th>total_connections_received</th><td>' + rdata.total_connections_received + '</td><td>运行以来连接过的客户端的总数量</td></tr>\
|
||||
<tr><th>total_commands_processed</th><td>' + rdata.total_commands_processed + '</td><td>运行以来执行过的命令的总数量</td></tr>\
|
||||
<tr><th>instantaneous_ops_per_sec</th><td>' + rdata.instantaneous_ops_per_sec + '</td><td>服务器每秒钟执行的命令数量</td></tr>\
|
||||
<tr><th>keyspace_hits</th><td>' + rdata.keyspace_hits + '</td><td>查找数据库键成功的次数</td></tr>\
|
||||
<tr><th>keyspace_misses</th><td>' + rdata.keyspace_misses + '</td><td>查找数据库键失败的次数</td></tr>\
|
||||
<tr><th>hit</th><td>' + hit + '%</td><td>查找数据库键命中率</td></tr>\
|
||||
<tr><th>latest_fork_usec</th><td>' + rdata.latest_fork_usec + '</td><td>最近一次 fork() 操作耗费的微秒数</td></tr>\
|
||||
<tbody>\
|
||||
</table></div>'
|
||||
$(".soft-man-con").html(Con);
|
||||
},'json');
|
||||
}
|
||||
//redis负载状态 end
|
||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 832 B |
@@ -7,8 +7,11 @@ import os
|
||||
import urllib
|
||||
import binascii
|
||||
import json
|
||||
import public
|
||||
import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
|
||||
|
||||
class score_main:
|
||||
|
||||
|
After Width: | Height: | Size: 659 B |