mirror of
https://github.com/towalink/wgfrontend.git
synced 2025-04-19 08:55:11 +00:00
Allow non-ssl login in case SSL/TLS is not used
This commit is contained in:
parent
8a979e674a
commit
1f07cb927a
@ -74,7 +74,9 @@ class WebApp():
|
|||||||
def check_username_and_password(self, username, password):
|
def check_username_and_password(self, username, password):
|
||||||
"""Check whether provided username and password are valid when authenticating"""
|
"""Check whether provided username and password are valid when authenticating"""
|
||||||
if (username in self.cfg.users) and (pwdtools.verify_password(self.cfg.users[username], password)):
|
if (username in self.cfg.users) and (pwdtools.verify_password(self.cfg.users[username], password)):
|
||||||
|
cherrypy.log('Login of user: ' + username, context='WEBAPP', severity=logging.INFO, traceback=False)
|
||||||
return
|
return
|
||||||
|
cherrypy.log('Login failed for user: ' + username, context='WEBAPP', severity=logging.WARNING, traceback=False)
|
||||||
return 'invalid username/password'
|
return 'invalid username/password'
|
||||||
|
|
||||||
def login_screen(self, from_page='..', username='', error_msg='', **kwargs):
|
def login_screen(self, from_page='..', username='', error_msg='', **kwargs):
|
||||||
@ -105,6 +107,23 @@ def run_webapp(cfg):
|
|||||||
"""Runs the CherryPy web application with the provided configuration data"""
|
"""Runs the CherryPy web application with the provided configuration data"""
|
||||||
script_path = os.path.dirname(os.path.abspath(__file__))
|
script_path = os.path.dirname(os.path.abspath(__file__))
|
||||||
app = WebApp(cfg)
|
app = WebApp(cfg)
|
||||||
|
# Use SSL if certificate files exist
|
||||||
|
ssl = os.path.exists(cfg.sslcertfile) and os.path.exists(cfg.sslkeyfile)
|
||||||
|
if ssl:
|
||||||
|
# Use ssl/tls if certificate files are present
|
||||||
|
cherrypy.server.ssl_module = 'builtin'
|
||||||
|
cherrypy.server.ssl_certificate = cfg.sslcertfile
|
||||||
|
cherrypy.server.ssl_private_key = cfg.sslkeyfile
|
||||||
|
# Define socket parameters
|
||||||
|
cherrypy.config.update({'server.socket_host': cfg.socket_host,
|
||||||
|
'server.socket_port': cfg.socket_port,
|
||||||
|
})
|
||||||
|
# Select environment
|
||||||
|
cherrypy.config.update({'staging':
|
||||||
|
{
|
||||||
|
'environment' : 'production'
|
||||||
|
}
|
||||||
|
})
|
||||||
# Configure the web application
|
# Configure the web application
|
||||||
app_conf = {
|
app_conf = {
|
||||||
'global': {
|
'global': {
|
||||||
@ -112,7 +131,7 @@ def run_webapp(cfg):
|
|||||||
},
|
},
|
||||||
'/': {
|
'/': {
|
||||||
'tools.sessions.on': True,
|
'tools.sessions.on': True,
|
||||||
'tools.sessions.secure': True,
|
'tools.sessions.secure': ssl,
|
||||||
'tools.sessions.httponly': True,
|
'tools.sessions.httponly': True,
|
||||||
'tools.staticdir.root': os.path.join(script_path, 'webroot'),
|
'tools.staticdir.root': os.path.join(script_path, 'webroot'),
|
||||||
'tools.session_auth.on': True,
|
'tools.session_auth.on': True,
|
||||||
@ -136,22 +155,6 @@ def run_webapp(cfg):
|
|||||||
'tools.staticfile.filename': os.path.join(script_path, 'webroot', 'static', 'favicon.ico')
|
'tools.staticfile.filename': os.path.join(script_path, 'webroot', 'static', 'favicon.ico')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# Use SSL if certificate files exist
|
|
||||||
if os.path.exists(cfg.sslcertfile) and os.path.exists(cfg.sslkeyfile):
|
|
||||||
# Use ssl/tls if certificate files are present
|
|
||||||
cherrypy.server.ssl_module = 'builtin'
|
|
||||||
cherrypy.server.ssl_certificate = cfg.sslcertfile
|
|
||||||
cherrypy.server.ssl_private_key = cfg.sslkeyfile
|
|
||||||
# Define socket parameters
|
|
||||||
cherrypy.config.update({'server.socket_host': cfg.socket_host,
|
|
||||||
'server.socket_port': cfg.socket_port,
|
|
||||||
})
|
|
||||||
# Select environment
|
|
||||||
cherrypy.config.update({'staging':
|
|
||||||
{
|
|
||||||
'environment' : 'production'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
# Start CherryPy
|
# Start CherryPy
|
||||||
cherrypy.tree.mount(app, config=app_conf)
|
cherrypy.tree.mount(app, config=app_conf)
|
||||||
if setupenv.is_root():
|
if setupenv.is_root():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user