mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Fix window java issue causing no stats
This commit is contained in:
parent
17ef71046c
commit
cda2120579
@ -1,6 +1,7 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import winreg
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -101,6 +102,39 @@ class Helpers:
|
|||||||
def get_servers_root_dir(self):
|
def get_servers_root_dir(self):
|
||||||
return self.servers_dir
|
return self.servers_dir
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def which_java():
|
||||||
|
# Adapted from LeeKamentsky's https://github.com/LeeKamentsky/python-javabridge/blob/master/javabridge/locate.py
|
||||||
|
jdk_key_paths = (
|
||||||
|
"SOFTWARE\\JavaSoft\\JDK",
|
||||||
|
"SOFTWARE\\JavaSoft\\Java Development Kit",
|
||||||
|
)
|
||||||
|
for jdk_key_path in jdk_key_paths:
|
||||||
|
try:
|
||||||
|
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, jdk_key_path) as kjdk:
|
||||||
|
kjdk_values = dict(
|
||||||
|
[
|
||||||
|
winreg.EnumValue(kjdk, i)[:2]
|
||||||
|
for i in range(winreg.QueryInfoKey(kjdk)[1])
|
||||||
|
]
|
||||||
|
)
|
||||||
|
current_version = kjdk_values["CurrentVersion"]
|
||||||
|
kjdk_current = winreg.OpenKey(
|
||||||
|
winreg.HKEY_LOCAL_MACHINE, jdk_key_path + "\\" + current_version
|
||||||
|
)
|
||||||
|
kjdk_current_values = dict(
|
||||||
|
[
|
||||||
|
winreg.EnumValue(kjdk_current, i)[:2]
|
||||||
|
for i in range(winreg.QueryInfoKey(kjdk_current)[1])
|
||||||
|
]
|
||||||
|
)
|
||||||
|
return kjdk_current_values["JavaHome"]
|
||||||
|
except WindowsError as e:
|
||||||
|
if e.errno == 2:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check_internet():
|
def check_internet():
|
||||||
try:
|
try:
|
||||||
|
@ -234,6 +234,21 @@ class ServerInstance:
|
|||||||
self.settings["executable"]
|
self.settings["executable"]
|
||||||
)
|
)
|
||||||
self.server_command = Helpers.cmdparse(self.settings["execution_command"])
|
self.server_command = Helpers.cmdparse(self.settings["execution_command"])
|
||||||
|
if self.helper.is_os_windows() and self.server_command[0] == "java":
|
||||||
|
logger.info(
|
||||||
|
"Detected nebulous java in start command. Replacing with full java path."
|
||||||
|
)
|
||||||
|
which_java_raw = self.helper.which_java()
|
||||||
|
java_path = which_java_raw + "\\bin\\java"
|
||||||
|
if not str(which_java_raw) == str(self.helper.get_servers_root_dir) or str(
|
||||||
|
self.helper.get_servers_root_dir
|
||||||
|
) in str(which_java_raw):
|
||||||
|
self.server_command[0] = java_path
|
||||||
|
else:
|
||||||
|
logger.critcal(
|
||||||
|
"Possible attack detected. User attempted to exec java binary from server directory."
|
||||||
|
)
|
||||||
|
return
|
||||||
self.server_path = Helpers.get_os_understandable_path(self.settings["path"])
|
self.server_path = Helpers.get_os_understandable_path(self.settings["path"])
|
||||||
|
|
||||||
# let's do some quick checking to make sure things actually exists
|
# let's do some quick checking to make sure things actually exists
|
||||||
|
Loading…
Reference in New Issue
Block a user