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.

91 lines
2.5 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. printf "%s" "jq could not be found, I'll install it for you\n"
  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 printf "Couldn't find a public IPv4 address on this host\n"
  30. DEBUG printf "Let see if we find a $VPNIF wireguard interface\n"
  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 printf "%s" "Can't find an IPv4 address on $VPNIF interface\n"
  34. else
  35. DEBUG printf "%s" "Found VPN IPv4 : $VPNIP4. Using it for monitoring purposes\n"
  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 printf "%s" "Couldn't find a public IPv6 address on this host\n"
  44. DEBUG printf "%s" "Let see if we find an IPv6 on $VPNIF interface\n"
  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 printf "%s" "Can't find an IPv6 address on $VPNIF interface"
  48. else
  49. DEBUG printf "%s" "Found VPN IPv6 : $VPNIP6. Using it for monitoring purposes"
  50. IP6=$VPNIP6
  51. fi
  52. fi
  53. printf "%s" "Password for sendmail@it-nea.eu: "
  54. stty -echo
  55. read -r mailpassword
  56. stty echo
  57. printf "\n"
  58. AUTHLOGIN=`printf "\0sendmail@it-nea.eu\0$mailpassword"|base64`
  59. # Generate first part on the command
  60. printf "%s" "ehlo `hostname -f`
  61. AUTH PLAIN
  62. $AUTHLOGIN
  63. MAIL FROM: noc@altinea.fr
  64. RCPT TO: support@altinea.fr
  65. DATA
  66. From: noc@altinea.fr
  67. To: support@altinea.fr
  68. Subject: Nouvelle demande de monitoring
  69. Content-Type: text/plain; charset=UTF-8
  70. Nouvelle IP à monitorer : `hostname -f`
  71. IPv4 : $IP4
  72. IPv6 : $IP6
  73. .
  74. quit
  75. " |openssl s_client -connect smtp.it-nea.eu:465 -verify_quiet -quiet > /dev/null || err_exit
  76. exit 1;