1- <<<<<<< .mine
21<?php
32/*
43Copyright (c) 2008, Till Brehm, projektfarm Gmbh
@@ -232,7 +231,7 @@ function onBeforeUpdate() {
232231
233232 //* Prevent that the database name and charset is changed
234233 $ old_record = $ app ->tform ->getDataRecord ($ this ->id );
235- if ($ old_record ["database_name " ] != $ restriction . $ this ->dataRecord ["database_name " ]) {
234+ if ($ old_record ["database_name " ] != $ dbname_prefix . $ this ->dataRecord ["database_name " ]) {
236235 $ app ->tform ->errorMessage .= $ app ->tform ->wordbook ["database_name_change_txt " ].'<br /> ' ;
237236 }
238237 if ($ old_record ["database_charset " ] != $ this ->dataRecord ["database_charset " ]) {
@@ -311,336 +310,4 @@ function onAfterUpdate() {
311310$ page = new page_action ;
312311$ page ->onLoad ();
313312
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
646313?>
0 commit comments