Skip to content

Commit 8ed9a0a

Browse files
committed
mail: mail_relay_domain domain should be unique per server
1 parent d72cc16 commit 8ed9a0a

27 files changed

+146
-5
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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_relay_domain {
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 relay domain */
45+
function validate_domain($field_name, $field_value, $validator) {
46+
global $app, $conf;
47+
48+
if(empty($field_value) || $field_name != 'domain') return;
49+
50+
51+
if(isset($app->remoting_lib->primary_id)) {
52+
$id = $app->remoting_lib->primary_id;
53+
} else {
54+
$id = $app->tform->primary_id;
55+
}
56+
57+
// mail_relay_domain.domain must be unique per server
58+
$sql = "SELECT relay_domain_id, domain FROM mail_relay_domain WHERE domain = ? AND server_id = ? AND relay_domain_id != ?";
59+
$domain_check = $app->db->queryOneRecord($sql, $field_value, $conf['server_id'], $id);
60+
61+
if($domain_check) return $this->get_error('domain_error_unique');
62+
}
63+
64+
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@
110110
'type' => 'STRIPNL'),
111111
),
112112
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
113-
'errmsg'=> 'domain_error_empty'),
114-
1 => array ( 'type' => 'UNIQUE',
115-
'errmsg'=> 'domain_error_unique'),
116-
2 => array ( 'type' => 'ISDOMAIN',
117-
'errmsg'=> 'domain_error_regex'),
113+
'errmsg' => 'domain_error_empty'),
114+
1 => array ( 'type' => 'ISDOMAIN',
115+
'errmsg' => 'domain_error_regex'),
116+
2 => array ( 'type' => 'CUSTOM',
117+
'class' => 'validate_mail_relay_domain',
118+
'function' => 'validate_domain',
119+
'errmsg' => 'domain_error_unique'),
118120
),
119121
'default' => '',
120122
'value' => '',

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ $wb['tab_relay_domain_title'] = 'Relay domain';
44
$wb['server_id_txt'] = 'Server';
55
$wb['active_txt'] = 'Active';
66
$wb['domain_txt'] = 'Domain';
7+
$wb['domain_error_regex'] = 'Invalid domain name.';
8+
$wb['domain_error_empty'] = 'Domain is empty.';
9+
$wb['domain_error_unique'] = 'This Domain already exists as a mail relay domain on this server.';

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ $wb['tab_relay_domain_title'] = 'Relay domain';
44
$wb['server_id_txt'] = 'Сървър';
55
$wb['active_txt'] = 'Активен';
66
$wb['domain_txt'] = 'Домейн';
7+
$wb['domain_error_regex'] = 'Invalid domain name.';
8+
$wb['domain_error_empty'] = 'Полето с домейн е празно.';
9+
$wb['domain_error_unique'] = 'This Domain already exists as a mail relay domain on this server.';

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ $wb['tab_relay_domain_title'] = 'Relay domain';
44
$wb['server_id_txt'] = 'Servidor';
55
$wb['active_txt'] = 'Ativo';
66
$wb['domain_txt'] = 'Domínio';
7+
$wb['domain_error_regex'] = 'O domínio é inválido.';
8+
$wb['domain_error_empty'] = 'O domínio está vazio.';
9+
$wb['domain_error_unique'] = 'This Domain already exists as a mail relay domain on this server.';

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ $wb['tab_relay_domain_title'] = 'Relay domain';
44
$wb['server_id_txt'] = 'Serveur';
55
$wb['active_txt'] = 'Actif';
66
$wb['domain_txt'] = 'Domaine';
7+
$wb['domain_error_regex'] = 'Nom de domaine invalide.';
8+
$wb['domain_error_empty'] = 'Le domain est vide.';
9+
$wb['domain_error_unique'] = 'This Domain already exists as a mail relay domain on this server.';

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ $wb['tab_relay_domain_title'] = 'Relay domain';
44
$wb['server_id_txt'] = 'Server';
55
$wb['active_txt'] = 'Aktivní';
66
$wb['domain_txt'] = 'Doména';
7+
$wb['domain_error_regex'] = 'Neplatný název domény.';
8+
$wb['domain_error_empty'] = 'Doména je prázdná.';
9+
$wb['domain_error_unique'] = 'This Domain already exists as a mail relay domain on this server.';

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ $wb['tab_relay_domain_title'] = 'Relay domain';
44
$wb['server_id_txt'] = 'Server';
55
$wb['active_txt'] = 'Aktiv';
66
$wb['domain_txt'] = 'Domain';
7+
$wb['domain_error_regex'] = 'Domain Name ist nicht gültig.';
8+
$wb['domain_error_empty'] = 'Domain ist leer.';
9+
$wb['domain_error_unique'] = 'This Domain already exists as a mail relay domain on this server.';

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ $wb['tab_relay_domain_title'] = 'Relay domain';
44
$wb['server_id_txt'] = 'Server';
55
$wb['active_txt'] = 'Aktiv';
66
$wb['domain_txt'] = 'Domæne';
7+
$wb['domain_error_regex'] = 'Ugyldigt domæne name.';
8+
$wb['domain_error_empty'] = 'Domæne er tom.';
9+
$wb['domain_error_unique'] = 'This Domain already exists as a mail relay domain on this server.';

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ $wb['tab_relay_domain_title'] = 'Relay domain';
44
$wb['server_id_txt'] = 'Server';
55
$wb['active_txt'] = 'Ενεργό';
66
$wb['domain_txt'] = 'Domain';
7+
$wb['domain_error_regex'] = 'Το όνομα domain δεν είναι έγκυρο/';
8+
$wb['domain_error_empty'] = 'Το Domain είναι άδειο.';
9+
$wb['domain_error_unique'] = 'This Domain already exists as a mail relay domain on this server.';

0 commit comments

Comments
 (0)