Fix window java issue causing no stats

This commit is contained in:
amcmanu3 2022-06-14 22:33:02 -04:00
parent 17ef71046c
commit cda2120579
2 changed files with 49 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import contextlib
import os
import re
import winreg
import sys
import json
import tempfile
@ -101,6 +102,39 @@ class Helpers:
def get_servers_root_dir(self):
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
def check_internet():
try:

View File

@ -234,6 +234,21 @@ class ServerInstance:
self.settings["executable"]
)
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"])
# let's do some quick checking to make sure things actually exists