From 91bffe153a897360fe3f4d1dc9992f3a4cb98f02 Mon Sep 17 00:00:00 2001 From: Hannaeko Date: Fri, 9 May 2025 16:57:06 +0200 Subject: [PATCH] make services a sections --- locales/en/main.ftl | 4 ++-- locales/fr/main.ftl | 4 ++-- src/resources/dns/friendly/rdata.rs | 31 +++++++++++++++++++++++------ src/resources/dns/internal/rdata.rs | 7 ++++--- templates/macros/display_rrset.html | 25 ++++++++++------------- templates/pages/records.html | 15 ++++++++++++++ 6 files changed, 59 insertions(+), 27 deletions(-) diff --git a/locales/en/main.ftl b/locales/en/main.ftl index 5a28eda..74da349 100644 --- a/locales/en/main.ftl +++ b/locales/en/main.ftl @@ -8,10 +8,11 @@ zone-content-aliases-header = Aliases zone-content-section-web-header = Web zone-content-section-mail-header = E-mail +zone-content-section-services-header = Services zone-content-section-general-header = General zone-content-record-type-address = - .type-name = Addresses + .type-name = IP addresses zone-content-record-type-mailserver = .type-name = E-mail servers @@ -22,7 +23,6 @@ zone-content-record-type-nameserver = zone-content-record-type-service = .type-name = Services - .data-address = Address: { $address } .data-priority = Priority: { $priority } .data-weight = Weight: { $weight } diff --git a/locales/fr/main.ftl b/locales/fr/main.ftl index 63ba1e0..ea94b46 100644 --- a/locales/fr/main.ftl +++ b/locales/fr/main.ftl @@ -8,10 +8,11 @@ zone-content-aliases-header = Alias zone-content-section-web-header = Web zone-content-section-mail-header = Courriel +zone-content-section-services-header = Services zone-content-section-general-header = Général zone-content-record-type-address = - .type-name = Adresses + .type-name = Adresses IP zone-content-record-type-mailserver = .type-name = Serveurs de courriel @@ -22,7 +23,6 @@ zone-content-record-type-nameserver = zone-content-record-type-service = .type-name = Services - .data-address = Adresse : { $address } .data-priority = Priorité : { $priority } .data-weight = Poids : { $weight } diff --git a/src/resources/dns/friendly/rdata.rs b/src/resources/dns/friendly/rdata.rs index 9cdb40f..84ddcc2 100644 --- a/src/resources/dns/friendly/rdata.rs +++ b/src/resources/dns/friendly/rdata.rs @@ -1,4 +1,4 @@ -use std::fmt; +use std::{collections::HashMap, fmt}; use serde::{Deserialize, Serialize, Serializer, ser::SerializeStruct}; @@ -157,15 +157,25 @@ impl WebConfiguration { pub struct FriendlyRecordSetGroup { owner: String, general_records: Vec>, + #[serde(serialize_with = "as_vector")] + services: HashMap>, mail: Option, web: Option, } +fn as_vector(services: &HashMap>, ser: S) -> Result + where S: Serializer +{ + let container: Vec<_> = services.iter().collect(); + serde::Serialize::serialize(&container, ser) +} + impl FriendlyRecordSetGroup { pub fn new(owner: String) -> Self { FriendlyRecordSetGroup { owner, general_records: Vec::new(), + services: HashMap::new(), mail: None, web: None, } @@ -237,6 +247,11 @@ impl From for FriendlyRecords { mail.spf = Some(FriendlyRecord::new(ttl, spf)); }, + FriendlyRData::Service(service) => { + let services = current_group.services.entry(service.service_type.clone()).or_insert(FriendlyRecordSet::new(ttl)); + + services.data.push(service) + } FriendlyRData::Alias(_) => {}, data => { // TODO: NS -> Skip if NS for zone (authority), create Delegation section with glue + DS for others (how to check if record is glue?) @@ -278,18 +293,22 @@ impl HasRType for Address { #[derive(Debug, Deserialize, Serialize)] pub struct Service { pub service_type: ServiceType, - pub service_name: Option, - pub service_protocol: Option, pub port: i64, pub weight: i64, pub priority: i64, pub server: String, } -#[derive(Debug, Deserialize, Serialize)] -#[serde(rename_all = "lowercase")] +#[derive(Debug, Deserialize, Serialize, Hash, Eq, PartialEq, Clone)] +#[serde(rename_all = "lowercase", tag = "service_type")] pub enum ServiceType { - Other, + Other { protocol: String, name: String }, +} + +impl HasRType for Service { + fn rtype(&self) -> FriendlyRType { + FriendlyRType::Service + } } #[derive(Debug, Deserialize, Serialize)] diff --git a/src/resources/dns/internal/rdata.rs b/src/resources/dns/internal/rdata.rs index 395cbe4..c8380c3 100644 --- a/src/resources/dns/internal/rdata.rs +++ b/src/resources/dns/internal/rdata.rs @@ -148,9 +148,10 @@ impl Srv { let protocol = labels[1]. strip_prefix('_'); if let (Some(service_name), Some(protocol)) = (service_name, protocol) { Some((labels[2].to_string(), friendly::FriendlyRData::Service(friendly::Service { - service_type: friendly::ServiceType::Other, - service_name: Some(service_name.into()), - service_protocol: Some(protocol.into()), + service_type: friendly::ServiceType::Other { + name: service_name.into(), + protocol: protocol.into() + }, port: self.port.into(), weight: self.weight.into(), priority: self.priority.into(), diff --git a/templates/macros/display_rrset.html b/templates/macros/display_rrset.html index 0542d21..83240db 100644 --- a/templates/macros/display_rrset.html +++ b/templates/macros/display_rrset.html @@ -1,7 +1,15 @@ -{% macro rrset(rtype, ttl, data, zone, lang) %} +{% macro rrset(rtype, ttl, data, zone, lang, service_type="") %}