mirror of
https://github.com/warmbly/warmbly.git
synced 2026-11-21 00:06:38 +00:00
feat: let a workspace confirm its main website with its _warmbly TXT record so sending-domain and form redirects can point there (website_domains, migration 000333, POST /emails/domains/:domain/redirect/website, rechecked every 6 hours), skip the visitor check while a destination is unconfirmed, and redesign the sending domain Redirect tab as a step checklist with the website record inline
This commit is contained in:
@@ -1975,6 +1975,8 @@ func main() {
|
||||
// Sending domains: tracking host per domain and the bare-domain redirect.
|
||||
sendingDomainService = sendingdomain.NewService(repository.NewDomainRedirectRepository(primaryDB), emailRepostory, nil, domainProver)
|
||||
sendingDomainService.WireAuditor(auditService)
|
||||
// A website the workspace proves with its TXT record becomes one of its own domains too.
|
||||
ownDomains.WireWebsites(repository.NewWebsiteDomainRepository(primaryDB), domainProver, nil)
|
||||
sendingDomainService.WireOwnDomains(ownDomains)
|
||||
sendingDomainService.WireCustomHosts(customHosts)
|
||||
// A linked self-hosted instance can have Warmbly Cloud serve a redirect instead.
|
||||
|
||||
@@ -652,8 +652,9 @@ Alongside them, `api_url` is this API's own public base (for a copyable example
|
||||
- `POST /emails/domains/bulk`: `domains` (1 to 100), `tracking_label` (one DNS label, such as `link`; each domain gets `<label>.<domain>`) and/or `redirect_url`, plus optional `tracking_hosts` and `redirect_urls` objects keyed by domain that give a listed domain its own host or website in place of the shared one. Each domain takes its vendor's path when the vendor's API can (writing the `CNAME`, forwarding the root) and is saved to wait for DNS otherwise. Optional `served_by` (`instance` or `cloud`) picks where a redirect no vendor forwards is served from; omitted keeps each domain's current choice. Answers `data`, one row per domain with `tracking` (`host`, `via` of `vendor` or `dns`, `verified`, `mailboxes`, `cname_target`, `note` when the vendor refused the record) and `redirect` (`target_url`, `via` of `vendor`, `dns` or `cloud`, `verified`, `reviewed`); a refused domain carries `error` and `code` on its row and never stops the others. Safe to retry: each setting is set, not added
|
||||
- `GET /emails/domains/:domain/tracking-suggestion`: the tracking `host` to offer, its `status` (`active`, `found` or `suggested`), the `cname_target`, and `vendor_domain` when a connected vendor account holds the domain
|
||||
- `PUT /emails/domains/:domain/tracking`: `host` for every mailbox on the domain (empty clears it); answers the verification result and the number of `mailboxes` changed. Idempotent
|
||||
- `PUT /emails/domains/:domain/redirect`: `target_url`, optional `include_www` (default `true`) and optional `served_by` (`instance`, or `cloud` on a self-hosted instance [linked to Warmbly Cloud](/guides/sending-domains/#serve-it-from-warmbly-cloud); omitted keeps the current choice, and a new redirect is served by this instance). `target_url` must be on one of the workspace's own domains (`redirect_target_not_own_domain` otherwise; see [redirect destination refusals](/api/error-codes/#redirect-destination-refusals)). Checks it once and answers the redirect with its `records`, `served_by`, `serve_host` (the tracking host that answers, which a proxy routes the domain to) and, once DNS verifies, `reach`: the last visit to the domain, with `status` (`ok`, `not_reaching`, `https_error` or `unreachable`), `hint` (`not_routed`, `host_header`, `wrong_target`, `certificate`, `no_listener`, or `settling` while the tracking service picks up a redirect that has just verified), a `detail` sentence, the `proxy` that answered when it named itself, and `checked_at`. A redirect served by this instance or Cloud for it also carries `target_active`, `false` with a `target_inactive_reason` when the saved `target_url` is no longer on the workspace's own domains and the domain answers as if it had no redirect. Idempotent: a repeat keeps the same ownership value, so the `TXT` record stays valid
|
||||
- `POST /emails/domains/:domain/redirect/verify`: check DNS and visit the domain now; for a redirect Warmbly Cloud serves, Cloud checks and the answer is its verdict. Safe to repeat
|
||||
- `PUT /emails/domains/:domain/redirect`: `target_url`, optional `include_www` (default `true`) and optional `served_by` (`instance`, or `cloud` on a self-hosted instance [linked to Warmbly Cloud](/guides/sending-domains/#serve-it-from-warmbly-cloud); omitted keeps the current choice, and a new redirect is served by this instance). `target_url` must be on one of the workspace's own domains, a confirmed website included (`redirect_target_not_own_domain` otherwise; see [redirect destination refusals](/api/error-codes/#redirect-destination-refusals)). Checks it once and answers the redirect with its `records`, `served_by`, `serve_host` (the tracking host that answers, which a proxy routes the domain to) and, once DNS verifies, `reach`: the last visit to the domain, with `status` (`ok`, `not_reaching`, `https_error` or `unreachable`), `hint` (`not_routed`, `host_header`, `wrong_target`, `certificate`, `no_listener`, or `settling` while the tracking service picks up a redirect that has just verified), a `detail` sentence, the `proxy` that answered when it named itself, and `checked_at`. A redirect served by this instance or Cloud for it also carries `target_active`, `false` with a `target_inactive_reason` when the saved `target_url` is no longer on the workspace's own domains and the domain answers as if it had no redirect. When the destination is the workspace's only through a [confirmed website](/guides/sending-domains/#confirm-your-website), the redirect carries `website` with `domain`, `verified` and `record` (the `TXT` record to publish at the website's DNS); while it is not verified, `reach` is absent because the domain is not served. Idempotent: a repeat keeps the same ownership value, so the `TXT` record stays valid
|
||||
- `POST /emails/domains/:domain/redirect/verify`: check DNS and visit the domain now; for a redirect Warmbly Cloud serves, Cloud checks and the answer is its verdict. A destination's website is looked at too. Safe to repeat
|
||||
- `POST /emails/domains/:domain/redirect/website`: `target_url`. Looks for the workspace's `TXT` record on the destination's website now and answers `domain`, `verified` and, when the website is not already one of the workspace's mailbox, tracking or forms domains, `record` (`type`, `name`, `value`, `ok`). A found record confirms the website for the workspace. Safe to repeat
|
||||
- `DELETE /emails/domains/:domain/redirect`: stop serving it, on Warmbly Cloud too when Cloud serves it. A repeat is a `404`
|
||||
- `PUT /emails/domains/:domain/vendor-forwarding`: `url`; the vendor account holding the domain forwards its root there. An empty `url` removes the forwarding where `can_unforward`. Answers the updated `vendor_domain`. Idempotent
|
||||
- `POST /emails/domains/:domain/vendor-tracking`: `host`, a subdomain of the domain; the vendor writes its `CNAME` to this instance's tracking host, then every mailbox on the domain uses the host. Answers like `PUT .../tracking`. Safe to retry: the record is replaced, not added
|
||||
|
||||
@@ -357,13 +357,14 @@ A redirect may only send visitors to a page on one of the workspace's own domain
|
||||
- a domain the workspace has a mailbox on, other than a shared email provider such as `gmail.com`
|
||||
- a verified tracking host of one of its mailboxes
|
||||
- the workspace's custom forms domain, once it is verified
|
||||
- a website the workspace confirmed by publishing its `_warmbly` `TXT` record on the website's registrable domain. Saving looks for the record before refusing, and `POST /emails/domains/:domain/redirect/website` returns the record to publish. See [confirm your website](/guides/sending-domains/#confirm-your-website)
|
||||
|
||||
Hosts are compared in lowercase, without a trailing dot and in their ASCII form, so `bücher.de` and `xn--bcher-kva.de` are the same domain. A subdomain matches its parent (`shop.acme.com` is on `acme.com`), but a name that only starts or ends the same way does not (`acme.com.example.net` and `notacme.com` are not on `acme.com`). An empty value still means no redirect.
|
||||
|
||||
```json
|
||||
{
|
||||
"error": "Bad Request",
|
||||
"message": "The redirect has to go to a page on one of this workspace's own domains: a domain it has a mailbox on (not a shared provider such as gmail.com), its verified tracking domain, its verified forms domain, or a subdomain of one of them. Use an address on one of those, or connect a mailbox or verify a domain first.",
|
||||
"message": "The redirect has to go to a page on one of this workspace's own domains: a domain it has a mailbox on (not a shared provider such as gmail.com), its verified tracking domain, its verified forms domain, a website it verified with its TXT record, or a subdomain of one of them. Verify the website under Sending domains > Redirect, or use an address on one of those.",
|
||||
"code": "redirect_target_not_own_domain",
|
||||
"request_id": "4bbbd1b2-8f86-47dd-8a7f-9476501ad20e"
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ These are made only when a workspace uses the feature behind them, so an instanc
|
||||
| Inbox vendor APIs (`api.inboxkit.com`, `api.zapmail.ai`, `api.mailforge.ai`, `api.infraforge.ai`, `api.maildoso.com`, `api.cheapinboxes.com`, `server.scaledmail.com`) | A workspace connects a vendor account, lists its mailboxes, imports them (each row's credentials are read as it connects), or has a vendor mailbox stopped on a connection error (checked every 15 minutes, at most once every 6 hours per mailbox). Also when the workspace opens its sending domains (the domain list of each active vendor account, at most once every five minutes per account), forwards a domain through its vendor, or has a tracking `CNAME` written there. Only that workspace's key is sent, to that vendor |
|
||||
| Google (`accounts.google.com`, `oauth2.googleapis.com`, `admin.googleapis.com`, `gmail.googleapis.com`) | A workspace creates, checks or uses a Google Workspace grant: the administrator's sign-in when that is how the domain is proved, token minting for the grant's addresses, the admin's directory entry and the domain's directory when picking mailboxes, and a Gmail profile read when a grant or mailbox is verified. Grants are re-checked hourly |
|
||||
| Microsoft (`login.microsoftonline.com`, `graph.microsoft.com`) | A workspace creates, checks or uses a Microsoft 365 grant: the administrator's consent sign-in, application token minting for the tenant, the organization's users, and a mailbox read when one connects. Grants are re-checked hourly |
|
||||
| DNS lookups | A workspace sets up a root redirect or a domain-wide tracking host, or proves a Google Workspace domain by DNS: `TXT`, address and `CNAME` lookups for that domain, through the host's resolver. Pending redirects are re-checked every 10 minutes, verified ones every 6 hours. The sending-domain authentication check (about once a day per domain, and on demand) reads SPF, DKIM and DMARC the same way, and when the host's resolver does not return a record it asks that domain's own nameservers directly on port 53 (never one on a private or loopback address) |
|
||||
| DNS lookups | A workspace sets up a root redirect or a domain-wide tracking host, or proves a Google Workspace domain by DNS: `TXT`, address and `CNAME` lookups for that domain, through the host's resolver. Pending redirects are re-checked every 10 minutes, verified ones every 6 hours. A redirect or form redirect to a website the workspace does not send from also reads the website's `_warmbly` `TXT` record, on save and on each check; a [confirmed website](/guides/sending-domains/#confirm-your-website) is kept in `website_domains` while the record stays published, read again every 6 hours, and deleted once the record is definitively gone or with the workspace. The sending-domain authentication check (about once a day per domain, and on demand) reads SPF, DKIM and DMARC the same way, and when the host's resolver does not return a record it asks that domain's own nameservers directly on port 53 (never one on a private or loopback address) |
|
||||
| The redirect's own domain | Once a root redirect's DNS verifies, the backend opens `http://<domain>/` and `https://<domain>/` like a visitor, without following it off the domain, to see whether the redirect answers. Only public addresses on ports 80 and 443 are opened. Repeated with the DNS check: every 10 minutes while visitors do not get the redirect (for two weeks after it verified), every 6 hours otherwise |
|
||||
| Warmbly Cloud (`api.warmbly.com`, or `WARMBLY_CLOUD_URL`) | A linked instance has a root redirect [served from Warmbly Cloud](/guides/sending-domains/#serve-it-from-warmbly-cloud): the domain, the website and the `www` setting, with the instance's link token, when it is saved, moved, checked or removed, and whenever the instance re-reads Cloud's verdict (on the same schedule as its own redirects) |
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ The **Design** tab styles the form while the canvas updates live. The defaults a
|
||||
|
||||
The **Settings** tab controls what a submission does:
|
||||
|
||||
- **Success message** is shown after submitting, or set a **redirect URL** to send the visitor to your own thank-you page instead. The page has to be on one of your workspace's own domains: a domain you have a mailbox on (not a shared provider such as `gmail.com`), a verified tracking domain, your verified [custom forms domain](#custom-domain), or a subdomain of one of them. Any other address is refused with `redirect_target_not_own_domain`. If a saved page stops qualifying, for example after the last mailbox on its domain is removed, the setting is kept and marked **Not in use**, and visitors see the success message until you change it.
|
||||
- **Success message** is shown after submitting, or set a **redirect URL** to send the visitor to your own thank-you page instead. The page has to be on one of your workspace's own domains: a domain you have a mailbox on (not a shared provider such as `gmail.com`), a verified tracking domain, your verified [custom forms domain](#custom-domain), a website you [confirmed](/guides/sending-domains/#confirm-your-website), or a subdomain of one of them. Any other address is refused with `redirect_target_not_own_domain`; if the page is on your main website, saving checks for its confirmation record first, so publishing that record is enough. If a saved page stops qualifying, for example after the last mailbox on its domain is removed, the setting is kept and marked **Not in use**, and visitors see the success message until you change it.
|
||||
- **Add to labels** puts the labels you pick on every submitted contact, for example "Website leads".
|
||||
- **Add to campaign** enrolls new contacts as leads in the campaign you pick. Sending still follows the campaign's own schedule, limits and windows; a form never causes immediate mail. Picking a campaign turns on its **Keep running for new leads** setting, so it waits between submissions instead of finishing; a campaign that had already finished restarts when a lead arrives, through the usual launch checks, and a refused restart is noted in its activity log while the lead waits.
|
||||
- **Spam protection** and **allowed embed domains** are covered below.
|
||||
|
||||
@@ -126,7 +126,7 @@ Warmbly serves the redirect from this instance's tracking service once DNS prove
|
||||
|
||||
### Set one up
|
||||
|
||||
Enter the website to send visitors to, such as `https://yourcompany.com`. It must be an `http` or `https` address on one of your workspace's own domains: a domain you have a mailbox on, a verified tracking host, your verified [forms domain](/guides/forms/), or a subdomain of one of them. Any other address is refused with `redirect_target_not_own_domain`, and so is a redirect back to the same domain or its `www`. A destination saved earlier that no longer qualifies, for example after the last mailbox on its domain is removed, is kept but shows **Not in use**, and the domain answers as if it had no redirect until you change it. **Include www** is on by default. Warmbly then lists the records to add at your DNS provider:
|
||||
Enter the website to send visitors to, such as `https://yourcompany.com`. It must be an `http` or `https` address on one of your workspace's own domains: a domain you have a mailbox on, a verified tracking host, your verified [forms domain](/guides/forms/), a website you [confirmed](#confirm-your-website), or a subdomain of one of them. A redirect back to the same domain or its `www` is refused. A destination saved earlier that no longer qualifies, for example after the last mailbox on its domain is removed, is kept but shows **Not in use**, and the domain answers as if it had no redirect until you change it or confirm the website. **Include www** is on by default. Warmbly then lists the records to add at your DNS provider:
|
||||
|
||||
| Purpose | Type | Name | Value | Needed to verify |
|
||||
| --- | --- | --- | --- | --- |
|
||||
@@ -140,6 +140,18 @@ When the tracking host has no public address to list, the root record is shown a
|
||||
|
||||
The root of a domain has to point here for the redirect to work, so a domain whose root already serves a website is not a candidate. Mail is unaffected: `MX`, SPF, DKIM and DMARC records live beside these and nothing here changes them.
|
||||
|
||||
### Confirm your website
|
||||
|
||||
Most teams keep their main website's domain out of cold outreach, so it is usually not a domain the workspace sends from. Confirm it once with a `TXT` record at that website's DNS provider:
|
||||
|
||||
| Type | Name | Value |
|
||||
| --- | --- | --- |
|
||||
| `TXT` | `_warmbly.<website domain>` | `warmbly-verify=<value>` |
|
||||
|
||||
The record goes on the website's registrable domain (`yourcompany.com` for `https://www.yourcompany.com`), and confirming it covers every page and subdomain under it. Saving a redirect to a website that is not confirmed yet shows the record to add instead of saving; once it is in place, **Check and save** saves it. The value is unique to your workspace on this instance, like the ownership value, so another workspace's record confirms nothing for yours. Adding it changes nothing about how your website is served. One confirmation covers every sending domain that redirects there, and [form redirects](/guides/forms/#settings) too.
|
||||
|
||||
Warmbly looks for the record again every 6 hours. When it is definitively gone, the website is no longer confirmed and redirects to it stop, showing the record to add again; a DNS lookup that fails or times out changes nothing. While a website is not confirmed, the redirect's progress shows that step with the record, and Warmbly does not open the domain to check what visitors get, since it is holding the redirect back itself.
|
||||
|
||||
### Verification
|
||||
|
||||
A redirect verifies when the `TXT` record and the root record are both in place. The `www` record is optional; without it, only the bare domain redirects.
|
||||
@@ -201,7 +213,7 @@ On a self-hosted instance [linked to Warmbly Cloud](/guides/warmbly-cloud/), a r
|
||||
### Limits
|
||||
|
||||
- The workspace must have a mailbox on the domain.
|
||||
- The website must be on one of the workspace's own domains, as described in [set one up](#set-one-up).
|
||||
- The website must be on one of the workspace's own domains or a [confirmed website](#confirm-your-website), as described in [set one up](#set-one-up).
|
||||
- Domains of shared email providers, such as `gmail.com` or `outlook.com`, are refused.
|
||||
- One workspace per domain on an instance. While one workspace's redirect for a domain is verified, another workspace's redirect for it is refused with `domain_redirect_taken` and does not verify.
|
||||
- The instance needs a tracking host (`TRACKING_DOMAIN`), because the tracking service is what answers. Without one, redirects are not offered, except from Warmbly Cloud on a linked instance.
|
||||
@@ -242,7 +254,7 @@ The vendor's domain list is read with the workspace's own API key, only for conn
|
||||
|
||||
## What travels in an export
|
||||
|
||||
Redirects travel in a [workspace export](/guides/workspace-export-import/). They arrive unverified and are served once the destination's own check sees both records. One Warmbly Cloud served for the source arrives served by the destination itself. The ownership value belongs to the workspace on the instance that issued it, so the destination lists its own value: publish that value in the `TXT` record, and point the root at the destination. A tracking host is part of each mailbox's settings and travels with the mailbox; it arrives unverified, and the destination's hourly check verifies it once the `CNAME` points at the destination and the destination's ownership value is published. Forwarding set through a vendor lives at the vendor and is unaffected by a move.
|
||||
Redirects travel in a [workspace export](/guides/workspace-export-import/). They arrive unverified and are served once the destination's own check sees both records. One Warmbly Cloud served for the source arrives served by the destination itself. The ownership value belongs to the workspace on the instance that issued it, so the destination lists its own value: publish that value in the `TXT` record, and point the root at the destination. A tracking host is part of each mailbox's settings and travels with the mailbox; it arrives unverified, and the destination's hourly check verifies it once the `CNAME` points at the destination and the destination's ownership value is published. Forwarding set through a vendor lives at the vendor and is unaffected by a move. [Confirmed websites](#confirm-your-website) do not travel: their record is bound to the source workspace, so the destination shows its own record to add for each website its redirects point at.
|
||||
|
||||
</Fold>
|
||||
|
||||
|
||||
@@ -264,6 +264,8 @@ A [community directory](/guides/integrations/#community-apps) listing does not t
|
||||
|
||||
[Slack](/guides/slack/) account links, the record of which Slack thread belongs to which assistant conversation, and which Slack thread mirrors which inbox conversation in the [inbox channel](/guides/slack/#inbox-in-slack) do not travel. They name the Slack install on the source instance, so members link again after Slack is reconnected on the destination, and inbox conversations start new Slack threads there. The assistant conversations themselves move with the Assistant group.
|
||||
|
||||
[Confirmed websites](/guides/sending-domains/#confirm-your-website) do not travel. The `TXT` record that confirms one is bound to the source workspace, so it proves nothing on the destination. Redirects and form redirects to the website arrive kept but not used, and the destination shows its own record to publish next to each one.
|
||||
|
||||
Reply and forward drafts kept in your browser are also excluded. Finish or copy them before moving to another instance. See [reply drafts](/guides/unibox/#reply-drafts).
|
||||
|
||||
</Fold>
|
||||
|
||||
@@ -148,6 +148,30 @@ func (h *Handler) VerifyDomainRedirect(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, r)
|
||||
}
|
||||
|
||||
type websiteProofRequest struct {
|
||||
TargetURL string `json:"target_url"`
|
||||
}
|
||||
|
||||
// VerifyRedirectWebsite is POST /emails/domains/:domain/redirect/website: the
|
||||
// TXT record that makes the destination's website the workspace's, checked now. Safe to repeat.
|
||||
func (h *Handler) VerifyRedirectWebsite(c *gin.Context) {
|
||||
orgID, _, ok := importCaller(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var req websiteProofRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
errx.Handle(c, errx.ErrInvalid)
|
||||
return
|
||||
}
|
||||
w, xerr := h.SendingDomainService.WebsiteProof(c.Request.Context(), orgID, c.Param("domain"), req.TargetURL)
|
||||
if xerr != nil {
|
||||
errx.Handle(c, xerr)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, w)
|
||||
}
|
||||
|
||||
// DeleteDomainRedirect is DELETE /emails/domains/:domain/redirect.
|
||||
func (h *Handler) DeleteDomainRedirect(c *gin.Context) {
|
||||
orgID, _, ok := importCaller(c)
|
||||
|
||||
@@ -680,6 +680,7 @@ func Run(
|
||||
sendingDomains.PUT("/:domain/tracking", h.SetDomainTracking)
|
||||
sendingDomains.PUT("/:domain/redirect", h.SetDomainRedirect)
|
||||
sendingDomains.POST("/:domain/redirect/verify", h.VerifyDomainRedirect)
|
||||
sendingDomains.POST("/:domain/redirect/website", h.VerifyRedirectWebsite)
|
||||
sendingDomains.DELETE("/:domain/redirect", h.DeleteDomainRedirect)
|
||||
sendingDomains.PUT("/:domain/vendor-forwarding", h.SetDomainVendorForwarding)
|
||||
sendingDomains.POST("/:domain/vendor-tracking", h.SetDomainVendorTracking)
|
||||
|
||||
@@ -322,11 +322,14 @@ func (s *service) Update(ctx context.Context, orgID, id uuid.UUID, in *models.Fo
|
||||
return nil, xerr
|
||||
}
|
||||
if u != "" && u != f.RedirectURL {
|
||||
own, xerr := s.ownDomains(ctx, orgID)
|
||||
if s.own == nil {
|
||||
return nil, owndomain.Refusal()
|
||||
}
|
||||
ok, xerr := s.own.Admit(ctx, orgID, u)
|
||||
if xerr != nil {
|
||||
return nil, xerr
|
||||
}
|
||||
if !owndomain.Within(owndomain.TargetHost(u), own) {
|
||||
if !ok {
|
||||
return nil, owndomain.Refusal()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1063,6 +1063,7 @@ var Tables = []Table{
|
||||
// with the reason. Kept as data so the docs page and the coverage test both
|
||||
// read from one list instead of restating it.
|
||||
var ExcludedTables = map[string]string{
|
||||
"website_domains": "A website's proof is a TXT value bound to the source workspace, so it proves nothing for the destination. The destination shows its own TXT value on each redirect and form that points at the website, and serves them once it is published.",
|
||||
"warmup_conversation_mailboxes": "Instance-local content reuse reservations against the shared warmup conversation library. Destination mailboxes build their own content history; full instance backups retain these reservations.",
|
||||
"email_account_transport_recovery": "Source-instance sync and provider-confirmed-send recovery clocks cannot authorize destination recovery. Full instance database backups retain them.",
|
||||
"sync_arrival_outbox": "Encrypted, org-key-owned arrival delivery queue bound to this instance's provider handles and body storage. Pending maps are excluded too so destination sync retries them; no queue secrets or blob references travel. Full instance backups retain queue, org keys and bodies together.",
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
// Package owndomain decides which hosts belong to a workspace, so a redirect
|
||||
// the workspace configures (a form's after-submit page, a sending domain's
|
||||
// root) only ever sends a visitor to the workspace's own site.
|
||||
// root) only ever sends a visitor to a domain the workspace has proved it controls.
|
||||
package owndomain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog/log"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
|
||||
"github.com/warmbly/warmbly/internal/errx"
|
||||
"github.com/warmbly/warmbly/internal/pkg/domainproof"
|
||||
"github.com/warmbly/warmbly/internal/pkg/mailhost"
|
||||
"github.com/warmbly/warmbly/internal/repository"
|
||||
)
|
||||
|
||||
// ErrIDNotOwn refuses a redirect destination outside the workspace's own domains.
|
||||
@@ -24,7 +30,7 @@ func Refusal() *errx.Error {
|
||||
}
|
||||
|
||||
// RefusalMessage names the kinds of domain a redirect may point at.
|
||||
const RefusalMessage = "The redirect has to go to a page on one of this workspace's own domains: a domain it has a mailbox on (not a shared provider such as gmail.com), its verified tracking domain, its verified forms domain, or a subdomain of one of them. Use an address on one of those, or connect a mailbox or verify a domain first."
|
||||
const RefusalMessage = "The redirect has to go to a page on one of this workspace's own domains: a domain it has a mailbox on (not a shared provider such as gmail.com), its verified tracking domain, its verified forms domain, a website it verified with its TXT record, or a subdomain of one of them. Verify the website under Sending domains > Redirect, or use an address on one of those."
|
||||
|
||||
// Mailboxes lists the domains the workspace has a mailbox on and its verified tracking hosts.
|
||||
type Mailboxes interface {
|
||||
@@ -40,6 +46,17 @@ type FormsDomains interface {
|
||||
type Resolver struct {
|
||||
mailboxes Mailboxes
|
||||
forms FormsDomains
|
||||
websites repository.WebsiteDomainRepository
|
||||
proof *domainproof.Prover
|
||||
txt domainproof.TXTResolver
|
||||
}
|
||||
|
||||
// WireWebsites lets a workspace add a website by publishing its TXT proof; a nil resolver uses the system's DNS.
|
||||
func (r *Resolver) WireWebsites(websites repository.WebsiteDomainRepository, proof *domainproof.Prover, txt domainproof.TXTResolver) {
|
||||
if txt == nil {
|
||||
txt = net.DefaultResolver
|
||||
}
|
||||
r.websites, r.proof, r.txt = websites, proof, txt
|
||||
}
|
||||
|
||||
// New builds the resolver; forms may be nil.
|
||||
@@ -47,10 +64,49 @@ func New(mailboxes Mailboxes, forms FormsDomains) *Resolver {
|
||||
return &Resolver{mailboxes: mailboxes, forms: forms}
|
||||
}
|
||||
|
||||
// Set is a workspace's own domains, split by how each was proved.
|
||||
type Set struct {
|
||||
// Base are its mailbox domains, verified tracking hosts and verified forms domain.
|
||||
Base []string
|
||||
// Websites are the domains it proved with its TXT record.
|
||||
Websites []string
|
||||
}
|
||||
|
||||
// Allows reports whether host is one of the set's domains or under one.
|
||||
func (s Set) Allows(host string) bool { return Within(host, s.Base) || Within(host, s.Websites) }
|
||||
|
||||
// All is every domain in the set.
|
||||
func (s Set) All() []string { return append(append([]string{}, s.Base...), s.Websites...) }
|
||||
|
||||
// Domains are the workspace's own domains: every domain it has a mailbox on
|
||||
// except shared providers, its verified tracking hosts, and its custom forms
|
||||
// domain once verified. Each is normalized; a host under one is also the workspace's.
|
||||
// except shared providers, its verified tracking hosts, its custom forms
|
||||
// domain once verified, and the websites it proved. Each is normalized; a host under one is also the workspace's.
|
||||
func (r *Resolver) Domains(ctx context.Context, orgID uuid.UUID) ([]string, *errx.Error) {
|
||||
set, xerr := r.Set(ctx, orgID)
|
||||
if xerr != nil {
|
||||
return nil, xerr
|
||||
}
|
||||
return set.All(), nil
|
||||
}
|
||||
|
||||
// Set is Domains split into the base domains and the proved websites.
|
||||
func (r *Resolver) Set(ctx context.Context, orgID uuid.UUID) (Set, *errx.Error) {
|
||||
base, xerr := r.base(ctx, orgID)
|
||||
if xerr != nil {
|
||||
return Set{}, xerr
|
||||
}
|
||||
set := Set{Base: base}
|
||||
if r.websites != nil {
|
||||
list, err := r.websites.Verified(ctx, orgID)
|
||||
if err != nil {
|
||||
return Set{}, errx.InternalError()
|
||||
}
|
||||
set.Websites = clean(list)
|
||||
}
|
||||
return set, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) base(ctx context.Context, orgID uuid.UUID) ([]string, *errx.Error) {
|
||||
var raw []string
|
||||
if r.mailboxes != nil {
|
||||
list, xerr := r.mailboxes.OwnedDomains(ctx, orgID)
|
||||
@@ -68,6 +124,11 @@ func (r *Resolver) Domains(ctx context.Context, orgID uuid.UUID) ([]string, *err
|
||||
raw = append(raw, domain)
|
||||
}
|
||||
}
|
||||
return clean(raw), nil
|
||||
}
|
||||
|
||||
// clean normalizes and dedupes, dropping shared providers.
|
||||
func clean(raw []string) []string {
|
||||
out := make([]string, 0, len(raw))
|
||||
seen := make(map[string]bool, len(raw))
|
||||
for _, d := range raw {
|
||||
@@ -78,7 +139,7 @@ func (r *Resolver) Domains(ctx context.Context, orgID uuid.UUID) ([]string, *err
|
||||
seen[d] = true
|
||||
out = append(out, d)
|
||||
}
|
||||
return out, nil
|
||||
return out
|
||||
}
|
||||
|
||||
// Allows reports whether the destination URL's host is one of the workspace's own domains or under one.
|
||||
@@ -87,11 +148,114 @@ func (r *Resolver) Allows(ctx context.Context, orgID uuid.UUID, target string) (
|
||||
if host == "" {
|
||||
return false, nil
|
||||
}
|
||||
domains, xerr := r.Domains(ctx, orgID)
|
||||
set, xerr := r.Set(ctx, orgID)
|
||||
if xerr != nil {
|
||||
return false, xerr
|
||||
}
|
||||
return Within(host, domains), nil
|
||||
return set.Allows(host), nil
|
||||
}
|
||||
|
||||
// Admit is Allows, and when the destination is not yet the workspace's, looks
|
||||
// for its TXT proof on the website now and records the website when it is there.
|
||||
func (r *Resolver) Admit(ctx context.Context, orgID uuid.UUID, target string) (bool, *errx.Error) {
|
||||
ok, xerr := r.Allows(ctx, orgID, target)
|
||||
if xerr != nil || ok {
|
||||
return ok, xerr
|
||||
}
|
||||
proof, xerr := r.Prove(ctx, orgID, target)
|
||||
if xerr != nil {
|
||||
return false, xerr
|
||||
}
|
||||
return proof != nil && proof.Verified, nil
|
||||
}
|
||||
|
||||
// Proof is the TXT record that makes a website the workspace's, and whether it is in place.
|
||||
type Proof struct {
|
||||
Domain string
|
||||
Verified bool
|
||||
Name string
|
||||
Value string
|
||||
}
|
||||
|
||||
// Record is the proof to publish for the destination's website, nil when it has none or websites are not wired.
|
||||
func (r *Resolver) Record(orgID uuid.UUID, target string) *Proof {
|
||||
site := Website(TargetHost(target))
|
||||
if r.proof == nil || site == "" {
|
||||
return nil
|
||||
}
|
||||
name, value := r.proof.Record(orgID, site)
|
||||
return &Proof{Domain: site, Name: name, Value: value}
|
||||
}
|
||||
|
||||
// Prove looks for the destination website's TXT proof now and records the website when it is there.
|
||||
func (r *Resolver) Prove(ctx context.Context, orgID uuid.UUID, target string) (*Proof, *errx.Error) {
|
||||
p := r.Record(orgID, target)
|
||||
if p == nil || r.websites == nil || mailhost.SharedProvider(p.Domain) {
|
||||
return p, nil
|
||||
}
|
||||
present, err := r.published(ctx, orgID, p.Domain)
|
||||
if err != nil || !present {
|
||||
return p, nil
|
||||
}
|
||||
if err := r.websites.Mark(ctx, orgID, p.Domain); err != nil {
|
||||
return nil, errx.InternalError()
|
||||
}
|
||||
p.Verified = true
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// published reads the proof at the website itself, never a parent; an error means the lookup could not tell.
|
||||
func (r *Resolver) published(ctx context.Context, orgID uuid.UUID, site string) (bool, error) {
|
||||
cctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
txts, err := r.txt.LookupTXT(cctx, domainproof.Name(site))
|
||||
if r.proof.Matches(txts, orgID, site) {
|
||||
return true, nil
|
||||
}
|
||||
var dnsErr *net.DNSError
|
||||
if err != nil && !(errors.As(err, &dnsErr) && dnsErr.IsNotFound) {
|
||||
return false, err
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// websiteRecheck is how often a proved website's TXT record is looked at again.
|
||||
const websiteRecheck = 6 * time.Hour
|
||||
|
||||
// Recheck looks again at proofs older than websiteRecheck; one whose record is definitively gone is dropped.
|
||||
func (r *Resolver) Recheck(ctx context.Context) {
|
||||
if r.websites == nil || r.proof == nil {
|
||||
return
|
||||
}
|
||||
due, err := r.websites.Due(ctx, time.Now().Add(-websiteRecheck), 50)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, w := range due {
|
||||
present, err := r.published(ctx, w.OrganizationID, w.Domain)
|
||||
switch {
|
||||
case err != nil:
|
||||
// A lookup that could not tell keeps the proof; it is asked again next pass.
|
||||
log.Info().Str("domain", w.Domain).Msg("website proof: lookup failed, kept")
|
||||
case present:
|
||||
_ = r.websites.Mark(ctx, w.OrganizationID, w.Domain)
|
||||
default:
|
||||
_ = r.websites.Drop(ctx, w.OrganizationID, w.Domain)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Website is the registrable domain a host belongs to, which is where its proof lives.
|
||||
func Website(host string) string {
|
||||
host = Normalize(host)
|
||||
if host == "" {
|
||||
return ""
|
||||
}
|
||||
site, err := publicsuffix.EffectiveTLDPlusOne(host)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return site
|
||||
}
|
||||
|
||||
// TargetHost is the normalized host of an absolute http(s) URL, or "" when it has none.
|
||||
|
||||
@@ -109,9 +109,9 @@ func (s *Service) ownDomains() *owndomain.Resolver {
|
||||
return owndomain.New(s.mailboxes, nil)
|
||||
}
|
||||
|
||||
// ownTarget refuses a redirect destination outside the workspace's own domains.
|
||||
// ownTarget refuses a redirect destination outside the workspace's own domains, looking for a website's TXT proof first.
|
||||
func (s *Service) ownTarget(ctx context.Context, orgID uuid.UUID, target string) *errx.Error {
|
||||
ok, xerr := s.ownDomains().Allows(ctx, orgID, target)
|
||||
ok, xerr := s.ownDomains().Admit(ctx, orgID, target)
|
||||
if xerr != nil {
|
||||
return xerr
|
||||
}
|
||||
@@ -121,20 +121,70 @@ func (s *Service) ownTarget(ctx context.Context, orgID uuid.UUID, target string)
|
||||
return nil
|
||||
}
|
||||
|
||||
// markTarget records on the row whether its destination is on one of the workspace's own domains, and so served.
|
||||
func markTarget(r *models.DomainRedirect, own []string) {
|
||||
// markTarget records on the row whether its destination is on one of the workspace's own domains, and so served,
|
||||
// with the website's TXT record when that is what proves it.
|
||||
func (s *Service) markTarget(r *models.DomainRedirect, own owndomain.Set) {
|
||||
if r == nil || r.LinkedInstanceID != nil || r.TargetURL == "" {
|
||||
return
|
||||
}
|
||||
active := owndomain.Within(owndomain.TargetHost(r.TargetURL), own)
|
||||
host := owndomain.TargetHost(r.TargetURL)
|
||||
active := own.Allows(host)
|
||||
r.TargetActive = &active
|
||||
if !owndomain.Within(host, own.Base) {
|
||||
r.Website = s.website(r.OrganizationID, r.TargetURL, active)
|
||||
}
|
||||
if !active {
|
||||
r.TargetInactiveReason = targetInactiveMessage
|
||||
if r.Website != nil {
|
||||
r.TargetInactiveReason = websiteUnprovedMessage(r.Website.Domain)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// website is the destination's proof as the dashboard shows it, nil when websites cannot be proved here.
|
||||
func (s *Service) website(orgID uuid.UUID, target string, verified bool) *models.RedirectWebsite {
|
||||
p := s.ownDomains().Record(orgID, target)
|
||||
if p == nil {
|
||||
return nil
|
||||
}
|
||||
return &models.RedirectWebsite{Domain: p.Domain, Verified: verified,
|
||||
Record: &models.DNSRecord{Purpose: "website", Type: "TXT", Name: p.Name, Value: p.Value, OK: verified}}
|
||||
}
|
||||
|
||||
const targetInactiveMessage = "Not in use: the destination is no longer on one of this workspace's own domains, so visitors get the domain's default page instead. This happens when the mailbox or verified domain it relied on was removed. Point the redirect at a page on a domain the workspace has a mailbox on, its verified tracking domain, or its verified forms domain, or reconnect that domain."
|
||||
|
||||
func websiteUnprovedMessage(site string) string {
|
||||
return "Not served yet: add the TXT record for " + site + " at its DNS provider to prove the website is this workspace's. Until then visitors get the domain's default page."
|
||||
}
|
||||
|
||||
// WebsiteProof is the TXT record that makes the destination's website the workspace's, checked now.
|
||||
func (s *Service) WebsiteProof(ctx context.Context, orgID uuid.UUID, domain, target string) (*models.RedirectWebsite, *errx.Error) {
|
||||
domain = normalizeDomain(domain)
|
||||
if xerr := s.ownDomain(ctx, orgID, domain); xerr != nil {
|
||||
return nil, xerr
|
||||
}
|
||||
cleaned, xerr := cleanTarget(target, domain)
|
||||
if xerr != nil {
|
||||
return nil, xerr
|
||||
}
|
||||
set, xerr := s.ownDomains().Set(ctx, orgID)
|
||||
if xerr != nil {
|
||||
return nil, xerr
|
||||
}
|
||||
host := owndomain.TargetHost(cleaned)
|
||||
if owndomain.Within(host, set.Base) {
|
||||
return &models.RedirectWebsite{Domain: owndomain.Website(host), Verified: true}, nil
|
||||
}
|
||||
proof, xerr := s.ownDomains().Prove(ctx, orgID, cleaned)
|
||||
if xerr != nil {
|
||||
return nil, xerr
|
||||
}
|
||||
if proof == nil {
|
||||
return nil, owndomain.Refusal()
|
||||
}
|
||||
return s.website(orgID, cleaned, proof.Verified || set.Allows(host)), nil
|
||||
}
|
||||
|
||||
func normalizeDomain(d string) string {
|
||||
return mailhost.NormalizeDomain(strings.TrimPrefix(strings.ToLower(strings.TrimSpace(d)), "www."))
|
||||
}
|
||||
@@ -149,7 +199,7 @@ func (s *Service) Overview(ctx context.Context, orgID uuid.UUID) ([]models.Sendi
|
||||
if err != nil {
|
||||
return nil, errx.InternalError()
|
||||
}
|
||||
own, xerr := s.ownDomains().Domains(ctx, orgID)
|
||||
own, xerr := s.ownDomains().Set(ctx, orgID)
|
||||
if xerr != nil {
|
||||
return nil, xerr
|
||||
}
|
||||
@@ -157,7 +207,7 @@ func (s *Service) Overview(ctx context.Context, orgID uuid.UUID) ([]models.Sendi
|
||||
for i := range redirects {
|
||||
r := redirects[i]
|
||||
s.decorate(&r, nil)
|
||||
markTarget(&r, own)
|
||||
s.markTarget(&r, own)
|
||||
byDomain[r.Domain] = &r
|
||||
}
|
||||
var links map[string]models.VendorDomainLink
|
||||
@@ -439,13 +489,18 @@ func (s *Service) probe(ctx context.Context, r *models.DomainRedirect) probe {
|
||||
// only drops when DNS says so definitively, never on a lookup that failed.
|
||||
// force asks Cloud to check again rather than report its last verdict.
|
||||
func (s *Service) check(ctx context.Context, r *models.DomainRedirect, force bool) (*models.DomainRedirect, *errx.Error) {
|
||||
ownTarget, ownErr := s.ownDomains().Admit(ctx, r.OrganizationID, r.TargetURL)
|
||||
if r.ServedBy == models.RedirectServedByCloud {
|
||||
// Cloud cannot see this workspace's domains, so a destination that is no longer its own stops being served there from here.
|
||||
if ok, xerr := s.ownDomains().Allows(ctx, r.OrganizationID, r.TargetURL); xerr == nil && !ok {
|
||||
if ownErr == nil && !ownTarget {
|
||||
if xerr := s.releaseCloud(ctx, r.OrganizationID, r.Domain); xerr != nil {
|
||||
log.Warn().Str("domain", r.Domain).Str("code", xerr.ResponseCode()).Msg("domain redirect: could not stop Cloud serving a destination off the workspace's domains")
|
||||
}
|
||||
return s.stop(ctx, r, targetInactiveMessage)
|
||||
msg := targetInactiveMessage
|
||||
if w := s.website(r.OrganizationID, r.TargetURL, false); w != nil {
|
||||
msg = websiteUnprovedMessage(w.Domain)
|
||||
}
|
||||
return s.stop(ctx, r, msg)
|
||||
}
|
||||
return s.checkCloud(ctx, r, force)
|
||||
}
|
||||
@@ -469,9 +524,9 @@ func (s *Service) check(ctx context.Context, r *models.DomainRedirect, force boo
|
||||
}
|
||||
return nil, errx.InternalError()
|
||||
}
|
||||
// DNS proves the name points here; opening it proves a visitor gets the redirect.
|
||||
// DNS proves the name points here; opening it proves a visitor gets the redirect, which is withheld until the destination is the workspace's.
|
||||
var reach *models.RedirectReach
|
||||
if verified && s.reach != nil {
|
||||
if verified && s.reach != nil && ownErr == nil && ownTarget {
|
||||
got := s.reach.Probe(ctx, r.Domain, r.TargetURL)
|
||||
// Tracking forgets a miss within a minute, so one that outlasts that is a real answer: this tracking service has no redirect for the name.
|
||||
if got.Hint == models.RedirectHintSettling && r.Verified && r.VerifiedAt != nil && time.Since(*r.VerifiedAt) > settleGrace {
|
||||
@@ -504,8 +559,8 @@ func (s *Service) finish(ctx context.Context, before *models.DomainRedirect, p *
|
||||
}
|
||||
s.decorate(fresh, p)
|
||||
if fresh.LinkedInstanceID == nil {
|
||||
if own, xerr := s.ownDomains().Domains(ctx, fresh.OrganizationID); xerr == nil {
|
||||
markTarget(fresh, own)
|
||||
if own, xerr := s.ownDomains().Set(ctx, fresh.OrganizationID); xerr == nil {
|
||||
s.markTarget(fresh, own)
|
||||
}
|
||||
}
|
||||
return fresh, nil
|
||||
@@ -619,6 +674,7 @@ func (s *Service) StartSweep(ctx context.Context) {
|
||||
}
|
||||
wg.Wait()
|
||||
s.reconcileCloud(ctx)
|
||||
s.ownDomains().Recheck(ctx)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
package sendingdomain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/warmbly/warmbly/internal/app/owndomain"
|
||||
"github.com/warmbly/warmbly/internal/models"
|
||||
"github.com/warmbly/warmbly/internal/repository"
|
||||
)
|
||||
|
||||
type memWebsites struct {
|
||||
rows map[string]repository.WebsiteDomain
|
||||
}
|
||||
|
||||
func websiteKey(org uuid.UUID, domain string) string { return org.String() + "|" + domain }
|
||||
|
||||
func (m *memWebsites) Verified(_ context.Context, org uuid.UUID) ([]string, error) {
|
||||
var out []string
|
||||
for _, w := range m.rows {
|
||||
if w.OrganizationID == org {
|
||||
out = append(out, w.Domain)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (m *memWebsites) Mark(_ context.Context, org uuid.UUID, domain string) error {
|
||||
w, ok := m.rows[websiteKey(org, domain)]
|
||||
if !ok {
|
||||
w = repository.WebsiteDomain{OrganizationID: org, Domain: domain, VerifiedAt: time.Now()}
|
||||
}
|
||||
w.LastCheckedAt = time.Now()
|
||||
m.rows[websiteKey(org, domain)] = w
|
||||
return nil
|
||||
}
|
||||
func (m *memWebsites) Drop(_ context.Context, org uuid.UUID, domain string) error {
|
||||
delete(m.rows, websiteKey(org, domain))
|
||||
return nil
|
||||
}
|
||||
func (m *memWebsites) Due(_ context.Context, before time.Time, _ int) ([]repository.WebsiteDomain, error) {
|
||||
var out []repository.WebsiteDomain
|
||||
for _, w := range m.rows {
|
||||
if w.LastCheckedAt.Before(before) {
|
||||
out = append(out, w)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (m *memWebsites) age(d time.Duration) {
|
||||
for k, w := range m.rows {
|
||||
w.LastCheckedAt = time.Now().Add(-d)
|
||||
m.rows[k] = w
|
||||
}
|
||||
}
|
||||
|
||||
// newWebsiteTest is a workspace sending from acme.io whose main website, frostlogic.se, has no mailbox.
|
||||
func newWebsiteTest() (*Service, *fakeDNS, *memWebsites, *fakeReach) {
|
||||
dns := baseDNS()
|
||||
s, _ := newTest(dns)
|
||||
mb := &fakeMailboxes{counts: map[string]int{"acme.io": 2}}
|
||||
s.mailboxes = mb
|
||||
sites := &memWebsites{rows: map[string]repository.WebsiteDomain{}}
|
||||
own := owndomain.New(mb, nil)
|
||||
own.WireWebsites(sites, s.proof, dns)
|
||||
s.WireOwnDomains(own)
|
||||
reach := &fakeReach{verdict: models.RedirectReach{Status: models.RedirectReachOK}}
|
||||
s.reach = reach
|
||||
return s, dns, sites, reach
|
||||
}
|
||||
|
||||
func TestAWebsiteProvedWithTheWorkspacesRecordTakesRedirects(t *testing.T) {
|
||||
s, dns, _, reach := newWebsiteTest()
|
||||
ctx := context.Background()
|
||||
org := uuid.New()
|
||||
|
||||
if _, xerr := s.SetRedirect(ctx, org, uuid.New(), "acme.io", RedirectInput{TargetURL: "https://www.frostlogic.se"}); xerr == nil || xerr.Identifier != owndomain.ErrIDNotOwn {
|
||||
t.Fatalf("an unproved website was accepted: %v", xerr)
|
||||
}
|
||||
proof, xerr := s.WebsiteProof(ctx, org, "acme.io", "www.frostlogic.se")
|
||||
if xerr != nil {
|
||||
t.Fatal(xerr)
|
||||
}
|
||||
if proof.Domain != "frostlogic.se" || proof.Verified || proof.Record == nil || proof.Record.Name != "_warmbly.frostlogic.se" || proof.Record.Value != s.proof.Value(org, "frostlogic.se") {
|
||||
t.Fatalf("proof = %+v", proof)
|
||||
}
|
||||
|
||||
// Another workspace's record proves the website for that workspace only.
|
||||
dns.txt["_warmbly.frostlogic.se"] = []string{s.proof.Value(uuid.New(), "frostlogic.se")}
|
||||
if _, xerr := s.SetRedirect(ctx, org, uuid.New(), "acme.io", RedirectInput{TargetURL: "https://www.frostlogic.se"}); xerr == nil {
|
||||
t.Fatal("another workspace's record proved the website")
|
||||
}
|
||||
|
||||
dns.txt["_warmbly.frostlogic.se"] = append(dns.txt["_warmbly.frostlogic.se"], proof.Record.Value)
|
||||
dns.ips["acme.io"] = dns.ips["track.warmbly.test"]
|
||||
dns.txt["_warmbly.acme.io"] = []string{s.proof.Value(org, "acme.io")}
|
||||
r, xerr := s.SetRedirect(ctx, org, uuid.New(), "acme.io", RedirectInput{TargetURL: "https://www.frostlogic.se"})
|
||||
if xerr != nil {
|
||||
t.Fatal(xerr)
|
||||
}
|
||||
if !r.Verified || r.TargetActive == nil || !*r.TargetActive || r.Website == nil || !r.Website.Verified || reach.probes == 0 {
|
||||
t.Fatalf("a proved website is not live: %+v", r)
|
||||
}
|
||||
if target, ok, err := s.Lookup(ctx, "acme.io"); err != nil || !ok || target != "https://www.frostlogic.se" {
|
||||
t.Fatalf("Lookup = %q, %v, %v", target, ok, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnUnprovedWebsiteIsHeldWithoutBlamingTheProxy(t *testing.T) {
|
||||
s, dns, sites, reach := newWebsiteTest()
|
||||
ctx := context.Background()
|
||||
org := uuid.New()
|
||||
dns.txt["_warmbly.frostlogic.se"] = []string{s.proof.Value(org, "frostlogic.se")}
|
||||
dns.ips["acme.io"] = dns.ips["track.warmbly.test"]
|
||||
dns.txt["_warmbly.acme.io"] = []string{s.proof.Value(org, "acme.io")}
|
||||
if _, xerr := s.SetRedirect(ctx, org, uuid.New(), "acme.io", RedirectInput{TargetURL: "frostlogic.se"}); xerr != nil {
|
||||
t.Fatal(xerr)
|
||||
}
|
||||
|
||||
// A lookup that could not tell keeps the website; a record that is gone drops it.
|
||||
sites.age(7 * time.Hour)
|
||||
dns.fail = true
|
||||
s.ownDomains().Recheck(ctx)
|
||||
dns.fail = false
|
||||
if len(sites.rows) != 1 {
|
||||
t.Fatal("a failed lookup dropped the website")
|
||||
}
|
||||
sites.age(7 * time.Hour)
|
||||
delete(dns.txt, "_warmbly.frostlogic.se")
|
||||
s.ownDomains().Recheck(ctx)
|
||||
if len(sites.rows) != 0 {
|
||||
t.Fatal("a website whose record is gone stayed proved")
|
||||
}
|
||||
if _, ok, err := s.Lookup(ctx, "acme.io"); err != nil || ok {
|
||||
t.Fatalf("an unproved website is served: %v, %v", ok, err)
|
||||
}
|
||||
|
||||
before := reach.probes
|
||||
r, xerr := s.VerifyRedirect(ctx, org, "acme.io")
|
||||
if xerr != nil {
|
||||
t.Fatal(xerr)
|
||||
}
|
||||
if reach.probes != before || r.Reach != nil {
|
||||
t.Fatalf("the visit ran for a redirect this instance withholds: %+v", r.Reach)
|
||||
}
|
||||
if r.TargetActive == nil || *r.TargetActive || r.Website == nil || r.Website.Verified || r.Website.Record == nil || r.Website.Record.Name != "_warmbly.frostlogic.se" {
|
||||
t.Fatalf("the website's record is not shown: %+v", r)
|
||||
}
|
||||
|
||||
// Publishing it again and checking puts the redirect back.
|
||||
dns.txt["_warmbly.frostlogic.se"] = []string{s.proof.Value(org, "frostlogic.se")}
|
||||
if r, _ = s.VerifyRedirect(ctx, org, "acme.io"); r.TargetActive == nil || !*r.TargetActive || r.Reach == nil {
|
||||
t.Fatalf("a re-proved website is not live: %+v", r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAWebsiteIsItsRegistrableDomain(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"www.frostlogic.se": "frostlogic.se",
|
||||
"shop.acme.co.uk": "acme.co.uk",
|
||||
"acme.com": "acme.com",
|
||||
"co.uk": "",
|
||||
"203.0.113.7": "",
|
||||
"Deep.Blog.ACME.com": "acme.com",
|
||||
}
|
||||
for host, want := range cases {
|
||||
if got := owndomain.Website(host); got != want {
|
||||
t.Errorf("Website(%q) = %q, want %q", host, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE website_domains;
|
||||
@@ -0,0 +1,10 @@
|
||||
-- Websites a workspace proved with its _warmbly TXT record, so its redirects may send visitors there.
|
||||
CREATE TABLE website_domains (
|
||||
organization_id uuid NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
domain text NOT NULL CHECK (domain = lower(domain) AND domain <> ''),
|
||||
verified_at timestamptz NOT NULL DEFAULT now(),
|
||||
last_checked_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (organization_id, domain)
|
||||
);
|
||||
|
||||
CREATE INDEX website_domains_checked_idx ON website_domains (last_checked_at);
|
||||
@@ -401,6 +401,8 @@ type DomainRedirect struct {
|
||||
TargetActive *bool `json:"target_active,omitempty"`
|
||||
// TargetInactiveReason says why, when TargetActive is false.
|
||||
TargetInactiveReason string `json:"target_inactive_reason,omitempty"`
|
||||
// Website is set when the destination is the workspace's only once it publishes its TXT proof there.
|
||||
Website *RedirectWebsite `json:"website,omitempty"`
|
||||
// VerifyToken is written into the TXT record; never serialized on its own.
|
||||
VerifyToken string `json:"-"`
|
||||
OrganizationID uuid.UUID `json:"-"`
|
||||
@@ -412,6 +414,14 @@ type DomainRedirect struct {
|
||||
LinkedInstanceID *uuid.UUID `json:"-"`
|
||||
}
|
||||
|
||||
// RedirectWebsite is a destination website and the TXT record that proves it is the workspace's.
|
||||
type RedirectWebsite struct {
|
||||
Domain string `json:"domain"`
|
||||
Verified bool `json:"verified"`
|
||||
// Record is the TXT record to publish at the website's DNS; absent when the website needs none.
|
||||
Record *DNSRecord `json:"record,omitempty"`
|
||||
}
|
||||
|
||||
// DomainRedirectLookup is what serving a host needs: the destination and whose rule it answers to.
|
||||
type DomainRedirectLookup struct {
|
||||
TargetURL string
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/warmbly/warmbly/internal/infrastructure/db"
|
||||
)
|
||||
|
||||
// WebsiteDomain is a website a workspace proved with its TXT record.
|
||||
type WebsiteDomain struct {
|
||||
OrganizationID uuid.UUID
|
||||
Domain string
|
||||
VerifiedAt time.Time
|
||||
LastCheckedAt time.Time
|
||||
}
|
||||
|
||||
// WebsiteDomainRepository stores the websites a workspace proved; every read a caller reaches is scoped by organization.
|
||||
type WebsiteDomainRepository interface {
|
||||
// Verified lists the workspace's proved websites.
|
||||
Verified(ctx context.Context, orgID uuid.UUID) ([]string, error)
|
||||
// Mark records a proof seen now, keeping the first verification time.
|
||||
Mark(ctx context.Context, orgID uuid.UUID, domain string) error
|
||||
// Drop forgets a website whose proof is gone.
|
||||
Drop(ctx context.Context, orgID uuid.UUID, domain string) error
|
||||
// Due are proofs last checked before the cutoff, oldest first.
|
||||
Due(ctx context.Context, before time.Time, limit int) ([]WebsiteDomain, error)
|
||||
}
|
||||
|
||||
type websiteDomainRepository struct{ DB *db.DB }
|
||||
|
||||
func NewWebsiteDomainRepository(database *db.DB) WebsiteDomainRepository {
|
||||
return &websiteDomainRepository{DB: database}
|
||||
}
|
||||
|
||||
func (r *websiteDomainRepository) Verified(ctx context.Context, orgID uuid.UUID) ([]string, error) {
|
||||
query := `SELECT domain FROM website_domains WHERE organization_id = $1 ORDER BY domain`
|
||||
rows, err := r.DB.Query(ctx, query, orgID)
|
||||
if err != nil {
|
||||
db.CaptureError(err, query, nil, "query")
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []string
|
||||
for rows.Next() {
|
||||
var d string
|
||||
if err := rows.Scan(&d); err != nil {
|
||||
db.CaptureError(err, query, nil, "scan")
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, d)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func (r *websiteDomainRepository) Mark(ctx context.Context, orgID uuid.UUID, domain string) error {
|
||||
query := `INSERT INTO website_domains (organization_id, domain) VALUES ($1, lower($2))
|
||||
ON CONFLICT (organization_id, domain) DO UPDATE SET last_checked_at = now()`
|
||||
if _, err := r.DB.Exec(ctx, query, orgID, domain); err != nil {
|
||||
db.CaptureError(err, query, nil, "exec")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *websiteDomainRepository) Drop(ctx context.Context, orgID uuid.UUID, domain string) error {
|
||||
query := `DELETE FROM website_domains WHERE organization_id = $1 AND domain = lower($2)`
|
||||
if _, err := r.DB.Exec(ctx, query, orgID, domain); err != nil {
|
||||
db.CaptureError(err, query, nil, "exec")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *websiteDomainRepository) Due(ctx context.Context, before time.Time, limit int) ([]WebsiteDomain, error) {
|
||||
query := `SELECT organization_id, domain, verified_at, last_checked_at FROM website_domains
|
||||
WHERE last_checked_at < $1 ORDER BY last_checked_at LIMIT $2`
|
||||
rows, err := r.DB.Query(ctx, query, before, limit)
|
||||
if err != nil {
|
||||
db.CaptureError(err, query, nil, "query")
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []WebsiteDomain
|
||||
for rows.Next() {
|
||||
var w WebsiteDomain
|
||||
if err := rows.Scan(&w.OrganizationID, &w.Domain, &w.VerifiedAt, &w.LastCheckedAt); err != nil {
|
||||
db.CaptureError(err, query, nil, "scan")
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, w)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
@@ -1,12 +1,22 @@
|
||||
// Where a root redirect is served from, whether visitors get it, and how to fix it (or hand it to Warmbly Cloud) when they do not.
|
||||
import React from "react";
|
||||
import { AnimatePresence, motion } from "framer-motion";
|
||||
import { AlertTriangleIcon, CheckCircle2Icon, CloudIcon, ExternalLinkIcon, Loader2Icon, ServerIcon, ZapIcon } from "lucide-react";
|
||||
import {
|
||||
AlertTriangleIcon,
|
||||
CheckCircle2Icon,
|
||||
CircleDashedIcon,
|
||||
CloudIcon,
|
||||
ExternalLinkIcon,
|
||||
Loader2Icon,
|
||||
RefreshCwIcon,
|
||||
ServerIcon,
|
||||
ZapIcon,
|
||||
} from "lucide-react";
|
||||
import type { DomainRedirect, RedirectServer } from "@/lib/api/models/app/emails/SendingDomain";
|
||||
import timeAgo from "@/lib/helper/timeAgo";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { CopyButton } from "./parts";
|
||||
import { PROXY_NAMES, redirectBlocked } from "./rules";
|
||||
import { CopyButton, DnsRecordsTable } from "./parts";
|
||||
import { PROXY_NAMES, redirectBlocked, shortUrl } from "./rules";
|
||||
import type { CloudServing } from "./cloudServing";
|
||||
|
||||
/* ── Served from ─────────────────────── */
|
||||
@@ -50,8 +60,10 @@ export function ServedByPicker({
|
||||
);
|
||||
} else if (!cloud.offer?.available) {
|
||||
cloudBody = "Warmbly Cloud does not serve redirects for this instance right now.";
|
||||
} else if (!cloudOpen) {
|
||||
} else if (!cloudOpen && cloud.offer.used >= cloud.offer.limit) {
|
||||
cloudBody = `Warmbly Cloud serves up to ${cloud.offer.limit} redirects for one instance, and this one has reached it.`;
|
||||
} else if (!cloudOpen) {
|
||||
cloudBody = "The Warmbly Cloud link is not tied to this workspace. Reconnect Warmbly Cloud from this workspace to serve redirects there.";
|
||||
} else {
|
||||
cloudBody = "Point the domain at Warmbly Cloud. It serves the redirect and its certificate, with nothing to set up on your server.";
|
||||
}
|
||||
@@ -131,89 +143,205 @@ function ServerOption({
|
||||
);
|
||||
}
|
||||
|
||||
/* ── Status ─────────────────────── */
|
||||
/* ── Progress ─────────────────────── */
|
||||
|
||||
/** The redirect's state as a visitor would meet it: waiting for DNS, live, or in place but not reaching them. */
|
||||
export function RedirectStatusBanner({ domain, redirect }: { domain: string; redirect: DomainRedirect }) {
|
||||
type StepState = "done" | "todo" | "blocked" | "waiting";
|
||||
|
||||
interface ProgressStep {
|
||||
key: string;
|
||||
state: StepState;
|
||||
title: string;
|
||||
body?: React.ReactNode;
|
||||
}
|
||||
|
||||
function StepMark({ state, n }: { state: StepState; n: number }) {
|
||||
if (state === "done") return <CheckCircle2Icon className="w-4 h-4 text-emerald-600" />;
|
||||
if (state === "blocked") return <AlertTriangleIcon className="w-4 h-4 text-amber-600" />;
|
||||
if (state === "waiting") return <CircleDashedIcon className="w-4 h-4 text-slate-300" />;
|
||||
return (
|
||||
<span className="size-4 rounded-full ring-1 ring-inset ring-amber-300 bg-amber-50 text-amber-700 text-[10px] font-semibold inline-flex items-center justify-center">
|
||||
{n}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** What stands between the redirect and a visitor, one step at a time, with the fix for the step that is missing. */
|
||||
export function RedirectProgress({
|
||||
domain,
|
||||
redirect,
|
||||
fix,
|
||||
onCheck,
|
||||
checking,
|
||||
}: {
|
||||
domain: string;
|
||||
redirect: DomainRedirect;
|
||||
/** Shown under the visitor step when DNS is right but visitors do not get the redirect. */
|
||||
fix: React.ReactNode;
|
||||
onCheck: () => void;
|
||||
checking: boolean;
|
||||
}) {
|
||||
const reach = redirect.reach ?? null;
|
||||
const blocked = redirectBlocked(redirect);
|
||||
const live = redirect.verified && !blocked;
|
||||
const cloud = redirect.served_by === "cloud";
|
||||
const tone = live ? "emerald" : "amber";
|
||||
const site = redirect.website?.record ? redirect.website : null;
|
||||
const siteOk = redirect.target_active !== false;
|
||||
const blocked = redirectBlocked(redirect);
|
||||
const live = redirect.verified && siteOk && !blocked;
|
||||
const checkedAt = redirect.last_checked_at ?? reach?.checked_at;
|
||||
const where = cloud ? "Warmbly Cloud" : "this server";
|
||||
|
||||
let title: string;
|
||||
let body: React.ReactNode;
|
||||
if (!redirect.verified) {
|
||||
title = "Waiting for DNS";
|
||||
body = redirect.last_error || (cloud ? "Add the records below to point the domain at Warmbly Cloud." : "Add the records below at your DNS provider.");
|
||||
} else if (blocked) {
|
||||
title = "DNS is in place, but visitors do not get the redirect";
|
||||
body = reach?.detail || `Opening ${domain} does not reach the redirect yet.`;
|
||||
} else {
|
||||
title = "Live";
|
||||
body = (
|
||||
<>
|
||||
{domain}
|
||||
{redirect.include_www ? ` and www.${domain}` : ""} redirect to{" "}
|
||||
<a
|
||||
href={redirect.target_url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="inline-flex items-center gap-0.5 underline decoration-emerald-300 hover:decoration-emerald-600 break-all"
|
||||
>
|
||||
{redirect.target_url}
|
||||
<ExternalLinkIcon className="w-2.5 h-2.5 shrink-0" />
|
||||
</a>
|
||||
.
|
||||
</>
|
||||
const steps: ProgressStep[] = [];
|
||||
steps.push(
|
||||
redirect.verified
|
||||
? { key: "dns", state: "done", title: `${domain} points at ${where}` }
|
||||
: cloud && !siteOk
|
||||
? { key: "dns", state: "waiting", title: `${domain} points at ${where}`, body: "Warmbly Cloud checks the records once the website is confirmed." }
|
||||
: {
|
||||
key: "dns",
|
||||
state: "todo",
|
||||
title: `Point ${domain} at ${where}`,
|
||||
body: redirect.last_error || "Add the DNS records listed below at your DNS provider.",
|
||||
},
|
||||
);
|
||||
if (site) {
|
||||
steps.push(
|
||||
site.verified
|
||||
? { key: "site", state: "done", title: `${site.domain} is confirmed as your website` }
|
||||
: {
|
||||
key: "site",
|
||||
state: "todo",
|
||||
title: `Confirm ${site.domain} is your website`,
|
||||
body: (
|
||||
<div className="space-y-2">
|
||||
<p>
|
||||
Redirects only send visitors to websites this workspace controls. Add this TXT record where{" "}
|
||||
<span className="font-medium text-slate-800">{site.domain}</span>'s DNS is managed (not {domain}'s), then
|
||||
press Check now. It does not change your website.
|
||||
</p>
|
||||
<DnsRecordsTable
|
||||
records={[{ key: "website", type: site.record!.type, name: site.record!.name, value: site.record!.value, ok: site.record!.ok }]}
|
||||
className="bg-white"
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
if (live) {
|
||||
steps.push({
|
||||
key: "visit",
|
||||
state: "done",
|
||||
title: "Visitors get the redirect",
|
||||
body:
|
||||
reach?.status === "unreachable" ? (
|
||||
reach.hint === "no_listener" ? (
|
||||
<>
|
||||
This server could not open {domain} to double-check, which some networks do not allow.{" "}
|
||||
<a
|
||||
href={`http://${domain}`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="text-sky-700 hover:text-sky-800 underline decoration-sky-300 hover:decoration-sky-600"
|
||||
>
|
||||
Open it
|
||||
</a>{" "}
|
||||
to confirm.
|
||||
</>
|
||||
) : (
|
||||
reach.detail
|
||||
)
|
||||
) : undefined,
|
||||
});
|
||||
} else if (blocked && siteOk) {
|
||||
steps.push({
|
||||
key: "visit",
|
||||
state: "blocked",
|
||||
title: "Visitors do not get the redirect yet",
|
||||
body: (
|
||||
<div className="space-y-2">
|
||||
<p>{reach?.detail || `Opening ${domain} does not reach the redirect yet.`}</p>
|
||||
{fix}
|
||||
</div>
|
||||
),
|
||||
});
|
||||
} else {
|
||||
steps.push({ key: "visit", state: "waiting", title: "Visitors get the redirect", body: "Checked by opening the domain once the steps above are done." });
|
||||
}
|
||||
|
||||
const left = steps.filter((st) => st.state === "todo").length;
|
||||
const headline = live
|
||||
? "Live"
|
||||
: blocked && siteOk
|
||||
? "DNS is in place, but visitors do not get the redirect"
|
||||
: left > 0
|
||||
? `${left} ${left === 1 ? "step" : "steps"} left`
|
||||
: "Almost there";
|
||||
let n = 0;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"rounded-md border px-3 py-2.5 flex items-start gap-2",
|
||||
tone === "emerald" ? "border-emerald-200 bg-emerald-50/60" : "border-amber-200 bg-amber-50/60",
|
||||
)}
|
||||
>
|
||||
{live ? (
|
||||
<CheckCircle2Icon className="w-3.5 h-3.5 text-emerald-600 mt-0.5 shrink-0" />
|
||||
) : blocked ? (
|
||||
<AlertTriangleIcon className="w-3.5 h-3.5 text-amber-600 mt-0.5 shrink-0" />
|
||||
) : (
|
||||
<Loader2Icon className="w-3.5 h-3.5 text-amber-600 mt-0.5 shrink-0" />
|
||||
)}
|
||||
<div className="min-w-0 flex-1 text-[11.5px] leading-relaxed">
|
||||
<div className="flex items-center gap-1.5 flex-wrap">
|
||||
<p className={cn("text-[12.5px] font-medium", tone === "emerald" ? "text-emerald-900" : "text-amber-900")}>{title}</p>
|
||||
{cloud && (
|
||||
<span className="h-4 px-1.5 rounded bg-white/70 ring-1 ring-inset ring-slate-200 text-slate-600 text-[10px] font-medium inline-flex items-center gap-1">
|
||||
<CloudIcon className="w-2.5 h-2.5" />
|
||||
Warmbly Cloud
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className={cn("break-words", tone === "emerald" ? "text-emerald-800/90" : "text-amber-800/90")}>{body}</p>
|
||||
{live && reach?.status === "unreachable" && reach.hint !== "no_listener" && reach.detail && (
|
||||
<p className="text-[11px] text-slate-500 mt-1">{reach.detail}</p>
|
||||
)}
|
||||
{live && reach?.status === "unreachable" && reach.hint === "no_listener" && (
|
||||
<p className="text-[11px] text-slate-500 mt-1">
|
||||
This server could not open {domain} to double-check, which some networks do not allow.{" "}
|
||||
<div className={cn("rounded-md border", live ? "border-emerald-200 bg-emerald-50/40" : "border-slate-200 bg-white")}>
|
||||
<div className="px-3 pt-2.5 pb-2 flex items-start gap-2">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-1.5 flex-wrap">
|
||||
<p className={cn("text-[12.5px] font-medium", live ? "text-emerald-900" : "text-slate-900")}>{headline}</p>
|
||||
{cloud && (
|
||||
<span className="h-4 px-1.5 rounded bg-white/70 ring-1 ring-inset ring-slate-200 text-slate-600 text-[10px] font-medium inline-flex items-center gap-1">
|
||||
<CloudIcon className="w-2.5 h-2.5" />
|
||||
Warmbly Cloud
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-[11.5px] text-slate-600 break-words">
|
||||
{domain}
|
||||
{redirect.include_www ? ` and www.${domain}` : ""} <span className="text-slate-400">→</span>{" "}
|
||||
<a
|
||||
href={`http://${domain}`}
|
||||
href={redirect.target_url}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="text-sky-700 hover:text-sky-800 underline decoration-sky-300 hover:decoration-sky-600"
|
||||
className="inline-flex items-center gap-0.5 text-slate-800 underline decoration-slate-300 hover:decoration-slate-600 break-all"
|
||||
>
|
||||
Open it
|
||||
</a>{" "}
|
||||
to confirm.
|
||||
{shortUrl(redirect.target_url)}
|
||||
<ExternalLinkIcon className="w-2.5 h-2.5 shrink-0" />
|
||||
</a>
|
||||
</p>
|
||||
)}
|
||||
{checkedAt && <p className="text-[11px] text-slate-500 mt-0.5">Last checked {timeAgo(checkedAt)}</p>}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onCheck}
|
||||
disabled={checking}
|
||||
className="shrink-0 h-6 px-2 rounded-md border border-slate-200 bg-white text-[11.5px] text-slate-700 hover:bg-slate-50 inline-flex items-center gap-1 transition-colors disabled:opacity-50"
|
||||
>
|
||||
<RefreshCwIcon className={cn("w-3 h-3", checking && "animate-spin")} />
|
||||
Check now
|
||||
</button>
|
||||
</div>
|
||||
<ol className="px-3 pb-2.5 space-y-2">
|
||||
{steps.map((st) => {
|
||||
if (st.state === "todo") n++;
|
||||
return (
|
||||
<li key={st.key} className="flex items-start gap-2">
|
||||
<span className="mt-px shrink-0">
|
||||
<StepMark state={st.state} n={n} />
|
||||
</span>
|
||||
<div className="min-w-0 flex-1 text-[11.5px] leading-relaxed">
|
||||
<p
|
||||
className={cn(
|
||||
"text-[12px]",
|
||||
st.state === "done" ? "text-slate-600" : st.state === "waiting" ? "text-slate-500" : "text-slate-900 font-medium",
|
||||
)}
|
||||
>
|
||||
{st.title}
|
||||
</p>
|
||||
{st.body && <div className="text-slate-600 break-words">{st.body}</div>}
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ol>
|
||||
{checkedAt && (
|
||||
<p className="px-3 pb-2 text-[11px] text-slate-400">
|
||||
Last checked {timeAgo(checkedAt)}. Warmbly also checks by itself.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,12 +18,19 @@ import {
|
||||
Loader2Icon,
|
||||
MinusIcon,
|
||||
MousePointerClickIcon,
|
||||
RefreshCwIcon,
|
||||
ShieldCheckIcon,
|
||||
Trash2Icon,
|
||||
XIcon,
|
||||
ZapIcon,
|
||||
} from "lucide-react";
|
||||
import type { SendingDomain, DNSRecord, DomainRedirect, RedirectServer, VendorDomainLink } from "@/lib/api/models/app/emails/SendingDomain";
|
||||
import type {
|
||||
SendingDomain,
|
||||
DNSRecord,
|
||||
DomainRedirect,
|
||||
RedirectServer,
|
||||
RedirectWebsite,
|
||||
VendorDomainLink,
|
||||
} from "@/lib/api/models/app/emails/SendingDomain";
|
||||
import type TrackingDomain from "@/lib/api/models/app/emails/TrackingDomain";
|
||||
import {
|
||||
useDeleteDomainRedirect,
|
||||
@@ -33,6 +40,7 @@ import {
|
||||
useSetVendorTracking,
|
||||
useTrackingSuggestion,
|
||||
useVerifyDomainRedirect,
|
||||
useVerifyRedirectWebsite,
|
||||
} from "@/lib/api/hooks/app/emails/useSendingDomains";
|
||||
import { vendorLabel } from "@/lib/api/models/app/emails/MailboxSources";
|
||||
import { Label, TextInput } from "@/components/ui/field";
|
||||
@@ -44,7 +52,7 @@ import buildError from "@/lib/helper/buildError";
|
||||
import { mailHostLabel } from "@/lib/mailHost";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { DnsRecordsTable, StatusPill, VendorChip, type RecordRow } from "./parts";
|
||||
import { ReachFix, RedirectStatusBanner, ServedByPicker } from "./RedirectServing";
|
||||
import { ReachFix, RedirectProgress, ServedByPicker } from "./RedirectServing";
|
||||
import { defaultServer, useCloudServing } from "./cloudServing";
|
||||
import CloudConnectDialog from "@/components/app/cloud/CloudConnectDialog";
|
||||
import {
|
||||
@@ -61,8 +69,20 @@ import {
|
||||
trackingRecord,
|
||||
trackingState,
|
||||
vendorCanCname,
|
||||
websiteUnproved,
|
||||
} from "./rules";
|
||||
|
||||
/** The lower-case host of a typed website address, or "". */
|
||||
function hostOf(raw: string): string {
|
||||
const t = raw.trim();
|
||||
if (!t) return "";
|
||||
try {
|
||||
return new URL(t.includes("://") ? t : `https://${t}`).hostname.toLowerCase();
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export type DomainTab = "overview" | "tracking" | "redirect";
|
||||
|
||||
const TABS: { key: DomainTab; label: string; icon: typeof GlobeIcon }[] = [
|
||||
@@ -998,11 +1018,12 @@ function DnsRedirect({
|
||||
const save = useSetDomainRedirect();
|
||||
const verify = useVerifyDomainRedirect();
|
||||
const remove = useDeleteDomainRedirect();
|
||||
const proveSite = useVerifyRedirectWebsite();
|
||||
const cloud = useCloudServing();
|
||||
const [checked, setChecked] = React.useState<DomainRedirect | null>(null);
|
||||
const [tried, setTried] = React.useState(false);
|
||||
// The API's refusal of the destination, shown under the field until it is edited.
|
||||
const [refused, setRefused] = React.useState("");
|
||||
// The record that confirms the typed website is the workspace's, once a save was refused for lack of it.
|
||||
const [proof, setProof] = React.useState<RedirectWebsite | null>(null);
|
||||
// "serve" came from a redirect visitors do not reach, so linking moves it; "pick" only selects Cloud.
|
||||
const [connecting, setConnecting] = React.useState<"pick" | "serve" | null>(null);
|
||||
|
||||
@@ -1019,7 +1040,7 @@ function DnsRedirect({
|
||||
const toCloud = server === "cloud";
|
||||
|
||||
function resetDrafts() {
|
||||
setRefused("");
|
||||
setProof(null);
|
||||
setUrlDraft(null);
|
||||
setWwwDraft(null);
|
||||
setServedDraft(null);
|
||||
@@ -1033,7 +1054,7 @@ function DnsRedirect({
|
||||
});
|
||||
setChecked(r);
|
||||
resetDrafts();
|
||||
if (r.verified && !redirectBlocked(r)) toast.success("Redirect saved and live");
|
||||
if (r.verified && r.target_active !== false && !redirectBlocked(r)) toast.success("Redirect saved and live");
|
||||
else if (r.verified) toast("Saved. DNS is in place, but visitors do not reach the redirect yet.");
|
||||
else if (r.served_by === "cloud") toast.success("Saved. Add the records below to point the domain at Warmbly Cloud.");
|
||||
else toast.success("Redirect saved. Add the DNS records below to switch it on.");
|
||||
@@ -1047,8 +1068,23 @@ function DnsRedirect({
|
||||
await persist(url.trim(), www, server);
|
||||
} catch (e) {
|
||||
const err = e as AppError;
|
||||
if (err.code === REDIRECT_NOT_OWN_DOMAIN) setRefused(err.message);
|
||||
toast.error(buildError(err));
|
||||
if (err.code !== REDIRECT_NOT_OWN_DOMAIN) {
|
||||
toast.error(buildError(err));
|
||||
return;
|
||||
}
|
||||
// Not refused for good: the website only has to carry the workspace's TXT record.
|
||||
try {
|
||||
const w = await proveSite.mutateAsync({ domain: domain.domain, url: url.trim() });
|
||||
if (w.verified) {
|
||||
await persist(url.trim(), www, server);
|
||||
return;
|
||||
}
|
||||
// A second press means the record was asked for already and is still not there.
|
||||
if (proof) toast(`The TXT record for ${w.domain} is not visible yet. It can take a few minutes to appear.`);
|
||||
setProof(w);
|
||||
} catch (pe) {
|
||||
toast.error(buildError(pe as AppError));
|
||||
}
|
||||
}
|
||||
};
|
||||
// Moving a redirect changes its records, so a live one stops until the new ones are in place.
|
||||
@@ -1098,7 +1134,8 @@ function DnsRedirect({
|
||||
try {
|
||||
const r = await verify.mutateAsync(domain.domain);
|
||||
setChecked(r);
|
||||
if (r.verified && !redirectBlocked(r)) toast.success("The redirect is live.");
|
||||
if (websiteUnproved(r)) toast(`The TXT record for ${r.website!.domain} is not visible yet. It can take a few minutes to appear.`);
|
||||
else if (r.verified && !redirectBlocked(r)) toast.success("The redirect is live.");
|
||||
else if (r.verified) toast("DNS is in place, but visitors do not reach the redirect yet.");
|
||||
else toast("Not every record is visible yet. It keeps checking by itself.");
|
||||
} catch (e) {
|
||||
@@ -1123,53 +1160,73 @@ function DnsRedirect({
|
||||
});
|
||||
}
|
||||
|
||||
// A proof card for a website other than the one now typed would ask for the wrong record.
|
||||
const typedHost = hostOf(url);
|
||||
const shownProof = proof && (typedHost === proof.domain || typedHost.endsWith(`.${proof.domain}`)) ? proof : null;
|
||||
const savedUnproved = websiteUnproved(redirect);
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{redirect && (
|
||||
<div className="space-y-2.5">
|
||||
<RedirectStatusBanner domain={domain.domain} redirect={redirect} />
|
||||
<ReachFix
|
||||
key={redirect.reach?.proxy ?? ""}
|
||||
domain={domain.domain}
|
||||
redirect={redirect}
|
||||
cloud={cloud}
|
||||
onServeFromCloud={serveFromCloud}
|
||||
onConnect={() => setConnecting("serve")}
|
||||
switching={save.isPending}
|
||||
/>
|
||||
</div>
|
||||
<RedirectProgress
|
||||
domain={domain.domain}
|
||||
redirect={redirect}
|
||||
onCheck={() => void checkNow()}
|
||||
checking={verify.isPending}
|
||||
fix={
|
||||
<ReachFix
|
||||
key={redirect.reach?.proxy ?? ""}
|
||||
domain={domain.domain}
|
||||
redirect={redirect}
|
||||
cloud={cloud}
|
||||
onServeFromCloud={serveFromCloud}
|
||||
onConnect={() => setConnecting("serve")}
|
||||
switching={save.isPending}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="space-y-2.5">
|
||||
{redirect && <Eyebrow>Settings</Eyebrow>}
|
||||
<div>
|
||||
<Label>Website</Label>
|
||||
<Label>Send visitors to</Label>
|
||||
<TextInput
|
||||
value={url}
|
||||
onChange={(v) => {
|
||||
setRefused("");
|
||||
setUrlDraft(v);
|
||||
}}
|
||||
onChange={setUrlDraft}
|
||||
placeholder="https://yourcompany.com"
|
||||
className="w-full"
|
||||
invalid={(tried && !!problem) || refused !== ""}
|
||||
invalid={tried && !!problem}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") void submit();
|
||||
}}
|
||||
/>
|
||||
{tried && problem ? (
|
||||
<p className="mt-1 text-[11px] text-rose-700">{problem}</p>
|
||||
) : refused ? (
|
||||
<p className="mt-1 text-[11px] text-rose-700" role="alert">
|
||||
{refused}
|
||||
</p>
|
||||
) : redirect?.target_active === false && url.trim() === redirect.target_url ? (
|
||||
<p className="mt-1 text-[11px] text-amber-800 leading-relaxed">
|
||||
{redirect.target_inactive_reason ||
|
||||
"Not in use: the destination is no longer on one of this workspace's own domains, so visitors get the domain's default page instead. This happens when the mailbox or verified domain it relied on was removed; point it at one of your own domains or reconnect that domain."}
|
||||
</p>
|
||||
) : redirect?.target_active === false && !savedUnproved && url.trim() === redirect.target_url ? (
|
||||
<p className="mt-1 text-[11px] text-amber-800 leading-relaxed">{redirect.target_inactive_reason}</p>
|
||||
) : null}
|
||||
<p className="mt-1 text-[11px] text-slate-500 leading-relaxed">{OWN_DOMAIN_HINT}</p>
|
||||
{!shownProof && <p className="mt-1 text-[11px] text-slate-500 leading-relaxed">{OWN_DOMAIN_HINT}</p>}
|
||||
</div>
|
||||
{shownProof?.record && !shownProof.verified && (
|
||||
<div className="rounded-md border border-sky-200 bg-sky-50/50 px-3 py-2.5 space-y-2" role="status">
|
||||
<div className="flex items-start gap-2">
|
||||
<ShieldCheckIcon className="w-3.5 h-3.5 text-sky-700 mt-0.5 shrink-0" />
|
||||
<div className="min-w-0 text-[11.5px] text-slate-600 leading-relaxed">
|
||||
<p className="text-[12.5px] font-medium text-slate-900">Confirm {shownProof.domain} is your website</p>
|
||||
<p>
|
||||
Redirects only send visitors to websites this workspace controls. Add this TXT record where {shownProof.domain}
|
||||
's DNS is managed, then save again. It does not change your website, and you only do it once for every
|
||||
domain that redirects there.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<DnsRecordsTable
|
||||
records={[{ key: "website", type: shownProof.record.type, name: shownProof.record.name, value: shownProof.record.value }]}
|
||||
className="bg-white"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="text-[12.5px] text-slate-900">Include www.{domain.domain}</div>
|
||||
@@ -1190,11 +1247,19 @@ function DnsRedirect({
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void submit()}
|
||||
disabled={save.isPending || (!!redirect && !changed)}
|
||||
disabled={save.isPending || proveSite.isPending || (!!redirect && !changed)}
|
||||
className="h-7 px-2.5 rounded-md bg-sky-600 hover:bg-sky-700 text-white text-[12px] font-medium inline-flex items-center gap-1.5 transition-colors disabled:opacity-50"
|
||||
>
|
||||
{save.isPending && <Loader2Icon className="w-3 h-3 animate-spin" />}
|
||||
{!redirect ? "Save redirect" : moving ? (toCloud ? "Move to Warmbly Cloud" : "Move to this server") : "Update redirect"}
|
||||
{(save.isPending || proveSite.isPending) && <Loader2Icon className="w-3 h-3 animate-spin" />}
|
||||
{shownProof
|
||||
? "Check and save"
|
||||
: !redirect
|
||||
? "Save redirect"
|
||||
: moving
|
||||
? toCloud
|
||||
? "Move to Warmbly Cloud"
|
||||
: "Move to this server"
|
||||
: "Update redirect"}
|
||||
</button>
|
||||
{redirect && changed && (
|
||||
<button
|
||||
@@ -1210,23 +1275,12 @@ function DnsRedirect({
|
||||
|
||||
{redirect && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Eyebrow>DNS records for {domain.domain}</Eyebrow>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void checkNow()}
|
||||
disabled={verify.isPending}
|
||||
className="ml-auto h-6 px-2 rounded-md border border-slate-200 text-[11.5px] text-slate-700 hover:bg-slate-50 inline-flex items-center gap-1 transition-colors disabled:opacity-50"
|
||||
>
|
||||
<RefreshCwIcon className={cn("w-3 h-3", verify.isPending && "animate-spin")} />
|
||||
Check now
|
||||
</button>
|
||||
</div>
|
||||
<Eyebrow>DNS records for {domain.domain}</Eyebrow>
|
||||
<DnsRecordsTable records={records} />
|
||||
<p className="text-[11.5px] text-slate-500 leading-relaxed">
|
||||
{redirect.served_by === "cloud"
|
||||
? `The root records point ${domain.domain} at Warmbly Cloud and replace whatever it serves today. New records can take from a few minutes to a few hours to appear. Warmbly Cloud checks by itself every 10 minutes and switches the redirect on once the ownership and root records are in place.`
|
||||
: `The root records replace whatever ${domain.domain} serves today. New records can take from a few minutes to a few hours to appear. Warmbly checks by itself every 10 minutes and switches the redirect on once the ownership and root records are in place, then opens the domain to make sure visitors get it.`}
|
||||
? `These point ${domain.domain} at Warmbly Cloud and replace whatever it serves today. New records can take a few minutes to a few hours to show up.`
|
||||
: `These point ${domain.domain} at this server and replace whatever it serves today. New records can take a few minutes to a few hours to show up.`}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -63,6 +63,8 @@ export function redirectBlocked(r: DomainRedirect | null | undefined): boolean {
|
||||
}
|
||||
|
||||
export function redirectState(d: SendingDomain): RedirectState {
|
||||
// A destination not yet the workspace's is not served, whatever DNS says.
|
||||
if (d.redirect?.target_active === false) return "pending";
|
||||
if (d.redirect?.verified) return redirectBlocked(d.redirect) ? "blocked" : "live";
|
||||
if (d.vendor_domain?.forwarding) return "vendor";
|
||||
if (d.redirect) return "pending";
|
||||
@@ -158,9 +160,18 @@ export const REDIRECT_NOT_OWN_DOMAIN = "redirect_target_not_own_domain";
|
||||
|
||||
/** Where a redirect may point, shown under every destination field. */
|
||||
export const OWN_DOMAIN_HINT =
|
||||
"Must be a page on one of your workspace's own domains: a domain you have a mailbox on (not gmail.com or another shared provider), your verified tracking domain, your verified forms domain, or a subdomain of one.";
|
||||
"Usually your main website. If you do not send from its domain, Warmbly asks for one TXT record there once, to confirm the website is yours.";
|
||||
|
||||
/** The redirect waits for its website's TXT record before it is served. */
|
||||
export function websiteUnproved(r: DomainRedirect | null | undefined): boolean {
|
||||
return !!r && r.target_active === false && !!r.website?.record && !r.website.verified;
|
||||
}
|
||||
|
||||
export function redirectPill(d: SendingDomain): PillInfo {
|
||||
if (websiteUnproved(d.redirect)) {
|
||||
const site = d.redirect!.website!.domain;
|
||||
return { tone: "amber", label: "Confirm website", title: `Add the TXT record for ${site} to confirm the website is this workspace's.` };
|
||||
}
|
||||
if (d.redirect && d.redirect.target_active === false) {
|
||||
return {
|
||||
tone: "amber",
|
||||
|
||||
@@ -99,7 +99,8 @@ export default function SettingsPanel({
|
||||
<p className="text-[11px] text-slate-500 mt-1">
|
||||
Must be a page on one of your workspace's own domains: a domain you have a mailbox on (not
|
||||
gmail.com or another shared provider), your verified tracking domain, your verified forms
|
||||
domain, or a subdomain of one. Leave empty to show the success message instead.
|
||||
domain, a website confirmed under Sending domains, or a subdomain of one. Leave empty to show
|
||||
the success message instead.
|
||||
</p>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
@@ -4,6 +4,7 @@ import type {
|
||||
BulkDomainResult,
|
||||
BulkDomainSetupRequest,
|
||||
DomainRedirect,
|
||||
RedirectWebsite,
|
||||
SendingDomain,
|
||||
SetDomainRedirectRequest,
|
||||
SetDomainTrackingResult,
|
||||
@@ -48,6 +49,17 @@ export async function setDomainRedirect(domain: string, body: SetDomainRedirectR
|
||||
});
|
||||
}
|
||||
|
||||
// Looks for the TXT record that makes the destination's website the workspace's, now.
|
||||
export async function verifyRedirectWebsite(domain: string, targetUrl: string): Promise<RedirectWebsite> {
|
||||
return await Request<RedirectWebsite>({
|
||||
method: "POST",
|
||||
url: `${base(domain)}/redirect/website`,
|
||||
data: { target_url: targetUrl },
|
||||
authorization: true,
|
||||
timeout: 15_000,
|
||||
});
|
||||
}
|
||||
|
||||
// Checks DNS now instead of waiting for the background check.
|
||||
export async function verifyDomainRedirect(domain: string): Promise<DomainRedirect> {
|
||||
return await Request<DomainRedirect>({
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
setDomainVendorForwarding,
|
||||
setDomainVendorTracking,
|
||||
verifyDomainRedirect,
|
||||
verifyRedirectWebsite,
|
||||
} from "@/lib/api/client/app/emails/sendingDomains";
|
||||
import type {
|
||||
BulkDomainResult,
|
||||
@@ -101,6 +102,17 @@ export function useVerifyDomainRedirect() {
|
||||
});
|
||||
}
|
||||
|
||||
// A website that verifies changes which redirects are served, so the list is read again.
|
||||
export function useVerifyRedirectWebsite() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ domain, url }: { domain: string; url: string }) => verifyRedirectWebsite(domain, url),
|
||||
onSuccess: (w) => {
|
||||
if (w.verified) qc.invalidateQueries({ queryKey: SENDING_DOMAINS_KEY });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteDomainRedirect() {
|
||||
const qc = useQueryClient();
|
||||
const store = useStoreRedirect();
|
||||
|
||||
@@ -11,7 +11,7 @@ export interface TrackingDomainUse {
|
||||
mailboxes: number;
|
||||
}
|
||||
|
||||
export type DNSRecordPurpose = "ownership" | "root" | "www";
|
||||
export type DNSRecordPurpose = "ownership" | "root" | "www" | "website";
|
||||
|
||||
/** One record to add at the DNS provider, and whether it is in place. */
|
||||
export interface DNSRecord {
|
||||
@@ -62,6 +62,16 @@ export interface DomainRedirect {
|
||||
target_active?: boolean;
|
||||
/** Why the saved destination is not in use, when target_active is false. */
|
||||
target_inactive_reason?: string;
|
||||
/** Set when the destination is the workspace's only once its website carries the workspace's TXT record. */
|
||||
website?: RedirectWebsite | null;
|
||||
}
|
||||
|
||||
/** A destination website and the TXT record, at the website's own DNS, that proves it is the workspace's. */
|
||||
export interface RedirectWebsite {
|
||||
domain: string;
|
||||
verified: boolean;
|
||||
/** Absent when the website is already one of the workspace's domains. */
|
||||
record?: DNSRecord | null;
|
||||
}
|
||||
|
||||
export interface SendingDomain {
|
||||
|
||||
Reference in New Issue
Block a user