You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.5 KiB

  1. #!/bin/sh
  2. #
  3. # adblock send mail script for mstmp
  4. # written by Dirk Brenken (dev@brenken.org)
  5. # Please note: you have to install and configure the package 'mstmp' before using this script.
  6. # This is free software, licensed under the GNU General Public License v3.
  7. # You should have received a copy of the GNU General Public License
  8. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  9. LC_ALL=C
  10. PATH="/usr/sbin:/usr/bin:/sbin:/bin"
  11. mail_ver="1.0.2"
  12. mail_daemon="$(command -v msmtp)"
  13. mail_profile="adb_notify"
  14. #mail_debug="--debug"
  15. mail_rc=1
  16. # mail daemon check
  17. #
  18. if [ ! -x "${mail_daemon}" ]
  19. then
  20. mail_daemon="$(command -v sendmail)"
  21. fi
  22. # info preparation
  23. #
  24. sys_info="$(strings /etc/banner 2>/dev/null; ubus call system board | sed -e 's/\"release\": {//' | sed -e 's/^[ \t]*//' | sed -e 's/[{}\",]//g' | sed -e 's/[ ]/ \t/' | sed '/^$/d' 2>/dev/null)"
  25. adb_info="$(/etc/init.d/adblock status 2>/dev/null)"
  26. if [ -f "/var/log/messages" ]
  27. then
  28. log_info="$(awk '/adblock-/{NR=1;max=79;if(length($0)>max+1)while($0){if(NR==1){print substr($0,1,max),"&#8629;"} else {print " ",substr($0,1,max)}{$0=substr($0,max+1);NR=NR+1}}else print}' /var/log/messages)"
  29. else
  30. log_info="$(logread -e "adblock-" | awk '{NR=1;max=79;if(length($0)>max+1)while($0){if(NR==1){print substr($0,1,max),"&#8629;"} else {print " ",substr($0,1,max)}{$0=substr($0,max+1);NR=NR+1}}else print}')"
  31. fi
  32. # mail header
  33. #
  34. mail_sender="no-reply@adblock"
  35. mail_receiver="!!!ChangeMe!!!"
  36. mail_topic="adblock notification"
  37. mail_head="From: ${mail_sender}\nTo: ${mail_receiver}\nSubject: ${mail_topic}\nReply-to: ${mail_sender}\nMime-Version: 1.0\nContent-Type: text/html\nContent-Disposition: inline\n\n"
  38. # mail body
  39. #
  40. mail_text="<html><body><pre style='display:block;font-family:monospace;font-size:1rem;padding:20;background-color:#f3eee5;white-space:pre'>"
  41. mail_text="${mail_text}\n<strong>++\n++ System Information ++\n++</strong>\n${sys_info}"
  42. mail_text="${mail_text}\n\n<strong>++\n++ Adblock Information ++\n++</strong>\n${adb_info}"
  43. mail_text="${mail_text}\n\n<strong>++\n++ Logfile Information ++\n++</strong>\n${log_info}"
  44. mail_text="${mail_text}</pre></body></html>"
  45. # send mail
  46. #
  47. if [ -x "${mail_daemon}" ]
  48. then
  49. printf "%b" "${mail_head}${mail_text}" 2>/dev/null | "${mail_daemon}" ${mail_debug} -a "${mail_profile}" "${mail_receiver}" >/dev/null 2>&1
  50. mail_rc=${?}
  51. logger -p "info" -t "adblock-notify-[${mail_ver}]" "mail sent to '${mail_receiver}' with rc '${mail_rc}'"
  52. else
  53. logger -p "err" -t "adblock-notify-[${mail_ver}]" "msmtp mail daemon not found"
  54. fi
  55. exit ${mail_rc}