Skip to content

Commit

Permalink
增加BasicAuth认证功能,修正apache2.2下的一些显示问题,
Browse files Browse the repository at this point in the history
  • Loading branch information
showpy committed Jun 21, 2019
1 parent 192c88a commit 9e087cb
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 25 deletions.
172 changes: 172 additions & 0 deletions BTPanel.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
<Compile Include="plugin\btwaf_httpd\btwaf_httpd_main.py" />
<Compile Include="plugin\btyw\btyw_main.py" />
<Compile Include="plugin\clear\clear_main.py" />
<Compile Include="plugin\coll\coll_main.py" />
<Compile Include="plugin\coll\inc\coll_common.py" />
<Compile Include="plugin\coll\inc\coll_db.py" />
<Compile Include="plugin\coll\inc\coll_server.py" />
<Compile Include="plugin\coll\inc\coll_shell.py" />
<Compile Include="plugin\coll\inc\coll_terminal.py" />
<Compile Include="plugin\coll\inc\coll_upload.py" />
<Compile Include="plugin\coll\inc\coll_user.py" />
<Compile Include="plugin\coll\inc\fun.py" />
<Compile Include="plugin\coll\inc\__init__.py" />
<Compile Include="plugin\deployment\deployment_main.py" />
<Compile Include="plugin\dns\dns_main.py" />
<Compile Include="plugin\docker\docker_main.py" />
Expand Down Expand Up @@ -240,6 +250,27 @@
<Folder Include="plugin\btwaf_httpd\btwaf\rule\" />
<Folder Include="plugin\btyw\" />
<Folder Include="plugin\clear\" />
<Folder Include="plugin\coll\" />
<Folder Include="plugin\coll\inc\" />
<Folder Include="plugin\coll\static\" />
<Folder Include="plugin\coll\static\css\" />
<Folder Include="plugin\coll\static\css\metroStyle\" />
<Folder Include="plugin\coll\static\css\metroStyle\img\" />
<Folder Include="plugin\coll\static\img\" />
<Folder Include="plugin\coll\static\js\" />
<Folder Include="plugin\coll\static\layui\" />
<Folder Include="plugin\coll\static\layui\css\" />
<Folder Include="plugin\coll\static\layui\css\modules\" />
<Folder Include="plugin\coll\static\layui\css\modules\laydate\" />
<Folder Include="plugin\coll\static\layui\css\modules\laydate\default\" />
<Folder Include="plugin\coll\static\layui\css\modules\layer\" />
<Folder Include="plugin\coll\static\layui\css\modules\layer\default\" />
<Folder Include="plugin\coll\static\layui\font\" />
<Folder Include="plugin\coll\static\layui\images\" />
<Folder Include="plugin\coll\static\layui\images\face\" />
<Folder Include="plugin\coll\static\layui\lay\" />
<Folder Include="plugin\coll\static\layui\lay\modules\" />
<Folder Include="plugin\coll\templates\" />
<Folder Include="plugin\deployment\" />
<Folder Include="plugin\deployment\package\" />
<Folder Include="plugin\dns\" />
Expand Down Expand Up @@ -934,6 +965,147 @@
<Content Include="plugin\clear\index.html" />
<Content Include="plugin\clear\info.json" />
<Content Include="plugin\clear\install.sh" />
<Content Include="plugin\coll\data - Copy.db" />
<Content Include="plugin\coll\data.db" />
<Content Include="plugin\coll\static\css\admin.css" />
<Content Include="plugin\coll\static\css\login.css" />
<Content Include="plugin\coll\static\css\metroStyle\img\active.png" />
<Content Include="plugin\coll\static\css\metroStyle\img\active_true.png" />
<Content Include="plugin\coll\static\css\metroStyle\img\ico.png" />
<Content Include="plugin\coll\static\css\metroStyle\img\line_conn.png" />
<Content Include="plugin\coll\static\css\metroStyle\img\loading.gif" />
<Content Include="plugin\coll\static\css\metroStyle\img\metro.gif" />
<Content Include="plugin\coll\static\css\metroStyle\img\metro.png" />
<Content Include="plugin\coll\static\css\metroStyle\metroStyle.css" />
<Content Include="plugin\coll\static\css\reset.css" />
<Content Include="plugin\coll\static\img\bg.png" />
<Content Include="plugin\coll\static\img\code.png" />
<Content Include="plugin\coll\static\img\ico-edit.png" />
<Content Include="plugin\coll\static\img\name.png" />
<Content Include="plugin\coll\static\img\password.png" />
<Content Include="plugin\coll\static\img\ver-code.png" />
<Content Include="plugin\coll\static\js\hashme.js" />
<Content Include="plugin\coll\static\js\jquery.ztree.core.js" />
<Content Include="plugin\coll\static\js\jquery.ztree.excheck.js" />
<Content Include="plugin\coll\static\js\jquery.ztree.exedit.js" />
<Content Include="plugin\coll\static\js\md5.js" />
<Content Include="plugin\coll\static\layui\css\layui.css" />
<Content Include="plugin\coll\static\layui\css\layui.mobile.css" />
<Content Include="plugin\coll\static\layui\css\modules\code.css" />
<Content Include="plugin\coll\static\layui\css\modules\laydate\default\laydate.css" />
<Content Include="plugin\coll\static\layui\css\modules\layer\default\icon-ext.png" />
<Content Include="plugin\coll\static\layui\css\modules\layer\default\icon.png" />
<Content Include="plugin\coll\static\layui\css\modules\layer\default\layer.css" />
<Content Include="plugin\coll\static\layui\css\modules\layer\default\loading-0.gif" />
<Content Include="plugin\coll\static\layui\css\modules\layer\default\loading-1.gif" />
<Content Include="plugin\coll\static\layui\css\modules\layer\default\loading-2.gif" />
<Content Include="plugin\coll\static\layui\font\iconfont.eot" />
<Content Include="plugin\coll\static\layui\font\iconfont.svg" />
<Content Include="plugin\coll\static\layui\font\iconfont.ttf" />
<Content Include="plugin\coll\static\layui\font\iconfont.woff" />
<Content Include="plugin\coll\static\layui\images\face\0.gif" />
<Content Include="plugin\coll\static\layui\images\face\1.gif" />
<Content Include="plugin\coll\static\layui\images\face\10.gif" />
<Content Include="plugin\coll\static\layui\images\face\11.gif" />
<Content Include="plugin\coll\static\layui\images\face\12.gif" />
<Content Include="plugin\coll\static\layui\images\face\13.gif" />
<Content Include="plugin\coll\static\layui\images\face\14.gif" />
<Content Include="plugin\coll\static\layui\images\face\15.gif" />
<Content Include="plugin\coll\static\layui\images\face\16.gif" />
<Content Include="plugin\coll\static\layui\images\face\17.gif" />
<Content Include="plugin\coll\static\layui\images\face\18.gif" />
<Content Include="plugin\coll\static\layui\images\face\19.gif" />
<Content Include="plugin\coll\static\layui\images\face\2.gif" />
<Content Include="plugin\coll\static\layui\images\face\20.gif" />
<Content Include="plugin\coll\static\layui\images\face\21.gif" />
<Content Include="plugin\coll\static\layui\images\face\22.gif" />
<Content Include="plugin\coll\static\layui\images\face\23.gif" />
<Content Include="plugin\coll\static\layui\images\face\24.gif" />
<Content Include="plugin\coll\static\layui\images\face\25.gif" />
<Content Include="plugin\coll\static\layui\images\face\26.gif" />
<Content Include="plugin\coll\static\layui\images\face\27.gif" />
<Content Include="plugin\coll\static\layui\images\face\28.gif" />
<Content Include="plugin\coll\static\layui\images\face\29.gif" />
<Content Include="plugin\coll\static\layui\images\face\3.gif" />
<Content Include="plugin\coll\static\layui\images\face\30.gif" />
<Content Include="plugin\coll\static\layui\images\face\31.gif" />
<Content Include="plugin\coll\static\layui\images\face\32.gif" />
<Content Include="plugin\coll\static\layui\images\face\33.gif" />
<Content Include="plugin\coll\static\layui\images\face\34.gif" />
<Content Include="plugin\coll\static\layui\images\face\35.gif" />
<Content Include="plugin\coll\static\layui\images\face\36.gif" />
<Content Include="plugin\coll\static\layui\images\face\37.gif" />
<Content Include="plugin\coll\static\layui\images\face\38.gif" />
<Content Include="plugin\coll\static\layui\images\face\39.gif" />
<Content Include="plugin\coll\static\layui\images\face\4.gif" />
<Content Include="plugin\coll\static\layui\images\face\40.gif" />
<Content Include="plugin\coll\static\layui\images\face\41.gif" />
<Content Include="plugin\coll\static\layui\images\face\42.gif" />
<Content Include="plugin\coll\static\layui\images\face\43.gif" />
<Content Include="plugin\coll\static\layui\images\face\44.gif" />
<Content Include="plugin\coll\static\layui\images\face\45.gif" />
<Content Include="plugin\coll\static\layui\images\face\46.gif" />
<Content Include="plugin\coll\static\layui\images\face\47.gif" />
<Content Include="plugin\coll\static\layui\images\face\48.gif" />
<Content Include="plugin\coll\static\layui\images\face\49.gif" />
<Content Include="plugin\coll\static\layui\images\face\5.gif" />
<Content Include="plugin\coll\static\layui\images\face\50.gif" />
<Content Include="plugin\coll\static\layui\images\face\51.gif" />
<Content Include="plugin\coll\static\layui\images\face\52.gif" />
<Content Include="plugin\coll\static\layui\images\face\53.gif" />
<Content Include="plugin\coll\static\layui\images\face\54.gif" />
<Content Include="plugin\coll\static\layui\images\face\55.gif" />
<Content Include="plugin\coll\static\layui\images\face\56.gif" />
<Content Include="plugin\coll\static\layui\images\face\57.gif" />
<Content Include="plugin\coll\static\layui\images\face\58.gif" />
<Content Include="plugin\coll\static\layui\images\face\59.gif" />
<Content Include="plugin\coll\static\layui\images\face\6.gif" />
<Content Include="plugin\coll\static\layui\images\face\60.gif" />
<Content Include="plugin\coll\static\layui\images\face\61.gif" />
<Content Include="plugin\coll\static\layui\images\face\62.gif" />
<Content Include="plugin\coll\static\layui\images\face\63.gif" />
<Content Include="plugin\coll\static\layui\images\face\64.gif" />
<Content Include="plugin\coll\static\layui\images\face\65.gif" />
<Content Include="plugin\coll\static\layui\images\face\66.gif" />
<Content Include="plugin\coll\static\layui\images\face\67.gif" />
<Content Include="plugin\coll\static\layui\images\face\68.gif" />
<Content Include="plugin\coll\static\layui\images\face\69.gif" />
<Content Include="plugin\coll\static\layui\images\face\7.gif" />
<Content Include="plugin\coll\static\layui\images\face\70.gif" />
<Content Include="plugin\coll\static\layui\images\face\71.gif" />
<Content Include="plugin\coll\static\layui\images\face\8.gif" />
<Content Include="plugin\coll\static\layui\images\face\9.gif" />
<Content Include="plugin\coll\static\layui\layui.all.js" />
<Content Include="plugin\coll\static\layui\layui.js" />
<Content Include="plugin\coll\static\layui\lay\modules\carousel.js" />
<Content Include="plugin\coll\static\layui\lay\modules\code.js" />
<Content Include="plugin\coll\static\layui\lay\modules\colorpicker.js" />
<Content Include="plugin\coll\static\layui\lay\modules\element.js" />
<Content Include="plugin\coll\static\layui\lay\modules\flow.js" />
<Content Include="plugin\coll\static\layui\lay\modules\form.js" />
<Content Include="plugin\coll\static\layui\lay\modules\jquery.js" />
<Content Include="plugin\coll\static\layui\lay\modules\laydate.js" />
<Content Include="plugin\coll\static\layui\lay\modules\layedit.js" />
<Content Include="plugin\coll\static\layui\lay\modules\layer.js" />
<Content Include="plugin\coll\static\layui\lay\modules\laypage.js" />
<Content Include="plugin\coll\static\layui\lay\modules\laytpl.js" />
<Content Include="plugin\coll\static\layui\lay\modules\mobile.js" />
<Content Include="plugin\coll\static\layui\lay\modules\rate.js" />
<Content Include="plugin\coll\static\layui\lay\modules\slider.js" />
<Content Include="plugin\coll\static\layui\lay\modules\table.js" />
<Content Include="plugin\coll\static\layui\lay\modules\tree.js" />
<Content Include="plugin\coll\static\layui\lay\modules\upload.js" />
<Content Include="plugin\coll\static\layui\lay\modules\util.js" />
<Content Include="plugin\coll\templates\head.html" />
<Content Include="plugin\coll\templates\iframe.html" />
<Content Include="plugin\coll\templates\index.html" />
<Content Include="plugin\coll\templates\login.html" />
<Content Include="plugin\coll\templates\menu.html" />
<Content Include="plugin\coll\templates\server.html" />
<Content Include="plugin\coll\templates\shell.html" />
<Content Include="plugin\coll\templates\terminal.html" />
<Content Include="plugin\coll\templates\upload.html" />
<Content Include="plugin\coll\templates\user.html" />
<Content Include="plugin\deployment\ico-deployment.png" />
<Content Include="plugin\deployment\icon.png" />
<Content Include="plugin\deployment\index.html" />
Expand Down
52 changes: 40 additions & 12 deletions BTPanel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
from werkzeug.wrappers import Response
from flask_socketio import SocketIO,emit,send

