Skip to content

Commit

Permalink
6.9.9-2
Browse files Browse the repository at this point in the history
  • Loading branch information
showpy committed Sep 4, 2019
1 parent 8372ff2 commit 1370874
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 83 deletions.
15 changes: 11 additions & 4 deletions BTPanel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def config(pdata = None):
if public.is_local(): data['is_local'] = 'checked'
return render_template( 'config.html',data=data)
import config
defs = ('get_cert_source','set_local','set_debug','get_panel_error_logs','clean_panel_error_logs','get_basic_auth_stat','set_basic_auth','get_cli_php_version','get_tmp_token','set_cli_php_version','DelOldSession', 'GetSessionCount', 'SetSessionConf', 'GetSessionConf','get_ipv6_listen','set_ipv6_status','GetApacheValue','SetApacheValue','GetNginxValue','SetNginxValue','get_token','set_token','set_admin_path','is_pro','get_php_config','get_config','SavePanelSSL','GetPanelSSL','GetPHPConf','SetPHPConf','GetPanelList','AddPanelInfo','SetPanelInfo','DelPanelInfo','ClickPanelInfo','SetPanelSSL','SetTemplates','Set502','setPassword','setUsername','setPanel','setPathInfo','setPHPMaxSize','getFpmConfig','setFpmConfig','setPHPMaxTime','syncDate','setPHPDisable','SetControl','ClosePanel','AutoUpdatePanel','SetPanelLock')
defs = ('get_php_session_path','set_php_session_path','get_cert_source','set_local','set_debug','get_panel_error_logs','clean_panel_error_logs','get_basic_auth_stat','set_basic_auth','get_cli_php_version','get_tmp_token','set_cli_php_version','DelOldSession', 'GetSessionCount', 'SetSessionConf', 'GetSessionConf','get_ipv6_listen','set_ipv6_status','GetApacheValue','SetApacheValue','GetNginxValue','SetNginxValue','get_token','set_token','set_admin_path','is_pro','get_php_config','get_config','SavePanelSSL','GetPanelSSL','GetPHPConf','SetPHPConf','GetPanelList','AddPanelInfo','SetPanelInfo','DelPanelInfo','ClickPanelInfo','SetPanelSSL','SetTemplates','Set502','setPassword','setUsername','setPanel','setPathInfo','setPHPMaxSize','getFpmConfig','setFpmConfig','setPHPMaxTime','syncDate','setPHPDisable','SetControl','ClosePanel','AutoUpdatePanel','SetPanelLock')
return publicObject(config.config(),defs,None,pdata);

@app.route('/ajax',methods=method_all)
Expand Down Expand Up @@ -1103,9 +1103,16 @@ def get_input():
exludes = ['blob']
for key in request.args.keys():
data[key] = str(request.args.get(key,''))
for key in request.form.keys():
if key in exludes: continue
data[key] = str(request.form.get(key,''))
try:
for key in request.form.keys():
if key in exludes: continue
data[key] = str(request.form.get(key,''))
except:
post = request.form.to_dict()
for key in post.keys():
if key in exludes: continue
data[key] = str(post[key])

if not hasattr(data,'data'): data.data = []
return data

Expand Down
4 changes: 2 additions & 2 deletions BTPanel/static/js/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -2644,13 +2644,13 @@ function web_shell() {
}, 500);
}
});
/*

if (socket) {
socket.emit('connect_event', '');
interval = setInterval(function () {
socket.emit('connect_event', '');
}, 1000);
}*/
}

