sqlite page started
This commit is contained in:
parent
5eaa855d64
commit
3b0f26211a
4 changed files with 94 additions and 1 deletions
11
README.md
11
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).
|
It was built using the static site generator [Starlight](https://starlight.astro.build).
|
||||||
|
|
||||||
More information on how to contribute will follow.
|
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/
|
||||||
|
|
|
||||||
|
|
@ -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:
|
While the server is downloading and installing the packages, let me give you a quick explanation of each package:
|
||||||
|
|
||||||
- postfix-sqlite \
|
- 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 \
|
||||||
Dovecot manages the emsrc/content/docs/ispmail-trixie/140-install-packages.mdx emails using IMAP.
|
Dovecot manages the emsrc/content/docs/ispmail-trixie/140-install-packages.mdx emails using IMAP.
|
||||||
- -lmtpd \
|
- -lmtpd \
|
||||||
|
|
@ -52,3 +53,5 @@ While the server is downloading and installing the packages, let me give you a q
|
||||||
Installs security updates automatically.
|
Installs security updates automatically.
|
||||||
|
|
||||||
TODO: move crowdsec into optional chapter
|
TODO: move crowdsec into optional chapter
|
||||||
|
|
||||||
|
TODO: postfix in no-chroot mode
|
||||||
|
|
|
||||||
|
|
@ -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.
|
to set up, fast, and ideal for small projects.
|
||||||
</Aside>
|
</Aside>
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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'
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
|
||||||
BIN
src/content/docs/ispmail-trixie/images/sqlite-schema.png
Normal file
BIN
src/content/docs/ispmail-trixie/images/sqlite-schema.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Loading…
Add table
Add a link
Reference in a new issue