Made templates work with new data.

This commit is contained in:
Slatian 2023-08-05 21:09:56 +02:00
parent 727d9a77cd
commit fdb23312df
11 changed files with 155 additions and 20 deletions

View File

@ -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"

View File

@ -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<String>,
#[serde(default)]
pub aliases: Vec<String>,
#[serde(default="zero")]
pub weight: i32,
pub servers: Vec<SocketAddr>,
@ -39,6 +43,7 @@ pub struct DnsResolverConfig {
pub search: Vec<String>,
pub protocol: DnsProtocol,
pub tls_dns_name: Option<String>,
#[serde(skip_serializing)] //Don't leak our bind address to the outside
pub bind_address: Option<SocketAddr>,
#[serde(default="default_true")]
pub trust_nx_responses: bool,

View File

@ -56,6 +56,7 @@ pub struct TemplateSettings {
pub format: ResponseFormat,
pub lang: String,
pub available_dns_resolvers: Vec<Selectable>,
//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);

View File

@ -20,6 +20,10 @@
{% if extra.stylesheet %}<link rel="stylesheet" href="{{extra.stylesheet}}" type="text/css" />{% endif %}
{% if extra.favicon %}<link rel="icon" href="{{extra.favicon}}" type="{{extra.favicon_mimetype|default(value="image/png")}}" \>{% endif %}
<!-- View: {{view}} -->
{% set used_dns_resolver = "default" %}
{% if data.result.used_dns_resolver %}
{% set used_dns_resolver = data.result.used_dns_resolver %}
{% endif%}
</head>
<body>
<header>
@ -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 %}"/>
<select name="dns">
{% for r in dns_resolvers %}
<option value="{{ r.id }}" {% if r.id == used_dns_resolver %}selected{%endif%}>{{ r.name }}</option>
{% endfor %}
</select>
<input type="submit" value="Query"/>
</form>
</nav>

View File

@ -24,10 +24,10 @@
{% set r = data.result.records %}
<section>
<h2>DNS Records</h2>
<h2>DNS Records via {{data.result.used_dns_resolver}}</h2>
{% if r.nxdomain %}
<p class="error box">Our DNS-Server claims that this domain doesn't exist, you shouldn't see any results below.</p>
<p class="error box">Our DNS-Server claims that this domain doesn't exist, there shouldn't be any results.</p>
{% elif r.timeout %}
<p class="error box">There was at least one timeout error while resolving this domain, the results below are incomplete.</p>
{% elif r.other_error %}
@ -66,7 +66,7 @@
<li>{{ helper::ip(extra=extra, ip=address) }}</li>
{% endfor %}
</ul>
{% else %}
{% elif not r.nxdomain %}
<p>No <code>A</code> (IPv4) Records.</p>
{% endif %}
@ -77,7 +77,7 @@
<li>{{ helper::ip(extra=extra, ip=address) }}</li>
{% endfor %}
</ul>
{% else %}
{% elif not r.nxdomain %}
<p>No <code>AAAA</code> (IPv6) Records.</p>
{% endif %}
@ -90,7 +90,7 @@
<li>{{ helper::dig(extra=extra, name=mx.exchange, fqdn=true, prefix=mx.preference) }}</li>
{% endfor %}
</ul>
{% else %}
{% elif not r.nxdomain %}
<p id="mx">No <code>MX</code> (Mail Exchange) records.</p>
{% endif %}
@ -116,7 +116,7 @@
</dl></li>
{% endfor %}
</ul>
{% else %}
{% elif not r.nxdomain %}
<p id="soa">No <code>SOA</code> records.</p>
{% endif %}
@ -129,7 +129,7 @@
<li>{{ helper::dig(extra=extra, name=ns) }}</li>
{% endfor %}
</ul>
{% else %}
{% elif not r.nxdomain %}
<p id="ns">No <code>NS</code> (Name Server) records.</p>
{% endif %}
@ -141,7 +141,7 @@
<li><code>{{caa}}</code></li>
{% endfor %}
</ul>
{% else %}
{% elif not r.nxdomain %}
<p id="caa">No <code>CAA</code> (<a target="_blank" href="https://de.wikipedia.org/wiki/DNS_Certification_Authority_Authorization">Certification Authority Authorization</a>) records.</p>
{% endif %}
@ -152,7 +152,7 @@
<li><code>{{txt}}</code></li>
{% endfor %}
</ul>
{% else %}
{% elif not r.nxdomain %}
<p id="txt">No <code>TXT</code> records.</p>
{% endif %}
@ -172,7 +172,7 @@
</dl></li>
{% endfor %}
</ul>
{% else %}
{% elif not r.nxdomain %}
<p id="srv">No <code>SRV</code> records.</p>
<p><code>SRV</code> or Service records usually live on their own subdomains like {{ helper::dig(extra=extra, name="_xmpp-client._tcp."~data.query) }}.
{% endif %}

View File

@ -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 }}.

View File

@ -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 %}
<section>
<h2>Connection Configuration</h2>
<dl>
<dt>Address{% if c.servers | length > 1 %}es{% endif %}</dt>
{% 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 %}
<dd>{{ helper::ip(extra=extra, ip=ip) }}</dd>
{%- endfor %}
{%- else %}
<dd>None Configured</dd>
{%- endif %}
<dt>Protocol</dt>
<dd>{{ c.protocol }}</dd>
{%- if c.tls_dns_name %}
<dt>DNS Name</dt>
<dd>{{ helper::dig(extra=extra, name=c.tls_dns_name) }}</dd>
{%- endif %}
{%- if c.search | length > 0 %}
<dt>Search</dt>
{%- for s in c.search %}
<dd>{{s}}</dd>
{%- endfor %}
{%- endif %}
</dl>
{%- if c.info_url %}
<p class="button-paragraph"><a href="{{c.info_url}}">More about the {{c.display_name}} DNS Server <small>(external link)</small></a></p>
{%- endif %}
</section>
{%- if c.aliases | length > 0 %}
<section>
<h2>Aliases</h2>
<ul>
{%- for a in c.aliases %}
<li>{{a}}</li>
{%- endfor %}
</ul>
<p class="box hint">You can use this DNS server by typing <code>via {{c.aliases | first }}</code> {% if c.aliases | length > 1 %}(or any other alias){% endif %} in the searchfield.</p>
</section>
{% endif %}
{% endblock %}

View File

@ -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 %}

View File

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block title %}List of DNS Servers{% endblock %}
{% block h1 %}List of DNS Servers{% endblock %}
{% block content %}
<section>
<p>This is a list of DNS resolvers that are configured with this echoip service.</p>
<ul class="link-list">
{% for c in dns_resolvers %}
<li><a href="{{ extra.base_url }}/dns_resolver/{{c.id}}">{{c.name}}</a></li>
{% endfor %}
</ul>
<p>The reasons for them being here range from them being popular, privacy friendly, interesting, don't take the a server listed here as endorsement.</p>
</section>
{% endblock %}

View File

@ -0,0 +1,4 @@
# Here is a list of supported dns resolvers
{% for r in dns_resolvers %}
=> ./{{ r.id }} {{r.name}}
{%- endfor %}

View File

@ -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;
}