Skip to content

Commit

Permalink
feat: DoH ability to use custom servers
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Ortega <[email protected]>
  • Loading branch information
M0NsTeRRR committed Jun 1, 2024
1 parent 0c643c6 commit ba7a2d4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 25 deletions.
6 changes: 3 additions & 3 deletions docs/pages/configuration/config/web-ui.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ hyperglass provides extensive customization options for the look and feel of the

[DNS over HTTPS](https://www.rfc-editor.org/rfc/rfc8484) is used to look up an FQDN query target from the perspective of the user's browser.

| Parameter | Type | Default Value | Description |
| :------------------ | :----- | :------------ | :-------------------------------------- |
| `dns_provider.name` | String | cloudflare | Cloudflare or Google DNS are supported. |
| Parameter | Type | Default Value | Description |
| :------------------ | :----- | :-------------------------------------- | :-------------------------------------- |
| `dns_provider.url` | String | https://cloudflare-dns.com/dns-query | HTTP url of your dns provider |

### Logo

Expand Down
5 changes: 0 additions & 5 deletions hyperglass/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@

STATUS_CODE_MAP = {"warning": 400, "error": 400, "danger": 500}

DNS_OVER_HTTPS = {
"google": "https://dns.google/resolve",
"cloudflare": "https://cloudflare-dns.com/dns-query",
}

PARSED_RESPONSE_FIELDS = (
("Prefix", "prefix", "left"),
("Active", "active", None),
Expand Down
18 changes: 3 additions & 15 deletions hyperglass/models/config/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
from pathlib import Path

# Third Party
from pydantic import Field, HttpUrl, FilePath, ValidationInfo, field_validator, model_validator
from pydantic import Field, HttpUrl, FilePath, ValidationInfo, field_validator
from pydantic_extra_types.color import Color

# Project
from hyperglass.defaults import DEFAULT_HELP, DEFAULT_TERMS
from hyperglass.constants import DNS_OVER_HTTPS, FUNC_COLOR_MAP
from hyperglass.constants import FUNC_COLOR_MAP

# Local
from ..main import HyperglassModel
from .opengraph import OpenGraph

DEFAULT_IMAGES = Path(__file__).parent.parent.parent / "images"
DOH_PROVIDERS_PATTERN = "|".join(DNS_OVER_HTTPS.keys())
PERCENTAGE_PATTERN = r"^([1-9][0-9]?|100)\%?$"

Percentage = Field(pattern=r"^([1-9][0-9]?|100)\%$")
Expand Down Expand Up @@ -186,18 +185,7 @@ class Theme(HyperglassModel):
class DnsOverHttps(HyperglassModel):
"""Validation model for DNS over HTTPS resolution."""

name: str = Field(default="cloudflare", pattern=DOH_PROVIDERS_PATTERN)
url: str = ""

@model_validator(mode="before")
def validate_dns(cls, data: "DnsOverHttps") -> t.Dict[str, str]:
"""Assign url field to model based on selected provider."""
name = data.get("name", "cloudflare")
url = DNS_OVER_HTTPS[name]
return {
"name": name,
"url": url,
}
url: HttpUrl = "https://cloudflare-dns.com/dns-query"


class HighlightPattern(HyperglassModel):
Expand Down
2 changes: 1 addition & 1 deletion hyperglass/models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def convert_paths(self, value: t.Type[PathTypeT]) -> PathTypeT:
*(p for p in value.parts if p not in Settings.original_app_path.parts)
)

if isinstance(value, str) and str(Settings.original_app_path) in value:
if isinstance(value, str) and value.startswith(str(Settings.original_app_path)):
if Settings.container:
path = Path(value)
return str(
Expand Down
2 changes: 1 addition & 1 deletion hyperglass/ui/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ interface _Highlight {

interface _Web {
credit: _Credit;
dns_provider: { name: string; url: string };
dns_provider: { url: string };
links: _Link[];
menus: _Menu[];
greeting: _Greeting;
Expand Down

0 comments on commit ba7a2d4

Please sign in to comment.