Skip to content

Commit b9ea02c

Browse files
author
Florian
committed
DKIM-Modifications
skip writing dkim-values for inactive domains removed the public-dkim-key from the interface added german language-file
1 parent 081fbc6 commit b9ea02c

25 files changed

+927
-54
lines changed

install/dist/lib/opensuse.lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ function configure_postfix($options = '')
265265
$command = 'chmod 755 /var/run/authdaemon.courier-imap';
266266
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
267267

268-
//* Changing maildrop lines in posfix master.cf
268+
//* Changing maildrop lines in posfix master.cf
269269
if(is_file($config_dir.'/master.cf')){
270270
copy($config_dir.'/master.cf', $config_dir.'/master.cf~');
271271
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
@author Florian Schaal, info@schaal-24.de
32+
@copyrighth Florian Schaal, info@schaal-24.de
33+
*/
34+
35+
class validate_dkim {
36+
37+
function get_error($errmsg) {
38+
global $app;
39+
if(isset($app->tform->wordbook[$errmsg])) {
40+
return $app->tform->wordbook[$errmsg]."<br>\r\n";
41+
} else {
42+
return $errmsg."<br>\r\n";
43+
}
44+
}
45+
46+
/**
47+
* Validator function for private DKIM-Key
48+
*/
49+
function check_private_key($field_name, $field_value, $validator) {
50+
$dkim_enabled=$_POST['dkim'];
51+
if ($dkim_enabled == 'y') {
52+
if (empty($field_value)) return $this->get_error($validator['errmsg']);
53+
exec('echo '.escapeshellarg($field_value).'|openssl rsa -check',$output,$result);
54+
if($result != 0) return $this->get_error($validator['errmsg']);
55+
}
56+
}
57+
58+
/**
59+
* Validator function for DKIM Path
60+
* @return boolean - true when the dkim-path exists and is writeable
61+
*/
62+
function check_dkim_path($field_name, $field_value, $validator) {
63+
if(empty($field_value)) return $this->get_error($validator['errmsg']);
64+
if (substr(sprintf('%o', fileperms($field_value)),-3) <= 600)
65+
return $this->get_error($validator['errmsg']);
66+
}
67+
68+
/**
69+
* Check function for DNS-Template
70+
*/
71+
function check_template($field_name, $field_value, $validator) {
72+
$dkim=false;
73+
foreach($field_value as $field ) { if($field == 'DKIM') $dkim=true; }
74+
if ($dkim && $field_value[0]!='DOMAIN') return $this->get_error($validator['errmsg']);
75+
}
76+
77+
/**
78+
* Validator function for $_POST
79+
*
80+
* @return boolean - true if $POST contains a real key-file
81+
*/
82+
function validate_post($key,$value) {
83+
switch ($key) {
84+
case 'public':
85+
if (preg_match("/(^-----BEGIN PUBLIC KEY-----)[a-zA-Z0-9\r\n\/\+=]{1,221}(-----END PUBLIC KEY-----(\n|\r)$)/",$value) === 1) { return true; } else { return false; }
86+
break;
87+
case 'private':
88+
if (preg_match("/(^-----BEGIN RSA PRIVATE KEY-----)[a-zA-Z0-9\r\n\/\+=]{1,850}(-----END RSA PRIVATE KEY-----(\n|\r)$)/",$value) === 1) { return true; } else { return false; }
89+
break;
90+
}
91+
}
92+
}
93+

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@
282282
'formtype' => 'TEXT',
283283
'default' => '/var/lib/amavis/dkim',
284284
'validators' => array ( 0 => array ('type' => 'CUSTOM',
285-
'class' => 'validate_dkim',
286-
'function' => 'check_dkim_path',
287-
'errmsg'=> 'dkim_path_error'),
288-
),
285+
'class' => 'validate_dkim',
286+
'function' => 'check_dkim_path',
287+
'errmsg'=> 'dkim_path_error'),
288+
),
289289
'value' => '',
290290
'width' => '40',
291291
'maxlength' => '255'

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ $wb['fastcgi_bin_txt'] = 'FastCGI Bin';
1919
$wb['module_txt'] = 'Modul';
2020
$wb['maildir_path_txt'] = 'Maildir Pfad';
2121
$wb['homedir_path_txt'] = 'Homedir Pfad';
22-
$wb["dkim_path_txt"] = 'DKIM Pfad';
23-
$wb["dkim_path_error"] = 'DKIM Pfad nicht gefunden oder nicht beschreibbar.';
22+
$wb['dkim_path_txt'] = 'DKIM Pfad';
23+
$wb['dkim_path_error'] = 'DKIM Pfad nicht gefunden oder nicht beschreibbar.';
2424
$wb['mailuser_uid_txt'] = 'Mailbenutzer UID';
2525
$wb['mailuser_gid_txt'] = 'Mailbenutzer GID';
2626
$wb['mailuser_name_txt'] = 'Mailbenutzer Name';

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">
@@ -113,4 +117,4 @@ <h2><tmpl_var name="list_head_txt"></h2>
113117
</div>
114118
</div>
115119

