Ich hatte hier-> Roundcube & 2FA schon mal einen Workaround geschrieben, wo man mittels eines kleinen Shellscripts ein Plugin (in dem Workaround das 2FA-Plugin) wiederherstellen kann.
Da das Script nur eine Notlösung war, hab ich mich mal hingesetzt und ein vernünftiges Shellscript entworfen, mit dem man beliebige manuell eingepflegte Plugins nach einem RC Update wiederherstellen kann.
Ich habe auch die Arbeitsweise des Scripts optimiert, so daß es nicht in Zeitintervallen immer wieder neu aufgerufen werden muß. In dieser Version reicht ein Cronjob @reboot.
Das Script benötigt die beiden Pakete "inotify-tools" und "mailutils", welche automatisch installiert werden, wenn sie nicht vorhanden sind.
Weiterhin schreibt das Script ein Logfile und versendet Mails bei Aktivität.
Alle Details sind in der Kommentarsektion am Anfang des Scripts nochmal erläutert.
Ich habe im Script beispielhaft wieder das 2FA Plugin verwendet. Wer dieses Plugin nicht benötigt, sollte es natürlich aus dem assoziativen Array entfernen, bevor das Script zum Einsatz kommt.
Hinweis:
Benutzderfinierte Plugins werden von Roundcube erst dann verwendet, wenn diese im Panel unter Konfiguration >> Webmail >> Plugins eingetragen sind.
Hier das vollständige Script:
Code: Select all
#!/bin/bash
#
#
# Automated Roundcube Plugin Monitoring Script
# Script Name: rc-plugin-watcher.sh
#
# Purpose:
# This script monitors selected Roundcube plugins for changes
# and automatically restores them if they are deleted.
#
# Note:
# The script uses inotify to respond to delete events in the
# plugin directories and sends email notifications when plugins are restored.
# The script automatically ensures that the packages "inotify-tools" and "mailutils"
# are installed on your system.
#
# Usage:
# 1. Define the "notification_email" variable as the
# email address for notifications.
# 2. Set up the script as a @reboot cron job to run it automatically after a reboot.
# Add the following line to your crontab file (using crontab -e):
# @reboot /bin/bash /path/to/script/rc-plugin-watcher.sh
# 3. Add plugin information (Name and URL) to the "plugins"
# associative array to monitor different plugins.
#
# Log File:
# The script writes its activities to a log file. The log file
# is located at: /var/log/rc-plugin-watcher.log
#
# Example of Plugin Definition:
# declare -A plugins=(
# ["plugin_name"]="https://github.com/plugin_author/plugin_repo/archive/refs/heads/master.zip"
# # Add more plugins here
# )
#
# Author: Jolinar
#
# Checking user privileges
if [[ $EUID -ne 0 ]]; then
exit 1
fi
# Email address for notifications
notification_email="your@email.tld"
# Determining the server name
server_name=$(hostname)
# Path to the log file
logfile="/var/log/rc-plugin-watcher.log"
# Function to check and install packages if not present
check_and_install_packages() {
local packages=("inotify-tools" "mailutils")
for package in "${packages[@]}"; do
if ! dpkg -l | grep -q "^ii\s*$package"; then
apt-get -y install -q "$package" >/dev/null 2>&1
echo "$(date '+%Y-%m-%d %H:%M:%S') - Package $package was installed." >> "$logfile"
fi
done
}
# Checking and possibly installing the packages
check_and_install_packages
# Creating the log file if not present
touch "$logfile"
# Directories
workdir="/usr/src/workdir"
plugindir="/home/keyhelp/www/roundcube/plugins"
# List of desired plugins and their URLs
declare -A plugins=(
["twofactor_gauthenticator"]="https://github.com/alexandregz/twofactor_gauthenticator/archive/refs/heads/master.zip"
# Add more plugins here
)
# Function to download and install a plugin
install_plugin() {
local plugin_name="$1"
local plugin_url="${plugins[$plugin_name]}"
if [ ! -d "$plugindir/$plugin_name" ]; then
mkdir -p "$workdir"
cd "$workdir" || exit 1
wget -q "$plugin_url" -O plugin.zip
if [ $? -eq 0 ]; then
unzip -q plugin.zip
rm plugin.zip
mv "$plugin_name"-master "$plugindir/$plugin_name"
chown -R keyhelp:keyhelp "$plugindir/$plugin_name"
find "$plugindir/$plugin_name" \( -type d -exec chmod 755 {} + \) -o \( -type f -exec chmod 644 {} + \)
# Using mailutils for email sending
echo "$(date '+%Y-%m-%d %H:%M:%S') - Roundcube Plugin '$plugin_name' was restored on server '$server_name'." >> "$logfile"
echo "Roundcube Plugin '$plugin_name' was restored on server '$server_name'." | mail -s "Plugin Restoration on Server $server_name" "$notification_email"
fi
fi
}
# Loop through the defined plugins and install them if missing
for plugin_name in "${!plugins[@]}"; do
if [ ! -d "$plugindir/$plugin_name" ]; then
install_plugin "$plugin_name"
fi
done
# Monitoring plugin directories using inotify
while true; do
event=$(inotifywait -q -e delete "$plugindir")
plugin_name=$(echo "$event" | awk '{print $3}')
if [[ -n "${plugins[$plugin_name]}" ]]; then
install_plugin "$plugin_name"
fi
done
exit 0
Alternativ auch direkt zum Download:
Code: Select all
wget -q https://ngc4594.eu/rc-plugin-watcher.sh
Ich lege solche Scripte immer im Verzeichnis /usr/local/bin/ ab.
Das Script jetzt noch mit:
Code: Select all
chmod +x /pfad/zum/script/rc-plugin-watcher.sh
Das wars auch schon!
Bitte nochmal auf Fehler bzw. Unzulänglichkeiten prüfen.
Ansonsten viel Spaß bei der Nutzung