mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-18 23:45:52 +08:00
2020-07-10 解决public冲突。
This commit is contained in:
+14
-14
@@ -8,11 +8,11 @@ import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -53,10 +53,10 @@ def getArgs():
|
||||
|
||||
def status():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "stop"
|
||||
|
||||
data = public.execShell('sudo sysctl -n net.ipv4.tcp_congestion_control')
|
||||
data = mw.execShell('sudo sysctl -n net.ipv4.tcp_congestion_control')
|
||||
r = data[0].strip()
|
||||
if r == 'bbr':
|
||||
return 'start'
|
||||
@@ -65,26 +65,26 @@ def status():
|
||||
|
||||
def start():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
public.execShell('echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf')
|
||||
mw.execShell('echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf')
|
||||
cmd = 'echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf'
|
||||
public.execShell(cmd)
|
||||
public.execShell('sysctl -p')
|
||||
mw.execShell(cmd)
|
||||
mw.execShell('sysctl -p')
|
||||
return '执行成功!重启系统生效'
|
||||
|
||||
|
||||
def stop():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
cmd1 = "sed -i '/net\.core\.default_qdisc/d' /etc/sysctl.conf"
|
||||
public.execShell(cmd1)
|
||||
mw.execShell(cmd1)
|
||||
cmd2 = "sed -i '/net\.ipv4\.tcp_congestion_control/d' /etc/sysctl.conf"
|
||||
public.execShell(cmd2)
|
||||
public.execShell("sysctl -p")
|
||||
mw.execShell(cmd2)
|
||||
mw.execShell("sysctl -p")
|
||||
return '执行成功!重启系统生效'
|
||||
|
||||
|
||||
|
||||
+51
-51
@@ -11,11 +11,11 @@ import sys
|
||||
import subprocess
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -64,7 +64,7 @@ def initDreplace():
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -74,7 +74,7 @@ def status():
|
||||
def csvnOp(method):
|
||||
|
||||
if app_debug:
|
||||
os_name = public.getOs()
|
||||
os_name = mw.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
|
||||
@@ -83,8 +83,8 @@ def csvnOp(method):
|
||||
#_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)
|
||||
ret_csvn_httpd = mw.execShell(_initd_csvn_httpd + ' ' + method)
|
||||
# ret_csvn = mw.execShell(_initd_csvn + ' ' + method)
|
||||
subprocess.Popen(_initd_csvn + ' ' + method,
|
||||
stdout=subprocess.PIPE, shell=True)
|
||||
if ret_csvn_httpd[1] == '':
|
||||
@@ -110,7 +110,7 @@ def reload():
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
_initd_csvn = '/etc/init.d/csvn'
|
||||
@@ -124,14 +124,14 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
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')
|
||||
ret_csvn = mw.execShell(_csvn + ' install')
|
||||
ret_csvn_httpd = mw.execShell(_csvn_httpd + ' install')
|
||||
if ret_csvn[1] == '' and ret_csvn_httpd[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -139,14 +139,14 @@ def initdInstall():
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
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')
|
||||
ret_csvn = mw.execShell(_csvn + ' remove')
|
||||
ret_csvn_httpd = mw.execShell(_csvn_httpd + ' remove')
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ def csvnEdit():
|
||||
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)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def userAdd():
|
||||
@@ -170,7 +170,7 @@ def userAdd():
|
||||
svn_auth_file = getServerDir() + "/data/conf/svn_auth_file"
|
||||
cmd = htpasswd + ' -b ' + svn_auth_file + ' ' + \
|
||||
args['username'] + ' ' + args['password']
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
# print data
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
@@ -185,7 +185,7 @@ def userDel():
|
||||
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)
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -194,8 +194,8 @@ def userDel():
|
||||
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)
|
||||
return mw.getJson([])
|
||||
auth = mw.readFile(svn_auth_file)
|
||||
auth = auth.strip()
|
||||
auth_list = auth.split("\n")
|
||||
|
||||
@@ -232,14 +232,14 @@ def userList():
|
||||
page_info = {'count': ulist_sum, 'p': page,
|
||||
'row': 10, 'tojs': 'csvnUserList'}
|
||||
data = {}
|
||||
data['list'] = public.getPage(page_info)
|
||||
data['list'] = mw.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)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def projectAdd():
|
||||
@@ -249,9 +249,9 @@ def projectAdd():
|
||||
path = getServerDir() + '/bin/svnadmin'
|
||||
dest = getServerDir() + '/data/repositories/' + args['name']
|
||||
cmd = path + ' create ' + dest
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
if data[1] == '':
|
||||
public.execShell('chown -R csvn:csvn ' + dest)
|
||||
mw.execShell('chown -R csvn:csvn ' + dest)
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
@@ -263,7 +263,7 @@ def projectDel():
|
||||
|
||||
dest = getServerDir() + '/data/repositories/' + args['name']
|
||||
cmd = 'rm -rf ' + dest
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -273,7 +273,7 @@ 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)
|
||||
content = mw.readFile(http_main_conf)
|
||||
return re.search('Listen\s(\d+)', content).groups()[0]
|
||||
except Exception as e:
|
||||
pass # print e
|
||||
@@ -284,7 +284,7 @@ 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)
|
||||
content = mw.readFile(http_main_conf)
|
||||
return re.search('wrapper.java.additional.3=-Djetty.port=(\d+)', content).groups()[0]
|
||||
except Exception as e:
|
||||
pass # print e
|
||||
@@ -347,18 +347,18 @@ def projectList():
|
||||
|
||||
data = {}
|
||||
data['data'] = ret_data
|
||||
data['list'] = public.getPage(
|
||||
data['list'] = mw.getPage(
|
||||
{'count': dlist_sum, 'p': page, 'row': 10, 'tojs': 'csvnProjectList'})
|
||||
data['ip'] = public.getLocalIp()
|
||||
data['ip'] = mw.getLocalIp()
|
||||
data['port'] = getHttpPort()
|
||||
data['csvn_port'] = getCsvnPort()
|
||||
|
||||
return public.getJson(data)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getAllAclList():
|
||||
svn_access_file = getServerDir() + '/data/conf/svn_access_file'
|
||||
aData = public.readFile(svn_access_file)
|
||||
aData = mw.readFile(svn_access_file)
|
||||
aData = re.sub('#.*', '', aData)
|
||||
aData = aData.strip().split('[')[1:]
|
||||
allAcl = {}
|
||||
@@ -394,7 +394,7 @@ def makeAclFile(content):
|
||||
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)
|
||||
return mw.writeFile(svn_access_file, tmp)
|
||||
|
||||
|
||||
def projectAclList():
|
||||
@@ -405,7 +405,7 @@ def projectAclList():
|
||||
acl = getAllAclList()
|
||||
|
||||
if name in acl:
|
||||
return public.getJson(acl[name])
|
||||
return mw.getJson(acl[name])
|
||||
else:
|
||||
return 'fail'
|
||||
|
||||
@@ -543,19 +543,19 @@ def getCsvnPwd(user):
|
||||
pwd_file = 'data/csvn_sync.pl'
|
||||
|
||||
if os.path.exists(pwd_file):
|
||||
return public.readFile(pwd_file).strip()
|
||||
return mw.readFile(pwd_file).strip()
|
||||
|
||||
import time
|
||||
cur_time = time.time()
|
||||
rand_pwd = public.md5(str(cur_time))
|
||||
rand_pwd = mw.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)
|
||||
data = mw.execShell(cmd)
|
||||
|
||||
public.writeFile(pwd_file, pwd)
|
||||
mw.writeFile(pwd_file, pwd)
|
||||
return pwd
|
||||
|
||||
|
||||
@@ -570,21 +570,21 @@ def projectScriptLoad():
|
||||
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)
|
||||
pct_content = mw.readFile(post_commit_tpl)
|
||||
mw.writeFile(post_commit_file, pct_content)
|
||||
mw.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 = mw.readFile(commit_tpl)
|
||||
ct_content = ct_content.replace('{$PROJECT_DIR}', mw.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)
|
||||
mw.writeFile(commit_file, ct_content)
|
||||
mw.execShell('chmod 777 ' + commit_file)
|
||||
|
||||
return 'ok'
|
||||
|
||||
@@ -596,11 +596,11 @@ def projectScriptUnload():
|
||||
|
||||
post_commit_file = getServerDir() + '/data/repositories/' + '/' + \
|
||||
args['pname'] + '/hooks/post-commit'
|
||||
public.execShell('rm -f ' + post_commit_file)
|
||||
mw.execShell('rm -f ' + post_commit_file)
|
||||
|
||||
commit_file = getServerDir() + '/data/repositories/' + '/' + \
|
||||
args['pname'] + '/hooks/commit'
|
||||
public.execShell('rm -f ' + commit_file)
|
||||
mw.execShell('rm -f ' + commit_file)
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -619,7 +619,7 @@ def projectScriptEdit():
|
||||
data['status'] = False
|
||||
data['msg'] = 'file does not exist'
|
||||
|
||||
return public.getJson(data)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def projectScriptDebug():
|
||||
@@ -637,7 +637,7 @@ def projectScriptDebug():
|
||||
data['status'] = False
|
||||
data['msg'] = 'file does not exist'
|
||||
|
||||
return public.getJson(data)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getTotalStatistics():
|
||||
@@ -647,12 +647,12 @@ def getTotalStatistics():
|
||||
svn_path = getServerDir() + '/data/repositories'
|
||||
data['status'] = True
|
||||
data['count'] = len(os.listdir(svn_path))
|
||||
data['ver'] = public.readFile(getServerDir() + '/version.pl').strip()
|
||||
return public.returnJson(True, 'ok', data)
|
||||
data['ver'] = mw.readFile(getServerDir() + '/version.pl').strip()
|
||||
return mw.returnJson(True, 'ok', data)
|
||||
else:
|
||||
data['status'] = False
|
||||
data['count'] = 0
|
||||
return public.returnJson(False, 'fail', data)
|
||||
return mw.returnJson(False, 'fail', data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+18
-18
@@ -8,7 +8,7 @@ import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
|
||||
def getPluginName():
|
||||
@@ -16,11 +16,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -51,7 +51,7 @@ def status():
|
||||
|
||||
|
||||
def getAllProjectList(search):
|
||||
path = public.getWwwDir()
|
||||
path = mw.getWwwDir()
|
||||
dlist = []
|
||||
if os.path.exists(path):
|
||||
for filename in os.listdir(path):
|
||||
@@ -92,7 +92,7 @@ def projectListEdit():
|
||||
|
||||
file = getServerDir() + '/' + args['name'] + '.json'
|
||||
if not os.path.exists(file):
|
||||
public.execShell('touch ' + file)
|
||||
mw.execShell('touch ' + file)
|
||||
return file
|
||||
|
||||
|
||||
@@ -103,17 +103,17 @@ def projectListDel():
|
||||
|
||||
file = getServerDir() + '/' + args['name'] + '.json'
|
||||
if os.path.exists(file):
|
||||
content = public.readFile(file)
|
||||
content = mw.readFile(file)
|
||||
contentObj = json.loads(content)
|
||||
asyncUser = contentObj['client_email']
|
||||
cmd = getServerDir() + '/google-cloud-sdk/bin/'
|
||||
public.execShell(cmd + 'gcloud auth revoke ' + asyncUser)
|
||||
public.execShell('rm -rf ' + file)
|
||||
mw.execShell(cmd + 'gcloud auth revoke ' + asyncUser)
|
||||
mw.execShell('rm -rf ' + file)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def checkUserExist(cmd, user):
|
||||
data = public.execShell(cmd + 'gcloud auth list | grep ' + user)
|
||||
data = mw.execShell(cmd + 'gcloud auth list | grep ' + user)
|
||||
if data[0] == '':
|
||||
return False
|
||||
return True
|
||||
@@ -129,14 +129,14 @@ def projectListAsync():
|
||||
if not os.path.exists(file):
|
||||
return 'not configured file!'
|
||||
|
||||
content = public.readFile(file)
|
||||
content = mw.readFile(file)
|
||||
contentObj = json.loads(content)
|
||||
asyncUser = contentObj['client_email']
|
||||
cmd = getServerDir() + '/google-cloud-sdk/bin/'
|
||||
projectDir = public.getWwwDir() + '/' + args['name']
|
||||
projectDir = mw.getWwwDir() + '/' + args['name']
|
||||
|
||||
if not checkUserExist(cmd, asyncUser):
|
||||
public.execShell(
|
||||
mw.execShell(
|
||||
cmd + 'gcloud auth activate-service-account --key-file ' + file)
|
||||
|
||||
pName = contentObj['project_id']
|
||||
@@ -147,7 +147,7 @@ def projectListAsync():
|
||||
|
||||
taskAdd = (None, 'gae[async]',
|
||||
'execshell', '0', time.strftime('%Y-%m-%d %H:%M:%S'), asyncCmd)
|
||||
public.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd)
|
||||
mw.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd)
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -160,12 +160,12 @@ def projectListCmd():
|
||||
if not os.path.exists(file):
|
||||
return 'not configured file!'
|
||||
|
||||
content = public.readFile(file)
|
||||
content = mw.readFile(file)
|
||||
contentObj = json.loads(content)
|
||||
asyncUser = contentObj['client_email']
|
||||
cmd = getServerDir() + '/google-cloud-sdk/bin/'
|
||||
pName = contentObj['project_id']
|
||||
projectDir = public.getWwwDir() + '/' + args['name']
|
||||
projectDir = mw.getWwwDir() + '/' + args['name']
|
||||
|
||||
setUserCmd = 'sudo ' + cmd + 'gcloud config set account ' + asyncUser
|
||||
setUserCmd += ' && sudo ' + cmd + 'gcloud config set project ' + pName
|
||||
@@ -183,7 +183,7 @@ def projectListUrl():
|
||||
if not os.path.exists(file):
|
||||
return 'not configured file!'
|
||||
|
||||
content = public.readFile(file)
|
||||
content = mw.readFile(file)
|
||||
contentObj = json.loads(content)
|
||||
asyncUser = contentObj['client_email']
|
||||
plist = asyncUser.split('@')
|
||||
@@ -216,9 +216,9 @@ def projectList():
|
||||
|
||||
data = {}
|
||||
data['data'] = ret_data
|
||||
data['list'] = public.getPage(
|
||||
data['list'] = mw.getPage(
|
||||
{'count': dlist_sum, 'p': page, 'row': 10, 'tojs': 'projectList'})
|
||||
return public.getJson(data)
|
||||
return mw.getJson(data)
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
|
||||
@@ -10,10 +10,10 @@ import subprocess
|
||||
import threading
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -67,13 +67,13 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
pn = getPluginName()
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep " + pn + " | grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -91,17 +91,17 @@ def initDreplace():
|
||||
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
if not os.path.exists(file_bin):
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def start():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' start')
|
||||
data = mw.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -109,7 +109,7 @@ def start():
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
data = mw.execShell(file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -117,7 +117,7 @@ def stop():
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' restart')
|
||||
data = mw.execShell(file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -125,7 +125,7 @@ def restart():
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
data = mw.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -144,16 +144,16 @@ def initdInstall():
|
||||
source_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
|
||||
if not app_debug:
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
|
||||
initd_bin = getInitDFile()
|
||||
|
||||
@@ -165,6 +165,7 @@ def initdUinstall():
|
||||
def gfConf():
|
||||
return getServerDir() + "/config/application-prod.properties"
|
||||
|
||||
|
||||
def getLog():
|
||||
return getServerDir() + "/logs/go-fastdfs-web.log"
|
||||
|
||||
|
||||
+19
-19
@@ -10,10 +10,10 @@ import subprocess
|
||||
import threading
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -67,13 +67,13 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
pn = getPluginName()
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep " + pn + " |grep -v grep |grep -v .jar | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -91,17 +91,17 @@ def initDreplace():
|
||||
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
if not os.path.exists(file_bin):
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def start():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' start')
|
||||
data = mw.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -109,7 +109,7 @@ def start():
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
data = mw.execShell(file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -117,7 +117,7 @@ def stop():
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' restart')
|
||||
data = mw.execShell(file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -125,7 +125,7 @@ def restart():
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
data = mw.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -144,16 +144,16 @@ def initdInstall():
|
||||
source_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
|
||||
if not app_debug:
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
|
||||
initd_bin = getInitDFile()
|
||||
|
||||
@@ -182,7 +182,7 @@ def gfConfSet():
|
||||
{'name': 'enable_cross_origin', 'type': 0, 'ps': '是否开启跨站访问'},
|
||||
{'name': 'enable_tus', 'type': 0, 'ps': '是否开启断点续传'}
|
||||
]
|
||||
file = public.readFile(gfConf())
|
||||
file = mw.readFile(gfConf())
|
||||
data = json.loads(file)
|
||||
|
||||
result = []
|
||||
@@ -191,7 +191,7 @@ def gfConfSet():
|
||||
g['value'] = data[g['name']]
|
||||
result.append(g)
|
||||
|
||||
return public.getJson(result)
|
||||
return mw.getJson(result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+80
-80
@@ -10,11 +10,11 @@ sys.path.append("/usr/local/lib/python2.7/site-packages")
|
||||
import psutil
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
import mysql
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -77,7 +77,7 @@ def getConfTpl():
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -85,8 +85,8 @@ def status():
|
||||
|
||||
|
||||
def getHomeDir():
|
||||
if public.isAppleSystem():
|
||||
user = public.execShell(
|
||||
if mw.isAppleSystem():
|
||||
user = mw.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
return '/Users/' + user
|
||||
else:
|
||||
@@ -94,8 +94,8 @@ def getHomeDir():
|
||||
|
||||
|
||||
def getRunUser():
|
||||
if public.isAppleSystem():
|
||||
user = public.execShell(
|
||||
if mw.isAppleSystem():
|
||||
user = mw.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
return user
|
||||
else:
|
||||
@@ -110,8 +110,8 @@ export HOME=%s && ''' % ( getRunUser(), getHomeDir())
|
||||
|
||||
def contentReplace(content):
|
||||
|
||||
service_path = public.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', public.getRootDir())
|
||||
service_path = mw.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$RUN_USER}', getRunUser())
|
||||
content = content.replace('{$HOME_DIR}', getHomeDir())
|
||||
@@ -122,7 +122,7 @@ def contentReplace(content):
|
||||
def initDreplace():
|
||||
|
||||
file_tpl = getInitdConfTpl()
|
||||
service_path = public.getServerDir()
|
||||
service_path = mw.getServerDir()
|
||||
|
||||
initD_path = getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
@@ -130,18 +130,18 @@ def initDreplace():
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
|
||||
if not os.path.exists(file_bin):
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
conf_bin = getConf()
|
||||
if not os.path.exists(conf_bin):
|
||||
public.execShell('mkdir -p ' + getServerDir() + '/custom/conf')
|
||||
mw.execShell('mkdir -p ' + getServerDir() + '/custom/conf')
|
||||
conf_tpl = getConfTpl()
|
||||
content = public.readFile(conf_tpl)
|
||||
content = mw.readFile(conf_tpl)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(conf_bin, content)
|
||||
mw.writeFile(conf_bin, content)
|
||||
|
||||
log_path = getServerDir() + '/log'
|
||||
if not os.path.exists(log_path):
|
||||
@@ -151,7 +151,7 @@ def initDreplace():
|
||||
|
||||
|
||||
def getRootUrl():
|
||||
content = public.readFile(getConf())
|
||||
content = mw.readFile(getConf())
|
||||
rep = 'ROOT_URL\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
if not tmp:
|
||||
@@ -160,7 +160,7 @@ def getRootUrl():
|
||||
|
||||
|
||||
def getSshPort():
|
||||
content = public.readFile(getConf())
|
||||
content = mw.readFile(getConf())
|
||||
rep = 'SSH_PORT\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
if not tmp:
|
||||
@@ -169,7 +169,7 @@ def getSshPort():
|
||||
|
||||
|
||||
def getRootPath():
|
||||
content = public.readFile(getConf())
|
||||
content = mw.readFile(getConf())
|
||||
rep = 'ROOT\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
if not tmp:
|
||||
@@ -178,7 +178,7 @@ def getRootPath():
|
||||
|
||||
|
||||
def getDbConfValue():
|
||||
content = public.readFile(getConf())
|
||||
content = mw.readFile(getConf())
|
||||
|
||||
rep_scope = "\[database\](.*?)\["
|
||||
tmp = re.findall(rep_scope, content, re.S)
|
||||
@@ -212,22 +212,22 @@ def isSqlError(mysqlMsg):
|
||||
_mysqlMsg = str(mysqlMsg)
|
||||
# print _mysqlMsg
|
||||
if "MySQLdb" in _mysqlMsg:
|
||||
return public.returnData(False, 'MySQLdb组件缺失! <br>进入SSH命令行输入: pip install mysql-python')
|
||||
return mw.returnData(False, 'MySQLdb组件缺失! <br>进入SSH命令行输入: pip install mysql-python')
|
||||
if "2002," in _mysqlMsg:
|
||||
return public.returnData(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
return mw.returnData(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
if "using password:" in _mysqlMsg:
|
||||
return public.returnData(False, '数据库管理密码错误!')
|
||||
return mw.returnData(False, '数据库管理密码错误!')
|
||||
if "Connection refused" in _mysqlMsg:
|
||||
return public.returnData(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
return mw.returnData(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
if "1133," in _mysqlMsg:
|
||||
return public.returnData(False, '数据库用户不存在!')
|
||||
return mw.returnData(False, '数据库用户不存在!')
|
||||
if "1007," in _mysqlMsg:
|
||||
return public.returnData(False, '数据库已经存在!')
|
||||
return mw.returnData(False, '数据库已经存在!')
|
||||
if "1044," in _mysqlMsg:
|
||||
return public.returnData(False, mysqlMsg[1])
|
||||
return mw.returnData(False, mysqlMsg[1])
|
||||
if "2003," in _mysqlMsg:
|
||||
return public.returnData(False, mysqlMsg[1])
|
||||
return public.returnData(True, 'OK')
|
||||
return mw.returnData(False, mysqlMsg[1])
|
||||
return mw.returnData(True, 'OK')
|
||||
|
||||
|
||||
def start():
|
||||
@@ -248,7 +248,7 @@ def start():
|
||||
if not data['status']:
|
||||
return data['msg']
|
||||
|
||||
data = public.execShell(__SR + file + ' start')
|
||||
data = mw.execShell(__SR + file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[0]
|
||||
@@ -256,7 +256,7 @@ def start():
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(__SR + file + ' stop')
|
||||
data = mw.execShell(__SR + file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -264,7 +264,7 @@ def stop():
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = public.execShell(__SR + file + ' restart')
|
||||
data = mw.execShell(__SR + file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -272,7 +272,7 @@ def restart():
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = public.execShell(__SR + file + ' reload')
|
||||
data = mw.execShell(__SR + file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -280,7 +280,7 @@ def reload():
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
os_name = mw.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
@@ -292,26 +292,26 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
os_name = mw.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)
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
os_name = mw.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -346,7 +346,7 @@ def getGogsConf():
|
||||
{'name': 'SHOW_FOOTER_VERSION', 'type': 2, 'ps': 'Gogs版本信息'},
|
||||
{'name': 'SHOW_FOOTER_TEMPLATE_LOAD_TIME', 'type': 2, 'ps': 'Gogs模板加载时间'},
|
||||
]
|
||||
conf = public.readFile(getConf())
|
||||
conf = mw.readFile(getConf())
|
||||
result = []
|
||||
|
||||
for g in gets:
|
||||
@@ -356,7 +356,7 @@ def getGogsConf():
|
||||
continue
|
||||
g['value'] = tmp.groups()[0]
|
||||
result.append(g)
|
||||
return public.getJson(result)
|
||||
return mw.getJson(result)
|
||||
|
||||
|
||||
def submitGogsConf():
|
||||
@@ -376,15 +376,15 @@ def submitGogsConf():
|
||||
'SHOW_FOOTER_TEMPLATE_LOAD_TIME']
|
||||
args = getArgs()
|
||||
filename = getConf()
|
||||
conf = public.readFile(filename)
|
||||
conf = mw.readFile(filename)
|
||||
for g in gets:
|
||||
if g in args:
|
||||
rep = g + '\s*=\s*(.*)'
|
||||
val = g + ' = ' + args[g]
|
||||
conf = re.sub(rep, val, conf)
|
||||
public.writeFile(filename, conf)
|
||||
mw.writeFile(filename, conf)
|
||||
reload()
|
||||
return public.returnJson(True, '设置成功')
|
||||
return mw.returnJson(True, '设置成功')
|
||||
|
||||
|
||||
def userList():
|
||||
@@ -417,12 +417,12 @@ def userList():
|
||||
|
||||
page_info = {'count': count, 'p': page,
|
||||
'row': page_size, 'tojs': 'gogsUserList'}
|
||||
data['list'] = public.getPage(page_info)
|
||||
data['list'] = mw.getPage(page_info)
|
||||
data['page'] = page
|
||||
data['page_size'] = page_size
|
||||
data['page_count'] = int(math.ceil(count / page_size))
|
||||
data['data'] = list_data
|
||||
return public.returnJson(True, 'OK', data)
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
|
||||
|
||||
def getAllUserProject(user, search=''):
|
||||
@@ -465,7 +465,7 @@ def userProjectList():
|
||||
search = ''
|
||||
|
||||
if not 'name' in args:
|
||||
return public.returnJson(False, '缺少参数name')
|
||||
return mw.returnJson(False, '缺少参数name')
|
||||
if 'page' in args:
|
||||
page = int(args['page'])
|
||||
|
||||
@@ -487,38 +487,38 @@ def userProjectList():
|
||||
data['root_url'] = getRootUrl()
|
||||
data['data'] = ret_data
|
||||
data['args'] = args
|
||||
data['list'] = public.getPage(
|
||||
data['list'] = mw.getPage(
|
||||
{'count': dlist_sum, 'p': page, 'row': page_size, 'tojs': 'userProjectList'})
|
||||
|
||||
return public.returnJson(True, 'OK', data)
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
|
||||
|
||||
def projectScriptEdit():
|
||||
args = getArgs()
|
||||
|
||||
if not 'user' in args:
|
||||
return public.returnJson(True, 'username missing')
|
||||
return mw.returnJson(True, 'username missing')
|
||||
|
||||
if not 'name' in args:
|
||||
return public.returnJson(True, 'project name missing')
|
||||
return mw.returnJson(True, 'project name missing')
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
post_receive = getRootPath() + '/' + user + '/' + name + \
|
||||
'/custom_hooks/commit'
|
||||
if os.path.exists(post_receive):
|
||||
return public.returnJson(True, 'OK', {'path': post_receive})
|
||||
return mw.returnJson(True, 'OK', {'path': post_receive})
|
||||
else:
|
||||
return public.returnJson(False, 'file does not exist')
|
||||
return mw.returnJson(False, 'file does not exist')
|
||||
|
||||
|
||||
def projectScriptLoad():
|
||||
args = getArgs()
|
||||
if not 'user' in args:
|
||||
return public.returnJson(True, 'username missing')
|
||||
return mw.returnJson(True, 'username missing')
|
||||
|
||||
if not 'name' in args:
|
||||
return public.returnJson(True, 'project name missing')
|
||||
return mw.returnJson(True, 'project name missing')
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
@@ -528,28 +528,28 @@ def projectScriptLoad():
|
||||
post_receive = path + '/custom_hooks/post-receive'
|
||||
|
||||
if not os.path.exists(path + '/custom_hooks'):
|
||||
public.execShell('mkdir -p ' + path + '/custom_hooks')
|
||||
mw.execShell('mkdir -p ' + path + '/custom_hooks')
|
||||
|
||||
pct_content = public.readFile(post_receive_tpl)
|
||||
pct_content = mw.readFile(post_receive_tpl)
|
||||
pct_content = pct_content.replace('{$PATH}', path + '/custom_hooks')
|
||||
public.writeFile(post_receive, pct_content)
|
||||
public.execShell('chmod 777 ' + post_receive)
|
||||
mw.writeFile(post_receive, pct_content)
|
||||
mw.execShell('chmod 777 ' + post_receive)
|
||||
|
||||
commit_tpl = getPluginDir() + '/hook/commit.tpl'
|
||||
commit = path + '/custom_hooks/commit'
|
||||
|
||||
codeDir = public.getRootDir() + '/git'
|
||||
codeDir = mw.getRootDir() + '/git'
|
||||
|
||||
cc_content = public.readFile(commit_tpl)
|
||||
cc_content = mw.readFile(commit_tpl)
|
||||
|
||||
sshUrl = 'ssh://127.0.0.1:' + getSshPort()
|
||||
cc_content = cc_content.replace('{$GITROOTURL}', sshUrl)
|
||||
cc_content = cc_content.replace('{$CODE_DIR}', codeDir)
|
||||
cc_content = cc_content.replace('{$USERNAME}', user)
|
||||
cc_content = cc_content.replace('{$PROJECT}', args['name'])
|
||||
cc_content = cc_content.replace('{$WEB_ROOT}', public.getWwwDir())
|
||||
public.writeFile(commit, cc_content)
|
||||
public.execShell('chmod 777 ' + commit)
|
||||
cc_content = cc_content.replace('{$WEB_ROOT}', mw.getWwwDir())
|
||||
mw.writeFile(commit, cc_content)
|
||||
mw.execShell('chmod 777 ' + commit)
|
||||
|
||||
return 'ok'
|
||||
|
||||
@@ -557,31 +557,31 @@ def projectScriptLoad():
|
||||
def projectScriptUnload():
|
||||
args = getArgs()
|
||||
if not 'user' in args:
|
||||
return public.returnJson(True, 'username missing')
|
||||
return mw.returnJson(True, 'username missing')
|
||||
|
||||
if not 'name' in args:
|
||||
return public.returnJson(True, 'project name missing')
|
||||
return mw.returnJson(True, 'project name missing')
|
||||
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
|
||||
post_receive = getRootPath() + '/' + user + '/' + name + \
|
||||
'/custom_hooks/post-receive'
|
||||
public.execShell('rm -f ' + post_receive)
|
||||
mw.execShell('rm -f ' + post_receive)
|
||||
|
||||
commit = getRootPath() + '/' + user + '/' + name + \
|
||||
'/custom_hooks/commit'
|
||||
public.execShell('rm -f ' + commit)
|
||||
mw.execShell('rm -f ' + commit)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def projectScriptDebug():
|
||||
args = getArgs()
|
||||
if not 'user' in args:
|
||||
return public.returnJson(True, 'username missing')
|
||||
return mw.returnJson(True, 'username missing')
|
||||
|
||||
if not 'name' in args:
|
||||
return public.returnJson(True, 'project name missing')
|
||||
return mw.returnJson(True, 'project name missing')
|
||||
user = args['user']
|
||||
name = args['name'] + '.git'
|
||||
commit_log = getRootPath() + '/' + user + '/' + name + \
|
||||
@@ -595,25 +595,25 @@ def projectScriptDebug():
|
||||
data['status'] = False
|
||||
data['msg'] = '没有日志文件'
|
||||
|
||||
return public.getJson(data)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def gogsEdit():
|
||||
data = {}
|
||||
data['post_receive'] = getPluginDir() + '/hook/post-receive.tpl'
|
||||
data['commit'] = getPluginDir() + '/hook/commit.tpl'
|
||||
return public.getJson(data)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getRsaPublic():
|
||||
path = getHomeDir()
|
||||
path += '/.ssh/id_rsa.pub'
|
||||
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
|
||||
data = {}
|
||||
data['public'] = content
|
||||
return public.getJson(data)
|
||||
data['mw'] = content
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getTotalStatistics():
|
||||
@@ -626,12 +626,12 @@ def getTotalStatistics():
|
||||
|
||||
data['status'] = True
|
||||
data['count'] = count
|
||||
data['ver'] = public.readFile(getServerDir() + '/version.pl').strip()
|
||||
return public.returnJson(True, 'ok', data)
|
||||
data['ver'] = mw.readFile(getServerDir() + '/version.pl').strip()
|
||||
return mw.returnJson(True, 'ok', data)
|
||||
else:
|
||||
data['status'] = False
|
||||
data['count'] = 0
|
||||
return public.returnJson(False, 'fail', data)
|
||||
return mw.returnJson(False, 'fail', data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+15
-15
@@ -9,10 +9,10 @@ import sys
|
||||
import subprocess
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -62,48 +62,48 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
pn = getPluginName()
|
||||
cmd = "ps -ef|grep 'jenkins.war' | grep -v grep | awk '{print $2}'"
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def start():
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
data = public.execShell('service jenkins start')
|
||||
data = mw.execShell('service jenkins start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def stop():
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
data = public.execShell('service jenkins stop')
|
||||
data = mw.execShell('service jenkins stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def restart():
|
||||
data = public.execShell('service jenkins restart')
|
||||
data = mw.execShell('service jenkins restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def reload():
|
||||
data = public.execShell('service jenkins restart')
|
||||
data = mw.execShell('service jenkins restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -119,13 +119,13 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
|
||||
if not app_debug:
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
|
||||
+41
-41
@@ -7,10 +7,10 @@ import time
|
||||
import shutil
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
@@ -46,13 +46,13 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
cmd = "ps -ef|grep xl2tpd |grep -v grep | grep -v python | awk '{print $2}'"
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
@@ -61,62 +61,62 @@ def status():
|
||||
def initConf():
|
||||
l2tp_cs = getServerDir() + '/chap-secrets'
|
||||
if not os.path.exists(l2tp_cs):
|
||||
public.execShell('cp -rf ' + getPluginDir() +
|
||||
'/tmp/chap-secrets' + ' ' + getServerDir())
|
||||
mw.execShell('cp -rf ' + getPluginDir() +
|
||||
'/tmp/chap-secrets' + ' ' + getServerDir())
|
||||
|
||||
l2tp_is = getServerDir() + '/ipsec.secrets'
|
||||
if not os.path.exists(l2tp_is):
|
||||
public.execShell('cp -rf ' + getPluginDir() +
|
||||
'/tmp/ipsec.secrets' + ' ' + getServerDir())
|
||||
mw.execShell('cp -rf ' + getPluginDir() +
|
||||
'/tmp/ipsec.secrets' + ' ' + getServerDir())
|
||||
|
||||
|
||||
def start():
|
||||
initConf()
|
||||
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
data = public.execShell('service xl2tpd start')
|
||||
data = mw.execShell('service xl2tpd start')
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def stop():
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
data = public.execShell('service xl2tpd stop')
|
||||
data = mw.execShell('service xl2tpd stop')
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def restart():
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
data = public.execShell('service xl2tpd restart')
|
||||
data = mw.execShell('service xl2tpd restart')
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def reload():
|
||||
data = public.execShell('service xl2tpd reload')
|
||||
data = mw.execShell('service xl2tpd reload')
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def getPathFile():
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return getServerDir() + '/chap-secrets'
|
||||
return '/etc/ppp/chap-secrets'
|
||||
|
||||
|
||||
def getPathFilePsk():
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return getServerDir() + '/ipsec.secrets'
|
||||
return '/etc/ipsec.secrets'
|
||||
|
||||
@@ -125,13 +125,13 @@ def getUserList():
|
||||
import re
|
||||
path = getPathFile()
|
||||
if not os.path.exists(path):
|
||||
return public.returnJson(False, '密码配置文件不存在!')
|
||||
conf = public.readFile(path)
|
||||
return mw.returnJson(False, '密码配置文件不存在!')
|
||||
conf = mw.readFile(path)
|
||||
|
||||
conf = re.sub('#(.*)\n', '', conf)
|
||||
|
||||
if conf.strip() == '':
|
||||
return public.returnJson(True, 'ok', [])
|
||||
return mw.returnJson(True, 'ok', [])
|
||||
|
||||
ulist = conf.strip().split('\n')
|
||||
|
||||
@@ -146,36 +146,36 @@ def getUserList():
|
||||
line_info['ip'] = line[3]
|
||||
user.append(line_info)
|
||||
|
||||
return public.returnJson(True, 'ok', user)
|
||||
return mw.returnJson(True, 'ok', user)
|
||||
|
||||
|
||||
def addUser():
|
||||
if public.isAppleSystem():
|
||||
return public.returnJson(False, "Apple Computer does not support")
|
||||
if mw.isAppleSystem():
|
||||
return mw.returnJson(False, "Apple Computer does not support")
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['username'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
ret = public.execShell('echo ' + args['username'] + '|l2tp -a')
|
||||
ret = mw.execShell('echo ' + args['username'] + '|l2tp -a')
|
||||
if ret[1] == '':
|
||||
return public.returnJson(True, '添加成功!:' + ret[0])
|
||||
return public.returnJson(False, '添加失败:' + ret[0])
|
||||
return mw.returnJson(True, '添加成功!:' + ret[0])
|
||||
return mw.returnJson(False, '添加失败:' + ret[0])
|
||||
|
||||
|
||||
def delUser():
|
||||
if public.isAppleSystem():
|
||||
return public.returnJson(False, "Apple Computer does not support")
|
||||
if mw.isAppleSystem():
|
||||
return mw.returnJson(False, "Apple Computer does not support")
|
||||
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['username'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
ret = public.execShell('echo ' + args['username'] + '|l2tp -d')
|
||||
ret = mw.execShell('echo ' + args['username'] + '|l2tp -d')
|
||||
if ret[1] == '':
|
||||
return public.returnJson(True, '删除成功!:' + ret[0])
|
||||
return public.returnJson(False, '删除失败:' + ret[0])
|
||||
return mw.returnJson(True, '删除成功!:' + ret[0])
|
||||
return mw.returnJson(False, '删除失败:' + ret[0])
|
||||
|
||||
|
||||
def modUser():
|
||||
@@ -192,17 +192,17 @@ def modUser():
|
||||
# sed -i "/^\<${user}\>/d" /etc/ppp/chap-secrets
|
||||
# echo "${user} l2tpd ${pass} *" >> /etc/ppp/chap-secrets
|
||||
|
||||
if public.isAppleSystem():
|
||||
public.execShell("sed -i .bak '/^\(" + username + "\)/d' " + path)
|
||||
if mw.isAppleSystem():
|
||||
mw.execShell("sed -i .bak '/^\(" + username + "\)/d' " + path)
|
||||
else:
|
||||
public.execShell("sed -i '/^\(" + username + "\)/d' " + path)
|
||||
mw.execShell("sed -i '/^\(" + username + "\)/d' " + path)
|
||||
# print 'echo "' + username + " l2tpd " + password + " *\" >>"
|
||||
# + path
|
||||
ret = public.execShell("echo \"" + username +
|
||||
" l2tpd " + password + " *\" >>" + path)
|
||||
ret = mw.execShell("echo \"" + username +
|
||||
" l2tpd " + password + " *\" >>" + path)
|
||||
if ret[1] == '':
|
||||
return public.returnJson(True, '修改成功!')
|
||||
return public.returnJson(False, '修改失败')
|
||||
return mw.returnJson(True, '修改成功!')
|
||||
return mw.returnJson(False, '修改失败')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+22
-23
@@ -7,10 +7,10 @@ import time
|
||||
import re
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -44,7 +44,7 @@ def getConfTpl():
|
||||
|
||||
def getMemPort():
|
||||
path = getConf()
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
rep = 'PORT\s*=\s*(\d*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0]
|
||||
@@ -68,7 +68,7 @@ def getArgs():
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -78,7 +78,7 @@ def status():
|
||||
def initDreplace():
|
||||
|
||||
file_tpl = getConfTpl()
|
||||
service_path = public.getServerDir()
|
||||
service_path = mw.getServerDir()
|
||||
|
||||
initD_path = getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
@@ -86,17 +86,17 @@ def initDreplace():
|
||||
file_bin = initD_path + '/memcached'
|
||||
|
||||
if not os.path.exists(file_bin):
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def memOp(method):
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' ' + method)
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -146,15 +146,15 @@ def runInfo():
|
||||
result['hit'] = float(result['get_hits']) / \
|
||||
float(result['cmd_get']) * 100
|
||||
|
||||
conf = public.readFile(getConf())
|
||||
conf = mw.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)
|
||||
return mw.getJson(result)
|
||||
except Exception, e:
|
||||
return public.getJson({})
|
||||
return mw.getJson({})
|
||||
|
||||
|
||||
def saveConf():
|
||||
@@ -164,13 +164,13 @@ def saveConf():
|
||||
print confFile
|
||||
try:
|
||||
args = getArgs()
|
||||
content = public.readFile(confFile)
|
||||
content = mw.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)
|
||||
mw.writeFile(confFile, content)
|
||||
restart()
|
||||
return 'save ok'
|
||||
except Exception as e:
|
||||
@@ -180,7 +180,7 @@ def saveConf():
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
@@ -191,24 +191,23 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
|
||||
mem_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(mem_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
return 'ok'
|
||||
|
||||
@@ -20,7 +20,7 @@ class mysql:
|
||||
def __Conn(self):
|
||||
'''连接MYSQL数据库'''
|
||||
try:
|
||||
import public
|
||||
import mw
|
||||
socket = '/tmp/mysql.sock'
|
||||
try:
|
||||
import MySQLdb
|
||||
@@ -28,13 +28,13 @@ class mysql:
|
||||
self.__DB_ERR = ex
|
||||
return False
|
||||
try:
|
||||
myconf = public.readFile(self.__DB_CNF)
|
||||
myconf = mw.readFile(self.__DB_CNF)
|
||||
rep = "port\s*=\s*([0-9]+)"
|
||||
self.__DB_PORT = int(re.search(rep, myconf).groups()[0])
|
||||
except:
|
||||
self.__DB_PORT = 3306
|
||||
# print self.__DB_PASS
|
||||
#self.__DB_PASS = public.M('config').where('id=?', (1,)).getField('mysql_root')
|
||||
#self.__DB_PASS = mw.M('config').where('id=?', (1,)).getField('mysql_root')
|
||||
try:
|
||||
self.__DB_CONN = MySQLdb.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS,
|
||||
port=self.__DB_PORT, charset="utf8", connect_timeout=1, unix_socket=socket)
|
||||
|
||||
+118
-118
@@ -12,11 +12,11 @@ reload(sys)
|
||||
sys.setdefaultencoding('utf-8')
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -25,14 +25,14 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
import mysql
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -61,8 +61,8 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def getConf():
|
||||
@@ -76,8 +76,8 @@ def getInitdTpl():
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = public.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', public.getRootDir())
|
||||
service_path = mw.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$SERVER_APP_PATH}', service_path + '/mysql')
|
||||
return content
|
||||
@@ -87,13 +87,13 @@ def pSqliteDb(dbname='databases'):
|
||||
file = getServerDir() + '/mysql.db'
|
||||
name = 'mysql'
|
||||
if not os.path.exists(file):
|
||||
conn = public.M(dbname).dbPos(getServerDir(), name)
|
||||
csql = public.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
csql = mw.readFile(getPluginDir() + '/conf/mysql.sql')
|
||||
csql_list = csql.split(';')
|
||||
for index in range(len(csql_list)):
|
||||
conn.execute(csql_list[index], ())
|
||||
else:
|
||||
conn = public.M(dbname).dbPos(getServerDir(), name)
|
||||
conn = mw.M(dbname).dbPos(getServerDir(), name)
|
||||
return conn
|
||||
|
||||
|
||||
@@ -114,10 +114,10 @@ def initDreplace():
|
||||
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
if not os.path.exists(file_bin):
|
||||
content = public.readFile(initd_tpl)
|
||||
content = mw.readFile(initd_tpl)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
mysql_conf_dir = getServerDir() + '/etc'
|
||||
if not os.path.exists(mysql_conf_dir):
|
||||
@@ -126,15 +126,15 @@ def initDreplace():
|
||||
mysql_conf = mysql_conf_dir + '/my.cnf'
|
||||
if not os.path.exists(mysql_conf):
|
||||
mysql_conf_tpl = getPluginDir() + '/conf/my.cnf'
|
||||
content = public.readFile(mysql_conf_tpl)
|
||||
content = mw.readFile(mysql_conf_tpl)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(mysql_conf, content)
|
||||
mw.writeFile(mysql_conf, content)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep mysqld |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -143,7 +143,7 @@ def status():
|
||||
|
||||
def getDataDir():
|
||||
file = getConf()
|
||||
content = public.readFile(file)
|
||||
content = mw.readFile(file)
|
||||
rep = 'datadir\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0].strip()
|
||||
@@ -152,14 +152,14 @@ def getDataDir():
|
||||
def binLog():
|
||||
args = getArgs()
|
||||
conf = getConf()
|
||||
con = public.readFile(conf)
|
||||
con = mw.readFile(conf)
|
||||
|
||||
if con.find('#log-bin=mysql-bin') != -1:
|
||||
if args.has_key('status'):
|
||||
return public.returnJson(False, '0')
|
||||
return mw.returnJson(False, '0')
|
||||
con = con.replace('#log-bin=mysql-bin', 'log-bin=mysql-bin')
|
||||
con = con.replace('#binlog_format=mixed', 'binlog_format=mixed')
|
||||
public.execShell('sync')
|
||||
mw.execShell('sync')
|
||||
restart()
|
||||
else:
|
||||
path = getDataDir()
|
||||
@@ -170,15 +170,15 @@ def binLog():
|
||||
continue
|
||||
if n[0:9] == 'mysql-bin':
|
||||
dsize += os.path.getsize(path + '/' + n)
|
||||
return public.returnJson(True, dsize)
|
||||
return mw.returnJson(True, dsize)
|
||||
con = con.replace('log-bin=mysql-bin', '#log-bin=mysql-bin')
|
||||
con = con.replace('binlog_format=mixed', '#binlog_format=mixed')
|
||||
public.execShell('sync')
|
||||
mw.execShell('sync')
|
||||
restart()
|
||||
public.execShell('rm -f ' + path + '/mysql-bin.*')
|
||||
mw.execShell('rm -f ' + path + '/mysql-bin.*')
|
||||
|
||||
public.writeFile(conf, con)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
mw.writeFile(conf, con)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def getErrorLog():
|
||||
@@ -193,25 +193,25 @@ def getErrorLog():
|
||||
break
|
||||
print filename
|
||||
if not os.path.exists(filename):
|
||||
return public.returnJson(False, '指定文件不存在!')
|
||||
return mw.returnJson(False, '指定文件不存在!')
|
||||
if args.has_key('close'):
|
||||
public.writeFile(filename, '')
|
||||
return public.returnJson(False, '日志已清空')
|
||||
info = public.getNumLines(filename, 1000)
|
||||
return public.returnJson(True, 'OK', info)
|
||||
mw.writeFile(filename, '')
|
||||
return mw.returnJson(False, '日志已清空')
|
||||
info = mw.getNumLines(filename, 1000)
|
||||
return mw.returnJson(True, 'OK', info)
|
||||
|
||||
|
||||
def getShowLogFile():
|
||||
file = getConf()
|
||||
content = public.readFile(file)
|
||||
content = mw.readFile(file)
|
||||
rep = 'slow-query-log-file\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0].strip()
|
||||
|
||||
|
||||
def pGetDbUser():
|
||||
if public.isAppleSystem():
|
||||
user = public.execShell(
|
||||
if mw.isAppleSystem():
|
||||
user = mw.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
return user
|
||||
return 'mysql'
|
||||
@@ -224,7 +224,7 @@ def initMysqlData():
|
||||
user = pGetDbUser()
|
||||
cmd = 'cd ' + serverdir + ' && ./scripts/mysql_install_db --user=' + \
|
||||
user + ' --basedir=' + serverdir + ' --ldata=' + datadir
|
||||
public.execShell(cmd)
|
||||
mw.execShell(cmd)
|
||||
return 0
|
||||
return 1
|
||||
|
||||
@@ -234,10 +234,10 @@ def initMysqlPwd():
|
||||
|
||||
serverdir = getServerDir()
|
||||
|
||||
pwd = public.getRandomString(16)
|
||||
pwd = mw.getRandomString(16)
|
||||
cmd_pass = serverdir + '/bin/mysqladmin -uroot password ' + pwd
|
||||
pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (pwd,))
|
||||
public.execShell(cmd_pass)
|
||||
mw.execShell(cmd_pass)
|
||||
return True
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ def reload():
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
initd_bin = getInitDFile()
|
||||
@@ -286,22 +286,22 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mysql_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(mysql_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
return 'ok'
|
||||
@@ -309,7 +309,7 @@ def initdUinstall():
|
||||
|
||||
def getMyDbPos():
|
||||
file = getConf()
|
||||
content = public.readFile(file)
|
||||
content = mw.readFile(file)
|
||||
rep = 'datadir\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0].strip()
|
||||
@@ -324,43 +324,43 @@ def setMyDbPos():
|
||||
s_datadir = getMyDbPos()
|
||||
t_datadir = args['datadir']
|
||||
if t_datadir == s_datadir:
|
||||
return public.returnJson(False, '与当前存储目录相同,无法迁移文件!')
|
||||
return mw.returnJson(False, '与当前存储目录相同,无法迁移文件!')
|
||||
|
||||
if not os.path.exists(t_datadir):
|
||||
public.execShell('mkdir -p ' + t_datadir)
|
||||
mw.execShell('mkdir -p ' + t_datadir)
|
||||
|
||||
# public.execShell('/etc/init.d/mysqld stop')
|
||||
# mw.execShell('/etc/init.d/mysqld stop')
|
||||
stop()
|
||||
public.execShell('cp -rf ' + s_datadir + '/* ' + t_datadir + '/')
|
||||
public.execShell('chown -R mysql.mysql ' + t_datadir)
|
||||
public.execShell('chmod -R 755 ' + t_datadir)
|
||||
public.execShell('rm -f ' + t_datadir + '/*.pid')
|
||||
public.execShell('rm -f ' + t_datadir + '/*.err')
|
||||
mw.execShell('cp -rf ' + s_datadir + '/* ' + t_datadir + '/')
|
||||
mw.execShell('chown -R mysql.mysql ' + t_datadir)
|
||||
mw.execShell('chmod -R 755 ' + t_datadir)
|
||||
mw.execShell('rm -f ' + t_datadir + '/*.pid')
|
||||
mw.execShell('rm -f ' + t_datadir + '/*.err')
|
||||
|
||||
path = getServerDir()
|
||||
myfile = path + '/etc/my.cnf'
|
||||
mycnf = public.readFile(myfile)
|
||||
public.writeFile(path + '/etc/my_backup.cnf', mycnf)
|
||||
mycnf = mw.readFile(myfile)
|
||||
mw.writeFile(path + '/etc/my_backup.cnf', mycnf)
|
||||
|
||||
mycnf = mycnf.replace(s_datadir, t_datadir)
|
||||
public.writeFile(myfile, mycnf)
|
||||
mw.writeFile(myfile, mycnf)
|
||||
start()
|
||||
|
||||
result = public.execShell(
|
||||
result = mw.execShell(
|
||||
'ps aux|grep mysqld| grep -v grep|grep -v python')
|
||||
if len(result[0]) > 10:
|
||||
public.writeFile('data/datadir.pl', t_datadir)
|
||||
return public.returnJson(True, '存储目录迁移成功!')
|
||||
mw.writeFile('data/datadir.pl', t_datadir)
|
||||
return mw.returnJson(True, '存储目录迁移成功!')
|
||||
else:
|
||||
public.execShell('pkill -9 mysqld')
|
||||
public.writeFile(myfile, public.readFile(path + '/etc/my_backup.cnf'))
|
||||
mw.execShell('pkill -9 mysqld')
|
||||
mw.writeFile(myfile, mw.readFile(path + '/etc/my_backup.cnf'))
|
||||
start()
|
||||
return public.returnJson(False, '文件迁移失败!')
|
||||
return mw.returnJson(False, '文件迁移失败!')
|
||||
|
||||
|
||||
def getMyPort():
|
||||
file = getConf()
|
||||
content = public.readFile(file)
|
||||
content = mw.readFile(file)
|
||||
rep = 'port\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0].strip()
|
||||
@@ -374,12 +374,12 @@ def setMyPort():
|
||||
|
||||
port = args['port']
|
||||
file = getConf()
|
||||
content = public.readFile(file)
|
||||
content = mw.readFile(file)
|
||||
rep = "port\s*=\s*([0-9]+)\s*\n"
|
||||
content = re.sub(rep, 'port = ' + port + '\n', content)
|
||||
public.writeFile(file, content)
|
||||
mw.writeFile(file, content)
|
||||
restart()
|
||||
return public.returnJson(True, '编辑成功!')
|
||||
return mw.returnJson(True, '编辑成功!')
|
||||
|
||||
|
||||
def runInfo():
|
||||
@@ -394,7 +394,7 @@ def runInfo():
|
||||
# print data
|
||||
if data[0] == 1045 or data[0] == 2003:
|
||||
pwd = db.getPwd()
|
||||
return public.returnJson(False, 'mysql password error:' + pwd + '!')
|
||||
return mw.returnJson(False, 'mysql password error:' + pwd + '!')
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
@@ -411,7 +411,7 @@ def runInfo():
|
||||
except:
|
||||
result['File'] = 'OFF'
|
||||
result['Position'] = 'OFF'
|
||||
return public.getJson(result)
|
||||
return mw.getJson(result)
|
||||
|
||||
|
||||
def myDbStatus():
|
||||
@@ -432,7 +432,7 @@ def myDbStatus():
|
||||
if result['mem']['query_cache_type'] != 'ON':
|
||||
result[
|
||||
'mem']['query_cache_size'] = '0'
|
||||
return public.getJson(result)
|
||||
return mw.getJson(result)
|
||||
|
||||
|
||||
def setDbStatus():
|
||||
@@ -442,7 +442,7 @@ def setDbStatus():
|
||||
'thread_cache_size', 'table_open_cache']
|
||||
args = getArgs()
|
||||
conFile = getConf()
|
||||
content = public.readFile(conFile)
|
||||
content = mw.readFile(conFile)
|
||||
n = 0
|
||||
for g in gets:
|
||||
s = 'M'
|
||||
@@ -457,25 +457,25 @@ def setDbStatus():
|
||||
else:
|
||||
content = content.replace('[mysqld]\n', '[mysqld]\n' + c)
|
||||
n += 1
|
||||
public.writeFile(conFile, content)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
mw.writeFile(conFile, content)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def isSqlError(mysqlMsg):
|
||||
# 检测数据库执行错误
|
||||
mysqlMsg = str(mysqlMsg)
|
||||
if "MySQLdb" in mysqlMsg:
|
||||
return public.returnJson(False, 'MySQLdb组件缺失! <br>进入SSH命令行输入: pip install mysql-python')
|
||||
return mw.returnJson(False, 'MySQLdb组件缺失! <br>进入SSH命令行输入: pip install mysql-python')
|
||||
if "2002," in mysqlMsg:
|
||||
return public.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
return mw.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
if "using password:" in mysqlMsg:
|
||||
return public.returnJson(False, '数据库管理密码错误!')
|
||||
return mw.returnJson(False, '数据库管理密码错误!')
|
||||
if "Connection refused" in mysqlMsg:
|
||||
return public.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
return mw.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
if "1133" in mysqlMsg:
|
||||
return public.returnJson(False, '数据库用户不存在!')
|
||||
return mw.returnJson(False, '数据库用户不存在!')
|
||||
if "1007" in mysqlMsg:
|
||||
return public.returnJson(False, '数据库已经存在!')
|
||||
return mw.returnJson(False, '数据库已经存在!')
|
||||
return None
|
||||
|
||||
|
||||
@@ -532,7 +532,7 @@ def getDbList():
|
||||
_page['p'] = page
|
||||
_page['row'] = page_size
|
||||
_page['tojs'] = 'dbList'
|
||||
data['page'] = public.getPage(_page)
|
||||
data['page'] = mw.getPage(_page)
|
||||
data['data'] = clist
|
||||
|
||||
info = {}
|
||||
@@ -540,7 +540,7 @@ def getDbList():
|
||||
'id=?', (1,)).getField('mysql_root')
|
||||
data['info'] = info
|
||||
|
||||
return public.getJson(data)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def syncGetDatabases():
|
||||
@@ -570,15 +570,15 @@ def syncGetDatabases():
|
||||
host = user[1]
|
||||
break
|
||||
|
||||
ps = public.getMsg('INPUT_PS')
|
||||
ps = mw.getMsg('INPUT_PS')
|
||||
if value[0] == 'test':
|
||||
ps = public.getMsg('DATABASE_TEST')
|
||||
ps = mw.getMsg('DATABASE_TEST')
|
||||
addTime = time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
if psdb.add('name,username,password,accept,ps,addtime', (value[0], value[0], '', host, ps, addTime)):
|
||||
n += 1
|
||||
|
||||
msg = public.getInfo('本次共从服务器获取了{1}个数据库!', (str(n),))
|
||||
return public.returnJson(True, msg)
|
||||
msg = mw.getInfo('本次共从服务器获取了{1}个数据库!', (str(n),))
|
||||
return mw.returnJson(True, msg)
|
||||
|
||||
|
||||
def toDbBase(find):
|
||||
@@ -586,7 +586,7 @@ def toDbBase(find):
|
||||
psdb = pSqliteDb('databases')
|
||||
if len(find['password']) < 3:
|
||||
find['username'] = find['name']
|
||||
find['password'] = public.md5(str(time.time()) + find['name'])[0:10]
|
||||
find['password'] = mw.md5(str(time.time()) + find['name'])[0:10]
|
||||
psdb.where("id=?", (find['id'],)).save(
|
||||
'password,username', (find['password'], find['username']))
|
||||
|
||||
@@ -632,8 +632,8 @@ def syncToDatabases():
|
||||
result = toDbBase(find)
|
||||
if result == 1:
|
||||
n += 1
|
||||
msg = public.getInfo('本次共同步了{1}个数据库!', (str(n),))
|
||||
return public.returnJson(True, msg)
|
||||
msg = mw.getInfo('本次共同步了{1}个数据库!', (str(n),))
|
||||
return mw.returnJson(True, msg)
|
||||
|
||||
|
||||
def setRootPwd():
|
||||
@@ -650,7 +650,7 @@ def setRootPwd():
|
||||
if isError != None:
|
||||
return isError
|
||||
|
||||
m_version = public.readFile(getServerDir() + '/version.pl')
|
||||
m_version = mw.readFile(getServerDir() + '/version.pl')
|
||||
if m_version.find('5.7') == 0 or m_version.find('8.0') == 0:
|
||||
pdb.execute(
|
||||
"UPDATE mysql.user SET authentication_string='' WHERE user='root'")
|
||||
@@ -663,9 +663,9 @@ def setRootPwd():
|
||||
"update mysql.user set Password=password('" + password + "') where User='root'")
|
||||
pdb.execute("flush privileges")
|
||||
pSqliteDb('config').where('id=?', (1,)).save('mysql_root', (password,))
|
||||
return public.returnJson(True, '数据库root密码修改成功!')
|
||||
return mw.returnJson(True, '数据库root密码修改成功!')
|
||||
except Exception as ex:
|
||||
return public.returnJson(False, '修改错误:' + str(ex))
|
||||
return mw.returnJson(False, '修改错误:' + str(ex))
|
||||
|
||||
|
||||
def setUserPwd():
|
||||
@@ -682,7 +682,7 @@ def setUserPwd():
|
||||
psdb = pSqliteDb('databases')
|
||||
name = psdb.where('id=?', (id,)).getField('name')
|
||||
|
||||
m_version = public.readFile(getServerDir() + '/version.pl')
|
||||
m_version = mw.readFile(getServerDir() + '/version.pl')
|
||||
if m_version.find('5.7') == 0 or m_version.find('8.0') == 0:
|
||||
tmp = pdb.query(
|
||||
"select Host from mysql.user where User='" + name + "' AND Host!='localhost'")
|
||||
@@ -702,10 +702,10 @@ def setUserPwd():
|
||||
return isError
|
||||
pdb.execute("flush privileges")
|
||||
psdb.where("id=?", (id,)).setField('password', newpassword)
|
||||
return public.returnJson(True, public.getInfo('修改数据库[{1}]密码成功!', (name,)))
|
||||
return mw.returnJson(True, mw.getInfo('修改数据库[{1}]密码成功!', (name,)))
|
||||
except Exception as ex:
|
||||
# print str(ex)
|
||||
return public.returnJson(False, public.getInfo('修改数据库[{1}]密码失败!', (name,)))
|
||||
return mw.returnJson(False, mw.getInfo('修改数据库[{1}]密码失败!', (name,)))
|
||||
|
||||
|
||||
def setDbPs():
|
||||
@@ -720,9 +720,9 @@ def setDbPs():
|
||||
try:
|
||||
psdb = pSqliteDb('databases')
|
||||
psdb.where("id=?", (sid,)).setField('ps', ps)
|
||||
return public.returnJson(True, public.getInfo('修改数据库[{1}]备注成功!', (name,)))
|
||||
return mw.returnJson(True, mw.getInfo('修改数据库[{1}]备注成功!', (name,)))
|
||||
except Exception as e:
|
||||
return public.returnJson(True, public.getInfo('修改数据库[{1}]备注失败!', (name,)))
|
||||
return mw.returnJson(True, mw.getInfo('修改数据库[{1}]备注失败!', (name,)))
|
||||
|
||||
|
||||
def addDb():
|
||||
@@ -746,15 +746,15 @@ def addDb():
|
||||
|
||||
reg = "^[\w\.-]+$"
|
||||
if not re.match(reg, args['name']):
|
||||
return public.returnJson(False, '数据库名称不能带有特殊符号!')
|
||||
return mw.returnJson(False, '数据库名称不能带有特殊符号!')
|
||||
checks = ['root', 'mysql', 'test', 'sys', 'panel_logs']
|
||||
if dbuser in checks or len(dbuser) < 1:
|
||||
return public.returnJson(False, '数据库用户名不合法!')
|
||||
return mw.returnJson(False, '数据库用户名不合法!')
|
||||
if dbname in checks or len(dbname) < 1:
|
||||
return public.returnJson(False, '数据库名称不合法!')
|
||||
return mw.returnJson(False, '数据库名称不合法!')
|
||||
|
||||
if len(password) < 1:
|
||||
password = public.md5(time.time())[0:8]
|
||||
password = mw.md5(time.time())[0:8]
|
||||
|
||||
wheres = {
|
||||
'utf8': 'utf8_general_ci',
|
||||
@@ -768,7 +768,7 @@ def addDb():
|
||||
psdb = pSqliteDb('databases')
|
||||
|
||||
if psdb.where("name=? or username=?", (dbname, dbuser)).count():
|
||||
return public.returnJson(False, '数据库已存在!')
|
||||
return mw.returnJson(False, '数据库已存在!')
|
||||
|
||||
result = pdb.execute("create database `" + dbname +
|
||||
"` DEFAULT CHARACTER SET " + codeing + " COLLATE " + codeStr)
|
||||
@@ -786,7 +786,7 @@ def addDb():
|
||||
addTime = time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
psdb.add('pid,name,username,password,accept,ps,addtime',
|
||||
(0, dbname, dbuser, password, address, ps, addTime))
|
||||
return public.returnJson(True, '添加成功!')
|
||||
return mw.returnJson(True, '添加成功!')
|
||||
|
||||
|
||||
def delDb():
|
||||
@@ -819,9 +819,9 @@ def delDb():
|
||||
|
||||
# 删除SQLITE
|
||||
psdb.where("id=?", (id,)).delete()
|
||||
return public.returnJson(True, '删除成功!')
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
except Exception as ex:
|
||||
return public.returnJson(False, '删除失败!' + str(ex))
|
||||
return mw.returnJson(False, '删除失败!' + str(ex))
|
||||
|
||||
|
||||
def getDbAccess():
|
||||
@@ -840,12 +840,12 @@ def getDbAccess():
|
||||
|
||||
users = mapToList(users)
|
||||
if len(users) < 1:
|
||||
return public.returnJson(True, "127.0.0.1")
|
||||
return mw.returnJson(True, "127.0.0.1")
|
||||
accs = []
|
||||
for c in users:
|
||||
accs.append(c[0])
|
||||
userStr = ','.join(accs)
|
||||
return public.returnJson(True, userStr)
|
||||
return mw.returnJson(True, userStr)
|
||||
|
||||
|
||||
def toSize(size):
|
||||
@@ -881,7 +881,7 @@ def setDbAccess():
|
||||
__createUser(dbname, name, password, access)
|
||||
|
||||
psdb.where('username=?', (name,)).save('accept', (access,))
|
||||
return public.returnJson(True, '设置成功!')
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def getDbInfo():
|
||||
@@ -910,7 +910,7 @@ def getDbInfo():
|
||||
|
||||
if not data:
|
||||
data = 0
|
||||
ret['data_size'] = public.toSize(data)
|
||||
ret['data_size'] = mw.toSize(data)
|
||||
# print ret
|
||||
ret['database'] = db_name
|
||||
|
||||
@@ -918,7 +918,7 @@ def getDbInfo():
|
||||
|
||||
for i in tables:
|
||||
if i == 1049:
|
||||
return public.returnJson(False, '指定数据库不存在!')
|
||||
return mw.returnJson(False, '指定数据库不存在!')
|
||||
table = mapToList(
|
||||
pdb.query("show table status from `%s` where name = '%s'" % (db_name, i[0])))
|
||||
if not table:
|
||||
@@ -930,14 +930,14 @@ def getDbInfo():
|
||||
ret2['collation'] = table[0][14]
|
||||
data_size = table[0][6] + table[0][8]
|
||||
ret2['data_byte'] = data_size
|
||||
ret2['data_size'] = public.toSize(data_size)
|
||||
ret2['data_size'] = mw.toSize(data_size)
|
||||
ret2['table_name'] = i[0]
|
||||
ret3.append(ret2)
|
||||
except:
|
||||
continue
|
||||
ret['tables'] = (ret3)
|
||||
|
||||
return public.getJson(ret)
|
||||
return mw.getJson(ret)
|
||||
|
||||
|
||||
def repairTable():
|
||||
@@ -960,8 +960,8 @@ def repairTable():
|
||||
if len(ret) > 0:
|
||||
for i in ret:
|
||||
pdb.execute('REPAIR TABLE `%s`.`%s`' % (db_name, i))
|
||||
return public.returnJson(True, "修复完成!")
|
||||
return public.returnJson(False, "修复失败!")
|
||||
return mw.returnJson(True, "修复完成!")
|
||||
return mw.returnJson(False, "修复失败!")
|
||||
|
||||
|
||||
def optTable():
|
||||
@@ -984,8 +984,8 @@ def optTable():
|
||||
if len(ret) > 0:
|
||||
for i in ret:
|
||||
pdb.execute('OPTIMIZE TABLE `%s`.`%s`' % (db_name, i))
|
||||
return public.returnJson(True, "优化成功!")
|
||||
return public.returnJson(False, "优化失败或者已经优化过了!")
|
||||
return mw.returnJson(True, "优化成功!")
|
||||
return mw.returnJson(False, "优化失败或者已经优化过了!")
|
||||
|
||||
|
||||
def alterTable():
|
||||
@@ -1010,8 +1010,8 @@ def alterTable():
|
||||
for i in ret:
|
||||
pdb.execute('alter table `%s`.`%s` ENGINE=`%s`' %
|
||||
(db_name, i, table_type))
|
||||
return public.returnJson(True, "更改成功!")
|
||||
return public.returnJson(False, "更改失败!")
|
||||
return mw.returnJson(True, "更改成功!")
|
||||
return mw.returnJson(False, "更改失败!")
|
||||
|
||||
|
||||
def getTotalStatistics():
|
||||
@@ -1020,12 +1020,12 @@ def getTotalStatistics():
|
||||
if st == 'start':
|
||||
data['status'] = True
|
||||
data['count'] = pSqliteDb('databases').count()
|
||||
data['ver'] = public.readFile(getServerDir() + '/version.pl').strip()
|
||||
return public.returnJson(True, 'ok', data)
|
||||
data['ver'] = mw.readFile(getServerDir() + '/version.pl').strip()
|
||||
return mw.returnJson(True, 'ok', data)
|
||||
else:
|
||||
data['status'] = False
|
||||
data['count'] = 0
|
||||
return public.returnJson(False, 'fail', data)
|
||||
return mw.returnJson(False, 'fail', data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+157
-155
@@ -8,11 +8,11 @@ import subprocess
|
||||
import json
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
@@ -48,12 +48,12 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def getConf():
|
||||
path = public.getServerDir() + "/openresty/nginx/conf/nginx.conf"
|
||||
path = mw.getServerDir() + "/openresty/nginx/conf/nginx.conf"
|
||||
return path
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ def initDomainInfo():
|
||||
data = []
|
||||
path_domains = getJsonPath('domains')
|
||||
|
||||
_list = public.M('sites').field('id,name,path').where(
|
||||
_list = mw.M('sites').field('id,name,path').where(
|
||||
'status=?', ('1',)).order('id desc').select()
|
||||
|
||||
for i in range(len(_list)):
|
||||
@@ -69,7 +69,7 @@ def initDomainInfo():
|
||||
tmp['name'] = _list[i]['name']
|
||||
tmp['path'] = _list[i]['path']
|
||||
|
||||
_list_domain = public.M('domain').field('name').where(
|
||||
_list_domain = mw.M('domain').field('name').where(
|
||||
'pid=?', (_list[i]['id'],)).order('id desc').select()
|
||||
|
||||
tmp_j = []
|
||||
@@ -78,8 +78,8 @@ def initDomainInfo():
|
||||
|
||||
tmp['domains'] = tmp_j
|
||||
data.append(tmp)
|
||||
cjson = public.getJson(data)
|
||||
public.writeFile(path_domains, cjson)
|
||||
cjson = mw.getJson(data)
|
||||
mw.writeFile(path_domains, cjson)
|
||||
|
||||
|
||||
def initSiteInfo():
|
||||
@@ -88,14 +88,14 @@ def initSiteInfo():
|
||||
path_config = getJsonPath('config')
|
||||
path_site = getJsonPath('site')
|
||||
|
||||
config_contents = public.readFile(path_config)
|
||||
config_contents = mw.readFile(path_config)
|
||||
config_contents = json.loads(config_contents)
|
||||
|
||||
domain_contents = public.readFile(path_domains)
|
||||
domain_contents = mw.readFile(path_domains)
|
||||
domain_contents = json.loads(domain_contents)
|
||||
|
||||
try:
|
||||
site_contents = public.readFile(path_site)
|
||||
site_contents = mw.readFile(path_site)
|
||||
except Exception as e:
|
||||
site_contents = "{}"
|
||||
|
||||
@@ -133,8 +133,8 @@ def initSiteInfo():
|
||||
|
||||
site_contents_new[name] = tmp
|
||||
|
||||
cjson = public.getJson(site_contents_new)
|
||||
public.writeFile(path_site, cjson)
|
||||
cjson = mw.getJson(site_contents_new)
|
||||
mw.writeFile(path_site, cjson)
|
||||
|
||||
|
||||
def initTotalInfo():
|
||||
@@ -142,11 +142,11 @@ def initTotalInfo():
|
||||
path_domains = getJsonPath('domains')
|
||||
path_total = getJsonPath('total')
|
||||
|
||||
domain_contents = public.readFile(path_domains)
|
||||
domain_contents = mw.readFile(path_domains)
|
||||
domain_contents = json.loads(domain_contents)
|
||||
|
||||
try:
|
||||
total_contents = public.readFile(path_total)
|
||||
total_contents = mw.readFile(path_total)
|
||||
except Exception as e:
|
||||
total_contents = "{}"
|
||||
|
||||
@@ -167,8 +167,8 @@ def initTotalInfo():
|
||||
_name[name] = tmp
|
||||
total_contents['sites'] = _name
|
||||
|
||||
cjson = public.getJson(total_contents)
|
||||
public.writeFile(path_total, cjson)
|
||||
cjson = mw.getJson(total_contents)
|
||||
mw.writeFile(path_total, cjson)
|
||||
|
||||
|
||||
def status():
|
||||
@@ -180,7 +180,7 @@ def status():
|
||||
if not os.path.exists(path):
|
||||
return 'stop'
|
||||
|
||||
conf = public.readFile(path)
|
||||
conf = mw.readFile(path)
|
||||
if conf.find("#include luawaf.conf;") != -1:
|
||||
return 'stop'
|
||||
if conf.find("luawaf.conf;") == -1:
|
||||
@@ -189,9 +189,9 @@ def status():
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = public.getServerDir()
|
||||
waf_path = public.getServerDir() + "/openresty/nginx/conf/waf"
|
||||
content = content.replace('{$ROOT_PATH}', public.getRootDir())
|
||||
service_path = mw.getServerDir()
|
||||
waf_path = mw.getServerDir() + "/openresty/nginx/conf/waf"
|
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$WAF_PATH}', waf_path)
|
||||
return content
|
||||
@@ -200,77 +200,77 @@ def contentReplace(content):
|
||||
def initDreplace():
|
||||
|
||||
config = getPluginDir() + '/waf/config.json'
|
||||
content = public.readFile(config)
|
||||
content = mw.readFile(config)
|
||||
content = json.loads(content)
|
||||
content['reqfile_path'] = public.getServerDir(
|
||||
content['reqfile_path'] = mw.getServerDir(
|
||||
) + "/openresty/nginx/conf/waf/html"
|
||||
public.writeFile(config, public.getJson(content))
|
||||
mw.writeFile(config, mw.getJson(content))
|
||||
|
||||
path = public.getServerDir() + "/openresty/nginx/conf"
|
||||
path = mw.getServerDir() + "/openresty/nginx/conf"
|
||||
if not os.path.exists(path + '/waf'):
|
||||
sdir = getPluginDir() + '/waf'
|
||||
cmd = 'cp -rf ' + sdir + ' ' + path
|
||||
public.execShell(cmd)
|
||||
mw.execShell(cmd)
|
||||
|
||||
config = public.getServerDir() + "/openresty/nginx/conf/waf/lua/init.lua"
|
||||
content = public.readFile(config)
|
||||
config = mw.getServerDir() + "/openresty/nginx/conf/waf/lua/init.lua"
|
||||
content = mw.readFile(config)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(config, content)
|
||||
mw.writeFile(config, content)
|
||||
|
||||
waf_conf = public.getServerDir() + "/openresty/nginx/conf/luawaf.conf"
|
||||
waf_conf = mw.getServerDir() + "/openresty/nginx/conf/luawaf.conf"
|
||||
waf_tpl = getPluginDir() + "/conf/luawaf.conf"
|
||||
content = public.readFile(waf_tpl)
|
||||
content = mw.readFile(waf_tpl)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(waf_conf, content)
|
||||
mw.writeFile(waf_conf, content)
|
||||
|
||||
|
||||
def start():
|
||||
initDreplace()
|
||||
|
||||
path = getConf()
|
||||
conf = public.readFile(path)
|
||||
conf = mw.readFile(path)
|
||||
conf = conf.replace('#include luawaf.conf;', "include luawaf.conf;")
|
||||
|
||||
public.writeFile(path, conf)
|
||||
public.restartWeb()
|
||||
mw.writeFile(path, conf)
|
||||
mw.restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def stop():
|
||||
path = public.getServerDir() + "/openresty/nginx/conf/waf"
|
||||
path = mw.getServerDir() + "/openresty/nginx/conf/waf"
|
||||
if os.path.exists(path):
|
||||
cmd = 'rm -rf ' + path
|
||||
public.execShell(cmd)
|
||||
mw.execShell(cmd)
|
||||
|
||||
path = getConf()
|
||||
conf = public.readFile(path)
|
||||
conf = mw.readFile(path)
|
||||
conf = conf.replace('include luawaf.conf;', "#include luawaf.conf;")
|
||||
|
||||
public.writeFile(path, conf)
|
||||
public.restartWeb()
|
||||
mw.writeFile(path, conf)
|
||||
mw.restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def restart():
|
||||
public.restartWeb()
|
||||
mw.restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def reload():
|
||||
stop()
|
||||
public.execShell('rm -rf ' + public.getServerDir() +
|
||||
"/openresty/nginx/logs/error.log")
|
||||
mw.execShell('rm -rf ' + mw.getServerDir() +
|
||||
"/openresty/nginx/logs/error.log")
|
||||
start()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def getJsonPath(name):
|
||||
path = public.getServerDir() + "/openresty/nginx/conf/waf/" + name + ".json"
|
||||
path = mw.getServerDir() + "/openresty/nginx/conf/waf/" + name + ".json"
|
||||
return path
|
||||
|
||||
|
||||
def getRuleJsonPath(name):
|
||||
path = public.getServerDir() + "/openresty/nginx/conf/waf/rule/" + name + ".json"
|
||||
path = mw.getServerDir() + "/openresty/nginx/conf/waf/rule/" + name + ".json"
|
||||
return path
|
||||
|
||||
|
||||
@@ -282,8 +282,8 @@ def getRule():
|
||||
|
||||
rule_name = args['rule_name']
|
||||
fpath = getRuleJsonPath(rule_name)
|
||||
content = public.readFile(fpath)
|
||||
return public.returnJson(True, 'ok', content)
|
||||
content = mw.readFile(fpath)
|
||||
return mw.returnJson(True, 'ok', content)
|
||||
|
||||
|
||||
def addRule():
|
||||
@@ -297,7 +297,7 @@ def addRule():
|
||||
ps = args['ps']
|
||||
|
||||
fpath = getRuleJsonPath(ruleName)
|
||||
content = public.readFile(fpath)
|
||||
content = mw.readFile(fpath)
|
||||
content = json.loads(content)
|
||||
|
||||
tmp_k = []
|
||||
@@ -308,10 +308,11 @@ def addRule():
|
||||
|
||||
content.append(tmp_k)
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(fpath, cjson)
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
return public.returnJson(True, '设置成功!', content)
|
||||
|
||||
def removeRule():
|
||||
args = getArgs()
|
||||
@@ -323,16 +324,17 @@ def removeRule():
|
||||
ruleName = args['ruleName']
|
||||
|
||||
fpath = getRuleJsonPath(ruleName)
|
||||
content = public.readFile(fpath)
|
||||
content = mw.readFile(fpath)
|
||||
content = json.loads(content)
|
||||
|
||||
k = content[index]
|
||||
content.remove(k)
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(fpath, cjson)
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
return public.returnJson(True, '设置成功!', content)
|
||||
|
||||
def setRuleState():
|
||||
args = getArgs()
|
||||
@@ -344,7 +346,7 @@ def setRuleState():
|
||||
ruleName = args['ruleName']
|
||||
|
||||
fpath = getRuleJsonPath(ruleName)
|
||||
content = public.readFile(fpath)
|
||||
content = mw.readFile(fpath)
|
||||
content = json.loads(content)
|
||||
|
||||
b = content[index][0]
|
||||
@@ -353,11 +355,10 @@ def setRuleState():
|
||||
else:
|
||||
content[index][0] = 1
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(fpath, cjson)
|
||||
|
||||
return public.returnJson(True, '设置成功!', content)
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
|
||||
def modifyRule():
|
||||
@@ -372,7 +373,7 @@ def modifyRule():
|
||||
rulePs = args['rulePs']
|
||||
|
||||
fpath = getRuleJsonPath(ruleName)
|
||||
content = public.readFile(fpath)
|
||||
content = mw.readFile(fpath)
|
||||
content = json.loads(content)
|
||||
|
||||
tmp = content[index]
|
||||
@@ -385,10 +386,10 @@ def modifyRule():
|
||||
|
||||
content[index] = tmp_k
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(fpath, cjson)
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(fpath, cjson)
|
||||
|
||||
return public.returnJson(True, '设置成功!', content)
|
||||
return mw.returnJson(True, '设置成功!', content)
|
||||
|
||||
|
||||
def getSiteRule():
|
||||
@@ -401,13 +402,13 @@ def getSiteRule():
|
||||
siteRule = args['ruleName']
|
||||
|
||||
path = getJsonPath('site')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
r = content[siteName][siteRule]
|
||||
|
||||
cjson = public.getJson(r)
|
||||
return public.returnJson(True, 'ok!', cjson)
|
||||
cjson = mw.getJson(r)
|
||||
return mw.returnJson(True, 'ok!', cjson)
|
||||
|
||||
|
||||
def addSiteRule():
|
||||
@@ -421,14 +422,14 @@ def addSiteRule():
|
||||
ruleValue = args['ruleValue']
|
||||
|
||||
path = getJsonPath('site')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
content[siteName][siteRule].append(ruleValue)
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def addIpWhite():
|
||||
@@ -441,7 +442,7 @@ def addIpWhite():
|
||||
end_ip = args['end_ip']
|
||||
|
||||
path = getRuleJsonPath('ip_white')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
data = []
|
||||
@@ -461,9 +462,9 @@ def addIpWhite():
|
||||
|
||||
content.append(data)
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def removeIpWhite():
|
||||
@@ -475,15 +476,15 @@ def removeIpWhite():
|
||||
index = args['index']
|
||||
|
||||
path = getRuleJsonPath('ip_white')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
k = content[int(index)]
|
||||
content.remove(k)
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def addIpBlack():
|
||||
@@ -496,7 +497,7 @@ def addIpBlack():
|
||||
end_ip = args['end_ip']
|
||||
|
||||
path = getRuleJsonPath('ip_black')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
data = []
|
||||
@@ -516,9 +517,9 @@ def addIpBlack():
|
||||
|
||||
content.append(data)
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def removeIpBlack():
|
||||
@@ -530,15 +531,15 @@ def removeIpBlack():
|
||||
index = args['index']
|
||||
|
||||
path = getRuleJsonPath('ip_black')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
k = content[int(index)]
|
||||
content.remove(k)
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setIpv6Black():
|
||||
@@ -550,13 +551,13 @@ def setIpv6Black():
|
||||
addr = args['addr'].replace('_', ':')
|
||||
path = getRuleJsonPath('ipv6_black')
|
||||
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
content.append(addr)
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def delIpv6Black():
|
||||
@@ -568,14 +569,14 @@ def delIpv6Black():
|
||||
addr = args['addr'].replace('_', ':')
|
||||
path = getRuleJsonPath('ipv6_black')
|
||||
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
content.remove(addr)
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def removeSiteRule():
|
||||
@@ -589,15 +590,15 @@ def removeSiteRule():
|
||||
index = args['index']
|
||||
|
||||
path = getJsonPath('site')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
ruleValue = content[siteName][siteRule][int(index)]
|
||||
content[siteName][siteRule].remove(ruleValue)
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setObjStatus():
|
||||
@@ -607,16 +608,16 @@ def setObjStatus():
|
||||
return data[1]
|
||||
|
||||
conf = getJsonPath('config')
|
||||
content = public.readFile(conf)
|
||||
content = mw.readFile(conf)
|
||||
cobj = json.loads(content)
|
||||
|
||||
o = args['obj']
|
||||
status = args['statusCode']
|
||||
cobj[o]['status'] = status
|
||||
|
||||
cjson = public.getJson(cobj)
|
||||
public.writeFile(conf, cjson)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setRetry():
|
||||
@@ -627,34 +628,34 @@ def setRetry():
|
||||
return data[1]
|
||||
|
||||
conf = getJsonPath('config')
|
||||
content = public.readFile(conf)
|
||||
content = mw.readFile(conf)
|
||||
cobj = json.loads(content)
|
||||
|
||||
cobj['retry'] = args
|
||||
|
||||
cjson = public.getJson(cobj)
|
||||
public.writeFile(conf, cjson)
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
|
||||
return public.returnJson(True, '设置成功!', [])
|
||||
return mw.returnJson(True, '设置成功!', [])
|
||||
|
||||
|
||||
def setSiteRetry():
|
||||
return public.returnJson(True, '设置成功-?!', [])
|
||||
return mw.returnJson(True, '设置成功-?!', [])
|
||||
|
||||
|
||||
def setCcConf():
|
||||
args = getArgs()
|
||||
data = checkArgs(args, ['siteName', 'cycle', 'limit', 'endtime','is_open_global','increase'])
|
||||
data = checkArgs(args, ['siteName', 'cycle', 'limit',
|
||||
'endtime', 'is_open_global', 'increase'])
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
conf = getJsonPath('config')
|
||||
content = public.readFile(conf)
|
||||
content = mw.readFile(conf)
|
||||
cobj = json.loads(content)
|
||||
|
||||
tmp = cobj['cc']
|
||||
|
||||
|
||||
tmp['cycle'] = int(args['cycle'])
|
||||
tmp['limit'] = int(args['limit'])
|
||||
tmp['endtime'] = int(args['endtime'])
|
||||
@@ -662,12 +663,14 @@ def setCcConf():
|
||||
tmp['increase'] = args['increase']
|
||||
cobj['cc'] = tmp
|
||||
|
||||
cjson = public.getJson(cobj)
|
||||
public.writeFile(conf, cjson)
|
||||
return public.returnJson(True, '设置成功!', [])
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
return mw.returnJson(True, '设置成功!', [])
|
||||
|
||||
|
||||
def setSiteCcConf():
|
||||
return public.returnJson(True, '设置成功-?!', [])
|
||||
return mw.returnJson(True, '设置成功-?!', [])
|
||||
|
||||
|
||||
def saveScanRule():
|
||||
args = getArgs()
|
||||
@@ -676,19 +679,19 @@ def saveScanRule():
|
||||
return data[1]
|
||||
|
||||
path = getRuleJsonPath('scan_black')
|
||||
cjson = public.getJson(args)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '设置成功!', [])
|
||||
cjson = mw.getJson(args)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '设置成功!', [])
|
||||
|
||||
|
||||
def getSiteConfig():
|
||||
path = getJsonPath('site')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
|
||||
content = json.loads(content)
|
||||
|
||||
total = getJsonPath('total')
|
||||
total_content = public.readFile(total)
|
||||
total_content = mw.readFile(total)
|
||||
total_content = json.loads(total_content)
|
||||
|
||||
# print total_content
|
||||
@@ -713,8 +716,8 @@ def getSiteConfig():
|
||||
# print tmp
|
||||
content[x]['total'] = tmp
|
||||
|
||||
content = public.getJson(content)
|
||||
return public.returnJson(True, 'ok!', content)
|
||||
content = mw.getJson(content)
|
||||
return mw.returnJson(True, 'ok!', content)
|
||||
|
||||
|
||||
def getSiteConfigByName():
|
||||
@@ -723,7 +726,7 @@ def getSiteConfigByName():
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
path = getJsonPath('site')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
siteName = args['siteName']
|
||||
@@ -731,7 +734,7 @@ def getSiteConfigByName():
|
||||
if siteName in content:
|
||||
retData = content[siteName]
|
||||
|
||||
return public.returnJson(True, 'ok!', retData)
|
||||
return mw.returnJson(True, 'ok!', retData)
|
||||
|
||||
|
||||
def addSiteCdnHeader():
|
||||
@@ -740,7 +743,7 @@ def addSiteCdnHeader():
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
path = getJsonPath('site')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
siteName = args['siteName']
|
||||
@@ -748,9 +751,9 @@ def addSiteCdnHeader():
|
||||
if siteName in content:
|
||||
content[siteName]['cdn_header'].append(args['cdn_header'])
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '添加成功!')
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '添加成功!')
|
||||
|
||||
|
||||
def removeSiteCdnHeader():
|
||||
@@ -759,7 +762,7 @@ def removeSiteCdnHeader():
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
path = getJsonPath('site')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
siteName = args['siteName']
|
||||
@@ -767,9 +770,9 @@ def removeSiteCdnHeader():
|
||||
if siteName in content:
|
||||
content[siteName]['cdn_header'].remove(args['cdn_header'])
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '删除成功!')
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
|
||||
|
||||
def outputData():
|
||||
@@ -779,8 +782,8 @@ def outputData():
|
||||
return data[1]
|
||||
|
||||
path = getRuleJsonPath(args['s_Name'])
|
||||
content = public.readFile(path)
|
||||
return public.returnJson(True, 'ok', content)
|
||||
content = mw.readFile(path)
|
||||
return mw.returnJson(True, 'ok', content)
|
||||
|
||||
|
||||
def importData():
|
||||
@@ -790,8 +793,8 @@ def importData():
|
||||
return data[1]
|
||||
|
||||
path = getRuleJsonPath(args['s_Name'])
|
||||
public.writeFile(path, args['pdata'])
|
||||
return public.returnJson(True, '设置成功!')
|
||||
mw.writeFile(path, args['pdata'])
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def getLogsList():
|
||||
@@ -801,7 +804,7 @@ def getLogsList():
|
||||
return data[1]
|
||||
|
||||
data = []
|
||||
path = public.getLogsDir() + '/waf'
|
||||
path = mw.getLogsDir() + '/waf'
|
||||
files = os.listdir(path)
|
||||
for f in files:
|
||||
if f == '.DS_Store':
|
||||
@@ -811,7 +814,7 @@ def getLogsList():
|
||||
fl = f[1].split('.')
|
||||
data.append(fl[0])
|
||||
|
||||
return public.returnJson(True, 'ok!', data)
|
||||
return mw.returnJson(True, 'ok!', data)
|
||||
|
||||
|
||||
def getSafeLogs():
|
||||
@@ -820,10 +823,10 @@ def getSafeLogs():
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
path = public.getLogsDir() + '/waf'
|
||||
path = mw.getLogsDir() + '/waf'
|
||||
file = path + '/' + args['siteName'] + '_' + args['toDate'] + '.log'
|
||||
if not os.path.exists(file):
|
||||
return public.returnJson(False, "文件不存在!")
|
||||
return mw.returnJson(False, "文件不存在!")
|
||||
|
||||
retData = []
|
||||
file = open(file)
|
||||
@@ -835,7 +838,7 @@ def getSafeLogs():
|
||||
|
||||
retData.append(json.loads(line))
|
||||
|
||||
return public.returnJson(True, '设置成功!', retData)
|
||||
return mw.returnJson(True, '设置成功!', retData)
|
||||
|
||||
|
||||
def setObjOpen():
|
||||
@@ -845,7 +848,7 @@ def setObjOpen():
|
||||
return data[1]
|
||||
|
||||
conf = getJsonPath('config')
|
||||
content = public.readFile(conf)
|
||||
content = mw.readFile(conf)
|
||||
cobj = json.loads(content)
|
||||
|
||||
o = args['obj']
|
||||
@@ -854,9 +857,9 @@ def setObjOpen():
|
||||
else:
|
||||
cobj[o]["open"] = True
|
||||
|
||||
cjson = public.getJson(cobj)
|
||||
public.writeFile(conf, cjson)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
cjson = mw.getJson(cobj)
|
||||
mw.writeFile(conf, cjson)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setSiteObjOpen():
|
||||
@@ -869,7 +872,7 @@ def setSiteObjOpen():
|
||||
obj = args['obj']
|
||||
|
||||
path = getJsonPath('site')
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
content = json.loads(content)
|
||||
|
||||
if type(content[siteName][obj]) == bool:
|
||||
@@ -883,20 +886,19 @@ def setSiteObjOpen():
|
||||
else:
|
||||
content[siteName][obj]['open'] = True
|
||||
|
||||
cjson = public.getJson(content)
|
||||
public.writeFile(path, cjson)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
|
||||
cjson = mw.getJson(content)
|
||||
mw.writeFile(path, cjson)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def getWafSrceen():
|
||||
conf = getJsonPath('total')
|
||||
return public.readFile(conf)
|
||||
return mw.readFile(conf)
|
||||
|
||||
|
||||
def getWafConf():
|
||||
conf = getJsonPath('config')
|
||||
return public.readFile(conf)
|
||||
return mw.readFile(conf)
|
||||
|
||||
|
||||
def getWafSite():
|
||||
|
||||
+32
-32
@@ -7,12 +7,12 @@ import time
|
||||
import subprocess
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
|
||||
app_debug = False
|
||||
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -53,11 +53,11 @@ def getArgs():
|
||||
|
||||
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')
|
||||
mw.execShell('rm -rf ' + path_bin + '/client_body_temp')
|
||||
mw.execShell('rm -rf ' + path_bin + '/fastcgi_temp')
|
||||
mw.execShell('rm -rf ' + path_bin + '/proxy_temp')
|
||||
mw.execShell('rm -rf ' + path_bin + '/scgi_temp')
|
||||
mw.execShell('rm -rf ' + path_bin + '/uwsgi_temp')
|
||||
|
||||
|
||||
def getConf():
|
||||
@@ -72,13 +72,13 @@ def getConfTpl():
|
||||
|
||||
def getOs():
|
||||
data = {}
|
||||
data['os'] = public.getOs()
|
||||
data['os'] = mw.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)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def getInitDTpl():
|
||||
@@ -112,15 +112,15 @@ def checkAuthEq(file, owner='root'):
|
||||
|
||||
def confReplace():
|
||||
service_path = os.path.dirname(os.getcwd())
|
||||
content = public.readFile(getConfTpl())
|
||||
content = mw.readFile(getConfTpl())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
|
||||
user = 'www'
|
||||
user_group = 'www'
|
||||
|
||||
if public.getOs() == 'darwin':
|
||||
if mw.getOs() == 'darwin':
|
||||
# macosx do
|
||||
user = public.execShell(
|
||||
user = mw.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
# user = 'root'
|
||||
user_group = 'staff'
|
||||
@@ -133,9 +133,9 @@ def confReplace():
|
||||
|
||||
nconf = getServerDir() + '/nginx/conf/nginx.conf'
|
||||
|
||||
__content = public.readFile(nconf)
|
||||
__content = mw.readFile(nconf)
|
||||
if __content.find('#user'):
|
||||
public.writeFile(getServerDir() + '/nginx/conf/nginx.conf', content)
|
||||
mw.writeFile(getServerDir() + '/nginx/conf/nginx.conf', content)
|
||||
|
||||
# give nginx root permission
|
||||
ng_exe_bin = getServerDir() + "/nginx/sbin/nginx"
|
||||
@@ -167,10 +167,10 @@ def initDreplace():
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
|
||||
# initd replace
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
# config replace
|
||||
confReplace()
|
||||
@@ -182,7 +182,7 @@ def initDreplace():
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep nginx |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -191,7 +191,7 @@ def status():
|
||||
|
||||
def start():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' start')
|
||||
data = mw.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -199,7 +199,7 @@ def start():
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
data = mw.execShell(file + ' stop')
|
||||
clearTemp()
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
@@ -208,7 +208,7 @@ def stop():
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' restart')
|
||||
data = mw.execShell(file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -216,7 +216,7 @@ def restart():
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
data = mw.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -224,7 +224,7 @@ def reload():
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
@@ -235,23 +235,23 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.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)
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
return 'ok'
|
||||
@@ -260,7 +260,7 @@ def initdUinstall():
|
||||
def runInfo():
|
||||
# 取Openresty负载状态
|
||||
try:
|
||||
result = public.httpGet('http://127.0.0.1/nginx_status')
|
||||
result = mw.httpGet('http://127.0.0.1/nginx_status')
|
||||
tmp = result.split()
|
||||
data = {}
|
||||
data['active'] = tmp[2]
|
||||
@@ -270,7 +270,7 @@ def runInfo():
|
||||
data['Reading'] = tmp[11]
|
||||
data['Writing'] = tmp[13]
|
||||
data['Waiting'] = tmp[15]
|
||||
return public.getJson(data)
|
||||
return mw.getJson(data)
|
||||
except Exception as e:
|
||||
return 'oprenresty not started'
|
||||
|
||||
|
||||
+107
-107
@@ -14,10 +14,10 @@ sys.setdefaultencoding('utf8')
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
sys.path.append("/usr/local/lib/python2.7/site-packages")
|
||||
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile(version):
|
||||
@@ -59,8 +59,8 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def getConf(version):
|
||||
@@ -71,20 +71,20 @@ def getConf(version):
|
||||
def status(version):
|
||||
cmd = "ps -ef|grep 'php/" + version + \
|
||||
"' |grep -v grep | grep -v python | awk '{print $2}'"
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def contentReplace(content, version):
|
||||
service_path = public.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', public.getRootDir())
|
||||
service_path = mw.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$PHP_VERSION}', version)
|
||||
|
||||
if public.isAppleSystem():
|
||||
# user = public.execShell(
|
||||
if mw.isAppleSystem():
|
||||
# user = mw.execShell(
|
||||
# "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
content = content.replace('{$PHP_USER}', 'nobody')
|
||||
content = content.replace('{$PHP_GROUP}', 'nobody')
|
||||
@@ -113,46 +113,46 @@ def contentReplace(content, version):
|
||||
|
||||
def makeOpenrestyConf():
|
||||
phpversions = ['00', '53', '54', '55', '56', '70', '71', '72', '73', '74']
|
||||
if public.isInstalledWeb():
|
||||
sdir = public.getServerDir()
|
||||
if mw.isInstalledWeb():
|
||||
sdir = mw.getServerDir()
|
||||
d_pathinfo = sdir + '/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 = mw.readFile(info)
|
||||
content = json.loads(content)
|
||||
versions = content['versions']
|
||||
tpl = getPluginDir() + '/conf/enable-php.conf'
|
||||
tpl_content = public.readFile(tpl)
|
||||
tpl_content = mw.readFile(tpl)
|
||||
for x in phpversions:
|
||||
dfile = sdir + '/openresty/nginx/conf/enable-php-' + x + '.conf'
|
||||
if not os.path.exists(dfile):
|
||||
if x == '00':
|
||||
public.writeFile(dfile, '')
|
||||
mw.writeFile(dfile, '')
|
||||
else:
|
||||
w_content = contentReplace(tpl_content, x)
|
||||
public.writeFile(dfile, w_content)
|
||||
mw.writeFile(dfile, w_content)
|
||||
|
||||
# php-fpm status
|
||||
for version in phpversions:
|
||||
dfile = sdir + '/openresty/nginx/conf/php_status/phpfpm_status_' + version + '.conf'
|
||||
tpl = getPluginDir() + '/conf/phpfpm_status.conf'
|
||||
if not os.path.exists(dfile):
|
||||
content = public.readFile(tpl)
|
||||
content = mw.readFile(tpl)
|
||||
content = contentReplace(content, version)
|
||||
public.writeFile(dfile, content)
|
||||
public.restartWeb()
|
||||
mw.writeFile(dfile, content)
|
||||
mw.restartWeb()
|
||||
|
||||
|
||||
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 = mw.readFile(tpl_php_fpm)
|
||||
content = contentReplace(content, version)
|
||||
public.writeFile(desc_php_fpm, content)
|
||||
mw.writeFile(desc_php_fpm, content)
|
||||
|
||||
|
||||
def phpFpmWwwReplace(version):
|
||||
@@ -164,13 +164,13 @@ def phpFpmWwwReplace(version):
|
||||
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 = mw.readFile(tpl_php_fpmwww)
|
||||
content = contentReplace(content, version)
|
||||
public.writeFile(service_php_fpmwww, content)
|
||||
mw.writeFile(service_php_fpmwww, content)
|
||||
|
||||
|
||||
def makePhpIni(version):
|
||||
d_ini = public.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
d_ini = mw.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
if not os.path.exists(d_ini):
|
||||
s_ini = getPluginDir() + '/conf/php' + version[0:1] + '.ini'
|
||||
shutil.copyfile(s_ini, d_ini)
|
||||
@@ -188,11 +188,11 @@ def initReplace(version):
|
||||
if not os.path.exists(file_bin):
|
||||
file_tpl = getPluginDir() + '/init.d/php.tpl'
|
||||
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = contentReplace(content, version)
|
||||
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
phpFpmWwwReplace(version)
|
||||
phpFpmReplace(version)
|
||||
@@ -200,14 +200,14 @@ def initReplace(version):
|
||||
session_path = '/tmp/session'
|
||||
if not os.path.exists(session_path):
|
||||
os.mkdir(session_path)
|
||||
if not public.isAppleSystem():
|
||||
public.execShell('chown -R www:www ' + session_path)
|
||||
if not mw.isAppleSystem():
|
||||
mw.execShell('chown -R www:www ' + session_path)
|
||||
return file_bin
|
||||
|
||||
|
||||
def phpOp(version, method):
|
||||
file = initReplace(version)
|
||||
data = public.execShell(file + ' ' + method)
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -231,7 +231,7 @@ def reload(version):
|
||||
|
||||
def initdStatus(version):
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile(version)
|
||||
if os.path.exists(initd_bin):
|
||||
@@ -242,23 +242,23 @@ def initdStatus(version):
|
||||
def initdInstall(version):
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
source_bin = initReplace(version)
|
||||
initd_bin = getInitDFile(version)
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
public.execShell('chkconfig --add ' + getPluginName() + version)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName() + version)
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall(version):
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
initd_bin = getInitDFile(version)
|
||||
os.remove(initd_bin)
|
||||
return 'ok'
|
||||
@@ -289,7 +289,7 @@ def getPhpConf(version):
|
||||
{'name': 'cgi.fix_pathinfo', 'type': 0, 'ps': '是否开启pathinfo'},
|
||||
{'name': 'date.timezone', 'type': 3, 'ps': '时区'}
|
||||
]
|
||||
phpini = public.readFile(getServerDir() + '/' + version + '/etc/php.ini')
|
||||
phpini = mw.readFile(getServerDir() + '/' + version + '/etc/php.ini')
|
||||
result = []
|
||||
for g in gets:
|
||||
rep = g['name'] + '\s*=\s*([0-9A-Za-z_& ~]+)(\s*;?|\r?\n)'
|
||||
@@ -298,7 +298,7 @@ def getPhpConf(version):
|
||||
continue
|
||||
g['value'] = tmp.groups()[0]
|
||||
result.append(g)
|
||||
return public.getJson(result)
|
||||
return mw.getJson(result)
|
||||
|
||||
|
||||
def submitPhpConf(version):
|
||||
@@ -308,22 +308,22 @@ def submitPhpConf(version):
|
||||
'default_socket_timeout', 'error_reporting']
|
||||
args = getArgs()
|
||||
filename = getServerDir() + '/' + version + '/etc/php.ini'
|
||||
phpini = public.readFile(filename)
|
||||
phpini = mw.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, '设置成功')
|
||||
mw.writeFile(filename, phpini)
|
||||
mw.execShell(getServerDir() + '/init.d/php' + version + ' reload')
|
||||
return mw.returnJson(True, '设置成功')
|
||||
|
||||
|
||||
def getLimitConf(version):
|
||||
fileini = getServerDir() + "/" + version + "/etc/php.ini"
|
||||
phpini = public.readFile(fileini)
|
||||
phpini = mw.readFile(fileini)
|
||||
filefpm = getServerDir() + "/" + version + "/etc/php-fpm.conf"
|
||||
phpfpm = public.readFile(filefpm)
|
||||
phpfpm = mw.readFile(filefpm)
|
||||
|
||||
# print fileini, filefpm
|
||||
data = {}
|
||||
@@ -352,7 +352,7 @@ def getLimitConf(version):
|
||||
except:
|
||||
data['pathinfo'] = False
|
||||
|
||||
return public.getJson(data)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def setMaxTime(version):
|
||||
@@ -363,22 +363,22 @@ def setMaxTime(version):
|
||||
|
||||
time = args['time']
|
||||
if int(time) < 30 or int(time) > 86400:
|
||||
return public.returnJson(False, '请填写30-86400间的值!')
|
||||
return mw.returnJson(False, '请填写30-86400间的值!')
|
||||
|
||||
filefpm = getServerDir() + "/" + version + "/etc/php-fpm.conf"
|
||||
conf = public.readFile(filefpm)
|
||||
conf = mw.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)
|
||||
mw.writeFile(filefpm, conf)
|
||||
|
||||
fileini = getServerDir() + "/" + version + "/etc/php.ini"
|
||||
phpini = public.readFile(fileini)
|
||||
phpini = mw.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, '设置成功!')
|
||||
mw.writeFile(fileini, phpini)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def setMaxSize(version):
|
||||
@@ -387,25 +387,25 @@ def setMaxSize(version):
|
||||
return 'missing time args!'
|
||||
max = args['max']
|
||||
if int(max) < 2:
|
||||
return public.returnJson(False, '上传大小限制不能小于2MB!')
|
||||
return mw.returnJson(False, '上传大小限制不能小于2MB!')
|
||||
|
||||
path = getServerDir() + '/' + version + '/etc/php.ini'
|
||||
conf = public.readFile(path)
|
||||
conf = mw.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)
|
||||
mw.writeFile(path, conf)
|
||||
|
||||
msg = public.getInfo('设置PHP-{1}最大上传大小为[{2}MB]!', (version, max,))
|
||||
public.writeLog('插件管理[PHP]', msg)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
msg = mw.getInfo('设置PHP-{1}最大上传大小为[{2}MB]!', (version, max,))
|
||||
mw.writeLog('插件管理[PHP]', msg)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def getFpmConfig(version):
|
||||
|
||||
filefpm = getServerDir() + '/' + version + '/etc/php-fpm.d/www.conf'
|
||||
conf = public.readFile(filefpm)
|
||||
conf = mw.readFile(filefpm)
|
||||
data = {}
|
||||
rep = "\s*pm.max_children\s*=\s*([0-9]+)\s*"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
@@ -426,7 +426,7 @@ def getFpmConfig(version):
|
||||
rep = "\s*pm\s*=\s*(\w+)\s*"
|
||||
tmp = re.search(rep, conf).groups()
|
||||
data['pm'] = tmp[0]
|
||||
return public.getJson(data)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def setFpmConfig(version):
|
||||
@@ -442,7 +442,7 @@ def setFpmConfig(version):
|
||||
pm = args['pm']
|
||||
|
||||
file = getServerDir() + '/' + version + '/etc/php-fpm.d/www.conf'
|
||||
conf = public.readFile(file)
|
||||
conf = mw.readFile(file)
|
||||
|
||||
rep = "\s*pm.max_children\s*=\s*([0-9]+)\s*"
|
||||
conf = re.sub(rep, "\npm.max_children = " + max_children, conf)
|
||||
@@ -461,91 +461,91 @@ def setFpmConfig(version):
|
||||
rep = "\s*pm\s*=\s*(\w+)\s*"
|
||||
conf = re.sub(rep, "\npm = " + pm + "\n", conf)
|
||||
|
||||
public.writeFile(file, conf)
|
||||
mw.writeFile(file, conf)
|
||||
reload(version)
|
||||
|
||||
msg = public.getInfo('设置PHP-{1}并发设置,max_children={2},start_servers={3},min_spare_servers={4},max_spare_servers={5}', (version, max_children,
|
||||
start_servers, min_spare_servers, max_spare_servers,))
|
||||
public.writeLog('插件管理[PHP]', msg)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
msg = mw.getInfo('设置PHP-{1}并发设置,max_children={2},start_servers={3},min_spare_servers={4},max_spare_servers={5}', (version, max_children,
|
||||
start_servers, min_spare_servers, max_spare_servers,))
|
||||
mw.writeLog('插件管理[PHP]', msg)
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def checkFpmStatusFile(version):
|
||||
if public.isInstalledWeb():
|
||||
sdir = public.getServerDir()
|
||||
if mw.isInstalledWeb():
|
||||
sdir = mw.getServerDir()
|
||||
dfile = sdir + '/openresty/nginx/conf/php_status/phpfpm_status_' + version + '.conf'
|
||||
if not os.path.exists(dfile):
|
||||
tpl = getPluginDir() + '/conf/phpfpm_status.conf'
|
||||
content = public.readFile(tpl)
|
||||
content = mw.readFile(tpl)
|
||||
content = contentReplace(content, version)
|
||||
public.writeFile(dfile, content)
|
||||
public.restartWeb()
|
||||
mw.writeFile(dfile, content)
|
||||
mw.restartWeb()
|
||||
|
||||
|
||||
def getFpmStatus(version):
|
||||
checkFpmStatusFile(version)
|
||||
result = public.httpGet(
|
||||
result = mw.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)
|
||||
return mw.getJson(tmp)
|
||||
|
||||
|
||||
def getDisableFunc(version):
|
||||
filename = public.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
filename = mw.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
if not os.path.exists(filename):
|
||||
return public.returnJson(False, '指定PHP版本不存在!')
|
||||
return mw.returnJson(False, '指定PHP版本不存在!')
|
||||
|
||||
phpini = public.readFile(filename)
|
||||
phpini = mw.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)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def setDisableFunc(version):
|
||||
filename = public.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
filename = mw.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
if not os.path.exists(filename):
|
||||
return public.returnJson(False, '指定PHP版本不存在!')
|
||||
return mw.returnJson(False, '指定PHP版本不存在!')
|
||||
|
||||
args = getArgs()
|
||||
disable_functions = args['disable_functions']
|
||||
|
||||
phpini = public.readFile(filename)
|
||||
phpini = mw.readFile(filename)
|
||||
rep = "disable_functions\s*=\s*.*\n"
|
||||
phpini = re.sub(rep, 'disable_functions = ' +
|
||||
disable_functions + "\n", phpini)
|
||||
|
||||
msg = public.getInfo('修改PHP-{1}的禁用函数为[{2}]', (version, disable_functions,))
|
||||
public.writeLog('插件管理[PHP]', msg)
|
||||
public.writeFile(filename, phpini)
|
||||
msg = mw.getInfo('修改PHP-{1}的禁用函数为[{2}]', (version, disable_functions,))
|
||||
mw.writeLog('插件管理[PHP]', msg)
|
||||
mw.writeFile(filename, phpini)
|
||||
reload(version)
|
||||
return public.returnJson(True, '设置成功!')
|
||||
return mw.returnJson(True, '设置成功!')
|
||||
|
||||
|
||||
def checkPhpinfoFile(v):
|
||||
if public.isInstalledWeb():
|
||||
sdir = public.getServerDir()
|
||||
if mw.isInstalledWeb():
|
||||
sdir = mw.getServerDir()
|
||||
dfile = sdir + '/openresty/nginx/conf/php_status/phpinfo_' + v + '.conf'
|
||||
if not os.path.exists(dfile):
|
||||
tpl = getPluginDir() + '/conf/phpinfo.conf'
|
||||
content = public.readFile(tpl)
|
||||
content = mw.readFile(tpl)
|
||||
content = contentReplace(content, v)
|
||||
public.writeFile(dfile, content)
|
||||
public.restartWeb()
|
||||
mw.writeFile(dfile, content)
|
||||
mw.restartWeb()
|
||||
|
||||
|
||||
def getPhpinfo(v):
|
||||
checkPhpinfoFile(v)
|
||||
sPath = public.getRootDir() + '/phpinfo/' + v
|
||||
public.execShell("rm -rf " + public.getRootDir() + '/phpinfo')
|
||||
public.execShell("mkdir -p " + sPath)
|
||||
public.writeFile(sPath + '/phpinfo.php', '<?php phpinfo(); ?>')
|
||||
sPath = mw.getRootDir() + '/phpinfo/' + v
|
||||
mw.execShell("rm -rf " + mw.getRootDir() + '/phpinfo')
|
||||
mw.execShell("mkdir -p " + sPath)
|
||||
mw.writeFile(sPath + '/phpinfo.php', '<?php phpinfo(); ?>')
|
||||
url = 'http://127.0.0.1/' + v + '/phpinfo.php'
|
||||
phpinfo = public.httpGet(url)
|
||||
os.system("rm -rf " + public.getRootDir() + '/phpinfo')
|
||||
phpinfo = mw.httpGet(url)
|
||||
os.system("rm -rf " + mw.getRootDir() + '/phpinfo')
|
||||
return phpinfo
|
||||
|
||||
|
||||
@@ -554,22 +554,22 @@ def get_php_info(args):
|
||||
|
||||
|
||||
def getLibConf(version):
|
||||
fname = public.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
fname = mw.getServerDir() + '/php/' + version + '/etc/php.ini'
|
||||
if not os.path.exists(fname):
|
||||
return public.returnJson(False, '指定PHP版本不存在!')
|
||||
return mw.returnJson(False, '指定PHP版本不存在!')
|
||||
|
||||
phpini = public.readFile(fname)
|
||||
phpini = mw.readFile(fname)
|
||||
|
||||
libpath = getPluginDir() + '/versions/phplib.conf'
|
||||
phplib = json.loads(public.readFile(libpath))
|
||||
phplib = json.loads(mw.readFile(libpath))
|
||||
|
||||
libs = []
|
||||
tasks = public.M('tasks').where(
|
||||
tasks = mw.M('tasks').where(
|
||||
"status!=?", ('1',)).field('status,name').select()
|
||||
for lib in phplib:
|
||||
lib['task'] = '1'
|
||||
for task in tasks:
|
||||
tmp = public.getStrBetween('[', ']', task['name'])
|
||||
tmp = mw.getStrBetween('[', ']', task['name'])
|
||||
if not tmp:
|
||||
continue
|
||||
tmp1 = tmp.split('-')
|
||||
@@ -582,7 +582,7 @@ def getLibConf(version):
|
||||
else:
|
||||
lib['status'] = True
|
||||
libs.append(lib)
|
||||
return public.returnJson(True, 'OK!', libs)
|
||||
return mw.returnJson(True, 'OK!', libs)
|
||||
|
||||
|
||||
def installLib(version):
|
||||
@@ -598,8 +598,8 @@ def installLib(version):
|
||||
rettime = time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
insert_info = (None, '安装[' + name + '-' + version + ']',
|
||||
'execshell', '0', rettime, execstr)
|
||||
public.M('tasks').add('id,name,type,status,addtime,execstr', insert_info)
|
||||
return public.returnJson(True, '已将下载任务添加到队列!')
|
||||
mw.M('tasks').add('id,name,type,status,addtime,execstr', insert_info)
|
||||
return mw.returnJson(True, '已将下载任务添加到队列!')
|
||||
|
||||
|
||||
def uninstallLib(version):
|
||||
@@ -612,11 +612,11 @@ def uninstallLib(version):
|
||||
execstr = "cd " + getPluginDir() + '/versions/' + version + " && /bin/bash " + \
|
||||
name + '.sh' + ' uninstall ' + version
|
||||
|
||||
data = public.execShell(execstr)
|
||||
data = mw.execShell(execstr)
|
||||
if data[0] == '' and data[1] == '':
|
||||
return public.returnJson(True, '已经卸载成功!')
|
||||
return mw.returnJson(True, '已经卸载成功!')
|
||||
else:
|
||||
return public.returnJson(False, '卸载信息![通道0]:' + data[0] + "[通道0]:" + data[1])
|
||||
return mw.returnJson(False, '卸载信息![通道0]:' + data[0] + "[通道0]:" + data[1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -14,10 +14,10 @@ sys.setdefaultencoding('utf8')
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
sys.path.append("/usr/local/lib/python2.7/site-packages")
|
||||
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -26,17 +26,17 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile(version):
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()+version
|
||||
return '/etc/init.d/' + getPluginName() + version
|
||||
|
||||
|
||||
def getArgs():
|
||||
@@ -59,8 +59,8 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+31
-31
@@ -7,11 +7,11 @@ import time
|
||||
import re
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
import site_api
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
@@ -45,12 +45,12 @@ def getArgs():
|
||||
|
||||
|
||||
def getConf():
|
||||
return public.getServerDir() + '/web_conf/nginx/vhost/phpmyadmin.conf'
|
||||
return mw.getServerDir() + '/web_conf/nginx/vhost/phpmyadmin.conf'
|
||||
|
||||
|
||||
def getPort():
|
||||
file = getConf()
|
||||
content = public.readFile(file)
|
||||
content = mw.readFile(file)
|
||||
rep = 'listen\s*(.*);'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0].strip()
|
||||
@@ -60,12 +60,12 @@ def getHomePage():
|
||||
try:
|
||||
port = getPort()
|
||||
ip = '127.0.0.1'
|
||||
if not public.isAppleSystem():
|
||||
ip = public.getLocalIp()
|
||||
if not mw.isAppleSystem():
|
||||
ip = mw.getLocalIp()
|
||||
url = 'http://' + ip + ':' + port + '/phpmyadmin/index.php'
|
||||
return public.returnJson(True, 'OK', url)
|
||||
return mw.returnJson(True, 'OK', url)
|
||||
except Exception as e:
|
||||
return public.returnJson(False, '插件未启动!')
|
||||
return mw.returnJson(False, '插件未启动!')
|
||||
|
||||
|
||||
def getPhpVer(expect=55):
|
||||
@@ -83,18 +83,18 @@ def getCachePhpVer():
|
||||
cacheFile = getServerDir() + '/php.pl'
|
||||
v = ''
|
||||
if os.path.exists(cacheFile):
|
||||
v = public.readFile(cacheFile)
|
||||
v = mw.readFile(cacheFile)
|
||||
else:
|
||||
v = getPhpVer()
|
||||
public.writeFile(cacheFile, v)
|
||||
mw.writeFile(cacheFile, v)
|
||||
return v
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = public.getServerDir()
|
||||
service_path = mw.getServerDir()
|
||||
php_ver = getCachePhpVer()
|
||||
# print php_ver
|
||||
content = content.replace('{$ROOT_PATH}', public.getRootDir())
|
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$PHP_VER}', php_ver)
|
||||
return content
|
||||
@@ -112,18 +112,18 @@ def start():
|
||||
file_run = getConf()
|
||||
|
||||
if not os.path.exists(file_run):
|
||||
centent = public.readFile(file_tpl)
|
||||
centent = mw.readFile(file_tpl)
|
||||
centent = contentReplace(centent)
|
||||
public.writeFile(file_run, centent)
|
||||
mw.writeFile(file_run, centent)
|
||||
|
||||
conf_run = getServerDir() + '/phpmyadmin/config.inc.php'
|
||||
if not os.path.exists(conf_run):
|
||||
conf_tpl = getPluginDir() + '/conf/config.inc.php'
|
||||
centent = public.readFile(conf_tpl)
|
||||
centent = mw.readFile(conf_tpl)
|
||||
# centent = contentReplace(centent)
|
||||
print public.writeFile(conf_run, centent)
|
||||
print mw.writeFile(conf_run, centent)
|
||||
|
||||
public.restartWeb()
|
||||
mw.restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ def stop():
|
||||
conf = getConf()
|
||||
if os.path.exists(conf):
|
||||
os.remove(conf)
|
||||
public.restartWeb()
|
||||
mw.restartWeb()
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ def setPhpVer():
|
||||
return 'phpver missing'
|
||||
|
||||
cacheFile = getServerDir() + '/php.pl'
|
||||
public.writeFile(cacheFile, args['phpver'])
|
||||
mw.writeFile(cacheFile, args['phpver'])
|
||||
restart()
|
||||
|
||||
return 'ok'
|
||||
@@ -159,37 +159,37 @@ def setPhpVer():
|
||||
def getSetPhpVer():
|
||||
cacheFile = getServerDir() + '/php.pl'
|
||||
if os.path.exists(cacheFile):
|
||||
return public.readFile(cacheFile).strip()
|
||||
return mw.readFile(cacheFile).strip()
|
||||
return ''
|
||||
|
||||
|
||||
def getPmaPort():
|
||||
try:
|
||||
port = getPort()
|
||||
return public.returnJson(True, 'OK', port)
|
||||
return mw.returnJson(True, 'OK', port)
|
||||
except Exception as e:
|
||||
print e
|
||||
return public.returnJson(False, '插件未启动!')
|
||||
return mw.returnJson(False, '插件未启动!')
|
||||
|
||||
|
||||
def setPmaPort():
|
||||
args = getArgs()
|
||||
if not 'port' in args:
|
||||
return public.returnJson(False, 'port missing!')
|
||||
return mw.returnJson(False, 'port missing!')
|
||||
|
||||
port = args['port']
|
||||
if port == '80':
|
||||
return public.returnJson(False, '80端不能使用!')
|
||||
return mw.returnJson(False, '80端不能使用!')
|
||||
|
||||
file = getConf()
|
||||
if not os.path.exists(file):
|
||||
return public.returnJson(False, '插件未启动!')
|
||||
content = public.readFile(file)
|
||||
return mw.returnJson(False, '插件未启动!')
|
||||
content = mw.readFile(file)
|
||||
rep = 'listen\s*(.*);'
|
||||
content = re.sub(rep, "listen " + port + ';', content)
|
||||
public.writeFile(file, content)
|
||||
public.restartWeb()
|
||||
return public.returnJson(True, '修改成功!')
|
||||
mw.writeFile(file, content)
|
||||
mw.restartWeb()
|
||||
return mw.returnJson(True, '修改成功!')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+49
-49
@@ -7,10 +7,10 @@ import time
|
||||
import shutil
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -52,13 +52,13 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
cmd = "ps -ef|grep pm2 |grep -v grep | grep -v python | awk '{print $2}'"
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
@@ -66,8 +66,8 @@ def status():
|
||||
|
||||
def rootDir():
|
||||
path = '/root'
|
||||
if public.isAppleSystem():
|
||||
user = public.execShell(
|
||||
if mw.isAppleSystem():
|
||||
user = mw.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
path = '/Users/' + user
|
||||
return path
|
||||
@@ -97,7 +97,7 @@ def pm2Log():
|
||||
|
||||
def pm2GetList():
|
||||
try:
|
||||
tmp = public.execShell(__SR + "pm2 list|grep -v 'pm2 show'")
|
||||
tmp = mw.execShell(__SR + "pm2 list|grep -v 'pm2 show'")
|
||||
t2 = tmp[0].replace("│", "").replace("└", "").replace(
|
||||
"─", "").replace("┴", "").replace("┘", "").strip().split("┤")
|
||||
if len(t2) == 1:
|
||||
@@ -107,7 +107,7 @@ def pm2GetList():
|
||||
tmpArr = t2[2].strip()
|
||||
appList = tmpArr.split('\n')
|
||||
result = []
|
||||
tmp = public.execShell('lsof -c node -P|grep LISTEN')
|
||||
tmp = mw.execShell('lsof -c node -P|grep LISTEN')
|
||||
plist = tmp[0].split('\n')
|
||||
for app in appList:
|
||||
if not app:
|
||||
@@ -135,7 +135,7 @@ def pm2GetList():
|
||||
if ptmp[1] == appInfo['pid']:
|
||||
appInfo['port'] = ptmp[8].split(':')[1].split('->')[0]
|
||||
if os.path.exists(__path + '/' + appInfo['name']):
|
||||
appInfo['path'] = public.readFile(
|
||||
appInfo['path'] = mw.readFile(
|
||||
__path + '/' + appInfo['name'])
|
||||
result.append(appInfo)
|
||||
return result
|
||||
@@ -145,7 +145,7 @@ def pm2GetList():
|
||||
|
||||
def pm2List():
|
||||
result = pm2GetList()
|
||||
return public.returnJson(True, 'ok', result)
|
||||
return mw.returnJson(True, 'ok', result)
|
||||
|
||||
|
||||
def pm2Add():
|
||||
@@ -160,21 +160,21 @@ def pm2Add():
|
||||
|
||||
runFile = (path + '/' + run).replace('//', '/')
|
||||
if not os.path.exists(runFile):
|
||||
return public.returnJson(False, '指定文件不存在!')
|
||||
return mw.returnJson(False, '指定文件不存在!')
|
||||
|
||||
nlist = pm2GetList()
|
||||
for node in nlist:
|
||||
if pname == node['name']:
|
||||
return public.returnJson(False, '指定项目名称已经存在!')
|
||||
return mw.returnJson(False, '指定项目名称已经存在!')
|
||||
if os.path.exists(path + '/package.json') and not os.path.exists(path + '/package-lock.json'):
|
||||
public.execShell(__SR + "cd " + path + ' && npm install -s')
|
||||
public.execShell(__SR + 'cd ' + path + ' && pm2 start ' +
|
||||
runFile + ' --name "' + pname + '"|grep ' + pname)
|
||||
public.execShell(__SR + 'pm2 save && pm2 startup')
|
||||
mw.execShell(__SR + "cd " + path + ' && npm install -s')
|
||||
mw.execShell(__SR + 'cd ' + path + ' && pm2 start ' +
|
||||
runFile + ' --name "' + pname + '"|grep ' + pname)
|
||||
mw.execShell(__SR + 'pm2 save && pm2 startup')
|
||||
if not os.path.exists(__path):
|
||||
public.execShell('mkdir -p ' + __path)
|
||||
public.writeFile(__path + '/' + pname, path)
|
||||
return public.returnJson(True, '添加成功!')
|
||||
mw.execShell('mkdir -p ' + __path)
|
||||
mw.writeFile(__path + '/' + pname, path)
|
||||
return mw.returnJson(True, '添加成功!')
|
||||
|
||||
|
||||
def pm2Delete():
|
||||
@@ -186,13 +186,13 @@ def pm2Delete():
|
||||
pname = args['pname']
|
||||
cmd = 'pm2 stop "' + pname + '" && pm2 delete "' + \
|
||||
pname + '" | grep "' + pname + '"'
|
||||
result = public.execShell(__SR + cmd)[0]
|
||||
result = mw.execShell(__SR + cmd)[0]
|
||||
if result.find('✓') != -1:
|
||||
public.execShell(__SR + 'pm2 save && pm2 startup')
|
||||
mw.execShell(__SR + 'pm2 save && pm2 startup')
|
||||
if os.path.exists(__path + '/' + pname):
|
||||
os.remove(__path + '/' + pname)
|
||||
return public.returnJson(True, '删除成功!')
|
||||
return public.returnJson(False, '删除失败!')
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
return mw.returnJson(False, '删除失败!')
|
||||
|
||||
|
||||
def pm2Stop():
|
||||
@@ -202,11 +202,11 @@ def pm2Stop():
|
||||
return data[1]
|
||||
|
||||
pname = args['pname']
|
||||
result = public.execShell(__SR + 'pm2 stop "' +
|
||||
pname + '"|grep ' + pname)[0]
|
||||
result = mw.execShell(__SR + 'pm2 stop "' +
|
||||
pname + '"|grep ' + pname)[0]
|
||||
if result.find('stoped') != -1:
|
||||
return public.returnJson(True, '项目[' + pname + ']已停止!')
|
||||
return public.returnJson(True, '项目[' + pname + ']停止失败!')
|
||||
return mw.returnJson(True, '项目[' + pname + ']已停止!')
|
||||
return mw.returnJson(True, '项目[' + pname + ']停止失败!')
|
||||
|
||||
|
||||
def pm2Start():
|
||||
@@ -216,11 +216,11 @@ def pm2Start():
|
||||
return data[1]
|
||||
|
||||
pname = args['pname']
|
||||
result = public.execShell(
|
||||
result = mw.execShell(
|
||||
__SR + 'pm2 start "' + pname + '"|grep ' + pname)[0]
|
||||
if result.find('online') != -1:
|
||||
return public.returnJson(True, '项目[' + pname + ']已启动!')
|
||||
return public.returnJson(False, '项目[' + pname + ']启动失败!')
|
||||
return mw.returnJson(True, '项目[' + pname + ']已启动!')
|
||||
return mw.returnJson(False, '项目[' + pname + ']启动失败!')
|
||||
|
||||
|
||||
def pm2VerList():
|
||||
@@ -231,11 +231,11 @@ def pm2VerList():
|
||||
|
||||
cmd = __SR + ' nvm ls-remote|grep -v v0|grep -v iojs'
|
||||
# print cmd
|
||||
tmp = public.execShell(cmd)
|
||||
tmp = mw.execShell(cmd)
|
||||
result['list'] = re.findall(rep, tmp[0])
|
||||
tmp = public.execShell(__SR + "nvm version")
|
||||
tmp = mw.execShell(__SR + "nvm version")
|
||||
result['version'] = tmp[0].strip()
|
||||
return public.returnJson(True, 'ok', result)
|
||||
return mw.returnJson(True, 'ok', result)
|
||||
|
||||
|
||||
def setNodeVersion():
|
||||
@@ -255,13 +255,13 @@ npm install pm2 -g
|
||||
npm config set registry $oldreg
|
||||
''' % (version, version, version)
|
||||
cmd = __SR + estr
|
||||
public.execShell(cmd)
|
||||
return public.returnJson(True, '已切换至[' + version + ']')
|
||||
mw.execShell(cmd)
|
||||
return mw.returnJson(True, '已切换至[' + version + ']')
|
||||
|
||||
|
||||
def getMod():
|
||||
cmd = __SR + "npm list --depth=0 -global"
|
||||
tmp = public.execShell(cmd)
|
||||
tmp = mw.execShell(cmd)
|
||||
modList = tmp[0].replace("│", "").replace("└", "").replace(
|
||||
"─", "").replace("┴", "").replace("┘", "").strip().split()
|
||||
result = []
|
||||
@@ -274,7 +274,7 @@ def getMod():
|
||||
mod['version'] = tmp[1]
|
||||
result.append(mod)
|
||||
|
||||
return public.returnJson(True, 'OK', result)
|
||||
return mw.returnJson(True, 'OK', result)
|
||||
|
||||
|
||||
# 安装库
|
||||
@@ -285,8 +285,8 @@ def installMod():
|
||||
return data[1]
|
||||
|
||||
mname = args['mname']
|
||||
public.execShell(__SR + 'npm install ' + mname + ' -g')
|
||||
return public.returnJson(True, '安装成功!')
|
||||
mw.execShell(__SR + 'npm install ' + mname + ' -g')
|
||||
return mw.returnJson(True, '安装成功!')
|
||||
|
||||
|
||||
def uninstallMod():
|
||||
@@ -298,9 +298,9 @@ def uninstallMod():
|
||||
mname = args['mname']
|
||||
myNot = ['pm2', 'npm']
|
||||
if mname in myNot:
|
||||
return public.returnJson(False, '不能卸载[' + mname + ']')
|
||||
public.execShell(__SR + 'npm uninstall ' + mname + ' -g')
|
||||
return public.returnJson(True, '卸载成功!')
|
||||
return mw.returnJson(False, '不能卸载[' + mname + ']')
|
||||
mw.execShell(__SR + 'npm uninstall ' + mname + ' -g')
|
||||
return mw.returnJson(True, '卸载成功!')
|
||||
|
||||
|
||||
def nodeLogRun():
|
||||
@@ -331,8 +331,8 @@ def nodeLogClearRun():
|
||||
|
||||
pname = args['pname']
|
||||
path = pm2LogDir() + '/logs/' + pname + '-out.log'
|
||||
public.execShell('rm -rf ' + path + '&& touch ' + path)
|
||||
return public.returnJson(True, '清空运行成功')
|
||||
mw.execShell('rm -rf ' + path + '&& touch ' + path)
|
||||
return mw.returnJson(True, '清空运行成功')
|
||||
|
||||
|
||||
def nodeLogClearErr():
|
||||
@@ -342,8 +342,8 @@ def nodeLogClearErr():
|
||||
return data[1]
|
||||
pname = args['pname']
|
||||
path = pm2LogDir() + '/logs/' + pname + '-error.log'
|
||||
public.execShell('rm -rf ' + path + '&& touch ' + path)
|
||||
return public.returnJson(True, '清空错误成功')
|
||||
mw.execShell('rm -rf ' + path + '&& touch ' + path)
|
||||
return mw.returnJson(True, '清空错误成功')
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
|
||||
+47
-47
@@ -7,10 +7,10 @@ import time
|
||||
import shutil
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -61,15 +61,15 @@ def getArgs():
|
||||
|
||||
def status():
|
||||
cmd = "ps -ef|grep pure-ftpd |grep -v grep | grep -v python | awk '{print $2}'"
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = public.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', public.getRootDir())
|
||||
service_path = mw.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
return content
|
||||
|
||||
@@ -86,18 +86,18 @@ def initDreplace():
|
||||
|
||||
# initd replace
|
||||
if not os.path.exists(file_bin):
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
pureSbinConfig = getServerDir() + "/sbin/pure-config.pl"
|
||||
if not os.path.exists(pureSbinConfig):
|
||||
pureTplConfig = getPluginDir() + "/init.d/pure-config.pl"
|
||||
content = public.readFile(pureTplConfig)
|
||||
content = mw.readFile(pureTplConfig)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(pureSbinConfig, content)
|
||||
public.execShell('chmod +x ' + pureSbinConfig)
|
||||
mw.writeFile(pureSbinConfig, content)
|
||||
mw.execShell('chmod +x ' + pureSbinConfig)
|
||||
|
||||
pureFtpdConfig = getServerDir() + "/etc/pure-ftpd.conf"
|
||||
pureFtpdConfigBak = getServerDir() + "/etc/pure-ftpd.bak.conf"
|
||||
@@ -105,16 +105,16 @@ def initDreplace():
|
||||
|
||||
if not os.path.exists(pureFtpdConfigBak):
|
||||
shutil.copyfile(pureFtpdConfig, pureFtpdConfigBak)
|
||||
content = public.readFile(pureFtpdConfigTpl)
|
||||
content = mw.readFile(pureFtpdConfigTpl)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(pureFtpdConfig, content)
|
||||
mw.writeFile(pureFtpdConfig, content)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def start():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' start')
|
||||
data = mw.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -122,7 +122,7 @@ def start():
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
data = mw.execShell(file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -130,7 +130,7 @@ def stop():
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' restart')
|
||||
data = mw.execShell(file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -138,7 +138,7 @@ def restart():
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
data = mw.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -146,7 +146,7 @@ def reload():
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
os_name = mw.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
@@ -158,45 +158,45 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
os_name = mw.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)
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
os_name = public.getOs()
|
||||
os_name = mw.getOs()
|
||||
if os_name == 'darwin':
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def pftpDB():
|
||||
file = getServerDir() + '/ftps.db'
|
||||
if not os.path.exists(file):
|
||||
conn = public.M('ftps').dbPos(getServerDir(), 'ftps')
|
||||
csql = public.readFile(getPluginDir() + '/conf/ftps.sql')
|
||||
conn = mw.M('ftps').dbPos(getServerDir(), 'ftps')
|
||||
csql = mw.readFile(getPluginDir() + '/conf/ftps.sql')
|
||||
csql_list = csql.split(';')
|
||||
for index in range(len(csql_list)):
|
||||
conn.execute(csql_list[index], ())
|
||||
else:
|
||||
conn = public.M('ftps').dbPos(getServerDir(), 'ftps')
|
||||
conn = mw.M('ftps').dbPos(getServerDir(), 'ftps')
|
||||
return conn
|
||||
|
||||
|
||||
def pftpUser():
|
||||
if public.isAppleSystem():
|
||||
user = public.execShell(
|
||||
if mw.isAppleSystem():
|
||||
user = mw.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
return user
|
||||
return 'www'
|
||||
@@ -207,40 +207,40 @@ def pftpAdd(username, password, path):
|
||||
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
os.system('chown ' + user + '.staff ' + path)
|
||||
else:
|
||||
os.system('chown www.www ' + path)
|
||||
|
||||
cmd = getServerDir() + '/bin/pure-pw useradd ' + username + ' -u ' + user + ' -d ' + \
|
||||
path + '<<EOF \n' + password + '\n' + password + '\nEOF'
|
||||
return public.execShell(cmd)
|
||||
return mw.execShell(cmd)
|
||||
|
||||
|
||||
def pftpMod(username, password):
|
||||
user = pftpUser()
|
||||
cmd = getServerDir() + '/bin/pure-pw passwd ' + username + \
|
||||
'<<EOF \n' + password + '\n' + password + '\nEOF'
|
||||
return public.execShell(cmd)
|
||||
return mw.execShell(cmd)
|
||||
|
||||
|
||||
def pftpStop(username):
|
||||
cmd = getServerDir() + '/bin/pure-pw usermod ' + username + ' -r 1'
|
||||
return public.execShell(cmd)
|
||||
return mw.execShell(cmd)
|
||||
|
||||
|
||||
def pftpStart(username):
|
||||
cmd = getServerDir() + '/bin/pure-pw usermod ' + username + " -r ''"
|
||||
return public.execShell(cmd)
|
||||
return mw.execShell(cmd)
|
||||
|
||||
|
||||
def pftpReload():
|
||||
public.execShell(getServerDir() + '/bin/pure-pw mkdb ' +
|
||||
getServerDir() + '/etc/pureftpd.pdb')
|
||||
mw.execShell(getServerDir() + '/bin/pure-pw mkdb ' +
|
||||
getServerDir() + '/etc/pureftpd.pdb')
|
||||
|
||||
|
||||
def getWwwDir():
|
||||
path = public.getWwwDir()
|
||||
path = mw.getWwwDir()
|
||||
return path
|
||||
|
||||
|
||||
@@ -248,7 +248,7 @@ def getFtpPort():
|
||||
import re
|
||||
try:
|
||||
file = getServerDir() + '/etc/pure-ftpd.conf'
|
||||
conf = public.readFile(file)
|
||||
conf = mw.readFile(file)
|
||||
rep = "\n#?\s*Bind\s+[0-9]+\.[0-9]+\.[0-9]+\.+[0-9]+,([0-9]+)"
|
||||
port = re.search(rep, conf).groups()[0]
|
||||
except:
|
||||
@@ -287,15 +287,15 @@ def getFtpList():
|
||||
_page['p'] = page
|
||||
_page['row'] = page_size
|
||||
_page['tojs'] = 'ftpList'
|
||||
data['page'] = public.getPage(_page)
|
||||
data['page'] = mw.getPage(_page)
|
||||
|
||||
info = {}
|
||||
info['ip'] = public.getLocalIp()
|
||||
info['ip'] = mw.getLocalIp()
|
||||
info['port'] = getFtpPort()
|
||||
data['info'] = info
|
||||
data['data'] = clist
|
||||
|
||||
return public.getJson(data)
|
||||
return mw.getJson(data)
|
||||
|
||||
|
||||
def addFtp():
|
||||
@@ -338,12 +338,12 @@ def delFtp():
|
||||
if not 'username' in args:
|
||||
return 'username missing'
|
||||
|
||||
public.execShell(getServerDir() +
|
||||
'/bin/pure-pw userdel ' + args['username'])
|
||||
mw.execShell(getServerDir() +
|
||||
'/bin/pure-pw userdel ' + args['username'])
|
||||
pftpReload()
|
||||
conn = pftpDB()
|
||||
conn.where("id=?", (args['id'],)).delete()
|
||||
public.writeLog('TYPE_FTP', 'FTP_DEL_SUCCESS', (args['username'],))
|
||||
mw.writeLog('TYPE_FTP', 'FTP_DEL_SUCCESS', (args['username'],))
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -380,12 +380,12 @@ def modFtpPort():
|
||||
if int(port) < 1 or int(port) > 65535:
|
||||
return '端口范围不正确!'
|
||||
file = file = getServerDir() + '/etc/pure-ftpd.conf'
|
||||
conf = public.readFile(file)
|
||||
conf = mw.readFile(file)
|
||||
rep = u"\n#?\s*Bind\s+[0-9]+\.[0-9]+\.[0-9]+\.+[0-9]+,([0-9]+)"
|
||||
# preg_match(rep,conf,tmp)
|
||||
conf = re.sub(
|
||||
rep, "\nBind 0.0.0.0," + port, conf)
|
||||
public.writeFile(file, conf)
|
||||
mw.writeFile(file, conf)
|
||||
restart()
|
||||
return 'ok'
|
||||
except Exception as ex:
|
||||
|
||||
@@ -8,7 +8,7 @@ import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('utf8')
|
||||
@@ -17,7 +17,7 @@ sys.path.append('/usr/local/lib/python2.7/site-packages')
|
||||
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -59,8 +59,8 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def getInitDTpl():
|
||||
@@ -89,7 +89,7 @@ def getRunLog():
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = public.getServerDir()
|
||||
service_path = mw.getServerDir()
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
return content
|
||||
|
||||
@@ -99,14 +99,14 @@ def initDreplace():
|
||||
ddir = getServerDir() + '/workers'
|
||||
if not os.path.exists(ddir):
|
||||
sdir = getPluginDir() + '/workers'
|
||||
public.execShell('cp -rf ' + sdir + ' ' + getServerDir())
|
||||
mw.execShell('cp -rf ' + sdir + ' ' + getServerDir())
|
||||
|
||||
cfg = getServerDir() + '/qb.conf'
|
||||
if not os.path.exists(cfg):
|
||||
cfg_tpl = getPluginDir() + '/conf/qb.conf'
|
||||
content = public.readFile(cfg_tpl)
|
||||
content = mw.readFile(cfg_tpl)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(cfg, content)
|
||||
mw.writeFile(cfg, content)
|
||||
|
||||
file_tpl = getInitDTpl()
|
||||
service_path = os.path.dirname(os.getcwd())
|
||||
@@ -118,16 +118,16 @@ def initDreplace():
|
||||
|
||||
# initd replace
|
||||
if not os.path.exists(file_bin):
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep qbittorrent_worker | grep -v grep | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -137,13 +137,13 @@ def status():
|
||||
def start():
|
||||
|
||||
cmd = "ps -ef | grep qbittorrent-nox |grep -v grep |awk '{print $2}'"
|
||||
ret = public.execShell(cmd)
|
||||
ret = mw.execShell(cmd)
|
||||
if ret[0] == '':
|
||||
public.execShell('qbittorrent-nox -d')
|
||||
mw.execShell('qbittorrent-nox -d')
|
||||
|
||||
file = initDreplace()
|
||||
|
||||
data = public.execShell(file + ' start')
|
||||
data = mw.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -151,9 +151,9 @@ def start():
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
data = mw.execShell(file + ' stop')
|
||||
# cmd = "ps -ef | grep qbittorrent-nox |grep -v grep |awk '{print $2}' | xargs kill"
|
||||
# public.execShell(cmd)
|
||||
# mw.execShell(cmd)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -161,7 +161,7 @@ def stop():
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' restart')
|
||||
data = mw.execShell(file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -169,7 +169,7 @@ def restart():
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
data = mw.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -177,7 +177,7 @@ def reload():
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
initd_bin = getInitDFile()
|
||||
@@ -189,24 +189,24 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mysql_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(mysql_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ def matchData(reg, content):
|
||||
|
||||
def getDbConfInfo():
|
||||
cfg = getConf()
|
||||
content = public.readFile(cfg)
|
||||
content = mw.readFile(cfg)
|
||||
data = {}
|
||||
data['DB_HOST'] = matchData("DB_HOST\s*=\s(.*)", content)
|
||||
data['DB_USER'] = matchData("DB_USER\s*=\s(.*)", content)
|
||||
@@ -229,7 +229,7 @@ def getDbConfInfo():
|
||||
|
||||
def getQbConf():
|
||||
cfg = getConf()
|
||||
content = public.readFile(cfg)
|
||||
content = mw.readFile(cfg)
|
||||
data = {}
|
||||
data['QB_HOST'] = matchData("QB_HOST\s*=\s(.*)", content)
|
||||
data['QB_PORT'] = matchData("QB_PORT\s*=\s(.*)", content)
|
||||
@@ -261,7 +261,7 @@ def pQbClient():
|
||||
def getQbUrl():
|
||||
info = getQbConf()
|
||||
url = 'http://' + info['QB_HOST'] + ':' + info['QB_PORT'] + '/'
|
||||
return public.returnJson(True, 'ok', url)
|
||||
return mw.returnJson(True, 'ok', url)
|
||||
|
||||
|
||||
def qbList():
|
||||
@@ -283,9 +283,9 @@ def qbList():
|
||||
data = {}
|
||||
data['type'] = tfilter
|
||||
data['torrents'] = torrents
|
||||
return public.returnJson(True, 'ok', data)
|
||||
return mw.returnJson(True, 'ok', data)
|
||||
except Exception as e:
|
||||
return public.returnJson(False, str(e))
|
||||
return mw.returnJson(False, str(e))
|
||||
|
||||
|
||||
def qbDel():
|
||||
@@ -295,7 +295,7 @@ def qbDel():
|
||||
return data[1]
|
||||
qb = pQbClient()
|
||||
data = qb.delete(args['hash'])
|
||||
return public.returnJson(True, '操作成功!', data)
|
||||
return mw.returnJson(True, '操作成功!', data)
|
||||
|
||||
|
||||
def qbAdd():
|
||||
@@ -306,7 +306,7 @@ def qbAdd():
|
||||
url = 'magnet:?xt=urn:btih:' + args['hash']
|
||||
qb = pQbClient()
|
||||
data = qb.download_from_link(url)
|
||||
return public.returnJson(True, '操作成功!', data)
|
||||
return mw.returnJson(True, '操作成功!', data)
|
||||
|
||||
|
||||
def test():
|
||||
@@ -315,7 +315,7 @@ def test():
|
||||
# print qb.download_from_link(magnet_link)
|
||||
torrents = qb.torrents(filter='downloading')
|
||||
for torrent in torrents:
|
||||
print public.returnJson(False, torrent)
|
||||
print mw.returnJson(False, torrent)
|
||||
|
||||
if __name__ == "__main__":
|
||||
func = sys.argv[1]
|
||||
|
||||
+22
-22
@@ -6,10 +6,10 @@ import os
|
||||
import time
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -59,7 +59,7 @@ def getArgs():
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep redis |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'")
|
||||
|
||||
if data[0] == '':
|
||||
@@ -78,22 +78,22 @@ def initDreplace():
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
|
||||
# initd replace
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
# config replace
|
||||
conf_content = public.readFile(getConf())
|
||||
conf_content = mw.readFile(getConf())
|
||||
conf_content = conf_content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(getServerDir() + '/redis.conf', conf_content)
|
||||
mw.writeFile(getServerDir() + '/redis.conf', conf_content)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def start():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' start')
|
||||
data = mw.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -101,7 +101,7 @@ def start():
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
data = mw.execShell(file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -109,7 +109,7 @@ def stop():
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' restart')
|
||||
data = mw.execShell(file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -117,7 +117,7 @@ def restart():
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
data = mw.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -125,7 +125,7 @@ def reload():
|
||||
|
||||
def runInfo():
|
||||
cmd = getServerDir() + "/bin/redis-cli info"
|
||||
data = public.execShell(cmd)[0]
|
||||
data = mw.execShell(cmd)[0]
|
||||
res = [
|
||||
'tcp_port',
|
||||
'uptime_in_days', # 已运行天数
|
||||
@@ -150,12 +150,12 @@ def runInfo():
|
||||
if not t[0] in res:
|
||||
continue
|
||||
result[t[0]] = t[1]
|
||||
return public.getJson(result)
|
||||
return mw.getJson(result)
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
@@ -166,23 +166,23 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.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)
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
return 'ok'
|
||||
|
||||
+47
-47
@@ -8,10 +8,10 @@ import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@ def getInitDTpl():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -58,18 +58,18 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = public.getServerDir()
|
||||
service_path = mw.getServerDir()
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
return content
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep rsync |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -77,20 +77,20 @@ def status():
|
||||
|
||||
|
||||
def appConf():
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return getServerDir() + '/rsyncd.conf'
|
||||
return '/etc/rsyncd.conf'
|
||||
|
||||
|
||||
def appConfPwd():
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return getServerDir() + '/rsyncd.passwd'
|
||||
return '/etc/rsyncd.passwd'
|
||||
|
||||
|
||||
def getLog():
|
||||
conf_path = appConf()
|
||||
conf = public.readFile(conf_path)
|
||||
conf = mw.readFile(conf_path)
|
||||
rep = 'log file\s*=\s*(.*)'
|
||||
tmp = re.search(rep, conf)
|
||||
if not tmp:
|
||||
@@ -100,18 +100,18 @@ def getLog():
|
||||
|
||||
def initDreplace():
|
||||
conf_path = appConf()
|
||||
conf = public.readFile(conf_path)
|
||||
conf = mw.readFile(conf_path)
|
||||
|
||||
compile_sub = re.compile('^#(.*)', re.M)
|
||||
conf = compile_sub.sub('', conf)
|
||||
conf_tpl_path = getPluginDir() + '/conf/rsyncd.conf'
|
||||
if conf.strip() == '':
|
||||
content = public.readFile(conf_tpl_path)
|
||||
public.writeFile(conf_path, content)
|
||||
content = mw.readFile(conf_tpl_path)
|
||||
mw.writeFile(conf_path, content)
|
||||
confpwd_path = appConfPwd()
|
||||
if not os.path.exists(confpwd_path):
|
||||
public.writeFile(confpwd_path, '')
|
||||
public.execShell('chmod 0600 ' + confpwd_path)
|
||||
mw.writeFile(confpwd_path, '')
|
||||
mw.execShell('chmod 0600 ' + confpwd_path)
|
||||
|
||||
initD_path = getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
@@ -121,23 +121,23 @@ def initDreplace():
|
||||
file_tpl = getInitDTpl()
|
||||
# initd replace
|
||||
if not os.path.exists(file_bin):
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
if os.path.exists('/usr/lib/systemd/system/rsyncd.service'):
|
||||
public.execShell('rm -rf /usr/lib/systemd/system/rsyncd*')
|
||||
mw.execShell('rm -rf /usr/lib/systemd/system/rsyncd*')
|
||||
|
||||
rlog = getLog()
|
||||
if os.path.exists(rlog):
|
||||
public.writeFile(rlog, '')
|
||||
mw.writeFile(rlog, '')
|
||||
return file_bin
|
||||
|
||||
|
||||
def start():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' start')
|
||||
data = mw.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -145,14 +145,14 @@ def start():
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
data = mw.execShell(file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def restart():
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
stop()
|
||||
start()
|
||||
@@ -160,10 +160,10 @@ def restart():
|
||||
|
||||
|
||||
def reload():
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
# data = public.execShell('systemctl reload rsyncd.service')
|
||||
# data = mw.execShell('systemctl reload rsyncd.service')
|
||||
# if data[1] == '':
|
||||
# return 'ok'
|
||||
# return 'fail'
|
||||
@@ -174,7 +174,7 @@ def reload():
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
initd_bin = getInitDFile()
|
||||
@@ -186,30 +186,30 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
p_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(p_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def getRecListData():
|
||||
path = appConf()
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
|
||||
flist = re.findall("\[(.*)\]", content)
|
||||
flist_len = len(flist)
|
||||
@@ -237,12 +237,12 @@ def getRecListData():
|
||||
|
||||
def getRecList():
|
||||
ret_list = getRecListData()
|
||||
return public.returnJson(True, 'ok', ret_list)
|
||||
return mw.returnJson(True, 'ok', ret_list)
|
||||
|
||||
|
||||
def getUPwdList():
|
||||
pwd_path = appConfPwd()
|
||||
pwd_content = public.readFile(pwd_path)
|
||||
pwd_content = mw.readFile(pwd_path)
|
||||
plist = pwd_content.strip().split('\n')
|
||||
plist_len = len(plist)
|
||||
data = {}
|
||||
@@ -264,12 +264,12 @@ def addRec():
|
||||
args_ps = args['ps']
|
||||
|
||||
pwd_path = appConfPwd()
|
||||
pwd_content = public.readFile(pwd_path)
|
||||
pwd_content = mw.readFile(pwd_path)
|
||||
pwd_content += args_name + ':' + args_pwd + "\n"
|
||||
public.writeFile(pwd_path, pwd_content)
|
||||
mw.writeFile(pwd_path, pwd_content)
|
||||
|
||||
path = appConf()
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
|
||||
con = "\n\n" + '[' + args_name + ']' + "\n"
|
||||
con += 'path = ' + args_path + "\n"
|
||||
@@ -278,8 +278,8 @@ def addRec():
|
||||
con += 'read only = false'
|
||||
|
||||
content = content + con
|
||||
public.writeFile(path, content)
|
||||
return public.returnJson(True, '添加成功')
|
||||
mw.writeFile(path, content)
|
||||
return mw.returnJson(True, '添加成功')
|
||||
|
||||
|
||||
def delRec():
|
||||
@@ -290,12 +290,12 @@ def delRec():
|
||||
args_name = args['name']
|
||||
|
||||
cmd = "sed -i '_bak' '/" + args_name + "/d' " + appConfPwd()
|
||||
public.execShell(cmd)
|
||||
mw.execShell(cmd)
|
||||
|
||||
try:
|
||||
|
||||
path = appConf()
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
|
||||
ret_list = getRecListData()
|
||||
ret_list_len = len(ret_list)
|
||||
@@ -317,10 +317,10 @@ def delRec():
|
||||
conre = re.search(reg, content, re.S)
|
||||
content = content.replace(
|
||||
"[" + args_name + "]\n" + conre.groups()[0], '')
|
||||
public.writeFile(path, content)
|
||||
return public.returnJson(True, '删除成功!')
|
||||
mw.writeFile(path, content)
|
||||
return mw.returnJson(True, '删除成功!')
|
||||
except Exception as e:
|
||||
return public.returnJson(False, '删除失败!')
|
||||
return mw.returnJson(False, '删除失败!')
|
||||
|
||||
|
||||
def cmdRec():
|
||||
@@ -331,13 +331,13 @@ def cmdRec():
|
||||
|
||||
an = args['name']
|
||||
pwd_list = getUPwdList()
|
||||
ip = public.getLocalIp()
|
||||
ip = mw.getLocalIp()
|
||||
|
||||
cmd = 'echo "' + pwd_list[an] + '" > /tmp/p.pass' + "<br>"
|
||||
cmd += 'chmod 600 /tmp/p.pass' + "<br>"
|
||||
cmd += 'rsync -arv --password-file=/tmp/p.pass --progress --delete /project ' + \
|
||||
an + '@' + ip + '::' + an
|
||||
return public.returnJson(True, 'OK!', cmd)
|
||||
return mw.returnJson(True, 'OK!', cmd)
|
||||
|
||||
# rsyncdReceive
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -7,10 +7,10 @@ import time
|
||||
import shutil
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
@@ -46,13 +46,13 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
cmd = "ps -ef|grep ssserver |grep -v grep | awk '{print $2}'"
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
@@ -62,7 +62,7 @@ def start():
|
||||
path = getPathFile()
|
||||
shell_cmd = 'ssserver -c ' + path + ' -d start'
|
||||
|
||||
data = public.execShell(shell_cmd)
|
||||
data = mw.execShell(shell_cmd)
|
||||
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
@@ -73,7 +73,7 @@ def stop():
|
||||
path = getPathFile()
|
||||
shell_cmd = 'ssserver -c ' + path + ' -d stop'
|
||||
|
||||
data = public.execShell(shell_cmd)
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -82,7 +82,7 @@ def stop():
|
||||
def restart():
|
||||
path = getPathFile()
|
||||
shell_cmd = 'ssserver -c ' + path + ' -d restart'
|
||||
data = public.execShell(shell_cmd)
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -91,7 +91,7 @@ def restart():
|
||||
def reload():
|
||||
path = getPathFile()
|
||||
shell_cmd = 'ssserver -c ' + path + ' -d restart'
|
||||
data = public.execShell(shell_cmd)
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -117,10 +117,10 @@ def initDreplace():
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
|
||||
# initd replace
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
return file_bin
|
||||
|
||||
@@ -133,7 +133,7 @@ def getInitDFile():
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
@@ -144,23 +144,23 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.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)
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
return 'ok'
|
||||
|
||||
+35
-33
@@ -8,11 +8,11 @@ import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -21,14 +21,14 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
import mysql
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -57,8 +57,8 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def getInitDTpl():
|
||||
@@ -80,10 +80,12 @@ def getCheckdbPos():
|
||||
file = getServerDir() + "/start_pos.pl"
|
||||
return file
|
||||
|
||||
|
||||
def getBlackList():
|
||||
file = getServerDir() + "/workers/black_list.txt"
|
||||
return file
|
||||
|
||||
|
||||
def getRunLog():
|
||||
file = getServerDir() + "/logs.pl"
|
||||
return file
|
||||
@@ -94,13 +96,13 @@ def initDreplace():
|
||||
ddir = getServerDir() + '/workers'
|
||||
if not os.path.exists(ddir):
|
||||
sdir = getPluginDir() + '/workers'
|
||||
public.execShell('cp -rf ' + sdir + ' ' + getServerDir())
|
||||
mw.execShell('cp -rf ' + sdir + ' ' + getServerDir())
|
||||
|
||||
cfg = getServerDir() + '/db.cfg'
|
||||
if not os.path.exists(cfg):
|
||||
cfg_tpl = getPluginDir() + '/workers/db.cfg'
|
||||
content = public.readFile(cfg_tpl)
|
||||
public.writeFile(cfg, content)
|
||||
content = mw.readFile(cfg_tpl)
|
||||
mw.writeFile(cfg, content)
|
||||
|
||||
file_tpl = getInitDTpl()
|
||||
service_path = os.path.dirname(os.getcwd())
|
||||
@@ -111,16 +113,16 @@ def initDreplace():
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
|
||||
# initd replace
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep \"simdht_worker.py\" | grep -v grep | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -130,7 +132,7 @@ def status():
|
||||
def start():
|
||||
file = initDreplace()
|
||||
|
||||
data = public.execShell(file + ' start')
|
||||
data = mw.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -138,7 +140,7 @@ def start():
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
data = mw.execShell(file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -146,7 +148,7 @@ def stop():
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' restart')
|
||||
data = mw.execShell(file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -154,7 +156,7 @@ def restart():
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
data = mw.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -162,7 +164,7 @@ def reload():
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
initd_bin = getInitDFile()
|
||||
@@ -174,24 +176,24 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mysql_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(mysql_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -202,7 +204,7 @@ def matchData(reg, content):
|
||||
|
||||
def getDbConfInfo():
|
||||
cfg = getDbConf()
|
||||
content = public.readFile(cfg)
|
||||
content = mw.readFile(cfg)
|
||||
data = {}
|
||||
data['DB_HOST'] = matchData("DB_HOST\s*=\s(.*)", content)
|
||||
data['DB_USER'] = matchData("DB_USER\s*=\s(.*)", content)
|
||||
@@ -227,23 +229,23 @@ def isSqlError(mysqlMsg):
|
||||
# 检测数据库执行错误
|
||||
mysqlMsg = str(mysqlMsg)
|
||||
if "MySQLdb" in mysqlMsg:
|
||||
return public.returnJson(False, 'MySQLdb组件缺失! <br>进入SSH命令行输入: pip install mysql-python')
|
||||
return mw.returnJson(False, 'MySQLdb组件缺失! <br>进入SSH命令行输入: pip install mysql-python')
|
||||
if "2002," in mysqlMsg:
|
||||
return public.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
return mw.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
if "using password:" in mysqlMsg:
|
||||
return public.returnJson(False, '数据库管理密码错误!')
|
||||
return mw.returnJson(False, '数据库管理密码错误!')
|
||||
if "Connection refused" in mysqlMsg:
|
||||
return public.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
return mw.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!')
|
||||
if "1133" in mysqlMsg:
|
||||
return public.returnJson(False, '数据库用户不存在!')
|
||||
return mw.returnJson(False, '数据库用户不存在!')
|
||||
if "1007" in mysqlMsg:
|
||||
return public.returnJson(False, '数据库已经存在!')
|
||||
return mw.returnJson(False, '数据库已经存在!')
|
||||
return None
|
||||
|
||||
|
||||
def getMinData(conn, sec):
|
||||
time_diff = 0
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
time_diff = 3 * 60
|
||||
pre = time.strftime("%Y-%m-%d %H:%M:%S",
|
||||
time.localtime(time.time() - sec - time_diff))
|
||||
@@ -267,10 +269,10 @@ def getTrendData():
|
||||
one = getMinData(pdb, 2)
|
||||
two = getMinData(pdb, 5)
|
||||
three = getMinData(pdb, 10)
|
||||
return public.getJson([one, two, three])
|
||||
return mw.getJson([one, two, three])
|
||||
except Exception as e:
|
||||
print str(e)
|
||||
return public.getJson([0, 0, 0])
|
||||
return mw.getJson([0, 0, 0])
|
||||
|
||||
|
||||
def dhtCmd():
|
||||
|
||||
+48
-48
@@ -8,10 +8,10 @@ import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -61,13 +61,13 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
pn = getPluginName()
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep " + pn + " |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -84,65 +84,65 @@ def initDreplace():
|
||||
os.mkdir(initD_path)
|
||||
|
||||
user = 'solr'
|
||||
if public.isAppleSystem():
|
||||
user = public.execShell(
|
||||
if mw.isAppleSystem():
|
||||
user = mw.execShell(
|
||||
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
|
||||
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
if not os.path.exists(file_bin):
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$RUN_USER}', user)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
file_py = initD_path + '/' + getPluginName() + '.py'
|
||||
if not os.path.exists(file_py):
|
||||
content = public.readFile(getPluginDir() + '/script/full.py')
|
||||
public.writeFile(file_py, content)
|
||||
public.execShell('chmod +x ' + file_py)
|
||||
content = mw.readFile(getPluginDir() + '/script/full.py')
|
||||
mw.writeFile(file_py, content)
|
||||
mw.execShell('chmod +x ' + file_py)
|
||||
|
||||
file_incr_py = initD_path + '/' + getPluginName() + '_incr.py'
|
||||
if not os.path.exists(file_incr_py):
|
||||
content = public.readFile(getPluginDir() + '/script/incr.py')
|
||||
public.writeFile(file_incr_py, content)
|
||||
public.execShell('chmod +x ' + file_incr_py)
|
||||
content = mw.readFile(getPluginDir() + '/script/incr.py')
|
||||
mw.writeFile(file_incr_py, content)
|
||||
mw.execShell('chmod +x ' + file_incr_py)
|
||||
|
||||
# realm.properties
|
||||
rp_path = getServerDir() + "/server/etc/realm.properties"
|
||||
rp_path_tpl = getPluginDir() + "/tpl/realm.properties"
|
||||
|
||||
# if not os.path.exists(rp_path):
|
||||
content = public.readFile(rp_path_tpl)
|
||||
public.writeFile(rp_path, content)
|
||||
content = mw.readFile(rp_path_tpl)
|
||||
mw.writeFile(rp_path, content)
|
||||
|
||||
# web.xml
|
||||
web_xml = getServerDir() + "/server/solr-webapp/webapp/WEB-INF/web.xml"
|
||||
web_xml_tpl = getPluginDir() + "/tpl/web.xml"
|
||||
content = public.readFile(web_xml_tpl)
|
||||
public.writeFile(web_xml, content)
|
||||
content = mw.readFile(web_xml_tpl)
|
||||
mw.writeFile(web_xml, content)
|
||||
|
||||
# solr-jetty-context.xml
|
||||
solr_jetty_context_xml = getServerDir() + "/server/contexts/solr-jetty-context.xml"
|
||||
solr_jetty_context_xml_tpl = getPluginDir() + "/tpl/solr-jetty-context.xml"
|
||||
content = public.readFile(solr_jetty_context_xml_tpl)
|
||||
public.writeFile(solr_jetty_context_xml, content)
|
||||
content = mw.readFile(solr_jetty_context_xml_tpl)
|
||||
mw.writeFile(solr_jetty_context_xml, content)
|
||||
|
||||
log_file = getLog()
|
||||
if os.path.exists(log_file):
|
||||
public.writeFile(log_file, '')
|
||||
mw.writeFile(log_file, '')
|
||||
|
||||
if not public.isAppleSystem():
|
||||
public.execShell('chown -R solr:solr ' + getServerDir())
|
||||
if not mw.isAppleSystem():
|
||||
mw.execShell('chown -R solr:solr ' + getServerDir())
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def runShell(shell):
|
||||
if public.isAppleSystem():
|
||||
data = public.execShell(shell)
|
||||
if mw.isAppleSystem():
|
||||
data = mw.execShell(shell)
|
||||
else:
|
||||
data = public.execShell('su - solr -c "/bin/bash ' + shell + '"')
|
||||
data = mw.execShell('su - solr -c "/bin/bash ' + shell + '"')
|
||||
return data
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ def reload():
|
||||
data = runShell(file + ' reload')
|
||||
|
||||
solr_log = getServerDir() + "/server/logs/solr.log"
|
||||
public.writeFile(solr_log, "")
|
||||
mw.writeFile(solr_log, "")
|
||||
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
@@ -196,16 +196,16 @@ def initdInstall():
|
||||
source_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
|
||||
if not app_debug:
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
|
||||
initd_bin = getInitDFile()
|
||||
|
||||
@@ -230,17 +230,17 @@ def collectionList():
|
||||
tmp['name'] = dirname
|
||||
dlist.append(tmp)
|
||||
data['list'] = dlist
|
||||
data['ip'] = public.getLocalIp()
|
||||
data['ip'] = mw.getLocalIp()
|
||||
data['port'] = '8983'
|
||||
|
||||
content = public.readFile(path + '/solr.xml')
|
||||
content = mw.readFile(path + '/solr.xml')
|
||||
|
||||
rep = "jetty.port:(.*)\}</int>"
|
||||
tmp = re.search(rep, content)
|
||||
port = tmp.groups()[0]
|
||||
data['port'] = port
|
||||
|
||||
return public.returnJson(True, 'OK', data)
|
||||
return mw.returnJson(True, 'OK', data)
|
||||
|
||||
|
||||
def addCollection():
|
||||
@@ -254,24 +254,24 @@ def addCollection():
|
||||
|
||||
retdata = runShell(solr_bin + ' create -c ' + name)
|
||||
if retdata[1] != "":
|
||||
return public.returnJson(False, '添加失败!:' + retdata[1])
|
||||
return mw.returnJson(False, '添加失败!:' + retdata[1])
|
||||
|
||||
sc_path = getServerDir() + "/server/solr/" + name + "/conf/solrconfig.xml"
|
||||
sc_path_tpl = getPluginDir() + "/tpl/solrconfig.xml"
|
||||
content = public.readFile(sc_path_tpl)
|
||||
public.writeFile(sc_path, content)
|
||||
content = mw.readFile(sc_path_tpl)
|
||||
mw.writeFile(sc_path, content)
|
||||
|
||||
sd_path = getServerDir() + "/server/solr/" + name + "/conf/db-data-config.xml"
|
||||
sd_path_tpl = getPluginDir() + "/tpl/db-data-config.xml"
|
||||
content = public.readFile(sd_path_tpl)
|
||||
public.writeFile(sd_path, content)
|
||||
content = mw.readFile(sd_path_tpl)
|
||||
mw.writeFile(sd_path, content)
|
||||
|
||||
sd_path = getServerDir() + "/server/solr/" + name + "/conf/managed-schema"
|
||||
sd_path_tpl = getPluginDir() + "/tpl/managed-schema"
|
||||
content = public.readFile(sd_path_tpl)
|
||||
public.writeFile(sd_path, content)
|
||||
content = mw.readFile(sd_path_tpl)
|
||||
mw.writeFile(sd_path, content)
|
||||
|
||||
return public.returnJson(True, '添加成功!:' + retdata[0])
|
||||
return mw.returnJson(True, '添加成功!:' + retdata[0])
|
||||
|
||||
|
||||
def removeCollection():
|
||||
@@ -285,8 +285,8 @@ def removeCollection():
|
||||
|
||||
retdata = runShell(solr_bin + ' delete -c ' + name)
|
||||
if retdata[1] != "":
|
||||
return public.returnJson(False, '删除失败!:' + retdata[1])
|
||||
return public.returnJson(True, '删除成功!:' + retdata[0])
|
||||
return mw.returnJson(False, '删除失败!:' + retdata[1])
|
||||
return mw.returnJson(True, '删除成功!:' + retdata[0])
|
||||
|
||||
|
||||
def confFileCollection():
|
||||
@@ -298,7 +298,7 @@ def confFileCollection():
|
||||
conf_file = getServerDir() + "/server/solr/" + \
|
||||
args['name'] + "/conf/" + args['conf_file']
|
||||
# print conf_file
|
||||
return public.returnJson(True, 'OK', {'path': conf_file})
|
||||
return mw.returnJson(True, 'OK', {'path': conf_file})
|
||||
|
||||
|
||||
def scriptFull():
|
||||
|
||||
+45
-43
@@ -9,10 +9,10 @@ import string
|
||||
import subprocess
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -68,8 +68,8 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def configTpl():
|
||||
@@ -79,7 +79,7 @@ def configTpl():
|
||||
for one in pathFile:
|
||||
file = path + '/' + one
|
||||
tmp.append(file)
|
||||
return public.getJson(tmp)
|
||||
return mw.getJson(tmp)
|
||||
|
||||
|
||||
def readConfigTpl():
|
||||
@@ -88,21 +88,21 @@ def readConfigTpl():
|
||||
if not data[0]:
|
||||
return data[1]
|
||||
|
||||
content = public.readFile(args['file'])
|
||||
content = mw.readFile(args['file'])
|
||||
content = contentReplace(content)
|
||||
return public.returnJson(True, 'ok', content)
|
||||
return mw.returnJson(True, 'ok', content)
|
||||
|
||||
|
||||
def contentReplace(content):
|
||||
service_path = public.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', public.getRootDir())
|
||||
service_path = mw.getServerDir()
|
||||
content = content.replace('{$ROOT_PATH}', mw.getRootDir())
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
content = content.replace('{$SERVER_APP}', service_path + '/sphinx')
|
||||
return content
|
||||
|
||||
|
||||
def status():
|
||||
data = public.execShell(
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep sphinx |grep -v grep | grep -v python | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
@@ -110,16 +110,16 @@ def status():
|
||||
|
||||
|
||||
def mkdirAll():
|
||||
content = public.readFile(getConf())
|
||||
content = mw.readFile(getConf())
|
||||
rep = 'path\s*=\s*(.*)'
|
||||
p = re.compile(rep)
|
||||
tmp = p.findall(content)
|
||||
|
||||
for x in tmp:
|
||||
if x.find('binlog') != -1:
|
||||
public.execShell('mkdir -p ' + x)
|
||||
mw.execShell('mkdir -p ' + x)
|
||||
else:
|
||||
public.execShell('mkdir -p ' + os.path.dirname(x))
|
||||
mw.execShell('mkdir -p ' + os.path.dirname(x))
|
||||
|
||||
|
||||
def initDreplace():
|
||||
@@ -134,24 +134,24 @@ def initDreplace():
|
||||
|
||||
# initd replace
|
||||
if not os.path.exists(file_bin):
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = contentReplace(content)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
# config replace
|
||||
conf_bin = getConf()
|
||||
if not os.path.exists(conf_bin):
|
||||
conf_content = public.readFile(getConfTpl())
|
||||
conf_content = mw.readFile(getConfTpl())
|
||||
conf_content = contentReplace(conf_content)
|
||||
public.writeFile(getServerDir() + '/sphinx.conf', conf_content)
|
||||
mw.writeFile(getServerDir() + '/sphinx.conf', conf_content)
|
||||
|
||||
mkdirAll()
|
||||
return file_bin
|
||||
|
||||
|
||||
def checkIndexSph():
|
||||
content = public.readFile(getConf())
|
||||
content = mw.readFile(getConf())
|
||||
rep = 'path\s*=\s*(.*)'
|
||||
p = re.compile(rep)
|
||||
tmp = p.findall(content)
|
||||
@@ -159,23 +159,24 @@ def checkIndexSph():
|
||||
if x.find('binlog') != -1:
|
||||
continue
|
||||
else:
|
||||
p = x+'.sph'
|
||||
if os.path.exists(p):
|
||||
p = x + '.sph'
|
||||
if os.path.exists(p):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def start():
|
||||
file = initDreplace()
|
||||
|
||||
data = sphinxConfParse()
|
||||
if 'index' in data :
|
||||
if 'index' in data:
|
||||
if checkIndexSph():
|
||||
rebuild()
|
||||
time.sleep(5)
|
||||
else:
|
||||
return '配置不正确!'
|
||||
|
||||
data = public.execShell(file + ' start')
|
||||
data = mw.execShell(file + ' start')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -183,7 +184,7 @@ def start():
|
||||
|
||||
def stop():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' stop')
|
||||
data = mw.execShell(file + ' stop')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -191,7 +192,7 @@ def stop():
|
||||
|
||||
def restart():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' restart')
|
||||
data = mw.execShell(file + ' restart')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -199,7 +200,7 @@ def restart():
|
||||
|
||||
def reload():
|
||||
file = initDreplace()
|
||||
data = public.execShell(file + ' reload')
|
||||
data = mw.execShell(file + ' reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
@@ -209,13 +210,13 @@ def rebuild():
|
||||
file = initDreplace()
|
||||
subprocess.Popen(file + ' rebuild &',
|
||||
stdout=subprocess.PIPE, shell=True)
|
||||
# data = public.execShell(file + ' rebuild')
|
||||
# data = mw.execShell(file + ' rebuild')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
@@ -226,30 +227,30 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.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)
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def runLog():
|
||||
path = getConf()
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
rep = 'log\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0]
|
||||
@@ -257,7 +258,7 @@ def runLog():
|
||||
|
||||
def getPort():
|
||||
path = getConf()
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
rep = 'listen\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0]
|
||||
@@ -265,7 +266,7 @@ def getPort():
|
||||
|
||||
def queryLog():
|
||||
path = getConf()
|
||||
content = public.readFile(path)
|
||||
content = mw.readFile(path)
|
||||
rep = 'query_log\s*=\s*(.*)'
|
||||
tmp = re.search(rep, content)
|
||||
return tmp.groups()[0]
|
||||
@@ -274,7 +275,7 @@ def queryLog():
|
||||
def runStatus():
|
||||
s = status()
|
||||
if s != 'start':
|
||||
return public.returnJson(False, '没有启动程序')
|
||||
return mw.returnJson(False, '没有启动程序')
|
||||
|
||||
sys.path.append(getPluginDir() + "/class")
|
||||
import sphinxapi
|
||||
@@ -288,13 +289,13 @@ def runStatus():
|
||||
for x in range(len(info_status)):
|
||||
rData[info_status[x][0]] = info_status[x][1]
|
||||
|
||||
return public.returnJson(True, 'ok', rData)
|
||||
return mw.returnJson(True, 'ok', rData)
|
||||
|
||||
|
||||
def sphinxConfParse():
|
||||
file = getConf()
|
||||
bin_dir = getServerDir()
|
||||
content = public.readFile(file)
|
||||
content = mw.readFile(file)
|
||||
rep = 'index\s(.*)'
|
||||
sindex = re.findall(rep, content)
|
||||
indexlen = len(sindex)
|
||||
@@ -313,12 +314,13 @@ def sphinxConfParse():
|
||||
cmd['cmd'] = bin_dir + '/bin/bin/indexer -c ' + bin_dir + '/sphinx.conf'
|
||||
return cmd
|
||||
|
||||
|
||||
def sphinxCmd():
|
||||
data = sphinxConfParse()
|
||||
if 'index' in data:
|
||||
return public.returnJson(True, 'ok', data)
|
||||
return mw.returnJson(True, 'ok', data)
|
||||
else:
|
||||
return public.returnJson(False, 'no index')
|
||||
return mw.returnJson(False, 'no index')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -8,7 +8,7 @@ import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
|
||||
def status():
|
||||
@@ -16,22 +16,22 @@ def status():
|
||||
|
||||
|
||||
def start():
|
||||
public.execShell('sysctl -p')
|
||||
mw.execShell('sysctl -p')
|
||||
return "ok"
|
||||
|
||||
|
||||
def stop():
|
||||
public.execShell('sysctl -p')
|
||||
mw.execShell('sysctl -p')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def restart():
|
||||
public.execShell('sysctl -p')
|
||||
mw.execShell('sysctl -p')
|
||||
return 'ok'
|
||||
|
||||
|
||||
def reload():
|
||||
public.execShell('sysctl -p')
|
||||
mw.execShell('sysctl -p')
|
||||
return 'ok'
|
||||
|
||||
|
||||
|
||||
+18
-18
@@ -7,10 +7,10 @@ import time
|
||||
import shutil
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getArgs():
|
||||
@@ -46,13 +46,13 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
cmd = "ps -ef|grep v2ray |grep -v grep | grep -v 'mdserver-web'| awk '{print $2}'"
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
@@ -61,7 +61,7 @@ def status():
|
||||
def start():
|
||||
|
||||
shell_cmd = 'service ' + getPluginName() + ' start'
|
||||
data = public.execShell(shell_cmd)
|
||||
data = mw.execShell(shell_cmd)
|
||||
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
@@ -71,7 +71,7 @@ def start():
|
||||
def stop():
|
||||
shell_cmd = 'service ' + getPluginName() + ' stop'
|
||||
|
||||
data = public.execShell(shell_cmd)
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
@@ -79,12 +79,12 @@ def stop():
|
||||
|
||||
def restart():
|
||||
shell_cmd = 'service ' + getPluginName() + ' restart'
|
||||
data = public.execShell(shell_cmd)
|
||||
data = mw.execShell(shell_cmd)
|
||||
|
||||
log_file = getLog()
|
||||
if os.path.exists(log_file):
|
||||
clear_log_cmd = "echo '' > " + log_file
|
||||
public.execShell(clear_log_cmd)
|
||||
mw.execShell(clear_log_cmd)
|
||||
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
@@ -93,14 +93,14 @@ def restart():
|
||||
|
||||
def reload():
|
||||
shell_cmd = 'service ' + getPluginName() + ' reload'
|
||||
data = public.execShell(shell_cmd)
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
return 'ok'
|
||||
return data[1]
|
||||
|
||||
|
||||
def getPathFile():
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return getServerDir() + '/config.json'
|
||||
return '/etc/v2ray/config.json'
|
||||
|
||||
@@ -113,7 +113,7 @@ def getInitDFile():
|
||||
|
||||
def initdStatus():
|
||||
shell_cmd = 'systemctl status v2ray.service | grep loaded | grep "enabled;"'
|
||||
data = public.execShell(shell_cmd)
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
return 'fail'
|
||||
return 'ok'
|
||||
@@ -122,19 +122,19 @@ def initdStatus():
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
public.execShell('systemctl enable ' + getPluginName())
|
||||
mw.execShell('systemctl enable ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
public.execShell('systemctl disable ' + getPluginName())
|
||||
mw.execShell('systemctl disable ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
|
||||
+17
-17
@@ -9,10 +9,10 @@ import sys
|
||||
import subprocess
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
app_debug = False
|
||||
if public.isAppleSystem():
|
||||
if mw.isAppleSystem():
|
||||
app_debug = True
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ def getPluginName():
|
||||
|
||||
|
||||
def getPluginDir():
|
||||
return public.getPluginDir() + '/' + getPluginName()
|
||||
return mw.getPluginDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getServerDir():
|
||||
return public.getServerDir() + '/' + getPluginName()
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
@@ -62,14 +62,14 @@ def getArgs():
|
||||
def checkArgs(data, ck=[]):
|
||||
for i in range(len(ck)):
|
||||
if not ck[i] in data:
|
||||
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, public.returnJson(True, 'ok'))
|
||||
return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!'))
|
||||
return (True, mw.returnJson(True, 'ok'))
|
||||
|
||||
|
||||
def status():
|
||||
pn = getPluginName()
|
||||
cmd = "ps -ef|grep 'waller.py' | grep -v grep | awk '{print $2}'"
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
@@ -86,16 +86,16 @@ def initDreplace():
|
||||
|
||||
file_bin = initD_path + '/' + getPluginName()
|
||||
if not os.path.exists(file_bin):
|
||||
content = public.readFile(file_tpl)
|
||||
content = mw.readFile(file_tpl)
|
||||
content = content.replace('{$SERVER_PATH}', service_path)
|
||||
public.writeFile(file_bin, content)
|
||||
public.execShell('chmod +x ' + file_bin)
|
||||
mw.writeFile(file_bin, content)
|
||||
mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
return file_bin
|
||||
|
||||
|
||||
def runShell(shell):
|
||||
data = public.execShell(shell)
|
||||
data = mw.execShell(shell)
|
||||
return data
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ def reload():
|
||||
data = runShell(file + ' reload')
|
||||
|
||||
solr_log = getServerDir() + "/code/logs/walle.log"
|
||||
public.writeFile(solr_log, "")
|
||||
mw.writeFile(solr_log, "")
|
||||
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
@@ -148,16 +148,16 @@ def initdInstall():
|
||||
source_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
public.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
|
||||
if not app_debug:
|
||||
public.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdUinstall():
|
||||
if not app_debug:
|
||||
public.execShell('chkconfig --del ' + getPluginName())
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
|
||||
initd_bin = getInitDFile()
|
||||
|
||||
@@ -172,13 +172,13 @@ def prodConf():
|
||||
|
||||
def initEnv():
|
||||
cmd = "cd " + getServerDir() + "/code" + " && sh admin.sh init"
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
return "shell:<br>" + data[0] + "<br>" + " error:<br>" + data[1]
|
||||
|
||||
|
||||
def initData():
|
||||
cmd = "cd " + getServerDir() + "/code" + " && sh admin.sh migration"
|
||||
data = public.execShell(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
return "shell:<br>" + data[0] + "<br>" + " error:<br>" + data[1]
|
||||
# rsyncdReceive
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -8,7 +8,7 @@ import re
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd() + "/class/core")
|
||||
import public
|
||||
import mw
|
||||
|
||||
|
||||
def status():
|
||||
|
||||
Reference in New Issue
Block a user