mirror of
https://github.com/aaPanel/aaPanel.git
synced 2026-09-13 21:17:40 +02:00
v6.8.8
1. Add user login function. 2. Add the first professional plug-in Nginx WAF. 3. Release a new version of the online editor. 4. Fixed some bugs.
This commit is contained in:
+143
@@ -11,12 +11,15 @@
|
||||
# Apache管理模块
|
||||
#------------------------------
|
||||
import public,os,re,shutil,math,psutil,time
|
||||
from json import loads
|
||||
os.chdir("/www/server/panel")
|
||||
|
||||
class apache:
|
||||
setupPath = '/www/server'
|
||||
apachedefaultfile = "%s/apache/conf/extra/httpd-default.conf" % (setupPath)
|
||||
apachempmfile = "%s/apache/conf/extra/httpd-mpm.conf" % (setupPath)
|
||||
httpdconf = "%s/apache/conf/httpd.conf" % (setupPath)
|
||||
|
||||
|
||||
def GetProcessCpuPercent(self,i,process_cpu):
|
||||
try:
|
||||
@@ -201,3 +204,143 @@ class apache:
|
||||
'<br>') + '</a>')
|
||||
public.serviceReload()
|
||||
return public.returnMsg(True, 'SET_SUCCESS')
|
||||
|
||||
def add_httpd_access_log_format(self,args):
|
||||
'''
|
||||
@name 添加httpd日志格式
|
||||
@author zhwen<zhw@bt.cn>
|
||||
@param log_format 需要设置的日志格式["$server_name","$remote_addr","-"....]
|
||||
@param log_format_name
|
||||
@param act 操作方式 add/edit
|
||||
'''
|
||||
try:
|
||||
log_format = loads(args.log_format)
|
||||
data = """
|
||||
#LOG_FORMAT_BEGIN_{n}
|
||||
LogFormat '{c}' {n}
|
||||
#LOG_FORMAT_END_{n}
|
||||
""".format(n=args.log_format_name,c=' '.join(log_format))
|
||||
data = data.replace('%{User-agent}i','"%{User-agent}i"')
|
||||
data = data.replace('%{Referer}i', '"%{Referer}i"')
|
||||
if args.act == 'edit':
|
||||
self.del_httpd_access_log_format(args)
|
||||
conf = public.readFile(self.httpdconf)
|
||||
if not conf:
|
||||
return public.returnMsg(False,'CONF_FILE_NOT_EXISTS')
|
||||
reg = '<IfModule log_config_module>'
|
||||
conf = re.sub(reg,'<IfModule log_config_module>'+data,conf)
|
||||
public.writeFile(self.httpdconf,conf)
|
||||
public.serviceReload()
|
||||
return public.returnMsg(True, 'SET_SUCCESS')
|
||||
except:
|
||||
return public.returnMsg(False, str(public.get_error_info()))
|
||||
|
||||
def del_httpd_access_log_format(self,args):
|
||||
'''
|
||||
@name 删除日志格式
|
||||
@author zhwen<zhw@bt.cn>
|
||||
@param log_format_name
|
||||
'''
|
||||
conf = public.readFile(self.httpdconf)
|
||||
if not conf:
|
||||
return public.returnMsg(False, 'CONF_FILE_NOT_EXISTS')
|
||||
reg = '\s*#LOG_FORMAT_BEGIN_{n}(\n|.)+#LOG_FORMAT_END_{n}\n?'.format(n=args.log_format_name)
|
||||
conf = re.sub(reg,'',conf)
|
||||
public.writeFile(self.httpdconf,conf)
|
||||
public.serviceReload()
|
||||
return public.returnMsg(True, 'SET_SUCCESS')
|
||||
|
||||
def get_httpd_access_log_format_parameter(self,args=None):
|
||||
data = {
|
||||
"%h":"Client's IP address",
|
||||
"%r":"Request agreement",
|
||||
"%t":"Request time",
|
||||
"%>s":"http status code",
|
||||
"%b":"Send data size",
|
||||
"%{Referer}i":"http referer",
|
||||
"%{User-agent}i":"http user agent",
|
||||
"%{X-Forwarded-For}i":"The real ip of the client",
|
||||
"%l":"Remote login name",
|
||||
"%u":"Remote user",
|
||||
"-":"-"
|
||||
}
|
||||
if hasattr(args,'log_format_name'):
|
||||
site_list = self._get_format_log_to_website(args.log_format_name)
|
||||
return {'site_list':site_list,'format_log':data}
|
||||
else:
|
||||
return data
|
||||
|
||||
def _process_log_format(self,tmp):
|
||||
log_tips = self.get_httpd_access_log_format_parameter()
|
||||
data = []
|
||||
for t in tmp:
|
||||
t = t.replace('\"','')
|
||||
t = t.replace("'", "")
|
||||
if t not in log_tips:
|
||||
continue
|
||||
data.append({t:log_tips[t]})
|
||||
return data
|
||||
|
||||
def get_httpd_access_log_format(self,args=None):
|
||||
try:
|
||||
reg = "#LOG_FORMAT_BEGIN.*"
|
||||
conf = public.readFile(self.httpdconf)
|
||||
if not conf:
|
||||
return public.returnMsg(False, 'CONF_FILE_NOT_EXISTS')
|
||||
data = re.findall(reg,conf)
|
||||
format_name = [i.split('_')[-1] for i in data]
|
||||
format_log = {}
|
||||
for i in format_name:
|
||||
format_reg = "#LOG_FORMAT_BEGIN_{n}(\n|.)+LogFormat\s+\'(.*)\'\s+{n}".format(n=i)
|
||||
tmp = re.search(format_reg,conf).groups()[1].split()
|
||||
format_log[i] = self._process_log_format(tmp)
|
||||
return format_log
|
||||
except:
|
||||
return public.get_error_info()
|
||||
|
||||
def set_httpd_format_log_to_website(self,args):
|
||||
'''
|
||||
@name 设置网站日志格式
|
||||
@author zhwen<zhw@bt.cn>
|
||||
@param sites aaa.com,bbb.com
|
||||
@param log_format_name
|
||||
'''
|
||||
# sites = args.sites.split(',')
|
||||
sites = loads(args.sites)
|
||||
try:
|
||||
all_site = public.M('sites').field('name').select()
|
||||
reg = 'CustomLog\s+"/www.*{}\s*'.format(args.log_format_name)
|
||||
for site in all_site:
|
||||
website_conf_file = '/www/server/panel/vhost/apache/{}.conf'.format(site['name'])
|
||||
conf = public.readFile(website_conf_file)
|
||||
if not conf:
|
||||
return public.returnMsg(False, 'CONF_FILE_NOT_EXISTS')
|
||||
format_exist_reg = '(CustomLog\s+"/www.*\_log).*'
|
||||
access_log = re.search(format_exist_reg, conf).groups()[0] + '" ' + args.log_format_name
|
||||
if site['name'] not in sites and re.search(format_exist_reg,conf):
|
||||
access_log = ' '.join(access_log.split()[:-1])
|
||||
conf = re.sub(reg, access_log, conf)
|
||||
public.writeFile(website_conf_file,conf)
|
||||
continue
|
||||
conf = re.sub(format_exist_reg,access_log,conf)
|
||||
public.writeFile(website_conf_file,conf)
|
||||
public.serviceReload()
|
||||
return public.returnMsg(True, 'SET_SUCCESS')
|
||||
except:
|
||||
return public.returnMsg(False, str(public.get_error_info()))
|
||||
|
||||
def _get_format_log_to_website(self,log_format_name):
|
||||
tmp = public.M('sites').field('name').select()
|
||||
reg = 'CustomLog.*{}'.format(log_format_name)
|
||||
data = {}
|
||||
for i in tmp:
|
||||
website_conf_file = '/www/server/panel/vhost/apache/{}.conf'.format(i['name'])
|
||||
conf = public.readFile(website_conf_file)
|
||||
if not conf:
|
||||
data[i['name']] = False
|
||||
continue
|
||||
if re.search(reg,conf):
|
||||
data[i['name']] = True
|
||||
else:
|
||||
data[i['name']] = False
|
||||
return data
|
||||
Reference in New Issue
Block a user