mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-19 09:45:28 +01:00
Add Java detect for win, and hook up to front end
This commit is contained in:
parent
32b3551108
commit
8e646df58c
@ -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"
|
||||
|
@ -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 + " "
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<form class="forms-sample" method="post" action="/panel/server_detail">
|
||||
<form class="forms-sample" method="post" id="config_form" action="/panel/server_detail">
|
||||
{% raw xsrf_form_html() %}
|
||||
<input type="hidden" name="id" value="{{ data['server_stats']['server_id']['server_id'] }}">
|
||||
<input type="hidden" name="subpage" value="config">
|
||||
@ -79,6 +79,19 @@
|
||||
placeholder="{{ translate('serverConfig', 'serverExecutable', data['lang']) }}" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="executable">{{ translate('serverConfig', 'javaVersion', data['lang']) }} <small
|
||||
class="text-muted ml-1"> - {{ translate('serverConfig', 'javaVersionDesc', data['lang'])
|
||||
}}</small> </label>
|
||||
<select class="form-select form-control form-control-lg select-css" id="java_selection"
|
||||
name="java_selection" form="config_form">
|
||||
<option value="">None</option>
|
||||
{% for path in data['java_versions'] %}
|
||||
<option value="{{path}}">{{path}}</option>
|
||||
{% end %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="execution_command">{{ translate('serverConfig', 'serverExecutionCommand', data['lang']) }}
|
||||
<small class="text-muted ml-1"> - {{ translate('serverConfig', 'serverExecutionCommandDesc',
|
||||
|
@ -300,6 +300,8 @@
|
||||
"serverCrashDetection": "Server Crash Detection",
|
||||
"serverExecutable": "Server Executable",
|
||||
"serverExecutableDesc": "The server's executable file",
|
||||
"javaVersion": "Override current Java Version",
|
||||
"javaVersionDesc": "If we've been able to find local java installs. (Windows 'Oracle' only)",
|
||||
"serverExecutionCommand": "Server Execution Command",
|
||||
"serverExecutionCommandDesc": "What will be launched in a hidden terminal",
|
||||
"serverIP": "Server IP",
|
||||
|
Loading…
x
Reference in New Issue
Block a user