Commit 9745d5bd authored by Jesse Norell's avatar Jesse Norell
Browse files

mail: transport domain must be unique per server

parent ef73cc67
......@@ -8,7 +8,10 @@ class upd_0094 extends installer_patch_update {
global $inst;
// Remove any duplicate mail_forwardings prior to adding unique key
$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)");
$inst->db->query("DELETE FROM mail_forwarding WHERE forwarding_id NOT IN (SELECT MIN(forwarding_id) FROM mail_forwarding GROUP BY source)");
// Remove any duplicate mail_transports prior to adding unique key
$inst->db->query("DELETE FROM mail_transport WHERE transport_id NOT IN (SELECT MIN(transport_id) FROM mail_transport GROUP BY domain, server_id)");
}
}
......@@ -14,3 +14,7 @@ DROP TABLE IF EXISTS `software_package`;
DROP TABLE IF EXISTS `software_repo`;
DROP TABLE IF EXISTS `software_update`;
DROP TABLE IF EXISTS `software_update_inst`;
-- mail_transport.domain must be unique
ALTER TABLE `mail_transport` DROP KEY `server_id_2`;
ALTER TABLE `mail_transport` ADD UNIQUE KEY `server_id_2` (`server_id`, `domain`);
......@@ -1023,7 +1023,7 @@ CREATE TABLE `mail_transport` (
`active` enum('n','y') NOT NULL DEFAULT 'n',
PRIMARY KEY (`transport_id`),
KEY `server_id` (`server_id`,`transport`),
KEY `server_id_2` (`server_id`,`domain`)
UNIQUE KEY `server_id_2` (`server_id`, `domain`)
) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
......
<?php
/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
Copyright (c) 2021, Jesse Norell <jesse@kci.net>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class validate_mail_transport {
function get_error($errmsg) {
global $app;
if(isset($app->tform->wordbook[$errmsg])) {
return $app->tform->wordbook[$errmsg]."<br>\r\n";
} else {
return $errmsg."<br>\r\n";
}
}
/* Validator function for checking the 'domain' of a mail transport */
function validate_domain($field_name, $field_value, $validator) {
global $app, $conf;
if(empty($field_value) || $field_name != 'domain') return;
if(isset($app->remoting_lib->primary_id)) {
$id = $app->remoting_lib->primary_id;
} else {
$id = $app->tform->primary_id;
}
// mail_transport.domain (could also be an email address) must be unique per server
$sql = "SELECT transport_id, domain FROM mail_transport WHERE domain = ? AND server_id = ? AND transport_id != ?";
$domain_check = $app->db->queryOneRecord($sql, $field_value, $conf['server_id'], $id);
if($domain_check) return $this->get_error('domain_error_unique');
}
}
......@@ -88,6 +88,14 @@ $form["tabs"]['transport'] = array (
4 => array( 'event' => 'SAVE',
'type' => 'STRIPNL')
),
'validators' => array(
0 => array(
'type' => 'CUSTOM',
'class' => 'validate_mail_transport',
'function' => 'validate_domain',
'errmsg'=> 'domain_error_unique',
)
),
'default' => '',
'value' => '',
'width' => '30',
......
......@@ -3,9 +3,9 @@ $wb['email_txt'] = 'Email';
$wb['destination_txt'] = 'Destination';
$wb['active_txt'] = 'Active';
$wb['email_error_isemail'] = 'Email address is invalid.';
$wb['email_error_unique'] = 'Duplicate Emailaddress.';
$wb['email_error_unique'] = 'Duplicate Email Address.';
$wb['no_domain_perm'] = 'You have no permission for this domain.';
$wb['destination_error_isemail'] = 'Destination Emailaddress is invalid.';
$wb['destination_error_isemail'] = 'Destination Email Address is invalid.';
$wb['limit_mailalias_txt'] = 'The max. number of email aliases for your account is reached.';
$wb['duplicate_mailbox_txt'] = 'There is already a mailbox with this email address';
$wb['domain_txt'] = 'Domain';
......
......@@ -10,6 +10,6 @@ $wb['greylisting_txt'] = 'Enable greylisting';
$wb['destination_error_empty'] = 'The destination must not be empty.';
$wb['destination_error_isemail'] = 'The destination contains at least one invalid email address.';
$wb['email_error_isemail'] = 'Please enter a valid email address.';
$wb['email_error_unique'] = 'Duplicate Emailaddress.';
$wb['email_error_unique'] = 'Duplicate Email Address.';
$wb['send_as_txt'] = 'Send as';
$wb['send_as_exp'] = 'Allow target to send mail using this address as origin (if target is internal)';
......@@ -8,4 +8,4 @@ $wb['sort_order_txt'] = 'Sort by';
$wb['active_txt'] = 'Active';
$wb['limit_mailrouting_txt'] = 'The max. number of routes for your account is reached.';
$wb['transport_txt'] = 'Transport';
?>
$wb['domain_error_unique'] = 'A mail transport for this Domain already exists on this server.';
......@@ -3,9 +3,9 @@ $wb['email_txt'] = 'Email';
$wb['destination_txt'] = 'Destination';
$wb['active_txt'] = 'Active';
$wb['email_error_isemail'] = 'Email address is invalid.';
$wb['email_error_unique'] = 'Duplicate Emailaddress.';
$wb['email_error_unique'] = 'Duplicate Email Address.';
$wb['no_domain_perm'] = 'You have no permission for this domain.';
$wb['destination_error_isemail'] = 'Destination Emailaddress is invalid.';
$wb['destination_error_isemail'] = 'Destination Email Address is invalid.';
$wb['limit_mailalias_txt'] = 'The max. number of email aliases for your account is reached.';
$wb['duplicate_mailbox_txt'] = 'There is already a mailbox with this email address';
$wb['domain_txt'] = 'Domain';
......
......@@ -10,6 +10,6 @@ $wb['greylisting_txt'] = 'Enable greylisting';
$wb['destination_error_empty'] = 'The destination must not be empty.';
$wb['destination_error_isemail'] = 'The destination contains at least one invalid email address.';
$wb['email_error_isemail'] = 'Please enter a valid email address.';
$wb['email_error_unique'] = 'Duplicate Emailaddress.';
$wb['email_error_unique'] = 'Duplicate Email Address.';
$wb['send_as_txt'] = 'Send as';
$wb['send_as_exp'] = 'Allow target to send mail using this address as origin (if target is internal)';
......@@ -8,4 +8,4 @@ $wb['sort_order_txt'] = 'Сортирай по';
$wb['active_txt'] = 'Активен';
$wb['limit_mailrouting_txt'] = 'The max. number of routes for your account is reached.';
$wb['transport_txt'] = 'Transport';
?>
$wb['domain_error_unique'] = 'A mail transport for this Domain already exists on this server.';
......@@ -8,3 +8,4 @@ $wb['sort_order_txt'] = 'Ordenar por';
$wb['active_txt'] = 'Ativo';
$wb['limit_mailrouting_txt'] = 'O limite de rotas de email para esta conta foi alcançado.';
$wb['transport_txt'] = 'Transporte';
$wb['domain_error_unique'] = 'A mail transport for this Domain already exists on this server.';
......@@ -8,4 +8,4 @@ $wb['sort_order_txt'] = 'Trier par';
$wb['active_txt'] = 'Actif';
$wb['limit_mailrouting_txt'] = 'Le nombre maximal de routes pour votre compte a été atteint.';
$wb['transport_txt'] = 'Transport';
?>
$wb['domain_error_unique'] = 'A mail transport for this Domain already exists on this server.';
......@@ -8,3 +8,4 @@ $wb['sort_order_txt'] = 'Třídit podle';
$wb['active_txt'] = 'Aktivní';
$wb['limit_mailrouting_txt'] = 'Byl dosažen maximální počet e-mail směrování pro Váš účet.';
$wb['transport_txt'] = 'Transport';
$wb['domain_error_unique'] = 'A mail transport for this Domain already exists on this server.';
......@@ -8,4 +8,4 @@ $wb['sort_order_txt'] = 'Sortiert nach';
$wb['active_txt'] = 'Aktiv';
$wb['limit_mailrouting_txt'] = 'Die maximale Anzahl an E-Mail Routen für Ihr Konto wurde erreicht.';
$wb['transport_txt'] = 'Transport';
?>
$wb['domain_error_unique'] = 'A mail transport for this Domain already exists on this server.';
......@@ -8,4 +8,4 @@ $wb['sort_order_txt'] = 'Sort by';
$wb['active_txt'] = 'Aktiv';
$wb['limit_mailrouting_txt'] = 'Max. antal af ruter for din konto er nået.';
$wb['transport_txt'] = 'Transport';
?>
$wb['domain_error_unique'] = 'A mail transport for this Domain already exists on this server.';
......@@ -8,4 +8,4 @@ $wb['sort_order_txt'] = 'Ταξινόμηση κατά';
$wb['active_txt'] = 'Ενεργό';
$wb['limit_mailrouting_txt'] = 'Το μέγιστο πλήθος των δρομολογήσεων email για τον λογαριασμό σας, εξαντλήθηκε.';
$wb['transport_txt'] = 'Transport';
?>
$wb['domain_error_unique'] = 'A mail transport for this Domain already exists on this server.';
......@@ -3,9 +3,9 @@ $wb['email_txt'] = 'Email';
$wb['destination_txt'] = 'Destination';
$wb['active_txt'] = 'Active';
$wb['email_error_isemail'] = 'Email address is invalid.';
$wb['email_error_unique'] = 'Duplicate Emailaddress.';
$wb['email_error_unique'] = 'Duplicate Email Address.';
$wb['no_domain_perm'] = 'You have no permission for this domain.';
$wb['destination_error_isemail'] = 'Destination Emailaddress is invalid.';
$wb['destination_error_isemail'] = 'Destination Email Address is invalid.';
$wb['limit_mailalias_txt'] = 'The max. number of email aliases for your account is reached.';
$wb['duplicate_mailbox_txt'] = 'There is already a mailbox with this email address.';
$wb['domain_txt'] = 'Domain';
......
......@@ -9,7 +9,7 @@ $wb['source_txt'] = 'Source Email';
$wb['destination_error_empty'] = 'The destination must not be empty.';
$wb['destination_error_isemail'] = 'The destination contains at least one invalid email address.';
$wb['email_error_isemail'] = 'Please enter a valid email address.';
$wb['email_error_unique'] = 'Duplicate Emailaddress.';
$wb['email_error_unique'] = 'Duplicate Email Address.';
$wb['send_as_txt'] = 'Send as';
$wb['send_as_exp'] = 'Allow target to send mail using this address as origin (if target is internal)';
$wb['greylisting_txt'] = 'Enable greylisting';
......@@ -8,4 +8,4 @@ $wb['sort_order_txt'] = 'Sort by';
$wb['active_txt'] = 'Active';
$wb['limit_mailrouting_txt'] = 'The max. number of routes for your account is reached.';
$wb['transport_txt'] = 'Transport';
?>
\ No newline at end of file
$wb['domain_error_unique'] = 'A mail transport for this Domain already exists on this server.';
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment