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 %} {{ server['stats'][0]['world_name'] }} : {{ server['stats'][0]['world_size'] }} @@ -169,11 +175,16 @@ {% if server['stats'][0]['int_ping_results'] %} {{ server['stats'][0]['online'] }} / {{ server['stats'][0]['max'] }} Max
- {{ server['stats'][0]['desc'] }}
- {{ server['stats'][0]['version'] }} - {% else %} - {{ _("Unable to connect to server") }} + + {% if server['stats'][0]['desc'] != 'False' %} + {{ server['stats'][0]['desc'] }}
+ {% end %} + + {% if server['stats'][0]['version'] != 'False' %} + {{ server['stats'][0]['version'] }} + {% end %} {% end %} + {% if server['stats'][0]['running'] %} diff --git a/app/frontend/templates/panel/server_details.html b/app/frontend/templates/panel/server_details.html new file mode 100644 index 00000000..c3ddab33 --- /dev/null +++ b/app/frontend/templates/panel/server_details.html @@ -0,0 +1,56 @@ +{% extends ../base.html %} + +{% block meta %} + +{% end %} + +{% block title %}Crafty Controller - Blank Page{% end %} + +{% block content %} + +
+ + +
+
+ +
+ +
+ + +
+
+
+
+ + + + + +
+
+
+
+ + + + + +
+ + +{% end %} + +{% block js %} + + +{% end %} \ No newline at end of file diff --git a/main.py b/main.py index 8dbde21a..388f08ab 100644 --- a/main.py +++ b/main.py @@ -9,8 +9,8 @@ import logging.config from app.classes.shared.console import console from app.classes.shared.helpers import helper from app.classes.shared.models import installer -from app.classes.shared.tasks import tasks_manager -from app.classes.minecraft.controller import controller + +from app.classes.shared.controller import controller from app.classes.shared.cmd import MainPrompt @@ -54,7 +54,7 @@ def setup_logging(debug=False): """ Our Main Starter """ if __name__ == '__main__': - parser = argparse.ArgumentParser("Crafty Commander - A Server Management System") + parser = argparse.ArgumentParser("Crafty Controller - A Server Management System") parser.add_argument('-i', '--ignore', action='store_true', @@ -78,20 +78,23 @@ if __name__ == '__main__': # print our pretty start message do_intro() - # our session file, helps prevent multiple commander agents on the same machine. + # our session file, helps prevent multiple controller agents on the same machine. helper.create_session_file(ignore=args.ignore) + # do our installer stuff + if not installer.is_fresh_install(): + installer.create_tables() + installer.default_settings() + + # now the tables are created, we can load the tasks_manger + from app.classes.shared.tasks import tasks_manager + tasks_manager.start_webserver() tasks_manager.start_scheduler() # slowing down reporting just for a 1/2 second so messages look cleaner time.sleep(.5) - # do our installer stuff - if installer.is_fresh_install(): - installer.create_tables() - installer.default_settings() - # init servers logger.info("Initializing all servers defined") console.info("Initializing all servers defined")