user notification backend

This commit is contained in:
Serghey Rodin 2015-10-29 15:01:14 +02:00
parent aa558a66c0
commit b560c99ceb
7 changed files with 303 additions and 1 deletions

View file

@ -0,0 +1,66 @@
#!/bin/bash
# info: update user notification
# options: USER NOTIFICATION
#
# The function updates user notification.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
nid=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER NOTIFICATION'
validate_format 'user' 'nid'
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Updating notification
update_object_value 'notifications' 'NID' "$nid" '$ACK' 'yes' 2>/dev/null
# Checking last notification
if [ -e "$USER_DATA/notifications.conf" ]; then
if [ -z "$(grep NID= $USER_DATA/notifications.conf)" ]; then
notice='no'
fi
if [ -z "$(grep "ACK='no'" $USER_DATA/notifications.conf)" ]; then
notice='no'
fi
else
notice='no'
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating notification counter
if [ "$notice" = 'no' ]; then
if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
sed -i "s/^TIME/NOTIFICATIONS='no'\nTIME/g" $USER_DATA/user.conf
else
update_user_value "$user" '$NOTIFICATIONS' "no"
fi
fi
# Logging
log_event "$OK" "$EVENT"
exit

View file

@ -180,6 +180,7 @@ U_DATABASES='0'
U_CRON_JOBS='0'
U_BACKUPS='0'
LANGUAGE=''
NOTIFICATIONS='no'
TIME='$TIME'
DATE='$DATE'" > $USER_DATA/user.conf
chmod 660 $USER_DATA/user.conf

71
bin/v-add-user-notification Executable file
View file

@ -0,0 +1,71 @@
#!/bin/bash
# info: add user notification
# options: USER TOPIC NOTICE [TYPE]
#
# The function adds user notification.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
topic=$(echo $2 |sed "s/'/%quote%/g")
notice=$(echo $3 |sed "s/'/%quote%/g")
type=$4
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER TOPIC NOTICE [TYPE]'
validate_format 'user' 'topic' 'notice'
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining notification id
if [ -e "$USER_DATA/notifications.conf" ]; then
nid=$(grep "NID=" $USER_DATA/notifications.conf |cut -f 2 -d \')
nid=$(echo "$nid" |sort -n |tail -n1)
if [ ! -z "$nid" ]; then
nid="$((nid +1))"
else
nid=1
fi
else
nid=1
fi
# Concatenating string
str="NID='$nid' TOPIC='$topic' NOTICE='$notice' TYPE='$type'"
str="$str ACK='no' TIME='$TIME' DATE='$DATE'"
# Adding to config
echo "$str" >> $USER_DATA/notifications.conf
# Changing permissions
chmod 660 $USER_DATA/notifications.conf
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating notification counter
if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
sed -i "s/^TIME/NOTIFICATIONS='yes'\nTIME/g" $USER_DATA/user.conf
else
update_user_value "$user" '$NOTIFICATIONS' "yes"
fi
exit

View file

@ -148,6 +148,7 @@ U_DATABASES='$U_DATABASES'
U_CRON_JOBS='$U_CRON_JOBS'
U_BACKUPS='$U_BACKUPS'
LANGUAGE='$LANGUAGE'
NOTIFICATIONS='$NOTIFICATIONS'
TIME='$TIME'
DATE='$DATE'" > $USER_DATA/user.conf
}

66
bin/v-delete-user-notification Executable file
View file

@ -0,0 +1,66 @@
#!/bin/bash
# info: delete user notification
# options: USER NOTIFICATION
#
# The function deletes user notification.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
nid=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER NOTIFICATION'
validate_format 'user' 'nid'
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Deleting notification
sed -i "/NID='$nid' /d" $USER_DATA/notifications.conf 2>/dev/null
# Checking last notification
if [ -e "$USER_DATA/notifications.conf" ]; then
if [ -z "$(grep NID= $USER_DATA/notifications.conf)" ]; then
notice='no'
fi
if [ -z "$(grep "ACK='no'" $USER_DATA/notifications.conf)" ]; then
notice='no'
fi
else
notice='no'
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating notification counter
if [ "$notice" = 'no' ]; then
if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
sed -i "s/^TIME/NOTIFICATIONS='no'\nTIME/g" $USER_DATA/user.conf
else
update_user_value "$user" '$NOTIFICATIONS' "no"
fi
fi
# Logging
log_event "$OK" "$EVENT"
exit

View file

@ -82,7 +82,7 @@ fields='$USER $FNAME $LNAME $PACKAGE $WEB_TEMPLATE $BACKEND_TEMPLATE
$U_USERS $U_DISK $U_DISK_DIRS $U_DISK_WEB $U_DISK_MAIL $U_DISK_DB
$U_BANDWIDTH $U_WEB_DOMAINS $U_WEB_SSL $U_WEB_ALIASES $U_DNS_DOMAINS
$U_DNS_RECORDS $U_MAIL_DOMAINS $U_MAIL_DKIM $U_MAIL_ACCOUNTS $U_DATABASES
$U_CRON_JOBS $U_BACKUPS $LANGUAGE $HOME $TIME $DATE'
$U_CRON_JOBS $U_BACKUPS $LANGUAGE $HOME $NOTIFICATIONS $TIME $DATE'
# Listing user
case $format in

97
bin/v-list-user-notifications Executable file
View file

@ -0,0 +1,97 @@
#!/bin/bash
# info: list user notifications
# options: USER [FORMAT]
#
# The function for getting the list notifications
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
format=${2-shell}
# Includes
source $VESTA/func/main.sh
# Json function
json_list_notifications() {
echo '{'
fileds_count=$(echo $fields| wc -w )
while read line; do
eval $line
if [ -n "$data" ]; then
echo -e ' },'
fi
i=1
IFS=' '
for field in $fields; do
eval value=\"$field\"
value=$(echo "$value"|sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
if [ $i -eq 1 ]; then
(( ++i))
echo -e "\t\"$value\": {"
else
if [ $i -lt $fileds_count ]; then
(( ++i))
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
else
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
data=1
fi
fi
done
done < $conf
if [ -n "$data" ]; then
echo -e ' }'
fi
echo -e '}'
}
# Shell function
shell_list_notifications() {
while read line ; do
eval $line
echo "$TOPIC" |sed -e "s/%quote%/'/g"
echo "$NOTICE" |sed -e "s/%quote%/'/g"
echo "$DATE $TIME"
echo "--"
echo
done < $conf
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking args
check_args '1' "$#" 'USER [FORMAT]'
validate_format 'user'
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining fileds to select
conf=$USER_DATA/notifications.conf
fields='$NID $TOPIC $NOTICE $TYPE $ACK $TIME $DATE'
# Listing favourites
case $format in
json) json_list_notifications ;;
plain) shell_list_notifications ;;
shell) shell_list_notifications ;;
*) check_args '1' '0' 'USER [FORMAT]'
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit