diff --git a/app/classes/minecraft/stats.py b/app/classes/minecraft/stats.py index fc983fe7..305239e8 100644 --- a/app/classes/minecraft/stats.py +++ b/app/classes/minecraft/stats.py @@ -250,7 +250,7 @@ class Stats: Server_Stats.version: server.get("version", False) }).execute() - # delete 1 week old data + # delete old data max_age = helper.get_setting("history_max_age") now = datetime.datetime.now() last_week = now.day - max_age diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index 602ee8ab..89b7ad5d 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -13,11 +13,13 @@ import logging from datetime import datetime from socket import gethostname + from app.classes.shared.console import console logger = logging.getLogger(__name__) try: + import requests from OpenSSL import crypto from argon2 import PasswordHasher @@ -96,6 +98,21 @@ class Helpers: return version_data + @staticmethod + def get_announcements(): + r = requests.get('https://craftycontrol.com/notify.json', timeout=2) + data = '[{"id":"1","date":"Unknown","title":"Error getting Announcements","desc":"Error getting ' \ + 'Announcements","link":""}] ' + + if r.status_code in [200, 201]: + try: + data = json.loads(r.content) + except: + pass + + return data + + def get_version_string(self): version_data = self.get_version() diff --git a/app/classes/shared/models.py b/app/classes/shared/models.py index 12bbfd11..a74bc7af 100644 --- a/app/classes/shared/models.py +++ b/app/classes/shared/models.py @@ -43,6 +43,7 @@ class Users(BaseModel): class Meta: table_name = "users" + class Audit_Log(BaseModel): audit_id = AutoField() created = DateTimeField(default=datetime.datetime.now) @@ -53,7 +54,6 @@ class Audit_Log(BaseModel): log_msg = TextField(default='') - class Host_Stats(BaseModel): time = DateTimeField(default=datetime.datetime.now) boot_time = CharField(default="") @@ -83,6 +83,7 @@ class Servers(BaseModel): auto_start_delay = IntegerField(default=10) crash_detection = BooleanField(default=0) stop_command = CharField(default="stop") + server_ip = CharField(default="127.0.0.1") server_port = IntegerField(default=25565) class Meta: @@ -166,7 +167,8 @@ class db_builder: @staticmethod def default_settings(): - + logger.info("Fresh Install Detected - Creating Default Settings") + console.info("Fresh Install Detected - Creating Default Settings") default_data = helper.find_default_password() username = default_data.get("username", 'admin') @@ -174,7 +176,7 @@ class db_builder: api_token = helper.random_string_generator(32) Users.insert({ - Users.username: username, + Users.username: username.lower(), Users.password: helper.encode_pass(password), Users.api_token: api_token, Users.enabled: True @@ -184,9 +186,12 @@ class db_builder: @staticmethod def is_fresh_install(): - if helper.check_file_exists(helper.db_path): + try: + user = Users.get_by_id(1) return False - return True + except: + return True + pass class db_shortcuts: diff --git a/app/classes/web/ajax_handler.py b/app/classes/web/ajax_handler.py index 0591ecf7..03641140 100644 --- a/app/classes/web/ajax_handler.py +++ b/app/classes/web/ajax_handler.py @@ -74,4 +74,31 @@ class AjaxHandler(BaseHandler): logger.warning("Skipping Log Line due to error: {}".format(e)) pass + elif page == "announcements": + data = helper.get_announcements() + page_data['notify_data'] = data + self.render_page('ajax/notify.html', page_data) + + + def post(self, page): + user_data = json.loads(self.get_secure_cookie("user_data")) + error = bleach.clean(self.get_argument('error', "WTF Error!")) + + page_data = { + 'user_data': user_data, + 'error': error + } + + if page == "send_command": + command = bleach.clean(self.get_body_argument('command', default=None, strip=True)) + server_id = bleach.clean(self.get_argument('id')) + + if server_id is None: + logger.warning("Server ID not found in send_command ajax call") + + srv_obj = controller.get_server_obj(server_id) + + if command: + if srv_obj.check_running(): + srv_obj.send_command(command) diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index e4a3460a..7bd323bd 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -26,6 +26,8 @@ class PanelHandler(BaseHandler): defined_servers = controller.list_defined_servers() page_data = { + # todo: make this actually pull and compare version data + 'update_available': False, 'version_data': helper.get_version_string(), 'user_data': user_data, 'server_stats': { @@ -128,6 +130,7 @@ class PanelHandler(BaseHandler): execution_command = self.get_argument('execution_command', None) stop_command = self.get_argument('stop_command', None) auto_start_delay = self.get_argument('auto_start_delay', '10') + server_ip = self.get_argument('server_ip', None) server_port = self.get_argument('server_port', None) auto_start = int(float(self.get_argument('auto_start', '0'))) crash_detection = int(float(self.get_argument('crash_detection', '0'))) @@ -152,6 +155,7 @@ class PanelHandler(BaseHandler): Servers.execution_command: execution_command, Servers.stop_command: stop_command, Servers.auto_start_delay: auto_start_delay, + Servers.server_ip: server_ip, Servers.server_port: server_port, Servers.auto_start: auto_start, Servers.crash_detection: crash_detection, diff --git a/app/classes/web/public_handler.py b/app/classes/web/public_handler.py index 14320121..34356510 100644 --- a/app/classes/web/public_handler.py +++ b/app/classes/web/public_handler.py @@ -95,10 +95,10 @@ class PublicHandler(BaseHandler): logger.info("User: {} Logged in from IP: {}".format(user_data, self.get_remote_ip())) # record this login - Users.update({ - Users.last_ip: self.get_remote_ip(), - Users.last_login: helper.get_time_as_string() - }).where(Users.username == entered_username).execute() + q = Users.select().where(Users.username == entered_username.lower()).get() + q.last_ip = self.get_remote_ip() + q.last_login = helper.get_time_as_string() + q.save() # log this login db_helper.add_to_audit_log(user_data.user_id, "Logged in", 0, self.get_remote_ip()) diff --git a/app/classes/web/server_handler.py b/app/classes/web/server_handler.py index 08436cad..f368fec1 100644 --- a/app/classes/web/server_handler.py +++ b/app/classes/web/server_handler.py @@ -36,7 +36,7 @@ class ServerHandler(BaseHandler): defined_servers = controller.list_defined_servers() page_data = { - 'version_data': "version_data_here", + 'version_data': helper.get_version_string(), 'user_data': user_data, 'server_stats': { 'total': len(controller.list_defined_servers()), diff --git a/app/config/serverjars.json b/app/config/serverjars.json index 45343a2c..736bef8a 100644 --- a/app/config/serverjars.json +++ b/app/config/serverjars.json @@ -1,5 +1,5 @@ { - "last_refreshed": "09/17/2020, 18:43:17", + "last_refreshed": "09/21/2020, 21:59:31", "servers": { "nukkitx": [ "1.14" diff --git a/app/frontend/templates/ajax/notify.html b/app/frontend/templates/ajax/notify.html new file mode 100644 index 00000000..90683da6 --- /dev/null +++ b/app/frontend/templates/ajax/notify.html @@ -0,0 +1,14 @@ +{% for item in data['notify_data'] %} + +
+

