wmdeit-cf-wmdelib/mailserver.cf

191 lines
3.6 KiB
CFEngine3
Raw Normal View History

2023-10-31 19:42:18 +00:00
#
#
#
bundle agent install_mailserver(param_cfg)
{
vars:
"default_cfg" data => '{
"pam_auth":true,
"vimb_auth":false,
"imap":true,
"submission":true,
"smtp":true,
"pop3":false,
"sieve":false,
"ssl":false,
"opendkim":false,
"myhostname":"$(sys.host)",
"myorigin":"$myhostname",
"mydestination":"$myhostname, localhost",
"mail_location" : "maildir:~/Maildir:LAYOUT=maildir++:INBOX=~/Maildir/.INBOX:CONTROL=~/Mail/control:INDEX=~/Mail/index",
"vmail_location" : "maildir:~/Maildir:LAYOUT=maildir++:INBOX=~/Maildir/.INBOX:CONTROL=~/Mail/control:INDEX=~/Mail/index",
}';
"cfg" data => mergedata(@(default_cfg),@(param_cfg));
"dovecot_protos" string => string_mustache (
'"lmtp"{{#cfg.imap}},"imap"{{/cfg.imap}}{{#cfg.pop3}},"pop3"{{/cfg.pop3}}{{#cfg.sieve}},"sieve"{{/cfg.sieve}}',
bundlestate("$(this.bundle)")
);
"imaps_port" string => ifelse(strcmp("$(cfg[ssl])","true"),"993","0");
"pop3s_port" string => ifelse(strcmp("$(cfg[ssl])","true"),"995","0");
"dbs" string => string_mustache('
"userdbs":[
2023-11-03 19:11:18 +00:00
{{#fg.vimb_auth}}
{
"driver":"sql",
"args":"$(dovecot_vimbadmin_sql.cfg_file)"
},
{{/cfg.vimb_auth}}
2023-10-31 19:42:18 +00:00
{{#cfg.pam_auth}}
{
"driver":"passwd",
"args":""
},
{{/cfg.pam_auth}}
2023-11-03 19:11:18 +00:00
],
"passdbs":[
{{#cfg.vimb_auth}}
2023-10-31 19:42:18 +00:00
{
"driver":"sql",
"args":"$(dovecot_vimbadmin_sql.cfg_file)"
2023-11-03 19:11:18 +00:00
} ,
2023-10-31 19:42:18 +00:00
{{/cfg.vimb_auth}}
{{#cfg.pam_auth}}
{
"driver":"pam",
"args":"dovecot"
},
{{/cfg.pam_auth}}
],',
bundlestate("$(this.bundle)"));
"dovecot_cfg" data => '{
"protocols":[$(dovecot_protos)],
"ssl":$(cfg[ssl]),
$(dbs)
"services":{
"imap-login":{
"raw":"
inet_listener imap {
port = 143
}
inet_listener imaps {
port = $(imaps_port)
ssl = yes
}
"
}
,
"pop3-login":{
"raw":"
inet_listener pop3 {
port = 110
}
inet_listener pop3s {
port = $(pop3s_port)
ssl = yes
}
"
}
,
"auth":{
"raw":"
unix_listener $(postfix.queue_dir)/private/auth {
user = postfix
group = postfix
mode = 0666
}
"
}
,
"lmtp":{
"raw":"
unix_listener $(postfix.queue_dir)/private/dovecot-lmtp {
group = postfix
mode = 0600
user = postfix
}
"
}
}
}';
"postfix_cfg" data => '{
"non_smtpd_milters":[
"unix:$(postfix.queue_dir)/private/opendkim"
]
,
"services" : [
{
"name":"submission"
"comment": "Submission service"
"enable":$(cfg[submission]),
"type":"inet",
"private":"n",
"unpriv":"-",
"chroot":"n",
"wakeup":"-",
"maxproc":"-",
"command":"smtpd",
"args":[
"{ -o smtpd_sender_restrictions = permit_sasl_authenticated reject }",
],
}
,
{
"name":"smtp",
"comment": "SMTP service",
"enable":$(cfg[smtp]),
"type":"inet",
"private":"n",
"unpriv":"-",
"chroot":"n",
"wakeup":"-",
"maxproc":"-",
"command":"smtpd",
"args":[
"{ -o smtpd_recipient_restrictions = permit_mynetworks reject_unauth_destination }"
"{ -o smtpd_client_restrictions = permit_mynetworks reject }",
"{ -o smtpd_relay_restrictions = permit_mynetworks reject }",
"{ -o smtpd_sender_restrictions = permit_mynetworks }"
]
}
]
,
"main_raw":"
myhostname=$(cfg[myhostname])
mydestination=$(cfg[mydestination])
myorigin=$(cfg[myorigin])
"
,
"master_raw":""
}
';
methods:
"any" usebundle => install_postfix_pkgs;
"any" usebundle => install_dovecot_pkgs;
"any" usebundle => dovecot(@(dovecot_cfg));
"any" usebundle => postfix(@(postfix_cfg));
reports:
2023-11-03 19:11:18 +00:00
# "DCP: $(dovecot_protos)";
# "DBS: $(dbs)";
2023-10-31 19:42:18 +00:00
}