Updated everything to new INS
This commit is contained in:
205
ins_backend.sql
Normal file
205
ins_backend.sql
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
-- phpMyAdmin SQL Dump
|
||||||
|
-- version 5.2.1deb1+deb12u1
|
||||||
|
-- https://www.phpmyadmin.net/
|
||||||
|
--
|
||||||
|
-- Host: localhost:3306
|
||||||
|
-- Generation Time: Dec 11, 2025 at 11:00 AM
|
||||||
|
-- Server version: 10.11.14-MariaDB-0+deb12u2
|
||||||
|
-- PHP Version: 8.2.29
|
||||||
|
|
||||||
|
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||||
|
START TRANSACTION;
|
||||||
|
SET time_zone = "+00:00";
|
||||||
|
|
||||||
|
|
||||||
|
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||||
|
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||||
|
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||||
|
/*!40101 SET NAMES utf8mb4 */;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Database: `oac_ins`
|
||||||
|
--
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `infonames`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `infonames` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`info` varchar(63) NOT NULL,
|
||||||
|
`tln_id` int(11) NOT NULL,
|
||||||
|
`uid` int(11) NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `records`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `records` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`infoname_id` int(11) NOT NULL,
|
||||||
|
`subname_id` int(11) DEFAULT NULL,
|
||||||
|
`type` enum('A','AAAA','TXT','CNAME','MX','SRV','NS') NOT NULL,
|
||||||
|
`value` varchar(2048) NOT NULL,
|
||||||
|
`ttl` int(11) DEFAULT 3600,
|
||||||
|
`priority` int(11) DEFAULT NULL,
|
||||||
|
`port` int(11) DEFAULT NULL,
|
||||||
|
`weight` int(11) DEFAULT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `subnames`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `subnames` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`name` varchar(63) NOT NULL,
|
||||||
|
`infoname_id` int(11) NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `tln`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `tln` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`name` varchar(63) NOT NULL,
|
||||||
|
`info` text DEFAULT NULL,
|
||||||
|
`owner_id` int(11) DEFAULT NULL,
|
||||||
|
`is_public` tinyint(1) DEFAULT 1,
|
||||||
|
`allow_subdomains` tinyint(1) DEFAULT 1
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `users`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `users` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`uid` varchar(36) NOT NULL,
|
||||||
|
`username` varchar(64) NOT NULL,
|
||||||
|
`password` varchar(255) NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indexes for dumped tables
|
||||||
|
--
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indexes for table `infonames`
|
||||||
|
--
|
||||||
|
ALTER TABLE `infonames`
|
||||||
|
ADD PRIMARY KEY (`id`),
|
||||||
|
ADD KEY `tln_id` (`tln_id`),
|
||||||
|
ADD KEY `uid` (`uid`);
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indexes for table `records`
|
||||||
|
--
|
||||||
|
ALTER TABLE `records`
|
||||||
|
ADD PRIMARY KEY (`id`),
|
||||||
|
ADD KEY `infoname_id` (`infoname_id`),
|
||||||
|
ADD KEY `subname_id` (`subname_id`);
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indexes for table `subnames`
|
||||||
|
--
|
||||||
|
ALTER TABLE `subnames`
|
||||||
|
ADD PRIMARY KEY (`id`),
|
||||||
|
ADD KEY `infoname_id` (`infoname_id`);
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indexes for table `tln`
|
||||||
|
--
|
||||||
|
ALTER TABLE `tln`
|
||||||
|
ADD PRIMARY KEY (`id`),
|
||||||
|
ADD UNIQUE KEY `name` (`name`),
|
||||||
|
ADD KEY `owner_id` (`owner_id`);
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indexes for table `users`
|
||||||
|
--
|
||||||
|
ALTER TABLE `users`
|
||||||
|
ADD PRIMARY KEY (`id`),
|
||||||
|
ADD UNIQUE KEY `uid` (`uid`),
|
||||||
|
ADD UNIQUE KEY `username` (`username`);
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for dumped tables
|
||||||
|
--
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for table `infonames`
|
||||||
|
--
|
||||||
|
ALTER TABLE `infonames`
|
||||||
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for table `records`
|
||||||
|
--
|
||||||
|
ALTER TABLE `records`
|
||||||
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for table `subnames`
|
||||||
|
--
|
||||||
|
ALTER TABLE `subnames`
|
||||||
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for table `tln`
|
||||||
|
--
|
||||||
|
ALTER TABLE `tln`
|
||||||
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for table `users`
|
||||||
|
--
|
||||||
|
ALTER TABLE `users`
|
||||||
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Constraints for dumped tables
|
||||||
|
--
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Constraints for table `infonames`
|
||||||
|
--
|
||||||
|
ALTER TABLE `infonames`
|
||||||
|
ADD CONSTRAINT `infonames_ibfk_1` FOREIGN KEY (`tln_id`) REFERENCES `tln` (`id`) ON DELETE CASCADE,
|
||||||
|
ADD CONSTRAINT `infonames_ibfk_2` FOREIGN KEY (`uid`) REFERENCES `users` (`id`) ON DELETE CASCADE;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Constraints for table `records`
|
||||||
|
--
|
||||||
|
ALTER TABLE `records`
|
||||||
|
ADD CONSTRAINT `records_ibfk_1` FOREIGN KEY (`infoname_id`) REFERENCES `infonames` (`id`) ON DELETE CASCADE,
|
||||||
|
ADD CONSTRAINT `records_ibfk_2` FOREIGN KEY (`subname_id`) REFERENCES `subnames` (`id`) ON DELETE CASCADE;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Constraints for table `subnames`
|
||||||
|
--
|
||||||
|
ALTER TABLE `subnames`
|
||||||
|
ADD CONSTRAINT `subnames_ibfk_1` FOREIGN KEY (`infoname_id`) REFERENCES `infonames` (`id`) ON DELETE CASCADE;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Constraints for table `tln`
|
||||||
|
--
|
||||||
|
ALTER TABLE `tln`
|
||||||
|
ADD CONSTRAINT `tln_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE SET NULL;
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||||
|
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||||
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
8
pom.xml
8
pom.xml
@@ -70,7 +70,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openautonomousconnection</groupId>
|
<groupId>org.openautonomousconnection</groupId>
|
||||||
<artifactId>protocol</artifactId>
|
<artifactId>protocol</artifactId>
|
||||||
<version>1.0.0-BETA.7</version>
|
<version>1.0.0-BETA.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.38</version>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#Sat Oct 04 01:25:22 CEST 2025
|
|
||||||
server.site.info=DNS-SERVER INFO SITE IP
|
|
||||||
server.site.register=SERVER IP TO DNS-FRONTENT WEBSITE
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package org.openautonomousconnection.dns;
|
|
||||||
|
|
||||||
import org.openautonomousconnection.protocol.side.dns.ConnectedProtocolClient;
|
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerDNSServer;
|
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class ClassicHandler extends ClassicHandlerDNSServer {
|
|
||||||
@Override
|
|
||||||
public void handleMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Classic_Domain getDomain(Classic_RequestDomain requestDomain) throws SQLException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Classic_Domain ping(Classic_RequestDomain requestDomain) throws SQLException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unsupportedClassicPacket(String className, Object[] content, ConnectedProtocolClient client) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
package org.openautonomousconnection.dns;
|
|
||||||
|
|
||||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
|
||||||
import org.openautonomousconnection.protocol.side.dns.ConnectedProtocolClient;
|
|
||||||
import org.openautonomousconnection.protocol.side.dns.ProtocolDNSServer;
|
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode;
|
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Server extends ProtocolDNSServer {
|
|
||||||
/**
|
|
||||||
* Constructs a ProtocolDNSServer with the specified configuration file.
|
|
||||||
*
|
|
||||||
* @throws IOException If an I/O error occurs.
|
|
||||||
* @throws CertificateException If a certificate error occurs.
|
|
||||||
*/
|
|
||||||
public Server() throws IOException, CertificateException {
|
|
||||||
super(new File("config.properties"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Domain> getDomains() {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDomainDestination(Domain domain) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSubnameDestination(Domain domain, String subname) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTLNInfoSite(String topLevelName) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DNSResponseCode validateDomain(Domain requestedDomain) {
|
|
||||||
if (!requestedDomain.getProtocol().equalsIgnoreCase("oac")) return DNSResponseCode.RESPONSE_INVALID_REQUEST;
|
|
||||||
return DNSResponseCode.RESPONSE_DOMAIN_FULLY_NOT_EXIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validationPacketSendFailed(Domain domain, ConnectedProtocolClient client, Exception exception) {
|
|
||||||
ProtocolBridge.getInstance().getLogger().exception("Failed to send ValidationPacket. (" +
|
|
||||||
"Domain: " + domain.getProtocol() + "." + (domain.hasSubname() ? domain.getSubname() : "") + "." + domain.getTopLevelName() + "/" + domain.getPath() + "?" + domain.getQuery() + "#" + domain.getFragment() + ";" +
|
|
||||||
";Client: " + client.getConnectionHandler().getClientID() + ")", exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void domainDestinationPacketFailedSend(ConnectedProtocolClient client, Domain domain, DNSResponseCode validationResponse, Exception exception) {
|
|
||||||
ProtocolBridge.getInstance().getLogger().exception("Failed to send DomainDestinationPacket. (" +
|
|
||||||
"Domain: " + domain.getProtocol() + "." + (domain.hasSubname() ? domain.getSubname() : "") + "." + domain.getTopLevelName() + "/" + domain.getPath() + "?" + domain.getQuery() + "#" + domain.getFragment() + ";" +
|
|
||||||
"Validation response: " + validationResponse + ";Client: " + client.getConnectionHandler().getClientID() + ")", exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package org.openautonomousconnection.ins;
|
||||||
|
|
||||||
|
import org.openautonomousconnection.ins.utils.ClassicHelper;
|
||||||
|
import org.openautonomousconnection.ins.utils.ParsedDomain;
|
||||||
|
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||||
|
import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecordType;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerINSServer;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ClassicHandler extends ClassicHandlerINSServer {
|
||||||
|
|
||||||
|
private ProtocolBridge bridge() {
|
||||||
|
return Main.getProtocolBridge();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion) {
|
||||||
|
bridge().getLogger().info("[ClassicHandler] Message received from ClientID " + client.getConnectionHandler().getClientID() +
|
||||||
|
" (Classic Version " + protocolVersion.version + ", Client Version: " +
|
||||||
|
client.getClientVersion().toString() + "): " + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Classic_Domain getDomain(Classic_RequestDomain requestDomain) throws SQLException {
|
||||||
|
|
||||||
|
ParsedDomain pd = ClassicHelper.parseDomain(requestDomain);
|
||||||
|
|
||||||
|
// FIRST try A-record
|
||||||
|
List<INSRecord> a = bridge().getProtocolINSServer().resolve(pd.tln, pd.name, pd.sub, INSRecordType.A);
|
||||||
|
|
||||||
|
if (!a.isEmpty()) {
|
||||||
|
return ClassicHelper.buildClassicDomain(pd, a.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no A, try CNAME
|
||||||
|
List<INSRecord> cnameList = bridge().getProtocolINSServer().resolve(pd.tln, pd.name, pd.sub, INSRecordType.CNAME);
|
||||||
|
|
||||||
|
if (cnameList.isEmpty()) return null; // completely not found
|
||||||
|
|
||||||
|
INSRecord cname = cnameList.get(0);
|
||||||
|
|
||||||
|
// CNAME target = "www.example.net" or "app.dev"
|
||||||
|
String[] cnameParts = cname.value.split("\\.");
|
||||||
|
if (cnameParts.length < 2) return null;
|
||||||
|
|
||||||
|
String cnameTln = cnameParts[cnameParts.length - 1];
|
||||||
|
String cnameName = cnameParts[cnameParts.length - 2];
|
||||||
|
String cnameSub = cnameParts.length > 2
|
||||||
|
? String.join(".", java.util.Arrays.copyOfRange(cnameParts, 0, cnameParts.length - 2))
|
||||||
|
: null;
|
||||||
|
|
||||||
|
List<INSRecord> aAfterCname = bridge().getProtocolINSServer().resolve(cnameTln, cnameName, cnameSub, INSRecordType.A);
|
||||||
|
|
||||||
|
if (aAfterCname.isEmpty()) return null;
|
||||||
|
|
||||||
|
return ClassicHelper.buildClassicDomain(pd, aAfterCname.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Classic_Domain ping(Classic_RequestDomain req) {
|
||||||
|
return new Classic_Domain(req.name, req.topLevelDomain, null, req.path, bridge());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unsupportedClassicPacket(String className, Object[] content, ConnectedProtocolClient client) {
|
||||||
|
bridge().getLogger().warn(
|
||||||
|
"[Classic UnsupportedPacket] From client " + client.getConnectionHandler().getClientID() +
|
||||||
|
": packet=" + className + " content=" + java.util.Arrays.toString(content)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
package org.openautonomousconnection.ins;
|
||||||
|
|
||||||
|
import dev.unlegitdqrk.unlegitlibrary.file.ConfigurationManager;
|
||||||
|
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||||
|
import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecordType;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Concrete INS server implementation backed by a SQL database.
|
||||||
|
* <p>
|
||||||
|
* This implementation expects a table schema similar to:
|
||||||
|
* <pre>
|
||||||
|
* CREATE TABLE ins_records (
|
||||||
|
* id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
* tln VARCHAR(64) NOT NULL,
|
||||||
|
* name VARCHAR(255) NOT NULL,
|
||||||
|
* sub VARCHAR(255) NULL,
|
||||||
|
* type VARCHAR(16) NOT NULL, -- matches {@link INSRecordType#name()}
|
||||||
|
* value VARCHAR(1024) NOT NULL,
|
||||||
|
* priority INT NOT NULL,
|
||||||
|
* weight INT NOT NULL,
|
||||||
|
* port INT NOT NULL,
|
||||||
|
* ttl INT NOT NULL
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
* CREATE TABLE ins_tln_info (
|
||||||
|
* tln VARCHAR(64) PRIMARY KEY,
|
||||||
|
* host VARCHAR(255) NOT NULL,
|
||||||
|
* port INT NOT NULL
|
||||||
|
* );
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public final class DatabaseINSServer extends ProtocolINSServer {
|
||||||
|
|
||||||
|
private final String jdbcUrl;
|
||||||
|
private final String jdbcUser;
|
||||||
|
private final String jdbcPassword;
|
||||||
|
|
||||||
|
private final ConfigurationManager configurationManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new database-backed INS server.
|
||||||
|
*
|
||||||
|
* @throws IOException If the base server initialization fails.
|
||||||
|
* @throws CertificateException If required certificate files are missing or invalid.
|
||||||
|
*/
|
||||||
|
public DatabaseINSServer() throws IOException, CertificateException {
|
||||||
|
super(new File("config.properties"));
|
||||||
|
|
||||||
|
configurationManager = new ConfigurationManager(new File("config.properties"));
|
||||||
|
configurationManager.loadProperties();
|
||||||
|
|
||||||
|
if (!configurationManager.isSet("db.url")) {
|
||||||
|
configurationManager.set("db.url", "jdbc:mysql://localhost:3306/DB_NAME?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC\n");
|
||||||
|
configurationManager.saveProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!configurationManager.isSet("db.user")) {
|
||||||
|
configurationManager.set("db.user", "username");
|
||||||
|
configurationManager.saveProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!configurationManager.isSet("db.password")) {
|
||||||
|
configurationManager.set("db.password", "password");
|
||||||
|
configurationManager.saveProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
jdbcUrl = configurationManager.getString("db.url");
|
||||||
|
jdbcUser = configurationManager.getString("db.user");
|
||||||
|
jdbcPassword = configurationManager.getString("db.password");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Connection openConnection() throws SQLException {
|
||||||
|
return DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves records for the given INS name from the database.
|
||||||
|
* <p>
|
||||||
|
* This method does a single lookup and returns exactly the records that
|
||||||
|
* match the given query (no CNAME recursion here – that is handled on a
|
||||||
|
* higher level, e.g. via {@code INSRecordTools.resolveWithCNAME(...)}).
|
||||||
|
*
|
||||||
|
* @param tln Top-level-name.
|
||||||
|
* @param name InfoName.
|
||||||
|
* @param sub Optional sub-name. May be {@code null}.
|
||||||
|
* @param type Desired record type.
|
||||||
|
*
|
||||||
|
* @return List of matching {@link INSRecord}s, or an empty list if none exist.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<INSRecord> resolve(String tln, String name, String sub, INSRecordType type) {
|
||||||
|
List<INSRecord> result = new ArrayList<>();
|
||||||
|
|
||||||
|
String sql =
|
||||||
|
"SELECT type, value, priority, weight, port, ttl " +
|
||||||
|
"FROM ins_records " +
|
||||||
|
"WHERE tln = ? AND name = ? AND type = ? " +
|
||||||
|
"AND ( (sub IS NULL AND ? IS NULL) OR sub = ? )";
|
||||||
|
|
||||||
|
try (Connection conn = openConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||||
|
|
||||||
|
ps.setString(1, tln);
|
||||||
|
ps.setString(2, name);
|
||||||
|
ps.setString(3, type.name());
|
||||||
|
ps.setString(4, sub);
|
||||||
|
ps.setString(5, sub);
|
||||||
|
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
while (rs.next()) {
|
||||||
|
INSRecordType dbType = INSRecordType.valueOf(rs.getString("type"));
|
||||||
|
String value = rs.getString("value");
|
||||||
|
int priority = rs.getInt("priority");
|
||||||
|
int weight = rs.getInt("weight");
|
||||||
|
int port = rs.getInt("port");
|
||||||
|
int ttl = rs.getInt("ttl");
|
||||||
|
|
||||||
|
result.add(new INSRecord(dbType, value, priority, weight, port, ttl));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
getProtocolBridge().getLogger().exception("Failed to resolve INS record from database", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the TLN info site,
|
||||||
|
* which is used when a client queries {@code info.<tln>} without any sub-name.
|
||||||
|
* <p>
|
||||||
|
* The result must be returned as {@code "host:port"}.
|
||||||
|
*
|
||||||
|
* @param tln The TLN the client is asking about.
|
||||||
|
*
|
||||||
|
* @return A {@code "host:port"} string or {@code null} if no TLN info site is configured.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String resolveTLNInfoSite(String tln) {
|
||||||
|
String sql = "SELECT host, port FROM ins_tln_info WHERE tln = ?";
|
||||||
|
|
||||||
|
try (Connection conn = openConnection();
|
||||||
|
PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||||
|
|
||||||
|
ps.setString(1, tln);
|
||||||
|
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
String host = rs.getString("host");
|
||||||
|
int port = rs.getInt("port");
|
||||||
|
return host + ":" + port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
getProtocolBridge().getLogger().exception("Failed to resolve TLN info site for tln=" + tln, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.openautonomousconnection.dns;
|
package org.openautonomousconnection.ins;
|
||||||
|
|
||||||
import dev.unlegitdqrk.unlegitlibrary.command.events.CommandExecutorMissingPermissionEvent;
|
import dev.unlegitdqrk.unlegitlibrary.command.events.CommandExecutorMissingPermissionEvent;
|
||||||
import dev.unlegitdqrk.unlegitlibrary.command.events.CommandNotFoundEvent;
|
import dev.unlegitdqrk.unlegitlibrary.command.events.CommandNotFoundEvent;
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
package org.openautonomousconnection.dns;
|
package org.openautonomousconnection.ins;
|
||||||
|
|
||||||
import dev.unlegitdqrk.unlegitlibrary.command.CommandExecutor;
|
import dev.unlegitdqrk.unlegitlibrary.command.CommandExecutor;
|
||||||
import dev.unlegitdqrk.unlegitlibrary.command.CommandManager;
|
import dev.unlegitdqrk.unlegitlibrary.command.CommandManager;
|
||||||
import dev.unlegitdqrk.unlegitlibrary.command.CommandPermission;
|
import dev.unlegitdqrk.unlegitlibrary.command.CommandPermission;
|
||||||
import dev.unlegitdqrk.unlegitlibrary.utils.Logger;
|
import lombok.Getter;
|
||||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||||
import org.openautonomousconnection.protocol.ProtocolSettings;
|
import org.openautonomousconnection.protocol.ProtocolSettings;
|
||||||
|
import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
|
||||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||||
|
|
||||||
|
import javax.annotation.processing.Generated;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
@@ -18,11 +18,13 @@ public class Main {
|
|||||||
private static final CommandExecutor commandExecutor = new CommandExecutor("DNS", PERMISSION_ALL) {};
|
private static final CommandExecutor commandExecutor = new CommandExecutor("DNS", PERMISSION_ALL) {};
|
||||||
private static CommandManager commandManager;
|
private static CommandManager commandManager;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static ProtocolBridge protocolBridge;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
ProtocolSettings settings = new ProtocolSettings();
|
ProtocolSettings settings = new ProtocolSettings();
|
||||||
new ProtocolBridge(new Server(), settings, ProtocolVersion.PV_1_0_0_BETA, new File("logs"));
|
protocolBridge = new ProtocolBridge(new DatabaseINSServer(), settings, ProtocolVersion.PV_1_0_0_BETA, new File("logs"));
|
||||||
ProtocolBridge.getInstance().setClassicHandlerDNSServer(new ClassicHandler());
|
commandManager = new CommandManager(protocolBridge.getProtocolSettings().eventManager);
|
||||||
commandManager = new CommandManager(ProtocolBridge.getInstance().getProtocolSettings().eventManager);
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.openautonomousconnection.ins.utils;
|
||||||
|
|
||||||
|
import org.openautonomousconnection.ins.Main;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||||
|
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||||
|
|
||||||
|
public class ClassicHelper {
|
||||||
|
public static Classic_Domain buildClassicDomain(ParsedDomain req, INSRecord rec) {
|
||||||
|
Classic_Domain info = new Classic_Domain(req.name, req.tln, req.sub, req.path, Main.getProtocolBridge());
|
||||||
|
|
||||||
|
String host = rec.value;
|
||||||
|
int port = rec.port > 0 ? rec.port : 80;
|
||||||
|
|
||||||
|
return new Classic_Domain(
|
||||||
|
req.name, req.tln,
|
||||||
|
host.contains(":") ? host : host + ":" + port,
|
||||||
|
req.path, Main.getProtocolBridge());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ParsedDomain parseDomain(Classic_RequestDomain req) {
|
||||||
|
String tln = req.topLevelDomain; // example: "net"
|
||||||
|
String full = req.name; // example: "api.v1.example"
|
||||||
|
|
||||||
|
String[] parts = full.split("\\.");
|
||||||
|
|
||||||
|
if (parts.length == 1) {
|
||||||
|
return new ParsedDomain(tln, full, null, req.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = parts[parts.length - 1];
|
||||||
|
String sub = parts.length > 1
|
||||||
|
? String.join(".", java.util.Arrays.copyOfRange(parts, 0, parts.length - 1))
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return new ParsedDomain(tln, name, sub, req.path);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.openautonomousconnection.ins.utils;
|
||||||
|
|
||||||
|
public final class ParsedDomain {
|
||||||
|
public final String tln;
|
||||||
|
public final String name;
|
||||||
|
public final String sub;
|
||||||
|
public final String path;
|
||||||
|
|
||||||
|
public ParsedDomain(String tln, String name, String sub, String path) {
|
||||||
|
this.tln = tln;
|
||||||
|
this.name = name;
|
||||||
|
this.sub = sub;
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user