#!/bin/sh # TODO : # - Add detection of VPN Interface to remove error message DEBUG() { [ "$_DEBUG" = "on" ] && $@ } # Define VPN interface name VPNIF="vpnaltinea" if ! [ -x "$(command -v jq)" ]; then echo "jq could not be found, I'll install it for you" apt install -y jq fi # Get public IP addresses EXTIP4=`curl -s https://checkipv4.altinea.fr/getIP.php` EXTIP6=`curl -s https://checkipv6.altinea.fr/getIP.php` # Testing if returned IPs are empty and setting # a dummy value for later comparison if [ -z "$EXTIP4" ]; then EXTIP4='dummy' fi if [ -z "$EXTIP6" ]; then EXTIP6='dummy' fi # Check if found IPv4 address is configured on this server if [ $(hostname -I |grep -c $EXTIP4) -ne 0 ]; then IP4=$EXTIP4 else # Let see if we can find an ip address on the configured VPN interface DEBUG echo "Couldn't find a public IPv4 address on this host" DEBUG echo "Let see if we find a $VPNIF wireguard interface" VPNIP4=`ip -j addr show dev $VPNIF | jq -r '.[0].addr_info | map(select(.family == "inet"))[0].local'` if [ -z "$VPNIP4" ]; then DEBUG echo "Can't find an IPv4 address on $VPNIF interface" else DEBUG echo "Found VPN IPv4 : $VPNIP4. Using it for monitoring purposes" IP4=$VPNIP4 fi fi # Same routine for IPv6 if [ $(hostname -I |grep -c $EXTIP6) -ne 0 ]; then IP6=$EXTIP6 else DEBUG echo "Couldn't find a public IPv6 address on this host" DEBUG echo "Let see if we find an IPv6 on $VPNIF interface" VPNIP6=`ip -j addr show dev $VPNIF | jq -r '.[0].addr_info | map(select(.family == "inet6"))[0].local'` if [ -z "$VPNIP6" ]; then DEBUG echo "Can't find an IPv6 address on $VPNIF interface" else DEBUG echo "Found VPN IPv6 : $VPNIP6. Using it for monitoring purposes" IP6=$VPNIP6 fi fi #RANDOMNB=`date +%S | grep -o .$ | sed s/0/10/` #ARTURL="https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/ascii/$RANDOMNB.txt" #ASCIIART=`curl -s $ARTURL` ASCIIART="" printf "Password for sendmail@it-nea.eu: " stty -echo IFS= read -r mailpassword stty echo printf "\n" AUTHLOGIN=`/usr/bin/echo -ne "\0sendmail@it-nea.eu\0$mailpassword"|base64` # Generate first part on the command /usr/bin/echo "ehlo `hostname -f` AUTH PLAIN $AUTHLOGIN MAIL FROM: noc@altinea.fr RCPT TO: support@altinea.fr DATA From: noc@altinea.fr To: support@altinea.fr Subject: Nouvelle demande de monitoring Content-Type: text/plain; charset=UTF-8 Nouvelle IP à monitorer : `hostname -f`\r IPv4 : $IP4\r IPv6 : $IP6\r $ASCIIART . quit " |openssl s_client -connect smtp.it-nea.eu:465 -quiet -verify_quiet > /dev/null || err_exit exit 1;