From 5190fe6131c81a97b333b6e8f828495e628ce1ba Mon Sep 17 00:00:00 2001
From: vogelor <vogelor@ispconfig3>
Date: Sun, 14 Dec 2008 11:08:10 -0500
Subject: [PATCH] The names of the database, the database-user, the shell-user and the ftp-user can now be restricted

---
 interface/web/sites/database_edit.php |   44 +++++++++++++++++++++++++++++---------------
 1 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/interface/web/sites/database_edit.php b/interface/web/sites/database_edit.php
index 18ace21..5147265 100644
--- a/interface/web/sites/database_edit.php
+++ b/interface/web/sites/database_edit.php
@@ -150,10 +150,14 @@
 		}
 
 		/*
-		 * If the names are restricted -> remove the client, so that the
+		 * If the names are restricted -> remove the restriction, so that the
 		 * data can be edited
 		 */
 		if ($interfaceConf['restrict_names'] == true){
+			/* get the restriction */
+			$restriction = '[CLIENTNAME]_';
+			if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname'];
+			$tmpRestriction = $restriction;
 			/* Get the group-id */
 			if($_SESSION["s"]["user"]["typ"] != 'admin') {
 				// Get the group-id of the user
@@ -168,18 +172,19 @@
 			$clientName = $tmp['name'];
 			if ($clientName == "") $clientName = 'default';
 			$clientName = convertClientName($clientName);
+			$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
 			if ($this->dataRecord['database_name'] != ""){
 				/* REMOVE the restriction */
-				$app->tpl->setVar("database_name", str_replace($clientName . '_' , '', $this->dataRecord['database_name']));
-				$app->tpl->setVar("database_user", str_replace($clientName . '_' , '', $this->dataRecord['database_user']));
+				$app->tpl->setVar("database_name", str_replace($restriction , '', $this->dataRecord['database_name']));
+				$app->tpl->setVar("database_user", str_replace($restriction , '', $this->dataRecord['database_user']));
 			}
 			if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
-				$app->tpl->setVar("database_name_prefix", '{client}_');
-				$app->tpl->setVar("database_user_prefix", '{client}_');
+				$app->tpl->setVar("database_name_prefix", $tmpRestriction);
+				$app->tpl->setVar("database_user_prefix", $tmpRestriction);
 			}
 			else {
-				$app->tpl->setVar("database_name_prefix", $clientName . '_');
-				$app->tpl->setVar("database_user_prefix", $clientName . '_');
+				$app->tpl->setVar("database_name_prefix", $restriction);
+				$app->tpl->setVar("database_user_prefix", $restriction);
 			}
 		}
 
@@ -231,6 +236,10 @@
 		 * If the names should be restricted -> do it!
 		 */
 		if ($interfaceConf['restrict_names'] == true){
+			/* get the restriction */
+			$restriction = '[CLIENTNAME]_';
+			if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname'];
+
 			/* Get the group-id */
 			if($_SESSION["s"]["user"]["typ"] != 'admin') {
 				// Get the group-id of the user
@@ -245,17 +254,17 @@
 			$clientName = $tmp['name'];
 			if ($clientName == "") $clientName = 'default';
 			$clientName = convertClientName($clientName);
-			$nameSuffix = $clientName . '_';
+			$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
 		}
 		else {
-			$nameSuffix = '';
+			$restriction = '';
 		}
 
 		$error = false;
 
 		//* Prevent that the database name and charset is changed
 		$old_record = $app->tform->getDataRecord($this->id);
-		if($old_record["database_name"] != $nameSuffix . $this->dataRecord["database_name"]) {
+		if($old_record["database_name"] != $restriction . $this->dataRecord["database_name"]) {
 			$app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'<br />';
 			$error = true;
 		}
@@ -278,8 +287,8 @@
 
 		if ($error == false){
 			/* restrict the names if there is no error */
-			$this->dataRecord['database_name'] = $nameSuffix . $this->dataRecord['database_name'];
-			$this->dataRecord['database_user'] = $nameSuffix . $this->dataRecord['database_user'];
+			$this->dataRecord['database_name'] = $restriction . $this->dataRecord['database_name'];
+			$this->dataRecord['database_user'] = $restriction . $this->dataRecord['database_user'];
 		}
 
 		parent::onBeforeUpdate();
@@ -287,12 +296,15 @@
 
 	function onBeforeInsert() {
 		global $app, $conf, $interfaceConf;
-		global $interfaceConf;
 
 		/*
 		 * If the names should be restricted -> do it!
 		 */
 		if ($interfaceConf['restrict_names'] == true){
+			/* get the restriction */
+			$restriction = '[CLIENTNAME]_';
+			if (isset($interfaceConf['restrict_dbname'])) $restriction = $interfaceConf['restrict_dbname'];
+
 			/* Get the group-id */
 			if($_SESSION["s"]["user"]["typ"] != 'admin') {
 				// Get the group-id of the user
@@ -307,9 +319,11 @@
 			$clientName = $tmp['name'];
 			if ($clientName == "") $clientName = 'default';
 			$clientName = convertClientName($clientName);
+			$restriction = str_replace('[CLIENTNAME]', $clientName, $restriction);
+
 			/* restrict the names */
-			$this->dataRecord['database_name'] = $clientName . '_' . $this->dataRecord['database_name'];
-			$this->dataRecord['database_user'] = $clientName . '_' . $this->dataRecord['database_user'];
+			$this->dataRecord['database_name'] = $restriction . $this->dataRecord['database_name'];
+			$this->dataRecord['database_user'] = $restriction . $this->dataRecord['database_user'];
 		}
 		parent::onBeforeInsert();
 	}

--
Gitblit v1.9.1