Merge branch 'dev' into incident/log-file-issues

This commit is contained in:
Zedifus 2022-07-18 22:03:03 +01:00
commit 31fe66776c
16 changed files with 126 additions and 132 deletions

View File

@ -27,4 +27,3 @@ This checklist encourages us to confirm any changes have been analyzed to reduce
* [ ] Have you resolved any lint issues?
* [ ] Have you assigned a reviewer?
* [ ] Have you applied correct labels?
* [ ] Have you updated CHANGELOG.md?

View File

@ -1,9 +1,23 @@
# Changelog
## --- [4.0.6] - 2022/07/06
## --- [4.0.7] - 2022/07/18
### New features
- Task toggle (!398+)
- Basic API for modifying tasks (!398+)
- Task toggle ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/398))
- Basic API for modifying tasks ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/398))
- Toggle Visible servers on status page ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/399))
### Bug fixes
- Fixes stats recording for Oracle hosts ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/397))
- Improve the use of the object oriented architecture ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/400))
- Fix issue with API Server Instance is not serializable ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/401))
- Fix an issue where the motd were not displayed properly one small screens ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/402))
### Tweaks
- Remove server.props requirement ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/403))
- Add platform & crafty version info to support logs ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/405))
### Lang
None
<br><br>
## --- [4.0.6] - 2022/07/06
### Bug fixes
- Remove redundant path check on backup restore ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/390))
- Fix issue with stats pinging on slow starting servers ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/391))

View File

@ -14,7 +14,6 @@ from app.classes.shared.console import Console
from app.classes.shared.helpers import Helpers
from app.classes.shared.main_models import DatabaseShortcuts
from app.classes.minecraft.server_props import ServerProps
from app.classes.minecraft.stats import Stats
from app.classes.models.servers import HelperServers
@ -172,18 +171,6 @@ class ServersController(metaclass=Singleton):
)
continue
settings_file = os.path.join(
Helpers.get_os_understandable_path(server["path"]), "server.properties"
)
# if the properties file isn't there, let's warn
if not Helpers.check_file_exists(settings_file):
logger.error(f"Unable to find {settings_file}. Skipping this server.")
Console.error(f"Unable to find {settings_file}. Skipping this server.")
continue
settings = ServerProps(settings_file)
temp_server_dict = {
"server_id": server.get("server_id"),
"server_data_obj": server,
@ -194,7 +181,6 @@ class ServersController(metaclass=Singleton):
self.stats,
self.file_helper,
),
"server_settings": settings.props,
}
# setup the server, do the auto start and all that jazz
@ -351,14 +337,6 @@ class ServersController(metaclass=Singleton):
def get_server_friendly_name(server_id):
return HelperServers.get_server_friendly_name(server_id)
def get_server_settings(self, server_id):
for server in self.servers_list:
if int(server["server_id"]) == int(server_id):
return server["server_settings"]
logger.warning(f"Unable to find server object for server id {server_id}")
return False
def crash_detection(self, server_obj):
svr = self.get_server_instance_by_id(server_obj.server_id)
# start or stop crash detection depending upon user preference

View File

@ -1,66 +0,0 @@
import pprint
import os
class ServerProps:
def __init__(self, filepath):
self.filepath = filepath
self.props = self._parse()
def _parse(self):
# Loads and parses the file specified in self.filepath
with open(self.filepath, encoding="utf-8") as full_path:
line = full_path.readline()
dictionary = {}
if os.path.exists(".header"):
os.remove(".header")
while line:
if "#" != line[0]:
string = line
string1 = string[: string.find("=")]
if "\n" in string:
string2 = string[string.find("=") + 1 : string.find("\n")]
else:
string2 = string[string.find("=") + 1 :]
dictionary[string1] = string2
else:
with open(".header", "a+", encoding="utf-8") as header:
header.write(line)
line = full_path.readline()
return dictionary
def print(self):
# Prints the properties dictionary (using pprint)
pprint.pprint(self.props)
def get(self):
# Returns the properties dictionary
return self.props
def update(self, key, val):
# Updates property in the properties dictionary [ update("pvp", "true") ]
# and returns boolean condition
if key in self.props.keys():
self.props[key] = val
return True
return False
def save(self):
# Writes to the new file
with open(self.filepath, "a+", encoding="utf-8") as f:
f.truncate(0)
with open(".header", encoding="utf-8") as header:
line = header.readline()
while line:
f.write(line)
line = header.readline()
header.close()
for key, value in self.props.items():
f.write(key + "=" + value + "\n")
if os.path.exists(".header"):
os.remove(".header")
@staticmethod
def cleanup():
if os.path.exists(".header"):
os.remove(".header")

View File

