Calgarypuck Forums - The Unofficial Calgary Flames Fan Community

Go Back   Calgarypuck Forums - The Unofficial Calgary Flames Fan Community > Main Forums > The Off Topic Forum > Tech Talk
Register Forum Rules FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread
Old 03-23-2010, 11:50 AM   #1
Azure
Had an idea!
 
Azure's Avatar
 
Join Date: Oct 2005
Exp:
Default Anyone with DDWRT/sendmail experience?

I'm trying to create a script that lets me plug in a router anywhere in the world and have it send me an email every certain amount of time.

Here is the script I have so far.

Quote:
#!/bin/sh
# WANIPCheck

# Some settings
INTERVAL=10
## SMTP="smtp.secureserver.net"
## FROM="test@myisp.com"
## FROM_NAME="JohnQ"
## USER="mylogin@mydomain.com"
## PASSWORD="XXXX"
## SUBJECT="TEST 1"
## MESSAGE="Test number 1"
## TO="test@anyemailaddress.com"


MAIL_BINARY=/jffs/sendmail
MAIL_SERVER="mail.myisp.ca"
## USER="user@myisp.ca"
## PASSWORD="xxxxx"
MAIL_TO="mail@anyemailaddress.com"
MAIL_FROM="mail@mydomain.com"
MAIL_SUBJECT="Router IP Address Update"


# Function for sending the log to an email address
##sendemail()

# The "main" loop
while sleep $INTERVAL
do
{
# Create the email message
CURR_WAN_IPADDR=`nvram get wan_ipaddr`
echo "Subject: $MAIL_SUBJECT" > /tmp/mailnotification
echo "WAN IP-Address is:"$CURR_WAN_IPADDR >> /tmp/mailnotification

# Send the email message
## /jffs/sendmail -S"$SMTP" -f$FROM -F"$FROM_NAME" -d"$DOMAIN" -u"$USER" -p"$PASSWORD" -s"$SUBJECT" -m"$MESSAGE" $TO
cat /tmp/mailnotification | $MAIL_BINARY -s$MAIL_SERVER -f$MAIL_FROM -v $MAIL_TO

# Cleanup email message
## echo $MAIL_BINARY
## echo $MAIL_SERVER
## echo $MAIL_TO
## echo $MAIL_FROM
## echo $MAIL_SUBJECT
cat /tmp/mailnotification
## rm /tmp/mailnotification
}
done
Ignore all the lines I commented out. I'm just playing around and don't want to delete stuff I might need.

I have gotten this working through my ISPs SMTP servers, but as soon as I try to use Gmail, Hotmail, or my domain's SMTP server(GoDaddy)....it doesn't go through.

I need to be able to modify the script to login and authorize the username/password, but I'm not completely sure how to do it. At least I think that would fix the problem.

I would prefer to use Gmail, but since they use SSL encryption it might not work. I could just as easily use the Godaddy smtp server, if it would work.

I'd really appreciate some help. Thanks.
Azure is offline   Reply With Quote
Old 03-23-2010, 11:56 AM   #2
Azure
Had an idea!
 
Azure's Avatar
 
Join Date: Oct 2005
Exp:
Default

I'm using mini sendmail, and my limited understanding says it only works with your ISPs smtp server.

That is what I'm trying to get around.
Azure is offline   Reply With Quote
Old 03-23-2010, 04:36 PM   #3
Shazam
Franchise Player
 
Shazam's Avatar
 
Join Date: Aug 2005
Location: Memento Mori
Exp:
Default

Are you saying that you want to send email from any SMTP server, even one you don't have an account on?
__________________
If you don't pass this sig to ten of your friends, you will become an Oilers fan.
Shazam is offline   Reply With Quote
Old 03-23-2010, 06:22 PM   #4
Azure
Had an idea!
 
Azure's Avatar
 
Join Date: Oct 2005
Exp:
Default

No, just from one that I have an account with.
Azure is offline   Reply With Quote
Old 03-23-2010, 09:14 PM   #5
sclitheroe
#1 Goaltender
 
Join Date: Sep 2005
Exp:
Default

