Skip to content

Commit

Permalink
6.9.9-4
Browse files Browse the repository at this point in the history
  • Loading branch information
showpy committed Sep 6, 2019
1 parent 847f044 commit 6a5acc9
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 62 deletions.
74 changes: 58 additions & 16 deletions class/apache.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def GetApacheStatus(self):
public.writeFile(apacheconf,confcontent)
public.serviceReload()
result = public.HttpGet('http://127.0.0.1/server-status?auto')
workermen = int(public.ExecShell("ps aux|grep httpd|grep 'start'|awk '{memsum+=$6};END {print memsum}'")[0]) / 1024
try:
workermen = int(public.ExecShell("ps aux|grep httpd|grep 'start'|awk '{memsum+=$6};END {print memsum}'")[0]) / 1024
except:
return public.returnMsg(False,"获取内存错误")
for proc in psutil.process_iter():
if proc.name() == "httpd":
self.GetProcessCpuPercent(proc.pid,process_cpu)
Expand All @@ -46,18 +49,30 @@ def GetApacheStatus(self):
data = {}

# 计算启动时间
Uptime = int(re.search("ServerUptimeSeconds:\s+(.*)",result).group(1))
Uptime = re.search("ServerUptimeSeconds:\s+(.*)",result)
if not Uptime:
return public.returnMsg(False, "获取启动时间错误")
Uptime = int(Uptime.group(1))
min = Uptime / 60
hours = min / 60
days = math.floor(hours / 24)
hours = math.floor(hours - (days * 24))
min = math.floor(min - (days * 60 * 24) - (hours * 60))

#格式化重启时间
restarttime = re.search("RestartTime:\s+(.*)",result).group(1)
rep = "\w+,\s([\w-]+)\s([\d\:]+)\sCST"
date = re.search(rep,restarttime).group(1)
timedetail = re.search(rep,restarttime).group(2)
restarttime = re.search("RestartTime:\s+(.*)",result)
if not restarttime:
return public.returnMsg(False, "获取重启时间错误")
restarttime = restarttime.group(1)
rep = "\w+,\s([\w-]+)\s([\d\:]+)\s\w+"
date = re.search(rep,restarttime)
if not date:
return public.returnMsg(False, "获取日期错误")
date = date.group(1)
timedetail = re.search(rep,restarttime)
if not timedetail:
return public.returnMsg(False, "获取时间详情错误")
timedetail=timedetail.group(2)
monthen = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
n = 0
for m in monthen:
Expand All @@ -67,16 +82,31 @@ def GetApacheStatus(self):
date = date.split("-")
date = "%s-%s-%s" % (date[2],date[1],date[0])

reqpersec = re.search("ReqPerSec:\s+(.*)", result).group(1)
reqpersec = re.search("ReqPerSec:\s+(.*)", result)
if not reqpersec:
return public.returnMsg(False, "获取 reqpersec 错误")
reqpersec = reqpersec.group(1)
if re.match("^\.", reqpersec):
reqpersec = "%s%s" % (0,reqpersec)
data["RestartTime"] = "%s %s" % (date,timedetail)
data["UpTime"] = "%s天%s小时%s分钟" % (str(int(days)),str(int(hours)),str(int(min)))
data["TotalAccesses"] = re.search("Total Accesses:\s+(\d+)",result).group(1)
data["TotalKBytes"] = re.search("Total kBytes:\s+(\d+)",result).group(1)
data["UpTime"] = "%s day %s hour %s minute" % (str(int(days)),str(int(hours)),str(int(min)))
total_acc = re.search("Total Accesses:\s+(\d+)",result)
if not total_acc:
return public.returnMsg(False, "获取 TotalAccesses 错误")
data["TotalAccesses"] = total_acc.group(1)
total_kb = re.search("Total kBytes:\s+(\d+)",result)
if not total_kb:
return public.returnMsg(False, "获取 TotalKBytes 错误")
data["TotalKBytes"] = total_kb.group(1)
data["ReqPerSec"] = round(float(reqpersec), 2)
data["BusyWorkers"] = re.search("BusyWorkers:\s+(\d+)",result).group(1)
data["IdleWorkers"] = re.search("IdleWorkers:\s+(\d+)",result).group(1)
busywork = re.search("BusyWorkers:\s+(\d+)",result)
if not busywork:
return public.returnMsg(False, "获取 BusyWorkers 错误")
data["BusyWorkers"] = busywork.group(1)
idlework = re.search("IdleWorkers:\s+(\d+)",result)
if not idlework:
return public.returnMsg(False, "获取 IdleWorkers 错误")
data["IdleWorkers"] = idlework.group(1)
data["workercpu"] = round(float(process_cpu["httpd"]),2)
data["workermem"] = "%s%s" % (int(workermen),"MB")
return data
Expand All @@ -93,8 +123,14 @@ def GetApacheValue(self):
n = 0
for i in gets:
rep = "(%s)\s+(\w+)" % i
k = re.search(rep, apachedefaultcontent).group(1)
v = re.search(rep, apachedefaultcontent).group(2)
k = re.search(rep, apachedefaultcontent)
if not k:
return public.returnMsg(False, "获取 Key {} 错误".format(k))
k = k.group(1)
v = re.search(rep, apachedefaultcontent)
if not v:
return public.returnMsg(False, "获取 Value {} 错误".format(v))
v = v.group(2)
psstr = ps[n]
kv = {"name":k,"value":v,"ps":psstr}
conflist.append(kv)
Expand All @@ -105,8 +141,14 @@ def GetApacheValue(self):
n = 0
for i in gets:
rep = "(%s)\s+(\w+)" % i
k = re.search(rep, apachempmcontent).group(1)
v = re.search(rep, apachempmcontent).group(2)
k = re.search(rep, apachempmcontent)
if not k:
return public.returnMsg(False, "获取 Key {} 错误".format(k))
k = k.group(1)
v = re.search(rep, apachempmcontent)
if not v:
return public.returnMsg(False, "获取 Value {} 错误".format(v))
v = v.group(2)
psstr = ps[n]
kv = {"name": k, "value": v, "ps": psstr}
conflist.append(kv)
Expand Down
3 changes: 2 additions & 1 deletion class/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ def __delattr__(self, key): delattr(self,key)
def get_items(self): return self



