migration complete - working!

master
io42630 1 year ago
parent a86d2c3c59
commit 264b576171

5
.gitignore vendored

@ -0,0 +1,5 @@
*.iml
**/.idea/
**/target/
**/config.properties
*.env

@ -0,0 +1 @@
java temurin-17.0.9+9

@ -9,6 +9,16 @@ The `Ride` object is then sent back to `reverse`.
Upon recieving a reply with data from `app`, `reverse` will forward this data to `forward`,
which in turn will finally forward it to the `user`.
#### Control
##### Routing / Access Control
* currently, there is a 1:1 mapping between `forward` and `reverse`.
* thus any `Ride` "submitted" to `forward` will
naturally be selected, and circle back to `reverse`.
* thus `forward` and `Ride` can both be stateless.
* if any access control, name resolution, port forwarding were to happen,
it would be done in `reverse`.
<br>
### Overview
@ -41,3 +51,19 @@ which in turn will finally forward it to the `user`.
* Build (e.g. with `build-install-all.sh`)
* Put the generated `forward-0.1.war` in a servlet container (e.g. Jetty).
* Launch the `reverse-0.1.jar` on your host.
### Migration (WIP)
#### How would we even test this?
* one instance of `foward`
* one instance of `reverse`
* one instance of `mirror`
* `reverse` uses `mirror` as app
* we call `forward` and see `mirror`
#### Steps TODO
* migrate `forward` to Spring ✅
* parametrize URLs
* check if `mirror` works
*

@ -0,0 +1,19 @@
#!/bin/bash
cd ./helper &&
mvn clean install &&
cd ../mirror &&
./build.sh &&
cd ../reverse &&
./build.sh &&
cd ../forward &&
./build.sh &

@ -1,13 +0,0 @@
#!/bin/bash
cd ./forward
./install-locally.sh
cd ..
cd ./helper
./install-locally.sh
cd ..
cd ./mirror
./install-locally.sh
cd ..
cd ./reverse
./install-locally.sh
cd ..

@ -0,0 +1,30 @@
version: '3'
services:
forward:
container_name: forward
image: io42630/forward:0.1
ports:
- "42001:8080"
- "42002:5005"
# See .env for vars.
reverse:
container_name: reverse
image: io42630/reverse:0.1
ports:
- "42005:8090"
- "42006:5005"
environment:
- forward.url=${FORWARD_URL}
- app.url=${APP_URL}
mirror:
container_name: mirror
image: io42630/mirror:0.1
ports:
- "42003:8080"
- "42004:5005"

@ -0,0 +1,3 @@
#!/bin/bash
docker compose down &

@ -0,0 +1,3 @@
#!/bin/bash
docker compose up --force-recreate &

@ -1,5 +0,0 @@
#### About
* Uses `com.olexyn.min.http.server.MinJettyServer` to host the servlets.
* Where to adjust the parameters:
* for `forward` -> `EmbeddedR`
* for `reverse` -> `RunAll`

@ -1,208 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.olexyn.misp.embedded</groupId>
<artifactId>embedded</artifactId>
<version>0.1</version>
<name>embedded</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.11</maven.compiler.source>
<maven.compiler.target>1.11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.olexyn.min.http.server</groupId>
<artifactId>min-http-server</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.helper</groupId>
<artifactId>misp-helper</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-servlet</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all</artifactId>
<version>9.4.28.v20200408</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.mirror</groupId>
<artifactId>misp-mirror</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.rev</groupId>
<artifactId>misp-rev</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.reverse</groupId>
<artifactId>reverse</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.fwd</groupId>
<artifactId>misp-fwd</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.forward</groupId>
<artifactId>forward</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.olexyn.misp.mirror</groupId>
<artifactId>mirror</artifactId>
<version>0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

@ -1,28 +0,0 @@
package com.olexyn.misp.embedded;
import com.olexyn.min.http.server.MinJettyServer;
import com.olexyn.misp.forward.Forward;
import com.olexyn.misp.mirror.Mirror;
public class EmbeddedR implements Runnable {
@Override
public void run() {
MinJettyServer server = new MinJettyServer();
server.PORT = 8090;
server.MAX_THREADS = 100;
server.MIN_THREADS = 10;
server.IDLE_TIMEOUT = 120;
server.addServletWithMapping("/mirror", Mirror.class);
server.addServletWithMapping("/app", Mirror.class);
server.addServletWithMapping("/forward", Forward.class);
server.start();
}
}

