diff --git a/app/classes/web/default_handler.py b/app/classes/web/default_handler.py index 14955ec2..5cc0b69c 100644 --- a/app/classes/web/default_handler.py +++ b/app/classes/web/default_handler.py @@ -7,17 +7,8 @@ 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) + # Override prepare() instead of get() to cover all possible HTTP methods. + def prepare(self): + self.set_status(404) + self.render("public/404.html") diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 1058cde2..c9131aed 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -39,8 +39,8 @@ class PanelHandler(BaseHandler): # 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 + self.set_status(301) + self.redirect("/server/step1") if page == 'unauthorized': template = "panel/denied.html" diff --git a/app/classes/web/public_handler.py b/app/classes/web/public_handler.py index aeb19bec..4c5b2ab3 100644 --- a/app/classes/web/public_handler.py +++ b/app/classes/web/public_handler.py @@ -60,7 +60,7 @@ class PublicHandler(BaseHandler): # if we have no page, let's go to login else: - self.redirect("/public/login") + template = "public/404.html" self.render(template, data=page_data) diff --git a/app/classes/web/server_handler.py b/app/classes/web/server_handler.py new file mode 100644 index 00000000..91409210 --- /dev/null +++ b/app/classes/web/server_handler.py @@ -0,0 +1,46 @@ +import json +import logging +import tornado.web +import tornado.escape +import bleach + +from app.classes.shared.console import console +from app.classes.shared.models import Users, installer +from app.classes.web.base_handler import BaseHandler +from app.classes.minecraft.controller import controller +from app.classes.shared.models import db_helper + + +logger = logging.getLogger(__name__) + + +class ServerHandler(BaseHandler): + + @tornado.web.authenticated + def get(self, page): + # name = tornado.escape.json_decode(self.current_user) + user_data = json.loads(self.get_secure_cookie("user_data")) + + template = "public/404.html" + + + page_data = { + 'version_data': "version_data_here", + 'user_data': user_data, + 'server_stats': { + 'total': len(controller.list_defined_servers()), + 'running': len(controller.list_running_servers()), + 'stopped': (len(controller.list_defined_servers()) - len(controller.list_running_servers())) + }, + 'hosts_data': db_helper.get_latest_hosts_stats() + + } + # print(page_data['hosts_data']) + + print(page) + + + self.render( + template, + data=page_data + ) \ No newline at end of file diff --git a/app/classes/web/tornado.py b/app/classes/web/tornado.py index e58d0acf..ca29a8c1 100644 --- a/app/classes/web/tornado.py +++ b/app/classes/web/tornado.py @@ -21,6 +21,7 @@ try: from app.classes.web.public_handler import PublicHandler from app.classes.web.panel_handler import PanelHandler from app.classes.web.default_handler import DefaultHandler + from app.classes.web.server_handler import ServerHandler except ModuleNotFoundError as e: logger.critical("Import Error: Unable to load {} module".format(e, e.name)) @@ -121,6 +122,7 @@ class webserver: (r'/', DefaultHandler), (r'/public/(.*)', PublicHandler), (r'/panel/(.*)', PanelHandler), + (r'/server/(.*)', ServerHandler), ] app = tornado.web.Application( diff --git a/app/frontend/templates/panel/denied.html b/app/frontend/templates/panel/denied.html new file mode 100644 index 00000000..02a4933f --- /dev/null +++ b/app/frontend/templates/panel/denied.html @@ -0,0 +1,69 @@ + + +
+ + + +