Skip to content

Commit b560c99

Browse files
committed
user notification backend
1 parent aa558a6 commit b560c99

File tree

7 files changed

+303
-1
lines changed

7 files changed

+303
-1
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# info: update user notification
3+
# options: USER NOTIFICATION
4+
#
5+
# The function updates user notification.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
nid=$2
15+
16+
# Includes
17+
source $VESTA/func/main.sh
18+
source $VESTA/conf/vesta.conf
19+
20+
21+
#----------------------------------------------------------#
22+
# Verifications #
23+
#----------------------------------------------------------#
24+
25+
check_args '2' "$#" 'USER NOTIFICATION'
26+
validate_format 'user' 'nid'
27+
is_object_valid 'user' 'USER' "$user"
28+
29+
30+
#----------------------------------------------------------#
31+
# Action #
32+
#----------------------------------------------------------#
33+
34+
# Updating notification
35+
update_object_value 'notifications' 'NID' "$nid" '$ACK' 'yes' 2>/dev/null
36+
37+
# Checking last notification
38+
if [ -e "$USER_DATA/notifications.conf" ]; then
39+
if [ -z "$(grep NID= $USER_DATA/notifications.conf)" ]; then
40+
notice='no'
41+
fi
42+
if [ -z "$(grep "ACK='no'" $USER_DATA/notifications.conf)" ]; then
43+
notice='no'
44+
fi
45+
else
46+
notice='no'
47+
fi
48+
49+
50+
#----------------------------------------------------------#
51+
# Vesta #
52+
#----------------------------------------------------------#
53+
54+
# Updating notification counter
55+
if [ "$notice" = 'no' ]; then
56+
if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
57+
sed -i "s/^TIME/NOTIFICATIONS='no'\nTIME/g" $USER_DATA/user.conf
58+
else
59+
update_user_value "$user" '$NOTIFICATIONS' "no"
60+
fi
61+
fi
62+
63+
# Logging
64+
log_event "$OK" "$EVENT"
65+
66+
exit

bin/v-add-user

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ U_DATABASES='0'
180180
U_CRON_JOBS='0'
181181
U_BACKUPS='0'
182182
LANGUAGE=''
183+
NOTIFICATIONS='no'
183184
TIME='$TIME'
184185
DATE='$DATE'" > $USER_DATA/user.conf
185186
chmod 660 $USER_DATA/user.conf

bin/v-add-user-notification

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# info: add user notification
3+
# options: USER TOPIC NOTICE [TYPE]
4+
#
5+
# The function adds user notification.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
topic=$(echo $2 |sed "s/'/%quote%/g")
15+
notice=$(echo $3 |sed "s/'/%quote%/g")
16+
type=$4
17+
18+
# Includes
19+
source $VESTA/func/main.sh
20+
source $VESTA/conf/vesta.conf
21+
22+
23+
#----------------------------------------------------------#
24+
# Verifications #
25+
#----------------------------------------------------------#
26+
27+
check_args '2' "$#" 'USER TOPIC NOTICE [TYPE]'
28+
validate_format 'user' 'topic' 'notice'
29+
is_object_valid 'user' 'USER' "$user"
30+
31+
32+
#----------------------------------------------------------#
33+
# Action #
34+
#----------------------------------------------------------#
35+
36+
# Defining notification id
37+
if [ -e "$USER_DATA/notifications.conf" ]; then
38+
nid=$(grep "NID=" $USER_DATA/notifications.conf |cut -f 2 -d \')
39+
nid=$(echo "$nid" |sort -n |tail -n1)
40+
if [ ! -z "$nid" ]; then
41+
nid="$((nid +1))"
42+
else
43+
nid=1
44+
fi
45+
else
46+
nid=1
47+
fi
48+
49+
# Concatenating string
50+
str="NID='$nid' TOPIC='$topic' NOTICE='$notice' TYPE='$type'"
51+
str="$str ACK='no' TIME='$TIME' DATE='$DATE'"
52+
53+
# Adding to config
54+
echo "$str" >> $USER_DATA/notifications.conf
55+
56+
# Changing permissions
57+
chmod 660 $USER_DATA/notifications.conf
58+
59+
60+
#----------------------------------------------------------#
61+
# Vesta #
62+
#----------------------------------------------------------#
63+
64+
# Updating notification counter
65+
if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
66+
sed -i "s/^TIME/NOTIFICATIONS='yes'\nTIME/g" $USER_DATA/user.conf
67+
else
68+
update_user_value "$user" '$NOTIFICATIONS' "yes"
69+
fi
70+
71+
exit

bin/v-change-user-package

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ U_DATABASES='$U_DATABASES'
148148
U_CRON_JOBS='$U_CRON_JOBS'
149149
U_BACKUPS='$U_BACKUPS'
150150
LANGUAGE='$LANGUAGE'
151+
NOTIFICATIONS='$NOTIFICATIONS'
151152
TIME='$TIME'
152153
DATE='$DATE'" > $USER_DATA/user.conf
153154
}