class panelSetup:
def init(self):
ua = request.headers.get('User-Agent')
if ua:
ua = ua.lower();
if ua.find('spider') != -1 or ua.find('bot') != -1: return redirect('https://www.baidu.com');
g.version = '6.9.9'
g.version = '6.9.34'
g.title = public.GetConfigValue('title')
g.uri = request.path
session['version'] = g.version;
Expand Down
5 changes: 5 additions & 0 deletions class/crontab_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@
class dict_obj:
def __contains__(self, key):
return getattr(self, key, None)

def __setitem__(self, key, value): setattr(self, key, value)

def __getitem__(self, key): return getattr(self, key, None)

def __delitem__(self, key): delattr(self, key)

def __delattr__(self, key): delattr(self, key)

def get_items(self): return self


Expand Down
34 changes: 21 additions & 13 deletions class/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,14 @@ def ToBackup(self,get):
name = public.M('databases').where("id=?",(id,)).getField('name')
root = public.M('config').where('id=?',(1,)).getField('mysql_root');
if not os.path.exists(session['config']['backup_path'] + '/database'): os.system('mkdir -p ' + session['config']['backup_path'] + '/database');
self.mypass(True, root);
if not self.mypass(True, root):return public.returnMsg(False, '数据库配置文件获取失败,请检查MySQL配置文件是否存在')

fileName = name + '_' + time.strftime('%Y%m%d_%H%M%S',time.localtime()) + '.sql.gz'
backupName = session['config']['backup_path'] + '/database/' + fileName
public.ExecShell("/www/server/mysql/bin/mysqldump --default-character-set="+ public.get_database_character(name) +" --force --opt \"" + name + "\" | gzip > " + backupName)
if not os.path.exists(backupName): return public.returnMsg(False,'BACKUP_ERROR');
self.mypass(False, root);

if not self.mypass(True, root): return public.returnMsg(False, '数据库配置文件获取失败,请检查MySQL配置文件是否存在')

