mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 04:19:26 +08:00
update
This commit is contained in:
@@ -128,7 +128,7 @@ class plugin:
|
||||
else:
|
||||
if pg['pid'] == sType:
|
||||
plugins_info.append(pg)
|
||||
except BaseException, e:
|
||||
except Exception, e:
|
||||
print e
|
||||
args = {}
|
||||
args['count'] = len(plugins_info)
|
||||
|
||||
@@ -48,7 +48,7 @@ def getRootDir():
|
||||
|
||||
def getOs():
|
||||
os = execShell('uname')
|
||||
return os[0]
|
||||
return os[0].lower().strip()
|
||||
|
||||
|
||||
def M(table):
|
||||
@@ -92,7 +92,7 @@ def md5(str):
|
||||
return False
|
||||
|
||||
|
||||
def GetFileMd5(filename):
|
||||
def getFileMd5(filename):
|
||||
# 文件的MD5值
|
||||
if not os.path.isfile(filename):
|
||||
return False
|
||||
@@ -108,7 +108,7 @@ def GetFileMd5(filename):
|
||||
return myhash.hexdigest()
|
||||
|
||||
|
||||
def GetRandomString(length):
|
||||
def getRandomString(length):
|
||||
# 取随机字符串
|
||||
str = ''
|
||||
chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
|
||||
|
||||
@@ -1,700 +0,0 @@
|
||||
# coding: utf-8
|
||||
|
||||
import psutil
|
||||
import time
|
||||
import os
|
||||
import public
|
||||
import re
|
||||
|
||||
|
||||
class system:
|
||||
setupPath = None
|
||||
pids = None
|
||||
|
||||
def __init__(self):
|
||||
self.setupPath = '/www/server'
|
||||
|
||||
def GetConcifInfo(self, get=None):
|
||||
# 取环境配置信息
|
||||
if not hasattr(web.ctx.session, 'config'):
|
||||
web.ctx.session.config = public.M('config').where("id=?", ('1',)).field(
|
||||
'webserver,sites_path,backup_path,status,mysql_root').find()
|
||||
if not hasattr(web.ctx.session.config, 'email'):
|
||||
web.ctx.session.config['email'] = public.M(
|
||||
'users').where("id=?", ('1',)).getField('email')
|
||||
data = {}
|
||||
data = web.ctx.session.config
|
||||
data['webserver'] = web.ctx.session.config['webserver']
|
||||
# PHP版本
|
||||
phpVersions = ('52', '53', '54', '55', '56',
|
||||
'70', '71', '72', '73', '74')
|
||||
|
||||
data['php'] = []
|
||||
|
||||
for version in phpVersions:
|
||||
tmp = {}
|
||||
tmp['setup'] = os.path.exists(
|
||||
self.setupPath + '/php/' + version + '/bin/php')
|
||||
if tmp['setup']:
|
||||
phpConfig = self.GetPHPConfig(version)
|
||||
tmp['version'] = version
|
||||
tmp['max'] = phpConfig['max']
|
||||
tmp['maxTime'] = phpConfig['maxTime']
|
||||
tmp['pathinfo'] = phpConfig['pathinfo']
|
||||
tmp['status'] = os.path.exists(
|
||||
'/tmp/php-cgi-' + version + '.sock')
|
||||
data['php'].append(tmp)
|
||||
|
||||
tmp = {}
|
||||
data['webserver'] = ''
|
||||
serviceName = 'nginx'
|
||||
tmp['setup'] = False
|
||||
phpversion = "54"
|
||||
phpport = '888'
|
||||
pstatus = False
|
||||
pauth = False
|
||||
if os.path.exists(self.setupPath + '/nginx'):
|
||||
data['webserver'] = 'nginx'
|
||||
serviceName = 'nginx'
|
||||
tmp['setup'] = os.path.exists(self.setupPath + '/nginx/sbin/nginx')
|
||||
configFile = self.setupPath + '/nginx/conf/nginx.conf'
|
||||
try:
|
||||
if os.path.exists(configFile):
|
||||
conf = public.readFile(configFile)
|
||||
rep = "listen\s+([0-9]+)\s*;"
|
||||
rtmp = re.search(rep, conf)
|
||||
if rtmp:
|
||||
phpport = rtmp.groups()[0]
|
||||
|
||||
if conf.find('AUTH_START') != -1:
|
||||
pauth = True
|
||||
if conf.find(self.setupPath + '/stop') == -1:
|
||||
pstatus = True
|
||||
configFile = self.setupPath + '/nginx/conf/enable-php.conf'
|
||||
conf = public.readFile(configFile)
|
||||
rep = "php-cgi-([0-9]+)\.sock"
|
||||
rtmp = re.search(rep, conf)
|
||||
if rtmp:
|
||||
phpversion = rtmp.groups()[0]
|
||||
except:
|
||||
pass
|
||||
|
||||
elif os.path.exists(self.setupPath + '/apache'):
|
||||
data['webserver'] = 'apache'
|
||||
serviceName = 'httpd'
|
||||
tmp['setup'] = os.path.exists(self.setupPath + '/apache/bin/httpd')
|
||||
configFile = self.setupPath + '/apache/conf/extra/httpd-vhosts.conf'
|
||||
try:
|
||||
if os.path.exists(configFile):
|
||||
conf = public.readFile(configFile)
|
||||
rep = "php-cgi-([0-9]+)\.sock"
|
||||
rtmp = re.search(rep, conf)
|
||||
if rtmp:
|
||||
phpversion = rtmp.groups()[0]
|
||||
rep = "Listen\s+([0-9]+)\s*\n"
|
||||
rtmp = re.search(rep, conf)
|
||||
if rtmp:
|
||||
phpport = rtmp.groups()[0]
|
||||
if conf.find('AUTH_START') != -1:
|
||||
pauth = True
|
||||
if conf.find(self.setupPath + '/stop') == -1:
|
||||
pstatus = True
|
||||
except:
|
||||
pass
|
||||
|
||||
tmp['type'] = data['webserver']
|
||||
tmp['version'] = public.readFile(
|
||||
self.setupPath + '/' + data['webserver'] + '/version.pl')
|
||||
tmp['status'] = False
|
||||
result = public.ExecShell('/etc/init.d/' + serviceName + ' status')
|
||||
if result[0].find('running') != -1:
|
||||
tmp['status'] = True
|
||||
data['web'] = tmp
|
||||
|
||||
tmp = {}
|
||||
vfile = self.setupPath + '/phpmyadmin/version.pl'
|
||||
tmp['version'] = public.readFile(vfile)
|
||||
tmp['setup'] = os.path.exists(vfile)
|
||||
tmp['status'] = pstatus
|
||||
tmp['phpversion'] = phpversion
|
||||
tmp['port'] = phpport
|
||||
tmp['auth'] = pauth
|
||||
data['phpmyadmin'] = tmp
|
||||
|
||||
tmp = {}
|
||||
tmp['setup'] = os.path.exists('/etc/init.d/tomcat')
|
||||
tmp['status'] = False
|
||||
if tmp['setup']:
|
||||
if os.path.exists('/www/server/tomcat/logs/catalina-daemon.pid'):
|
||||
tmp['status'] = self.getPid('jsvc')
|
||||
if not tmp['status']:
|
||||
tmp['status'] = self.getPid('java')
|
||||
tmp['version'] = public.readFile(self.setupPath + '/tomcat/version.pl')
|
||||
data['tomcat'] = tmp
|
||||
|
||||
tmp = {}
|
||||
tmp['setup'] = os.path.exists(self.setupPath + '/mysql/bin/mysql')
|
||||
tmp['version'] = public.readFile(self.setupPath + '/mysql/version.pl')
|
||||
tmp['status'] = os.path.exists('/tmp/mysql.sock')
|
||||
data['mysql'] = tmp
|
||||
|
||||
tmp = {}
|
||||
tmp['setup'] = os.path.exists(self.setupPath + '/redis/runtest')
|
||||
tmp['status'] = os.path.exists('/var/run/redis_6379.pid')
|
||||
data['redis'] = tmp
|
||||
|
||||
tmp = {}
|
||||
tmp['setup'] = os.path.exists('/usr/local/memcached/bin/memcached')
|
||||
tmp['status'] = os.path.exists('/var/run/memcached.pid')
|
||||
data['memcached'] = tmp
|
||||
|
||||
tmp = {}
|
||||
tmp['setup'] = os.path.exists(
|
||||
self.setupPath + '/pure-ftpd/bin/pure-pw')
|
||||
tmp['version'] = public.readFile(
|
||||
self.setupPath + '/pure-ftpd/version.pl')
|
||||
tmp['status'] = os.path.exists('/var/run/pure-ftpd.pid')
|
||||
data['pure-ftpd'] = tmp
|
||||
data['panel'] = self.GetPanelInfo()
|
||||
data['systemdate'] = public.ExecShell(
|
||||
'date +"%Y-%m-%d %H:%M:%S %Z %z"')[0].strip()
|
||||
|
||||
return data
|
||||
|
||||
# 名取PID
|
||||
def getPid(self, pname):
|
||||
try:
|
||||
if not self.pids:
|
||||
self.pids = psutil.pids()
|
||||
for pid in self.pids:
|
||||
if psutil.Process(pid).name() == pname:
|
||||
return True
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
|
||||
# 检测指定进程是否存活
|
||||
def checkProcess(self, pid):
|
||||
try:
|
||||
if not self.pids:
|
||||
self.pids = psutil.pids()
|
||||
if int(pid) in self.pids:
|
||||
return True
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
|
||||
def GetPanelInfo(self, get=None):
|
||||
# 取面板配置
|
||||
address = public.GetLocalIp()
|
||||
try:
|
||||
try:
|
||||
port = web.ctx.host.split(':')[1]
|
||||
except:
|
||||
port = public.readFile('data/port.pl')
|
||||
except:
|
||||
port = '8888'
|
||||
domain = ''
|
||||
if os.path.exists('data/domain.conf'):
|
||||
domain = public.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')
|
||||
|
||||
templates = []
|
||||
for template in os.listdir('templates/'):
|
||||
if os.path.isdir('templates/' + template):
|
||||
templates.append(template)
|
||||
template = public.readFile('data/templates.pl')
|
||||
|
||||
check502 = ''
|
||||
if os.path.exists('data/502Task.pl'):
|
||||
check502 = 'checked'
|
||||
return {'port': port, 'address': address, 'domain': domain, 'auto': autoUpdate, '502': check502, 'limitip': limitip, 'templates': templates, 'template': template}
|
||||
|
||||
def GetPHPConfig(self, version):
|
||||
# 取PHP配置
|
||||
file = self.setupPath + "/php/" + version + "/etc/php.ini"
|
||||
phpini = public.readFile(file)
|
||||
file = self.setupPath + "/php/" + version + "/etc/php-fpm.conf"
|
||||
phpfpm = public.readFile(file)
|
||||
data = {}
|
||||
try:
|
||||
rep = "upload_max_filesize\s*=\s*([0-9]+)M"
|
||||
tmp = re.search(rep, phpini).groups()
|
||||
data['max'] = tmp[0]
|
||||
except:
|
||||
data['max'] = '50'
|
||||
try:
|
||||
rep = "request_terminate_timeout\s*=\s*([0-9]+)\n"
|
||||
tmp = re.search(rep, phpfpm).groups()
|
||||
data['maxTime'] = tmp[0]
|
||||
except:
|
||||
data['maxTime'] = 0
|
||||
|
||||
try:
|
||||
rep = ur"\n;*\s*cgi\.fix_pathinfo\s*=\s*([0-9]+)\s*\n"
|
||||
tmp = re.search(rep, phpini).groups()
|
||||
|
||||
if tmp[0] == '1':
|
||||
data['pathinfo'] = True
|
||||
else:
|
||||
data['pathinfo'] = False
|
||||
except:
|
||||
data['pathinfo'] = False
|
||||
|
||||
return data
|
||||
|
||||
def GetSystemTotal(self, get, interval=1):
|
||||
# 取系统统计信息
|
||||
data = self.GetMemInfo()
|
||||
cpu = self.GetCpuInfo(interval)
|
||||
data['cpuNum'] = cpu[1]
|
||||
data['cpuRealUsed'] = cpu[0]
|
||||
data['time'] = self.GetBootTime()
|
||||
data['system'] = self.GetSystemVersion()
|
||||
data['isuser'] = public.M('users').where(
|
||||
'username=?', ('admin',)).count()
|
||||
data['version'] = web.ctx.session.version
|
||||
return data
|
||||
|
||||
def GetLoadAverage(self, get):
|
||||
c = os.getloadavg()
|
||||
data = {}
|
||||
data['one'] = float(c[0])
|
||||
data['five'] = float(c[1])
|
||||
data['fifteen'] = float(c[2])
|
||||
data['max'] = psutil.cpu_count() * 2
|
||||
data['limit'] = data['max']
|
||||
data['safe'] = data['max'] * 0.75
|
||||
return data
|
||||
|
||||
def GetAllInfo(self, get):
|
||||
data = {}
|
||||
data['load_average'] = self.GetLoadAverage(get)
|
||||
data['title'] = self.GetTitle()
|
||||
data['network'] = self.GetNetWorkApi(get)
|
||||
data['panel_status'] = not os.path.exists(
|
||||
'/www/server/panel/data/close.pl')
|
||||
import firewalls
|
||||
ssh_info = firewalls.firewalls().GetSshInfo(None)
|
||||
data['enable_ssh_status'] = ssh_info['status']
|
||||
data['disable_ping_status'] = not ssh_info['ping']
|
||||
data['time'] = self.GetBootTime()
|
||||
#data['system'] = self.GetSystemVersion();
|
||||
#data['mem'] = self.GetMemInfo();
|
||||
data['version'] = web.ctx.session.version
|
||||
return data
|
||||
|
||||
def GetTitle(self):
|
||||
titlePl = 'data/title.pl'
|
||||
title = '宝塔Linux面板'
|
||||
if os.path.exists(titlePl):
|
||||
title = public.readFile(titlePl).strip()
|
||||
return title
|
||||
|
||||
def GetSystemVersion(self):
|
||||
# 取操作系统版本
|
||||
import public
|
||||
version = public.readFile('/etc/redhat-release')
|
||||
if not version:
|
||||
version = public.readFile(
|
||||
'/etc/issue').strip().split("\n")[0].replace('\\n', '').replace('\l', '').strip()
|
||||
else:
|
||||
version = version.replace('release ', '').strip()
|
||||
return version
|
||||
|
||||
def GetBootTime(self):
|
||||
# 取系统启动时间
|
||||
import public
|
||||
import math
|
||||
conf = public.readFile('/proc/uptime').split()
|
||||
tStr = float(conf[0])
|
||||
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.getMsg('SYS_BOOT_TIME', (str(int(days)), str(int(hours)), str(int(min))))
|
||||
|
||||
def GetCpuInfo(self, interval=1):
|
||||
# 取CPU信息
|
||||
cpuCount = psutil.cpu_count()
|
||||
used = psutil.cpu_percent(interval=interval)
|
||||
return used, cpuCount
|
||||
|
||||
def GetMemInfo(self, get=None):
|
||||
# 取内存信息
|
||||
mem = psutil.virtual_memory()
|
||||
memInfo = {'memTotal': mem.total / 1024 / 1024, 'memFree': mem.free / 1024 / 1024,
|
||||
'memBuffers': mem.buffers / 1024 / 1024, 'memCached': mem.cached / 1024 / 1024}
|
||||
memInfo['memRealUsed'] = memInfo['memTotal'] - \
|
||||
memInfo['memFree'] - memInfo['memBuffers'] - memInfo['memCached']
|
||||
return memInfo
|
||||
|
||||
def GetDiskInfo(self, get=None):
|
||||
return self.GetDiskInfo2()
|
||||
# 取磁盘分区信息
|
||||
diskIo = psutil.disk_partitions()
|
||||
diskInfo = []
|
||||
|
||||
for disk in diskIo:
|
||||
if disk[1] == '/mnt/cdrom':
|
||||
continue
|
||||
if disk[1] == '/boot':
|
||||
continue
|
||||
tmp = {}
|
||||
tmp['path'] = disk[1]
|
||||
tmp['size'] = psutil.disk_usage(disk[1])
|
||||
diskInfo.append(tmp)
|
||||
return diskInfo
|
||||
|
||||
def GetDiskInfo2(self):
|
||||
# 取磁盘分区信息
|
||||
temp = public.ExecShell("df -h -P|grep '/'|grep -v tmpfs")[0]
|
||||
tempInodes = public.ExecShell("df -i -P|grep '/'|grep -v tmpfs")[0]
|
||||
temp1 = temp.split('\n')
|
||||
tempInodes1 = tempInodes.split('\n')
|
||||
diskInfo = []
|
||||
n = 0
|
||||
cuts = ['/mnt/cdrom', '/boot', '/boot/efi', '/dev',
|
||||
'/dev/shm', '/run/lock', '/run', '/run/shm', '/run/user']
|
||||
for tmp in temp1:
|
||||
n += 1
|
||||
inodes = tempInodes1[n - 1].split()
|
||||
disk = tmp.split()
|
||||
if len(disk) < 5:
|
||||
continue
|
||||
if disk[1].find('M') != -1:
|
||||
continue
|
||||
if disk[1].find('K') != -1:
|
||||
continue
|
||||
if len(disk[5].split('/')) > 4:
|
||||
continue
|
||||
if disk[5] in cuts:
|
||||
continue
|
||||
arr = {}
|
||||
arr['path'] = disk[5]
|
||||
tmp1 = [disk[1], disk[2], disk[3], disk[4]]
|
||||
arr['size'] = tmp1
|
||||
arr['inodes'] = [inodes[1], inodes[2], inodes[3], inodes[4]]
|
||||
if disk[5] == '/':
|
||||
bootLog = '/tmp/panelBoot.pl'
|
||||
if disk[2].find('M') != -1:
|
||||
if os.path.exists(bootLog):
|
||||
os.system('rm -f ' + bootLog)
|
||||
else:
|
||||
if not os.path.exists(bootLog):
|
||||
os.system('sleep 1 && /etc/init.d/bt reload &')
|
||||
diskInfo.append(arr)
|
||||
return diskInfo
|
||||
|
||||
# 清理系统垃圾
|
||||
def ClearSystem(self, get):
|
||||
count = total = 0
|
||||
tmp_total, tmp_count = self.ClearMail()
|
||||
count += tmp_count
|
||||
total += tmp_total
|
||||
tmp_total, tmp_count = self.ClearOther()
|
||||
count += tmp_count
|
||||
total += tmp_total
|
||||
return count, total
|
||||
|
||||
# 清理邮件日志
|
||||
def ClearMail(self):
|
||||
rpath = '/var/spool'
|
||||
total = count = 0
|
||||
import shutil
|
||||
con = ['cron', 'anacron', 'mail']
|
||||
for d in os.listdir(rpath):
|
||||
if d in con:
|
||||
continue
|
||||
dpath = rpath + '/' + d
|
||||
time.sleep(0.2)
|
||||
num = size = 0
|
||||
for n in os.listdir(dpath):
|
||||
filename = dpath + '/' + n
|
||||
fsize = os.path.getsize(filename)
|
||||
size += fsize
|
||||
if os.path.isdir(filename):
|
||||
shutil.rmtree(filename)
|
||||
else:
|
||||
os.remove(filename)
|
||||
print '\t\033[1;32m[OK]\033[0m'
|
||||
num += 1
|
||||
total += size
|
||||
count += num
|
||||
return total, count
|
||||
|
||||
# 清理其它
|
||||
def ClearOther(self):
|
||||
clearPath = [
|
||||
{'path': '/www/server/panel', 'find': 'testDisk_'},
|
||||
{'path': '/www/wwwlogs', 'find': 'log'},
|
||||
{'path': '/tmp', 'find': 'panelBoot.pl'},
|
||||
{'path': '/www/server/panel/install', 'find': '.rpm'}
|
||||
]
|
||||
|
||||
total = count = 0
|
||||
for c in clearPath:
|
||||
for d in os.listdir(c['path']):
|
||||
if d.find(c['find']) == -1:
|
||||
continue
|
||||
filename = c['path'] + '/' + d
|
||||
fsize = os.path.getsize(filename)
|
||||
total += fsize
|
||||
if os.path.isdir(filename):
|
||||
shutil.rmtree(filename)
|
||||
else:
|
||||
os.remove(filename)
|
||||
count += 1
|
||||
public.serviceReload()
|
||||
os.system('echo > /tmp/panelBoot.pl')
|
||||
return total, count
|
||||
|
||||
def GetNetWork(self, get=None):
|
||||
# return self.GetNetWorkApi(get);
|
||||
# 取网络流量信息
|
||||
try:
|
||||
networkIo = psutil.net_io_counters()[:4]
|
||||
if not hasattr(web.ctx.session, 'otime'):
|
||||
web.ctx.session.up = networkIo[0]
|
||||
web.ctx.session.down = networkIo[1]
|
||||
web.ctx.session.otime = time.time()
|
||||
|
||||
ntime = time.time()
|
||||
networkInfo = {}
|
||||
networkInfo['upTotal'] = networkIo[0]
|
||||
networkInfo['downTotal'] = networkIo[1]
|
||||
networkInfo['up'] = round(float(
|
||||
networkIo[0] - web.ctx.session.up) / 1024 / (ntime - web.ctx.session.otime), 2)
|
||||
networkInfo['down'] = round(float(
|
||||
networkIo[1] - web.ctx.session.down) / 1024 / (ntime - web.ctx.session.otime), 2)
|
||||
networkInfo['downPackets'] = networkIo[3]
|
||||
networkInfo['upPackets'] = networkIo[2]
|
||||
|
||||
web.ctx.session.up = networkIo[0]
|
||||
web.ctx.session.down = networkIo[1]
|
||||
web.ctx.session.otime = ntime
|
||||
|
||||
networkInfo['cpu'] = self.GetCpuInfo()
|
||||
networkInfo['load'] = self.GetLoadAverage(get)
|
||||
return networkInfo
|
||||
except:
|
||||
return None
|
||||
|
||||
def GetNetWorkApi(self, get=None):
|
||||
# 取网络流量信息
|
||||
try:
|
||||
tmpfile = 'data/network.temp'
|
||||
networkIo = psutil.net_io_counters()[:4]
|
||||
|
||||
if not os.path.exists(tmpfile):
|
||||
public.writeFile(tmpfile, str(
|
||||
networkIo[0]) + '|' + str(networkIo[1]) + '|' + str(int(time.time())))
|
||||
|
||||
lastValue = public.readFile(tmpfile).split('|')
|
||||
|
||||
ntime = time.time()
|
||||
networkInfo = {}
|
||||
networkInfo['upTotal'] = networkIo[0]
|
||||
networkInfo['downTotal'] = networkIo[1]
|
||||
networkInfo['up'] = round(
|
||||
float(networkIo[0] - int(lastValue[0])) / 1024 / (ntime - int(lastValue[2])), 2)
|
||||
networkInfo['down'] = round(
|
||||
float(networkIo[1] - int(lastValue[1])) / 1024 / (ntime - int(lastValue[2])), 2)
|
||||
networkInfo['downPackets'] = networkIo[3]
|
||||
networkInfo['upPackets'] = networkIo[2]
|
||||
|
||||
public.writeFile(tmpfile, str(
|
||||
networkIo[0]) + '|' + str(networkIo[1]) + '|' + str(int(time.time())))
|
||||
|
||||
#networkInfo['cpu'] = self.GetCpuInfo(0.1)
|
||||
return networkInfo
|
||||
except:
|
||||
return None
|
||||
|
||||
def GetNetWorkOld(self):
|
||||
# 取网络流量信息
|
||||
import time
|
||||
pnet = public.readFile('/proc/net/dev')
|
||||
rep = '([^\s]+):[\s]{0,}(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)'
|
||||
pnetall = re.findall(rep, pnet)
|
||||
networkInfo = {}
|
||||
networkInfo['upTotal'] = networkInfo['downTotal'] = networkInfo['up'] = networkInfo[
|
||||
'down'] = networkInfo['downPackets'] = networkInfo['upPackets'] = 0
|
||||
for pnetInfo in pnetall:
|
||||
if pnetInfo[0] == 'io':
|
||||
continue
|
||||
networkInfo['downTotal'] += int(pnetInfo[1])
|
||||
networkInfo['downPackets'] += int(pnetInfo[2])
|
||||
networkInfo['upTotal'] += int(pnetInfo[9])
|
||||
networkInfo['upPackets'] += int(pnetInfo[10])
|
||||
|
||||
if not hasattr(web.ctx.session, 'otime'):
|
||||
web.ctx.session.up = networkInfo['upTotal']
|
||||
web.ctx.session.down = networkInfo['downTotal']
|
||||
web.ctx.session.otime = time.time()
|
||||
ntime = time.time()
|
||||
tmpDown = networkInfo['downTotal'] - web.ctx.session.down
|
||||
tmpUp = networkInfo['upTotal'] - web.ctx.session.up
|
||||
networkInfo['down'] = str(
|
||||
round(float(tmpDown) / 1024 / (ntime - web.ctx.session.otime), 2))
|
||||
networkInfo['up'] = str(
|
||||
round(float(tmpUp) / 1024 / (ntime - web.ctx.session.otime), 2))
|
||||
if networkInfo['down'] < 0:
|
||||
networkInfo['down'] = 0
|
||||
if networkInfo['up'] < 0:
|
||||
networkInfo['up'] = 0
|
||||
|
||||
web.ctx.session.up = networkInfo['upTotal']
|
||||
web.ctx.session.down = networkInfo['downTotal']
|
||||
web.ctx.session.otime = ntime
|
||||
networkInfo['cpu'] = self.GetCpuInfo()
|
||||
return networkInfo
|
||||
|
||||
def ServiceAdmin(self, get=None):
|
||||
# 服务管理
|
||||
|
||||
if get.name == 'mysqld':
|
||||
public.CheckMyCnf()
|
||||
|
||||
if get.name == 'phpmyadmin':
|
||||
import ajax
|
||||
get.status = 'True'
|
||||
ajax.ajax().setPHPMyAdmin(get)
|
||||
return public.returnMsg(True, 'SYS_EXEC_SUCCESS')
|
||||
|
||||
# 检查httpd配置文件
|
||||
if get.name == 'apache' or get.name == 'httpd':
|
||||
get.name = 'httpd'
|
||||
if not os.path.exists(self.setupPath + '/apache/bin/apachectl'):
|
||||
return public.returnMsg(True, 'SYS_NOT_INSTALL_APACHE')
|
||||
vhostPath = self.setupPath + '/panel/vhost/apache'
|
||||
if not os.path.exists(vhostPath):
|
||||
public.ExecShell('mkdir ' + vhostPath)
|
||||
public.ExecShell('/etc/init.d/httpd start')
|
||||
|
||||
if get.type == 'start':
|
||||
public.ExecShell('/etc/init.d/httpd stop')
|
||||
public.ExecShell('pkill -9 httpd')
|
||||
|
||||
result = public.ExecShell(
|
||||
'ulimit -n 10240 && ' + self.setupPath + '/apache/bin/apachectl -t')
|
||||
if result[1].find('Syntax OK') == -1:
|
||||
public.WriteLog("TYPE_SOFT", 'SYS_EXEC_ERR', (str(result),))
|
||||
return public.returnMsg(False, 'SYS_CONF_APACHE_ERR', (result[1].replace("\n", '<br>'),))
|
||||
|
||||
if get.type == 'restart':
|
||||
public.ExecShell('pkill -9 httpd')
|
||||
public.ExecShell('/etc/init.d/httpd start')
|
||||
|
||||
# 检查nginx配置文件
|
||||
elif get.name == 'nginx':
|
||||
vhostPath = self.setupPath + '/panel/vhost/rewrite'
|
||||
if not os.path.exists(vhostPath):
|
||||
public.ExecShell('mkdir ' + vhostPath)
|
||||
vhostPath = self.setupPath + '/panel/vhost/nginx'
|
||||
if not os.path.exists(vhostPath):
|
||||
public.ExecShell('mkdir ' + vhostPath)
|
||||
public.ExecShell('/etc/init.d/nginx start')
|
||||
|
||||
result = public.ExecShell(
|
||||
'ulimit -n 10240 && nginx -t -c ' + self.setupPath + '/nginx/conf/nginx.conf')
|
||||
if result[1].find('perserver') != -1:
|
||||
limit = self.setupPath + '/nginx/conf/nginx.conf'
|
||||
nginxConf = public.readFile(limit)
|
||||
limitConf = "limit_conn_zone $binary_remote_addr zone=perip:10m;\n\t\tlimit_conn_zone $server_name zone=perserver:10m;"
|
||||
nginxConf = nginxConf.replace(
|
||||
"#limit_conn_zone $binary_remote_addr zone=perip:10m;", limitConf)
|
||||
public.writeFile(limit, nginxConf)
|
||||
public.ExecShell('/etc/init.d/nginx start')
|
||||
return public.returnMsg(True, 'SYS_CONF_NGINX_REP')
|
||||
|
||||
if result[1].find('proxy') != -1:
|
||||
import panelSite
|
||||
panelSite.panelSite().CheckProxy(get)
|
||||
public.ExecShell('/etc/init.d/nginx start')
|
||||
return public.returnMsg(True, 'SYS_CONF_NGINX_REP')
|
||||
|
||||
# return result
|
||||
if result[1].find('successful') == -1:
|
||||
public.WriteLog("TYPE_SOFT", 'SYS_EXEC_ERR', (str(result),))
|
||||
return public.returnMsg(False, 'SYS_CONF_NGINX_ERR', (result[1].replace("\n", '<br>'),))
|
||||
|
||||
# 执行
|
||||
execStr = "/etc/init.d/" + get.name + " " + get.type
|
||||
if execStr == '/etc/init.d/pure-ftpd reload':
|
||||
execStr = self.setupPath + '/pure-ftpd/bin/pure-pw mkdb ' + \
|
||||
self.setupPath + '/pure-ftpd/etc/pureftpd.pdb'
|
||||
if execStr == '/etc/init.d/pure-ftpd start':
|
||||
os.system('pkill -9 pure-ftpd')
|
||||
if execStr == '/etc/init.d/tomcat reload':
|
||||
execStr = '/etc/init.d/tomcat stop && /etc/init.d/tomcat start'
|
||||
if execStr == '/etc/init.d/tomcat restart':
|
||||
execStr = '/etc/init.d/tomcat stop && /etc/init.d/tomcat start'
|
||||
|
||||
if get.name != 'mysqld':
|
||||
result = public.ExecShell(execStr)
|
||||
else:
|
||||
os.system(execStr)
|
||||
result = []
|
||||
result.append('')
|
||||
result.append('')
|
||||
|
||||
if result[1].find('nginx.pid') != -1:
|
||||
public.ExecShell('pkill -9 nginx && sleep 1')
|
||||
public.ExecShell('/etc/init.d/nginx start')
|
||||
if get.type != 'test':
|
||||
public.WriteLog("TYPE_SOFT", 'SYS_EXEC_SUCCESS', (execStr,))
|
||||
|
||||
if len(result[1]) > 1 and get.name != 'pure-ftpd':
|
||||
return public.returnMsg(False, '<p>警告消息: <p>' + result[1].replace('\n', '<br>'))
|
||||
return public.returnMsg(True, 'SYS_EXEC_SUCCESS')
|
||||
|
||||
def RestartServer(self, get):
|
||||
if not public.IsRestart():
|
||||
return public.returnMsg(False, 'EXEC_ERR_TASK')
|
||||
public.ExecShell("sync && /etc/init.d/bt stop && init 6 &")
|
||||
return public.returnMsg(True, 'SYS_REBOOT')
|
||||
|
||||
# 释放内存
|
||||
def ReMemory(self, get):
|
||||
os.system('sync')
|
||||
scriptFile = 'script/rememory.sh'
|
||||
if not os.path.exists(scriptFile):
|
||||
public.downloadFile(web.ctx.session.home +
|
||||
'/script/rememory.sh', scriptFile)
|
||||
public.ExecShell("/bin/bash " + self.setupPath +
|
||||
'/panel/' + scriptFile)
|
||||
return self.GetMemInfo()
|
||||
|
||||
# 重启面板
|
||||
def ReWeb(self, get):
|
||||
# if not public.IsRestart(): return
|
||||
# public.returnMsg(False,'EXEC_ERR_TASK');
|
||||
public.ExecShell('/etc/init.d/bt restart &')
|
||||
return True
|
||||
|
||||
# 修复面板
|
||||
def RepPanel(self, get):
|
||||
vp = ''
|
||||
if public.readFile('/www/server/panel/class/common.py').find('checkSafe') != -1:
|
||||
vp = '_pro'
|
||||
public.ExecShell("wget -O update.sh " + public.get_url() +
|
||||
"/install/update" + vp + ".sh && bash update.sh")
|
||||
if hasattr(web.ctx.session, 'getCloudPlugin'):
|
||||
del(web.ctx.session['getCloudPlugin'])
|
||||
return True
|
||||
|
||||
# 升级到专业版
|
||||
def UpdatePro(self, get):
|
||||
public.ExecShell("wget -O update.sh " + public.get_url() +
|
||||
"/install/update_pro.sh && bash update.sh pro")
|
||||
if hasattr(web.ctx.session, 'getCloudPlugin'):
|
||||
del(web.ctx.session['getCloudPlugin'])
|
||||
return True
|
||||
Executable
+408
@@ -0,0 +1,408 @@
|
||||
# coding: utf-8
|
||||
|
||||
import psutil
|
||||
import time
|
||||
import os
|
||||
import re
|
||||
import math
|
||||
|
||||
|
||||
import public
|
||||
from flask import Flask, session
|
||||
|
||||
|
||||
class system_api:
|
||||
setupPath = None
|
||||
pids = None
|
||||
|
||||
def __init__(self):
|
||||
self.setupPath = '/www/server'
|
||||
|
||||
# 名取PID
|
||||
def getPid(self, pname):
|
||||
try:
|
||||
if not self.pids:
|
||||
self.pids = psutil.pids()
|
||||
for pid in self.pids:
|
||||
if psutil.Process(pid).name() == pname:
|
||||
return True
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
|
||||
# 检测指定进程是否存活
|
||||
def checkProcess(self, pid):
|
||||
try:
|
||||
if not self.pids:
|
||||
self.pids = psutil.pids()
|
||||
if int(pid) in self.pids:
|
||||
return True
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
|
||||
def getPanelInfo(self, get=None):
|
||||
# 取面板配置
|
||||
address = public.GetLocalIp()
|
||||
try:
|
||||
try:
|
||||
port = web.ctx.host.split(':')[1]
|
||||
except:
|
||||
port = public.readFile('data/port.pl')
|
||||
except:
|
||||
port = '8888'
|
||||
domain = ''
|
||||
if os.path.exists('data/domain.conf'):
|
||||
domain = public.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')
|
||||
|
||||
templates = []
|
||||
for template in os.listdir('templates/'):
|
||||
if os.path.isdir('templates/' + template):
|
||||
templates.append(template)
|
||||
template = public.readFile('data/templates.pl')
|
||||
|
||||
check502 = ''
|
||||
if os.path.exists('data/502Task.pl'):
|
||||
check502 = 'checked'
|
||||
return {'port': port, 'address': address, 'domain': domain, 'auto': autoUpdate, '502': check502, 'limitip': limitip, 'templates': templates, 'template': template}
|
||||
|
||||
def getSystemTotal(self, interval=1):
|
||||
# 取系统统计信息
|
||||
data = self.getMemInfo()
|
||||
cpu = self.getCpuInfo(interval)
|
||||
data['cpuNum'] = cpu[1]
|
||||
data['cpuRealUsed'] = cpu[0]
|
||||
data['time'] = self.getBootTime()
|
||||
data['system'] = self.getSystemVersion()
|
||||
data['isuser'] = public.M('users').where(
|
||||
'username=?', ('admin',)).count()
|
||||
data['version'] = '0.0.1'
|
||||
return data
|
||||
|
||||
def getLoadAverage(self, get=None):
|
||||
c = os.getloadavg()
|
||||
data = {}
|
||||
data['one'] = float(c[0])
|
||||
data['five'] = float(c[1])
|
||||
data['fifteen'] = float(c[2])
|
||||
data['max'] = psutil.cpu_count() * 2
|
||||
data['limit'] = data['max']
|
||||
data['safe'] = data['max'] * 0.75
|
||||
return data
|
||||
|
||||
def getAllInfo(self, get):
|
||||
data = {}
|
||||
data['load_average'] = self.GetLoadAverage(get)
|
||||
data['title'] = self.GetTitle()
|
||||
data['network'] = self.GetNetWorkApi(get)
|
||||
data['panel_status'] = not os.path.exists(
|
||||
'/www/server/panel/data/close.pl')
|
||||
import firewalls
|
||||
ssh_info = firewalls.firewalls().GetSshInfo(None)
|
||||
data['enable_ssh_status'] = ssh_info['status']
|
||||
data['disable_ping_status'] = not ssh_info['ping']
|
||||
data['time'] = self.GetBootTime()
|
||||
# data['system'] = self.GetSystemVersion();
|
||||
# data['mem'] = self.GetMemInfo();
|
||||
data['version'] = web.ctx.session.version
|
||||
return data
|
||||
|
||||
def getTitle(self):
|
||||
titlePl = 'data/title.pl'
|
||||
title = '宝塔Linux面板'
|
||||
if os.path.exists(titlePl):
|
||||
title = public.readFile(titlePl).strip()
|
||||
return title
|
||||
|
||||
def getSystemVersion(self):
|
||||
# 取操作系统版本
|
||||
os = public.getOs()
|
||||
if os == 'darwin':
|
||||
return os
|
||||
|
||||
version = public.readFile('/etc/redhat-release')
|
||||
if not version:
|
||||
version = public.readFile(
|
||||
'/etc/issue').strip().split("\n")[0].replace('\\n', '').replace('\l', '').strip()
|
||||
else:
|
||||
version = version.replace('release ', '').strip()
|
||||
return version
|
||||
|
||||
def getBootTime(self):
|
||||
# 取系统启动时间
|
||||
start_time = psutil.boot_time()
|
||||
run_time = time.time() - start_time
|
||||
# conf = public.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.getMsg('SYS_BOOT_TIME', (str(int(days)), str(int(hours)), str(int(min))))
|
||||
|
||||
def getCpuInfo(self, interval=1):
|
||||
# 取CPU信息
|
||||
cpuCount = psutil.cpu_count()
|
||||
used = psutil.cpu_percent(interval=interval)
|
||||
return used, cpuCount
|
||||
|
||||
def getMemInfo(self, get=None):
|
||||
# 取内存信息
|
||||
mem = psutil.virtual_memory()
|
||||
if public.getOs() == 'darwin':
|
||||
memInfo = {
|
||||
'memTotal': mem.total / 1024 / 1024
|
||||
}
|
||||
memInfo['memRealUsed'] = memInfo['memTotal'] * (mem.percent / 100)
|
||||
else:
|
||||
memInfo = {
|
||||
'memTotal': mem.total / 1024 / 1024,
|
||||
'memFree': mem.free / 1024 / 1024,
|
||||
'memBuffers': mem.buffers / 1024 / 1024,
|
||||
'memCached': mem.cached / 1024 / 1024
|
||||
}
|
||||
|
||||
memInfo['memRealUsed'] = memInfo['memTotal'] - \
|
||||
memInfo['memFree'] - memInfo['memBuffers'] - \
|
||||
memInfo['memCached']
|
||||
return memInfo
|
||||
|
||||
def getDiskInfo(self, get=None):
|
||||
return self.getDiskInfo2()
|
||||
# 取磁盘分区信息
|
||||
diskIo = psutil.disk_partitions()
|
||||
diskInfo = []
|
||||
|
||||
for disk in diskIo:
|
||||
if disk[1] == '/mnt/cdrom':
|
||||
continue
|
||||
if disk[1] == '/boot':
|
||||
continue
|
||||
tmp = {}
|
||||
tmp['path'] = disk[1]
|
||||
tmp['size'] = psutil.disk_usage(disk[1])
|
||||
diskInfo.append(tmp)
|
||||
return diskInfo
|
||||
|
||||
def getDiskInfo2(self):
|
||||
# 取磁盘分区信息
|
||||
temp = public.execShell(
|
||||
"df -h -P|grep '/'|grep -v tmpfs | grep -v devfs")[0]
|
||||
tempInodes = public.execShell(
|
||||
"df -i -P|grep '/'|grep -v tmpfs | grep -v devfs")[0]
|
||||
temp1 = temp.split('\n')
|
||||
tempInodes1 = tempInodes.split('\n')
|
||||
diskInfo = []
|
||||
n = 0
|
||||
cuts = ['/mnt/cdrom', '/boot', '/boot/efi', '/dev',
|
||||
'/dev/shm', '/run/lock', '/run', '/run/shm', '/run/user']
|
||||
for tmp in temp1:
|
||||
n += 1
|
||||
inodes = tempInodes1[n - 1].split()
|
||||
disk = tmp.split()
|
||||
if len(disk) < 5:
|
||||
continue
|
||||
if disk[1].find('M') != -1:
|
||||
continue
|
||||
if disk[1].find('K') != -1:
|
||||
continue
|
||||
if len(disk[5].split('/')) > 4:
|
||||
continue
|
||||
if disk[5] in cuts:
|
||||
continue
|
||||
arr = {}
|
||||
arr['path'] = disk[5]
|
||||
tmp1 = [disk[1], disk[2], disk[3], disk[4]]
|
||||
arr['size'] = tmp1
|
||||
arr['inodes'] = [inodes[1], inodes[2], inodes[3], inodes[4]]
|
||||
if disk[5] == '/':
|
||||
bootLog = os.getcwd() + '/tmp/panelBoot.pl'
|
||||
if disk[2].find('M') != -1:
|
||||
if os.path.exists(bootLog):
|
||||
os.system('rm -f ' + bootLog)
|
||||
else:
|
||||
if not os.path.exists(bootLog):
|
||||
pass
|
||||
if inodes[2] != '0':
|
||||
diskInfo.append(arr)
|
||||
return diskInfo
|
||||
|
||||
# 清理系统垃圾
|
||||
def clearSystem(self, get):
|
||||
count = total = 0
|
||||
tmp_total, tmp_count = self.ClearMail()
|
||||
count += tmp_count
|
||||
total += tmp_total
|
||||
tmp_total, tmp_count = self.ClearOther()
|
||||
count += tmp_count
|
||||
total += tmp_total
|
||||
return count, total
|
||||
|
||||
# 清理邮件日志
|
||||
def clearMail(self):
|
||||
rpath = '/var/spool'
|
||||
total = count = 0
|
||||
import shutil
|
||||
con = ['cron', 'anacron', 'mail']
|
||||
for d in os.listdir(rpath):
|
||||
if d in con:
|
||||
continue
|
||||
dpath = rpath + '/' + d
|
||||
time.sleep(0.2)
|
||||
num = size = 0
|
||||
for n in os.listdir(dpath):
|
||||
filename = dpath + '/' + n
|
||||
fsize = os.path.getsize(filename)
|
||||
size += fsize
|
||||
if os.path.isdir(filename):
|
||||
shutil.rmtree(filename)
|
||||
else:
|
||||
os.remove(filename)
|
||||
print '\t\033[1;32m[OK]\033[0m'
|
||||
num += 1
|
||||
total += size
|
||||
count += num
|
||||
return total, count
|
||||
|
||||
# 清理其它
|
||||
def clearOther(self):
|
||||
clearPath = [
|
||||
{'path': '/www/server/panel', 'find': 'testDisk_'},
|
||||
{'path': '/www/wwwlogs', 'find': 'log'},
|
||||
{'path': '/tmp', 'find': 'panelBoot.pl'},
|
||||
{'path': '/www/server/panel/install', 'find': '.rpm'}
|
||||
]
|
||||
|
||||
total = count = 0
|
||||
for c in clearPath:
|
||||
for d in os.listdir(c['path']):
|
||||
if d.find(c['find']) == -1:
|
||||
continue
|
||||
filename = c['path'] + '/' + d
|
||||
fsize = os.path.getsize(filename)
|
||||
total += fsize
|
||||
if os.path.isdir(filename):
|
||||
shutil.rmtree(filename)
|
||||
else:
|
||||
os.remove(filename)
|
||||
count += 1
|
||||
public.serviceReload()
|
||||
os.system('echo > /tmp/panelBoot.pl')
|
||||
return total, count
|
||||
|
||||
def getNetWork(self, get=None):
|
||||
# return self.GetNetWorkApi(get);
|
||||
# 取网络流量信息
|
||||
try:
|
||||
# 取网络流量信息
|
||||
networkIo = psutil.net_io_counters()[:4]
|
||||
if not "otime" in session:
|
||||
session['up'] = networkIo[0]
|
||||
session['down'] = networkIo[1]
|
||||
session['otime'] = time.time()
|
||||
|
||||
ntime = time.time()
|
||||
networkInfo = {}
|
||||
networkInfo['upTotal'] = networkIo[0]
|
||||
networkInfo['downTotal'] = networkIo[1]
|
||||
networkInfo['up'] = round(float(
|
||||
networkIo[0] - session['up']) / 1024 / (ntime - session['otime']), 2)
|
||||
networkInfo['down'] = round(
|
||||
float(networkIo[1] - session['down']) / 1024 / (ntime - session['otime']), 2)
|
||||
networkInfo['downPackets'] = networkIo[3]
|
||||
networkInfo['upPackets'] = networkIo[2]
|
||||
|
||||
# print networkIo[1], session['down'], ntime, session['otime']
|
||||
session['up'] = networkIo[0]
|
||||
session['down'] = networkIo[1]
|
||||
session['otime'] = time.time()
|
||||
|
||||
networkInfo['cpu'] = self.getCpuInfo()
|
||||
networkInfo['load'] = self.getLoadAverage(get)
|
||||
networkInfo['mem'] = self.getMemInfo(get)
|
||||
|
||||
return networkInfo
|
||||
except Exception, e:
|
||||
return None
|
||||
|
||||
def getNetWorkApi(self, get=None):
|
||||
# 取网络流量信息
|
||||
try:
|
||||
tmpfile = 'data/network.temp'
|
||||
networkIo = psutil.net_io_counters()[:4]
|
||||
|
||||
if not os.path.exists(tmpfile):
|
||||
public.writeFile(tmpfile, str(
|
||||
networkIo[0]) + '|' + str(networkIo[1]) + '|' + str(int(time.time())))
|
||||
|
||||
lastValue = public.readFile(tmpfile).split('|')
|
||||
|
||||
ntime = time.time()
|
||||
networkInfo = {}
|
||||
networkInfo['upTotal'] = networkIo[0]
|
||||
networkInfo['downTotal'] = networkIo[1]
|
||||
networkInfo['up'] = round(
|
||||
float(networkIo[0] - int(lastValue[0])) / 1024 / (ntime - int(lastValue[2])), 2)
|
||||
networkInfo['down'] = round(
|
||||
float(networkIo[1] - int(lastValue[1])) / 1024 / (ntime - int(lastValue[2])), 2)
|
||||
networkInfo['downPackets'] = networkIo[3]
|
||||
networkInfo['upPackets'] = networkIo[2]
|
||||
|
||||
public.writeFile(tmpfile, str(
|
||||
networkIo[0]) + '|' + str(networkIo[1]) + '|' + str(int(time.time())))
|
||||
|
||||
# networkInfo['cpu'] = self.GetCpuInfo(0.1)
|
||||
return networkInfo
|
||||
except:
|
||||
return None
|
||||
|
||||
def restartServer(self, get):
|
||||
if not public.IsRestart():
|
||||
return public.returnMsg(False, 'EXEC_ERR_TASK')
|
||||
public.ExecShell("sync && /etc/init.d/bt stop && init 6 &")
|
||||
return public.returnMsg(True, 'SYS_REBOOT')
|
||||
|
||||
# 释放内存
|
||||
def reMemory(self, get):
|
||||
os.system('sync')
|
||||
scriptFile = 'script/rememory.sh'
|
||||
if not os.path.exists(scriptFile):
|
||||
public.downloadFile(web.ctx.session.home +
|
||||
'/script/rememory.sh', scriptFile)
|
||||
public.ExecShell("/bin/bash " + self.setupPath +
|
||||
'/panel/' + scriptFile)
|
||||
return self.GetMemInfo()
|
||||
|
||||
# 重启面板
|
||||
def reWeb(self, get):
|
||||
# if not public.IsRestart(): return
|
||||
# public.returnMsg(False,'EXEC_ERR_TASK');
|
||||
public.ExecShell('/etc/init.d/bt restart &')
|
||||
return True
|
||||
|
||||
# 修复面板
|
||||
def repPanel(self, get):
|
||||
vp = ''
|
||||
if public.readFile('/www/server/panel/class/common.py').find('checkSafe') != -1:
|
||||
vp = '_pro'
|
||||
public.ExecShell("wget -O update.sh " + public.get_url() +
|
||||
"/install/update" + vp + ".sh && bash update.sh")
|
||||
if hasattr(web.ctx.session, 'getCloudPlugin'):
|
||||
del(web.ctx.session['getCloudPlugin'])
|
||||
return True
|
||||
|
||||
# 升级到专业版
|
||||
def updatePro(self, get):
|
||||
public.ExecShell("wget -O update.sh " + public.get_url() +
|
||||
"/install/update_pro.sh && bash update.sh pro")
|
||||
if hasattr(web.ctx.session, 'getCloudPlugin'):
|
||||
del(web.ctx.session['getCloudPlugin'])
|
||||
return True
|
||||
@@ -15,11 +15,11 @@ Install_openresty()
|
||||
mkdir -p $serverPath/tmp
|
||||
echo '正在安装脚本文件...' > $install_tmp
|
||||
|
||||
wget -O $serverPath/tmp/openresty.tar.gz https://openresty.org/download/openresty-1.13.6.2.tar.gz
|
||||
cd $serverPath/tmp && tar -zxvf openresty.tar.gz
|
||||
#wget -O $serverPath/tmp/openresty.tar.gz https://openresty.org/download/openresty-1.13.6.2.tar.gz
|
||||
#cd $serverPath/tmp && tar -zxvf openresty.tar.gz
|
||||
|
||||
mkdir -p $serverPath/openresty
|
||||
cd openresty* && ./configure --prefix=$serverPath/openresty && make && make install
|
||||
cd $serverPath/tmp/openresty* && ./configure --prefix=$serverPath/openresty && make && make install
|
||||
|
||||
echo '安装完成' > $install_tmp
|
||||
#rm -rf $serverPath/tmp
|
||||
|
||||
+7
-174
@@ -9,140 +9,17 @@ from flask import Flask, session
|
||||
from flask import Blueprint, render_template
|
||||
from flask import jsonify
|
||||
|
||||
sys.path.append("class/")
|
||||
sys.path.append("class/core")
|
||||
import public
|
||||
|
||||
import system_api
|
||||
|
||||
system = Blueprint('system', __name__, template_folder='templates')
|
||||
|
||||
|
||||
def GetCpuInfo(interval=1):
|
||||
# 取CPU信息
|
||||
cpuCount = psutil.cpu_count()
|
||||
used = psutil.cpu_percent(interval=interval)
|
||||
return used, cpuCount
|
||||
|
||||
|
||||
def GetLoadAverage():
|
||||
c = os.getloadavg()
|
||||
data = {}
|
||||
data['one'] = float(c[0])
|
||||
data['five'] = float(c[1])
|
||||
data['fifteen'] = float(c[2])
|
||||
data['max'] = psutil.cpu_count() * 2
|
||||
data['limit'] = data['max']
|
||||
data['safe'] = data['max'] * 0.75
|
||||
return data
|
||||
|
||||
|
||||
def GetMemInfo():
|
||||
# 取内存信息
|
||||
mem = psutil.virtual_memory()
|
||||
memInfo = {'memTotal': mem.total / 1024 / 1024,
|
||||
'memFree': mem.free / 1024 / 1024,
|
||||
# 'memBuffers': mem.buffers / 1024 / 1024,
|
||||
# 'memCached': mem.cached / 1024 / 1024
|
||||
}
|
||||
|
||||
memInfo['memRealUsed'] = memInfo['memTotal'] - \
|
||||
memInfo['memFree']
|
||||
#- memInfo['memBuffers'] - memInfo['memCached']
|
||||
return memInfo
|
||||
|
||||
|
||||
def GetBootTime():
|
||||
conf = public.readFile('/proc/uptime').split()
|
||||
tStr = float(conf[0])
|
||||
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.getMsg('SYS_BOOT_TIME', (str(int(days)), str(int(hours)), str(int(min))))
|
||||
|
||||
|
||||
def GetSystemVersion():
|
||||
# 取操作系统版本
|
||||
version = public.readFile('/etc/redhat-release')
|
||||
if not version:
|
||||
version = public.readFile(
|
||||
'/etc/issue').strip().split("\n")[0].replace('\\n', '').replace('\l', '').strip()
|
||||
else:
|
||||
version = version.replace('release ', '').strip()
|
||||
return version
|
||||
|
||||
|
||||
@system.route("/network")
|
||||
def network():
|
||||
# 取网络流量信息
|
||||
networkIo = psutil.net_io_counters()[:4]
|
||||
if not hasattr(session, 'otime'):
|
||||
session['up'] = networkIo[0]
|
||||
session['down'] = networkIo[1]
|
||||
session['otime'] = time.time()
|
||||
|
||||
ntime = time.time()
|
||||
networkInfo = {}
|
||||
networkInfo['upTotal'] = networkIo[0]
|
||||
networkInfo['downTotal'] = networkIo[1]
|
||||
networkInfo['up'] = round(float(
|
||||
networkIo[0] - session['up']) / 1024 / (ntime - session['otime']), 2)
|
||||
networkInfo['down'] = round(
|
||||
float(networkIo[1] - session['down']) / 1024 / (ntime - session['otime']), 2)
|
||||
networkInfo['downPackets'] = networkIo[3]
|
||||
networkInfo['upPackets'] = networkIo[2]
|
||||
|
||||
session['up'] = networkIo[0]
|
||||
session['down'] = networkIo[1]
|
||||
session['otime'] = time.time()
|
||||
|
||||
networkInfo['cpu'] = GetCpuInfo()
|
||||
networkInfo['load'] = GetLoadAverage()
|
||||
return jsonify(networkInfo)
|
||||
|
||||
|
||||
@system.route("/diskinfo")
|
||||
def diskinfo():
|
||||
# 取磁盘分区信息
|
||||
temp = public.ExecShell("df -h -P|grep '/'|grep -v tmpfs")[0]
|
||||
tempInodes = public.ExecShell("df -i -P|grep '/'|grep -v tmpfs")[0]
|
||||
temp1 = temp.split('\n')
|
||||
tempInodes1 = tempInodes.split('\n')
|
||||
diskInfo = []
|
||||
n = 0
|
||||
cuts = ['/mnt/cdrom', '/boot', '/boot/efi', '/dev',
|
||||
'/dev/shm', '/run/lock', '/run', '/run/shm', '/run/user']
|
||||
for tmp in temp1:
|
||||
n += 1
|
||||
inodes = tempInodes1[n - 1].split()
|
||||
disk = tmp.split()
|
||||
if len(disk) < 5:
|
||||
continue
|
||||
if disk[1].find('M') != -1:
|
||||
continue
|
||||
if disk[1].find('K') != -1:
|
||||
continue
|
||||
if len(disk[5].split('/')) > 4:
|
||||
continue
|
||||
if disk[5] in cuts:
|
||||
continue
|
||||
arr = {}
|
||||
arr['path'] = disk[5]
|
||||
tmp1 = [disk[1], disk[2], disk[3], disk[4]]
|
||||
arr['size'] = tmp1
|
||||
arr['inodes'] = [inodes[1], inodes[2], inodes[3], inodes[4]]
|
||||
if disk[5] == '/':
|
||||
bootLog = '/tmp/panelBoot.pl'
|
||||
if disk[2].find('M') != -1:
|
||||
if os.path.exists(bootLog):
|
||||
os.system('rm -f ' + bootLog)
|
||||
else:
|
||||
pass
|
||||
if not os.path.exists(bootLog):
|
||||
os.system('sleep 1 &')
|
||||
# print arr
|
||||
diskInfo.append(arr)
|
||||
return jsonify(diskInfo)
|
||||
data = system_api.system_api().getNetWork()
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
@system.route("/update_panel")
|
||||
@@ -152,55 +29,11 @@ def updatePanel():
|
||||
|
||||
@system.route("/system_total")
|
||||
def systemTotal():
|
||||
# 取系统统计信息
|
||||
data = GetMemInfo()
|
||||
cpu = GetCpuInfo(1)
|
||||
data['cpuNum'] = cpu[1]
|
||||
data['cpuRealUsed'] = cpu[0]
|
||||
# data['time'] = GetBootTime()
|
||||
# data['system'] = GetSystemVersion()
|
||||
data['isuser'] = public.M('users').where('username=?', ('admin',)).count()
|
||||
data['version'] = '0.0.1'
|
||||
return jsonify(data)
|
||||
data = system_api.system_api().getSystemTotal()
|
||||
return public.getJson(data)
|
||||
|
||||
|
||||
@system.route("/disk_info")
|
||||
def diskInfo():
|
||||
# 取磁盘分区信息
|
||||
temp = public.execShell("df -h -P|grep '/'|grep -v tmpfs")[0]
|
||||
tempInodes = public.execShell("df -i -P|grep '/'|grep -v tmpfs")[0]
|
||||
temp1 = temp.split('\n')
|
||||
tempInodes1 = tempInodes.split('\n')
|
||||
diskInfo = []
|
||||
n = 0
|
||||
cuts = ['/mnt/cdrom', '/boot', '/boot/efi', '/dev',
|
||||
'/dev/shm', '/run/lock', '/run', '/run/shm', '/run/user']
|
||||
for tmp in temp1:
|
||||
n += 1
|
||||
inodes = tempInodes1[n - 1].split()
|
||||
disk = tmp.split()
|
||||
if len(disk) < 5:
|
||||
continue
|
||||
if disk[1].find('M') != -1:
|
||||
continue
|
||||
if disk[1].find('K') != -1:
|
||||
continue
|
||||
if len(disk[5].split('/')) > 4:
|
||||
continue
|
||||
if disk[5] in cuts:
|
||||
continue
|
||||
arr = {}
|
||||
arr['path'] = disk[5]
|
||||
tmp1 = [disk[1], disk[2], disk[3], disk[4]]
|
||||
arr['size'] = tmp1
|
||||
arr['inodes'] = [inodes[1], inodes[2], inodes[3], inodes[4]]
|
||||
if disk[5] == '/':
|
||||
bootLog = os.getcwd() + '/tmp/panelBoot.pl'
|
||||
if disk[2].find('M') != -1:
|
||||
if os.path.exists(bootLog):
|
||||
os.system('rm -f ' + bootLog)
|
||||
else:
|
||||
if not os.path.exists(bootLog):
|
||||
pass
|
||||
diskInfo.append(arr)
|
||||
diskInfo = system_api.system_api().getDiskInfo()
|
||||
return public.getJson(diskInfo)
|
||||
|
||||
Executable
+244
@@ -0,0 +1,244 @@
|
||||
#!/bin/bash
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
export PATH
|
||||
public_file=/www/server/panel/install/public.sh
|
||||
if [ ! -f $public_file ];then
|
||||
wget -O $public_file http://download.bt.cn/install/public.sh -T 5;
|
||||
fi
|
||||
. $public_file
|
||||
download_Url=$NODE_URL
|
||||
mkdir -p /www/server
|
||||
run_path="/root"
|
||||
Is_64bit=`getconf LONG_BIT`
|
||||
|
||||
centos_version=`cat /etc/redhat-release | grep ' 7.' | grep -i centos`
|
||||
if [ "${centos_version}" != '' ]; then
|
||||
rpm_path="centos7"
|
||||
else
|
||||
rpm_path="centos6"
|
||||
fi
|
||||
|
||||
Install_SendMail()
|
||||
{
|
||||
yum install postfix mysql-libs -y
|
||||
if [ "${centos_version}" != '' ];then
|
||||
systemctl start postfix
|
||||
systemctl enable postfix
|
||||
else
|
||||
service postfix start
|
||||
chkconfig --level 2345 postfix on
|
||||
fi
|
||||
}
|
||||
|
||||
Install_Curl()
|
||||
{
|
||||
if [ -f "/usr/local/curl/newcurl.pl" ];then
|
||||
return;
|
||||
fi
|
||||
cd ${run_path}
|
||||
curl_version="7.54.1"
|
||||
if [ ! -f "curl-$curl_version.tar.gz" ];then
|
||||
wget -O curl-$curl_version.tar.gz ${download_Url}/src/curl-$curl_version.tar.gz -T 5
|
||||
fi
|
||||
tar zxf curl-$curl_version.tar.gz
|
||||
cd curl-$curl_version
|
||||
./configure --prefix=/usr/local/curl --enable-ares --without-nss --with-ssl=/usr/local/openssl
|
||||
make && make install
|
||||
cd ..
|
||||
rm -rf curl-$curl_version
|
||||
rm -rf curl-$curl_version.tar.gz
|
||||
echo -e "Install_Curl" >> /www/server/lib.pl
|
||||
echo -e "Ture" >> /usr/local/curl/newcurl.pl
|
||||
}
|
||||
|
||||
Install_Libiconv()
|
||||
{
|
||||
if [ -d '/usr/local/libiconv' ];then
|
||||
return
|
||||
fi
|
||||
cd ${run_path}
|
||||
if [ ! -f "libiconv-1.14.tar.gz" ];then
|
||||
wget -O libiconv-1.14.tar.gz ${download_Url}/src/libiconv-1.14.tar.gz -T 5
|
||||
fi
|
||||
mkdir /patch
|
||||
wget -O /patch/libiconv-glibc-2.16.patch ${download_Url}/src/patch/libiconv-glibc-2.16.patch -T 5
|
||||
tar zxf libiconv-1.14.tar.gz
|
||||
cd libiconv-1.14
|
||||
patch -p0 < /patch/libiconv-glibc-2.16.patch
|
||||
./configure --prefix=/usr/local/libiconv --enable-static
|
||||
make && make install
|
||||
cd ${run_path}
|
||||
rm -rf libiconv-1.14
|
||||
rm -f libiconv-1.14.tar.gz
|
||||
echo -e "Install_Libiconv" >> /www/server/lib.pl
|
||||
}
|
||||
|
||||
Install_Libmcrypt()
|
||||
{
|
||||
if [ -f '/usr/local/lib/libmcrypt.so' ];then
|
||||
return;
|
||||
fi
|
||||
cd ${run_path}
|
||||
if [ ! -f "libmcrypt-2.5.8.tar.gz" ];then
|
||||
wget -O libmcrypt-2.5.8.tar.gz ${download_Url}/src/libmcrypt-2.5.8.tar.gz -T 5
|
||||
fi
|
||||
tar zxf libmcrypt-2.5.8.tar.gz
|
||||
cd libmcrypt-2.5.8
|
||||
|
||||
./configure
|
||||
make && make install
|
||||
/sbin/ldconfig
|
||||
cd libltdl/
|
||||
./configure --enable-ltdl-install
|
||||
make && make install
|
||||
ln -sf /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
|
||||
ln -sf /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
|
||||
ln -sf /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
|
||||
ln -sf /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
|
||||
ldconfig
|
||||
cd ${run_path}
|
||||
rm -rf libmcrypt-2.5.8
|
||||
rm -f libmcrypt-2.5.8.tar.gz
|
||||
echo -e "Install_Libmcrypt" >> /www/server/lib.pl
|
||||
}
|
||||
|
||||
Install_Mcrypt()
|
||||
{
|
||||
if [ -f '/usr/bin/mcrypt' ] || [ -f '/usr/local/bin/mcrypt' ];then
|
||||
return;
|
||||
fi
|
||||
cd ${run_path}
|
||||
if [ ! -f "mcrypt-2.6.8.tar.gz" ];then
|
||||
wget -O mcrypt-2.6.8.tar.gz ${download_Url}/src/mcrypt-2.6.8.tar.gz -T 5
|
||||
fi
|
||||
tar zxf mcrypt-2.6.8.tar.gz
|
||||
cd mcrypt-2.6.8
|
||||
./configure
|
||||
make && make install
|
||||
cd ${run_path}
|
||||
rm -rf mcrypt-2.6.8
|
||||
rm -f mcrypt-2.6.8.tar.gz
|
||||
echo -e "Install_Mcrypt" >> /www/server/lib.pl
|
||||
}
|
||||
|
||||
Install_Mhash()
|
||||
{
|
||||
if [ -f '/usr/local/lib/libmhash.so' ];then
|
||||
return;
|
||||
fi
|
||||
cd ${run_path}
|
||||
if [ ! -f "mhash-0.9.9.9.tar.gz" ];then
|
||||
wget -O mhash-0.9.9.9.tar.gz ${download_Url}/src/mhash-0.9.9.9.tar.gz -T 5
|
||||
fi
|
||||
tar zxf mhash-0.9.9.9.tar.gz
|
||||
cd mhash-0.9.9.9
|
||||
./configure
|
||||
make && make install
|
||||
ln -sf /usr/local/lib/libmhash.a /usr/lib/libmhash.a
|
||||
ln -sf /usr/local/lib/libmhash.la /usr/lib/libmhash.la
|
||||
ln -sf /usr/local/lib/libmhash.so /usr/lib/libmhash.so
|
||||
ln -sf /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
|
||||
ln -sf /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
|
||||
ldconfig
|
||||
cd ${run_path}
|
||||
rm -rf mhash-0.9.9.9*
|
||||
echo -e "Install_Mhash" >> /www/server/lib.pl
|
||||
}
|
||||
|
||||
|
||||
Install_Freetype()
|
||||
{
|
||||
if [ -d /usr/local/freetype ];then
|
||||
return;
|
||||
fi
|
||||
cd ${run_path}
|
||||
if [ ! -f "freetype-2.4.12.tar.gz" ];then
|
||||
wget -O freetype-2.4.12.tar.gz ${download_Url}/src/freetype-2.4.12.tar.gz -T 5
|
||||
fi
|
||||
tar zxf freetype-2.4.12.tar.gz
|
||||
cd freetype-2.4.12
|
||||
./configure --prefix=/usr/local/freetype
|
||||
make && make install
|
||||
|
||||
cat > /etc/ld.so.conf.d/freetype.conf<<EOF
|
||||
/usr/local/freetype/lib
|
||||
EOF
|
||||
ldconfig
|
||||
ln -sf /usr/local/freetype/include/freetype2 /usr/local/include
|
||||
ln -sf /usr/local/freetype/include/ft2build.h /usr/local/include
|
||||
cd ${run_path}
|
||||
rm -rf freetype-2.4.12
|
||||
rm -f freetype-2.4.12.tar.gz
|
||||
echo -e "Install_Freetype" >> /www/server/lib.pl
|
||||
}
|
||||
|
||||
Install_Pcre()
|
||||
{
|
||||
Cur_Pcre_Ver=`pcre-config --version|grep '^8.' 2>&1`
|
||||
if [ "$Cur_Pcre_Ver" == "" ];then
|
||||
pcre_version=8.40
|
||||
wget -O pcre-$pcre_version.tar.gz ${download_Url}/src/pcre-$pcre_version.tar.gz -T 5
|
||||
tar zxf pcre-$pcre_version.tar.gz
|
||||
cd pcre-$pcre_version
|
||||
if [ "$Is_64bit" == "64" ];then
|
||||
./configure --prefix=/usr --docdir=/usr/share/doc/pcre-$pcre_version --libdir=/usr/lib64 --enable-unicode-properties --enable-pcre16 --enable-pcre32 --enable-pcregrep-libz --enable-pcregrep-libbz2 --enable-pcretest-libreadline --disable-static --enable-utf8
|
||||
else
|
||||
./configure --prefix=/usr --docdir=/usr/share/doc/pcre-$pcre_version --enable-unicode-properties --enable-pcre16 --enable-pcre32 --enable-pcregrep-libz --enable-pcregrep-libbz2 --enable-pcretest-libreadline --disable-static --enable-utf8
|
||||
fi
|
||||
make && make install
|
||||
cd ..
|
||||
rm -rf pcre-$pcre_version
|
||||
rm -f pcre-$pcre_version.tar.gz
|
||||
fi
|
||||
}
|
||||
|
||||
Install_OpenSSL()
|
||||
{
|
||||
if [ ! -d "/usr/local/openssl" ];then
|
||||
cd ${run_path}
|
||||
wget ${download_Url}/src/openssl-1.0.2l.tar.gz -T 20
|
||||
tar -zxf openssl-1.0.2l.tar.gz
|
||||
rm -f openssl-1.0.2l.tar.gz
|
||||
cd openssl-1.0.2l
|
||||
./config --openssldir=/usr/local/openssl zlib-dynamic shared
|
||||
make && make install
|
||||
echo '1.0.2l_shared' > /usr/local/openssl/version.pl
|
||||
cd ..
|
||||
rm -rf openssl-1.0.2l
|
||||
cat > /etc/ld.so.conf.d/openssl.conf <<EOF
|
||||
/usr/local/openssl/lib
|
||||
EOF
|
||||
ldconfig
|
||||
fi
|
||||
}
|
||||
Install_Lib()
|
||||
{
|
||||
if [ -f "/www/server/nginx/sbin/nginx" ] || [ -f "/www/server/apache/bin/httpd" ] || [ -f "/www/server/mysql/bin/mysql" ]; then
|
||||
return
|
||||
fi
|
||||
lockFile='/www/server/panel/data/bt_lib.lock'
|
||||
if [ ! -f "${lockFile}" ];then
|
||||
sed -i "s#SELINUX=enforcing#SELINUX=disabled#" /etc/selinux/config
|
||||
rpm -e --nodeps mariadb-libs-*
|
||||
|
||||
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
|
||||
rm -f /var/run/yum.pid
|
||||
for yumPack in make cmake gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel patch wget libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel tar bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal gettext gettext-devel ncurses-devel gmp-devel pspell-devel libcap diffutils ca-certificates net-tools libc-client-devel psmisc libXpm-devel git-core c-ares-devel libicu-devel libxslt libxslt-devel zip unzip glibc.i686 libstdc++.so.6 cairo-devel bison-devel ncurses-devel libaio-devel perl perl-devel perl-Data-Dumper lsof pcre pcre-devel vixie-cron crontabs expat-devel readline-devel;
|
||||
do yum -y install $yumPack;done
|
||||
|
||||
Install_SendMail
|
||||
mv /etc/yum.repos.d/epel.repo.backup /etc/yum.repos.d/epel.repo
|
||||
groupadd www
|
||||
useradd -s /sbin/nologin -M -g www www
|
||||
echo 'true' > $lockFile
|
||||
fi
|
||||
}
|
||||
|
||||
Install_Lib
|
||||
Install_OpenSSL
|
||||
Install_Pcre
|
||||
Install_Curl
|
||||
Install_Mhash
|
||||
Install_Libmcrypt
|
||||
Install_Mcrypt
|
||||
Install_Libiconv
|
||||
+37
-215
@@ -9,15 +9,11 @@ $(function() {
|
||||
$("#memory").text(lan.index.memre);
|
||||
}
|
||||
}, function() {
|
||||
if (!($(this).hasClass("mem-action"))) {
|
||||
$(this).find(".mem-re-min").show();
|
||||
} else {
|
||||
$(this).find(".mem-re-min").hide();
|
||||
}
|
||||
$(this).removeClass("shine_green");
|
||||
$(this).find(".mask").css({ "color": "#20a53a" });
|
||||
$(this).find(".mem-re-con").css({ "top": "15px", opacity: 1, "display": "none" });
|
||||
$("#memory").text(getCookie("mem-before"));
|
||||
$(this).find(".mem-re-min").hide();
|
||||
}).click(function() {
|
||||
$(this).find(".mem-re-min").hide();
|
||||
if (!($(this).hasClass("mem-action"))) {
|
||||
@@ -126,6 +122,7 @@ function GetPercent(num, total) {
|
||||
|
||||
function GetDiskInfo() {
|
||||
$.get('/system/disk_info', function(rdata) {
|
||||
console.log(rdata);
|
||||
var dBody
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
if (rdata[i].path == '/' || rdata[i].path == '/www') {
|
||||
@@ -157,7 +154,7 @@ function GetDiskInfo() {
|
||||
$("#systemInfoList").append(dBody);
|
||||
setImg();
|
||||
}
|
||||
});
|
||||
},'json');
|
||||
}
|
||||
|
||||
//清理垃圾
|
||||
@@ -169,6 +166,19 @@ function ClearSystem() {
|
||||
});
|
||||
}
|
||||
|
||||
function setMemImg(info){
|
||||
setCookie("memRealUsed", parseInt((info.memRealUsed)));
|
||||
$("#memory").html(parseInt((info.memRealUsed)) + '/' + info.memTotal + ' (MB)');
|
||||
setCookie("mem-before", $("#memory").text());
|
||||
if (!getCookie('memSize')) setCookie('memSize', parseInt(info.memTotal));
|
||||
var memPre = Math.floor(info.memRealUsed / (info.memTotal / 100));
|
||||
$("#left").html(memPre);
|
||||
setcolor(memPre, "#left", 75, 90, 95);
|
||||
$("#state").html(info.cpuRealUsed);
|
||||
setcolor(memPre, "#state", 30, 70, 90);
|
||||
setImg();
|
||||
}
|
||||
|
||||
function getInfo() {
|
||||
$.get("/system/system_total", function(info) {
|
||||
setCookie("memRealUsed", parseInt((info.memRealUsed)));
|
||||
@@ -180,7 +190,7 @@ function getInfo() {
|
||||
setcolor(memPre, "#left", 75, 90, 95);
|
||||
$("#info").html(info.system);
|
||||
$("#running").html(info.time);
|
||||
$("#core").html(info.cpuNum + " " + lan.index.cpu_core);
|
||||
$("#core").html(info.cpuNum + " " + '核心');
|
||||
$("#state").html(info.cpuRealUsed);
|
||||
setcolor(memPre, "#state", 30, 70, 90);
|
||||
var memFree = info.memTotal - info.memRealUsed;
|
||||
@@ -221,28 +231,27 @@ function setcolor(pre, s, s1, s2, s3) {
|
||||
function getNet() {
|
||||
var up;
|
||||
var down;
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "/system/network",
|
||||
async: true,
|
||||
success: function(net) {
|
||||
$("#InterfaceSpeed").html(lan.index.interfacespeed + ": 1.0Gbps");
|
||||
$("#upSpeed").html(net.up + ' KB');
|
||||
$("#downSpeed").html(net.down + ' KB');
|
||||
$("#downAll").html(ToSize(net.downTotal));
|
||||
$("#downAll").attr('title', lan.index.package + ':' + net.downPackets)
|
||||
$("#upAll").html(ToSize(net.upTotal));
|
||||
$("#upAll").attr('title', lan.index.package + ':' + net.upPackets)
|
||||
$("#core").html(net.cpu[1] + " " + lan.index.cpu_core);
|
||||
$("#state").html(net.cpu[0]);
|
||||
setcolor(net.cpu[0], "#state", 30, 70, 90);
|
||||
setCookie("upNet", net.up);
|
||||
setCookie("downNet", net.down);
|
||||
getLoad(net.load);
|
||||
setImg();
|
||||
}
|
||||
});
|
||||
$.get("/system/network", function(net) {
|
||||
$("#InterfaceSpeed").html(lan.index.interfacespeed + ": 1.0Gbps");
|
||||
$("#upSpeed").html(net.up + ' KB');
|
||||
$("#downSpeed").html(net.down + ' KB');
|
||||
$("#downAll").html(ToSize(net.downTotal));
|
||||
$("#downAll").attr('title', lan.index.package + ':' + net.downPackets)
|
||||
$("#upAll").html(ToSize(net.upTotal));
|
||||
$("#upAll").attr('title', lan.index.package + ':' + net.upPackets)
|
||||
$("#core").html(net.cpu[1] + " " + lan.index.cpu_core);
|
||||
$("#state").html(net.cpu[0]);
|
||||
setcolor(net.cpu[0], "#state", 30, 70, 90);
|
||||
setCookie("upNet", net.up);
|
||||
setCookie("downNet", net.down);
|
||||
getLoad(net.load);
|
||||
|
||||
// console.log(net.mem);
|
||||
// setMemImg(net.mem);
|
||||
setImg();
|
||||
},'json');
|
||||
}
|
||||
|
||||
//网络Io
|
||||
function NetImg() {
|
||||
var myChartNetwork = echarts.init(document.getElementById('NetImg'));
|
||||
@@ -476,26 +485,6 @@ function checkUpdate() {
|
||||
}
|
||||
|
||||
|
||||
function updateMsg() {
|
||||
window.open("http://www.bt.cn/bbs/thread-1186-1-1.html");
|
||||
$.get('/ajax?action=UpdatePanel', function(rdata) {
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: lan.index.update_to + '[' + rdata.version + ']',
|
||||
area: '400px',
|
||||
shadeClose: false,
|
||||
closeBtn: 2,
|
||||
content: '<div class="setchmod bt-form pd20 pb70">' +
|
||||
'<p style="padding: 0 0 10px;line-height: 24px;">' + rdata.updateMsg + '</p>' +
|
||||
'<div class="bt-form-submit-btn">' +
|
||||
'<button type="button" class="btn btn-danger btn-sm btn-title" onclick="layer.closeAll()">' + lan.public.cancel + '</button>' +
|
||||
'<button type="button" class="btn btn-success btn-sm btn-title" onclick="updateVersion(\'' + rdata.version + '\')" >' + lan.index.update_go + '</button>' +
|
||||
'</div>' +
|
||||
'</div>'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//开始升级
|
||||
function updateVersion(version) {
|
||||
var loadT = layer.msg(lan.index.update_the, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
@@ -525,32 +514,6 @@ function updateVersion(version) {
|
||||
});
|
||||
}
|
||||
|
||||
//更新日志
|
||||
function openLog() {
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: '640px',
|
||||
title: lan.index.update_log,
|
||||
closeBtn: 2,
|
||||
shift: 5,
|
||||
shadeClose: false,
|
||||
content: '<div class="DrawRecordCon"></div>'
|
||||
});
|
||||
$.get('https://www.bt.cn/Api/getUpdateLogs', function(rdata) {
|
||||
var body = '';
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
body += '<div class="DrawRecord DrawRecordlist">\
|
||||
<div class="DrawRecordL">' + rdata[i].addtime + '<i></i></div>\
|
||||
<div class="DrawRecordR">\
|
||||
<h3>' + rdata[i].title + '</h3>\
|
||||
<p>' + rdata[i].body + '</p>\
|
||||
</div>\
|
||||
</div>'
|
||||
}
|
||||
$(".DrawRecordCon").html(body);
|
||||
}, 'jsonp');
|
||||
}
|
||||
|
||||
|
||||
//重启服务器
|
||||
function ReBoot() {
|
||||
@@ -624,137 +587,8 @@ function WSafeRestart() {
|
||||
$(".layui-layer-close").unbind("click");
|
||||
}
|
||||
|
||||
function reWeb() {
|
||||
// layer.confirm(lan.index.panel_reboot_msg, { title: lan.index.panel_reboot_title, closeBtn: 2, icon: 3 }, function() {
|
||||
// var loadT = layer.msg(lan.index.panel_reboot_to, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
// $.get('/system?action=ReWeb', function(rdata) {
|
||||
// layer.close(loadT);
|
||||
// layer.msg(rdata.msg, { icon: 5 });
|
||||
// }).error(function() {
|
||||
// layer.close(loadT);
|
||||
// layer.msg(lan.index.panel_reboot_ok, { icon: 1 });
|
||||
// setTimeout(function() {
|
||||
// window.location.reload();
|
||||
// }, 3000)
|
||||
// });
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
//查看网络状态
|
||||
function GetNetWorkList(rflush) {
|
||||
var loadT = layer.msg(lan.public.the_get, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/ajax?action=GetNetWorkList', '', function(rdata) {
|
||||
layer.close(loadT);
|
||||
var tbody = ""
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
tbody += "<tr>" +
|
||||
"<td>" + rdata[i].type + "</td>" +
|
||||
"<td>" + rdata[i].laddr[0] + ":" + rdata[i].laddr[1] + "</td>" +
|
||||
"<td>" + (rdata[i].raddr.length > 1 ? "<a style='color:blue;' title='" + lan.index.net_dorp_ip + "' href=\"javascript:dropAddress('" + rdata[i].raddr[0] + "');\">" + rdata[i].raddr[0] + "</a>:" + rdata[i].raddr[1] : 'NONE') + "</td>" +
|
||||
"<td>" + rdata[i].status + "</td>" +
|
||||
"<td>" + rdata[i].process + "</td>" +
|
||||
"<td>" + rdata[i].pid + "</td>" +
|
||||
"</tr>"
|
||||
}
|
||||
|
||||
if (rflush) {
|
||||
$("#networkList").html(tbody);
|
||||
return;
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: ['650px', '600px'],
|
||||
title: lan.index.net_status_title,
|
||||
closeBtn: 2,
|
||||
shift: 5,
|
||||
shadeClose: true,
|
||||
content: "<div class='divtable' style='margin:15px;'>\
|
||||
<button class='btn btn-default btn-sm pull-right' onclick='GetNetWorkList(true);' style='margin-bottom:5px;'>" + lan.public.fresh + "</button>\
|
||||
<table class='table table-hover table-bordered'>\
|
||||
<thead>\
|
||||
<tr>\
|
||||
<th>" + lan.index.net_protocol + "</th>\
|
||||
<th>" + lan.index.net_address_dst + "</th>\
|
||||
<th>" + lan.index.net_address_src + "</th>\
|
||||
<th>" + lan.index.net_address_status + "</th>\
|
||||
<th>" + lan.index.net_process + "</th>\
|
||||
<th>" + lan.index.net_process_pid + "</th>\
|
||||
</tr>\
|
||||
</thead>\
|
||||
<tbody id='networkList'>" + tbody + "</tbody>\
|
||||
</table></div>"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//进程管理
|
||||
function GetProcessList(rflush) {
|
||||
var loadT = layer.msg(lan.index.process_check, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/ajax?action=GetProcessList', '', function(rdata) {
|
||||
layer.close(loadT);
|
||||
var tbody = "";
|
||||
for (var i = 0; i < rdata.length; i++) {
|
||||
tbody += "<tr>" +
|
||||
"<td>" + rdata[i].pid + "</td>" +
|
||||
"<td>" + rdata[i].name + "</td>" +
|
||||
"<td>" + rdata[i].cpu_percent + "%</td>" +
|
||||
"<td>" + rdata[i].memory_percent + "%</td>" +
|
||||
"<td>" + ToSize(rdata[i].io_read_bytes) + '/' + ToSize(rdata[i].io_write_bytes) + "</td>" +
|
||||
"<td>" + rdata[i].status + "</td>" +
|
||||
"<td>" + rdata[i].threads + "</td>" +
|
||||
"<td>" + rdata[i].user + "</td>" +
|
||||
"<td><a title='" + lan.index.process_kill_title + "' style='color:red;' href=\"javascript:;\" onclick=\"killProcess(" + rdata[i].pid + ",'" + rdata[i].name + "',this)\">" + lan.index.process_kill + "</a></td>" +
|
||||
"</tr>";
|
||||
}
|
||||
|
||||
if (rflush) {
|
||||
$("#processList").html(tbody);
|
||||
return;
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: ['70%', '600px'],
|
||||
title: lan.index.process_title,
|
||||
closeBtn: 2,
|
||||
shift: 5,
|
||||
shadeClose: true,
|
||||
content: "<div class='divtable' style='margin:15px;'>\
|
||||
<button class='btn btn-default btn-sm pull-right' onclick='GetProcessList(true);' style='margin-bottom:5px;'>" + lan.public.fresh + "</button>\
|
||||
<table class='table table-hover table-bordered'>\
|
||||
<thead>\
|
||||
<tr>\
|
||||
<th>" + lan.index.process_pid + "</th>\
|
||||
<th>" + lan.index.process_name + "</th>\
|
||||
<th>" + lan.index.process_cpu + "</th>\
|
||||
<th>" + lan.index.process_mem + "</th>\
|
||||
<th>" + lan.index.process_disk + "</th>\
|
||||
<th>" + lan.index.process_status + "</th>\
|
||||
<th>" + lan.index.process_thread + "</th>\
|
||||
<th>" + lan.index.process_user + "</th>\
|
||||
<th>" + lan.index.process_act + "</th>\
|
||||
</tr>\
|
||||
</thead>\
|
||||
<tbody id='processList'>" + tbody + "</tbody>\
|
||||
</table></div>"
|
||||
});
|
||||
});
|
||||
}
|
||||
//结束指定进程
|
||||
function killProcess(pid, name, obj) {
|
||||
var that = $(obj).parents('tr');
|
||||
layer.confirm(lan.get('process_kill_confirm', [name, pid]), { icon: 3, closeBtn: 2 }, function() {
|
||||
loadT = layer.msg(lan.index.kill_msg, { icon: 16, time: 0, shade: [0.3, '#000'] });
|
||||
$.post('/ajax?action=KillProcess', 'pid=' + pid, function(rdata) {
|
||||
that.remove();
|
||||
layer.close(loadT);
|
||||
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//屏蔽指定IP
|
||||
function dropAddress(address) {
|
||||
layer.confirm(lan.index.net_doup_ip_msg, { icon: 3, closeBtn: 2 }, function() {
|
||||
@@ -840,16 +674,4 @@ function showDanger(num, port) {
|
||||
</div>'
|
||||
});
|
||||
$(".showDanger td").css("padding", "8px")
|
||||
}
|
||||
|
||||
function showDangerIP() {
|
||||
var body = $("#dangerhtmltable").html();
|
||||
layer.open({
|
||||
type: 1,
|
||||
area: ['500px', '500px'],
|
||||
title: '攻击日志',
|
||||
closeBtn: 2,
|
||||
shift: 5,
|
||||
content: '<div class="pd15 divtable" style="height:430px;overflow:auto"><table class="table table-hover"><thead><tr><th>源IP地址</th><th>用户</th><th style="text-align: right;">时间</th></tr></thead>' + body + '</table></div><p style="color:red;padding-left:12px">*以上记录来源于本服务器日志,查看命令:cat /var/log/secure</p>'
|
||||
});
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
<div class="container-fluid" style="padding-bottom: 66px;">
|
||||
|
||||
<div class="danger-tips">
|
||||
<div class="alert alert-warning" id="messageError" style="display: none;background-color: #ffe0e0;border-color: #ffb0b0;color: #ff2020; margin-bottom:0"></div>
|
||||
<div class="alert alert-warning" id="messageError" style="display: none;background-color: #ffe0e0;border-color: #ffb0b0;color: #ff2020; margin-bottom:0;margin-top: 12px;"></div>
|
||||
</div>
|
||||
|
||||
<div class="server bgw mtb15">
|
||||
@@ -36,7 +36,7 @@
|
||||
</div>
|
||||
<div class="mask"><span id="Load">0</span>%</div>
|
||||
</div>
|
||||
<h4 id="LoadState" class="c5 f15">获取中:</h4>
|
||||
<h4 id="LoadState" class="c5 f15">获取中...</h4>
|
||||
</li>
|
||||
<li class="col-xs-6 col-sm-3 col-md-3 col-lg-2 mtb20 circle-box text-center">
|
||||
<h3 class="c5 f15">CPU使用率</h3>
|
||||
@@ -49,7 +49,7 @@
|
||||
</div>
|
||||
<div class="mask"><span id="state">0</span>%</div>
|
||||
</div>
|
||||
<h4 id="core" class="c5 f15">$data['lan']['S2']</h4>
|
||||
<h4 id="core" class="c5 f15">获取中...</h4>
|
||||
</li>
|
||||
<li class="col-xs-6 col-sm-3 col-md-3 col-lg-2 mtb20 circle-box text-center">
|
||||
<h3 class="c5 f15">内存使用率</h3>
|
||||
@@ -61,10 +61,10 @@
|
||||
<div class="right"></div>
|
||||
</div>
|
||||
<div class="mask"><span id="left">0</span>%</div>
|
||||
<div class="mem-re-min"></div>
|
||||
<div class="mem-re-con" title="$data['lan']['P3']"></div>
|
||||
<div class="mem-re-min" style="display: none;"></div>
|
||||
<div class="mem-re-con" title=""></div>
|
||||
</div>
|
||||
<h4 id="memory" class="c5 f15">$data['lan']['S2']</h4>
|
||||
<h4 id="memory" class="c5 f15">获取中...</h4>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -143,5 +143,6 @@ setTimeout(function() {
|
||||
setTimeout(function() {
|
||||
getInfo();
|
||||
}, 1500);
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user