From bb3716c03ebfb41ea8ecea658e0dec1841d46c00 Mon Sep 17 00:00:00 2001 From: Benjamin Bittner Date: Tue, 1 Jan 2013 12:50:10 +0100 Subject: [PATCH] Feature #1150; Add random SQL-Prefixes to customer DBs --- customer_mysql.php | 15 ++++++++++++++- lng/english.lng.php | 2 +- lng/german.lng.php | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/customer_mysql.php b/customer_mysql.php index a7eb13fc..739be394 100644 --- a/customer_mysql.php +++ b/customer_mysql.php @@ -162,7 +162,6 @@ elseif($page == 'mysqls') } else { - $username = $userinfo['loginname'] . $settings['customer']['mysqlprefix'] . (intval($userinfo['mysql_lastaccountnumber']) + 1); if(count($sql_root) > 1) { @@ -181,6 +180,20 @@ elseif($page == 'mysqls') // Begin root-session $db_root = new db($sql_root[$dbserver]['host'], $sql_root[$dbserver]['user'], $sql_root[$dbserver]['password'], ''); + + if ($settings['customer']['mysqlprefix'] == "RANDOM") { + $result = $db_root->query('SELECT `User` FROM mysql.user'); + while ($row = $db_root->fetch_array($result)) { + $allsqlusers[] = $row[User]; + } + $username = $userinfo['loginname'] . '-' . substr(md5(uniqid(microtime(), 1)), 20, 3); + while (in_Array($username , $allsqlusers)) { + $username = $userinfo['loginname'] . '-' . substr(md5(uniqid(microtime(), 1)), 20, 3); + } + } else { + $username = $userinfo['loginname'] . $settings['customer']['mysqlprefix'] . (intval($userinfo['mysql_lastaccountnumber']) + 1); + } + $db_root->query('CREATE DATABASE `' . $db_root->escape($username) . '`'); $log->logAction(USR_ACTION, LOG_INFO, "created database '" . $username . "'"); foreach(array_map('trim', explode(',', $settings['system']['mysql_access_host'])) as $mysql_access_host) diff --git a/lng/english.lng.php b/lng/english.lng.php index 08f766a1..493915de 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -339,7 +339,7 @@ $lng['serversettings']['session_timeout']['description'] = 'How long does a user $lng['serversettings']['accountprefix']['title'] = 'Customer prefix'; $lng['serversettings']['accountprefix']['description'] = 'Which prefix should customer accounts have?'; $lng['serversettings']['mysqlprefix']['title'] = 'SQL Prefix'; -$lng['serversettings']['mysqlprefix']['description'] = 'Which prefix should MySQL accounts have?'; +$lng['serversettings']['mysqlprefix']['description'] = 'Which prefix should MySQL accounts have?
Use "RANDOM" as vlaue to get a 3-digit random prefix'; $lng['serversettings']['ftpprefix']['title'] = 'FTP Prefix'; $lng['serversettings']['ftpprefix']['description'] = 'Which prefix should ftp accounts have?'; $lng['serversettings']['documentroot_prefix']['title'] = 'Home directory'; diff --git a/lng/german.lng.php b/lng/german.lng.php index 661581f5..62d3f930 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -339,7 +339,7 @@ $lng['serversettings']['session_timeout']['description'] = 'Wie lange muss ein B $lng['serversettings']['accountprefix']['title'] = 'Kundenprefix'; $lng['serversettings']['accountprefix']['description'] = 'Welchen Prefix sollen die Kundenaccounts haben?'; $lng['serversettings']['mysqlprefix']['title'] = 'SQL-Prefix'; -$lng['serversettings']['mysqlprefix']['description'] = 'Welchen Prefix sollen die MySQL-Benutzerkonten haben?'; +$lng['serversettings']['mysqlprefix']['description'] = 'Welchen Prefix sollen die MySQL-Benutzerkonten haben?
Mit "RANDOM" als Wert wird ein 3-Stelliger Zufallswert als Prefix genutzt'; $lng['serversettings']['ftpprefix']['title'] = 'FTP-Prefix'; $lng['serversettings']['ftpprefix']['description'] = 'Welchen Prefix sollen die FTP-Benutzerkonten haben?'; $lng['serversettings']['documentroot_prefix']['title'] = 'Heimatverzeichnis';