sql = public.M('backup')
addTime = time.strftime('%Y-%m-%d %X',time.localtime())
Expand Down Expand Up @@ -457,17 +457,17 @@ def InputSql(self,get):
public.ExecShell("cd " + backupPath + " && gunzip -q " + '"'+file+'"')
isgzip = True
if not os.path.exists(backupPath + '/' + tmpFile) or tmpFile == '': return public.returnMsg(False, 'FILE_NOT_EXISTS',(tmpFile,))
self.mypass(True, root);
if not self.mypass(True, root): return public.returnMsg(False, '数据库配置文件获取失败,请检查MySQL配置文件是否存在')
os.system(public.GetConfigValue('setup_path') + "/mysql/bin/mysql -uroot -p" + root + " --force \"" + name + "\" < " +'"'+ backupPath + '/' +tmpFile+'"')
self.mypass(False, root);
if not self.mypass(True, root): return public.returnMsg(False, '数据库配置文件获取失败,请检查MySQL配置文件是否存在')
if isgzip:
os.system('cd ' +backupPath+ ' && gzip ' + file.split('/')[-1][:-3]);
else:
os.system("rm -f " + backupPath + '/' +tmpFile)
else:
self.mypass(True, root);
if not self.mypass(True, root): return public.returnMsg(False, '数据库配置文件获取失败,请检查MySQL配置文件是否存在')
os.system(public.GetConfigValue('setup_path') + "/mysql/bin/mysql -uroot -p" + root + " --force \"" + name + "\" < "+'"' + file+'"')
self.mypass(False, root);
if not self.mypass(True, root): return public.returnMsg(False, '数据库配置文件获取失败,请检查MySQL配置文件是否存在')


public.WriteLog("TYPE_DATABASE", 'DATABASE_INPUT_SUCCESS',(name,))
Expand Down Expand Up @@ -508,8 +508,10 @@ def mypass(self,act,root):
rep = "\[mysqldump\]\nuser=root"
sea = "[mysqldump]\n"
subStr = sea + "user=root\npassword=\"" + root + "\"\n";
if type(mycnf)==bool:return False
mycnf = mycnf.replace(sea,subStr)
if len(mycnf) > 100: public.writeFile('/etc/my.cnf',mycnf);
return True

#添加到服务器
def ToDataBase(self,find):
Expand Down Expand Up @@ -593,14 +595,16 @@ def SetDatabaseAccess(self,get):
db_name = public.M('databases').where('username=?',(name,)).getField('name');
access = get['access']
password = public.M('databases').where("username=?",(name,)).getField('password')
users = panelMysql.panelMysql().query("select Host from mysql.user where User='" + name + "' AND Host!='localhost'")
mysql_obj = panelMysql.panelMysql()
result = mysql_obj.query("show databases")
isError = self.IsSqlError(result)
if isError != None: return isError
users = mysql_obj.query("select Host from mysql.user where User='" + name + "' AND Host!='localhost'")
for us in users:
panelMysql.panelMysql().execute("drop user '" + name + "'@'" + us[0] + "'")
mysql_obj.execute("drop user '" + name + "'@'" + us[0] + "'")
self.__CreateUsers(db_name,name,password,access)

return public.returnMsg(True, 'SET_SUCCESS')



#获取数据库配置信息
def GetMySQLInfo(self,get):
data = {}
Expand Down Expand Up @@ -756,7 +760,10 @@ def GetRunStatus(self,get):
except:pass
for d in data:
for g in gets:
if d[0] == g: result[g] = d[1];
try:
if d[0] == g: result[g] = d[1];
except:
pass
result['Run'] = int(time.time()) - int(result['Uptime'])
tmp = panelMysql.panelMysql().query('show master status');
try:
Expand All @@ -767,6 +774,7 @@ def GetRunStatus(self,get):
result['Position'] = 'OFF';
return result;


#取慢日志
def GetSlowLogs(self,get):
path = self.GetMySQLInfo(get)['datadir'] + '/mysql-slow.log';
Expand Down
2 changes: 2 additions & 0 deletions class/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ def BatchPaste(self,get):
if not self.CheckDir(get.path): return public.returnMsg(False,'FILE_DANGER');
if not 'selected' in session: return public.returnMsg(False,'操作失败,请重新操作复制或剪切过程')
i = 0;
if not 'selected' in session:return public.returnMsg(False,'操作失败,请重新操作');
myfiles = json.loads(session['selected']['data'])
l = len(myfiles);
if get.type == '1':
Expand Down Expand Up @@ -1036,6 +1037,7 @@ def move(self,sfile,dfile):

