From 7471c24a220fdaaf375125cd881831f9d5c1aa99 Mon Sep 17 00:00:00 2001 From: Louis Guidez Date: Wed, 28 Feb 2024 15:13:13 +0000 Subject: [PATCH] compile utility in a container, statically, to use in maddy container --- Containerfile | 21 ++++++++ Makefile | 2 +- README.md | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- 4 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 Containerfile create mode 100644 README.md diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..b5cda83 --- /dev/null +++ b/Containerfile @@ -0,0 +1,21 @@ +FROM golang:1.19-alpine AS build-env + +# Required for mattn/go-sqlite3 +ENV CGO_ENABLED=1 + +RUN set -ex && \ + apk upgrade --no-cache --available && \ + apk add --no-cache build-base gcc musl-dev + +WORKDIR /maddy-hostux-check-password + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . ./ + +RUN make + +FROM foxcpp/maddy:0.6 + +COPY --from=build-env /maddy-hostux-check-password/build/maddy-hostux-check-password /bin/maddy-hostux-check-password \ No newline at end of file diff --git a/Makefile b/Makefile index ed35b99..2130eeb 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ BUILD_DIR := ./build GO := go # Flags for go build -BUILD_FLAGS := -o $(BUILD_DIR)/$(APP_NAME) +BUILD_FLAGS := -o $(BUILD_DIR)/$(APP_NAME) -tags netgo -ldflags "-s -w -extldflags '-static'" .PHONY: all build clean diff --git a/README.md b/README.md new file mode 100644 index 0000000..26bdd1d --- /dev/null +++ b/README.md @@ -0,0 +1,134 @@ +# Password Check Utility for Maddy + +Features: +* Authenticates email accounts against the SQLite database used by Hostux panel +* Updates "last accessed" on a successful authentication + +## Testing + +### Maddy + +Build the image: +```bash +docker build -f Containerfile -t hostux/maddy:latest . +``` + +For `maddy.conf`: +```conf +$(hostname) = {env:MADDY_HOSTNAME} +$(primary_domain) = {env:MADDY_DOMAIN} +$(local_domains) = $(primary_domain) + +tls off + +auth.external hostux_auth { + helper /bin/checkpw + perdomain yes + domains $(local_domains) +} + +storage.imapsql local_mailboxes { + driver sqlite3 + dsn imapsql.db +} + +hostname $(hostname) + +table.chain local_rewrites { + optional_step regexp "(.+)\+(.+)@(.+)" "$1@$3" + optional_step static { + entry postmaster postmaster@$(primary_domain) + } + optional_step file /etc/maddy/aliases +} + +msgpipeline local_routing { + destination postmaster $(local_domains) { + modify { + replace_rcpt &local_rewrites + } + + deliver_to &local_mailboxes + } + + default_destination { + reject 550 5.1.1 "User doesn't exist" + } +} + +smtp tcp://0.0.0.0:25 { + limits { + all rate 20 1s + all concurrency 10 + } + + dmarc yes + check { + require_mx_record + dkim + spf + } + + source $(local_domains) { + reject 501 5.1.8 "Use Submission for outgoing SMTP" + } + default_source { + destination postmaster $(local_domains) { + deliver_to &local_routing + } + default_destination { + reject 550 5.1.1 "User doesn't exist" + } + } +} + +imap tcp://0.0.0.0:143 { + auth &hostux_auth + storage &local_mailboxes +} +``` + +```bash +docker volume create maddydata +docker network create maddy-test + +docker run --rm \ + --name maddy \ + -e MADDY_HOSTNAME=mx.maddy.test \ + -e MADDY_DOMAIN=maddy.test \ + -e HOSTUX_EMAIL_DATABASE_SQLITE=/email.sqlite \ + -v maddydata:/data \ + -v ~/maddy-hostux-check-password/email.sqlite:/email.sqlite \ + -p 143:143 \ + hostux/maddy:latest + +docker run --rm -it -v maddydata:/data --entrypoint ash foxcpp/maddy:0.6 +``` + +### CLI Imap Client + +```bash +pip install imap-cli +export PATH="$PATH:/home/louis_guidez76/.local/bin" +``` + +In `~/.config/imap-cli`: +```ini +[imap] +hostname = localhost +username = louis@hostux.fr +password = ... +ssl = False + +[display] +format_list = + ID: {mail_id} + Flags: {flags} + From: {from} + To: {to} + Date: {date} + Subject: {subject} +format_thread = {uid} {subject} <<< FROM {from} +format_status = {directory:>20} : {count:>5} Mails - {unseen:>5} Unseen - {recent:>5} Recent +limit = 10 +``` \ No newline at end of file diff --git a/go.mod b/go.mod index 58a1c0a..6dbfad0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module main -go 1.21.6 +go 1.21 require ( github.com/mattn/go-sqlite3 v1.14.22