Posts mit dem Label Postfix werden angezeigt. Alle Posts anzeigen
Posts mit dem Label Postfix werden angezeigt. Alle Posts anzeigen

31.12.19

Fail2ban für Postfix

# Fail2Ban filter for postfix authentication failures
#

[INCLUDES]

before = common.conf

/etc/fail2ban/filter.d/postfix-sasl.conf

[Definition]

_daemon = (?:postfix/smtpd|postfix/submission/smtpd)

failregex = ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?\s*$
             ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:Login|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?\s*$
             ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed:
             ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:Login|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed:
             ^%(__prefix_line)swarning: (.*?)does not resolve to address <HOST>: Name or service not known$
             ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:login|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?\s*$
             ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:login|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed:

# Author: Yaroslav Halchenko
Testen mit
fail2ban-regex /var/log/mail.log /etc/fail2ban/filter.d/postfix-sasl.conf

/etc/fail2ban/jail.local:
[postfix-sasl]
enabled  = true
port     = smtp,ssmtp
filter   = postfix-sasl
logpath  = /var/log/mail.log
maxretry = 3

Jails anzeigen:
fail2ban-client status

IP wieder freigeben:
fail2ban-client set sshd unbanip [IP]

Mail anpassen:
mwl -> /sendmail-common.conf
in action.d/iptables-multiport.conf:
actionban = <iptables> -I f2b-<name> 1 -s <ip> -j <blocktype>
<------>    /usr/local/bin/fail2ban-push.php <name> <protocol> <port> <ip>


Tabelle:
CREATE TABLE `sync_fail2ban` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `hostname` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
 `created` datetime NOT NULL,
 `name` text COLLATE utf8_unicode_ci NOT NULL,
 `protocol` varchar(16) COLLATE utf8_unicode_ci NOT NULL,
 `port` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
 `ip` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`reversedns` text COLLATE utf8_unicode_ci NOT NULL,
 PRIMARY KEY (`id`),
 KEY `hostname` (`hostname`,`ip`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

PHP-Script:

#!/usr/bin/php
<?php
$name = $_SERVER["argv"][1];
$protocol = $_SERVER["argv"][2];
$port = $_SERVER["argv"][3];
if (!preg_match('/^\d{1,5}$/', $port))
$port = getservbyname($_SERVER["argv"][3], $protocol);
$ip = $_SERVER["argv"][4];
$date = date("Y-m-d H:i:s");
$hostname = gethostname();

// Verbindungsdaten einfügen | insert your database settings
$link = new mysqli("localhost", "fail2ban", "password", "fail2ban");
// Ab hier nix verändern | don’t change anything below
if ($link->connect_error) {
die("Verbindung fehlgeschlagen: " . $link->connect_error());
}
$query = "INSERT INTO sync_fail2ban (name, protocol, port, ip, created, hostname)
VALUES ('$name', '$protocol', '$port', '$ip', '$date','$hostname')";
if ($link->query($query) === TRUE ){
echo "Eintrag erfolgreich geschrieben";
} else {
echo "ERROR: " .$query . "<br>" . $link->error;
}
$link->close ();
?>


13.2.17

Mails von zu Hause verschicken über Postfix

Hier eine super Anleitung, mit der man Postfix so konfigurieren kann, dass er einen anderen Mailserver (z.B. den eigenen) als Relay mit SASL-Auth. nimmt.


Kurzform:
echo [mailrelay.domain.com] [username]:[password] > /etc/postfix/relay_password
postmap hash:/etc/postfix/relay_password
  

postfix/main.cf:
mynetworks_style = [host/subnet]

relayhost = [mailrelay.domain.com]
smtp_sasl_password_maps=hash:/etc/postfix/relay_password
smtp_sasl_auth_enable=yes
smtp_sasl_security_options = noanonymous

12.1.17

Postfixadmin

apt-get install postfixadmin

Fix:
1. /etc/postfixadmin/dbconfig.inc.php
$dbtype=mysqli

2. Fehler:bei https://gehrdener.de/postfixadmin/setup.php?debug=1
DEBUG INFORMATION:
Invalid query: Invalid default value for 'created'


Fix:
Strict Mode off:

Erstelle
/etc/mysql/conf.d/disable_strict_mode.cnf
 
Inhalt:
sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
 
service mysql restart
 
 
Alias definieren in /etc/main.cf
 virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_alias_maps.cf

Inhalt:
hosts = localhost
user = [DBUSER]
password = [PASSWORD]
dbname = [DBNAME]
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
 
Virtuelle Domänen
Main.cf: 
virtual_alias_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf

 
In der mysql-virtual_domains.cf  
query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'

13.12.16

Postfix - Standard Installation mit Dovecot Auth - quick memo

apt-get install dovecot dovecot-managesieved postgrey spamassassin dovecot-lmtpd


main.cf:

smtpd_recipient_restrictions =.
    # Unsere Kinderchens erlauben!
    permit_sasl_authenticated,
    permit_mynetworks,
    # RBL checken (könnte auch nur über policyd-weight erfolgen)
    reject_rbl_client zen.spamhaus.org,
   reject_rbl_client ix.dnsbl.manitu.net,
    reject_rbl_client bl.spamcop.net,
    # policyd-weight
    #check_policy_service inet:127.0.0.1:12525,
    # Greylisting checken über TCP-Socket:
   check_policy_service inet:127.0.0.1:10023,
    reject_unauth_destination,
   reject_non_fqdn_sender,
    reject_non_fqdn_recipient,
   reject_unknown_recipient_domain

Dazu:
 smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_use_tls = yes
soft_bounce = yes


Fehler beim Versenden:
fatal: no SASL authentication mechanisms


In /etc/dovecot/conf.d/10-master.conf ggfs. einkommentieren

unix_listener auth-userdb {
    mode = 0666
    user = postfix
    group = postfix
  }

 # Postfix smtp-auth
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
  }

