66Redistribution and use in source and binary forms, with or without modification,
77are permitted provided that the following conditions are met:
88
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.
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.
1717
1818THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1919ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
4040
4141require_once ('../../lib/config.inc.php ' );
4242require_once ('../../lib/app.inc.php ' );
43+ require_once ('tools.inc.php ' );
4344
4445//* Check permissions for module
4546$ app ->auth ->check_module_permissions ('sites ' );
4950$ app ->load ('tform_actions ' );
5051
5152class page_action extends tform_actions {
52-
53+
5354 function onShowNew () {
5455 global $ app , $ conf ;
55-
56+
5657 // we will check only users, not admins
5758 if ($ _SESSION ["s " ]["user " ]["typ " ] == 'user ' ) {
58-
59+
5960 // Get the limits of the client
6061 $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
6162 $ 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 " );
62-
63+
6364 // Check if the user may add another database.
6465 if ($ client ["limit_database " ] >= 0 ) {
6566 $ tmp = $ app ->db ->queryOneRecord ("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = $ client_group_id " );
@@ -68,35 +69,35 @@ function onShowNew() {
6869 }
6970 }
7071 }
71-
72+
7273 parent ::onShowNew ();
7374 }
74-
75+
7576 function onShowEnd () {
76- global $ app , $ conf ;
77-
77+ global $ app , $ conf, $ interfaceConf ;
78+
7879 if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' && !$ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
79-
80+
8081 // Get the limits of the client
8182 $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
8283 $ 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 " );
83-
84+
8485 // Set the webserver to the default server of the client
8586 $ tmp = $ app ->db ->queryOneRecord ("SELECT server_name FROM server WHERE server_id = $ client [default_dbserver]" );
8687 $ app ->tpl ->setVar ("server_id " ,"<option value=' $ client [default_dbserver]'> $ tmp [server_name]</option> " );
8788 unset($ tmp );
88-
89+
8990 } elseif ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' && $ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
90-
91+
9192 // Get the limits of the client
9293 $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
9394 $ 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 " );
94-
95+
9596 // Set the webserver to the default server of the client
9697 $ tmp = $ app ->db ->queryOneRecord ("SELECT server_name FROM server WHERE server_id = $ client [default_dbserver]" );
9798 $ app ->tpl ->setVar ("server_id " ,"<option value=' $ client [default_dbserver]'> $ tmp [server_name]</option> " );
9899 unset($ tmp );
99-
100+
100101 // Fill the client select field
101102 $ 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 ' ];
102103 $ clients = $ app ->db ->queryAllRecords ($ sql );
@@ -108,9 +109,9 @@ function onShowEnd() {
108109 }
109110 }
110111 $ app ->tpl ->setVar ("client_group_id " ,$ client_select );
111-
112+
112113 } else {
113-
114+
114115 // The user is admin
115116 if ($ this ->id > 0 ) {
116117 $ server_id = $ this ->dataRecord ["server_id " ];
@@ -119,7 +120,7 @@ function onShowEnd() {
119120 $ tmp = $ app ->db ->queryOneRecord ("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1 " );
120121 $ server_id = $ tmp ['server_id ' ];
121122 }
122-
123+
123124 $ sql = "SELECT ip_address FROM server_ip WHERE server_id = $ server_id " ;
124125 $ ips = $ app ->db ->queryAllRecords ($ sql );
125126 $ ip_select = "<option value='*'>*</option> " ;
@@ -133,7 +134,7 @@ function onShowEnd() {
133134 $ app ->tpl ->setVar ("ip_address " ,$ ip_select );
134135 unset($ tmp );
135136 unset($ ips );
136-
137+
137138 // Fill the client select field
138139 $ sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0 " ;
139140 $ clients = $ app ->db ->queryAllRecords ($ sql );
@@ -145,86 +146,177 @@ function onShowEnd() {
145146 }
146147 }
147148 $ app ->tpl ->setVar ("client_group_id " ,$ client_select );
148-
149+
149150 }
150-
151+
152+ /*
153+ * If the names are restricted -> remove the client, so that the
154+ * data can be edited
155+ */
156+ if ($ interfaceConf ['restrict_names ' ] == true ){
157+ /* Get the group-id */
158+ if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
159+ // Get the group-id of the user
160+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
161+ }
162+ else {
163+ // Get the group-id from the data itself
164+ $ client_group_id = $ this ->dataRecord ['sys_groupid ' ];
165+ }
166+ /* get the name of the client */
167+ $ tmp = $ app ->db ->queryOneRecord ("SELECT name FROM sys_group WHERE groupid = " . $ client_group_id );
168+ $ clientName = $ tmp ['name ' ];
169+ if ($ clientName == "" ) $ clientName = 'default ' ;
170+ $ clientName = convertClientName ($ clientName );
171+ if ($ this ->dataRecord ['database_name ' ] != "" ){
172+ /* REMOVE the restriction */
173+ $ app ->tpl ->setVar ("database_name " , str_replace ($ clientName . '_ ' , '' , $ this ->dataRecord ['database_name ' ]));
174+ $ app ->tpl ->setVar ("database_user " , str_replace ($ clientName . '_ ' , '' , $ this ->dataRecord ['database_user ' ]));
175+ }
176+ if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' || $ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
177+ $ app ->tpl ->setVar ("database_name_prefix " , '{client}_ ' );
178+ $ app ->tpl ->setVar ("database_user_prefix " , '{client}_ ' );
179+ }
180+ else {
181+ $ app ->tpl ->setVar ("database_name_prefix " , $ clientName . '_ ' );
182+ $ app ->tpl ->setVar ("database_user_prefix " , $ clientName . '_ ' );
183+ }
184+ }
185+
151186 parent ::onShowEnd ();
152187 }
153-
188+
154189 function onSubmit () {
155190 global $ app , $ conf ;
156-
191+
157192 if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
158193 // Get the limits of the client
159194 $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
160195 $ 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 " );
161-
196+
162197 // When the record is updated
163198 if ($ this ->id > 0 ) {
164199 // restore the server ID if the user is not admin and record is edited
165200 $ tmp = $ app ->db ->queryOneRecord ("SELECT server_id FROM web_database WHERE database_id = " .intval ($ this ->id ));
166201 $ this ->dataRecord ["server_id " ] = $ tmp ["server_id " ];
167202 unset($ tmp );
168- // When the record is inserted
203+ // When the record is inserted
169204 } else {
170205 // set the server ID to the default dbserver of the client
171206 $ this ->dataRecord ["server_id " ] = $ client ["default_dbserver " ];
172-
173-
207+
208+
174209 // Check if the user may add another database
175- if ($ client ["limit_web_domain " ] >= 0 ) {
210+ if ($ client ["limit_database " ] >= 0 ) {
176211 $ tmp = $ app ->db ->queryOneRecord ("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = $ client_group_id " );
177212 if ($ tmp ["number " ] >= $ client ["limit_database " ]) {
178213 $ app ->error ($ app ->tform ->wordbook ["limit_database_txt " ]);
179214 }
180215 }
181-
216+
182217 }
183-
218+
184219 // 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
185220 if (!$ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) unset($ this ->dataRecord ["client_group_id " ]);
186221 }
187-
188-
222+
223+
189224 parent ::onSubmit ();
190225 }
191226
192227 function onBeforeUpdate () {
193- global $ app , $ conf ;
228+ global $ app , $ conf, $ interfaceConf ;
194229
195- //* Check if the server has been changed
196- // We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
197- if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' || $ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
198- $ rec = $ app ->db ->queryOneRecord ("SELECT server_id from web_database WHERE database_id = " .$ this ->id );
199- if ($ rec ['server_id ' ] != $ this ->dataRecord ["server_id " ]) {
200- //* Add a error message and switch back to old server
201- $ app ->tform ->errorMessage .= $ app ->lng ('The Server can not be changed. ' );
202- $ this ->dataRecord ["server_id " ] = $ rec ['server_id ' ];
230+ /*
231+ * If the names should be restricted -> do it!
232+ */
233+ if ($ interfaceConf ['restrict_names ' ] == true ){
234+ /* Get the group-id */
235+ if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
236+ // Get the group-id of the user
237+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
238+ }
239+ else {
240+ // Get the group-id from the data itself
241+ $ client_group_id = $ this ->dataRecord ['client_group_id ' ];
203242 }
204- unset($ rec );
243+ /* get the name of the client */
244+ $ tmp = $ app ->db ->queryOneRecord ("SELECT name FROM sys_group WHERE groupid = " . $ client_group_id );
245+ $ clientName = $ tmp ['name ' ];
246+ if ($ clientName == "" ) $ clientName = 'default ' ;
247+ $ clientName = convertClientName ($ clientName );
248+ $ nameSuffix = $ clientName . '_ ' ;
249+ }
250+ else {
251+ $ nameSuffix = '' ;
205252 }
206- }
207253
208- function onUpdate () {
209- global $ app , $ conf ;
210-
254+ $ error = false ;
255+
211256 //* Prevent that the database name and charset is changed
212257 $ old_record = $ app ->tform ->getDataRecord ($ this ->id );
213- if ($ old_record ["database_name " ] != $ this ->dataRecord ["database_name " ]) {
258+ if ($ old_record ["database_name " ] != $ nameSuffix . $ this ->dataRecord ["database_name " ]) {
214259 $ app ->tform ->errorMessage .= $ app ->tform ->wordbook ["database_name_change_txt " ].'<br /> ' ;
260+ $ error = true ;
215261 }
216262 if ($ old_record ["database_charset " ] != $ this ->dataRecord ["database_charset " ]) {
217263 $ app ->tform ->errorMessage .= $ app ->tform ->wordbook ["database_charset_change_txt " ].'<br /> ' ;
264+ $ error = true ;
265+ }
266+
267+ //* Check if the server has been changed
268+ // We do this only for the admin or reseller users, as normal clients can not change the server ID anyway
269+ if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' || $ app ->auth ->has_clients ($ _SESSION ['s ' ]['user ' ]['userid ' ])) {
270+ if ($ old_record ["server_id " ] != $ this ->dataRecord ["server_id " ]) {
271+ //* Add a error message and switch back to old server
272+ $ app ->tform ->errorMessage .= $ app ->lng ('The Server can not be changed. ' );
273+ $ this ->dataRecord ["server_id " ] = $ rec ['server_id ' ];
274+ $ error = true ;
275+ }
218276 }
219277 unset($ old_record );
220-
221- parent ::onUpdate ();
222-
278+
279+ if ($ error == false ){
280+ /* restrict the names if there is no error */
281+ $ this ->dataRecord ['database_name ' ] = $ nameSuffix . $ this ->dataRecord ['database_name ' ];
282+ $ this ->dataRecord ['database_user ' ] = $ nameSuffix . $ this ->dataRecord ['database_user ' ];
283+ }
284+
285+ parent ::onBeforeUpdate ();
286+ }
287+
288+ function onBeforeInsert () {
289+ global $ app , $ conf , $ interfaceConf ;
290+ global $ interfaceConf ;
291+
292+ /*
293+ * If the names should be restricted -> do it!
294+ */
295+ if ($ interfaceConf ['restrict_names ' ] == true ){
296+ /* Get the group-id */
297+ if ($ _SESSION ["s " ]["user " ]["typ " ] != 'admin ' ) {
298+ // Get the group-id of the user
299+ $ client_group_id = $ _SESSION ["s " ]["user " ]["default_group " ];
300+ }
301+ else {
302+ // Get the group-id from the data itself
303+ $ client_group_id = $ this ->dataRecord ['client_group_id ' ];
304+ }
305+ /* get the name of the client */
306+ $ tmp = $ app ->db ->queryOneRecord ("SELECT name FROM sys_group WHERE groupid = " . $ client_group_id );
307+ $ clientName = $ tmp ['name ' ];
308+ if ($ clientName == "" ) $ clientName = 'default ' ;
309+ $ clientName = convertClientName ($ clientName );
310+ /* restrict the names */
311+ $ this ->dataRecord ['database_name ' ] = $ clientName . '_ ' . $ this ->dataRecord ['database_name ' ];
312+ $ this ->dataRecord ['database_user ' ] = $ clientName . '_ ' . $ this ->dataRecord ['database_user ' ];
313+ }
314+ parent ::onBeforeInsert ();
223315 }
224-
316+
225317 function onAfterInsert () {
226318 global $ app , $ conf ;
227-
319+
228320 // make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
229321 // also make sure that the user can not delete domain created by a admin
230322 if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' && isset ($ this ->dataRecord ["client_group_id " ])) {
@@ -236,11 +328,11 @@ function onAfterInsert() {
236328 $ app ->db ->query ("UPDATE web_database SET sys_groupid = $ client_group_id, sys_perm_group = 'riud' WHERE database_id = " .$ this ->id );
237329 }
238330 }
239-
331+
240332 function onAfterUpdate () {
241333 global $ app , $ conf ;
242-
243- // make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
334+
335+ // make sure that the record belongs to the client group and not the admin group when a admin inserts it
244336 // also make sure that the user can not delete domain created by a admin
245337 if ($ _SESSION ["s " ]["user " ]["typ " ] == 'admin ' && isset ($ this ->dataRecord ["client_group_id " ])) {
246338 $ client_group_id = intval ($ this ->dataRecord ["client_group_id " ]);
@@ -250,9 +342,9 @@ function onAfterUpdate() {
250342 $ client_group_id = intval ($ this ->dataRecord ["client_group_id " ]);
251343 $ app ->db ->query ("UPDATE web_database SET sys_groupid = $ client_group_id, sys_perm_group = 'riud' WHERE database_id = " .$ this ->id );
252344 }
253-
345+
254346 }
255-
347+
256348}
257349
258350$ page = new page_action ;
0 commit comments