From fdb23312df043a971a4be292e9aacf2a141bae87 Mon Sep 17 00:00:00 2001 From: Slatian Date: Sat, 5 Aug 2023 21:09:56 +0200 Subject: [PATCH] Made templates work with new data. --- echoip_test.toml | 4 +++ src/config/dns.rs | 5 +++ src/templating_engine.rs | 2 ++ templates/base.html | 9 +++++ templates/dig.html | 20 +++++------ templates/dig.txt | 18 +++++----- templates/dns_resolver.html | 57 ++++++++++++++++++++++++++++++++ templates/dns_resolver.txt | 38 +++++++++++++++++++++ templates/dns_resolver_list.html | 16 +++++++++ templates/dns_resolver_list.txt | 4 +++ templates/static/style.css | 2 +- 11 files changed, 155 insertions(+), 20 deletions(-) create mode 100644 templates/dns_resolver.html create mode 100644 templates/dns_resolver.txt create mode 100644 templates/dns_resolver_list.html create mode 100644 templates/dns_resolver_list.txt diff --git a/echoip_test.toml b/echoip_test.toml index dccccac..96dde4c 100644 --- a/echoip_test.toml +++ b/echoip_test.toml @@ -63,6 +63,10 @@ burst = 15 [dns.resolver.digitalcourage] display_name = "Digitalcourage 3" +info_url = "https://digitalcourage.de/support/zensurfreier-dns-server" +aliases = ["dc","dc3","digitalcourage3"] + servers = ["5.9.164.112:853","[2a01:4f8:251:554::2]:853"] protocol = "tls" tls_dns_name = "dns3.digitalcourage.de" + diff --git a/src/config/dns.rs b/src/config/dns.rs index da0188e..2ea25a3 100644 --- a/src/config/dns.rs +++ b/src/config/dns.rs @@ -32,6 +32,10 @@ pub fn default_dns_resolver_name() -> String { #[derive(Deserialize, Serialize, Clone)] pub struct DnsResolverConfig { pub display_name: String, + #[serde(default)] + pub info_url: Option, + #[serde(default)] + pub aliases: Vec, #[serde(default="zero")] pub weight: i32, pub servers: Vec, @@ -39,6 +43,7 @@ pub struct DnsResolverConfig { pub search: Vec, pub protocol: DnsProtocol, pub tls_dns_name: Option, + #[serde(skip_serializing)] //Don't leak our bind address to the outside pub bind_address: Option, #[serde(default="default_true")] pub trust_nx_responses: bool, diff --git a/src/templating_engine.rs b/src/templating_engine.rs index fb3d60a..e64efaf 100644 --- a/src/templating_engine.rs +++ b/src/templating_engine.rs @@ -56,6 +56,7 @@ pub struct TemplateSettings { pub format: ResponseFormat, pub lang: String, pub available_dns_resolvers: Vec, + //pub dns_resolver: String, } #[derive(serde::Deserialize, serde::Serialize, Clone)] @@ -118,6 +119,7 @@ impl Engine { //intented for shared macros context.insert("format", &settings.format.to_string()); context.insert("language", &settings.lang); + context.insert("dns_resolvers", &settings.available_dns_resolvers); context.insert("data", &view); context.insert("extra", &self.template_config); diff --git a/templates/base.html b/templates/base.html index 8be005c..60d0491 100644 --- a/templates/base.html +++ b/templates/base.html @@ -20,6 +20,10 @@ {% if extra.stylesheet %}{% endif %} {% if extra.favicon %}{% endif %} + {% set used_dns_resolver = "default" %} + {% if data.result.used_dns_resolver %} + {% set used_dns_resolver = data.result.used_dns_resolver %} + {% endif%}
@@ -30,6 +34,11 @@ title="Search for an IP-Adress, Domain-Name, or ASN." placeholder="1.2.3.4, 2001::1:2:3:4, example.org, AS1234" value="{% if view == "dig" %}{{ data.query }}{% elif view == "ip" %}{{ data.result.address }}{% elif view == "asn"%}AS{{ data.asn }}{% endif %}"/> + diff --git a/templates/dig.html b/templates/dig.html index fffa081..2c17877 100644 --- a/templates/dig.html +++ b/templates/dig.html @@ -24,10 +24,10 @@ {% set r = data.result.records %}
-

DNS Records

+

DNS Records via {{data.result.used_dns_resolver}}

{% if r.nxdomain %} -

Our DNS-Server claims that this domain doesn't exist, you shouldn't see any results below.

+

Our DNS-Server claims that this domain doesn't exist, there shouldn't be any results.

{% elif r.timeout %}

There was at least one timeout error while resolving this domain, the results below are incomplete.

{% elif r.other_error %} @@ -66,7 +66,7 @@
  • {{ helper::ip(extra=extra, ip=address) }}
  • {% endfor %} - {% else %} + {% elif not r.nxdomain %}

    No A (IPv4) Records.

    {% endif %} @@ -77,7 +77,7 @@
  • {{ helper::ip(extra=extra, ip=address) }}
  • {% endfor %} - {% else %} + {% elif not r.nxdomain %}

    No AAAA (IPv6) Records.

    {% endif %} @@ -90,7 +90,7 @@
  • {{ helper::dig(extra=extra, name=mx.exchange, fqdn=true, prefix=mx.preference) }}
  • {% endfor %} - {% else %} + {% elif not r.nxdomain %}

    No MX (Mail Exchange) records.

    {% endif %} @@ -116,7 +116,7 @@ {% endfor %} - {% else %} + {% elif not r.nxdomain %}

    No SOA records.

    {% endif %} @@ -129,7 +129,7 @@
  • {{ helper::dig(extra=extra, name=ns) }}
  • {% endfor %} - {% else %} + {% elif not r.nxdomain %}

    No NS (Name Server) records.

    {% endif %} @@ -141,7 +141,7 @@
  • {{caa}}
  • {% endfor %} - {% else %} + {% elif not r.nxdomain %}

    No CAA (Certification Authority Authorization) records.

    {% endif %} @@ -152,7 +152,7 @@
  • {{txt}}
  • {% endfor %} - {% else %} + {% elif not r.nxdomain %}

    No TXT records.

    {% endif %} @@ -172,7 +172,7 @@ {% endfor %} - {% else %} + {% elif not r.nxdomain %}

    No SRV records.

    SRV or Service records usually live on their own subdomains like {{ helper::dig(extra=extra, name="_xmpp-client._tcp."~data.query) }}. {% endif %} diff --git a/templates/dig.txt b/templates/dig.txt index 33847ad..2b32473 100644 --- a/templates/dig.txt +++ b/templates/dig.txt @@ -26,7 +26,7 @@ Your IDN would decode to {% set r = data.result.records -%} ## DNS Records {% if r.nxdomain %} -Our DNS-Server claims that this domain doesn't exist, you shouldn't see any results below. +Our DNS-Server claims that this domain doesn't exist, there shouldn't be any results. {%- elif r.timeout -%} There was at least one timeout error while resolving this domain, the results below are incomplete. {%- elif r.other_error -%} @@ -61,7 +61,7 @@ A (IPv4) records: {% for address in r.a -%} * {{ address }} {% endfor %} -{%- else %} +{%- elif not r.nxdomain %} No A (IPv4) Records. {% endif -%} @@ -70,7 +70,7 @@ AAAA (IPv6) records: {% for address in r.aaaa -%} * {{ address }} {% endfor %} -{%- else %} +{%- elif not r.nxdomain %} No AAAA (IPv6) Records. {% endif -%} @@ -81,7 +81,7 @@ MX (Mail Exchange) records: {% for mx in r.mx | sort(attribute="preference") | reverse -%} * {{ mx.preference }} {{ mx.exchange }} {% endfor %} -{%- else %} +{%- elif not r.nxdomain %} No MX (Mail Exchange) records. {% endif %} @@ -96,7 +96,7 @@ SOA (Source Of Authority) records: * expire: {{soa.expire / 3600 | round(precision=2)}}h * minimum: {{soa.minimum / 60 | round(precision=2)}}m TTL {% endfor %} -{%- else %} +{%- elif not r.nxdomain %} No SOA (Source Of Authority) records. {% endif %} @@ -105,7 +105,7 @@ NS (Name Server) records: {% for ns in r.ns -%} * {{ns}} {% endfor %} -{%- else %} +{%- elif not r.nxdomain %} No NS (Name Server) records. {% endif %} @@ -114,7 +114,7 @@ CAA (Certification Authority Authorization) records: {% for caa in r.caa -%} * {{caa}} {% endfor %} -{%- else %} +{%- elif not r.nxdomain %} No CAA (Certification Authority Authorization) records. {% endif %} @@ -123,7 +123,7 @@ TXT records: {% for txt in r.txt -%} * {{txt}} {% endfor %} -{%- else %} +{%- elif not r.nxdomain %} No TXT records. {% endif %} @@ -135,7 +135,7 @@ SRV records: * Port: {{srv.port}} * Target: {{srv.target}} {% endfor %} -{%- else %} +{%- elif not r.nxdomain %} No SRV records. SRV or Service records usually live on their own subdomains like {{ "_xmpp-client._tcp."~data.query }}. diff --git a/templates/dns_resolver.html b/templates/dns_resolver.html new file mode 100644 index 0000000..5d8a195 --- /dev/null +++ b/templates/dns_resolver.html @@ -0,0 +1,57 @@ +{% extends "base.html" %} +{% import "helpers.html" as helper %} + +{% block title %}{{ data.config.display_name }}{% endblock %} +{% block h1 %}DNS Resolver: {{ data.config.display_name }}{% endblock %} + +{% block content %} +{%- set c = data.config %} +

    +

    Connection Configuration

    +
    +
    Address{% if c.servers | length > 1 %}es{% endif %}
    + {% if c.servers | length > 0 %} + {%- for a in c.servers %} + {% if a is matching("^\[") %} + {% set ip = a | split(pat="]") | first | trim_start_matches(pat="[") %} + {% else %} + {% set ip = a | split(pat=":") | first %} + {% endif %} +
    {{ helper::ip(extra=extra, ip=ip) }}
    + {%- endfor %} + {%- else %} +
    None Configured
    + {%- endif %} + +
    Protocol
    +
    {{ c.protocol }}
    + + {%- if c.tls_dns_name %} +
    DNS Name
    +
    {{ helper::dig(extra=extra, name=c.tls_dns_name) }}
    + {%- endif %} + + {%- if c.search | length > 0 %} +
    Search
    + {%- for s in c.search %} +
    {{s}}
    + {%- endfor %} + {%- endif %} +
    + {%- if c.info_url %} +

    More about the {{c.display_name}} DNS Server (external link)

    + {%- endif %} +
    + +{%- if c.aliases | length > 0 %} +
    +

    Aliases

    +
      + {%- for a in c.aliases %} +
    • {{a}}
    • + {%- endfor %} +
    +

    You can use this DNS server by typing via {{c.aliases | first }} {% if c.aliases | length > 1 %}(or any other alias){% endif %} in the searchfield.

    +
    +{% endif %} +{% endblock %} diff --git a/templates/dns_resolver.txt b/templates/dns_resolver.txt new file mode 100644 index 0000000..89e653c --- /dev/null +++ b/templates/dns_resolver.txt @@ -0,0 +1,38 @@ +# DNS Resolver: {{ data.config.display_name }} + +{%- set c = data.config %} +{% if c.servers | length == 1 %} +Address: {{ c.servers | first }} +{% elif c.servers | length > 1 %} +Addresses: +{%- for a in c.servers %} +* {{a}} +{%- endfor %} +{%- else %} +Address: None Configured +{%- endif %} + +Protocol: {{ c.protocol }} +{%-if c.tls_dns_name %} +DNS Name: {{ c.tls_dns_name }} +{%- endif %} +{%- if c.search | length == 1 %} +Search: {{ c.search | first }} +{%- elif c.search | length > 1 %} +Search: +{%- for s in c.search %} +* {{s}} +{%- endfor %} +{%- endif %} +{%- if c.aliases | length == 1 %} +Alias: {{ c.aliases | first }} +{%- elif c.aliases | length > 1 %} +Aliases: +{%- for a in c.aliases %} +* {{a}} +{%- endfor %} +{%- endif %} +{%- if c.info_url %} + +=> {{ c.info_url }} +{%- endif %} diff --git a/templates/dns_resolver_list.html b/templates/dns_resolver_list.html new file mode 100644 index 0000000..dc18b3c --- /dev/null +++ b/templates/dns_resolver_list.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block title %}List of DNS Servers{% endblock %} +{% block h1 %}List of DNS Servers{% endblock %} + +{% block content %} +
    +

    This is a list of DNS resolvers that are configured with this echoip service.

    + +

    The reasons for them being here range from them being popular, privacy friendly, interesting, don't take the a server listed here as endorsement.

    +
    +{% endblock %} diff --git a/templates/dns_resolver_list.txt b/templates/dns_resolver_list.txt new file mode 100644 index 0000000..5e11045 --- /dev/null +++ b/templates/dns_resolver_list.txt @@ -0,0 +1,4 @@ +# Here is a list of supported dns resolvers +{% for r in dns_resolvers %} +=> ./{{ r.id }} {{r.name}} +{%- endfor %} diff --git a/templates/static/style.css b/templates/static/style.css index 5ea4b48..061ad3b 100644 --- a/templates/static/style.css +++ b/templates/static/style.css @@ -571,7 +571,7 @@ tr:hover, th { /* Search form styling */ -form.search > input { +form.search > input, form.search > select { font-size: 1.2em; font-weight: bold; }