mirror of https://gitlab.com/bashrc2/epicyon
Option to notify by mail
parent
794da93c52
commit
2bc4bdd15e
|
@ -29,6 +29,8 @@
|
||||||
PROJECT_NAME=epicyon
|
PROJECT_NAME=epicyon
|
||||||
epicyonInstallDir=/opt/${PROJECT_NAME}
|
epicyonInstallDir=/opt/${PROJECT_NAME}
|
||||||
|
|
||||||
|
MY_EMAIL_ADDRESS="username@domain"
|
||||||
|
|
||||||
local_domain=$HOSTNAME
|
local_domain=$HOSTNAME
|
||||||
if [ -f /var/lib/tor/hidden_service_epicyon/hostname ]; then
|
if [ -f /var/lib/tor/hidden_service_epicyon/hostname ]; then
|
||||||
local_domain=$(cat /var/lib/tor/hidden_service_epicyon/hostname)
|
local_domain=$(cat /var/lib/tor/hidden_service_epicyon/hostname)
|
||||||
|
@ -38,18 +40,18 @@ fi
|
||||||
function notification_translate_text {
|
function notification_translate_text {
|
||||||
text="$1"
|
text="$1"
|
||||||
if ! grep -q '"language":' "${epicyonInstallDir}/config.json"; then
|
if ! grep -q '"language":' "${epicyonInstallDir}/config.json"; then
|
||||||
echo "$text"
|
echo "$text"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
language=$(cat "${epicyonInstallDir}/config.json" | awk -F '"language":' '{print $2}' | awk -F '"' '{print $2}')
|
language=$(cat "${epicyonInstallDir}/config.json" | awk -F '"language":' '{print $2}' | awk -F '"' '{print $2}')
|
||||||
translationsFilename="${epicyonInstallDir}/translations/${language}.json"
|
translationsFilename="${epicyonInstallDir}/translations/${language}.json"
|
||||||
if [ ! -f "$translationsFilename" ]; then
|
if [ ! -f "$translationsFilename" ]; then
|
||||||
echo "$text"
|
echo "$text"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if ! grep -q "\"$text\":" "$translationsFilename"; then
|
if ! grep -q "\"$text\":" "$translationsFilename"; then
|
||||||
echo "$text"
|
echo "$text"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
grep "\"$text\":" "$translationsFilename" | awk -F '"' '{print $4}'
|
grep "\"$text\":" "$translationsFilename" | awk -F '"' '{print $4}'
|
||||||
}
|
}
|
||||||
|
@ -71,7 +73,7 @@ function matrix_server_message {
|
||||||
|
|
||||||
MATRIX_DATA_DIR='/var/lib/matrix'
|
MATRIX_DATA_DIR='/var/lib/matrix'
|
||||||
homeserver_config="${MATRIX_DATA_DIR}/homeserver.yaml"
|
homeserver_config="${MATRIX_DATA_DIR}/homeserver.yaml"
|
||||||
|
|
||||||
# shellcheck disable=SC2002
|
# shellcheck disable=SC2002
|
||||||
MATRIX_DOMAIN_NAME=$(cat "$homeserver_config" | grep "server_name:" | head -n 1 | awk -F '"' '{print $2}')
|
MATRIX_DOMAIN_NAME=$(cat "$homeserver_config" | grep "server_name:" | head -n 1 | awk -F '"' '{print $2}')
|
||||||
if [ ! "$MATRIX_DOMAIN_NAME" ]; then
|
if [ ! "$MATRIX_DOMAIN_NAME" ]; then
|
||||||
|
@ -110,31 +112,42 @@ function sendNotification {
|
||||||
USERNAME="$1"
|
USERNAME="$1"
|
||||||
SUBJECT="$2"
|
SUBJECT="$2"
|
||||||
MESSAGE="$3"
|
MESSAGE="$3"
|
||||||
|
|
||||||
|
hasSent=
|
||||||
|
|
||||||
if [ -d /etc/prosody ]; then
|
if [ -d /etc/prosody ]; then
|
||||||
if [ -f /usr/bin/sendxmpp ]; then
|
if [ -f /usr/bin/sendxmpp ]; then
|
||||||
# generate a random password for a temporary user account
|
# generate a random password for a temporary user account
|
||||||
notification_user_password=$(openssl rand -base64 32 | tr -dc A-Za-z0-9 | head -c 30 ; echo -n '')
|
notification_user_password=$(openssl rand -base64 32 | tr -dc A-Za-z0-9 | head -c 30 ; echo -n '')
|
||||||
# register a temporary xmpp user account to send the message
|
# register a temporary xmpp user account to send the message
|
||||||
if prosodyctl register "notification" "$local_domain" "$notification_user_password"; then
|
if prosodyctl register "notification" "$local_domain" "$notification_user_password"; then
|
||||||
if [[ "$SUBJECT" == *' Tor '* ]]; then
|
if [[ "$SUBJECT" == *' Tor '* ]]; then
|
||||||
MESSAGE="$SUBJECT"
|
MESSAGE="$SUBJECT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f /usr/bin/sendxmpp ]; then
|
if [ -f /usr/bin/sendxmpp ]; then
|
||||||
# kill any existing message which hasn't sent
|
# kill any existing message which hasn't sent
|
||||||
kill_sendxmpp_process
|
kill_sendxmpp_process
|
||||||
# send the xmpp notification using the temporary account
|
# send the xmpp notification using the temporary account
|
||||||
echo "${MESSAGE}" | /usr/bin/sendxmpp -u notification -p "${notification_user_password}" -j localhost -o ${local_domain} --message-type=headline -n -t -s ${PROJECT_NAME} ${USERNAME}@${local_domain}
|
echo "${MESSAGE}" | /usr/bin/sendxmpp -u notification -p "${notification_user_password}" -j localhost -o ${local_domain} --message-type=headline -n -t -s ${PROJECT_NAME} ${USERNAME}@${local_domain}
|
||||||
|
hasSent=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# remove the temporary xmpp account
|
# remove the temporary xmpp account
|
||||||
prosodyctl deluser "notification@$local_domain"
|
prosodyctl deluser "notification@$local_domain"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d /etc/matrix ]; then
|
if [ -d /etc/matrix ]; then
|
||||||
matrix_server_message "${USERNAME}" "${USERNAME}" "$MESSAGE"
|
matrix_server_message "${USERNAME}" "${USERNAME}" "$MESSAGE"
|
||||||
|
hasSent=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! "$hasSent" ]; then
|
||||||
|
if [[ "$MY_EMAIL_ADDRESS" != "username@domain" ]]; then
|
||||||
|
# send to a fixed email address for a single user instance
|
||||||
|
echo "$MESSAGE" | /usr/bin/mail -s "$SUBJECT" "$MY_EMAIL_ADDRESS"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,17 +158,17 @@ function notifications {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "${epicyonInstallDir}/config.json" ]; then
|
if [ ! -f "${epicyonInstallDir}/config.json" ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# shellcheck disable=SC2002
|
# shellcheck disable=SC2002
|
||||||
EPICYON_DOMAIN_NAME=$(cat "${epicyonInstallDir}/config.json" | awk -F '"domain":' '{print $2}' | awk -F '"' '{print $2}')
|
EPICYON_DOMAIN_NAME=$(cat "${epicyonInstallDir}/config.json" | awk -F '"domain":' '{print $2}' | awk -F '"' '{print $2}')
|
||||||
for d in ${epicyonInstallDir}/accounts/*/ ; do
|
for d in ${epicyonInstallDir}/accounts/*/ ; do
|
||||||
if [[ "$d" != *'@'* ]]; then
|
if [[ "$d" != *'@'* ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
epicyonDir="${d::-1}"
|
epicyonDir="${d::-1}"
|
||||||
USERNAME=$(echo "$epicyonDir" | awk -F '/' '{print $5}' | awk -F '@' '{print $1}')
|
USERNAME=$(echo "$epicyonDir" | awk -F '/' '{print $5}' | awk -F '@' '{print $1}')
|
||||||
|
|
||||||
# send notifications for calendar events to XMPP/email users
|
# send notifications for calendar events to XMPP/email users
|
||||||
epicyonCalendarfile="$epicyonDir/.newCalendar"
|
epicyonCalendarfile="$epicyonDir/.newCalendar"
|
||||||
|
@ -166,7 +179,7 @@ function notifications {
|
||||||
if [[ "$epicyonCalendarfileContent" == '/calendar'* ]]; then
|
if [[ "$epicyonCalendarfileContent" == '/calendar'* ]]; then
|
||||||
epicyonCalendarmessage="Epicyon: ${EPICYON_DOMAIN_NAME}/users/${USERNAME}${epicyonCalendarfileContent}"
|
epicyonCalendarmessage="Epicyon: ${EPICYON_DOMAIN_NAME}/users/${USERNAME}${epicyonCalendarfileContent}"
|
||||||
fi
|
fi
|
||||||
sendNotification "$USERNAME" "Epicyon" "$epicyonCalendarmessage"
|
sendNotification "$USERNAME" "Epicyon" "$epicyonCalendarmessage"
|
||||||
echo "##sent##" >> "$epicyonCalendarfile"
|
echo "##sent##" >> "$epicyonCalendarfile"
|
||||||
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonCalendarfile"
|
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonCalendarfile"
|
||||||
fi
|
fi
|
||||||
|
@ -181,7 +194,7 @@ function notifications {
|
||||||
if [[ "$epicyonDMfileContent" == *':'* ]]; then
|
if [[ "$epicyonDMfileContent" == *':'* ]]; then
|
||||||
epicyonDMmessage="Epicyon: $epicyonDMfileContent"
|
epicyonDMmessage="Epicyon: $epicyonDMfileContent"
|
||||||
fi
|
fi
|
||||||
sendNotification "$USERNAME" "Epicyon" "$epicyonDMmessage"
|
sendNotification "$USERNAME" "Epicyon" "$epicyonDMmessage"
|
||||||
echo "##sent##" > "$epicyonDMfile"
|
echo "##sent##" > "$epicyonDMfile"
|
||||||
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonDMfile"
|
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonDMfile"
|
||||||
fi
|
fi
|
||||||
|
@ -211,7 +224,7 @@ function notifications {
|
||||||
if [[ "$epicyonReplyFileContent" == *':'* ]]; then
|
if [[ "$epicyonReplyFileContent" == *':'* ]]; then
|
||||||
epicyonReplyMessage="Epicyon: $epicyonReplyFileContent"
|
epicyonReplyMessage="Epicyon: $epicyonReplyFileContent"
|
||||||
fi
|
fi
|
||||||
sendNotification "$USERNAME" "Epicyon" "$epicyonReplyMessage"
|
sendNotification "$USERNAME" "Epicyon" "$epicyonReplyMessage"
|
||||||
echo "##sent##" > "$epicyonReplyFile"
|
echo "##sent##" > "$epicyonReplyFile"
|
||||||
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonReplyFile"
|
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonReplyFile"
|
||||||
fi
|
fi
|
||||||
|
@ -221,18 +234,18 @@ function notifications {
|
||||||
epicyonPatchFile="$epicyonDir/.newPatch"
|
epicyonPatchFile="$epicyonDir/.newPatch"
|
||||||
if [ -f "$epicyonPatchFile" ]; then
|
if [ -f "$epicyonPatchFile" ]; then
|
||||||
if [ -f "${epicyonPatchFile}Content" ]; then
|
if [ -f "${epicyonPatchFile}Content" ]; then
|
||||||
if ! grep -q "##sent##" "$epicyonPatchFile"; then
|
if ! grep -q "##sent##" "$epicyonPatchFile"; then
|
||||||
epicyonPatchMessage=$(cat "$epicyonPatchFile")
|
epicyonPatchMessage=$(cat "$epicyonPatchFile")
|
||||||
if [ "$epicyonPatchMessage" ]; then
|
if [ "$epicyonPatchMessage" ]; then
|
||||||
# notify the member
|
# notify the member
|
||||||
sendNotification "$USERNAME" "Epicyon" "$epicyonPatchMessage"
|
sendNotification "$USERNAME" "Epicyon" "$epicyonPatchMessage"
|
||||||
echo "##sent##" > "$epicyonPatchFile"
|
echo "##sent##" > "$epicyonPatchFile"
|
||||||
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonPatchFile"
|
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonPatchFile"
|
||||||
# send the patch to them by email
|
# send the patch to them by email
|
||||||
cat "${epicyonPatchFile}Content" | mail -s "[Epicyon] $epicyonPatchMessage" "${USERNAME}@${HOSTNAME}"
|
cat "${epicyonPatchFile}Content" | mail -s "[Epicyon] $epicyonPatchMessage" "${USERNAME}@${HOSTNAME}"
|
||||||
rm "${epicyonPatchFile}Content"
|
rm "${epicyonPatchFile}Content"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -245,7 +258,7 @@ function notifications {
|
||||||
if [[ "$epicyonShareFileContent" == *':'* ]]; then
|
if [[ "$epicyonShareFileContent" == *':'* ]]; then
|
||||||
epicyonShareMessage="Epicyon: $epicyonShareFileContent"
|
epicyonShareMessage="Epicyon: $epicyonShareFileContent"
|
||||||
fi
|
fi
|
||||||
sendNotification "$USERNAME" "Epicyon" "$epicyonShareMessage"
|
sendNotification "$USERNAME" "Epicyon" "$epicyonShareMessage"
|
||||||
echo "##sent##" > "$epicyonShareFile"
|
echo "##sent##" > "$epicyonShareFile"
|
||||||
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonShareFile"
|
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonShareFile"
|
||||||
fi
|
fi
|
||||||
|
@ -269,13 +282,13 @@ function notifications {
|
||||||
if [ $epicyonNotify ]; then
|
if [ $epicyonNotify ]; then
|
||||||
cp "$epicyonFollowFile" "$epicyonFollowNotificationsFile"
|
cp "$epicyonFollowFile" "$epicyonFollowNotificationsFile"
|
||||||
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonFollowNotificationsFile"
|
chown ${PROJECT_NAME}:${PROJECT_NAME} "$epicyonFollowNotificationsFile"
|
||||||
|
|
||||||
epicyonFollowMessage=$(notification_translate_text "New follow request")" ${EPICYON_DOMAIN_NAME}/users/${USERNAME}/followers"
|
epicyonFollowMessage=$(notification_translate_text "New follow request")" ${EPICYON_DOMAIN_NAME}/users/${USERNAME}/followers"
|
||||||
sendNotification "$USERNAME" "Epicyon" "$epicyonFollowMessage"
|
sendNotification "$USERNAME" "Epicyon" "$epicyonFollowMessage"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
notifications
|
notifications
|
||||||
|
|
Loading…
Reference in New Issue