Lots of ISP's don't allow port 25 connections outbound from their networks (they only allow SMTP on 25 to one of their own SMTP servers) - Telus is one such ISP, for example. Can you configure your sendmail instance to connect on an alternate MSA, which is typically port 587?
__________________
-Scott
sclitheroe is offline   Reply With Quote
Old 03-23-2010, 09:16 PM   #6
sclitheroe
#1 Goaltender
 
Join Date: Sep 2005
Exp:
Default

Personally I would also rethink the email approach too - why not load a util on there that would allow your routers to make secure DNS A record updates on a DNS server that you run yourself (and probably run on a non-standard port to avoid any other ISP interactions)...in effect becoming your own personal DynDNS service. Then, you have a name server that can always resolve the names of your routers to IP addresses.
__________________
-Scott
sclitheroe is offline   Reply With Quote
Old 03-23-2010, 09:34 PM   #7
Azure
Had an idea!
 
Azure's Avatar
 
Join Date: Oct 2005
Exp:
Default

Quote:
Originally Posted by sclitheroe View Post
Lots of ISP's don't allow port 25 connections outbound from their networks (they only allow SMTP on 25 to one of their own SMTP servers) - Telus is one such ISP, for example. Can you configure your sendmail instance to connect on an alternate MSA, which is typically port 587?
There is actually an option to change the port, IIRC. I'll try that.

Thanks.
Azure is offline   Reply With Quote
Old 03-23-2010, 09:35 PM   #8
Azure
Had an idea!
 
Azure's Avatar
 
Join Date: Oct 2005
Exp:
Default

Quote:
Originally Posted by sclitheroe View Post
Personally I would also rethink the email approach too - why not load a util on there that would allow your routers to make secure DNS A record updates on a DNS server that you run yourself (and probably run on a non-standard port to avoid any other ISP interactions)...in effect becoming your own personal DynDNS service. Then, you have a name server that can always resolve the names of your routers to IP addresses.
What kind of utility would do that?

I'm trying to get away from assigning IP addresses until the routers are plugged in somewhere.

So I need a quick way to get that IP address.
Azure is offline   Reply With Quote
Old 03-24-2010, 11:51 AM   #9
Shazam
Franchise Player
 
Shazam's Avatar
 
Join Date: Aug 2005
Location: Memento Mori
Exp:
Default

Quote:
Originally Posted by sclitheroe View Post
Lots of ISP's don't allow port 25 connections outbound from their networks (they only allow SMTP on 25 to one of their own SMTP servers) - Telus is one such ISP, for example. Can you configure your sendmail instance to connect on an alternate MSA, which is typically port 587?
Yeah, this essentially. Otherwise your SMTP server becomes a massive relaying opportunity.
__________________
If you don't pass this sig to ten of your friends, you will become an Oilers fan.
Shazam is offline   Reply With Quote
Old 03-24-2010, 04:14 PM   #10
Azure
Had an idea!
 
Azure's Avatar
 
Join Date: Oct 2005
Exp:
Default

Even if I use ssmtp I don't think its possible to actually have it connect properly.

My best bet would probably be setting up some kind of DynDNS server.

Ever heard of MintDNS?
Azure is offline   Reply With Quote
Old 03-24-2010, 05:35 PM   #11
sclitheroe
#1 Goaltender
 
Join Date: Sep 2005
Exp:
Default

Here's another approach that would be even easier - set up a web server somewhere that you have access to the logs for. Have a scheduled task on each router that fetches a page such as http://mywebserver/name_of_router.html, on an hourly basis

Then, you can grep the webserver logs for the router name, and the last line found is the most recent IP address for that router.

Easy Peasy Lemon Squeezy
__________________
-Scott
sclitheroe is offline   Reply With Quote
Old 03-24-2010, 06:04 PM   #12
Azure
Had an idea!
 
Azure's Avatar
 
Join Date: Oct 2005
Exp:
Default

Yeah, you're pretty smart for a geek.



Thanks, I'll look into that.
Azure is offline   Reply With Quote
Old 03-26-2010, 02:40 PM   #13
Azure
Had an idea!
 
Azure's Avatar
 
Join Date: Oct 2005
Exp:
Default

