Merge pull request #1419 from nextcloud/enh/1417/add-outdated-notification

add an AIO outdated notification
This commit is contained in:
Simon L 2022-11-18 10:38:43 +01:00 committed by GitHub
commit e56a388cc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 92 additions and 2 deletions

View file

@ -41,6 +41,9 @@ while true; do
# Check for updates and send notification if yes
sudo -u www-data php /var/www/docker-aio/php/src/Cron/UpdateNotification.php
# Check if AIO is outdated
sudo -u www-data php /var/www/docker-aio/php/src/Cron/OutdatedNotification.php
# Remove sessions older than 24h
find "/mnt/docker-aio-config/session/" -mindepth 1 -mmin +1440 -delete

View file

@ -227,12 +227,14 @@ RUN set -ex; \
COPY start.sh /
COPY notify.sh /
COPY notify-all.sh /
RUN set -ex; \
chmod +x /start.sh && \
chmod +x /entrypoint.sh && \
chmod +r /upgrade.exclude && \
chmod +x /cron.sh && \
chmod +x /notify.sh && \
chmod +x /notify-all.sh && \
chmod +x /activate-collabora.sh
RUN set -ex; \

View file

@ -0,0 +1,27 @@
#!/bin/bash
if [[ "$EUID" = 0 ]]; then
COMMAND=(sudo -E -u www-data php /var/www/html/occ)
else
COMMAND=(php /var/www/html/occ)
fi
SUBJECT="$1"
MESSAGE="$2"
if [ "$("${COMMAND[@]}" config:app:get notifications enabled)" = "no" ]; then
echo "Cannot send notification as notification app is not enabled."
exit 1
fi
echo "Posting notifications to all users..."
NC_USERS=$("${COMMAND[@]}" user:list | sed 's|^ - ||g' | sed 's|:.*||')
mapfile -t NC_USERS <<< "$NC_USERS"
for user in "${NC_USERS[@]}"
do
echo "Posting '$SUBJECT' to: $user"
"${COMMAND[@]}" notification:generate "$user" "$NC_DOMAIN: $SUBJECT" -l "$MESSAGE"
done
echo "Done!"
exit 0

View file

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
// increase memory limit to 2GB
ini_set('memory_limit', '2048M');
use DI\Container;
require __DIR__ . '/../../vendor/autoload.php';
$container = \AIO\DependencyInjection::GetContainer();
/** @var \AIO\Docker\DockerActionManager $dockerActionManger */
$dockerActionManger = $container->get(\AIO\Docker\DockerActionManager::class);
/** @var \AIO\ContainerDefinitionFetcher $containerDefinitionFetcher */
$containerDefinitionFetcher = $container->get(\AIO\ContainerDefinitionFetcher::class);
$id = 'nextcloud-aio-nextcloud';
$nextcloudContainer = $containerDefinitionFetcher->GetContainerById($id);
$isNextcloudImageOutdated = $dockerActionManger->isNextcloudImageOutdated();
if ($isNextcloudImageOutdated === true) {
$dockerActionManger->sendNotification($nextcloudContainer, 'AIO is outdated!', 'Please open the AIO interface or ask an administrator to update it. If you do not want to do it manually each time, you can enable the daily backup feature from the AIO interface which automatically updates all containers.', '/notify-all.sh');
}

View file

@ -540,7 +540,7 @@ class DockerActionManager
return true;
}
public function sendNotification(Container $container, string $subject, string $message) : void
public function sendNotification(Container $container, string $subject, string $message, string $file = '/notify.sh') : void
{
if ($this->GetContainerStartingState($container) instanceof RunningState) {
@ -558,7 +558,7 @@ class DockerActionManager
'Tty' => true,
'Cmd' => [
'bash',
'/notify.sh',
$file,
$subject,
$message
],
@ -739,4 +739,36 @@ class DockerActionManager
}
return false;
}
private function GetCreatedTimeOfNextcloudImage() : ?string {
$imageName = 'nextcloud/aio-nextcloud' . ':' . $this->GetCurrentChannel();
try {
$imageUrl = $this->BuildApiUrl(sprintf('images/%s/json', $imageName));
$imageOutput = json_decode($this->guzzleClient->get($imageUrl)->getBody()->getContents(), true);
if (!isset($imageOutput['Created'])) {
error_log('Created is not set of image ' . $imageName);
return null;
}
return str_replace('T', ' ', $imageOutput['Created']);
} catch (\Exception $e) {
return null;
}
}
public function isNextcloudImageOutdated() : bool {
$createdTime = $this->GetCreatedTimeOfNextcloudImage();
if ($createdTime === null) {
return false;
}
// If the image is older than 90 days, it is outdated.
if ((time() - (60 * 60 * 24 * 90)) > strtotime($createdTime)) {
return true;
}
return false;
}
}