diff --git a/.DS_Store b/.DS_Store index feca861..c96c693 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index 4f6b277..920ec8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target/* +.DS_Store diff --git a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Controllers/RemoteVMController.java b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Controllers/RemoteVMController.java index 322bc25..e2f2003 100644 --- a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Controllers/RemoteVMController.java +++ b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Controllers/RemoteVMController.java @@ -14,19 +14,19 @@ public class RemoteVMController { - public static void startVm(VM vm, String remoteAddress){ + public static void startVm(VM vm, String remoteAddress, String httpAuth){ try { + HttpResponse response = Unirest.post(remoteAddress+"/vm/") .header("Content-Type", "application/json") + .header("Authentication", httpAuth) .body("{\"name\":\""+vm.getDomain()+"\",\"action\":\"start\"}") .asString(); Gson g = new Gson(); VM remote = g.fromJson(response.getBody(), VM.class); - - } catch (Exception e) { JDialog dialog = new JDialog(); @@ -47,19 +47,18 @@ public static void startVm(VM vm, String remoteAddress){ } - public static void stopVM(VM vm, String remoteAddress){ + public static void stopVM(VM vm, String remoteAddress, String httpAuth){ try { HttpResponse response = Unirest.post(remoteAddress+"/vm/") .header("Content-Type", "application/json") + .header("Authentication", httpAuth) .body("{\"name\":\""+vm.getDomain()+"\",\"action\":\"stop\"}") .asString(); Gson g = new Gson(); VM remote = g.fromJson(response.getBody(), VM.class); - - } catch (Exception e) { JDialog dialog = new JDialog(); diff --git a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Controllers/VMController.java b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Controllers/VMController.java index 48ff4e8..3863938 100644 --- a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Controllers/VMController.java +++ b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Controllers/VMController.java @@ -32,7 +32,7 @@ public void startVM(VM vm){ VMController.startVMthread(vmToStart, context); }else{ - RemoteVMController.startVm(vm, context.remoteAddress); + RemoteVMController.startVm(vm, context.remoteAddress, context.httpAuth); } @@ -45,7 +45,7 @@ public void stopVM(VM vm){ if(context.local){ VMController.stopVMthread(vmToStop, context); }else{ - RemoteVMController.stopVM(vm, context.remoteAddress); + RemoteVMController.stopVM(vm, context.remoteAddress, context.httpAuth); } diff --git a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Objects/Context.java b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Objects/Context.java index fd808b5..7ba527e 100644 --- a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Objects/Context.java +++ b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Objects/Context.java @@ -35,7 +35,7 @@ public class Context { public MainContent mainContent; public JFrame mainJFrame; public String defaultSaveLocation; - private static final String versionString = "0.5.3"; + private static final String versionString = "0.5.4"; public Boolean checkForUpdates; private String applicationDefaultSaveLocation; public Integer windowHeight; @@ -45,6 +45,7 @@ public class Context { public long autoRefreshRate; public boolean local; public String remoteAddress; + public String httpAuth; private String currentSelectedUUID; public ArrayList remoteConnections; @@ -64,6 +65,7 @@ public Context(){ private void initDefaults(){ this.checkForUpdates = true; this.local = true; + this.httpAuth = ""; this.remoteAddress = ""; this.remoteConnections = new ArrayList(); diff --git a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Objects/RemoteConnection.java b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Objects/RemoteConnection.java index f855a7f..c2854b1 100644 --- a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Objects/RemoteConnection.java +++ b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Objects/RemoteConnection.java @@ -5,5 +5,6 @@ public class RemoteConnection { public String name; public String address; public Boolean favorite; + public String httpAuthentication; } diff --git a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Processors/Remote/RemoteVMDetailProcessor.java b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Processors/Remote/RemoteVMDetailProcessor.java index 120ca21..f4fd59d 100644 --- a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Processors/Remote/RemoteVMDetailProcessor.java +++ b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Processors/Remote/RemoteVMDetailProcessor.java @@ -8,11 +8,12 @@ public class RemoteVMDetailProcessor { - public static VM getDetails(VM vm, String remoteAddress) { + public static VM getDetails(VM vm, String remoteAddress, String httpAuth) { try { HttpResponse response = Unirest.post(remoteAddress+"/vm/details/") .header("Content-Type", "application/json") + .header("Authentication", httpAuth) .body("{\"name\":\""+vm.getDomain()+"\"}") .asString(); diff --git a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Processors/Remote/RemoteVMListProcessor.java b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Processors/Remote/RemoteVMListProcessor.java index 574d03b..c1a05f2 100644 --- a/src/main/java/com/lucaoonk/Virt_Commander/Backend/Processors/Remote/RemoteVMListProcessor.java +++ b/src/main/java/com/lucaoonk/Virt_Commander/Backend/Processors/Remote/RemoteVMListProcessor.java @@ -27,16 +27,17 @@ public RemoteVMListProcessor(Context context){ } public void runCommand() throws IOException{ - this.vmList = getVMdomainList(context.remoteAddress, context); + this.vmList = getVMdomainList(context.remoteAddress, context, context.httpAuth); context.updateVMList(vmList); } - public static ArrayList getVMdomainList(String remoteAddress, Context context) throws IOException { + public static ArrayList getVMdomainList(String remoteAddress, Context context, String httpAuth) throws IOException { try { HttpResponse response = Unirest.get(remoteAddress+"/list") .header("Content-Type", "application/json") + .header("Authentication", httpAuth) .asString(); Gson g = new Gson(); @@ -46,7 +47,7 @@ public static ArrayList getVMdomainList(String remoteAddress, Context contex ArrayList actualVMs = new ArrayList(); for (VM vm : list.vms) { - actualVMs.add(RemoteVMDetailProcessor.getDetails(vm, remoteAddress)); + actualVMs.add(RemoteVMDetailProcessor.getDetails(vm, remoteAddress, httpAuth)); } return actualVMs; diff --git a/src/main/java/com/lucaoonk/Virt_Commander/Backend/RemoteConnector.java b/src/main/java/com/lucaoonk/Virt_Commander/Backend/RemoteConnector.java index 95b4589..f197b73 100644 --- a/src/main/java/com/lucaoonk/Virt_Commander/Backend/RemoteConnector.java +++ b/src/main/java/com/lucaoonk/Virt_Commander/Backend/RemoteConnector.java @@ -23,6 +23,8 @@ public class RemoteConnector implements ActionListener{ private Context context; private JComboBox combobox; private JTextArea remoteAddressText; + private JTextArea httpAuthenticationText; + private JButton removeButton; private JTextArea remoteNameText; private JButton addButton; @@ -83,6 +85,13 @@ public void actionPerformed(ActionEvent e) { RemoteConnection connection = ((RemoteConnectionComboItem)item).getValue(); context.remoteAddress = connection.address; + + if(connection.httpAuthentication != ""){ + context.httpAuth = connection.httpAuthentication; + }else{ + context.httpAuth = ""; + } + context.local = false; remoteDialog.dispose(); context.refresh(); @@ -118,7 +127,8 @@ public void actionPerformed(ActionEvent e) { RemoteConnection connection = new RemoteConnection(); connection.address = remoteAddressText.getText(); connection.name = remoteNameText.getText(); - + connection.httpAuthentication = httpAuthenticationText.getText(); + System.out.println(connection.name+" " + connection.address); context.remoteConnections.add(connection); context.writeConnections(); @@ -146,9 +156,13 @@ private void showConnectionEditor(){ this.remoteNameText = remoteNameText; remoteNameText.setSize(80, 20); + JTextArea httpAuthText = new JTextArea(); + this.httpAuthenticationText = httpAuthText; + httpAuthenticationText.setSize(80, 20); + // remoteAddressText.setSize(100, 20); panel.setBorder(new EmptyBorder(10,10,10,10)); - panel.setLayout(new GridLayout(5,2)); + panel.setLayout(new GridLayout(7,2)); panel.add(new JLabel("Select a connection and click remove to remove it")); panel.add(new JLabel("New Connection Name")); @@ -172,6 +186,15 @@ private void showConnectionEditor(){ panel.add(new JLabel()); + panel.add(new JLabel("HTTP authentication (leave empty if none should be used)")); + + panel.add(new JLabel()); + + panel.add(httpAuthenticationText); + + panel.add(new JLabel()); + + JButton addButton = new JButton("Add new Connection"); this.addButton = addButton; addButton.addActionListener(this); @@ -180,7 +203,7 @@ private void showConnectionEditor(){ // panel.add(switchToLocalButton); dialog.add(panel); - dialog.setSize(500, 200); + dialog.setSize(500, 250); dialog.setLocationRelativeTo(null); dialog.setVisible(true); dialog.setResizable(false);