mirror of
https://github.com/aaPanel/aaPanel.git
synced 2026-08-30 11:49:48 +02:00
update to 6.8.27
This commit is contained in:
+151
-59
@@ -25,10 +25,10 @@ class data:
|
||||
'''
|
||||
def setPs(self,get):
|
||||
id = get.id
|
||||
get.ps = public.xssencode(get.ps)
|
||||
get.ps = public.xssencode2(get.ps)
|
||||
if public.M(get.table).where("id=?",(id,)).setField('ps',get.ps):
|
||||
return public.returnMsg(True,'EDIT_SUCCESS')
|
||||
return public.returnMsg(False,'EDIT_ERROR')
|
||||
return public.return_msg_gettext(True,'Setup successfully!')
|
||||
return public.return_msg_gettext(False,'Failed to modify')
|
||||
|
||||
#端口扫描
|
||||
def CheckPort(self,port):
|
||||
@@ -142,7 +142,7 @@ class data:
|
||||
conf = public.readFile(
|
||||
self.setupPath + '/panel/vhost/' + self.web_server + '/detail/' + siteName + '.conf')
|
||||
if self.web_server == 'nginx':
|
||||
rep = r"enable-php-(\w{2,5})\.conf"
|
||||
rep = r"enable-php-(\w{2,5})[-\w]*\.conf"
|
||||
elif self.web_server == 'apache':
|
||||
rep = r"php-cgi-(\w{2,5})\.sock"
|
||||
else:
|
||||
@@ -172,6 +172,37 @@ class data:
|
||||
except:
|
||||
return 0
|
||||
|
||||
def get_site_quota(self,path):
|
||||
'''
|
||||
@name 获取网站目录配额信息
|
||||
@author hwliang<2022-02-15>
|
||||
@param path<string> 网站目录
|
||||
@return dict
|
||||
'''
|
||||
res = {'size':0 ,'used':0 }
|
||||
try:
|
||||
from projectModel.quotaModel import main
|
||||
quota_info = main().get_quota_path_list(get_path = path)
|
||||
if isinstance(quota_info,dict):
|
||||
return quota_info
|
||||
return res
|
||||
except: return res
|
||||
|
||||
def get_database_quota(self,db_name):
|
||||
'''
|
||||
@name 获取网站目录配额信息
|
||||
@author hwliang<2022-02-15>
|
||||
@param path<string> 网站目录
|
||||
@return dict
|
||||
'''
|
||||
res = {'size':0 ,'used':0 }
|
||||
try:
|
||||
from projectModel.quotaModel import main
|
||||
quota_info = main().get_quota_mysql_list(get_name = db_name)
|
||||
if isinstance(quota_info,dict):
|
||||
return quota_info
|
||||
return res
|
||||
except: return res
|
||||
|
||||
'''
|
||||
* 取数据列表
|
||||
@@ -181,6 +212,7 @@ class data:
|
||||
* @return Json page.分页数 , count.总行数 data.取回的数据
|
||||
'''
|
||||
def getData(self,get):
|
||||
import one_key_wp
|
||||
try:
|
||||
table = get.table
|
||||
data = self.GetSql(get)
|
||||
@@ -188,29 +220,55 @@ class data:
|
||||
|
||||
if table == 'backup':
|
||||
import os
|
||||
backup_path = public.M('config').where('id=?',(1,)).getField('backup_path')
|
||||
for i in range(len(data['data'])):
|
||||
if data['data'][i]['size'] == 0:
|
||||
if os.path.exists(data['data'][i]['filename']): data['data'][i]['size'] = os.path.getsize(data['data'][i]['filename'])
|
||||
if os.path.exists(data['data'][i]['filename']):
|
||||
data['data'][i]['size'] = os.path.getsize(data['data'][i]['filename'])
|
||||
else:
|
||||
if not os.path.exists(data['data'][i]['filename']):
|
||||
if (data['data'][i]['filename'].find('/www/') != -1 or data['data'][i]['filename'].find(backup_path) != -1) and data['data'][i]['filename'][0] == '/' and data['data'][i]['filename'].find('|') == -1:
|
||||
data['data'][i]['size'] = 0
|
||||
data['data'][i]['ps'] = public.get_msg_gettext("File does not exist!")
|
||||
|
||||
elif table == 'sites' or table == 'databases':
|
||||
type = '0'
|
||||
if table == 'databases': type = '1'
|
||||
for i in range(len(data['data'])):
|
||||
data['data'][i]['backup_count'] = SQL.table('backup').where("pid=? AND type=?",(data['data'][i]['id'],type)).count()
|
||||
if table == 'databases': data['data'][i]['conn_config'] = json.loads(data['data'][i]['conn_config'])
|
||||
data['data'][i]['quota'] = self.get_database_quota(data['data'][i]['name'])
|
||||
if table == 'sites':
|
||||
for i in range(len(data['data'])):
|
||||
data['data'][i]['domain'] = SQL.table('domain').where("pid=?",(data['data'][i]['id'],)).count()
|
||||
data['data'][i]['ssl'] = self.get_site_ssl_info(data['data'][i]['name'])
|
||||
data['data'][i]['php_version'] = self.get_php_version(data['data'][i]['name'])
|
||||
data['data'][i]['attack'] = self.get_analysis(get,data['data'][i])
|
||||
data['data'][i]['project_type'] = SQL.table('sites').where('id=?',(data['data'][i]['id'])).field('project_type').find()['project_type']
|
||||
if data['data'][i]['project_type'] == 'WP':
|
||||
data['data'][i]['cache_status'] = one_key_wp.one_key_wp().get_cache_status(data['data'][i]['id'])
|
||||
if not data['data'][i]['status'] in ['0','1',0,1]:
|
||||
data['data'][i]['status'] = '1'
|
||||
data['data'][i]['quota'] = self.get_site_quota(data['data'][i]['path'])
|
||||
elif table == 'firewall':
|
||||
for i in range(len(data['data'])):
|
||||
if data['data'][i]['port'].find(':') != -1 or data['data'][i]['port'].find('.') != -1 or data['data'][i]['port'].find('-') != -1:
|
||||
data['data'][i]['status'] = -1
|
||||
else:
|
||||
data['data'][i]['status'] = self.CheckPort(int(data['data'][i]['port']))
|
||||
|
||||
|
||||
elif table == 'ftps':
|
||||
for i in range(len(data['data'])):
|
||||
data['data'][i]['quota'] = self.get_site_quota(data['data'][i]['path'])
|
||||
|
||||
try:
|
||||
for _find in data['data']:
|
||||
_keys = _find.keys()
|
||||
for _key in _keys:
|
||||
_find[_key] = public.xsssec(_find[_key])
|
||||
except:
|
||||
pass
|
||||
|
||||
#返回
|
||||
return data
|
||||
except:
|
||||
@@ -229,15 +287,21 @@ class data:
|
||||
SQL = public.M(tableName)
|
||||
where = "id=?"
|
||||
find = SQL.where(where,(id,)).field(field).find()
|
||||
try:
|
||||
_keys = find.keys()
|
||||
for _key in _keys:
|
||||
find[_key] = public.xsssec(find[_key])
|
||||
except:
|
||||
pass
|
||||
return find
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
* 取字段值
|
||||
* @param String _GET['tab'] 数据库表名
|
||||
* @param String _GET['key'] 字段
|
||||
* @param String _GET['id'] 条件ID
|
||||
* @return String
|
||||
* @return String
|
||||
'''
|
||||
def getKey(self,get):
|
||||
tableName = get.table
|
||||
@@ -246,7 +310,7 @@ class data:
|
||||
SQL = db.Sql().table(tableName)
|
||||
where = "id=?"
|
||||
retuls = SQL.where(where,(id,)).getField(keyName)
|
||||
return retuls
|
||||
return public.xsssec(retuls)
|
||||
|
||||
'''
|
||||
* 获取数据与分页
|
||||
@@ -259,117 +323,138 @@ class data:
|
||||
def GetSql(self,get,result = '1,2,3,4,5,8'):
|
||||
#判断前端是否传入参数
|
||||
order = "id desc"
|
||||
if hasattr(get,'order'):
|
||||
order = get.order
|
||||
|
||||
if hasattr(get,'order'):
|
||||
# 验证参数格式
|
||||
if re.match(r"^[\w\s\-\.]+$",get.order):
|
||||
order = get.order
|
||||
|
||||
limit = 20
|
||||
if hasattr(get,'limit'):
|
||||
if hasattr(get,'limit'):
|
||||
limit = int(get.limit)
|
||||
|
||||
if hasattr(get,'result'):
|
||||
result = get.result
|
||||
|
||||
if limit < 1: limit = 20
|
||||
|
||||
if hasattr(get,'result'):
|
||||
# 验证参数格式
|
||||
if re.match(r"^[\d\,]+$",get.result):
|
||||
result = get.result
|
||||
|
||||
SQL = db.Sql()
|
||||
data = {}
|
||||
#取查询条件
|
||||
where = ''
|
||||
param = ()
|
||||
if hasattr(get,'search'):
|
||||
if sys.version_info[0] == 2: get.search = get.search.encode('utf-8')
|
||||
where = self.GetWhere(get.table,get.search)
|
||||
where,param = self.GetWhere(get.table,get.search)
|
||||
if get.table == 'backup':
|
||||
where += " and type='" + get.type+"'"
|
||||
|
||||
where += " and type='{}'".format(int(get.type))
|
||||
|
||||
if get.table == 'sites' and get.search:
|
||||
pid = SQL.table('domain').where("name LIKE '%"+get.search+"%'",()).getField('pid')
|
||||
pid = SQL.table('domain').where("name LIKE ?",("%{}%".format(get.search),)).getField('pid')
|
||||
if pid:
|
||||
if where:
|
||||
where += " or id=" + str(pid)
|
||||
else:
|
||||
where += "id=" + str(pid)
|
||||
|
||||
if get.table == 'sites' and hasattr(get,'type'):
|
||||
if get.type != '-1':
|
||||
type_where = "type_id=%s" % get.type
|
||||
if where == '':
|
||||
where = type_where
|
||||
else:
|
||||
where += " and " + type_where
|
||||
if get.table == 'sites':
|
||||
if where:
|
||||
where = "({}) AND project_type='PHP'".format(where)
|
||||
else:
|
||||
where = "project_type='PHP'"
|
||||
where = "(project_type='PHP' OR project_type='WP')"
|
||||
|
||||
if hasattr(get,'type'):
|
||||
if get.type != '-1':
|
||||
where += " AND type_id={}".format(int(get.type))
|
||||
|
||||
if get.table == 'databases':
|
||||
if hasattr(get,'db_type'):
|
||||
if where:
|
||||
where += " AND db_type='{}'".format(int(get.db_type))
|
||||
else:
|
||||
where = "db_type='{}'".format(int(get.db_type))
|
||||
if hasattr(get,'sid'):
|
||||
if where:
|
||||
where += " AND sid='{}'".format(int(get.sid))
|
||||
else:
|
||||
where = "sid='{}'".format(int(get.sid))
|
||||
|
||||
field = self.GetField(get.table)
|
||||
#实例化数据库对象
|
||||
|
||||
|
||||
|
||||
|
||||
#是否直接返回所有列表
|
||||
if hasattr(get,'list'):
|
||||
data = SQL.table(get.table).where(where,()).field(field).order(order).select()
|
||||
data = SQL.table(get.table).where(where,param).field(field).order(order).select()
|
||||
return data
|
||||
|
||||
|
||||
#取总行数
|
||||
count = SQL.table(get.table).where(where,()).count()
|
||||
count = SQL.table(get.table).where(where,param).count()
|
||||
#get.uri = get
|
||||
#包含分页类
|
||||
import page
|
||||
#实例化分页类
|
||||
page = page.Page()
|
||||
|
||||
|
||||
info = {}
|
||||
info['count'] = count
|
||||
info['row'] = limit
|
||||
|
||||
|
||||
info['p'] = 1
|
||||
if hasattr(get,'p'):
|
||||
info['p'] = int(get['p'])
|
||||
info['uri'] = get
|
||||
if info['p'] <1: info['p'] = 1
|
||||
|
||||
try:
|
||||
from flask import request
|
||||
info['uri'] = public.url_encode(request.full_path)
|
||||
except:
|
||||
info['uri'] = ''
|
||||
info['return_js'] = ''
|
||||
if hasattr(get,'tojs'):
|
||||
info['return_js'] = get.tojs
|
||||
|
||||
if re.match(r"^[\w\.\-]+$",get.tojs):
|
||||
info['return_js'] = get.tojs
|
||||
|
||||
data['where'] = where
|
||||
|
||||
|
||||
#获取分页数据
|
||||
data['page'] = page.GetPage(info,result)
|
||||
#取出数据
|
||||
data['data'] = SQL.table(get.table).where(where,()).order(order).field(field).limit(str(page.SHIFT)+','+str(page.ROW)).select()
|
||||
data['data'] = SQL.table(get.table).where(where,param).order(order).field(field).limit(str(page.SHIFT)+','+str(page.ROW)).select()
|
||||
return data
|
||||
|
||||
|
||||
#获取条件
|
||||
def GetWhere(self,tableName,search):
|
||||
if not search: return ""
|
||||
def GetWhere(self,tableName,search):
|
||||
if not search: return "",()
|
||||
|
||||
if type(search) == bytes: search = search.encode('utf-8').strip()
|
||||
try:
|
||||
search = re.search(r"[\w\x80-\xff\.]+",search).group()
|
||||
search = re.search(r"[\w\x80-\xff\.\_\-]+",search).group()
|
||||
except:
|
||||
return ''
|
||||
return '',()
|
||||
wheres = {
|
||||
'sites' : "id='"+search+"' or name like '%"+search+"%' or status like '%"+search+"%' or ps like '%"+search+"%'",
|
||||
'ftps' : "id='"+search+"' or name like '%"+search+"%' or ps like '%"+search+"%'",
|
||||
'databases' : "id='"+search+"' or name like '%"+search+"%' or ps like '%"+search+"%'",
|
||||
'logs' : "uid='"+search+"' or username='"+search+"' or type like '%"+search+"%' or log like '%"+search+"%' or addtime like '%"+search+"%'",
|
||||
'backup' : "pid="+search+"",
|
||||
'users' : "id='"+search+"' or username='"+search+"'",
|
||||
'domain' : "pid='"+search+"' or name='"+search+"'",
|
||||
'tasks' : "status='"+search+"' or type='"+search+"'"
|
||||
'sites' : ("name LIKE ? OR ps LIKE ?",('%'+search+'%','%'+search+'%')),
|
||||
'ftps' : ("name LIKE ? OR ps LIKE ?",('%'+search+'%','%'+search+'%')),
|
||||
'databases' : ("(name LIKE ? OR ps LIKE ?)",("%"+search+"%","%"+search+"%")),
|
||||
'logs' : ("username=? OR type LIKE ? OR log LIKE ?",(search,'%'+search+'%','%'+search+'%')),
|
||||
'backup' : ("pid=?",(search,)),
|
||||
'users' : ("id='?' OR username=?",(search,search)),
|
||||
'domain' : ("pid=? OR name=?",(search,search)),
|
||||
'tasks' : ("status=? OR type=?",(search,search)),
|
||||
}
|
||||
try:
|
||||
return wheres[tableName]
|
||||
except:
|
||||
return ''
|
||||
|
||||
return '',()
|
||||
|
||||
# 获取返回的字段
|
||||
def GetField(self,tableName):
|
||||
fields = {
|
||||
'sites' : "id,name,path,status,ps,addtime,edate",
|
||||
'ftps' : "id,pid,name,password,status,ps,addtime,path",
|
||||
'databases' : "id,pid,name,username,password,accept,ps,addtime",
|
||||
'databases' : "id,sid,pid,name,username,password,accept,ps,addtime,db_type,conn_config",
|
||||
'logs' : "id,uid,username,type,log,addtime",
|
||||
'backup' : "id,pid,name,filename,addtime,size",
|
||||
'backup' : "id,pid,name,filename,addtime,size,ps",
|
||||
'users' : "id,username,phone,email,login_ip,login_time",
|
||||
'firewall' : "id,port,ps,addtime",
|
||||
'domain' : "id,pid,name,port,addtime",
|
||||
@@ -379,3 +464,10 @@ class data:
|
||||
return fields[tableName]
|
||||
except:
|
||||
return ''
|
||||
|
||||
def get_analysis(self,get,i):
|
||||
import log_analysis
|
||||
get.path = '/www/wwwlogs/{}.log'.format(i['name'])
|
||||
get.action = 'get_result'
|
||||
data = log_analysis.log_analysis().get_result(get)
|
||||
return int(data['php']) + int(data['san']) + int(data['sql']) + int(data['xss'])
|
||||
Reference in New Issue
Block a user