http

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2023 License: MIT Imports: 70 Imported by: 1

Documentation

Overview

Package http provides HTTP listeners/servers, for autoconfiguration/autodiscovery, the account and admin web interface and MTA-STS policies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleForward added in v0.0.2

func HandleForward(h *config.WebForward, w http.ResponseWriter, r *http.Request, path string) (handled bool)

HandleForward handles a request by forwarding it to another webserver and passing the response on. I.e. a reverse proxy. It handles websocket connections by monitoring the websocket handshake and then just passing along the websocket frames.

func HandleRedirect added in v0.0.2

func HandleRedirect(h *config.WebRedirect, w http.ResponseWriter, r *http.Request) (handled bool)

HandleRedirect writes a response with an HTTP redirect.

func HandleStatic added in v0.0.2

func HandleStatic(h *config.WebStatic, w http.ResponseWriter, r *http.Request) (handled bool)

HandleStatic serves static files. If a directory is requested and the URL path doesn't end with a slash, a response with a redirect to the URL path with trailing slash is written. If a directory is requested and an index.html exists, that file is returned. Otherwise, for directories with ListFiles configured, a directory listing is returned.

func Listen added in v0.0.2

func Listen()

Listen binds to sockets for HTTP listeners, including those required for ACME to generate TLS certificates. It stores the listeners so Serve can start serving them.

func Serve added in v0.0.2

func Serve()

Serve starts serving on the initialized listeners.

func WebHandle added in v0.0.2

func WebHandle(w *loggingWriter, r *http.Request, host dns.Domain) (handled bool)

WebHandle serves an HTTP request by going through the list of WebHandlers, check if there is a domain+path match, and running the handler if so. WebHandle runs after the built-in handlers for mta-sts, autoconfig, etc. If no handler matched, false is returned. WebHandle sets w.Name to that of the matching handler.

Types

type Account

type Account struct{}

Account exports web API functions for the account web interface. All its methods are exported under api/. Function calls require valid HTTP Authentication credentials of a user.

func (Account) DestinationSave

func (Account) DestinationSave(ctx context.Context, destName string, oldDest, newDest config.Destination)

DestinationSave updates a destination. OldDest is compared against the current destination. If it does not match, an error is returned. Otherwise newDest is saved and the configuration reloaded.

func (Account) Destinations

func (Account) Destinations(ctx context.Context) (dns.Domain, map[string]config.Destination)

Destinations returns the default domain, and the destinations (keys are email addresses, or localparts to the default domain). todo: replace with a function that returns the whole account, when sherpadoc understands unnamed struct fields.

func (Account) ImportAbort

func (Account) ImportAbort(ctx context.Context, importToken string) error

ImportAbort aborts an import that is in progress. If the import exists and isn't finished, no changes will have been made by the import.

func (Account) SetPassword

func (Account) SetPassword(ctx context.Context, password string)

SetPassword saves a new password for the account, invalidating the previous password. Sessions are not interrupted, and will keep working. New login attempts must use the new password. Password must be at least 8 characters.

type Admin

type Admin struct{}

Admin exports web API functions for the admin web interface. All its methods are exported under api/. Function calls require valid HTTP Authentication credentials of a user.

func (Admin) Account

func (Admin) Account(ctx context.Context, account string) map[string]any

Account returns the parsed configuration of an account.

func (Admin) AccountAdd

func (Admin) AccountAdd(ctx context.Context, accountName, address string)

AccountAdd adds existing a new account, with an initial email address, and reloads the configuration.

func (Admin) AccountRemove

func (Admin) AccountRemove(ctx context.Context, accountName string)

AccountRemove removes an existing account and reloads the configuration.

func (Admin) Accounts

func (Admin) Accounts(ctx context.Context) []string

Accounts returns the names of all configured accounts.

func (Admin) AddressAdd

func (Admin) AddressAdd(ctx context.Context, address, accountName string)

AddressAdd adds a new address to the account, which must already exist.

func (Admin) AddressRemove

func (Admin) AddressRemove(ctx context.Context, address string)

AddressRemove removes an existing address.

func (Admin) CheckDomain

func (Admin) CheckDomain(ctx context.Context, domainName string) (r CheckResult)

CheckDomain checks the configuration for the domain, such as MX, SMTP STARTTLS, SPF, DKIM, DMARC, TLSRPT, MTASTS, autoconfig, autodiscover.

func (Admin) CheckUpdatesEnabled added in v0.0.2

func (Admin) CheckUpdatesEnabled(ctx context.Context) bool

CheckUpdatesEnabled returns whether checking for updates is enabled.

func (Admin) ClientConfigDomain

func (Admin) ClientConfigDomain(ctx context.Context, domain string) mox.ClientConfig

ClientConfigDomain returns configurations for email clients, IMAP and Submission (SMTP) for the domain.

