init: projet complet copymail pour Raspberry Pi
Stack: Nginx + PHP 8.2 + MariaDB + Postfix + Dovecot + Samba - install.sh: script installation automatisé pour RPi OS Bookworm - Interface web: visionneuse mails + admin (comptes, domaine, dashboard) - Chaque compte mail génère automatiquement un share Samba - Processeur cron: extraction pièces jointes via zbateson/mail-mime-parser - Zéro injection SQL (PDO + prepared statements) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
126
scripts/apply_config.sh
Normal file
126
scripts/apply_config.sh
Normal file
@@ -0,0 +1,126 @@
|
||||
#!/bin/bash
|
||||
# apply_config.sh
|
||||
# Régénère les configs Postfix/Dovecot/Samba depuis les valeurs en BDD et recharge les services
|
||||
|
||||
set -e
|
||||
|
||||
PHP=/usr/bin/php
|
||||
|
||||
# Récupère les valeurs depuis la BDD via PHP
|
||||
DOMAIN=$($PHP -r "require '/opt/copymail/web/includes/db.php'; echo cfg('domain');")
|
||||
HOSTNAME=$($PHP -r "require '/opt/copymail/web/includes/db.php'; echo cfg('hostname');")
|
||||
SMTP_PORT=$($PHP -r "require '/opt/copymail/web/includes/db.php'; echo cfg('smtp_port');")
|
||||
SUBM_PORT=$($PHP -r "require '/opt/copymail/web/includes/db.php'; echo cfg('submission_port');")
|
||||
IMAP_PORT=$($PHP -r "require '/opt/copymail/web/includes/db.php'; echo cfg('imap_port');")
|
||||
IMAPS_PORT=$($PHP -r "require '/opt/copymail/web/includes/db.php'; echo cfg('imaps_port');")
|
||||
WORKGROUP=$($PHP -r "require '/opt/copymail/web/includes/db.php'; echo cfg('smb_workgroup');")
|
||||
|
||||
# --- Postfix main.cf ---
|
||||
cat > /etc/postfix/main.cf << POSTFIX
|
||||
# CopyMail - généré automatiquement
|
||||
myhostname = ${HOSTNAME}.${DOMAIN}
|
||||
mydomain = ${DOMAIN}
|
||||
myorigin = \$mydomain
|
||||
inet_interfaces = all
|
||||
inet_protocols = ipv4
|
||||
mydestination = localhost
|
||||
mynetworks = 127.0.0.0/8
|
||||
|
||||
# Virtual mailboxes
|
||||
virtual_mailbox_domains = ${DOMAIN}
|
||||
virtual_mailbox_base = /var/mail/vhosts
|
||||
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
|
||||
virtual_minimum_uid = 100
|
||||
virtual_uid_maps = static:5000
|
||||
virtual_gid_maps = static:5000
|
||||
|
||||
smtpd_banner = \$myhostname ESMTP
|
||||
biff = no
|
||||
append_dot_mydomain = no
|
||||
readme_directory = no
|
||||
|
||||
# Taille max message: 50 Mo
|
||||
message_size_limit = 52428800
|
||||
POSTFIX
|
||||
|
||||
# --- Postfix master.cf (ports) ---
|
||||
cat > /etc/postfix/master.cf << MASTER
|
||||
smtp inet n - y - - smtpd
|
||||
${SUBM_PORT} inet n - y - - smtpd
|
||||
-o syslog_name=postfix/submission
|
||||
-o smtpd_tls_security_level=encrypt
|
||||
-o smtpd_sasl_auth_enable=yes
|
||||
pickup unix n - y 60 1 pickup
|
||||
cleanup unix n - y - 0 cleanup
|
||||
qmgr unix n - n 300 1 qmgr
|
||||
tlsmgr unix - - y 1000? 1 tlsmgr
|
||||
rewrite unix - - y - - trivial-rewrite
|
||||
bounce unix - - y - 0 bounce
|
||||
defer unix - - y - 0 bounce
|
||||
trace unix - - y - 0 bounce
|
||||
verify unix - - y - 1 verify
|
||||
flush unix n - y 1000? 0 flush
|
||||
proxymap unix - - n - - proxymap
|
||||
proxywrite unix - - n - 1 proxymap
|
||||
smtp unix - - y - - smtp
|
||||
relay unix - - y - - smtp
|
||||
showq unix n - y - - showq
|
||||
error unix - - y - - error
|
||||
retry unix - - y - - error
|
||||
discard unix - - y - - discard
|
||||
local unix - n n - - local
|
||||
virtual unix - n n - - virtual
|
||||
lmtp unix - - y - - lmtp
|
||||
anvil unix - - y - 1 anvil
|
||||
scache unix - - y - 1 scache
|
||||
MASTER
|
||||
|
||||
# --- Dovecot ---
|
||||
cat > /etc/dovecot/conf.d/10-mail.conf << DOVECOT
|
||||
mail_location = maildir:/var/mail/vhosts/%d/%n/Maildir
|
||||
mail_privileged_group = vmail
|
||||
DOVECOT
|
||||
|
||||
cat > /etc/dovecot/conf.d/10-auth.conf << DOVECOTAUTH
|
||||
auth_mechanisms = plain login
|
||||
!include auth-passwdfile.conf.ext
|
||||
DOVECOTAUTH
|
||||
|
||||
cat > /etc/dovecot/conf.d/auth-passwdfile.conf.ext << PASSFILE
|
||||
passdb {
|
||||
driver = passwd-file
|
||||
args = scheme=SHA512-CRYPT /etc/dovecot/users
|
||||
}
|
||||
userdb {
|
||||
driver = static
|
||||
args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n
|
||||
}
|
||||
PASSFILE
|
||||
|
||||
cat > /etc/dovecot/conf.d/10-master.conf << DOVMASTER
|
||||
service imap-login {
|
||||
inet_listener imap {
|
||||
port = ${IMAP_PORT}
|
||||
}
|
||||
inet_listener imaps {
|
||||
port = ${IMAPS_PORT}
|
||||
ssl = yes
|
||||
}
|
||||
}
|
||||
service auth {
|
||||
unix_listener auth-userdb {
|
||||
mode = 0600
|
||||
user = vmail
|
||||
}
|
||||
}
|
||||
DOVMASTER
|
||||
|
||||
# --- Samba workgroup ---
|
||||
sed -i "s/^\s*workgroup\s*=.*/ workgroup = ${WORKGROUP}/" /etc/samba/smb.conf
|
||||
|
||||
# --- Rechargement ---
|
||||
systemctl reload postfix || systemctl restart postfix
|
||||
systemctl reload dovecot || systemctl restart dovecot
|
||||
systemctl reload smbd || systemctl restart smbd
|
||||
|
||||
echo "OK: configuration appliquée pour ${DOMAIN}"
|
||||
Reference in New Issue
Block a user