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.

97 lines
2.6 KiB

4 years ago
  1. #!/bin/sh
  2. # TODO :
  3. # - Add detection of VPN Interface to remove error message
  4. DEBUG() {
  5. [ "$_DEBUG" = "on" ] && $@
  6. }
  7. # Define VPN interface name
  8. VPNIF="vpnaltinea"
  9. if ! [ -x "$(command -v jq)" ]; then
  10. echo "jq could not be found, I'll install it for you"
  11. apt install -y jq
  12. fi
  13. # Get public IP addresses
  14. EXTIP4=`curl -s https://checkipv4.altinea.fr/getIP.php`
  15. EXTIP6=`curl -s https://checkipv6.altinea.fr/getIP.php`
  16. # Testing if returned IPs are empty and setting
  17. # a dummy value for later comparison
  18. if [ -z "$EXTIP4" ]; then
  19. EXTIP4='dummy'
  20. fi
  21. if [ -z "$EXTIP6" ]; then
  22. EXTIP6='dummy'
  23. fi
  24. # Check if found IPv4 address is configured on this server
  25. if [ $(hostname -I |grep -c $EXTIP4) -ne 0 ]; then
  26. IP4=$EXTIP4
  27. else
  28. # Let see if we can find an ip address on the configured VPN interface
  29. DEBUG echo "Couldn't find a public IPv4 address on this host"
  30. DEBUG echo "Let see if we find a $VPNIF wireguard interface"
  31. VPNIP4=`ip -j addr show dev $VPNIF | jq -r '.[0].addr_info | map(select(.family == "inet"))[0].local'`
  32. if [ -z "$VPNIP4" ]; then
  33. DEBUG echo "Can't find an IPv4 address on $VPNIF interface"
  34. else
  35. DEBUG echo "Found VPN IPv4 : $VPNIP4. Using it for monitoring purposes"
  36. IP4=$VPNIP4
  37. fi
  38. fi
  39. # Same routine for IPv6
  40. if [ $(hostname -I |grep -c $EXTIP6) -ne 0 ]; then
  41. IP6=$EXTIP6
  42. else
  43. DEBUG echo "Couldn't find a public IPv6 address on this host"
  44. DEBUG echo "Let see if we find an IPv6 on $VPNIF interface"
  45. VPNIP6=`ip -j addr show dev $VPNIF | jq -r '.[0].addr_info | map(select(.family == "inet6"))[0].local'`
  46. if [ -z "$VPNIP6" ]; then
  47. DEBUG echo "Can't find an IPv6 address on $VPNIF interface"
  48. else
  49. DEBUG echo "Found VPN IPv6 : $VPNIP6. Using it for monitoring purposes"
  50. IP6=$VPNIP6
  51. fi
  52. fi
  53. #RANDOMNB=`date +%S | grep -o .$ | sed s/0/10/`
  54. #ARTURL="https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/ascii/$RANDOMNB.txt"
  55. #ASCIIART=`curl -s $ARTURL`
  56. ASCIIART=""
  57. printf "Password for sendmail@it-nea.eu: "
  58. stty -echo
  59. IFS= read -r mailpassword
  60. stty echo
  61. printf "\n"
  62. AUTHLOGIN=`/usr/bin/echo -ne "\0sendmail@it-nea.eu\0$mailpassword"|base64`
  63. # Generate first part on the command
  64. /usr/bin/echo "ehlo `hostname -f`
  65. AUTH PLAIN
  66. $AUTHLOGIN
  67. MAIL FROM: noc@altinea.fr
  68. RCPT TO: support@altinea.fr
  69. DATA
  70. From: noc@altinea.fr
  71. To: support@altinea.fr
  72. Subject: Nouvelle demande de monitoring
  73. Content-Type: text/html; charset=UTF-8
  74. Nouvelle IP à monitorer : `hostname -f`
  75. IPv4 : $IP4
  76. IPv6 : $IP6
  77. $ASCIIART
  78. .
  79. quit
  80. " |openssl s_client -connect smtp.it-nea.eu:465 -quiet -verify_quiet > /dev/null || err_exit
  81. exit 1;