diff --git a/README.md b/README.md index 0c7cf1d..b4c182f 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,14 @@ This repository holds the ISPmail guide as found on workaround.org. It was built using the static site generator [Starlight](https://starlight.astro.build). More information on how to contribute will follow. + +# Software used + +Static site generator: https://starlight.astro.build/ + +Diagrams/Illustrations: + +- DrawIO +- https://github.com/pascal-brand38/astro-splide +- https://pascal-brand38.github.io/astro-dev/packages/astro-splide/ +- https://splidejs.com/guides/options/ diff --git a/src/content/docs/ispmail-trixie/140-install-packages.md b/src/content/docs/ispmail-trixie/140-install-packages.md index 858688b..20052d2 100644 --- a/src/content/docs/ispmail-trixie/140-install-packages.md +++ b/src/content/docs/ispmail-trixie/140-install-packages.md @@ -20,7 +20,8 @@ DEBIAN_FRONTEND=noninteractive \ While the server is downloading and installing the packages, let me give you a quick explanation of each package: - postfix-sqlite \ - Postfix is the MTA (mail transport agent) that speaks SMTP to send and receive emails. This package installs Postfix with support for SQLite databases. + Postfix is the MTA (mail transport agent) that speaks SMTP to send and receive emails. This package installs Postfix + with support for SQLite databases. - dovecot \ Dovecot manages the emsrc/content/docs/ispmail-trixie/140-install-packages.mdx emails using IMAP. - -lmtpd \ @@ -52,3 +53,5 @@ While the server is downloading and installing the packages, let me give you a q Installs security updates automatically. TODO: move crowdsec into optional chapter + +TODO: postfix in no-chroot mode diff --git a/src/content/docs/ispmail-trixie/155-sqlite.mdx b/src/content/docs/ispmail-trixie/155-sqlite.mdx index 1318218..fb55a09 100644 --- a/src/content/docs/ispmail-trixie/155-sqlite.mdx +++ b/src/content/docs/ispmail-trixie/155-sqlite.mdx @@ -19,3 +19,82 @@ non-existent users. That information will be put into an SQLite database file th to set up, fast, and ideal for small projects. +The database will contain three tables: + +- virtual*domains: list of domains (\_name*) that your mail server is responsible for +- virtual_users: list of email addresses that lead to mailboxes. We store the email address, a hashed/salted password + and optionally a quota to limit the disk space usage. +- virtual*aliases: list of email addresses (\_source*) that forward to other addresses (_destination_) + +Creating and accessing the database is done using the _sqlite3_ command. The "3" is because SQLite has some breaking +changes in the past and _sqlite3_ is used to make it clear that this only works for version 3 database files. + +On your server run: + +```sh +sqlite3 /var/vmail/ispmail.sqlite +``` + +The database file is created and you will be greeted with: + +``` +SQLite version 3.46.1 2024-08-13 09:16:08 +Enter ".help" for usage hints. +sqlite> +``` + +At this point you can run SQL queries or use special commands that start with a dot like ".dump" or ".schema". Paste +this SQL block to create the necessary tables: + +```sql +CREATE TABLE IF NOT EXISTS virtual_domains ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL +); + +CREATE TABLE IF NOT EXISTS virtual_users ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + domain_id INTEGER NOT NULL, + email TEXT NOT NULL UNIQUE, + password TEXT NOT NULL, + quota INTEGER NOT NULL DEFAULT 0, + FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS virtual_aliases ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + domain_id INTEGER NOT NULL, + source TEXT NOT NULL, + destination TEXT NOT NULL, + FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE +); +``` + +You have now created the schema. It defines the _fields_ (or _columns_) of each row. + +Graphically it looks like: + +![ISPmail database schema](images/sqlite-schema.png) + +Paste the following block to create some test data to play with: + +```sql +REPLACE INTO virtual_domains (id, name) +VALUES (1, 'example.org'); + +REPLACE INTO virtual_users (id, domain_id, password, email) +VALUES ( + 1, + 1, + '{BLF-CRYPT}$2y$05$.WedBCNZiwxY1CG3aleIleu6lYjup2CIg0BP4M4YCZsO204Czz07W', + 'john@example.org' +); + +REPLACE INTO virtual_aliases (id, domain_id, source, destination) +VALUES ( + 1, + 1, + 'jack@example.org', + 'john@example.org' +); +``` diff --git a/src/content/docs/ispmail-trixie/images/sqlite-schema.png b/src/content/docs/ispmail-trixie/images/sqlite-schema.png new file mode 100644 index 0000000..9075fb9 Binary files /dev/null and b/src/content/docs/ispmail-trixie/images/sqlite-schema.png differ