2021-01-09 01:12:27 +01:00
|
|
|
{#-
|
|
|
|
which table are we setting up
|
|
|
|
-#}
|
2021-01-03 01:01:18 +01:00
|
|
|
use vmail;
|
2021-01-08 01:16:01 +01:00
|
|
|
{#-
|
|
|
|
setup mailserver domain
|
|
|
|
#}
|
2021-01-03 01:01:18 +01:00
|
|
|
insert into domains (domain) values ('{{ mailserver_domain }}');
|
2021-01-08 01:16:01 +01:00
|
|
|
{#-
|
|
|
|
create all mail users, domains and enter password hashes...
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE `accounts` (
|
|
|
|
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
|
|
|
`username` varchar(64) NOT NULL,
|
|
|
|
`domain` varchar(255) NOT NULL,
|
|
|
|
`password` varchar(255) NOT NULL,
|
|
|
|
`quota` int unsigned DEFAULT '0',
|
|
|
|
`enabled` boolean DEFAULT '0',
|
|
|
|
`sendonly` boolean DEFAULT '0',
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
UNIQUE KEY (`username`, `domain`),
|
|
|
|
FOREIGN KEY (`domain`) REFERENCES `domains` (`domain`)
|
|
|
|
);
|
|
|
|
|
2021-01-08 23:47:14 +01:00
|
|
|
mailserver__accounts:
|
|
|
|
- username: 'alice'
|
2021-01-08 01:16:01 +01:00
|
|
|
domain: 'example.com'
|
2021-01-09 01:12:27 +01:00
|
|
|
password_hash: # generate with $(doveadm pw -s SHA512-CRYPT)
|
|
|
|
# or $ python -c 'import crypt,getpass; print(crypt.crypt(getpass.getpass(), crypt.mksalt(crypt.METHOD_SHA512)))'
|
2021-01-08 01:16:01 +01:00
|
|
|
quota: '0'
|
|
|
|
enabled: true
|
|
|
|
sendonly: false
|
|
|
|
|
2021-01-08 23:47:14 +01:00
|
|
|
mailserver__alias:
|
2021-01-09 01:12:27 +01:00
|
|
|
- src_username: 'bob' # null for catchall
|
2021-01-08 23:47:14 +01:00
|
|
|
src_domain: 'example.com'
|
|
|
|
dest_username: 'alice'
|
|
|
|
dest_domain: 'example.com'
|
|
|
|
enabled: true
|
|
|
|
|
2021-01-08 01:16:01 +01:00
|
|
|
#}
|
|
|
|
{% for account in mailserver__accounts %}
|
2021-01-08 23:47:14 +01:00
|
|
|
{#
|
2021-01-09 01:41:21 +01:00
|
|
|
INSERT into accounts (username, domain, password, quota, enabled, sendonly) values ('{{ account["username"] }}', '{{ account["domain"] }}', '{{ account["password_hash"] }}', {{ account["quota"]|default(0) | int }}, {{ account["enabled"] | bool |ternary('true', 'false') }} , {{ account["sendonly"] | bool |ternary('true', 'false' }});
|
2021-01-08 23:47:14 +01:00
|
|
|
#}
|
|
|
|
REPLACE into accounts
|
|
|
|
(username, domain, password, quota, enabled, sendonly)
|
|
|
|
values
|
2021-01-09 01:41:21 +01:00
|
|
|
('{{ account["username"] }}', '{{ account["domain"] }}', '{{ account["password_hash"] }}', {{ account["quota"]|default(0) | int }}, {{ account["enabled"] | bool | ternary('true', 'false') }} , {{ account["sendonly"] | bool | ternary('true', 'false' )}});
|
2021-01-08 01:16:01 +01:00
|
|
|
{% endfor %}
|
|
|
|
{#-
|
|
|
|
create all mail aliases and stuff like that...
|
|
|
|
#}
|
2021-01-08 23:47:14 +01:00
|
|
|
{% for alias in mailserver__alias %}
|
|
|
|
{#
|
|
|
|
INSERT into aliases
|
|
|
|
(source_username, source_domain, destination_username, destination_domain, enabled)
|
|
|
|
values
|
2021-01-09 01:41:21 +01:00
|
|
|
('{{ alias["src_username"] }}', '{{ alias["src_domain"] }}', '{{ alias["dest_username"] }}', '{{ alias["dest_domain"] }}', {{ alias["enabled"] | bool | ternary('true', 'false') }});
|
2021-01-08 23:47:14 +01:00
|
|
|
#}
|
|
|
|
REPLACE into aliases
|
|
|
|
(source_username, source_domain, destination_username, destination_domain, enabled)
|
|
|
|
values
|
2021-01-09 01:12:27 +01:00
|
|
|
(
|
2021-01-09 01:41:21 +01:00
|
|
|
{%- if alias["src_username"] == 'null' -%}
|
2021-01-09 01:12:27 +01:00
|
|
|
null
|
|
|
|
{%- else -%}
|
|
|
|
'{{ alias["src_username"] }}'
|
|
|
|
{%- endif -%}
|
2021-01-09 01:41:21 +01:00
|
|
|
, '{{ alias["src_domain"] }}', '{{ alias["dest_username"] }}', '{{ alias["dest_domain"] }}', {{ alias["enabled"] | bool | ternary('true', 'false') }});
|
2021-01-08 23:47:14 +01:00
|
|
|
{% endfor %}
|