Skip to content

Commit 414a128

Browse files
committed
Add dkim support (patch developed by Florian)
1 parent 9b15981 commit 414a128

File tree

14 files changed

+571
-5
lines changed

14 files changed

+571
-5
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE `mail_domain` ADD `dkim_public` MEDIUMTEXT NOT NULL AFTER `domain`;
2+
ALTER TABLE `mail_domain` ADD `dkim_private` MEDIUMTEXT NOT NULL AFTER `domain`;
3+
ALTER TABLE `mail_domain` ADD `dkim` ENUM( 'n', 'y' ) NOT NULL AFTER `domain`;

install/sql/ispconfig3.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ CREATE TABLE `mail_domain` (
663663
`sys_perm_other` varchar(5) NOT NULL default '',
664664
`server_id` int(11) unsigned NOT NULL default '0',
665665
`domain` varchar(255) NOT NULL default '',
666+
`dkim` ENUM( 'n', 'y' ) NOT NULL default 'n',
667+
`dkim_private` mediumtext NOT NULL default '',
668+
`dkim_public` mediumtext NOT NULL default '',
666669
`active` enum('n','y') NOT NULL,
667670
PRIMARY KEY (`domain_id`),
668671
KEY `server_id` (`server_id`,`domain`),
@@ -2172,4 +2175,4 @@ INSERT INTO `sys_user` (`userid`, `sys_userid`, `sys_groupid`, `sys_perm_user`,
21722175

21732176
INSERT INTO sys_config VALUES ('1','db','db_version','3.0.5.2');
21742177

2175-
SET FOREIGN_KEY_CHECKS = 1;
2178+
SET FOREIGN_KEY_CHECKS = 1;

install/tpl/amavisd_user_config.master

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ $LOGFILE = "/var/log/amavis.log"; # (defaults to empty, no log)
7575
# Set the log_level to 5 for debugging
7676
$log_level = 0; # (defaults to 0)
7777

78+
# DKIM
79+
80+
$enable_dkim_verification = 1;
81+
$enable_dkim_signing = 1; # load DKIM signing code,
82+
@dkim_signature_options_bysender_maps = (
83+
{ '.' => { ttl => 21*24*3600, c => 'relaxed/simple' } } );
7884

7985
#------------ Do not modify anything below this line -------------
8086
1; # insure a defined return

install/tpl/opensuse_amavisd_conf.master

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,5 +778,11 @@ $spam_admin = undef;
778778
$DO_SYSLOG = 1;
779779
$LOGFILE = "/var/log/amavis.log"; # (defaults to empty, no log)
780780

781+
# DKIM
782+
783+
$enable_dkim_verification = 1;
784+
$enable_dkim_signing = 1; # load DKIM signing code,
785+
@dkim_signature_options_bysender_maps = (
786+
{ '.' => { ttl => 21*24*3600, c => 'relaxed/simple' } } );
781787

782788
1; # insure a defined return

install/tpl/server.ini.master

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ backup_mode=rootgz
2121
module=postfix_mysql
2222
maildir_path=/var/vmail/[domain]/[localpart]
2323
homedir_path=/var/vmail
24+
dkim_path=/etc/postfix/dkim
2425
pop3_imap_daemon=courier
2526
mail_filter_syntax=maildrop
2627
mailuser_uid=5000
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2007 - 2013, Till Brehm, projektfarm Gmbh
5+
Copyright (c) 2013, Florian Schaal, info@schaal-24.de
6+
All rights reserved.
7+
8+
Redistribution and use in source and binary forms, with or without modification,
9+
are permitted provided that the following conditions are met:
10+
11+
* Redistributions of source code must retain the above copyright notice,
12+
this list of conditions and the following disclaimer.
13+
* Redistributions in binary form must reproduce the above copyright notice,
14+
this list of conditions and the following disclaimer in the documentation
15+
and/or other materials provided with the distribution.
16+
* Neither the name of ISPConfig nor the names of its contributors
17+
may be used to endorse or promote products derived from this software without
18+
specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
class validate_dkim {
33+
34+
function get_error($errmsg) {
35+
global $app;
36+
if(isset($app->tform->wordbook[$errmsg])) {
37+
return $app->tform->wordbook[$errmsg]."<br>\r\n";
38+
} else {
39+
return $errmsg."<br>\r\n";
40+
}
41+
}
42+
43+
/* Validator function for private DKIM-Key */
44+
function check_private_key($field_name, $field_value, $validator) {
45+
$dkim_enabled=$_POST['dkim'];
46+
if ($dkim_enabled == 'y') {
47+
if (empty($field_value)) return $this->get_error($validator['errmsg']);
48+
exec('echo "'.$field_value.'"|openssl rsa -check',$output,$result);
49+
if($result != 0) return $this->get_error($validator['errmsg']);
50+
}
51+
}
52+
53+
/* Validator function for DKIM Path */
54+
function check_dkim_path($field_name, $field_value, $validator) {
55+
if(empty($field_value)) return $this->get_error($validator['errmsg']);
56+
if (substr(sprintf('%o', fileperms($field_value)),-3) <= 600)
57+
return $this->get_error($validator['errmsg']);
58+
}
59+
60+
}

interface/web/admin/form/server_config.tform.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@
211211
'width' => '40',
212212
'maxlength' => '255'
213213
),
214+
'dkim_path' => array(
215+
'datatype' => 'VARCHAR',
216+
'formtype' => 'TEXT',
217+
'default' => '/var/db/dkim',
218+
'validators' => array ( 0 => array ('type' => 'CUSTOM',
219+
'class' => 'validate_dkim',
220+
'function' => 'check_dkim_path',
221+
'errmsg'=> 'dkim_path_error'),
222+
),
223+
'value' => '',
224+
'width' => '40',
225+
'maxlength' => '255'
226+
),
214227
'pop3_imap_daemon' => array(
215228
'datatype' => 'VARCHAR',
216229
'formtype' => 'SELECT',

interface/web/admin/lib/lang/en_server_config.lng

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ $wb["fastcgi_bin_txt"] = 'FastCGI Bin';
3030
$wb["module_txt"] = 'Module';
3131
$wb["maildir_path_txt"] = 'Maildir Path';
3232
$wb["homedir_path_txt"] = 'Homedir Path';
33+
$wb["dkim_path_txt"] = 'DKIM Path';
34+
$wb["dkim_path_error"] = 'DKIM Path not found or not writeable.';
3335
$wb["mailuser_uid_txt"] = 'Mailuser UID';
3436
$wb["mailuser_gid_txt"] = 'Mailuser GID';
3537
$wb["mailuser_name_txt"] = 'Mailuser Name';

interface/web/admin/templates/server_config_mail_edit.htm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ <h2><tmpl_var name="list_head_txt"></h2>
1919
<label for="homedir_path">{tmpl_var name='homedir_path_txt'}</label>
2020
<input name="homedir_path" id="homedir_path" value="{tmpl_var name='homedir_path'}" size="40" maxlength="255" type="text" class="textInput" />
2121
</div>
22+
<div class="ctrlHolder">
23+
<label for="dkim_path">{tmpl_var name='dkim_path_txt'}</label>
24+
<input name="dkim_path" id="dkim_path" value="{tmpl_var name='dkim_path'}" size="40" maxlength="255" type="text" class="textInput" />
25+
</div>
2226
<div class="ctrlHolder">
2327
<p class="label">{tmpl_var name='pop3_imap_daemon_txt'}</p>
2428
<div class="multiField">
@@ -95,4 +99,4 @@ <h2><tmpl_var name="list_head_txt"></h2>
9599
</div>
96100
</div>
97101

98-
</div>
102+
</div>

interface/web/mail/form/mail_domain.tform.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,33 @@
9898
'maxlength' => '255',
9999
'searchable' => 1
100100
),
101+
'dkim' => array (
102+
'datatype' => 'VARCHAR',
103+
'formtype' => 'CHECKBOX',
104+
'default' => 'n',
105+
'value' => array(0 => 'n',1 => 'y')
106+
),
107+
'dkim_private' => array (
108+
'datatype' => 'TEXT',
109+
'formtype' => 'TEXTAREA',
110+
'default' => '',
111+
'value' => '',
112+
'cols' => '30',
113+
'rows' => '10',
114+
'validators' => array ( 0 => array ('type' => 'CUSTOM',
115+
'class' => 'validate_dkim',
116+
'function' => 'check_private_key',
117+
'errmsg'=> 'dkim_private_key_error'),
118+
),
119+
),
120+
'dkim_public' => array (
121+
'datatype' => 'TEXT',
122+
'formtype' => 'TEXTAREA',
123+
'default' => '',
124+
'value' => '',
125+
'cols' => '30',
126+
'rows' => '10'
127+
),
101128
'active' => array (
102129
'datatype' => 'VARCHAR',
103130
'formtype' => 'CHECKBOX',
@@ -111,4 +138,4 @@
111138
);
112139

113140

114-
?>
141+
?>

0 commit comments

Comments
 (0)