Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # script courtesy of @lbergey on PIAF Forum
  4.  
  5. dt=$(date)
  6. # Make a Temp file to use as a Global Variable
  7. ck=$(mktemp)
  8. cd /root
  9. # Set Global Variable to "N" for trigger a iptables-restart
  10. echo "N" > $ck
  11. # process all .iptables files in /root
  12. ls -1 /root/*.iptables | while read line
  13. do
  14. echo "account: $line"
  15. # extract fqdn and ip address from the .iptables file
  16. fqdn=`cat ${line} | cut -f 1 -d " "`
  17. ip=`cat ${line} | cut -f 2 -d " "`
  18. # Only process records where the ip address is not equal to fqdn and
  19. # ip and fqdn are not empty
  20. if [ "$fqdn" != "$ip" ] && [[ -n "${ip// }" ]] && [[ -n "${fqdn// }" ]]; then
  21. # Get the current IP for the fqdn
  22. test=`dig +short $fqdn`
  23. LEN=${#test}
  24. if [ $LEN -gt 15 ]; then
  25. echo "Ooops. We gotta a DIG overage problem. Forcing a match on IP to avoid disaster."
  26. test=$ip
  27. fi
  28. if [ $LEN -lt 7 ]; then
  29. echo "Ooops. We gotta a DIG fail problem. Forcing a match on IP to avoid disaster."
  30. test=$ip
  31. fi
  32. if [ "$ip" != "$test" ]; then
  33. echo "Account ${line} CHANGED"
  34. echo "$dt" >> /var/log/ipchecker.log
  35. echo "Account ${line} CHANGED" >> /var/log/ipchecker.log
  36. # Set the iptables-restart flag to Yes
  37. echo "Y" > $ck
  38. echo " FQDN: $fqdn"
  39. echo "OLD IP: $ip"
  40. echo "NEW IP: $test"
  41. echo " FQDN: $fqdn" >> /var/log/ipchecker.log
  42. echo "OLD IP: $ip" >> /var/log/ipchecker.log
  43. echo "NEW IP: $test" >> /var/log/ipchecker.log
  44. echo "$fqdn $test" > ${line}
  45. fi
  46. fi
  47. done
  48. # Retreive the iptables-restart flag
  49. restartflag=$(cat $ck)
  50. # Remove the Temp File
  51. rm -f $ck
  52. if [ "$restartflag" == "Y" ]; then
  53. echo "iptables-restart"
  54. echo "iptables-restart" >> /var/log/ipchecker.log
  55. /usr/local/sbin/iptables-restart
  56. fi
  57. exit 0
  58. #eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement