fixed endless redirect issue on non-existant paths

This commit is contained in:
Phillip Tarrant 2020-08-19 13:21:19 -04:00
parent de98e5727c
commit 81d5ff05e8
6 changed files with 31 additions and 6 deletions

View File

@ -27,7 +27,6 @@ class Controller:
self.servers_list = [] self.servers_list = []
servers = db_helper.get_all_defined_servers() servers = db_helper.get_all_defined_servers()
print(servers)
for s in servers: for s in servers:
settings_file = os.path.join(s['path'], 'server.properties') settings_file = os.path.join(s['path'], 'server.properties')

View File

@ -0,0 +1,23 @@
import logging
from app.classes.web.base_handler import BaseHandler
logger = logging.getLogger(__name__)
class DefaultHandler(BaseHandler):
def get(self, page=None):
# sensible defaults
template = "public/404.html"
self.render(template)
def post(self, page=None):
# sensible defaults
template = "public/404.html"
self.render(template)

View File

@ -35,8 +35,12 @@ class PanelHandler(BaseHandler):
'hosts_data': db_helper.get_latest_hosts_stats() 'hosts_data': db_helper.get_latest_hosts_stats()
} }
print(page_data['hosts_data']) # print(page_data['hosts_data'])
# if no servers defined, let's go to the build server area
if page_data['server_stats']['total'] == 0:
self.redirect("server/step1")
return False
if page == 'unauthorized': if page == 'unauthorized':
template = "panel/denied.html" template = "panel/denied.html"

View File

@ -60,7 +60,7 @@ class PublicHandler(BaseHandler):
# if we have no page, let's go to login # if we have no page, let's go to login
else: else:
self.redirect("public/login") self.redirect("/public/login")
self.render(template, data=page_data) self.render(template, data=page_data)

View File

@ -20,6 +20,7 @@ try:
import tornado.httpserver import tornado.httpserver
from app.classes.web.public_handler import PublicHandler from app.classes.web.public_handler import PublicHandler
from app.classes.web.panel_handler import PanelHandler from app.classes.web.panel_handler import PanelHandler
from app.classes.web.default_handler import DefaultHandler
except ModuleNotFoundError as e: except ModuleNotFoundError as e:
logger.critical("Import Error: Unable to load {} module".format(e, e.name)) logger.critical("Import Error: Unable to load {} module".format(e, e.name))
@ -117,7 +118,7 @@ class webserver:
tornado.locale.set_default_locale(lang) tornado.locale.set_default_locale(lang)
handlers = [ handlers = [
(r'/', PublicHandler), (r'/', DefaultHandler),
(r'/public/(.*)', PublicHandler), (r'/public/(.*)', PublicHandler),
(r'/panel/(.*)', PanelHandler), (r'/panel/(.*)', PanelHandler),
] ]

View File

@ -97,8 +97,6 @@ if __name__ == '__main__':
installer.create_tables() installer.create_tables()
installer.default_settings() installer.default_settings()
# installer.create_tables()
# init servers # init servers
logger.info("Initializing all servers defined") logger.info("Initializing all servers defined")
console.info("Initializing all servers defined") console.info("Initializing all servers defined")