Maverickcdn
Senior Member
Hello everyone... So I've been killing time writing possibly the most overly complicated/really featureless script for users of RMerlin's firmware. But I wanted to contribute back something within my wheel house.
What is it you ask... simply a preconfigured script to send you an Email notification if/when your WAN IP changes. I prefer not to use a DDNS service and find this works great for my needs. This script is targeted at those that dont want to learn about creating/writing their own notification script or just want something easily installed/configured and does what its supposed to.
Started out very simple (about 120 lines) and worked great for 2+ years. After a recent upgrade I incorrectly named the entry in cron and got caught with a WAN IP change and no notification, what started as simply adding cron entry/checking functions grew to this ridiculous script I now have. I figure Ive gotten this far I might as well see it out that its usable to my desires from what I intended when I started
But here in lies my dilemma... Im a total noob!
Before I go through the effort of making this a supported release and uploading this to a github account I wanted to get other peoples opinions and maybe a few people willing to try it out and give their feedback. Consider this an alpha/beta release. The core functions have worked flawlessly for years for me (beta) but now its become quite elaborate (back to alpha status). I have been running this myself for 2 weeks now and have noticed no ill effects.
Most of the functions/techniques are pulled from other SNBforum contributors (you're all a wealth of knowledge) and from posts from other users here (sendmail/curl formats etc)
My major concerns
1) basic script command usage/formatting etc. Everything works but is there a better way....
2) smtp_plain_auth login is untested, I dont have an Email provider that allows plain_auth login.
3) script is currently tested with 4 major email providers total, would like to see more tested
4) is running getrealip.sh every time the bestway to check WAN IP, seems to me I might be able to check the nvram var it sets, but is this more robust and wont interrupt any firmware operations.
5) confirmation that a DHCP ip change does not trigger a wan-event (untested) but seems to me, no wan-events are triggered with WAN DHCP, the scripts usage of cron is nearly entirely based on my observation of no wan-events when my modem/router negotiate DHCP (and potentially changes)
6) init-start or services-start for cru entry adds?
7) better to save all user settings in a file in addons folder or okay to keep them retained in single file and overwriting...?
The scripts is nearly 1800 lines as there is a lot of terminal screen output so I dont expect much of anyone, but if you're willing to skim through and point out anything that stands out to you it would be greatly appreciated!
It could be more robust but as long as you follow the instructions and correctly input your details (theres no email format checking etc) it will work.
And if you're bold enough to try it and report back thats even better! Only works on 384.15 and newer though as it does use wan-event which was introduced then and Im unsure on which firmware introduced getrealip.sh. Its possible to have this work with versions of Johns fork and older than 384.15 but would require probably another 200ish lines of code. Maybe another coder in training could fork this to work with older versions
SEE POST #15 for new Beta link
With the usual prerequisite script necessities applied, create a file in /jffs/scripts called wicens.sh, copy and paste the pastebin text to the file, then run 'sh /jffs/scripts/wicens.sh setup' to start.
Use 'sh /jffs/scripts/wicens.sh test' to ensure the sending of Emails works properly.
To truly test the script is, run through the setup, then go back in the file and edit the saved_wan_ip variable to something different then let the script run with cron or manually invoke it. If more than 1 Email notification is set though, the script will sleep the full time set for the 1/2, 2/3 and 3/4 email interval time etc.
Look forward to hearing some critiques/criticisms/feedback and hopefully some tester feedback.
What is it you ask... simply a preconfigured script to send you an Email notification if/when your WAN IP changes. I prefer not to use a DDNS service and find this works great for my needs. This script is targeted at those that dont want to learn about creating/writing their own notification script or just want something easily installed/configured and does what its supposed to.
Started out very simple (about 120 lines) and worked great for 2+ years. After a recent upgrade I incorrectly named the entry in cron and got caught with a WAN IP change and no notification, what started as simply adding cron entry/checking functions grew to this ridiculous script I now have. I figure Ive gotten this far I might as well see it out that its usable to my desires from what I intended when I started
But here in lies my dilemma... Im a total noob!
Before I go through the effort of making this a supported release and uploading this to a github account I wanted to get other peoples opinions and maybe a few people willing to try it out and give their feedback. Consider this an alpha/beta release. The core functions have worked flawlessly for years for me (beta) but now its become quite elaborate (back to alpha status). I have been running this myself for 2 weeks now and have noticed no ill effects.
Most of the functions/techniques are pulled from other SNBforum contributors (you're all a wealth of knowledge) and from posts from other users here (sendmail/curl formats etc)
My major concerns
1) basic script command usage/formatting etc. Everything works but is there a better way....
2) smtp_plain_auth login is untested, I dont have an Email provider that allows plain_auth login.
3) script is currently tested with 4 major email providers total, would like to see more tested
4) is running getrealip.sh every time the bestway to check WAN IP, seems to me I might be able to check the nvram var it sets, but is this more robust and wont interrupt any firmware operations.
5) confirmation that a DHCP ip change does not trigger a wan-event (untested) but seems to me, no wan-events are triggered with WAN DHCP, the scripts usage of cron is nearly entirely based on my observation of no wan-events when my modem/router negotiate DHCP (and potentially changes)
6) init-start or services-start for cru entry adds?
7) better to save all user settings in a file in addons folder or okay to keep them retained in single file and overwriting...?
The scripts is nearly 1800 lines as there is a lot of terminal screen output so I dont expect much of anyone, but if you're willing to skim through and point out anything that stands out to you it would be greatly appreciated!
It could be more robust but as long as you follow the instructions and correctly input your details (theres no email format checking etc) it will work.
And if you're bold enough to try it and report back thats even better! Only works on 384.15 and newer though as it does use wan-event which was introduced then and Im unsure on which firmware introduced getrealip.sh. Its possible to have this work with versions of Johns fork and older than 384.15 but would require probably another 200ish lines of code. Maybe another coder in training could fork this to work with older versions
WICENS - WAN IP Change Email Notification Script.
Run with option 'help' for more info about this script.
This script when configured will send an Email (1-4) at variable intervals
X(second/minute/hour/day) to your Email notifying you when your WAN IP has
changed.
Supports Gmail, Hotmail, Outlook
IMPORTANT NOTE: your Email user name and password are stored as plain text
within the script. If you dont practice good security habits around your
router ssh access, this script might not be for you.
Uses firmware built in getrealip.sh to retrieve your WAN IP using Google
STUN server. This will show your WAN IP regardless if your router is behind
NAT (unbridged modem) or not.
Executed by settable minute || hour cron run (default 31min) for checking
your current WAN IP. Also executed by 'wan-event connected' trigger. A DHCP
renewal when your IP changes may not trigger a 'wan-event connected' event.
All cron/wan-event entries are automatically generated upon completion of
your Email user login information and is double checked with every run.
'wan-event connected' execution has a 90 sec delay from trigger to WAN IP
check as we wait for DHCP/NTP to catch up on reboots.
SMTP Email send formats available:
sendmail - StartTLS v1.1 higher (eg. GMail port 587)
sendmail - StartTLS v1 only
curl - SSL (eg GMail port 465)
sendmail - SMTP plain auth (no encryption)
sendmail - ISP based (no password reqd, generally port 25)
IMPORTANT - If using GMail, you must enable 'insecure app' access to your
GMail account. If you use 2factor authentication you must setup an assigned
password in GMail for this script to use.
### Technical ###
Script generates a lock file in /tmp called wicens.lock to prevent
duplicate runs as well as another file in /tmp called wicenssendmail.lock
when sending Email notifications. Script will automatically remove (with
cron) stale lock files if original starting process no longer exists or
lock files are over age limit.
Sendmail/Curl output for Emails is saved to /tmp/wicenssendmail.log for
debugging if neeeded. This file can be viewed by running this script with
'error' option
Sendmail doesnt always return an error code on a misconfiguration so false
send success can occur. If script says email has sent but no email received
use '/jffs/scripts/wicens.sh error' to read sendmail output for errors
The script does not update its saved WAN IP until the script has completed
sending all notifications and adds to the Email message of success or
failure in updating it, so in the event of message failure it should run
again with next cron run and attempt to send again.
Every Sunday the script will write to log the number of calls from cron.
If you use any send format other than smtp_isp_nopswd or smtp_plain_auth
the required file Equifax_Secure_Certificate_Authority.pem will be
downloaded and added to /jffs/configs.
Thank you for using this script.
Run with option 'help' for more info about this script.
This script when configured will send an Email (1-4) at variable intervals
X(second/minute/hour/day) to your Email notifying you when your WAN IP has
changed.
Supports Gmail, Hotmail, Outlook
IMPORTANT NOTE: your Email user name and password are stored as plain text
within the script. If you dont practice good security habits around your
router ssh access, this script might not be for you.
Uses firmware built in getrealip.sh to retrieve your WAN IP using Google
STUN server. This will show your WAN IP regardless if your router is behind
NAT (unbridged modem) or not.
Executed by settable minute || hour cron run (default 31min) for checking
your current WAN IP. Also executed by 'wan-event connected' trigger. A DHCP
renewal when your IP changes may not trigger a 'wan-event connected' event.
All cron/wan-event entries are automatically generated upon completion of
your Email user login information and is double checked with every run.
'wan-event connected' execution has a 90 sec delay from trigger to WAN IP
check as we wait for DHCP/NTP to catch up on reboots.
SMTP Email send formats available:
sendmail - StartTLS v1.1 higher (eg. GMail port 587)
sendmail - StartTLS v1 only
curl - SSL (eg GMail port 465)
sendmail - SMTP plain auth (no encryption)
sendmail - ISP based (no password reqd, generally port 25)
IMPORTANT - If using GMail, you must enable 'insecure app' access to your
GMail account. If you use 2factor authentication you must setup an assigned
password in GMail for this script to use.
### Technical ###
Script generates a lock file in /tmp called wicens.lock to prevent
duplicate runs as well as another file in /tmp called wicenssendmail.lock
when sending Email notifications. Script will automatically remove (with
cron) stale lock files if original starting process no longer exists or
lock files are over age limit.
Sendmail/Curl output for Emails is saved to /tmp/wicenssendmail.log for
debugging if neeeded. This file can be viewed by running this script with
'error' option
Sendmail doesnt always return an error code on a misconfiguration so false
send success can occur. If script says email has sent but no email received
use '/jffs/scripts/wicens.sh error' to read sendmail output for errors
The script does not update its saved WAN IP until the script has completed
sending all notifications and adds to the Email message of success or
failure in updating it, so in the event of message failure it should run
again with next cron run and attempt to send again.
Every Sunday the script will write to log the number of calls from cron.
If you use any send format other than smtp_isp_nopswd or smtp_plain_auth
the required file Equifax_Secure_Certificate_Authority.pem will be
downloaded and added to /jffs/configs.
Thank you for using this script.
SEE POST #15 for new Beta link
With the usual prerequisite script necessities applied, create a file in /jffs/scripts called wicens.sh, copy and paste the pastebin text to the file, then run 'sh /jffs/scripts/wicens.sh setup' to start.
Use 'sh /jffs/scripts/wicens.sh test' to ensure the sending of Emails works properly.
To truly test the script is, run through the setup, then go back in the file and edit the saved_wan_ip variable to something different then let the script run with cron or manually invoke it. If more than 1 Email notification is set though, the script will sleep the full time set for the 1/2, 2/3 and 3/4 email interval time etc.
Look forward to hearing some critiques/criticisms/feedback and hopefully some tester feedback.
Last edited: