feat(mail-admin): read-only account view for mail.produktor.io (#74)
- admin/: Go stdlib-only HTTP viewer, lists accounts from config/postfix-accounts.cf with per-mailbox message counts (INBOX and total, same numbers doveadm reports) and storage; quota from dovecot-quotas.cf; Basic Auth from .env; offline tests vs fixtures (go test -race ./...) - compose: mail-admin service, build admin/Dockerfile, publishes 127.0.0.1:19945 / 172.17.0.1:19945; config and mail-data mounted :ro, no docker socket - NPM proxy host 66: location /admin/ -> 172.17.0.1:19945 - README: account admin section
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
// env returns the value of key or def when unset/empty.
|
||||
func env(key, def string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
// envRequired returns the value of key or exits: a missing credential must
|
||||
// fail loudly, never run with an open door.
|
||||
func envRequired(key string) string {
|
||||
v := os.Getenv(key)
|
||||
if v == "" {
|
||||
log.Fatalf("mail-admin: %s is required (set it in mail-server/.env)", key)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func main() {
|
||||
s := &server{
|
||||
accountsPath: envRequired("MAIL_ADMIN_ACCOUNTS"),
|
||||
quotaPath: envRequired("MAIL_ADMIN_QUOTAS"),
|
||||
maildirRoot: envRequired("MAIL_ADMIN_MAILDIR"),
|
||||
basePath: env("MAIL_ADMIN_BASE_PATH", ""),
|
||||
user: envRequired("MAIL_ADMIN_USER"),
|
||||
pass: envRequired("MAIL_ADMIN_PASSWORD"),
|
||||
}
|
||||
addr := env("MAIL_ADMIN_LISTEN", ":8080")
|
||||
log.Printf("mail-admin listening on %s, base path %q", addr, s.basePath)
|
||||
log.Fatal(http.ListenAndServe(addr, s.handler()))
|
||||
}
|
||||
Reference in New Issue
Block a user