commit | author | age
|
cfa9da
|
1 |
<?php |
T |
2 |
/* |
|
3 |
Copyright (c) 2008, 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/database.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'; |
cfa9da
|
43 |
|
T |
44 |
//* Check permissions for module |
|
45 |
$app->auth->check_module_permissions('sites'); |
|
46 |
|
|
47 |
// Loading classes |
|
48 |
$app->uses('tpl,tform,tform_actions'); |
|
49 |
$app->load('tform_actions'); |
|
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') { |
3cebc3
|
58 |
if(!$app->tform->checkClientLimit('limit_database')) { |
T |
59 |
$app->error($app->tform->wordbook["limit_database_txt"]); |
|
60 |
} |
|
61 |
if(!$app->tform->checkResellerLimit('limit_database')) { |
|
62 |
$app->error('Reseller: '.$app->tform->wordbook["limit_database_txt"]); |
cfa9da
|
63 |
} |
41d7d1
|
64 |
} else { |
SC |
65 |
$settings = $app->getconf->get_global_config('sites'); |
|
66 |
$app->tform->formDef['tabs']['database']['fields']['server_id']['default'] = intval($settings['default_dbserver']); |
cfa9da
|
67 |
} |
T |
68 |
|
|
69 |
parent::onShowNew(); |
|
70 |
} |
|
71 |
|
|
72 |
function onShowEnd() { |
|
73 |
global $app, $conf, $interfaceConf; |
|
74 |
|
|
75 |
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
76 |
|
|
77 |
// Get the limits of the client |
|
78 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
323f1f
|
79 |
$client = $app->db->queryOneRecord("SELECT db_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
cfa9da
|
80 |
|
T |
81 |
// Set the webserver to the default server of the client |
cc7a82
|
82 |
$tmp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE server_id IN ?", explode(',', $client['db_servers'])); |
bd6659
|
83 |
|
SJ |
84 |
$only_one_server = count($tmp) === 1; |
|
85 |
$app->tpl->setVar('only_one_server', $only_one_server); |
|
86 |
|
|
87 |
if ($only_one_server) { |
|
88 |
$app->tpl->setVar('server_id_value', $tmp[0]['server_id']); |
|
89 |
} |
|
90 |
|
|
91 |
foreach ($tmp as $db_server) { |
75b7fc
|
92 |
$options_db_servers .= '<option value="'.$db_server['server_id'].'"'.($this->id > 0 && $this->dataRecord["server_id"] == $db_server['server_id'] ? ' selected="selected"' : '').'>'.$db_server['server_name'].'</option>'; |
bd6659
|
93 |
} |
SJ |
94 |
|
|
95 |
$app->tpl->setVar("server_id", $options_db_servers); |
cfa9da
|
96 |
unset($tmp); |
T |
97 |
|
|
98 |
} elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
99 |
|
|
100 |
// Get the limits of the client |
|
101 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
323f1f
|
102 |
$client = $app->db->queryOneRecord("SELECT client.client_id, limit_web_domain, db_servers, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); |
b1a6a5
|
103 |
|
cfa9da
|
104 |
// Set the webserver to the default server of the client |
cc7a82
|
105 |
$tmp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE server_id IN ?", explode(',', $client['db_servers'])); |
bd6659
|
106 |
|
SJ |
107 |
$only_one_server = count($tmp) === 1; |
|
108 |
$app->tpl->setVar('only_one_server', $only_one_server); |
|
109 |
|
|
110 |
if ($only_one_server) { |
|
111 |
$app->tpl->setVar('server_id_value', $tmp[0]['server_id']); |
|
112 |
} |
|
113 |
|
|
114 |
foreach ($tmp as $db_server) { |
75b7fc
|
115 |
$options_db_servers .= '<option value="'.$db_server['server_id'].'"'.($this->id > 0 && $this->dataRecord["server_id"] == $db_server['server_id'] ? ' selected="selected"' : '').'>'.$db_server['server_name'].'</option>'; |
bd6659
|
116 |
} |
SJ |
117 |
|
|
118 |
$app->tpl->setVar("server_id", $options_db_servers); |
cfa9da
|
119 |
unset($tmp); |
T |
120 |
|
|
121 |
} else { |
|
122 |
|
|
123 |
// The user is admin |
|
124 |
if($this->id > 0) { |
|
125 |
$server_id = $this->dataRecord["server_id"]; |
|
126 |
} else { |
|
127 |
// Get the first server ID |
|
128 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1"); |
|
129 |
$server_id = $tmp['server_id']; |
|
130 |
} |
|
131 |
|
|
132 |
} |
|
133 |
|
|
134 |
/* |
|
135 |
* If the names are restricted -> remove the restriction, so that the |
|
136 |
* data can be edited |
|
137 |
*/ |
b1a6a5
|
138 |
|
cfa9da
|
139 |
//* Get the database name and database user prefix |
31f6ce
|
140 |
$app->uses('getconf,tools_sites'); |
cfa9da
|
141 |
$global_config = $app->getconf->get_global_config('sites'); |
31f6ce
|
142 |
$dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); |
b1a6a5
|
143 |
|
cfa9da
|
144 |
if ($this->dataRecord['database_name'] != ""){ |
T |
145 |
/* REMOVE the restriction */ |
10b4c8
|
146 |
$app->tpl->setVar("database_name", $app->tools_sites->removePrefix($this->dataRecord['database_name'], $this->dataRecord['database_name_prefix'], $dbname_prefix)); |
cfa9da
|
147 |
} |
b1a6a5
|
148 |
|
ba18a8
|
149 |
if($this->dataRecord['database_name'] == "") { |
07c297
|
150 |
$app->tpl->setVar("database_name_prefix", $dbname_prefix); |
SC |
151 |
} else { |
|
152 |
$app->tpl->setVar("database_name_prefix", $app->tools_sites->getPrefix($this->dataRecord['database_name_prefix'], $dbname_prefix, $global_config['dbname_prefix'])); |
|
153 |
} |
b1a6a5
|
154 |
|
32f2de
|
155 |
if($this->id > 0) { |
T |
156 |
//* we are editing a existing record |
9e247a
|
157 |
$edit_disabled = @($_SESSION["s"]["user"]["typ"] == 'admin')? 0 : 1; //* admin can change the database-name |
FS |
158 |
$app->tpl->setVar("edit_disabled", $edit_disabled); |
6a8d0d
|
159 |
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]); |
T |
160 |
$app->tpl->setVar("database_charset_value", $this->dataRecord["database_charset"]); |
323f1f
|
161 |
$app->tpl->setVar("limit_database_quota", $this->dataRecord["database_quota"]); |
32f2de
|
162 |
} else { |
6a8d0d
|
163 |
$app->tpl->setVar("edit_disabled", 0); |
32f2de
|
164 |
} |
cfa9da
|
165 |
|
T |
166 |
parent::onShowEnd(); |
|
167 |
} |
|
168 |
|
|
169 |
function onSubmit() { |
|
170 |
global $app, $conf; |
|
171 |
|
cc7a82
|
172 |
$parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["parent_domain_id"]); |
b1a6a5
|
173 |
if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm"); |
MC |
174 |
|
cfa9da
|
175 |
if($_SESSION["s"]["user"]["typ"] != 'admin') { |
T |
176 |
// Get the limits of the client |
|
177 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
9d9833
|
178 |
$client = $app->db->queryOneRecord("SELECT db_servers, limit_database, limit_database_quota, parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.groupid = ?", $client_group_id); |
cfa9da
|
179 |
|
T |
180 |
// When the record is updated |
|
181 |
if($this->id > 0) { |
|
182 |
// restore the server ID if the user is not admin and record is edited |
323f1f
|
183 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE database_id = ?", $app->functions->intval($this->id)); |
cfa9da
|
184 |
$this->dataRecord["server_id"] = $tmp["server_id"]; |
T |
185 |
unset($tmp); |
323f1f
|
186 |
//* Check client quota |
FS |
187 |
if ($client['limit_database_quota'] >= 0) { |
|
188 |
//* get the database prefix |
|
189 |
$app->uses('getconf,tools_sites'); |
|
190 |
$global_config = $app->getconf->get_global_config('sites'); |
|
191 |
$dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); |
|
192 |
//* get quota from other databases |
|
193 |
$tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = ? AND database_name <> ?", $client_group_id, $dbname_prefix.$this->dataRecord['database_name']); |
|
194 |
$used_quota = $app->functions->intval($tmp['db_quota']); |
|
195 |
$new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]); |
|
196 |
if(($used_quota + $new_db_quota > $client['limit_database_quota']) || ($new_db_quota < 0 && $client['limit_database_quota'] >= 0)) { |
|
197 |
$max_free_quota = floor($client['limit_database_quota'] - $used_quota); |
|
198 |
if($max_free_quota < 0) { |
|
199 |
$max_free_quota = 0; |
|
200 |
} |
|
201 |
$app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>"; |
|
202 |
$this->dataRecord['database_quota'] = $max_free_quota; |
|
203 |
} |
|
204 |
unset($tmp); |
|
205 |
unset($global_config); |
|
206 |
unset($dbname_prefix); |
|
207 |
} |
9d7676
|
208 |
|
SC |
209 |
if($client['parent_client_id'] > 0) { |
|
210 |
// Get the limits of the reseller |
cc7a82
|
211 |
$reseller = $app->db->queryOneRecord("SELECT limit_database, limit_database_quota FROM client WHERE client_id = ?", $client['parent_client_id']); |
9d7676
|
212 |
|
SC |
213 |
//* Check the website quota of the client |
|
214 |
if ($reseller['limit_database_quota'] >= 0) { |
|
215 |
//* get the database prefix |
|
216 |
$app->uses('getconf,tools_sites'); |
|
217 |
$global_config = $app->getconf->get_global_config('sites'); |
|
218 |
$dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); |
|
219 |
//* get quota from other databases |
|
220 |
$tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database, sys_group, client WHERE web_database.sys_groupid=sys_group.groupid AND sys_group.client_id=client.client_id AND ? IN (client.parent_client_id, client.client_id) AND database_name <> ?", $client['parent_client_id'], $dbname_prefix.$this->dataRecord['database_name']); |
|
221 |
|
|
222 |
$used_quota = $app->functions->intval($tmp['db_quota']); |
|
223 |
$new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]); |
|
224 |
if(($used_quota + $new_db_quota > $reseller["limit_database_quota"]) || ($new_db_quota < 0 && $reseller["limit_database_quota"] >= 0)) { |
|
225 |
$max_free_quota = floor($reseller["limit_database_quota"] - $used_quota); |
|
226 |
if($max_free_quota < 0) $max_free_quota = 0; |
|
227 |
$app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>"; |
|
228 |
$this->dataRecord["database_quota"] = $max_free_quota; |
|
229 |
} |
|
230 |
unset($tmp); |
|
231 |
unset($global_config); |
|
232 |
unset($dbname_prefix); |
|
233 |
} |
|
234 |
} |
cfa9da
|
235 |
// When the record is inserted |
T |
236 |
} else { |
f19308
|
237 |
$client['db_servers_ids'] = explode(',', $client['db_servers']); |
cfa9da
|
238 |
|
f19308
|
239 |
// Check if chosen server is in authorized servers for this client |
SJ |
240 |
if (!(is_array($client['db_servers_ids']) && in_array($this->dataRecord["server_id"], $client['db_servers_ids'])) && $_SESSION["s"]["user"]["typ"] != 'admin') { |
|
241 |
$app->error($app->tform->wordbook['error_not_allowed_server_id']); |
|
242 |
} |
cfa9da
|
243 |
|
T |
244 |
// Check if the user may add another database |
|
245 |
if($client["limit_database"] >= 0) { |
323f1f
|
246 |
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = ?", $client_group_id); |
cfa9da
|
247 |
if($tmp["number"] >= $client["limit_database"]) { |
T |
248 |
$app->error($app->tform->wordbook["limit_database_txt"]); |
|
249 |
} |
|
250 |
} |
|
251 |
|
323f1f
|
252 |
//* Check client quota |
FS |
253 |
if ($client['limit_database_quota'] >= 0) { |
|
254 |
$tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = ?", $client_group_id); |
0543b2
|
255 |
$db_quota = $tmp['db_quota']; |
F |
256 |
$new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]); |
|
257 |
if(($db_quota + $new_db_quota > $client['limit_database_quota']) || ($new_db_quota < 0 && $client['limit_database_quota'] >= 0)) { |
|
258 |
$max_free_quota = floor($client['limit_database_quota'] - $db_quota); |
|
259 |
if($max_free_quota < 0) $max_free_quota = 0; |
|
260 |
$app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>"; |
|
261 |
$this->dataRecord['database_quota'] = $max_free_quota; |
|
262 |
} |
|
263 |
unset($tmp); |
|
264 |
} |
cfa9da
|
265 |
} |
bfcdef
|
266 |
} else { |
b1a6a5
|
267 |
// check if client of database parent domain is client of db user! |
cc7a82
|
268 |
$web_group = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ?", $this->dataRecord['parent_domain_id']); |
b1a6a5
|
269 |
if($this->dataRecord['database_user_id']) { |
cc7a82
|
270 |
$group = $app->db->queryOneRecord("SELECT sys_groupid FROM web_database_user WHERE database_user_id = ?", $this->dataRecord['database_user_id']); |
b1a6a5
|
271 |
if($group['sys_groupid'] != $web_group['sys_groupid']) { |
MC |
272 |
$app->error($app->tform->wordbook['database_client_differs_txt']); |
|
273 |
} |
|
274 |
} |
|
275 |
if($this->dataRecord['database_ro_user_id']) { |
cc7a82
|
276 |
$group = $app->db->queryOneRecord("SELECT sys_groupid FROM web_database_user WHERE database_user_id = ?", $this->dataRecord['database_ro_user_id']); |
b1a6a5
|
277 |
if($group['sys_groupid'] != $web_group['sys_groupid']) { |
MC |
278 |
$app->error($app->tform->wordbook['database_client_differs_txt']); |
|
279 |
} |
|
280 |
} |
|
281 |
} |
cfa9da
|
282 |
|
T |
283 |
|
|
284 |
parent::onSubmit(); |
|
285 |
} |
|
286 |
|
|
287 |
function onBeforeUpdate() { |
|
288 |
global $app, $conf, $interfaceConf; |
|
289 |
|
7b47c0
|
290 |
//* Site shall not be empty |
5a43e7
|
291 |
if($this->dataRecord['parent_domain_id'] == 0) $app->tform->errorMessage .= $app->tform->lng("database_site_error_empty").'<br />'; |
b1a6a5
|
292 |
|
cfa9da
|
293 |
//* Get the database name and database user prefix |
31f6ce
|
294 |
$app->uses('getconf,tools_sites'); |
cfa9da
|
295 |
$global_config = $app->getconf->get_global_config('sites'); |
31f6ce
|
296 |
$dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); |
b1a6a5
|
297 |
|
cfa9da
|
298 |
//* Prevent that the database name and charset is changed |
T |
299 |
$old_record = $app->tform->getDataRecord($this->id); |
b1a6a5
|
300 |
$dbname_prefix = $app->tools_sites->getPrefix($old_record['database_name_prefix'], $dbname_prefix); |
MC |
301 |
$this->dataRecord['database_name_prefix'] = $dbname_prefix; |
|
302 |
|
9e247a
|
303 |
//* Only admin can change the database name |
FS |
304 |
if ($_SESSION["s"]["user"]["typ"] != 'admin') { |
|
305 |
if($old_record["database_name"] != $dbname_prefix . $this->dataRecord["database_name"]) { |
|
306 |
$app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'<br />'; |
|
307 |
} |
cfa9da
|
308 |
} |
T |
309 |
if($old_record["database_charset"] != $this->dataRecord["database_charset"]) { |
|
310 |
$app->tform->errorMessage .= $app->tform->wordbook["database_charset_change_txt"].'<br />'; |
|
311 |
} |
b1a6a5
|
312 |
|
MC |
313 |
if(!$this->dataRecord['database_user_id']) { |
|
314 |
$app->tform->errorMessage .= $app->tform->wordbook["database_user_missing_txt"].'<br />'; |
|
315 |
} |
|
316 |
|
967cd6
|
317 |
//* Database username and database name shall not be empty |
e1f89d
|
318 |
if($this->dataRecord['database_name'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_name_error_empty"].'<br />'; |
b1a6a5
|
319 |
|
cfa9da
|
320 |
//* Check if the server has been changed |
T |
321 |
// We do this only for the admin or reseller users, as normal clients can not change the server ID anyway |
|
322 |
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
323 |
if($old_record["server_id"] != $this->dataRecord["server_id"]) { |
|
324 |
//* Add a error message and switch back to old server |
|
325 |
$app->tform->errorMessage .= $app->lng('The Server can not be changed.'); |
|
326 |
$this->dataRecord["server_id"] = $rec['server_id']; |
|
327 |
} |
|
328 |
} |
|
329 |
unset($old_record); |
b1a6a5
|
330 |
|
MC |
331 |
if(strlen($dbname_prefix . $this->dataRecord['database_name']) > 64) $app->tform->errorMessage .= str_replace('{db}', $dbname_prefix . $this->dataRecord['database_name'], $app->tform->wordbook["database_name_error_len"]).'<br />'; |
|
332 |
|
fb3a98
|
333 |
//* Check database name and user against blacklist |
b1a6a5
|
334 |
$dbname_blacklist = array($conf['db_database'], 'mysql'); |
MC |
335 |
if(in_array($dbname_prefix . $this->dataRecord['database_name'], $dbname_blacklist)) { |
fb3a98
|
336 |
$app->tform->errorMessage .= $app->lng('Database name not allowed.').'<br />'; |
T |
337 |
} |
b1a6a5
|
338 |
|
cfa9da
|
339 |
if ($app->tform->errorMessage == ''){ |
T |
340 |
/* restrict the names if there is no error */ |
b1a6a5
|
341 |
/* crop user and db names if they are too long -> mysql: user: 16 chars / db: 64 chars */ |
cfa9da
|
342 |
$this->dataRecord['database_name'] = substr($dbname_prefix . $this->dataRecord['database_name'], 0, 64); |
T |
343 |
} |
b1a6a5
|
344 |
|
1ca823
|
345 |
//* Check for duplicates |
cc7a82
|
346 |
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as dbnum FROM web_database WHERE database_name = ? AND server_id = ? AND database_id != ?", $this->dataRecord['database_name'], $this->dataRecord["server_id"], $this->id); |
1ca823
|
347 |
if($tmp['dbnum'] > 0) $app->tform->errorMessage .= $app->lng('database_name_error_unique').'<br />'; |
b1a6a5
|
348 |
|
MC |
349 |
// get the web server ip (parent domain) |
cc7a82
|
350 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ?", $this->dataRecord['parent_domain_id']); |
b1a6a5
|
351 |
if($tmp['server_id'] && $tmp['server_id'] != $this->dataRecord['server_id']) { |
MC |
352 |
// we need remote access rights for this server, so get it's ip address |
|
353 |
$server_config = $app->getconf->get_server_config($tmp['server_id'], 'server'); |
|
354 |
if($server_config['ip_address']!='') { |
cc6568
|
355 |
if($this->dataRecord['remote_access'] != 'y'){ |
H |
356 |
$this->dataRecord['remote_ips'] = $server_config['ip_address']; |
|
357 |
$this->dataRecord['remote_access'] = 'y'; |
|
358 |
} else { |
|
359 |
if($this->dataRecord['remote_ips'] != ''){ |
|
360 |
if(preg_match('/(^|,)' . preg_quote($server_config['ip_address'], '/') . '(,|$)/', $this->dataRecord['remote_ips']) == false) { |
|
361 |
$this->dataRecord['remote_ips'] .= ',' . $server_config['ip_address']; |
|
362 |
} |
b1a6a5
|
363 |
$tmp = preg_split('/\s*,\s*/', $this->dataRecord['remote_ips']); |
MC |
364 |
$tmp = array_unique($tmp); |
|
365 |
$this->dataRecord['remote_ips'] = implode(',', $tmp); |
|
366 |
unset($tmp); |
cc6568
|
367 |
} |
H |
368 |
} |
b1a6a5
|
369 |
} |
MC |
370 |
} |
4b7584
|
371 |
|
MC |
372 |
if ($app->tform->errorMessage == '') { |
|
373 |
// force update of the used database user |
|
374 |
if($this->dataRecord['database_user_id']) { |
cc7a82
|
375 |
$user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_user_id']); |
4b7584
|
376 |
if($user_old_rec) { |
MC |
377 |
$user_new_rec = $user_old_rec; |
|
378 |
$user_new_rec['server_id'] = $this->dataRecord['server_id']; |
|
379 |
$app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_user_id'], $user_old_rec, $user_new_rec); |
|
380 |
} |
|
381 |
} |
|
382 |
if($this->dataRecord['database_ro_user_id']) { |
cc7a82
|
383 |
$user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_ro_user_id']); |
4b7584
|
384 |
if($user_old_rec) { |
MC |
385 |
$user_new_rec = $user_old_rec; |
|
386 |
$user_new_rec['server_id'] = $this->dataRecord['server_id']; |
|
387 |
$app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_ro_user_id'], $user_old_rec, $user_new_rec); |
|
388 |
} |
|
389 |
} |
|
390 |
} |
b1a6a5
|
391 |
|
cfa9da
|
392 |
parent::onBeforeUpdate(); |
T |
393 |
} |
|
394 |
|
|
395 |
function onBeforeInsert() { |
|
396 |
global $app, $conf, $interfaceConf; |
b1a6a5
|
397 |
|
5a43e7
|
398 |
//* Site shell not be empty |
T |
399 |
if($this->dataRecord['parent_domain_id'] == 0) $app->tform->errorMessage .= $app->tform->lng("database_site_error_empty").'<br />'; |
b1a6a5
|
400 |
|
967cd6
|
401 |
//* Database username and database name shall not be empty |
e1f89d
|
402 |
if($this->dataRecord['database_name'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_name_error_empty"].'<br />'; |
cfa9da
|
403 |
|
T |
404 |
//* Get the database name and database user prefix |
31f6ce
|
405 |
$app->uses('getconf,tools_sites'); |
cfa9da
|
406 |
$global_config = $app->getconf->get_global_config('sites'); |
31f6ce
|
407 |
$dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); |
b1a6a5
|
408 |
$this->dataRecord['database_name_prefix'] = $dbname_prefix; |
MC |
409 |
|
|
410 |
if(strlen($dbname_prefix . $this->dataRecord['database_name']) > 64) $app->tform->errorMessage .= str_replace('{db}', $dbname_prefix . $this->dataRecord['database_name'], $app->tform->wordbook["database_name_error_len"]).'<br />'; |
|
411 |
|
fb3a98
|
412 |
//* Check database name and user against blacklist |
b1a6a5
|
413 |
$dbname_blacklist = array($conf['db_database'], 'mysql'); |
MC |
414 |
if(in_array($dbname_prefix . $this->dataRecord['database_name'], $dbname_blacklist)) { |
fb3a98
|
415 |
$app->tform->errorMessage .= $app->lng('Database name not allowed.').'<br />'; |
T |
416 |
} |
b1a6a5
|
417 |
|
cfa9da
|
418 |
/* restrict the names */ |
b1a6a5
|
419 |
/* crop user and db names if they are too long -> mysql: user: 16 chars / db: 64 chars */ |
6ae1c7
|
420 |
if ($app->tform->errorMessage == ''){ |
T |
421 |
$this->dataRecord['database_name'] = substr($dbname_prefix . $this->dataRecord['database_name'], 0, 64); |
|
422 |
} |
b1a6a5
|
423 |
|
1ca823
|
424 |
//* Check for duplicates |
cc7a82
|
425 |
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as dbnum FROM web_database WHERE database_name = ? AND server_id = ?", $this->dataRecord['database_name'], $this->dataRecord["server_id"]); |
1ca823
|
426 |
if($tmp['dbnum'] > 0) $app->tform->errorMessage .= $app->tform->lng('database_name_error_unique').'<br />'; |
cfa9da
|
427 |
|
b1a6a5
|
428 |
// get the web server ip (parent domain) |
cc7a82
|
429 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ?", $this->dataRecord['parent_domain_id']); |
b1a6a5
|
430 |
if($tmp['server_id'] && $tmp['server_id'] != $this->dataRecord['server_id']) { |
MC |
431 |
// we need remote access rights for this server, so get it's ip address |
|
432 |
$server_config = $app->getconf->get_server_config($tmp['server_id'], 'server'); |
|
433 |
if($server_config['ip_address']!='') { |
cc6568
|
434 |
if($this->dataRecord['remote_access'] != 'y'){ |
H |
435 |
$this->dataRecord['remote_ips'] = $server_config['ip_address']; |
|
436 |
$this->dataRecord['remote_access'] = 'y'; |
|
437 |
} else { |
|
438 |
if($this->dataRecord['remote_ips'] != ''){ |
|
439 |
if(preg_match('/(^|,)' . preg_quote($server_config['ip_address'], '/') . '(,|$)/', $this->dataRecord['remote_ips']) == false) { |
|
440 |
$this->dataRecord['remote_ips'] .= ',' . $server_config['ip_address']; |
|
441 |
} |
b1a6a5
|
442 |
$tmp = preg_split('/\s*,\s*/', $this->dataRecord['remote_ips']); |
MC |
443 |
$tmp = array_unique($tmp); |
|
444 |
$this->dataRecord['remote_ips'] = implode(',', $tmp); |
|
445 |
unset($tmp); |
cc6568
|
446 |
} |
H |
447 |
} |
b1a6a5
|
448 |
} |
MC |
449 |
} |
|
450 |
|
4b7584
|
451 |
if ($app->tform->errorMessage == '') { |
MC |
452 |
// force update of the used database user |
|
453 |
if($this->dataRecord['database_user_id']) { |
cc7a82
|
454 |
$user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_user_id']); |
4b7584
|
455 |
if($user_old_rec) { |
MC |
456 |
$user_new_rec = $user_old_rec; |
|
457 |
$user_new_rec['server_id'] = $this->dataRecord['server_id']; |
|
458 |
$app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_user_id'], $user_old_rec, $user_new_rec); |
|
459 |
} |
|
460 |
} |
|
461 |
if($this->dataRecord['database_ro_user_id']) { |
cc7a82
|
462 |
$user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_ro_user_id']); |
4b7584
|
463 |
if($user_old_rec) { |
MC |
464 |
$user_new_rec = $user_old_rec; |
|
465 |
$user_new_rec['server_id'] = $this->dataRecord['server_id']; |
|
466 |
$app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_ro_user_id'], $user_old_rec, $user_new_rec); |
|
467 |
} |
|
468 |
} |
|
469 |
} |
|
470 |
|
|
471 |
|
cfa9da
|
472 |
parent::onBeforeInsert(); |
T |
473 |
} |
|
474 |
|
b1a6a5
|
475 |
function onInsertSave($sql) { |
MC |
476 |
global $app, $conf; |
381520
|
477 |
|
b1a6a5
|
478 |
$app->db->query($sql); |
MC |
479 |
if($app->db->errorMessage != '') die($app->db->errorMessage); |
|
480 |
$new_id = $app->db->insertID(); |
|
481 |
|
|
482 |
return $new_id; |
|
483 |
} |
|
484 |
|
|
485 |
function onUpdateSave($sql) { |
|
486 |
global $app; |
|
487 |
if(!empty($sql) && !$app->tform->isReadonlyTab($app->tform->getCurrentTab(), $this->id)) { |
|
488 |
|
|
489 |
$app->db->query($sql); |
|
490 |
if($app->db->errorMessage != '') die($app->db->errorMessage); |
|
491 |
} |
|
492 |
} |
|
493 |
|
cfa9da
|
494 |
function onAfterInsert() { |
T |
495 |
global $app, $conf; |
b1a6a5
|
496 |
|
2f7e60
|
497 |
$app->uses('sites_database_plugin'); |
MC |
498 |
$app->sites_database_plugin->processDatabaseInsert($this); |
cfa9da
|
499 |
} |
T |
500 |
|
|
501 |
function onAfterUpdate() { |
|
502 |
global $app, $conf; |
|
503 |
|
2f7e60
|
504 |
$app->uses('sites_database_plugin'); |
MC |
505 |
$app->sites_database_plugin->processDatabaseUpdate($this); |
cfa9da
|
506 |
} |
T |
507 |
|
|
508 |
} |
|
509 |
|
|
510 |
$page = new page_action; |
|
511 |
$page->onLoad(); |
|
512 |
|
b1a6a5
|
513 |
?> |