commit | author | age
|
11c7f5
|
1 |
<<<<<<< .mine
|
R |
2 |
<?php
|
|
3 |
/*
|
|
4 |
Copyright (c) 2008, Till Brehm, projektfarm Gmbh
|
|
5 |
All rights reserved.
|
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification,
|
|
8 |
are permitted provided that the following conditions are met:
|
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice,
|
|
11 |
this list of conditions and the following disclaimer.
|
|
12 |
* Redistributions in binary form must reproduce the above copyright notice,
|
|
13 |
this list of conditions and the following disclaimer in the documentation
|
|
14 |
and/or other materials provided with the distribution.
|
|
15 |
* Neither the name of ISPConfig nor the names of its contributors
|
|
16 |
may be used to endorse or promote products derived from this software without
|
|
17 |
specific prior written permission.
|
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29 |
*/
|
|
30 |
|
|
31 |
|
|
32 |
/******************************************
|
|
33 |
* Begin Form configuration
|
|
34 |
******************************************/
|
|
35 |
|
|
36 |
$tform_def_file = "form/database.tform.php";
|
|
37 |
|
|
38 |
/******************************************
|
|
39 |
* End Form configuration
|
|
40 |
******************************************/
|
|
41 |
|
|
42 |
require_once('../../lib/config.inc.php');
|
|
43 |
require_once('../../lib/app.inc.php');
|
|
44 |
require_once('tools.inc.php');
|
|
45 |
|
|
46 |
//* Check permissions for module
|
|
47 |
$app->auth->check_module_permissions('sites');
|
|
48 |
|
|
49 |
// Loading classes
|
|
50 |
$app->uses('tpl,tform,tform_actions');
|
|
51 |
$app->load('tform_actions');
|
|
52 |
|
|
53 |
class page_action extends tform_actions {
|
|
54 |
|
|
55 |
function onShowNew() {
|
|
56 |
global $app, $conf;
|
|
57 |
|
|
58 |
// we will check only users, not admins
|
|
59 |
if($_SESSION["s"]["user"]["typ"] == 'user') {
|
|
60 |
|
|
61 |
// Get the limits of the client
|
|
62 |
$client_group_id = $_SESSION["s"]["user"]["default_group"];
|
|
63 |
$client = $app->db->queryOneRecord("SELECT limit_database FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
|
|
64 |
|
|
65 |
// Check if the user may add another database.
|
|
66 |
if($client["limit_database"] >= 0) {
|
|
67 |
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = $client_group_id");
|
|
68 |
if($tmp["number"] >= $client["limit_database"]) {
|
|
69 |
$app->error($app->tform->wordbook["limit_database_txt"]);
|
|
70 |
}
|
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
parent::onShowNew();
|
|
75 |
}
|
|
76 |
|
|
77 |
function onShowEnd() {
|
|
78 |
global $app, $conf, $interfaceConf;
|
|
79 |
|
|
80 |
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
|
|
81 |
|
|
82 |
// Get the limits of the client
|
|
83 |
$client_group_id = $_SESSION["s"]["user"]["default_group"];
|
|
84 |
$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");
|
|
85 |
|
|
86 |
// Set the webserver to the default server of the client
|
|
87 |
$tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_dbserver]");
|
|
88 |
$app->tpl->setVar("server_id","<option value='$client[default_dbserver]'>$tmp[server_name]</option>");
|
|
89 |
unset($tmp);
|
|
90 |
|
|
91 |
} elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
|
|
92 |
|
|
93 |
// Get the limits of the client
|
|
94 |
$client_group_id = $_SESSION["s"]["user"]["default_group"];
|
|
95 |
$client = $app->db->queryOneRecord("SELECT client_id, default_dbserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
|
|
96 |
|
|
97 |
// Set the webserver to the default server of the client
|
|
98 |
$tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_dbserver]");
|
|
99 |
$app->tpl->setVar("server_id","<option value='$client[default_dbserver]'>$tmp[server_name]</option>");
|
|
100 |
unset($tmp);
|
|
101 |
|
|
102 |
// Fill the client select field
|
|
103 |
$sql = "SELECT groupid, name FROM sys_group, client WHERE sys_group.client_id = client.parent_client_id AND client.parent_client_id = ".$client['client_id'];
|
|
104 |
$clients = $app->db->queryAllRecords($sql);
|
|
105 |
$client_select = '';
|
|
106 |
if(is_array($clients)) {
|
|
107 |
foreach( $clients as $client) {
|
|
108 |
$selected = @($client["groupid"] == $this->dataRecord["sys_groupid"])?'SELECTED':'';
|
|
109 |
$client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n";
|
|
110 |
}
|
|
111 |
}
|
|
112 |
$app->tpl->setVar("client_group_id",$client_select);
|
|
113 |
|
|
114 |
} else {
|
|
115 |
|
|
116 |
// The user is admin
|
|
117 |
if($this->id > 0) {
|
|
118 |
$server_id = $this->dataRecord["server_id"];
|
|
119 |
} else {
|
|
120 |
// Get the first server ID
|
|
121 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1");
|
|
122 |
$server_id = $tmp['server_id'];
|
|
123 |
}
|
|
124 |
|
|
125 |
$sql = "SELECT ip_address FROM server_ip WHERE server_id = $server_id";
|
|
126 |
$ips = $app->db->queryAllRecords($sql);
|
|
127 |
$ip_select = "<option value='*'>*</option>";
|
|
128 |
//$ip_select = "";
|
|
129 |
if(is_array($ips)) {
|
|
130 |
foreach( $ips as $ip) {
|
|
131 |
$selected = ($ip["ip_address"] == $this->dataRecord["ip_address"])?'SELECTED':'';
|
|
132 |
$ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
|
|
133 |
}
|
|
134 |
}
|
|
135 |
$app->tpl->setVar("ip_address",$ip_select);
|
|
136 |
unset($tmp);
|
|
137 |
unset($ips);
|
|
138 |
|
|
139 |
// Fill the client select field
|
|
140 |
$sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0";
|
|
141 |
$clients = $app->db->queryAllRecords($sql);
|
|
142 |
$client_select = "<option value='0'></option>";
|
|
143 |
if(is_array($clients)) {
|
|
144 |
foreach( $clients as $client) {
|
|
145 |
$selected = @($client["groupid"] == $this->dataRecord["sys_groupid"])?'SELECTED':'';
|
|
146 |
$client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n";
|
|
147 |
}
|
|
148 |
}
|
|
149 |
$app->tpl->setVar("client_group_id",$client_select);
|
|
150 |
|
|
151 |
}
|
|
152 |
|
|
153 |
/*
|
|
154 |
* If the names are restricted -> remove the restriction, so that the
|
|
155 |
* data can be edited
|
|
156 |
*/
|
|
157 |
|
|
158 |
//* Get the database name and database user prefix
|
|
159 |
$app->uses('getconf');
|
|
160 |
$global_config = $app->getconf->get_global_config('sites');
|
|
161 |
$dbname_prefix = replacePrefix($global_config['dbname_prefix'], $this->dataRecord);
|
|
162 |
$dbuser_prefix = replacePrefix($global_config['dbuser_prefix'], $this->dataRecord);
|
|
163 |
|
|
164 |
if ($this->dataRecord['database_name'] != ""){
|
|
165 |
/* REMOVE the restriction */
|
|
166 |
$app->tpl->setVar("database_name", str_replace($dbname_prefix , '', $this->dataRecord['database_name']));
|
|
167 |
$app->tpl->setVar("database_user", str_replace($dbuser_prefix , '', $this->dataRecord['database_user']));
|
|
168 |
}
|
|
169 |
|
|
170 |
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
|
|
171 |
$app->tpl->setVar("database_name_prefix", $global_config['dbname_prefix']);
|
|
172 |
$app->tpl->setVar("database_user_prefix", $global_config['dbuser_prefix']);
|
|
173 |
} else {
|
|
174 |
$app->tpl->setVar("database_name_prefix", $dbname_prefix);
|
|
175 |
$app->tpl->setVar("database_user_prefix", $dbuser_prefix);
|
|
176 |
}
|
|
177 |
|
|
178 |
parent::onShowEnd();
|
|
179 |
}
|
|
180 |
|
|
181 |
function onSubmit() {
|
|
182 |
global $app, $conf;
|
|
183 |
|
|
184 |
if($_SESSION["s"]["user"]["typ"] != 'admin') {
|
|
185 |
// Get the limits of the client
|
|
186 |
$client_group_id = $_SESSION["s"]["user"]["default_group"];
|
|
187 |
$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");
|
|
188 |
|
|
189 |
// When the record is updated
|
|
190 |
if($this->id > 0) {
|
|
191 |
// restore the server ID if the user is not admin and record is edited
|
|
192 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE database_id = ".intval($this->id));
|
|
193 |
$this->dataRecord["server_id"] = $tmp["server_id"];
|
|
194 |
unset($tmp);
|
|
195 |
// When the record is inserted
|
|
196 |
} else {
|
|
197 |
// set the server ID to the default dbserver of the client
|
|
198 |
$this->dataRecord["server_id"] = $client["default_dbserver"];
|
|
199 |
|
|
200 |
|
|
201 |
// Check if the user may add another database
|
|
202 |
if($client["limit_database"] >= 0) {
|
|
203 |
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = $client_group_id");
|
|
204 |
if($tmp["number"] >= $client["limit_database"]) {
|
|
205 |
$app->error($app->tform->wordbook["limit_database_txt"]);
|
|
206 |
}
|
|
207 |
}
|
|
208 |
|
|
209 |
}
|
|
210 |
|
|
211 |
// Clients may not set the client_group_id, so we unset them if user is not a admin and the client is not a reseller
|
|
212 |
if(!$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]);
|
|
213 |
}
|
|
214 |
|
|
215 |
|
|
216 |
parent::onSubmit();
|
|
217 |
}
|
|
218 |
|
|
219 |
function onBeforeUpdate() {
|
|
220 |
global $app, $conf, $interfaceConf;
|
|
221 |
|
|
222 |
/*
|
|
223 |
* If the names should be restricted -> do it!
|
|
224 |
*/
|
|
225 |
|
|
226 |
|
|
227 |
//* Get the database name and database user prefix
|
|
228 |
$app->uses('getconf');
|
|
229 |
$global_config = $app->getconf->get_global_config('sites');
|
|
230 |
$dbname_prefix = replacePrefix($global_config['dbname_prefix'], $this->dataRecord);
|
|
231 |
$dbuser_prefix = replacePrefix($global_config['dbuser_prefix'], $this->dataRecord);
|
|
232 |
|
|
233 |
//* Prevent that the database name and charset is changed
|
|
234 |
$old_record = $app->tform->getDataRecord($this->id);
|
|
235 |
if($old_record["database_name"] != $restriction . $this->dataRecord["database_name"]) {
|
|
236 |
$app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'<br />';
|
|
237 |
}
|
|
238 |
if($old_record["database_charset"] != $this->dataRecord["database_charset"]) {
|
|
239 |
$app->tform->errorMessage .= $app->tform->wordbook["database_charset_change_txt"].'<br />';
|
|
240 |
}
|
|
241 |
|
|
242 |
//* Check if the server has been changed
|
|
243 |
// We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
|
|
244 |
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
|
|
245 |
if($old_record["server_id"] != $this->dataRecord["server_id"]) {
|
|
246 |
//* Add a error message and switch back to old server
|
|
247 |
$app->tform->errorMessage .= $app->lng('The Server can not be changed.');
|
|
248 |
$this->dataRecord["server_id"] = $rec['server_id'];
|
|
249 |
}
|
|
250 |
}
|
|
251 |
unset($old_record);
|
|
252 |
|
|
253 |
if ($app->tform->errorMessage == ''){
|
|
254 |
/* restrict the names if there is no error */
|
|
255 |
$this->dataRecord['database_name'] = $dbname_prefix . $this->dataRecord['database_name'];
|
|
256 |
$this->dataRecord['database_user'] = $dbuser_prefix . $this->dataRecord['database_user'];
|
|
257 |
}
|
|
258 |
|
|
259 |
parent::onBeforeUpdate();
|
|
260 |
}
|
|
261 |
|
|
262 |
function onBeforeInsert() {
|
|
263 |
global $app, $conf, $interfaceConf;
|
|
264 |
|
|
265 |
//* Get the database name and database user prefix
|
|
266 |
$app->uses('getconf');
|
|
267 |
$global_config = $app->getconf->get_global_config('sites');
|
|
268 |
$dbname_prefix = replacePrefix($global_config['dbname_prefix'], $this->dataRecord);
|
|
269 |
$dbuser_prefix = replacePrefix($global_config['dbuser_prefix'], $this->dataRecord);
|
|
270 |
|
|
271 |
/* restrict the names */
|
|
272 |
$this->dataRecord['database_name'] = $dbname_prefix . $this->dataRecord['database_name'];
|
|
273 |
$this->dataRecord['database_user'] = $dbuser_prefix . $this->dataRecord['database_user'];
|
|
274 |
|
|
275 |
parent::onBeforeInsert();
|
|
276 |
}
|
|
277 |
|
|
278 |
function onAfterInsert() {
|
|
279 |
global $app, $conf;
|
|
280 |
|
|
281 |
// make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
|
|
282 |
// also make sure that the user can not delete domain created by a admin
|
|
283 |
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
|
|
284 |
$client_group_id = intval($this->dataRecord["client_group_id"]);
|
|
285 |
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE database_id = ".$this->id);
|
|
286 |
}
|
|
287 |
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
|
|
288 |
$client_group_id = intval($this->dataRecord["client_group_id"]);
|
|
289 |
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE database_id = ".$this->id);
|
|
290 |
}
|
|
291 |
}
|
|
292 |
|
|
293 |
function onAfterUpdate() {
|
|
294 |
global $app, $conf;
|
|
295 |
|
|
296 |
// make sure that the record belongs to the client group and not the admin group when a admin inserts it
|
|
297 |
// also make sure that the user can not delete domain created by a admin
|
|
298 |
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
|
|
299 |
$client_group_id = intval($this->dataRecord["client_group_id"]);
|
|
300 |
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE database_id = ".$this->id);
|
|
301 |
}
|
|
302 |
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
|
|
303 |
$client_group_id = intval($this->dataRecord["client_group_id"]);
|
|
304 |
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE database_id = ".$this->id);
|
|
305 |
}
|
|
306 |
|
|
307 |
}
|
|
308 |
|
|
309 |
}
|
|
310 |
|
|
311 |
$page = new page_action;
|
|
312 |
$page->onLoad();
|
|
313 |
|
|
314 |
=======
|
|
315 |
<?php
|
|
316 |
/*
|
|
317 |
Copyright (c) 2008, Till Brehm, projektfarm Gmbh
|
|
318 |
All rights reserved.
|
|
319 |
|
|
320 |
Redistribution and use in source and binary forms, with or without modification,
|
|
321 |
are permitted provided that the following conditions are met:
|
|
322 |
|
|
323 |
* Redistributions of source code must retain the above copyright notice,
|
|
324 |
this list of conditions and the following disclaimer.
|
|
325 |
* Redistributions in binary form must reproduce the above copyright notice,
|
|
326 |
this list of conditions and the following disclaimer in the documentation
|
|
327 |
and/or other materials provided with the distribution.
|
|
328 |
* Neither the name of ISPConfig nor the names of its contributors
|
|
329 |
may be used to endorse or promote products derived from this software without
|
|
330 |
specific prior written permission.
|
|
331 |
|
|
332 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
333 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
334 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
335 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
336 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
337 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
338 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
339 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
340 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
341 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
342 |
*/
|
|
343 |
|
|
344 |
|
|
345 |
/******************************************
|
|
346 |
* Begin Form configuration
|
|
347 |
******************************************/
|
|
348 |
|
|
349 |
$tform_def_file = "form/database.tform.php";
|
|
350 |
|
|
351 |
/******************************************
|
|
352 |
* End Form configuration
|
|
353 |
******************************************/
|
|
354 |
|
|
355 |
require_once('../../lib/config.inc.php');
|
|
356 |
require_once('../../lib/app.inc.php');
|
|
357 |
require_once('tools.inc.php');
|
|
358 |
|
|
359 |
//* Check permissions for module
|
|
360 |
$app->auth->check_module_permissions('sites');
|
|
361 |
|
|
362 |
// Loading classes
|
|
363 |
$app->uses('tpl,tform,tform_actions');
|
|
364 |
$app->load('tform_actions');
|
|
365 |
|
|
366 |
class page_action extends tform_actions {
|
|
367 |
|
|
368 |
function onShowNew() {
|
|
369 |
global $app, $conf;
|
|
370 |
|
|
371 |
// we will check only users, not admins
|
|
372 |
if($_SESSION["s"]["user"]["typ"] == 'user') {
|
|
373 |
|
|
374 |
// Get the limits of the client
|
|
375 |
$client_group_id = $_SESSION["s"]["user"]["default_group"];
|
|
376 |
$client = $app->db->queryOneRecord("SELECT limit_database FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
|
|
377 |
|
|
378 |
// Check if the user may add another database.
|
|
379 |
if($client["limit_database"] >= 0) {
|
|
380 |
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = $client_group_id");
|
|
381 |
if($tmp["number"] >= $client["limit_database"]) {
|
|
382 |
$app->error($app->tform->wordbook["limit_database_txt"]);
|
|
383 |
}
|
|
384 |
}
|
|
385 |
}
|
|
386 |
|
|
387 |
parent::onShowNew();
|
|
388 |
}
|
|
389 |
|
|
390 |
function onShowEnd() {
|
|
391 |
global $app, $conf, $interfaceConf;
|
|
392 |
|
|
393 |
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
|
|
394 |
|
|
395 |
// Get the limits of the client
|
|
396 |
$client_group_id = $_SESSION["s"]["user"]["default_group"];
|
|
397 |
$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");
|
|
398 |
|
|
399 |
// Set the webserver to the default server of the client
|
|
400 |
$tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_dbserver]");
|
|
401 |
$app->tpl->setVar("server_id","<option value='$client[default_dbserver]'>$tmp[server_name]</option>");
|
|
402 |
unset($tmp);
|
|
403 |
|
|
404 |
} elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
|
|
405 |
|
|
406 |
// Get the limits of the client
|
|
407 |
$client_group_id = $_SESSION["s"]["user"]["default_group"];
|
|
408 |
$client = $app->db->queryOneRecord("SELECT client_id, default_dbserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
|
|
409 |
|
|
410 |
// Set the webserver to the default server of the client
|
|
411 |
$tmp = $app->db->queryOneRecord("SELECT server_name FROM server WHERE server_id = $client[default_dbserver]");
|
|
412 |
$app->tpl->setVar("server_id","<option value='$client[default_dbserver]'>$tmp[server_name]</option>");
|
|
413 |
unset($tmp);
|
|
414 |
|
|
415 |
// Fill the client select field
|
|
416 |
$sql = "SELECT groupid, name FROM sys_group, client WHERE sys_group.client_id = client.parent_client_id AND client.parent_client_id = ".$client['client_id'];
|
|
417 |
$clients = $app->db->queryAllRecords($sql);
|
|
418 |
$client_select = '';
|
|
419 |
if(is_array($clients)) {
|
|
420 |
foreach( $clients as $client) {
|
|
421 |
$selected = @($client["groupid"] == $this->dataRecord["sys_groupid"])?'SELECTED':'';
|
|
422 |
$client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n";
|
|
423 |
}
|
|
424 |
}
|
|
425 |
$app->tpl->setVar("client_group_id",$client_select);
|
|
426 |
|
|
427 |
} else {
|
|
428 |
|
|
429 |
// The user is admin
|
|
430 |
if($this->id > 0) {
|
|
431 |
$server_id = $this->dataRecord["server_id"];
|
|
432 |
} else {
|
|
433 |
// Get the first server ID
|
|
434 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1");
|
|
435 |
$server_id = $tmp['server_id'];
|
|
436 |
}
|
|
437 |
|
|
438 |
$sql = "SELECT ip_address FROM server_ip WHERE server_id = $server_id";
|
|
439 |
$ips = $app->db->queryAllRecords($sql);
|
|
440 |
$ip_select = "<option value='*'>*</option>";
|
|
441 |
//$ip_select = "";
|
|
442 |
if(is_array($ips)) {
|
|
443 |
foreach( $ips as $ip) {
|
|
444 |
$selected = ($ip["ip_address"] == $this->dataRecord["ip_address"])?'SELECTED':'';
|
|
445 |
$ip_select .= "<option value='$ip[ip_address]' $selected>$ip[ip_address]</option>\r\n";
|
|
446 |
}
|
|
447 |
}
|
|
448 |
$app->tpl->setVar("ip_address",$ip_select);
|
|
449 |
unset($tmp);
|
|
450 |
unset($ips);
|
|
451 |
|
|
452 |
// Fill the client select field
|
|
453 |
$sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0";
|
|
454 |
$clients = $app->db->queryAllRecords($sql);
|
|
455 |
$client_select = "<option value='0'></option>";
|
|
456 |
if(is_array($clients)) {
|
|
457 |
foreach( $clients as $client) {
|
|
458 |
$selected = @($client["groupid"] == $this->dataRecord["sys_groupid"])?'SELECTED':'';
|
|
459 |
$client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n";
|
|
460 |
}
|
|
461 |
}
|
|
462 |
$app->tpl->setVar("client_group_id",$client_select);
|
|
463 |
|
|
464 |
}
|
|
465 |
|
|
466 |
/*
|
|
467 |
* If the names are restricted -> remove the restriction, so that the
|
|
468 |
* data can be edited
|
|
469 |
*/
|
|
470 |
|
|
471 |
//* Get the database name and database user prefix
|
|
472 |
$app->uses('getconf');
|
|
473 |
$global_config = $app->getconf->get_global_config('sites');
|
|
474 |
$dbname_prefix = ($global_config['dbname_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbname_prefix']);
|
|
475 |
$dbuser_prefix = ($global_config['dbuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbuser_prefix']);
|
|
476 |
|
|
477 |
if ($this->dataRecord['database_name'] != ""){
|
|
478 |
/* REMOVE the restriction */
|
|
479 |
$app->tpl->setVar("database_name", str_replace($dbname_prefix , '', $this->dataRecord['database_name']));
|
|
480 |
$app->tpl->setVar("database_user", str_replace($dbuser_prefix , '', $this->dataRecord['database_user']));
|
|
481 |
}
|
|
482 |
|
|
483 |
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
|
|
484 |
$app->tpl->setVar("database_name_prefix", $global_config['dbname_prefix']);
|
|
485 |
$app->tpl->setVar("database_user_prefix", $global_config['dbuser_prefix']);
|
|
486 |
} else {
|
|
487 |
$app->tpl->setVar("database_name_prefix", $dbname_prefix);
|
|
488 |
$app->tpl->setVar("database_user_prefix", $dbuser_prefix);
|
|
489 |
}
|
|
490 |
|
|
491 |
parent::onShowEnd();
|
|
492 |
}
|
|
493 |
|
|
494 |
function onSubmit() {
|
|
495 |
global $app, $conf;
|
|
496 |
|
|
497 |
if($_SESSION["s"]["user"]["typ"] != 'admin') {
|
|
498 |
// Get the limits of the client
|
|
499 |
$client_group_id = $_SESSION["s"]["user"]["default_group"];
|
|
500 |
$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");
|
|
501 |
|
|
502 |
// When the record is updated
|
|
503 |
if($this->id > 0) {
|
|
504 |
// restore the server ID if the user is not admin and record is edited
|
|
505 |
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE database_id = ".intval($this->id));
|
|
506 |
$this->dataRecord["server_id"] = $tmp["server_id"];
|
|
507 |
unset($tmp);
|
|
508 |
// When the record is inserted
|
|
509 |
} else {
|
|
510 |
// set the server ID to the default dbserver of the client
|
|
511 |
$this->dataRecord["server_id"] = $client["default_dbserver"];
|
|
512 |
|
|
513 |
|
|
514 |
// Check if the user may add another database
|
|
515 |
if($client["limit_database"] >= 0) {
|
|
516 |
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = $client_group_id");
|
|
517 |
if($tmp["number"] >= $client["limit_database"]) {
|
|
518 |
$app->error($app->tform->wordbook["limit_database_txt"]);
|
|
519 |
}
|
|
520 |
}
|
|
521 |
|
|
522 |
}
|
|
523 |
|
|
524 |
// Clients may not set the client_group_id, so we unset them if user is not a admin and the client is not a reseller
|
|
525 |
if(!$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]);
|
|
526 |
}
|
|
527 |
|
|
528 |
|
|
529 |
parent::onSubmit();
|
|
530 |
}
|
|
531 |
|
|
532 |
function onBeforeUpdate() {
|
|
533 |
global $app, $conf, $interfaceConf;
|
|
534 |
|
|
535 |
/*
|
|
536 |
* If the names should be restricted -> do it!
|
|
537 |
*/
|
|
538 |
|
|
539 |
|
|
540 |
//* Get the database name and database user prefix
|
|
541 |
$app->uses('getconf');
|
|
542 |
$global_config = $app->getconf->get_global_config('sites');
|
|
543 |
$dbname_prefix = ($global_config['dbname_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbname_prefix']);
|
|
544 |
$dbuser_prefix = ($global_config['dbuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbuser_prefix']);
|
|
545 |
|
|
546 |
//* Prevent that the database name and charset is changed
|
|
547 |
$old_record = $app->tform->getDataRecord($this->id);
|
|
548 |
if($old_record["database_name"] != $dbname_prefix . $this->dataRecord["database_name"]) {
|
|
549 |
$app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'<br />';
|
|
550 |
}
|
|
551 |
if($old_record["database_charset"] != $this->dataRecord["database_charset"]) {
|
|
552 |
$app->tform->errorMessage .= $app->tform->wordbook["database_charset_change_txt"].'<br />';
|
|
553 |
}
|
|
554 |
|
|
555 |
//* Check if the server has been changed
|
|
556 |
// We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
|
|
557 |
if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
|
|
558 |
if($old_record["server_id"] != $this->dataRecord["server_id"]) {
|
|
559 |
//* Add a error message and switch back to old server
|
|
560 |
$app->tform->errorMessage .= $app->lng('The Server can not be changed.');
|
|
561 |
$this->dataRecord["server_id"] = $rec['server_id'];
|
|
562 |
}
|
|
563 |
}
|
|
564 |
unset($old_record);
|
|
565 |
|
|
566 |
if ($app->tform->errorMessage == ''){
|
|
567 |
/* restrict the names if there is no error */
|
|
568 |
$this->dataRecord['database_name'] = $dbname_prefix . $this->dataRecord['database_name'];
|
|
569 |
$this->dataRecord['database_user'] = $dbuser_prefix . $this->dataRecord['database_user'];
|
|
570 |
}
|
|
571 |
|
|
572 |
parent::onBeforeUpdate();
|
|
573 |
}
|
|
574 |
|
|
575 |
function onBeforeInsert() {
|
|
576 |
global $app, $conf, $interfaceConf;
|
|
577 |
|
|
578 |
//* Get the database name and database user prefix
|
|
579 |
$app->uses('getconf');
|
|
580 |
$global_config = $app->getconf->get_global_config('sites');
|
|
581 |
$dbname_prefix = ($global_config['dbname_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbname_prefix']);
|
|
582 |
$dbuser_prefix = ($global_config['dbuser_prefix'] == '')?'':str_replace('[CLIENTNAME]', $this->getClientName(), $global_config['dbuser_prefix']);
|
|
583 |
|
|
584 |
/* restrict the names */
|
|
585 |
$this->dataRecord['database_name'] = $dbname_prefix . $this->dataRecord['database_name'];
|
|
586 |
$this->dataRecord['database_user'] = $dbuser_prefix . $this->dataRecord['database_user'];
|
|
587 |
|
|
588 |
parent::onBeforeInsert();
|
|
589 |
}
|
|
590 |
|
|
591 |
function onAfterInsert() {
|
|
592 |
global $app, $conf;
|
|
593 |
|
|
594 |
// make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
|
|
595 |
// also make sure that the user can not delete domain created by a admin
|
|
596 |
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
|
|
597 |
$client_group_id = intval($this->dataRecord["client_group_id"]);
|
|
598 |
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE database_id = ".$this->id);
|
|
599 |
}
|
|
600 |
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
|
|
601 |
$client_group_id = intval($this->dataRecord["client_group_id"]);
|
|
602 |
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE database_id = ".$this->id);
|
|
603 |
}
|
|
604 |
}
|
|
605 |
|
|
606 |
function onAfterUpdate() {
|
|
607 |
global $app, $conf;
|
|
608 |
|
|
609 |
// make sure that the record belongs to the client group and not the admin group when a admin inserts it
|
|
610 |
// also make sure that the user can not delete domain created by a admin
|
|
611 |
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
|
|
612 |
$client_group_id = intval($this->dataRecord["client_group_id"]);
|
|
613 |
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE database_id = ".$this->id);
|
|
614 |
}
|
|
615 |
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) {
|
|
616 |
$client_group_id = intval($this->dataRecord["client_group_id"]);
|
|
617 |
$app->db->query("UPDATE web_database SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE database_id = ".$this->id);
|
|
618 |
}
|
|
619 |
|
|
620 |
}
|
|
621 |
|
|
622 |
function getClientName() {
|
|
623 |
global $app, $conf;
|
|
624 |
|
|
625 |
if($_SESSION["s"]["user"]["typ"] != 'admin') {
|
|
626 |
// Get the group-id of the user
|
|
627 |
$client_group_id = $_SESSION["s"]["user"]["default_group"];
|
|
628 |
} else {
|
|
629 |
// Get the group-id from the data itself
|
|
630 |
$client_group_id = $this->dataRecord['client_group_id'];
|
|
631 |
}
|
|
632 |
/* get the name of the client */
|
|
633 |
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id);
|
|
634 |
$clientName = $tmp['name'];
|
|
635 |
if ($clientName == "") $clientName = 'default';
|
|
636 |
$clientName = convertClientName($clientName);
|
|
637 |
|
|
638 |
}
|
|
639 |
|
|
640 |
}
|
|
641 |
|
|
642 |
$page = new page_action;
|
|
643 |
$page->onLoad();
|
|
644 |
|
|
645 |
>>>>>>> .r717
|
73c2f2
|
646 |
?> |