minor fixes to Domains.update + another unit-test
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -823,17 +823,62 @@ class Domains extends ApiCommand implements ResourceEntity
|
|||||||
$hsts_preload = $this->getParam('hsts_preload', true, $result['hsts_preload']);
|
$hsts_preload = $this->getParam('hsts_preload', true, $result['hsts_preload']);
|
||||||
$ocsp_stapling = $this->getParam('ocsp_stapling', true, $result['ocsp_stapling']);
|
$ocsp_stapling = $this->getParam('ocsp_stapling', true, $result['ocsp_stapling']);
|
||||||
|
|
||||||
|
// count subdomain usage of source-domain
|
||||||
|
$subdomains_stmt = Database::prepare("
|
||||||
|
SELECT COUNT(`id`) AS count FROM `" . TABLE_PANEL_DOMAINS . "` WHERE
|
||||||
|
`parentdomainid` = :resultid
|
||||||
|
");
|
||||||
|
$subdomains = Database::pexecute_first($subdomains_stmt, array(
|
||||||
|
'resultid' => $result['id']
|
||||||
|
), true, true);
|
||||||
|
$subdomains = $subdomains['count'];
|
||||||
|
|
||||||
|
// count where this domain is alias domain
|
||||||
|
$alias_check_stmt = Database::prepare("
|
||||||
|
SELECT COUNT(`id`) AS count FROM `" . TABLE_PANEL_DOMAINS . "` WHERE
|
||||||
|
`aliasdomain` = :resultid
|
||||||
|
");
|
||||||
|
$alias_check = Database::pexecute_first($alias_check_stmt, array(
|
||||||
|
'resultid' => $result['id']
|
||||||
|
), true, true);
|
||||||
|
$alias_check = $alias_check['count'];
|
||||||
|
|
||||||
|
// count where we are used in email-accounts
|
||||||
|
$domain_emails_result_stmt = Database::prepare("
|
||||||
|
SELECT `email`, `email_full`, `destination`, `popaccountid` AS `number_email_forwarders`
|
||||||
|
FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `customerid` = :customerid AND `domainid` = :id
|
||||||
|
");
|
||||||
|
Database::pexecute($domain_emails_result_stmt, array(
|
||||||
|
'customerid' => $result['customerid'],
|
||||||
|
'id' => $result['id']
|
||||||
|
), true, true);
|
||||||
|
|
||||||
|
$emails = Database::num_rows();
|
||||||
|
$email_forwarders = 0;
|
||||||
|
$email_accounts = 0;
|
||||||
|
|
||||||
|
while ($domain_emails_row = $domain_emails_result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
if ($domain_emails_row['destination'] != '') {
|
||||||
|
$domain_emails_row['destination'] = explode(' ', makeCorrectDestination($domain_emails_row['destination']));
|
||||||
|
$email_forwarders += count($domain_emails_row['destination']);
|
||||||
|
if (in_array($domain_emails_row['email_full'], $domain_emails_row['destination'])) {
|
||||||
|
$email_forwarders -= 1;
|
||||||
|
$email_accounts ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// handle change of customer (move domain from customer to customer)
|
// handle change of customer (move domain from customer to customer)
|
||||||
if ($customerid > 0 && $customerid != $result['customerid'] && Settings::Get('panel.allow_domain_change_customer') == '1') {
|
if ($customerid > 0 && $customerid != $result['customerid'] && Settings::Get('panel.allow_domain_change_customer') == '1') {
|
||||||
|
// check whether target customer has enough resources
|
||||||
$customer_stmt = Database::prepare("
|
$customer_stmt = Database::prepare("
|
||||||
SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "`
|
SELECT * FROM `" . TABLE_PANEL_CUSTOMERS . "`
|
||||||
WHERE `customerid` = :customerid
|
WHERE `customerid` = :customerid
|
||||||
AND (`subdomains_used` + :subdomains <= `subdomains` OR `subdomains` = '-1' )
|
AND (`subdomains_used` + :subdomains <= `subdomains` OR `subdomains` = '-1' )
|
||||||
AND (`emails_used` + :emails <= `emails` OR `emails` = '-1' )
|
AND (`emails_used` + :emails <= `emails` OR `emails` = '-1' )
|
||||||
AND (`email_forwarders_used` + :forwarders <= `email_forwarders` OR `email_forwarders` = '-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(
|
$params = array(
|
||||||
'customerid' => $customerid,
|
'customerid' => $customerid,
|
||||||
'subdomains' => $subdomains,
|
'subdomains' => $subdomains,
|
||||||
@@ -844,13 +889,18 @@ class Domains extends ApiCommand implements ResourceEntity
|
|||||||
if ($this->getUserDetail('customers_see_all') == '0') {
|
if ($this->getUserDetail('customers_see_all') == '0') {
|
||||||
$params['adminid'] = $this->getUserDetail('adminid');
|
$params['adminid'] = $this->getUserDetail('adminid');
|
||||||
}
|
}
|
||||||
|
$customer = Database::pexecute_first($customer_stmt, $params, true, true);
|
||||||
$result = Database::pexecute_first($customer_stmt, $params, true, true);
|
if (empty($customer) || $customer['customerid'] != $customerid) {
|
||||||
if (empty($result) || $result['customerid'] != $customerid) {
|
|
||||||
standard_error('customerdoesntexist', '', true);
|
standard_error('customerdoesntexist', '', true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$customerid = $result['customerid'];
|
$customerid = $result['customerid'];
|
||||||
|
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($this->getUserData(), array(
|
||||||
|
'id' => $customerid
|
||||||
|
))->get();
|
||||||
|
$customer = json_decode($json_result, true)['data'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle change of admin (move domain from admin to admin)
|
// handle change of admin (move domain from admin to admin)
|
||||||
@@ -923,9 +973,9 @@ class Domains extends ApiCommand implements ResourceEntity
|
|||||||
// If path is empty and 'Use domain name as default value for DocumentRoot path' is enabled in settings,
|
// If path is empty and 'Use domain name as default value for DocumentRoot path' is enabled in settings,
|
||||||
// set default path to subdomain or domain name
|
// set default path to subdomain or domain name
|
||||||
if (Settings::Get('system.documentroot_use_default_value') == 1) {
|
if (Settings::Get('system.documentroot_use_default_value') == 1) {
|
||||||
$documentroot = makeCorrectDir($result['documentroot'] . '/' . $result['domain']);
|
$documentroot = makeCorrectDir($customer['documentroot'] . '/' . $result['domain']);
|
||||||
} else {
|
} else {
|
||||||
$documentroot = $result['documentroot'];
|
$documentroot = $customer['documentroot'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,26 @@ class DomainsTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @depends testAdminDomainsUpdate
|
* @depends testAdminDomainsUpdate
|
||||||
*/
|
*/
|
||||||
|
public function testAdminDomainsMoveButUnknownCustomer()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
// get customer
|
||||||
|
$json_result = Customers::getLocal($admin_userdata, array(
|
||||||
|
'loginname' => 'test1'
|
||||||
|
))->get();
|
||||||
|
$customer_userdata = json_decode($json_result, true)['data'];
|
||||||
|
$data = [
|
||||||
|
'domainname' => 'test.local',
|
||||||
|
'customerid' => $customer_userdata['customerid'] + 1
|
||||||
|
];
|
||||||
|
Settings::Set('panel.allow_domain_change_customer', 1);
|
||||||
|
$this->expectExceptionMessage("The customer you have chosen doesn't exist.");
|
||||||
|
Domains::getLocal($admin_userdata, $data)->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testAdminDomainsMoveButUnknownCustomer
|
||||||
|
*/
|
||||||
public function testAdminDomainsDelete()
|
public function testAdminDomainsDelete()
|
||||||
{
|
{
|
||||||
global $admin_userdata;
|
global $admin_userdata;
|
||||||
@@ -159,4 +179,5 @@ class DomainsTest extends TestCase
|
|||||||
$result = json_decode($json_result, true)['data'];
|
$result = json_decode($json_result, true)['data'];
|
||||||
$this->assertEquals('test.local', $result['domain']);
|
$this->assertEquals('test.local', $result['domain']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user