term.on('data', function (data) {
pdata_socket['data'] = data;
Expand Down
19 changes: 19 additions & 0 deletions BTPanel/static/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,25 @@ var site = {
_html.append(bt.render_help(['请根据您的程序需求选择版本', '若非必要,请尽量不要使用PHP5.2,这会降低您的服务器安全性;', 'PHP7不支持mysql扩展,默认安装mysqli以及mysql-pdo。']));
$('#webedit-con').append(_html);
bt.render_clicks(_form_data.clicks);
$('#webedit-con').append('<div class="user_pw_tit" style="margin-top: 2px;padding-top: 11px;border-top: #ccc 1px dashed;"><span class="tit">session隔离</span><span class="btswitch-p"style="display: inline-flex;"><input class="btswitch btswitch-ios" id="session_switch" type="checkbox"><label class="btswitch-btn session-btn" for="session_switch" ></label></span></div><div class="user_pw" style="margin-top: 10px; display: block;"></div>'
+ bt.render_help(['开启后将会把session文件存放到独立文件夹独立文件夹,不与其他站点公用存储位置','若您在PHP配置中将session保存到memcache/redis等缓存器时,请不要开启此选项']));
function get_session_status(){
var loading = bt.load('正在获取session状态请稍后');
bt.send('get_php_session_path','config/get_php_session_path',{id:web.id},function(tdata){
loading.close();
$('#session_switch').prop("checked",tdata);
})
};
get_session_status()
$('#session_switch').click(function() {
var val = $(this).prop('checked');
bt.send('set_php_session_path','config/set_php_session_path',{id:web.id,act:val? 1:0},function(rdata){
bt.msg(rdata)
})
setTimeout(function () {
get_session_status();
}, 500)
})
})
})
},
Expand Down
10 changes: 10 additions & 0 deletions BTPanel/static/js/soft.js
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,7 @@ var soft = {
'<option value="files" '+ (res.save_handler == 'files'?'selected':'') +'>files</option>'+
(version != '52'?'<option value="redis" '+ (res.save_handler == 'redis'?'selected':'') +'>redis</option>':'') +
(version != '73'?'<option value="memcache" '+ (res.save_handler == 'memcache'?'selected':'') +'>memcache</option>':'')+
'<option value="memcached" '+ (res.save_handler == 'memcached'?'selected':'') +'>memcached</option>'+
'</select>'+
'</div>'+
'</div>'+
Expand Down Expand Up @@ -1830,6 +1831,10 @@ var soft = {
$('[name="ip"]').val('127.0.0.1');
$('[name="port"]').val('11211');
break;
case 'memcached':
$('[name="ip"]').val('127.0.0.1');
$('[name="port"]').val('11211');
break;
}
});
$('.btn_conf_save').click(function(){
Expand Down Expand Up @@ -1863,6 +1868,11 @@ var soft = {
$('[name="port"]').attr('disabled',false);
$('[name="passwd"]').attr('disabled','disabled').val('');
break;
case 'memcached':
$('[name="ip"]').attr('disabled',false);
$('[name="port"]').attr('disabled',false);
$('[name="passwd"]').attr('disabled','disabled').val('');
break;
}
}
});
Expand Down
84 changes: 46 additions & 38 deletions class/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,55 @@ def GetProcessCpuPercent(self,i,process_cpu):
except:
pass
def GetNginxStatus(self,get):
process_cpu = {}
worker = int(public.ExecShell("ps aux|grep nginx|grep 'worker process'|wc -l")[0])-1
workermen = int(public.ExecShell("ps aux|grep nginx|grep 'worker process'|awk '{memsum+=$6};END {print memsum}'")[0]) / 1024
for proc in psutil.process_iter():
if proc.name() == "nginx":
self.GetProcessCpuPercent(proc.pid,process_cpu)
time.sleep(0.5)
#取Nginx负载状态
self.CheckStatusConf()
result = public.HttpGet('http://127.0.0.1/nginx_status')
tmp = result.split()
data = {}
if "request_time" in tmp:
data['accepts'] = tmp[8]
data['handled'] = tmp[9]
data['requests'] = tmp[10]
data['Reading'] = tmp[13]
data['Writing'] = tmp[15]
data['Waiting'] = tmp[17]
else:
data['accepts'] = tmp[9]
data['handled'] = tmp[7]
data['requests'] = tmp[8]
data['Reading'] = tmp[11]
data['Writing'] = tmp[13]
data['Waiting'] = tmp[15]
data['active'] = tmp[2]
data['worker'] = worker
data['workercpu'] = round(float(process_cpu["nginx"]),2)
data['workermen'] = "%s%s" % (int(workermen), "MB")
return data
try:
process_cpu = {}
worker = int(public.ExecShell("ps aux|grep nginx|grep 'worker process'|wc -l")[0])-1
workermen = int(public.ExecShell("ps aux|grep nginx|grep 'worker process'|awk '{memsum+=$6};END {print memsum}'")[0]) / 1024
for proc in psutil.process_iter():
if proc.name() == "nginx":
self.GetProcessCpuPercent(proc.pid,process_cpu)
time.sleep(0.5)
#取Nginx负载状态
self.CheckStatusConf()
result = public.HttpGet('http://127.0.0.1/nginx_status')
tmp = result.split()
data = {}
if "request_time" in tmp:
data['accepts'] = tmp[8]
data['handled'] = tmp[9]
data['requests'] = tmp[10]
data['Reading'] = tmp[13]
data['Writing'] = tmp[15]
data['Waiting'] = tmp[17]
else:
data['accepts'] = tmp[9]
data['handled'] = tmp[7]
data['requests'] = tmp[8]
data['Reading'] = tmp[11]
data['Writing'] = tmp[13]
data['Waiting'] = tmp[15]
data['active'] = tmp[2]
data['worker'] = worker
data['workercpu'] = round(float(process_cpu["nginx"]),2)
data['workermen'] = "%s%s" % (int(workermen), "MB")
return data
except Exception as ex:
public.WriteLog('信息获取',"Nginx负载状态获取失败: %s" % ex)
return public.returnMsg(False,'数据获取失败!')

