[WICENS] WAN IP Change Email Notification Script

  • ATTENTION! You'll notice a Prefix dropdown when you create a thread. If your post applies to one of the topics listed, please use that Prefix for your post. When browsing the thread list you can use the Prefix to filter the view.
  • ATTENTION! As of November 1, 2020, you are not able to reply to threads 6 months after the thread is opened if there are more than 500 posts in the thread.
    Threads will not be locked, so posts may still be edited by their authors.
    Just start a new thread on the topic to post if you get an error message when trying to reply to a thread.

Maverickcdn

Senior Member
WICENS - WAN IP Change Email Notification Script v1.00 Jan2021 v.1.11 Feb1,2021
added NTP wait, and nohup to user scripts.

This script is targeted at those that do not use a DDNS service but need to know if their WAN IP changes (ie. you run a VPN server etc) or you just want to know if and when your WAN IP has changed.

Script requires being configured with your To/From Email address(es), server address/port etc.

Fw must be 384.15 or newer.

To install, scripts/ssh must be enabled. From an SSH terminal, copy/paste
Code:
curl --retry 3 "https://raw.githubusercontent.com/maverickcdn/wicens/master/wicens.sh" -o "/jffs/scripts/wicens.sh" && chmod a+rx "/jffs/scripts/wicens.sh"

For first run, use the following to access the Menu.
Code:
sh /jffs/scripts/wicens.sh
Then select option 1 to create the config

After first run, you should be able to access the menu by simply entering
Code:
wicens

Use option b to create a backup of your configured settings if ever formatting /jffs or reinstalling wicens. Saved to /jffs/scripts/wicensconfig.bak

Use option s to call your own script when the WAN IP changes.

In SMTP server send config type, option 4 (SMTP Plain auth) is still untested.

Please visit the Github for more information, or install the script and use option a to view the readme/about page.

Hope people can find this script useful, and would welcome your feedback, there's already 3 user requested custom fields. I find scripting a nice escape from everyday life.

menu.JPGsample.JPG

To truly test the script (built in test only tests Email function), use nano to edit the saved_wan_ip to something different (not blank) at the top of the file and let it run with cron (or manual run through menu). Those taking advantage of the custom script calling function should certainly test it this way. Just note if you have eg. 2 email notifications set 1 day apart the script will sleep and will be locked that entire time till all are sent, to test I suggest setting just 1 notification and changing settings after testing if you require more than one notification

Feeling generous?
 
Last edited:

Jack Yaz

Part of the Furniture
Nice to have another person join the script development party!

How is the email password stored?
Edit, i rtfm'd :D
Code:
IMPORTANT - Your Email address(es) are stored as plain text within this script. Your Email password is obfuscated and saved to the script. If you dont practice good security habits around your router ssh access, this script might not be for you.
 

Maverickcdn

Senior Member
Nice to have another person join the script development party!

How is the email password stored?
Edit, i rtfm'd :D
Code:
IMPORTANT - Your Email address(es) are stored as plain text within this script. Your Email password is obfuscated and saved to the script. If you dont practice good security habits around your router ssh access, this script might not be for you.
Thank you sir, I consider myself the head of the useless script department ;)

All good! Its not 'plain text' anymore, but at least not AAABBBBCCC in the file. It is 'encrypted', but is quite trivial to decode given you have the information required
 

maghuro

Very Senior Member
Very good! Keep going...
And it's finally nice to have a backup function so we can keep the settings between script updates :)

-----

Very nice to have the custom script calling but oops.....

Screenshot_20210114-075228448.png
 

Maverickcdn

Senior Member
Very good! Keep going...
And it's finally nice to have a backup function so we can keep the settings between script updates :)

-----

Very nice to have the custom script calling but oops.....
I was just about to bed ;)

Curious, if it actually saved the path properly or not, you could reuse option s from the menu and itll show the saved value

Did you download using the link above? would you mind trying dos2unix like last time, the formatting of the wicens header looks wonky too.

Honestly the script calling was a last minute throw in and I think I tested a handful of times with text files, it looks to be trying to execute your script when using sed to write the path to the file, I may have to base64 encode it before writing nevermind already is
 

maghuro

Very Senior Member
I was just about to bed ;)

Curious, if it actually saved the path properly or not, you could reuse option s from the menu and itll show the saved value

