diff --git a/class/core/common.py b/class/core/common.py
index 8d25e3a81..c8da7c337 100755
--- a/class/core/common.py
+++ b/class/core/common.py
@@ -13,7 +13,7 @@ import re
import hashlib
from random import Random
-import public
+import mw
import db
from flask import redirect
@@ -41,7 +41,7 @@ def checkClose():
def initDB():
try:
sql = db.Sql().dbfile('default')
- csql = public.readFile('data/sql/default.sql')
+ csql = mw.readFile('data/sql/default.sql')
csql_list = csql.split(';')
for index in range(len(csql_list)):
sql.execute(csql_list[index], ())
@@ -51,33 +51,33 @@ def initDB():
def initInitD():
- script = public.getRunDir() + '/scripts/init.d/mw.tpl'
- script_bin = public.getRunDir() + '/scripts/init.d/mw'
+ script = mw.getRunDir() + '/scripts/init.d/mw.tpl'
+ script_bin = mw.getRunDir() + '/scripts/init.d/mw'
# if os.path.exists(script_bin):
# return
- content = public.readFile(script)
- content = content.replace("{$SERVER_PATH}", public.getRunDir())
+ content = mw.readFile(script)
+ content = content.replace("{$SERVER_PATH}", mw.getRunDir())
- public.writeFile(script_bin, content)
- public.execShell('chmod +x ' + script_bin)
+ mw.writeFile(script_bin, content)
+ mw.execShell('chmod +x ' + script_bin)
- if not public.isAppleSystem():
+ if not mw.isAppleSystem():
initd_bin = '/etc/init.d/mw'
if not os.path.exists(initd_bin):
import shutil
shutil.copyfile(script_bin, initd_bin)
- public.execShell('chmod +x ' + initd_bin)
- #加入自启动
- public.execShell('chkconfig --add mw')
+ mw.execShell('chmod +x ' + initd_bin)
+ # 加入自启动
+ mw.execShell('chkconfig --add mw')
def initUserInfo():
- data = public.M('users').where('id=?', (1,)).getField('password')
+ data = mw.M('users').where('id=?', (1,)).getField('password')
if data == '21232f297a57a5a743894a0e4a801fc3':
- pwd = public.getRandomString(8).lower()
- file_pw = public.getRunDir() + '/data/default.pl'
- public.writeFile(file_pw, pwd)
- public.M('users').where('id=?', (1,)).setField(
- 'password', public.md5(pwd))
+ pwd = mw.getRandomString(8).lower()
+ file_pw = mw.getRunDir() + '/data/default.pl'
+ mw.writeFile(file_pw, pwd)
+ mw.M('users').where('id=?', (1,)).setField(
+ 'password', mw.md5(pwd))
diff --git a/class/core/config_api.py b/class/core/config_api.py
index c4d527e09..525b1de13 100755
--- a/class/core/config_api.py
+++ b/class/core/config_api.py
@@ -4,7 +4,7 @@ import psutil
import time
import os
import sys
-import public
+import mw
import re
import json
import pwd
@@ -26,9 +26,9 @@ class config_api:
# 取面板列表
def getPanelListApi(self):
- data = public.M('panel').field(
+ data = mw.M('panel').field(
'id,title,url,username,password,click,addtime').order('click desc').select()
- return public.getJson(data)
+ return mw.getJson(data)
def addPanelInfoApi(self):
title = request.form.get('title', '')
@@ -36,24 +36,24 @@ class config_api:
username = request.form.get('username', '')
password = request.form.get('password', '')
# 校验是还是重复
- isAdd = public.M('panel').where(
+ isAdd = mw.M('panel').where(
'title=? OR url=?', (title, url)).count()
if isAdd:
- return public.returnJson(False, '备注或面板地址重复!')
- isRe = public.M('panel').add('title,url,username,password,click,addtime',
- (title, url, username, password, 0, int(time.time())))
+ return mw.returnJson(False, '备注或面板地址重复!')
+ isRe = mw.M('panel').add('title,url,username,password,click,addtime',
+ (title, url, username, password, 0, int(time.time())))
if isRe:
- return public.returnJson(True, '添加成功!')
- return public.returnJson(False, '添加失败!')
+ return mw.returnJson(True, '添加成功!')
+ return mw.returnJson(False, '添加失败!')
# 删除面板资料
def delPanelInfoApi(self):
mid = request.form.get('id', '')
- isExists = public.M('panel').where('id=?', (mid,)).count()
+ isExists = mw.M('panel').where('id=?', (mid,)).count()
if not isExists:
- return public.returnJson(False, '指定面板资料不存在!')
- public.M('panel').where('id=?', (mid,)).delete()
- return public.returnJson(True, '删除成功!')
+ return mw.returnJson(False, '指定面板资料不存在!')
+ mw.M('panel').where('id=?', (mid,)).delete()
+ return mw.returnJson(True, '删除成功!')
# 修改面板资料
def setPanelInfoApi(self):
@@ -63,51 +63,51 @@ class config_api:
password = request.form.get('password', '')
mid = request.form.get('id', '')
# 校验是还是重复
- isSave = public.M('panel').where(
+ isSave = mw.M('panel').where(
'(title=? OR url=?) AND id!=?', (title, url, mid)).count()
if isSave:
- return public.returnJson(False, '备注或面板地址重复!')
+ return mw.returnJson(False, '备注或面板地址重复!')
# 更新到数据库
- isRe = public.M('panel').where('id=?', (mid,)).save(
+ isRe = mw.M('panel').where('id=?', (mid,)).save(
'title,url,username,password', (title, url, username, password))
if isRe:
- return public.returnJson(True, '修改成功!')
- return public.returnJson(False, '修改失败!')
+ return mw.returnJson(True, '修改成功!')
+ return mw.returnJson(False, '修改失败!')
def syncDateApi(self):
- if public.isAppleSystem():
- return public.returnJson(True, '开发系统不必同步时间!')
+ if mw.isAppleSystem():
+ return mw.returnJson(True, '开发系统不必同步时间!')
- data = public.execShell('ntpdate -s time.nist.gov')
+ data = mw.execShell('ntpdate -s time.nist.gov')
if data[0] == '':
- return public.returnJson(True, '同步成功!')
- return public.returnJson(False, '同步失败:' + data[0])
+ return mw.returnJson(True, '同步成功!')
+ return mw.returnJson(False, '同步失败:' + data[0])
def setPasswordApi(self):
password1 = request.form.get('password1', '')
password2 = request.form.get('password2', '')
if password1 != password2:
- return public.returnJson(False, '两次输入的密码不一致,请重新输入!')
+ return mw.returnJson(False, '两次输入的密码不一致,请重新输入!')
if len(password1) < 5:
- return public.returnJson(False, '用户密码不能小于5位!')
- public.M('users').where("username=?", (session['username'],)).setField(
- 'password', public.md5(password1.strip()))
- return public.returnJson(True, '密码修改成功!')
+ return mw.returnJson(False, '用户密码不能小于5位!')
+ mw.M('users').where("username=?", (session['username'],)).setField(
+ 'password', mw.md5(password1.strip()))
+ return mw.returnJson(True, '密码修改成功!')
def setNameApi(self):
name1 = request.form.get('name1', '')
name2 = request.form.get('name2', '')
if name1 != name2:
- return public.returnJson(False, '两次输入的用户名不一致,请重新输入!')
+ return mw.returnJson(False, '两次输入的用户名不一致,请重新输入!')
if len(name1) < 3:
- return public.returnJson(False, '用户名长度不能少于3位')
+ return mw.returnJson(False, '用户名长度不能少于3位')
- public.M('users').where("username=?", (session['username'],)).setField(
+ mw.M('users').where("username=?", (session['username'],)).setField(
'username', name1.strip())
session['username'] = name1
- return public.returnJson(True, '用户修改成功!')
+ return mw.returnJson(True, '用户修改成功!')
def setApi(self):
webname = request.form.get('webname', '')
@@ -120,34 +120,34 @@ class config_api:
if domain != '':
reg = "^([\w\-\*]{1,100}\.){1,4}(\w{1,10}|\w{1,10}\.\w{1,10})$"
if not re.match(reg, domain):
- return public.returnJson(False, '主域名格式不正确')
+ return mw.returnJson(False, '主域名格式不正确')
if int(port) >= 65535 or int(port) < 100:
- return public.returnJson(False, '端口范围不正确!')
+ return mw.returnJson(False, '端口范围不正确!')
- if webname != public.getConfig('title'):
- public.setConfig('title', webname)
+ if webname != mw.getConfig('title'):
+ mw.setConfig('title', webname)
- if sites_path != public.getWwwDir():
- public.setWwwDir(sites_path)
+ if sites_path != mw.getWwwDir():
+ mw.setWwwDir(sites_path)
- if backup_path != public.getWwwDir():
- public.setBackupDir(backup_path)
+ if backup_path != mw.getWwwDir():
+ mw.setBackupDir(backup_path)
- if port != public.getHostPort():
+ if port != mw.getHostPort():
import system_api
- public.setHostPort(port)
+ mw.setHostPort(port)
system_api.system_api().restartMw()
- if host_ip != public.getHostAddr():
- public.setHostAddr(host_ip)
+ if host_ip != mw.getHostAddr():
+ mw.setHostAddr(host_ip)
- mhost = public.getHostAddr()
+ mhost = mw.getHostAddr()
info = {
'uri': '/config',
'host': mhost + ':' + port
}
- return public.returnJson(True, '保存成功!', info)
+ return mw.returnJson(True, '保存成功!', info)
def setAdminPathApi(self):
admin_path = request.form.get('admin_path', '').strip()
@@ -159,59 +159,59 @@ class config_api:
admin_path = '/'
if admin_path != '/':
if len(admin_path) < 6:
- return public.returnJson(False, '安全入口地址长度不能小于6位!')
+ return mw.returnJson(False, '安全入口地址长度不能小于6位!')
if admin_path in admin_path_checks:
- return public.returnJson(False, '该入口已被面板占用,请使用其它入口!')
+ return mw.returnJson(False, '该入口已被面板占用,请使用其它入口!')
if not re.match("^/[\w\./-_]+$", admin_path):
- return public.returnJson(False, '入口地址格式不正确,示例: /my_panel')
+ return mw.returnJson(False, '入口地址格式不正确,示例: /my_panel')
else:
- domain = public.readFile('data/domain.conf')
+ domain = mw.readFile('data/domain.conf')
if not domain:
domain = ''
- limitip = public.readFile('data/limitip.conf')
+ limitip = mw.readFile('data/limitip.conf')
if not limitip:
limitip = ''
if not domain.strip() and not limitip.strip():
- return public.returnJson(False, '警告,关闭安全入口等于直接暴露你的后台地址在外网,十分危险,至少开启以下一种安全方式才能关闭:
1、绑定访问域名
2、绑定授权IP')
+ return mw.returnJson(False, '警告,关闭安全入口等于直接暴露你的后台地址在外网,十分危险,至少开启以下一种安全方式才能关闭:
1、绑定访问域名
2、绑定授权IP')
admin_path_file = 'data/admin_path.pl'
admin_path_old = '/'
if os.path.exists(admin_path_file):
- admin_path_old = public.readFile(admin_path_file).strip()
+ admin_path_old = mw.readFile(admin_path_file).strip()
if admin_path_old != admin_path:
- public.writeFile(admin_path_file, admin_path)
- public.restartMw()
- return public.returnJson(True, '修改成功!')
+ mw.writeFile(admin_path_file, admin_path)
+ mw.restartMw()
+ return mw.returnJson(True, '修改成功!')
def closePanelApi(self):
filename = 'data/close.pl'
if os.path.exists(filename):
os.remove(filename)
- return public.returnJson(True, '开启成功')
- public.writeFile(filename, 'True')
- public.execShell("chmod 600 " + filename)
- public.execShell("chown root.root " + filename)
- return public.returnJson(True, '面板已关闭!')
+ return mw.returnJson(True, '开启成功')
+ mw.writeFile(filename, 'True')
+ mw.execShell("chmod 600 " + filename)
+ mw.execShell("chown root.root " + filename)
+ return mw.returnJson(True, '面板已关闭!')
def setIpv6StatusApi(self):
ipv6_file = 'data/ipv6.pl'
if os.path.exists('data/ipv6.pl'):
os.remove(ipv6_file)
- public.writeLog('面板设置', '关闭面板IPv6兼容!')
+ mw.writeLog('面板设置', '关闭面板IPv6兼容!')
else:
- public.writeFile(ipv6_file, 'True')
- public.writeLog('面板设置', '开启面板IPv6兼容!')
- public.restartMw()
- return public.returnJson(True, '设置成功!')
+ mw.writeFile(ipv6_file, 'True')
+ mw.writeLog('面板设置', '开启面板IPv6兼容!')
+ mw.restartMw()
+ return mw.returnJson(True, '设置成功!')
# 获取面板证书
def getPanelSslApi(self):
cert = {}
- cert['privateKey'] = public.readFile('ssl/privateKey.pem')
- cert['certPem'] = public.readFile('ssl/certificate.pem')
+ cert['privateKey'] = mw.readFile('ssl/privateKey.pem')
+ cert['certPem'] = mw.readFile('ssl/certificate.pem')
cert['rep'] = os.path.exists('ssl/input.pl')
- return public.getJson(cert)
+ return mw.getJson(cert)
# 保存面板证书
def savePanelSslApi(self):
@@ -222,37 +222,37 @@ class config_api:
certPem = request.form.get('certPem', '').strip()
privateKey = request.form.get('privateKey', '').strip()
- public.writeFile(checkCert, certPem)
+ mw.writeFile(checkCert, certPem)
if privateKey:
- public.writeFile(keyPath, privateKey)
+ mw.writeFile(keyPath, privateKey)
if certPem:
- public.writeFile(certPath, certPem)
- if not public.checkCert(checkCert):
- return public.returnJson(False, '证书错误,请检查!')
- public.writeFile('ssl/input.pl', 'True')
- return public.returnJson(True, '证书已保存!')
+ mw.writeFile(certPath, certPem)
+ if not mw.checkCert(checkCert):
+ return mw.returnJson(False, '证书错误,请检查!')
+ mw.writeFile('ssl/input.pl', 'True')
+ return mw.returnJson(True, '证书已保存!')
# 设置面板SSL
def setPanelSslApi(self):
- sslConf = public.getRunDir() + '/data/ssl.pl'
+ sslConf = mw.getRunDir() + '/data/ssl.pl'
if os.path.exists(sslConf):
os.system('rm -f ' + sslConf)
- return public.returnJson(True, 'SSL已关闭,请使用http协议访问面板!')
+ return mw.returnJson(True, 'SSL已关闭,请使用http协议访问面板!')
else:
os.system('pip install cffi==1.10')
os.system('pip install cryptography==2.1')
os.system('pip install pyOpenSSL==16.2')
try:
if not self.createSSL():
- return public.returnJson(False, '开启失败,无法自动安装pyOpenSSL组件!
请尝试手动安装: pip install pyOpenSSL
')
- public.writeFile(sslConf, 'True')
+ return mw.returnJson(False, '开启失败,无法自动安装pyOpenSSL组件!请尝试手动安装: pip install pyOpenSSL
')
+ mw.writeFile(sslConf, 'True')
except Exception as ex:
- return public.returnJson(False, '开启失败,无法自动安装pyOpenSSL组件!请尝试手动安装: pip install pyOpenSSL
')
- return public.returnJson(True, '开启成功,请使用https协议访问面板!')
+ return mw.returnJson(False, '开启失败,无法自动安装pyOpenSSL组件!请尝试手动安装: pip install pyOpenSSL
')
+ return mw.returnJson(True, '开启成功,请使用https协议访问面板!')
def getApi(self):
data = {}
- return public.getJson(data)
+ return mw.getJson(data)
##### ----- end ----- ###
# 自签证书
@@ -275,8 +275,8 @@ class config_api:
private_key = OpenSSL.crypto.dump_privatekey(
OpenSSL.crypto.FILETYPE_PEM, key)
if len(cert_ca) > 100 and len(private_key) > 100:
- public.writeFile('ssl/certificate.pem', cert_ca)
- public.writeFile('ssl/privateKey.pem', private_key)
+ mw.writeFile('ssl/certificate.pem', cert_ca)
+ mw.writeFile('ssl/privateKey.pem', private_key)
print cert_ca, private_key
return True
return False
@@ -287,20 +287,20 @@ class config_api:
def get(self):
data = {}
- data['title'] = public.getConfig('title')
- data['site_path'] = public.getWwwDir()
- data['backup_path'] = public.getBackupDir()
+ data['title'] = mw.getConfig('title')
+ data['site_path'] = mw.getWwwDir()
+ data['backup_path'] = mw.getBackupDir()
sformat = 'date +"%Y-%m-%d %H:%M:%S %Z %z"'
- data['systemdate'] = public.execShell(sformat)[0].strip()
+ data['systemdate'] = mw.execShell(sformat)[0].strip()
- data['port'] = public.getHostPort()
- data['ip'] = public.getHostAddr()
+ data['port'] = mw.getHostPort()
+ data['ip'] = mw.getHostAddr()
admin_path_file = 'data/admin_path.pl'
if not os.path.exists(admin_path_file):
data['admin_path'] = '/'
else:
- data['admin_path'] = public.readFile(admin_path_file)
+ data['admin_path'] = mw.readFile(admin_path_file)
ipv6_file = 'data/ipv6.pl'
if os.path.exists('data/ipv6.pl'):
@@ -314,9 +314,9 @@ class config_api:
else:
data['ssl'] = ''
- data['site_count'] = public.M('sites').count()
+ data['site_count'] = mw.M('sites').count()
- data['username'] = public.M('users').where(
+ data['username'] = mw.M('users').where(
"id=?", (1,)).getField('username')
return data
diff --git a/class/core/crontab_api.py b/class/core/crontab_api.py
index 52fe16ec6..08d0206d4 100755
--- a/class/core/crontab_api.py
+++ b/class/core/crontab_api.py
@@ -4,7 +4,7 @@ import psutil
import time
import os
import sys
-import public
+import mw
import re
import json
import pwd
@@ -21,7 +21,7 @@ class crontab_api:
##### ----- start ----- ###
def listApi(self):
- _list = public.M('crontab').where('', ()).field(self.field).limit(
+ _list = mw.M('crontab').where('', ()).field(self.field).limit(
'0,30').order('id desc').select()
data = []
@@ -29,54 +29,54 @@ class crontab_api:
tmp = _list[i]
if _list[i]['type'] == "day":
tmp['type'] = '每天'
- tmp['cycle'] = public.getInfo('每天, {1}点{2}分 执行', (str(
+ tmp['cycle'] = mw.getInfo('每天, {1}点{2}分 执行', (str(
_list[i]['where_hour']), str(_list[i]['where_minute'])))
elif _list[i]['type'] == "day-n":
- tmp['type'] = public.getInfo(
+ tmp['type'] = mw.getInfo(
'每{1}天', (str(_list[i]['where1']),))
- tmp['cycle'] = public.getInfo('每隔{1}天, {2}点{3}分 执行', (str(
+ tmp['cycle'] = mw.getInfo('每隔{1}天, {2}点{3}分 执行', (str(
_list[i]['where1']), str(_list[i]['where_hour']), str(_list[i]['where_minute'])))
elif _list[i]['type'] == "hour":
tmp['type'] = '每小时'
- tmp['cycle'] = public.getInfo(
+ tmp['cycle'] = mw.getInfo(
'每小时, 第{1}分钟 执行', (str(_list[i]['where_minute']),))
elif _list[i]['type'] == "hour-n":
- tmp['type'] = public.getInfo(
+ tmp['type'] = mw.getInfo(
'每{1}小时', (str(_list[i]['where1']),))
- tmp['cycle'] = public.getInfo('每{1}小时, 第{2}分钟 执行', (str(
+ tmp['cycle'] = mw.getInfo('每{1}小时, 第{2}分钟 执行', (str(
_list[i]['where1']), str(_list[i]['where_minute'])))
elif _list[i]['type'] == "minute-n":
- tmp['type'] = public.getInfo(
+ tmp['type'] = mw.getInfo(
'每{1}分钟', (str(_list[i]['where1']),))
- tmp['cycle'] = public.getInfo(
+ tmp['cycle'] = mw.getInfo(
'每隔{1}分钟执行', (str(_list[i]['where1']),))
elif _list[i]['type'] == "week":
tmp['type'] = '每周'
if not _list[i]['where1']:
_list[i]['where1'] = '0'
- tmp['cycle'] = public.getInfo('每周{1}, {2}点{3}分执行', (self.toWeek(int(
+ tmp['cycle'] = mw.getInfo('每周{1}, {2}点{3}分执行', (self.toWeek(int(
_list[i]['where1'])), str(_list[i]['where_hour']), str(_list[i]['where_minute'])))
elif _list[i]['type'] == "month":
tmp['type'] = '每月'
- tmp['cycle'] = public.getInfo('每月, {1}日 {2}点{3}分执行', (str(_list[i]['where1']), str(
+ tmp['cycle'] = mw.getInfo('每月, {1}日 {2}点{3}分执行', (str(_list[i]['where1']), str(
_list[i]['where_hour']), str(_list[i]['where_minute'])))
data.append(tmp)
_ret = {}
_ret['data'] = data
- count = public.M('crontab').where('', ()).count()
+ count = mw.M('crontab').where('', ()).count()
_page = {}
_page['count'] = count
_page['tojs'] = 'remind'
- _ret['page'] = public.getPage(_page)
- return public.getJson(_ret)
+ _ret['page'] = mw.getPage(_page)
+ return mw.getJson(_ret)
# 设置计划任务状态
def setCronStatusApi(self):
mid = request.form.get('id', '')
- cronInfo = public.M('crontab').where(
+ cronInfo = mw.M('crontab').where(
'id=?', (mid,)).field(self.field).find()
status = 1
if cronInfo['status'] == status:
@@ -86,17 +86,17 @@ class crontab_api:
cronInfo['status'] = 1
self.syncToCrond(cronInfo)
- public.M('crontab').where('id=?', (mid,)).setField('status', status)
- public.writeLog(
+ mw.M('crontab').where('id=?', (mid,)).setField('status', status)
+ mw.writeLog(
'计划任务', '修改计划任务[' + cronInfo['name'] + ']状态为[' + str(status) + ']')
- return public.returnJson(True, '设置成功')
+ return mw.returnJson(True, '设置成功')
# 获取指定任务数据
def getCrondFindApi(self):
sid = request.form.get('id', '')
- data = public.M('crontab').where(
+ data = mw.M('crontab').where(
'id=?', (sid,)).field(self.field).find()
- return public.getJson(data)
+ return mw.getJson(data)
def modifyCrondApi(self):
sid = request.form.get('id', '')
@@ -114,7 +114,7 @@ class crontab_api:
urladdress = request.form.get('urladdress', '')
if len(iname) < 1:
- return public.returnJson(False, '任务名称不能为空!')
+ return mw.returnJson(False, '任务名称不能为空!')
params = {
'name': iname,
@@ -131,7 +131,7 @@ class crontab_api:
'urladdress': urladdress,
}
cuonConfig, get, name = self.getCrondCycle(params)
- cronInfo = public.M('crontab').where(
+ cronInfo = mw.M('crontab').where(
'id=?', (sid,)).field(self.field).find()
del(cronInfo['id'])
del(cronInfo['addtime'])
@@ -145,21 +145,21 @@ class crontab_api:
cronInfo['sbody'] = get['sbody']
cronInfo['urladdress'] = get['urladdress']
- addData = public.M('crontab').where('id=?', (sid,)).save('name,type,where1,where_hour,where_minute,save,backup_to,sbody,urladdress', (get[
+ addData = mw.M('crontab').where('id=?', (sid,)).save('name,type,where1,where_hour,where_minute,save,backup_to,sbody,urladdress', (get[
'name'], field_type, get['where1'], get['hour'], get['minute'], get['save'], get['backup_to'], get['sbody'], get['urladdress']))
self.removeForCrond(cronInfo['echo'])
self.syncToCrond(cronInfo)
- public.writeLog('计划任务', '修改计划任务[' + cronInfo['name'] + ']成功')
- return public.returnJson(True, '修改成功')
+ mw.writeLog('计划任务', '修改计划任务[' + cronInfo['name'] + ']成功')
+ return mw.returnJson(True, '修改成功')
def logsApi(self):
sid = request.form.get('id', '')
- echo = public.M('crontab').where("id=?", (sid,)).field('echo').find()
- logFile = public.getServerDir() + '/cron/' + echo['echo'] + '.log'
+ echo = mw.M('crontab').where("id=?", (sid,)).field('echo').find()
+ logFile = mw.getServerDir() + '/cron/' + echo['echo'] + '.log'
if not os.path.exists(logFile):
- return public.returnJson(False, '当前日志为空!')
- log = public.getNumLines(logFile, 2000)
- return public.returnJson(True, log)
+ return mw.returnJson(False, '当前日志为空!')
+ log = mw.getNumLines(logFile, 2000)
+ return mw.returnJson(True, log)
def addApi(self):
iname = request.form.get('name', '')
@@ -176,7 +176,7 @@ class crontab_api:
urladdress = request.form.get('urladdress', '')
if len(iname) < 1:
- return public.returnJson(False, '任务名称不能为空!')
+ return mw.returnJson(False, '任务名称不能为空!')
params = {
'name': iname,
@@ -195,7 +195,7 @@ class crontab_api:
# print params
cuonConfig, get, name = self.getCrondCycle(params)
- cronPath = public.getServerDir() + '/cron'
+ cronPath = mw.getServerDir() + '/cron'
cronName = self.getShell(params)
# print cuonConfig, _params, name
@@ -213,30 +213,30 @@ class crontab_api:
return wRes
self.crondReload()
- addData = public.M('crontab').add('name,type,where1,where_hour,where_minute,echo,addtime,status,save,backup_to,stype,sname,sbody,urladdress', (iname, field_type, where1, hour, minute, cronName, time.strftime(
+ addData = mw.M('crontab').add('name,type,where1,where_hour,where_minute,echo,addtime,status,save,backup_to,stype,sname,sbody,urladdress', (iname, field_type, where1, hour, minute, cronName, time.strftime(
'%Y-%m-%d %X', time.localtime()), 1, save, backup_to, stype, sname, sbody, urladdress))
if addData > 0:
- return public.returnJson(True, '添加成功')
- return public.returnJson(False, '添加失败')
+ return mw.returnJson(True, '添加成功')
+ return mw.returnJson(False, '添加失败')
def startTaskApi(self):
sid = request.form.get('id', '')
- echo = public.M('crontab').where('id=?', (sid,)).getField('echo')
- execstr = public.getServerDir() + '/cron/' + echo
+ echo = mw.M('crontab').where('id=?', (sid,)).getField('echo')
+ execstr = mw.getServerDir() + '/cron/' + echo
os.system('chmod +x ' + execstr)
os.system('nohup ' + execstr + ' >> ' + execstr + '.log 2>&1 &')
- return public.returnJson(True, '任务已执行!')
+ return mw.returnJson(True, '任务已执行!')
def delApi(self):
sid = request.form.get('id', '')
try:
- find = public.M('crontab').where(
+ find = mw.M('crontab').where(
"id=?", (sid,)).field('name,echo').find()
if not self.removeForCrond(find['echo']):
- return public.returnJson(False, '无法写入文件,请检查是否开启了系统加固功能!')
+ return mw.returnJson(False, '无法写入文件,请检查是否开启了系统加固功能!')
- cronPath = public.getServerDir() + '/cron'
+ cronPath = mw.getServerDir() + '/cron'
sfile = cronPath + '/' + find['echo']
if os.path.exists(sfile):
@@ -245,22 +245,22 @@ class crontab_api:
if os.path.exists(sfile):
os.remove(sfile)
- public.M('crontab').where("id=?", (sid,)).delete()
- public.writeLog('计划任务', public.getInfo(
+ mw.M('crontab').where("id=?", (sid,)).delete()
+ mw.writeLog('计划任务', mw.getInfo(
'删除计划任务[{1}]成功!', (find['name'],)))
- return public.returnJson(True, '删除成功')
+ return mw.returnJson(True, '删除成功')
except Exception as e:
- return public.returnJson(False, '删除失败:' + str(e))
+ return mw.returnJson(False, '删除失败:' + str(e))
def delLogsApi(self):
sid = request.form.get('id', '')
try:
- echo = public.M('crontab').where("id=?", (sid,)).getField('echo')
- logFile = public.getServerDir() + '/cron/' + echo + '.log'
+ echo = mw.M('crontab').where("id=?", (sid,)).getField('echo')
+ logFile = mw.getServerDir() + '/cron/' + echo + '.log'
os.remove(logFile)
- return public.returnJson(True, '任务日志已清空!')
+ return mw.returnJson(True, '任务日志已清空!')
except:
- return public.returnJson(False, '任务日志清空失败!')
+ return mw.returnJson(False, '任务日志清空失败!')
# 取数据列表
def getDataListApi(self):
@@ -268,19 +268,19 @@ class crontab_api:
if stype == 'databases':
db_list = {}
db_list['orderOpt'] = []
- path = public.getServerDir() + '/mysql'
+ path = mw.getServerDir() + '/mysql'
if not os.path.exists(path + '/mysql.db'):
db_list['data'] = []
else:
- db_list['data'] = public.M('databases').dbPos(
+ db_list['data'] = mw.M('databases').dbPos(
path, 'mysql').field('name,ps').select()
- return public.getJson(db_list)
+ return mw.getJson(db_list)
data = {}
- data['data'] = public.M(stype).field('name,ps').select()
+ data['data'] = mw.M(stype).field('name,ps').select()
data['orderOpt'] = []
# try:
- # tmp = public.readFile('data/libList.conf')
+ # tmp = mw.readFile('data/libList.conf')
# libs = json.loads(tmp)
# import imp
# for lib in libs:
@@ -291,7 +291,7 @@ class crontab_api:
# data['orderOpt'].append(tmp)
# except Exception as e:
# print e
- return public.getJson(data)
+ return mw.getJson(data)
##### ----- start ----- ###
# 转换大写星期
@@ -318,7 +318,7 @@ class crontab_api:
name = '每天'
elif params['type'] == "day-n":
cuonConfig = self.getDay_N(params)
- name = public.getInfo('每{1}天', (params['where1'],))
+ name = mw.getInfo('每{1}天', (params['where1'],))
elif params['type'] == "hour":
cuonConfig = self.getHour(params)
name = '每小时'
@@ -384,24 +384,24 @@ class crontab_api:
log = '.log'
wheres = {
- 'path': head + "python " + public.getServerDir() + "/mdserver-web/scripts/backup.py path " + param['sname'] + " " + str(param['save']),
- 'site': head + "python " + public.getServerDir() + "/mdserver-web/scripts/backup.py site " + param['sname'] + " " + str(param['save']),
- 'database': head + "python " + public.getServerDir() + "/mdserver-web/scripts/backup.py database " + param['sname'] + " " + str(param['save']),
- 'logs': head + "python " + public.getServerDir() + "/mdserver-web/scripts/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
- 'rememory': head + "/bin/bash " + public.getServerDir() + '/mdserver-web/scripts/rememory.sh'
+ 'path': head + "python " + mw.getServerDir() + "/mdserver-web/scripts/backup.py path " + param['sname'] + " " + str(param['save']),
+ 'site': head + "python " + mw.getServerDir() + "/mdserver-web/scripts/backup.py site " + param['sname'] + " " + str(param['save']),
+ 'database': head + "python " + mw.getServerDir() + "/mdserver-web/scripts/backup.py database " + param['sname'] + " " + str(param['save']),
+ 'logs': head + "python " + mw.getServerDir() + "/mdserver-web/scripts/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
+ 'rememory': head + "/bin/bash " + mw.getServerDir() + '/mdserver-web/scripts/rememory.sh'
}
if param['backup_to'] != 'localhost':
- cfile = public.getServerDir() + "/mdserver-web/plugin/" + param[
+ cfile = mw.getServerDir() + "/mdserver-web/plugin/" + param[
'backup_to'] + "/" + param['backup_to'] + "_main.py"
if not os.path.exists(cfile):
- cfile = public.getServerDir() + "/mdserver-web/script/backup_" + \
+ cfile = mw.getServerDir() + "/mdserver-web/script/backup_" + \
param['backup_to'] + ".py"
wheres = {
'path': head + "python " + cfile + " path " + param['sname'] + " " + str(param['save']),
'site': head + "python " + cfile + " site " + param['sname'] + " " + str(param['save']),
'database': head + "python " + cfile + " database " + param['sname'] + " " + str(param['save']),
- 'logs': head + "python " + public.getServerDir() + "/mdserver-web/scripts/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
- 'rememory': head + "/bin/bash " + public.getServerDir() + '/mdserver-web/scripts/rememory.sh'
+ 'logs': head + "python " + mw.getServerDir() + "/mdserver-web/scripts/logs_backup.py " + param['sname'] + log + " " + str(param['save']),
+ 'rememory': head + "/bin/bash " + mw.getServerDir() + '/mdserver-web/scripts/rememory.sh'
}
try:
shell = wheres[stype]
@@ -418,16 +418,16 @@ endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
'''
- cronPath = public.getServerDir() + '/cron'
+ cronPath = mw.getServerDir() + '/cron'
if not os.path.exists(cronPath):
- public.execShell('mkdir -p ' + cronPath)
+ mw.execShell('mkdir -p ' + cronPath)
if not 'echo' in param:
- cronName = public.md5(public.md5(str(time.time()) + '_mw'))
+ cronName = mw.md5(mw.md5(str(time.time()) + '_mw'))
else:
cronName = param['echo']
file = cronPath + '/' + cronName
- public.writeFile(file, self.checkScript(shell))
- public.execShell('chmod 750 ' + file)
+ mw.writeFile(file, self.checkScript(shell))
+ mw.execShell('chmod 750 ' + file)
return cronName
# 检查脚本
@@ -443,52 +443,52 @@ echo "--------------------------------------------------------------------------
u_file = '/var/spool/cron/crontabs/root'
if not os.path.exists(u_file):
file = '/var/spool/cron/root'
- if public.isAppleSystem():
+ if mw.isAppleSystem():
file = '/etc/crontab'
else:
file = u_file
if not os.path.exists(file):
- public.writeFile(file, '')
- conf = public.readFile(file)
+ mw.writeFile(file, '')
+ conf = mw.readFile(file)
conf += config + "\n"
- if public.writeFile(file, conf):
+ if mw.writeFile(file, conf):
if not os.path.exists(u_file):
- public.execShell("chmod 600 '" + file +
- "' && chown root.root " + file)
+ mw.execShell("chmod 600 '" + file +
+ "' && chown root.root " + file)
else:
- public.execShell("chmod 600 '" + file +
- "' && chown root.crontab " + file)
+ mw.execShell("chmod 600 '" + file +
+ "' && chown root.crontab " + file)
return True
- return public.returnJson(False, '文件写入失败,请检查是否开启系统加固功能!')
+ return mw.returnJson(False, '文件写入失败,请检查是否开启系统加固功能!')
# 重载配置
def crondReload(self):
- if public.isAppleSystem():
+ if mw.isAppleSystem():
if os.path.exists('/etc/crontab'):
pass
- # public.execShell('/usr/sbin/cron restart')
+ # mw.execShell('/usr/sbin/cron restart')
else:
if os.path.exists('/etc/init.d/crond'):
- public.execShell('/etc/init.d/crond reload')
+ mw.execShell('/etc/init.d/crond reload')
elif os.path.exists('/etc/init.d/cron'):
- public.execShell('service cron restart')
+ mw.execShell('service cron restart')
else:
- public.execShell("systemctl reload crond")
+ mw.execShell("systemctl reload crond")
# 从crond删除
def removeForCrond(self, echo):
u_file = '/var/spool/cron/crontabs/root'
if not os.path.exists(u_file):
file = '/var/spool/cron/root'
- if public.isAppleSystem():
+ if mw.isAppleSystem():
file = '/etc/crontab'
else:
file = u_file
- conf = public.readFile(file)
+ conf = mw.readFile(file)
rep = ".+" + str(echo) + ".+\n"
conf = re.sub(rep, "", conf)
- if not public.writeFile(file, conf):
+ if not mw.writeFile(file, conf):
return False
self.crondReload()
return True
@@ -502,7 +502,7 @@ echo "--------------------------------------------------------------------------
cronInfo['minute'] = cronInfo['where_minute']
cronInfo['week'] = cronInfo['where1']
cuonConfig, cronInfo, name = self.getCrondCycle(cronInfo)
- cronPath = public.getServerDir() + '/cron'
+ cronPath = mw.getServerDir() + '/cron'
cronName = self.getShell(cronInfo)
if type(cronName) == dict:
return cronName
diff --git a/class/core/db.py b/class/core/db.py
index 22d3142a5..d7a6ecbf9 100755
--- a/class/core/db.py
+++ b/class/core/db.py
@@ -194,8 +194,8 @@ class Sql():
opt = opt[0:len(opt) - 1]
sql = "UPDATE " + self.__DB_TABLE + " SET " + opt + self.__OPT_WHERE
- import public
- public.writeFile('/tmp/test.pl', sql)
+ import mw
+ mw.writeFile('/tmp/test.pl', sql)
# 处理拼接WHERE与UPDATE参数
tmp = list(param)
@@ -249,8 +249,8 @@ class Sql():
def create(self, name):
# 创建数据表
self.__GetConn()
- import public
- script = public.readFile('data/' + name + '.sql')
+ import mw
+ script = mw.readFile('data/' + name + '.sql')
result = self.__DB_CONN.executescript(script)
self.__DB_CONN.commit()
return result.rowcount
@@ -258,8 +258,8 @@ class Sql():
def fofile(self, filename):
# 执行脚本
self.__GetConn()
- import public
- script = public.readFile(filename)
+ import mw
+ script = mw.readFile(filename)
result = self.__DB_CONN.executescript(script)
self.__DB_CONN.commit()
return result.rowcount
diff --git a/class/core/files_api.py b/class/core/files_api.py
index 50456df20..52672cf5a 100755
--- a/class/core/files_api.py
+++ b/class/core/files_api.py
@@ -4,7 +4,7 @@ import psutil
import time
import os
import sys
-import public
+import mw
import re
import json
import pwd
@@ -21,7 +21,7 @@ class files_api:
rPath = None
def __init__(self):
- self.rPath = public.getRootDir() + '/recycle_bin/'
+ self.rPath = mw.getRootDir() + '/recycle_bin/'
##### ----- start ----- ###
def getBodyApi(self):
@@ -33,13 +33,13 @@ class files_api:
line = request.form.get('line', '100')
if not os.path.exists(path):
- return public.returnJson(False, '文件不存在', (path,))
+ return mw.returnJson(False, '文件不存在', (path,))
try:
- data = public.getNumLines(path, int(line))
- return public.returnJson(True, 'OK', data)
+ data = mw.getNumLines(path, int(line))
+ return mw.returnJson(True, 'OK', data)
except Exception as ex:
- return public.returnJson(False, u'无法正确读取文件!' + str(ex))
+ return mw.returnJson(False, u'无法正确读取文件!' + str(ex))
def saveBodyApi(self):
path = request.form.get('path', '').encode('utf-8')
@@ -67,21 +67,21 @@ class files_api:
sfile = request.form.get('sfile', '').encode('utf-8')
dfile = request.form.get('dfile', '').encode('utf-8')
if not self.checkFileName(dfile):
- return public.returnJson(False, '文件名中不能包含特殊字符!')
+ return mw.returnJson(False, '文件名中不能包含特殊字符!')
if not os.path.exists(sfile):
- return public.returnJson(False, '指定文件不存在!')
+ return mw.returnJson(False, '指定文件不存在!')
if not self.checkDir(sfile):
- return public.returnJson(False, 'FILE_DANGER')
+ return mw.returnJson(False, 'FILE_DANGER')
import shutil
try:
shutil.move(sfile, dfile)
- msg = public.getInfo('移动文件或目录[{1}]到[{2}]成功!', (sfile, dfile,))
- public.writeLog('文件管理', msg)
- return public.returnJson(True, '移动文件或目录成功!')
+ msg = mw.getInfo('移动文件或目录[{1}]到[{2}]成功!', (sfile, dfile,))
+ mw.writeLog('文件管理', msg)
+ return mw.returnJson(True, '移动文件或目录成功!')
except:
- return public.returnJson(False, '移动文件或目录失败!')
+ return mw.returnJson(False, '移动文件或目录失败!')
def deleteApi(self):
path = request.form.get('path', '').encode('utf-8')
@@ -90,12 +90,12 @@ class files_api:
def fileAccessApi(self):
filename = request.form.get('filename', '').encode('utf-8')
data = self.getAccess(filename)
- return public.getJson(data)
+ return mw.getJson(data)
def setFileAccessApi(self):
- if public.isAppleSystem():
- return public.returnJson(True, '开发机不设置!')
+ if mw.isAppleSystem():
+ return mw.returnJson(True, '开发机不设置!')
filename = request.form.get('filename', '').encode('utf-8')
user = request.form.get('user', '').encode('utf-8')
@@ -103,30 +103,30 @@ class files_api:
sall = '-R'
try:
if not self.checkDir(filename):
- return public.returnJson(False, '请不要花样作死')
+ return mw.returnJson(False, '请不要花样作死')
if not os.path.exists(filename):
- return public.returnJson(False, '指定文件不存在!')
+ return mw.returnJson(False, '指定文件不存在!')
os.system('chmod ' + sall + ' ' + access + " '" + filename + "'")
os.system('chown ' + sall + ' ' + user +
':' + user + " '" + filename + "'")
- msg = public.getInfo(
+ msg = mw.getInfo(
'设置[{1}]权限为[{2}]所有者为[{3}]', (filename, access, user,))
- public.writeLog('文件管理', msg)
- return public.returnJson(True, '设置成功!')
+ mw.writeLog('文件管理', msg)
+ return mw.returnJson(True, '设置成功!')
except:
- return public.returnJson(False, '设置失败!')
+ return mw.returnJson(False, '设置失败!')
def getDirSizeApi(self):
path = request.form.get('path', '').encode('utf-8')
tmp = self.getDirSize(path)
- return public.returnJson(True, tmp[0].split()[0])
+ return mw.returnJson(True, tmp[0].split()[0])
def getDirApi(self):
path = request.form.get('path', '').encode('utf-8')
if not os.path.exists(path):
- path = public.getRootDir() + "/wwwroot"
+ path = mw.getRootDir() + "/wwwroot"
search = request.args.get('search', '').strip().lower()
page = request.args.get('p', '1').strip().lower()
row = request.args.get('showRow', '10')
@@ -140,35 +140,35 @@ class files_api:
file = request.form.get('path', '').encode('utf-8')
try:
if not self.checkFileName(file):
- return public.returnJson(False, '文件名中不能包含特殊字符!')
+ return mw.returnJson(False, '文件名中不能包含特殊字符!')
if os.path.exists(file):
- return public.returnJson(False, '指定文件已存在!')
+ return mw.returnJson(False, '指定文件已存在!')
_path = os.path.dirname(file)
if not os.path.exists(_path):
os.makedirs(_path)
open(file, 'w+').close()
self.setFileAccept(file)
- msg = public.getInfo('创建文件[{1}]成功!', (file,))
- public.writeLog('文件管理', msg)
- return public.returnJson(True, '文件创建成功!')
+ msg = mw.getInfo('创建文件[{1}]成功!', (file,))
+ mw.writeLog('文件管理', msg)
+ return mw.returnJson(True, '文件创建成功!')
except Exception as e:
# print str(e)
- return public.returnJson(True, '文件创建失败!')
+ return mw.returnJson(True, '文件创建失败!')
def createDirApi(self):
path = request.form.get('path', '').encode('utf-8')
try:
if not self.checkFileName(path):
- return public.returnJson(False, '目录名中不能包含特殊字符!')
+ return mw.returnJson(False, '目录名中不能包含特殊字符!')
if os.path.exists(path):
- return public.returnJson(False, '指定目录已存在!')
+ return mw.returnJson(False, '指定目录已存在!')
os.makedirs(path)
self.setFileAccept(path)
- msg = public.getInfo('创建目录[{1}]成功!', (path,))
- public.writeLog('文件管理', msg)
- return public.returnJson(True, '目录创建成功!')
+ msg = mw.getInfo('创建目录[{1}]成功!', (path,))
+ mw.writeLog('文件管理', msg)
+ return mw.returnJson(True, '目录创建成功!')
except Exception as e:
- return public.returnJson(False, '目录创建失败!')
+ return mw.returnJson(False, '目录创建失败!')
def downloadFileApi(self):
import db
@@ -177,20 +177,20 @@ class files_api:
path = request.form.get('path', '').encode('utf-8')
filename = request.form.get('filename', '').encode('utf-8')
- isTask = public.getRootDir() + '/tmp/panelTask.pl'
+ isTask = mw.getRootDir() + '/tmp/panelTask.pl'
execstr = url + '|mw|' + path + '/' + filename
- public.M('tasks').add('name,type,status,addtime,execstr',
- ('下载文件[' + filename + ']', 'download', '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr))
- public.writeFile(isTask, 'True')
+ mw.M('tasks').add('name,type,status,addtime,execstr',
+ ('下载文件[' + filename + ']', 'download', '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr))
+ mw.writeFile(isTask, 'True')
# self.setFileAccept(path + '/' + filename)
- return public.returnJson(True, '已将下载任务添加到队列!')
+ return mw.returnJson(True, '已将下载任务添加到队列!')
def removeTaskApi(self):
mid = request.form.get('id', '').encode('utf-8')
try:
- name = public.M('tasks').where('id=?', (mid,)).getField('name')
- status = public.M('tasks').where('id=?', (mid,)).getField('status')
- public.M('tasks').delete(mid)
+ name = mw.M('tasks').where('id=?', (mid,)).getField('name')
+ status = mw.M('tasks').where('id=?', (mid,)).getField('status')
+ mw.M('tasks').delete(mid)
if status == '-1':
os.system(
"kill `ps -ef |grep 'python panelSafe.pyc'|grep -v grep|grep -v panelExec|awk '{print $2}'`")
@@ -208,12 +208,12 @@ done
os.system(
'rm -f ' + name.replace('扫描目录[', '').replace(']', '') + '/scan.pl')
- isTask = public.getRootDir() + '/tmp/panelTask.pl'
- public.writeFile(isTask, 'True')
+ isTask = mw.getRootDir() + '/tmp/panelTask.pl'
+ mw.writeFile(isTask, 'True')
os.system('/etc/init.d/mw start')
except:
os.system('/etc/init.d/mw start')
- return public.returnJson(True, '任务已删除!')
+ return mw.returnJson(True, '任务已删除!')
# 上传文件
def uploadFileApi(self):
@@ -236,9 +236,9 @@ done
os.chown(filename, p_stat.st_uid, p_stat.st_gid)
os.chmod(filename, p_stat.st_mode)
- msg = public.getInfo('上传文件[{1}] 到 [{2}]成功!', (filename, path))
- public.writeLog('文件管理', msg)
- return public.returnMsg(True, '上传成功!')
+ msg = mw.getInfo('上传文件[{1}] 到 [{2}]成功!', (filename, path))
+ mw.writeLog('文件管理', msg)
+ return mw.returnMsg(True, '上传成功!')
def getRecycleBinApi(self):
rPath = self.rPath
@@ -274,7 +274,7 @@ done
data['files'].append(tmp)
except:
continue
- return public.returnJson(True, 'OK', data)
+ return mw.returnJson(True, 'OK', data)
# 回收站开关
def recycleBinApi(self):
@@ -284,12 +284,12 @@ done
c = 'data/recycle_bin_db.pl'
if os.path.exists(c):
os.remove(c)
- public.writeLog('文件管理', '已关闭回收站功能!')
- return public.returnJson(True, '已关闭回收站功能!')
+ mw.writeLog('文件管理', '已关闭回收站功能!')
+ return mw.returnJson(True, '已关闭回收站功能!')
else:
- public.writeFile(c, 'True')
- public.writeLog('文件管理', '已开启回收站功能!')
- return public.returnJson(True, '已开启回收站功能!')
+ mw.writeFile(c, 'True')
+ mw.writeLog('文件管理', '已开启回收站功能!')
+ return mw.returnJson(True, '已开启回收站功能!')
def reRecycleBinApi(self):
rPath = self.rPath
@@ -298,13 +298,13 @@ done
try:
import shutil
shutil.move(rPath + path, dFile)
- msg = public.getInfo('移动文件[{1}]到回收站成功!', (dFile,))
- public.writeLog('文件管理', msg)
- return public.returnJson(True, '恢复成功!')
+ msg = mw.getInfo('移动文件[{1}]到回收站成功!', (dFile,))
+ mw.writeLog('文件管理', msg)
+ return mw.returnJson(True, '恢复成功!')
except Exception as e:
- msg = public.getInfo('从回收站恢复[{1}]失败!', (dFile,))
- public.writeLog('文件管理', msg)
- return public.returnJson(False, '恢复失败!')
+ msg = mw.getInfo('从回收站恢复[{1}]失败!', (dFile,))
+ mw.writeLog('文件管理', msg)
+ return mw.returnJson(False, '恢复失败!')
def delRecycleBinApi(self):
rPath = self.rPath
@@ -313,7 +313,7 @@ done
dFile = path.split('_t_')[0]
if not self.checkDir(path):
- return public.returnJson(False, '敏感目录,请不要花样作死!')
+ return mw.returnJson(False, '敏感目录,请不要花样作死!')
os.system('which chattr && chattr -R -i ' + rPath + path)
if os.path.isdir(rPath + path):
@@ -323,14 +323,14 @@ done
os.remove(rPath + path)
tfile = path.replace('_mw_', '/').split('_t_')[0]
- msg = public.getInfo('已彻底从回收站删除{1}!', (tfile,))
- public.writeLog('文件管理', msg)
- return public.returnJson(True, msg)
+ msg = mw.getInfo('已彻底从回收站删除{1}!', (tfile,))
+ mw.writeLog('文件管理', msg)
+ return mw.returnJson(True, msg)
# 获取进度
def getSpeedApi(self):
- data = public.getSpeed()
- return public.returnJson(True, '已清空回收站!', data)
+ data = mw.getSpeed()
+ return mw.returnJson(True, '已清空回收站!', data)
def closeRecycleBinApi(self):
rPath = self.rPath
@@ -341,19 +341,19 @@ done
for name in rlist:
i += 1
path = rPath + name
- public.writeSpeed(name, i, l)
+ mw.writeSpeed(name, i, l)
if os.path.isdir(path):
shutil.rmtree(path)
else:
os.remove(path)
- public.writeSpeed(None, 0, 0)
- public.writeLog('文件管理', '已清空回收站!')
- return public.returnJson(True, '已清空回收站!')
+ mw.writeSpeed(None, 0, 0)
+ mw.writeLog('文件管理', '已清空回收站!')
+ return mw.returnJson(True, '已清空回收站!')
def deleteDirApi(self):
path = request.form.get('path', '').encode('utf-8')
if not os.path.exists(path):
- return public.returnJson(False, '指定文件不存在!')
+ return mw.returnJson(False, '指定文件不存在!')
# 检查是否为.user.ini
if path.find('.user.ini'):
@@ -361,21 +361,21 @@ done
try:
if os.path.exists('data/recycle_bin.pl'):
if self.mvRecycleBin(path):
- return public.returnJson(True, '已将文件移动到回收站!')
- public.execShell('rm -rf ' + path)
- public.writeLog('文件管理', '删除文件成功!', (path,))
- return public.returnJson(True, '删除文件成功!')
+ return mw.returnJson(True, '已将文件移动到回收站!')
+ mw.execShell('rm -rf ' + path)
+ mw.writeLog('文件管理', '删除文件成功!', (path,))
+ return mw.returnJson(True, '删除文件成功!')
except:
- return public.returnJson(False, '删除文件失败!')
+ return mw.returnJson(False, '删除文件失败!')
def closeLogsApi(self):
- logPath = public.getLogsDir()
+ logPath = mw.getLogsDir()
os.system('rm -f ' + logPath + '/*')
- os.system('kill -USR1 `cat ' + public.getServerDir() +
+ os.system('kill -USR1 `cat ' + mw.getServerDir() +
'openresty/nginx/logs/nginx.pid`')
- public.writeLog('文件管理', '网站日志已被清空!')
+ mw.writeLog('文件管理', '网站日志已被清空!')
tmp = self.getDirSize(logPath)
- return public.returnJson(True, tmp[0].split()[0])
+ return mw.returnJson(True, tmp[0].split()[0])
def setBatchDataApi(self):
path = request.form.get('path', '').encode('utf-8')
@@ -391,21 +391,21 @@ done
'user': user,
'data': data
}
- return public.returnJson(True, '标记成功,请在目标目录点击粘贴所有按钮!')
+ return mw.returnJson(True, '标记成功,请在目标目录点击粘贴所有按钮!')
elif stype == '3':
for key in json.loads(data):
try:
key = key.encode('utf-8')
filename = path + '/' + key
if not self.checkDir(filename):
- return public.returnJson(False, 'FILE_DANGER')
+ return mw.returnJson(False, 'FILE_DANGER')
os.system('chmod -R ' + access + " '" + filename + "'")
os.system('chown -R ' + user + ':' +
user + " '" + filename + "'")
except:
continue
- public.writeLog('文件管理', '批量设置权限成功!')
- return public.returnJson(True, '批量设置权限成功!')
+ mw.writeLog('文件管理', '批量设置权限成功!')
+ return mw.returnJson(True, '批量设置权限成功!')
else:
import shutil
isRecyle = os.path.exists('data/recycle_bin.pl')
@@ -420,10 +420,10 @@ done
continue
i += 1
- public.writeSpeed(key, i, l)
+ mw.writeSpeed(key, i, l)
if os.path.isdir(filename):
if not self.checkDir(filename):
- return public.returnJson(False, '请不要花样作死!')
+ return mw.returnJson(False, '请不要花样作死!')
if isRecyle:
self.mvRecycleBin(topath)
else:
@@ -437,9 +437,9 @@ done
os.remove(filename)
except:
continue
- public.writeSpeed(None, 0, 0)
- public.writeLog('文件管理', '批量删除成功!')
- return public.returnJson(True, '批量删除成功!')
+ mw.writeSpeed(None, 0, 0)
+ mw.writeLog('文件管理', '批量删除成功!')
+ return mw.returnJson(True, '批量删除成功!')
def checkExistsFilesApi(self):
dfile = request.form.get('dfile', '').encode('utf-8')
@@ -464,7 +464,7 @@ done
tmp['size'] = os.path.getsize(filename)
tmp['mtime'] = str(int(stat.st_mtime))
data.append(tmp)
- return public.returnJson(True, 'ok', data)
+ return mw.returnJson(True, 'ok', data)
def batchPasteApi(self):
path = request.form.get('path', '').encode('utf-8')
@@ -472,14 +472,14 @@ done
# filename = request.form.get('filename', '').encode('utf-8')
import shutil
if not self.checkDir(path):
- return public.returnJson(False, '请不要花样作死!')
+ return mw.returnJson(False, '请不要花样作死!')
i = 0
myfiles = json.loads(session['selected']['data'])
l = len(myfiles)
if stype == '1':
for key in myfiles:
i += 1
- public.writeSpeed(key, i, l)
+ mw.writeSpeed(key, i, l)
try:
sfile = session['selected'][
@@ -494,14 +494,14 @@ done
os.chown(dfile, stat.st_uid, stat.st_gid)
except:
continue
- msg = public.getInfo('从[{1}]批量复制到[{2}]成功',
- (session['selected']['path'], path,))
- public.writeLog('文件管理', msg)
+ msg = mw.getInfo('从[{1}]批量复制到[{2}]成功',
+ (session['selected']['path'], path,))
+ mw.writeLog('文件管理', msg)
else:
for key in myfiles:
try:
i += 1
- public.writeSpeed(key, i, l)
+ mw.writeSpeed(key, i, l)
sfile = session['selected'][
'path'] + '/' + key.encode('utf-8')
@@ -510,21 +510,21 @@ done
shutil.move(sfile, dfile)
except:
continue
- msg = public.getInfo('从[{1}]批量移动到[{2}]成功',
- (session['selected']['path'], path,))
- public.writeLog('文件管理', msg)
- public.writeSpeed(None, 0, 0)
+ msg = mw.getInfo('从[{1}]批量移动到[{2}]成功',
+ (session['selected']['path'], path,))
+ mw.writeLog('文件管理', msg)
+ mw.writeSpeed(None, 0, 0)
errorCount = len(myfiles) - i
del(session['selected'])
- msg = public.getInfo('批量操作成功[{1}],失败[{2}]', (str(i), str(errorCount)))
- return public.returnJson(True, msg)
+ msg = mw.getInfo('批量操作成功[{1}],失败[{2}]', (str(i), str(errorCount)))
+ return mw.returnJson(True, msg)
def copyFileApi(self):
sfile = request.form.get('sfile', '').encode('utf-8')
dfile = request.form.get('dfile', '').encode('utf-8')
if not os.path.exists(sfile):
- return public.returnJson(False, '指定文件不存在!')
+ return mw.returnJson(False, '指定文件不存在!')
if os.path.isdir(sfile):
return self.copyDir(sfile, dfile)
@@ -532,33 +532,33 @@ done
import shutil
try:
shutil.copyfile(sfile, dfile)
- msg = public.getInfo('复制文件[{1}]到[{2}]成功!', (sfile, dfile,))
- public.writeLog('文件管理', msg)
+ msg = mw.getInfo('复制文件[{1}]到[{2}]成功!', (sfile, dfile,))
+ mw.writeLog('文件管理', msg)
stat = os.stat(sfile)
os.chown(dfile, stat.st_uid, stat.st_gid)
- return public.returnJson(True, '文件复制成功!')
+ return mw.returnJson(True, '文件复制成功!')
except:
- return public.returnJson(False, '文件复制失败!')
+ return mw.returnJson(False, '文件复制失败!')
##### ----- end ----- ###
def copyDir(self, sfile, dfile):
if not os.path.exists(sfile):
- return public.returnJson(False, '指定目录不存在!')
+ return mw.returnJson(False, '指定目录不存在!')
if os.path.exists(dfile):
- return public.returnJson(False, '指定目录已存在!')
+ return mw.returnJson(False, '指定目录已存在!')
import shutil
try:
shutil.copytree(sfile, dfile)
stat = os.stat(sfile)
os.chown(dfile, stat.st_uid, stat.st_gid)
- msg = public.getInfo('复制目录[{1}]到[{2}]成功!', (sfile, dfile))
- public.writeLog('文件管理', msg)
- return public.returnJson(True, '目录复制成功!')
+ msg = mw.getInfo('复制目录[{1}]到[{2}]成功!', (sfile, dfile))
+ mw.writeLog('文件管理', msg)
+ return mw.returnJson(True, '目录复制成功!')
except:
- return public.returnJson(False, '目录复制失败!')
+ return mw.returnJson(False, '目录复制失败!')
# 检查敏感目录
def checkDir(self, path):
@@ -590,15 +590,15 @@ done
'/selinux',
'/www/server',
'/www/server/data',
- public.getRootDir())
+ mw.getRootDir())
return not path in nDirs
def getDirSize(self, path):
- if public.getOs() == 'darwin':
- tmp = public.execShell('du -sh ' + path)
+ if mw.getOs() == 'darwin':
+ tmp = mw.execShell('du -sh ' + path)
else:
- tmp = public.execShell('du -sbh ' + path)
+ tmp = mw.execShell('du -sbh ' + path)
return tmp
def checkFileName(self, filename):
@@ -613,8 +613,8 @@ done
def setFileAccept(self, filename):
auth = 'www:www'
- if public.getOs() == 'darwin':
- user = public.execShell(
+ if mw.getOs() == 'darwin':
+ user = mw.execShell(
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
auth = user + ':staff'
os.system('chown -R ' + auth + ' ' + filename)
@@ -630,20 +630,20 @@ done
try:
import shutil
shutil.move(path, rFile)
- public.writeLog('文件管理', public.getInfo(
+ mw.writeLog('文件管理', mw.getInfo(
'移动文件[{1}]到回收站成功!', (path)))
return True
except:
- public.writeLog('文件管理', public.getInfo(
+ mw.writeLog('文件管理', mw.getInfo(
'移动文件[{1}]到回收站失败!', (path)))
return False
def getBody(self, path):
if not os.path.exists(path):
- return public.returnJson(False, '文件不存在', (path,))
+ return mw.returnJson(False, '文件不存在', (path,))
if os.path.getsize(path) > 2097152:
- return public.returnJson(False, u'不能在线编辑大于2MB的文件!')
+ return mw.returnJson(False, u'不能在线编辑大于2MB的文件!')
fp = open(path, 'rb')
data = {}
@@ -690,13 +690,13 @@ done
data['data'] = srcBody.decode('utf-8')
data['encoding'] = u'utf-8'
- return public.returnJson(True, 'OK', data)
+ return mw.returnJson(True, 'OK', data)
except Exception as ex:
- return public.returnJson(False, u'文件编码不被兼容,无法正确读取文件!' + str(ex))
+ return mw.returnJson(False, u'文件编码不被兼容,无法正确读取文件!' + str(ex))
def saveBody(self, path, data, encoding='utf-8'):
if not os.path.exists(path):
- return public.returnJson(False, '文件不存在')
+ return mw.returnJson(False, '文件不存在')
try:
if encoding == 'ascii':
encoding = 'utf-8'
@@ -710,18 +710,18 @@ done
fp.write(data)
fp.close()
- public.writeLog('文件管理', '文件保存成功', (path,))
- return public.returnJson(True, '文件保存成功')
+ mw.writeLog('文件管理', '文件保存成功', (path,))
+ return mw.returnJson(True, '文件保存成功')
except Exception as ex:
- return public.returnJson(False, 'FILE_SAVE_ERR:' + str(ex))
+ return mw.returnJson(False, 'FILE_SAVE_ERR:' + str(ex))
def zip(self, sfile, dfile, stype, path):
if sfile.find(',') == -1:
if not os.path.exists(path + '/' + sfile):
- return public.returnMsg(False, '指定文件不存在!')
+ return mw.returnMsg(False, '指定文件不存在!')
try:
- tmps = public.getRunDir() + '/tmp/panelExec.log'
+ tmps = mw.getRunDir() + '/tmp/panelExec.log'
if stype == 'zip':
os.system("cd '" + path + "' && zip '" + dfile +
"' -r '" + sfile + "' > " + tmps + " 2>&1")
@@ -734,15 +734,15 @@ done
os.system("cd '" + path + "' && tar -zcvf '" +
dfile + "' " + sfiles + " > " + tmps + " 2>&1")
self.setFileAccept(dfile)
- public.writeLog("文件管理", '文件压缩成功!', (sfile, dfile))
- return public.returnJson(True, '文件压缩成功!')
+ mw.writeLog("文件管理", '文件压缩成功!', (sfile, dfile))
+ return mw.returnJson(True, '文件压缩成功!')
except:
- return public.returnJson(False, '文件压缩失败!')
+ return mw.returnJson(False, '文件压缩失败!')
def delete(self, path):
if not os.path.exists(path):
- return public.returnJson(False, '指定文件不存在!')
+ return mw.returnJson(False, '指定文件不存在!')
# 检查是否为.user.ini
if path.find('.user.ini') >= 0:
@@ -751,13 +751,13 @@ done
try:
if os.path.exists('data/recycle_bin.pl'):
if self.mvRecycleBin(path):
- return public.returnJson(True, '已将文件移动到回收站!')
+ return mw.returnJson(True, '已将文件移动到回收站!')
os.remove(path)
- public.writeLog('文件管理', public.getInfo(
+ mw.writeLog('文件管理', mw.getInfo(
'删除文件[{1}]成功!', (path)))
- return public.returnJson(True, '删除文件成功!')
+ return mw.returnJson(True, '删除文件成功!')
except:
- return public.returnJson(False, '删除文件失败!')
+ return mw.returnJson(False, '删除文件失败!')
def getAccess(self, filename):
data = {}
@@ -792,7 +792,7 @@ done
info['row'] = page_size
info['p'] = page
info['tojs'] = 'getFiles'
- pageObj = public.getPageObject(info, '1,2,3,4,5,6,7,8')
+ pageObj = mw.getPageObject(info, '1,2,3,4,5,6,7,8')
data['PAGE'] = pageObj[0]
i = 0
@@ -840,4 +840,4 @@ done
data['DIR'] = sorted(dirnames)
data['FILES'] = sorted(filenames)
data['PATH'] = path.replace('//', '/')
- return public.getJson(data)
+ return mw.getJson(data)
diff --git a/class/core/firewall_api.py b/class/core/firewall_api.py
index a232b7e59..4d072c4a0 100755
--- a/class/core/firewall_api.py
+++ b/class/core/firewall_api.py
@@ -4,7 +4,7 @@ import psutil
import time
import os
import sys
-import public
+import mw
import re
import json
import pwd
@@ -23,7 +23,7 @@ class firewall_api:
self.__isFirewalld = True
if os.path.exists('/usr/sbin/ufw'):
self.__isUfw = True
- if public.isAppleSystem():
+ if mw.isAppleSystem():
self.__isMac = True
##### ----- start ----- ###
@@ -35,27 +35,27 @@ class firewall_api:
rep = "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\/\d{1,2})?$"
if not re.search(rep, port):
- return public.returnJson(False, '您输入的IP地址不合法!')
+ return mw.returnJson(False, '您输入的IP地址不合法!')
address = port
- if public.M('firewall').where("port=?", (address,)).count() > 0:
- return public.returnJson(False, '您要放屏蔽的IP已存在屏蔽列表,无需重复处理!')
+ if mw.M('firewall').where("port=?", (address,)).count() > 0:
+ return mw.returnJson(False, '您要放屏蔽的IP已存在屏蔽列表,无需重复处理!')
if self.__isUfw:
- public.execShell('ufw deny from ' + address + ' to any')
+ mw.execShell('ufw deny from ' + address + ' to any')
else:
if self.__isFirewalld:
cmd = 'firewall-cmd --permanent --add-rich-rule=\'rule family=ipv4 source address="' + \
address + '" drop\''
- public.execShell(cmd)
+ mw.execShell(cmd)
else:
cmd = 'iptables -I INPUT -s ' + address + ' -j DROP'
- public.execShell(cmd)
+ mw.execShell(cmd)
- msg = public.getInfo('屏蔽IP[{1}]成功!', (address,))
- public.writeLog("防火墙管理", msg)
+ msg = mw.getInfo('屏蔽IP[{1}]成功!', (address,))
+ mw.writeLog("防火墙管理", msg)
addtime = time.strftime('%Y-%m-%d %X', time.localtime())
- public.M('firewall').add('port,ps,addtime', (address, ps, addtime))
+ mw.M('firewall').add('port,ps,addtime', (address, ps, addtime))
self.firewallReload()
- return public.returnJson(True, '添加成功!')
+ return mw.returnJson(True, '添加成功!')
# 添加放行端口
def addAcceptPortApi(self):
@@ -67,19 +67,19 @@ class firewall_api:
rep = "^\d{1,5}(:\d{1,5})?$"
if not re.search(rep, port):
- return public.returnJson(False, '端口范围不正确!')
+ return mw.returnJson(False, '端口范围不正确!')
- if public.M('firewall').where("port=?", (port,)).count() > 0:
- return public.returnJson(False, '您要放行的端口已存在,无需重复放行!')
+ if mw.M('firewall').where("port=?", (port,)).count() > 0:
+ return mw.returnJson(False, '您要放行的端口已存在,无需重复放行!')
- msg = public.getInfo('放行端口[{1}]成功', (port,))
- public.writeLog("防火墙管理", msg)
+ msg = mw.getInfo('放行端口[{1}]成功', (port,))
+ mw.writeLog("防火墙管理", msg)
addtime = time.strftime('%Y-%m-%d %X', time.localtime())
- public.M('firewall').add('port,ps,addtime', (port, ps, addtime))
+ mw.M('firewall').add('port,ps,addtime', (port, ps, addtime))
self.addAcceptPort(port)
self.firewallReload()
- return public.returnJson(True, '添加放行(' + port + ')端口成功!')
+ return mw.returnJson(True, '添加放行(' + port + ')端口成功!')
# 删除IP屏蔽
def delDropAddressApi(self):
@@ -88,55 +88,55 @@ class firewall_api:
sid = request.form.get('id', '').strip()
address = port
if self.__isUfw:
- public.execShell('ufw delete deny from ' + address + ' to any')
+ mw.execShell('ufw delete deny from ' + address + ' to any')
else:
if self.__isFirewalld:
- public.execShell(
+ mw.execShell(
'firewall-cmd --permanent --remove-rich-rule=\'rule family=ipv4 source address="' + address + '" drop\'')
elif self.__isMac:
pass
else:
cmd = 'iptables -D INPUT -s ' + address + ' -j DROP'
- public.execShell(cmd)
+ mw.execShell(cmd)
- msg = public.getInfo('解除IP[{1}]的屏蔽!', (address,))
- public.writeLog("防火墙管理", msg)
- public.M('firewall').where("id=?", (sid,)).delete()
+ msg = mw.getInfo('解除IP[{1}]的屏蔽!', (address,))
+ mw.writeLog("防火墙管理", msg)
+ mw.M('firewall').where("id=?", (sid,)).delete()
self.firewallReload()
- return public.returnJson(True, '删除成功!')
+ return mw.returnJson(True, '删除成功!')
# 删除放行端口
def delAcceptPortApi(self):
port = request.form.get('port', '').strip()
sid = request.form.get('id', '').strip()
- mw_port = public.readFile('data/port.pl')
+ mw_port = mw.readFile('data/port.pl')
try:
if(port == mw_port):
- return public.returnJson(False, '失败,不能删除当前面板端口!')
+ return mw.returnJson(False, '失败,不能删除当前面板端口!')
if self.__isUfw:
- public.execShell('ufw delete allow ' + port + '/tcp')
+ mw.execShell('ufw delete allow ' + port + '/tcp')
else:
if self.__isFirewalld:
- public.execShell(
- 'firewall-cmd --permanent --zone=public --remove-port=' + port + '/tcp')
- public.execShell(
- 'firewall-cmd --permanent --zone=public --remove-port=' + port + '/udp')
+ mw.execShell(
+ 'firewall-cmd --permanent --zone=mw --remove-port=' + port + '/tcp')
+ mw.execShell(
+ 'firewall-cmd --permanent --zone=mw --remove-port=' + port + '/udp')
else:
- public.execShell(
+ mw.execShell(
'iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT')
- msg = public.getInfo('删除防火墙放行端口[{1}]成功!', (port,))
- public.writeLog("防火墙管理", msg)
- public.M('firewall').where("id=?", (sid,)).delete()
+ msg = mw.getInfo('删除防火墙放行端口[{1}]成功!', (port,))
+ mw.writeLog("防火墙管理", msg)
+ mw.M('firewall').where("id=?", (sid,)).delete()
self.firewallReload()
- return public.returnJson(True, '删除成功!')
+ return mw.returnJson(True, '删除成功!')
except Exception as e:
- return public.returnJson(False, '删除失败!:' + str(e))
+ return mw.returnJson(False, '删除失败!:' + str(e))
def getWwwPathApi(self):
- path = public.getLogsDir()
- return public.getJson({'path': path})
+ path = mw.getLogsDir()
+ return mw.getJson({'path': path})
def getListApi(self):
p = request.form.get('p', '1').strip()
@@ -151,17 +151,17 @@ class firewall_api:
def getSshInfoApi(self):
file = '/etc/ssh/sshd_config'
- conf = public.readFile(file)
+ conf = mw.readFile(file)
rep = "#*Port\s+([0-9]+)\s*\n"
port = re.search(rep, conf).groups(0)[0]
isPing = True
try:
- if public.isAppleSystem():
+ if mw.isAppleSystem():
isPing = True
else:
file = '/etc/sysctl.conf'
- conf = public.readFile(file)
+ conf = mw.readFile(file)
rep = "#*net\.ipv4\.icmp_echo_ignore_all\s*=\s*([0-9]+)"
tmp = re.search(rep, conf).groups(0)[0]
if tmp == '1':
@@ -175,17 +175,17 @@ class firewall_api:
if os.path.exists('/usr/bin/apt-get'):
if os.path.exists('/etc/init.d/sshd'):
cmd = "service sshd status | grep -P '(dead|stop)'|grep -v grep"
- status = public.execShell(cmd)
+ status = mw.execShell(cmd)
else:
cmd = "service ssh status | grep -P '(dead|stop)'|grep -v grep"
- status = public.execShell(cmd)
+ status = mw.execShell(cmd)
else:
if version.find(' 7.') != -1:
cmd = "systemctl status sshd.service | grep 'dead'|grep -v grep"
- status = public.execShell(cmd)
+ status = mw.execShell(cmd)
else:
cmd = "/etc/init.d/sshd status | grep -e 'stopped' -e '已停'|grep -v grep"
- status = public.execShell(cmd)
+ status = mw.execShell(cmd)
if len(status[0]) > 3:
status = False
else:
@@ -196,54 +196,54 @@ class firewall_api:
data['status'] = status
data['ping'] = isPing
- if public.isAppleSystem():
+ if mw.isAppleSystem():
data['firewall_status'] = False
else:
data['firewall_status'] = self.getFwStatus()
- return public.getJson(data)
+ return mw.getJson(data)
def setSshPortApi(self):
port = request.form.get('port', '1').strip()
if int(port) < 22 or int(port) > 65535:
- return public.returnJson(False, '端口范围必需在22-65535之间!')
+ return mw.returnJson(False, '端口范围必需在22-65535之间!')
ports = ['21', '25', '80', '443', '7200', '8080', '888', '8888']
if port in ports:
- return public.returnJson(False, '(' + port + ')' + '特殊端口不可设置!')
+ return mw.returnJson(False, '(' + port + ')' + '特殊端口不可设置!')
file = '/etc/ssh/sshd_config'
- conf = public.readFile(file)
+ conf = mw.readFile(file)
rep = "#*Port\s+([0-9]+)\s*\n"
conf = re.sub(rep, "Port " + port + "\n", conf)
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
if self.__isFirewalld:
- public.execShell('setenforce 0')
- public.execShell(
+ mw.execShell('setenforce 0')
+ mw.execShell(
'sed -i "s#SELINUX=enforcing#SELINUX=disabled#" /etc/selinux/config')
- public.execShell("systemctl restart sshd.service")
+ mw.execShell("systemctl restart sshd.service")
elif self.__isUfw:
- public.execShell('ufw allow ' + port + '/tcp')
- public.execShell("service ssh restart")
+ mw.execShell('ufw allow ' + port + '/tcp')
+ mw.execShell("service ssh restart")
else:
- public.execShell(
+ mw.execShell(
'iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT')
- public.execShell("/etc/init.d/sshd restart")
+ mw.execShell("/etc/init.d/sshd restart")
self.firewallReload()
- # public.M('firewall').where(
+ # mw.M('firewall').where(
# "ps=?", ('SSH远程管理服务',)).setField('port', port)
- msg = public.getInfo('改SSH端口为[{1}]成功!', port)
- public.writeLog("防火墙管理", msg)
- return public.returnJson(True, '修改成功!')
+ msg = mw.getInfo('改SSH端口为[{1}]成功!', port)
+ mw.writeLog("防火墙管理", msg)
+ return mw.returnJson(True, '修改成功!')
def setSshStatusApi(self):
- if public.isAppleSystem():
- return public.returnJson(True, '开发机不能操作!')
+ if mw.isAppleSystem():
+ return mw.returnJson(True, '开发机不能操作!')
status = request.form.get('status', '1').strip()
- version = public.readFile('/etc/redhat-release')
+ version = mw.readFile('/etc/redhat-release')
if int(status) == 1:
msg = 'SSH服务已停用'
act = 'stop'
@@ -252,68 +252,68 @@ class firewall_api:
act = 'start'
if not os.path.exists('/etc/redhat-release'):
- public.execShell('service ssh ' + act)
+ mw.execShell('service ssh ' + act)
elif version.find(' 7.') != -1:
- public.execShell("systemctl " + act + " sshd.service")
+ mw.execShell("systemctl " + act + " sshd.service")
else:
- public.execShell("/etc/init.d/sshd " + act)
+ mw.execShell("/etc/init.d/sshd " + act)
- public.writeLog("防火墙管理", msg)
- return public.returnJson(True, '操作成功!')
+ mw.writeLog("防火墙管理", msg)
+ return mw.returnJson(True, '操作成功!')
def setPingApi(self):
- if public.isAppleSystem():
- return public.returnJson(True, '开发机不能操作!')
+ if mw.isAppleSystem():
+ return mw.returnJson(True, '开发机不能操作!')
status = request.form.get('status')
filename = '/etc/sysctl.conf'
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
if conf.find('net.ipv4.icmp_echo') != -1:
rep = u"net\.ipv4\.icmp_echo.*"
conf = re.sub(rep, 'net.ipv4.icmp_echo_ignore_all=' + status, conf)
else:
conf += "\nnet.ipv4.icmp_echo_ignore_all=" + status
- public.writeFile(filename, conf)
- public.execShell('sysctl -p')
- return public.returnJson(True, '设置成功!')
+ mw.writeFile(filename, conf)
+ mw.execShell('sysctl -p')
+ return mw.returnJson(True, '设置成功!')
def setFwApi(self):
- if public.isAppleSystem():
- return public.returnJson(True, '开发机不能设置!')
+ if mw.isAppleSystem():
+ return mw.returnJson(True, '开发机不能设置!')
status = request.form.get('status', '1')
if status == '1':
if self.__isUfw:
- public.execShell('/usr/sbin/ufw stop')
+ mw.execShell('/usr/sbin/ufw stop')
return
if self.__isFirewalld:
- public.execShell('systemctl stop firewalld.service')
- public.execShell('systemctl disable firewalld.service')
+ mw.execShell('systemctl stop firewalld.service')
+ mw.execShell('systemctl disable firewalld.service')
elif self.__isMac:
pass
else:
- public.execShell('/etc/init.d/iptables save')
- public.execShell('/etc/init.d/iptables stop')
+ mw.execShell('/etc/init.d/iptables save')
+ mw.execShell('/etc/init.d/iptables stop')
else:
if self.__isUfw:
- public.execShell('/usr/sbin/ufw start')
+ mw.execShell('/usr/sbin/ufw start')
return
if self.__isFirewalld:
- public.execShell('systemctl start firewalld.service')
- public.execShell('systemctl enable firewalld.service')
+ mw.execShell('systemctl start firewalld.service')
+ mw.execShell('systemctl enable firewalld.service')
elif self.__isMac:
pass
else:
- public.execShell('/etc/init.d/iptables save')
- public.execShell('/etc/init.d/iptables restart')
+ mw.execShell('/etc/init.d/iptables save')
+ mw.execShell('/etc/init.d/iptables restart')
- return public.returnJson(True, '设置成功!')
+ return mw.returnJson(True, '设置成功!')
def delPanelLogsApi(self):
- public.M('logs').where('id>?', (0,)).delete()
- public.writeLog('面板设置', '面板操作日志已清空!')
- return public.returnJson(True, '面板操作日志已清空!')
+ mw.M('logs').where('id>?', (0,)).delete()
+ mw.writeLog('面板设置', '面板操作日志已清空!')
+ return mw.returnJson(True, '面板操作日志已清空!')
##### ----- start ----- ###
@@ -321,19 +321,19 @@ class firewall_api:
start = (page - 1) * limit
- _list = public.M('firewall').field('id,port,ps,addtime').limit(
+ _list = mw.M('firewall').field('id,port,ps,addtime').limit(
str(start) + ',' + str(limit)).order('id desc').select()
data = {}
data['data'] = _list
- count = public.M('firewall').count()
+ count = mw.M('firewall').count()
_page = {}
_page['count'] = count
_page['tojs'] = 'showAccept'
_page['p'] = page
- data['page'] = public.getPage(_page)
- return public.getJson(data)
+ data['page'] = mw.getPage(_page)
+ return mw.getJson(data)
def getLogList(self, page, limit, search=''):
find_search = ''
@@ -343,56 +343,56 @@ class firewall_api:
start = (page - 1) * limit
- _list = public.M('logs').where(find_search, ()).field(
+ _list = mw.M('logs').where(find_search, ()).field(
'id,type,log,addtime').limit(str(start) + ',' + str(limit)).order('id desc').select()
data = {}
data['data'] = _list
- count = public.M('logs').where(find_search, ()).count()
+ count = mw.M('logs').where(find_search, ()).count()
_page = {}
_page['count'] = count
_page['tojs'] = 'getLogs'
_page['p'] = page
- data['page'] = public.getPage(_page)
- return public.getJson(data)
+ data['page'] = mw.getPage(_page)
+ return mw.getJson(data)
def addAcceptPort(self, port):
if self.__isUfw:
- public.execShell('ufw allow ' + port + '/tcp')
+ mw.execShell('ufw allow ' + port + '/tcp')
else:
if self.__isFirewalld:
port = port.replace(':', '-')
- cmd = 'firewall-cmd --permanent --zone=public --add-port=' + port + '/tcp'
- public.execShell(cmd)
+ cmd = 'firewall-cmd --permanent --zone=mw --add-port=' + port + '/tcp'
+ mw.execShell(cmd)
elif self.__isMac:
pass
else:
cmd = 'iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ' + port + ' -j ACCEPT'
- public.execShell(cmd)
+ mw.execShell(cmd)
def firewallReload(self):
if self.__isUfw:
- public.execShell('/usr/sbin/ufw reload')
+ mw.execShell('/usr/sbin/ufw reload')
return
if self.__isFirewalld:
- public.execShell('firewall-cmd --reload')
+ mw.execShell('firewall-cmd --reload')
elif self.__isMac:
pass
else:
- public.execShell('/etc/init.d/iptables save')
- public.execShell('/etc/init.d/iptables restart')
+ mw.execShell('/etc/init.d/iptables save')
+ mw.execShell('/etc/init.d/iptables restart')
def getFwStatus(self):
if self.__isUfw:
cmd = "ps -ef|grep ufw |grep -v grep | awk '{print $2}'"
- data = public.execShell(cmd)
+ data = mw.execShell(cmd)
if data[0] == '':
return False
return True
if self.__isFirewalld:
cmd = "ps -ef|grep firewalld |grep -v grep | awk '{print $2}'"
- data = public.execShell(cmd)
+ data = mw.execShell(cmd)
if data[0] == '':
return False
return True
@@ -400,7 +400,7 @@ class firewall_api:
return False
else:
cmd = "ps -ef|grep iptables |grep -v grep | awk '{print $2}'"
- data = public.execShell(cmd)
+ data = mw.execShell(cmd)
if data[0] == '':
return False
return True
diff --git a/class/core/public.py b/class/core/mw.py
similarity index 100%
rename from class/core/public.py
rename to class/core/mw.py
diff --git a/class/core/page.py b/class/core/page.py
index b85ca370b..18062911b 100755
--- a/class/core/page.py
+++ b/class/core/page.py
@@ -2,7 +2,7 @@
import math
import string
-import public
+import mw
class Page():
@@ -29,7 +29,7 @@ class Page():
__END_NUM = None # 结束行
def __init__(self):
- # tmp = public.getMsg('PAGE')
+ # tmp = mw.getMsg('PAGE')
if False:
self.__PREV = tmp['PREV']
self.__NEXT = tmp['NEXT']
diff --git a/class/core/plugins_api.py b/class/core/plugins_api.py
index 38d3f9eb7..f54d05226 100755
--- a/class/core/plugins_api.py
+++ b/class/core/plugins_api.py
@@ -3,7 +3,7 @@
import psutil
import time
import os
-import public
+import mw
import re
import json
@@ -50,7 +50,7 @@ class plugins_api:
sPage = request.args.get('p', '1')
# print sPage
data = self.getPluginList(sType, int(sPage))
- return public.getJson(data)
+ return mw.getJson(data)
def fileApi(self):
name = request.args.get('name', '')
@@ -65,24 +65,24 @@ class plugins_api:
if not os.path.exists(file):
return ''
- c = public.readFile(file)
+ c = mw.readFile(file)
return c
def indexListApi(self):
data = self.getIndexList()
- return public.getJson(data)
+ return mw.getJson(data)
def indexSortApi(self):
sort = request.form.get('ssort', '')
if sort.strip() == '':
- return public.returnJson(False, '排序数据不能为空!')
+ return mw.returnJson(False, '排序数据不能为空!')
data = self.setIndexSort(sort)
if data:
- return public.returnJson(True, '成功!')
- return public.returnJson(False, '失败!')
+ return mw.returnJson(True, '成功!')
+ return mw.returnJson(False, '失败!')
def installApi(self):
- rundir = public.getRunDir()
+ rundir = mw.getRunDir()
name = request.form.get('name', '')
version = request.form.get('version', '')
@@ -92,18 +92,18 @@ class plugins_api:
mmsg = 'upgrade'
if name.strip() == '':
- return public.returnJson(False, '缺少插件名称!', ())
+ return mw.returnJson(False, '缺少插件名称!', ())
if version.strip() == '':
- return public.returnJson(False, '缺少版本信息!', ())
+ return mw.returnJson(False, '缺少版本信息!', ())
infoJsonPos = self.__plugin_dir + '/' + name + '/' + 'info.json'
# print infoJsonPos
if not os.path.exists(infoJsonPos):
- return public.returnJson(False, '配置文件不存在!', ())
+ return mw.returnJson(False, '配置文件不存在!', ())
- pluginInfo = json.loads(public.readFile(infoJsonPos))
+ pluginInfo = json.loads(mw.readFile(infoJsonPos))
execstr = "cd " + os.getcwd() + "/plugins/" + \
name + " && /bin/bash " + pluginInfo["shell"] \
@@ -112,25 +112,25 @@ class plugins_api:
taskAdd = (None, mmsg + '[' + name + '-' + version + ']',
'execshell', '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr)
- public.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd)
- return public.returnJson(True, '已将安装任务添加到队列!')
+ mw.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd)
+ return mw.returnJson(True, '已将安装任务添加到队列!')
def uninstallOldApi(self):
- rundir = public.getRunDir()
+ rundir = mw.getRunDir()
name = request.form.get('name', '')
version = request.form.get('version', '')
if name.strip() == '':
- return public.returnJson(False, "缺少插件名称!", ())
+ return mw.returnJson(False, "缺少插件名称!", ())
if version.strip() == '':
- return public.returnJson(False, "缺少版本信息!", ())
+ return mw.returnJson(False, "缺少版本信息!", ())
infoJsonPos = self.__plugin_dir + '/' + name + '/' + 'info.json'
if not os.path.exists(infoJsonPos):
- return public.returnJson(False, "配置文件不存在!", ())
+ return mw.returnJson(False, "配置文件不存在!", ())
- pluginInfo = json.loads(public.readFile(infoJsonPos))
+ pluginInfo = json.loads(mw.readFile(infoJsonPos))
execstr = "cd " + os.getcwd() + "/plugins/" + \
name + " && /bin/bash " + pluginInfo["shell"] \
@@ -139,50 +139,50 @@ class plugins_api:
taskAdd = (None, '卸载[' + name + '-' + version + ']',
'execshell', '0', time.strftime('%Y-%m-%d %H:%M:%S'), execstr)
- public.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd)
- return public.returnJson(True, '已将卸载任务添加到队列!')
+ mw.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd)
+ return mw.returnJson(True, '已将卸载任务添加到队列!')
# 卸载时间短,不加入任务中...
def uninstallApi(self):
- rundir = public.getRunDir()
+ rundir = mw.getRunDir()
name = request.form.get('name', '')
version = request.form.get('version', '')
if name.strip() == '':
- return public.returnJson(False, "缺少插件名称!", ())
+ return mw.returnJson(False, "缺少插件名称!", ())
if version.strip() == '':
- return public.returnJson(False, "缺少版本信息!", ())
+ return mw.returnJson(False, "缺少版本信息!", ())
infoJsonPos = self.__plugin_dir + '/' + name + '/' + 'info.json'
if not os.path.exists(infoJsonPos):
- return public.returnJson(False, "配置文件不存在!", ())
+ return mw.returnJson(False, "配置文件不存在!", ())
- pluginInfo = json.loads(public.readFile(infoJsonPos))
+ pluginInfo = json.loads(mw.readFile(infoJsonPos))
execstr = "cd " + os.getcwd() + "/plugins/" + \
name + " && /bin/bash " + pluginInfo["shell"] \
+ " uninstall " + version
- data = public.execShell(execstr)
- if public.isAppleSystem():
+ data = mw.execShell(execstr)
+ if mw.isAppleSystem():
print execstr
print data[0], data[1]
- return public.returnJson(True, '卸载执行成功!')
+ return mw.returnJson(True, '卸载执行成功!')
# if data[1] == '':
- # return public.returnJson(True, '已将卸载成功!')
+ # return mw.returnJson(True, '已将卸载成功!')
# else:
- # return public.returnJson(False, '卸载出现错误信息!' + data[1])
+ # return mw.returnJson(False, '卸载出现错误信息!' + data[1])
def checkApi(self):
name = request.form.get('name', '')
if name.strip() == '':
- return public.returnJson(False, "缺少插件名称!", ())
+ return mw.returnJson(False, "缺少插件名称!", ())
infoJsonPos = self.__plugin_dir + '/' + name + '/' + 'info.json'
if not os.path.exists(infoJsonPos):
- return public.returnJson(False, "配置文件不存在!", ())
- return public.returnJson(True, "插件存在!", ())
+ return mw.returnJson(False, "配置文件不存在!", ())
+ return mw.returnJson(True, "插件存在!", ())
def setIndexApi(self):
name = request.form.get('name', '')
@@ -195,7 +195,7 @@ class plugins_api:
def settingApi(self):
name = request.args.get('name', '')
html = self.__plugin_dir + '/' + name + '/index.html'
- return public.readFile(html)
+ return mw.readFile(html)
def runApi(self):
name = request.form.get('name', '')
@@ -206,8 +206,8 @@ class plugins_api:
data = self.run(name, func, version, args, script)
if data[1] == '':
- return public.returnJson(True, "OK", data[0].strip())
- return public.returnJson(False, data[1].strip())
+ return mw.returnJson(True, "OK", data[0].strip())
+ return mw.returnJson(False, data[1].strip())
def callbackApi(self):
name = request.form.get('name', '')
@@ -217,23 +217,23 @@ class plugins_api:
data = self.callback(name, func, args, script)
if data[0]:
- return public.returnJson(True, "OK", data[1])
- return public.returnJson(False, data[1])
+ return mw.returnJson(True, "OK", data[1])
+ return mw.returnJson(False, data[1])
def updateZipApi(self):
- tmp_path = public.getRootDir() + '/temp'
+ tmp_path = mw.getRootDir() + '/temp'
if not os.path.exists(tmp_path):
os.makedirs(tmp_path)
- public.execShell("rm -rf " + tmp_path + '/*')
+ mw.execShell("rm -rf " + tmp_path + '/*')
tmp_file = tmp_path + '/plugin_tmp.zip'
from werkzeug.utils import secure_filename
from flask import request
f = request.files['plugin_zip']
if f.filename[-4:] != '.zip':
- return public.returnJson(False, '仅支持zip文件!')
+ return mw.returnJson(False, '仅支持zip文件!')
f.save(tmp_file)
- public.execShell('cd ' + tmp_path + ' && unzip ' + tmp_file)
+ mw.execShell('cd ' + tmp_path + ' && unzip ' + tmp_file)
os.remove(tmp_file)
p_info = tmp_path + '/info.json'
@@ -253,47 +253,47 @@ class plugins_api:
tmp_path = d_path
p_info = tmp_path + '/info.json'
try:
- data = json.loads(public.readFile(p_info))
- data['size'] = public.getPathSize(tmp_path)
+ data = json.loads(mw.readFile(p_info))
+ data['size'] = mw.getPathSize(tmp_path)
if not 'author' in data:
data['author'] = '未知'
if not 'home' in data:
data['home'] = 'https://www.bt.cn/bbs/forum-40-1.html'
- plugin_path = public.getPluginDir() + data['name'] + '/info.json'
+ plugin_path = mw.getPluginDir() + data['name'] + '/info.json'
data['old_version'] = '0'
data['tmp_path'] = tmp_path
if os.path.exists(plugin_path):
try:
- old_info = json.loads(public.ReadFile(plugin_path))
+ old_info = json.loads(mw.ReadFile(plugin_path))
data['old_version'] = old_info['versions']
except:
pass
except:
- public.execShell("rm -rf " + tmp_path)
- return public.returnJson(False, '在压缩包中没有找到插件信息,请检查插件包!')
+ mw.execShell("rm -rf " + tmp_path)
+ return mw.returnJson(False, '在压缩包中没有找到插件信息,请检查插件包!')
protectPlist = ('openresty', 'mysql', 'php', 'csvn', 'gogs', 'pureftp')
if data['name'] in protectPlist:
- return public.returnJson(False, '[' + data['name'] + '],重要插件不可修改!')
- return public.getJson(data)
+ return mw.returnJson(False, '[' + data['name'] + '],重要插件不可修改!')
+ return mw.getJson(data)
def inputZipApi(self):
plugin_name = request.form.get('plugin_name', '')
tmp_path = request.form.get('tmp_path', '')
if not os.path.exists(tmp_path):
- return public.returnJson(False, '临时文件不存在,请重新上传!')
- plugin_path = public.getPluginDir() + '/' + plugin_name
+ return mw.returnJson(False, '临时文件不存在,请重新上传!')
+ plugin_path = mw.getPluginDir() + '/' + plugin_name
if not os.path.exists(plugin_path):
- print public.execShell('mkdir -p ' + plugin_path)
- public.execShell("\cp -rf " + tmp_path + '/* ' + plugin_path + '/')
- public.execShell('chmod -R 755 ' + plugin_path)
- p_info = public.readFile(plugin_path + '/info.json')
+ print mw.execShell('mkdir -p ' + plugin_path)
+ mw.execShell("\cp -rf " + tmp_path + '/* ' + plugin_path + '/')
+ mw.execShell('chmod -R 755 ' + plugin_path)
+ p_info = mw.readFile(plugin_path + '/info.json')
if p_info:
- public.writeLog('软件管理', '安装第三方插件[%s]' %
- json.loads(p_info)['title'])
- return public.returnJson(True, '安装成功!')
- public.execShell("rm -rf " + plugin_path)
- return public.returnJson(False, '安装失败!')
+ mw.writeLog('软件管理', '安装第三方插件[%s]' %
+ json.loads(p_info)['title'])
+ return mw.returnJson(True, '安装成功!')
+ mw.execShell("rm -rf " + plugin_path)
+ return mw.returnJson(False, '安装失败!')
##### ----- end ----- ###
# 进程是否存在
@@ -319,11 +319,11 @@ class plugins_api:
# 检查是否正在安装
def checkSetupTask(self, sName, sVer, sCoexist):
if not self.__tasks:
- self.__tasks = public.M('tasks').where(
+ self.__tasks = mw.M('tasks').where(
"status!=?", ('1',)).field('status,name').select()
isTask = '1'
for task in self.__tasks:
- tmpt = public.getStrBetween('[', ']', task['name'])
+ tmpt = mw.getStrBetween('[', ']', task['name'])
if not tmpt:
continue
tmp1 = tmpt.split('-')
@@ -407,9 +407,9 @@ class plugins_api:
def checkDisplayIndex(self, name, version):
if not os.path.exists(self.__index):
- public.writeFile(self.__index, '[]')
+ mw.writeFile(self.__index, '[]')
- indexList = json.loads(public.readFile(self.__index))
+ indexList = json.loads(mw.readFile(self.__index))
if type(version) == list:
for index in range(len(version)):
vname = name + '-' + version[index]
@@ -424,7 +424,7 @@ class plugins_api:
def getVersion(self, path):
version_f = path + '/version.pl'
if os.path.exists(version_f):
- return public.readFile(version_f).strip()
+ return mw.readFile(version_f).strip()
return ''
# 构造本地插件信息
@@ -436,13 +436,13 @@ class plugins_api:
if info["checks"][0:1] == '/':
checks = info["checks"]
else:
- checks = public.getRootDir() + '/' + info['checks']
+ checks = mw.getRootDir() + '/' + info['checks']
if info.has_key('path'):
path = info['path']
if path[0:1] != '/':
- path = public.getRootDir() + '/' + path
+ path = mw.getRootDir() + '/' + path
if info.has_key('coexist') and info['coexist']:
coexist = True
@@ -538,7 +538,7 @@ class plugins_api:
json_file = path + '/info.json'
if os.path.exists(json_file):
try:
- data = json.loads(public.readFile(json_file))
+ data = json.loads(mw.readFile(json_file))
tmp_data = self.makeList(data, sType)
for index in range(len(tmp_data)):
plugins_info.append(tmp_data[index])
@@ -556,7 +556,7 @@ class plugins_api:
json_file = path + '/info.json'
if os.path.exists(json_file):
try:
- data = json.loads(public.readFile(json_file))
+ data = json.loads(mw.readFile(json_file))
tmp_data = self.makeList(data, sType)
for index in range(len(tmp_data)):
plugins_info.append(tmp_data[index])
@@ -606,7 +606,7 @@ class plugins_api:
if os.path.isdir(path):
json_file = path + '/info.json'
if os.path.exists(json_file):
- data = json.loads(public.readFile(json_file))
+ data = json.loads(mw.readFile(json_file))
if sType == '0':
tmp_list.append(data)
@@ -667,7 +667,7 @@ class plugins_api:
if os.path.isdir(path):
json_file = path + '/info.json'
if os.path.exists(json_file):
- data = json.loads(public.readFile(json_file))
+ data = json.loads(mw.readFile(json_file))
if sType == '0':
tmp_list.append(data)
@@ -695,7 +695,7 @@ class plugins_api:
# print sType, sPage, sPageSize
ret = {}
- ret['type'] = json.loads(public.readFile(self.__type))
+ ret['type'] = json.loads(mw.readFile(self.__type))
# plugins_info = self.getAllListThread(sType)
# plugins_info = self.getAllListProcess(sType)
data = self.getAllListPage(sType, sPage, sPageSize)
@@ -707,14 +707,14 @@ class plugins_api:
args['tojs'] = 'getSList'
args['row'] = sPageSize
- ret['list'] = public.getPage(args)
+ ret['list'] = mw.getPage(args)
return ret
def getIndexList(self):
if not os.path.exists(self.__index):
- public.writeFile(self.__index, '[]')
+ mw.writeFile(self.__index, '[]')
- indexList = json.loads(public.readFile(self.__index))
+ indexList = json.loads(mw.readFile(self.__index))
plist = []
app = []
for i in indexList:
@@ -726,7 +726,7 @@ class plugins_api:
json_file = path + '/info.json'
if os.path.exists(json_file):
try:
- data = json.loads(public.readFile(json_file))
+ data = json.loads(mw.readFile(json_file))
tmp_data = self.makeList(data)
for index in range(len(tmp_data)):
if tmp_data[index]['versions'] == info[1] or info[1] in tmp_data[index]['versions']:
@@ -743,40 +743,40 @@ class plugins_api:
def setIndexSort(self, sort):
data = sort.split('|')
- public.writeFile(self.__index, json.dumps(data))
+ mw.writeFile(self.__index, json.dumps(data))
return True
def addIndex(self, name, version):
if not os.path.exists(self.__index):
- public.writeFile(self.__index, '[]')
+ mw.writeFile(self.__index, '[]')
- indexList = json.loads(public.readFile(self.__index))
+ indexList = json.loads(mw.readFile(self.__index))
vname = name + '-' + version
if vname in indexList:
- return public.returnJson(False, '请不要重复添加!')
+ return mw.returnJson(False, '请不要重复添加!')
if len(indexList) >= 12:
- return public.returnJson(False, '首页最多只能显示12个软件!')
+ return mw.returnJson(False, '首页最多只能显示12个软件!')
indexList.append(vname)
- public.writeFile(self.__index, json.dumps(indexList))
- return public.returnJson(True, '添加成功!')
+ mw.writeFile(self.__index, json.dumps(indexList))
+ return mw.returnJson(True, '添加成功!')
def removeIndex(self, name, version):
if not os.path.exists(self.__index):
- public.writeFile(self.__index, '[]')
+ mw.writeFile(self.__index, '[]')
- indexList = json.loads(public.readFile(self.__index))
+ indexList = json.loads(mw.readFile(self.__index))
vname = name + '-' + version
if not vname in indexList:
- return public.returnJson(True, '删除成功!')
+ return mw.returnJson(True, '删除成功!')
indexList.remove(vname)
- public.writeFile(self.__index, json.dumps(indexList))
- return public.returnJson(True, '删除成功!')
+ mw.writeFile(self.__index, json.dumps(indexList))
+ return mw.returnJson(True, '删除成功!')
# shell 调用
def run(self, name, func, version, args='', script='index'):
- path = public.getRunDir() + '/' + self.__plugin_dir + \
+ path = mw.getRunDir() + '/' + self.__plugin_dir + \
'/' + name + '/' + script + '.py'
py = 'python ' + path
@@ -787,24 +787,24 @@ class plugins_api:
if not os.path.exists(path):
return ('', '')
- data = public.execShell(py_cmd)
+ data = mw.execShell(py_cmd)
# data = os.popen(py_cmd).read()
- if public.isAppleSystem():
+ if mw.isAppleSystem():
print 'run', py_cmd
# print os.path.exists(py_cmd)
return (data[0].strip(), data[1].strip())
# 映射包调用
def callback(self, name, func, args='', script='index'):
- package = public.getRunDir() + '/plugins/' + name
+ package = mw.getRunDir() + '/plugins/' + name
if not os.path.exists(package):
return (False, "插件不存在!")
sys.path.append(package)
eval_str = "__import__('" + script + "')." + func + '(' + args + ')'
newRet = eval(eval_str)
- if public.isAppleSystem():
+ if mw.isAppleSystem():
print 'callback', eval_str
return (True, newRet)
diff --git a/class/core/site_api.py b/class/core/site_api.py
index 2371cddcf..7cf40de37 100755
--- a/class/core/site_api.py
+++ b/class/core/site_api.py
@@ -3,7 +3,7 @@
import time
import os
import sys
-import public
+import mw
import re
import json
import pwd
@@ -31,20 +31,20 @@ class site_api:
def __init__(self):
# nginx conf
- self.setupPath = public.getServerDir() + '/web_conf'
+ self.setupPath = mw.getServerDir() + '/web_conf'
self.vhostPath = vh = self.setupPath + '/nginx/vhost'
if not os.path.exists(vh):
- public.execShell("mkdir -p " + vh + " && chmod -R 755 " + vh)
+ mw.execShell("mkdir -p " + vh + " && chmod -R 755 " + vh)
self.rewritePath = rw = self.setupPath + '/nginx/rewrite'
if not os.path.exists(rw):
- public.execShell("mkdir -p " + rw + " && chmod -R 755 " + rw)
+ mw.execShell("mkdir -p " + rw + " && chmod -R 755 " + rw)
self.passPath = self.setupPath + '/nginx/pass'
# if not os.path.exists(pp):
- # public.execShell("mkdir -p " + rw + " && chmod -R 755 " + rw)
+ # mw.execShell("mkdir -p " + rw + " && chmod -R 755 " + rw)
- self.logsPath = public.getRootDir() + '/wwwlogs'
+ self.logsPath = mw.getRootDir() + '/wwwlogs'
# ssl conf
- if public.isAppleSystem():
+ if mw.isAppleSystem():
self.sslDir = self.setupPath + '/letsencrypt/'
else:
self.sslDir = '/etc/letsencrypt/live/'
@@ -57,7 +57,7 @@ class site_api:
start = (int(p) - 1) * (int(limit))
- siteM = public.M('sites')
+ siteM = mw.M('sites')
if type_id != '' and type_id == '-1' and type_id == '0':
siteM.where('type_id=?', (type_id))
@@ -65,7 +65,7 @@ class site_api:
(str(start)) + ',' + limit).order('id desc').select()
for i in range(len(_list)):
- _list[i]['backup_count'] = public.M('backup').where(
+ _list[i]['backup_count'] = mw.M('backup').where(
"pid=? AND type=?", (_list[i]['id'], 0)).count()
_ret = {}
@@ -78,50 +78,50 @@ class site_api:
_page['p'] = p
_page['row'] = limit
- _ret['page'] = public.getPage(_page)
- return public.getJson(_ret)
+ _ret['page'] = mw.getPage(_page)
+ return mw.getJson(_ret)
def setDefaultSiteApi(self):
name = request.form.get('name', '').encode('utf-8')
import time
# 清理旧的
- defaultSite = public.readFile('data/defaultSite.pl')
+ defaultSite = mw.readFile('data/defaultSite.pl')
if defaultSite:
path = self.getHostConf(defaultSite)
if os.path.exists(path):
- conf = public.readFile(path)
+ conf = mw.readFile(path)
rep = "listen\s+80.+;"
conf = re.sub(rep, 'listen 80;', conf, 1)
rep = "listen\s+443.+;"
conf = re.sub(rep, 'listen 443 ssl;', conf, 1)
- public.writeFile(path, conf)
+ mw.writeFile(path, conf)
path = self.getHostConf(name)
if os.path.exists(path):
- conf = public.readFile(path)
+ conf = mw.readFile(path)
rep = "listen\s+80\s*;"
conf = re.sub(rep, 'listen 80 default_server;', conf, 1)
rep = "listen\s+443\s*ssl\s*\w*\s*;"
conf = re.sub(rep, 'listen 443 ssl default_server;', conf, 1)
- public.writeFile(path, conf)
+ mw.writeFile(path, conf)
- public.writeFile('data/defaultSite.pl', name)
- public.restartWeb()
- return public.returnJson(True, '设置成功!')
+ mw.writeFile('data/defaultSite.pl', name)
+ mw.restartWeb()
+ return mw.returnJson(True, '设置成功!')
def getDefaultSiteApi(self):
data = {}
- data['sites'] = public.M('sites').field(
+ data['sites'] = mw.M('sites').field(
'name').order('id desc').select()
- data['defaultSite'] = public.readFile('data/defaultSite.pl')
- return public.getJson(data)
+ data['defaultSite'] = mw.readFile('data/defaultSite.pl')
+ return mw.getJson(data)
def setPsApi(self):
mid = request.form.get('id', '').encode('utf-8')
ps = request.form.get('ps', '').encode('utf-8')
- if public.M('sites').where("id=?", (mid,)).setField('ps', ps):
- return public.returnJson(True, '修改成功!')
- return public.returnJson(False, '修改失败!')
+ if mw.M('sites').where("id=?", (mid,)).setField('ps', ps):
+ return mw.returnJson(True, '修改成功!')
+ return mw.returnJson(False, '修改失败!')
def stopApi(self):
mid = request.form.get('id', '').encode('utf-8')
@@ -130,114 +130,114 @@ class site_api:
if not os.path.exists(path):
os.makedirs(path)
- public.writeFile(path + '/index.html',
- 'The website has been closed!!!')
+ mw.writeFile(path + '/index.html',
+ 'The website has been closed!!!')
- binding = public.M('binding').where('pid=?', (mid,)).field(
+ binding = mw.M('binding').where('pid=?', (mid,)).field(
'id,pid,domain,path,port,addtime').select()
for b in binding:
bpath = path + '/' + b['path']
if not os.path.exists(bpath):
- public.execShell('mkdir -p ' + bpath)
- public.execShell('ln -sf ' + path +
- '/index.html ' + bpath + '/index.html')
+ mw.execShell('mkdir -p ' + bpath)
+ mw.execShell('ln -sf ' + path +
+ '/index.html ' + bpath + '/index.html')
- sitePath = public.M('sites').where("id=?", (mid,)).getField('path')
+ sitePath = mw.M('sites').where("id=?", (mid,)).getField('path')
# nginx
file = self.getHostConf(name)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if conf:
conf = conf.replace(sitePath, path)
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
- public.M('sites').where("id=?", (mid,)).setField('status', '0')
- public.restartWeb()
- msg = public.getInfo('网站[{1}]已被停用!', (name,))
- public.writeLog('网站管理', msg)
- return public.returnJson(True, '站点已停用!')
+ mw.M('sites').where("id=?", (mid,)).setField('status', '0')
+ mw.restartWeb()
+ msg = mw.getInfo('网站[{1}]已被停用!', (name,))
+ mw.writeLog('网站管理', msg)
+ return mw.returnJson(True, '站点已停用!')
def startApi(self):
mid = request.form.get('id', '').encode('utf-8')
name = request.form.get('name', '').encode('utf-8')
path = self.setupPath + '/stop'
- sitePath = public.M('sites').where("id=?", (mid,)).getField('path')
+ sitePath = mw.M('sites').where("id=?", (mid,)).getField('path')
# nginx
file = self.getHostConf(name)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if conf:
conf = conf.replace(path, sitePath)
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
- public.M('sites').where("id=?", (mid,)).setField('status', '1')
- public.restartWeb()
- msg = public.getInfo('网站[{1}]已被启用!', (name,))
- public.writeLog('网站管理', msg)
- return public.returnJson(True, '站点已启用!')
+ mw.M('sites').where("id=?", (mid,)).setField('status', '1')
+ mw.restartWeb()
+ msg = mw.getInfo('网站[{1}]已被启用!', (name,))
+ mw.writeLog('网站管理', msg)
+ return mw.returnJson(True, '站点已启用!')
def getBackupApi(self):
limit = request.form.get('limit', '').encode('utf-8')
p = request.form.get('p', '').encode('utf-8')
mid = request.form.get('search', '').encode('utf-8')
- find = public.M('sites').where("id=?", (mid,)).field(
+ find = mw.M('sites').where("id=?", (mid,)).field(
"id,name,path,status,ps,addtime,edate").find()
start = (int(p) - 1) * (int(limit))
- _list = public.M('backup').where('pid=?', (mid,)).field('id,type,name,pid,filename,size,addtime').limit(
+ _list = mw.M('backup').where('pid=?', (mid,)).field('id,type,name,pid,filename,size,addtime').limit(
(str(start)) + ',' + limit).order('id desc').select()
_ret = {}
_ret['data'] = _list
- count = public.M('backup').where("id=?", (mid,)).count()
+ count = mw.M('backup').where("id=?", (mid,)).count()
info = {}
info['count'] = count
info['tojs'] = 'getBackup'
info['p'] = p
info['row'] = limit
- _ret['page'] = public.getPage(info)
+ _ret['page'] = mw.getPage(info)
_ret['site'] = find
- return public.getJson(_ret)
+ return mw.getJson(_ret)
def toBackupApi(self):
mid = request.form.get('id', '').encode('utf-8')
- find = public.M('sites').where(
+ find = mw.M('sites').where(
"id=?", (mid,)).field('name,path,id').find()
fileName = find['name'] + '_' + \
time.strftime('%Y%m%d_%H%M%S', time.localtime()) + '.zip'
- backupPath = public.getBackupDir() + '/site'
+ backupPath = mw.getBackupDir() + '/site'
zipName = backupPath + '/' + fileName
if not (os.path.exists(backupPath)):
os.makedirs(backupPath)
- tmps = public.getRunDir() + '/tmp/panelExec.log'
+ tmps = mw.getRunDir() + '/tmp/panelExec.log'
execStr = "cd '" + find['path'] + "' && zip '" + \
zipName + "' -r ./* > " + tmps + " 2>&1"
# print execStr
- public.execShell(execStr)
+ mw.execShell(execStr)
if os.path.exists(zipName):
fsize = os.path.getsize(zipName)
else:
fsize = 0
- sql = public.M('backup').add('type,name,pid,filename,size,addtime',
- (0, fileName, find['id'], zipName, fsize, public.getDate()))
+ sql = mw.M('backup').add('type,name,pid,filename,size,addtime',
+ (0, fileName, find['id'], zipName, fsize, mw.getDate()))
- msg = public.getInfo('备份网站[{1}]成功!', (find['name'],))
- public.writeLog('网站管理', msg)
- return public.returnJson(True, '备份成功!')
+ msg = mw.getInfo('备份网站[{1}]成功!', (find['name'],))
+ mw.writeLog('网站管理', msg)
+ return mw.returnJson(True, '备份成功!')
def delBackupApi(self):
mid = request.form.get('id', '').encode('utf-8')
- filename = public.M('backup').where(
+ filename = mw.M('backup').where(
"id=?", (mid,)).getField('filename')
if os.path.exists(filename):
os.remove(filename)
- name = public.M('backup').where("id=?", (mid,)).getField('name')
- msg = public.getInfo('删除网站[{1}]的备份[{2}]成功!', (name, filename))
- public.writeLog('网站管理', msg)
- public.M('backup').where("id=?", (mid,)).delete()
- return public.returnJson(True, '站点删除成功!')
+ name = mw.M('backup').where("id=?", (mid,)).getField('name')
+ msg = mw.getInfo('删除网站[{1}]的备份[{2}]成功!', (name, filename))
+ mw.writeLog('网站管理', msg)
+ mw.M('backup').where("id=?", (mid,)).delete()
+ return mw.returnJson(True, '站点删除成功!')
def getPhpVersionApi(self):
return self.getPhpVersion()
@@ -248,17 +248,17 @@ class site_api:
# nginx
file = self.getHostConf(siteName)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if conf:
rep = "enable-php-([0-9]{2,3})\.conf"
tmp = re.search(rep, conf).group()
conf = conf.replace(tmp, 'enable-php-' + version + '.conf')
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
- public.restartWeb()
- msg = public.getInfo('成功切换网站[{1}]的PHP版本为PHP-{2}', (siteName, version))
- public.writeLog("网站管理", msg)
- return public.returnJson(True, msg)
+ mw.restartWeb()
+ msg = mw.getInfo('成功切换网站[{1}]的PHP版本为PHP-{2}', (siteName, version))
+ mw.writeLog("网站管理", msg)
+ return mw.returnJson(True, msg)
def getDomainApi(self):
pid = request.form.get('pid', '').encode('utf-8')
@@ -269,9 +269,9 @@ class site_api:
pid = request.form.get('id', '').encode('utf-8')
data = {}
- domains = public.M('domain').where(
+ domains = mw.M('domain').where(
'pid=?', (pid,)).field('name,id').select()
- binding = public.M('binding').where(
+ binding = mw.M('binding').where(
'pid=?', (pid,)).field('domain,id').select()
if type(binding) == str:
return binding
@@ -281,28 +281,28 @@ class site_api:
tmp['id'] = b['id']
domains.append(tmp)
data['domains'] = domains
- data['email'] = public.M('users').getField('email')
+ data['email'] = mw.M('users').getField('email')
if data['email'] == '287962566@qq.com':
data['email'] = ''
- return public.returnJson(True, 'OK', data)
+ return mw.returnJson(True, 'OK', data)
def getDirBindingApi(self):
mid = request.form.get('id', '').encode('utf-8')
- path = public.M('sites').where('id=?', (mid,)).getField('path')
+ path = mw.M('sites').where('id=?', (mid,)).getField('path')
if not os.path.exists(path):
checks = ['/', '/usr', '/etc']
if path in checks:
data = {}
data['dirs'] = []
data['binding'] = []
- return public.returnJson(True, 'OK', data)
+ return mw.returnJson(True, 'OK', data)
os.system('mkdir -p ' + path)
os.system('chmod 755 ' + path)
os.system('chown www:www ' + path)
- siteName = public.M('sites').where(
+ siteName = mw.M('sites').where(
'id=?', (get.id,)).getField('name')
- public.writeLog(
+ mw.writeLog(
'网站管理', '站点[' + siteName + '],根目录[' + path + ']不存在,已重新创建!')
dirnames = []
@@ -318,15 +318,15 @@ class site_api:
data = {}
data['dirs'] = dirnames
- data['binding'] = public.M('binding').where('pid=?', (mid,)).field(
+ data['binding'] = mw.M('binding').where('pid=?', (mid,)).field(
'id,pid,domain,path,port,addtime').select()
- return public.returnJson(True, 'OK', data)
+ return mw.returnJson(True, 'OK', data)
def getDirUserIniApi(self):
mid = request.form.get('id', '').encode('utf-8')
- path = public.M('sites').where('id=?', (mid,)).getField('path')
- name = public.M('sites').where("id=?", (mid,)).getField('name')
+ path = mw.M('sites').where('id=?', (mid,)).getField('path')
+ name = mw.M('sites').where("id=?", (mid,)).getField('name')
data = {}
data['logs'] = self.getLogsStatus(name)
data['userini'] = False
@@ -335,37 +335,37 @@ class site_api:
data['runPath'] = self.getSiteRunPath(mid)
data['pass'] = self.getHasPwd(name)
data['path'] = path
- return public.returnJson(True, 'OK', data)
+ return mw.returnJson(True, 'OK', data)
def setDirUserIniApi(self):
path = request.form.get('path', '').encode('utf-8')
filename = path + '/.user.ini'
self.delUserInI(path)
if os.path.exists(filename):
- public.execShell("which chattr && chattr -i " + filename)
+ mw.execShell("which chattr && chattr -i " + filename)
os.remove(filename)
- return public.returnJson(True, '已清除防跨站设置!')
- public.writeFile(filename, 'open_basedir=' + path + '/:/tmp/:/proc/')
- public.execShell("which chattr && chattr +i " + filename)
- return public.returnJson(True, '已打开防跨站设置!')
+ return mw.returnJson(True, '已清除防跨站设置!')
+ mw.writeFile(filename, 'open_basedir=' + path + '/:/tmp/:/proc/')
+ mw.execShell("which chattr && chattr +i " + filename)
+ return mw.returnJson(True, '已打开防跨站设置!')
def logsOpenApi(self):
mid = request.form.get('id', '').encode('utf-8')
- name = public.M('sites').where("id=?", (mid,)).getField('name')
+ name = mw.M('sites').where("id=?", (mid,)).getField('name')
# NGINX
filename = self.getHostConf(name)
if os.path.exists(filename):
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
rep = self.logsPath + "/" + name + ".log"
if conf.find(rep) != -1:
conf = conf.replace(rep, "off")
else:
conf = conf.replace('access_log off', 'access_log ' + rep)
- public.writeFile(filename, conf)
+ mw.writeFile(filename, conf)
- public.restartWeb()
- return public.returnJson(True, '操作成功!')
+ mw.restartWeb()
+ return mw.returnJson(True, '操作成功!')
def getCertListApi(self):
try:
@@ -377,14 +377,14 @@ class site_api:
mpath = vpath + '/' + d + '/info.json'
if not os.path.exists(mpath):
continue
- tmp = public.readFile(mpath)
+ tmp = mw.readFile(mpath)
if not tmp:
continue
tmp1 = json.loads(tmp)
data.append(tmp1)
- return public.returnJson(True, 'OK', data)
+ return mw.returnJson(True, 'OK', data)
except:
- return public.returnJson(True, 'OK', [])
+ return mw.returnJson(True, 'OK', [])
def getSslApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
@@ -392,11 +392,11 @@ class site_api:
path = self.sslDir + siteName
csrpath = path + "/fullchain.pem" # 生成证书路径
keypath = path + "/privkey.pem" # 密钥文件路径
- key = public.readFile(keypath)
- csr = public.readFile(csrpath)
+ key = mw.readFile(keypath)
+ csr = mw.readFile(csrpath)
file = self.getHostConf(siteName)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
keyText = 'ssl_certificate'
status = True
@@ -406,12 +406,12 @@ class site_api:
stype = -1
toHttps = self.isToHttps(siteName)
- id = public.M('sites').where("name=?", (siteName,)).getField('id')
- domains = public.M('domain').where(
+ id = mw.M('sites').where("name=?", (siteName,)).getField('id')
+ domains = mw.M('domain').where(
"pid=?", (id,)).field('name').select()
data = {'status': status, 'domain': domains, 'key': key,
'csr': csr, 'type': stype, 'httpTohttps': toHttps}
- return public.returnJson(True, 'OK', data)
+ return mw.returnJson(True, 'OK', data)
def setSslApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
@@ -420,55 +420,55 @@ class site_api:
path = self.sslDir + siteName
if not os.path.exists(path):
- public.execShell('mkdir -p ' + path)
+ mw.execShell('mkdir -p ' + path)
csrpath = path + "/fullchain.pem" # 生成证书路径
keypath = path + "/privkey.pem" # 密钥文件路径
if(key.find('KEY') == -1):
- return public.returnJson(False, '秘钥错误,请检查!')
+ return mw.returnJson(False, '秘钥错误,请检查!')
if(csr.find('CERTIFICATE') == -1):
- return public.returnJson(False, '证书错误,请检查!')
+ return mw.returnJson(False, '证书错误,请检查!')
- public.writeFile('/tmp/cert.pl', csr)
- if not public.checkCert('/tmp/cert.pl'):
- return public.returnJson(False, '证书错误,请粘贴正确的PEM格式证书!')
+ mw.writeFile('/tmp/cert.pl', csr)
+ if not mw.checkCert('/tmp/cert.pl'):
+ return mw.returnJson(False, '证书错误,请粘贴正确的PEM格式证书!')
- public.execShell('\\cp -a ' + keypath + ' /tmp/backup1.conf')
- public.execShell('\\cp -a ' + csrpath + ' /tmp/backup2.conf')
+ mw.execShell('\\cp -a ' + keypath + ' /tmp/backup1.conf')
+ mw.execShell('\\cp -a ' + csrpath + ' /tmp/backup2.conf')
# 清理旧的证书链
if os.path.exists(path + '/README'):
- public.execShell('rm -rf ' + path)
- public.execShell('rm -rf ' + path + '-00*')
- public.execShell('rm -rf /etc/letsencrypt/archive/' + siteName)
- public.execShell(
+ mw.execShell('rm -rf ' + path)
+ mw.execShell('rm -rf ' + path + '-00*')
+ mw.execShell('rm -rf /etc/letsencrypt/archive/' + siteName)
+ mw.execShell(
'rm -rf /etc/letsencrypt/archive/' + siteName + '-00*')
- public.execShell(
+ mw.execShell(
'rm -f /etc/letsencrypt/renewal/' + siteName + '.conf')
- public.execShell('rm -rf /etc/letsencrypt/renewal/' +
- siteName + '-00*.conf')
- public.execShell('rm -rf ' + path + '/README')
- public.execShell('mkdir -p ' + path)
+ mw.execShell('rm -rf /etc/letsencrypt/renewal/' +
+ siteName + '-00*.conf')
+ mw.execShell('rm -rf ' + path + '/README')
+ mw.execShell('mkdir -p ' + path)
- public.writeFile(keypath, key)
- public.writeFile(csrpath, csr)
+ mw.writeFile(keypath, key)
+ mw.writeFile(csrpath, csr)
# 写入配置文件
result = self.setSslConf(siteName)
# print result['msg']
if not result['status']:
- return public.getJson(result)
+ return mw.getJson(result)
- isError = public.checkWebConfig()
+ isError = mw.checkWebConfig()
if(type(isError) == str):
- public.execShell('\\cp -a /tmp/backup1.conf ' + keypath)
- public.execShell('\\cp -a /tmp/backup2.conf ' + csrpath)
- return public.returnJson(False, 'ERROR:
' + isError.replace("\n", '
') + '')
+ mw.execShell('\\cp -a /tmp/backup1.conf ' + keypath)
+ mw.execShell('\\cp -a /tmp/backup2.conf ' + csrpath)
+ return mw.returnJson(False, 'ERROR:
' + isError.replace("\n", '
') + '')
- public.restartWeb()
- public.writeLog('网站管理', '证书已保存!')
- return public.returnJson(True, '证书已保存!')
+ mw.restartWeb()
+ mw.writeLog('网站管理', '证书已保存!')
+ return mw.returnJson(True, '证书已保存!')
def setCertToSiteApi(self):
certName = request.form.get('certName', '').encode('utf-8')
@@ -476,34 +476,34 @@ class site_api:
try:
path = self.sslDir + siteName
if not os.path.exists(path):
- return public.returnJson(False, '证书不存在!')
+ return mw.returnJson(False, '证书不存在!')
result = self.setSslConf(siteName)
if not result['status']:
- return public.getJson(result)
+ return mw.getJson(result)
- public.restartWeb()
- public.writeLog('网站管理', '证书已部署!')
- return public.returnJson(True, '证书已部署!')
+ mw.restartWeb()
+ mw.writeLog('网站管理', '证书已部署!')
+ return mw.returnJson(True, '证书已部署!')
except Exception as ex:
- return public.returnJson(False, '设置错误,' + str(ex))
+ return mw.returnJson(False, '设置错误,' + str(ex))
def removeCertApi(self):
certName = request.form.get('certName', '').encode('utf-8')
try:
path = self.sslDir + certName
if not os.path.exists(path):
- return public.returnJson(False, '证书已不存在!')
+ return mw.returnJson(False, '证书已不存在!')
os.system("rm -rf " + path)
- return public.returnJson(True, '证书已删除!')
+ return mw.returnJson(True, '证书已删除!')
except:
- return public.returnJson(False, '删除失败!')
+ return mw.returnJson(False, '删除失败!')
def closeSslConfApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
file = self.getHostConf(siteName)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if conf:
rep = "\n\s*#HTTP_TO_HTTPS_START(.|\n){1,300}#HTTP_TO_HTTPS_END"
@@ -540,12 +540,12 @@ class site_api:
conf = re.sub(rep, '', conf)
rep = "\s+listen\s+443.*;"
conf = re.sub(rep, '', conf)
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
- msg = public.getInfo('网站[{1}]关闭SSL成功!', (siteName,))
- public.writeLog('网站管理', msg)
- public.restartWeb()
- return public.returnJson(True, 'SSL已关闭!')
+ msg = mw.getInfo('网站[{1}]关闭SSL成功!', (siteName,))
+ mw.writeLog('网站管理', msg)
+ mw.restartWeb()
+ return mw.returnJson(True, 'SSL已关闭!')
def createLetApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
@@ -556,33 +556,33 @@ class site_api:
email_args = request.form.get('email', '').encode('utf-8')
domains = json.loads(domains)
- email = public.M('users').getField('email')
+ email = mw.M('users').getField('email')
if email_args.strip() != '':
- public.M('users').setField('email', email_args)
+ mw.M('users').setField('email', email_args)
email = email_args
if not len(domains):
- return public.returnJson(False, '请选择域名')
+ return mw.returnJson(False, '请选择域名')
file = self.getHostConf(siteName)
if os.path.exists(file):
- siteConf = public.readFile(file)
+ siteConf = mw.readFile(file)
if siteConf.find('301-START') != -1:
- return public.returnJson(False, '检测到您的站点做了301重定向设置,请先关闭重定向!')
+ return mw.returnJson(False, '检测到您的站点做了301重定向设置,请先关闭重定向!')
letpath = self.sslDir + siteName
csrpath = letpath + "/fullchain.pem" # 生成证书路径
keypath = letpath + "/privkey.pem" # 密钥文件路径
actionstr = updateOf
- siteInfo = public.M('sites').where(
+ siteInfo = mw.M('sites').where(
'name=?', (siteName,)).field('id,name,path').find()
path = self.getSitePath(siteName)
srcPath = siteInfo['path']
# 检测acem是否安装
- if public.isAppleSystem():
- user = public.execShell(
+ if mw.isAppleSystem():
+ user = mw.execShell(
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
acem = '/Users/' + user + '/.acme.sh/acme.sh'
else:
@@ -591,11 +591,11 @@ class site_api:
acem = '/.acme.sh/acme.sh'
if not os.path.exists(acem):
try:
- public.execShell("curl -sS curl https://get.acme.sh | sh")
+ mw.execShell("curl -sS curl https://get.acme.sh | sh")
except:
- return public.returnJson(False, '尝试自动安装ACME失败,请通过以下命令尝试手动安装安装命令: curl https://get.acme.sh | sh
' + acem)
+ return mw.returnJson(False, '尝试自动安装ACME失败,请通过以下命令尝试手动安装安装命令: curl https://get.acme.sh | sh
' + acem)
if not os.path.exists(acem):
- return public.returnJson(False, '尝试自动安装ACME失败,请通过以下命令尝试手动安装安装命令: curl https://get.acme.sh | sh
' + acem)
+ return mw.returnJson(False, '尝试自动安装ACME失败,请通过以下命令尝试手动安装安装命令: curl https://get.acme.sh | sh
' + acem)
force_bool = False
if force == 'true':
@@ -618,15 +618,15 @@ class site_api:
domainCount = 0
for domain in domains:
- if public.checkIp(domain):
+ if mw.checkIp(domain):
continue
if domain.find('*.') != -1:
- return public.returnJson(False, '泛域名不能使用【文件验证】的方式申请证书!')
+ return mw.returnJson(False, '泛域名不能使用【文件验证】的方式申请证书!')
execStr += ' -w ' + path
execStr += ' -d ' + domain
domainCount += 1
if domainCount == 0:
- return public.returnJson(False, '请选择域名(不包括IP地址与泛域名)!')
+ return mw.returnJson(False, '请选择域名(不包括IP地址与泛域名)!')
home_path = '/root/.acme.sh/' + domains[0]
home_cert = home_path + '/fullchain.cer'
@@ -637,8 +637,8 @@ class site_api:
home_cert = home_path + '/fullchain.cer'
home_key = home_path + '/' + domains[0] + '.key'
- if public.isAppleSystem():
- user = public.execShell(
+ if mw.isAppleSystem():
+ user = mw.execShell(
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
acem = '/Users/' + user + '/.acme.sh/'
if not os.path.exists(home_cert):
@@ -650,7 +650,7 @@ class site_api:
cmd = 'export ACCOUNT_EMAIL=' + email + ' && ' + execStr
print domains
print cmd
- result = public.execShell(cmd)
+ result = mw.execShell(cmd)
if not os.path.exists(home_cert.replace("\*", "*")):
data = {}
@@ -672,33 +672,33 @@ class site_api:
4、如果您的站点设置了301重定向,请先将其关闭
\
5、如果以上检查都确认没有问题,请尝试更换DNS服务商
'
data['status'] = False
- return public.getJson(data)
+ return mw.getJson(data)
if not os.path.exists(letpath):
- public.execShell("mkdir -p " + letpath)
- public.execShell("ln -sf \"" + home_cert + "\" \"" + csrpath + '"')
- public.execShell("ln -sf \"" + home_key + "\" \"" + keypath + '"')
- public.execShell('echo "let" > "' + letpath + '/README"')
+ mw.execShell("mkdir -p " + letpath)
+ mw.execShell("ln -sf \"" + home_cert + "\" \"" + csrpath + '"')
+ mw.execShell("ln -sf \"" + home_key + "\" \"" + keypath + '"')
+ mw.execShell('echo "let" > "' + letpath + '/README"')
if(actionstr == '2'):
- return public.returnJson(True, '证书已更新!')
+ return mw.returnJson(True, '证书已更新!')
# 写入配置文件
result = self.setSslConf(siteName)
if not result['status']:
- return public.getJson(result)
- result['csr'] = public.readFile(csrpath)
- result['key'] = public.readFile(keypath)
- public.restartWeb()
+ return mw.getJson(result)
+ result['csr'] = mw.readFile(csrpath)
+ result['key'] = mw.readFile(keypath)
+ mw.restartWeb()
- return public.returnJson(True, 'OK', result)
+ return mw.returnJson(True, 'OK', result)
def httpToHttpsApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
file = self.getHostConf(siteName)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if conf:
# if conf.find('ssl_certificate') == -1:
- # return public.returnJson(False, '当前未开启SSL')
+ # return mw.returnJson(False, '当前未开启SSL')
to = """#error_page 404/404.html;
# HTTP_TO_HTTPS_START
if ($server_port !~ 443){
@@ -706,31 +706,31 @@ class site_api:
}
# HTTP_TO_HTTPS_END"""
conf = conf.replace('#error_page 404/404.html;', to)
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
- public.restartWeb()
- return public.returnJson(True, '设置成功!证书也要设置好哟!')
+ mw.restartWeb()
+ return mw.returnJson(True, '设置成功!证书也要设置好哟!')
def closeToHttpsApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
file = self.getHostConf(siteName)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if conf:
rep = "\n\s*#HTTP_TO_HTTPS_START(.|\n){1,300}#HTTP_TO_HTTPS_END"
conf = re.sub(rep, '', conf)
rep = "\s+if.+server_port.+\n.+\n\s+\s*}"
conf = re.sub(rep, '', conf)
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
- public.restartWeb()
- return public.returnJson(True, '关闭HTTPS跳转成功!')
+ mw.restartWeb()
+ return mw.returnJson(True, '关闭HTTPS跳转成功!')
def getIndexApi(self):
sid = request.form.get('id', '').encode('utf-8')
data = {}
index = self.getIndex(sid)
data['index'] = index
- return public.getJson(data)
+ return mw.getJson(data)
def setIndexApi(self):
sid = request.form.get('id', '').encode('utf-8')
@@ -776,28 +776,28 @@ class site_api:
def getHostConfApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
host = self.getHostConf(siteName)
- return public.getJson({'host': host})
+ return mw.getJson({'host': host})
def getRewriteConfApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
rewrite = self.getRewriteConf(siteName)
- return public.getJson({'rewrite': rewrite})
+ return mw.getJson({'rewrite': rewrite})
def getRewriteTplApi(self):
tplname = request.form.get('tplname', '').encode('utf-8')
- file = public.getRunDir() + '/rewrite/nginx/' + tplname + '.conf'
+ file = mw.getRunDir() + '/rewrite/nginx/' + tplname + '.conf'
if not os.path.exists(file):
- return public.returnJson(False, '模版不存在!')
- return public.returnJson(True, 'OK', file)
+ return mw.returnJson(False, '模版不存在!')
+ return mw.returnJson(True, 'OK', file)
def getRewriteListApi(self):
rlist = self.getRewriteList()
- return public.getJson(rlist)
+ return mw.getJson(rlist)
def getRootDirApi(self):
data = {}
- data['dir'] = public.getWwwDir()
- return public.getJson(data)
+ data['dir'] = mw.getWwwDir()
+ return mw.getJson(data)
def setEndDateApi(self):
sid = request.form.get('id', '').encode('utf-8')
@@ -813,15 +813,15 @@ class site_api:
return self.add(webname, port, ps, path, version)
def addDomainApi(self):
- isError = public.checkWebConfig()
+ isError = mw.checkWebConfig()
if isError != True:
- return public.returnJson(False, 'ERROR: 检测到配置文件有错误,请先排除后再操作
' + isError.replace("\n", '
') + '')
+ return mw.returnJson(False, 'ERROR: 检测到配置文件有错误,请先排除后再操作
' + isError.replace("\n", '
') + '')
domain = request.form.get('domain', '').encode('utf-8')
webname = request.form.get('webname', '').encode('utf-8')
pid = request.form.get('id', '').encode('utf-8')
if len(domain) < 3:
- return public.returnJson(False, '域名不能为空!')
+ return mw.returnJson(False, '域名不能为空!')
domains = domain.split(',')
for domain in domains:
if domain == "":
@@ -833,35 +833,35 @@ class site_api:
reg = "^([\w\-\*]{1,100}\.){1,4}([\w\-]{1,24}|[\w\-]{1,24}\.[\w\-]{1,24})$"
if not re.match(reg, domain_name):
- return public.returnJson(False, '域名格式不正确!')
+ return mw.returnJson(False, '域名格式不正确!')
if len(domain) == 2:
domain_port = domain[1]
if domain_port == "":
domain_port = "80"
- if not public.checkPort(domain_port):
- return public.returnJson(False, '端口范围不合法!')
+ if not mw.checkPort(domain_port):
+ return mw.returnJson(False, '端口范围不合法!')
- opid = public.M('domain').where(
+ opid = mw.M('domain').where(
"name=? AND (port=? OR pid=?)", (domain, domain_port, pid)).getField('pid')
if opid:
- if public.M('sites').where('id=?', (opid,)).count():
- return public.returnJson(False, '指定域名已绑定过!')
- public.M('domain').where('pid=?', (opid,)).delete()
+ if mw.M('sites').where('id=?', (opid,)).count():
+ return mw.returnJson(False, '指定域名已绑定过!')
+ mw.M('domain').where('pid=?', (opid,)).delete()
- if public.M('binding').where('domain=?', (domain,)).count():
- return public.returnJson(False, '您添加的域名已存在!')
+ if mw.M('binding').where('domain=?', (domain,)).count():
+ return mw.returnJson(False, '您添加的域名已存在!')
self.nginxAddDomain(webname, domain_name, domain_port)
- public.restartWeb()
- msg = public.getInfo('网站[{1}]添加域名[{2}]成功!', (webname, domain_name))
- public.writeLog('网站管理', msg)
- public.M('domain').add('pid,name,port,addtime',
- (pid, domain_name, domain_port, public.getDate()))
+ mw.restartWeb()
+ msg = mw.getInfo('网站[{1}]添加域名[{2}]成功!', (webname, domain_name))
+ mw.writeLog('网站管理', msg)
+ mw.M('domain').add('pid,name,port,addtime',
+ (pid, domain_name, domain_port, mw.getDate()))
- return public.returnJson(True, '域名添加成功!')
+ return mw.returnJson(True, '域名添加成功!')
def addDirBindApi(self):
pid = request.form.get('id', '').encode('utf-8')
@@ -873,99 +873,99 @@ class site_api:
if len(tmp) > 1:
port = tmp[1]
if dirName == '':
- public.returnJson(False, '目录不能为空!')
+ mw.returnJson(False, '目录不能为空!')
reg = "^([\w\-\*]{1,100}\.){1,4}(\w{1,10}|\w{1,10}\.\w{1,10})$"
if not re.match(reg, domain):
- return public.returnJson(False, '主域名格式不正确!')
+ return mw.returnJson(False, '主域名格式不正确!')
- siteInfo = public.M('sites').where(
+ siteInfo = mw.M('sites').where(
"id=?", (pid,)).field('id,path,name').find()
webdir = siteInfo['path'] + '/' + dirName
- if public.M('binding').where("domain=?", (domain,)).count() > 0:
- return public.returnJson(False, '您添加的域名已存在!')
- if public.M('domain').where("name=?", (domain,)).count() > 0:
- return public.returnJson(False, '您添加的域名已存在!')
+ if mw.M('binding').where("domain=?", (domain,)).count() > 0:
+ return mw.returnJson(False, '您添加的域名已存在!')
+ if mw.M('domain').where("name=?", (domain,)).count() > 0:
+ return mw.returnJson(False, '您添加的域名已存在!')
filename = self.getHostConf(siteInfo['name'])
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
if conf:
rep = "enable-php-([0-9]{2,3})\.conf"
tmp = re.search(rep, conf).groups()
version = tmp[0]
- source_dirbind_tpl = public.getRunDir() + '/data/tpl/nginx_dirbind.conf'
- content = public.readFile(source_dirbind_tpl)
+ source_dirbind_tpl = mw.getRunDir() + '/data/tpl/nginx_dirbind.conf'
+ content = mw.readFile(source_dirbind_tpl)
content = content.replace('{$PORT}', port)
content = content.replace('{$PHPVER}', version)
content = content.replace('{$DIRBIND}', domain)
content = content.replace('{$ROOT_DIR}', webdir)
content = content.replace('{$SERVER_MAIN}', siteInfo['name'])
content = content.replace('{$OR_REWRITE}', self.rewritePath)
- content = content.replace('{$LOGPATH}', public.getLogsDir())
+ content = content.replace('{$LOGPATH}', mw.getLogsDir())
conf += "\r\n" + content
shutil.copyfile(filename, '/tmp/backup.conf')
- public.writeFile(filename, conf)
- conf = public.readFile(filename)
+ mw.writeFile(filename, conf)
+ conf = mw.readFile(filename)
# 检查配置是否有误
- isError = public.checkWebConfig()
+ isError = mw.checkWebConfig()
if isError != True:
shutil.copyfile('/tmp/backup.conf', filename)
- return public.returnJson(False, 'ERROR:
' + isError.replace("\n", '
') + '')
+ return mw.returnJson(False, 'ERROR:
' + isError.replace("\n", '
') + '')
- public.M('binding').add('pid,domain,port,path,addtime',
- (pid, domain, port, dirName, public.getDate()))
+ mw.M('binding').add('pid,domain,port,path,addtime',
+ (pid, domain, port, dirName, mw.getDate()))
- public.restartWeb()
- msg = public.getInfo('网站[{1}]子目录[{2}]绑定到[{3}]',
- (siteInfo['name'], dirName, domain))
- public.writeLog('网站管理', msg)
- return public.returnJson(True, '添加成功!')
+ mw.restartWeb()
+ msg = mw.getInfo('网站[{1}]子目录[{2}]绑定到[{3}]',
+ (siteInfo['name'], dirName, domain))
+ mw.writeLog('网站管理', msg)
+ return mw.returnJson(True, '添加成功!')
def delDirBindApi(self):
mid = request.form.get('id', '').encode('utf-8')
- binding = public.M('binding').where(
+ binding = mw.M('binding').where(
"id=?", (mid,)).field('id,pid,domain,path').find()
- siteName = public.M('sites').where(
+ siteName = mw.M('sites').where(
"id=?", (binding['pid'],)).getField('name')
filename = self.getHostConf(siteName)
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
if conf:
rep = "\s*.+BINDING-" + \
binding['domain'] + \
"-START(.|\n)+BINDING-" + binding['domain'] + "-END"
conf = re.sub(rep, '', conf)
- public.writeFile(filename, conf)
+ mw.writeFile(filename, conf)
- public.M('binding').where("id=?", (mid,)).delete()
+ mw.M('binding').where("id=?", (mid,)).delete()
filename = self.getDirBindRewrite(siteName, binding['path'])
if os.path.exists(filename):
os.remove(filename)
- public.restartWeb()
- msg = public.getInfo('删除网站[{1}]子目录[{2}]绑定',
- (siteName, binding['path']))
- public.writeLog('网站管理', msg)
- return public.returnJson(True, '删除成功!')
+ mw.restartWeb()
+ msg = mw.getInfo('删除网站[{1}]子目录[{2}]绑定',
+ (siteName, binding['path']))
+ mw.writeLog('网站管理', msg)
+ return mw.returnJson(True, '删除成功!')
# 取子目录Rewrite
def getDirBindRewriteApi(self):
mid = request.form.get('id', '').encode('utf-8')
add = request.form.get('add', '0').encode('utf-8')
- find = public.M('binding').where(
+ find = mw.M('binding').where(
"id=?", (mid,)).field('id,pid,domain,path').find()
- site = public.M('sites').where(
+ site = mw.M('sites').where(
"id=?", (find['pid'],)).field('id,name,path').find()
filename = self.getDirBindRewrite(site['name'], find['path'])
if add == '1':
- public.writeFile(filename, '')
+ mw.writeFile(filename, '')
file = self.getHostConf(site['name'])
- conf = public.readFile(file)
+ conf = mw.readFile(file)
domain = find['domain']
rep = "\n#BINDING-" + domain + \
"-START(.|\n)+BINDING-" + domain + "-END"
@@ -973,20 +973,20 @@ class site_api:
dirConf = tmp.replace('rewrite/' + site['name'] + '.conf;', 'rewrite/' + site[
'name'] + '_' + find['path'] + '.conf;')
conf = conf.replace(tmp, dirConf)
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
data = {}
data['rewrite_dir'] = self.rewritePath
data['status'] = False
if os.path.exists(filename):
data['status'] = True
- data['data'] = public.readFile(filename)
+ data['data'] = mw.readFile(filename)
data['rlist'] = []
for ds in os.listdir(self.rewritePath):
if ds == 'list.txt':
continue
data['rlist'].append(ds[0:len(ds) - 5])
data['filename'] = filename
- return public.getJson(data)
+ return mw.getJson(data)
# 修改物理路径
def setPathApi(self):
@@ -995,59 +995,59 @@ class site_api:
path = self.getPath(path)
if path == "" or mid == '0':
- return public.returnJson(False, "目录不能为空!")
+ return mw.returnJson(False, "目录不能为空!")
import files_api
if not files_api.files_api().checkDir(path):
- return public.returnJson(False, "不能以系统关键目录作为站点目录")
+ return mw.returnJson(False, "不能以系统关键目录作为站点目录")
- siteFind = public.M("sites").where(
+ siteFind = mw.M("sites").where(
"id=?", (mid,)).field('path,name').find()
if siteFind["path"] == path:
- return public.returnJson(False, "与原路径一致,无需修改!")
+ return mw.returnJson(False, "与原路径一致,无需修改!")
file = self.getHostConf(siteFind['name'])
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if conf:
conf = conf.replace(siteFind['path'], path)
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
# 创建basedir
# userIni = path + '/.user.ini'
# if os.path.exists(userIni):
- # public.execShell("chattr -i " + userIni)
- # public.writeFile(userIni, 'open_basedir=' + path + '/:/tmp/:/proc/')
- # public.execShell('chmod 644 ' + userIni)
- # public.execShell('chown root:root ' + userIni)
- # public.execShell('chattr +i ' + userIni)
-
- public.restartWeb()
- public.M("sites").where("id=?", (mid,)).setField('path', path)
- msg = public.getInfo('修改网站[{1}]物理路径成功!', (siteFind['name'],))
- public.writeLog('网站管理', msg)
- return public.returnJson(True, "设置成功!")
+ # mw.execShell("chattr -i " + userIni)
+ # mw.writeFile(userIni, 'open_basedir=' + path + '/:/tmp/:/proc/')
+ # mw.execShell('chmod 644 ' + userIni)
+ # mw.execShell('chown root:root ' + userIni)
+ # mw.execShell('chattr +i ' + userIni)
+
+ mw.restartWeb()
+ mw.M("sites").where("id=?", (mid,)).setField('path', path)
+ msg = mw.getInfo('修改网站[{1}]物理路径成功!', (siteFind['name'],))
+ mw.writeLog('网站管理', msg)
+ return mw.returnJson(True, "设置成功!")
# 设置当前站点运行目录
def setSiteRunPathApi(self):
mid = request.form.get('id', '').encode('utf-8')
runPath = request.form.get('runPath', '').encode('utf-8')
- siteName = public.M('sites').where('id=?', (mid,)).getField('name')
- sitePath = public.M('sites').where('id=?', (mid,)).getField('path')
+ siteName = mw.M('sites').where('id=?', (mid,)).getField('name')
+ sitePath = mw.M('sites').where('id=?', (mid,)).getField('path')
newPath = sitePath + runPath
# 处理Nginx
filename = self.getHostConf(siteName)
if os.path.exists(filename):
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
rep = '\s*root\s*(.+);'
path = re.search(rep, conf).groups()[0]
conf = conf.replace(path, newPath)
- public.writeFile(filename, conf)
+ mw.writeFile(filename, conf)
self.delUserInI(sitePath)
self.setDirUserINI(newPath)
- public.restartWeb()
- return public.returnJson(True, '设置成功!')
+ mw.restartWeb()
+ return mw.returnJson(True, '设置成功!')
# 设置目录加密
def setHasPwdApi(self):
@@ -1057,15 +1057,15 @@ class site_api:
mid = request.form.get('id', '')
if len(username.strip()) == 0 or len(password.strip()) == 0:
- return public.returnJson(False, '用户名或密码不能为空!')
+ return mw.returnJson(False, '用户名或密码不能为空!')
if siteName == '':
- siteName = public.M('sites').where('id=?', (mid,)).getField('name')
+ siteName = mw.M('sites').where('id=?', (mid,)).getField('name')
# self.closeHasPwd(get)
filename = self.passPath + '/' + siteName + '.pass'
print filename
- passconf = username + ':' + public.hasPwd(password)
+ passconf = username + ':' + mw.hasPwd(password)
if siteName == 'phpmyadmin':
configFile = self.getHostConf('phpmyadmin')
@@ -1073,7 +1073,7 @@ class site_api:
configFile = self.getHostConf(siteName)
# 处理Nginx配置
- conf = public.readFile(configFile)
+ conf = mw.readFile(configFile)
if conf:
rep = '#error_page 404 /404.html;'
if conf.find(rep) == -1:
@@ -1084,24 +1084,24 @@ class site_api:
auth_basic_user_file %s;
# AUTH_END''' % (filename,)
conf = conf.replace(rep, rep + data)
- public.writeFile(configFile, conf)
+ mw.writeFile(configFile, conf)
# 写密码配置
passDir = self.passPath
if not os.path.exists(passDir):
- public.execShell('mkdir -p ' + passDir)
- public.writeFile(filename, passconf)
+ mw.execShell('mkdir -p ' + passDir)
+ mw.writeFile(filename, passconf)
- public.restartWeb()
- msg = public.getInfo('设置网站[{1}]为需要密码认证!', (siteName,))
- public.writeLog("网站管理", msg)
- return public.returnJson(True, '设置成功!')
+ mw.restartWeb()
+ msg = mw.getInfo('设置网站[{1}]为需要密码认证!', (siteName,))
+ mw.writeLog("网站管理", msg)
+ return mw.returnJson(True, '设置成功!')
# 取消目录加密
def closeHasPwdApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
mid = request.form.get('id', '')
if siteName == '':
- siteName = public.M('sites').where('id=?', (mid,)).getField('name')
+ siteName = mw.M('sites').where('id=?', (mid,)).getField('name')
if siteName == 'phpmyadmin':
configFile = self.getHostConf('phpmyadmin')
@@ -1109,15 +1109,15 @@ class site_api:
configFile = self.getHostConf(siteName)
if os.path.exists(configFile):
- conf = public.readFile(configFile)
+ conf = mw.readFile(configFile)
rep = "\n\s*#AUTH_START(.|\n){1,200}#AUTH_END"
conf = re.sub(rep, '', conf)
- public.writeFile(configFile, conf)
+ mw.writeFile(configFile, conf)
- public.restartWeb()
- msg = public.getInfo('清除网站[{1}]的密码认证!', (siteName,))
- public.writeLog("网站管理", msg)
- return public.returnJson(True, '设置成功!')
+ mw.restartWeb()
+ msg = mw.getInfo('清除网站[{1}]的密码认证!', (siteName,))
+ mw.writeLog("网站管理", msg)
+ return mw.returnJson(True, '设置成功!')
def delDomainApi(self):
domain = request.form.get('domain', '').encode('utf-8')
@@ -1125,15 +1125,15 @@ class site_api:
port = request.form.get('port', '').encode('utf-8')
pid = request.form.get('id', '')
- find = public.M('domain').where("pid=? AND name=?",
- (pid, domain)).field('id,name').find()
+ find = mw.M('domain').where("pid=? AND name=?",
+ (pid, domain)).field('id,name').find()
- domain_count = public.M('domain').where("pid=?", (pid,)).count()
+ domain_count = mw.M('domain').where("pid=?", (pid,)).count()
if domain_count == 1:
- return public.returnJson(False, '最后一个域名不能删除!')
+ return mw.returnJson(False, '最后一个域名不能删除!')
file = self.getHostConf(webname)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if conf:
# 删除域名
rep = "server_name\s+(.+);"
@@ -1145,19 +1145,19 @@ class site_api:
# 删除端口
rep = "listen\s+([0-9]+);"
tmp = re.findall(rep, conf)
- port_count = public.M('domain').where(
+ port_count = mw.M('domain').where(
'pid=? AND port=?', (pid, port)).count()
- if public.inArray(tmp, port) == True and port_count < 2:
+ if mw.inArray(tmp, port) == True and port_count < 2:
rep = "\n*\s+listen\s+" + port + ";"
conf = re.sub(rep, '', conf)
# 保存配置
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
- public.M('domain').where("id=?", (find['id'],)).delete()
- msg = public.getInfo('网站[{1}]删除域名[{2}]成功!', (webname, domain))
- public.writeLog('网站管理', msg)
- public.restartWeb()
- return public.returnJson(True, '站点删除成功!')
+ mw.M('domain').where("id=?", (find['id'],)).delete()
+ msg = mw.getInfo('网站[{1}]删除域名[{2}]成功!', (webname, domain))
+ mw.writeLog('网站管理', msg)
+ mw.restartWeb()
+ return mw.returnJson(True, '站点删除成功!')
def deleteApi(self):
sid = request.form.get('id', '').encode('utf-8')
@@ -1168,7 +1168,7 @@ class site_api:
def getProxyListApi(self):
siteName = request.form.get('siteName', '').encode('utf-8')
conf_path = self.getHostConf(siteName)
- old_conf = public.readFile(conf_path)
+ old_conf = mw.readFile(conf_path)
rep = "(#PROXY-START(\n|.)+#PROXY-END)"
url_rep = "proxy_pass (.*);|ProxyPass\s/\s(.*)|Host\s(.*);"
host_rep = "Host\s(.*);"
@@ -1193,10 +1193,10 @@ class site_api:
# 备份并替换老虚拟主机配置文件
os.system("cp %s %s_bak" % (conf_path, conf_path))
conf = re.sub(rep, "", old_conf)
- public.writeFile(conf_path, conf)
+ mw.writeFile(conf_path, conf)
# self.createProxy(get)
- public.restartWeb()
+ mw.restartWeb()
proxyUrl = self.__read_config(self.__proxyfile)
sitename = sitename
@@ -1204,61 +1204,61 @@ class site_api:
for i in proxyUrl:
if i["sitename"] == sitename:
proxylist.append(i)
- return public.getJson(proxylist)
+ return mw.getJson(proxylist)
def getSiteTypesApi(self):
# 取网站分类
- data = public.M("site_types").field("id,name").order("id asc").select()
+ data = mw.M("site_types").field("id,name").order("id asc").select()
data.insert(0, {"id": 0, "name": "默认分类"})
- return public.getJson(data)
+ return mw.getJson(data)
def getSiteDocApi(self):
stype = request.form.get('type', '0').strip().encode('utf-8')
vlist = []
vlist.append('')
- vlist.append(public.getServerDir() +
+ vlist.append(mw.getServerDir() +
'/openresty/nginx/html/index.html')
- vlist.append(public.getServerDir() + '/openresty/nginx/html/404.html')
- vlist.append(public.getServerDir() +
+ vlist.append(mw.getServerDir() + '/openresty/nginx/html/404.html')
+ vlist.append(mw.getServerDir() +
'/openresty/nginx/html/index.html')
- vlist.append(public.getServerDir() + '/web_conf/stop/index.html')
+ vlist.append(mw.getServerDir() + '/web_conf/stop/index.html')
data = {}
data['path'] = vlist[int(stype)]
- return public.returnJson(True, 'ok', data)
+ return mw.returnJson(True, 'ok', data)
def addSiteTypeApi(self):
name = request.form.get('name', '').strip().encode('utf-8')
if not name:
- return public.returnJson(False, "分类名称不能为空")
+ return mw.returnJson(False, "分类名称不能为空")
if len(name) > 18:
- return public.returnJson(False, "分类名称长度不能超过6个汉字或18位字母")
- if public.M('site_types').count() >= 10:
- return public.returnJson(False, '最多添加10个分类!')
- if public.M('site_types').where('name=?', (name,)).count() > 0:
- return public.returnJson(False, "指定分类名称已存在!")
- public.M('site_types').add("name", (name,))
- return public.returnJson(True, '添加成功!')
+ return mw.returnJson(False, "分类名称长度不能超过6个汉字或18位字母")
+ if mw.M('site_types').count() >= 10:
+ return mw.returnJson(False, '最多添加10个分类!')
+ if mw.M('site_types').where('name=?', (name,)).count() > 0:
+ return mw.returnJson(False, "指定分类名称已存在!")
+ mw.M('site_types').add("name", (name,))
+ return mw.returnJson(True, '添加成功!')
def removeSiteTypeApi(self):
mid = request.form.get('id', '').encode('utf-8')
- if public.M('site_types').where('id=?', (mid,)).count() == 0:
- return public.returnJson(False, "指定分类不存在!")
- public.M('site_types').where('id=?', (mid,)).delete()
- public.M("sites").where("type_id=?", (mid,)).save("type_id", (0,))
- return public.returnJson(True, "分类已删除!")
+ if mw.M('site_types').where('id=?', (mid,)).count() == 0:
+ return mw.returnJson(False, "指定分类不存在!")
+ mw.M('site_types').where('id=?', (mid,)).delete()
+ mw.M("sites").where("type_id=?", (mid,)).save("type_id", (0,))
+ return mw.returnJson(True, "分类已删除!")
def modifySiteTypeNameApi(self):
# 修改网站分类名称
name = request.form.get('name', '').strip().encode('utf-8')
mid = request.form.get('id', '').encode('utf-8')
if not name:
- return public.returnJson(False, "分类名称不能为空")
+ return mw.returnJson(False, "分类名称不能为空")
if len(name) > 18:
- return public.returnJson(False, "分类名称长度不能超过6个汉字或18位字母")
- if public.M('site_types').where('id=?', (mid,)).count() == 0:
- return public.returnJson(False, "指定分类不存在!")
- public.M('site_types').where('id=?', (mid,)).setField('name', name)
- return public.returnJson(True, "修改成功!")
+ return mw.returnJson(False, "分类名称长度不能超过6个汉字或18位字母")
+ if mw.M('site_types').where('id=?', (mid,)).count() == 0:
+ return mw.returnJson(False, "指定分类不存在!")
+ mw.M('site_types').where('id=?', (mid,)).setField('name', name)
+ return mw.returnJson(True, "修改成功!")
def setSiteTypeApi(self):
# 设置指定站点的分类
@@ -1266,8 +1266,8 @@ class site_api:
mid = request.form.get('id', '').encode('utf-8')
site_ids = json.loads(site_ids)
for sid in site_ids:
- print public.M('sites').where('id=?', (sid,)).setField('type_id', mid)
- return public.returnJson(True, "设置成功!")
+ print mw.M('sites').where('id=?', (sid,)).setField('type_id', mid)
+ return mw.returnJson(True, "设置成功!")
##### ----- end ----- ###
@@ -1312,7 +1312,7 @@ class site_api:
def getSitePath(self, siteName):
file = self.getHostConf(siteName)
if os.path.exists(file):
- conf = public.readFile(file)
+ conf = mw.readFile(file)
rep = '\s*root\s*(.+);'
path = re.search(rep, conf).groups()[0]
return path
@@ -1320,13 +1320,13 @@ class site_api:
# 取当站点前运行目录
def getSiteRunPath(self, mid):
- siteName = public.M('sites').where('id=?', (mid,)).getField('name')
- sitePath = public.M('sites').where('id=?', (mid,)).getField('path')
+ siteName = mw.M('sites').where('id=?', (mid,)).getField('name')
+ sitePath = mw.M('sites').where('id=?', (mid,)).getField('path')
path = sitePath
filename = self.getHostConf(siteName)
if os.path.exists(filename):
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
rep = '\s*root\s*(.+);'
path = re.search(rep, conf).groups()[0]
@@ -1361,23 +1361,23 @@ class site_api:
return self.rewritePath + '/' + siteName + '_' + dirname + '.conf'
def getIndexConf(self):
- return public.getServerDir() + '/openresty/nginx/conf/nginx.conf'
+ return mw.getServerDir() + '/openresty/nginx/conf/nginx.conf'
def getDomain(self, pid):
- _list = public.M('domain').where("pid=?", (pid,)).field(
+ _list = mw.M('domain').where("pid=?", (pid,)).field(
'id,pid,name,port,addtime').select()
- return public.getJson(_list)
+ return mw.getJson(_list)
def getLogs(self, siteName):
- logPath = public.getLogsDir() + '/' + siteName + '.log'
+ logPath = mw.getLogsDir() + '/' + siteName + '.log'
if not os.path.exists(logPath):
- return public.returnJson(False, '日志为空')
- return public.returnJson(True, public.getNumLines(logPath, 100))
+ return mw.returnJson(False, '日志为空')
+ return mw.returnJson(True, mw.getNumLines(logPath, 100))
# 取日志状态
def getLogsStatus(self, siteName):
filename = self.getHostConf(siteName)
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
if conf.find('#ErrorLog') != -1:
return False
if conf.find("access_log /dev/null") != -1:
@@ -1387,55 +1387,55 @@ class site_api:
# 取目录加密状态
def getHasPwd(self, siteName):
filename = self.getHostConf(siteName)
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
if conf.find('#AUTH_START') != -1:
return True
return False
def getSitePhpVersion(self, siteName):
- conf = public.readFile(self.getHostConf(siteName))
+ conf = mw.readFile(self.getHostConf(siteName))
rep = "enable-php-([0-9]{2,3})\.conf"
tmp = re.search(rep, conf).groups()
data = {}
data['phpversion'] = tmp[0]
- return public.getJson(data)
+ return mw.getJson(data)
def getIndex(self, sid):
- siteName = public.M('sites').where("id=?", (sid,)).getField('name')
+ siteName = mw.M('sites').where("id=?", (sid,)).getField('name')
file = self.getHostConf(siteName)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
rep = "\s+index\s+(.+);"
tmp = re.search(rep, conf).groups()
return tmp[0].replace(' ', ',')
def setIndex(self, sid, index):
if index.find('.') == -1:
- return public.returnJson(False, '默认文档格式不正确,例:index.html')
+ return mw.returnJson(False, '默认文档格式不正确,例:index.html')
index = index.replace(' ', '')
index = index.replace(',,', ',')
if len(index) < 3:
- return public.returnJson(False, '默认文档不能为空!')
+ return mw.returnJson(False, '默认文档不能为空!')
- siteName = public.M('sites').where("id=?", (sid,)).getField('name')
+ siteName = mw.M('sites').where("id=?", (sid,)).getField('name')
index_l = index.replace(",", " ")
file = self.getHostConf(siteName)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if conf:
rep = "\s+index\s+.+;"
conf = re.sub(rep, "\n\tindex " + index_l + ";", conf)
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
- public.writeLog('TYPE_SITE', 'SITE_INDEX_SUCCESS', (siteName, index_l))
- return public.returnJson(True, '设置成功!')
+ mw.writeLog('TYPE_SITE', 'SITE_INDEX_SUCCESS', (siteName, index_l))
+ return mw.returnJson(True, '设置成功!')
def getLimitNet(self, sid):
- siteName = public.M('sites').where("id=?", (sid,)).getField('name')
+ siteName = mw.M('sites').where("id=?", (sid,)).getField('name')
filename = self.getHostConf(siteName)
# 站点总并发
data = {}
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
try:
rep = "\s+limit_conn\s+perserver\s+([0-9]+);"
tmp = re.search(rep, conf).groups()
@@ -1455,15 +1455,15 @@ class site_api:
data['perip'] = 0
data['limit_rate'] = 0
- return public.getJson(data)
+ return mw.getJson(data)
def checkIndexConf(self):
limit = self.getIndexConf()
- nginxConf = public.readFile(limit)
+ nginxConf = mw.readFile(limit)
limitConf = "limit_conn_zone $binary_remote_addr zone=perip:10m;\n\t\tlimit_conn_zone $server_name zone=perserver:10m;"
nginxConf = nginxConf.replace(
"#limit_conn_zone $binary_remote_addr zone=perip:10m;", limitConf)
- public.writeFile(limit, nginxConf)
+ mw.writeFile(limit, nginxConf)
def saveLimitNet(self, sid, perserver, perip, limit_rate):
@@ -1471,10 +1471,10 @@ class site_api:
str_perip = 'limit_conn perip ' + perip + ';'
str_limit_rate = 'limit_rate ' + limit_rate + 'k;'
- siteName = public.M('sites').where("id=?", (sid,)).getField('name')
+ siteName = mw.M('sites').where("id=?", (sid,)).getField('name')
filename = self.getHostConf(siteName)
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
if(conf.find('limit_conn perserver') != -1):
# 替换总并发
rep = "limit_conn\s+perserver\s+([0-9]+);"
@@ -1491,15 +1491,15 @@ class site_api:
conf = conf.replace('#error_page 404/404.html;', "#error_page 404/404.html;\n " +
str_perserver + "\n " + str_perip + "\n " + str_limit_rate)
- public.writeFile(filename, conf)
- public.restartWeb()
- public.writeLog('TYPE_SITE', 'SITE_NETLIMIT_OPEN_SUCCESS', (siteName,))
- return public.returnJson(True, '设置成功!')
+ mw.writeFile(filename, conf)
+ mw.restartWeb()
+ mw.writeLog('TYPE_SITE', 'SITE_NETLIMIT_OPEN_SUCCESS', (siteName,))
+ return mw.returnJson(True, '设置成功!')
def closeLimitNet(self, sid):
- siteName = public.M('sites').where("id=?", (sid,)).getField('name')
+ siteName = mw.M('sites').where("id=?", (sid,)).getField('name')
filename = self.getHostConf(siteName)
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
# 清理总并发
rep = "\s+limit_conn\s+perserver\s+([0-9]+);"
conf = re.sub(rep, '', conf)
@@ -1511,15 +1511,15 @@ class site_api:
# 清理请求流量限制
rep = "\s+limit_rate\s+([0-9]+)\w+;"
conf = re.sub(rep, '', conf)
- public.writeFile(filename, conf)
- public.restartWeb()
- public.writeLog(
+ mw.writeFile(filename, conf)
+ mw.restartWeb()
+ mw.writeLog(
'TYPE_SITE', 'SITE_NETLIMIT_CLOSE_SUCCESS', (siteName,))
- return public.returnJson(True, '已关闭流量限制!')
+ return mw.returnJson(True, '已关闭流量限制!')
def getSecurity(self, sid, name):
filename = self.getHostConf(name)
- conf = public.readFile(filename)
+ conf = mw.readFile(filename)
data = {}
if conf.find('SECURITY-START') != -1:
rep = "#SECURITY-START(\n|.){1,500}#SECURITY-END"
@@ -1531,25 +1531,25 @@ class site_api:
data['status'] = True
else:
data['fix'] = 'jpg,jpeg,gif,png,js,css'
- domains = public.M('domain').where(
+ domains = mw.M('domain').where(
'pid=?', (sid,)).field('name').select()
tmp = []
for domain in domains:
tmp.append(domain['name'])
data['domains'] = ','.join(tmp)
data['status'] = False
- return public.getJson(data)
+ return mw.getJson(data)
def setSecurity(self, sid, name, fix, domains, status):
if len(fix) < 2:
- return public.returnJson(False, 'URL后缀不能为空!')
+ return mw.returnJson(False, 'URL后缀不能为空!')
file = self.getHostConf(name)
if os.path.exists(file):
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if conf.find('SECURITY-START') != -1:
rep = "\s{0,4}#SECURITY-START(\n|.){1,500}#SECURITY-END\n?"
conf = re.sub(rep, '', conf)
- public.writeLog('网站管理', '站点[' + name + ']已关闭防盗链设置!')
+ mw.writeLog('网站管理', '站点[' + name + ']已关闭防盗链设置!')
else:
rconf = '''#SECURITY-START 防盗链配置
location ~ .*\.(%s)$
@@ -1564,10 +1564,10 @@ location ~ .*\.(%s)$
# SECURITY-END
include enable-php-''' % (fix.strip().replace(',', '|'), domains.strip().replace(',', ' '))
conf = re.sub("include\s+enable-php-", rconf, conf)
- public.writeLog('网站管理', '站点[' + name + ']已开启防盗链!')
- public.writeFile(file, conf)
- public.restartWeb()
- return public.returnJson(True, '设置成功!')
+ mw.writeLog('网站管理', '站点[' + name + ']已开启防盗链!')
+ mw.writeFile(file, conf)
+ mw.restartWeb()
+ return mw.returnJson(True, '设置成功!')
def getPhpVersion(self):
phpVersions = ('00', '52', '53', '54', '55',
@@ -1580,18 +1580,18 @@ include enable-php-''' % (fix.strip().replace(',', '|'), domains.strip().replace
tmp['name'] = '纯静态'
data.append(tmp)
- checkPath = public.getServerDir() + '/php/' + val + '/bin/php'
+ checkPath = mw.getServerDir() + '/php/' + val + '/bin/php'
if os.path.exists(checkPath):
tmp['version'] = val
tmp['name'] = 'PHP-' + val
data.append(tmp)
- return public.getJson(data)
+ return mw.getJson(data)
# 是否跳转到https
def isToHttps(self, siteName):
file = self.getHostConf(siteName)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if conf:
if conf.find('HTTP_TO_HTTPS_START') != -1:
return True
@@ -1611,13 +1611,13 @@ include enable-php-''' % (fix.strip().replace(',', '|'), domains.strip().replace
def createRootDir(self, path):
if not os.path.exists(path):
os.makedirs(path)
- if not public.isAppleSystem():
- public.execShell('chown -R www:www ' + path)
- public.execShell('chmod -R 755 ' + path)
+ if not mw.isAppleSystem():
+ mw.execShell('chown -R www:www ' + path)
+ mw.execShell('chmod -R 755 ' + path)
def nginxAddDomain(self, webname, domain, port):
file = self.getHostConf(webname)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
if not conf:
return
@@ -1625,25 +1625,25 @@ include enable-php-''' % (fix.strip().replace(',', '|'), domains.strip().replace
rep = "server_name\s*(.*);"
tmp = re.search(rep, conf).group()
domains = tmp.split(' ')
- if not public.inArray(domains, domain):
+ if not mw.inArray(domains, domain):
newServerName = tmp.replace(';', ' ' + domain + ';')
conf = conf.replace(tmp, newServerName)
# 添加端口
rep = "listen\s+([0-9]+)\s*[default_server]*\s*;"
tmp = re.findall(rep, conf)
- if not public.inArray(tmp, port):
+ if not mw.inArray(tmp, port):
listen = re.search(rep, conf).group()
conf = conf.replace(
listen, listen + "\n\tlisten " + port + ';')
# 保存配置文件
- public.writeFile(file, conf)
+ mw.writeFile(file, conf)
return True
def nginxAddConf(self):
- source_tpl = public.getRunDir() + '/data/tpl/nginx.conf'
+ source_tpl = mw.getRunDir() + '/data/tpl/nginx.conf'
vhost_file = self.vhostPath + '/' + self.siteName + '.conf'
- content = public.readFile(source_tpl)
+ content = mw.readFile(source_tpl)
content = content.replace('{$PORT}', self.sitePort)
content = content.replace('{$SERVER_NAME}', self.siteName)
@@ -1651,9 +1651,9 @@ include enable-php-''' % (fix.strip().replace(',', '|'), domains.strip().replace
content = content.replace('{$PHPVER}', self.phpVersion)
content = content.replace('{$OR_REWRITE}', self.rewritePath)
- logsPath = public.getLogsDir()
+ logsPath = mw.getLogsDir()
content = content.replace('{$LOGPATH}', logsPath)
- public.writeFile(vhost_file, content)
+ mw.writeFile(vhost_file, content)
rewrite_content = '''
location /{
@@ -1664,7 +1664,7 @@ location /{
}
'''
rewrite_file = self.rewritePath + '/' + self.siteName + '.conf'
- public.writeFile(rewrite_file, rewrite_content)
+ mw.writeFile(rewrite_file, rewrite_content)
def add(self, webname, port, ps, path, version):
@@ -1676,18 +1676,18 @@ location /{
self.sitePort = port.strip().replace(' ', '')
self.phpVersion = version
- if public.M('sites').where("name=?", (self.siteName,)).count():
- return public.returnJson(False, '您添加的站点已存在!')
+ if mw.M('sites').where("name=?", (self.siteName,)).count():
+ return mw.returnJson(False, '您添加的站点已存在!')
# 写入数据库
- pid = public.M('sites').add('name,path,status,ps,edate,addtime,type_id',
- (self.siteName, self.sitePath, '1', ps, '0000-00-00', public.getDate(), 0,))
- opid = public.M('domain').where(
+ pid = mw.M('sites').add('name,path,status,ps,edate,addtime,type_id',
+ (self.siteName, self.sitePath, '1', ps, '0000-00-00', mw.getDate(), 0,))
+ opid = mw.M('domain').where(
"name=?", (self.siteName,)).getField('pid')
if opid:
- if public.M('sites').where('id=?', (opid,)).count():
- return public.returnJson(False, '您添加的域名已存在!')
- public.M('domain').where('pid=?', (opid,)).delete()
+ if mw.M('sites').where('id=?', (opid,)).count():
+ return mw.returnJson(False, '您添加的域名已存在!')
+ mw.M('domain').where('pid=?', (opid,)).delete()
# 添加更多域名
for domain in siteMenu['domainlist']:
@@ -1696,20 +1696,20 @@ location /{
spid = str(pid)
# self.addDomain(domain, webname, pid)
- public.M('domain').add('pid,name,port,addtime',
- (pid, self.siteName, self.sitePort, public.getDate()))
+ mw.M('domain').add('pid,name,port,addtime',
+ (pid, self.siteName, self.sitePort, mw.getDate()))
self.createRootDir(self.sitePath)
self.nginxAddConf()
data = {}
data['siteStatus'] = False
- public.restartWeb()
- return public.returnJson(True, '添加成功')
+ mw.restartWeb()
+ return mw.returnJson(True, '添加成功')
def deleteWSLogs(self, webname):
- assLogPath = public.getLogsDir() + '/' + webname + '.log'
- errLogPath = public.getLogsDir() + '/' + webname + '.error.log'
+ assLogPath = mw.getLogsDir() + '/' + webname + '.log'
+ errLogPath = mw.getLogsDir() + '/' + webname + '.error.log'
confFile = self.setupPath + '/nginx/vhost/' + webname + '.conf'
rewriteFile = self.setupPath + '/nginx/rewrite/' + webname + '.conf'
rewriteFile = self.setupPath + '/nginx/pass/' + webname + '.conf'
@@ -1722,29 +1722,29 @@ location /{
keyPath,
certPath]
for i in logs:
- public.deleteFile(i)
+ mw.deleteFile(i)
def delete(self, sid, webname, path):
self.deleteWSLogs(webname)
if path == '1':
- rootPath = public.getWwwDir() + '/' + webname
- public.execShell('rm -rf ' + rootPath)
+ rootPath = mw.getWwwDir() + '/' + webname
+ mw.execShell('rm -rf ' + rootPath)
- public.M('sites').where("id=?", (sid,)).delete()
- public.restartWeb()
- return public.returnJson(True, '站点删除成功!')
+ mw.M('sites').where("id=?", (sid,)).delete()
+ mw.restartWeb()
+ return mw.returnJson(True, '站点删除成功!')
def setEndDate(self, sid, edate):
- result = public.M('sites').where(
+ result = mw.M('sites').where(
'id=?', (sid,)).setField('edate', edate)
- siteName = public.M('sites').where('id=?', (sid,)).getField('name')
- public.writeLog('TYPE_SITE', '设置成功,站点到期后将自动停止!', (siteName, edate))
- return public.returnJson(True, '设置成功,站点到期后将自动停止!')
+ siteName = mw.M('sites').where('id=?', (sid,)).getField('name')
+ mw.writeLog('TYPE_SITE', '设置成功,站点到期后将自动停止!', (siteName, edate))
+ return mw.returnJson(True, '设置成功,站点到期后将自动停止!')
# ssl相关方法 start
def setSslConf(self, siteName):
file = self.getHostConf(siteName)
- conf = public.readFile(file)
+ conf = mw.readFile(file)
keyPath = self.sslDir + siteName + '/privkey.pem'
certPath = self.sslDir + siteName + '/fullchain.pem'
@@ -1761,47 +1761,47 @@ location /{
error_page 497 https://$host$request_uri;
""" % (certPath, keyPath)
if(conf.find('ssl_certificate') != -1):
- return public.returnData(True, 'SSL开启成功!')
+ return mw.returnData(True, 'SSL开启成功!')
conf = conf.replace('#error_page 404/404.html;', sslStr)
rep = "listen\s+([0-9]+)\s*[default_server]*;"
tmp = re.findall(rep, conf)
- if not public.inArray(tmp, '443'):
+ if not mw.inArray(tmp, '443'):
listen = re.search(rep, conf).group()
conf = conf.replace(
listen, listen + "\n\tlisten 443 ssl http2;")
shutil.copyfile(file, '/tmp/backup.conf')
- public.writeFile(file, conf)
- isError = public.checkWebConfig()
+ mw.writeFile(file, conf)
+ isError = mw.checkWebConfig()
if(isError != True):
shutil.copyfile('/tmp/backup.conf', file)
- return public.returnData(False, '证书错误:
' + isError.replace("\n", '
') + '')
+ return mw.returnData(False, '证书错误:
' + isError.replace("\n", '
') + '')
- public.restartWeb()
+ mw.restartWeb()
self.saveCert(keyPath, certPath)
- msg = public.getInfo('网站[{1}]开启SSL成功!', siteName)
- public.writeLog('网站管理', msg)
- return public.returnData(True, 'SSL开启成功!')
+ msg = mw.getInfo('网站[{1}]开启SSL成功!', siteName)
+ mw.writeLog('网站管理', msg)
+ return mw.returnData(True, 'SSL开启成功!')
def saveCert(self, keyPath, certPath):
try:
certInfo = self.getCertName(certPath)
if not certInfo:
- return public.returnData(False, '证书解析失败!')
+ return mw.returnData(False, '证书解析失败!')
vpath = self.sslDir + certInfo['subject']
if not os.path.exists(vpath):
os.system('mkdir -p ' + vpath)
- public.writeFile(vpath + '/privkey.pem',
- public.readFile(keyPath))
- public.writeFile(vpath + '/fullchain.pem',
- public.readFile(certPath))
- public.writeFile(vpath + '/info.json', json.dumps(certInfo))
- return public.returnData(True, '证书保存成功!')
+ mw.writeFile(vpath + '/privkey.pem',
+ mw.readFile(keyPath))
+ mw.writeFile(vpath + '/fullchain.pem',
+ mw.readFile(certPath))
+ mw.writeFile(vpath + '/info.json', json.dumps(certInfo))
+ return mw.returnData(True, '证书保存成功!')
except Exception as e:
- return public.returnData(False, '证书保存失败!')
+ return mw.returnData(False, '证书保存失败!')
# 获取证书名称
def getCertName(self, certPath):
@@ -1809,7 +1809,7 @@ location /{
openssl = '/usr/local/openssl/bin/openssl'
if not os.path.exists(openssl):
openssl = 'openssl'
- result = public.execShell(
+ result = mw.execShell(
openssl + " x509 -in " + certPath + " -noout -subject -enddate -startdate -issuer")
tmp = result[0].split("\n")
data = {}
@@ -1819,7 +1819,7 @@ location /{
data['issuer'] = tmp[3].split('O=')[-1].split(',')[0]
if data['issuer'].find('/') != -1:
data['issuer'] = data['issuer'].split('/')[0]
- result = public.execShell(
+ result = mw.execShell(
openssl + " x509 -in " + certPath + " -noout -text|grep DNS")
data['dns'] = result[0].replace(
'DNS:', '').replace(' ', '').strip().split(',')
@@ -1840,8 +1840,8 @@ location /{
useriniPath = npath + '/.user.ini'
if not os.path.exists(useriniPath):
continue
- public.execShell('which chattr && chattr -i ' + useriniPath)
- public.execShell('rm -f ' + useriniPath)
+ mw.execShell('which chattr && chattr -i ' + useriniPath)
+ mw.execShell('rm -f ' + useriniPath)
except:
continue
return True
@@ -1850,16 +1850,16 @@ location /{
def setDirUserINI(self, newPath):
filename = newPath + '/.user.ini'
if os.path.exists(filename):
- public.execShell("chattr -i " + filename)
+ mw.execShell("chattr -i " + filename)
os.remove(filename)
- return public.returnJson(True, '已清除防跨站设置!')
+ return mw.returnJson(True, '已清除防跨站设置!')
self.delUserInI(newPath)
- public.writeFile(filename, 'open_basedir=' +
- newPath + '/:/tmp/:/proc/')
- public.execShell("chattr +i " + filename)
+ mw.writeFile(filename, 'open_basedir=' +
+ newPath + '/:/tmp/:/proc/')
+ mw.execShell("chattr +i " + filename)
- return public.returnJson(True, '已打开防跨站设置!')
+ return mw.returnJson(True, '已打开防跨站设置!')
# 转换时间
def strfToTime(self, sdate):
diff --git a/class/core/system_api.py b/class/core/system_api.py
index a54533e1e..b1ac395ed 100755
--- a/class/core/system_api.py
+++ b/class/core/system_api.py
@@ -11,7 +11,7 @@ from flask import Flask, session
from flask import request
import db
-import public
+import mw
import config_api
@@ -31,12 +31,12 @@ class system_api:
pids = None
def __init__(self):
- self.setupPath = public.getServerDir()
+ self.setupPath = mw.getServerDir()
##### ----- start ----- ###
def networkApi(self):
data = self.getNetWork()
- return public.getJson(data)
+ return mw.getJson(data)
def updateServerApi(self):
stype = request.args.get('type', 'check')
@@ -45,11 +45,11 @@ class system_api:
def systemTotalApi(self):
data = self.getSystemTotal()
- return public.getJson(data)
+ return mw.getJson(data)
def diskInfoApi(self):
diskInfo = self.getDiskInfo()
- return public.getJson(diskInfo)
+ return mw.getJson(diskInfo)
def setControlApi(self):
stype = request.form.get('type', '')
@@ -61,58 +61,58 @@ class system_api:
start = request.args.get('start', '')
end = request.args.get('end', '')
data = self.getLoadAverageData(start, end)
- return public.getJson(data)
+ return mw.getJson(data)
def getCpuIoApi(self):
start = request.args.get('start', '')
end = request.args.get('end', '')
data = self.getCpuIoData(start, end)
- return public.getJson(data)
+ return mw.getJson(data)
def getDiskIoApi(self):
start = request.args.get('start', '')
end = request.args.get('end', '')
data = self.getDiskIoData(start, end)
- return public.getJson(data)
+ return mw.getJson(data)
def getNetworkIoApi(self):
start = request.args.get('start', '')
end = request.args.get('end', '')
data = self.getNetWorkIoData(start, end)
- return public.getJson(data)
+ return mw.getJson(data)
def rememoryApi(self):
os.system('sync')
- scriptFile = public.getRunDir() + '/script/rememory.sh'
- public.execShell("/bin/bash " + scriptFile)
+ scriptFile = mw.getRunDir() + '/script/rememory.sh'
+ mw.execShell("/bin/bash " + scriptFile)
data = self.getMemInfo()
- return public.getJson(data)
+ return mw.getJson(data)
# 重启面板
def restartApi(self):
self.restartMw()
- return public.returnJson(True, '面板已重启!')
+ return mw.returnJson(True, '面板已重启!')
def restartServerApi(self):
- if public.isAppleSystem():
- return public.returnJson(False, "开发环境不可重起")
+ if mw.isAppleSystem():
+ return mw.returnJson(False, "开发环境不可重起")
self.restartServer()
- return public.returnJson(True, '正在重启服务器!')
+ return mw.returnJson(True, '正在重启服务器!')
##### ----- end ----- ###
@async
def restartMw(self):
sleep(1)
- cmd = public.getRunDir() + '/scripts/init.d/mw restart'
- #print cmd
- public.execShell(cmd)
+ cmd = mw.getRunDir() + '/scripts/init.d/mw restart'
+ # print cmd
+ mw.execShell(cmd)
@async
def restartServer(self):
- if not public.isRestart():
- return public.returnJson(False, '请等待所有安装任务完成再执行!')
- public.execShell("sync && init 6 &")
- return public.returnJson(True, '命令发送成功!')
+ if not mw.isRestart():
+ return mw.returnJson(False, '请等待所有安装任务完成再执行!')
+ mw.execShell("sync && init 6 &")
+ return mw.returnJson(True, '命令发送成功!')
# 名取PID
def getPid(self, pname):
@@ -150,30 +150,30 @@ class system_api:
def getPanelInfo(self, get=None):
# 取面板配置
- address = public.GetLocalIp()
+ address = mw.GetLocalIp()
try:
try:
port = web.ctx.host.split(':')[1]
except:
- port = public.readFile('data/port.pl')
+ port = mw.readFile('data/port.pl')
except:
port = '8888'
domain = ''
if os.path.exists('data/domain.conf'):
- domain = public.readFile('data/domain.conf')
+ domain = mw.readFile('data/domain.conf')
autoUpdate = ''
if os.path.exists('data/autoUpdate.pl'):
autoUpdate = 'checked'
limitip = ''
if os.path.exists('data/limitip.conf'):
- limitip = public.readFile('data/limitip.conf')
+ limitip = mw.readFile('data/limitip.conf')
templates = []
for template in os.listdir('templates/'):
if os.path.isdir('templates/' + template):
templates.append(template)
- template = public.readFile('data/templates.pl')
+ template = mw.readFile('data/templates.pl')
check502 = ''
if os.path.exists('data/502Task.pl'):
@@ -188,7 +188,7 @@ class system_api:
data['cpuRealUsed'] = cpu[0]
data['time'] = self.getBootTime()
data['system'] = self.getSystemVersion()
- data['isuser'] = public.M('users').where(
+ data['isuser'] = mw.M('users').where(
'username=?', ('admin',)).count()
data['version'] = '0.0.1'
return data
@@ -225,22 +225,22 @@ class system_api:
titlePl = 'data/title.pl'
title = 'Linux面板'
if os.path.exists(titlePl):
- title = public.readFile(titlePl).strip()
+ title = mw.readFile(titlePl).strip()
return title
def getSystemVersion(self):
# 取操作系统版本
- if public.getOs() == 'darwin':
- data = public.execShell('sw_vers')[0]
+ if mw.getOs() == 'darwin':
+ data = mw.execShell('sw_vers')[0]
data_list = data.strip().split("\n")
mac_version = ''
for x in data_list:
mac_version += x.split("\t")[1] + ' '
return mac_version
- version = public.readFile('/etc/redhat-release')
+ version = mw.readFile('/etc/redhat-release')
if not version:
- version = public.readFile(
+ version = mw.readFile(
'/etc/issue').strip().split("\n")[0].replace('\\n', '').replace('\l', '').strip()
else:
version = version.replace('release ', '').strip()
@@ -250,14 +250,14 @@ class system_api:
# 取系统启动时间
start_time = psutil.boot_time()
run_time = time.time() - start_time
- # conf = public.readFile('/proc/uptime').split()
+ # conf = mw.readFile('/proc/uptime').split()
tStr = float(run_time)
min = tStr / 60
hours = min / 60
days = math.floor(hours / 24)
hours = math.floor(hours - (days * 24))
min = math.floor(min - (days * 60 * 24) - (hours * 60))
- return public.getInfo('已不间断运行: {1}天{2}小时{3}分钟', (str(int(days)), str(int(hours)), str(int(min))))
+ return mw.getInfo('已不间断运行: {1}天{2}小时{3}分钟', (str(int(days)), str(int(hours)), str(int(min))))
def getCpuInfo(self, interval=1):
# 取CPU信息
@@ -268,7 +268,7 @@ class system_api:
def getMemInfo(self):
# 取内存信息
mem = psutil.virtual_memory()
- if public.getOs() == 'darwin':
+ if mw.getOs() == 'darwin':
memInfo = {
'memTotal': mem.total / 1024 / 1024
}
@@ -292,7 +292,7 @@ class system_api:
import psutil
mem = psutil.virtual_memory()
- if public.getOs() == 'darwin':
+ if mw.getOs() == 'darwin':
return mem.percent
memInfo = {'memTotal': mem.total / 1024 / 1024, 'memFree': mem.free / 1024 / 1024,
@@ -323,9 +323,9 @@ class system_api:
def getDiskInfo2(self):
# 取磁盘分区信息
- temp = public.execShell(
+ temp = mw.execShell(
"df -h -P|grep '/'|grep -v tmpfs | grep -v devfs")[0]
- tempInodes = public.execShell(
+ tempInodes = mw.execShell(
"df -i -P|grep '/'|grep -v tmpfs | grep -v devfs")[0]
temp1 = temp.split('\n')
tempInodes1 = tempInodes.split('\n')
@@ -423,7 +423,7 @@ class system_api:
else:
os.remove(filename)
count += 1
- public.serviceReload()
+ mw.serviceReload()
os.system('echo > /tmp/panelBoot.pl')
return total, count
@@ -470,10 +470,10 @@ class system_api:
networkIo = psutil.net_io_counters()[:4]
if not os.path.exists(tmpfile):
- public.writeFile(tmpfile, str(
+ mw.writeFile(tmpfile, str(
networkIo[0]) + '|' + str(networkIo[1]) + '|' + str(int(time.time())))
- lastValue = public.readFile(tmpfile).split('|')
+ lastValue = mw.readFile(tmpfile).split('|')
ntime = time.time()
networkInfo = {}
@@ -486,7 +486,7 @@ class system_api:
networkInfo['downPackets'] = networkIo[3]
networkInfo['upPackets'] = networkIo[2]
- public.writeFile(tmpfile, str(
+ mw.writeFile(tmpfile, str(
networkIo[0]) + '|' + str(networkIo[1]) + '|' + str(int(time.time())))
# networkInfo['cpu'] = self.GetCpuInfo(0.1)
@@ -496,24 +496,24 @@ class system_api:
def getNetWorkIoData(self, start, end):
# 取指定时间段的网络Io
- data = public.M('network').dbfile('system').where("addtime>=? AND addtime<=?", (start, end)).field(
+ data = mw.M('network').dbfile('system').where("addtime>=? AND addtime<=?", (start, end)).field(
'id,up,down,total_up,total_down,down_packets,up_packets,addtime').order('id asc').select()
return self.toAddtime(data)
def getDiskIoData(self, start, end):
# 取指定时间段的磁盘Io
- data = public.M('diskio').dbfile('system').where("addtime>=? AND addtime<=?", (start, end)).field(
+ data = mw.M('diskio').dbfile('system').where("addtime>=? AND addtime<=?", (start, end)).field(
'id,read_count,write_count,read_bytes,write_bytes,read_time,write_time,addtime').order('id asc').select()
return self.toAddtime(data)
def getCpuIoData(self, start, end):
# 取指定时间段的CpuIo
- data = public.M('cpuio').dbfile('system').where("addtime>=? AND addtime<=?",
- (start, end)).field('id,pro,mem,addtime').order('id asc').select()
+ data = mw.M('cpuio').dbfile('system').where("addtime>=? AND addtime<=?",
+ (start, end)).field('id,pro,mem,addtime').order('id asc').select()
return self.toAddtime(data, True)
def getLoadAverageData(self, start, end):
- data = public.M('load_average').dbfile('system').where("addtime>=? AND addtime<=?", (
+ data = mw.M('load_average').dbfile('system').where("addtime>=? AND addtime<=?", (
start, end)).field('id,pro,one,five,fifteen,addtime').order('id asc').select()
return self.toAddtime(data)
@@ -559,37 +559,37 @@ class system_api:
filename = 'data/control.conf'
if stype == '0':
- public.execShell("rm -f " + filename)
+ mw.execShell("rm -f " + filename)
elif stype == '1':
_day = int(day)
if _day < 1:
- return public.returnJson(False, "设置失败!")
- public.writeFile(filename, day)
+ return mw.returnJson(False, "设置失败!")
+ mw.writeFile(filename, day)
elif stype == 'del':
- if not public.isRestart():
- return public.returnJson(False, '请等待所有安装任务完成再执行')
+ if not mw.isRestart():
+ return mw.returnJson(False, '请等待所有安装任务完成再执行')
os.remove("data/system.db")
sql = db.Sql().dbfile('system')
- csql = public.readFile('data/sql/system.sql')
+ csql = mw.readFile('data/sql/system.sql')
csql_list = csql.split(';')
for index in range(len(csql_list)):
sql.execute(csql_list[index], ())
- return public.returnJson(True, "监控服务已关闭")
+ return mw.returnJson(True, "监控服务已关闭")
else:
data = {}
if os.path.exists(filename):
try:
- data['day'] = int(public.readFile(filename))
+ data['day'] = int(mw.readFile(filename))
except:
data['day'] = 30
data['status'] = True
else:
data['day'] = 30
data['status'] = False
- return public.getJson(data)
+ return mw.getJson(data)
- return public.returnJson(True, "设置成功!")
+ return mw.returnJson(True, "设置成功!")
def versionDiff(self, old, new):
'''
@@ -619,7 +619,7 @@ class system_api:
def getServerInfo(self):
upAddr = 'https://raw.githubusercontent.com/midoks/mdserver-web/master/version/info.json'
try:
- version = public.httpGet(upAddr)
+ version = mw.httpGet(upAddr)
version = json.loads(version)
return version[0]
except Exception as e:
@@ -629,71 +629,71 @@ class system_api:
def updateServer(self, stype, version=''):
# 更新服务
try:
- if not public.isRestart():
- return public.returnJson(False, '请等待所有安装任务完成再执行!')
+ if not mw.isRestart():
+ return mw.returnJson(False, '请等待所有安装任务完成再执行!')
if stype == 'check':
version_now = config_api.config_api().getVersion()
version_new_info = self.getServerInfo()
if not 'version' in version_new_info:
- return public.returnJson(False, '服务器数据有问题!')
+ return mw.returnJson(False, '服务器数据有问题!')
diff = self.versionDiff(
version_now, version_new_info['version'])
print diff
if diff == 'new':
- return public.returnJson(True, '有新版本!', version_new_info['version'])
+ return mw.returnJson(True, '有新版本!', version_new_info['version'])
elif diff == 'test':
- return public.returnJson(True, '有测试版本!', version_new_info['version'])
+ return mw.returnJson(True, '有测试版本!', version_new_info['version'])
else:
- return public.returnJson(False, '已经是最新,无需更新!')
+ return mw.returnJson(False, '已经是最新,无需更新!')
if stype == 'info':
version_new_info = self.getServerInfo()
version_now = config_api.config_api().getVersion()
if not 'version' in version_new_info:
- return public.returnJson(False, '服务器数据有问题!')
+ return mw.returnJson(False, '服务器数据有问题!')
diff = self.versionDiff(
version_now, version_new_info['version'])
- return public.returnJson(True, '更新信息!', version_new_info)
+ return mw.returnJson(True, '更新信息!', version_new_info)
if stype == 'update':
if version == '':
- return public.returnJson(False, '缺少版本信息!')
+ return mw.returnJson(False, '缺少版本信息!')
v_new_info = self.getServerInfo()
if v_new_info['version'] != version:
- return public.returnJson(False, '更新失败,请重试!')
+ return mw.returnJson(False, '更新失败,请重试!')
if not 'path' in v_new_info or v_new_info['path'] == '':
- return public.returnJson(False, '下载地址不存在!')
+ return mw.returnJson(False, '下载地址不存在!')
newUrl = v_new_info['path']
- toPath = public.getRootDir() + '/temp'
+ toPath = mw.getRootDir() + '/temp'
if not os.path.exists(toPath):
- public.execShell('mkdir -p ' + toPath)
+ mw.execShell('mkdir -p ' + toPath)
if not os.path.exists(toPath + '/mw.zip'):
- public.execShell('wget -O ' + toPath + '/mw.zip ' + newUrl)
+ mw.execShell('wget -O ' + toPath + '/mw.zip ' + newUrl)
- public.execShell('unzip -o ' + toPath + '/mw.zip' + ' -d ./')
- public.execShell('unzip -o mdserver-web.zip -d ./')
- public.execShell('rm -f mdserver-web.zip')
- return public.returnJson(True, '安装更新成功!')
+ mw.execShell('unzip -o ' + toPath + '/mw.zip' + ' -d ./')
+ mw.execShell('unzip -o mdserver-web.zip -d ./')
+ mw.execShell('rm -f mdserver-web.zip')
+ return mw.returnJson(True, '安装更新成功!')
- return public.returnJson(False, '已经是最新,无需更新!')
+ return mw.returnJson(False, '已经是最新,无需更新!')
except Exception as ex:
print 'updateServer', ex
- return public.returnJson(False, "连接服务器失败!")
+ return mw.returnJson(False, "连接服务器失败!")
# 修复面板
def repPanel(self, get):
vp = ''
- if public.readFile('/www/server/mdserver-web/class/common.py').find('checkSafe') != -1:
+ if mw.readFile('/www/server/mdserver-web/class/common.py').find('checkSafe') != -1:
vp = '_pro'
- public.ExecShell("wget -O update.sh " + public.get_url() +
- "/install/update" + vp + ".sh && bash update.sh")
+ mw.ExecShell("wget -O update.sh " + mw.get_url() +
+ "/install/update" + vp + ".sh && bash update.sh")
if hasattr(web.ctx.session, 'getCloudPlugin'):
del(web.ctx.session['getCloudPlugin'])
return True
diff --git a/class/core/task_api.py b/class/core/task_api.py
index 0204aa015..b0bbf1c52 100755
--- a/class/core/task_api.py
+++ b/class/core/task_api.py
@@ -4,7 +4,7 @@ import psutil
import time
import os
import sys
-import public
+import mw
import re
import json
import pwd
@@ -19,7 +19,7 @@ class task_api:
pass
def countApi(self):
- c = public.M('tasks').where("status!=?", ('1',)).count()
+ c = mw.M('tasks').where("status!=?", ('1',)).count()
return str(c)
def listApi(self):
@@ -31,36 +31,36 @@ class task_api:
start = (int(p) - 1) * int(limit)
limit_str = str(start) + ',' + str(limit)
- _list = public.M('tasks').where('', ()).field(
+ _list = mw.M('tasks').where('', ()).field(
'id,name,type,status,addtime,start,end').limit(limit_str).order('id desc').select()
_ret = {}
_ret['data'] = _list
- count = public.M('tasks').where('', ()).count()
+ count = mw.M('tasks').where('', ()).count()
_page = {}
_page['count'] = count
_page['tojs'] = 'remind'
_page['p'] = p
- _ret['page'] = public.getPage(_page)
- return public.getJson(_ret)
+ _ret['page'] = mw.getPage(_page)
+ return mw.getJson(_ret)
def getExecLogApi(self):
file = os.getcwd() + "/tmp/panelExec.log"
- v = public.getLastLine(file, 100)
+ v = mw.getLastLine(file, 100)
return v
def getTaskSpeedApi(self):
tempFile = os.getcwd() + '/tmp/panelExec.log'
freshFile = os.getcwd() + '/tmp/panelFresh'
- find = public.M('tasks').where('status=? OR status=?',
- ('-1', '0')).field('id,type,name,execstr').find()
+ find = mw.M('tasks').where('status=? OR status=?',
+ ('-1', '0')).field('id,type,name,execstr').find()
if not len(find):
- return public.returnJson(False, '当前没有任务队列在执行-2!')
+ return mw.returnJson(False, '当前没有任务队列在执行-2!')
isTask = os.getcwd() + '/tmp/panelTask.pl'
- public.writeFile(isTask, 'True')
+ mw.writeFile(isTask, 'True')
echoMsg = {}
echoMsg['name'] = find['name']
@@ -68,19 +68,19 @@ class task_api:
if find['type'] == 'download':
import json
try:
- tmp = public.readFile(tempFile)
+ tmp = mw.readFile(tempFile)
if len(tmp) < 10:
- return public.returnJson(False, '当前没有任务队列在执行-3!')
+ return mw.returnJson(False, '当前没有任务队列在执行-3!')
echoMsg['msg'] = json.loads(tmp)
echoMsg['isDownload'] = True
except:
- public.M('tasks').where(
+ mw.M('tasks').where(
"id=?", (find['id'],)).save('status', ('0',))
- return public.returnJson(False, '当前没有任务队列在执行-4!')
+ return mw.returnJson(False, '当前没有任务队列在执行-4!')
else:
- echoMsg['msg'] = public.getLastLine(tempFile, 10)
+ echoMsg['msg'] = mw.getLastLine(tempFile, 10)
echoMsg['isDownload'] = False
- echoMsg['task'] = public.M('tasks').where("status!=?", ('1',)).field(
+ echoMsg['task'] = mw.M('tasks').where("status!=?", ('1',)).field(
'id,status,name,type').order("id asc").select()
- return public.getJson(echoMsg)
+ return mw.getJson(echoMsg)
diff --git a/plugins/bbr/index.py b/plugins/bbr/index.py
index 88419b7e9..e12ce3d4a 100755
--- a/plugins/bbr/index.py
+++ b/plugins/bbr/index.py
@@ -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 '执行成功!重启系统生效'
diff --git a/plugins/csvn/index.py b/plugins/csvn/index.py
index 103827569..a3ea21b1a 100755
--- a/plugins/csvn/index.py
+++ b/plugins/csvn/index.py
@@ -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__":
diff --git a/plugins/gae/index.py b/plugins/gae/index.py
index dead2a809..41cd63ebc 100755
--- a/plugins/gae/index.py
+++ b/plugins/gae/index.py
@@ -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]
diff --git a/plugins/go-fastdfs-web/index.py b/plugins/go-fastdfs-web/index.py
index 57e908705..563af9f43 100755
--- a/plugins/go-fastdfs-web/index.py
+++ b/plugins/go-fastdfs-web/index.py
@@ -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"
diff --git a/plugins/go-fastdfs/index.py b/plugins/go-fastdfs/index.py
index 113874225..d43090781 100755
--- a/plugins/go-fastdfs/index.py
+++ b/plugins/go-fastdfs/index.py
@@ -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__":
diff --git a/plugins/gogs/index.py b/plugins/gogs/index.py
index 41ee6193a..c1ebf9f6b 100755
--- a/plugins/gogs/index.py
+++ b/plugins/gogs/index.py
@@ -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组件缺失!
进入SSH命令行输入: pip install mysql-python')
+ return mw.returnData(False, 'MySQLdb组件缺失!
进入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__":
diff --git a/plugins/jenkins/index.py b/plugins/jenkins/index.py
index 6bd7e096f..416ef28f6 100755
--- a/plugins/jenkins/index.py
+++ b/plugins/jenkins/index.py
@@ -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'
diff --git a/plugins/l2tp/index.py b/plugins/l2tp/index.py
index e0b1eb576..e3e059789 100755
--- a/plugins/l2tp/index.py
+++ b/plugins/l2tp/index.py
@@ -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__":
diff --git a/plugins/memcached/index.py b/plugins/memcached/index.py
index 1b0a527d6..4dc2b4151 100755
--- a/plugins/memcached/index.py
+++ b/plugins/memcached/index.py
@@ -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'
diff --git a/plugins/mysql/class/mysql.py b/plugins/mysql/class/mysql.py
index 01191cc53..4b4b8e3da 100755
--- a/plugins/mysql/class/mysql.py
+++ b/plugins/mysql/class/mysql.py
@@ -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)
diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py
index 65f0c3eee..c84d614f4 100755
--- a/plugins/mysql/index.py
+++ b/plugins/mysql/index.py
@@ -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组件缺失!
进入SSH命令行输入: pip install mysql-python')
+ return mw.returnJson(False, 'MySQLdb组件缺失!
进入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__":
diff --git a/plugins/op_waf/index.py b/plugins/op_waf/index.py
index a0aa2b3de..9d8e6aad7 100755
--- a/plugins/op_waf/index.py
+++ b/plugins/op_waf/index.py
@@ -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():
diff --git a/plugins/openresty/index.py b/plugins/openresty/index.py
index 62ef6e404..0e01bc947 100755
--- a/plugins/openresty/index.py
+++ b/plugins/openresty/index.py
@@ -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'
diff --git a/plugins/php/index.py b/plugins/php/index.py
index 12abcf09b..d67ae2e59 100755
--- a/plugins/php/index.py
+++ b/plugins/php/index.py
@@ -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', '')
+ sPath = mw.getRootDir() + '/phpinfo/' + v
+ mw.execShell("rm -rf " + mw.getRootDir() + '/phpinfo')
+ mw.execShell("mkdir -p " + sPath)
+ mw.writeFile(sPath + '/phpinfo.php', '')
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__":
diff --git a/plugins/php_guard/index.py b/plugins/php_guard/index.py
index e33c41529..ee891aeb7 100755
--- a/plugins/php_guard/index.py
+++ b/plugins/php_guard/index.py
@@ -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__":
diff --git a/plugins/phpmyadmin/index.py b/plugins/phpmyadmin/index.py
index d6d97b0f8..2fab0edb7 100755
--- a/plugins/phpmyadmin/index.py
+++ b/plugins/phpmyadmin/index.py
@@ -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__":
diff --git a/plugins/pm2/index.py b/plugins/pm2/index.py
index 919d2f0ab..c90f7423c 100755
--- a/plugins/pm2/index.py
+++ b/plugins/pm2/index.py
@@ -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]
diff --git a/plugins/pureftp/index.py b/plugins/pureftp/index.py
index 5fb1b163a..1aecc6bb0 100755
--- a/plugins/pureftp/index.py
+++ b/plugins/pureftp/index.py
@@ -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 + '< 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:
diff --git a/plugins/qbittorrent/index.py b/plugins/qbittorrent/index.py
index c7b6abbe3..6e7e33127 100755
--- a/plugins/qbittorrent/index.py
+++ b/plugins/qbittorrent/index.py
@@ -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]
diff --git a/plugins/redis/index.py b/plugins/redis/index.py
index 5536d9bd5..2458651ad 100755
--- a/plugins/redis/index.py
+++ b/plugins/redis/index.py
@@ -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'
diff --git a/plugins/rsyncd/index.py b/plugins/rsyncd/index.py
index 0d650725c..dbb9fa497 100755
--- a/plugins/rsyncd/index.py
+++ b/plugins/rsyncd/index.py
@@ -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' + "
"
cmd += 'chmod 600 /tmp/p.pass' + "
"
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__":
diff --git a/plugins/shadowsocks/index.py b/plugins/shadowsocks/index.py
index f6833ea6e..52fcb2f88 100755
--- a/plugins/shadowsocks/index.py
+++ b/plugins/shadowsocks/index.py
@@ -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'
diff --git a/plugins/simdht/index.py b/plugins/simdht/index.py
index 1a6bc8e1f..ef13fd982 100755
--- a/plugins/simdht/index.py
+++ b/plugins/simdht/index.py
@@ -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组件缺失!
进入SSH命令行输入: pip install mysql-python')
+ return mw.returnJson(False, 'MySQLdb组件缺失!
进入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():
diff --git a/plugins/solr/index.py b/plugins/solr/index.py
index 051da15d1..8eab399f4 100755
--- a/plugins/solr/index.py
+++ b/plugins/solr/index.py
@@ -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:(.*)\}"
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():
diff --git a/plugins/sphinx/index.py b/plugins/sphinx/index.py
index 9a18832d5..449b40416 100755
--- a/plugins/sphinx/index.py
+++ b/plugins/sphinx/index.py
@@ -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__":
diff --git a/plugins/sys-opt/index.py b/plugins/sys-opt/index.py
index b6ed7e891..7d5ddf27f 100755
--- a/plugins/sys-opt/index.py
+++ b/plugins/sys-opt/index.py
@@ -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'
diff --git a/plugins/v2ray/index.py b/plugins/v2ray/index.py
index 8b8d71032..39deb0a0b 100755
--- a/plugins/v2ray/index.py
+++ b/plugins/v2ray/index.py
@@ -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'
diff --git a/plugins/walle/index.py b/plugins/walle/index.py
index d2beba03e..26d9eab50 100755
--- a/plugins/walle/index.py
+++ b/plugins/walle/index.py
@@ -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:
" + data[0] + "
" + " error:
" + data[1]
def initData():
cmd = "cd " + getServerDir() + "/code" + " && sh admin.sh migration"
- data = public.execShell(cmd)
+ data = mw.execShell(cmd)
return "shell:
" + data[0] + "
" + " error:
" + data[1]
# rsyncdReceive
if __name__ == "__main__":
diff --git a/plugins/webssh/index.py b/plugins/webssh/index.py
index 9780ba8c3..cf5b27b8a 100755
--- a/plugins/webssh/index.py
+++ b/plugins/webssh/index.py
@@ -8,7 +8,7 @@ import re
import sys
sys.path.append(os.getcwd() + "/class/core")
-import public
+import mw
def status():
diff --git a/route/__init__.py b/route/__init__.py
index 6bc12a44d..b0cba6d17 100755
--- a/route/__init__.py
+++ b/route/__init__.py
@@ -28,7 +28,7 @@ sys.path.append(os.getcwd() + "/class/core")
sys.path.append("/usr/local/lib/python2.7/site-packages")
import db
-import public
+import mw
import config_api
app = Flask(__name__, template_folder='templates/default')
@@ -55,7 +55,7 @@ except:
str(sys.version_info[0])
app.config['SESSION_FILE_THRESHOLD'] = 1024
app.config['SESSION_FILE_MODE'] = 384
- public.execShell("pip install flask_sqlalchemy &")
+ mw.execShell("pip install flask_sqlalchemy &")
app.config['SESSION_PERMANENT'] = True
app.config['SESSION_USE_SIGNER'] = True
@@ -70,7 +70,7 @@ socketio.init_app(app)
# debug macosx dev
-if public.isAppleSystem():
+if mw.isAppleSystem():
app.debug = True
app.config.version = app.config.version + str(time.time())
@@ -103,16 +103,16 @@ def publicObject(toObject, func, action=None, get=None):
return data
except Exception as e:
data = {'msg': '访问异常:' + str(e) + '!', "status": False}
- return public.getJson(data)
+ return mw.getJson(data)
@app.route("/test")
def test():
print sys.version_info
print session
- os = public.getOs()
+ os = mw.getOs()
print os
- return public.getLocalIp()
+ return mw.getLocalIp()
@app.route('/close')
@@ -120,7 +120,7 @@ def close():
if not os.path.exists('data/close.pl'):
return redirect('/')
data = {}
- data['cmd'] = 'rm -rf ' + public.getRunDir() + '/data/close.pl'
+ data['cmd'] = 'rm -rf ' + mw.getRunDir() + '/data/close.pl'
return render_template('close.html', data=data)
@@ -137,7 +137,7 @@ def code():
out = StringIO()
codeImage[0].save(out, "png")
- session['code'] = public.md5(''.join(codeImage[1]).lower())
+ session['code'] = mw.md5(''.join(codeImage[1]).lower())
img = Response(out.getvalue(), headers={'Content-Type': 'image/png'})
return make_response(img)
@@ -170,18 +170,18 @@ def doLogin():
code = request.form.get('code', '').strip()
if session.has_key('code'):
- if session['code'] != public.md5(code):
- return public.returnJson(False, '验证码错误,请重新输入!')
+ if session['code'] != mw.md5(code):
+ return mw.returnJson(False, '验证码错误,请重新输入!')
- userInfo = public.M('users').where(
+ userInfo = mw.M('users').where(
"id=?", (1,)).field('id,username,password').find()
- password = public.md5(password)
+ password = mw.md5(password)
login_cache_count = 5
login_cache_limit = cache.get('login_cache_limit')
filename = 'data/close.pl'
if os.path.exists(filename):
- return public.returnJson(False, '面板已经关闭!')
+ return mw.returnJson(False, '面板已经关闭!')
if userInfo['username'] != username or userInfo['password'] != password:
msg = "密码错误,帐号:{1},密码:{2},登录IP:{3}", ((
@@ -193,18 +193,18 @@ def doLogin():
login_cache_limit = int(login_cache_limit) + 1
if login_cache_limit >= login_cache_count:
- public.writeFile(filename, 'True')
- return public.returnJson(False, '面板已经关闭!')
+ mw.writeFile(filename, 'True')
+ return mw.returnJson(False, '面板已经关闭!')
cache.set('login_cache_limit', login_cache_limit, timeout=10000)
login_cache_limit = cache.get('login_cache_limit')
- public.writeLog('用户登录', public.getInfo(msg))
- return public.returnJson(False, public.getInfo("用户名或密码错误,您还可以尝试[{1}]次!", (str(login_cache_count - login_cache_limit))))
+ mw.writeLog('用户登录', mw.getInfo(msg))
+ return mw.returnJson(False, mw.getInfo("用户名或密码错误,您还可以尝试[{1}]次!", (str(login_cache_count - login_cache_limit))))
cache.delete('login_cache_limit')
session['login'] = True
session['username'] = userInfo['username']
- return public.returnJson(True, '登录成功,正在跳转...')
+ return mw.returnJson(True, '登录成功,正在跳转...')
@app.route('//', methods=['POST', 'GET'])
@@ -246,14 +246,14 @@ try:
import paramiko
ssh = paramiko.SSHClient()
except:
- public.execShell('pip install paramiko==2.0.2 &')
+ mw.execShell('pip install paramiko==2.0.2 &')
def create_rsa():
- public.execShell("rm -f /root/.ssh/*")
- public.execShell('ssh-keygen -q -t rsa -P "" -f /root/.ssh/id_rsa')
- public.execShell('cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
- public.execShell('chmod 600 /root/.ssh/authorized_keys')
+ mw.execShell("rm -f /root/.ssh/*")
+ mw.execShell('ssh-keygen -q -t rsa -P "" -f /root/.ssh/id_rsa')
+ mw.execShell('cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys')
+ mw.execShell('chmod 600 /root/.ssh/authorized_keys')
def clear_ssh():
@@ -265,8 +265,8 @@ do
ps -t /dev/$i |grep -v TTY |awk '{print $1}' | xargs kill -9
done
'''
- if not public.isAppleSystem():
- info = public.execShell(sh)
+ if not mw.isAppleSystem():
+ info = mw.execShell(sh)
print info[0], info[1]
@@ -279,14 +279,14 @@ def connect_ssh():
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
- ssh.connect('localhost', public.getSSHPort())
+ ssh.connect('localhost', mw.getSSHPort())
except Exception as e:
- if public.getSSHStatus():
+ if mw.getSSHStatus():
try:
- ssh.connect('127.0.0.1', public.getSSHPort())
+ ssh.connect('127.0.0.1', mw.getSSHPort())
except:
return False
- ssh.connect('127.0.0.1', public.getSSHPort())
+ ssh.connect('127.0.0.1', mw.getSSHPort())
shell = ssh.invoke_shell(term='xterm', width=83, height=21)
shell.setblocking(0)
return True
@@ -354,7 +354,7 @@ def connected_msg(msg):
# pdata = get_input_data(data)
# if not isLogined():
# emit(pdata.s_response, {
-# 'data': public.returnData(-1, '会话丢失,请重新登陆面板!\r\n')})
+# 'data': mw.returnData(-1, '会话丢失,请重新登陆面板!\r\n')})
# return None
# mods = ['site', 'ftp', 'database', 'ajax', 'system', 'crontab', 'files',
# 'config', 'panel_data', 'plugin', 'ssl', 'auth', 'firewall', 'panel_wxapp']
diff --git a/scripts/backup.py b/scripts/backup.py
index 1032b9506..d5c69b3ec 100755
--- a/scripts/backup.py
+++ b/scripts/backup.py
@@ -17,7 +17,7 @@ reload(sys)
sys.setdefaultencoding('utf-8')
-import public
+import mw
import db
import time
@@ -36,14 +36,14 @@ class backupTools:
"----------------------------------------------------------------------------")
return
- backup_path = public.getRootDir() + '/backup/site'
+ backup_path = mw.getRootDir() + '/backup/site'
if not os.path.exists(backup_path):
- public.execShell("mkdir -p " + backup_path)
+ mw.execShell("mkdir -p " + backup_path)
filename = backup_path + "/web_" + name + "_" + \
time.strftime('%Y%m%d_%H%M%S', time.localtime()) + '.tar.gz'
- public.execShell("cd " + os.path.dirname(path) + " && tar zcvf '" +
- filename + "' '" + os.path.basename(path) + "' > /dev/null")
+ mw.execShell("cd " + os.path.dirname(path) + " && tar zcvf '" +
+ filename + "' '" + os.path.basename(path) + "' > /dev/null")
endDate = time.strftime('%Y/%m/%d %X', time.localtime())
@@ -60,7 +60,7 @@ class backupTools:
sql.table('backup').add('type,name,pid,filename,addtime,size', ('0', os.path.basename(
filename), pid, filename, endDate, os.path.getsize(filename)))
log = u"网站[" + name + u"]备份成功,用时[" + str(round(outTime, 2)) + u"]秒"
- public.writeLog(u'计划任务', log)
+ mw.writeLog(u'计划任务', log)
print(u"★[" + endDate + "] " + log)
print(u"|---保留最新的[" + count + u"]份备份")
print(u"|---文件名:" + filename)
@@ -72,7 +72,7 @@ class backupTools:
num = len(backups) - int(count)
if num > 0:
for backup in backups:
- public.execShell("rm -f " + backup['filename'])
+ mw.execShell("rm -f " + backup['filename'])
sql.table('backup').where('id=?', (backup['id'],)).delete()
num -= 1
print(u"|---已清理过期备份文件:" + backup['filename'])
@@ -80,9 +80,9 @@ class backupTools:
break
def backupDatabase(self, name, count):
- db_path = public.getServerDir() + '/mysql'
+ db_path = mw.getServerDir() + '/mysql'
db_name = 'mysql'
- name = public.M('databases').dbPos(db_path, 'mysql').where(
+ name = mw.M('databases').dbPos(db_path, 'mysql').where(
'name=?', (name,)).getField('name')
startTime = time.time()
if not name:
@@ -93,26 +93,26 @@ class backupTools:
u"----------------------------------------------------------------------------")
return
- backup_path = public.getRootDir() + '/backup/database'
+ backup_path = mw.getRootDir() + '/backup/database'
if not os.path.exists(backup_path):
- public.execShell("mkdir -p " + backup_path)
+ mw.execShell("mkdir -p " + backup_path)
filename = backup_path + "/db_" + name + "_" + \
time.strftime('%Y%m%d_%H%M%S', time.localtime()) + ".sql.gz"
import re
- mysql_root = public.M('config').dbPos(db_path, db_name).where(
+ mysql_root = mw.M('config').dbPos(db_path, db_name).where(
"id=?", (1,)).getField('mysql_root')
- mycnf = public.readFile(db_path + '/etc/my.cnf')
+ mycnf = mw.readFile(db_path + '/etc/my.cnf')
rep = "\[mysqldump\]\nuser=root"
sea = "[mysqldump]\n"
subStr = sea + "user=root\npassword=" + mysql_root + "\n"
mycnf = mycnf.replace(sea, subStr)
if len(mycnf) > 100:
- public.writeFile(db_path + '/etc/my.cnf', mycnf)
+ mw.writeFile(db_path + '/etc/my.cnf', mycnf)
- public.execShell(
+ mw.execShell(
db_path + "/bin/mysqldump --opt --default-character-set=utf8 " + name + " | gzip > " + filename)
if not os.path.exists(filename):
@@ -123,47 +123,47 @@ class backupTools:
u"----------------------------------------------------------------------------")
return
- mycnf = public.readFile(db_path + '/etc/my.cnf')
+ mycnf = mw.readFile(db_path + '/etc/my.cnf')
mycnf = mycnf.replace(subStr, sea)
if len(mycnf) > 100:
- public.writeFile(db_path + '/etc/my.cnf', mycnf)
+ mw.writeFile(db_path + '/etc/my.cnf', mycnf)
endDate = time.strftime('%Y/%m/%d %X', time.localtime())
outTime = time.time() - startTime
- pid = public.M('databases').dbPos(db_path, db_name).where(
+ pid = mw.M('databases').dbPos(db_path, db_name).where(
'name=?', (name,)).getField('id')
- public.M('backup').add('type,name,pid,filename,addtime,size', (1, os.path.basename(
+ mw.M('backup').add('type,name,pid,filename,addtime,size', (1, os.path.basename(
filename), pid, filename, endDate, os.path.getsize(filename)))
log = u"数据库[" + name + u"]备份成功,用时[" + str(round(outTime, 2)) + u"]秒"
- public.writeLog(u'计划任务', log)
+ mw.writeLog(u'计划任务', log)
print("★[" + endDate + "] " + log)
print(u"|---保留最新的[" + count + u"]份备份")
print(u"|---文件名:" + filename)
# 清理多余备份
- backups = public.M('backup').where(
+ backups = mw.M('backup').where(
'type=? and pid=?', ('1', pid)).field('id,filename').select()
num = len(backups) - int(count)
if num > 0:
for backup in backups:
- public.execShell("rm -f " + backup['filename'])
- public.M('backup').where('id=?', (backup['id'],)).delete()
+ mw.execShell("rm -f " + backup['filename'])
+ mw.M('backup').where('id=?', (backup['id'],)).delete()
num -= 1
print(u"|---已清理过期备份文件:" + backup['filename'])
if num < 1:
break
def backupSiteAll(self, save):
- sites = public.M('sites').field('name').select()
+ sites = mw.M('sites').field('name').select()
for site in sites:
self.backupSite(site['name'], save)
def backupDatabaseAll(self, save):
- db_path = public.getServerDir() + '/mysql'
+ db_path = mw.getServerDir() + '/mysql'
db_name = 'mysql'
- databases = public.M('databases').dbPos(
+ databases = mw.M('databases').dbPos(
db_path, db_name).field('name').select()
for database in databases:
self.backupDatabase(database['name'], save)
diff --git a/scripts/logs_backup.py b/scripts/logs_backup.py
index beed24ba9..a290fff2a 100755
--- a/scripts/logs_backup.py
+++ b/scripts/logs_backup.py
@@ -18,12 +18,12 @@ sys.path.append(chdir + '/class/core')
reload(sys)
sys.setdefaultencoding('utf-8')
-import public
+import mw
print('==================================================================')
print('★[' + time.strftime("%Y/%m/%d %H:%M:%S") + '],切割日志')
print('==================================================================')
print('|--当前保留最新的[' + sys.argv[2] + ']份')
-logsPath = public.getLogsDir()
+logsPath = mw.getLogsDir()
px = '.log'
@@ -49,7 +49,7 @@ def split_logs(oldFileName, num):
def split_all(save):
- sites = public.M('sites').field('name').select()
+ sites = mw.M('sites').field('name').select()
for site in sites:
oldFileName = logsPath + site['name'] + px
split_logs(oldFileName, save)
@@ -66,5 +66,5 @@ if __name__ == '__main__':
siteName = siteName.replace("-access_log", '')
oldFileName = logsPath + '/' + sys.argv[1]
split_logs(oldFileName, num)
- path = public.getServerDir()
+ path = mw.getServerDir()
os.system("kill -USR1 `cat " + path + "/openresty/nginx/logs/nginx.pid`")
diff --git a/setting.py b/setting.py
index 962522474..fcd96ee4e 100755
--- a/setting.py
+++ b/setting.py
@@ -7,7 +7,7 @@ import os
chdir = os.getcwd()
sys.path.append(chdir + '/class/core')
sys.path.append("/usr/local/lib/python2.7/site-packages")
-import public
+import mw
import system_api
cpu_info = system_api.system_api().getCpuInfo()
workers = cpu_info[1]
@@ -16,7 +16,7 @@ workers = cpu_info[1]
if not os.path.exists(os.getcwd() + '/logs'):
os.mkdir(os.getcwd() + '/logs')
-mw_port = public.readFile('data/port.pl')
+mw_port = mw.readFile('data/port.pl')
if mw_port:
mw_port.strip()
bind = []
diff --git a/task.py b/task.py
index d6ccbb1ba..66cec577e 100755
--- a/task.py
+++ b/task.py
@@ -17,7 +17,7 @@ sys.path.append(os.getcwd() + "/class/core")
reload(sys)
sys.setdefaultencoding('utf-8')
import db
-import public
+import mw
global pre, timeoutCount, logPath, isTask, oldEdate, isCheck
@@ -49,8 +49,8 @@ def async(f):
@async
def restartMw():
time.sleep(1)
- cmd = public.getRunDir() + '/scripts/init.d/mw restart'
- public.execShell(cmd)
+ cmd = mw.getRunDir() + '/scripts/init.d/mw restart'
+ mw.execShell(cmd)
class MyBad():
@@ -171,13 +171,13 @@ def mainSafe():
isCheck += 1
return True
isCheck = 0
- isStart = public.execShell(
+ isStart = mw.execShell(
"ps aux |grep 'python main.py'|grep -v grep|awk '{print $2}'")[0]
if not isStart:
os.system('/etc/init.d/bt start')
- isStart = public.execShell(
+ isStart = mw.execShell(
"ps aux |grep 'python main.py'|grep -v grep|awk '{print $2}'")[0]
- public.writeLog('守护程序', '面板服务程序启动成功 -> PID: ' + isStart)
+ mw.writeLog('守护程序', '面板服务程序启动成功 -> PID: ' + isStart)
except:
time.sleep(30)
mainSafe()
@@ -188,14 +188,14 @@ def siteEdate():
global oldEdate
try:
if not oldEdate:
- oldEdate = public.readFile('data/edate.pl')
+ oldEdate = mw.readFile('data/edate.pl')
if not oldEdate:
oldEdate = '0000-00-00'
mEdate = time.strftime('%Y-%m-%d', time.localtime())
if oldEdate == mEdate:
return False
- edateSites = public.M('sites').where('edate>? AND edate AND (status=? OR status=?)',
- ('0000-00-00', mEdate, 1, u'正在运行')).field('id,name').select()
+ edateSites = mw.M('sites').where('edate>? AND edate AND (status=? OR status=?)',
+ ('0000-00-00', mEdate, 1, u'正在运行')).field('id,name').select()
import panelSite
siteObject = panelSite.panelSite()
for site in edateSites:
@@ -204,7 +204,7 @@ def siteEdate():
get.name = site['name']
siteObject.SiteStop(get)
oldEdate = mEdate
- public.writeFile('data/edate.pl', mEdate)
+ mw.writeFile('data/edate.pl', mEdate)
except:
pass
@@ -219,7 +219,7 @@ def systemTask():
filename = 'data/control.conf'
sql = db.Sql().dbfile('system')
- csql = public.readFile('data/sql/system.sql')
+ csql = mw.readFile('data/sql/system.sql')
csql_list = csql.split(';')
for index in range(len(csql_list)):
sql.execute(csql_list[index], ())
@@ -236,7 +236,7 @@ def systemTask():
day = 30
try:
- day = int(public.readFile(filename))
+ day = int(mw.readFile(filename))
if day < 1:
time.sleep(10)
continue
@@ -360,7 +360,7 @@ def systemTask():
def check502Task():
try:
while True:
- if os.path.exists(public.getRunDir() + '/data/502Task.pl'):
+ if os.path.exists(mw.getRunDir() + '/data/502Task.pl'):
check502()
time.sleep(30)
except:
@@ -372,7 +372,7 @@ def check502():
try:
phpversions = ['53', '54', '55', '56', '70', '71', '72', '73', '74']
for version in phpversions:
- sdir = public.getServerDir()
+ sdir = mw.getServerDir()
php_path = sdir + '/php/' + version + '/sbin/php-fpm'
if not os.path.exists(php_path):
continue
@@ -380,14 +380,14 @@ def check502():
continue
if startPHPVersion(version):
print '检测到PHP-' + version + '处理异常,已自动修复!'
- public.writeLog('PHP守护程序', '检测到PHP-' + version + '处理异常,已自动修复!')
+ mw.writeLog('PHP守护程序', '检测到PHP-' + version + '处理异常,已自动修复!')
except Exception as e:
print str(e)
# 处理指定PHP版本
def startPHPVersion(version):
- sdir = public.getServerDir()
+ sdir = mw.getServerDir()
try:
fpm = sdir + '/php/init.d/php' + version
php_path = sdir + '/php/' + version + '/sbin/php-fpm'
@@ -404,8 +404,8 @@ def startPHPVersion(version):
# 尝试重启服务
cgi = '/tmp/php-cgi-' + version + '.sock'
pid = sdir + '/php/' + version + '/var/run/php-fpm.pid'
- data = public.execShell("ps -ef | grep php/" + version +
- " | grep -v grep|grep -v python |awk '{print $2}'")
+ data = mw.execShell("ps -ef | grep php/" + version +
+ " | grep -v grep|grep -v python |awk '{print $2}'")
if data[0] != '':
os.system("ps -ef | grep php/" + version +
" | grep -v grep|grep -v python |awk '{print $2}' | xargs kill ")
@@ -430,7 +430,7 @@ def startPHPVersion(version):
def checkPHPVersion(version):
try:
url = 'http://127.0.0.1/phpfpm_status_' + version
- result = public.httpGet(url)
+ result = mw.httpGet(url)
# print version,result
# 检查nginx
if result.find('Bad Gateway') != -1:
@@ -442,7 +442,7 @@ def checkPHPVersion(version):
if result.find('Connection refused') != -1:
global isTask
if os.path.exists(isTask):
- isStatus = public.readFile(isTask)
+ isStatus = mw.readFile(isTask)
if isStatus == 'True':
return True
filename = '/etc/init.d/openresty'
diff --git a/tools.py b/tools.py
index 89322ca9f..143a0ae1d 100755
--- a/tools.py
+++ b/tools.py
@@ -13,7 +13,7 @@ sys.path.append(os.getcwd() + "/class/core")
reload(sys)
sys.setdefaultencoding('utf-8')
import db
-import public
+import mw
def set_mysql_root(password):
@@ -51,13 +51,13 @@ echo '==========================================='
echo "root密码成功修改为: ${pwd}"
echo "The root password set ${pwd} successuful"'''
- server = public.getServerDir() + '/mysql'
+ server = mw.getServerDir() + '/mysql'
root_mysql = root_mysql.replace('${server}', server)
- public.writeFile('mysql_root.sh', root_mysql)
+ mw.writeFile('mysql_root.sh', root_mysql)
os.system("/bin/bash mysql_root.sh " + password)
os.system("rm -f mysql_root.sh")
- pos = public.getServerDir() + '/mysql'
+ pos = mw.getServerDir() + '/mysql'
result = sql.table('config').dbPos(pos, 'mysql').where(
'id=?', (1,)).setField('mysql_root', password)
@@ -67,7 +67,7 @@ def set_panel_pwd(password, ncli=False):
import db
sql = db.Sql()
result = sql.table('users').where('id=?', (1,)).setField(
- 'password', public.md5(password))
+ 'password', mw.md5(password))
username = sql.table('users').where('id=?', (1,)).getField('username')
if ncli:
print("|-用户名: " + username)
@@ -94,7 +94,7 @@ def set_panel_username(username=None):
username = sql.table('users').where('id=?', (1,)).getField('username')
if username == 'admin':
- username = public.getRandomString(8).lower()
+ username = mw.getRandomString(8).lower()
sql.table('users').where('id=?', (1,)).setField('username', username)
print('username: ' + username)