func (Admin) ConfigFiles

func (Admin) ConfigFiles(ctx context.Context) (staticPath, dynamicPath, static, dynamic string)

ConfigFiles returns the paths and contents of the static and dynamic configuration files.

func (Admin) DMARCReportID

func (Admin) DMARCReportID(ctx context.Context, domain string, reportID int64) (report dmarcdb.DomainFeedback)

DMARCReportID returns a single DMARC report.

func (Admin) DMARCReports

func (Admin) DMARCReports(ctx context.Context, start, end time.Time, domain string) (reports []dmarcdb.DomainFeedback)

DMARCReports returns DMARC reports overlapping with period start/end, for the given domain (or all domains if empty). The reports are sorted first by period end (most recent first), then by domain.

func (Admin) DMARCSummaries

func (Admin) DMARCSummaries(ctx context.Context, start, end time.Time, domain string) (domainSummaries []DMARCSummary)

DMARCSummaries returns a summary of received DMARC reports overlapping with period start/end for one or all domains (when domain is empty). The returned summaries are ordered by domain name.

func (Admin) DNSBLStatus

func (Admin) DNSBLStatus(ctx context.Context) map[string]map[string]string

DNSBLStatus returns the IPs from which outgoing connections may be made and their current status in DNSBLs that are configured. The IPs are typically the configured listen IPs, or otherwise IPs on the machines network interfaces, with internal/private IPs removed.

The returned value maps IPs to per DNSBL statuses, where "pass" means not listed and anything else is an error string, e.g. "fail: ..." or "temperror: ...".

func (Admin) Domain

func (Admin) Domain(ctx context.Context, domain string) dns.Domain

Domain returns the dns domain for a (potentially unicode as IDNA) domain name.

func (Admin) DomainAdd

func (Admin) DomainAdd(ctx context.Context, domain, accountName, localpart string)

DomainAdd adds a new domain and reloads the configuration.

func (Admin) DomainLocalparts

func (Admin) DomainLocalparts(ctx context.Context, domain string) (localpartAccounts map[string]string)

DomainLocalparts returns the encoded localparts and accounts configured in domain.

func (Admin) DomainRecords

func (Admin) DomainRecords(ctx context.Context, domain string) []string

DomainRecords returns lines describing DNS records that should exist for the configured domain.

func (Admin) DomainRemove

func (Admin) DomainRemove(ctx context.Context, domain string)

DomainRemove removes an existing domain and reloads the configuration.

func (Admin) Domains

func (Admin) Domains(ctx context.Context) []dns.Domain

Domains returns all configured domain names, in UTF-8 for IDNA domains.

func (Admin) LogLevelRemove

func (Admin) LogLevelRemove(ctx context.Context, pkg string)

LogLevelRemove removes a log level for a package, which cannot be the empty string.

func (Admin) LogLevelSet

func (Admin) LogLevelSet(ctx context.Context, pkg string, levelStr string)

LogLevelSet sets a log level for a package.

func (Admin) LogLevels

func (Admin) LogLevels(ctx context.Context) map[string]string

LogLevels returns the current log levels.

func (Admin) LookupIP

func (Admin) LookupIP(ctx context.Context, ip string) Reverse

LookupIP does a reverse lookup of ip.

func (Admin) MTASTSPolicies

func (Admin) MTASTSPolicies(ctx context.Context) (records []mtastsdb.PolicyRecord)

MTASTSPolicies returns all mtasts policies from the cache.

func (Admin) QueueDrop

func (Admin) QueueDrop(ctx context.Context, id int64)

QueueDrop removes a message from the queue.

func (Admin) QueueKick

func (Admin) QueueKick(ctx context.Context, id int64)

QueueKick initiates delivery of a message from the queue.

func (Admin) QueueList

func (Admin) QueueList(ctx context.Context) []queue.Msg

QueueList returns the messages currently in the outgoing queue.

func (Admin) QueueSize

func (Admin) QueueSize(ctx context.Context) int

QueueSize returns the number of messages currently in the outgoing queue.

func (Admin) SetAccountLimits added in v0.0.3

func (Admin) SetAccountLimits(ctx context.Context, accountName string, maxOutgoingMessagesPerDay, maxFirstTimeRecipientsPerDay int)

SetAccountLimits set new limits on outgoing messages for an account.

func (Admin) SetPassword

func (Admin) SetPassword(ctx context.Context, accountName, password string)

SetPassword saves a new password for an account, invalidating the previous password. Sessions are not interrupted, and will keep working. New login attempts must use the new password. Password must be at least 8 characters.

func (Admin) TLSRPTSummaries

func (Admin) TLSRPTSummaries(ctx context.Context, start, end time.Time, domain string) (domainSummaries []TLSRPTSummary)

