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 |
|
|
41 |
require_once('../../lib/config.inc.php'); |
|
42 |
require_once('../../lib/app.inc.php'); |
|
43 |
require_once('tools.inc.php'); |
|
44 |
|
|
45 |
//* Check permissions for module |
|
46 |
$app->auth->check_module_permissions('sites'); |
|
47 |
|
|
48 |
// Loading classes |
|
49 |
$app->uses('tpl,tform,tform_actions'); |
|
50 |
$app->load('tform_actions'); |
|
51 |
|
|
52 |
class page_action extends tform_actions { |
|
53 |
|
|
54 |
function onShowNew() { |
|
55 |
global $app, $conf; |
|
56 |
|
|
57 |
// we will check only users, not admins |
|
58 |
if($_SESSION["s"]["user"]["typ"] == 'user') { |
3cebc3
|
59 |
if(!$app->tform->checkClientLimit('limit_database')) { |
T |
60 |
$app->error($app->tform->wordbook["limit_database_txt"]); |
|
61 |
} |
|
62 |
if(!$app->tform->checkResellerLimit('limit_database')) { |
|
63 |
$app->error('Reseller: '.$app->tform->wordbook["limit_database_txt"]); |
cfa9da
|
64 |
} |
T |
65 |
} |
|
66 |
|
|
67 |
parent::onShowNew(); |
|
68 |
} |
|
69 |
|
|
70 |
function onShowEnd() { |
|
71 |
global $app, $conf, $interfaceConf; |
|
72 |
|
|
73 |
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
74 |
|
|
75 |
// Get the limits of the client |
|
76 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
|
77 |
$client = $app->db->queryOneRecord("SELECT default_dbserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); |
|
78 |
|
|
79 |
// Set the webserver to the default server of the client |
|
80 |
$tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_dbserver]"); |
|
81 |
$app->tpl->setVar("server_id","<option value='$client[default_dbserver]'>$tmp[server_name]</option>"); |
|
82 |
unset($tmp); |
|
83 |
|
|
84 |
} elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
85 |
|
|
86 |
// Get the limits of the client |
|
87 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
11faaa
|
88 |
$client = $app->db->queryOneRecord("SELECT client.client_id, limit_web_domain, default_webserver, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); |
e4baff
|
89 |
|
cfa9da
|
90 |
// Set the webserver to the default server of the client |
e4baff
|
91 |
$tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_webserver]"); |
T |
92 |
$app->tpl->setVar("server_id","<option value='$client[default_webserver]'>$tmp[server_name]</option>"); |
cfa9da
|
93 |
unset($tmp); |
T |
94 |
|
|
95 |
} else { |
|
96 |
|
|
97 |
// The user is admin |
|
98 |
if($this->id > 0) { |
|
99 |
$server_id = $this->dataRecord["server_id"]; |
|
100 |
} else { |
|
101 |
// Get the first server ID |
|
102 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1"); |
|
103 |
$server_id = $tmp['server_id']; |
|
104 |
} |
|
105 |
|
|
106 |
} |
|
107 |
|
|
108 |
/* |
|
109 |
* If the names are restricted -> remove the restriction, so that the |
|
110 |
* data can be edited |
|
111 |
*/ |
|
112 |
|
|
113 |
//* Get the database name and database user prefix |
|
114 |
$app->uses('getconf'); |
|
115 |
$global_config = $app->getconf->get_global_config('sites'); |
|
116 |
$dbname_prefix = replacePrefix($global_config['dbname_prefix'], $this->dataRecord); |
|
117 |
|
|
118 |
if ($this->dataRecord['database_name'] != ""){ |
|
119 |
/* REMOVE the restriction */ |
|
120 |
$app->tpl->setVar("database_name", str_replace($dbname_prefix , '', $this->dataRecord['database_name'])); |
|
121 |
} |
|
122 |
|
|
123 |
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
124 |
$app->tpl->setVar("database_name_prefix", $global_config['dbname_prefix']); |
|
125 |
} else { |
|
126 |
$app->tpl->setVar("database_name_prefix", $dbname_prefix); |
|
127 |
} |
32f2de
|
128 |
|
T |
129 |
if($this->id > 0) { |
|
130 |
//* we are editing a existing record |
6a8d0d
|
131 |
$app->tpl->setVar("edit_disabled", 1); |
T |
132 |
$app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]); |
|
133 |
$app->tpl->setVar("database_charset_value", $this->dataRecord["database_charset"]); |
32f2de
|
134 |
} else { |
6a8d0d
|
135 |
$app->tpl->setVar("edit_disabled", 0); |
32f2de
|
136 |
} |
cfa9da
|
137 |
|
T |
138 |
parent::onShowEnd(); |
|
139 |
} |
|
140 |
|
|
141 |
function onSubmit() { |
|
142 |
global $app, $conf; |
|
143 |
|
|
144 |
if($_SESSION["s"]["user"]["typ"] != 'admin') { |
|
145 |
// Get the limits of the client |
|
146 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
|
147 |
$client = $app->db->queryOneRecord("SELECT default_dbserver, limit_database FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id"); |
|
148 |
|
|
149 |
// When the record is updated |
|
150 |
if($this->id > 0) { |
|
151 |
// restore the server ID if the user is not admin and record is edited |
|
152 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE database_id = ".intval($this->id)); |
|
153 |
$this->dataRecord["server_id"] = $tmp["server_id"]; |
|
154 |
unset($tmp); |
|
155 |
// When the record is inserted |
|
156 |
} else { |
|
157 |
// set the server ID to the default dbserver of the client |
|
158 |
$this->dataRecord["server_id"] = $client["default_dbserver"]; |
|
159 |
|
|
160 |
|
|
161 |
// Check if the user may add another database |
|
162 |
if($client["limit_database"] >= 0) { |
|
163 |
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = $client_group_id"); |
|
164 |
if($tmp["number"] >= $client["limit_database"]) { |
|
165 |
$app->error($app->tform->wordbook["limit_database_txt"]); |
|
166 |
} |
|
167 |
} |
|
168 |
|
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
|
|
173 |
parent::onSubmit(); |
|
174 |
} |
|
175 |
|
|
176 |
function onBeforeUpdate() { |
|
177 |
global $app, $conf, $interfaceConf; |
|
178 |
|
5a43e7
|
179 |
//* Site shell not be empty |
T |
180 |
if($this->dataRecord['parent_domain_id'] == 0) $app->tform->errorMessage .= $app->tform->lng("database_site_error_empty").'<br />'; |
cfa9da
|
181 |
|
T |
182 |
//* Get the database name and database user prefix |
|
183 |
$app->uses('getconf'); |
|
184 |
$global_config = $app->getconf->get_global_config('sites'); |
|
185 |
$dbname_prefix = replacePrefix($global_config['dbname_prefix'], $this->dataRecord); |
381520
|
186 |
|
cfa9da
|
187 |
//* Prevent that the database name and charset is changed |
T |
188 |
$old_record = $app->tform->getDataRecord($this->id); |
|
189 |
if($old_record["database_name"] != $dbname_prefix . $this->dataRecord["database_name"]) { |
|
190 |
$app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'<br />'; |
|
191 |
} |
|
192 |
if($old_record["database_charset"] != $this->dataRecord["database_charset"]) { |
|
193 |
$app->tform->errorMessage .= $app->tform->wordbook["database_charset_change_txt"].'<br />'; |
|
194 |
} |
967cd6
|
195 |
|
T |
196 |
//* Database username and database name shall not be empty |
e1f89d
|
197 |
if($this->dataRecord['database_name'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_name_error_empty"].'<br />'; |
381520
|
198 |
|
cfa9da
|
199 |
//* Check if the server has been changed |
T |
200 |
// We do this only for the admin or reseller users, as normal clients can not change the server ID anyway |
|
201 |
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
|
202 |
if($old_record["server_id"] != $this->dataRecord["server_id"]) { |
|
203 |
//* Add a error message and switch back to old server |
|
204 |
$app->tform->errorMessage .= $app->lng('The Server can not be changed.'); |
|
205 |
$this->dataRecord["server_id"] = $rec['server_id']; |
|
206 |
} |
|
207 |
} |
|
208 |
unset($old_record); |
6ae1c7
|
209 |
|
T |
210 |
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 />'; |
fb3a98
|
211 |
|
T |
212 |
//* Check database name and user against blacklist |
|
213 |
$dbname_blacklist = array($conf['db_database'],'mysql'); |
|
214 |
if(in_array($dbname_prefix . $this->dataRecord['database_name'],$dbname_blacklist)) { |
|
215 |
$app->tform->errorMessage .= $app->lng('Database name not allowed.').'<br />'; |
|
216 |
} |
|
217 |
|
cfa9da
|
218 |
if ($app->tform->errorMessage == ''){ |
T |
219 |
/* restrict the names if there is no error */ |
|
220 |
/* crop user and db names if they are too long -> mysql: user: 16 chars / db: 64 chars */ |
|
221 |
$this->dataRecord['database_name'] = substr($dbname_prefix . $this->dataRecord['database_name'], 0, 64); |
|
222 |
} |
1ca823
|
223 |
|
T |
224 |
//* Check for duplicates |
|
225 |
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as dbnum FROM web_database WHERE database_name = '".$this->dataRecord['database_name']."' AND server_id = '".$this->dataRecord["server_id"]."' AND database_id != '".$this->id."'"); |
|
226 |
if($tmp['dbnum'] > 0) $app->tform->errorMessage .= $app->lng('database_name_error_unique').'<br />'; |
|
227 |
|
23765c
|
228 |
// get the web server ip (parent domain) |
M |
229 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = '".$this->dataRecord['parent_domain_id']."'"); |
|
230 |
if($tmp['server_id'] && $tmp['server_id'] != $this->dataRecord['server_id']) { |
|
231 |
// we need remote access rights for this server, so get it's ip address |
|
232 |
$server_config = $app->getconf->get_server_config($tmp['server_id'], 'server'); |
|
233 |
if($server_config['ip_address']!='') { |
381520
|
234 |
if($this->dataRecord['remote_access'] != 'y') $this->dataRecord['remote_ips'] = ''; |
23765c
|
235 |
$this->dataRecord['remote_access'] = 'y'; |
381520
|
236 |
if(preg_match('/(^|,)' . preg_quote($server_config['ip_address'], '/') . '(,|$)/', $this->dataRecord['remote_ips']) == false) { |
M |
237 |
$this->dataRecord['remote_ips'] .= ($this->dataRecord['remote_ips'] != '' ? ',' : '') . $server_config['ip_address']; |
|
238 |
} |
23765c
|
239 |
} |
M |
240 |
} |
|
241 |
|
|
242 |
|
cfa9da
|
243 |
parent::onBeforeUpdate(); |
T |
244 |
} |
|
245 |
|
|
246 |
function onBeforeInsert() { |
|
247 |
global $app, $conf, $interfaceConf; |
967cd6
|
248 |
|
5a43e7
|
249 |
//* Site shell not be empty |
T |
250 |
if($this->dataRecord['parent_domain_id'] == 0) $app->tform->errorMessage .= $app->tform->lng("database_site_error_empty").'<br />'; |
|
251 |
|
967cd6
|
252 |
//* Database username and database name shall not be empty |
e1f89d
|
253 |
if($this->dataRecord['database_name'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_name_error_empty"].'<br />'; |
cfa9da
|
254 |
|
T |
255 |
//* Get the database name and database user prefix |
|
256 |
$app->uses('getconf'); |
|
257 |
$global_config = $app->getconf->get_global_config('sites'); |
|
258 |
$dbname_prefix = replacePrefix($global_config['dbname_prefix'], $this->dataRecord); |
6ae1c7
|
259 |
|
T |
260 |
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 />'; |
fb3a98
|
261 |
|
T |
262 |
//* Check database name and user against blacklist |
|
263 |
$dbname_blacklist = array($conf['db_database'],'mysql'); |
|
264 |
if(in_array($dbname_prefix . $this->dataRecord['database_name'],$dbname_blacklist)) { |
|
265 |
$app->tform->errorMessage .= $app->lng('Database name not allowed.').'<br />'; |
|
266 |
} |
|
267 |
|
cfa9da
|
268 |
/* restrict the names */ |
T |
269 |
/* crop user and db names if they are too long -> mysql: user: 16 chars / db: 64 chars */ |
6ae1c7
|
270 |
if ($app->tform->errorMessage == ''){ |
T |
271 |
$this->dataRecord['database_name'] = substr($dbname_prefix . $this->dataRecord['database_name'], 0, 64); |
|
272 |
} |
1ca823
|
273 |
|
T |
274 |
//* Check for duplicates |
|
275 |
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as dbnum FROM web_database WHERE database_name = '".$this->dataRecord['database_name']."' AND server_id = '".$this->dataRecord["server_id"]."'"); |
|
276 |
if($tmp['dbnum'] > 0) $app->tform->errorMessage .= $app->tform->lng('database_name_error_unique').'<br />'; |
cfa9da
|
277 |
|
23765c
|
278 |
// get the web server ip (parent domain) |
M |
279 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = '".$this->dataRecord['parent_domain_id']."'"); |
|
280 |
if($tmp['server_id'] && $tmp['server_id'] != $this->dataRecord['server_id']) { |
|
281 |
// we need remote access rights for this server, so get it's ip address |
|
282 |
$server_config = $app->getconf->get_server_config($tmp['server_id'], 'server'); |
|
283 |
if($server_config['ip_address']!='') { |
381520
|
284 |
if($this->dataRecord['remote_access'] != 'y') $this->dataRecord['remote_ips'] = ''; |
23765c
|
285 |
$this->dataRecord['remote_access'] = 'y'; |
381520
|
286 |
if(preg_match('/(^|,)' . preg_quote($server_config['ip_address'], '/') . '(,|$)/', $this->dataRecord['remote_ips']) == false) { |
M |
287 |
$this->dataRecord['remote_ips'] .= ($this->dataRecord['remote_ips'] != '' ? ',' : '') . $server_config['ip_address']; |
|
288 |
} |
23765c
|
289 |
} |
M |
290 |
} |
|
291 |
|
cfa9da
|
292 |
parent::onBeforeInsert(); |
T |
293 |
} |
|
294 |
|
381520
|
295 |
function onInsertSave($sql) { |
M |
296 |
global $app, $conf; |
|
297 |
|
|
298 |
if($this->dataRecord["parent_domain_id"] > 0) { |
|
299 |
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); |
|
300 |
|
|
301 |
//* The Database user shall be owned by the same group then the website |
|
302 |
$sys_groupid = $web['sys_groupid']; |
|
303 |
} else { |
|
304 |
$sys_groupid = $this->dataRecord['sys_groupid']; |
|
305 |
} |
|
306 |
|
|
307 |
|
|
308 |
if($this->dataRecord['database_user_id']) { |
|
309 |
// check if there has already been a database on this server with that user |
|
310 |
$check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_database` WHERE `server_id` = '" . intval($this->dataRecord['server_id']) . "' AND (`database_user_id` = '" . intval($this->dataRecord['database_user_id']) . "' OR `database_ro_user_id` = '" . intval($this->dataRecord['database_user_id']) . "') AND `sys_groupid` = '" . intval($sys_groupid) . "'"); |
|
311 |
|
|
312 |
if($check && $check['cnt'] < 1) { |
|
313 |
// we need to make a datalog insert for the database users that are connected to this database |
|
314 |
$db_user = $app->db->queryOneRecord("SELECT * FROM `web_database_user` WHERE `database_user_id` = '" . intval($this->dataRecord['database_user_id']) . "' AND `sys_groupid` = '" . intval($sys_groupid) . "'"); |
|
315 |
if($db_user) { |
|
316 |
$db_user['server_id'] = $this->dataRecord['server_id']; |
|
317 |
$app->db->datalogSave('web_database_user', 'INSERT', 'database_user_id', $db_user['database_user_id'], array(), $db_user); |
|
318 |
} |
|
319 |
} |
|
320 |
} |
|
321 |
|
|
322 |
if($this->dataRecord['database_ro_user_id']) { |
|
323 |
// check if there has already been a database on this server with that user |
|
324 |
$check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_database` WHERE `server_id` = '" . intval($this->dataRecord['server_id']) . "' AND (`database_user_id` = '" . intval($this->dataRecord['database_ro_user_id']) . "' OR `database_ro_user_id` = '" . intval($this->dataRecord['database_ro_user_id']) . "') AND `sys_groupid` = '" . intval($sys_groupid) . "'"); |
|
325 |
|
|
326 |
if($check && $check['cnt'] < 1) { |
|
327 |
// we need to make a datalog insert for the database users that are connected to this database |
|
328 |
$db_user = $app->db->queryOneRecord("SELECT * FROM `web_database_user` WHERE `database_user_id` = '" . intval($this->dataRecord['database_ro_user_id']) . "' AND `sys_groupid` = '" . intval($sys_groupid) . "'"); |
|
329 |
if($db_user) { |
|
330 |
$db_user['server_id'] = $this->dataRecord['server_id']; |
|
331 |
$app->db->datalogSave('web_database_user', 'INSERT', 'database_user_id', $db_user['database_user_id'], array(), $db_user); |
|
332 |
} |
|
333 |
} |
|
334 |
} |
|
335 |
|
|
336 |
$app->db->query($sql); |
|
337 |
if($app->db->errorMessage != '') die($app->db->errorMessage); |
|
338 |
$new_id = $app->db->insertID(); |
|
339 |
|
|
340 |
return $new_id; |
|
341 |
} |
|
342 |
|
|
343 |
function onUpdateSave($sql) { |
|
344 |
global $app; |
|
345 |
if(!empty($sql) && !$app->tform->isReadonlyTab($app->tform->getCurrentTab(),$this->id)) { |
|
346 |
$old_record = $app->tform->getDataRecord($this->id); |
|
347 |
|
|
348 |
if($this->dataRecord["parent_domain_id"] > 0) { |
|
349 |
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); |
|
350 |
|
|
351 |
//* The Database user shall be owned by the same group then the website |
|
352 |
$sys_groupid = $web['sys_groupid']; |
|
353 |
} else { |
|
354 |
$sys_groupid = $this->dataRecord['sys_groupid']; |
|
355 |
} |
|
356 |
|
|
357 |
// check if database user has changed |
|
358 |
if($old_record['database_user_id'] && $old_record['database_user_id'] != $this->dataRecord['database_user_id'] && $old_record['database_user_id'] != $this->dataRecord['database_ro_user_id']) { |
|
359 |
// check if any database on the server still uses this one |
|
360 |
$check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_database` WHERE `server_id` = '" . intval($this->dataRecord['server_id']) . "' AND (`database_user_id` = '" . intval($old_record['database_user_id']) . "' OR `database_ro_user_id` = '" . intval($old_record['database_user_id']) . "') AND `sys_groupid` = '" . intval($sys_groupid) . "' AND `database_id` != '" . intval($this->id) . "'"); |
|
361 |
if($check['cnt'] < 1) { |
|
362 |
// send a datalog delete |
|
363 |
$db_user = $app->db->queryOneRecord("SELECT * FROM `web_database_user` WHERE `database_user_id` = '" . intval($old_record['database_user_id']) . "' AND `sys_groupid` = '" . intval($sys_groupid) . "'"); |
|
364 |
if($db_user) { |
|
365 |
$db_user['server_id'] = $this->dataRecord['server_id']; |
|
366 |
$app->db->datalogSave('web_database_user', 'DELETE', 'database_user_id', $db_user['database_user_id'], $db_user, array()); |
|
367 |
} |
|
368 |
} |
|
369 |
} |
|
370 |
// check if readonly database user has changed |
|
371 |
if($old_record['database_ro_user_id'] && $old_record['database_ro_user_id'] != $this->dataRecord['database_ro_user_id'] && $old_record['database_ro_user_id'] != $this->dataRecord['database_user_id']) { |
|
372 |
// check if any database on the server still uses this one |
|
373 |
$check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_database` WHERE `server_id` = '" . intval($this->dataRecord['server_id']) . "' AND (`database_user_id` = '" . intval($old_record['database_ro_user_id']) . "' OR `database_ro_user_id` = '" . intval($old_record['database_ro_user_id']) . "') AND `sys_groupid` = '" . intval($sys_groupid) . "' AND `database_id` != '" . intval($this->id) . "'"); |
|
374 |
if($check['cnt'] < 1) { |
|
375 |
// send a datalog delete |
|
376 |
$db_user = $app->db->queryOneRecord("SELECT * FROM `web_database_user` WHERE `database_user_id` = '" . intval($old_record['database_ro_user_id']) . "' AND `sys_groupid` = '" . intval($sys_groupid) . "'"); |
|
377 |
if($db_user) { |
|
378 |
$db_user['server_id'] = $this->dataRecord['server_id']; |
|
379 |
$app->db->datalogSave('web_database_user', 'DELETE', 'database_user_id', $db_user['database_user_id'], $db_user, array()); |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
|
|
384 |
if($this->dataRecord['database_user_id']) { |
|
385 |
// check if there has already been a database on this server with that user |
|
386 |
$check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_database` WHERE `server_id` = '" . intval($this->dataRecord['server_id']) . "' AND (`database_user_id` = '" . intval($this->dataRecord['database_user_id']) . "' OR `database_ro_user_id` = '" . intval($this->dataRecord['database_user_id']) . "') AND `sys_groupid` = '" . intval($sys_groupid) . "'"); |
|
387 |
|
|
388 |
if($check && $check['cnt'] < 1) { |
|
389 |
// we need to make a datalog insert for the database users that are connected to this database |
|
390 |
$db_user = $app->db->queryOneRecord("SELECT * FROM `web_database_user` WHERE `database_user_id` = '" . intval($this->dataRecord['database_user_id']) . "' AND `sys_groupid` = '" . intval($sys_groupid) . "'"); |
|
391 |
if($db_user) { |
|
392 |
$db_user['server_id'] = $this->dataRecord['server_id']; |
|
393 |
$app->db->datalogSave('web_database_user', 'INSERT', 'database_user_id', $db_user['database_user_id'], array(), $db_user); |
|
394 |
} |
|
395 |
} |
|
396 |
} |
|
397 |
|
|
398 |
if($this->dataRecord['database_ro_user_id']) { |
|
399 |
// check if there has already been a database on this server with that user |
|
400 |
$check = $app->db->queryOneRecord("SELECT COUNT(*) as `cnt` FROM `web_database` WHERE `server_id` = '" . intval($this->dataRecord['server_id']) . "' AND (`database_user_id` = '" . intval($this->dataRecord['database_ro_user_id']) . "' OR `database_ro_user_id` = '" . intval($this->dataRecord['database_ro_user_id']) . "') AND `sys_groupid` = '" . intval($sys_groupid) . "'"); |
|
401 |
|
|
402 |
if($check && $check['cnt'] < 1) { |
|
403 |
// we need to make a datalog insert for the database users that are connected to this database |
|
404 |
$db_user = $app->db->queryOneRecord("SELECT * FROM `web_database_user` WHERE `database_user_id` = '" . intval($this->dataRecord['database_ro_user_id']) . "' AND `sys_groupid` = '" . intval($sys_groupid) . "'"); |
|
405 |
if($db_user) { |
|
406 |
$db_user['server_id'] = $this->dataRecord['server_id']; |
|
407 |
$app->db->datalogSave('web_database_user', 'INSERT', 'database_user_id', $db_user['database_user_id'], array(), $db_user); |
|
408 |
} |
|
409 |
} |
|
410 |
} |
|
411 |
|
|
412 |
$app->db->query($sql); |
|
413 |
if($app->db->errorMessage != '') die($app->db->errorMessage); |
|
414 |
} |
|
415 |
} |
|
416 |
|
cfa9da
|
417 |
function onAfterInsert() { |
T |
418 |
global $app, $conf; |
5a43e7
|
419 |
|
T |
420 |
if($this->dataRecord["parent_domain_id"] > 0) { |
|
421 |
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); |
|
422 |
|
|
423 |
//* The Database user shall be owned by the same group then the website |
|
424 |
$sys_groupid = $web['sys_groupid']; |
|
425 |
$backup_interval = $web['backup_interval']; |
|
426 |
$backup_copies = $web['backup_copies']; |
|
427 |
|
|
428 |
$sql = "UPDATE web_database SET sys_groupid = '$sys_groupid', backup_interval = '$backup_interval', backup_copies = '$backup_copies' WHERE database_id = ".$this->id; |
|
429 |
$app->db->query($sql); |
cfa9da
|
430 |
} |
T |
431 |
} |
|
432 |
|
|
433 |
function onAfterUpdate() { |
|
434 |
global $app, $conf; |
|
435 |
|
5a43e7
|
436 |
if($this->dataRecord["parent_domain_id"] > 0) { |
T |
437 |
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".intval($this->dataRecord["parent_domain_id"])); |
|
438 |
|
|
439 |
//* The Database user shall be owned by the same group then the website |
|
440 |
$sys_groupid = $web['sys_groupid']; |
|
441 |
$backup_interval = $web['backup_interval']; |
|
442 |
$backup_copies = $web['backup_copies']; |
|
443 |
|
|
444 |
$sql = "UPDATE web_database SET sys_groupid = '$sys_groupid', backup_interval = '$backup_interval', backup_copies = '$backup_copies' WHERE database_id = ".$this->id; |
|
445 |
$app->db->query($sql); |
cfa9da
|
446 |
} |
T |
447 |
|
|
448 |
} |
|
449 |
|
|
450 |
} |
|
451 |
|
|
452 |
$page = new page_action; |
|
453 |
$page->onLoad(); |
|
454 |
|
73c2f2
|
455 |
?> |