#from flask_basicauth import BasicAuth
#app.config['BASIC_AUTH_USERNAME'] = 'admin'
#app.config['BASIC_AUTH_PASSWORD'] = '11111'
#app.config['BASIC_AUTH_FORCE'] = True
#basic_auth = BasicAuth(app)

#设置BasicAuth
basic_auth_conf = 'config/basic_auth.json'
app.config['BASIC_AUTH_OPEN'] = False
if os.path.exists(basic_auth_conf):
try:
ba_conf = json.loads(public.readFile(basic_auth_conf))
app.config['BASIC_AUTH_USERNAME'] = ba_conf['basic_user']
app.config['BASIC_AUTH_PASSWORD'] = ba_conf['basic_pwd']
app.config['BASIC_AUTH_OPEN'] = ba_conf['open']
except: pass

cache = SimpleCache()
socketio = SocketIO()
Expand Down Expand Up @@ -81,6 +85,22 @@
def service_status():
return 'True'


@app.before_request
def basic_auth_check():
if app.config['BASIC_AUTH_OPEN']:
if request.path in ['/public']: return;
auth = request.authorization
if not comm.get_sk(): return;
if not auth: return send_authenticated()
tips = '_bt.cn'
if public.md5(auth.username.strip() + tips) != app.config['BASIC_AUTH_USERNAME'] or public.md5(auth.password.strip() + tips) != app.config['BASIC_AUTH_PASSWORD']:
return send_authenticated()


