diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index c870c918..bba2dfc5 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -16,6 +16,7 @@ import zipfile import pathlib import ctypes import subprocess +import itertools from datetime import datetime from socket import gethostname from contextlib import redirect_stderr, suppress @@ -84,6 +85,46 @@ class Helpers: @staticmethod def find_java_installs(): + # If we're windows return oracle java versions, + # otherwise java vers need to be manual. + if os.name == "nt": + # Adapted from LeeKamentsky >>> + # https://github.com/LeeKamentsky/python-javabridge/blob/master/javabridge/locate.py + jdk_key_paths = ( + "SOFTWARE\\JavaSoft\\JDK", + "SOFTWARE\\JavaSoft\\Java Development Kit", + ) + java_paths = [] + for jdk_key_path in jdk_key_paths: + try: + with suppress(OSError), winreg.OpenKey( + winreg.HKEY_LOCAL_MACHINE, jdk_key_path + ) as kjdk: + for i in itertools.count(): + version = winreg.EnumKey(kjdk, i) + kjdk_current = winreg.OpenKey( + winreg.HKEY_LOCAL_MACHINE, + jdk_key_path, + ) + kjdk_current = winreg.OpenKey( + winreg.HKEY_LOCAL_MACHINE, + jdk_key_path + "\\" + version, + ) + kjdk_current_values = dict( # pylint: disable=consider-using-dict-comprehension + [ + winreg.EnumValue(kjdk_current, i)[:2] + for i in range(winreg.QueryInfoKey(kjdk_current)[1]) + ] + ) + java_paths.append(kjdk_current_values["JavaHome"]) + except OSError as e: + if e.errno == 2: + continue + raise + return java_paths + + # If we get here we're linux so we will use 'update-alternatives' + # (If distro does not have update-alternatives then manual input.) try: paths = subprocess.check_output( ["/usr/bin/update-alternatives", "--list", "java"], encoding="utf8" diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 1bf5ba54..919a1593 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -9,6 +9,7 @@ import threading import bleach import libgravatar import requests +import shlex import tornado.web import tornado.escape from tornado import iostream @@ -627,6 +628,7 @@ class PanelHandler(BaseHandler): "/panel/error?error=Unauthorized access Server Config" ) return + page_data["java_versions"] = Helpers.find_java_installs() if subpage == "files": if ( @@ -1361,9 +1363,12 @@ class PanelHandler(BaseHandler): server_id = self.check_server_id() if server_id is None: return - execution_list = execution_command.split(" ") + execution_list = shlex.split(execution_command) if java_selection: - execution_list[0] = java_selection + if self.helper.is_os_windows(): + execution_list[0] = '"' + java_selection + '/bin/java"' + else: + execution_list[0] = '"' + java_selection + '"' execution_command = "" for item in execution_list: execution_command += item + " " diff --git a/app/frontend/templates/panel/server_config.html b/app/frontend/templates/panel/server_config.html index 74216884..c5e05996 100644 --- a/app/frontend/templates/panel/server_config.html +++ b/app/frontend/templates/panel/server_config.html @@ -36,7 +36,7 @@
-
+ {% raw xsrf_form_html() %} @@ -79,6 +79,19 @@ placeholder="{{ translate('serverConfig', 'serverExecutable', data['lang']) }}" required>
+
+ + +
+