Updated to latest WebServer Version

This commit is contained in:
Finn
2026-02-01 19:33:09 +01:00
parent c1c00cd697
commit e2fa68e96b
8 changed files with 90 additions and 20 deletions

View File

@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.openautonomousconnection</groupId>
<artifactId>OAC2Web</artifactId>
<artifactId>Web2OAC</artifactId>
<version>1.0.0-BETA.1.1</version>
<organization>
<name>Open Autonomous Connection</name>
@@ -104,7 +104,7 @@
<dependency>
<groupId>org.openautonomousconnection</groupId>
<artifactId>WebServer</artifactId>
<version>1.0.0-BETA.1.5</version>
<version>1.0.0-BETA.1.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>

View File

@@ -37,9 +37,6 @@ public class api implements WebPage {
("Bad request:\n" + exception.getMessage()).getBytes());
}
String hidden = "ins";
try {
HashMap<String, String> dataMap = new HashMap<>();
dataMap.put("ip", hostIp);

View File

@@ -0,0 +1,83 @@
package org.openautonomousconnection.oac2web;
import com.google.gson.JsonObject;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponsePacket;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.WebRequestMethod;
import org.openautonomousconnection.webserver.api.Route;
import org.openautonomousconnection.webserver.api.WebPage;
import org.openautonomousconnection.webserver.api.WebPageContext;
import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
@Route(path = "docs.html")
public class docs implements WebPage {
@Override
public WebResponsePacket handle(WebPageContext webPageContext) throws Exception {
if (webPageContext.request.getMethod() == WebRequestMethod.POST) {
String hostIp = webPageContext.request.getHeaders().get("ip");
String description = webPageContext.request.getHeaders().get("description");
int tcp = 0;
int udp = 0;
try {
tcp = Integer.parseInt(webPageContext.request.getHeaders().get("tcp"));
udp = Integer.parseInt(webPageContext.request.getHeaders().get("udp"));
} catch (NumberFormatException exception) {
return new WebResponsePacket(400, "text/plain", webPageContext.request.getHeaders(),
("Bad request:\n" + exception.getMessage()).getBytes());
}
try {
HashMap<String, String> dataMap = new HashMap<>();
dataMap.put("ip", hostIp);
dataMap.put("tcp", String.valueOf(tcp));
dataMap.put("udp", String.valueOf(udp));
dataMap.put("desc", description);
URL url = new URL("https://open-autonomous-connection.org/api/add.php");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);
JsonObject jsonData = new JsonObject();
for (Map.Entry<String, String> entry : dataMap.entrySet()) {
jsonData.addProperty(entry.getKey(), entry.getValue());
try (OutputStream os = connection.getOutputStream()) {
byte[] input = jsonData.toString().getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
}
int responseCode = connection.getResponseCode();
StringBuilder response = new StringBuilder();
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
}
connection.disconnect();
return new WebResponsePacket(200, "text/plain", webPageContext.request.getHeaders(), ("Published\n" +
"Received Response Code: " + responseCode + "\n" + "Received Response: " + response).getBytes());
} catch (Exception e) {
return new WebResponsePacket(500, "text/plain", webPageContext.request.getHeaders(),
("Bad request:\n" + e.getMessage()).getBytes());
}
}
return new WebResponsePacket(400, "text/plain", webPageContext.request.getHeaders(), "Bad request".getBytes());
}
}

View File

@@ -14,8 +14,6 @@ public class download implements WebPage {
@Override
public WebResponsePacket handle(WebPageContext webPageContext) {
if (webPageContext.request.getPath().equalsIgnoreCase("download.html"))
return HttpsProxy.proxyGet(webPageContext, "https://open-autonomous-connection.org/download.html");
return null;
return HttpsProxy.proxyGet(webPageContext, "https://open-autonomous-connection.org/download.html");
}
}

View File

@@ -14,8 +14,6 @@ public class index implements WebPage {
@Override
public WebResponsePacket handle(WebPageContext webPageContext) {
if (webPageContext.request.getPath().equalsIgnoreCase("index.html"))
return HttpsProxy.proxyGet(webPageContext, "https://open-autonomous-connection.org/index.html");
return null;
return HttpsProxy.proxyGet(webPageContext, "https://open-autonomous-connection.org/index.html");
}
}

View File

@@ -14,8 +14,6 @@ public class ins implements WebPage {
@Override
public WebResponsePacket handle(WebPageContext webPageContext) {
if (webPageContext.request.getPath().equalsIgnoreCase("ins.php"))
return HttpsProxy.proxyGet(webPageContext, "https://open-autonomous-connection.org/ins.php");
return null;
return HttpsProxy.proxyGet(webPageContext, "https://open-autonomous-connection.org/ins.php");
}
}

View File

@@ -14,8 +14,6 @@ public class license implements WebPage {
@Override
public WebResponsePacket handle(WebPageContext webPageContext) {
if (webPageContext.request.getPath().equalsIgnoreCase("license.html"))
return HttpsProxy.proxyGet(webPageContext, "https://open-autonomous-connection.org/license.html");
return null;
return HttpsProxy.proxyGet(webPageContext, "https://open-autonomous-connection.org/license.html");
}
}

View File

@@ -14,8 +14,6 @@ public class wiki implements WebPage {
@Override
public WebResponsePacket handle(WebPageContext webPageContext) {
if (webPageContext.request.getPath().equalsIgnoreCase("wiki.html"))
return HttpsProxy.proxyGet(webPageContext, "https://open-autonomous-connection.org/wiki.html");
return null;
return HttpsProxy.proxyGet(webPageContext, "https://open-autonomous-connection.org/wiki.html");
}
}