Compare commits

..

10 Commits

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`, 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`. 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> <br>
### Overview ### Overview
@ -19,13 +29,6 @@ which in turn will finally forward it to the `user`.
#### What does not work: #### What does not work:
* Handling 301 (Moved Permanently). * Handling 301 (Moved Permanently).
* Forwarding PUT requests - if needed, the logic might be quickly added to `doPut` in `forward`. * Forwarding PUT requests - if needed, the logic might be quickly added to `doPut` in `forward`.
* The `forward.war` has issues - meanwhile run `forward` embedded with Jetty.
<br>
### Demo
[![IMAGE ALT TEXT](http://img.youtube.com/vi/WcSvzeu6nKo/0.jpg)](https://youtu.be/WcSvzeu6nKo "misp Demo")
<br> <br>
@ -41,3 +44,24 @@ which in turn will finally forward it to the `user`.
* Build (e.g. with `build-install-all.sh`) * Build (e.g. with `build-install-all.sh`)
* Put the generated `forward-0.1.war` in a servlet container (e.g. Jetty). * Put the generated `forward-0.1.war` in a servlet container (e.g. Jetty).
* Launch the `reverse-0.1.jar` on your host. * Launch the `reverse-0.1.jar` on your host.
### Security Considerations
* user might access other resources (i.e. another app)
* user might manipulate the `app` URL
* the URL of the app is provided as ENV
* `reverse` calls said URL.
* the URL is never transmitted over the network
* the `Ride` object which `forward` receives contains only the _original_ request and the response payload from `app`
* user might use redirect magic
* user can not manipulate URL directly
* but if the server is not properly configured, the user might exploit that
* thus only expose local servers that you consider hardened.
* TODO possibly do some Header editing, before calling `app` URL in `Tools.send()`
### Considerations How to add multiple host mapping
* keep `forward` agnostic
* supply parameter to `/` indicating desired target service
* in `reverse`
* maintain a map of desired service -> URL

@ -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,31 @@
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}
- check.supply.interval.ms=${CHECK_SUPPLY_INTERVAL_MS}
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();
}
}