def GetPHPStatus(self,get):
#取指定PHP版本的负载状态
self.CheckStatusConf();
version = get.version
result = public.HttpGet('http://127.0.0.1/phpfpm_'+version+'_status?json')
tmp = json.loads(result)
fTime = time.localtime(int(tmp['start time']))
tmp['start time'] = time.strftime('%Y-%m-%d %H:%M:%S',fTime)
return tmp
try:
self.CheckStatusConf();
version = get.version
result = public.HttpGet('http://127.0.0.1/phpfpm_'+version+'_status?json')
tmp = json.loads(result)
fTime = time.localtime(int(tmp['start time']))
tmp['start time'] = time.strftime('%Y-%m-%d %H:%M:%S',fTime)
return tmp
except Exception as ex:
public.WriteLog('信息获取',"PHP负载状态获取失败: %s" % ex)
return public.returnMsg(False,'负载状态获取失败!')

def CheckStatusConf(self):
if public.get_webserver() != 'nginx': return;
Expand Down
3 changes: 1 addition & 2 deletions class/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ 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.8'
g.version = '6.9.9'
g.title = public.GetConfigValue('title')
g.uri = request.path
session['version'] = g.version;
Expand Down
102 changes: 92 additions & 10 deletions class/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,10 @@ def GetSessionConf(self,get):

reppath = '\nsession.save_path\s*=\s*"tcp\:\/\/([\d\.]+):(\d+).*\r?\n'
passrep = '\nsession.save_path\s*=\s*"tcp://[\w\.\?\:]+=(.*)"\r?\n'
memcached = '\nsession.save_path\s*=\s*"([\d\.]+):(\d+)"'
save_path = re.search(reppath, phpini)
if not save_path:
save_path = re.search(memcached, phpini)
passwd = re.search(passrep, phpini)
port = ""
if passwd:
Expand Down Expand Up @@ -656,6 +659,15 @@ def SetSessionConf(self, get):
rep = 'session.save_handler\s*=\s*(.+)\r?\n'
val = 'session.save_handler = ' + g + '\n'
phpini = re.sub(rep, val, phpini)
if g == "memcached":
if not re.search("memcached.so", phpini):
return public.returnMsg(False, '请先安装%s扩展' % g)
rep = '\nsession.save_path\s*=\s*(.+)\r?\n'
val = '\nsession.save_path = "%s:%s" \n' % (ip,port)
if re.search(rep, phpini):
phpini = re.sub(rep, val, phpini)
else:
phpini = re.sub('\n;session.save_path = "/tmp"', '\n;session.save_path = "/tmp"' + val, phpini)
if g == "memcache":
if not re.search("memcache.so",phpini):
return public.returnMsg(False, '请先安装%s扩展' % g)
Expand Down Expand Up @@ -692,24 +704,39 @@ def SetSessionConf(self, get):

# 获取Session文件数量
def GetSessionCount(self, get):
d="/tmp"
d=["/tmp","/www/php_session"]

count = 0
list = os.listdir(d)
for l in list:
if "sess_" in l:
count += 1
for i in d:
if not os.path.exists(i): os.makedirs(i)
list = os.listdir(i)
for l in list:
if os.path.isdir(i+"/"+l):
l1 = os.listdir(i+"/"+l)
for ll in l1:
if "sess_" in ll:
count += 1
continue
if "sess_" in l:
count += 1

s = "find /tmp -mtime +1 |grep 'sess_'|wc -l"
old_file_conf = int(public.ExecShell(s)[0].split("\n")[0])
old_file = int(public.ExecShell(s)[0].split("\n")[0])

s = "find /www/php_session -mtime +1 |grep 'sess_'|wc -l"
old_file += int(public.ExecShell(s)[0].split("\n")[0])

return {"total":count,"oldfile":old_file_conf}
return {"total":count,"oldfile":old_file}

# 删除老文件
def DelOldSession(self,get):
s = "find /tmp -mtime +1 |grep 'sess_'|xargs rm -f"
os.system(s)
s = "find /tmp -mtime +1 |grep 'sess_'|wc -l"
old_file_conf = int(public.ExecShell(s)[0].split("\n")[0])
s = "find /www/php_session -mtime +1 |grep 'sess_'|xargs rm -f"
os.system(s)
# s = "find /tmp -mtime +1 |grep 'sess_'|wc -l"
# old_file_conf = int(public.ExecShell(s)[0].split("\n")[0])
old_file_conf = self.GetSessionCount(get)
if old_file_conf == 0:
return public.returnMsg(True, '清理成功')
else:
Expand Down Expand Up @@ -963,4 +990,59 @@ def set_local(self,get):
t_str = '开启'
public.writeFile(d_path,'True')
public.WriteLog('面板配置','%s离线模式' % t_str)
return public.returnMsg(True,'设置成功!')
return public.returnMsg(True,'设置成功!')

