add testing for mysql-server/customer-update of allowed_mysqlserver; beautify config-command/file details
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -479,7 +479,7 @@ abstract class ApiCommand extends ApiParameter
|
||||
{
|
||||
$customer_ids = [];
|
||||
if ($this->isAdmin()) {
|
||||
// if we're an admin, list all ftp-users of all the admins customers
|
||||
// if we're an admin, list all of the admins customers
|
||||
// or optionally for one specific customer identified by id or loginname
|
||||
$customerid = $this->getParam('customerid', true, 0);
|
||||
$loginname = $this->getParam('loginname', true, '');
|
||||
|
||||
@@ -1117,7 +1117,21 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
}
|
||||
|
||||
// validate allowed_mysqls whether the customer has databases on a removed, now disallowed db-server and abort if true
|
||||
// @todo
|
||||
$former_allowed_mysqlserver = json_decode($result['allowed_mysqlserver'], true);
|
||||
if ($allowed_mysqlserver != $former_allowed_mysqlserver) {
|
||||
$to_remove_mysqlserver = array_diff($former_allowed_mysqlserver, $allowed_mysqlserver);
|
||||
if (count($to_remove_mysqlserver) > 0) {
|
||||
foreach ($to_remove_mysqlserver as $mysqlserver_check) {
|
||||
$result_ms = $this->apiCall('MysqlServer.databasesOnServer', [
|
||||
'mysql_server' => $mysqlserver_check,
|
||||
'customerid' => $id
|
||||
]);
|
||||
if ($result_ms['count'] > 0) {
|
||||
Response::standardError('mysqlserverstillhasdbs', '', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($email == '') {
|
||||
Response::standardError([
|
||||
|
||||
@@ -31,6 +31,7 @@ use PDOException;
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\Api\ApiCommand;
|
||||
use Froxlor\Api\ResourceEntity;
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\Validate\Validate;
|
||||
|
||||
class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
@@ -274,6 +275,31 @@ class MysqlServer extends ApiCommand implements ResourceEntity
|
||||
throw new Exception('@TODO Later', 303);
|
||||
}
|
||||
|
||||
/**
|
||||
* check whether a given customer / current user (as customer) has
|
||||
* databases on the given dbserver
|
||||
*
|
||||
* @param int mysql_server
|
||||
* @param int $customerid
|
||||
* optional, admin-only, select ftp-users of a specific customer by id
|
||||
* @param string $loginname
|
||||
* optional, admin-only, select ftp-users of a specific customer by loginname
|
||||
*
|
||||
* @access admin, customer
|
||||
* @return string json-encoded array count
|
||||
*/
|
||||
public function databasesOnServer()
|
||||
{
|
||||
$dbserver = $this->getParam('mysql_server');
|
||||
$customer_ids = $this->getAllowedCustomerIds();
|
||||
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT COUNT(*) num_dbs FROM `" . TABLE_PANEL_DATABASES . "`
|
||||
WHERE `customerid` IN (" . implode(", ", $customer_ids) . ") AND `dbserver` = :dbserver");
|
||||
$result = Database::pexecute_first($result_stmt, ['dbserver' => $dbserver], true, true);
|
||||
return $this->response(['count' => $result['num_dbs']]);
|
||||
}
|
||||
|
||||
private function generateNewUserData(array $sql, array $sql_root)
|
||||
{
|
||||
$content = '<?php' . PHP_EOL;
|
||||
|
||||
@@ -846,7 +846,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
|
||||
public function listing()
|
||||
{
|
||||
if ($this->isAdmin()) {
|
||||
// if we're an admin, list all databases of all the admins customers
|
||||
// if we're an admin, list all subdomains of all the admins customers
|
||||
// or optionally for one specific customer identified by id or loginname
|
||||
$customerid = $this->getParam('customerid', true, 0);
|
||||
$loginname = $this->getParam('loginname', true, '');
|
||||
|
||||
Reference in New Issue
Block a user