Skip to content

Commit

Permalink
6.9.28
Browse files Browse the repository at this point in the history
  • Loading branch information
showpy committed Jul 24, 2019
1 parent 49c55b8 commit 54a946a
Show file tree
Hide file tree
Showing 16 changed files with 568 additions and 123 deletions.
6 changes: 5 additions & 1 deletion BTPanel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from werkzeug.wrappers import Response
from flask_socketio import SocketIO,emit,send
dns_client = None
app.config['DEBUG'] = os.path.exists('data/debug.pl')

#设置BasicAuth
basic_auth_conf = 'config/basic_auth.json'
Expand Down Expand Up @@ -413,9 +414,11 @@ def config(pdata = None):
data['basic_auth'] = c_obj.get_basic_auth_stat(None)
data['basic_auth']['value'] = '已关闭'
if data['basic_auth']['open']: data['basic_auth']['value'] = '已开启'
data['debug'] = ''
if app.config['DEBUG']: data['debug'] = 'checked'
return render_template( 'config.html',data=data)
import config
defs = ('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_cert_source','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 @@ -918,6 +921,7 @@ def connected_msg(msg):


def check_csrf():
if app.config['DEBUG']: return True
request_token = request.cookies.get('request_token')
if session['request_token'] != request_token: return False
http_token = request.headers.get('x-http-token')
Expand Down
Binary file added BTPanel/static/img/dep_ico/Temmoku_MVC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BTPanel/static/img/dep_ico/chengxuxia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
153 changes: 118 additions & 35 deletions BTPanel/static/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,41 +176,109 @@ function setTemplate(){

//设置面板SSL
function setPanelSSL(){
var status = $("#sshswitch").prop("checked")==true?1:0;
var msg = $("#panelSSL").attr('checked')?lan.config.ssl_close_msg:'<a style="font-weight: bolder;font-size: 16px;">'+lan.config.ssl_open_ps+'</a><li style="margin-top: 12px;color:red;">'+lan.config.ssl_open_ps_1+'</li><li>'+lan.config.ssl_open_ps_2+'</li><li>'+lan.config.ssl_open_ps_3+'</li><p style="margin-top: 10px;"><input type="checkbox" id="checkSSL" /><label style="font-weight: 400;margin: 3px 5px 0px;" for="checkSSL">'+lan.config.ssl_open_ps_4+'</label><a target="_blank" class="btlink" href="https://www.bt.cn/bbs/thread-4689-1-1.html" style="float: right;">'+lan.config.ssl_open_ps_5+'</a></p>';
layer.confirm(msg,{title:lan.config.ssl_title,closeBtn:2,icon:3,area:'550px',cancel:function(){
if(status == 0){
$("#panelSSL").prop("checked",false);
}
else{
$("#panelSSL").prop("checked",true);
}
}},function(){
if(window.location.protocol.indexOf('https') == -1){
if(!$("#checkSSL").prop('checked')){
layer.msg(lan.config.ssl_ps,{icon:2});
return false;
}
}
var loadT = layer.msg(lan.config.ssl_msg,{icon:16,time:0,shade: [0.3, '#000']});
$.post('/config?action=SetPanelSSL','',function(rdata){
layer.close(loadT);
layer.msg(rdata.msg,{icon:rdata.status?1:5});
if(rdata.status === true){
$.get('/system?action=ReWeb',function(){});
setTimeout(function(){
window.location.href = ((window.location.protocol.indexOf('https') != -1)?'http://':'https://') + window.location.host + window.location.pathname;
},1500);
}
});
},function(){
if(status == 0){
$("#panelSSL").prop("checked",false);
}
else{
$("#panelSSL").prop("checked",true);
}
});
var status = $("#panelSSL").prop("checked");
var loadT = layer.msg(lan.config.ssl_msg,{icon:16,time:0,shade: [0.3, '#000']});
if(status){
var confirm = layer.confirm('是否关闭面板SSL证书', {title:'提示',btn: ['确定','取消'],icon:0,closeBtn:2}, function() {
bt.send('SetPanelSSL', 'config/SetPanelSSL', {}, function (rdata) {
layer.close(loadT);
if (rdata.status) {
layer.msg(rdata.msg,{icon:1});
$.get('/system?action=ReWeb', function () {
});
setTimeout(function () {
window.location.href = ((window.location.protocol.indexOf('https') != -1) ? 'http://' : 'https://') + window.location.host + window.location.pathname;
}, 1500);
}
else {
layer.msg(res.rdata,{icon:2});
}
});
return;
})
}
else {
bt.send('get_cert_source', 'config/get_cert_source', {}, function (rdata) {
layer.close(loadT);
var sdata = rdata;
var _data = {
title: '面板SSL',
area: '530px',
list: [
{
html:'<div style="margin-left: 58px;"><i class="layui-layer-ico layui-layer-ico3"></i><a style="font-weight: bolder;font-size: 16px;">'+lan.config.ssl_open_ps+'</a><li style="margin-top: 12px;color:red;">'+lan.config.ssl_open_ps_1+'</li><li>'+lan.config.ssl_open_ps_2+'</li><li>'+lan.config.ssl_open_ps_3+'</li></div>'
},
{
title: '类型',
name: 'cert_type',
type: 'select',
width: '200px',
value: sdata.cert_type,
items: [{value: '1', title: '自签证书'}, {value: '2', title: 'Let\'s Encrypt'}],
callback: function (obj) {
var subid = obj.attr('name') + '_subid';
$('#' + subid).remove();
if (obj.val() == '2') {
var _tr = bt.render_form_line({
title: '管理员邮箱',
name: 'email',
placeholder: '管理员邮箱',
value: sdata.email
});
obj.parents('div.line').append('<div class="line" id=' + subid + '>' + _tr.html + '</div>');
}
}
},
{
html:'<div style="margin-left: 58px;"><p style="margin-top: 10px;"><input type="checkbox" id="checkSSL" /><label style="font-weight: 400;margin: 3px 5px 0px;" for="checkSSL">'+lan.config.ssl_open_ps_4+'</label><a target="_blank" class="btlink" href="https://www.bt.cn/bbs/thread-4689-1-1.html" style="float: right;">'+lan.config.ssl_open_ps_5+'</a></p></div>'
}

],
btns: [
{
title: '关闭', name: 'close', callback: function (rdata, load, callback) {
load.close();
$("#panelSSL").prop("checked", false);
}
},
{
title: '提交', name: 'submit', css: 'btn-success', callback: function (rdata, load, callback) {
if(!$('#checkSSL').is(':checked')){
bt.msg({status:false,msg:'请先确认风险!'})
return;
}
var confirm = layer.confirm('是否开启面板SSL证书', {title:'提示',btn: ['确定','取消'],icon:0,closeBtn:2}, function() {
var loading = bt.load();
bt.send('SetPanelSSL', 'config/SetPanelSSL', rdata, function (rdata) {
loading.close()
if (rdata.status) {
layer.msg(rdata.msg,{icon:1});
$.get('/system?action=ReWeb', function () {
});
setTimeout(function () {
window.location.href = ((window.location.protocol.indexOf('https') != -1) ? 'http://' : 'https://') + window.location.host + window.location.pathname;
}, 1500);
}
else {
layer.msg(rdata.msg,{icon:2});
}
})
});
}

}
],
end: function () {
$("#panelSSL").prop("checked", false);
}
};

var _bs = bt.render_form(_data);
setTimeout(function () {
$('.cert_type' + _bs).trigger('change')
}, 200);
});
}
}

function GetPanelSSL(){
Expand Down Expand Up @@ -261,6 +329,21 @@ function SavePanelSSL(){
});
}

function SetDebug() {
var status_s = {false:'开启',true:'关闭'}
var debug_stat = $("#panelDebug").prop('checked');
bt.confirm({ title: status_s[debug_stat] + "开发者模式", msg: "您真的要" + status_s[debug_stat]+"开发者模式吗?"}, function () {
var loadT = layer.msg(lan.public.the, { icon: 16, time: 0, shade: [0.3, '#000'] });
$.post('/config?action=set_debug', {}, function (rdata) {
layer.close(loadT);
if (rdata.status) {
layer.closeAll();
}
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
});
});
}

if(window.location.protocol.indexOf('https') != -1){
$("#panelSSL").attr('checked',true);
}
Expand Down
18 changes: 13 additions & 5 deletions BTPanel/static/js/public_backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,10 +779,17 @@ var bt =
var _form = $("<div data-id='form"+bs+"' class='bt-form bt-form pd20 pb70'></div>");
var _lines = data.list;
var clicks = [];
for (var i = 0;i<_lines.length;i++){
var rRet = bt.render_form_line(_lines[i],bs);
for(var s = 0;s<rRet.clicks.length;s++) clicks.push(rRet.clicks[s]);
_form.append(rRet.html);
for (var i = 0; i < _lines.length; i++)
{
var _obj = _lines[i]
if (_obj.hasOwnProperty("html")) {
_form.append(_obj.html)
}
else {
var rRet = bt.render_form_line(_obj, bs);
for (var s = 0; s < rRet.clicks.length; s++) clicks.push(rRet.clicks[s]);
_form.append(rRet.html);
}
}

var _btn_html = '';
Expand All @@ -799,7 +806,8 @@ var bt =
area: data.area,
title: data.title,
closeBtn: 2,
content:_form.prop("outerHTML")
content:_form.prop("outerHTML"),
end: data.end ? data.end : false
})
setTimeout(function(){
bt.render_clicks(clicks,loadOpen,callback);
Expand Down
7 changes: 7 additions & 0 deletions BTPanel/templates/default/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
<label class='btswitch-btn' for='panelApi' onclick="SetPanelApi(2)"></label>
</div>
</div>
<div class="ss-text pull-left mr50">
<em title="开发者模式">开发者模式</em>
<div class='ssh-item'>
<input class='btswitch btswitch-ios' id='panelDebug' type='checkbox' {{data['debug']}}>
<label class='btswitch-btn' for='panelDebug' onclick="SetDebug()"></label>
</div>
</div>
</div>
</div>
<div class="setbox bgw mtb15">
Expand Down
2 changes: 1 addition & 1 deletion class/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def init(self):
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.27'
g.version = '6.9.28'
g.title = public.GetConfigValue('title')
g.uri = request.path
session['version'] = g.version;
Expand Down
61 changes: 45 additions & 16 deletions class/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,20 +416,29 @@ def SetTemplates(self,get):

#设置面板SSL
def SetPanelSSL(self,get):
sslConf = '/www/server/panel/data/ssl.pl';
if os.path.exists(sslConf):
os.system('rm -f ' + sslConf);
return public.returnMsg(True,'PANEL_SSL_CLOSE');
if hasattr(get,"email"):
rep_mail = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$"
if not re.search(rep_mail,get.email):
return public.returnMsg(False,'邮箱格式不合法')
import setPanelLets
sp = setPanelLets.setPanelLets()
sps = sp.set_lets(get)
return sps
else:
os.system('pip install cffi');
os.system('pip install cryptography');
os.system('pip install pyOpenSSL');
try:
if not self.CreateSSL(): return public.returnMsg(False,'PANEL_SSL_ERR');
public.writeFile(sslConf,'True')
except Exception as ex:
return public.returnMsg(False,'PANEL_SSL_ERR');
return public.returnMsg(True,'PANEL_SSL_OPEN');
sslConf = '/www/server/panel/data/ssl.pl';
if os.path.exists(sslConf):
os.system('rm -f ' + sslConf);
return public.returnMsg(True,'PANEL_SSL_CLOSE');
else:
os.system('pip install cffi');
os.system('pip install cryptography');
os.system('pip install pyOpenSSL');
try:
if not self.CreateSSL(): return public.returnMsg(False,'PANEL_SSL_ERR');
public.writeFile(sslConf,'True')
except Exception as ex:
return public.returnMsg(False,'PANEL_SSL_ERR');
return public.returnMsg(True,'PANEL_SSL_OPEN');
#自签证书
def CreateSSL(self):
if os.path.exists('ssl/input.pl'): return True;
Expand All @@ -447,8 +456,8 @@ def CreateSSL(self):
cert_ca = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
private_key = OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, key)
if len(cert_ca) > 100 and len(private_key) > 100:
public.writeFile('ssl/certificate.pem',cert_ca)
public.writeFile('ssl/privateKey.pem',private_key)
public.writeFile('ssl/certificate.pem',cert_ca,'wb+')
public.writeFile('ssl/privateKey.pem',private_key,'wb+')
return True
return False

Expand Down Expand Up @@ -913,4 +922,24 @@ def clean_panel_error_logs(self,get):
filename = 'logs/error.log'
public.writeFile(filename,'')
public.WriteLog('面板配置','清空面板运行日志')
return public.returnMsg(True,'已清空!')
return public.returnMsg(True,'已清空!')

# 获取lets证书
def get_cert_source(self,get):
import setPanelLets
sp = setPanelLets.setPanelLets()
spg = sp.get_cert_source()
return spg

#设置debug模式
def set_debug(self,get):
debug_path = 'data/debug.pl'
if os.path.exists(debug_path):
t_str = '关闭'
os.remove(debug_path)
else:
t_str = '开启'
public.writeFile(debug_path,'True')
public.WriteLog('面板配置','%s开发者模式(debug)' % t_str)
public.restart_panel()
return public.returnMsg(True,'设置成功!')
4 changes: 3 additions & 1 deletion class/panelSite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,9 @@ def GetProxyList(self, get):
n = 0
for w in ["nginx", "apache"]:
conf_path = "%s/panel/vhost/%s/%s.conf" % (self.setupPath, w, get.sitename)
old_conf = public.readFile(conf_path)
old_conf = ""
if os.path.exists(conf_path):
old_conf = public.readFile(conf_path)
rep = "(#PROXY-START(\n|.)+#PROXY-END)"
url_rep = "proxy_pass (.*);|ProxyPass\s/\s(.*)|Host\s(.*);"
host_rep = "Host\s(.*);"
Expand Down
Loading

0 comments on commit 54a946a

Please sign in to comment.