Did you download using the link above? would you mind trying dos2unix like last time, the formatting of the wicens header looks wonky too.

Honestly the script calling was a last minute throw in and I think I tested a handful of times with text files, it looks to be trying to execute your script when using sed to write the path to the file, I may have to base64 encode it before writing nevermind already is
Same result after dos2unix :)

In fact, when running wicens, I think after running the custom script it throws some errors too, but the screen is cleaned very quickly and I can't capture them...
Maybe they're the same!
 

Maverickcdn

Senior Member
let me sleep on it

Code:
#!/bin/sh

entry=/jffs/scripts/testing
custom=$(echo "$entry" | openssl base64 | tr -d '\n')
script_name_full=/jffs/scripts/test2
user_custom_script='L2pmZnMvc2NyaXB0cy90ZXN0aW5nCg=='
sed -i "1,/user_custom_script=.*/{s~user_custom_script=.*~user_custom_script='$custom'~;}" "$script_name_full"

I created a testing file which should have sent a message to my log if it was executed and ran the code and it didnt execute the script in the entered path and saved the encoded text to the file so Im not sure....... tomorrow...


And to confirm did you download using the command in the first post?
 

maghuro

Very Senior Member
let me sleep on it

Code:
#!/bin/sh

entry=/jffs/scripts/testing
custom=$(echo "$entry" | openssl base64 | tr -d '\n')
script_name_full=/jffs/scripts/test2
user_custom_script='L2pmZnMvc2NyaXB0cy90ZXN0aW5nCg=='
sed -i "1,/user_custom_script=.*/{s~user_custom_script=.*~user_custom_script='$custom'~;}" "$script_name_full"

I created a testing file which should have sent a message to my log if it was executed and ran the code and it didnt execute the script in the entered path and saved the encoded text to the file so Im not sure....... tomorrow...


And to confirm did you download using the command in the first post?
Yes I used your command:)

Get yourself a good night of sleep...I'm getting out for work myself

Thanks for your work!!
 

Maverickcdn

Senior Member
Well two sips of coffee and Im pretty sure I know what the issue is, problem is I cant debug it without updating my own FW or having someone else confirm my suspicions... problem is openssl was updated between beta1 and beta2, so in theory my beta3 tests would fail too ( i dont see any changes to openssl between 3 and 4)

Its line 521 in the script where I try and base64 encode the entry.... it looks like openssl is missing dependencies or the syntax has changed....

Can you try this command and let me know if it fails for you or not
Code:
echo "maghuro testing" | openssl base64

Should return
Code:
bWFnaHVybyB0ZXN0aW5nCg==

Capture.JPG


Doesnt help I go through the effort of coding to see if sed failed but dont bother to check if the variable even has a value :p
 
Last edited:

maghuro

Very Senior Member
Well two sips of coffee and Im pretty sure I know what the issue is, problem is I cant debug it without updating my own FW or having someone else confirm my suspicions... problem is openssl was updated between beta1 and beta2, so in theory my beta3 tests would fail too ( i dont see any changes to openssl between 3 and 4)

Its line 521 in the script where I try and base64 encode the entry.... it looks like openssl is missing dependencies or the syntax has changed....

Can you try this command and let me know if it fails for you or not
Code:
echo "maghuro testing" | openssl base64

Should return
Code:
bWFnaHVyb3Rlc3RpbmcK

View attachment 29512

Doesnt help I go through the effort of coding to see if sed failed but dont bother to check if the variable even has a value :p
Well, instead of nothing it throws the correct value and then... The error :D

Code:
adminRT-AC86U/tmp/home/root echo "maghuro testing" | openssl base64   bWFnaHVybyB0ZXN0aW5nCg==                                                  548051459328:error:25066067:DSO support routines:dlfcn_load:could not load the shared library:crypto/dso/dso_dlfcn.c:118:filename(libengines.so): libengines.so: cannot open shared object file: No such file or directory    548051459328:error:25070067:DSO support routines:DSO_load:could not load the shared library:crypto/dso/dso_lib.c:162:                               548051459328:error:0E07506E:configuration file routines:module_load_dso:error loading dso:crypto/conf/conf_mod.c:224:module=engines, path=engines   548051459328:error:0E076071:configuration file routines:module_run:unknown module name:crypto/conf/conf_mod.c:165:module=engines
 

Maverickcdn

