This commit is contained in:
femsci 2023-12-11 19:33:47 +01:00
parent 1109fed17e
commit 2e2d21bea7
Signed by: femsci
GPG key ID: 08F7911F0E650C67
8 changed files with 93 additions and 22 deletions

View file

@ -9,6 +9,6 @@ namespace IPMeow.Lib.Server;
public class DnsServer : IRoutedServer public class DnsServer : IRoutedServer
{ {
public required IPAddress Address { get; set; } public required IPAddress Address { get; set; }
public required ICollection<Protocol> Protocols { get; set; } public required ICollection<Endpoint> Protocols { get; set; }
public bool SupportsTls { get; set; } public bool SupportsTls { get; set; }
} }

View file

@ -9,5 +9,5 @@ namespace IPMeow.Lib.Server;
public interface IRoutedServer public interface IRoutedServer
{ {
public IPAddress Address { get; set; } public IPAddress Address { get; set; }
public ICollection<Protocol> Protocols { get; set; } public ICollection<Endpoint> Protocols { get; set; }
} }

View file

@ -5,8 +5,9 @@ using System.Threading.Tasks;
namespace IPMeow.Lib.Server; namespace IPMeow.Lib.Server;
public struct Protocol public struct Endpoint
{ {
public short Port { get; set; } public short? Port { get; set; }
public string Protocol { get; set; }
public string Name { get; set; } public string Name { get; set; }
} }

View file

@ -7,7 +7,7 @@ namespace IPMeow.Lib.Server;
public static class Protocols public static class Protocols
{ {
private static readonly HashSet<Protocol> _protos = new() private static readonly HashSet<Endpoint> _protos = new()
{ {
Http, Http,
Dns, Dns,
@ -24,26 +24,26 @@ public static class Protocols
Imap Imap
}; };
public static readonly Protocol Http = new() { Name = "HTTP", Port = 80 }; public static readonly Endpoint Http = new() { Name = "HTTP", Port = 80 };
public static readonly Protocol Dns = new() { Name = "DNS", Port = 53 }; public static readonly Endpoint Dns = new() { Name = "DNS", Port = 53 };
public static readonly Protocol DnsOverTls = new() { Name = "DNS-over-TLS", Port = 853 }; public static readonly Endpoint DnsOverTls = new() { Name = "DNS-over-TLS", Port = 853 };
public static readonly Protocol DnsOverHttps = new() { Name = "DNS-over-HTTPS", Port = 443 }; public static readonly Endpoint DnsOverHttps = new() { Name = "DNS-over-HTTPS", Port = 443 };
public static readonly Protocol Ntp = new() { Name = "NTP", Port = 123 }; public static readonly Endpoint Ntp = new() { Name = "NTP", Port = 123 };
public static readonly Protocol Ssh = new() { Name = "SSH", Port = 22 }; public static readonly Endpoint Ssh = new() { Name = "SSH", Port = 22 };
public static readonly Protocol Snmp = new() { Name = "SNMP", Port = 161 }; public static readonly Endpoint Snmp = new() { Name = "SNMP", Port = 161 };
public static readonly Protocol Ldap = new() { Name = "LDAP", Port = 389 }; public static readonly Endpoint Ldap = new() { Name = "LDAP", Port = 389 };
public static readonly Protocol Kerberos = new() { Name = "Kerberos", Port = 88 }; public static readonly Endpoint Kerberos = new() { Name = "Kerberos", Port = 88 };
public static readonly Protocol Radius = new() { Name = "RADIUS", Port = 1812 }; public static readonly Endpoint Radius = new() { Name = "RADIUS", Port = 1812 };
public static readonly Protocol Smtp = new() { Name = "SMTP", Port = 25 }; public static readonly Endpoint Smtp = new() { Name = "SMTP", Port = 25 };
public static readonly Protocol Pop3 = new() { Name = "POP3", Port = 110 }; public static readonly Endpoint Pop3 = new() { Name = "POP3", Port = 110 };
public static readonly Protocol Imap = new() { Name = "IMAP", Port = 143 }; public static readonly Endpoint Imap = new() { Name = "IMAP", Port = 143 };
public static Protocol? GetByPort(short port) public static Endpoint? GetByPort(short port)
{ {
return _protos.SingleOrDefault(s => s.Port == port); return _protos.SingleOrDefault(s => s.Port == port);
} }
public static Protocol? GetByName(string name) public static Endpoint? GetByName(string name)
{ {
return _protos.SingleOrDefault(s => s.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); return _protos.SingleOrDefault(s => s.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
} }

View file

@ -8,6 +8,6 @@ public class Network
{ {
[Key] [Key]
public required string Name { get; set; } public required string Name { get; set; }
public virtual ICollection<DnsServer> DnsServers { get; set; } public virtual ICollection<IRoutedServer> ServiceServers { get; set; } = default!;
public virtual ICollection<Prefix> Networks { get; set; } public virtual ICollection<Prefix> Networks { get; set; } = default!;
} }

View file

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using IPMeow.Lib.Address;
using IPMeow.Lib.Site;
namespace IPMeow.Server.Address;
public class AddressManager
{
private readonly Dictionary<MacAddress, (IPAddress, DateTime)> _dynAssignments = new();
public IPv6Address AssignRandomV6(MacAddress addr, Network n)
{
throw new NotImplementedException();
IPv6Address ip = new(IPAddress.None);
_dynAssignments.Add(addr, (ip, DateTime.UtcNow));
}
public IPv4Address AssignRandomV4(MacAddress addr, Network n)
{
throw new NotImplementedException();
IPv4Address ip = new(IPAddress.None);
_dynAssignments.Add(addr, (ip, DateTime.UtcNow));
}
}

View file

@ -0,0 +1,38 @@
using IPMeow.Lib.Request;
using IPMeow.Lib.Site;
using IPMeow.Server.Data;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace IPMeow.Server.Controllers;
[ApiController]
[Route("api/network/v6")]
public class V6NetworkController : ControllerBase
{
public V6NetworkController(IpamContext data)
{
_data = data;
}
private readonly IpamContext _data;
[HttpGet("settings/{name}")]
public async Task<Network?> GetSettings(string name)
{
return await _data.Networks.AsNoTracking().SingleOrDefaultAsync(x => x.Name == name);
}
}
[ApiController]
[Route("api/network/v4")]
public class V4NetworkController : ControllerBase
{
public V4NetworkController(IpamContext data)
{
_data = data;
}
private readonly IpamContext _data;
}

View file

@ -1,4 +1,5 @@
using IPMeow.Lib.Host; using IPMeow.Lib.Host;
using IPMeow.Lib.Site;
using IPMeow.Server.Data.Model; using IPMeow.Server.Data.Model;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@ -9,6 +10,7 @@ public class IpamContext : DbContext
public DbSet<Lib.Host.Host> Hosts => Set<Lib.Host.Host>(); public DbSet<Lib.Host.Host> Hosts => Set<Lib.Host.Host>();
public DbSet<HostInterface> HostInterfaces => Set<HostInterface>(); public DbSet<HostInterface> HostInterfaces => Set<HostInterface>();
public DbSet<AddressAssignment> Assignments => Set<AddressAssignment>(); public DbSet<AddressAssignment> Assignments => Set<AddressAssignment>();
public DbSet<Network> Networks => Set<Network>();
protected override void OnConfiguring(DbContextOptionsBuilder opt) protected override void OnConfiguring(DbContextOptionsBuilder opt)
{ {