diff --git a/app/classes/minecraft/serverjars.py b/app/classes/minecraft/serverjars.py index d1ae73de..82604edf 100644 --- a/app/classes/minecraft/serverjars.py +++ b/app/classes/minecraft/serverjars.py @@ -9,7 +9,7 @@ from datetime import datetime from app.classes.shared.helpers import helper from app.classes.shared.console import console from app.classes.shared.models import Servers -from app.classes.minecraft.controller import controller +from app.classes.shared.controller import controller from app.classes.minecraft.server_props import ServerProps logger = logging.getLogger(__name__) diff --git a/app/classes/minecraft/stats.py b/app/classes/minecraft/stats.py index c6dc59c2..fc983fe7 100644 --- a/app/classes/minecraft/stats.py +++ b/app/classes/minecraft/stats.py @@ -8,7 +8,7 @@ import datetime from app.classes.shared.helpers import helper from app.classes.minecraft.mc_ping import ping -from app.classes.minecraft.controller import controller +from app.classes.shared.controller import controller from app.classes.shared.models import Host_Stats, Server_Stats logger = logging.getLogger(__name__) @@ -161,7 +161,7 @@ class Stats: server_id = s.get('server_id', None) - logger.info('Getting stats for server: {}'.format(server_id)) + logger.debug('Getting stats for server: {}'.format(server_id)) # get our server object, settings and data dictionaries server_obj = s.get('server_obj', None) diff --git a/app/classes/minecraft/controller.py b/app/classes/shared/controller.py similarity index 100% rename from app/classes/minecraft/controller.py rename to app/classes/shared/controller.py diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index 98b089b0..53cfc3da 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -236,7 +236,7 @@ class Helpers: data = json.loads(file_data) pid = data.get('pid') started = data.get('started') - console.critical("Another commander agent seems to be running...\npid: {} \nstarted on: {}".format(pid, started)) + console.critical("Another Crafty Controller agent seems to be running...\npid: {} \nstarted on: {}".format(pid, started)) except Exception as e: pass diff --git a/app/classes/shared/models.py b/app/classes/shared/models.py index 542c5a64..e6353a14 100644 --- a/app/classes/shared/models.py +++ b/app/classes/shared/models.py @@ -28,8 +28,6 @@ class BaseModel(Model): class Meta: database = database -# todo: access logs - class Users(BaseModel): user_id = AutoField() @@ -112,6 +110,7 @@ class Commands(BaseModel): user = ForeignKeyField(Users, backref='user') source_ip = CharField(default='127.0.0.1') command = CharField(default='') + executed = BooleanField(default=False) class Meta: table_name = "commands" @@ -205,10 +204,14 @@ class db_shortcuts: # print(server_data) return server_data - def get_latest_hosts_stats(self): + @staticmethod + def get_latest_hosts_stats(): query = Host_Stats.select().order_by(Host_Stats.id.desc()).get() return model_to_dict(query) + def get_unactioned_commands(self): + query = Commands.select().where(Commands.executed == False) + return self.return_rows(query) installer = db_builder() db_helper = db_shortcuts() diff --git a/app/classes/shared/tasks.py b/app/classes/shared/tasks.py index e85bee38..ec950dcf 100644 --- a/app/classes/shared/tasks.py +++ b/app/classes/shared/tasks.py @@ -8,10 +8,11 @@ import threading from app.classes.shared.helpers import helper from app.classes.shared.console import console from app.classes.web.tornado import webserver -from app.classes.minecraft import server_props + from app.classes.minecraft.stats import stats -from app.classes.minecraft.controller import controller +from app.classes.shared.controller import controller from app.classes.minecraft.serverjars import server_jar_obj +from app.classes.shared.models import db_helper logger = logging.getLogger(__name__) @@ -34,6 +35,9 @@ class TasksManager: self.schedule_thread = threading.Thread(target=self.scheduler_thread, daemon=True, name="scheduler") + self.command_thread = threading.Thread(target=self.command_watcher, daemon=True, name="command_watcher") + self.command_thread.start() + def get_main_thread_run_status(self): return self.main_thread_exiting @@ -47,6 +51,16 @@ class TasksManager: self._main_graceful_exit() time.sleep(5) + def command_watcher(self): + while True: + # select any commands waiting to be processed + commands = db_helper.get_unactioned_commands() + + time.sleep(1) + + # def parse_command(self, command): + + def _main_graceful_exit(self): try: os.remove(helper.session_file) diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 1cf307aa..706a9658 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -7,7 +7,7 @@ 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.controller import controller from app.classes.shared.models import db_helper from app.classes.shared.helpers import helper @@ -65,6 +65,11 @@ class PanelHandler(BaseHandler): template = "panel/dashboard.html" + elif page == 'server_detail': + + template = "panel/server_details.html" + + self.render( template, data=page_data diff --git a/app/classes/web/server_handler.py b/app/classes/web/server_handler.py index 7306eb6d..9ec0ec62 100644 --- a/app/classes/web/server_handler.py +++ b/app/classes/web/server_handler.py @@ -4,7 +4,7 @@ import logging from app.classes.shared.console import console from app.classes.web.base_handler import BaseHandler -from app.classes.minecraft.controller import controller +from app.classes.shared.controller import controller from app.classes.shared.models import db_helper, Servers from app.classes.minecraft.serverjars import server_jar_obj from app.classes.minecraft.stats import stats diff --git a/app/frontend/templates/panel/dashboard.html b/app/frontend/templates/panel/dashboard.html index 7db509c6..c7fef96a 100644 --- a/app/frontend/templates/panel/dashboard.html +++ b/app/frontend/templates/panel/dashboard.html @@ -161,7 +161,13 @@ {% end %} " role="progressbar" style="width: {{server['stats'][0]['mem_percent']}}%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"> - {{server['stats'][0]['mem_percent']}}% - {{server['stats'][0]['mem']}} + {{server['stats'][0]['mem_percent']}}% - + + {% if server['stats'][0]['mem'] == 0 %} + 0 MB + {% else %} + {{server['stats'][0]['mem']}} + {% end %}