metalx1000

Nextcloud push notifications with ntfy

Dec 23rd, 2022
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.21 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2022  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. dir="$HOME/.fbk"
  21. log="$dir/nextcloud_notification.log"
  22. mkdir -p "$dir" || exit 1
  23. touch "$log"
  24.  
  25. source $HOME/.fbk/nex/push.conf
  26. #nextcloud data
  27. #domain="server.com"
  28. #port="3214"
  29. #
  30. ##ntfy data
  31. #ntfy_server="server.com"
  32. #ntfy_port="654"
  33. #ntfy_topic="messages"
  34. #ntfy_user="username"
  35. #ntfy_password="password"
  36.  
  37. #declare -A users
  38. #users["user1"]="password1"
  39. #users["user2"]="password2"
  40.  
  41. for user in ${!users[*]}
  42. do
  43.   password="${users[$user]}"
  44.   curl -s -H 'Accept: application/json, text/plain, */*' -u $user:$password https://$domain:$port/nextcloud/ocs/v2.php/apps/notifications/api/v2/notifications|jq '.ocs.data[]|(.subject + "|" + .message + "|" + .link)'|while read n
  45.   do
  46.     nlog="$(echo $n|base64 -w0)"
  47.     subject="$(echo "$n"|cut -d\| -f1)"
  48.     message="$(echo "$n"|cut -d\| -f2|tr "\n" " ")"
  49.     link="$(echo "$n"|cut -d\| -f3)"
  50.     #echo "$n"
  51.     #echo "---------------------"
  52.     #curl -k -H \"Click:$link\" -H \"Title: $subject\" -u $ntfy_user:$ntfy_password -d \"$message\" https://$ntfy_server:$ntfy_port/$ntfy_topic"|tr "\n" " "
  53. #    echo "$message"
  54. #    grep "$nlog" "$log"|wc -l
  55.     if [[ $(grep "$nlog" "$log"|wc -l) == 0 ]]
  56.     then
  57.       echo "$nlog" >> $log
  58.       curl -k -H "Click:$link" -H "Title: $subject" -u $ntfy_user:$ntfy_password -d "$message" https://$ntfy_server:$ntfy_port/$ntfy_topic
  59.       echo "$message"
  60.     fi
  61.   done
  62. done
  63.  
Add Comment
Please, Sign In to add comment