Skip to content
This repository was archived by the owner on Nov 22, 2020. It is now read-only.

Commit d6f6bdf

Browse files
authored
Merge pull request #2 from V2C-Development-Team/feature/secure-tunnel
Feature/secure tunnel
2 parents 651903a + cae77ad commit d6f6bdf

16 files changed

+547
-48
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
[submodule "v2c-recognizer"]
1414
path = v2c-recognizer
1515
url = [email protected]:V2C-Development-Team/v2c-recognizer
16+
[submodule "v2c-dashboard-backend"]
17+
path = v2c-dashboard-backend
18+
url = [email protected]:V2C-Development-Team/v2c-dashboard-backend.git

build.bat

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
rem pull the repos
44
git submodule update --init --recursive
55

6+
rem build this project
7+
call .\gradlew clean shadowJar --refresh-dependencies
8+
69
rem build the java projects
7-
for %%m in (v2c-desktop-controller-linux v2c-dispatcher) do (
10+
for %%m in (v2c-desktop-controller-linux v2c-dispatcher v2c-dashboard-backend) do (
811
echo Building %%m
912
cd %%m
1013
call .\gradlew clean shadowJar --refresh-dependencies

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ sourceCompatibility = prjCompat
1515
targetCompatibility = prjCompat
1616

1717
dependencies {
18+
implementation 'com.jcraft:jsch:0.1.55'
1819
implementation 'commons-cli:commons-cli:1.4'
1920
implementation 'org.apache.commons:commons-lang3:3.11'
2021
implementation 'org.json:json:20200518'

run.bat

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
@echo off
2-
start "" /d v2c-dispatcher java -jar build\libs\v2c-dispatcher.jar
3-
ping -n 3 127.0.0.1>nul
4-
start "" /d v2c-desktop-controller-linux java -jar build\libs\v2c-desktop-controller-linux.jar -u
5-
start "" /d v2c-recognizer\Recognizer cmd /c "python speech.py"
6-
start "" /d v2c-recognizer\Recognizer cmd /c "python widget.py"
7-
start "" /d v2c-dashboard cmd /c "npm start"
1+
java -jar build\libs\v2c-poc-submission.jar

src/main/java/edu/uco/cs/v2c/poc/ModuleID.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
import edu.uco.cs.v2c.poc.control.ModuleHandler.ProcessType;
44

55
public enum ModuleID {
6-
HOME,
7-
DISPATCHER(ProcessType.JAVA_PROCESS, "v2c-dispatcher/build/libs/v2c-dispatcher.jar"),
8-
RECOGNIZER(ProcessType.PYTHON_PROCESS, "v2c-recognizer/Recognizer/speech.py"),
9-
DESKTOP_CONTROLLER(ProcessType.JAVA_PROCESS, "v2c-desktop-controller-linux/build/libs/v2c-desktop-controller-linux.jar"),
10-
DASHBOARD_BACKEND(ProcessType.JAVA_PROCESS, "v2c-dashboard-backend/build/libs/v2c-dashboard-backend.jar"),
11-
DASHBOARD_FRONTEND(ProcessType.NPM_PROCESS, "v2c-dashboard");
6+
DISPATCHER(ProcessType.JAVA_PROCESS, "v2c-dispatcher/build/libs/v2c-dispatcher.jar", false),
7+
RECOGNIZER(ProcessType.PYTHON_PROCESS, "v2c-recognizer/Recognizer/speech.py", false),
8+
DESKTOP_CONTROLLER(ProcessType.JAVA_PROCESS, "v2c-desktop-controller-linux/build/libs/v2c-desktop-controller-linux.jar", false),
9+
DASHBOARD_BACKEND(ProcessType.JAVA_PROCESS, "v2c-dashboard-backend/build/libs/v2c-dashboard-backend.jar", true),
10+
DASHBOARD_FRONTEND(ProcessType.NPM_PROCESS, "v2c-dashboard", false);
1211

12+
private boolean hasTunnel = false;
1313
private String name = null;
1414
private String defaultModulePath = null;
1515
private ProcessType processType = null;
1616

17-
private ModuleID() {
18-
this(null, null);
19-
}
20-
21-
private ModuleID(ProcessType processType, String defaultModulePath) {
17+
private ModuleID(ProcessType processType, String defaultModulePath, boolean hasTunnel) {
18+
this.hasTunnel = hasTunnel;
2219
this.processType = processType;
2320
this.defaultModulePath = defaultModulePath;
2421
String[] tokens = name().split("_");
@@ -35,6 +32,10 @@ private ModuleID(ProcessType processType, String defaultModulePath) {
3532
return name;
3633
}
3734

35+
public boolean hasTunnel() {
36+
return hasTunnel;
37+
}
38+
3839
public ProcessType getProcessType() {
3940
return processType;
4041
}
Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,71 @@
11
package edu.uco.cs.v2c.poc;
22

3+
import java.awt.event.WindowEvent;
4+
import java.awt.event.WindowListener;
5+
import java.util.HashSet;
6+
import java.util.Set;
7+
38
import javax.swing.JButton;
49

5-
import edu.uco.cs.v2c.poc.control.ConfigureAction;
10+
import edu.uco.cs.v2c.poc.control.ModuleConfigAction;
611
import edu.uco.cs.v2c.poc.control.ModuleHandler;
712
import edu.uco.cs.v2c.poc.control.StartAction;
813
import edu.uco.cs.v2c.poc.control.StopAction;
14+
import edu.uco.cs.v2c.poc.control.TunnelConfigAction;
15+
import edu.uco.cs.v2c.poc.net.Tunnel;
916
import edu.uco.cs.v2c.poc.ui.LandingFrame;
1017
import edu.uco.cs.v2c.poc.ui.ModuleComponent;
1118

1219
public class SubmissionPOC {
1320

21+
private static Set<ModuleHandler> handlers = new HashSet<>();
22+
1423
public static void main(String[] args) {
1524
LandingFrame landingFrame = new LandingFrame();
25+
1626
for(ModuleID moduleID : ModuleID.values()) {
1727
if(moduleID.getProcessType() == null) continue;
1828
ModuleComponent moduleComponent = landingFrame.getModule(moduleID);
19-
ModuleHandler moduleHandler = ModuleHandler.build(moduleComponent, moduleID);
29+
ModuleHandler moduleHandler = ModuleHandler.build(landingFrame.getHomeComponent(), moduleComponent, moduleID);
30+
handlers.add(moduleHandler);
31+
2032
JButton startButton = moduleComponent.addButton("START MODULE", new StartAction(moduleHandler));
2133
moduleHandler.addButtonToEnableOnDyingProcess(startButton);
2234
JButton stopButton = moduleComponent.addButton("STOP MODULE", new StopAction(moduleHandler));
2335
stopButton.setEnabled(false);
2436
moduleHandler.addButtonToEnableOnLivingProcess(stopButton);
25-
moduleComponent.addButton("CONFIGURE", new ConfigureAction(moduleHandler));
37+
moduleComponent.addButton("CONFIGURE", new ModuleConfigAction(moduleHandler));
38+
39+
if(moduleID.hasTunnel()) {
40+
Tunnel tunnel = new Tunnel();
41+
moduleComponent.addButton("TUNNEL", new TunnelConfigAction(moduleHandler, tunnel));
42+
moduleHandler.setTunnel(tunnel);
43+
}
44+
45+
landingFrame.getHomeComponent().addModuleHandler(moduleHandler);
2646
}
47+
48+
landingFrame.addWindowListener(new WindowListener() {
49+
50+
@Override public void windowOpened(WindowEvent e) { }
51+
52+
@Override public void windowClosing(WindowEvent e) {
53+
for(ModuleHandler handler : handlers)
54+
handler.terminate();
55+
}
56+
57+
@Override public void windowClosed(WindowEvent e) { }
58+
59+
@Override public void windowIconified(WindowEvent e) { }
60+
61+
@Override public void windowDeiconified(WindowEvent e) { }
62+
63+
@Override public void windowActivated(WindowEvent e) { }
64+
65+
@Override public void windowDeactivated(WindowEvent e) { }
66+
67+
});
68+
2769
}
2870

2971
}

src/main/java/edu/uco/cs/v2c/poc/control/ConfigureAction.java renamed to src/main/java/edu/uco/cs/v2c/poc/control/ModuleConfigAction.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
import java.awt.event.ActionEvent;
44

5-
import edu.uco.cs.v2c.poc.ui.ConfigurationFrame;
5+
import edu.uco.cs.v2c.poc.ui.ModuleConfigFrame;
66

7-
public class ConfigureAction extends ModuleAction {
7+
public class ModuleConfigAction extends ModuleAction {
88

9-
public ConfigureAction(ModuleHandler handler) {
9+
private ModuleConfigFrame moduleConfigFrame = null;
10+
11+
public ModuleConfigAction(ModuleHandler handler) {
1012
super(handler);
1113
}
1214

1315
@Override public void actionPerformed(ActionEvent e) {
14-
ConfigurationFrame configurationFrame = new ConfigurationFrame(this);
15-
configurationFrame.setVisible(true);
16+
if(moduleConfigFrame == null)
17+
moduleConfigFrame = new ModuleConfigFrame(this);
18+
moduleConfigFrame.setVisible(true);
1619
}
1720

1821
public void onConfigUpdate(String runtimeBin, String moduleBin) {

src/main/java/edu/uco/cs/v2c/poc/control/ModuleHandler.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.apache.commons.lang3.SystemUtils;
1717

1818
import edu.uco.cs.v2c.poc.ModuleID;
19+
import edu.uco.cs.v2c.poc.net.Tunnel;
20+
import edu.uco.cs.v2c.poc.ui.HomeComponent;
1921
import edu.uco.cs.v2c.poc.ui.ModuleComponent;
2022

2123
public class ModuleHandler implements Runnable {
@@ -61,16 +63,19 @@ public String getBin() {
6163

6264
private AtomicBoolean go = new AtomicBoolean();
6365
private AtomicReference<Process> currentProcess = new AtomicReference<>();
66+
private HomeComponent homeComponent = null;
6467
private ModuleComponent moduleComponent = null;
6568
private ModuleID moduleID = null;
6669
private Set<JButton> enabledButtonsOnLivingProcess = new HashSet<>();
6770
private Set<JButton> enabledButtonsOnDyingProcess = new HashSet<>();
6871
private String runtimeBin = null;
6972
private String moduleBin = null;
7073
private Thread thread = null;
74+
private Tunnel tunnel = null;
7175

72-
private ModuleHandler(ModuleComponent moduleComponent, ModuleID moduleID) {
76+
private ModuleHandler(HomeComponent homeComponent, ModuleComponent moduleComponent, ModuleID moduleID) {
7377
this.moduleID = moduleID;
78+
this.homeComponent = homeComponent;
7479
this.moduleComponent = moduleComponent;
7580
if(moduleID != null) {
7681
moduleComponent.setActive(false);
@@ -79,8 +84,8 @@ private ModuleHandler(ModuleComponent moduleComponent, ModuleID moduleID) {
7984
}
8085
}
8186

82-
public static ModuleHandler build(ModuleComponent moduleComponent, ModuleID moduleID) {
83-
ModuleHandler handler = new ModuleHandler(moduleComponent, moduleID);
87+
public static ModuleHandler build(HomeComponent homeComponent, ModuleComponent moduleComponent, ModuleID moduleID) {
88+
ModuleHandler handler = new ModuleHandler(homeComponent, moduleComponent, moduleID);
8489
handler.thread = new Thread(handler);
8590
handler.thread.setDaemon(true);
8691
handler.thread.start();
@@ -141,14 +146,19 @@ public void setModuleBin(String moduleBin) {
141146
processBuilder.redirectErrorStream(true);
142147

143148
try {
149+
if(moduleID.hasTunnel() && tunnel != null && tunnel.isEnabled())
150+
tunnel.spinUp();
151+
144152
Process process = processBuilder.start();
145153
currentProcess.set(process);
146154

147155
moduleComponent.setActive(true);
156+
homeComponent.notifyModuleStateChange(moduleID, true);
148157
for(JButton button : enabledButtonsOnLivingProcess)
149158
button.setEnabled(true);
150159
for(JButton button : enabledButtonsOnDyingProcess)
151160
button.setEnabled(false);
161+
moduleComponent.putLine("Starting module...");
152162

153163
try(BufferedReader streamReader = new BufferedReader(
154164
new InputStreamReader(process.getInputStream()))) {
@@ -163,10 +173,15 @@ public void setModuleBin(String moduleBin) {
163173
} finally {
164174
go.set(false);
165175
moduleComponent.setActive(false);
176+
homeComponent.notifyModuleStateChange(moduleID, false);
166177
for(JButton button : enabledButtonsOnDyingProcess)
167178
button.setEnabled(true);
168179
for(JButton button : enabledButtonsOnLivingProcess)
169180
button.setEnabled(false);
181+
moduleComponent.putLine("Module terminated.");
182+
183+
if(moduleID.hasTunnel() && tunnel != null)
184+
tunnel.spinDown();
170185
}
171186
}
172187
} catch(InterruptedException e) { }
@@ -205,4 +220,8 @@ public void addButtonToEnableOnLivingProcess(JButton button) {
205220
public void addButtonToEnableOnDyingProcess(JButton button) {
206221
enabledButtonsOnDyingProcess.add(button);
207222
}
223+
224+
public void setTunnel(Tunnel tunnel) {
225+
this.tunnel = tunnel;
226+
}
208227
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package edu.uco.cs.v2c.poc.control;
2+
3+
import java.awt.event.ActionEvent;
4+
import java.io.File;
5+
6+
import edu.uco.cs.v2c.poc.net.Tunnel;
7+
import edu.uco.cs.v2c.poc.ui.TunnelConfigFrame;
8+
9+
public class TunnelConfigAction extends ModuleAction {
10+
11+
private Tunnel tunnel = null;
12+
private TunnelConfigFrame tunnelConfigFrame = null;
13+
14+
public TunnelConfigAction(ModuleHandler handler, Tunnel tunnel) {
15+
super(handler);
16+
this.tunnel = tunnel;
17+
}
18+
19+
@Override public void actionPerformed(ActionEvent e) {
20+
if(tunnelConfigFrame == null)
21+
tunnelConfigFrame = new TunnelConfigFrame(this);
22+
tunnelConfigFrame.setVisible(true);
23+
}
24+
25+
public boolean onConfigUpdate(String localPort, String remoteHost, String remotePort,
26+
String internalHost, String internalPort, String username,
27+
String keyfilePath, String keyfilePassword) {
28+
29+
try {
30+
int lPort = Integer.parseInt(localPort);
31+
int iPort = Integer.parseInt(internalPort);
32+
int rPort = Integer.parseInt(remotePort);
33+
34+
tunnel.setLocalPort(lPort)
35+
.setRemoteHost(remoteHost)
36+
.setRemotePort(rPort)
37+
.setInternalHost(internalHost)
38+
.setInternalPort(iPort)
39+
.setKeyfile(keyfilePath, keyfilePassword.isBlank() ? null : keyfilePassword);
40+
41+
return true;
42+
43+
} catch(Exception e) { }
44+
45+
return false;
46+
}
47+
48+
public void setEnabled(boolean enabled) {
49+
tunnel.setEnabled(enabled);
50+
}
51+
52+
}

0 commit comments

Comments
 (0)