finished redirect woes, adding server handler, made 404 and default pages pretty

This commit is contained in:
Phillip Tarrant 2020-08-19 13:54:10 -04:00
parent 81d5ff05e8
commit a6c1a885d6
8 changed files with 140 additions and 18 deletions

View File

@ -7,17 +7,8 @@ logger = logging.getLogger(__name__)
class DefaultHandler(BaseHandler): class DefaultHandler(BaseHandler):
def get(self, page=None): # Override prepare() instead of get() to cover all possible HTTP methods.
def prepare(self):
# sensible defaults self.set_status(404)
template = "public/404.html" self.render("public/404.html")
self.render(template)
def post(self, page=None):
# sensible defaults
template = "public/404.html"
self.render(template)

View File

@ -39,8 +39,8 @@ class PanelHandler(BaseHandler):
# if no servers defined, let's go to the build server area # if no servers defined, let's go to the build server area
if page_data['server_stats']['total'] == 0: if page_data['server_stats']['total'] == 0:
self.redirect("server/step1") self.set_status(301)
return False self.redirect("/server/step1")
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") template = "public/404.html"
self.render(template, data=page_data) self.render(template, data=page_data)

View File

@ -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
)

View File

@ -21,6 +21,7 @@ try:
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 from app.classes.web.default_handler import DefaultHandler
from app.classes.web.server_handler import ServerHandler
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))
@ -121,6 +122,7 @@ class webserver:
(r'/', DefaultHandler), (r'/', DefaultHandler),
(r'/public/(.*)', PublicHandler), (r'/public/(.*)', PublicHandler),
(r'/panel/(.*)', PanelHandler), (r'/panel/(.*)', PanelHandler),
(r'/server/(.*)', ServerHandler),
] ]
app = tornado.web.Application( app = tornado.web.Application(

View File

@ -0,0 +1,69 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Crafty Commander</title>
<!-- plugins:css -->
<link rel="stylesheet" href="/static/assets/vendors/mdi/css/materialdesignicons.min.css">
<link rel="stylesheet" href="/static/assets/vendors/flag-icon-css/css/flag-icon.min.css">
<link rel="stylesheet" href="/static/assets/vendors/ti-icons/css/themify-icons.css">
<link rel="stylesheet" href="/static/assets/vendors/typicons/typicons.css">
<link rel="stylesheet" href="/static/assets/vendors/css/vendor.bundle.base.css">
<!-- endinject -->
<!-- Plugin css for this page -->
<!-- End Plugin css for this page -->
<!-- Layout styles -->
<link rel="stylesheet" href="/static/assets/css/dark/style.css">
<!-- End Layout styles -->
<link rel="shortcut icon" href="/static/assets/images/favicon.png" />
</head>
<body class="dark-theme">
<div class="container-scroller">
<div class="container-fluid page-body-wrapper full-page-wrapper">
<div class="content-wrapper d-flex align-items-center auth auth-bg-1 theme-one">
<div class="row w-100">
<div class="col-lg-4 mx-auto">
<div class="auto-form-wrapper">
<div class="text-center">
<img src="/static/assets/images/logo_long.jpg"><br /><br />
<div class="col-sm-12 grid-margin stretch-card">
<div class="card card-statistics social-card google-card card-colored">
<div class="card-body">
<h4 class="platform-name mb-3 mt-4 font-weight-semibold user-name">Access Denied</h4>
<h5 class="headline font-weight-medium">You do not have access to this resource</h5>
<p class="mb-2 comment font-weight-light">
Contact your server administrator for access to this resource, or if you think you should have access
to this resource, contact support.<br /><br />
<a class="d-inline font-weight-medium" href="https://discord.gg/9VJPhCE"> Contact Crafty Control Support via Discord</a>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- content-wrapper ends -->
</div>
<!-- page-body-wrapper ends -->
</div>
<!-- container-scroller -->
<!-- plugins:js -->
<script src="/static/assets/vendors/js/vendor.bundle.base.js"></script>
<!-- endinject -->
<!-- inject:js -->
<script src="/static/assets/js/shared/off-canvas.js"></script>
<script src="/static/assets/js/shared/hoverable-collapse.js"></script>
<script src="/static/assets/js/shared/misc.js"></script>
<script src="/static/assets/js/shared/settings.js"></script>
<script src="/static/assets/js/shared/todolist.js"></script>
<!-- endinject -->
</body>
</html>

View File

@ -28,9 +28,22 @@
<div class="auto-form-wrapper"> <div class="auto-form-wrapper">
<div class="text-center"> <div class="text-center">
<img src="/static/assets/images/logo_long.jpg"> <img src="/static/assets/images/logo_long.jpg"><br /><br />
<div class="col-sm-12 grid-margin stretch-card">
<div class="card card-statistics social-card facebook-card card-colored">
<div class="card-body">
<h4 class="platform-name mb-3 mt-4 font-weight-semibold user-name">404</h4>
<h5 class="headline font-weight-medium">Page Not Found</h5>
<p class="mb-2 comment font-weight-light">
We were unable to find the page you are looking for. Please try again, or go back and refresh.
<br /><br />
<a class="d-inline font-weight-medium" href="https://discord.gg/9VJPhCE"> Contact Crafty Control Support via Discord</a>
</p>
</div>
</div>
</div> </div>
404 ! </div>
</div> </div>

View File

@ -0,0 +1 @@
Step 1