v-delete-user-notification 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. # info: delete user notification
  3. # options: USER NOTIFICATION
  4. # labels: panel
  5. #
  6. # example: v-delete-user-notification admin 1
  7. #
  8. # The function deletes user notification.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. user=$1
  14. nid=$2
  15. # Includes
  16. # shellcheck source=/usr/local/hestia/func/main.sh
  17. source $HESTIA/func/main.sh
  18. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  19. source $HESTIA/conf/hestia.conf
  20. #----------------------------------------------------------#
  21. # Verifications #
  22. #----------------------------------------------------------#
  23. check_args '2' "$#" 'USER NOTIFICATION'
  24. is_format_valid 'user' 'nid'
  25. is_object_valid 'user' 'USER' "$user"
  26. # Perform verification if read-only mode is enabled
  27. check_hestia_demo_mode
  28. #----------------------------------------------------------#
  29. # Action #
  30. #----------------------------------------------------------#
  31. # Deleting notification
  32. sed -i "/NID='$nid' /d" $USER_DATA/notifications.conf 2>/dev/null
  33. # Checking last notification
  34. if [ -e "$USER_DATA/notifications.conf" ]; then
  35. if [ -z "$(grep NID= $USER_DATA/notifications.conf)" ]; then
  36. notice='no'
  37. fi
  38. if [ -z "$(grep "ACK='no'" $USER_DATA/notifications.conf)" ]; then
  39. notice='no'
  40. fi
  41. else
  42. notice='no'
  43. fi
  44. #----------------------------------------------------------#
  45. # Hestia #
  46. #----------------------------------------------------------#
  47. # Updating notification counter
  48. if [ "$notice" = 'no' ]; then
  49. if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then
  50. sed -i "s/^TIME/NOTIFICATIONS='no'\nTIME/g" $USER_DATA/user.conf
  51. else
  52. update_user_value "$user" '$NOTIFICATIONS' "no"
  53. fi
  54. fi
  55. # Logging
  56. log_event "$OK" "$ARGUMENTS"
  57. exit