#复制目录
def copytree(self,sfile,dfile):
if not os.path.exists(dfile): os.makedirs(dfile)
for f_name in os.listdir(sfile):
src_filename = (sfile + '/' + f_name).replace('//','/')
dst_filename = (dfile + '/' + f_name).replace('//','/')
Expand Down
22 changes: 17 additions & 5 deletions class/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#-------------------------------------------------------------------
# 宝塔Linux面板
#-------------------------------------------------------------------
# Copyright (c) 2015-2018 宝塔软件(http:#bt.cn) All rights reserved.
# Copyright (c) 2015-2099 宝塔软件(http:#bt.cn) All rights reserved.
#-------------------------------------------------------------------
# Author: 黄文良 <[email protected]>
#-------------------------------------------------------------------
Expand All @@ -28,8 +28,14 @@ def GetNginxValue(self):
n = 0
for i in gets:
rep = "(%s)\s+(\w+)" % i
k = re.search(rep, ngconfcontent).group(1)
v = re.search(rep, ngconfcontent).group(2)
k = re.search(rep, ngconfcontent)
if not k:
return public.returnMsg(False,"获取 key {} 失败".format(k))
k = k.group(1)
v = re.search(rep, ngconfcontent)
if not v:
return public.returnMsg(False,"获取 value {} 失败".format(v))
v = v.group(2)
if re.search(unitrep,v):
u = str.upper(v[-1])
v = v[:-1]
Expand All @@ -48,8 +54,14 @@ def GetNginxValue(self):
n = 0
for i in gets:
rep = "(%s)\s+(\w+)" % i
k = re.search(rep, proxycontent).group(1)
v = re.search(rep, proxycontent).group(2)
k = re.search(rep, proxycontent)
if not k:
return public.returnMsg(False,"获取 key {} 失败".format(k))
k=k.group(1)
v = re.search(rep, proxycontent)
if not v:
return public.returnMsg(False,"获取 value {} 失败".format(v))
v = v.group(2)
if re.search(unitrep, v):
u = str.upper(v[-1])
v = v[:-1]
Expand Down
11 changes: 9 additions & 2 deletions class/panelSite.py
Original file line number Diff line number Diff line change
Expand Up @@ -3225,13 +3225,19 @@ def GetSiteRunPath(self,get):
if os.path.exists(filename):
conf = public.readFile(filename)
rep = '\s*root\s*(.+);'
path = re.search(rep,conf).groups()[0];
path = re.search(rep,conf)
if not path:
return public.returnMsg(False,"获取站点运行目录失败")
path = path.groups()[0]
else:
filename = self.setupPath + '/panel/vhost/apache/' + siteName + '.conf'
if os.path.exists(filename):
conf = public.readFile(filename)
rep = '\s*DocumentRoot\s*"(.+)"\s*\n'
path = re.search(rep,conf).groups()[0];
path = re.search(rep,conf)
if not path:
return public.returnMsg(False,"获取站点运行目录失败")
path = path.groups()[0]

data = {}
if sitePath == path:
Expand All @@ -3253,6 +3259,7 @@ def GetSiteRunPath(self,get):

data['dirs'] = dirnames;
return data;


#设置当前站点运行目录
def SetSiteRunPath(self,get):
Expand Down
1 change: 0 additions & 1 deletion class/panelTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def get_task_lists(self,get):
if type(data) == str:
public.WriteLog('任务队列',data)
return []

if not 'num' in get: get.num = 15
num = int(get.num)
for i in range(len(data)):
Expand Down
9 changes: 5 additions & 4 deletions class/plugin_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,11 @@ def SetupPackage(self,get):
site_name = get.site_name;
php_version = get.php_version;
#取基础信息
find = public.M('sites').where('name=?',(site_name,)).field('id,path,name').find();
path = find['path'];
find = public.M('sites').where('name=?',(site_name,)).field('id,path,name').find()
if not 'path' in find:
return public.returnMsg(False, '网站不存在!')
path = find['path']
if path.replace('//','/') == '/': return public.returnMsg(False,'危险的网站根目录!')

#获取包信息
pinfo = self.GetPackageInfo(name);
id = pinfo['id']
Expand Down Expand Up @@ -474,7 +475,7 @@ def depTotal(self,id):
#获取进度
def GetSpeed(self,get):
try:
if not os.path.exists(self.logPath): return public.returnMsg(False,'当前没有部署任务!');
if not os.path.exists(self.logPath): public.returnMsg(False,'当前没有部署任务!');
return json.loads(public.readFile(self.logPath));
except:
return {'name':'准备部署','total':0,'used':0,'pre':0,'speed':0}
Expand Down
17 changes: 12 additions & 5 deletions class/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,18 @@ def ReadFile(filename,mode = 'r'):
fp = open(filename, mode)
f_body = fp.read()
fp.close()
except:
fp = open(filename, mode,encoding="utf-8")
f_body = fp.read()
fp.close()

except Exception as ex:
if sys.version_info[0] != 2:
try:
fp = open(filename, mode,encoding="utf-8");
f_body = fp.read()
fp.close()
except Exception as ex2:
WriteLog('打开文件',str(ex2))
return False
else:
WriteLog('打开文件',str(ex))
return False
return f_body

def readFile(filename,mode='r'):
Expand Down
Loading

0 comments on commit 6a5acc9

Please sign in to comment.