Skip to content

Commit

Permalink
add safety when unsetting isemaildomain flag in domain, fixes #1305
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kaufmann <[email protected]>
  • Loading branch information
d00p committed Jan 12, 2025
1 parent fde43f8 commit ec42003
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
19 changes: 18 additions & 1 deletion admin_domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
$alias_check = $alias_check['count'];

$domain_emails_result_stmt = Database::prepare("
SELECT `email`, `email_full`, `destination`, `popaccountid` AS `number_email_forwarders`
SELECT `email`, `email_full`, `destination`, `popaccountid`
FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `customerid` = :customerid AND `domainid` = :id
");
Database::pexecute($domain_emails_result_stmt, [
Expand Down Expand Up @@ -593,6 +593,23 @@
}
echo 0;
exit();
} elseif ($action == 'jqEmaildomainNote') {
$domainid = intval(Request::post('id'));
$newval = intval(Request::post('newval'));
try {
$json_result = Domains::getLocal($userinfo, [
'id' => $domainid
])->get();
} catch (Exception $e) {
Response::dynamicError($e->getMessage());
}
$result = json_decode($json_result, true)['data'];
if ((int)$newval == 0 && $newval != $result['isemaildomain']) {
echo json_encode(['changed' => true, 'info' => lng('admin.emaildomainwarning')]);
exit();
}
echo 0;
exit();
} elseif ($action == 'import') {
if (Request::post('send') == 'send') {
$separator = Validate::validate(Request::post('separator'), 'separator');
Expand Down
10 changes: 9 additions & 1 deletion lib/Froxlor/Api/Commands/Domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,9 @@ private function getIpsFromIdArray(array $ids)
* (default yes), 3 = always, default 0 (never)
* @param bool $isemaildomain
* optional, allow email usage with this domain, default 0 (false)
* @param bool $emaildomainverified
* optional, when setting $isemaildomain to false, this needs to be set to true to confirm the action in case email addresses exist for this domain,
* default 0 (false)
* @param bool $email_only
* optional, restrict domain to email usage, default 0 (false)
* @param int $selectserveralias
Expand Down Expand Up @@ -1190,6 +1193,7 @@ public function update()

$subcanemaildomain = $this->getParam('subcanemaildomain', true, $result['subcanemaildomain']);
$isemaildomain = $this->getBoolParam('isemaildomain', true, $result['isemaildomain']);
$emaildomainverified = $this->getBoolParam('emaildomainverified', true, 0);
$email_only = $this->getBoolParam('email_only', true, $result['email_only']);
$p_serveraliasoption = $this->getParam('selectserveralias', true, -1);
$speciallogfile = $this->getBoolParam('speciallogfile', true, $result['speciallogfile']);
Expand Down Expand Up @@ -1273,7 +1277,7 @@ public function update()

// count where we are used in email-accounts
$domain_emails_result_stmt = Database::prepare("
SELECT `email`, `email_full`, `destination`, `popaccountid` AS `number_email_forwarders`
SELECT `email`, `email_full`, `destination`, `popaccountid`
FROM `" . TABLE_MAIL_VIRTUAL . "` WHERE `customerid` = :customerid AND `domainid` = :id
");
Database::pexecute($domain_emails_result_stmt, [
Expand All @@ -1296,6 +1300,10 @@ public function update()
}
}

if ($emails > 0 && (int)$isemaildomain == 0 && (int)$result['isemaildomain'] == 1 && (int)$emaildomainverified == 0) {
Response::standardError('emaildomainstillhasaddresses', '', true);
}

// handle change of customer (move domain from customer to customer)
if ($customerid > 0 && $customerid != $result['customerid'] && Settings::Get('panel.allow_domain_change_customer') == '1') {
// check whether target customer has enough resources
Expand Down
2 changes: 1 addition & 1 deletion lib/Froxlor/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static function updateCounters($returndebuginfo = false)
]);
$customer['emails_used_new'] = (int)$customer_emails['number_emails'];

$customer_emails_result_stmt = Database::prepare('SELECT `email`, `email_full`, `destination`, `popaccountid` AS `number_email_forwarders` FROM `' . TABLE_MAIL_VIRTUAL . '`
$customer_emails_result_stmt = Database::prepare('SELECT `email`, `email_full`, `destination`, `popaccountid` FROM `' . TABLE_MAIL_VIRTUAL . '`
WHERE `customerid` = :cid');
Database::pexecute($customer_emails_result_stmt, [
"cid" => $customer['customerid']
Expand Down
4 changes: 4 additions & 0 deletions lib/formfields/admin/domains/formfield.domains_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@
'type' => 'hidden',
'value' => '0'
],
'emaildomainverified' => [
'type' => 'hidden',
'value' => '0'
],
]
],
'section_bssl' => [
Expand Down
2 changes: 2 additions & 0 deletions lng/de.lng.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@
'apiguide' => 'API Guide',
'domain_duplicate' => 'Domain duplizieren',
'domain_duplicate_named' => '%s duplizieren',
'emaildomainwarning' => '<div id="emaildomainnote" class="invalid-feedback">ACHTUNG: Durch die Änderung dieser Einstellung löschen Sie alle bestehenden E-Mail-Adressen und -Konten unwiderruflich.</div>',
],
'apikeys' => [
'no_api_keys' => 'Keine API Keys gefunden',
Expand Down Expand Up @@ -976,6 +977,7 @@
'invalidpgppublickey' => 'Der angegebene PGP Public Key ist ungültig',
'invalid_validtime' => 'Wert der valid_time in Sekunden muss zwischen 10 und 120 liegen.',
'customerphpenabledbutnoconfig' => 'Kunde hat PHP aktiviert aber keine PHP-Konfiguration wurde gewählt.',
'emaildomainstillhasaddresses' => 'Maildomain-Flag kann nicht deaktiviert werden, da für diese Domain noch E-Mail-Adressen vorhanden sind.',
],
'extras' => [
'description' => 'Hier können Sie zusätzliche Extras einrichten, wie zum Beispiel einen Verzeichnisschutz.<br />Die Änderungen sind erst nach einer kurzen Zeit wirksam.',
Expand Down
2 changes: 2 additions & 0 deletions lng/en.lng.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@
'backups' => [
'backups' => 'Backups',
],
'emaildomainwarning' => '<div id="emaildomainnote" class="invalid-feedback">WARNING: By changing this setting you will delete all existing e-mail addresses and -accounts permanently.</div>',
],
'apcuinfo' => [
'clearcache' => 'Clear APCu cache',
Expand Down Expand Up @@ -1048,6 +1049,7 @@
'invalidpgppublickey' => 'The PGP Public Key is not valid',
'invalid_validtime' => 'Valid time in seconds can only be between 10 and 120',
'customerphpenabledbutnoconfig' => 'Customer has PHP activated but no PHP-configuration was selected.',
'emaildomainstillhasaddresses' => 'Cannot deactivate mail-domain flag, as there are still email-addresses for this domain.',
],
'extras' => [
'description' => 'Here you can add some extras, for example directory protection.<br />The system will need some time to apply the new settings after every change.',
Expand Down

0 comments on commit ec42003

Please sign in to comment.