# 修改.user.ini文件
def _edit_user_ini(self,file,s_conf,act,session_path):
os.system("chattr -i {}".format(file))
conf = public.readFile(file)
if act == "1":
if "session.save_path" in conf:
return False
conf = conf + ":{}/".format(session_path)
conf = conf + "\n" + s_conf
else:
rep = "\n*session.save_path(.|\n)*files"
rep1 = ":{}".format(session_path)
conf = re.sub(rep,"",conf)
conf = re.sub(rep1,"",conf)
public.writeFile(file, conf)
os.system("chattr +i {}".format(file))

# 设置php_session存放到独立文件夹
def set_php_session_path(self,get):
'''
get.id site id
get.act 0/1
:param get:
:return:
'''
import panelSite
site_info = public.M('sites').where('id=?', (get.id,)).field('name,path').find()
session_path = "/www/php_session/{}".format(site_info["name"])
if os.path.exists(session_path):
os.makedirs(session_path)
run_path = panelSite.panelSite().GetSiteRunPath(get)["runPath"]
user_ini_file = "{site_path}{run_path}/.user.ini".format(site_path=site_info["path"], run_path=run_path)
conf = "session.save_path={}/\nsession.save_handler = files".format(session_path)
if get.act == "1":
if not os.path.exists(user_ini_file):
public.writeFile(user_ini_file,conf)
os.system("chattr +i {}".format(user_ini_file))
return public.returnMsg(True,"设置成功")
self._edit_user_ini(user_ini_file,conf,get.act,session_path)
return public.returnMsg(True, "设置成功")
else:
self._edit_user_ini(user_ini_file,conf,get.act,session_path)
return public.returnMsg(True, "设置成功")

# 获取php_session是否存放到独立文件夹
def get_php_session_path(self,get):
import panelSite
site_info = public.M('sites').where('id=?', (get.id,)).field('name,path').find()
run_path = panelSite.panelSite().GetSiteRunPath(get)["runPath"]
user_ini_file = "{site_path}{run_path}/.user.ini".format(site_path=site_info["path"], run_path=run_path)
conf = public.readFile(user_ini_file)
if conf and "session.save_path" in conf:
return True
return False
1 change: 1 addition & 0 deletions class/datatool.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def GetdataInfo(self,get):
ret3 = []
for i in tables:
if i == 1049: return public.returnMsg(False,'指定数据库不存在!')
if type(i) == int: continue
table = self.map_to_list(self.DB_MySQL.query("show table status from `%s` where name = '%s'" % (db_name, i[0])))
if not table: continue
try:
Expand Down
6 changes: 3 additions & 3 deletions class/firewalls.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def SetPing(self,get):

#改远程端口
def SetSshPort(self,get):
#return public.returnMsg(False,'演示服务器,禁止此操作!');
port = get.port
if int(port) < 22 or int(port) > 65535: return public.returnMsg(False,'FIREWALL_SSH_PORT_ERR');
ports = ['21','25','80','443','8080','888','8888'];
Expand All @@ -224,7 +223,7 @@ def SetSshPort(self,get):
public.writeFile(file,conf)

if self.__isFirewalld:
self.__Obj.AddAcceptPort(port);
public.ExecShell('firewall-cmd --permanent --zone=public --add-port='+port+'/tcp')
public.ExecShell('setenforce 0');
public.ExecShell('sed -i "s#SELINUX=enforcing#SELINUX=disabled#" /etc/selinux/config');
public.ExecShell("systemctl restart sshd.service")
Expand All @@ -236,7 +235,8 @@ def SetSshPort(self,get):
public.ExecShell("/etc/init.d/sshd restart")

self.FirewallReload()
public.M('firewall').where("ps=?",('SSH远程管理服务',)).setField('port',port)
public.M('firewall').where("ps=? or ps=? or port=?",('SSH远程管理服务','SSH远程服务',port)).delete()
public.M('firewall').add('port,ps,addtime',(port,'SSH远程服务',time.strftime('%Y-%m-%d %X',time.localtime())))
public.WriteLog("TYPE_FIREWALL", "FIREWALL_SSH_PORT",(port,))
return public.returnMsg(True,'EDIT_SUCCESS')

Expand Down
Loading

0 comments on commit 1370874

Please sign in to comment.