bin/v-delete-user-notification

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# info: delete user notification
3+
# options: USER NOTIFICATION
4+
#
5+
# The function deletes user notification.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
nid=$2
15+
16+
# Includes
17+
source $VESTA/func/main.sh
18+
source $VESTA/conf/vesta.conf
19+
20+
21+
#----------------------------------------------------------#
22+
# Verifications #
23+
#----------------------------------------------------------#
24+
25+
check_args '2' "$#" 'USER NOTIFICATION'
26+
validate_format 'user' 'nid'
27+
is_object_valid 'user' 'USER' "$user"
28+
29+
30+
#----------------------------------------------------------#
31+
# Action #
32+
#----------------------------------------------------------#
33+
34+
# Deleting notification
35+
sed -i "/NID='$nid' /d" $USER_DATA/notifications.conf 2>/dev/null
36+
37+
# Checking last notification
38+
if [ -e "$USER_DATA/notifications.conf" ]; then
39+
if [ -z "$(grep NID= $USER_DATA/notifications.conf)" ]; then
40+
notice='no'
41+
fi
42+
if [ -z "$(grep "ACK='no'" $USER_DATA/notifications.conf)" ]; then
43+
notice='no'
44+
fi
45+
else
46+
notice='no'
47+
fi
48+
49+
50+
#----------------------------------------------------------#
51+
# Vesta #
52+
#----------------------------------------------------------#
53+
54+
# Updating notification counter
55+
if [ "$notice" = 'no' ]; then
56+
if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
57+
sed -i "s/^TIME/NOTIFICATIONS='no'\nTIME/g" $USER_DATA/user.conf
58+
else
59+
update_user_value "$user" '$NOTIFICATIONS' "no"
60+
fi
61+
fi
62+
63+
# Logging
64+
log_event "$OK" "$EVENT"
65+
66+
exit

bin/v-list-user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fields='$USER $FNAME $LNAME $PACKAGE $WEB_TEMPLATE $BACKEND_TEMPLATE
8282
$U_USERS $U_DISK $U_DISK_DIRS $U_DISK_WEB $U_DISK_MAIL $U_DISK_DB
8383
$U_BANDWIDTH $U_WEB_DOMAINS $U_WEB_SSL $U_WEB_ALIASES $U_DNS_DOMAINS
8484
$U_DNS_RECORDS $U_MAIL_DOMAINS $U_MAIL_DKIM $U_MAIL_ACCOUNTS $U_DATABASES
85-
$U_CRON_JOBS $U_BACKUPS $LANGUAGE $HOME $TIME $DATE'
85+
$U_CRON_JOBS $U_BACKUPS $LANGUAGE $HOME $NOTIFICATIONS $TIME $DATE'
8686

8787
# Listing user
8888
case $format in

bin/v-list-user-notifications

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
# info: list user notifications
3+
# options: USER [FORMAT]
4+
#
5+
# The function for getting the list notifications
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
format=${2-shell}
15+
16+
# Includes
17+
source $VESTA/func/main.sh
18+
19+
# Json function
20+
json_list_notifications() {
21+
echo '{'
22+
fileds_count=$(echo $fields| wc -w )
23+
while read line; do
24+
eval $line
25+
if [ -n "$data" ]; then
26+
echo -e ' },'
27+
fi
28+
i=1
29+
IFS=' '
30+
for field in $fields; do
31+
eval value=\"$field\"
32+
value=$(echo "$value"|sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
33+
if [ $i -eq 1 ]; then
34+
(( ++i))
35+
echo -e "\t\"$value\": {"
36+
else
37+
if [ $i -lt $fileds_count ]; then
38+
(( ++i))
39+
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
40+
else
41+
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
42+
data=1
43+
fi
44+
fi
45+
done
46+
done < $conf
47+
if [ -n "$data" ]; then
48+
echo -e ' }'
49+
fi
50+
echo -e '}'
51+
}
52+
53+
# Shell function
54+
shell_list_notifications() {
55+
while read line ; do
56+
eval $line
57+
echo "$TOPIC" |sed -e "s/%quote%/'/g"
58+
echo "$NOTICE" |sed -e "s/%quote%/'/g"
59+
echo "$DATE $TIME"
60+
echo "--"
61+
echo
62+
done < $conf
63+
}
64+
65+
66+
#----------------------------------------------------------#
67+
# Verifications #
68+
#----------------------------------------------------------#
69+
70+
# Checking args
71+
check_args '1' "$#" 'USER [FORMAT]'
72+
validate_format 'user'
73+
is_object_valid 'user' 'USER' "$user"
74+
75+
76+
#----------------------------------------------------------#
77+
# Action #
78+
#----------------------------------------------------------#
79+
80+
# Defining fileds to select
81+
conf=$USER_DATA/notifications.conf
82+
fields='$NID $TOPIC $NOTICE $TYPE $ACK $TIME $DATE'
83+
84+
# Listing favourites
85+
case $format in
86+
json) json_list_notifications ;;
87+
plain) shell_list_notifications ;;
88+
shell) shell_list_notifications ;;
89+
*) check_args '1' '0' 'USER [FORMAT]'
90+
esac
91+
92+
93+
#----------------------------------------------------------#
94+
# Vesta #
95+
#----------------------------------------------------------#
96+
97+
exit

0 commit comments

Comments
 (0)