2020-08-13 14:38:36 +00:00
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import tornado.web
|
|
|
|
import tornado.escape
|
|
|
|
import bleach
|
|
|
|
|
|
|
|
from app.classes.shared.console import console
|
2020-08-17 02:47:53 +00:00
|
|
|
from app.classes.shared.models import Users, installer
|
2020-08-13 14:38:36 +00:00
|
|
|
from app.classes.web.base_handler import BaseHandler
|
2020-08-31 17:46:25 +00:00
|
|
|
from app.classes.shared.controller import controller
|
2020-08-19 01:04:43 +00:00
|
|
|
from app.classes.shared.models import db_helper
|
2020-08-28 18:38:42 +00:00
|
|
|
from app.classes.shared.helpers import helper
|
2020-08-19 01:04:43 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2020-08-17 02:47:53 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
class PanelHandler(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 = "panel/denied.html"
|
|
|
|
|
2020-08-24 17:08:17 +00:00
|
|
|
defined_servers = controller.list_defined_servers()
|
2020-08-19 01:04:43 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
page_data = {
|
|
|
|
'version_data': "version_data_here",
|
2020-08-19 01:04:43 +00:00
|
|
|
'user_data': user_data,
|
|
|
|
'server_stats': {
|
2020-08-24 17:08:17 +00:00
|
|
|
'total': len(defined_servers),
|
2020-08-19 01:04:43 +00:00
|
|
|
'running': len(controller.list_running_servers()),
|
|
|
|
'stopped': (len(controller.list_defined_servers()) - len(controller.list_running_servers()))
|
|
|
|
},
|
2020-08-24 17:08:17 +00:00
|
|
|
'menu_servers': defined_servers,
|
2020-08-28 18:38:42 +00:00
|
|
|
'hosts_data': db_helper.get_latest_hosts_stats(),
|
|
|
|
'show_contribute': helper.get_setting("show_contribute_link", True)
|
2020-08-13 14:38:36 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 17:21:19 +00:00
|
|
|
# if no servers defined, let's go to the build server area
|
|
|
|
if page_data['server_stats']['total'] == 0:
|
2020-08-19 17:54:10 +00:00
|
|
|
self.set_status(301)
|
|
|
|
self.redirect("/server/step1")
|
2020-08-24 02:17:36 +00:00
|
|
|
return False
|
2020-08-17 02:47:53 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
if page == 'unauthorized':
|
|
|
|
template = "panel/denied.html"
|
|
|
|
|
2020-08-28 03:21:55 +00:00
|
|
|
elif page == 'credits':
|
|
|
|
template = "panel/credits.html"
|
|
|
|
|
2020-08-28 18:38:42 +00:00
|
|
|
elif page == 'contribute':
|
|
|
|
template = "panel/contribute.html"
|
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
elif page == 'dashboard':
|
2020-08-24 17:08:17 +00:00
|
|
|
page_data['servers'] = db_helper.get_all_servers_stats()
|
2020-08-27 22:30:56 +00:00
|
|
|
|
2020-08-24 23:11:17 +00:00
|
|
|
for s in page_data['servers']:
|
|
|
|
try:
|
|
|
|
data = json.loads(s['int_ping_results'])
|
|
|
|
s['int_ping_results'] = data
|
|
|
|
except:
|
|
|
|
pass
|
2020-08-28 03:21:55 +00:00
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
template = "panel/dashboard.html"
|
|
|
|
|
2020-08-31 17:46:25 +00:00
|
|
|
elif page == 'server_detail':
|
|
|
|
|
|
|
|
template = "panel/server_details.html"
|
|
|
|
|
|
|
|
|
2020-08-13 14:38:36 +00:00
|
|
|
self.render(
|
|
|
|
template,
|
|
|
|
data=page_data
|
2020-08-24 17:08:17 +00:00
|
|
|
)
|