I used to play around with Google Voice texting with PHP. I even had a buddy setup a personal web site using php to send mass texts before google recently made this available.

Google, however, has not released an official API. Most implementations to do this are hacky and are rather prone to break when google decides to change something with their login page. I looked for and tested a couple of PHP scripts, but could not find any working implementation. If you can find a working PHP script, I'd be happy to play with it.

The Python script I've used for google voice has been consistently updated when things break, which is why I find it preferable. Python is just as easy to setup on the router as PHP. If you like, I can try to do what you described, but in Python, unless you can find a working PHP script.
This is what I use for google voice.http://everydayscripting.blogspot.com/2011/10/login-problems-solved.html

You will need to create two files for this script.
/opt/logs/vpn
/opt/logs/hourly_vpn

/opt/logs/vpn - will keep a continuous log of all vpn connections
/opt/logs/hourly_vpn -will maintain logs for the current hour. Once they have been emailed at the end of the hour, it will be wiped clear.

Download and unpack 'scripts.zip' and upload the following scripts and place them in /opt/scripts/
client-connect.py
gvoice.py
hourly_vpn.py
mail.py

Looks like you've tried to run the script manually from the command line. It won't work just manually executed. It must be placed in the web gui. It makes sense that 'common_name' wasn't found because it will be supplied directly from OpenVPN when someone connects. Or were there issues before this, and you tried running it manually to check it out?

Looks like you've tried to run the script manually from the command line. It won't work just manually executed. It must be placed in the web gui. It makes sense that 'common_name' wasn't found because it will be supplied directly from OpenVPN when someone connects. Or were there issues before this, and you tried running it manually to check it out?
.
.
.

Click to expand...

I have used it so, but after adding this 2 lines I can´t connect to my router/vpn, without them it´s possible.
So I tested it directly from command prompt of course with problems as I have mentioned before.

Just to be clear we're on the same page. There are two tutorials in this thread. The first tutorial sends an email every time a client connects. I believe you are looking at the second tutorial. The second tutorials sends a text message (not an email) when a client connects, and then sends an email once per hour with the last hour's connection logs.

The client-connect scripts in the first and second tutorial are different. If you're looking for emails notifications only, go with the code that's displayed in the first post only.

I fallowed the steps you provided in you first post, installing python, created the two scrips, only changing "gmailUser", "gmailPassword", and "recipient" options, then placed them in "/opt/scripts/" and lastly added the entries you provided in OpenVPN server "custom configuration" space. I then rebooted the router but after making these changes I cannot connect to my VPN server, if I remove the entries I added in openvpn custom configuration space, I'm able to connect to the VPN sever again.
I took a look at the logs and I see this entry from the vpn server

Wow this is great! Thanks so much for this lancethepants!
Now if only i could get the same working but for when a (new) WLAN client connects ;-)

I changed the formatting a little bit to my taste (the first tutorial, sending Email).
Just thought it would be nice to have a multiline email and more info on disconnect,
and maybe someone else will like my formatting too, so here it is.

I tried to convert the seconds of the duration to a better format but the pythontotal noob that i am, failed.
Tried this: formatted_duration = datetime.timedelta(seconds=duration)
But no luck, even tho seconds=10000 in it works... probably some dumb variable string stuff.
Of course the bytes sent/received could be converted to KB/MB/GB too.

I've double checked my gmail user name and password and they are correct. Any idesas why its not working?

Click to expand...

If you are absolutely sure that everything is correctly set up, i could only think of your gmail-password
containing a special character that python doesnt like... would need to be escaped. Just a hunch tho.

I'm not sure what you mean by this statement. This should work for LAN or WLAN connecting clients. I am probably misunderstanding.

Very nice formatting, I like it very much. I've actually changed to use it myself

Click to expand...

Oh sorry, i guess i shouldve been clearer. Something like this, but notification when a new WLAN client connects, without VPN.
Example, using a Guest network, get notified when someone joins. There was talk about that in another thread already
but i couldnt get a script that was posted there running and couldnt be bothered (yet) to further spend time on it.

Thanks lancethepants...I fixed the "gmailuser" entry in the "mail.py" script as you suggested, then rebooted router for good measure but I'm still having the same issue. My gmail password has no special characters, just letters, numbers and no spaces.

Thanks lancethepants...I fixed the "gmailuser" entry in the "mail.py" script as you suggested, then rebooted router for good measure but I'm still having the same issue. My gmail password has no special characters, just letters, numbers and no spaces.

Click to expand...

Are you sure you have a working Python installation? Is the path correct? like /opt/bin/python27
Because i actually have only 2.5 installed and had to change the path, but it works fine.
Try executing the mail.py on its own, what kind of output do you get? python /opt/scripts/mail.py

I had no errors when I isntalled Python through Entware. The path is correct, its "opt/bin/python2.7", theres also symlink named "python" in that same direcotry that points to "python2.7"

Last night I started from scratch, erased NVRAM and configured only OpenVPN and Entware but I still had the same problem.

When I run "python /opt/scripts/mail.py" in putty, nothing happens but when I excute "python /opt/scripts/client-connect.py" the below happens. Lancethepants said the below is normal since the script is not meant to be excecuted manually.