Senior Member
Well, instead of nothing it throws the correct value and then... The error :D

Well... I think that my script will function fine still despite the error message if its still outputting the encoded text. I guess you could try and report back.

Can you confirm one more thing, save a custom script path, then go back to the Main Menu then re-select option s... it should prompt there is already a saved value and print out the path to the script you entered and ask if you want to keep or overwrite it.
 

maghuro

Very Senior Member
Well... I think that my script will function fine still despite the error message if its still outputting the encoded text. I guess you could try and report back.

Can you confirm one more thing, save a custom script path, then go back to the Main Menu then re-select option s... it should prompt there is already a saved value and print out the path to the script you entered and ask if you want to keep or overwrite it.
Yes, despite the error, everything is working perfectly well!

Regarding the custom script, no complains is good news, I tried that and it works as you described.

You sir are the true useless/usefull script master :)
 

maghuro

Very Senior Member
My dear... After 15 days my router changed its ip, and that lease time observed is no good :)

First it only shows in seconds, and it's showing negative value...
 

Attachments

  • Screenshot_20210131-120628423 (1).jpg
    Screenshot_20210131-120628423 (1).jpg
    71.6 KB · Views: 32

maghuro

Very Senior Member
Again, now different :)
 

Attachments

  • Screenshot_20210131-210006990_1.jpg
    Screenshot_20210131-210006990_1.jpg
    38.6 KB · Views: 18

Maverickcdn

Senior Member
Nobody said I was good at math ;) (or coding...). I guess in the end you at least got the notification!

Do you have an NTP server set on Administration-->System in the firmware ? I may have to pinch some code for checking NTP status from another script

In your router system log what is the date when wicens sent the email? is it accurate? (my guess is the date is incorrect because of a reboot or something)

My thought is your system time is incorrect (likely the setup time in the script when you first set it up), or the script is running to early when the router hasnt updated its time after a reboot?

You can try erasing the values for all three WAN IP variables at the top of the script file, IP/epoch/date and re run the script manually and let it save fresh or just run the reset option and reenter your config.... assuming your system time is correct.
 

Maverickcdn

Senior Member
I think you'd be best to ensure your system time is correct, use the reset option and then reconfigure (dont reload a backup)

You can then use option 4 to see a sample Email and see if its calculating the correct lease time. If it occurs again Ill need to see your syslog from the time the lease renewed to when wicens posted in the log it was done sending/updating
 

maghuro

Very Senior Member
Nobody said I was good at math ;) (or coding...). I guess in the end you at least got the notification!

Do you have an NTP server set on Administration-->System in the firmware ? I may have to pinch some code for checking NTP status from another script

In your router system log what is the date when wicens sent the email? is it accurate? (my guess is the date is incorrect because of a reboot or something)

My thought is your system time is incorrect (likely the setup time in the script when you first set it up), or the script is running to early when the router hasnt updated its time after a reboot?

You can try erasing the values for all three WAN IP variables at the top of the script file, IP/epoch/date and re run the script manually and let it save fresh or just run the reset option and reenter your config.... assuming your system time is correct.
Working as expected since day 1! (Or since day -23392 or something like that :p )

I'm using ntpmerlin as my chrony manager. You should check some amtm scripts code, so you can steal the portion of code that waits for ntp ready before executing the script :)
 

Maverickcdn

Senior Member
You should check some amtm scripts code, so you can steal the portion of code that waits for ntp ready before executing the script :)
No worries that was on my list of things to do, Ive seen the code in the big player scripts just never got around to implementing it.

For giggles what does this return for you right now?
Code:
head -n23 < /jffs/scripts/wicens.sh | tail -n1
 

maghuro

Very Senior Member
No worries that was on my list of things to do, Ive seen the code in the big player scripts just never got around to implementing it.

For giggles what does this return for you right now?
Code:
head -n23 < /jffs/scripts/wicens.sh | tail -n1


This sir:
saved_wan_epoch='1612125671'
 

Maverickcdn

Senior Member
This sir:
saved_wan_epoch='1612125671'
Thanks, looks good. Likely an NTP issue, can you just confirm in your router log, those times wicens sent you the Email it was logged as being called by wan-event and not cron? Im fairly certain this is an NTP issue as my script is setting the epoch time before NTP has done its thing

Does your router reboot on WAN drops or anything?
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top