def send_authenticated():
return Response('', 401,{'WWW-Authenticate': 'Basic realm="Login Required"'})

@app.route('/',methods=method_all)
def home():
comReturn = comm.local()
Expand Down Expand Up @@ -186,7 +206,7 @@ def ftp(pdata = None):
data['isSetup'] = True;
if os.path.exists(public.GetConfigValue('setup_path') + '/pure-ftpd') == False: data['isSetup'] = False;
data['lan'] = public.GetLan('ftp')
return render_template( 'ftp.html',data=data)
return render_template('ftp.html',data=data)
import ftp
ftpObject = ftp.ftp()
defs = ('AddUser','DeleteUser','SetUserPassword','SetStatus','setPort')
Expand Down Expand Up @@ -337,6 +357,7 @@ def config(pdata = None):
if comReturn: return comReturn
if request.method == method_get[0] and not pdata:
import system,wxapp,config
c_obj = config.config()
data = system.system().GetConcifInfo()
data['lan'] = public.GetLan('config')
try:
Expand All @@ -351,13 +372,15 @@ def config(pdata = None):
if not os.path.exists(workers_p): public.writeFile(workers_p,'1')
data['workers'] = int(public.readFile(workers_p))
data['session_timeout'] = int(public.readFile(sess_out_path))
if config.config().get_ipv6_listen(None): data['ipv6'] = 'checked'
if config.config().get_token(None)['open']: data['api'] = 'checked'
if c_obj.get_ipv6_listen(None): data['ipv6'] = 'checked'
if c_obj.get_token(None)['open']: data['api'] = 'checked'
data['basic_auth'] = c_obj.get_basic_auth_stat(None)
data['basic_auth']['value'] = '已关闭'
if data['basic_auth']['open']: data['basic_auth']['value'] = '已开启'
return render_template( 'config.html',data=data)
import config
configObject = config.config()
defs = ('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(configObject,defs,None,pdata);
defs = ('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)
def ajax(pdata = None):
Expand Down Expand Up @@ -455,7 +478,12 @@ def plugin(pdata = None):
def panel_public():
get = get_input();
get.client_ip = public.GetClientIp();

if get.fun in ['scan_login','login_qrcode','set_login','is_scan_ok','blind']:
#检查是否验证过安全入口
if get.fun in ['login_qrcode','is_scan_ok']:
global admin_check_auth,admin_path,route_path,admin_path_file
if admin_path != '/bt' and os.path.exists(admin_path_file) and not 'admin_auth' in session: return 'False'
import wxapp
pluwx = wxapp.wxapp()
checks = pluwx._check(get)
Expand Down
Loading

0 comments on commit 9e087cb

Please sign in to comment.