Thanks for helping, this would be icing on the cake if I could get it to work, only difference I see is that i'm using Entware and not Optware. What version of tomato you running?

I'll give that a try once I get home tonight. I just did a quick look at the Entware packages and see two that might be the package you suggested. I see "pyopenssl" and "python-openssl"...Should I go with the "python-openssl"?

I'll give that a try once I get home tonight. I just did a quick look at the Entware packages and see two that might be the package you suggested. I see "pyopenssl" and "python-openssl"...Should I go with the "python-openssl"?

I've got Open VPN setup on a Ubuntu VM, and it works nicely. I'd like to set an email notification, using our Exchange server, to notify when a VPN user connects. Is optware strictly necessary for what I'd like to achieve? As the VM is running smoothly, with a bare minimum of stuff on there, I don't want to risk disrupting it and/or increasing the attack surface (plus I'm a Linux noob and tend to break it beyond repair relatively easily).

NM I've done a bit more research, and I think all I need is OpenVPN --client-connect script, and then just need to configure a bash script to fire off an email.

Thanks for great tuturial lancethepants. tried to get this working on ddwrt but I am stuck with thescript-security 2 --client-connect "/opt/bin/python2.7 /opt/scripts/client-connect.py"
I think the problem may be related to openvpn on ddwrt not sure.These are all the test I did see link http://www.dd-wrt.com/phpBB2/viewtopic.php?t=174158
Any help is appreciated, even though I know it is not related to your script.

One question I have, how did you install python? I don't see any mention of optware or entware (which I now prefer). Both package managers I believe install python to /opt/bin, but your other thread mentions /opt/usr/bin.

Let's first make sure we can successfully send an email with python.
mail.py should already be populated with your gmail username/password and destination email address. Make sure they are properly surrounded by singe quotes ('). My first post is missing one on the 'gmailUser' line, but I wasn't able to edit that post last I checked.

Create another python script in the same directory as mail.py, with the following code. This is just the client-connect script really stripped down. You can't really just run client-connect on its own, it needs to be called by openvpn, but this script we can run just to make sure you actually get an email sent.

Thanks for your response, yea I can send an email if i run python /opt/scripts/client-connect.py (I edited the client-connect.py script)
That is why i believe the problem is with the --client-connect command

EDIT
I use optware, to installed python i use opkg install python

If I run the --client-connect command directly in router via telnet i get this error

Hmmm, I'm not sure what optware you're using. The one I just installed uses the command "ipkg", not "opkg", and installs python in to /opt/bin.
Entware uses the command "opkg", but also installs python in to /opt/bin.
Make sure you install the python-openssl package of whatever you're using, if it exists separate. That may be, entware is this way. Otherwise, I am stumped, I'm not familiar with the optware you are using.

Also, the errors you're posting are two separate things. The first clearly shows that you're needing to use the --dev flag (and this is why I asked what version of OpenVPN you were using), while the 2nd conflicts with the first (it indicates you're able to actually run/launch OpenVPN, while the first clearly shows it doesn't start/run).

It would be beneficial if lancethepants could disclose what OpenVPN version he's using, as they may have changed the command line parsing code between versions, or the different Entware/Optware installations you two are using have OpenVPN that's built differently. Both are plausible explanations.

Overall I would suggest trying Entware if you could, given that Optware isn't even maintained reliably any more, and the Entware folks understand what the hell they're doing. You'll need to completely nuke (or move out of the way) your existing /opt bits. Entware does have OpenVPN, as well as python-openssl.

Thanks koitsu the first error Options error: You must define TUN/TAP device (--dev) occurs when I try to run the commandscript-security 2 --client-connect "/opt/usr/bin/python2.7 /opt/scripts/client-connect.py"
in telnet on the router (openvpn server)

The second error AUTH_FAILED is when I enter the commandscript-security 2 --client-connect "/opt/usr/bin/python2.7 /opt/scripts/client-connect.py" in the GUI of the router (openvpn server) and then when i try to connect to the server from an openvpn client I see this error on the client.

My openvpn works once I remove script-security 2 --client-connect "/opt/usr/bin/python2.7 /opt/scripts/client-connect.py" from the router (openvpn server)

I would have a look at entware today, who knows maybe I am using entware. I will also submit a bug ticket on my router's firmware website(ddwrt) letting them know that the --client-connect command in the openvpn binary they compiled on the firmaware may not be working as expected.

I'm using version 2.3.2 of OpenVPN, and have used it since 2.1 variants. Perhaps support for this hasn't been compiled in. It may be part if the management interface, which can be excluded. I compile my own binaries of OpenVPN, and use the bind command in a startup script to mount it over Tomato's. This is supported in Tomato's included binaries too.
Your optware page mentions somewhere big endienness I thought. Perhaps that is why you have to use a different optware.

Thanks lancethepants I believe you are correct maybe its a problem with how ddwrt compiled openvpn in its firmware. I will look to see if I can figure out how to compile my own binaries as well. If you have any manuals or any instructions I can use to compile my own binary please don't hesitate to send me a PM. Till then I don't want to clutter this thread with issues not related to the topic.