v-add-user-notification 1.9 KB

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