{{ item['title'] }}

+ +
{{ item['date'] }}
+ {{ item['desc'] }} +
+
+ + + +{% end %} + diff --git a/app/frontend/templates/base.html b/app/frontend/templates/base.html index c8f2b1fa..afe50031 100644 --- a/app/frontend/templates/base.html +++ b/app/frontend/templates/base.html @@ -44,30 +44,6 @@ - {% include notify.html %} @@ -111,6 +87,20 @@ $(function () { $('[data-toggle="tooltip"]').tooltip() }) + + + $(document).ready(function(){ + $("#notificationDropdown").click(function(){ + $.get("/ajax/announcements", function(data){ + console.log(data); + bootbox.alert({ + title: "Notifications", + message: data, + + }); + }); + }); + }); {% block js %} diff --git a/app/frontend/templates/footer.html b/app/frontend/templates/footer.html index 03c4cfab..fe371681 100644 --- a/app/frontend/templates/footer.html +++ b/app/frontend/templates/footer.html @@ -1,8 +1,11 @@ \ No newline at end of file diff --git a/app/frontend/templates/main_menu.html b/app/frontend/templates/main_menu.html index b08fbc67..8e6b6d97 100644 --- a/app/frontend/templates/main_menu.html +++ b/app/frontend/templates/main_menu.html @@ -33,43 +33,16 @@ -