LMTP für Sieve aktivieren
/etc/dovecot/conf.d/20-lmtp.conf
protocol lmtp {
  # Space separated list of plugins to load (default is global mail_plugins).
  mail_plugins = $mail_plugins sieve
}


Pfad:
/etc/dovecot/conf.d/90-sieve.conf:  sieve = file:~/sieve;active=~/.dovecot.sieve

Im Home:
.dovecot.sieve -> sieve/Alles.sieve



Bei Änderung in der config von Postfix, soft_bounce = yes => alle Fehler werden zu temporären Fehlern, d.h. Mails bleiben in der Queue.


Login lokal testen:
telnet localhost 143
a login "user@domain" "password"


Sieve läuft auf Port 4190. Nach Update von dovecot(?) startete der Sieve-Daemon nicht mehr.
Gucken, ob in der /etc/dovecot/dovecout.conf folgende Zeile enthalten ist:

protocols = imap pop3 sieve


6.4.16

SSL mit Postfix

Das Postfixbuch ist das Mittel der Wahl bei der Installation von Postfix.
Auf Seite 595 ff. der 3. Auflage ist auch beschrieben, wie man Zertifikate erstellt.
Leider hat sich dabei ein kleiner Fehler eingeschlichen, der natürlich in einer neueren Version wieder ausgebügelt sein wird (nicht Peer? ;)).

Also zum Mitschreiben.....

Neues CA erstellen (Pfad stammt aus einer Ubuntu Installation)

/usr/lib/ssl/misc/CA.pl -newca

Request erstellen

/usr/lib/ssl/misc/CA.pl -newreq
(Passwort des Root CA angeben)

Wichtig

Common Name (e.g. server FQDN or YOUR name) []:

Hier muss der FQDN des Mailservers stehen, z.B. mx1.example.com

Dann das Client Zertifikat signieren mit

/usr/lib/ssl/misc/CA.pl -sign

Nun muss man noch das Passwort des neuen Zertifikates entfernen, damit Postfix ohne Rückfrage starten kann.
Hier fehlen im Postfixbuch die Anweisungen -in und -out.

openssl rsa -in newkey.pem -out key.pem

Damit nicht jeder lesen kann, die Rechte mit

chmod 400 *.pem

setzen. Auch im Verzeichnis demoCA (falls angelegt) und demoCA/private.

In Postfix braucht es nur eine Anweisung und drei Pfade:

smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
smtpd_tls_cert_file = /etc/postfix/cert.pem
smtpd_tls_key_file = /etc/postfix/ssl/key.pem
smtpd_use_tls = yes

Wenn Dovecot installiert ist, kann man die gleichen Zertifikate zum Abruf der Emails verwenden.

Datei:
/etc/dovecot/conf.d/10-ssl.conf

## Meine Zertifikate
ssl_cert = </etc/postfix/cert.pem
ssl_key = </etc/postfix/key.pem


SSL aktivierern dort mit

ssl = yes (oder required)
Protokoll ergänzen in der dovecot.conf

protocols = imap pop3 lmtp sieve imaps


Verbindung testen:

openssl s_client -starttls smtp -crlf -connect localhost:25


Openhab und Ecoflow Max - API Anbindung

 Ich wollte die neu erworbene Powerstation in Openhab einbinden, um den aktuellen Status (Ladestand etc.) über Openhab auswerten zu können. ...