mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Fixed port assumption
This commit is contained in:
1 parent
e5fb0f0dbb
commit
ba7b662b93
3 files changed
+31
-6
No files matched your search
@@ -36,10 +36,15 @@ class Remote:
|
|||||||
username: str = ""
|
username: str = ""
|
||||||
|
|
||||||
def addresses(self) -> list[tuple[str, str]]:
|
def addresses(self) -> list[tuple[str, str]]:
|
||||||
"""`(label, base url)`, primary first — the order every connect tries."""
|
"""`(label, base url)`, primary first — the order every connect tries.
|
||||||
|
|
||||||
|
Each address keeps its OWN port. The fallback once borrowed the
|
||||||
|
primary's, so a reverse-proxied fallback (`konduktor.example.net`,
|
||||||
|
served on 443) was tried at `:8765` because the LAN address named it.
|
||||||
|
"""
|
||||||
out = [("primary", _base(self.host, self.port))]
|
out = [("primary", _base(self.host, self.port))]
|
||||||
if self.fallback_host:
|
if self.fallback_host:
|
||||||
out.append(("fallback", _base(self.fallback_host, self.fallback_port or self.port)))
|
out.append(("fallback", _base(self.fallback_host, self.fallback_port)))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def public(self) -> dict:
|
def public(self) -> dict:
|
||||||
@@ -47,9 +52,11 @@ class Remote:
|
|||||||
|
|
||||||
|
|
||||||
def _base(host: str, port: int | None) -> str:
|
def _base(host: str, port: int | None) -> str:
|
||||||
|
"""An address as typed → a base URL. A full URL (`https://…`, the way to
|
||||||
|
reach a server behind the user's own reverse proxy) is taken exactly as
|
||||||
|
given, port and all; anything else is plain HTTP on its port, else 8765."""
|
||||||
host = host.strip()
|
host = host.strip()
|
||||||
if host.startswith("http://") or host.startswith("https://"):
|
if host.startswith("http://") or host.startswith("https://"):
|
||||||
# A full URL (behind the user's own reverse proxy): taken as given.
|
|
||||||
return host.rstrip("/")
|
return host.rstrip("/")
|
||||||
bare, inline = split_host(host)
|
bare, inline = split_host(host)
|
||||||
if inline is not None:
|
if inline is not None:
|
||||||
|
|||||||
@@ -121,6 +121,24 @@ back = rp.unpack_analysis(rp.pack_analysis(PreparedAnalysis(measured=measured, k
|
|||||||
check("…and the detected key", back.key == key, back.key)
|
check("…and the detected key", back.key == key, back.key)
|
||||||
check("no analysis is None", rp.pack_analysis(None) is None and rp.unpack_analysis(None) is None)
|
check("no analysis is None", rp.pack_analysis(None) is None and rp.unpack_analysis(None) is None)
|
||||||
|
|
||||||
|
print("== remote addresses ==")
|
||||||
|
from konduktor.adapters.remote.config import Remote
|
||||||
|
|
||||||
|
r = Remote(id="r", name="NAS", host="192.168.1.20", port=8765, fallback_host="konduktor.example.net")
|
||||||
|
check("each address is built from its own parts",
|
||||||
|
r.addresses() == [("primary", "http://192.168.1.20:8765"), ("fallback", "http://konduktor.example.net:8765")],
|
||||||
|
r.addresses())
|
||||||
|
r = Remote(id="r", name="NAS", host="192.168.1.20", port=9000, fallback_host="konduktor.example.net")
|
||||||
|
check("…so a bare fallback gets the default port, not the primary's 9000",
|
||||||
|
r.addresses()[1] == ("fallback", "http://konduktor.example.net:8765"), r.addresses())
|
||||||
|
r = Remote(id="r", name="NAS", host="192.168.1.20", port=9000, fallback_host="https://konduktor.example.net/")
|
||||||
|
check("a full URL is used exactly as typed (a reverse proxy's port)",
|
||||||
|
r.addresses()[1] == ("fallback", "https://konduktor.example.net"), r.addresses())
|
||||||
|
r = Remote(id="r", name="NAS", host="http://nas.lan:8080")
|
||||||
|
check("…a URL with its own port keeps it", r.addresses() == [("primary", "http://nas.lan:8080")])
|
||||||
|
check("host:port typed inline is split", Remote(id="r", name="N", host="nas.local:9001").addresses()[0][1]
|
||||||
|
== "http://nas.local:9001")
|
||||||
|
|
||||||
print("== versions ==")
|
print("== versions ==")
|
||||||
check("same version talks", rp.compatible((1, 0), (1, 0)) is None)
|
check("same version talks", rp.compatible((1, 0), (1, 0)) is None)
|
||||||
check("a newer server minor talks", rp.compatible((1, 0), (1, 3)) is None)
|
check("a newer server minor talks", rp.compatible((1, 0), (1, 3)) is None)
|
||||||
|
|||||||
@@ -241,12 +241,12 @@ function RemoteFormView({
|
|||||||
{field(
|
{field(
|
||||||
'Address',
|
'Address',
|
||||||
<input className={`${input} font-mono`} value={host} onChange={(e) => setHost(e.target.value)} placeholder="192.168.1.20 or nas.local:8765" />,
|
<input className={`${input} font-mono`} value={host} onChange={(e) => setHost(e.target.value)} placeholder="192.168.1.20 or nas.local:8765" />,
|
||||||
'The server’s address on your network. Add :port if it is not 8765.',
|
'The server’s address on your network. Add :port if it is not 8765, or enter a full https://… address if it sits behind a reverse proxy.',
|
||||||
)}
|
)}
|
||||||
{field(
|
{field(
|
||||||
'Fallback address',
|
'Fallback address',
|
||||||
<input className={`${input} font-mono`} value={fallback} onChange={(e) => setFallback(e.target.value)} placeholder="Optional — e.g. its Tailscale address" />,
|
<input className={`${input} font-mono`} value={fallback} onChange={(e) => setFallback(e.target.value)} placeholder="Optional — e.g. https://konduktor.example.net" />,
|
||||||
'Tried when the first one does not answer — away from home, for instance.',
|
'Tried when the first one does not answer — away from home, for instance. Same rules: host[:port] for the server itself (8765 if no port), or a full https://… address used exactly as typed.',
|
||||||
)}
|
)}
|
||||||
{field('Username', <input className={input} value={username} onChange={(e) => setUsername(e.target.value)} autoComplete="username" />)}
|
{field('Username', <input className={input} value={username} onChange={(e) => setUsername(e.target.value)} autoComplete="username" />)}
|
||||||
{field(
|
{field(
|
||||||
|
|||||||
Reference in new issue
Block a user