Compare commits
9 Commits
1.0.0-BETA
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aeadf55ec9 | ||
|
|
740e85fa3f | ||
|
|
357b30b037 | ||
|
|
f81cb0ee15 | ||
|
|
09dd207bb1 | ||
|
|
2d829fe341 | ||
|
|
de22a8ab67 | ||
|
|
a365b57638 | ||
|
|
eda1b24a26 |
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -8,7 +8,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="23" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="25" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
1
LICENSE
1
LICENSE
@@ -1 +1,2 @@
|
||||
Please read the license here: https://open-autonomous-connection.org/license.html
|
||||
Download all third parties licenses here: https://open-autonomous-connection.org/assets/licenses.zip
|
||||
|
||||
@@ -10,7 +10,8 @@ This project (OAC) is licensed under
|
||||
the [Open Autonomous Public License (OAPL)](https://open-autonomous-connection.org/license.html).
|
||||
|
||||
**Third-party components:**
|
||||
|
||||
<br />
|
||||
Download all license here: https://open-autonomous-connection.org/assets/licenses.zip
|
||||
- *UnlegitLibrary* is authored by the same copyright holder and is used here under a special agreement:
|
||||
While [UnlegitLibrary](https://repo.unlegitdqrk.dev/UnlegitDqrk/unlegitlibrary/) is generally distributed under
|
||||
the [GNU GPLv3](https://repo.unlegitdqrk.dev/UnlegitDqrk/unlegitlibrary/src/branch/master/LICENSE),
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openautonomousconnection</groupId>
|
||||
<artifactId>INSServer</artifactId>
|
||||
<version>1.0.0-BETA.1.0</version>
|
||||
<version>1.0.1-BETA.0.3</version>
|
||||
<description>The default INS-Server</description>
|
||||
<url>https://open-autonomous-connection.org/</url>
|
||||
<issueManagement>
|
||||
@@ -37,44 +37,6 @@
|
||||
<name>Open Autonomous Public License (OAPL)</name>
|
||||
<url>https://open-autonomous-connection.org/license.html</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>GNU General Public License v3.0</name>
|
||||
<url>https://www.gnu.org/licenses/gpl-3.0.html</url>
|
||||
<comments>Default license: Applies to all users and projects unless an explicit alternative license has been
|
||||
granted.</comments>
|
||||
</license>
|
||||
<license>
|
||||
<name>LPGL 3</name>
|
||||
<url>https://www.gnu.org/licenses/lgpl-3.0.html#license-text</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>LPGL 2.1</name>
|
||||
<url>https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.en#SEC1</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>WTPL License</name>
|
||||
<url>https://github.com/ronmamo/reflections/tree/master?tab=WTFPL-1-ov-file</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>Apache License 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>MIT License</name>
|
||||
<url>https://opensource.org/license/mit</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>javassist</name>
|
||||
<url>https://github.com/jboss-javassist/javassist/blob/master/License.html</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>projectlombok</name>
|
||||
<url>https://github.com/projectlombok/lombok?tab=License-1-ov-file</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>mariadb</name>
|
||||
<url>https://mariadb.com/docs/general-resources/community/community/faq/licensing-questions/licensing-faq</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<organization>
|
||||
<name>Open Autonomous Connection</name>
|
||||
@@ -105,6 +67,13 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.42</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
<compilerArgs>
|
||||
<arg>--add-exports</arg>
|
||||
<arg>java.base/sun.security.x509=ALL-UNNAMED</arg>
|
||||
@@ -143,17 +112,9 @@
|
||||
<url>https://repo.open-autonomous-connection.org/api/packages/open-autonomous-connection/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.38</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.target>23</maven.compiler.target>
|
||||
<maven.compiler.source>23</maven.compiler.source>
|
||||
<maven.compiler.target>25</maven.compiler.target>
|
||||
<maven.compiler.source>25</maven.compiler.source>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
@@ -2,22 +2,24 @@ package ins.frontend;
|
||||
|
||||
import ins.frontend.utils.RegistrarDao;
|
||||
import ins.frontend.utils.WebApp;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponsePacket;
|
||||
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceResponsePacket;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketFlags;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketHeader;
|
||||
import org.openautonomousconnection.webserver.api.Route;
|
||||
import org.openautonomousconnection.webserver.api.SessionContext;
|
||||
import org.openautonomousconnection.webserver.api.WebPage;
|
||||
import org.openautonomousconnection.webserver.api.WebPageContext;
|
||||
import org.openautonomousconnection.webserver.utils.HeaderMaps;
|
||||
import org.openautonomousconnection.webserver.utils.Html;
|
||||
import org.openautonomousconnection.webserver.utils.MergedRequestParams;
|
||||
import org.openautonomousconnection.webserver.utils.QuerySupport;
|
||||
import org.openautonomousconnection.webserver.utils.WebUrlUtil;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* INS registrar ins.frontend (TLN / InfoName / Records) with proper POST parameter parsing.
|
||||
* INS registrar dashboard (TLN / InfoName / Records) for protocol v1.0.1 resource packets.
|
||||
*
|
||||
* <p>Supported actions (POST recommended for mutations):</p>
|
||||
* <ul>
|
||||
@@ -28,12 +30,9 @@ import java.util.Map;
|
||||
* <li>delete_infoname</li>
|
||||
* <li>add_record</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Important: Listing/editing/deleting records requires DAO methods that are not part of the provided snippet.
|
||||
* This page currently supports adding records only.</p>
|
||||
*/
|
||||
@Route(path = "dashboard.html")
|
||||
public final class dashboard implements WebPage {
|
||||
@Route(path = "/dashboard.html")
|
||||
public final class dashboard extends WebPage {
|
||||
|
||||
private static Integer normalizeNullableInt(String s) {
|
||||
if (s == null) return null;
|
||||
@@ -47,30 +46,26 @@ public final class dashboard implements WebPage {
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResponsePacket handle(WebPageContext ctx) throws Exception {
|
||||
public WebResourceResponsePacket handle(WebPageContext ctx) throws Exception {
|
||||
WebApp.init();
|
||||
|
||||
SessionContext session = SessionContext.from(
|
||||
ctx.client,
|
||||
(ProtocolWebServer) ctx.client.getServer(),
|
||||
ctx.request.getHeaders()
|
||||
);
|
||||
|
||||
if (!session.isValid() || session.getUser() == null) {
|
||||
return plain(401, "Authentication required (session).");
|
||||
if (ctx.session == null || !ctx.session.isValid() || ctx.session.getUser() == null) {
|
||||
return plain(ctx, 401, "Authentication required (session).");
|
||||
}
|
||||
|
||||
int userId;
|
||||
try {
|
||||
userId = Integer.parseInt(session.getUser());
|
||||
userId = Integer.parseInt(ctx.session.getUser());
|
||||
} catch (Exception e) {
|
||||
return plain(401, "Invalid session user.");
|
||||
return plain(ctx, 401, "Invalid session user.");
|
||||
}
|
||||
|
||||
RegistrarDao dao = WebApp.get().dao();
|
||||
|
||||
// Raw target and merged params (GET + POST).
|
||||
String rawTarget = org.openautonomousconnection.webserver.utils.QuerySupport.extractRawTarget(ctx.request);
|
||||
// Build target for param merging: "/path?query"
|
||||
String rawTarget = WebUrlUtil.extractPathAndQuery(ctx.request.getUrl());
|
||||
if (rawTarget == null) rawTarget = "/dashboard.html";
|
||||
|
||||
Map<String, String> headers = ctx.request.getHeaders();
|
||||
byte[] body = ctx.request.getBody();
|
||||
|
||||
@@ -90,7 +85,7 @@ public final class dashboard implements WebPage {
|
||||
}
|
||||
}
|
||||
|
||||
return render(userId, msg, err, dao);
|
||||
return render(ctx, userId, msg, err, dao);
|
||||
}
|
||||
|
||||
private ActionResult executeAction(String action, MergedRequestParams p, int userId, RegistrarDao dao) throws Exception {
|
||||
@@ -171,7 +166,6 @@ public final class dashboard implements WebPage {
|
||||
if (!dao.isOwnerOfInfoName(infonameId, userId)) return ActionResult.err("Not owner of this infoname.");
|
||||
if (type.isBlank() || value == null || value.isBlank()) return ActionResult.err("Missing type/value.");
|
||||
|
||||
// Validate allow_subdomains against TLN of this infoname (owned list contains TLN metadata).
|
||||
RegistrarDao.InfoNameRow[] owned = dao.listOwnedInfoNames(userId);
|
||||
RegistrarDao.InfoNameRow row = null;
|
||||
for (RegistrarDao.InfoNameRow r : owned) {
|
||||
@@ -194,7 +188,7 @@ public final class dashboard implements WebPage {
|
||||
return ActionResult.err("Unknown action: " + action);
|
||||
}
|
||||
|
||||
private WebResponsePacket render(int userId, String msg, String err, RegistrarDao dao) throws Exception {
|
||||
private WebResourceResponsePacket render(WebPageContext ctx, int userId, String msg, String err, RegistrarDao dao) throws Exception {
|
||||
RegistrarDao.TlnRow[] tlns = dao.listVisibleTlns(userId);
|
||||
RegistrarDao.InfoNameRow[] owned = dao.listOwnedInfoNames(userId);
|
||||
|
||||
@@ -259,7 +253,7 @@ public final class dashboard implements WebPage {
|
||||
);
|
||||
|
||||
String html = Html.page("INS Registrar", body);
|
||||
return new WebResponsePacket(200, "text/html", new HashMap<>(), Html.utf8(html));
|
||||
return html(ctx, 200, html);
|
||||
}
|
||||
|
||||
private String renderTlnSection(RegistrarDao.TlnRow[] tlns, int userId) {
|
||||
@@ -348,8 +342,33 @@ public final class dashboard implements WebPage {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private WebResponsePacket plain(int code, String text) {
|
||||
return new WebResponsePacket(code, "text/plain", new HashMap<>(), Html.utf8(text));
|
||||
private WebResourceResponsePacket plain(WebPageContext ctx, int code, String text) {
|
||||
byte[] body = (text == null ? "" : text).getBytes(StandardCharsets.UTF_8);
|
||||
Map<String, String> headers = HeaderMaps.mutable();
|
||||
headers.put("content-length", String.valueOf(body.length));
|
||||
return new WebResourceResponsePacket(outHeader(ctx), code, "text/plain; charset=utf-8", headers, body, null);
|
||||
}
|
||||
|
||||
private WebResourceResponsePacket html(WebPageContext ctx, int code, String html) {
|
||||
byte[] body = Html.utf8(html);
|
||||
Map<String, String> headers = HeaderMaps.mutable();
|
||||
headers.put("content-length", String.valueOf(body.length));
|
||||
return new WebResourceResponsePacket(outHeader(ctx), code, "text/html; charset=utf-8", headers, body, null);
|
||||
}
|
||||
|
||||
private WebPacketHeader outHeader(WebPageContext ctx) {
|
||||
WebPacketHeader in = (ctx != null && ctx.request != null) ? ctx.request.getHeader() : null;
|
||||
if (in == null) {
|
||||
return new WebPacketHeader(0, 0, 0, 0, WebPacketFlags.RESOURCE, System.currentTimeMillis());
|
||||
}
|
||||
return new WebPacketHeader(
|
||||
in.getRequestId(),
|
||||
in.getTabId(),
|
||||
in.getPageId(),
|
||||
in.getFrameId(),
|
||||
in.getFlags() | WebPacketFlags.RESOURCE,
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
}
|
||||
|
||||
private String safeMsg(Exception e) {
|
||||
|
||||
@@ -1,27 +1,31 @@
|
||||
package ins.frontend;
|
||||
|
||||
import ins.frontend.utils.WebApp;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponsePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceResponsePacket;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketFlags;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketHeader;
|
||||
import org.openautonomousconnection.webserver.api.Route;
|
||||
import org.openautonomousconnection.webserver.api.WebPage;
|
||||
import org.openautonomousconnection.webserver.api.WebPageContext;
|
||||
import org.openautonomousconnection.webserver.utils.HeaderMaps;
|
||||
import org.openautonomousconnection.webserver.utils.Html;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Landing page for the registrar ins.frontend.
|
||||
* Landing page for INS registrar frontend (v1.0.1).
|
||||
*/
|
||||
@Route(path = "index.html")
|
||||
public final class index implements WebPage {
|
||||
@Route(path = "/index.html")
|
||||
public final class index extends WebPage {
|
||||
|
||||
@Override
|
||||
public WebResponsePacket handle(WebPageContext ctx) {
|
||||
public WebResourceResponsePacket handle(WebPageContext ctx) {
|
||||
WebApp.init();
|
||||
|
||||
String html = Html.page("OAC INS Registrar", """
|
||||
<div class="card">
|
||||
<h2>OAC INS Registrar</h2>
|
||||
<p class="muted">What you want to do?</p>
|
||||
<p class="muted">What you want to do? You can checkout the source of this site here: https://repo.open-autonomous-connection.org/open-autonomous-connection/INSServer/</p>
|
||||
<div class="col"><a href="info.html">Info</a></div><br />
|
||||
<div class="row">
|
||||
<div class="col"><a href="login.html">Login</a></div>
|
||||
@@ -31,6 +35,25 @@ public final class index implements WebPage {
|
||||
</div>
|
||||
""");
|
||||
|
||||
return new WebResponsePacket(200, "text/html", new HashMap<>(), Html.utf8(html));
|
||||
byte[] body = Html.utf8(html);
|
||||
Map<String, String> headers = HeaderMaps.mutable();
|
||||
headers.put("content-length", String.valueOf(body.length));
|
||||
|
||||
return new WebResourceResponsePacket(outHeader(ctx), 200, "text/html; charset=utf-8", headers, body, null);
|
||||
}
|
||||
|
||||
private WebPacketHeader outHeader(WebPageContext ctx) {
|
||||
WebPacketHeader in = (ctx != null && ctx.request != null) ? ctx.request.getHeader() : null;
|
||||
if (in == null) {
|
||||
return new WebPacketHeader(0, 0, 0, 0, WebPacketFlags.RESOURCE, System.currentTimeMillis());
|
||||
}
|
||||
return new WebPacketHeader(
|
||||
in.getRequestId(),
|
||||
in.getTabId(),
|
||||
in.getPageId(),
|
||||
in.getFrameId(),
|
||||
in.getFlags() | WebPacketFlags.RESOURCE,
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,27 @@
|
||||
package ins.frontend;
|
||||
|
||||
import ins.frontend.utils.WebApp;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponsePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceResponsePacket;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketFlags;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketHeader;
|
||||
import org.openautonomousconnection.webserver.api.Route;
|
||||
import org.openautonomousconnection.webserver.api.WebPage;
|
||||
import org.openautonomousconnection.webserver.api.WebPageContext;
|
||||
import org.openautonomousconnection.webserver.utils.HeaderMaps;
|
||||
import org.openautonomousconnection.webserver.utils.Html;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Landing page for the registrar ins.frontend.
|
||||
* Info page for INS registrar frontend (v1.0.1).
|
||||
*/
|
||||
@Route(path = "info.html")
|
||||
public final class info implements WebPage {
|
||||
@Route(path = "/info.html")
|
||||
public final class info extends WebPage {
|
||||
|
||||
@Override
|
||||
public WebResponsePacket handle(WebPageContext ctx) {
|
||||
public WebResourceResponsePacket handle(WebPageContext ctx) {
|
||||
WebApp.init();
|
||||
|
||||
String html = Html.page("INS Info", """
|
||||
<section class="card">
|
||||
<h2>OAC Default INS Server</h2>
|
||||
@@ -30,7 +34,7 @@ public final class info implements WebPage {
|
||||
<p>
|
||||
It provides a trusted reference point for resolving InfoNames
|
||||
and enables initial client connections
|
||||
to the OAC ecosystem.
|
||||
to the OAC.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
@@ -42,8 +46,30 @@ public final class info implements WebPage {
|
||||
Note: Alternative or private INS servers may exist, but the default INS
|
||||
server represents the official and stable reference instance.
|
||||
</p>
|
||||
</section> """);
|
||||
|
||||
return new WebResponsePacket(200, "text/html", new HashMap<>(), Html.utf8(html));
|
||||
<p>Checkout the Source here: https://repo.open-autonomous-connection.org/open-autonomous-connection/INSServer/</p>
|
||||
</section>
|
||||
""");
|
||||
|
||||
byte[] body = Html.utf8(html);
|
||||
Map<String, String> headers = HeaderMaps.mutable();
|
||||
headers.put("content-length", String.valueOf(body.length));
|
||||
|
||||
return new WebResourceResponsePacket(outHeader(ctx), 200, "text/html; charset=utf-8", headers, body, null);
|
||||
}
|
||||
|
||||
private WebPacketHeader outHeader(WebPageContext ctx) {
|
||||
WebPacketHeader in = (ctx != null && ctx.request != null) ? ctx.request.getHeader() : null;
|
||||
if (in == null) {
|
||||
return new WebPacketHeader(0, 0, 0, 0, WebPacketFlags.RESOURCE, System.currentTimeMillis());
|
||||
}
|
||||
return new WebPacketHeader(
|
||||
in.getRequestId(),
|
||||
in.getTabId(),
|
||||
in.getPageId(),
|
||||
in.getFrameId(),
|
||||
in.getFlags() | WebPacketFlags.RESOURCE,
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,46 +2,132 @@ package ins.frontend;
|
||||
|
||||
import ins.frontend.utils.UserDao;
|
||||
import ins.frontend.utils.WebApp;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponsePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceResponsePacket;
|
||||
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
|
||||
import org.openautonomousconnection.protocol.side.web.managers.SessionManager;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.WebRequestMethod;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketFlags;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketHeader;
|
||||
import org.openautonomousconnection.webserver.api.Route;
|
||||
import org.openautonomousconnection.webserver.api.SessionContext;
|
||||
import org.openautonomousconnection.webserver.api.WebPage;
|
||||
import org.openautonomousconnection.webserver.api.WebPageContext;
|
||||
import org.openautonomousconnection.webserver.utils.HeaderMaps;
|
||||
import org.openautonomousconnection.webserver.utils.Html;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Login page with existing-session short-circuit.
|
||||
*
|
||||
* <p>Username stored in DB as plain text.</p>
|
||||
* Login page (v1.0.1).
|
||||
*/
|
||||
@Route(path = "/login.html")
|
||||
public final class login implements WebPage {
|
||||
public final class login extends WebPage {
|
||||
|
||||
private static WebResponsePacket ok(String html) {
|
||||
return new WebResponsePacket(200, "text/html; charset=utf-8", HeaderMaps.mutable(), Html.utf8(html));
|
||||
private enum ReqMethod { GET, POST, OTHER }
|
||||
|
||||
@Override
|
||||
public WebResourceResponsePacket handle(WebPageContext ctx) throws Exception {
|
||||
WebApp.init();
|
||||
|
||||
// If a valid session already exists -> go dashboard (keep session)
|
||||
if (ctx.session != null && ctx.session.isValid() && ctx.session.getUser() != null) {
|
||||
return redirect302(ctx, "dashboard.html", ctx.session.getSessionId());
|
||||
}
|
||||
|
||||
private static WebResponsePacket text(int code, String msg) {
|
||||
return new WebResponsePacket(code, "text/plain; charset=utf-8", HeaderMaps.mutable(), msg.getBytes(StandardCharsets.UTF_8));
|
||||
ReqMethod method = detectMethod(ctx);
|
||||
if (method == ReqMethod.GET) {
|
||||
return ok(ctx, renderForm(null));
|
||||
}
|
||||
|
||||
private static WebResponsePacket redirect302(String location, String session) {
|
||||
if (method != ReqMethod.POST) {
|
||||
return text(ctx, 405, "Method Not Allowed");
|
||||
}
|
||||
|
||||
String contentType = headerIgnoreCase(ctx.request.getHeaders(), "content-type");
|
||||
String ctLower = (contentType == null) ? "" : contentType.toLowerCase(Locale.ROOT);
|
||||
|
||||
if (!ctLower.startsWith("application/x-www-form-urlencoded")) {
|
||||
return ok(ctx, renderForm("Unsupported content-type: " + Html.esc(contentType)));
|
||||
}
|
||||
|
||||
Map<String, List<String>> form = parseFormUrlEncoded(ctx.request.getBody());
|
||||
String username = first(form, "username");
|
||||
String password = first(form, "password");
|
||||
|
||||
if (username == null || password == null) {
|
||||
return ok(ctx, renderForm("Missing username/password."));
|
||||
}
|
||||
|
||||
String lookupUsername = username.trim();
|
||||
|
||||
UserDao.UserRow user = WebApp.get().users().findByUsername(lookupUsername).orElse(null);
|
||||
if (user == null) {
|
||||
return ok(ctx, renderForm("Invalid credentials."));
|
||||
}
|
||||
|
||||
boolean okPw = WebApp.get().passwordHasher().verify(password, user.passwordEncoded());
|
||||
if (!okPw) {
|
||||
return ok(ctx, renderForm("Invalid credentials."));
|
||||
}
|
||||
|
||||
String ip = resolveIp(ctx);
|
||||
String ua = headerIgnoreCase(ctx.request.getHeaders(), "user-agent");
|
||||
if (ua == null) ua = "";
|
||||
|
||||
String session = SessionManager.create(
|
||||
String.valueOf(user.id()),
|
||||
ip,
|
||||
ua,
|
||||
(ProtocolWebServer) ctx.client.getServer()
|
||||
);
|
||||
|
||||
return redirect302(ctx, "dashboard.html", session);
|
||||
}
|
||||
|
||||
private ReqMethod detectMethod(WebPageContext ctx) {
|
||||
// Preferred: request.getMethod() via reflection (avoids depending on specific enum package).
|
||||
try {
|
||||
Method m = ctx.request.getClass().getMethod("getMethod");
|
||||
Object v = m.invoke(ctx.request);
|
||||
if (v != null) {
|
||||
String s = String.valueOf(v).trim().toUpperCase(Locale.ROOT);
|
||||
if ("GET".equals(s)) return ReqMethod.GET;
|
||||
if ("POST".equals(s)) return ReqMethod.POST;
|
||||
return ReqMethod.OTHER;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// Fall back below.
|
||||
}
|
||||
|
||||
// Fallback: treat presence of body as POST-like.
|
||||
byte[] body = ctx.request.getBody();
|
||||
if (body != null && body.length > 0) return ReqMethod.POST;
|
||||
return ReqMethod.GET;
|
||||
}
|
||||
|
||||
private static WebResourceResponsePacket ok(WebPageContext ctx, String html) {
|
||||
byte[] body = Html.utf8(html);
|
||||
Map<String, String> headers = HeaderMaps.mutable();
|
||||
headers.put("location", location);
|
||||
if (session != null && !session.isBlank()) {
|
||||
headers.put("Location", "dashboard.html");
|
||||
headers.put("Set-Cookie", "session=" + session + "; Path=/; HttpOnly; SameSite=Lax");
|
||||
headers.put("session", session);
|
||||
headers.put("cookie", session);
|
||||
headers.put("content-length", String.valueOf(body.length));
|
||||
return new WebResourceResponsePacket(outHeader(ctx), 200, "text/html; charset=utf-8", headers, body, null);
|
||||
}
|
||||
return new WebResponsePacket(302, "text/plain; charset=utf-8", headers, new byte[0]);
|
||||
|
||||
private static WebResourceResponsePacket text(WebPageContext ctx, int code, String msg) {
|
||||
byte[] body = (msg == null ? "" : msg).getBytes(StandardCharsets.UTF_8);
|
||||
Map<String, String> headers = HeaderMaps.mutable();
|
||||
headers.put("content-length", String.valueOf(body.length));
|
||||
return new WebResourceResponsePacket(outHeader(ctx), code, "text/plain; charset=utf-8", headers, body, null);
|
||||
}
|
||||
|
||||
private static WebResourceResponsePacket redirect302(WebPageContext ctx, String location, String session) {
|
||||
Map<String, String> headers = HeaderMaps.mutable();
|
||||
headers.put("Location", location);
|
||||
if (session != null && !session.isBlank()) {
|
||||
headers.put("Set-Cookie", "session=" + session + "; Path=/; HttpOnly; SameSite=Lax");
|
||||
// optional fallback for stacks that read a direct header:
|
||||
headers.put("session", session);
|
||||
}
|
||||
return new WebResourceResponsePacket(outHeader(ctx), 302, "text/plain; charset=utf-8", headers, new byte[0], null);
|
||||
}
|
||||
|
||||
private static String renderForm(String errOrOk) {
|
||||
@@ -140,7 +226,7 @@ public final class login implements WebPage {
|
||||
continue;
|
||||
}
|
||||
if (c == '%' && i + 2 < s.length()) {
|
||||
int hi = hex(s.charAt(i + 1));
|
||||
int hi = hex(c = s.charAt(i + 1));
|
||||
int lo = hex(s.charAt(i + 2));
|
||||
if (hi >= 0 && lo >= 0) {
|
||||
tmp[n++] = (byte) ((hi << 4) | lo);
|
||||
@@ -149,7 +235,7 @@ public final class login implements WebPage {
|
||||
}
|
||||
}
|
||||
|
||||
byte[] b = String.valueOf(c).getBytes(StandardCharsets.UTF_8);
|
||||
byte[] b = String.valueOf(s.charAt(i)).getBytes(StandardCharsets.UTF_8);
|
||||
for (byte bb : b) tmp[n++] = bb;
|
||||
}
|
||||
|
||||
@@ -163,69 +249,18 @@ public final class login implements WebPage {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResponsePacket handle(WebPageContext ctx) throws Exception {
|
||||
WebApp.init();
|
||||
|
||||
// 1) If a valid session already exists -> go dashboard (keep session)
|
||||
SessionContext existing = SessionContext.from(
|
||||
ctx.client,
|
||||
(ProtocolWebServer) ctx.client.getServer(),
|
||||
ctx.request.getHeaders()
|
||||
private static WebPacketHeader outHeader(WebPageContext ctx) {
|
||||
WebPacketHeader in = (ctx != null && ctx.request != null) ? ctx.request.getHeader() : null;
|
||||
if (in == null) {
|
||||
return new WebPacketHeader(0, 0, 0, 0, WebPacketFlags.RESOURCE, System.currentTimeMillis());
|
||||
}
|
||||
return new WebPacketHeader(
|
||||
in.getRequestId(),
|
||||
in.getTabId(),
|
||||
in.getPageId(),
|
||||
in.getFrameId(),
|
||||
in.getFlags() | WebPacketFlags.RESOURCE,
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
if (existing.isValid() && existing.getUser() != null) {
|
||||
return redirect302("dashboard.html", existing.getSessionId());
|
||||
}
|
||||
|
||||
WebRequestMethod method = ctx.request.getMethod();
|
||||
if (method == null) method = WebRequestMethod.GET;
|
||||
|
||||
if (method == WebRequestMethod.GET) {
|
||||
return ok(renderForm(null));
|
||||
}
|
||||
|
||||
if (method != WebRequestMethod.POST) {
|
||||
return text(405, "Method Not Allowed");
|
||||
}
|
||||
|
||||
String contentType = headerIgnoreCase(ctx.request.getHeaders(), "content-type");
|
||||
String ctLower = (contentType == null) ? "" : contentType.toLowerCase(Locale.ROOT);
|
||||
|
||||
if (!ctLower.startsWith("application/x-www-form-urlencoded")) {
|
||||
return ok(renderForm("Unsupported content-type: " + Html.esc(contentType)));
|
||||
}
|
||||
|
||||
Map<String, List<String>> form = parseFormUrlEncoded(ctx.request.getBody());
|
||||
String username = first(form, "username");
|
||||
String password = first(form, "password");
|
||||
|
||||
if (username == null || password == null) {
|
||||
return ok(renderForm("Missing username/password."));
|
||||
}
|
||||
|
||||
String lookupUsername = username.trim();
|
||||
|
||||
UserDao.UserRow user = WebApp.get().users().findByUsername(lookupUsername).orElse(null);
|
||||
if (user == null) {
|
||||
return ok(renderForm("Invalid credentials."));
|
||||
}
|
||||
|
||||
boolean okPw = WebApp.get().passwordHasher().verify(password, user.passwordEncoded());
|
||||
if (!okPw) {
|
||||
return ok(renderForm("Invalid credentials."));
|
||||
}
|
||||
|
||||
String ip = resolveIp(ctx);
|
||||
String ua = headerIgnoreCase(ctx.request.getHeaders(), "user-agent");
|
||||
if (ua == null) ua = "";
|
||||
|
||||
String session = SessionManager.create(
|
||||
String.valueOf(user.id()),
|
||||
ip,
|
||||
ua,
|
||||
(ProtocolWebServer) ctx.client.getServer()
|
||||
);
|
||||
|
||||
return redirect302("dashboard.html", session);
|
||||
}
|
||||
}
|
||||
@@ -2,44 +2,120 @@ package ins.frontend;
|
||||
|
||||
import ins.frontend.utils.RegistrationService;
|
||||
import ins.frontend.utils.WebApp;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponsePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceResponsePacket;
|
||||
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
|
||||
import org.openautonomousconnection.protocol.side.web.managers.SessionManager;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.WebRequestMethod;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketFlags;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketHeader;
|
||||
import org.openautonomousconnection.webserver.api.Route;
|
||||
import org.openautonomousconnection.webserver.api.SessionContext;
|
||||
import org.openautonomousconnection.webserver.api.WebPage;
|
||||
import org.openautonomousconnection.webserver.api.WebPageContext;
|
||||
import org.openautonomousconnection.webserver.utils.HeaderMaps;
|
||||
import org.openautonomousconnection.webserver.utils.Html;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Register page with existing-session short-circuit.
|
||||
* Register page (v1.0.1).
|
||||
*/
|
||||
@Route(path = "/register.html")
|
||||
public final class register implements WebPage {
|
||||
public final class register extends WebPage {
|
||||
|
||||
private static WebResponsePacket ok(String html) {
|
||||
return new WebResponsePacket(200, "text/html; charset=utf-8", HeaderMaps.mutable(), Html.utf8(html));
|
||||
private enum ReqMethod { GET, POST, OTHER }
|
||||
|
||||
@Override
|
||||
public WebResourceResponsePacket handle(WebPageContext ctx) throws Exception {
|
||||
WebApp.init();
|
||||
|
||||
// If a valid session already exists -> go dashboard (keep session)
|
||||
if (ctx.session != null && ctx.session.isValid() && ctx.session.getUser() != null) {
|
||||
return redirect302(ctx, "dashboard.html", ctx.session.getSessionId());
|
||||
}
|
||||
|
||||
private static WebResponsePacket text(int code, String msg) {
|
||||
return new WebResponsePacket(code, "text/plain; charset=utf-8", HeaderMaps.mutable(), msg.getBytes(StandardCharsets.UTF_8));
|
||||
ReqMethod method = detectMethod(ctx);
|
||||
if (method == ReqMethod.GET) {
|
||||
return ok(ctx, renderForm(null));
|
||||
}
|
||||
|
||||
private static WebResponsePacket redirect302(String location, String session) {
|
||||
if (method != ReqMethod.POST) {
|
||||
return text(ctx, 405, "Method Not Allowed");
|
||||
}
|
||||
|
||||
String contentType = headerIgnoreCase(ctx.request.getHeaders(), "content-type");
|
||||
String ctLower = (contentType == null) ? "" : contentType.toLowerCase(Locale.ROOT);
|
||||
|
||||
if (!ctLower.startsWith("application/x-www-form-urlencoded")) {
|
||||
return ok(ctx, renderForm("Unsupported content-type: " + Html.esc(contentType)));
|
||||
}
|
||||
|
||||
Map<String, List<String>> form = parseFormUrlEncoded(ctx.request.getBody());
|
||||
String username = first(form, "username");
|
||||
String password = first(form, "password");
|
||||
|
||||
RegistrationService service = new RegistrationService(WebApp.get().users(), WebApp.get().passwordHasher());
|
||||
RegistrationService.Result r = service.register(username, password);
|
||||
|
||||
if (!r.ok()) {
|
||||
return ok(ctx, renderForm(r.error()));
|
||||
}
|
||||
|
||||
// Create new session (user just registered)
|
||||
String ip = resolveIp(ctx);
|
||||
String ua = headerIgnoreCase(ctx.request.getHeaders(), "user-agent");
|
||||
if (ua == null) ua = "";
|
||||
|
||||
String session = SessionManager.create(
|
||||
String.valueOf(r.userId()),
|
||||
ip,
|
||||
ua,
|
||||
(ProtocolWebServer) ctx.client.getServer()
|
||||
);
|
||||
|
||||
return redirect302(ctx, "dashboard.html", session);
|
||||
}
|
||||
|
||||
private ReqMethod detectMethod(WebPageContext ctx) {
|
||||
try {
|
||||
Method m = ctx.request.getClass().getMethod("getMethod");
|
||||
Object v = m.invoke(ctx.request);
|
||||
if (v != null) {
|
||||
String s = String.valueOf(v).trim().toUpperCase(Locale.ROOT);
|
||||
if ("GET".equals(s)) return ReqMethod.GET;
|
||||
if ("POST".equals(s)) return ReqMethod.POST;
|
||||
return ReqMethod.OTHER;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
byte[] body = ctx.request.getBody();
|
||||
if (body != null && body.length > 0) return ReqMethod.POST;
|
||||
return ReqMethod.GET;
|
||||
}
|
||||
|
||||
private static WebResourceResponsePacket ok(WebPageContext ctx, String html) {
|
||||
byte[] body = Html.utf8(html);
|
||||
Map<String, String> headers = HeaderMaps.mutable();
|
||||
headers.put("location", location);
|
||||
headers.put("content-length", String.valueOf(body.length));
|
||||
return new WebResourceResponsePacket(outHeader(ctx), 200, "text/html; charset=utf-8", headers, body, null);
|
||||
}
|
||||
|
||||
private static WebResourceResponsePacket text(WebPageContext ctx, int code, String msg) {
|
||||
byte[] body = (msg == null ? "" : msg).getBytes(StandardCharsets.UTF_8);
|
||||
Map<String, String> headers = HeaderMaps.mutable();
|
||||
headers.put("content-length", String.valueOf(body.length));
|
||||
return new WebResourceResponsePacket(outHeader(ctx), code, "text/plain; charset=utf-8", headers, body, null);
|
||||
}
|
||||
|
||||
private static WebResourceResponsePacket redirect302(WebPageContext ctx, String location, String session) {
|
||||
Map<String, String> headers = HeaderMaps.mutable();
|
||||
headers.put("Location", location);
|
||||
if (session != null && !session.isBlank()) {
|
||||
headers.put("Location", "dashboard.html");
|
||||
headers.put("Set-Cookie", "session=" + session + "; Path=/; HttpOnly; SameSite=Lax");
|
||||
headers.put("session", session);
|
||||
headers.put("cookie", session);
|
||||
}
|
||||
return new WebResponsePacket(302, "text/plain; charset=utf-8", headers, new byte[0]);
|
||||
return new WebResourceResponsePacket(outHeader(ctx), 302, "text/plain; charset=utf-8", headers, new byte[0], null);
|
||||
}
|
||||
|
||||
private static String renderForm(String errOrOk) {
|
||||
@@ -138,7 +214,7 @@ public final class register implements WebPage {
|
||||
continue;
|
||||
}
|
||||
if (c == '%' && i + 2 < s.length()) {
|
||||
int hi = hex(s.charAt(i + 1));
|
||||
int hi = hex(c = s.charAt(i + 1));
|
||||
int lo = hex(s.charAt(i + 2));
|
||||
if (hi >= 0 && lo >= 0) {
|
||||
tmp[n++] = (byte) ((hi << 4) | lo);
|
||||
@@ -147,7 +223,7 @@ public final class register implements WebPage {
|
||||
}
|
||||
}
|
||||
|
||||
byte[] b = String.valueOf(c).getBytes(StandardCharsets.UTF_8);
|
||||
byte[] b = String.valueOf(s.charAt(i)).getBytes(StandardCharsets.UTF_8);
|
||||
for (byte bb : b) tmp[n++] = bb;
|
||||
}
|
||||
|
||||
@@ -161,61 +237,18 @@ public final class register implements WebPage {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResponsePacket handle(WebPageContext ctx) throws Exception {
|
||||
WebApp.init();
|
||||
|
||||
// 1) If a valid session already exists -> go dashboard (keep session)
|
||||
SessionContext existing = SessionContext.from(
|
||||
ctx.client,
|
||||
(ProtocolWebServer) ctx.client.getServer(),
|
||||
ctx.request.getHeaders()
|
||||
private static WebPacketHeader outHeader(WebPageContext ctx) {
|
||||
WebPacketHeader in = (ctx != null && ctx.request != null) ? ctx.request.getHeader() : null;
|
||||
if (in == null) {
|
||||
return new WebPacketHeader(0, 0, 0, 0, WebPacketFlags.RESOURCE, System.currentTimeMillis());
|
||||
}
|
||||
return new WebPacketHeader(
|
||||
in.getRequestId(),
|
||||
in.getTabId(),
|
||||
in.getPageId(),
|
||||
in.getFrameId(),
|
||||
in.getFlags() | WebPacketFlags.RESOURCE,
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
if (existing.isValid() && existing.getUser() != null) {
|
||||
return redirect302("dashboard.html", existing.getSessionId());
|
||||
}
|
||||
|
||||
WebRequestMethod method = ctx.request.getMethod();
|
||||
if (method == null) method = WebRequestMethod.GET;
|
||||
|
||||
if (method == WebRequestMethod.GET) {
|
||||
return ok(renderForm(null));
|
||||
}
|
||||
|
||||
if (method != WebRequestMethod.POST) {
|
||||
return text(405, "Method Not Allowed");
|
||||
}
|
||||
|
||||
String contentType = headerIgnoreCase(ctx.request.getHeaders(), "content-type");
|
||||
String ctLower = (contentType == null) ? "" : contentType.toLowerCase(Locale.ROOT);
|
||||
|
||||
if (!ctLower.startsWith("application/x-www-form-urlencoded")) {
|
||||
return ok(renderForm("Unsupported content-type: " + Html.esc(contentType)));
|
||||
}
|
||||
|
||||
Map<String, List<String>> form = parseFormUrlEncoded(ctx.request.getBody());
|
||||
String username = first(form, "username");
|
||||
String password = first(form, "password");
|
||||
|
||||
RegistrationService service = new RegistrationService(WebApp.get().users(), WebApp.get().passwordHasher());
|
||||
RegistrationService.Result r = service.register(username, password);
|
||||
|
||||
if (!r.ok()) {
|
||||
return ok(renderForm(r.error()));
|
||||
}
|
||||
|
||||
// 2) Create new session (user just registered)
|
||||
String ip = resolveIp(ctx);
|
||||
String ua = headerIgnoreCase(ctx.request.getHeaders(), "user-agent");
|
||||
if (ua == null) ua = "";
|
||||
|
||||
String session = SessionManager.create(
|
||||
String.valueOf(r.userId()),
|
||||
ip,
|
||||
ua,
|
||||
(ProtocolWebServer) ctx.client.getServer()
|
||||
);
|
||||
|
||||
return redirect302("dashboard.html", session);
|
||||
}
|
||||
}
|
||||
67
pom.xml
67
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.openautonomousconnection</groupId>
|
||||
<artifactId>INSServer</artifactId>
|
||||
<version>1.0.0-BETA.1.0</version>
|
||||
<version>1.0.1-BETA.0.3</version>
|
||||
<organization>
|
||||
<name>Open Autonomous Connection</name>
|
||||
<url>https://open-autonomous-connection.org/</url>
|
||||
@@ -15,8 +15,8 @@
|
||||
<description>The default INS-Server</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>23</maven.compiler.source>
|
||||
<maven.compiler.target>23</maven.compiler.target>
|
||||
<maven.compiler.source>25</maven.compiler.source>
|
||||
<maven.compiler.target>25</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@@ -53,47 +53,6 @@
|
||||
<name>Open Autonomous Public License (OAPL)</name>
|
||||
<url>https://open-autonomous-connection.org/license.html</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>GNU General Public License v3.0</name>
|
||||
<url>https://www.gnu.org/licenses/gpl-3.0.html</url>
|
||||
<comments>
|
||||
Default license: Applies to all users and projects unless an explicit alternative license has been
|
||||
granted.
|
||||
</comments>
|
||||
</license>
|
||||
<license>
|
||||
<name>LPGL 3</name>
|
||||
<url>https://www.gnu.org/licenses/lgpl-3.0.html#license-text</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>LPGL 2.1</name>
|
||||
<url>https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.en#SEC1</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>WTPL License</name>
|
||||
<url>https://github.com/ronmamo/reflections/tree/master?tab=WTFPL-1-ov-file</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>Apache License 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>MIT License</name>
|
||||
<url>https://opensource.org/license/mit</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>javassist</name>
|
||||
<url>https://github.com/jboss-javassist/javassist/blob/master/License.html</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>projectlombok</name>
|
||||
<url>https://github.com/projectlombok/lombok?tab=License-1-ov-file</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>mariadb</name>
|
||||
<url>https://mariadb.com/docs/general-resources/community/community/faq/licensing-questions/licensing-faq
|
||||
</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<repositories>
|
||||
@@ -110,19 +69,18 @@
|
||||
<dependency>
|
||||
<groupId>org.openautonomousconnection</groupId>
|
||||
<artifactId>Protocol</artifactId>
|
||||
<version>1.0.0-BETA.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.38</version>
|
||||
<scope>provided</scope>
|
||||
<version>1.0.1-BETA.0.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<version>3.5.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.42</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -153,6 +111,13 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.42</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
<compilerArgs>
|
||||
<arg>--add-exports</arg>
|
||||
<arg>java.base/sun.security.x509=ALL-UNNAMED</arg>
|
||||
|
||||
@@ -71,7 +71,7 @@ public final class DatabaseINSServer extends ProtocolINSServer {
|
||||
out.sort(recordComparator(type));
|
||||
return out;
|
||||
} catch (SQLException ex) {
|
||||
getProtocolBridge().getLogger().exception(
|
||||
getProtocolBridge().getProtocolValues().logger.exception(
|
||||
"INS resolve failed for " + formatName(tln, name, sub) + " type=" + type,
|
||||
ex
|
||||
);
|
||||
@@ -100,7 +100,7 @@ public final class DatabaseINSServer extends ProtocolINSServer {
|
||||
if (rs.next()) return rs.getString("info");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
getProtocolBridge().getLogger().exception("Failed to resolve TLN info site for tln=" + tln, ex);
|
||||
getProtocolBridge().getProtocolValues().logger.exception("Failed to resolve TLN info site for tln=" + tln, ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -131,12 +131,12 @@ public final class DatabaseINSServer extends ProtocolINSServer {
|
||||
String canonical = formatName(tln, name, sub).toLowerCase(Locale.ROOT);
|
||||
if (!visited.add(canonical)) {
|
||||
// loop detected
|
||||
getProtocolBridge().getLogger().warn("CNAME loop detected for " + canonical + " type=" + requestedType);
|
||||
getProtocolBridge().getProtocolValues().logger.warn("CNAME loop detected for " + canonical + " type=" + requestedType);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
if (depth > MAX_CNAME_DEPTH) {
|
||||
getProtocolBridge().getLogger().warn("CNAME recursion limit exceeded for " + canonical + " type=" + requestedType);
|
||||
getProtocolBridge().getProtocolValues().logger.warn("CNAME recursion limit exceeded for " + canonical + " type=" + requestedType);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ public final class DatabaseINSServer extends ProtocolINSServer {
|
||||
for (INSRecord cname : cnames) {
|
||||
TargetName target = parseCnameTarget(cname.value);
|
||||
if (target == null) {
|
||||
getProtocolBridge().getLogger().warn("Invalid CNAME target '" + cname.value + "' on " + canonical);
|
||||
getProtocolBridge().getProtocolValues().logger.warn("Invalid CNAME target '" + cname.value + "' on " + canonical);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ public class Listener extends EventListener {
|
||||
public void onCommandNotFound(CommandNotFoundEvent event) {
|
||||
StringBuilder argsBuilder = new StringBuilder();
|
||||
for (String arg : event.getArgs()) argsBuilder.append(arg).append(" ");
|
||||
Main.getProtocolBridge().getLogger().error("Command '" + event.getName() + argsBuilder.toString() + "' not found!");
|
||||
Main.getProtocolBridge().getProtocolValues().logger.error("Command '" + event.getName() + argsBuilder.toString() + "' not found!");
|
||||
}
|
||||
|
||||
@dev.unlegitdqrk.unlegitlibrary.event.Listener
|
||||
public void onMissingCommandPermission(CommandExecutorMissingPermissionEvent event) {
|
||||
Main.getProtocolBridge().getLogger().error("You do not have enough permissions to execute this command!");
|
||||
Main.getProtocolBridge().getProtocolValues().logger.error("You do not have enough permissions to execute this command!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package org.openautonomousconnection.insserver;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.addon.AddonLoader;
|
||||
import dev.unlegitdqrk.unlegitlibrary.command.CommandExecutor;
|
||||
import dev.unlegitdqrk.unlegitlibrary.command.CommandManager;
|
||||
import dev.unlegitdqrk.unlegitlibrary.command.CommandPermission;
|
||||
import dev.unlegitdqrk.unlegitlibrary.event.EventManager;
|
||||
import dev.unlegitdqrk.unlegitlibrary.file.ConfigurationManager;
|
||||
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
|
||||
import dev.unlegitdqrk.unlegitlibrary.utils.Logger;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.insserver.commands.StopCommand;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
@@ -29,10 +31,15 @@ public class Main {
|
||||
private static ProtocolValues values;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (!new File("logs").exists()) new File("logs").mkdir();
|
||||
Logger logger = new Logger(new File("logs"), false, true);
|
||||
|
||||
values = new ProtocolValues();
|
||||
values.packetHandler = new PacketHandler();
|
||||
values.eventManager = new EventManager();
|
||||
values.protocolVersion = ProtocolVersion.PV_1_0_1_BETA;
|
||||
values.eventManager.registerListener(new Listener());
|
||||
values.logger = logger;
|
||||
|
||||
if (!new File("config.properties").exists()) {
|
||||
new File("config.properties").createNewFile();
|
||||
@@ -69,8 +76,8 @@ public class Main {
|
||||
config.saveProperties();
|
||||
}
|
||||
|
||||
if (!config.isSet("ins.ins.frontend")) {
|
||||
config.set("ins.ins.frontend", "INS FRONTEND SITE (HOST)");
|
||||
if (!config.isSet("ins.frontend")) {
|
||||
config.set("ins.frontend", "INS FRONTEND SITE (HOST)");
|
||||
config.saveProperties();
|
||||
}
|
||||
|
||||
@@ -81,10 +88,10 @@ public class Main {
|
||||
int tcpPort = config.getInt("port");
|
||||
|
||||
String info = config.getString("ins.info");
|
||||
String frontend = config.getString("ins.ins.frontend");
|
||||
String frontend = config.getString("ins.frontend");
|
||||
|
||||
DatabaseINSServer server = new DatabaseINSServer(info, frontend, url, user, password);
|
||||
protocolBridge = new ProtocolBridge(server, values, ProtocolVersion.PV_1_0_0_BETA, new File("logs"));
|
||||
protocolBridge = new ProtocolBridge(server, values);
|
||||
server.start(tcpPort);
|
||||
|
||||
commandManager = new CommandManager(values.eventManager);
|
||||
|
||||
Reference in New Issue
Block a user