commit | author | age
|
532ae5
|
1 |
<?php |
L |
2 |
/* |
|
3 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
|
4 |
All rights reserved. |
|
5 |
|
|
6 |
Redistribution and use in source and binary forms, with or without modification, |
|
7 |
are permitted provided that the following conditions are met: |
|
8 |
|
|
9 |
* Redistributions of source code must retain the above copyright notice, |
|
10 |
this list of conditions and the following disclaimer. |
|
11 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
12 |
this list of conditions and the following disclaimer in the documentation |
|
13 |
and/or other materials provided with the distribution. |
|
14 |
* Neither the name of ISPConfig nor the names of its contributors |
|
15 |
may be used to endorse or promote products derived from this software without |
|
16 |
specific prior written permission. |
|
17 |
|
|
18 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
19 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
21 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
22 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
23 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
24 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
25 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
26 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
27 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
*/ |
|
29 |
|
|
30 |
|
|
31 |
/****************************************** |
|
32 |
* Begin Form configuration |
|
33 |
******************************************/ |
|
34 |
|
|
35 |
$tform_def_file = "form/mail_domain.tform.php"; |
|
36 |
|
|
37 |
/****************************************** |
|
38 |
* End Form configuration |
|
39 |
******************************************/ |
|
40 |
|
b1a6a5
|
41 |
require_once '../../lib/config.inc.php'; |
MC |
42 |
require_once '../../lib/app.inc.php'; |
532ae5
|
43 |
|
L |
44 |
//* Check permissions for module |
|
45 |
$app->auth->check_module_permissions('mail'); |
|
46 |
|
|
47 |
// Loading classes |
10b4c8
|
48 |
$app->uses('tpl,tform,tform_actions,tools_sites'); |
532ae5
|
49 |
$app->load('tform_actions'); |
L |
50 |
|
|
51 |
class page_action extends tform_actions { |
|
52 |
|
|
53 |
function onShowNew() { |
|
54 |
global $app, $conf; |
|
55 |
|
|
56 |
// we will check only users, not admins |
|
57 |
if($_SESSION["s"]["user"]["typ"] == 'user') { |
|
58 |
if(!$app->tform->checkClientLimit('limit_maildomain')) { |
|
59 |
$app->error($app->tform->wordbook["limit_maildomain_txt"]); |
|
60 |
} |
|
61 |
if(!$app->tform->checkResellerLimit('limit_maildomain')) { |
|
62 |
$app->error('Reseller: '.$app->tform->wordbook["limit_maildomain_txt"]); |
|
63 |
} |
41d7d1
|
64 |
} else { |
SC |
65 |
$settings = $app->getconf->get_global_config('mail'); |
|
66 |
$app->tform->formDef['tabs']['domain']['fields']['server_id']['default'] = intval($settings['default_mailserver']); |
532ae5
|
67 |
} |
L |
68 |
|
|
69 |
parent::onShowNew(); |
|
70 |
} |
|
71 |
|
|
72 |
function onShowEnd() { |
|
73 |
global $app, $conf; |
|
74 |
|
3e94c8
|
75 |
$app->uses('ini_parser,getconf'); |
SC |
76 |
$settings = $app->getconf->get_global_config('domains'); |
|
77 |
|
|
78 |
if($_SESSION["s"]["user"]["typ"] == 'admin' && $settings['use_domain_module'] != 'y') { |
532ae5
|
79 |
// Getting Clients of the user |
ca4b71
|
80 |
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name"; |
b1a6a5
|
81 |
|
532ae5
|
82 |
$clients = $app->db->queryAllRecords($sql); |
L |
83 |
$client_select = ''; |
|
84 |
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>"; |
8ab3cd
|
85 |
//$tmp_data_record = $app->tform->getDataRecord($this->id); |
532ae5
|
86 |
if(is_array($clients)) { |
L |
87 |
foreach( $clients as $client) { |
8ab3cd
|
88 |
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':''; |
615a0a
|
89 |
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n"; |
532ae5
|
90 |
} |
L |
91 |
} |
b1a6a5
|
92 |
$app->tpl->setVar("client_group_id", $client_select); |
532ae5
|
93 |
|
L |
94 |
} elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
95 |
|
|
96 |
// Get the limits of the client |
|
97 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
2af58c
|
98 |
$client = $app->db->queryOneRecord("SELECT client.client_id, client.contact_name, client.default_mailserver, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname, sys_group.name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ? order by client.contact_name", $client_group_id); |
532ae5
|
99 |
|
L |
100 |
// Set the mailserver to the default server of the client |
2af58c
|
101 |
$tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = ?", $client['default_mailserver']); |
b1a6a5
|
102 |
$app->tpl->setVar("server_id", "<option value='$client[default_mailserver]'>$tmp[server_name]</option>"); |
532ae5
|
103 |
unset($tmp); |
L |
104 |
|
3e94c8
|
105 |
if ($settings['use_domain_module'] != 'y') { |
SC |
106 |
// Fill the client select field |
2af58c
|
107 |
$sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ? ORDER BY client.company_name, client.contact_name, sys_group.name"; |
MC |
108 |
$clients = $app->db->queryAllRecords($sql, $client['client_id']); |
|
109 |
$tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client['client_id']); |
3e94c8
|
110 |
$client_select = '<option value="'.$tmp['groupid'].'">'.$client['contactname'].'</option>'; |
SC |
111 |
//$tmp_data_record = $app->tform->getDataRecord($this->id); |
|
112 |
if(is_array($clients)) { |
|
113 |
foreach( $clients as $client) { |
|
114 |
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':''; |
|
115 |
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n"; |
|
116 |
} |
532ae5
|
117 |
} |
3e94c8
|
118 |
$app->tpl->setVar("client_group_id", $client_select); |
532ae5
|
119 |
} |
L |
120 |
} |
|
121 |
|
bd6659
|
122 |
if($_SESSION["s"]["user"]["typ"] != 'admin') |
SJ |
123 |
{ |
|
124 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
cc7a82
|
125 |
$client_mail = $app->db->queryOneRecord("SELECT mail_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
bd6659
|
126 |
|
SJ |
127 |
$client_mail['mail_servers_ids'] = explode(',', $client_mail['mail_servers']); |
|
128 |
|
|
129 |
$only_one_server = count($client_mail['mail_servers_ids']) === 1; |
|
130 |
$app->tpl->setVar('only_one_server', $only_one_server); |
|
131 |
|
|
132 |
if ($only_one_server) { |
|
133 |
$app->tpl->setVar('server_id_value', $client_mail['mail_servers_ids'][0]); |
|
134 |
} |
|
135 |
|
2af58c
|
136 |
$sql = "SELECT server_id, server_name FROM server WHERE server_id IN ?"; |
MC |
137 |
$mail_servers = $app->db->queryAllRecords($sql, $client_mail['mail_servers_ids']); |
bd6659
|
138 |
|
SJ |
139 |
$options_mail_servers = ""; |
|
140 |
|
|
141 |
foreach ($mail_servers as $mail_server) { |
|
142 |
$options_mail_servers .= "<option value='$mail_server[server_id]'>$mail_server[server_name]</option>"; |
|
143 |
} |
|
144 |
|
|
145 |
$app->tpl->setVar("client_server_id", $options_mail_servers); |
|
146 |
unset($options_mail_servers); |
|
147 |
|
|
148 |
} |
|
149 |
|
532ae5
|
150 |
/* |
L |
151 |
* Now we have to check, if we should use the domain-module to select the domain |
|
152 |
* or not |
|
153 |
*/ |
|
154 |
if ($settings['use_domain_module'] == 'y') { |
|
155 |
/* |
|
156 |
* The domain-module is in use. |
|
157 |
*/ |
9ec304
|
158 |
$domains = $app->tools_sites->getDomainModuleDomains("mail_domain", $this->dataRecord["domain"]); |
532ae5
|
159 |
$domain_select = ''; |
L |
160 |
if(is_array($domains) && sizeof($domains) > 0) { |
|
161 |
/* We have domains in the list, so create the drop-down-list */ |
|
162 |
foreach( $domains as $domain) { |
4e18bd
|
163 |
$domain_select .= "<option value=" . $domain['domain_id'] ; |
532ae5
|
164 |
if ($domain['domain'] == $this->dataRecord["domain"]) { |
L |
165 |
$domain_select .= " selected"; |
|
166 |
} |
8c1761
|
167 |
$domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . "</option>\r\n"; |
532ae5
|
168 |
} |
L |
169 |
} |
|
170 |
else { |
|
171 |
/* |
|
172 |
* We have no domains in the domain-list. This means, we can not add ANY new domain. |
|
173 |
* To avoid, that the variable "domain_option" is empty and so the user can |
|
174 |
* free enter a domain, we have to create a empty option! |
|
175 |
*/ |
|
176 |
$domain_select .= "<option value=''></option>\r\n"; |
|
177 |
} |
b1a6a5
|
178 |
$app->tpl->setVar("domain_option", $domain_select); |
b3a7a3
|
179 |
$app->tpl->setVar("domain_module", 1); |
FS |
180 |
} else { |
|
181 |
$app->tpl->setVar("domain_module", 0); |
532ae5
|
182 |
} |
L |
183 |
|
|
184 |
|
|
185 |
// Get the spamfilter policys for the user |
2af58c
|
186 |
$tmp_user = $app->db->queryOneRecord("SELECT policy_id FROM spamfilter_users WHERE email = ?", '@' . $this->dataRecord["domain"]); |
ed1d29
|
187 |
$sql = "SELECT id, policy_name FROM spamfilter_policy WHERE ".$app->tform->getAuthSQL('r')." ORDER BY policy_name"; |
532ae5
|
188 |
$policys = $app->db->queryAllRecords($sql); |
L |
189 |
$policy_select = "<option value='0'>".$app->tform->wordbook["no_policy"]."</option>"; |
|
190 |
if(is_array($policys)) { |
|
191 |
foreach( $policys as $p) { |
|
192 |
$selected = ($p["id"] == $tmp_user["policy_id"])?'SELECTED':''; |
|
193 |
$policy_select .= "<option value='$p[id]' $selected>$p[policy_name]</option>\r\n"; |
|
194 |
} |
|
195 |
} |
b1a6a5
|
196 |
$app->tpl->setVar("policy", $policy_select); |
532ae5
|
197 |
unset($policys); |
L |
198 |
unset($policy_select); |
|
199 |
unset($tmp_user); |
|
200 |
|
|
201 |
if($this->id > 0) { |
|
202 |
//* we are editing a existing record |
|
203 |
$app->tpl->setVar("edit_disabled", 1); |
|
204 |
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]); |
|
205 |
} else { |
|
206 |
$app->tpl->setVar("edit_disabled", 0); |
|
207 |
} |
|
208 |
|
9e0cb0
|
209 |
// load dkim-values |
FS |
210 |
$sql = "SELECT domain, dkim_private, dkim_public, dkim_selector FROM mail_domain WHERE domain_id = ?"; |
|
211 |
$rec = $app->db->queryOneRecord($sql, $app->functions->intval($_GET['id'])); |
|
212 |
$dns_key = str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"),'',$rec['dkim_public']); |
|
213 |
$dns_record = '.' . $rec['dkim_selector'] . '_domainkey._' . $rec['domain'] . '. 3600 TXT v=DKIM1; t=s; p=' . $dns_key; |
|
214 |
$app->tpl->setVar('dkim_selector', $rec['dkim_selector']); |
|
215 |
$app->tpl->setVar('dkim_private', $rec['dkim_private']); |
|
216 |
$app->tpl->setVar('dkim_public', $rec['dkim_public']); |
d48a08
|
217 |
if (!empty($rec['dkim_public'])) $app->tpl->setVar('dns_record', $dns_record); |
9e0cb0
|
218 |
|
532ae5
|
219 |
parent::onShowEnd(); |
L |
220 |
} |
|
221 |
|
|
222 |
function onSubmit() { |
|
223 |
global $app, $conf; |
b1a6a5
|
224 |
|
MC |
225 |
/* check if the domain module is used - and check if the selected domain can be used! */ |
4e18bd
|
226 |
$app->uses('ini_parser,getconf'); |
M |
227 |
$settings = $app->getconf->get_global_config('domains'); |
|
228 |
if ($settings['use_domain_module'] == 'y') { |
3e94c8
|
229 |
if ($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
SC |
230 |
$this->dataRecord['client_group_id'] = $app->tools_sites->getClientIdForDomain($this->dataRecord['domain']); |
|
231 |
} |
b1a6a5
|
232 |
$domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['domain']); |
MC |
233 |
if(!$domain_check) { |
|
234 |
// invalid domain selected |
|
235 |
$app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />"; |
|
236 |
} else { |
|
237 |
$this->dataRecord['domain'] = $domain_check; |
|
238 |
} |
|
239 |
} |
|
240 |
|
|
241 |
if($_SESSION["s"]["user"]["typ"] != 'admin') { |
532ae5
|
242 |
// Get the limits of the client |
604c0c
|
243 |
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
cc7a82
|
244 |
$client = $app->db->queryOneRecord("SELECT limit_maildomain, default_mailserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
532ae5
|
245 |
// When the record is updated |
L |
246 |
if($this->id > 0) { |
|
247 |
// restore the server ID if the user is not admin and record is edited |
2af58c
|
248 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM mail_domain WHERE domain_id = ?", $this->id); |
532ae5
|
249 |
$this->dataRecord["server_id"] = $tmp["server_id"]; |
L |
250 |
unset($tmp); |
|
251 |
// When the record is inserted |
|
252 |
} else { |
f19308
|
253 |
$client['mail_servers_ids'] = explode(',', $client['mail_servers']); |
532ae5
|
254 |
|
f19308
|
255 |
// Check if chosen server is in authorized servers for this client |
SJ |
256 |
if (!(is_array($client['mail_servers_ids']) && in_array($this->dataRecord["server_id"], $client['mail_servers_ids']))) { |
|
257 |
$app->error($app->tform->wordbook['error_not_allowed_server_id']); |
|
258 |
} |
|
259 |
|
532ae5
|
260 |
if($client["limit_maildomain"] >= 0) { |
cc7a82
|
261 |
$tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM mail_domain WHERE sys_groupid = ?", $client_group_id); |
532ae5
|
262 |
if($tmp["number"] >= $client["limit_maildomain"]) { |
L |
263 |
$app->error($app->tform->wordbook["limit_maildomain_txt"]); |
|
264 |
} |
|
265 |
} |
|
266 |
} |
|
267 |
|
|
268 |
// Clients may not set the client_group_id, so we unset them if user is not a admin |
|
269 |
if(!$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]); |
|
270 |
} |
|
271 |
|
|
272 |
//* make sure that the email domain is lowercase |
|
273 |
if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]); |
|
274 |
|
|
275 |
|
|
276 |
parent::onSubmit(); |
|
277 |
} |
|
278 |
|
|
279 |
function onAfterInsert() { |
|
280 |
global $app, $conf; |
|
281 |
|
|
282 |
// Spamfilter policy |
65ea2e
|
283 |
$policy_id = $app->functions->intval($this->dataRecord["policy"]); |
532ae5
|
284 |
if($policy_id > 0) { |
2af58c
|
285 |
$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", '@' . $this->dataRecord["domain"]); |
532ae5
|
286 |
if($tmp_user["id"] > 0) { |
L |
287 |
// There is already a record that we will update |
3a11d2
|
288 |
$app->db->datalogUpdate('spamfilter_users', array("policy_id" => $policy_id), 'id', $tmp_user["id"]); |
532ae5
|
289 |
} else { |
2af58c
|
290 |
$tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ?", $this->id); |
532ae5
|
291 |
// We create a new record |
3a11d2
|
292 |
$insert_data = array( |
MC |
293 |
"sys_userid" => $_SESSION["s"]["user"]["userid"], |
|
294 |
"sys_groupid" => $tmp_domain["sys_groupid"], |
|
295 |
"sys_perm_user" => 'riud', |
|
296 |
"sys_perm_group" => 'riud', |
|
297 |
"sys_perm_other" => '', |
|
298 |
"server_id" => $this->dataRecord["server_id"], |
|
299 |
"priority" => 5, |
|
300 |
"policy_id" => $policy_id, |
|
301 |
"email" => '@' . $this->dataRecord["domain"], |
|
302 |
"fullname" => '@' . $this->dataRecord["domain"], |
|
303 |
"local" => 'Y' |
|
304 |
); |
532ae5
|
305 |
$app->db->datalogInsert('spamfilter_users', $insert_data, 'id'); |
L |
306 |
unset($tmp_domain); |
|
307 |
} |
03aed0
|
308 |
} // endif spamfilter policy |
a5ce43
|
309 |
|
91a394
|
310 |
//* create dns-record with dkim-values if the zone exists |
FS |
311 |
if ( $this->dataRecord['active'] == 'y' && $this->dataRecord['dkim'] == 'y' ) { |
|
312 |
$soa = $app->db->queryOneRecord("SELECT id AS zone, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, server_id, ttl, serial FROM dns_soa WHERE active = 'Y' AND origin = ?", $this->dataRecord['domain'].'.'); |
|
313 |
if ( isset($soa) && !empty($soa) ) $this->update_dns($this->dataRecord, $soa); |
|
314 |
} |
|
315 |
|
532ae5
|
316 |
} |
L |
317 |
|
|
318 |
function onBeforeUpdate() { |
|
319 |
global $app, $conf; |
|
320 |
|
|
321 |
//* Check if the server has been changed |
|
322 |
// We do this only for the admin or reseller users, as normal clients can not change the server ID anyway |
|
323 |
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
2af58c
|
324 |
$rec = $app->db->queryOneRecord("SELECT server_id, domain from mail_domain WHERE domain_id = ?", $this->id); |
532ae5
|
325 |
if($rec['server_id'] != $this->dataRecord["server_id"]) { |
L |
326 |
//* Add a error message and switch back to old server |
|
327 |
$app->tform->errorMessage .= $app->lng('The Server can not be changed.'); |
|
328 |
$this->dataRecord["server_id"] = $rec['server_id']; |
|
329 |
} |
|
330 |
unset($rec); |
|
331 |
//* If the user is neither admin nor reseller |
|
332 |
} else { |
|
333 |
//* We do not allow users to change a domain which has been created by the admin |
2af58c
|
334 |
$rec = $app->db->queryOneRecord("SELECT domain from mail_domain WHERE domain_id = ?", $this->id); |
b1a6a5
|
335 |
if($rec['domain'] != $this->dataRecord["domain"] && $app->tform->checkPerm($this->id, 'u')) { |
532ae5
|
336 |
//* Add a error message and switch back to old server |
L |
337 |
$app->tform->errorMessage .= $app->lng('The Domain can not be changed. Please ask your Administrator if you want to change the domain name.'); |
|
338 |
$this->dataRecord["domain"] = $rec['domain']; |
|
339 |
} |
|
340 |
unset($rec); |
|
341 |
} |
a5ce43
|
342 |
|
532ae5
|
343 |
} |
L |
344 |
|
|
345 |
function onAfterUpdate() { |
|
346 |
global $app, $conf; |
|
347 |
|
|
348 |
// Spamfilter policy |
65ea2e
|
349 |
$policy_id = $app->functions->intval($this->dataRecord["policy"]); |
2af58c
|
350 |
$tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", '@' . $this->dataRecord["domain"]); |
532ae5
|
351 |
if($policy_id > 0) { |
L |
352 |
if($tmp_user["id"] > 0) { |
|
353 |
// There is already a record that we will update |
3a11d2
|
354 |
$app->db->datalogUpdate('spamfilter_users', array("policy_id" => $policy_id), 'id', $tmp_user["id"]); |
532ae5
|
355 |
} else { |
2af58c
|
356 |
$tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ?", $this->id); |
532ae5
|
357 |
// We create a new record |
3a11d2
|
358 |
$insert_data = array( |
MC |
359 |
"sys_userid" => $_SESSION["s"]["user"]["userid"], |
|
360 |
"sys_groupid" => $tmp_domain["sys_groupid"], |
|
361 |
"sys_perm_user" => 'riud', |
|
362 |
"sys_perm_group" => 'riud', |
|
363 |
"sys_perm_other" => '', |
|
364 |
"server_id" => $this->dataRecord["server_id"], |
|
365 |
"priority" => 5, |
|
366 |
"policy_id" => $policy_id, |
|
367 |
"email" => '@' . $this->dataRecord["domain"], |
|
368 |
"fullname" => '@' . $this->dataRecord["domain"], |
|
369 |
"local" => 'Y' |
|
370 |
); |
532ae5
|
371 |
$app->db->datalogInsert('spamfilter_users', $insert_data, 'id'); |
L |
372 |
unset($tmp_domain); |
|
373 |
} |
|
374 |
} else { |
|
375 |
if($tmp_user["id"] > 0) { |
|
376 |
// There is already a record but the user shall have no policy, so we delete it |
|
377 |
$app->db->datalogDelete('spamfilter_users', 'id', $tmp_user["id"]); |
|
378 |
} |
|
379 |
} // endif spamfilter policy |
|
380 |
//** If the domain name or owner has been changed, change the domain and owner in all mailbox records |
|
381 |
if($this->oldDataRecord['domain'] != $this->dataRecord['domain'] || (isset($this->dataRecord['client_group_id']) && $this->oldDataRecord['sys_groupid'] != $this->dataRecord['client_group_id'])) { |
|
382 |
$app->uses('getconf'); |
7fe908
|
383 |
$mail_config = $app->getconf->get_server_config($this->dataRecord["server_id"], 'mail'); |
532ae5
|
384 |
|
L |
385 |
//* Update the mailboxes |
2af58c
|
386 |
$mailusers = $app->db->queryAllRecords("SELECT * FROM mail_user WHERE email like ?", '%@' . $this->oldDataRecord['domain']); |
604c0c
|
387 |
$sys_groupid = $app->functions->intval((isset($this->dataRecord['client_group_id']))?$this->dataRecord['client_group_id']:$this->oldDataRecord['sys_groupid']); |
2af58c
|
388 |
$tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = ?", $client_group_id); |
604c0c
|
389 |
$client_user_id = $app->functions->intval(($tmp['userid'] > 0)?$tmp['userid']:1); |
532ae5
|
390 |
if(is_array($mailusers)) { |
L |
391 |
foreach($mailusers as $rec) { |
|
392 |
// setting Maildir, Homedir, UID and GID |
7fe908
|
393 |
$mail_parts = explode("@", $rec['email']); |
MC |
394 |
$maildir = str_replace("[domain]", $this->dataRecord['domain'], $mail_config["maildir_path"]); |
|
395 |
$maildir = str_replace("[localpart]", $mail_parts[0], $maildir); |
3a11d2
|
396 |
$email = $mail_parts[0].'@'.$this->dataRecord['domain']; |
MC |
397 |
$app->db->datalogUpdate('mail_user', array("maildir" => $maildir, "email" => $email, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailuser_id', $rec['mailuser_id']); |
532ae5
|
398 |
} |
L |
399 |
} |
|
400 |
|
|
401 |
//* Update the aliases |
2af58c
|
402 |
$forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source like ? OR destination like ?", '%@' . $this->oldDataRecord['domain'], '%@' . $this->oldDataRecord['domain']); |
532ae5
|
403 |
if(is_array($forwardings)) { |
L |
404 |
foreach($forwardings as $rec) { |
3a11d2
|
405 |
$destination = str_replace($this->oldDataRecord['domain'], $this->dataRecord['domain'], $rec['destination']); |
MC |
406 |
$source = str_replace($this->oldDataRecord['domain'], $this->dataRecord['domain'], $rec['source']); |
|
407 |
$app->db->datalogUpdate('mail_forwarding', array("source" => $source, "destination" => $destination, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'forwarding_id', $rec['forwarding_id']); |
532ae5
|
408 |
} |
L |
409 |
} |
7fe908
|
410 |
|
532ae5
|
411 |
//* Update the mailinglist |
2af58c
|
412 |
$app->db->query("UPDATE mail_mailinglist SET sys_userid = ?, sys_groupid = ? WHERE domain = ?", $client_user_id, $sys_groupid, $this->oldDataRecord['domain']); |
0df526
|
413 |
|
TB |
414 |
//* Update fetchmail accounts |
2af58c
|
415 |
$fetchmail = $app->db->queryAllRecords("SELECT * FROM mail_get WHERE destination like ?", '%@' . $this->oldDataRecord['domain']); |
0df526
|
416 |
if(is_array($fetchmail)) { |
TB |
417 |
foreach($fetchmail as $rec) { |
3a11d2
|
418 |
$destination = str_replace($this->oldDataRecord['domain'], $this->dataRecord['domain'], $rec['destination']); |
MC |
419 |
$app->db->datalogUpdate('mail_get', array("destination" => $destination, "sys_userid" => $client_user_id, "sys_groupid" => $sys_groupid), 'mailget_id', $rec['mailget_id']); |
0df526
|
420 |
} |
TB |
421 |
} |
|
422 |
|
532ae5
|
423 |
//* Delete the old spamfilter record |
2af58c
|
424 |
$tmp = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = ?", '@' . $this->oldDataRecord["domain"]); |
532ae5
|
425 |
$app->db->datalogDelete('spamfilter_users', 'id', $tmp["id"]); |
L |
426 |
unset($tmp); |
|
427 |
|
|
428 |
} // end if domain name changed |
|
429 |
|
9e0cb0
|
430 |
//* update dns-record when the dkim record was changed |
FS |
431 |
// NOTE: only if the domain-name was not changed |
|
432 |
if ( $this->dataRecord['active'] == 'y' && $this->dataRecord['domain'] == $this->oldDataRecord['domain'] ) { |
|
433 |
$dkim_active = @($this->dataRecord['dkim'] == 'y') ? true : false; |
|
434 |
$selector = @($this->dataRecord['dkim_selector'] != $this->oldDataRecord['dkim_selector']) ? true : false; |
|
435 |
$dkim_private = @($this->dataRecord['dkim_private'] != $this->oldDataRecord['dkim_private']) ? true : false; |
|
436 |
|
91a394
|
437 |
$soa = $app->db->queryOneRecord("SELECT id AS zone, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, server_id, ttl, serial FROM dns_soa WHERE active = 'Y' AND origin = ?", $this->dataRecord['domain'].'.'); |
9e0cb0
|
438 |
|
FS |
439 |
if ( ($selector || $dkim_private || $dkim_active) && $dkim_active ) |
|
440 |
//* create a new record only if the dns-zone exists |
|
441 |
if ( isset($soa) && !empty($soa) ) { |
|
442 |
$this->update_dns($this->dataRecord, $soa); |
|
443 |
} |
91a394
|
444 |
if (! $dkim_active) { |
9e0cb0
|
445 |
// updated existing dmarc-record to policy 'none' |
2af58c
|
446 |
$sql = "SELECT * from dns_rr WHERE name = ? AND data LIKE 'v=DMARC1%' AND " . $app->tform->getAuthSQL('r'); |
MC |
447 |
$rec = $app->db->queryOneRecord($sql, '_dmarc.'.$this->dataRecord['domain'].'.'); |
9e0cb0
|
448 |
if (is_array($rec)) |
FS |
449 |
if (strpos($rec['data'], 'p=none=') === false) { |
|
450 |
$rec['data'] = str_replace(array('quarantine', 'reject'), 'none', $rec['data']); |
|
451 |
$app->db->datalogUpdate('dns_rr', $rec, 'id', $rec['id']); |
|
452 |
$soa_id = $app->functions->intval($soa['zone']); |
|
453 |
$serial = $app->validate_dns->increase_serial($soa["serial"]); |
3a11d2
|
454 |
$app->db->datalogUpdate('dns_soa', array("serial" => $serial), 'id', $soa_id); |
9e0cb0
|
455 |
} |
FS |
456 |
} |
|
457 |
} |
|
458 |
|
|
459 |
} |
|
460 |
|
|
461 |
private function update_dns($dataRecord, $new_rr) { |
|
462 |
global $app, $conf; |
|
463 |
|
|
464 |
// purge old rr-record(s) |
2af58c
|
465 |
$sql = "SELECT * FROM dns_rr WHERE name LIKE ? AND data LIKE 'v=DKIM1%' AND " . $app->tform->getAuthSQL('r') . " ORDER BY serial DESC"; |
MC |
466 |
$rec = $app->db->queryAllRecords($sql, '%._domainkey.'.$dataRecord['domain'].'.'); |
9e0cb0
|
467 |
if (is_array($rec[1])) { |
FS |
468 |
for ($i=1; $i < count($rec); ++$i) |
|
469 |
$app->db->datalogDelete('dns_rr', 'id', $rec[$i]['id']); |
|
470 |
} |
|
471 |
// also delete a dsn-records with same selector |
2af58c
|
472 |
$sql = "SELECT * from dns_rr WHERE name ? AND data LIKE 'v=DKIM1%' AND " . $app->tform->getAuthSQL('r'); |
MC |
473 |
$rec = $app->db->queryAllRecords($sql, '._domainkey.'.$dataRecord['dkim_selector'].'.', $dataRecord['domain']); |
9e0cb0
|
474 |
if (is_array($rec)) |
FS |
475 |
foreach ($rec as $del) |
|
476 |
$app->db->datalogDelete('dns_rr', 'id', $del['id']); |
|
477 |
|
|
478 |
$new_rr['name'] = $dataRecord['dkim_selector'].'._domainkey.'.$dataRecord['domain'].'.'; |
|
479 |
$new_rr['type'] = 'TXT'; |
|
480 |
$new_rr['data'] = 'v=DKIM1; t=s; p='.str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\r","\n"), '', $this->dataRecord['dkim_public']); |
|
481 |
$new_rr['aux'] = 0; |
|
482 |
$new_rr['active'] = 'Y'; |
|
483 |
$new_rr['stamp'] = date('Y-m-d H:i:s'); |
|
484 |
$new_rr['serial'] = $app->validate_dns->increase_serial($new_rr['serial']); |
|
485 |
$app->db->datalogInsert('dns_rr', $new_rr, 'id', $new_rr['zone']); |
91a394
|
486 |
$zone = $app->db->queryOneRecord("SELECT id, serial FROM dns_soa WHERE active = 'Y' AND id = ?", $new_rr['zone']); |
9e0cb0
|
487 |
$new_serial = $app->validate_dns->increase_serial($zone['serial']); |
3a11d2
|
488 |
$app->db->datalogUpdate('dns_soa', array("serial" => $new_serial), 'id', $zone['id']); |
532ae5
|
489 |
} |
L |
490 |
} |
|
491 |
|
|
492 |
$page = new page_action; |
|
493 |
$page->onLoad(); |
|
494 |
|
b1a6a5
|
495 |
?> |