Files
nextcloud/Containers/mastercontainer/cron.sh
T
Pablo Zmdl 93cf3d3931 Two factor authentication for both login variants
This adds optional two factor authentication based on shared
TOTP-secrets to both login variants (password and AIO token
authentication).

The 2FA can be enabled as soon as the containers are running in a
section below the backup configuration. As long as it is not enabled,
the AIO UI shows a warning at the top, and inside the Nextcloud a
notification is shown to all Nextcloud admins, strongly recommending to
enable it. The Nextcloud admin notification is sent via the
mastercontainer's `cron.sh`, thus will be renewed whenever it is
dismissed.

In order to show the notices, this PR includes a notification system for
the AIO UI, providing two variants: notices, and warnings. Notices have
a green background and border and vanish after 5 seconds. Warnings have
a orange-leaning yellow background and border and don't vanish (and
can't be dismissed manually, neither).

Another visual improvement is highlighted section headlines: If the URL
hash matches an `h2` element's ID, the `h2` is highlighted and if the
`h2` is followed by a `detail` element, that `detail` is opened. If
effect, browsing to `#two-factor-auth` jumps to the section, which is
highlighted and opened already (as shown in the second screenshot
below).

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
AI-assistant: Claude Opus 4.8
2026-08-20 16:33:29 +02:00

89 lines
3.3 KiB
Bash

#!/bin/bash
if [ "$AIO_LOG_LEVEL" = 'debug' ]; then
set -x
fi
while true; do
if [ -f "/mnt/docker-aio-config/data/daily_backup_time" ]; then
set -x
BACKUP_TIME="$(head -1 "/mnt/docker-aio-config/data/daily_backup_time")"
export BACKUP_TIME
export DAILY_BACKUP=1
if [ "$(sed -n '2p' "/mnt/docker-aio-config/data/daily_backup_time")" != 'automaticUpdatesAreNotEnabled' ]; then
export AUTOMATIC_UPDATES=1
else
export AUTOMATIC_UPDATES=0
export START_CONTAINERS=1
fi
if [ "$(sed -n '3p' "/mnt/docker-aio-config/data/daily_backup_time")" != 'successNotificationsAreNotEnabled' ]; then
export SEND_SUCCESS_NOTIFICATIONS=1
else
export SEND_SUCCESS_NOTIFICATIONS=0
fi
if [ "$AIO_LOG_LEVEL" != 'debug' ]; then
set +x
fi
if [ -f "/mnt/docker-aio-config/data/daily_backup_running" ]; then
export LOCK_FILE_PRESENT=1
else
export LOCK_FILE_PRESENT=0
fi
else
export BACKUP_TIME="04:00"
export DAILY_BACKUP=0
export LOCK_FILE_PRESENT=0
fi
# Allow to continue directly if e.g. the mastercontainer was updated. Otherwise wait for the next execution
if [ "$LOCK_FILE_PRESENT" = 0 ]; then
while [ "$(date +%H:%M)" != "$BACKUP_TIME" ]; do
sleep 30
done
fi
if [ "$DAILY_BACKUP" = 1 ]; then
bash /daily-backup.sh
fi
# Make sure to delete the lock file always
rm -f "/mnt/docker-aio-config/data/daily_backup_running"
# Check for updates and send notification if yes on saturdays
if [ "$(date +%u)" = 6 ]; then
su-exec www-data php /var/www/docker-aio/php/src/Cron/UpdateNotification.php
fi
# Check if AIO is outdated
su-exec www-data php /var/www/docker-aio/php/src/Cron/OutdatedNotification.php
# Nag admins to enable two-factor authentication if it is not set up yet
su-exec www-data php /var/www/docker-aio/php/src/Cron/TwoFactorAuthNotification.php
# Update deSEC DNS IP record (no-op when IP is unchanged or deSEC is not configured)
su-exec www-data php /var/www/docker-aio/php/src/Cron/UpdateDesecIp.php
# Remove sessions older than 24h
find "/mnt/docker-aio-config/session/" -mindepth 1 -mmin +1440 -delete
# Remove nextcloud-aio-domaincheck container
if su-exec www-data docker ps --format "{{.Names}}" --filter "status=exited" | grep -q "^nextcloud-aio-domaincheck$"; then
su-exec www-data docker container remove nextcloud-aio-domaincheck
fi
# Remove dangling images (support both deprecated label-schema and OCI standard vendor label)
su-exec www-data docker image prune --filter "label=org.label-schema.vendor=Nextcloud" --force
su-exec www-data docker image prune --filter "label=org.opencontainers.image.vendor=Nextcloud" --force
# Check for available free space
su-exec www-data php /var/www/docker-aio/php/src/Cron/CheckFreeDiskSpace.php
# Remove mastercontainer from default bridge network
if su-exec www-data docker inspect nextcloud-aio-mastercontainer --format "{{.NetworkSettings.Networks}}" | grep -q "bridge"; then
su-exec www-data docker network disconnect bridge nextcloud-aio-mastercontainer
fi
# Wait 60s so that the whole loop will not be executed again
sleep 60
done