@ -6,10 +6,10 @@ import datetime
import base64
import typing as t
from app.classes.shared.null_writer import NullWriter
from app.classes.minecraft.mc_ping import ping
from app.classes.models.management import HostStats
from app.classes.models.servers import HelperServers
from app.classes.shared.null_writer import NullWriter
from app.classes.shared.helpers import Helpers
with redirect_stderr(NullWriter()):
@ -87,7 +87,9 @@ class Stats:
try:
cpu_freq = psutil.cpu_freq()
except NotImplementedError:
cpu_freq = psutil._common.scpufreq(current=0, min=0, max=0)
cpu_freq = None
if cpu_freq is None:
cpu_freq = psutil._common.scpufreq(current=-1, min=-1, max=-1)
memory = psutil.virtual_memory()
try:
node_stats: NodeStatsDict = {
@ -224,11 +226,6 @@ class Stats:
logger.info(f"Getting players for server {server}")
# get our settings and data dictionaries
# server_settings = server.get('server_settings', {})
# server_data = server.get('server_data_obj', {})
# TODO: search server properties file for possible override of 127.0.0.1
internal_ip = server["server_ip"]
server_port = server["server_port"]

View File

@ -37,6 +37,7 @@ class Servers(BaseModel):
server_port = IntegerField(default=25565)
logs_delete_after = IntegerField(default=0)
type = CharField(default="minecraft-java")
show_status = BooleanField(default=1)
class Meta:
table_name = "servers"
@ -80,6 +81,7 @@ class HelperServers:
server_type: This is the type of server you're creating.
server_port: The port the server will be monitored on, defaults to 25565
server_host: The host the server will be monitored on, defaults to 127.0.0.1
show_status: Should Crafty show this server on the public status page
Returns:
int: The new server's id

View File

@ -1,6 +1,7 @@
import os
import pathlib
from pathlib import Path
import platform
import shutil
import time
import logging
@ -175,6 +176,19 @@ class Controller:
id="logs_" + str(exec_user["user_id"]),
args=[temp_dir, temp_zip_storage + ".zip", exec_user],
)
# Make version file .txt when we download it for support
# Most people have a default editor for .txt also more mobile friendly...
FileHelpers.copy_file(
os.path.join(self.project_root, "app", "config", "version.json"),
os.path.join(temp_dir, "crafty_sys_info.txt"),
)
with open(
os.path.join(temp_dir, "crafty_sys_info.txt"), "a", encoding="utf-8"
) as f:
f.write("\n")
f.write("OS Info:\n")
f.write("OS: " + str(platform.system()) + "\n")
f.write("Version: " + str(platform.release()))
FileHelpers.make_compressed_archive(temp_zip_storage, temp_dir)
if len(self.helper.websocket_helper.clients) > 0:
self.helper.websocket_helper.broadcast_user(

View File

@ -1244,7 +1244,6 @@ class ServerInstance:
# process stats
p_stats = Stats._try_get_process_stats(self.process, self.check_running())
# TODO: search server properties file for possible override of 127.0.0.1
internal_ip = server["server_ip"]
server_port = server["server_port"]
server_name = server.get("server_name", f"ID#{server_id}")
@ -1253,7 +1252,10 @@ class ServerInstance:
if HelperServers.get_server_type_by_id(server_id) == "minecraft-bedrock":
int_mc_ping = ping_bedrock(internal_ip, int(server_port))
else:
int_mc_ping = ping(internal_ip, int(server_port))
try:
int_mc_ping = ping(internal_ip, int(server_port))
except:
int_mc_ping = False
int_data = False
ping_data = {}
@ -1315,11 +1317,6 @@ class ServerInstance:
logger.info(f"Getting players for server {server}")
# get our settings and data dictionaries
# server_settings = server.get('server_settings', {})
# server_data = server.get('server_data_obj', {})
# TODO: search server properties file for possible override of 127.0.0.1
internal_ip = server["server_ip"]
server_port = server["server_port"]
@ -1377,9 +1374,6 @@ class ServerInstance:
# process stats
p_stats = Stats._try_get_process_stats(self.process, self.check_running())
# TODO: search server properties file for possible override of 127.0.0.1
# internal_ip = server['server_ip']
# server_port = server['server_port']
internal_ip = server_dt["server_ip"]
server_port = server_dt["server_port"]

View File

@ -10,6 +10,7 @@ from app.classes.models.users import ApiKeys
from app.classes.shared.helpers import Helpers
from app.classes.shared.main_controller import Controller
from app.classes.shared.translation import Translation
from app.classes.models.management import DatabaseShortcuts
logger = logging.getLogger(__name__)
@ -204,6 +205,10 @@ class BaseHandler(tornado.web.RequestHandler):
authorized_servers = self.controller.servers.get_authorized_servers(
user["user_id"] # TODO: API key authorized servers?
)
authorized_servers = [
DatabaseShortcuts.get_data_obj(x.server_object)
for x in authorized_servers
]
logger.debug("Checking results")
if user:

View File

@ -192,9 +192,9 @@ class PanelHandler(BaseHandler):
total_players = 0
for server in page_data["servers"]:
total_players += len(
self.controller.servers.stats.get_server_players(
self.controller.servers.get_server_instance_by_id(
server["server_data"]["server_id"]
)
).get_server_players()
)
page_data["num_players"] = total_players
@ -539,9 +539,7 @@ class PanelHandler(BaseHandler):
except Exception as e:
logger.error(f"Failed to get server waiting to start: {e}")
page_data["waiting_start"] = False
page_data[
"get_players"
] = lambda: self.controller.servers.stats.get_server_players(server_id)
page_data["get_players"] = server.get_server_players()
page_data["active_link"] = subpage
page_data["permissions"] = {
"Commands": EnumPermissionsServer.COMMANDS,
@ -877,9 +875,6 @@ class PanelHandler(BaseHandler):
page_data["schedules"] = HelpersManagement.get_schedules_by_server(
server_id
)
page_data[
"get_players"
] = lambda: self.controller.servers.stats.get_server_players(server_id)
page_data["active_link"] = "schedules"
page_data["permissions"] = {
"Commands": EnumPermissionsServer.COMMANDS,
@ -945,9 +940,6 @@ class PanelHandler(BaseHandler):
self.redirect("/panel/error?error=Invalid Schedule ID")
return
schedule = self.controller.management.get_scheduled_task_model(sch_id)
page_data[
"get_players"
] = lambda: self.controller.servers.stats.get_server_players(server_id)
page_data["active_link"] = "schedules"
page_data["permissions"] = {
"Commands": EnumPermissionsServer.COMMANDS,
@ -1384,6 +1376,7 @@ class PanelHandler(BaseHandler):
server_ip = self.get_argument("server_ip", None)
server_port = self.get_argument("server_port", None)
executable_update_url = self.get_argument("executable_update_url", None)
show_status = int(float(self.get_argument("show_status", "0")))
else:
execution_command = server_obj.execution_command
executable = server_obj.executable
@ -1461,6 +1454,7 @@ class PanelHandler(BaseHandler):
server_obj.server_ip = server_ip
server_obj.server_port = server_port
server_obj.executable_update_url = executable_update_url
server_obj.show_status = show_status
else:
server_obj.path = server_obj.path
server_obj.log_path = server_obj.log_path

View File

@ -21,6 +21,18 @@
display: block;
}
.toggle-handle {
background-color: white !important;
}
.toggle-on {
color: black !important;
}
.toggle {
height: 0px !important;
}
.sidebar>.nav>.nav-item:not(.nav-profile)>.nav-link:before {
content: none;
position: absolute;

View File

@ -73,7 +73,7 @@
</style>
<h2>{{ translate('serverPlayerManagement', 'players', data['lang']) }}:</h2>
<ul style="list-style: none;padding: 0px;margin: 0px; margin-bottom: 1rem;gap: 1rem;">
{% for player in data['get_players']() %}
{% for player in data['get_players'] %}
<li class="playerItem">
<h3>{{ player }}</h3>
<div class="buttons">

View File

@ -176,24 +176,35 @@
<div class="form-check-flat">
<label for="auto_start" class="form-check-label ml-4 mb-4">
{% if data['server_stats']['server_id']['auto_start'] %}
<input type="checkbox" class="form-check-input" id="auto_start" name="auto_start" checked=""
value="1">{{ translate('serverConfig', 'serverAutoStart', data['lang']) }}
<input type="checkbox" class="form-check-input" id="auto_start" name="auto_start" checked="" data-toggle="toggle"
value="1">&nbsp;&nbsp;{{ translate('serverConfig', 'serverAutoStart', data['lang']) }}
{% else %}
<input type="checkbox" class="form-check-input" id="auto_start" name="auto_start" value="1">{{
<input type="checkbox" class="form-check-input" id="auto_start" name="auto_start" value="1" data-toggle="toggle">&nbsp;&nbsp;{{
translate('serverConfig', 'serverAutoStart', data['lang']) }}
{% end %}
</label>
<label for="crash_detection" class="form-check-label ml-4 mb-4">
{% if data['server_stats']['server_id']['crash_detection'] %}
<input type="checkbox" class="form-check-input" id="crash_detection" name="crash_detection"
checked="" value="1">{{ translate('serverConfig', 'serverCrashDetection', data['lang']) }}
<input type="checkbox" class="form-check-input" id="crash_detection" name="crash_detection" data-toggle="toggle"
checked="" value="1">&nbsp;&nbsp;{{ translate('serverConfig', 'serverCrashDetection', data['lang']) }}
{% else %}
<input type="checkbox" class="form-check-input" id="crash_detection" name="crash_detection"
value="1">{{ translate('serverConfig', 'serverCrashDetection', data['lang']) }}
<input type="checkbox" class="form-check-input" id="crash_detection" name="crash_detection" data-toggle="toggle"
value="1">&nbsp;&nbsp;{{ translate('serverConfig', 'serverCrashDetection', data['lang']) }}
{% end %}
</label>
{% if data['super_user'] %}
<label for="show_status" class="form-check-label ml-4 mb-4">
{% if data['server_stats']['server_id']['show_status'] %}
<input type="checkbox" class="form-check-input" id="show_status" name="show_status" data-toggle="toggle"
checked="" value="1">&nbsp;&nbsp;{{ translate('serverConfig', 'showStatus', data['lang']) }}
{% else %}
<input type="checkbox" class="form-check-input" id="show_status" name="show_status" data-toggle="toggle"
value="1">&nbsp;&nbsp;{{ translate('serverConfig', 'showStatus', data['lang']) }}
{% end %}
</label>
{% end %}
</div>
<button type="submit" class="btn btn-success mr-2"><i class="fas fa-save"></i> {{
@ -243,13 +254,33 @@
</div>
<style>
.toggle-handle {
background-color: white !important;
}
.toggle-on {
color: black !important;
background-color: blueviolet !important;
}
.toggle {
height: 0px !important;
background-color: grey !important;
}
</style>
<!-- content-wrapper ends -->
{% end %}
{% block js %}
<script>
$(function() {
$('.form-check-input').bootstrapToggle({
on: '',
off: ''
});
})
const serverId = new URLSearchParams(document.location.search).get('id')

View File

@ -27,6 +27,7 @@
<span id="sync" style="margin-left: 5px;"><i class="fas fa-sync fa-spin"></i></span></h4>
{% end %}
{% for server in data['servers'] %}
{% if server['server_data']['show_status'] %}
<tr>
<td id="server_name_{{ server['stats']['server_id']['server_id'] }}">
<i class="fas fa-server"></i>
@ -71,6 +72,7 @@
</td>
</tr>
{% end %}
{% end %}
</tbody>
</table>
</div>
@ -125,7 +127,7 @@
<div class="media-body">
{% if server['stats']['desc'] != 'False' %}
<div id="m_server_motd_{{ server['stats']['server_id']['server_id'] }}">
<span id="input_motd_{{ server['stats']['server_id']['server_id'] }}" class="input_motd">{{
<span id="m_input_motd_{{ server['stats']['server_id']['server_id'] }}" class="input_motd">{{
server['stats']['desc'] }}</span> <br />
</div>
{% end %}
@ -143,6 +145,7 @@
<div id="m_server_motd_{{ server['stats']['server_id']['server_id'] }}">
<span class="text-warning"><i class="fas fa-exclamation-triangle"></i> Crafty can't get infos from this Server </span>
</div>
<div id="m_server_version_{{ server['stats']['server_id']['server_id'] }}"></div>
</div>
</div>
{% end %}
@ -200,7 +203,7 @@
}
motd = motd + `<span id="input_motd_` + server.id + `" class="input_motd">` + server.desc + `</span> <br />`;
m_motd = m_motd + `<div class="media-body"><span id="input_motd_` + server.id + `" class="input_motd">` + server.desc + `</span></div>`;
m_motd = m_motd + `<div class="media-body"><span id="m_input_motd_` + server.id + `" class="input_motd">` + server.desc + `</span></div>`;
server_motd.innerHTML = motd;
m_server_motd.innerHTML = m_motd;
}

View File

@ -0,0 +1,16 @@
# Generated by database migrator
import peewee
def migrate(migrator, database, **kwargs):
migrator.add_columns("servers", show_status=peewee.BooleanField(default=1))
"""
Write your migrations here.
"""
def rollback(migrator, database, **kwargs):
migrator.drop_columns("servers", ["show_status"])
"""
Write your rollback migrations here.
"""

View File

@ -323,7 +323,8 @@
"stopBeforeDeleting": "Please stop the server before deleting it",
"update": "Update Executable",
"yesDelete": "Yes, delete",
"yesDeleteFiles": "Yes, delete files"
"yesDeleteFiles": "Yes, delete files",
"showStatus": "Show On Public Status Page"
},
"serverConfigHelp": {
"desc": "Here is where you can change the configuration of your server",