TLSRPTSummaries returns a summary of received TLS reports overlapping with period start/end for one or all domains (when domain is empty). The returned summaries are ordered by domain name.

func (Admin) TLSReportID

func (Admin) TLSReportID(ctx context.Context, domain string, reportID int64) tlsrptdb.TLSReportRecord

TLSReportID returns a single TLS report.

func (Admin) TLSReports

func (Admin) TLSReports(ctx context.Context, start, end time.Time, domain string) (reports []tlsrptdb.TLSReportRecord)

TLSReports returns TLS reports overlapping with period start/end, for the given domain (or all domains if empty). The reports are sorted first by period end (most recent first), then by domain.

func (Admin) WebserverConfig added in v0.0.2

func (Admin) WebserverConfig(ctx context.Context) (conf WebserverConfig)

WebserverConfig returns the current webserver config

func (Admin) WebserverConfigSave added in v0.0.2

func (Admin) WebserverConfigSave(ctx context.Context, oldConf, newConf WebserverConfig) (savedConf WebserverConfig)

WebserverConfigSave saves a new webserver config. If oldConf is not equal to the current config, an error is returned.

type AutoconfCheckResult

type AutoconfCheckResult struct {
	IPs []string
	Result
}

type AutodiscoverCheckResult

type AutodiscoverCheckResult struct {
	Records []AutodiscoverSRV
	Result
}

type AutodiscoverSRV

type AutodiscoverSRV struct {
	net.SRV
	IPs []string
}

type CheckResult

CheckResult is the analysis of a domain, its actual configuration (DNS, TLS, connectivity) and the mox configuration. It includes configuration instructions (e.g. DNS records), and warnings and errors encountered.

type DKIMCheckResult

type DKIMCheckResult struct {
	Records []DKIMRecord
	Result
}

type DKIMRecord

type DKIMRecord struct {
	Selector string
	TXT      string
	Record   *dkim.Record
}

type DMARCCheckResult

type DMARCCheckResult struct {
	Domain string
	TXT    string
	Record *DMARCRecord
	Result
}

type DMARCRecord

type DMARCRecord struct {
	dmarc.Record
}

type DMARCSummary

type DMARCSummary struct {
	Domain                string
	Total                 int
	DispositionNone       int
	DispositionQuarantine int
	DispositionReject     int
	DKIMFail              int
	SPFFail               int
	PolicyOverrides       map[dmarcrpt.PolicyOverride]int
}

DMARCSummary presents DMARC aggregate reporting statistics for a single domain over a period.

type IPRevCheckResult

type IPRevCheckResult struct {
	Hostname dns.Domain          // This hostname, IPs must resolve back to this.
	IPNames  map[string][]string // IP to names.
	Result
}

type MTASTSCheckResult

type MTASTSCheckResult struct {
	CNAMEs     []string
	TXT        string
	Record     *MTASTSRecord
	PolicyText string
	Policy     *mtasts.Policy
	Result
}

type MTASTSRecord

type MTASTSRecord struct {
	mtasts.Record
}

type MX

type MX struct {
	Host string
	Pref int
	IPs  []string
}

type MXCheckResult

type MXCheckResult struct {
	Records []MX
	Result
}

type Result

type Result struct {
	Errors       []string
	Warnings     []string
	Instructions []string
}

type Reverse

type Reverse struct {
	Hostnames []string
}

Reverse is the result of a reverse lookup.

type SPFCheckResult

type SPFCheckResult struct {
	DomainTXT    string
	DomainRecord *SPFRecord
	HostTXT      string
	HostRecord   *SPFRecord
	Result
}

type SPFRecord

type SPFRecord struct {
	spf.Record
}

type SRVConfCheckResult

type SRVConfCheckResult struct {
	SRVs map[string][]*net.SRV // Service (e.g. "_imaps") to records.
	Result
}

type TLSCheckResult

type TLSCheckResult struct {
	Result
}

type TLSRPTCheckResult

type TLSRPTCheckResult struct {
	TXT    string
	Record *TLSRPTRecord
	Result
}

type TLSRPTRecord

type TLSRPTRecord struct {
	tlsrpt.Record
}

type TLSRPTSummary

type TLSRPTSummary struct {
	Domain           string
	Success          int64
	Failure          int64
	ResultTypeCounts map[tlsrpt.ResultType]int
}

TLSRPTSummary presents TLS reporting statistics for a single domain over a period.

type WebserverConfig added in v0.0.2

type WebserverConfig struct {
	WebDNSDomainRedirects [][2]dns.Domain // From server to frontend.
	WebDomainRedirects    [][2]string     // From frontend to server, it's not convenient to create dns.Domain in the frontend.
	WebHandlers           []config.WebHandler
}

WebserverConfig is the combination of WebDomainRedirects and WebHandlers from the domains.conf configuration file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL