Skip to content

Commit c14d6c0

Browse files
author
Marius Burkard
committed
Merge branch '6219-duplicate-mail_transport-domain-are-allowed' into develop
2 parents 6211ded + f8cd496 commit c14d6c0

38 files changed

+115
-37
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ public function onBeforeSQL() {
88
global $inst;
99

1010
// Remove any duplicate mail_forwardings prior to adding unique key
11-
//$inst->db->query("DELETE FROM mail_forwarding WHERE forwarding_id IN (SELECT forwarding_id FROM (SELECT forwarding_id, COUNT(source) AS source_count FROM mail_forwarding GROUP BY source HAVING source_count > 1) as t1)");
11+
//$inst->db->query("DELETE FROM mail_forwarding WHERE forwarding_id NOT IN (SELECT MIN(forwarding_id) FROM mail_forwarding GROUP BY source)");
12+
13+
// Remove any duplicate mail_transports prior to adding unique key
14+
$inst->db->query("DELETE FROM mail_transport WHERE transport_id NOT IN (SELECT MIN(transport_id) FROM mail_transport GROUP BY domain, server_id)");
1215
}
1316

1417
}

install/sql/incremental/upd_dev_collection.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ DROP TABLE IF EXISTS `software_package`;
1414
DROP TABLE IF EXISTS `software_repo`;
1515
DROP TABLE IF EXISTS `software_update`;
1616
DROP TABLE IF EXISTS `software_update_inst`;
17+
18+
-- mail_transport.domain must be unique
19+
ALTER TABLE `mail_transport` DROP KEY `server_id_2`;
20+
ALTER TABLE `mail_transport` ADD UNIQUE KEY `server_id_2` (`server_id`, `domain`);

install/sql/ispconfig3.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ CREATE TABLE `mail_transport` (
10231023
`active` enum('n','y') NOT NULL DEFAULT 'n',
10241024
PRIMARY KEY (`transport_id`),
10251025
KEY `server_id` (`server_id`,`transport`),
1026-
KEY `server_id_2` (`server_id`,`domain`)
1026+
UNIQUE KEY `server_id_2` (`server_id`, `domain`)
10271027
) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
10281028

10291029
-- --------------------------------------------------------
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5+
Copyright (c) 2021, Jesse Norell <jesse@kci.net>
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_mail_transport {
33+
34+
function get_error($errmsg) {
35+
global $app;
36+
37+
if(isset($app->tform->wordbook[$errmsg])) {
38+
return $app->tform->wordbook[$errmsg]."<br>\r\n";
39+
} else {
40+
return $errmsg."<br>\r\n";
41+
}
42+
}
43+
44+
/* Validator function for checking the 'domain' of a mail transport */
45+
function validate_domain($field_name, $field_value, $validator) {
46+
global $app, $conf;
47+
48+
if(isset($app->remoting_lib->primary_id)) {
49+
$id = $app->remoting_lib->primary_id;
50+
} else {
51+
$id = $app->tform->primary_id;
52+
}
53+
54+
// mail_transport.domain (could also be an email address) must be unique per server
55+
$sql = "SELECT transport_id, domain FROM mail_transport WHERE domain = ? AND server_id = ? AND transport_id != ?";
56+
$domain_check = $app->db->queryOneRecord($sql, $field_value, $app->tform_actions->dataRecord['server_id'], $id);
57+
58+
if($domain_check) return $this->get_error('domain_error_unique');
59+
}
60+
61+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@
8888
4 => array( 'event' => 'SAVE',
8989
'type' => 'STRIPNL')
9090
),
91+
'validators' => array(
92+
0 => array(
93+
'type' => 'CUSTOM',
94+
'class' => 'validate_mail_transport',
95+
'function' => 'validate_domain',
96+
'errmsg'=> 'domain_error_unique',
97+
)
98+
),
9199
'default' => '',
92100
'value' => '',
93101
'width' => '30',

interface/web/mail/lib/lang/ar_mail_alias.lng

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ $wb['email_txt'] = 'Email';
33
$wb['destination_txt'] = 'Destination';
44
$wb['active_txt'] = 'Active';
55
$wb['email_error_isemail'] = 'Email address is invalid.';
6-
$wb['email_error_unique'] = 'Duplicate Emailaddress.';
6+
$wb['email_error_unique'] = 'Duplicate Email Address.';
77
$wb['no_domain_perm'] = 'You have no permission for this domain.';
8-
$wb['destination_error_isemail'] = 'Destination Emailaddress is invalid.';
8+
$wb['destination_error_isemail'] = 'Destination Email Address is invalid.';
99
$wb['limit_mailalias_txt'] = 'The max. number of email aliases for your account is reached.';
1010
$wb['duplicate_mailbox_txt'] = 'There is already a mailbox with this email address';
1111
$wb['domain_txt'] = 'Domain';

interface/web/mail/lib/lang/ar_mail_forward.lng

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ $wb['greylisting_txt'] = 'Enable greylisting';
1010
$wb['destination_error_empty'] = 'The destination must not be empty.';
1111
$wb['destination_error_isemail'] = 'The destination contains at least one invalid email address.';
1212
$wb['email_error_isemail'] = 'Please enter a valid email address.';
13-
$wb['email_error_unique'] = 'Duplicate Emailaddress.';
13+
$wb['email_error_unique'] = 'Duplicate Email Address.';
1414
$wb['send_as_txt'] = 'Send as';
1515
$wb['send_as_exp'] = 'Allow target to send mail using this address as origin (if target is internal)';

interface/web/mail/lib/lang/ar_mail_transport.lng

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ $wb['sort_order_txt'] = 'Sort by';
88
$wb['active_txt'] = 'Active';
99
$wb['limit_mailrouting_txt'] = 'The max. number of routes for your account is reached.';
1010
$wb['transport_txt'] = 'Transport';
11-
?>
11+
$wb['domain_error_unique'] = 'A mail transport for this Domain already exists on this server.';

interface/web/mail/lib/lang/bg_mail_alias.lng

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ $wb['email_txt'] = 'Email';
33
$wb['destination_txt'] = 'Destination';
44
$wb['active_txt'] = 'Active';
55
$wb['email_error_isemail'] = 'Email address is invalid.';
6-
$wb['email_error_unique'] = 'Duplicate Emailaddress.';
6+
$wb['email_error_unique'] = 'Duplicate Email Address.';
77
$wb['no_domain_perm'] = 'You have no permission for this domain.';
8-
$wb['destination_error_isemail'] = 'Destination Emailaddress is invalid.';
8+
$wb['destination_error_isemail'] = 'Destination Email Address is invalid.';
99
$wb['limit_mailalias_txt'] = 'The max. number of email aliases for your account is reached.';
1010
$wb['duplicate_mailbox_txt'] = 'There is already a mailbox with this email address';
1111
$wb['domain_txt'] = 'Domain';

interface/web/mail/lib/lang/bg_mail_forward.lng

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ $wb['greylisting_txt'] = 'Enable greylisting';
1010
$wb['destination_error_empty'] = 'The destination must not be empty.';
1111
$wb['destination_error_isemail'] = 'The destination contains at least one invalid email address.';
1212
$wb['email_error_isemail'] = 'Please enter a valid email address.';
13-
$wb['email_error_unique'] = 'Duplicate Emailaddress.';
13+
$wb['email_error_unique'] = 'Duplicate Email Address.';
1414
$wb['send_as_txt'] = 'Send as';
1515
$wb['send_as_exp'] = 'Allow target to send mail using this address as origin (if target is internal)';

0 commit comments

Comments
 (0)