mirror of
https://github.com/directorz/mailfull-go.git
synced 2025-12-17 17:47:04 +00:00
Implement to generate configuration for postfix/dovecot #6
This commit is contained in:
140
generateconfig.go
Normal file
140
generateconfig.go
Normal file
@@ -0,0 +1,140 @@
|
||||
package mailfull
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GenerateConfigPostfix generate a configuration for Postfix.
|
||||
func (r *Repository) GenerateConfigPostfix() string {
|
||||
cfg := fmt.Sprintf(`
|
||||
#
|
||||
# Sample configuration: main.cf
|
||||
# Generated by mailfull %s on %s
|
||||
#
|
||||
|
||||
#myhostname = host.example.com
|
||||
mydomain = $myhostname
|
||||
myorigin = $mydomain
|
||||
|
||||
inet_interfaces = all
|
||||
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
|
||||
mynetworks_style = host
|
||||
recipient_delimiter = -
|
||||
message_size_limit = 10240000
|
||||
mailbox_size_limit = 51200000
|
||||
virtual_mailbox_limit = 51200000
|
||||
|
||||
virtual_mailbox_domains = hash:%s
|
||||
virtual_mailbox_base = %s
|
||||
virtual_mailbox_maps = hash:%s
|
||||
virtual_uid_maps = static:%d
|
||||
virtual_gid_maps = static:%d
|
||||
virtual_alias_maps = hash:%s
|
||||
transport_maps = regexp:%s
|
||||
alias_maps = hash:/etc/aliases, hash:%s
|
||||
alias_database = hash:/etc/aliases, hash:%s
|
||||
|
||||
smtpd_sasl_auth_enable = yes
|
||||
smtpd_sasl_local_domain = $myhostname
|
||||
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
|
||||
smtpd_sasl_type = dovecot
|
||||
smtpd_sasl_path = private/auth
|
||||
|
||||
smtpd_tls_cert_file = /etc/pki/dovecot/certs/dovecot.pem
|
||||
smtpd_tls_key_file = /etc/pki/dovecot/private/dovecot.pem
|
||||
#smtpd_tls_CAfile =
|
||||
smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache
|
||||
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3
|
||||
|
||||
smtp_tls_security_level = may
|
||||
smtp_tls_loglevel = 1
|
||||
smtpd_tls_security_level = may
|
||||
smtpd_tls_loglevel = 1
|
||||
`,
|
||||
Version, time.Now().Format(time.RFC3339),
|
||||
filepath.Join(r.DirDatabasePath, FileNameDbDomains),
|
||||
r.DirMailDataPath,
|
||||
filepath.Join(r.DirDatabasePath, FileNameDbMaildirs),
|
||||
r.uid,
|
||||
r.gid,
|
||||
filepath.Join(r.DirDatabasePath, FileNameDbDestinations),
|
||||
filepath.Join(r.DirDatabasePath, FileNameDbLocaltable),
|
||||
filepath.Join(r.DirDatabasePath, FileNameDbForwards),
|
||||
filepath.Join(r.DirDatabasePath, FileNameDbForwards),
|
||||
)
|
||||
|
||||
return cfg[1:]
|
||||
}
|
||||
|
||||
// GenerateConfigDovecot generate a configuration for Dovecot.
|
||||
func (r *Repository) GenerateConfigDovecot() string {
|
||||
cfg := fmt.Sprintf(`
|
||||
#
|
||||
# Sample configuration: dovecot.conf
|
||||
# Generated by mailfull %s on %s
|
||||
#
|
||||
|
||||
protocols = imap pop3
|
||||
auth_mechanisms = plain login
|
||||
mail_location = maildir:~/Maildir
|
||||
|
||||
ssl = yes
|
||||
ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
|
||||
ssl_key = </etc/pki/dovecot/private/dovecot.pem
|
||||
#ssl_ca =
|
||||
|
||||
disable_plaintext_auth = yes
|
||||
|
||||
service imap-login {
|
||||
inet_listener imap {
|
||||
port = 143
|
||||
}
|
||||
inet_listener imaps {
|
||||
port = 993
|
||||
ssl = yes
|
||||
}
|
||||
}
|
||||
|
||||
service pop3-login {
|
||||
inet_listener pop3 {
|
||||
port = 110
|
||||
}
|
||||
inet_listener pop3s {
|
||||
port = 995
|
||||
ssl = yes
|
||||
}
|
||||
}
|
||||
|
||||
service auth {
|
||||
unix_listener /var/spool/postfix/private/auth {
|
||||
mode = 0666
|
||||
user = postfix
|
||||
group = postfix
|
||||
}
|
||||
}
|
||||
|
||||
passdb {
|
||||
driver = passwd-file
|
||||
args = %s
|
||||
}
|
||||
userdb {
|
||||
driver = static
|
||||
args = uid=%d gid=%d home=%s/%%d/%%n
|
||||
}
|
||||
|
||||
passdb {
|
||||
driver = pam
|
||||
}
|
||||
userdb {
|
||||
driver = passwd
|
||||
}
|
||||
`,
|
||||
Version, time.Now().Format(time.RFC3339),
|
||||
filepath.Join(r.DirDatabasePath, FileNameDbPasswords),
|
||||
r.uid, r.gid, r.DirMailDataPath,
|
||||
)
|
||||
|
||||
return cfg[1:]
|
||||
}
|
||||
Reference in New Issue
Block a user