* 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:
@@ -17,7 +17,7 @@ use Froxlor\Settings;
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package API
|
||||
* @since 0.10.0
|
||||
*
|
||||
*
|
||||
*/
|
||||
class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEntity
|
||||
{
|
||||
@@ -31,13 +31,15 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
* optional, default is 0
|
||||
* @param string $description
|
||||
* optional, description for database
|
||||
* @param string $custom_suffix
|
||||
* optional, name for database
|
||||
* @param bool $sendinfomail
|
||||
* optional, send created resource-information to customer, default: false
|
||||
* @param int $customerid
|
||||
* optional, required when called as admin (if $loginname is not specified)
|
||||
* @param string $loginname
|
||||
* optional, required when called as admin (if $customerid is not specified)
|
||||
*
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws \Exception
|
||||
* @return string json-encoded array
|
||||
@@ -50,6 +52,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
// parameters
|
||||
$dbserver = $this->getParam('mysql_server', true, 0);
|
||||
$databasedescription = $this->getParam('description', true, '');
|
||||
$databasename = $this->getParam('custom_suffix', true, '');
|
||||
$sendinfomail = $this->getBoolParam('sendinfomail', true, 0);
|
||||
// get needed customer info to reduce the mysql-usage-counter by one
|
||||
$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\System\Crypt::validatePassword($password, 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
|
||||
$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.
|
||||
$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
|
||||
if ($username == false) {
|
||||
@@ -181,7 +190,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
* optional, the databasename
|
||||
* @param int $mysql_server
|
||||
* optional, specify database-server, default is none
|
||||
*
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws \Exception
|
||||
* @return string json-encoded array
|
||||
@@ -281,7 +290,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
* optional, required when called as admin (if $loginname is not specified)
|
||||
* @param string $loginname
|
||||
* optional, required when called as admin (if $customerid is not specified)
|
||||
*
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws \Exception
|
||||
* @return string json-encoded array
|
||||
@@ -370,7 +379,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
* optional specify offset for resultset
|
||||
* @param array $sql_orderby
|
||||
* optional array with index = fieldname and value = ASC|DESC to order the resultset by one or more fields
|
||||
*
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws \Exception
|
||||
* @return string json-encoded array count|list
|
||||
@@ -434,7 +443,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
* optional, admin-only, select dbs of a specific customer by id
|
||||
* @param string $loginname
|
||||
* optional, admin-only, select dbs of a specific customer by loginname
|
||||
*
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws \Exception
|
||||
* @return string json-encoded array
|
||||
@@ -465,7 +474,7 @@ class Mysqls extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
|
||||
* optional, required when called as admin (if $loginname is not specified)
|
||||
* @param string $loginname
|
||||
* optional, required when called as admin (if $customerid is not specified)
|
||||
*
|
||||
*
|
||||
* @access admin, customer
|
||||
* @throws \Exception
|
||||
* @return string json-encoded array
|
||||
|
||||
@@ -16,9 +16,9 @@ use Froxlor\Settings;
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*
|
||||
*
|
||||
* @since 0.9.31
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -87,6 +87,8 @@ class DbManager
|
||||
while (in_array($username, $allsqlusers)) {
|
||||
$username = $loginname . '-' . substr(md5(uniqid(microtime(), 1)), 20, 3);
|
||||
}
|
||||
} elseif (strtoupper(Settings::Get('customer.mysqlprefix')) == 'DBNAME') {
|
||||
$username = $loginname;
|
||||
} else {
|
||||
$username = $loginname . Settings::Get('customer.mysqlprefix') . (intval($last_accnumber) + 1);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Froxlor\Settings;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
@@ -22,6 +24,11 @@ return array(
|
||||
'title' => $lng['mysql']['database_create'],
|
||||
'image' => 'icons/mysql_add.png',
|
||||
'fields' => array(
|
||||
'custom_suffix' => array(
|
||||
'visible' => (strtoupper(Settings::Get('customer.mysqlprefix')) == 'DBNAME') ? true : false,
|
||||
'label' => $lng['mysql']['databasename'],
|
||||
'type' => 'text'
|
||||
),
|
||||
'description' => array(
|
||||
'label' => $lng['mysql']['databasedescription'],
|
||||
'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']['description'] = 'Which prefix should customer accounts have?';
|
||||
$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']['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';
|
||||
|
||||
@@ -327,7 +327,7 @@ $lng['serversettings']['session_timeout']['description'] = 'Wie lange muss ein B
|
||||
$lng['serversettings']['accountprefix']['title'] = 'Kundenpräfix';
|
||||
$lng['serversettings']['accountprefix']['description'] = 'Welchen Präfix sollen die Kundenaccounts haben?';
|
||||
$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']['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';
|
||||
|
||||
@@ -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
|
||||
@@ -136,7 +169,7 @@ class MysqlsTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @depends testCustomerMysqlsAdd
|
||||
@@ -144,7 +177,7 @@ class MysqlsTest extends TestCase
|
||||
public function testAdminMysqlsUpdatePwdOnly()
|
||||
{
|
||||
global $admin_userdata;
|
||||
|
||||
|
||||
$newPwd = \Froxlor\System\Crypt::generatePassword();
|
||||
$data = [
|
||||
'dbname' => 'test1sql1',
|
||||
@@ -172,12 +205,13 @@ class MysqlsTest extends TestCase
|
||||
|
||||
$json_result = Mysqls::getLocal($customer_userdata)->listing();
|
||||
$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('test1_abc123', $result['list'][1]['databasename']);
|
||||
|
||||
$json_result = Mysqls::getLocal($customer_userdata)->listingCount();
|
||||
$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']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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
|
||||
|
||||
Reference in New Issue
Block a user