Alright, I have the script put together.

Problem is I don't know if a command exists in Linux where you can browse to a router in the command line.

At least I haven't been able to find it.
Azure is offline   Reply With Quote
Old 03-26-2010, 03:25 PM   #14
ericschand
Scoring Winger
 
Join Date: May 2005
Exp:
Default

Quote:
Originally Posted by Azure View Post
Alright, I have the script put together.

Problem is I don't know if a command exists in Linux where you can browse to a router in the command line.

At least I haven't been able to find it.
Text-based web browser?

Try "lynx"

ers
ericschand is offline   Reply With Quote
Old 03-26-2010, 04:10 PM   #15
sclitheroe
#1 Goaltender
 
Join Date: Sep 2005
Exp:
Default

You mean browser from a router command line, non-interactively, right? In that case, wget is what you want.

Hell, you could even pipe a text file with an HTTP GET command into telnet over port 80, assuming the router's OS has a telnet function.
__________________
-Scott
sclitheroe is offline   Reply With Quote
Old 03-26-2010, 05:37 PM   #16
Azure
Had an idea!
 
Azure's Avatar
 
Join Date: Oct 2005
Exp:
Default

It does have a telnet function.

Anyways, the following script...

Quote:
#!/bin/sh
# NSlookup, script to browse to a webserver to drop the routers IP addres for future configuration.
# Created by Azure

# Some settings
INTERVAL=10

# The "main" loop
while sleep $INTERVAL
do
wget http://mywebserver.org
done
Works perfectly. When I check the log files on my webserver they all show up.

Being able to send a text file could let me use '`nvram get wan_ipaddr`' and send it on through. I'll try to figure out how to send it with HTTP GET.

The other thing I was thinking would be to create a subdomain, like mywebserver.com/subdomain. Would it be possible to do a special search on my web server to only check the log files for that subdomain?

That would eliminate basically all my other problems and I could just run the script above on every router.
Azure is offline   Reply With Quote
Old 03-26-2010, 05:48 PM   #17
sclitheroe
#1 Goaltender
 
Join Date: Sep 2005
Exp:
Default

Quote:
Originally Posted by Azure View Post
It does have a telnet function.

Anyways, the following script...



Works perfectly. When I check the log files on my webserver they all show up.

Being able to send a text file could let me use '`nvram get wan_ipaddr`' and send it on through. I'll try to figure out how to send it with HTTP GET.

The other thing I was thinking would be to create a subdomain, like mywebserver.com/subdomain. Would it be possible to do a special search on my web server to only check the log files for that subdomain?

That would eliminate basically all my other problems and I could just run the script above on every router.
Even wget'ing an invalid URL should be logged in your web server logs, so you wget http://mywebserver/$MYIPADDRESS , (assuming you've set $MYIPADDRESS first, of course) and its not going to return anything, but it will get logged, and from there you can parse the logs. Or something like that
__________________
-Scott
sclitheroe is offline   Reply With Quote
Old 03-26-2010, 06:02 PM   #18
Azure
Had an idea!
 
Azure's Avatar
 
Join Date: Oct 2005
Exp:
Default

Or I could use the grep command.

assuming the log files are at the following directory.../var/log/apache2/access.log

I should be able to go

grep subdomain access.log

and find all results in the access.log folder that have subdomain included. Which could be a lot, but I would change the 'subdomain' to something I know wouldn't be in there as a rule.

or better yet, go

grep -i subdomain access.log

and it should search everything while being case insensitive.
Azure is offline   Reply With Quote
Old 03-26-2010, 06:12 PM   #19
Azure
Had an idea!
 
Azure's Avatar
 
Join Date: Oct 2005
Exp:
Default

Yep.

If I put in the script to go to

http://mywebserver.org/routerconfig

and run the script, then when I go to the webserver to check the logs and go

grep -i routerconfig access.log

it brings up all requests made to that subdomain despite it not existing.

sweet, now I just have to figure out how to make it work as a script on the router, and not just a script i'm executing in telnet.

thanks!
Azure is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 05:41 AM.

Calgary Flames
2023-24




Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright Calgarypuck 2021