Cleanup index

This commit is contained in:
amcmanu3 2023-03-03 17:31:29 -05:00
parent 7f11494d36
commit c23bfdea8c
2 changed files with 32 additions and 28 deletions

View File

@ -16,6 +16,7 @@ import zipfile
import pathlib import pathlib
import ctypes import ctypes
import shutil import shutil
import shlex
import subprocess import subprocess
import itertools import itertools
from datetime import datetime from datetime import datetime
@ -147,6 +148,29 @@ class Helpers:
logger.error(f"Unable to resolve remote bedrock download url! \n{e}") logger.error(f"Unable to resolve remote bedrock download url! \n{e}")
return False return False
def get_execution_java(self, value, execution_command):
if self.is_os_windows():
execution_list = shlex.split(execution_command, posix=False)
else:
execution_list = shlex.split(execution_command, posix=True)
if (
not any(value in path for path in self.find_java_installs())
and value != "java"
):
return
if value != "java":
if self.is_os_windows():
execution_list[0] = '"' + value + '/bin/java"'
else:
execution_list[0] = '"' + value + '"'
else:
execution_list[0] = "java"
execution_command = ""
for item in execution_list:
execution_command += item + " "
return execution_command
def detect_java(self): def detect_java(self):
if len(self.find_java_installs()) > 0: if len(self.find_java_installs()) > 0:
return True return True

View File

@ -83,6 +83,7 @@ class ApiServersServerIndexHandler(BaseApiHandler):
) )
try: try:
# prevent general users from becoming bad actors
if auth_data[4]["superuser"]: if auth_data[4]["superuser"]:
validate(data, server_patch_schema) validate(data, server_patch_schema)
else: else:
@ -115,38 +116,17 @@ class ApiServersServerIndexHandler(BaseApiHandler):
for key in data: for key in data:
# If we don't validate the input there could be security issues # If we don't validate the input there could be security issues
if key == "java_selection" and data[key] != "none": if key == "java_selection" and data[key] != "none":
java_flag = True
try: try:
if self.helper.is_os_windows(): command = self.helper.get_execution_java(
execution_list = shlex.split( data[key], server_obj.execution_command
server_obj.execution_command, posix=False
)
else:
execution_list = shlex.split(
server_obj.execution_command, posix=True
) )
setattr(server_obj, "execution_command", command)
except ValueError: except ValueError:
return self.finish_json( return self.finish_json(
200, {"status": "error", "error": "INVALID EXECUTION COMMAND"} 400, {"status": "error", "error": "INVALID EXECUTION COMMAND"}
) )
if ( java_flag = True
not any(
data[key] in path for path in self.helper.find_java_installs()
)
and data[key] != "java"
):
return
if data[key] != "java":
if self.helper.is_os_windows():
execution_list[0] = '"' + data[key] + '/bin/java"'
else:
execution_list[0] = '"' + data[key] + '"'
else:
execution_list[0] = "java"
execution_command = ""
for item in execution_list:
execution_command += item + " "
setattr(server_obj, "execution_command", execution_command)
if key != "path": if key != "path":
if key == "execution_command" and java_flag: if key == "execution_command" and java_flag:
continue continue