mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2026-02-18 15:16:25 +00:00
Compare commits
9 Commits
copilot/fi
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0fcbd33ee1 | ||
|
|
c8acacb5b1 | ||
|
|
322841cbeb | ||
|
|
de3d617840 | ||
|
|
a98a5b298d | ||
|
|
4d55d037c0 | ||
|
|
bdc02ce882 | ||
|
|
d73223cd93 | ||
|
|
376ba57f35 |
@@ -95,6 +95,51 @@ echo "$(clamd -V) is starting... please wait a moment."
|
||||
nice -n10 clamd &
|
||||
BACKGROUND_TASKS+=($!)
|
||||
|
||||
# Give clamd time to start up, especially with limited resources
|
||||
# This grace period allows clamd to initialize fully before health checks begin
|
||||
# Can be configured via CLAMD_STARTUP_TIMEOUT environment variable
|
||||
STARTUP_GRACE_PERIOD=${CLAMD_STARTUP_TIMEOUT:-600} # Default: 10 minutes in seconds
|
||||
echo "Waiting up to ${STARTUP_GRACE_PERIOD} seconds for clamd to start up..."
|
||||
|
||||
# Helper function to check if clamd is ready
|
||||
clamd_is_ready() {
|
||||
[ "$(echo "PING" | nc -w 1 localhost 3310 2>/dev/null)" = "PONG" ]
|
||||
}
|
||||
|
||||
# Wait for clamd to be ready or until timeout
|
||||
START_TIME=$(date +%s)
|
||||
POLL_INTERVAL=10
|
||||
CLAMD_READY=0
|
||||
|
||||
while true; do
|
||||
CURRENT_TIME=$(date +%s)
|
||||
ELAPSED=$((CURRENT_TIME - START_TIME))
|
||||
|
||||
# Check if clamd is responsive by attempting to connect on localhost
|
||||
# clamd listens on 0.0.0.0:3310 (configured in Dockerfile)
|
||||
if clamd_is_ready; then
|
||||
echo "clamd is ready after ${ELAPSED} seconds"
|
||||
CLAMD_READY=1
|
||||
break
|
||||
fi
|
||||
|
||||
# Check if we've exceeded the timeout
|
||||
if [ ${ELAPSED} -ge ${STARTUP_GRACE_PERIOD} ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
sleep ${POLL_INTERVAL}
|
||||
done
|
||||
|
||||
# Report final status only if not already reported as ready
|
||||
if [ ${CLAMD_READY} -eq 0 ]; then
|
||||
if clamd_is_ready; then
|
||||
echo "clamd is now ready (started during final check)"
|
||||
else
|
||||
echo "Warning: clamd did not respond to PING within ${STARTUP_GRACE_PERIOD} seconds - it may still be starting up"
|
||||
fi
|
||||
fi
|
||||
|
||||
while true; do
|
||||
for bg_task in ${BACKGROUND_TASKS[*]}; do
|
||||
if ! kill -0 ${bg_task} 1>&2; then
|
||||
|
||||
@@ -842,11 +842,11 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'danger',
|
||||
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
||||
'msg' => 'access_denied'
|
||||
if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'danger',
|
||||
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
||||
'msg' => 'access_denied'
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@@ -2732,11 +2732,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
$gal = (isset($_data['gal'])) ? intval($_data['gal']) : $is_now['gal'];
|
||||
$description = (!empty($_data['description']) && isset($_SESSION['acl']['domain_desc']) && $_SESSION['acl']['domain_desc'] == "1") ? $_data['description'] : $is_now['description'];
|
||||
(int)$relayhost = (isset($_data['relayhost']) && isset($_SESSION['acl']['domain_relayhost']) && $_SESSION['acl']['domain_relayhost'] == "1") ? intval($_data['relayhost']) : intval($is_now['relayhost']);
|
||||
$tags_raw = isset($_data['tags']) ? $_data['tags'] : array();
|
||||
$tags = is_array($tags_raw) ? $tags_raw : json_decode($tags_raw, true);
|
||||
if (!is_array($tags)) {
|
||||
$tags = array();
|
||||
}
|
||||
$tags = (is_array($_data['tags']) ? $_data['tags'] : array());
|
||||
}
|
||||
else {
|
||||
$_SESSION['return'][] = array(
|
||||
@@ -2757,11 +2753,11 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
':domain' => $domain
|
||||
));
|
||||
// save tags
|
||||
foreach($tags as $index => $tag){
|
||||
if (empty($tag)) continue;
|
||||
if ($index > $GLOBALS['TAGGING_LIMIT']) {
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'warning',
|
||||
foreach($tags as $index => $tag){
|
||||
if (empty($tag)) continue;
|
||||
if ($index > $GLOBALS['TAGGING_LIMIT']) {
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'warning',
|
||||
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
||||
'msg' => array('tag_limit_exceeded', 'limit '.$GLOBALS['TAGGING_LIMIT'])
|
||||
);
|
||||
@@ -2773,8 +2769,6 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
':tag_name' => $tag,
|
||||
));
|
||||
}
|
||||
$stmt = $pdo->prepare("UPDATE `domain` SET `modified` = NOW() WHERE `domain` = :domain");
|
||||
$stmt->execute(array(':domain' => $domain));
|
||||
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'success',
|
||||
@@ -2797,11 +2791,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
$maxquota = (!empty($_data['maxquota'])) ? $_data['maxquota'] : ($is_now['max_quota_for_mbox'] / 1048576);
|
||||
$quota = (!empty($_data['quota'])) ? $_data['quota'] : ($is_now['max_quota_for_domain'] / 1048576);
|
||||
$description = (!empty($_data['description'])) ? $_data['description'] : $is_now['description'];
|
||||
$tags_raw = isset($_data['tags']) ? $_data['tags'] : array();
|
||||
$tags = is_array($tags_raw) ? $tags_raw : json_decode($tags_raw, true);
|
||||
if (!is_array($tags)) {
|
||||
$tags = array();
|
||||
}
|
||||
$tags = (is_array($_data['tags']) ? $_data['tags'] : array());
|
||||
if ($relay_all_recipients == '1') {
|
||||
$backupmx = '1';
|
||||
}
|
||||
@@ -2941,19 +2931,17 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
);
|
||||
break;
|
||||
}
|
||||
$stmt = $pdo->prepare("INSERT INTO `tags_domain` (`domain`, `tag_name`) VALUES (:domain, :tag_name)");
|
||||
$stmt->execute(array(
|
||||
':domain' => $domain,
|
||||
':tag_name' => $tag,
|
||||
));
|
||||
}
|
||||
$stmt = $pdo->prepare("UPDATE `domain` SET `modified` = NOW() WHERE `domain` = :domain");
|
||||
$stmt->execute(array(':domain' => $domain));
|
||||
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'success',
|
||||
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
||||
'msg' => array('domain_modified', htmlspecialchars($domain))
|
||||
$stmt = $pdo->prepare("INSERT INTO `tags_domain` (`domain`, `tag_name`) VALUES (:domain, :tag_name)");
|
||||
$stmt->execute(array(
|
||||
':domain' => $domain,
|
||||
':tag_name' => $tag,
|
||||
));
|
||||
}
|
||||
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'success',
|
||||
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
||||
'msg' => array('domain_modified', htmlspecialchars($domain))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6120,15 +6108,14 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
else {
|
||||
$domains = $_data['domain'];
|
||||
}
|
||||
$tags_raw = isset($_data['tags']) ? $_data['tags'] : array();
|
||||
$tags = is_array($tags_raw) ? $tags_raw : json_decode($tags_raw, true);
|
||||
$tags = $_data['tags'];
|
||||
if (!is_array($tags)) $tags = array();
|
||||
|
||||
$modifiedDomains = array();
|
||||
$wasModified = false;
|
||||
foreach ($domains as $domain) {
|
||||
if (!is_valid_domain_name($domain)) {
|
||||
$_SESSION['return'][] = array(
|
||||
|
||||
$wasModified = false;
|
||||
foreach ($domains as $domain) {
|
||||
if (!is_valid_domain_name($domain)) {
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'danger',
|
||||
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
||||
'msg' => 'domain_invalid'
|
||||
@@ -6141,44 +6128,27 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
||||
'msg' => 'access_denied'
|
||||
);
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
$domainModified = false;
|
||||
foreach($tags as $tag){
|
||||
// delete tag
|
||||
$domainModified = true;
|
||||
$wasModified = true;
|
||||
$stmt = $pdo->prepare("DELETE FROM `tags_domain` WHERE `domain` = :domain AND `tag_name` = :tag_name");
|
||||
$stmt->execute(array(
|
||||
':domain' => $domain,
|
||||
':tag_name' => $tag,
|
||||
));
|
||||
}
|
||||
if ($domainModified) {
|
||||
$modifiedDomains[] = $domain;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$wasModified) return false;
|
||||
if (!empty($modifiedDomains)) {
|
||||
$placeholders = array();
|
||||
$params = array();
|
||||
foreach ($modifiedDomains as $idx => $modifiedDomain) {
|
||||
$placeholders[] = ":domain".$idx;
|
||||
$params[":domain".$idx] = $modifiedDomain;
|
||||
}
|
||||
$stmt = $pdo->prepare("UPDATE `domain` SET `modified` = NOW() WHERE `domain` IN (".implode(',', $placeholders).")");
|
||||
$stmt->execute($params);
|
||||
$modifiedDomains = array_map('htmlspecialchars', $modifiedDomains);
|
||||
}
|
||||
$modifiedDomains = (empty($modifiedDomains)) ? array('-') : $modifiedDomains;
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'success',
|
||||
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
||||
'msg' => array('domain_modified', implode(', ', $modifiedDomains))
|
||||
);
|
||||
break;
|
||||
foreach($tags as $tag){
|
||||
// delete tag
|
||||
$wasModified = true;
|
||||
$stmt = $pdo->prepare("DELETE FROM `tags_domain` WHERE `domain` = :domain AND `tag_name` = :tag_name");
|
||||
$stmt->execute(array(
|
||||
':domain' => $domain,
|
||||
':tag_name' => $tag,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$wasModified) return false;
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'success',
|
||||
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
||||
'msg' => array('domain_modified', $domain)
|
||||
);
|
||||
break;
|
||||
case 'tags_mailbox':
|
||||
if (!is_array($_data['username'])) {
|
||||
$usernames = array();
|
||||
|
||||
@@ -75,6 +75,7 @@ services:
|
||||
environment:
|
||||
- TZ=${TZ}
|
||||
- SKIP_CLAMD=${SKIP_CLAMD:-n}
|
||||
- CLAMD_STARTUP_TIMEOUT=${CLAMD_STARTUP_TIMEOUT:-600}
|
||||
volumes:
|
||||
- ./data/conf/clamav/:/etc/clamav/:Z
|
||||
- clamd-db-vol-1:/var/lib/clamav
|
||||
|
||||
Reference in New Issue
Block a user