Page 1 of 1
Pause Sabnzbd when VPN is not connected
Posted: December 13th, 2012, 7:37 am
by suzie123
Hi, I was hoping for a little help with this one.
I'm running xbmcbuntu, with Sabnzbd. I have openVPN configured through network-manager-openvpn.
Because i'm booting directly into XBMC I have no way to tell if my VPN is connected. To check I have to SSH in and run "curl ifconfig.me" and then go to whatsmyip.com and check the location. It's a pain, and defeats the purpose if my VPN drops.
I'm looking for a way to tell sabnzbd, via script, to pause if the Network Manager VPN is not connected.
Any ideas?
Many thanks...

Re: Pause Sabnzbd when VPN is not connected
Posted: December 13th, 2012, 10:49 am
by shypike
The hard part is writing the script to determine the nextwork situation.
After that you can just use the "curl" tool to activate SABnzbd's API.
(See:
http://wiki.sabnzbd.org/api )
Re: Pause Sabnzbd when VPN is not connected
Posted: December 13th, 2012, 11:29 am
by sander
So you're running Ubuntu? Then I'll help you:
"curl ifconfig.me" seems enough to me; probably the two first bytes of the IP address are enough to determine whether the VPN is on or off. So IMHO you don't need to find out the exact location.
create a script / one-line to pause SABnzbd
create a script / one-line to unpause SABnzbd
Run it all each 5 minutes from crontab
If this approach is OK with you, I can help. As I like python and I dislike shell script, I would prefer just one python script with the above functionality.
Re: Pause Sabnzbd when VPN is not connected
Posted: December 13th, 2012, 4:49 pm
by suzie123
Thanks to you both for your replies.
That sounds great, thanks sander.
I understand what the script needs to do, though am a complete noob when it comes to putting it together. So your offer is greatly appreciated.
In terms of python vs shell. It's all jazz to me.. haha.
Re: Pause Sabnzbd when VPN is not connected
Posted: December 13th, 2012, 5:34 pm
by jcfp
shypike wrote:The hard part is writing the script to determine the nextwork situation.
Maybe that can be worked around by getting network-manager itself to run the script(s) at the correct times, along the lines of
this.
Re: Pause Sabnzbd when VPN is not connected
Posted: December 14th, 2012, 12:47 am
by sander
OK, first the public IP checker:
Can save the text below in a file sabonoff.py, and run it with "python sabonoff.py", and post the output here. Run it for both the VPN on and off.
Code: Select all
#!/bin/bin/python
ipurl = 'http://ifconfig.me/ip'
import urllib2
f = urllib2.urlopen(ipurl)
ipaddress = f.readline().rstrip()
(byte1,byte2,byte3,byte3)=ipaddress.split('.')
print byte1 + '.' + byte2
Re: Pause Sabnzbd when VPN is not connected
Posted: December 18th, 2012, 1:36 am
by sander
No reaction from suzie123 ... I hate that.