-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpf_wan_updater.sh
37 lines (30 loc) · 1000 Bytes
/
pf_wan_updater.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh
# Script to check and compare current WAN IP
# If WAN IP has changed, send email
# Uses SMTP configuration in System > Advanced > Notifications
# Written by Tate Galbraith
provider="whatismyip.akamai.com" # Specify where to check IP
curwanip=$(curl -s $provider)
location=$1 # Accept first argument as location ID
date=$(date)
# Check if the old_wan_ip file exists?
# Create the file in /tmp if it does not
if [ ! -f /tmp/old_wan_ip ]; then
echo $curwanip > /tmp/old_wan_ip
fi
oldwanip=$(cat /tmp/old_wan_ip)
message="Public WAN IP Change Alert!\n\n\
Date: $date\n\
Location: $location\n\
Old IP: $oldwanip\n\
New IP: $curwanip\n\n\
Please update site-to-site VPN settings accordingly."
subject="pfSense Public WAN IP Change Alert"
# Check if current and old IPs match
if [ $curwanip = $oldwanip ]; then
exit # Nothing to do
else
# Send the email notification then update old IP
printf "$message" | /usr/local/bin/mail.php -s="$subject"
echo $curwanip > /tmp/old_wan_ip
fi