@ -4,49 +4,12 @@
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>910</x> <x>1420</x>
<y>50</y> <y>610</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> <w>100</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
<panel_attributes>mispbridge <panel_attributes>forward
bg=#B39DDB bg=#B39DDB
layer=-1</panel_attributes> layer=-1</panel_attributes>
<additional_attributes/> <additional_attributes/>
@ -54,85 +17,46 @@ layer=-1</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>410</x> <x>1170</x>
<y>140</y> <y>680</y>
<w>300</w> <w>280</w>
<h>50</h> <h>50</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;&lt;&lt;- <panel_attributes>lt=&lt;&lt;&lt;-
POST (Ride) POST (Ride)
Generated by Loop</panel_attributes> Generated by Loop</panel_attributes>
<additional_attributes>280.0;20.0;10.0;20.0</additional_attributes> <additional_attributes>260.0;20.0;10.0;20.0</additional_attributes>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>760</x> <x>1170</x>
<y>180</y> <y>830</y>
<w>200</w> <w>280</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> <h>50</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;&lt;&lt;- <panel_attributes>lt=&lt;&lt;&lt;-
GET (Ride)(Request) POST (Ride)(Request)
(Data)</panel_attributes> (Data)</panel_attributes>
<additional_attributes>280.0;20.0;10.0;20.0</additional_attributes> <additional_attributes>260.0;20.0;10.0;20.0</additional_attributes>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>760</x> <x>1170</x>
<y>310</y> <y>880</y>
<w>190</w> <w>280</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> <h>40</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;&lt;&lt;. <panel_attributes>lt=&lt;&lt;&lt;.
OK (Ride)</panel_attributes> OK (Ride)</panel_attributes>
<additional_attributes>10.0;20.0;280.0;20.0</additional_attributes> <additional_attributes>10.0;20.0;260.0;20.0</additional_attributes>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>150</x> <x>760</x>
<y>90</y> <y>610</y>
<w>80</w> <w>80</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
@ -143,97 +67,116 @@ bg=#90CAF9</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>200</x> <x>800</x>
<y>220</y> <y>760</y>
<w>200</w> <w>400</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;&lt;&lt;- <panel_attributes>lt=&lt;&lt;&lt;-
GET (Request) GET (Request)
fg=#1E88E5</panel_attributes> fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;20.0;180.0;20.0</additional_attributes> <additional_attributes>10.0;20.0;380.0;20.0</additional_attributes>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>200</x> <x>800</x>
<y>270</y> <y>810</y>
<w>200</w> <w>400</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;&lt;&lt;. <panel_attributes>lt=&lt;&lt;&lt;.
OK (Data) OK (Data)
fg=#1E88E5</panel_attributes> fg=#1E88E5</panel_attributes>
<additional_attributes>180.0;20.0;10.0;20.0</additional_attributes> <additional_attributes>380.0;20.0;10.0;20.0</additional_attributes>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>410</x> <x>1170</x>
<y>200</y> <y>740</y>
<w>300</w> <w>280</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;&lt;&lt;. <panel_attributes>lt=&lt;&lt;&lt;.
OK (Ride)(Request)</panel_attributes> OK (Ride)(Request)</panel_attributes>
<additional_attributes>10.0;20.0;280.0;20.0</additional_attributes> <additional_attributes>10.0;20.0;260.0;20.0</additional_attributes>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>150</x> <x>630</x>
<y>50</y> <y>320</y>
<w>300</w> <w>1330</w>
<h>30</h> <h>640</h>
</coordinates> </coordinates>
<panel_attributes>localhost <panel_attributes>
lt=-</panel_attributes> lt=..
layer=-10</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>120</x> <x>1430</x>
<y>20</y> <y>700</y>
<w>910</w> <w>80</w>
<h>400</h> <h>40</h>
</coordinates> </coordinates>
<panel_attributes> <panel_attributes>Available
lt=.. Rides
layer=-10</panel_attributes> bg=#FFF59D
transparency=0</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<id>Relation</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>940</x> <x>1430</x>
<y>110</y> <y>740</y>
<w>30</w> <w>80</w>
<h>310</h> <h>110</h>
</coordinates> </coordinates>
<panel_attributes>lt=- <panel_attributes>Booked
fg=#1E88E5</panel_attributes> Rides
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes> bg=#E6EE9C
transparency=0
layer=1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1430</x>
<y>850</y>
<w>80</w>
<h>60</h>
</coordinates>
<panel_attributes>Loaded
Rides
bg=#A5D6A7
transparency=0</panel_attributes>
<additional_attributes/>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>180</x> <x>790</x>
<y>110</y> <y>630</y>
<w>30</w> <w>30</w>
<h>310</h> <h>320</h>
</coordinates> </coordinates>
<panel_attributes>lt=- <panel_attributes>lt=-
fg=#1E88E5</panel_attributes> fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes> <additional_attributes>10.0;10.0;10.0;300.0</additional_attributes>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>930</x> <x>790</x>
<y>200</y> <y>780</y>
<w>40</w> <w>20</w>
<h>130</h> <h>50</h>
</coordinates> </coordinates>
<panel_attributes> <panel_attributes>
bg=#F6F6F6 bg=#F6F6F6
@ -241,100 +184,211 @@ transparency=0
layer=4</panel_attributes> layer=4</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element>
<id>Relation</id>
<coordinates>
<x>1460</x>
<y>630</y>
<w>30</w>
<h>320</h>
</coordinates>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;300.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1420</x>
<y>340</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>forward
bg=#B39DDB
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>860</x>
<y>340</y>
<w>410</w>
<h>30</h>
</coordinates>
<panel_attributes>reverse
bg=#B39DDB
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>170</x> <x>1430</x>
<y>240</y> <y>450</y>
<w>40</w> <w>80</w>
<h>50</h> <h>50</h>
</coordinates> </coordinates>
<panel_attributes> <panel_attributes>Available
bg=#F6F6F6 Rides
transparency=0 bg=#FFF59D
layer=4</panel_attributes> transparency=0</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>720</x> <x>1460</x>
<y>110</y> <y>360</y>
<w>30</w> <w>30</w>
<h>310</h> <h>180</h>
</coordinates> </coordinates>
<panel_attributes>lt=- <panel_attributes>lt=-
fg=#5E35B1 fg=#5E35B1
layer=-4</panel_attributes> layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes> <additional_attributes>10.0;10.0;10.0;160.0</additional_attributes>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>390</x> <x>1170</x>
<y>110</y> <y>440</y>
<w>30</w> <w>280</w>
<h>310</h> <h>40</h>
</coordinates> </coordinates>
<panel_attributes>lt=- <panel_attributes>lt=&lt;&lt;&lt;-
fg=#5E35B1 POST (Available)</panel_attributes>
layer=-4</panel_attributes> <additional_attributes>260.0;20.0;10.0;20.0</additional_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes> </element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>470</y>
<w>280</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;.
OK (# Available)</panel_attributes>
<additional_attributes>10.0;20.0;260.0;20.0</additional_attributes>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>380</x> <x>860</x>
<y>160</y> <y>390</y>
<w>40</w> <w>140</w>
<h>210</h> <h>40</h>
</coordinates> </coordinates>
<panel_attributes> <panel_attributes>Reverse.main()
bg=#F6F6F6 bg=#FFF59D
transparency=0 transparency=0</panel_attributes>
layer=4</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>690</x> <x>1090</x>
<y>160</y> <y>390</y>
<w>40</w> <w>150</w>
<h>60</h> <h>40</h>
</coordinates> </coordinates>
<panel_attributes> <panel_attributes>CheckSuppyR
bg=#F6F6F6 (Runnable)
transparency=0 bg=#FFF59D
layer=4</panel_attributes> transparency=0</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>690</x> <x>1090</x>
<y>310</y> <y>550</y>
<w>40</w> <w>150</w>
<h>60</h> <h>40</h>
</coordinates> </coordinates>
<panel_attributes> <panel_attributes>JourneyGeneratorR
bg=#F6F6F6 (Runnable)
transparency=0 bg=#FFF59D
layer=4</panel_attributes> transparency=0</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>730</x> <x>1090</x>
<y>200</y> <y>640</y>
<w>40</w> <w>150</w>
<h>130</h> <h>40</h>
</coordinates> </coordinates>
<panel_attributes> <panel_attributes>JourneyR
bg=#F6F6F6 (Runnable)
transparency=0 bg=#FFF59D
layer=4</panel_attributes> transparency=0</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element>
<id>Relation</id>
<coordinates>
<x>990</x>
<y>390</y>
<w>120</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
1</panel_attributes>
<additional_attributes>100.0;20.0;10.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>990</x>
<y>410</y>
<w>120</w>
<h>180</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
1</panel_attributes>
<additional_attributes>100.0;160.0;10.0;10.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>580</y>
<w>80</w>
<h>80</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
1-1000</panel_attributes>
<additional_attributes>10.0;60.0;10.0;10.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>670</y>
<w>30</w>
<h>280</h>
</coordinates>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;260.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1170</x>
<y>420</y>
<w>30</w>
<h>130</h>
</coordinates>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;110.0</additional_attributes>
</element>
</diagram> </diagram>

@ -0,0 +1,4 @@
FROM eclipse-temurin:17-alpine
COPY /target/forward-0.1.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`

@ -0,0 +1,9 @@
#!/bin/bash
mvn clean install &&
docker build -t io42630/forward:0.1 .

@ -1,10 +0,0 @@
#!/bin/bash
version="0.1"
file="target/forward-${version}.war"
groupId="com.olexyn.misp.forward"
artifactId="forward"
mvn package
mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=war -DgeneratePom=true

@ -1,124 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?> <?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">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <modelVersion>4.0.0</modelVersion>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent>
<modelVersion>4.0.0</modelVersion> <groupId>com.olexyn</groupId>
<artifactId>zeeroot</artifactId>
<groupId>com.olexyn.misp.forward</groupId> <version>spring-boot-jdk17-0.1</version>
<artifactId>forward</artifactId> </parent>
<version>0.1</version> <groupId>com.olexyn.misp</groupId>
<packaging>war</packaging> <artifactId>forward</artifactId>
<version>0.1</version>
<name>forward Maven Webapp</name> <packaging>jar</packaging>
<!-- FIXME change it to the project's website --> <name>forward</name>
<url>http://www.example.com</url> <dependencyManagement>
<dependencies>
<properties> <dependency>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <groupId>com.olexyn</groupId>
<maven.compiler.source>11</maven.compiler.source> <artifactId>zeebom</artifactId>
<maven.compiler.target>11</maven.compiler.target> <version>1.1.1</version>
</properties> <type>pom</type>
<scope>import</scope>
<dependencies> </dependency>
<dependency> </dependencies>
<groupId>junit</groupId> </dependencyManagement>
<artifactId>junit</artifactId> <dependencies>
<version>4.11</version> <dependency>
<scope>test</scope> <groupId>com.olexyn.misp</groupId>
</dependency> <artifactId>helper</artifactId>
<dependency> <version>0.2</version>
<groupId>com.olexyn.misp.helper</groupId> <scope>compile</scope>
<artifactId>helper</artifactId> </dependency>
<version>0.1</version> <dependency>
<scope>compile</scope> <groupId>commons-io</groupId>
</dependency> <artifactId>commons-io</artifactId>
<dependency> </dependency>
<groupId>commons-io</groupId> <dependency>
<artifactId>commons-io</artifactId> <groupId>org.json</groupId>
<version>2.6</version> <artifactId>json</artifactId>
<scope>compile</scope> </dependency>
</dependency> <dependency>
<dependency> <groupId>org.springframework.boot</groupId>
<groupId>org.eclipse.jetty.orbit</groupId> <artifactId>spring-boot-starter-web</artifactId>
<artifactId>javax.servlet</artifactId> </dependency>
<version>3.0.0.v201112011016</version> <dependency>
<scope>compile</scope> <groupId>org.springframework.boot</groupId>
</dependency> <artifactId>spring-boot-autoconfigure</artifactId>
<dependency> </dependency>
<groupId>org.json</groupId> <dependency>
<artifactId>json</artifactId> <groupId>org.springframework.boot</groupId>
<version>20190722</version> <artifactId>spring-boot-starter-tomcat</artifactId>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <!-- for some godforsaken reason this is required. -->
<artifactId>jetty-server</artifactId> <groupId>org.aspectj</groupId>
<version>9.4.28.v20200408</version> <artifactId>aspectjweaver</artifactId>
</dependency> </dependency>
<dependency> </dependencies>
<groupId>com.olexyn.min.http.server</groupId>
<artifactId>min-http-server</artifactId>
<version>0.1</version>
<scope>compile</scope>
</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-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.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>9.4.28.v20200408</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_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-war-plugin</artifactId>
<version>3.2.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>
</plugins>
</pluginManagement>
</build>
</project> </project>

@ -0,0 +1,13 @@
package com.olexyn.misp.forward;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class App {
public static void main(String... args) {
SpringApplication.run(App.class, args);
}
}

@ -1,12 +1,14 @@
package com.olexyn.misp.forward; package com.olexyn.misp.forward.web;
import com.olexyn.misp.helper.JsonHelper; import com.olexyn.misp.helper.JsonHelper;
import com.olexyn.misp.helper.Ride; import com.olexyn.misp.helper.Ride;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.ServletInputStream; import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
@ -14,7 +16,10 @@ import java.io.PrintWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class Forward extends HttpServlet { import static com.olexyn.misp.helper.Constants.AVAILABLE;
@RestController
public class Forward {
private static final long WAIT_FOR_USER_REQUEST = 500; private static final long WAIT_FOR_USER_REQUEST = 500;
@ -23,10 +28,10 @@ public class Forward extends HttpServlet {
private final Map<Long, Ride> loaded = new HashMap<>(); private final Map<Long, Ride> loaded = new HashMap<>();
@Override @GetMapping("/")
public void doGet(HttpServletRequest request, HttpServletResponse response) { public void doGet(HttpServletRequest request, HttpServletResponse response) {
Thread handleGetRequestThread = new Thread(() -> { handleGetRequest(request, response); }); Thread handleGetRequestThread = new Thread(() -> handleGetRequest(request, response));
handleGetRequestThread.setName("handleGetRequestThread"); handleGetRequestThread.setName("handleGetRequestThread");
handleGetRequestThread.start(); handleGetRequestThread.start();
try {handleGetRequestThread.join(); } catch (InterruptedException ignored) { } try {handleGetRequestThread.join(); } catch (InterruptedException ignored) { }
@ -40,7 +45,7 @@ public class Forward extends HttpServlet {
* Wait for Ride to appear in `loaded`. This happens due to POST (Ride)(Request)(Data) from `reverse`. * Wait for Ride to appear in `loaded`. This happens due to POST (Ride)(Request)(Data) from `reverse`.
* Finally send OK (Data) to `user`. * Finally send OK (Data) to `user`.
*/ */
protected void handleGetRequest(HttpServletRequest request, HttpServletResponse response) { private void handleGetRequest(HttpServletRequest request, HttpServletResponse response) {
try { try {
final Ride ride; final Ride ride;
@ -56,8 +61,8 @@ public class Forward extends HttpServlet {
} }
// ride exists only locally, thus safe // ride exists only locally, thus safe
ride = available.entrySet().iterator().next().getValue(); ride = available.entrySet().iterator().next().getValue();
// ride exists only in "available", access through which is sync, thus safe // ride exists only in AVAILABLE, access through which is sync, thus safe
available.remove(ride.getID()); available.remove(ride.getId());
// needed because POST (Ride) wait()s // needed because POST (Ride) wait()s
available.notify(); available.notify();
} }
@ -65,7 +70,7 @@ public class Forward extends HttpServlet {
synchronized (booked) { synchronized (booked) {
// ride exists only locally, thus safe // ride exists only locally, thus safe
booked.put(ride.getID(), ride); booked.put(ride.getId(), ride);
// ride exists only in "booked", access through which is sync, thus safe // ride exists only in "booked", access through which is sync, thus safe
ride.setRequest(parsedRequest); ride.setRequest(parsedRequest);
// POST (Ride) wait()s // POST (Ride) wait()s
@ -75,7 +80,7 @@ public class Forward extends HttpServlet {
synchronized (loaded) { synchronized (loaded) {
while (!loaded.containsKey(ride.getID())) { while (!loaded.containsKey(ride.getId())) {
loaded.notify(); loaded.notify();
if (loaded.size() > 0) { break; } if (loaded.size() > 0) { break; }
@ -86,7 +91,7 @@ public class Forward extends HttpServlet {
// what if ride exists in another map, e.g. "available' // what if ride exists in another map, e.g. "available'
// in that case illegal access is possible // in that case illegal access is possible
// be carefull to removing ride from all other references, when adding it to "loaded". // be carefull to removing ride from all other references, when adding it to "loaded".
ride.setData(loaded.remove(ride.getID()).getData()); ride.setData(loaded.remove(ride.getId()).getData());
} }
response.setStatus(200); response.setStatus(200);
@ -99,7 +104,7 @@ public class Forward extends HttpServlet {
} }
@Override @PostMapping("/")
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String payload = IOUtils.toString(request.getReader()); String payload = IOUtils.toString(request.getReader());
@ -108,7 +113,7 @@ public class Forward extends HttpServlet {
JSONObject obj = new JSONObject(payload); JSONObject obj = new JSONObject(payload);
if (obj.has("available")) { if (obj.has(AVAILABLE)) {
Thread handlePostAvailableT = new Thread(() -> { handlePostAvailable(request, response); }); Thread handlePostAvailableT = new Thread(() -> { handlePostAvailable(request, response); });
handlePostAvailableT.setName("handlePostAvailableT"); handlePostAvailableT.setName("handlePostAvailableT");
handlePostAvailableT.start(); handlePostAvailableT.start();
@ -126,7 +131,7 @@ public class Forward extends HttpServlet {
} }
if (obj.has("id") && hasData) { if (obj.has("id") && hasData) {
Thread handlePostRideRequestDataT = new Thread(() -> { handlePostRideRequestData(request, response, payload); }); Thread handlePostRideRequestDataT = new Thread(() -> { handlePostRideRequestData(payload); });
handlePostRideRequestDataT.setName("handlePostRideRequestDataT"); handlePostRideRequestDataT.setName("handlePostRideRequestDataT");
handlePostRideRequestDataT.start(); handlePostRideRequestDataT.start();
try {handlePostRideRequestDataT.join(); } catch (InterruptedException ignored) { } try {handlePostRideRequestDataT.join(); } catch (InterruptedException ignored) { }
@ -138,16 +143,16 @@ public class Forward extends HttpServlet {
* Handle POST (Ride)(Request)(Data) * Handle POST (Ride)(Request)(Data)
* Move the Ride from `booked` to `loaded`, so it can be picked up by OK (Data) of GET (Request). * Move the Ride from `booked` to `loaded`, so it can be picked up by OK (Data) of GET (Request).
*/ */
protected void handlePostRideRequestData(HttpServletRequest request, HttpServletResponse response, String payload) { private void handlePostRideRequestData(String payload) {
final Ride ride = new Ride(payload); final Ride ride = new Ride(payload);
synchronized (booked) { synchronized (booked) {
booked.remove(ride.getID()); booked.remove(ride.getId());
} }
synchronized (loaded) { synchronized (loaded) {
loaded.put(ride.getID(), ride); loaded.put(ride.getId(), ride);
loaded.notify(); loaded.notify();
} }
} }
@ -157,17 +162,17 @@ public class Forward extends HttpServlet {
* Handle POST (Available). * Handle POST (Available).
* Send current # of available Rides to `reverse`. * Send current # of available Rides to `reverse`.
*/ */
protected void handlePostAvailable(HttpServletRequest request, HttpServletResponse response) { private void handlePostAvailable(HttpServletRequest req, HttpServletResponse res) {
JSONObject obj = new JSONObject().put("available", available.size()); JSONObject obj = new JSONObject().put(AVAILABLE, available.size());
response.setStatus(200); res.setStatus(200);
try { try {
PrintWriter writer = response.getWriter(); PrintWriter writer = res.getWriter();
writer.write(obj.toString()); writer.write(obj.toString());
writer.flush(); writer.flush();
writer.close(); writer.close();
} catch (Exception ignored) {} } catch (Exception ignored) { /* ignored */ }
} }
@ -177,24 +182,24 @@ public class Forward extends HttpServlet {
* Wait till a GET (Request) arrives from `user`. * Wait till a GET (Request) arrives from `user`.
* Return OK (Ride)(Request) to `reverse`. * Return OK (Ride)(Request) to `reverse`.
*/ */
protected void handlePostRide(HttpServletRequest request, HttpServletResponse response, String payload) { private void handlePostRide(HttpServletRequest request, HttpServletResponse response, String payload) {
try { try {
final Ride ride = new Ride(payload); final Ride ride = new Ride(payload);
synchronized (available) { synchronized (available) {
available.put(ride.getID(), ride); available.put(ride.getId(), ride);
available.notify(); available.notify();
} }
// ID is final/threadsafe // ID is final/threadsafe
while (!(booked.containsKey(ride.getID()))) { while (!(booked.containsKey(ride.getId()))) {
Thread.sleep(WAIT_FOR_USER_REQUEST); Thread.sleep(WAIT_FOR_USER_REQUEST);
} }
synchronized (booked) { synchronized (booked) {
// ride = booked.get(ride.getID()); // ride = booked.get(ride.getId());
ride.setRequest(booked.get(ride.getID()).getRequest()); ride.setRequest(booked.get(ride.getId()).getRequest());
} }
response.setStatus(200); response.setStatus(200);
@ -203,6 +208,6 @@ public class Forward extends HttpServlet {
writer.flush(); writer.flush();
writer.close(); writer.close();
} catch (Exception ignored) {} } catch (Exception ignored) { /* ignored */ }
} }
} }

@ -1,22 +0,0 @@
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>misp-fwd</display-name>
<servlet>
<servlet-name>misp-fwd</servlet-name>
<servlet-class>com.olexyn.misp.forward.Forward</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>misp-fwd</servlet-name>
<url-pattern>/forward</url-pattern>
</servlet-mapping>
</web-app>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 617 B

@ -1,20 +0,0 @@
<html>
<head>
<title>misp-fwd</title>
</head>
<body bgcolor=white>
<table border="0">
<tr>
<td align=center>
<img src="images/io42630.png">
</td>
</tr>
<tr>
<td>
<h1>misp-fwd</h1>
</td>
</tr>
</table>
</body>
</html>

@ -0,0 +1,7 @@
#POST http://localhost:42001
GET http://node175251-env-1739619.sh1.hidora.com:11231/
Content-Type: application/json
{
"hello": "world"
}

@ -0,0 +1,7 @@
#POST http://localhost:42001
POST http://node175251-env-1739619.sh1.hidora.com:11231/
Content-Type: application/json
{
"hello": "world"
}

@ -0,0 +1,6 @@
### MISP Helper
#### Build
* do `mvn clean install` for local
* or `mvn deploy` for local nexus

@ -1,10 +0,0 @@
#!/bin/bash
version="0.1"
file="target/helper-${version}.jar"
groupId="com.olexyn.misp.helper"
artifactId="helper"
mvn package
mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=jar -DgeneratePom=true

@ -1,84 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?> <?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">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <modelVersion>4.0.0</modelVersion>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent>
<modelVersion>4.0.0</modelVersion> <groupId>com.olexyn</groupId>
<artifactId>zeeroot</artifactId>
<groupId>com.olexyn.misp.helper</groupId> <version>17.0.1</version>
<artifactId>helper</artifactId> </parent>
<version>0.1</version> <groupId>com.olexyn.misp</groupId>
<artifactId>helper</artifactId>
<name>helper</name> <version>0.2</version>
<name>helper</name>
<properties> <dependencyManagement>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <dependencies>
<maven.compiler.source>11</maven.compiler.source> <dependency>
<maven.compiler.target>11</maven.compiler.target> <groupId>com.olexyn</groupId>
</properties> <artifactId>zeebom</artifactId>
<version>1.1.1</version>
<dependencies> <type>pom</type>
<dependency> <scope>import</scope>
<groupId>junit</groupId> </dependency>
<artifactId>junit</artifactId> </dependencies>
<version>4.13.1</version> </dependencyManagement>
</dependency> <dependencies>
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20190722</version> </dependency>
</dependency> <dependency>
</dependencies> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<build> </dependencies>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<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>
<!-- see http://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>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
</plugin>
</plugins>
</reporting>
</project> </project>

@ -0,0 +1,9 @@
package com.olexyn.misp.helper;
public interface Constants {
String AVAILABLE = "available";
String POST = "POST";
String GET = "GET";
String EMPTY = "";
}

@ -1,5 +1,7 @@
package com.olexyn.misp.helper; package com.olexyn.misp.helper;
import lombok.Getter;
import lombok.Setter;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -8,50 +10,28 @@ public class Ride {
private static long count = 0L; private static long count = 0L;
final private Long id; @Getter
private Long id;
@Getter
@Setter
private String request; private String request;
@Getter
@Setter
private String data; private String data;
public Ride() { id = count++; }
public Ride() {
id = count++;
}
public Ride(String jsonString) { this(new JSONObject(jsonString)); } public Ride(String jsonString) { this(new JSONObject(jsonString)); }
public Ride(JSONObject obj) { public Ride(JSONObject obj) {
long _id; try { id = obj.getLong("id"); } catch (JSONException e) { id = count++; }
try { _id = obj.getLong("id"); } catch (JSONException e) { _id = count++; }
id = _id;
try { request = obj.getString("request"); } catch (JSONException e) { request = null; } try { request = obj.getString("request"); } catch (JSONException e) { request = null; }
try { data = obj.getString("data"); } catch (JSONException e) { data = null; } try { data = obj.getString("data"); } catch (JSONException e) { data = null; }
} }
public void setRequest(String request) {
this.request = request;
}
public void setData(String data) {
this.data = data;
}
public String getRequest() {
return this.request;
}
public String getData() {
return this.data;
}
public Long getID() {
return this.id;
}
public String json() { public String json() {
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
obj.put("id", id); obj.put("id", id);

@ -0,0 +1,29 @@
package com.olexyn.misp.helper;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
public class SymEnc {
public static void main(String[] args) throws Exception {
// Step 1: Generate a symmetric AES key (alternatively, you can specify your own)
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(128); // Key size
SecretKey secretKey = keyGenerator.generateKey();
// Step 2: Create and initialize the Cipher for AES encryption
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
// Step 3: Encrypt the string
String inputString = "Your String Here";
byte[] encryptedBytes = cipher.doFinal(inputString.getBytes());
// Convert encrypted bytes to Base64 to get a string representation
String encryptedString = Base64.getEncoder().encodeToString(encryptedBytes);
System.out.println("Encrypted String: " + encryptedString);
}
}

@ -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

@ -0,0 +1,4 @@
FROM eclipse-temurin:17-alpine
COPY /target/mirror-0.1.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"]

@ -0,0 +1,9 @@
#!/bin/bash
mvn clean install &&
docker build -t io42630/mirror:0.1 .

@ -1,10 +0,0 @@
#!/bin/bash
version="0.1"
file="target/misp-mirror-${version}.war"
groupId="com.olexyn.misp.mirror"
artifactId="misp-mirror"
mvn package
mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=war -DgeneratePom=true

@ -1,90 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?> <?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>
<parent>
<groupId>com.olexyn</groupId>
<artifactId>zeeroot</artifactId>
<version>spring-boot-jdk17-0.1</version>
</parent>
<groupId>com.olexyn.misp</groupId>
<artifactId>mirror</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>mirror</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.olexyn</groupId>
<artifactId>zeebom</artifactId>
<version>1.1.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.olexyn.misp</groupId>
<artifactId>helper</artifactId>
<version>0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<!-- for some godforsaken reason this is required. -->
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
</dependencies>
<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.mirror</groupId>
<artifactId>mirror</artifactId>
<version>0.1</version>
<packaging>war</packaging>
<name>mirror Maven Webapp</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>11</maven.compiler.source>
<maven.compiler.target>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.misp.helper</groupId>
<artifactId>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.orbit</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0.0.v201112011016</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_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-war-plugin</artifactId>
<version>3.2.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>
</plugins>
</pluginManagement>
</build>
</project> </project>

@ -0,0 +1,13 @@
package com.olexyn.misp.mirror;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class App {
public static void main(String... args) {
SpringApplication.run(App.class, args);
}
}

@ -1,9 +1,11 @@
package com.olexyn.misp.mirror; package com.olexyn.misp.mirror.web;
import com.olexyn.misp.helper.WebPrint; import com.olexyn.misp.helper.WebPrint;
import org.json.JSONObject; import org.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
@ -11,7 +13,8 @@ import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Mirror extends HttpServlet { @RestController
public class Mirror {
private final List<String> list = new ArrayList<>(); private final List<String> list = new ArrayList<>();
@ -32,7 +35,7 @@ public class Mirror extends HttpServlet {
} }
@Override @GetMapping("/")
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
addRequest(request); addRequest(request);
@ -53,13 +56,9 @@ public class Mirror extends HttpServlet {
} }
@Override @PostMapping("/")
public void doPost(HttpServletRequest request, HttpServletResponse response) { addRequest(request); } public void doPost(HttpServletRequest request, HttpServletResponse response) { addRequest(request); }
@Override
public void doPut(HttpServletRequest request, HttpServletResponse response) { addRequest(request); }
} }

@ -1,23 +0,0 @@
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>misp-mirror</display-name>
<servlet>
<servlet-name>misp-mirror</servlet-name>
<servlet-class>com.olexyn.misp.mirror.Mirror</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>misp-mirror</servlet-name>
<url-pattern>/mirror</url-pattern>
</servlet-mapping>
</web-app>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 617 B

@ -1,20 +0,0 @@
<html>
<head>
<title>misp-mirror</title>
</head>
<body bgcolor=white>
<table border="0">
<tr>
<td align=center>
<img src="images/io42630.png">
</td>
</tr>
<tr>
<td>
<h1>misp-mirror</h1>
</td>
</tr>
</table>
</body>
</html>

@ -0,0 +1,7 @@
#!/bin/bash
docker push io42630/forward:0.1

@ -0,0 +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 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"]

@ -1,3 +1,12 @@
### MISP Reverse
#### What it is...
* JAR / adapter / reverse proxy.
* connects to MISP forward server.
#### Overview #### Overview
* `Reverse` * `Reverse`
* Core * Core
@ -13,4 +22,8 @@
* Runnable * Runnable
* Journey fo a `Ride` through the App. * Journey fo a `Ride` through the App.
* `Tools` * `Tools`
* Performs the actual request. * Performs the actual request.
### Build
* maven clean package
* Dockerfile -> build

@ -0,0 +1,8 @@
#!/bin/bash
mvn clean install &&
docker build -t io42630/reverse:0.1 .

@ -1,11 +0,0 @@
#!/bin/bash
version="0.1"
artifactId="reverse"
file="target/${artifactId}-${version}.jar"
groupId="com.olexyn.misp.reverse"
mvn package
mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=jar -DgeneratePom=true

@ -3,84 +3,74 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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"> 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> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.olexyn.misp.reverse</groupId> <groupId>com.olexyn</groupId>
<artifactId>zeeroot</artifactId>
<version>17.0.1</version>
</parent>
<groupId>com.olexyn.misp</groupId>
<artifactId>reverse</artifactId> <artifactId>reverse</artifactId>
<version>0.1</version> <version>0.1</version>
<name>reverse</name> <name>reverse</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <dependencyManagement>
<maven.compiler.source>11</maven.compiler.source> <dependencies>
<maven.compiler.target>11</maven.compiler.target> <dependency>
</properties> <groupId>com.olexyn</groupId>
<artifactId>zeebom</artifactId>
<version>1.1.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>com.olexyn.misp.helper</groupId> <groupId>com.olexyn.misp</groupId>
<artifactId>helper</artifactId> <artifactId>helper</artifactId>
<version>0.1</version> <version>0.2</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20190722</version>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins>
<plugins> <plugin>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> <artifactId>maven-assembly-plugin</artifactId>
<plugin> <configuration>
<artifactId>maven-clean-plugin</artifactId> <archive>
<version>3.1.0</version> <manifest>
</plugin> <mainClass>com.olexyn.misp.reverse.Reverse</mainClass>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> </manifest>
<plugin> </archive>
<artifactId>maven-resources-plugin</artifactId> <descriptorRefs>
<version>3.0.2</version> <descriptorRef>jar-with-dependencies</descriptorRef>
</plugin> </descriptorRefs>
<plugin> </configuration>
<artifactId>maven-compiler-plugin</artifactId> <executions>
<version>3.8.0</version> <execution>
</plugin> <id>make-assembly</id> <!-- this is used for inheritance merges -->
<plugin> <phase>package</phase> <!-- bind to the packaging phase -->
<artifactId>maven-surefire-plugin</artifactId> <goals>
<version>2.22.1</version> <goal>single</goal>
</plugin> </goals>
<plugin> </execution>
<artifactId>maven-jar-plugin</artifactId> </executions>
<version>3.0.2</version> </plugin>
</plugin> </plugins>
<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> </build>
</project> </project>

@ -6,19 +6,23 @@ import com.olexyn.misp.reverse.runnable.JourneyGeneratorR;
public class Reverse implements Runnable { public class Reverse implements Runnable {
public String FORWARD_URL = "http://localhost:8090/forward"; public static final String FORWARD_URL = System.getenv("forward.url");
public String APP_URL = "http://localhost:8090/app"; public static final String APP_URL = System.getenv("app.url");
public static final int CHECK_SUPPLY_INTERVAL_MS = Integer.parseInt(System.getenv("check.supply.interval.ms"));
public static final int OVERHEAD = 8;
public static final int CHECK_DEPLETION_INTERVAL = 500;
public static final int START_NEW_JOURNEY_INTERVAL = 100;
public void start() { public void start() {
CheckSuppyR checkSuppyR = new CheckSuppyR(this); CheckSuppyR checkSuppyR = new CheckSuppyR();
Thread checkSupplyT = new Thread(checkSuppyR); Thread checkSupplyT = new Thread(checkSuppyR);
checkSupplyT.setName("checkSupplyT"); checkSupplyT.setName("checkSupplyT");
checkSupplyT.start(); checkSupplyT.start();
Thread journeyGeneratorT = new Thread(new JourneyGeneratorR(this, checkSuppyR)); Thread journeyGeneratorT = new Thread(new JourneyGeneratorR(checkSuppyR));
journeyGeneratorT.setName("journeyGeneratorT"); journeyGeneratorT.setName("journeyGeneratorT");
journeyGeneratorT.start(); journeyGeneratorT.start();
} }

@ -5,16 +5,19 @@ import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL; import java.net.URL;
public class Tools { public class Tools {
public static String send(String method, String urlString, String body) throws IOException { 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(); HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(method); connection.setRequestMethod(method);
connection.getHeaderFields(); // TODO
boolean getToForward = method.equals("GET") && urlString.contains("forward"); boolean getToForward = method.equals("GET") && urlString.contains("forward");

@ -1,34 +1,32 @@
package com.olexyn.misp.reverse.runnable; package com.olexyn.misp.reverse.runnable;
import com.olexyn.misp.reverse.Reverse;
import com.olexyn.misp.reverse.Tools; import com.olexyn.misp.reverse.Tools;
import lombok.Getter;
import org.json.JSONObject; import org.json.JSONObject;
import static com.olexyn.misp.helper.Constants.POST;
import static com.olexyn.misp.reverse.Reverse.CHECK_SUPPLY_INTERVAL_MS;
import static com.olexyn.misp.reverse.Reverse.FORWARD_URL;
import static com.olexyn.misp.helper.Constants.AVAILABLE;
public class CheckSuppyR implements Runnable { public class CheckSuppyR implements Runnable {
@Getter
private int available; private int available;
public int CHECK_SUPPLY_INTERVAL = 100;
private Reverse reverse;
public CheckSuppyR(Reverse reverse) {
this.reverse = reverse;
}
@Override @Override
public void run() { public void run() {
while (true) { while (true) {
JSONObject obj = new JSONObject().put("available", 0); JSONObject obj = new JSONObject().put(AVAILABLE, 0);
try { 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); JSONObject resultObj = new JSONObject(result);
available = resultObj.getInt("available"); available = resultObj.getInt(AVAILABLE);
Thread.sleep(CHECK_SUPPLY_INTERVAL); Thread.sleep(CHECK_SUPPLY_INTERVAL_MS);
} catch (Exception ignored) { } } catch (Exception ignored) { }
} }
@ -36,6 +34,4 @@ public class CheckSuppyR implements Runnable {
} }
public int getAvailable() { return available; }
} }

@ -1,31 +1,25 @@
package com.olexyn.misp.reverse.runnable; package com.olexyn.misp.reverse.runnable;
import com.olexyn.misp.reverse.Reverse; import static com.olexyn.misp.reverse.Reverse.CHECK_DEPLETION_INTERVAL;
import static com.olexyn.misp.reverse.Reverse.OVERHEAD;
import static com.olexyn.misp.reverse.Reverse.START_NEW_JOURNEY_INTERVAL;
public class JourneyGeneratorR implements Runnable { public class JourneyGeneratorR implements Runnable {
public int OVERHEAD = 8; private final CheckSuppyR checkSuppyR;
public int CHECK_DEPLETION_INTERVAL = 500;
public int START_NEW_JOURNEY_INTERVAL = 100;
private Reverse reverse; public JourneyGeneratorR(CheckSuppyR checkSuppyR) {
private CheckSuppyR checkSuppyR;
public JourneyGeneratorR(Reverse reverse , CheckSuppyR checkSuppyR) {
this.reverse = reverse;
this.checkSuppyR = checkSuppyR; this.checkSuppyR = checkSuppyR;
} }
@Override @Override
public void run() { public void run() {
int LIMIT = 0; int LIMIT = 0;
while (true) { while (true) {
try { try {
Thread journeyT = new Thread(new JourneyR(reverse)); Thread journeyT = new Thread(new JourneyR());
journeyT.setName("journeyT"); journeyT.setName("journeyT");
journeyT.start(); journeyT.start();
LIMIT++; LIMIT++;
@ -39,7 +33,7 @@ public class JourneyGeneratorR implements Runnable {
} }
// TODO rework this, so it sends - but not too much, and so it wais - but not too long. // TODO rework this, so it sends - but not too much, and so it wais - but not too long.
} catch (Exception ignored) { } } catch (Exception ignored) { /* ignored */ }
} }
} }
} }

@ -1,55 +1,49 @@
package com.olexyn.misp.reverse.runnable; package com.olexyn.misp.reverse.runnable;
import com.olexyn.misp.helper.Ride; import com.olexyn.misp.helper.Ride;
import com.olexyn.misp.reverse.Reverse;
import com.olexyn.misp.reverse.Tools; import com.olexyn.misp.reverse.Tools;
import java.io.IOException; import java.io.IOException;
public class JourneyR implements Runnable { import static com.olexyn.misp.helper.Constants.EMPTY;
import static com.olexyn.misp.helper.Constants.GET;
private Reverse reverse; import static com.olexyn.misp.helper.Constants.POST;
import static com.olexyn.misp.reverse.Reverse.APP_URL;
public JourneyR(Reverse reverse) { import static com.olexyn.misp.reverse.Reverse.FORWARD_URL;
this.reverse = reverse;
}
public class JourneyR implements Runnable {
@Override @Override
public void run() { public void run() {
try { try {
Ride _ride = sendPostRide(); var ride = sendPostRide();
_ride = sendGetRequest(_ride); sendGetRequest(ride);
sendPostRideRequestData(_ride); sendPostRideRequestData(ride);
} catch (Exception ignored) { } } catch (Exception ignored) { /* ignored */ }
} }
Ride sendPostRide() throws IOException { private Ride sendPostRide() throws IOException {
final Ride ride = new Ride(); Ride ride = new Ride();
final String result = Tools.send("POST", reverse.FORWARD_URL, ride.json()); String result = Tools.send(POST, FORWARD_URL, ride.json());
String _req = new Ride(result).getRequest(); String reqStr = new Ride(result).getRequest();
String request = (_req == null) ? "" : _req; reqStr = (reqStr == null) ? EMPTY : reqStr;
ride.setRequest(request); ride.setRequest(reqStr);
return ride; return ride;
} }
private Ride sendGetRequest(Ride ride) throws IOException {
Ride sendGetRequest(Ride ride) throws IOException { String result = Tools.send(GET, APP_URL, ride.getRequest());
final String result = Tools.send("GET", reverse.APP_URL, ride.getRequest());
ride.setData(result); ride.setData(result);
return ride; return ride;
} }
private void sendPostRideRequestData(Ride ride) throws IOException {
void sendPostRideRequestData(Ride ride) throws IOException { Tools.send(POST, FORWARD_URL, ride.json());
Tools.send("POST", reverse.FORWARD_URL, ride.json());
} }
} }
Loading…
Cancel
Save