* Fix makeoption function call * Update formfield.mysql_add.php Added database name * Update formfield.mysql_add.php * Update formfield.mysql_add.php * Update Mysqls.php * Update DbManager.php * Update formfield.mysql_add.php * Update german.lng.php * Update formfield.mysql_add.php * Update Mysqls.php * Added field database_name (Feature #672) * Added Testfunction for customer choosed database name * Fixed test for customer choosed database name Added docs for param $name * Fixed mysql api command add Removed doubled code * Set settings for customer choosed db name * Fixed wrong excepted for database name * Renamed parameter database_name to custom_suffix * Changed testCustomerMysqlsList Added testCustomerMysqlsDBNameDelete
This commit is contained in:
@@ -31,6 +31,8 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
|||||||
* optional, default is 0
|
* optional, default is 0
|
||||||
* @param string $description
|
* @param string $description
|
||||||
* optional, description for database
|
* optional, description for database
|
||||||
|
* @param string $custom_suffix
|
||||||
|
* optional, name for database
|
||||||
* @param bool $sendinfomail
|
* @param bool $sendinfomail
|
||||||
* optional, send created resource-information to customer, default: false
|
* optional, send created resource-information to customer, default: false
|
||||||
* @param int $customerid
|
* @param int $customerid
|
||||||
@@ -50,6 +52,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
|||||||
// parameters
|
// parameters
|
||||||
$dbserver = $this->getParam('mysql_server', true, 0);
|
$dbserver = $this->getParam('mysql_server', true, 0);
|
||||||
$databasedescription = $this->getParam('description', true, '');
|
$databasedescription = $this->getParam('description', true, '');
|
||||||
|
$databasename = $this->getParam('custom_suffix', true, '');
|
||||||
$sendinfomail = $this->getBoolParam('sendinfomail', true, 0);
|
$sendinfomail = $this->getBoolParam('sendinfomail', true, 0);
|
||||||
// get needed customer info to reduce the mysql-usage-counter by one
|
// get needed customer info to reduce the mysql-usage-counter by one
|
||||||
$customer = $this->getCustomerData('mysqls');
|
$customer = $this->getCustomerData('mysqls');
|
||||||
@@ -58,6 +61,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
|||||||
$password = \Froxlor\Validate\Validate::validate($password, 'password', '', '', array(), true);
|
$password = \Froxlor\Validate\Validate::validate($password, 'password', '', '', array(), true);
|
||||||
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
$password = \Froxlor\System\Crypt::validatePassword($password, true);
|
||||||
$databasedescription = \Froxlor\Validate\Validate::validate(trim($databasedescription), 'description', '', '', array(), true);
|
$databasedescription = \Froxlor\Validate\Validate::validate(trim($databasedescription), 'description', '', '', array(), true);
|
||||||
|
$databasename = \Froxlor\Validate\Validate::validate(trim($databasename), 'database_name', '', '', array(), true);
|
||||||
|
|
||||||
// validate whether the dbserver exists
|
// validate whether the dbserver exists
|
||||||
$dbserver = \Froxlor\Validate\Validate::validate($dbserver, html_entity_decode($this->lng['mysql']['mysql_server']), '', '', 0, true);
|
$dbserver = \Froxlor\Validate\Validate::validate($dbserver, html_entity_decode($this->lng['mysql']['mysql_server']), '', '', 0, true);
|
||||||
@@ -79,7 +83,12 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
|||||||
);
|
);
|
||||||
// create database, user, set permissions, etc.pp.
|
// create database, user, set permissions, etc.pp.
|
||||||
$dbm = new \Froxlor\Database\DbManager($this->logger());
|
$dbm = new \Froxlor\Database\DbManager($this->logger());
|
||||||
$username = $dbm->createDatabase($newdb_params['loginname'], $password, $newdb_params['mysql_lastaccountnumber']);
|
|
||||||
|
if(strtoupper(Settings::Get('customer.mysqlprefix')) == 'DBNAME' && !empty($databasename)) {
|
||||||
|
$username = $dbm->createDatabase($newdb_params['loginname'].'_'.$databasename, $password);
|
||||||
|
} else {
|
||||||
|
$username = $dbm->createDatabase($newdb_params['loginname'], $password, $newdb_params['mysql_lastaccountnumber']);
|
||||||
|
}
|
||||||
|
|
||||||
// we've checked against the password in dbm->createDatabase
|
// we've checked against the password in dbm->createDatabase
|
||||||
if ($username == false) {
|
if ($username == false) {
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ class DbManager
|
|||||||
while (in_array($username, $allsqlusers)) {
|
while (in_array($username, $allsqlusers)) {
|
||||||
$username = $loginname . '-' . substr(md5(uniqid(microtime(), 1)), 20, 3);
|
$username = $loginname . '-' . substr(md5(uniqid(microtime(), 1)), 20, 3);
|
||||||
}
|
}
|
||||||
|
} elseif (strtoupper(Settings::Get('customer.mysqlprefix')) == 'DBNAME') {
|
||||||
|
$username = $loginname;
|
||||||
} else {
|
} else {
|
||||||
$username = $loginname . Settings::Get('customer.mysqlprefix') . (intval($last_accnumber) + 1);
|
$username = $loginname . Settings::Get('customer.mysqlprefix') . (intval($last_accnumber) + 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Froxlor\Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file is part of the Froxlor project.
|
* This file is part of the Froxlor project.
|
||||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||||
@@ -22,6 +24,11 @@ return array(
|
|||||||
'title' => $lng['mysql']['database_create'],
|
'title' => $lng['mysql']['database_create'],
|
||||||
'image' => 'icons/mysql_add.png',
|
'image' => 'icons/mysql_add.png',
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
|
'custom_suffix' => array(
|
||||||
|
'visible' => (strtoupper(Settings::Get('customer.mysqlprefix')) == 'DBNAME') ? true : false,
|
||||||
|
'label' => $lng['mysql']['databasename'],
|
||||||
|
'type' => 'text'
|
||||||
|
),
|
||||||
'description' => array(
|
'description' => array(
|
||||||
'label' => $lng['mysql']['databasedescription'],
|
'label' => $lng['mysql']['databasedescription'],
|
||||||
'type' => 'text'
|
'type' => 'text'
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ $lng['serversettings']['session_timeout']['description'] = 'How long does a user
|
|||||||
$lng['serversettings']['accountprefix']['title'] = 'Customer prefix';
|
$lng['serversettings']['accountprefix']['title'] = 'Customer prefix';
|
||||||
$lng['serversettings']['accountprefix']['description'] = 'Which prefix should customer accounts have?';
|
$lng['serversettings']['accountprefix']['description'] = 'Which prefix should customer accounts have?';
|
||||||
$lng['serversettings']['mysqlprefix']['title'] = 'SQL Prefix';
|
$lng['serversettings']['mysqlprefix']['title'] = 'SQL Prefix';
|
||||||
$lng['serversettings']['mysqlprefix']['description'] = 'Which prefix should MySQL accounts have?</br>Use "RANDOM" as value to get a 3-digit random prefix';
|
$lng['serversettings']['mysqlprefix']['description'] = 'Which prefix should MySQL accounts have?</br>Use "RANDOM" as value to get a 3-digit random prefix</br>Use "DBNAME" as the value, a database name field is used together with the customer name as a prefix.';
|
||||||
$lng['serversettings']['ftpprefix']['title'] = 'FTP Prefix';
|
$lng['serversettings']['ftpprefix']['title'] = 'FTP Prefix';
|
||||||
$lng['serversettings']['ftpprefix']['description'] = 'Which prefix should ftp accounts have?<br/><b>If you change this you also have to change the Quota SQL Query in your FTP Server config file in case you use it!</b> ';
|
$lng['serversettings']['ftpprefix']['description'] = 'Which prefix should ftp accounts have?<br/><b>If you change this you also have to change the Quota SQL Query in your FTP Server config file in case you use it!</b> ';
|
||||||
$lng['serversettings']['documentroot_prefix']['title'] = 'Home directory';
|
$lng['serversettings']['documentroot_prefix']['title'] = 'Home directory';
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ $lng['serversettings']['session_timeout']['description'] = 'Wie lange muss ein B
|
|||||||
$lng['serversettings']['accountprefix']['title'] = 'Kundenpräfix';
|
$lng['serversettings']['accountprefix']['title'] = 'Kundenpräfix';
|
||||||
$lng['serversettings']['accountprefix']['description'] = 'Welchen Präfix sollen die Kundenaccounts haben?';
|
$lng['serversettings']['accountprefix']['description'] = 'Welchen Präfix sollen die Kundenaccounts haben?';
|
||||||
$lng['serversettings']['mysqlprefix']['title'] = 'MySQL-Präfix';
|
$lng['serversettings']['mysqlprefix']['title'] = 'MySQL-Präfix';
|
||||||
$lng['serversettings']['mysqlprefix']['description'] = 'Welchen Präfix sollen die MySQL-Benutzerkonten haben?</br>Mit "RANDOM" als Wert wird ein 3-stelliger Zufallswert als Präfix verwendet.';
|
$lng['serversettings']['mysqlprefix']['description'] = 'Welchen Präfix sollen die MySQL-Benutzerkonten haben?</br>Mit "RANDOM" als Wert wird ein 3-stelliger Zufallswert als Präfix verwendet.</br>Mit "DBNAME" als Wert wird ein Feld Databankname zusammen mit dem Kundennamen als Präfix genutzt.';
|
||||||
$lng['serversettings']['ftpprefix']['title'] = 'FTP-Präfix';
|
$lng['serversettings']['ftpprefix']['title'] = 'FTP-Präfix';
|
||||||
$lng['serversettings']['ftpprefix']['description'] = 'Welchen Präfix sollen die FTP-Benutzerkonten haben?<br/><b>Falls FTP-Quoatas verwendet werden, ist es notwendig das Quota-SQL-Query in der FTP-Server-Config ebenfalls zu ändern!</b>';
|
$lng['serversettings']['ftpprefix']['description'] = 'Welchen Präfix sollen die FTP-Benutzerkonten haben?<br/><b>Falls FTP-Quoatas verwendet werden, ist es notwendig das Quota-SQL-Query in der FTP-Server-Config ebenfalls zu ändern!</b>';
|
||||||
$lng['serversettings']['documentroot_prefix']['title'] = 'Heimatverzeichnis';
|
$lng['serversettings']['documentroot_prefix']['title'] = 'Heimatverzeichnis';
|
||||||
|
|||||||
@@ -52,6 +52,39 @@ class MysqlsTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCustomerMysqlsDBNameAdd() {
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
// Set customer.mysqlprefix to DBNAME
|
||||||
|
Settings::Set('customer.mysqlprefix', 'DBNAME');
|
||||||
|
|
||||||
|
$newPwd = \Froxlor\System\Crypt::generatePassword();
|
||||||
|
$data = [
|
||||||
|
'mysql_password' => $newPwd,
|
||||||
|
'custom_suffix' => 'abc123',
|
||||||
|
'description' => 'testdb',
|
||||||
|
'sendinfomail' => TRAVIS_CI == 1 ? 0 : 1
|
||||||
|
];
|
||||||
|
$json_result = Mysqls::getLocal($customer_userdata, $data)->add();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals('test1_abc123', $result['databasename']);
|
||||||
|
$this->assertEquals(0, $result['dbserver']);
|
||||||
|
|
||||||
|
// test connection
|
||||||
|
try {
|
||||||
|
$test_conn = new \PDO("mysql:host=127.0.0.1", 'test1_abc123', $newPwd);
|
||||||
|
unset($test_conn);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$this->fail($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @depends testCustomerMysqlsAdd
|
* @depends testCustomerMysqlsAdd
|
||||||
@@ -172,12 +205,13 @@ class MysqlsTest extends TestCase
|
|||||||
|
|
||||||
$json_result = Mysqls::getLocal($customer_userdata)->listing();
|
$json_result = Mysqls::getLocal($customer_userdata)->listing();
|
||||||
$result = json_decode($json_result, true)['data'];
|
$result = json_decode($json_result, true)['data'];
|
||||||
$this->assertEquals(1, $result['count']);
|
$this->assertEquals(2, $result['count']);
|
||||||
$this->assertEquals('test1sql1', $result['list'][0]['databasename']);
|
$this->assertEquals('test1sql1', $result['list'][0]['databasename']);
|
||||||
|
$this->assertEquals('test1_abc123', $result['list'][1]['databasename']);
|
||||||
|
|
||||||
$json_result = Mysqls::getLocal($customer_userdata)->listingCount();
|
$json_result = Mysqls::getLocal($customer_userdata)->listingCount();
|
||||||
$result = json_decode($json_result, true)['data'];
|
$result = json_decode($json_result, true)['data'];
|
||||||
$this->assertEquals(1, $result);
|
$this->assertEquals(2, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -202,6 +236,28 @@ class MysqlsTest extends TestCase
|
|||||||
$this->assertEquals('test1sql1', $result['databasename']);
|
$this->assertEquals('test1sql1', $result['databasename']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @depends testCustomerMysqlsList
|
||||||
|
*/
|
||||||
|
public function testCustomerMysqlsDBNameDelete()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'dbname' => 'test1_abc123'
|
||||||
|
];
|
||||||
|
$json_result = Mysqls::getLocal($customer_userdata, $data)->delete();
|
||||||
|
$result = json_decode($json_result, true)['data'];
|
||||||
|
$this->assertEquals('test1_abc123', $result['databasename']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @depends testCustomerMysqlsAdd
|
* @depends testCustomerMysqlsAdd
|
||||||
|
|||||||
Reference in New Issue
Block a user