simplified and wrapped internal api calls

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2018-03-04 18:30:16 +01:00
parent b664917147
commit cfa07bab47
10 changed files with 209 additions and 221 deletions

View File

@@ -331,36 +331,6 @@ abstract class ApiCommand
return $param_value;
}
/**
* returns "module::function()" for better error-messages (missing parameter etc.)
* makes debugging a whole lot more comfortable
*
* @return string
*/
private function getModFunctionString()
{
$_class = get_called_class();
$level = 2;
if (version_compare(PHP_VERSION, "5.4.0", "<")) {
$trace = debug_backtrace();
} else {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
while (true) {
$class = $trace[$level]['class'];
$func = $trace[$level]['function'];
if ($class != $_class) {
$level ++;
if ($level > 5) {
break;
}
continue;
}
return $class . ':' . $func;
}
}
/**
* update value of parameter
*
@@ -399,6 +369,24 @@ abstract class ApiCommand
return $this->mail;
}
/**
* call an api-command internally
*
* @param string $module
* @param string $function
* @param array|null $params
*
* @return array
*/
protected function apiCall($command = null, $params = null)
{
$_command = explode(".", $command);
$module = $_command[0];
$function = $_command[1];
$json_result = $module::getLocal($this->getUserData(), $params)->{$function}();
return json_decode($json_result, true)['data'];
}
/**
* return api-compatible response in JSON format and send corresponding http-header
*
@@ -448,6 +436,35 @@ abstract class ApiCommand
), true, true);
}
/**
* returns "module::function()" for better error-messages (missing parameter etc.)
* makes debugging a whole lot more comfortable
*
* @return string
*/
private function getModFunctionString()
{
$_class = get_called_class();
$level = 2;
if (version_compare(PHP_VERSION, "5.4.0", "<")) {
$trace = debug_backtrace();
} else {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
while (true) {
$class = $trace[$level]['class'];
$func = $trace[$level]['function'];
if ($class != $_class) {
$level ++;
if ($level > 5) {
break;
}
continue;
}
return $class . ':' . $func;
}
}
/**
* read user data from database by api-request-header fields
*
@@ -490,6 +507,13 @@ abstract class ApiCommand
throw new Exception("Invalid API credentials", 400);
}
/**
* run 'trim' function on an array recursively
*
* @param array $input
*
* @return array
*/
private function trimArray($input)
{
if (! is_array($input)) {

View File

@@ -285,10 +285,9 @@ class Admins extends ApiCommand implements ResourceEntity
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] added admin '" . $loginname . "'");
// get all admin-data for return-array
$json_result = Admins::getLocal($this->getUserData(), array(
$result = $this->apiCall('Admins.get', array(
'id' => $adminid
))->get();
$result = json_decode($json_result, true)['data'];
));
return $this->response(200, "successfull", $result);
}
}
@@ -314,12 +313,11 @@ class Admins extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$json_result = Admins::getLocal($this->getUserData(), array(
$result = $this->apiCall('Admins.get', array(
'id' => $id,
'loginname' => $loginname
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['adminid'];
if ($this->getUserDetail('change_serversettings') == 1 || $result['adminid'] == $this->getUserDetail('adminid')) {
@@ -553,10 +551,9 @@ class Admins extends ApiCommand implements ResourceEntity
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] edited admin '" . $result['loginname'] . "'");
// get all admin-data for return-array
$json_result = Admins::getLocal($this->getUserData(), array(
$result = $this->apiCall('Admins.get', array(
'id' => $result['adminid']
))->get();
$result = json_decode($json_result, true)['data'];
));
return $this->response(200, "successfull", $result);
}
}
@@ -582,12 +579,11 @@ class Admins extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$json_result = Admins::getLocal($this->getUserData(), array(
$result = $this->apiCall('Admins.get', array(
'id' => $id,
'loginname' => $loginname
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['adminid'];
// don't be stupid
@@ -684,11 +680,10 @@ class Admins extends ApiCommand implements ResourceEntity
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$json_result = Admins::getLocal($this->getUserData(), array(
$result = $this->apiCall('Admins.get', array(
'id' => $id,
'loginname' => $loginname
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['adminid'];
$result_stmt = Database::prepare("

View File

@@ -536,8 +536,8 @@ class Customers extends ApiCommand implements ResourceEntity
);
$domainid = - 1;
try {
$std_domain = Domains::getLocal($this->getUserData(), $ins_data)->add();
$domainid = json_decode($std_domain, true)['data']['id'];
$std_domain = $this->apiCall('Domains.add', $ins_data);
$domainid = $std_domain['id'];
} catch (Exception $e) {
$this->logger()->logAction(ADM_ACTION, LOG_ERR, "[API] Unable to add standard-subdomain: " . $e->getMessage());
}
@@ -638,10 +638,9 @@ class Customers extends ApiCommand implements ResourceEntity
}
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] added customer '" . $loginname . "'");
$json_result = Customers::getLocal($this->getUserData(), array(
$result = $this->apiCall('Customers.get', array(
'loginname' => $loginname
))->get();
$result = json_decode($json_result, true)['data'];
));
return $this->response(200, "successfull", $result);
}
throw new Exception("No more resources available", 406);
@@ -666,12 +665,11 @@ class Customers extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$json_result = Customers::getLocal($this->getUserData(), array(
$result = $this->apiCall('Customers.get', array(
'id' => $id,
'loginname' => $loginname
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['customerid'];
if ($this->isAdmin()) {
@@ -802,8 +800,8 @@ class Customers extends ApiCommand implements ResourceEntity
);
$domainid = - 1;
try {
$std_domain = Domains::getLocal($this->getUserData(), $ins_data)->add();
$domainid = json_decode($std_domain, true)['data']['id'];
$std_domain = $this->apiCall('Domains.add', $ins_data);
$domainid = $std_domain['id'];
} catch (Exception $e) {
$this->logger()->logAction(ADM_ACTION, LOG_ERR, "[API] Unable to add standard-subdomain: " . $e->getMessage());
}
@@ -823,10 +821,10 @@ class Customers extends ApiCommand implements ResourceEntity
if ($createstdsubdomain == '0' && $result['standardsubdomain'] != '0') {
try {
$std_domain = Domains::getLocal($this->getUserData(), array(
$std_domain = $this->apiCall('Domains.delete', array(
'id' => $result['standardsubdomain'],
'is_stdsubdomain' => 1
))->delete();
));
} catch (Exception $e) {
$this->logger()->logAction(ADM_ACTION, LOG_ERR, "[API] Unable to delete standard-subdomain: " . $e->getMessage());
}
@@ -1157,21 +1155,19 @@ class Customers extends ApiCommand implements ResourceEntity
*/
if ($this->isAdmin()) {
if ($move_to_admin > 0 && $move_to_admin != $result['adminid']) {
$json_result = Customers::getLocal($this->getUserData(), array(
$move_result = $this->apiCall('Customers.move', array(
'id' => $result['customerid'],
'adminid' => $move_to_admin
))->move();
$move_result = json_decode($json_result, true)['data'];
));
if ($move_result != true) {
standard_error('moveofcustomerfailed', $move_result, true);
}
}
}
$json_result = Customers::getLocal($this->getUserData(), array(
$result = $this->apiCall('Customers.get', array(
'id' => $result['customerid']
))->get();
$result = json_decode($json_result, true)['data'];
));
return $this->response(200, "successfull", $result);
}
@@ -1196,12 +1192,11 @@ class Customers extends ApiCommand implements ResourceEntity
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$delete_userfiles = $this->getParam('delete_userfiles', true, 0);
$json_result = Customers::getLocal($this->getUserData(), array(
$result = $this->apiCall('Customers.get', array(
'id' => $id,
'loginname' => $loginname
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['customerid'];
// @fixme use Databases-ApiCommand later
@@ -1443,12 +1438,11 @@ class Customers extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$json_result = Customers::getLocal($this->getUserData(), array(
$result = $this->apiCall('Customers.get', array(
'id' => $id,
'loginname' => $loginname
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['customerid'];
$result_stmt = Database::prepare("
@@ -1488,12 +1482,11 @@ class Customers extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$ln_optional = ($id <= 0 ? false : true);
$loginname = $this->getParam('loginname', $ln_optional, '');
$json_result = Customers::getLocal($this->getUserData(), array(
$c_result = $this->apiCall('Customers.get', array(
'id' => $id,
'loginname' => $loginname
))->get();
$c_result = json_decode($json_result, true)['data'];
));
$id = $c_result['customerid'];
// check if target-admin is the current admin
@@ -1502,10 +1495,9 @@ class Customers extends ApiCommand implements ResourceEntity
}
// get target admin
$json_result = Admins::getLocal($this->getUserData(), array(
$a_result = $this->apiCall('Admins.get', array(
'id' => $adminid
))->get();
$a_result = json_decode($json_result, true)['data'];
));
// Update customer entry
$updCustomer_stmt = Database::prepare("
@@ -1538,10 +1530,10 @@ class Customers extends ApiCommand implements ResourceEntity
updateCounters(false);
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] moved user '" . $c_result['loginname'] . "' from admin/reseller '" . $c_result['adminname'] . " to admin/reseller '" . $a_result['loginname'] . "'");
$json_result = Customers::getLocal($this->getUserData(), array(
$result = $this->apiCall('Customers.get', array(
'id' => $c_result['customerid']
))->get();
$result = json_decode($json_result, true)['data'];
));
return $this->response(200, "successfull", $result);
}
throw new Exception("Not allowed to execute given command.", 403);

View File

@@ -178,10 +178,9 @@ class Domains extends ApiCommand implements ResourceEntity
), '', true);
}
$json_result = Customers::getLocal($this->getUserData(), array(
$customer = $this->apiCall('Customers.get', array(
'id' => $customerid
))->get();
$customer = json_decode($json_result, true)['data'];
));
if ($this->getUserDetail('customers_see_all') == '1') {
$admin_stmt = Database::prepare("
@@ -743,10 +742,9 @@ class Domains extends ApiCommand implements ResourceEntity
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] added domain '" . $domain . "'");
$json_result = Domains::getLocal($this->getUserData(), array(
$result = $this->apiCall('Domains.get', array(
'domainname' => $domain
))->get();
$result = json_decode($json_result, true)['data'];
));
return $this->response(200, "successfull", $result);
}
}
@@ -777,12 +775,11 @@ class Domains extends ApiCommand implements ResourceEntity
$domainname = $this->getParam('domainname', $dn_optional, '');
// get requested domain
$json_result = Domains::getLocal($this->getUserData(), array(
$result = $this->apiCall('Domains.get', array(
'id' => $id,
'domainname' => $domainname,
'no_std_subdomain' => true
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['id'];
// optional parameters
@@ -877,8 +874,7 @@ class Domains extends ApiCommand implements ResourceEntity
AND (`subdomains_used` + :subdomains <= `subdomains` OR `subdomains` = '-1' )
AND (`emails_used` + :emails <= `emails` OR `emails` = '-1' )
AND (`email_forwarders_used` + :forwarders <= `email_forwarders` OR `email_forwarders` = '-1' )
AND (`email_accounts_used` + :accounts <= `email_accounts` OR `email_accounts` = '-1' ) " . ($this->getUserDetail('customers_see_all') ? '' : " AND `adminid` = :adminid")
);
AND (`email_accounts_used` + :accounts <= `email_accounts` OR `email_accounts` = '-1' ) " . ($this->getUserDetail('customers_see_all') ? '' : " AND `adminid` = :adminid"));
$params = array(
'customerid' => $customerid,
'subdomains' => $subdomains,
@@ -897,10 +893,9 @@ class Domains extends ApiCommand implements ResourceEntity
$customerid = $result['customerid'];
// get customer
$json_result = Customers::getLocal($this->getUserData(), array(
$customer = $this->apiCall('Customers.get', array(
'id' => $customerid
))->get();
$customer = json_decode($json_result, true)['data'];
));
}
// handle change of admin (move domain from admin to admin)
@@ -1664,11 +1659,10 @@ class Domains extends ApiCommand implements ResourceEntity
$is_stdsubdomain = $this->getParam('is_stdsubdomain', true, 0);
$remove_subbutmain_domains = $this->getParam('delete_mainsubdomains', true, 0);
$json_result = Domains::getLocal($this->getUserData(), array(
$result = $this->apiCall('Domains.get', array(
'id' => $id,
'domainname' => $domainname
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['id'];
// check for deletion of main-domains which are logically subdomains, #329

View File

@@ -192,11 +192,10 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
// required parameter
$id = $this->getParam('id');
$json_result = PhpSettings::getLocal($this->getUserData(), array(
$result = $this->apiCall('PhpSettings.get', array(
'id' => $id
))->get();
$result = json_decode($json_result, true)['data'];
));
// parameters
$description = $this->getParam('description', true, $result['description']);
@@ -283,11 +282,10 @@ class FpmDaemons extends ApiCommand implements ResourceEntity
if ($id == 1) {
standard_error('cannotdeletedefaultphpconfig', '', true);
}
$json_result = FpmDaemons::getLocal($this->getUserData(), array(
$result = $this->apiCall('FpmDaemons.get', array(
'id' => $id
))->get();
$result = json_decode($json_result, true)['data'];
));
// set default fpm daemon config for all php-config that use this config that is to be deleted
$upd_stmt = Database::prepare("

View File

@@ -84,10 +84,9 @@ class Ftps extends ApiCommand implements ResourceEntity
if ($this->isAdmin()) {
// get customer id
$customer_id = $this->getParam('customer_id');
$json_result = Customers::getLocal($this->getUserData(), array(
$customer = $this->apiCall('Customers.get', array(
'id' => $customer_id
))->get();
$customer = json_decode($json_result, true)['data'];
));
// check whether the customer has enough resources to get the ftp-user added
if ($customer['ftps_used'] >= $customer['ftps'] && $customer['ftps'] != '-1') {
throw new Exception("Customer has no more resources available", 406);
@@ -254,11 +253,10 @@ class Ftps extends ApiCommand implements ResourceEntity
$this->mailer()->ClearAddresses();
}
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_WARNING, "[API] added ftp-user '" . $username . "'");
$json_result = Ftps::getLocal($this->getUserData(), array(
$result = $this->apiCall('Ftps.get', array(
'username' => $username
))->get();
$result = json_decode($json_result, true)['data'];
));
return $this->response(200, "successfull", $result);
}
}
@@ -288,8 +286,8 @@ class Ftps extends ApiCommand implements ResourceEntity
if ($this->getUserDetail('customers_see_all') == false) {
// if it's a reseller or an admin who cannot see all customers, we need to check
// whether the database belongs to one of his customers
$json_result = Customers::getLocal($this->getUserData())->listing();
$custom_list_result = json_decode($json_result, true)['data']['list'];
$_custom_list_result = $this->apiCall('Customers.listing');
$custom_list_result = $_custom_list_result['list'];
$customer_ids = array();
foreach ($custom_list_result as $customer) {
$customer_ids[] = $customer['customerid'];
@@ -336,12 +334,11 @@ class Ftps extends ApiCommand implements ResourceEntity
$id = $this->getParam('id', true, 0);
$un_optional = ($id <= 0 ? false : true);
$username = $this->getParam('username', $un_optional, '');
$json_result = Ftps::getLocal($this->getUserData(), array(
$result = $this->apiCall('Ftps.get', array(
'id' => $id,
'username' => $username
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['id'];
// parameters
@@ -364,10 +361,9 @@ class Ftps extends ApiCommand implements ResourceEntity
if ($this->isAdmin()) {
// get customer id
$customer_id = $this->getParam('customer_id');
$json_result = Customers::getLocal($this->getUserData(), array(
$customer = $this->apiCall('Customers.get', array(
'id' => $customer_id
))->get();
$customer = json_decode($json_result, true)['data'];
));
} else {
$customer_id = $this->getUserDetail('customerid');
$customer = $this->getUserData();
@@ -430,11 +426,10 @@ class Ftps extends ApiCommand implements ResourceEntity
"customerid" => $customer['customerid'],
"id" => $id
), true, true);
$json_result = Ftps::getLocal($this->getUserData(), array(
$result = $this->apiCall('Ftps.get', array(
'username' => $result['username']
))->get();
$result = json_decode($json_result, true)['data'];
));
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_NOTICE, "[API] updated ftp-user '" . $result['username'] . "'");
return $this->response(200, "successfull", $result);
}
@@ -460,16 +455,16 @@ class Ftps extends ApiCommand implements ResourceEntity
$loginname = $this->getParam('loginname', true, '');
if (! empty($customerid) || ! empty($loginname)) {
$json_result = Customers::getLocal($this->getUserData(), array(
$_result = $this->apiCall('Customers.get', array(
'id' => $customerid,
'loginname' => $loginname
))->get();
));
$custom_list_result = array(
json_decode($json_result, true)['data']
$_result
);
} else {
$json_result = Customers::getLocal($this->getUserData())->listing();
$custom_list_result = json_decode($json_result, true)['data']['list'];
$_custom_list_result = $this->apiCall('Customers.listing');
$custom_list_result = $_custom_list_result['list'];
}
$customer_ids = array();
foreach ($custom_list_result as $customer) {
@@ -526,19 +521,17 @@ class Ftps extends ApiCommand implements ResourceEntity
}
// get ftp-user
$json_result = Ftps::getLocal($this->getUserData(), array(
$result = $this->apiCall('Ftps.get', array(
'id' => $id,
'username' => $username
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['id'];
if ($this->isAdmin()) {
// get customer-data
$json_result = Customers::getLocal($this->getUserData(), array(
$customer_data = $this->apiCall('Customers.get', array(
'id' => $result['customerid']
))->get();
$customer_data = json_decode($json_result, true)['data'];
));
} else {
$customer_data = $this->getUserData();
}

View File

@@ -215,10 +215,9 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
}
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] added IP/port '" . $ip . ":" . $port . "'");
// get ip for return-array
$json_result = IpsAndPorts::getLocal($this->getUserData(), array(
$result = $this->apiCall('IpsAndPorts.get', array(
'id' => $ins_data['id']
))->get();
$result = json_decode($json_result, true)['data'];
));
return $this->response(200, "successfull", $result);
}
throw new Exception("Not allowed to execute given command.", 403);
@@ -237,11 +236,10 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
{
if ($this->isAdmin() && ($this->getUserDetail('change_serversettings') || ! empty($this->getUserDetail('ip')))) {
$id = $this->getParam('id');
$json_result = IpsAndPorts::getLocal($this->getUserData(), array(
$result = $this->apiCall('IpsAndPorts.get', array(
'id' => $id
))->get();
$result = json_decode($json_result, true)['data'];
));
$ip = validate_ip2($this->getParam('ip', true, $result['ip']), false, 'invalidip', false, false, false, true);
$port = validate($this->getParam('port', true, $result['port']), 'port', '/^(([1-9])|([1-9][0-9])|([1-9][0-9][0-9])|([1-9][0-9][0-9][0-9])|([1-5][0-9][0-9][0-9][0-9])|(6[0-4][0-9][0-9][0-9])|(65[0-4][0-9][0-9])|(655[0-2][0-9])|(6553[0-5]))$/Di', array(
@@ -373,10 +371,9 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
$this->logger()->logAction(ADM_ACTION, LOG_WARNING, "[API] changed IP/port from '" . $result['ip'] . ":" . $result['port'] . "' to '" . $ip . ":" . $port . "'");
$json_result = IpsAndPorts::getLocal($this->getUserData(), array(
$result = $this->apiCall('IpsAndPorts.get', array(
'id' => $result['id']
))->get();
$result = json_decode($json_result, true)['data'];
));
return $this->response(200, "successfull", $result);
}
}
@@ -397,11 +394,10 @@ class IpsAndPorts extends ApiCommand implements ResourceEntity
{
if ($this->isAdmin() && $this->getUserDetail('change_serversettings')) {
$id = $this->getParam('id');
$json_result = IpsAndPorts::getLocal($this->getUserData(), array(
$result = $this->apiCall('IpsAndPorts.get', array(
'id' => $id
))->get();
$result = json_decode($json_result, true)['data'];
));
$result_checkdomain_stmt = Database::prepare("
SELECT `id_domain` as `id` FROM `" . TABLE_DOMAINTOIP . "` WHERE `id_ipandports` = :id

View File

@@ -62,7 +62,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
if (! isset($sql_root) || ! is_array($sql_root)) {
throw new ErrorException("Database server with index #" . $dbserver . " is unknown", 404);
}
if ($sendinfomail != 1) {
$sendinfomail = 0;
}
@@ -71,10 +71,9 @@ class Mysqls extends ApiCommand implements ResourceEntity
if ($this->isAdmin()) {
// get customer id
$customer_id = $this->getParam('customer_id');
$json_result = Customers::getLocal($this->getUserData(), array(
$customer = $this->apiCall('Customers.get', array(
'id' => $customer_id
))->get();
$customer = json_decode($json_result, true)['data'];
));
// check whether the customer has enough resources to get the database added
if ($customer['mysqls_used'] >= $customer['mysqls'] && $customer['mysqls'] != '-1') {
throw new Exception("Customer has no more resources available", 406);
@@ -196,10 +195,9 @@ class Mysqls extends ApiCommand implements ResourceEntity
}
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_WARNING, "[API] added mysql-database '" . $username . "'");
$json_result = Mysqls::getLocal($this->getUserData(), array(
$result = $this->apiCall('Mysqls.get', array(
'dbname' => $username
))->get();
$result = json_decode($json_result, true)['data'];
));
return $this->response(200, "successfull", $result);
}
throw new Exception("No more resources available", 406);
@@ -225,13 +223,13 @@ class Mysqls extends ApiCommand implements ResourceEntity
$dn_optional = ($id <= 0 ? false : true);
$dbname = $this->getParam('dbname', $dn_optional, '');
$dbserver = $this->getParam('mysql_server', true, - 1);
if ($this->isAdmin()) {
if ($this->getUserDetail('customers_see_all') != 1) {
// if it's a reseller or an admin who cannot see all customers, we need to check
// whether the database belongs to one of his customers
$json_result = Customers::getLocal($this->getUserData())->listing();
$custom_list_result = json_decode($json_result, true)['data']['list'];
$_custom_list_result = $this->apiCall('Customers.listing');
$custom_list_result = $_custom_list_result['list'];
$customer_ids = array();
foreach ($custom_list_result as $customer) {
$customer_ids[] = $customer['customerid'];
@@ -311,7 +309,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
* optional, update password for the database
* @param string $description
* optional, description for database
*
*
* @access admin, customer
* @throws Exception
* @return array
@@ -322,17 +320,16 @@ class Mysqls extends ApiCommand implements ResourceEntity
$dn_optional = ($id <= 0 ? false : true);
$dbname = $this->getParam('dbname', $dn_optional, '');
$dbserver = $this->getParam('mysql_server', true, - 1);
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'mysql')) {
throw new Exception("You cannot access this resource", 405);
}
$json_result = Mysqls::getLocal($this->getUserData(), array(
$result = $this->apiCall('Mysqls.get', array(
'id' => $id,
'dbname' => $dbname,
'mysql_server' => $dbserver
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['id'];
// paramters
@@ -352,15 +349,14 @@ class Mysqls extends ApiCommand implements ResourceEntity
if (! isset($sql_root) || ! is_array($sql_root)) {
throw new ErrorException("Database server with index #" . $dbserver . " is unknown", 404);
}
// get needed customer info to reduce the mysql-usage-counter by one
if ($this->isAdmin()) {
// get customer id
$customer_id = $this->getParam('customer_id');
$json_result = Customers::getLocal($this->getUserData(), array(
'id' => $result['customerid']
))->get();
$customer = json_decode($json_result, true)['data'];
$customer = $this->apiCall('Customers.get', array(
'id' => $customer_id
));
// check whether the customer has enough resources to get the database added
if ($customer['mysqls_used'] >= $customer['mysqls'] && $customer['mysqls'] != '-1') {
throw new Exception("Customer has no more resources available", 406);
@@ -406,7 +402,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
"id" => $id
);
Database::pexecute($stmt, $params, true, true);
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_WARNING, "[API] updated mysql-database '" . $result['databasename'] . "'");
return $this->response(200, "successfull", $params);
}
@@ -436,16 +432,16 @@ class Mysqls extends ApiCommand implements ResourceEntity
$loginname = $this->getParam('loginname', true, '');
if (! empty($customer_id) || ! empty($loginname)) {
$json_result = Customers::getLocal($this->getUserData(), array(
$customer = $this->apiCall('Customers.get', array(
'id' => $customerid,
'loginname' => $loginname
))->get();
));
$custom_list_result = array(
json_decode($json_result, true)['data']
$customer
);
} else {
$json_result = Customers::getLocal($this->getUserData())->listing();
$custom_list_result = json_decode($json_result, true)['data']['list'];
$_custom_list_result = $this->apiCall('Customers.listing');
$custom_list_result = $_custom_list_result['list'];
}
$customer_ids = array();
foreach ($custom_list_result as $customer) {
@@ -526,17 +522,16 @@ class Mysqls extends ApiCommand implements ResourceEntity
$dn_optional = ($id <= 0 ? false : true);
$dbname = $this->getParam('dbname', $dn_optional, '');
$dbserver = $this->getParam('mysql_server', true, - 1);
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'mysql')) {
throw new Exception("You cannot access this resource", 405);
}
$json_result = Mysqls::getLocal($this->getUserData(), array(
$result = $this->apiCall('Mysqls.get', array(
'id' => $id,
'dbname' => $dbname,
'mysql_server' => $dbserver
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['id'];
// Begin root-session
@@ -554,10 +549,9 @@ class Mysqls extends ApiCommand implements ResourceEntity
// get needed customer info to reduce the mysql-usage-counter by one
if ($this->isAdmin()) {
$json_result = Customers::getLocal($this->getUserData(), array(
$customer = $this->apiCall('Customers.get', array(
'id' => $result['customerid']
))->get();
$customer = json_decode($json_result, true)['data'];
));
$mysql_used = $customer['mysqls_used'];
$customer_id = $customer['customer_id'];
} else {

View File

@@ -230,7 +230,11 @@ class PhpSettings extends ApiCommand implements ResourceEntity
inserttask('1');
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] php setting with description '" . $description . "' has been created by '" . $this->getUserDetail('loginname') . "'");
return $this->response(200, "successfull", $ins_data);
$result = $this->apiCall('PhpSettings.get', array(
'id' => $ins_data['id']
));
return $this->response(200, "successfull", $result);
}
throw new Exception("Not allowed to execute given command.", 403);
}
@@ -250,11 +254,10 @@ class PhpSettings extends ApiCommand implements ResourceEntity
// required parameter
$id = $this->getParam('id');
$json_result = PhpSettings::getLocal($this->getUserData(), array(
$result = $this->apiCall('PhpSettings.get', array(
'id' => $id
))->get();
$result = json_decode($json_result, true)['data'];
));
// parameters
$description = $this->getParam('description', true, $result['description']);
@@ -341,7 +344,11 @@ class PhpSettings extends ApiCommand implements ResourceEntity
inserttask('1');
$this->logger()->logAction(ADM_ACTION, LOG_INFO, "[API] php setting with description '" . $description . "' has been updated by '" . $this->getUserDetail('loginname') . "'");
return $this->response(200, "successfull", $upd_data);
$result = $this->apiCall('PhpSettings.get', array(
'id' => $id
));
return $this->response(200, "successfull", $result);
}
throw new Exception("Not allowed to execute given command.", 403);
}
@@ -359,11 +366,10 @@ class PhpSettings extends ApiCommand implements ResourceEntity
{
if ($this->isAdmin() && $this->getUserDetail('change_serversettings') == 1) {
$id = $this->getParam('id');
$json_result = PhpSettings::getLocal($this->getUserData(), array(
$result = $this->apiCall('PhpSettings.get', array(
'id' => $id
))->get();
$result = json_decode($json_result, true)['data'];
));
if ((Settings::Get('system.mod_fcgid') == '1' && Settings::Get('system.mod_fcgid_defaultini_ownvhost') == $id) || (Settings::Get('phpfpm.enabled') == '1' && Settings::Get('phpfpm.vhost_defaultini') == $id)) {
standard_error('cannotdeletehostnamephpconfig', '', true);

View File

@@ -80,10 +80,9 @@ class SubDomains extends ApiCommand implements ResourceEntity
if ($this->isAdmin()) {
// get customer id
$customer_id = $this->getParam('customer_id');
$json_result = Customers::getLocal($this->getUserData(), array(
$customer = $this->apiCall('Customers.get', array(
'id' => $customer_id
))->get();
$customer = json_decode($json_result, true)['data'];
));
// check whether the customer has enough resources to get the subdomain added
if ($customer['subdomains_used'] >= $customer['subdomains'] && $customer['subdomains'] != '-1') {
throw new Exception("Customer has no more resources available", 406);
@@ -329,11 +328,10 @@ class SubDomains extends ApiCommand implements ResourceEntity
Admins::increaseUsage(($this->isAdmin() ? $customer['adminid'] : $this->getUserDetail('adminid')), 'subdomains_used');
$this->logger()->logAction($this->isAdmin() ? ADM_ACTION : USR_ACTION, LOG_INFO, "[API] added subdomain '" . $completedomain . "'");
$json_result = SubDomains::getLocal($this->getUserData(), array(
$result = $this->apiCall('SubDomains.get', array(
'id' => $subdomain_id
))->get();
$result = json_decode($json_result, true)['data'];
));
return $this->response(200, "successfull", $result);
}
throw new Exception("No more resources available", 406);
@@ -367,8 +365,8 @@ class SubDomains extends ApiCommand implements ResourceEntity
if ($this->getUserDetail('customers_see_all') != 1) {
// if it's a reseller or an admin who cannot see all customers, we need to check
// whether the database belongs to one of his customers
$json_result = Customers::getLocal($this->getUserData())->listing();
$custom_list_result = json_decode($json_result, true)['data']['list'];
$_custom_list_result = $this->apiCall('Customers.listing');
$custom_list_result = $_custom_list_result['list'];
$customer_ids = array();
foreach ($custom_list_result as $customer) {
$customer_ids[] = $customer['customerid'];
@@ -428,16 +426,16 @@ class SubDomains extends ApiCommand implements ResourceEntity
$loginname = $this->getParam('loginname', true, '');
if (! empty($customerid) || ! empty($loginname)) {
$json_result = Customers::getLocal($this->getUserData(), array(
'id' => $customerid,
$result = $this->apiCall('Customers.get', array(
'id' => $id,
'loginname' => $loginname
))->get();
));
$custom_list_result = array(
json_decode($json_result, true)['data']
$result
);
} else {
$json_result = Customers::getLocal($this->getUserData())->listing();
$custom_list_result = json_decode($json_result, true)['data']['list'];
$_custom_list_result = $this->apiCall('Customers.listing');
$custom_list_result = $_custom_list_result['list'];
}
$customer_ids = array();
$customer_stdsubs = array();
@@ -505,20 +503,18 @@ class SubDomains extends ApiCommand implements ResourceEntity
if ($this->isAdmin() == false && Settings::IsInList('panel.customer_hide_options', 'domains')) {
throw new Exception("You cannot access this resource", 405);
}
$json_result = SubDomains::getLocal($this->getUserData(), array(
$result = $this->apiCall('SubDomains.get', array(
'id' => $id,
'domainname' => $domainname
))->get();
$result = json_decode($json_result, true)['data'];
));
$id = $result['id'];
// get needed customer info to reduce the subdomain-usage-counter by one
if ($this->isAdmin()) {
$json_result = Customers::getLocal($this->getUserData(), array(
$customer = $this->apiCall('Customers.get', array(
'id' => $result['customerid']
))->get();
$customer = json_decode($json_result, true)['data'];
));
$subdomains_used = $customer['subdomains_used'];
$customer_id = $customer['customer_id'];
} else {