116-
</div>
120+
</div>
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2007, 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+
/******************************************
33+
* Begin Form configuration
34+
******************************************/
35+
36+
$tform_def_file = "form/dns_dkim.tform.php";
37+
38+
/******************************************
39+
* End Form configuration
40+
******************************************/
41+
42+
require_once('../../lib/config.inc.php');
43+
require_once('../../lib/app.inc.php');
44+
45+
//* Check permissions for module
46+
$app->auth->check_module_permissions('dns');
47+
48+
// Loading classes
49+
$app->uses('tpl,tform,tform_actions,validate_dns');
50+
$app->load('tform_actions');
51+
52+
class page_action extends tform_actions {
53+
54+
function onShowNew() {
55+
global $app, $conf;
56+
// we will check only users, not admins
57+
if($_SESSION["s"]["user"]["typ"] == 'user') {
58+
59+
// Get the limits of the client
60+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
61+
$client = $app->db->queryOneRecord("SELECT limit_dns_record FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
62+
63+
// Check if the user may add another record.
64+
if($client["limit_dns_record"] >= 0) {
65+
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = $client_group_id");
66+
if($tmp["number"] >= $client["limit_dns_record"]) {
67+
$app->error($app->tform->wordbook["limit_dns_record_txt"]);
68+
}
69+
}
70+
}
71+
72+
parent::onShowNew();
73+
}
74+
75+
function onSubmit() {
76+
global $app, $conf;
77+
// Get the parent soa record of the domain
78+
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = '".$app->functions->intval($_POST["zone"])."' AND ".$app->tform->getAuthSQL('r'));
79+
// Check if Domain belongs to user
80+
if($soa["id"] != $_POST["zone"]) $app->tform->errorMessage .= $app->tform->wordbook["no_zone_perm"];
81+
82+
// Check the client limits, if user is not the admin
83+
if($_SESSION["s"]["user"]["typ"] != 'admin') { // if user is not admin
84+
// Get the limits of the client
85+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
86+
$client = $app->db->queryOneRecord("SELECT limit_dns_record FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
87+
// Check if the user may add another record.
88+
if($this->id == 0 && $client["limit_dns_record"] >= 0) {
89+
$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = $client_group_id");
90+
if($tmp["number"] >= $client["limit_dns_record"]) {
91+
$app->error($app->tform->wordbook["limit_dns_record_txt"]);
92+
}
93+
}
94+
} // end if user is not admin
95+
96+
// Set the server ID of the rr record to the same server ID as the parent record.
97+
$this->dataRecord["server_id"] = $soa["server_id"];
98+
99+
// add dkim-settings to the public-key in the txt-record
100+
$this->dataRecord['data']='v=DKIM1; t=s; p='.$this->dataRecord['data'];
101+
$this->dataRecord['name']='default._domainkey.'.$this->dataRecord['name'];
102+
103+
// Update the serial number and timestamp of the RR record
104+
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_rr WHERE id = ".$this->id);
105+
$this->dataRecord["serial"] = $app->validate_dns->increase_serial($soa["serial"]);
106+
$this->dataRecord["stamp"] = date('Y-m-d H:i:s');
107+
108+
// check for duplicate entry
109+
$check=$app->db->queryOneRecord("SELECT * FROM dns_rr WHERE zone = ".$this->dataRecord["zone"]." AND type = '".$this->dataRecord["type"]."' AND data ='".$this->dataRecord["data"]."' AND name = '".$this->dataRecord['name']."'");
110+
if ($check!='') $app->tform->errorMessage .= $app->tform->wordbook["record_exists_txt"];
111+
112+
parent::onSubmit();
113+
}
114+
115+
function onAfterInsert() {
116+
global $app, $conf;
117+
118+
//* Set the sys_groupid of the rr record to be the same then the sys_groupid of the soa record
119+
$soa = $app->db->queryOneRecord("SELECT sys_groupid,serial FROM dns_soa WHERE id = '".$app->functions->intval($this->dataRecord["zone"])."' AND ".$app->tform->getAuthSQL('r'));
120+
$app->db->datalogUpdate('dns_rr', "sys_groupid = ".$soa['sys_groupid'], 'id', $this->id);
121+
122+
//* Update the serial number of the SOA record
123+
$soa_id = $app->functions->intval($_POST["zone"]);
124+
$serial = $app->validate_dns->increase_serial($soa["serial"]);
125+
$app->db->datalogUpdate('dns_soa', "serial = $serial", 'id', $soa_id);
126+
}
127+
128+
function onAfterUpdate() {
129+
global $app, $conf;
130+
131+
//* Update the serial number of the SOA record
132+
$soa = $app->db->queryOneRecord("SELECT serial FROM dns_soa WHERE id = '".$app->functions->intval($this->dataRecord["zone"])."' AND ".$app->tform->getAuthSQL('r'));
133+
$soa_id = $app->functions->intval($_POST["zone"]);
134+
$serial = $app->validate_dns->increase_serial($soa["serial"]);
135+
$app->db->datalogUpdate('dns_soa', "serial = $serial", 'id', $soa_id);
136+
}
137+
}
138+
139+
$page = new page_action;
140+
$page->onLoad();
141+
142+
?>

interface/web/dns/dns_dkim_get.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
Copyright (c) 2007 - 2013, Till Brehm, projektfarm Gmbh
4+
Copyright (c) 2013, Florian Schaal, info@schaal-24.de
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
/**
32+
* This script is invoked by interface/web/dns/templates/dns_dkim_edit.htm
33+
* when generating the DKIM Private-key.
34+
*
35+
* return DKIM Public-Key for the DNS-record
36+
*/
37+
38+
require_once('../../lib/config.inc.php');
39+
require_once('../../lib/app.inc.php');
40+
41+
//* Check permissions for module
42+
$app->auth->check_module_permissions('dns');
43+
44+
global $app, $conf;
45+
46+
// Loading classes
47+
$app->uses('tform,tform_actions');
48+
49+
header('Content-Type: text/xml; charset=utf-8');
50+
header('Cache-Control: must-revalidate, pre-check=0, no-store, no-cache, max-age=0, post-check=0');
51+
52+
/**
53+
* This function fix PHP's messing up POST input containing characters space, dot,
54+
* open square bracket and others to be compatible with with the deprecated register_globals
55+
* @return array POST
56+
*/
57+
58+
function getRealPOST() {
59+
$pairs = explode("&", file_get_contents("php://input"));
60+
$vars = array();
61+
foreach ($pairs as $pair) {
62+
$nv = explode("=", $pair, 2);
63+
$name = urldecode($nv[0]);
64+
$value = $nv[1];
65+
$vars[$name] = $value;
66+
}
67+
return $vars;
68+
}
69+
70+
/**
71+
* This function formats the public-key
72+
* @param array $pubkey
73+
* @return string public-key
74+
*/
75+
function pub_key($pubkey) {
76+
$public_key='';
77+
foreach($pubkey as $values) $public_key=$public_key.$values;
78+
return $public_key;
79+
}
80+
81+
$_POST=getRealPost();
82+
83+
if (ctype_digit($_POST['zone'])) {
84+
// Get the parent soa record of the domain
85+
$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = '".$app->db->quote($_POST['zone'])."' AND ".$app->tform->getAuthSQL('r'));
86+
87+
$public_key=$app->db->queryOneRecord("SELECT dkim_public FROM mail_domain WHERE domain = '".substr_replace($soa['origin'],'',-1)."' AND ".$app->tform->getAuthSQL('r'));
88+
89+
$public_key=pub_key($public_key);
90+
91+
$public_key=str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"),'',$public_key);
92+
93+
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
94+
echo "<formatname>\n";
95+
echo "<data>".$public_key."</data>\n";
96+
echo "<name>".$soa['origin']."</name>\n";
97+
echo "</formatname>\n";
98+
}
99+
?>

0 commit comments

Comments
 (0)