From c08db6fc31172b02bfff014ccc657e93e3cc8dbb Mon Sep 17 00:00:00 2001 From: Osiris Team Date: Tue, 12 Sep 2023 23:19:55 +0200 Subject: [PATCH] 7.3.8, 7.3.9, 7.3.10 - added .env info command - added .find java command --- pom.xml | 2 +- .../java/com/osiris/autoplug/client/Main.java | 8 ++ .../autoplug/client/console/Commands.java | 112 +++++++++++++++++- 3 files changed, 119 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index d1f9fff3..74cd037d 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.osiris.autoplug.client autoplug-client - 7.3.7 + 7.3.10 jar AutoPlug-Client diff --git a/src/main/java/com/osiris/autoplug/client/Main.java b/src/main/java/com/osiris/autoplug/client/Main.java index ee1ad5f3..4338ab10 100644 --- a/src/main/java/com/osiris/autoplug/client/Main.java +++ b/src/main/java/com/osiris/autoplug/client/Main.java @@ -28,6 +28,7 @@ import com.osiris.dyml.YamlSection; import com.osiris.jlib.logger.AL; import com.osiris.jlib.logger.MessageFormatter; +import com.osiris.jprocesses2.ProcessUtils; import org.fusesource.jansi.AnsiConsole; import java.io.File; @@ -140,6 +141,13 @@ public static void main(String[] _args) { AL.debug(Main.class, "!!!IMPORTANT!!! -> THIS LOG-FILE CONTAINS SENSITIVE INFORMATION <- !!!IMPORTANT!!!"); AL.debug(Main.class, "!!!IMPORTANT!!! -> THIS LOG-FILE CONTAINS SENSITIVE INFORMATION <- !!!IMPORTANT!!!"); AL.debug(Main.class, "!!!IMPORTANT!!! -> THIS LOG-FILE CONTAINS SENSITIVE INFORMATION <- !!!IMPORTANT!!!"); + String command = ""; + try { + command = new ProcessUtils().getThis().command; + } catch (Throwable e) { + command = e.getMessage(); + } + AL.debug(Main.class, "START COMMAND: " + command); AL.debug(Main.class, "JAR: " + new UtilsJar().getThisJar()); AL.debug(Main.class, "ARGS: " + (args != null ? new UtilsLists().toString(args) : "")); AL.debug(Main.class, "SYSTEM OS: " + System.getProperty("os.name")); diff --git a/src/main/java/com/osiris/autoplug/client/console/Commands.java b/src/main/java/com/osiris/autoplug/client/console/Commands.java index 44176726..64fb829f 100644 --- a/src/main/java/com/osiris/autoplug/client/console/Commands.java +++ b/src/main/java/com/osiris/autoplug/client/console/Commands.java @@ -38,11 +38,13 @@ import java.io.BufferedReader; import java.io.File; +import java.io.IOException; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.URL; -import java.util.List; -import java.util.Objects; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.*; /** * Listens for input started with . @@ -76,6 +78,8 @@ public static boolean execute(@NotNull String command) { AL.info(".con info | Shows details about AutoPlugs network connections (.ci)"); AL.info(".con reload | Closes and reconnects all connections (.cr)"); AL.info(".backup | Ignores cool-down and does an backup (.b)"); + AL.info(".env info | Shows environment details (.ei)"); + AL.info(".find java | Finds all Java installations and lists current Javas binaries (.fj)"); AL.info(""); AL.info("Server related commands:"); AL.info(".start | Starts the server (.s)"); @@ -175,6 +179,64 @@ public static boolean execute(@NotNull String command) { AL.info("MEM total: " + conPrivate.memTotal + " Gb"); } return true; + } else if (command.equals(".env info") || command.equals(".ei")) { + + AL.info("###################################################"); + AL.info("ALL PROPERTIES:"); + AL.info("###################################################"); + Properties props = System.getProperties(); + props.forEach((key, val) -> { + AL.info(key + ": " + val); + }); + + AL.info("###################################################"); + AL.info("ALL ENVIRONMENT VARIABLES:"); + AL.info("###################################################"); + // Get all environment variables + Map env = System.getenv(); + // Loop through and print each environment variable + for (Map.Entry entry : env.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + AL.info(key + ": " + value); + } + + return true; + } else if (command.equals(".find java") || command.equals(".fj")) { + Path directoryPath = new File(System.getProperty("java.home")).toPath(); + + AL.info("###################################################"); + AL.info("ALL BINARY FILES IN " + directoryPath + ": "); + AL.info("###################################################"); + try { + Files.walkFileTree(directoryPath, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + // Check if the file name contains "java" + if (file.toFile().isFile() && (!file.getFileName().toString().contains(".") || file.getFileName().toString().contains(".exe"))) { + AL.info(file.toString()); + } + return FileVisitResult.CONTINUE; + } + }); + } catch (IOException e) { + AL.warn(e); + } + + AL.info("###################################################"); + AL.info("JAVA INSTALLATIONS: "); + AL.info("###################################################"); + List javaInstallations = findJavaInstallations(); + + if (javaInstallations.isEmpty()) { + AL.info("No Java installations found."); + } else { + AL.info("Possible Java installations found:"); + for (String installation : javaInstallations) { + AL.info(installation); + } + } + return true; } else if (command.equals(".check") || command.equals(".c")) { MyBThreadManager myManager = new UtilsTasks().createManagerAndPrinter(); new TaskSelfUpdater("SelfUpdater", myManager.manager).start(); @@ -225,6 +287,52 @@ public static boolean execute(@NotNull String command) { return false; } + public static List findJavaInstallations() { + List installations = new ArrayList<>(); + + // Get all drives on the system + File[] drives; + try { + drives = File.listRoots(); + } catch (Exception e) { + AL.warn("Failed to fetch drives, using fallback hardcoded drives.", e); + drives = new File[]{Paths.get("/").toFile(), Paths.get("C:\\").toFile(), Paths.get("D:\\").toFile()}; + } + + for (File drive : drives) { + try { + findJavaInstallationsInDrive(drive, installations); + } catch (Exception e) { + AL.warn("Failed for drive: " + drive, e); + } + } + + return installations; + } + + private static void findJavaInstallationsInDrive(File directory, List installations) { + // Check if the directory is named "bin" + File binDirectory = new File(directory, "bin"); + + if (binDirectory.exists() && binDirectory.isDirectory()) { + // Check if the "java" file exists in the "bin" directory + for (File f : binDirectory.listFiles()) { + if (f.getName().startsWith("java")) { + installations.add(binDirectory.getAbsolutePath()); + break; + } + } + } + + // Recursively search subdirectories + File[] subDirectories = directory.listFiles(File::isDirectory); + if (subDirectories != null) { + for (File subDirectory : subDirectories) { + findJavaInstallationsInDrive(subDirectory, installations); + } + } + } + public static boolean installPlugin(String command) throws Exception { String input = command.replaceFirst("\\.install plugin", "").replaceFirst("\\.ip", "").trim(); SearchResult result = null;