commit | author | age
|
9f94a1
|
1 |
<?php |
MF |
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/xmpp_domain.tform.php"; |
|
36 |
|
|
37 |
/****************************************** |
|
38 |
* End Form configuration |
|
39 |
******************************************/ |
|
40 |
|
|
41 |
require_once '../../lib/config.inc.php'; |
|
42 |
require_once '../../lib/app.inc.php'; |
|
43 |
|
|
44 |
//* Check permissions for module |
|
45 |
$app->auth->check_module_permissions('mail'); |
|
46 |
|
|
47 |
// Loading classes |
|
48 |
$app->uses('tpl,tform,tform_actions,tools_sites'); |
|
49 |
$app->load('tform_actions'); |
|
50 |
|
|
51 |
class page_action extends tform_actions { |
f52de0
|
52 |
var $_xmpp_type = 'server'; |
9f94a1
|
53 |
|
MF |
54 |
function onLoad() { |
|
55 |
$show_type = 'server'; |
f52de0
|
56 |
if(isset($_REQUEST['type']) && $_REQUEST['type'] == 'modules') { |
9f94a1
|
57 |
$show_type = 'modules'; |
f52de0
|
58 |
} elseif(isset($_REQUEST['type']) && $_REQUEST['type'] == 'muc') { |
9f94a1
|
59 |
$show_type = 'muc'; |
f52de0
|
60 |
}elseif(isset($_REQUEST['type']) && $_REQUEST['type'] == 'ssl') { |
MF |
61 |
$show_type = 'ssl'; |
9f94a1
|
62 |
} |
MF |
63 |
|
|
64 |
$_SESSION['s']['var']['xmpp_type'] = $show_type; |
|
65 |
$this->_xmpp_type = $show_type; |
|
66 |
|
|
67 |
parent::onLoad(); |
|
68 |
} |
|
69 |
|
|
70 |
function onShowNew() { |
|
71 |
global $app, $conf; |
|
72 |
|
|
73 |
// we will check only users, not admins |
|
74 |
if($_SESSION["s"]["user"]["typ"] == 'user') { |
36c8a2
|
75 |
if(!$app->tform->checkClientLimit('limit_xmpp_domain')) { |
9f94a1
|
76 |
$app->error($app->tform->wordbook["limit_xmppdomain_txt"]); |
MF |
77 |
} |
36c8a2
|
78 |
if(!$app->tform->checkResellerLimit('limit_xmpp_domain')) { |
9f94a1
|
79 |
$app->error('Reseller: '.$app->tform->wordbook["limit_xmppdomain_txt"]); |
MF |
80 |
} |
|
81 |
} else { |
|
82 |
$settings = $app->getconf->get_global_config('xmpp'); |
36c8a2
|
83 |
} |
MF |
84 |
$app->tform->formDef['tabs']['domain']['fields']['server_id']['default'] = intval($settings['default_xmppserver']); |
9f94a1
|
85 |
|
36c8a2
|
86 |
parent::onShowNew(); |
9f94a1
|
87 |
} |
MF |
88 |
|
|
89 |
function onShowEnd() { |
|
90 |
global $app, $conf; |
|
91 |
|
|
92 |
$app->uses('ini_parser,getconf'); |
|
93 |
$settings = $app->getconf->get_global_config('domains'); |
36c8a2
|
94 |
|
MF |
95 |
$read_limits = array('limit_xmpp_pastebin', 'limit_xmpp_httparchive', 'limit_xmpp_anon', 'limit_xmpp_vjud', 'limit_xmpp_proxy', 'limit_xmpp_status'); |
|
96 |
if($_SESSION["s"]["user"]["typ"] != 'admin') { |
|
97 |
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
cc7a82
|
98 |
$client = $app->db->queryOneRecord("SELECT client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
36c8a2
|
99 |
// add limits to template to be able to hide settings |
MF |
100 |
foreach($read_limits as $limit) $app->tpl->setVar($limit, $client[$limit]); |
|
101 |
}else{ |
|
102 |
foreach($read_limits as $limit) $app->tpl->setVar($limit, 'y'); |
|
103 |
} |
|
104 |
|
9f94a1
|
105 |
|
MF |
106 |
if($_SESSION["s"]["user"]["typ"] == 'admin' && $settings['use_domain_module'] != 'y') { |
|
107 |
// Getting Clients of the user |
|
108 |
$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"; |
|
109 |
|
|
110 |
$clients = $app->db->queryAllRecords($sql); |
|
111 |
$client_select = ''; |
|
112 |
if($_SESSION["s"]["user"]["typ"] == 'admin') $client_select .= "<option value='0'></option>"; |
|
113 |
//$tmp_data_record = $app->tform->getDataRecord($this->id); |
|
114 |
if(is_array($clients)) { |
|
115 |
foreach( $clients as $client) { |
|
116 |
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':''; |
|
117 |
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n"; |
|
118 |
} |
|
119 |
} |
|
120 |
$app->tpl->setVar("client_group_id", $client_select); |
|
121 |
|
|
122 |
} elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
123 |
|
|
124 |
// Get the limits of the client |
|
125 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
2af58c
|
126 |
$client = $app->db->queryOneRecord("SELECT client.client_id, client.contact_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, 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); |
9f94a1
|
127 |
|
MF |
128 |
if ($settings['use_domain_module'] != 'y') { |
|
129 |
// Fill the client select field |
2af58c
|
130 |
$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 |
131 |
$clients = $app->db->queryAllRecords($sql, $client['client_id']); |
|
132 |
$tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client['client_id']); |
9f94a1
|
133 |
$client_select = '<option value="'.$tmp['groupid'].'">'.$client['contactname'].'</option>'; |
MF |
134 |
//$tmp_data_record = $app->tform->getDataRecord($this->id); |
|
135 |
if(is_array($clients)) { |
|
136 |
foreach( $clients as $client) { |
|
137 |
$selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':''; |
|
138 |
$client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n"; |
|
139 |
} |
|
140 |
} |
|
141 |
$app->tpl->setVar("client_group_id", $client_select); |
|
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
if($_SESSION["s"]["user"]["typ"] != 'admin') |
|
146 |
{ |
|
147 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
cc7a82
|
148 |
$client_xmpp = $app->db->queryOneRecord("SELECT xmpp_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
9f94a1
|
149 |
|
MF |
150 |
$client_xmpp['xmpp_servers_ids'] = explode(',', $client_xmpp['xmpp_servers']); |
|
151 |
|
|
152 |
$only_one_server = count($client_xmpp['xmpp_servers_ids']) === 1; |
|
153 |
$app->tpl->setVar('only_one_server', $only_one_server); |
|
154 |
|
|
155 |
if ($only_one_server) { |
|
156 |
$app->tpl->setVar('server_id_value', $client_xmpp['xmpp_servers_ids'][0]); |
|
157 |
} |
|
158 |
|
2af58c
|
159 |
$sql = "SELECT server_id, server_name FROM server WHERE server_id IN ?"; |
MC |
160 |
$xmpp_servers = $app->db->queryAllRecords($sql, $client_xmpp['xmpp_servers_ids']); |
9f94a1
|
161 |
|
MF |
162 |
$options_xmpp_servers = ""; |
|
163 |
|
|
164 |
foreach ($xmpp_servers as $xmpp_server) { |
|
165 |
$options_xmpp_servers .= "<option value='$xmpp_server[server_id]'>$xmpp_server[server_name]</option>"; |
|
166 |
} |
|
167 |
|
|
168 |
$app->tpl->setVar("client_server_id", $options_xmpp_servers); |
|
169 |
unset($options_xmpp_servers); |
|
170 |
|
|
171 |
} |
|
172 |
|
|
173 |
/* |
|
174 |
* Now we have to check, if we should use the domain-module to select the domain |
|
175 |
* or not |
|
176 |
*/ |
|
177 |
if ($settings['use_domain_module'] == 'y') { |
|
178 |
/* |
|
179 |
* The domain-module is in use. |
|
180 |
*/ |
|
181 |
$domains = $app->tools_sites->getDomainModuleDomains("xmpp_domain", $this->dataRecord["domain"]); |
|
182 |
$domain_select = ''; |
|
183 |
if(is_array($domains) && sizeof($domains) > 0) { |
|
184 |
/* We have domains in the list, so create the drop-down-list */ |
|
185 |
foreach( $domains as $domain) { |
|
186 |
$domain_select .= "<option value=" . $domain['domain_id'] ; |
|
187 |
if ($domain['domain'] == $this->dataRecord["domain"]) { |
|
188 |
$domain_select .= " selected"; |
|
189 |
} |
|
190 |
$domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . "</option>\r\n"; |
|
191 |
} |
|
192 |
} |
|
193 |
else { |
|
194 |
/* |
|
195 |
* We have no domains in the domain-list. This means, we can not add ANY new domain. |
|
196 |
* To avoid, that the variable "domain_option" is empty and so the user can |
|
197 |
* free enter a domain, we have to create a empty option! |
|
198 |
*/ |
|
199 |
$domain_select .= "<option value=''></option>\r\n"; |
|
200 |
} |
|
201 |
$app->tpl->setVar("domain_option", $domain_select); |
|
202 |
$app->tpl->setVar("domain_module", 1); |
|
203 |
} else { |
|
204 |
$app->tpl->setVar("domain_module", 0); |
|
205 |
} |
|
206 |
|
|
207 |
|
|
208 |
if($this->id > 0) { |
|
209 |
//* we are editing a existing record |
|
210 |
$app->tpl->setVar("edit_disabled", 1); |
|
211 |
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]); |
|
212 |
} else { |
|
213 |
$app->tpl->setVar("edit_disabled", 0); |
|
214 |
} |
|
215 |
|
|
216 |
|
|
217 |
parent::onShowEnd(); |
|
218 |
} |
|
219 |
|
|
220 |
function onSubmit() { |
|
221 |
global $app, $conf; |
|
222 |
|
|
223 |
/* check if the domain module is used - and check if the selected domain can be used! */ |
|
224 |
$app->uses('ini_parser,getconf'); |
|
225 |
$settings = $app->getconf->get_global_config('domains'); |
|
226 |
if ($settings['use_domain_module'] == 'y') { |
|
227 |
if ($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
228 |
$this->dataRecord['client_group_id'] = $app->tools_sites->getClientIdForDomain($this->dataRecord['domain']); |
|
229 |
} |
|
230 |
$domain_check = $app->tools_sites->checkDomainModuleDomain($this->dataRecord['domain']); |
|
231 |
if(!$domain_check) { |
|
232 |
// invalid domain selected |
|
233 |
$app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />"; |
|
234 |
} else { |
|
235 |
$this->dataRecord['domain'] = $domain_check; |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
if($_SESSION["s"]["user"]["typ"] != 'admin') { |
|
240 |
// Get the limits of the client |
|
241 |
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
cc7a82
|
242 |
$client = $app->db->queryOneRecord("SELECT limit_xmpp_domain FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
9f94a1
|
243 |
// When the record is updated |
MF |
244 |
if($this->id > 0) { |
|
245 |
// restore the server ID if the user is not admin and record is edited |
2af58c
|
246 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM xmpp_domain WHERE domain_id = ?", $this->id); |
9f94a1
|
247 |
$this->dataRecord["server_id"] = $tmp["server_id"]; |
MF |
248 |
unset($tmp); |
|
249 |
// When the record is inserted |
|
250 |
} else { |
|
251 |
$client['xmpp_servers_ids'] = explode(',', $client['xmpp_servers']); |
|
252 |
|
|
253 |
// Check if chosen server is in authorized servers for this client |
|
254 |
if (!(is_array($client['xmpp_servers_ids']) && in_array($this->dataRecord["server_id"], $client['xmpp_servers_ids']))) { |
|
255 |
$app->error($app->tform->wordbook['error_not_allowed_server_id']); |
|
256 |
} |
|
257 |
|
36c8a2
|
258 |
if($client["limit_xmpp_domain"] >= 0) { |
cc7a82
|
259 |
$tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM xmpp_domain WHERE sys_groupid = ?", $client_group_id); |
36c8a2
|
260 |
if($tmp["number"] >= $client["limit_xmpp_domain"]) { |
9f94a1
|
261 |
$app->error($app->tform->wordbook["limit_xmppdomain_txt"]); |
MF |
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
|
|
266 |
// Clients may not set the client_group_id, so we unset them if user is not a admin |
|
267 |
if(!$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]); |
|
268 |
} |
|
269 |
|
|
270 |
//* make sure that the xmpp domain is lowercase |
|
271 |
if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]); |
|
272 |
|
07e1dc
|
273 |
// Read management method |
3e994a
|
274 |
if(isset($this->dataRecord["management_method"])) |
029167
|
275 |
// Set management method to 0 as long as the mailaccount hook is not implemented |
MF |
276 |
$this->dataRecord["management_method"] = 0; |
3e994a
|
277 |
switch($this->dataRecord["management_method"]){ |
9f94a1
|
278 |
case 0: |
3e994a
|
279 |
$this->dataRecord["management_method"] = 'normal'; |
9f94a1
|
280 |
break; |
MF |
281 |
case 1: |
3e994a
|
282 |
$this->dataRecord["management_method"] = 'maildomain'; |
MF |
283 |
// Check for corresponding mail domain |
2af58c
|
284 |
$tmp = $app->db->queryOneRecord("SELECT count(domain_id) AS number FROM mail_domain WHERE domain = ? AND ".$app->tform->getAuthSQL('r')." ORDER BY domain", $this->dataRecord["domain"]); |
536f80
|
285 |
if($tmp['number']==0){ |
3e994a
|
286 |
$app->error($app->tform->wordbook["no_corresponding_maildomain_txt"]); |
MF |
287 |
break; |
|
288 |
} |
9f94a1
|
289 |
break; |
MF |
290 |
} |
|
291 |
// vjud opt mode |
|
292 |
if(isset($this->dataRecord["vjud_opt_mode"])) |
|
293 |
$this->dataRecord["vjud_opt_mode"] = $this->dataRecord["vjud_opt_mode"] == 0 ? 'in' : 'out'; |
|
294 |
if(isset($this->dataRecord["muc_restrict_room_creation"])){ |
|
295 |
switch($this->dataRecord["muc_restrict_room_creation"]){ |
|
296 |
case 0: |
|
297 |
$this->dataRecord["muc_restrict_room_creation"] = 'false'; |
|
298 |
break; |
|
299 |
case 1: |
|
300 |
$this->dataRecord["muc_restrict_room_creation"] = 'member'; |
|
301 |
break; |
|
302 |
case 2: |
|
303 |
$this->dataRecord["muc_restrict_room_creation"] = 'true'; |
|
304 |
break; |
|
305 |
} |
|
306 |
} |
|
307 |
|
cbae4b
|
308 |
// Reset public registration to 'n', is not yet supported |
MF |
309 |
$this->dataRecord["public_registration"] = 'n'; |
|
310 |
|
9f94a1
|
311 |
parent::onSubmit(); |
MF |
312 |
} |
|
313 |
|
|
314 |
function onAfterInsert() { |
|
315 |
global $app, $conf; |
|
316 |
|
|
317 |
// make sure that the record belongs to the client group and not the admin group when admin inserts it |
|
318 |
// also make sure that the user can not delete domain created by a admin |
|
319 |
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) { |
|
320 |
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]); |
2af58c
|
321 |
$app->db->query("UPDATE xmpp_domain SET sys_groupid = ?, sys_perm_group = 'ru' WHERE domain_id = ?", $client_group_id, $this->id); |
9f94a1
|
322 |
} |
MF |
323 |
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) { |
|
324 |
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]); |
2af58c
|
325 |
$app->db->query("UPDATE xmpp_domain SET sys_groupid = ?, sys_perm_group = 'riud' WHERE domain_id = ?", $client_group_id, $this->id); |
9f94a1
|
326 |
} |
MF |
327 |
|
|
328 |
//* make sure that the xmpp domain is lowercase |
|
329 |
if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]); |
3e994a
|
330 |
|
MF |
331 |
// create new accounts from mail domain |
a7d804
|
332 |
//if($this->dataRecord['management_method']=='maildomain') |
MF |
333 |
// $this->syncMailusers($this->dataRecord['domain']); |
9f94a1
|
334 |
|
MF |
335 |
// Insert DNS Records |
|
336 |
$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'].'.'); |
|
337 |
if ( isset($soa) && !empty($soa) ) $this->update_dns($this->dataRecord, $soa); |
|
338 |
} |
|
339 |
|
|
340 |
function onBeforeUpdate() { |
|
341 |
global $app, $conf; |
|
342 |
|
|
343 |
if($this->_xmpp_type == 'server') { |
07e1dc
|
344 |
// Check if the domain has been changed |
2af58c
|
345 |
$rec = $app->db->queryOneRecord("SELECT domain from xmpp_domain WHERE domain_id = ?", $this->id); |
07e1dc
|
346 |
if($this->dataRecord['domain']!=$rec['domain']) |
MF |
347 |
$app->error($app->tform->wordbook["cant_change_domainname_txt"]); |
|
348 |
|
9f94a1
|
349 |
//* Check if the server has been changed |
MF |
350 |
// We do this only for the admin or reseller users, as normal clients can not change the server ID anyway |
|
351 |
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
352 |
if (isset($this->dataRecord["server_id"])) { |
2af58c
|
353 |
$rec = $app->db->queryOneRecord("SELECT server_id from xmpp_domain WHERE domain_id = ?", $this->id); |
9f94a1
|
354 |
if($rec['server_id'] != $this->dataRecord["server_id"]) { |
MF |
355 |
//* Add a error message and switch back to old server |
|
356 |
$app->tform->errorMessage .= $app->lng('The Server can not be changed.'); |
|
357 |
$this->dataRecord["server_id"] = $rec['server_id']; |
|
358 |
} |
|
359 |
unset($rec); |
|
360 |
} |
|
361 |
//* If the user is neither admin nor reseller |
|
362 |
} else { |
|
363 |
//* We do not allow users to change a domain which has been created by the admin |
2af58c
|
364 |
$rec = $app->db->queryOneRecord("SELECT sys_perm_group, domain from xmpp_domain WHERE domain_id = ?", $this->id); |
9f94a1
|
365 |
if(isset($this->dataRecord["domain"]) && $rec['domain'] != $this->dataRecord["domain"] && $app->tform->checkPerm($this->id, 'u')) { |
MF |
366 |
//* Add a error message and switch back to old server |
|
367 |
$app->tform->errorMessage .= $app->lng('The Domain can not be changed. Please ask your Administrator if you want to change the domain name.'); |
|
368 |
$this->dataRecord["domain"] = $rec['domain']; |
|
369 |
} |
|
370 |
unset($rec); |
|
371 |
} |
|
372 |
} |
|
373 |
|
f52de0
|
374 |
if($this->_xmpp_type == 'ssl'){ |
MF |
375 |
//* Check that all fields for the SSL cert creation are filled |
|
376 |
if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'create') { |
|
377 |
if($this->dataRecord['ssl_state'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_state_empty').'<br />'; |
|
378 |
if($this->dataRecord['ssl_locality'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_locality_empty').'<br />'; |
|
379 |
if($this->dataRecord['ssl_organisation'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_organisation_empty').'<br />'; |
|
380 |
if($this->dataRecord['ssl_organisation_unit'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_organisation_unit_empty').'<br />'; |
|
381 |
if($this->dataRecord['ssl_country'] == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_country_empty').'<br />'; |
|
382 |
} |
|
383 |
|
|
384 |
if(isset($this->dataRecord['ssl_action']) && $this->dataRecord['ssl_action'] == 'save') { |
|
385 |
if(trim($this->dataRecord['ssl_cert']) == '') $app->tform->errorMessage .= $app->tform->lng('error_ssl_cert_empty').'<br />'; |
|
386 |
} |
|
387 |
} |
|
388 |
|
9f94a1
|
389 |
//* make sure that the xmpp domain is lowercase |
MF |
390 |
if(isset($this->dataRecord["domain"])) $this->dataRecord["domain"] = strtolower($this->dataRecord["domain"]); |
|
391 |
|
|
392 |
} |
|
393 |
|
|
394 |
function onAfterUpdate() { |
|
395 |
global $app, $conf; |
|
396 |
|
3e994a
|
397 |
// create new accounts from mail domain |
a7d804
|
398 |
//if($this->oldDataRecord['management_method'] != 'maildomain' && $this->dataRecord['management_method']=='maildomain') |
MF |
399 |
// $this->syncMailusers($this->dataRecord['domain']); |
3e994a
|
400 |
// or reset to normal permissions |
a7d804
|
401 |
//elseif($this->oldDataRecord['management_method'] == 'maildomain' && $this->dataRecord['management_method']!='maildomain') |
MF |
402 |
// $this->desyncMailusers($this->dataRecord['domain']); |
9f94a1
|
403 |
// Update DNS Records |
MF |
404 |
// TODO: Update gets only triggered from main form. WHY? |
a7d804
|
405 |
$soa = $app->db->queryOneRecord("SELECT id AS zone, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other FROM dns_soa WHERE active = 'Y' AND = ?", $this->dataRecord['domain'].'.'); |
MF |
406 |
if ( isset($soa) && !empty($soa) ) $this->update_dns($this->dataRecord, $soa); |
9f94a1
|
407 |
} |
MF |
408 |
|
|
409 |
|
|
410 |
|
|
411 |
private function update_dns($dataRecord, $new_rr) { |
|
412 |
global $app, $conf; |
|
413 |
|
2af58c
|
414 |
$rec = $app->db->queryOneRecord("SELECT use_pubsub, use_proxy, use_anon_host, use_vjud, use_muc_host from xmpp_domain WHERE domain_id = ?", $this->id); |
9f94a1
|
415 |
$required_hosts = array('xmpp'); |
MF |
416 |
if($rec['use_pubsub']=='y') |
|
417 |
$required_hosts[] = 'pubsub'; |
|
418 |
if($rec['use_proxy']=='y') |
|
419 |
$required_hosts[] = 'proxy'; |
|
420 |
if($rec['use_anon_host']=='y') |
|
421 |
$required_hosts[] = 'anon'; |
|
422 |
if($rec['use_vjud']=='y') |
|
423 |
$required_hosts[] = 'vjud'; |
|
424 |
if($rec['use_muc_host']=='y') |
|
425 |
$required_hosts[] = 'muc'; |
|
426 |
|
|
427 |
// purge old rr-record |
2af58c
|
428 |
$sql = "SELECT * FROM dns_rr WHERE zone = ? AND (name IN ? AND type = 'CNAME' OR name LIKE ? AND type = 'SRV') AND " . $app->tform->getAuthSQL('r') . " ORDER BY serial DESC"; |
MC |
429 |
$rec = $app->db->queryAllRecords($sql, $new_rr['zone'], array('xmpp', 'pubsub', 'proxy', 'anon', 'vjud', 'muc'), '_xmpp-%'); |
9f94a1
|
430 |
if (is_array($rec[1])) { |
MF |
431 |
for ($i=0; $i < count($rec); ++$i) |
|
432 |
$app->db->datalogDelete('dns_rr', 'id', $rec[$i]['id']); |
|
433 |
} |
|
434 |
|
|
435 |
// create new cname rr-records |
|
436 |
foreach($required_hosts AS $h){ |
|
437 |
$rr = $new_rr; |
|
438 |
$rr['name'] = $h; |
|
439 |
$rr['type'] = 'CNAME'; |
|
440 |
$rr['data'] = 'jalapeno.spicyweb.de.'; |
|
441 |
$rr['aux'] = 0; |
|
442 |
$rr['active'] = 'Y'; |
|
443 |
$rr['stamp'] = date('Y-m-d H:i:s'); |
|
444 |
$rr['serial'] = $app->validate_dns->increase_serial($new_rr['serial']); |
|
445 |
$app->db->datalogInsert('dns_rr', $rr, 'id', $rr['zone']); |
|
446 |
} |
|
447 |
|
|
448 |
//create new srv rr-records |
|
449 |
$rr = $new_rr; |
|
450 |
$rr['name'] = '_xmpp-client._tcp.'.$dataRecord['domain'].'.'; |
|
451 |
$rr['type'] = 'SRV'; |
|
452 |
$rr['data'] = '5 5222 jalapeno.spicyweb.de.'; |
|
453 |
$rr['aux'] = 0; |
|
454 |
$rr['active'] = 'Y'; |
|
455 |
$rr['stamp'] = date('Y-m-d H:i:s'); |
|
456 |
$rr['serial'] = $app->validate_dns->increase_serial($new_rr['serial']); |
|
457 |
$app->db->datalogInsert('dns_rr', $rr, 'id', $rr['zone']); |
|
458 |
$rr = $new_rr; |
|
459 |
$rr['name'] = '_xmpp-server._tcp.'.$dataRecord['domain'].'.'; |
|
460 |
$rr['type'] = 'SRV'; |
|
461 |
$rr['data'] = '5 5269 jalapeno.spicyweb.de.'; |
|
462 |
$rr['aux'] = 0; |
|
463 |
$rr['active'] = 'Y'; |
|
464 |
$rr['stamp'] = date('Y-m-d H:i:s'); |
|
465 |
$rr['serial'] = $app->validate_dns->increase_serial($new_rr['serial']); |
|
466 |
$app->db->datalogInsert('dns_rr', $rr, 'id', $rr['zone']); |
|
467 |
|
|
468 |
// Refresh zone |
|
469 |
$zone = $app->db->queryOneRecord("SELECT id, serial FROM dns_soa WHERE active = 'Y' AND id = ?", $new_rr['zone']); |
|
470 |
$new_serial = $app->validate_dns->increase_serial($zone['serial']); |
3a11d2
|
471 |
$app->db->datalogUpdate('dns_soa', array("serial" => $new_serial), 'id', $zone['id']); |
9f94a1
|
472 |
} |
MF |
473 |
|
a7d804
|
474 |
/* |
MF |
475 |
* NOT YET FINISHED |
9f94a1
|
476 |
|
3e994a
|
477 |
private function syncMailusers($domain){ |
MF |
478 |
global $app, $conf; |
|
479 |
// get all mailusers |
|
480 |
$db_mailusers = $app->db->queryAllRecords("SELECT email, password, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other FROM mail_user WHERE email like ?", '@'.$this->dataRecord['domain'].'.'); |
|
481 |
// get existing xmpp users |
|
482 |
$db_xmppusers = $app->db->queryAllRecords("SELECT jid, password, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other FROM xmpp_user WHERE jid like ?", '@'.$this->dataRecord['domain'].'.'); |
|
483 |
|
|
484 |
// Migrate user accounts |
|
485 |
$users_delete = array(); |
|
486 |
$users_update = array(); |
|
487 |
$users_create = array(); |
|
488 |
foreach($db_xmppusers AS $ix=>$x){ |
|
489 |
$matched = false; |
|
490 |
foreach($db_mailusers AS $im=>$m){ |
|
491 |
if($x['jid']==$m['email']){ |
|
492 |
// User matched, mark for update |
|
493 |
$x['password'] = $m['password']; |
|
494 |
$users_update[] = $x; |
|
495 |
unset($db_xmppusers[$ix]); |
|
496 |
unset($db_mailusers[$im]); |
|
497 |
$matched = true; |
|
498 |
break; |
|
499 |
} |
|
500 |
} |
|
501 |
// XMPP user not matched, mark for deletion |
|
502 |
if(!$matched){ |
|
503 |
$users_delete[] = $x; |
|
504 |
unset($db_xmppusers[$ix]); |
|
505 |
} |
|
506 |
} |
|
507 |
// Mark remaining mail users for creation |
|
508 |
$users_create = $db_xmppusers; |
|
509 |
foreach($users_create AS $u){ |
|
510 |
$u['server_id'] = $this->dataRecord['server_id']; |
|
511 |
$u['sys_perm_user'] = 'r'; |
|
512 |
$u['sys_perm_group'] = 'r'; |
|
513 |
$app->db->datalogInsert('xmpp_user', $u, 'xmppuser_id'); |
|
514 |
} |
|
515 |
foreach($users_update AS $u){ |
|
516 |
$u['sys_perm_user'] = 'r'; |
|
517 |
$u['sys_perm_group'] = 'r'; |
|
518 |
$app->db->datalogUpdate('xmpp_user', $u, 'xmppuser_id', $u['xmppuser_id']); |
|
519 |
} |
|
520 |
foreach($users_delete AS $u){ |
|
521 |
$app->db->datalogDelete('xmpp_user', 'xmppuser_id', $u['xmppuser_id']); |
|
522 |
} |
|
523 |
|
|
524 |
} |
|
525 |
|
|
526 |
private function desyncMailusers($domain){ |
|
527 |
global $app, $conf; |
|
528 |
// get existing xmpp users |
|
529 |
$db_xmppusers = $app->db->queryAllRecords("SELECT jid, password, sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other FROM xmpp_user WHERE jid like ?", '@'.$this->dataRecord['domain'].'.'); |
|
530 |
foreach($db_xmppusers AS $u){ |
|
531 |
$u['sys_perm_user'] = 'riud'; |
|
532 |
$u['sys_perm_group'] = 'riud'; |
|
533 |
$app->db->datalogUpdate('xmpp_user', $u, 'xmppuser_id', $u['xmppuser_id']); |
|
534 |
} |
|
535 |
} |
a7d804
|
536 |
*/ |
3e994a
|
537 |
|
9f94a1
|
538 |
} |
MF |
539 |
|
|
540 |
$page = new page_action; |
|
541 |
$page->onLoad(); |
|
542 |
|
|
543 |
?> |