<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>johker&#039;s blog &#187; script</title>
	<atom:link href="http://johker.ibutho.de/tag/script/feed/" rel="self" type="application/rss+xml" />
	<link>http://johker.ibutho.de</link>
	<description>stories about me, my life and my trips</description>
	<lastBuildDate>Sun, 18 Dec 2011 11:53:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Der neue Server: Teil X Sonstiges</title>
		<link>http://johker.ibutho.de/2010/01/13/der-neue-server-teil-x-sonstiges/</link>
		<comments>http://johker.ibutho.de/2010/01/13/der-neue-server-teil-x-sonstiges/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 18:33:15 +0000</pubDate>
		<dc:creator>johker</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[a2ensite]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[chroot]]></category>
		<category><![CDATA[chrooted]]></category>
		<category><![CDATA[csr]]></category>
		<category><![CDATA[diffie-hellman]]></category>
		<category><![CDATA[guest]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[sftp]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[tausch]]></category>
		<category><![CDATA[vHost]]></category>
		<category><![CDATA[vhost automation]]></category>

		<guid isPermaLink="false">http://johker.ibutho.de/?p=159</guid>
		<description><![CDATA[Der Entwurf zu diesem Beitrag ist schon fast ein Jahr alt. Ich will ihn nun endlich mal veröffentlichen in der Hoffnung, dass er einigen Leuten hilft und ihnen Arbeit abnimmt. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212; In diesem Beitrag sind alle Dinge zusammengefasst, die thematisch &#8230; <a href="http://johker.ibutho.de/2010/01/13/der-neue-server-teil-x-sonstiges/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Der Entwurf zu diesem Beitrag ist schon fast ein Jahr alt. Ich will ihn nun endlich mal veröffentlichen in der Hoffnung, dass er einigen Leuten hilft und ihnen Arbeit abnimmt.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>In diesem Beitrag sind alle Dinge zusammengefasst, die thematisch nicht direkt zusammenpassen oder nicht direkt in einen einzigen Beitrag passen, da sie mehrere Themen streifen.</p>
<h1>ssl-Zertifikat erstellen</h1>
<p>Jetzt erstellen wir ein <em>ssl</em>-Zertifikat, welches wir bei <a href="http://cacert.org/" target="_blank">cacert.org</a> signieren lassen. Dies bietet einige Vorteile gegenüber dem Selbst-Signieren (self-signing). Leider ist das <em>cacert.org</em> Root-Zertifikat noch nicht in Firefox aufgenommen und somit erhält man immer diese lästige Warnung, wenn man eine cacert-zertifizierte Webseite aufruft, bis man deren Root-Zertifikat in Firefox importiert.<br />
Am Besten geht man nach dieser Anleitung vor zum Erstellen eines Zertifikats: <a href="http://wiki.cacert.org/wiki/CSRGenerator" target="_blank">http://wiki.cacert.org/wiki/CSRGenerator</a>. Danach verschiebt man den Private-Key nach &#8220;<em>/etc/ssl/private</em>&#8221; und den Public-Key nach &#8220;<em>/etc/ssl/certs</em>&#8220;. Nun kann man das Zertifikat z.B. in Apache verwenden, aber auch für den Mailserver, IMAP-/POP-Server, svn, &#8230; Sollte eine Applikation nicht auf den Private-Key zugreifen können, benötigt aber Zugriff darauf, so muss man den Benutzer unter der die Applikation läuft in die Gruppe &#8220;<em>ssl-cert</em>&#8221; aufnehmen (<strong>ACHTUNG:</strong> Dies könnte ein Sicherheitsrisiko darstellen!).</p>
<h2>Diffie-Hellman-Code erzeugen</h2>
<p>Dies wird z.B. für postfix gebraucht, aber auch für einige IMAP-Server, deshalb erzeugen wir hier diesen Code und speichern ihn unter &#8220;/etc/ssl/private/&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl gendh <span style="color: #660033;">-out</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>dh_1024.pem <span style="color: #660033;">-2</span> <span style="color: #660033;">-rand</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom <span style="color: #000000;">1024</span>
openssl gendh <span style="color: #660033;">-out</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>dh_512.pem <span style="color: #660033;">-2</span> <span style="color: #660033;">-rand</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom <span style="color: #000000;">512</span></pre></div></div>

<h2>SSL-vHost in apache erstellen</h2>
<p>Um in <em>apache</em> einen SSL-vHost erstellen kann, muss man die Datei <em>ports.conf</em> unter &#8220;<em>/etc/apache2</em>&#8221; ändern und die folgende Zeilen hinzufügen/ergänzen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>IfModule mod_ssl.c<span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #666666; font-style: italic;"># SSL name based virtual hosts are not yet supported, therefore no</span>
    <span style="color: #666666; font-style: italic;"># NameVirtualHost statement here</span>
    NameVirtualHost <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">443</span>
    Listen <span style="color: #000000;">443</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>IfModule<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Danach können wie gehabt vHosts erstellt werden, mit dem Unterschied, dass die Zeile &#8220;<VirtualHost *:80>&#8221; in &#8220;<VirtualHost *:443>&#8221; geändert werden und folgende Zeilen hinzugefügt werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">        SSLEngine on
        SSLCertificateFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs<span style="color: #000000; font-weight: bold;">/</span>server.pem
        SSLCertificateKeyFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>privatekey.pem
        SSLCipherSuite HIGH
        SSLProtocol all <span style="color: #660033;">-SSLv2</span></pre></div></div>

<p>Weiter unten stelle ich ein Skript vor, mit welchem man bequem vHosts (sowohl mit und ohne SSL) erstellen kann und automatisch von Port 80 auf Port 443 weiterleiten, wenn der vHost SSL unterstützt.</p>
<p>Quellen:<br />
<a href="http://wiki.cacert.org/wiki/CSRGenerator" target="_blank">http://wiki.cacert.org/wiki/CSRGenerator</a><br />
<a href="http://cacert.org/" target="_blank">http://cacert.org/</a></p>
<h1>sftp-Gastzugang</h1>
<p>Oft möchte man Leuten einen Zuganz zu seinem Server verschaffen, damit man etwas in ein bestimmtes Verzeichnis hochladen, bzw. daraus herunterladen darf, aber nicht aus diesem Verzeichnis herausnavigieren darf und evtl. Schaden anrichten kann. Dies kann man mit openSSH 5.0 sehr einfach lösen, da es eingebaute chroot-Mechanismen hat. So kann man z.B. eine ganze Gruppe auf ihr Home-Laufwerk oder einen anderen Ordner beschränken oder aber auch nur einen einzigen Benutzer. Im Folgenden legen wir eine Gruppe &#8220;<em>chrooted</em>&#8221; an, welche auf ihr Home-Laufwerk beschränkt sein wird. Alle Home-Laufwerke dieser Gruppe werden standardmäßig unter &#8220;<em>/home/chrooted</em>&#8221; liegen. Für unseren Gastbenutzer legen wir darunter ein Verzeichnis &#8220;<em>upload</em>&#8221; an und ändern die Rechte entsprechend:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> upload
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #000000; font-weight: bold;">&lt;</span>uploaduser<span style="color: #000000; font-weight: bold;">&gt;</span>:<span style="color: #c20cb9; font-weight: bold;">users</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>chrooted<span style="color: #000000; font-weight: bold;">/</span>upload
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">775</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>chrooted<span style="color: #000000; font-weight: bold;">/</span>upload</pre></div></div>

<p>Will man Ordner außerhalb des Home-Laufwerks zugänglich machen, kann man diese mit &#8220;<em>mount -o bind</em>&#8221; temporär einbinden, bzw. über die &#8220;<em>/etc/fstab</em>&#8221; dauerhaft:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>pfad<span style="color: #000000; font-weight: bold;">/</span>zum<span style="color: #000000; font-weight: bold;">/</span>quellverzeichnis <span style="color: #000000; font-weight: bold;">/</span>pfad<span style="color: #000000; font-weight: bold;">/</span>zum<span style="color: #000000; font-weight: bold;">/</span>zielverzeichnis none rw,<span style="color: #7a0874; font-weight: bold;">bind</span> <span style="color: #000000;">0</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Gruppe &#8220;<em>chrooted</em>&#8221; anlegen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">addgroup <span style="color: #660033;">--system</span> chrooted</pre></div></div>

<p>Um einen Benutzer in die Gruppe &#8220;<em>chrooted</em>&#8221; aufzunehmen, führt man folgenden Befehl aus:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adduser <span style="color: #000000; font-weight: bold;">&lt;</span>uploaduser<span style="color: #000000; font-weight: bold;">&gt;</span> chrooted</pre></div></div>

<p>Danach muss man die <em>sshd_config</em> anpassen, bzw. erweitern:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#Subsystem sftp /usr/lib/openssh/sftp-server</span>
Subsystem sftp internal-sftp
&nbsp;
Match group chrooted
        <span style="color: #666666; font-style: italic;"># chroot all users of these group to their homes</span>
        <span style="color: #666666; font-style: italic;"># %h will be substituted by the user's home</span>
        <span style="color: #666666; font-style: italic;"># %u will be substituted with the user's user name</span>
        ChrootDirectory <span style="color: #000000; font-weight: bold;">%</span>h
        AllowTcpForwarding no
        ForceCommand internal-sftp</pre></div></div>

<p>Wichtig ist, dass das Home-Verzeichnis des Benutzers <strong>root</strong> gehören muss (&#8220;chown root: /pfad/zu/home&#8221;). Die Unterordner sollten dann wieder dem Benutzer gehören, damit das ganze auch Sinn macht und er Dateien hoch-/runterladen kann. In unserem Beispiel bedeutet das, dass &#8220;<em>/home/chrooted</em>&#8221; root gehören muss und &#8220;<em>/home/chrooted/upload</em>&#8221; dem <uploaduser>.<br />
Zusätzlich kann man nun noch unter &#8220;/etc/passwd&#8221; die Standardkonsole des <uploadusers> auf &#8220;<em>/bin/false</em>&#8221; setzen, denn der Benutzer darf sich nur via <em>sftp</em> anmelden und nicht über die Konsole:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>uploaduser<span style="color: #000000; font-weight: bold;">&gt;</span>:x:<span style="color: #000000;">1666</span>:<span style="color: #000000;">1666</span>:Guest upload-account,,,:<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>chrooted:<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span></pre></div></div>

<p>Quellen:<br />
<a href="http://binblog.wordpress.com/2008/04/06/openssh-chrooted-sftp-eg-for-webhosting/" target="_blank">http://binblog.wordpress.com/2008/04/06/openssh-chrooted-sftp-eg-for-webhosting/</a><br />
<a href="http://www.debian-administration.org/articles/590" target="_blank">http://www.debian-administration.org/articles/590</a></p>
<h1>Tauschverzeichnis anlegen</h1>
<p>Da alle Konsolenbenutzer auch Mitglied in der Gruppe &#8220;<em>users</em>&#8221; sind, ist es ein leichtes ein Tausch-Verzeichnis unter &#8220;<em>/home/shared</em>&#8221; anzulegen. Darunter legen wir &#8211; der Benutzerfreundlichkeit zuliebe &#8211; einen Symlink nach &#8220;/home/chrooted/upload&#8221; an (siehe vorheriges Kapitel):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>shared
<span style="color: #c20cb9; font-weight: bold;">chown</span> root:<span style="color: #c20cb9; font-weight: bold;">users</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>shared
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">775</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>shared
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>chrooted<span style="color: #000000; font-weight: bold;">/</span>upload upload</pre></div></div>

<p>Nun können sich alle Konsolenbenutzer über dieses Verzeichnis austauschen und auf die Dateien des Gast-Accounts zugreifen, welche für ihn bereitstellen bzw. je nach Rechten auch welche löschen.</p>
<h1>vHosts-Skript</h1>
<p>Um einem die Arbeit etwas zu erleichtern habe ich schnell ein kleines <em>bash</em>-Skript runtergehackt, mit welchem man bequem vHosts unter <em>apache2</em> anlegen kann. Ist man nach <a href="http://johker.ibutho.de/2009/03/22/der-neue-server-teil-4-apache/">Der neue Server: Teil 4 apache</a> vorgegangen, so müssen im Skript normalerweise keine Änderungen vorgenommen werden, anderfalls braucht das Skript evtl. ein paar Anpassungen.</p>
<p>Hier das Skript:</p>
<p><i>createVhost.sh:</i></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># createVhost.sh - Creates an Apache2 vHost configuration</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Copyright (C) 2009 johker</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License v2 as published by the Free Software Foundation</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License v2 for more details.</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">### CHANGE ME! ###</span>
&nbsp;
<span style="color: #007800;">WWW_ROOT</span>=<span style="color: #ff0000;">&quot;/var/www&quot;</span>
<span style="color: #007800;">SITES_ROOT</span>=<span style="color: #ff0000;">&quot;/etc/apache2/sites-available&quot;</span>
&nbsp;
<span style="color: #007800;">CHANGE_PHP_INI</span>=<span style="color: #ff0000;">&quot;no&quot;</span>
&nbsp;
<span style="color: #007800;">EXAMPLE_ROOT</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$WWW_ROOT</span>/example&quot;</span>
<span style="color: #007800;">SITES_EXAMPLE</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$SITES_ROOT</span>/example&quot;</span>
<span style="color: #007800;">SITES_EXAMPLE_SSL</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$SITES_EXAMPLE</span>-ssl&quot;</span>
&nbsp;
<span style="color: #007800;">SSL_PRIV_DEFAULT</span>=<span style="color: #ff0000;">&quot;/etc/ssl/private/privatekey.pem&quot;</span>
<span style="color: #007800;">SSL_PUB_DEFAULT</span>=<span style="color: #ff0000;">&quot;/etc/ssl/certs/publickey.pem&quot;</span>
&nbsp;
<span style="color: #007800;">PHP_INI_TEMPLATE</span>=<span style="color: #ff0000;">&quot;/etc/php5/cgi/php.ini&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### END CHANGE ME! ###</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#############################################################</span>
<span style="color: #666666; font-style: italic;">########## DO NOT CHANGE ANYTHING BELOW THIS LINE! ##########</span>
<span style="color: #666666; font-style: italic;">#############################################################</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Make sure only root can run our script</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(id -u)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ERROR: This script must be run as root!&quot;</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Query the user for some details</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;Domain name: &quot;</span> SRV_NAME
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;Domain aliases (leave blank if no aliases available, separated by blank): &quot;</span> SRV_ALIAS
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;Admin e-mail address: &quot;</span> SRV_ADMIN
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;vHost owner (system user): &quot;</span> USER
<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span>  <span style="color: #ff0000;">&quot;Use SSL (yes/no)[no]: &quot;</span> SSL
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$SSL</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #666666; font-style: italic;"># set default value</span>
	<span style="color: #007800;">SSL</span>=<span style="color: #ff0000;">&quot;no&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$SSL</span> == <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;SSL private key[<span style="color: #007800;">$SSL_PRIV_DEFAULT</span>]: &quot;</span> CERT_PRIV
	<span style="color: #c20cb9; font-weight: bold;">read</span> <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;SSL public key[<span style="color: #007800;">$SSL_PUB_DEFAULT</span>]: &quot;</span> CERT_PUB
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$CERT_PRIV</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #666666; font-style: italic;"># set default value</span>
		<span style="color: #007800;">CERT_PRIV</span>=<span style="color: #007800;">$SSL_PRIV_DEFAULT</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$CERT_PUB</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #666666; font-style: italic;"># set default value</span>
		<span style="color: #007800;">CERT_PUB</span>=<span style="color: #007800;">$SSL_PUB_DEFAULT</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">VHOST_ROOT</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$WWW_ROOT</span>/<span style="color: #007800;">$SRV_NAME</span>&quot;</span>
<span style="color: #007800;">DOC_ROOT</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$VHOST_ROOT</span>/docs&quot;</span>
<span style="color: #007800;">CONF_ROOT</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$VHOST_ROOT</span>/conf&quot;</span>
<span style="color: #007800;">LOG_ROOT</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$VHOST_ROOT</span>/logs&quot;</span>
<span style="color: #007800;">TMP_ROOT</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$VHOST_ROOT</span>/tmp&quot;</span>
&nbsp;
<span style="color: #007800;">PHP_FCGI</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$CONF_ROOT</span>/php-fcgi.conf&quot;</span>
<span style="color: #007800;">PHP_INI</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$CONF_ROOT</span>/php.ini&quot;</span>
&nbsp;
<span style="color: #007800;">VHOST_CONF</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$SITES_ROOT</span>/<span style="color: #007800;">$SRV_NAME</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># GROUP equals USER</span>
<span style="color: #007800;">GROUP</span>=<span style="color: #007800;">$USER</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> changeFcgiConfig <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># adjust fcgi config</span>
	<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{SRV_NAME}!<span style="color: #007800;">$SRV_NAME</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$PHP_FCGI</span>
	<span style="color: #666666; font-style: italic;"># ... php.ini</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$CHANGE_PHP_INI</span> == <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!;upload_tmp_dir =!upload_tmp_dir = <span style="color: #007800;">$TMP_ROOT</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$PHP_INI</span>
		<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!;open_basedir =!open_basedir = <span style="color: #007800;">$DOC_ROOT</span>:<span style="color: #007800;">$TMP_ROOT</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$PHP_INI</span>
		<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!;session.save_path = /var/lib/php5!session.save_path = <span style="color: #007800;">$TMP_ROOT</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$PHP_INI</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> createDirs <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># create the directory structure</span>
&nbsp;
	<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> <span style="color: #007800;">$EXAMPLE_ROOT</span> <span style="color: #007800;">$VHOST_ROOT</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$CHANGE_PHP_INI</span> == <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #666666; font-style: italic;"># don't put a symlink to php.ini in $CONF_ROOT, but copy it there</span>
		<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$CONF_ROOT</span><span style="color: #000000; font-weight: bold;">/</span>php.ini
		<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #007800;">$PHP_INI_TEMPLATE</span> <span style="color: #007800;">$CONF_ROOT</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
	changeFcgiConfig
&nbsp;
	<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #007800;">$USER</span>:<span style="color: #007800;">$GROUP</span> <span style="color: #660033;">-R</span> <span style="color: #007800;">$VHOST_ROOT</span>
&nbsp;
	<span style="color: #c20cb9; font-weight: bold;">chattr</span> +i <span style="color: #007800;">$CONF_ROOT</span><span style="color: #000000; font-weight: bold;">/</span>php-fcgi.conf
	<span style="color: #666666; font-style: italic;"># as $CONF_ROOT/php.ini is just a symlink most of the time, chattr will usually fail</span>
	<span style="color: #c20cb9; font-weight: bold;">chattr</span> +i <span style="color: #007800;">$CONF_ROOT</span><span style="color: #000000; font-weight: bold;">/</span>php.ini <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> createApacheConfig <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># now let's adjust the apache vHost-configuration</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$SSL</span> == <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #007800;">$SITES_EXAMPLE_SSL</span> <span style="color: #007800;">$VHOST_CONF</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #007800;">$SITES_EXAMPLE</span> <span style="color: #007800;">$VHOST_CONF</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># now do sed operations on $VHOST_CONF</span>
	<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{SRV_NAME}!<span style="color: #007800;">$SRV_NAME</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SRV_ALIAS</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{SRV_ALIAS}!!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{SRV_ALIAS}!<span style="color: #007800;">$SRV_ALIAS</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
		<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!#	ServerAlias!	ServerAlias!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{SRV_ADMIN}!<span style="color: #007800;">$SRV_ADMIN</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
	<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{USER}!<span style="color: #007800;">$USER</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
	<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{GROUP}!<span style="color: #007800;">$GROUP</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
&nbsp;
	<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{DOC_ROOT}!<span style="color: #007800;">$DOC_ROOT</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
	<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{CONF_ROOT}!<span style="color: #007800;">$CONF_ROOT</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
	<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{LOG_ROOT}!<span style="color: #007800;">$LOG_ROOT</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$SSL</span> == <span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{CERT_PUB}!<span style="color: #007800;">$CERT_PUB</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
		<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s!{CERT_PRIV}!<span style="color: #007800;">$CERT_PRIV</span>!g&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$VHOST_CONF</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
createDirs
createApacheConfig
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></td></tr></table></div>

<p>Die dazugehörenden Ordnerstruktur unter &#8220;<em>/var/www/example</em>&#8220;:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example<span style="color: #000000; font-weight: bold;">/</span>conf
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example<span style="color: #000000; font-weight: bold;">/</span>docs
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example<span style="color: #000000; font-weight: bold;">/</span>tmp
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example<span style="color: #000000; font-weight: bold;">/</span>logs
<span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>access.log
<span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>error.log
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>php5<span style="color: #000000; font-weight: bold;">/</span>cgi<span style="color: #000000; font-weight: bold;">/</span>php.ini <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>php.ini</pre></div></div>

<p>Hier noch die Datei &#8220;<em>php-fcgi.conf</em>&#8220;, welche nach &#8220;<em>/var/www/example/conf/</em>&#8221; gehört: </p>
<p><i>php-fcgi.conf:</i></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">PHPRC</span>=<span style="color: #ff0000;">&quot;/var/www/{SRV_NAME}/conf&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> PHPRC
<span style="color: #007800;">PHP_FCGI_CHILDREN</span>=<span style="color: #000000;">3</span>
<span style="color: #7a0874; font-weight: bold;">export</span> PHP_FCGI_CHILDREN
<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php5-cgi</pre></div></div>

<p>Dazu noch die vHost-configs &#8220;example&#8221;, sowie &#8220;example-ssl&#8221; unter /etc/apache2/sites-available&#8221;:</p>
<ul>
<li><i>example</i>:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>VirtualHost <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">80</span><span style="color: #000000; font-weight: bold;">&gt;</span>
        SuExecUserGroup <span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>GROUP<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        ServerName <span style="color: #7a0874; font-weight: bold;">&#123;</span>SRV_NAME<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #666666; font-style: italic;">#	ServerAlias {SRV_ALIAS}</span>
        ServerAdmin <span style="color: #7a0874; font-weight: bold;">&#123;</span>SRV_ADMIN<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        DocumentRoot <span style="color: #7a0874; font-weight: bold;">&#123;</span>DOC_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span>
        AddHandler fcgid-script .php
        <span style="color: #000000; font-weight: bold;">&lt;</span>Directory <span style="color: #7a0874; font-weight: bold;">&#123;</span>DOC_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                FCGIWrapper <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONF_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>php-fcgi.conf .php
                Options +SymLinksIfOwnerMatch +MultiViews +ExecCGI <span style="color: #660033;">-Indexes</span>
                AllowOverride FileInfo AuthConfig
                Order allow,deny
                allow from all
        <span style="color: #000000; font-weight: bold;">&lt;/</span>Directory<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
        ErrorLog <span style="color: #7a0874; font-weight: bold;">&#123;</span>LOG_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>error.log
        CustomLog <span style="color: #7a0874; font-weight: bold;">&#123;</span>LOG_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>access.log combined
        LogLevel warn
        ServerSignature Off
<span style="color: #000000; font-weight: bold;">&lt;/</span>VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

</li>
<li><i>example-ssl</i>:

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>VirtualHost <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">80</span><span style="color: #000000; font-weight: bold;">&gt;</span>
        ServerName <span style="color: #7a0874; font-weight: bold;">&#123;</span>SRV_NAME<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #666666; font-style: italic;">#	ServerAlias {SRV_ALIAS}</span>
        ServerAdmin <span style="color: #7a0874; font-weight: bold;">&#123;</span>SRV_ADMIN<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;</span>IfModule mod_ssl.c<span style="color: #000000; font-weight: bold;">&gt;</span>
          RewriteEngine   on
	  RewriteCond     <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>SERVER_PORT<span style="color: #7a0874; font-weight: bold;">&#125;</span> ^<span style="color: #000000;">80</span>$
          RewriteRule     ^<span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>$ https:<span style="color: #000000; font-weight: bold;">//%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>SERVER_NAME<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #007800;">$1</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>L,R<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
	  RewriteLog      <span style="color: #7a0874; font-weight: bold;">&#123;</span>LOG_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rewrite.log
          RewriteLogLevel <span style="color: #000000;">2</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>IfModule<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
        ErrorLog <span style="color: #7a0874; font-weight: bold;">&#123;</span>LOG_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>error.log
        CustomLog <span style="color: #7a0874; font-weight: bold;">&#123;</span>LOG_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>access.log combined
        LogLevel warn
&nbsp;
        ServerSignature Off
<span style="color: #000000; font-weight: bold;">&lt;/</span>VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>VirtualHost <span style="color: #000000; font-weight: bold;">*</span>:<span style="color: #000000;">443</span><span style="color: #000000; font-weight: bold;">&gt;</span>
        SuExecUserGroup <span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>GROUP<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        ServerName <span style="color: #7a0874; font-weight: bold;">&#123;</span>SRV_NAME<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #666666; font-style: italic;">#	ServerAlias {SRV_ALIAS}</span>
        ServerAdmin <span style="color: #7a0874; font-weight: bold;">&#123;</span>SRV_ADMIN<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        SSLEngine on
        SSLCertificateFile <span style="color: #7a0874; font-weight: bold;">&#123;</span>CERT_PUB<span style="color: #7a0874; font-weight: bold;">&#125;</span>
        SSLCertificateKeyFile <span style="color: #7a0874; font-weight: bold;">&#123;</span>CERT_PRIV<span style="color: #7a0874; font-weight: bold;">&#125;</span>
        SSLCipherSuite HIGH
        SSLProtocol all <span style="color: #660033;">-SSLv2</span>
&nbsp;
        DocumentRoot <span style="color: #7a0874; font-weight: bold;">&#123;</span>DOC_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span>
        AddHandler fcgid-script .php
        <span style="color: #000000; font-weight: bold;">&lt;</span>Directory <span style="color: #7a0874; font-weight: bold;">&#123;</span>DOC_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                FCGIWrapper <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONF_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>php-fcgi.conf .php
                Options +SymLinksIfOwnerMatch +MultiViews +ExecCGI <span style="color: #660033;">-Indexes</span>
                AllowOverride FileInfo
                Order allow,deny
                allow from all
        <span style="color: #000000; font-weight: bold;">&lt;/</span>Directory<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
        ErrorLog <span style="color: #7a0874; font-weight: bold;">&#123;</span>LOG_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>error.log
        CustomLog <span style="color: #7a0874; font-weight: bold;">&#123;</span>LOG_ROOT<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>access.log combined
        LogLevel warn
&nbsp;
        ServerSignature Off
<span style="color: #000000; font-weight: bold;">&lt;/</span>VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

</li>
</ul>
<p>Das Skript kann als Benutzer <strong>root</strong> ausgeführt werden. Es fragt nach ein paar Parametern (default-Werte stehen in eckigen Klammern und können durch Drücken der Eingabetaste übernommen werden) und erstellt dann den vHost und die dazugehörige Konfiguration. Nach Ausführen des Skripts muss der vHost noch mittels des &#8220;<em>a2ensite</em>&#8220;-Befehls aktiviert werden und die <em>apache</em>-Konfiguration muss neu eingelesen werden.</p>
]]></content:encoded>
			<wfw:commentRss>http://johker.ibutho.de/2010/01/13/der-neue-server-teil-x-sonstiges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fetchmail Integration in postfixadmin</title>
		<link>http://johker.ibutho.de/2009/04/07/fetchmail-integration-in-postfixadmin/</link>
		<comments>http://johker.ibutho.de/2009/04/07/fetchmail-integration-in-postfixadmin/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 21:26:34 +0000</pubDate>
		<dc:creator>johker</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tipps und Tricks]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[cronjob]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[fetchmail]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[konfiguration]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[postfixadmin]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://johker.ibutho.de/?p=227</guid>
		<description><![CDATA[Viele Benutzer haben auch Mailboxen bei anderen Anbietern, z.B. bei gmx oder web.de. Damit diese Benutzer ihre E-Mails aggregieren können, wird fetchmail eingerichtet. fetchmail ist bereits in postfixadmin integriert, somit können fetchmail-Einträge über postfixadmin verwaltet werden (derzeit leider nur von &#8230; <a href="http://johker.ibutho.de/2009/04/07/fetchmail-integration-in-postfixadmin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Viele Benutzer haben auch Mailboxen bei anderen Anbietern, z.B. bei gmx oder web.de. Damit diese Benutzer ihre E-Mails aggregieren können, wird <em>fetchmail</em> eingerichtet. <em>fetchmail</em> ist bereits in <em>postfixadmin</em> integriert, somit können <em>fetchmail</em>-Einträge über <em>postfixadmin</em> verwaltet werden (derzeit leider nur von Administratoren). Über das mitgelieferte <em>fetchmail.pl</em>-Skript werden die Daten aus der Datenbank ausgelesen, <em>fetchmail</em> aufgerufen, die Mails durch <em>amavisd-new</em> überprüft und an die Mailboxen der Benutzer ausgeliefert. Das <em>perl</em>-Skript wurde etwas angepasst, damit es mit <em>postgres</em> interagieren kann. Des Weiteren wurden die Dateinamen etwas angepasst.</p>
<p>Installation:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> fetchmail
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> liblockfile-simple-perl</pre></div></div>

<p>Nötige Verzeichnisse für das Skript anlegen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>fetchmail
<span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>fetchmail<span style="color: #000000; font-weight: bold;">/</span>fetchmail-all.lock</pre></div></div>

<p>Das Skript:</p>
<p><em>fetchmail.pl</em></p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> MIME<span style="color: #339933;">::</span><span style="color: #006600;">Base64</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># use Data::Dumper;</span>
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Temp</span> <span style="color: #009966; font-style: italic;">qw/ mkstemp /</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Sys<span style="color: #339933;">::</span><span style="color: #006600;">Syslog</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># require liblockfile-simple-perl</span>
<span style="color: #000000; font-weight: bold;">use</span> LockFile<span style="color: #339933;">::</span><span style="color: #006600;">Simple</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span>lock trylock unlock<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
openlog<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;fetchmail-all&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;pid&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;mail&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> log_and_die <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$message</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
  syslog<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;err&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">die</span> <span style="color: #0000ff;">$message</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># read options and arguments</span>
&nbsp;
<span style="color: #0000ff;">$configfile</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;/etc/fetchmail/config&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">@ARGS1</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #000000; font-weight: bold;">ARGV</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$_</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span> <span style="color: #0000ff;">@ARGS1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^-/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^--config$/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">$configfile</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span> <span style="color: #0000ff;">@ARGS1</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># postgres settings</span>
<span style="color: #0000ff;">$database</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;postfix&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$hostname</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;127.0.0.1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$user</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;postfix&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$password</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;XXXXXX&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$run_dir</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;/var/run/fetchmail&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># use specified config file</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>e <span style="color: #0000ff;">$configfile</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">do</span> <span style="color: #0000ff;">$configfile</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">$dsn</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;DBI:Pg:database=$database;host=$hostname&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$lock_file</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$run_dir</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;/fetchmail-all.lock&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$lockmgr</span> <span style="color: #339933;">=</span> LockFile<span style="color: #339933;">::</span><span style="color: #006600;">Simple</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">make</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>autoclean <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span>max <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$lockmgr</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">lock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$lock_file</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> log_and_die <span style="color: #ff0000;">&quot;can't lock ${lock_file}&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#postgres connect</span>
<span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$dsn</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$user</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> log_and_die <span style="color: #ff0000;">&quot;cannot connect the database&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$sql</span><span style="color: #339933;">=</span><span style="color: #cc0000; font-style: italic;">&lt;&lt;SQL;
SELECT id,mailbox,src_server,src_auth,src_user,src_password,src_folder,fetchall,keep,protocol,mda,extra_options,usessl 
FROM fetchmail
WHERE date_part('epoch',now())-date_part('epoch',date) &gt; poll_time*60
SQL</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">%config</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">map</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$mailbox</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$src_server</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$src_auth</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$src_user</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$src_password</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$src_folder</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$fetchall</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$keep</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$protocol</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$mda</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$extra_options</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$usessl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">=@</span><span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span>
&nbsp;
  syslog<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;info&quot;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;fetch ${src_user}@${src_server} for ${mailbox}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #0000ff;">$cmd</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;user '${src_user}' there with password '&quot;</span><span style="color: #339933;">.</span>decode_base64<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$src_password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;'&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$cmd</span><span style="color: #339933;">.=</span><span style="color: #ff0000;">&quot; folder '${src_folder}'&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$src_folder</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$cmd</span><span style="color: #339933;">.=</span><span style="color: #ff0000;">&quot; mda &quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$mda</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$mda</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#       $cmd.=&quot; mda \&quot;/usr/local/libexec/dovecot/deliver -m ${mailbox}\&quot;&quot;;</span>
        <span style="color: #0000ff;">$cmd</span><span style="color: #339933;">.=</span><span style="color: #ff0000;">&quot; is '${mailbox}' here&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #0000ff;">$cmd</span><span style="color: #339933;">.=</span><span style="color: #ff0000;">&quot; keep&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$keep</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$cmd</span><span style="color: #339933;">.=</span><span style="color: #ff0000;">&quot; fetchall&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$fetchall</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$cmd</span><span style="color: #339933;">.=</span><span style="color: #ff0000;">&quot; ssl&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$usessl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$cmd</span><span style="color: #339933;">.=</span><span style="color: #ff0000;">&quot; &quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$extra_options</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$extra_options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #0000ff;">$text</span><span style="color: #339933;">=</span><span style="color: #cc0000; font-style: italic;">&lt;&lt;TXT;
set postmaster &quot;postmaster&quot;
set nobouncemail
set no spambounce
set properties &quot;&quot;
set syslog
&nbsp;
poll ${src_server} with proto ${protocol}
        $cmd
&nbsp;
TXT</span>
&nbsp;
  <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$file_handler</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> mkstemp<span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;/tmp/fetchmail-all-XXXXX&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> log_and_die <span style="color: #ff0000;">&quot;cannot open/create fetchmail temp file&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">print</span> <span style="color: #0000ff;">$file_handler</span> <span style="color: #0000ff;">$text</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">close</span> <span style="color: #0000ff;">$file_handler</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #0000ff;">$ret</span><span style="color: #339933;">=</span><span style="color: #ff0000;">`/usr/bin/fetchmail -f $filename -i $run_dir/fetchmail.pid`</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066;">unlink</span> <span style="color: #0000ff;">$filename</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #0000ff;">$sql</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;UPDATE fetchmail SET returned_text=&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">quote</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ret</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;, date=now() WHERE id=&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$id</span><span style="color: #339933;">;</span>
  <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">do</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">selectall_arrayref</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$lockmgr</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">unlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$lock_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
closelog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Damit das Skript regelmäßig ausgeführt wird, legen wir einen Cronjob dafür an (als Benutzer <strong>root</strong>). In der hier gezeigten Konfiguration wird das Skript alle 5 Minuten ausgeführt.</p>
<p><em>crontab -e</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">*/</span><span style="color: #000000;">5</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>PFAD<span style="color: #000000; font-weight: bold;">/</span>ZU<span style="color: #000000; font-weight: bold;">/</span>fetchmail.pl <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://johker.ibutho.de/2009/04/07/fetchmail-integration-in-postfixadmin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Der neue Server: Teil 6 Spambekämpfung</title>
		<link>http://johker.ibutho.de/2009/04/01/der-neue-server-teil-6-spambekampfung/</link>
		<comments>http://johker.ibutho.de/2009/04/01/der-neue-server-teil-6-spambekampfung/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 15:55:25 +0000</pubDate>
		<dc:creator>johker</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[amavis]]></category>
		<category><![CDATA[amavisd-new]]></category>
		<category><![CDATA[anti-spam]]></category>
		<category><![CDATA[bash script]]></category>
		<category><![CDATA[bayes]]></category>
		<category><![CDATA[clamav]]></category>
		<category><![CDATA[content filter]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[cronjob]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[detect virus]]></category>
		<category><![CDATA[dkim]]></category>
		<category><![CDATA[dspam]]></category>
		<category><![CDATA[fight junk]]></category>
		<category><![CDATA[fight spam]]></category>
		<category><![CDATA[fight virus]]></category>
		<category><![CDATA[gateway]]></category>
		<category><![CDATA[konfiguration]]></category>
		<category><![CDATA[lmtp]]></category>
		<category><![CDATA[mta]]></category>
		<category><![CDATA[policyd-weight]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[pyzor]]></category>
		<category><![CDATA[razor]]></category>
		<category><![CDATA[sa-compile]]></category>
		<category><![CDATA[sa-learn]]></category>
		<category><![CDATA[sa-update]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[sieve]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[spamassassin]]></category>
		<category><![CDATA[Spambekämpfung]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[Virenfilter]]></category>
		<category><![CDATA[volatile]]></category>

		<guid isPermaLink="false">http://johker.ibutho.de/?p=192</guid>
		<description><![CDATA[Nachfolgend wird erklärt, wie man policyd-weight, amavisd-new, clamav, spamassassin, dspam installiert, konfiguriert und in das bestehende Setup integriert. policyd-weight policyd-weight ist ein effektives Tool zur Spambekämpfung schon vor der Annahme einer E-Mail. Es überprüft das &#8220;Envelope&#8221; und gleicht die Absenderadresse &#8230; <a href="http://johker.ibutho.de/2009/04/01/der-neue-server-teil-6-spambekampfung/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Nachfolgend wird erklärt, wie man <em>policyd-weight</em>, <em>amavisd-new</em>, <em>clamav</em>, <em>spamassassin</em>, <em>dspam</em> installiert, konfiguriert und in das bestehende Setup integriert.</p>
<h1>policyd-weight</h1>
<p><em>policyd-weight</em> ist ein effektives Tool zur Spambekämpfung schon vor der Annahme einer E-Mail. Es überprüft das &#8220;Envelope&#8221; und gleicht die Absenderadresse gegen mehrere DNS-Blacklists ab.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> policyd-weight</pre></div></div>

<p>Danach erstellen wir noch eine Standardkonfiguration für <em>policyd-weight</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">policyd-weight defaults <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>policyd-weight.conf</pre></div></div>

<p>Folgende Zeile in &#8220;<em>/etc/postfix/main.cf</em>&#8221; ändern:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">###  check_policy_service inet:127.0.0.1:12525,</span></pre></div></div>

<p>&#8230; zu:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">check_policy_service inet:127.0.0.1:<span style="color: #000000;">12525</span>,</pre></div></div>

<p>Jetzt muss die <em>postfix</em>-Konfiguration neu geladen werden und <em>policyd-weight</em> neu gestartet werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>policyd-weight restart
postfix reload</pre></div></div>

<h1>amavisd-new</h1>
<p><em>Amavisd-new</em> ist ein Content-Filter, der sich in fast jeden MTA integrieren lässt. Über <em>amavisd-new</em> lassen sich viele verschiedene Tools, wie z.B. <em>ClamAV</em> zur Virenprüfung, <em>Spamassassin</em> zur Spamfilterung oder <em>dspam</em> &#8211; ebenfalls zu Spamfilterung &#8211; integrieren.<br />
Wenn eine E-Mail in <em>postfix</em> ankommt, wird diese an <em>amavis</em> weitergeleitet, überprüft und wieder &#8211; mit zusätzlichen Headern &#8211; an <em>postfix</em> zur Auslieferung zurückgesendet. Natürlich kann man <em>amavis</em> auch so konfigurieren, dass bestimmte Nachrichtentypen, z.B. Virusmails oder Spammails, sofort geblockt werden. Sobald die Nachricht von <em>amavis</em> an postfix zurückgegeben wurde, kann eine automatische Einsortierung in Ordner über <em>sieve</em> folgen (z.B. Spam-Mails nach Junk).</p>
<p>Installation:<br />
Zu &#8220;<em>/etc/apt/sources.list</em>&#8221; hinzufügen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># volatile repository (e.g. for clamav)</span>
deb http:<span style="color: #000000; font-weight: bold;">//</span>volatile.debian.org<span style="color: #000000; font-weight: bold;">/</span>debian-volatile lenny<span style="color: #000000; font-weight: bold;">/</span>volatile main contrib non-free</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> amavisd-new spamassassin clamav clamav-daemon clamav-freshclam pax lha arj <span style="color: #c20cb9; font-weight: bold;">bzip2</span> unrar zoo nomarch <span style="color: #c20cb9; font-weight: bold;">cpio</span> lzop cabextract apt-listchanges libauthen-sasl-perl libdbi-perl dspam libmail-dkim-perl razor pyzor dcc-client libdbd-pg-perl</pre></div></div>

<p>Nun folgt die Konfiguration von <em>amavis</em> (Konfigurationsdateien sind unter &#8220;<em>/etc/amavis/conf.d/</em>&#8221; zu finden). Ich führe jeweils nur geänderte Zeilen auf:</p>
<p><em>01-debian</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$unrar</span>      = <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">'rar'</span>, <span style="color: #ff0000;">'unrar'</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #666666; font-style: italic;">#disabled (non-free, no security support)</span>
<span style="color: #666666; font-style: italic;">#$unrar         = undef;</span>
<span style="color: #007800;">$lha</span>    = <span style="color: #ff0000;">'lha'</span>; <span style="color: #666666; font-style: italic;">#disabled (non-free, no security support)</span>
<span style="color: #666666; font-style: italic;">#$lha   = undef;</span></pre></div></div>

<p><em>05-domain_id</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">@</span>local_domains_acl = <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>;</pre></div></div>

<p><em>05-node_id</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$myhostname</span> = <span style="color: #ff0000;">&quot;mail.domain.tld&quot;</span>;</pre></div></div>

<p><em>15-content_filter_mode</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">@</span>bypass_virus_checks_maps = <span style="color: #7a0874; font-weight: bold;">&#40;</span> 
   \<span style="color: #000000; font-weight: bold;">%</span>bypass_virus_checks, \<span style="color: #000000; font-weight: bold;">@</span>bypass_virus_checks_acl, \<span style="color: #007800;">$bypass_virus_checks_re</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">@</span>bypass_spam_checks_maps = <span style="color: #7a0874; font-weight: bold;">&#40;</span>
   \<span style="color: #000000; font-weight: bold;">%</span>bypass_spam_checks, \<span style="color: #000000; font-weight: bold;">@</span>bypass_spam_checks_acl, \<span style="color: #007800;">$bypass_spam_checks_re</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;</pre></div></div>

<p><em>20-debian_defaults</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$final_virus_destiny</span>      = D_DISCARD;  <span style="color: #666666; font-style: italic;"># (data not lost, see virus quarantine)</span>
<span style="color: #007800;">$final_banned_destiny</span>     = D_PASS;   <span style="color: #666666; font-style: italic;"># D_REJECT when front-end MTA</span>
<span style="color: #007800;">$final_spam_destiny</span>       = D_PASS;
<span style="color: #007800;">$final_bad_header_destiny</span> = D_PASS;     <span style="color: #666666; font-style: italic;"># False-positive prone (for spam)</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># $sa_spam_subject_tag = '***SPAM*** ';</span>
<span style="color: #007800;">$sa_tag_level_deflt</span>  = undef;</pre></div></div>

<p><em>50-user</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$max_servers</span> = <span style="color: #000000;">2</span>;
&nbsp;
<span style="color: #007800;">$policy_bank</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #ff0000;">'MYNETS'</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> = <span style="color: #7a0874; font-weight: bold;">&#123;</span>   <span style="color: #666666; font-style: italic;"># mail originating from @mynetworks</span>
  originating =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000;">1</span>,  <span style="color: #666666; font-style: italic;"># is true in MYNETS by default, but let's make it explicit</span>
  os_fingerprint_method =<span style="color: #000000; font-weight: bold;">&gt;</span> undef,  <span style="color: #666666; font-style: italic;"># don't query p0f for internal clients</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>;
&nbsp;
<span style="color: #007800;">$recipient_delimiter</span> = <span style="color: #ff0000;">'+'</span>;
&nbsp;
<span style="color: #007800;">$warnvirusrecip</span> = <span style="color: #000000;">1</span>;
&nbsp;
<span style="color: #007800;">$mailfrom_notify_admin</span> = <span style="color: #ff0000;">&quot;postmaster\@<span style="color: #007800;">$mydomain</span>&quot;</span>;
<span style="color: #007800;">$mailfrom_notify_recip</span> = <span style="color: #ff0000;">&quot;postmaster\@<span style="color: #007800;">$mydomain</span>&quot;</span>;
<span style="color: #007800;">$mailfrom_notify_spamadmin</span> = <span style="color: #ff0000;">&quot;postmaster\@<span style="color: #007800;">$mydomain</span>&quot;</span>;</pre></div></div>

<p>Jetzt fügen wir noch den <em>clamav</em>-Nutzer der <em>amavis</em>-Gruppe hinzu:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adduser clamav amavis</pre></div></div>

<p>Danach müssen wir Änderungen an der <em>postfix</em>-Konfiguration vornehmen:</p>
<p><em>Zu <em>main.cf</em> hinzufügen</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">content_filter = amavis:<span style="color: #7a0874; font-weight: bold;">&#91;</span>127.0.0.1<span style="color: #7a0874; font-weight: bold;">&#93;</span>:<span style="color: #000000;">10024</span>
receive_override_options = no_address_mappings</pre></div></div>

<p><em>Zu <em>master.cf</em> hinzufügen</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">amavis       unix  -       -       n       -       <span style="color: #000000;">2</span>       lmtp 
    <span style="color: #660033;">-o</span> <span style="color: #007800;">lmtp_data_done_timeout</span>=<span style="color: #000000;">1200</span>
    <span style="color: #660033;">-o</span> <span style="color: #007800;">lmtp_send_xforward_command</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span>
    <span style="color: #660033;">-o</span> <span style="color: #007800;">disable_dns_lookups</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span>
    <span style="color: #660033;">-o</span> <span style="color: #007800;">max_use</span>=<span style="color: #000000;">20</span>
127.0.0.1:<span style="color: #000000;">10025</span> inet n  -       n       -       -       smtpd
    <span style="color: #660033;">-o</span> <span style="color: #007800;">content_filter</span>=
    <span style="color: #660033;">-o</span> <span style="color: #007800;">local_recipient_maps</span>=
    <span style="color: #660033;">-o</span> <span style="color: #007800;">relay_recipient_maps</span>=
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_delay_reject</span>=no
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_restriction_classes</span>=
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_client_restrictions</span>=
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_helo_restrictions</span>=
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_sender_restrictions</span>=
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_recipient_restrictions</span>=permit_mynetworks,reject
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_data_restrictions</span>=reject_unauth_pipelining
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_end_of_data_restrictions</span>=
    <span style="color: #660033;">-o</span> <span style="color: #007800;">mynetworks</span>=127.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span>    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_error_sleep_time</span>=<span style="color: #000000;">0</span>
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_soft_error_limit</span>=<span style="color: #000000;">1001</span>
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_hard_error_limit</span>=<span style="color: #000000;">1000</span>
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_client_connection_count_limit</span>=<span style="color: #000000;">0</span>
    <span style="color: #660033;">-o</span> <span style="color: #007800;">smtpd_client_connection_rate_limit</span>=<span style="color: #000000;">0</span>
    <span style="color: #660033;">-o</span> <span style="color: #007800;">receive_override_options</span>=no_header_body_checks,no_unknown_recipient_checks</pre></div></div>

<p>Zuletzt werden <em>postfix</em>, <em>amavis</em> und <em>clamav</em> neu gestartet:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>postfix restart
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>amavis restart
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>clamav-daemon restart</pre></div></div>

<h2>Testen der Konfiguration</h2>
<p>Zum Testen genügt es eine Mail an den Mailserver zu schicken und sich danach die Header-Informationen anzuschauen. Finden sich ähnliche Header wie die folgenden in der Mail wieder, so wird amavis aufgerufen.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">X-virus-scanned: Debian amavisd-new at domain.tld
X-spam-flag: NO
X-spam-score: <span style="color: #000000;">2.898</span>
X-spam-level: <span style="color: #000000; font-weight: bold;">**</span>
X-spam-status: No, <span style="color: #007800;">score</span>=<span style="color: #000000;">2.898</span> <span style="color: #007800;">required</span>=<span style="color: #000000;">6.31</span> <span style="color: #007800;">tests</span>=<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #007800;">SPF_PASS</span>=-<span style="color: #000000;">0.001</span>, <span style="color: #007800;">TVD_SPACE_RATIO</span>=<span style="color: #000000;">2.899</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Des Weiteren kann man mit folgendem Befehl testen, ob Spam erkannt wird:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sendmail</span> john<span style="color: #000000; font-weight: bold;">@</span>example.com <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>spamassassin<span style="color: #000000; font-weight: bold;">/</span>examples<span style="color: #000000; font-weight: bold;">/</span>sample-spam.txt</pre></div></div>

<p>&#8230; oder Viren:</p>

<div class="wp_syntax"><div class="code"><pre class="test" style="font-family:monospace;">telnet localhost 25
HELO localhost
MAIL FROM: &lt;user@change_to_my_domain.tld&gt;
RCPT TO: &lt;user@change_to_my_domain.tld&gt;
DATA
From: virus-tester
To: undisclosed-recipients:;
Subject: amavisd test - simple - spam test pattern
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
.
&nbsp;
quit</pre></div></div>

<h1>Spamassassin Konfiguration</h1>
<p>Ans Ende der Datei &#8220;/etc/spamassassin/local.cf&#8221; anfügen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">use_bayes <span style="color: #000000;">1</span>
use_bayes_rules <span style="color: #000000;">1</span>
bayes_auto_learn <span style="color: #000000;">1</span>
bayes_auto_expire <span style="color: #000000;">0</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># pyzor</span>
use_pyzor <span style="color: #000000;">1</span>
pyzor_path <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pyzor
&nbsp;
<span style="color: #666666; font-style: italic;"># razor</span>
use_razor2 <span style="color: #000000;">1</span>
razor_config <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>razor<span style="color: #000000; font-weight: bold;">/</span>razor-agent.conf</pre></div></div>

<p><em>/etc/spamassassin/v312.pre</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">loadplugin Mail::SpamAssassin::Plugin::DKIM</pre></div></div>

<p><em>/etc/spamassassin/v320.pre</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">loadplugin Mail::SpamAssassin::Plugin::Shortcircuit
loadplugin Mail::SpamAssassin::Plugin::Rule2XSBody</pre></div></div>

<p>Razor konfigurieren:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">su</span> - amavis
razor-admin <span style="color: #660033;">-create</span></pre></div></div>

<p>Spamassassin-Regeln neu laden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sa-update</pre></div></div>

<h2>Automatische Updates</h2>
<p>Um <em>spamassassin</em> voll auszureizen, richten wir einen <em>cronjob</em> ein über welchen jede Nacht die Regeln auf den neuesten Stand gebracht werden (als <strong>root</strong> ausführen!):</p>
<p><em>/usr/local/sbin/updateSpamassassin</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
sa-update <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
sa-compile <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">crontab <span style="color: #660033;">-e</span>
<span style="color: #000000;">42</span> <span style="color: #000000;">3</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>updateSpamassassin <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</pre></div></div>

<h2>Ham/Spam aus /var/vmail lernen</h2>
<p>Nun erstellen wir noch ein Skript, welches Spam, bzw. Ham aus den Mailboxen der Benutzer lernt (aus den Ordnern &#8220;INBOX&#8221; und &#8220;Junk&#8221;). Dieses Skript rufen wir wöchentlich über einen Cronjob auf.</p>
<p><em>/usr/local/sbin/trainSpamassassin</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">VMAILDIR</span>=<span style="color: #ff0000;">&quot;/var/vmail&quot;</span>
<span style="color: #007800;">SADIR</span>=<span style="color: #ff0000;">&quot;/var/lib/amavis/.spamassassin&quot;</span>
<span style="color: #007800;">DBPATH</span>=<span style="color: #ff0000;">&quot;/var/lib/amavis/.spamassassin/bayes&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$VMAILDIR</span>
<span style="color: #000000; font-weight: bold;">for</span> domain <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-maxdepth</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-not</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #660033;">-type</span> d<span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">domaindir</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$VMAILDIR</span>/<span style="color: #007800;">$domain</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$domaindir</span>
        <span style="color: #000000; font-weight: bold;">for</span> user <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">find</span> .<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-maxdepth</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-not</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #660033;">-type</span> d<span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
                <span style="color: #007800;">maildir</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$domaindir</span>/<span style="color: #007800;">$user</span>/maildir&quot;</span>
                <span style="color: #007800;">inbox</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$maildir</span>/cur&quot;</span>
                <span style="color: #007800;">junk</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$maildir</span>/.Junk/cur&quot;</span>
&nbsp;
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Learning ham from <span style="color: #007800;">$inbox</span>&quot;</span>
                sa-learn <span style="color: #660033;">--ham</span> <span style="color: #660033;">--showdots</span> <span style="color: #660033;">--dbpath</span> <span style="color: #007800;">$DBPATH</span> <span style="color: #007800;">$inbox</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Learning junk from <span style="color: #007800;">$junk</span>&quot;</span>
                sa-learn <span style="color: #660033;">--spam</span> <span style="color: #660033;">--showdots</span> <span style="color: #660033;">--dbpath</span> <span style="color: #007800;">$DBPATH</span> <span style="color: #007800;">$junk</span>
        <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> amavis:amavis <span style="color: #007800;">$SADIR</span></pre></div></div>

<p>Nun noch das Skript in die <em>crontab</em> aufnehmen (als <strong>root</strong> ausführen!):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">crontab <span style="color: #660033;">-e</span>
<span style="color: #000000;">33</span> <span style="color: #000000;">4</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>trainSpamassassin <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</pre></div></div>

<h1>Globale sieve-Regeln</h1>
<p>Um dem Benutzer das Erstellen von <em>sieve</em>-Regeln für Spam zu ersparen, fügen wir in die Datei &#8220;/var/vmail/default.sieve&#8221; folgende Zeile ein, um Spam-Mails automatisch in den Ordner &#8220;Junk&#8221; zu verschieben (<em>sieve</em> wurde schon in Teil 5 dieser Serie konfiguriert):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">require <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;fileinto&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
<span style="color: #666666; font-style: italic;"># Move spam to spam folder</span>
<span style="color: #000000; font-weight: bold;">if</span> header :contains <span style="color: #ff0000;">&quot;X-Spam-Flag&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;YES&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  fileinto <span style="color: #ff0000;">&quot;Junk&quot;</span>;
  stop;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<h1>dspam</h1>
<p>Die Konfiguration von <em>dspam</em> wird nachgereicht.</p>
<p>Quellen:</p>
<p>http://workaround.org/articles/ispmail-etch/#step-5-deliver-emails-through-the-dovecot-lda</p>
<p>http://www200.pair.com/mecham/spam/spamfilter20090215.html#amavisconfig</p>
<p>http://wiki.rootforum.de/mailserver/postfix/clamav_amavisd</p>
<p>http://www.howtoforge.com/virtual-users-domains-postfix-courier-mysql-squirrelmail-debian-lenny-p3</p>
<p>http://www.tuxj0b.de/HOWTO_Mailserver_mit_Postfix_Dovecot_Antispam_und_PostgreSQL_Backend</p>
]]></content:encoded>
			<wfw:commentRss>http://johker.ibutho.de/2009/04/01/der-neue-server-teil-6-spambekampfung/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

