mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Creation of Command model, moved controler to shared in prep for plugins
This commit is contained in:
parent
79532ffc6b
commit
d6c894c3d9
@ -9,7 +9,7 @@ from datetime import datetime
|
|||||||
from app.classes.shared.helpers import helper
|
from app.classes.shared.helpers import helper
|
||||||
from app.classes.shared.console import console
|
from app.classes.shared.console import console
|
||||||
from app.classes.shared.models import Servers
|
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
|
from app.classes.minecraft.server_props import ServerProps
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -8,7 +8,7 @@ import datetime
|
|||||||
|
|
||||||
from app.classes.shared.helpers import helper
|
from app.classes.shared.helpers import helper
|
||||||
from app.classes.minecraft.mc_ping import ping
|
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
|
from app.classes.shared.models import Host_Stats, Server_Stats
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -161,7 +161,7 @@ class Stats:
|
|||||||
|
|
||||||
server_id = s.get('server_id', None)
|
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
|
# get our server object, settings and data dictionaries
|
||||||
server_obj = s.get('server_obj', None)
|
server_obj = s.get('server_obj', None)
|
||||||
|
@ -236,7 +236,7 @@ class Helpers:
|
|||||||
data = json.loads(file_data)
|
data = json.loads(file_data)
|
||||||
pid = data.get('pid')
|
pid = data.get('pid')
|
||||||
started = data.get('started')
|
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:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -28,8 +28,6 @@ class BaseModel(Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
database = database
|
database = database
|
||||||
|
|
||||||
# todo: access logs
|
|
||||||
|
|
||||||
|
|
||||||
class Users(BaseModel):
|
class Users(BaseModel):
|
||||||
user_id = AutoField()
|
user_id = AutoField()
|
||||||
@ -112,6 +110,7 @@ class Commands(BaseModel):
|
|||||||
user = ForeignKeyField(Users, backref='user')
|
user = ForeignKeyField(Users, backref='user')
|
||||||
source_ip = CharField(default='127.0.0.1')
|
source_ip = CharField(default='127.0.0.1')
|
||||||
command = CharField(default='')
|
command = CharField(default='')
|
||||||
|
executed = BooleanField(default=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
table_name = "commands"
|
table_name = "commands"
|
||||||
@ -205,10 +204,14 @@ class db_shortcuts:
|
|||||||
# print(server_data)
|
# print(server_data)
|
||||||
return 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()
|
query = Host_Stats.select().order_by(Host_Stats.id.desc()).get()
|
||||||
return model_to_dict(query)
|
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()
|
installer = db_builder()
|
||||||
db_helper = db_shortcuts()
|
db_helper = db_shortcuts()
|
||||||
|
@ -8,10 +8,11 @@ import threading
|
|||||||
from app.classes.shared.helpers import helper
|
from app.classes.shared.helpers import helper
|
||||||
from app.classes.shared.console import console
|
from app.classes.shared.console import console
|
||||||
from app.classes.web.tornado import webserver
|
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.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.minecraft.serverjars import server_jar_obj
|
||||||
|
from app.classes.shared.models import db_helper
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -34,6 +35,9 @@ class TasksManager:
|
|||||||
|
|
||||||
self.schedule_thread = threading.Thread(target=self.scheduler_thread, daemon=True, name="scheduler")
|
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):
|
def get_main_thread_run_status(self):
|
||||||
return self.main_thread_exiting
|
return self.main_thread_exiting
|
||||||
|
|
||||||
@ -47,6 +51,16 @@ class TasksManager:
|
|||||||
self._main_graceful_exit()
|
self._main_graceful_exit()
|
||||||
time.sleep(5)
|
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):
|
def _main_graceful_exit(self):
|
||||||
try:
|
try:
|
||||||
os.remove(helper.session_file)
|
os.remove(helper.session_file)
|
||||||
|
@ -7,7 +7,7 @@ import bleach
|
|||||||
from app.classes.shared.console import console
|
from app.classes.shared.console import console
|
||||||
from app.classes.shared.models import Users, installer
|
from app.classes.shared.models import Users, installer
|
||||||
from app.classes.web.base_handler import BaseHandler
|
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.models import db_helper
|
||||||
from app.classes.shared.helpers import helper
|
from app.classes.shared.helpers import helper
|
||||||
|
|
||||||
@ -65,6 +65,11 @@ class PanelHandler(BaseHandler):
|
|||||||
|
|
||||||
template = "panel/dashboard.html"
|
template = "panel/dashboard.html"
|
||||||
|
|
||||||
|
elif page == 'server_detail':
|
||||||
|
|
||||||
|
template = "panel/server_details.html"
|
||||||
|
|
||||||
|
|
||||||
self.render(
|
self.render(
|
||||||
template,
|
template,
|
||||||
data=page_data
|
data=page_data
|
||||||
|
@ -4,7 +4,7 @@ import logging
|
|||||||
|
|
||||||
from app.classes.shared.console import console
|
from app.classes.shared.console import console
|
||||||
from app.classes.web.base_handler import BaseHandler
|
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.shared.models import db_helper, Servers
|
||||||
from app.classes.minecraft.serverjars import server_jar_obj
|
from app.classes.minecraft.serverjars import server_jar_obj
|
||||||
from app.classes.minecraft.stats import stats
|
from app.classes.minecraft.stats import stats
|
||||||
|
@ -161,7 +161,13 @@
|
|||||||
{% end %}
|
{% end %}
|
||||||
" role="progressbar" style="width: {{server['stats'][0]['mem_percent']}}%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
|
" role="progressbar" style="width: {{server['stats'][0]['mem_percent']}}%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
|
||||||
</div>
|
</div>
|
||||||
{{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 %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ server['stats'][0]['world_name'] }} : {{ server['stats'][0]['world_size'] }}
|
{{ server['stats'][0]['world_name'] }} : {{ server['stats'][0]['world_size'] }}
|
||||||
@ -169,11 +175,16 @@
|
|||||||
<td>
|
<td>
|
||||||
{% if server['stats'][0]['int_ping_results'] %}
|
{% if server['stats'][0]['int_ping_results'] %}
|
||||||
{{ server['stats'][0]['online'] }} / {{ server['stats'][0]['max'] }} Max<br />
|
{{ server['stats'][0]['online'] }} / {{ server['stats'][0]['max'] }} Max<br />
|
||||||
{{ server['stats'][0]['desc'] }} <br />
|
|
||||||
{{ server['stats'][0]['version'] }}
|
{% if server['stats'][0]['desc'] != 'False' %}
|
||||||
{% else %}
|
{{ server['stats'][0]['desc'] }} <br />
|
||||||
{{ _("Unable to connect to server") }}
|
{% end %}
|
||||||
|
|
||||||
|
{% if server['stats'][0]['version'] != 'False' %}
|
||||||
|
{{ server['stats'][0]['version'] }}
|
||||||
|
{% end %}
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if server['stats'][0]['running'] %}
|
{% if server['stats'][0]['running'] %}
|
||||||
|
56
app/frontend/templates/panel/server_details.html
Normal file
56
app/frontend/templates/panel/server_details.html
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
{% extends ../base.html %}
|
||||||
|
|
||||||
|
{% block meta %}
|
||||||
|
<!-- <meta http-equiv="refresh" content="60">-->
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
{% block title %}Crafty Controller - Blank Page{% end %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="content-wrapper">
|
||||||
|
|
||||||
|
<!-- Page Title Header Starts-->
|
||||||
|
<div class="row page-title-header">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="page-header">
|
||||||
|
<h4 class="page-title">Dashboard</h4>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!-- Page Title Header Ends-->
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 grid-margin">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!-- content-wrapper ends -->
|
||||||
|
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<script>
|
||||||
|
|
||||||
|
$( document ).ready(function() {
|
||||||
|
console.log('ready for JS!')
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% end %}
|
21
main.py
21
main.py
@ -9,8 +9,8 @@ import logging.config
|
|||||||
from app.classes.shared.console import console
|
from app.classes.shared.console import console
|
||||||
from app.classes.shared.helpers import helper
|
from app.classes.shared.helpers import helper
|
||||||
from app.classes.shared.models import installer
|
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
|
from app.classes.shared.cmd import MainPrompt
|
||||||
|
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ def setup_logging(debug=False):
|
|||||||
""" Our Main Starter """
|
""" Our Main Starter """
|
||||||
if __name__ == '__main__':
|
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',
|
parser.add_argument('-i', '--ignore',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -78,20 +78,23 @@ if __name__ == '__main__':
|
|||||||
# print our pretty start message
|
# print our pretty start message
|
||||||
do_intro()
|
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)
|
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_webserver()
|
||||||
tasks_manager.start_scheduler()
|
tasks_manager.start_scheduler()
|
||||||
|
|
||||||
# slowing down reporting just for a 1/2 second so messages look cleaner
|
# slowing down reporting just for a 1/2 second so messages look cleaner
|
||||||
time.sleep(.5)
|
time.sleep(.5)
|
||||||
|
|
||||||
# do our installer stuff
|
|
||||||
if installer.is_fresh_install():
|
|
||||||
installer.create_tables()
|
|
||||||
installer.default_settings()
|
|
||||||
|
|
||||||
# init servers
|
# init servers
|
||||||
logger.info("Initializing all servers defined")
|
logger.info("Initializing all servers defined")
|
||||||
console.info("Initializing all servers defined")
|
console.info("Initializing all servers defined")
|
||||||
|
Loading…
Reference in New Issue
Block a user