Gerade neuere PHP basierende (IMAP) Webmailer haben das Problem, das jede Aktion in der Oberfläche einen erneuten Login am verursacht. Um dies zu verhindern, kann ein Cache auf dem Webserver eingerichtet werden. Dieser verbindet den jeweiligen Benutzer dem Server und hält die Verbindung noch einige Zeit offen. Löst der Benutzer anschließend im Webmailer eine erneute Verbindung aus, wird diese vom Cache abgefangen und die bereits offene zwischengespeicherte Verbindung weiterhin genutzt. Der IMAP-Server muss so nicht bei jeder Aktion im Webmailer erneut die Zugangsdaten des Benutzers prüfen, was bei einem komplexeren Anmelde Backend zu einer massiven Leistungssteigerung führt. Nach einigen Tests habe ich mich für http://www.imapproxy.org entschieden. Dieser überzeugt durch einfache Konfiguration und hohe Leistung. Leider fehlt ein passendes init-script für Gentoo-Linux. Dies lässt sich aber problemlos nachholen.
Installation unter Gentoo
Kopieren des Download-Links von http://www.imapproxy.org/download.html in die Zwischenablage
cd /usr/src
wget http://www.imapproxy.org/downloads/up-imapproxy-VERSION.tar.gz (vorher kopiert :- )
tar xfz up-imapproxy-1.2.6.tar.gz
Gentoo sollte als Meta-Distribution alle Abhängigkeiten zum Kompilieren erfüllen. Für andere Distributionen sollten die entsprechenden Pakete (GCC, MAKE, usw.) installiert werden.
Konfigurieren und Kompilieren:
./configure --prefix=/usr --sysconfdir=/etc/imapproxy --localstatedir=/var
make
Installieren:
Ein Blick ins Makefile verrät das von „make install“ nur 2 Dateien nach /usr/sbin kopiert werden. „make install-init“ sollte man unter Gentoo nicht ausführen, da die scripte unter /etc/init.d abgelegt werden. Die Konfiguration kann auch per Hand kopiert werden.
make install
mkdir /etc/imapproxy
cp scripts/imapproxy.conf /etc/imapproxy
Nun schnell noch ein für gentoo passendes init-script schreiben und unter /etc/init.d ablegen …
Die Konfiguration erfolgt in der Datei /etc/imapproxy/imapproxy.conf. Die Kommentare sind mehr als ausreichend. Ich empfehle aus sicherheitsgründen den Proxy ausschließlich an das loopback Interface (127.0.0.1) zu binden. Sollte sich der IMAP-Server im gleichem Netz (z.B. DMZ) oder gar auf dem gleichem Host befinden, kann auf SSL verzichtet werden.
#!/sbin/runscript
#Runscript for imap-proxy under Gentoo Linux
#
opts="checkconfig reload"
depend() {
need net hostname localmount
}
checkconfig() {
if [ ! -e /etc/imapproxy/imapproxy.conf ]; then
eerror "Please create /etc/imapproxy/imapproxy.conf first!"
return 1
fi
}
start() {
checkconfig || return 1
ebegin "Starting imap proxy"
start-stop-daemon --start --quiet --exec /usr/sbin/in.imapproxyd -- -p /var/run/imapproxy.pid -f /etc/imapproxy/imapproxy.conf
eend $? "Failed to start imap proxy"
}
stop() {
ebegin "Stopping imap proxy"
start-stop-daemon --stop --quiet --pidfile /var/run/imapproxy.pid
}
Nun kann der Proxy gestartet werden.
/etc/init.d/imapproxy start
“tail /var/log/messages /var/log/mail.log” sollten nun folgende Zeilen zeigen:
in.imapproxyd: main(): Using pidfile '/var/run/imapproxy.pid'
in.imapproxyd: main(): Using configuration file '/etc/imapproxy/imapproxy.conf'
in.imapproxyd: Using syslog facility 'LOG_MAIL' for logging.
in.imapproxyd[1957]: Masking syslog priority up to LOG_INFO.
in.imapproxyd[1957]: main(): SELECT caching is disabled
in.imapproxyd[1957]: main(): Internal admin commands are disabled
in.imapproxyd[1957]: main(): Allocating 3072 IMAP connection structures.
in.imapproxyd[1957]: ServerInit(): Using '/var/log/imapproxy_protocol.log' for global protocol logging file.
in.imapproxyd[1957]: ServerInit(): proxying to IMAP server '**********'.
in.imapproxyd[1957]: ServerInit(): Proxying to IMAP port 143
in.imapproxyd[1957]: main(): Binding to tcp 127.0.0.1:1430
in.imapproxyd[1957]: main(): Using global statistics file '/var/run/pimpstats'
in.imapproxyd[1957]: Daemonize(): Configured to run in background mode.
in.imapproxyd[1959]: BecomeNonRoot(): Process will run as uid 65534 (nobody) and gid 65534 (nobody).
in.imapproxyd[1959]: main(): Launched ICC recycle thread with id -1381332080
in.imapproxyd[1959]: main(): imapproxy version 1.2.6 normal server startup.
INIT, “netstat -nlp” und “ps -Al” sollten bestätigen das der Proxy läuft.
netstat -nlp | grep -i imapproxy
tcp 0 0 127.0.0.1:1430 0.0.0.0:* LISTEN 1959/in.imapproxyd
ps -AlF
5 S nobody 1959 1 0 78 0 - 5067 415801 1176 0 16:37 ? 00:00:00 /usr/sbin/in.imapproxyd -p /var/run/imapproxy.pid -f /etc/imapproxy/imapproxy.conf
/etc/init.d/imapproxy status
* status: started
Abschließend wird der Webmailer zur Verwendung des IMAP-Proxys konfiguriert und fertig.
z.B. Roundcube:
$rcmail_config['default_host'] = 'localhost';
$rcmail_config['default_port'] = 1430;
Anfangs sollte man die “syslog_facility” mindestens auf “LOG_INFO”. Dies hilft bei der Fehlersuche.