@ -1,23 +0,0 @@
package com.olexyn.misp.embedded;
import com.olexyn.misp.reverse.Reverse;
public class RunAll {
public static void main(String... args) throws InterruptedException {
Thread embeddedT = new Thread(new EmbeddedR());
embeddedT.start();
Thread.sleep(2000);
Reverse reverse = new Reverse();
reverse.FORWARD_URL = "http://localhost:8090/forward";
reverse.APP_URL = "http://localhost:8090/app";
//reverse.APP_URL = "https://olexyn.com/wp/";
Thread reverseT = new Thread(reverse);
reverseT.start();
}
}

@ -1,4 +1,4 @@
FROM eclipse-temurin:17-alpine
COPY /target/forward-0.1.jar /usr/local/lib/forward.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/forward.jar"]
EXPOSE 8080 5005
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-jar","/usr/local/lib/forward.jar"]

@ -1,9 +0,0 @@
#### About
The `forward` servlet.
#### Deploy (TODO)
* Run `install-locally.sh`
* Find the `forward-0.1.war` in `./target`
* Copy it to `tomcat/webapps`.
* Assuming tomcat runs at `http://localhost:9090`
* Then the servlet will be at `http://localhost:9090/forward-0.1/mirror`

@ -26,7 +26,7 @@ public class Forward {
private final Map<Long, Ride> loaded = new HashMap<>();
@GetMapping
@GetMapping("/")
public void doGet(HttpServletRequest request, HttpServletResponse response) {
Thread handleGetRequestThread = new Thread(() -> handleGetRequest(request, response));
@ -102,7 +102,7 @@ public class Forward {
}
@PostMapping
@PostMapping("/")
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String payload = IOUtils.toString(request.getReader());

@ -0,0 +1,6 @@
POST http://localhost:42001
Content-Type: application/json
{
"hello": "world"
}

@ -1,26 +0,0 @@
#!/bin/bash
tomcat_webapps="${HOME}/app/tomcat/webapps"
jetty_webapps="${HOME}/app/jetty9.4/webapps"
webapps=$jetty_webapps
cwd=$(pwd)
/home/user/app/tomcat/bin/shutdown.sh
echo "================"
echo "END TOMCAT STOP "
echo "================"
cp -v "${cwd}/misp-mirror/target/misp-mirror-0.1.war" "${webapps}"
cp -v "${cwd}/misp-rev/target/misp-rev-0.1.war" "${webapps}"
cp -v "${cwd}/test-proxy/target/test-proxy-0.1.war" "${webapps}"
echo "================"
echo "END COPY"
echo "================"
# /home/user/app/tomcat/bin/startup.sh
echo "================"
echo "END TOMCAT START "
echo "================"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

@ -1,340 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="13.3">
<zoom_level>10</zoom_level>
<element>
<id>UMLClass</id>
<coordinates>
<x>910</x>
<y>50</y>
<w>90</w>
<h>30</h>
</coordinates>
<panel_attributes>inet
lt=-</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>680</x>
<y>50</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>webhost
lt=-
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>910</x>
<y>90</y>
<w>90</w>
<h>30</h>
</coordinates>
<panel_attributes>user
bg=#90CAF9</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>680</x>
<y>90</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>mispbridge
bg=#B39DDB
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>410</x>
<y>140</y>
<w>300</w>
<h>50</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
POST (Ride)
Generated by Loop</panel_attributes>
<additional_attributes>280.0;20.0;10.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>760</x>
<y>180</y>
<w>200</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
GET (Request)
fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;20.0;180.0;20.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>350</x>
<y>90</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>mispclient
bg=#B39DDB
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>410</x>
<y>290</y>
<w>300</w>
<h>50</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
GET (Ride)(Request)
(Data)</panel_attributes>
<additional_attributes>280.0;20.0;10.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>760</x>
<y>310</y>
<w>190</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;.
OK (Data)
fg=#1E88E5</panel_attributes>
<additional_attributes>170.0;20.0;10.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>410</x>
<y>350</y>
<w>300</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;.
OK (Ride)</panel_attributes>
<additional_attributes>10.0;20.0;280.0;20.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>150</x>
<y>90</y>
<w>80</w>
<h>30</h>
</coordinates>
<panel_attributes>app
bg=#90CAF9</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>200</x>
<y>220</y>
<w>200</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
GET (Request)
fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;20.0;180.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>200</x>
<y>270</y>
<w>200</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;.
OK (Data)
fg=#1E88E5</panel_attributes>
<additional_attributes>180.0;20.0;10.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>410</x>
<y>200</y>
<w>300</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;.
OK (Ride)(Request)</panel_attributes>
<additional_attributes>10.0;20.0;280.0;20.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>150</x>
<y>50</y>
<w>300</w>
<h>30</h>
</coordinates>
<panel_attributes>localhost
lt=-</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>120</x>
<y>20</y>
<w>910</w>
<h>400</h>
</coordinates>
<panel_attributes>
lt=..
layer=-10</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>940</x>
<y>110</y>
<w>30</w>
<h>310</h>
</coordinates>
<panel_attributes>lt=-
fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>180</x>
<y>110</y>
<w>30</w>
<h>310</h>
</coordinates>
<panel_attributes>lt=-
fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>930</x>
<y>200</y>
<w>40</w>
<h>130</h>
</coordinates>
<panel_attributes>
bg=#F6F6F6
transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>170</x>
<y>240</y>
<w>40</w>
<h>50</h>
</coordinates>
<panel_attributes>
bg=#F6F6F6
transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>720</x>
<y>110</y>
<w>30</w>
<h>310</h>
</coordinates>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>390</x>
<y>110</y>
<w>30</w>
<h>310</h>
</coordinates>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>380</x>
<y>160</y>
<w>40</w>
<h>210</h>
</coordinates>
<panel_attributes>
bg=#F6F6F6
transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>690</x>
<y>160</y>
<w>40</w>
<h>60</h>
</coordinates>
<panel_attributes>
bg=#F6F6F6
transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>690</x>
<y>310</y>
<w>40</w>
<h>60</h>
</coordinates>
<panel_attributes>
bg=#F6F6F6
transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>730</x>
<y>200</y>
<w>40</w>
<h>130</h>
</coordinates>
<panel_attributes>
bg=#F6F6F6
transparency=0
layer=4</panel_attributes>
<additional_attributes/>
</element>
</diagram>

@ -1,4 +1,4 @@
FROM eclipse-temurin:17-alpine
COPY /target/mirror-0.1.jar /usr/local/lib/mirror-0.1.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/mirror-0.1.jar"]
EXPOSE 8080 5005
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-jar","/usr/local/lib/mirror-0.1.jar"]

@ -1,4 +1,4 @@
FROM eclipse-temurin:17-alpine
COPY /target/reverse-0.1-jar-with-dependencies.jar /usr/local/lib/reverse-0.1-jar-with-dependencies.jar
EXPOSE 8090
ENTRYPOINT ["java","-jar","/usr/local/lib/reverse-0.1-jar-with-dependencies.jar"]
EXPOSE 8090 5005
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-jar","/usr/local/lib/reverse-0.1-jar-with-dependencies.jar"]

@ -6,8 +6,8 @@ import com.olexyn.misp.reverse.runnable.JourneyGeneratorR;
public class Reverse implements Runnable {
public String FORWARD_URL = "http://localhost:8090/forward";
public String APP_URL = "http://localhost:8090/app";
public static final String FORWARD_URL = System.getenv("forward.url");
public static final String APP_URL = System.getenv("app.url");
public void start() {

@ -5,6 +5,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
@ -13,7 +14,7 @@ public class Tools {
public static String send(String method, String urlString, String body) throws IOException {
URL url = new URL(urlString);
URL url = URI.create(urlString).toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(method);

@ -5,6 +5,8 @@ import com.olexyn.misp.reverse.Tools;
import lombok.Getter;
import org.json.JSONObject;
import static com.olexyn.misp.reverse.Reverse.FORWARD_URL;
public class CheckSuppyR implements Runnable {
@Getter
@ -25,7 +27,7 @@ public class CheckSuppyR implements Runnable {
JSONObject obj = new JSONObject().put("available", 0);
try {
String result = Tools.send("POST", reverse.FORWARD_URL, obj.toString());
String result = Tools.send("POST", FORWARD_URL, obj.toString());
JSONObject resultObj = new JSONObject(result);

Loading…
Cancel
Save