[FreeNAS 9 Plugins] - SAB / SB / CP / HP / Maraschino / HTPC / Mylar / LL / Gamez

Status
Not open for further replies.

denist

Contributor
Joined
Jan 28, 2013
Messages
188
yes i am using the Transmission plugin. I use your guid to setup sabnzbd,couch,transmission,nginx. After i confirm that all that is working then i start the openvn install which i use this guide. https://forums.freebsd.org/threads/54531/. Once that is completed and confirmed working i then implement a killswitch py script with the code below
Code:
#!/usr/local/bin/python2.7
import sys
import socket
import subprocess
url = 'Netherlands.privateinternetaccess.com'
try:
  # Raise if it can't ping the server or openvpn isn't running
  subprocess.check_output(['service', 'openvpn', 'status'])
  subprocess.check_output(['ping', '-c', '1', url])
except subprocess.CalledProcessError:
  pass
else:
  sys.exit()
hostname, aliaslist, ipaddrlist = socket.gethostbyname_ex(url)
content = '''
add 01006 allow ip from 192.168.2.0/24 to 192.168.2.0/24 keep-state
'''
rule_number = 2001
for ip in ipaddrlist:
  content += '''
add {} allow ip from 192.168.2.0/24 to {} keep-state
add {} allow ip from {} to 192.168.2.0/24 keep-state
'''.format(rule_number, ip, rule_number + 1, ip)
  rule_number += 2
content += '''
add 04000 allow ip from 127.0.0.1 to any
add 05000 allow ip from 10.0.0.0/8 to any
add 05002 allow ip from any to 10.0.0.0/8
add 65534 deny ip from any to any
'''
# Stop ipfw
subprocess.call(['service', 'openvpn', 'stop'])
subprocess.call(['service', 'ipfw', 'stop'])
f = open('/sabnzbd/scripts/ipfw_rules', 'w')
f.write(content)
f.close()
# Start ipfw
subprocess.call(['service', 'ipfw', 'start'])
# Check if running
if 'ipfw' in subprocess.check_output(['service', '-e']):
  subprocess.call(['service', 'openvpn', 'start'])
sys.exit()



which i then use the freenas gui cron to run every 5 min. (jexec transmission_1 python2.7 /sabnzbd/scripts/pia.py

this checks VPN and create ipfw_rules so the internet works when openvpn works. I confirm this is working then i move to the last step which was the the port forward rule for pia and transmission script and then the errors come up.

Thank you for you time.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
I think your issues might be related to the space in your first line.
definitely get rid of that, you also want to use the PATH I give since the plugin puts things in a weird place.
 

denist

Contributor
Joined
Jan 28, 2013
Messages
188
Quick question when i create a crontab -e

would this be ok

*/5 * * * * /sabnzbd/scripts/port_forward.sh >> /var/log/pia.log 2>&1

or


*/5 * * * * /usr/bin/sh /sabnzbd/scripts/port_forward.sh >> /var/log/pia.log 2>&1
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Quick question when i create a crontab -e

would this be ok

*/5 * * * * /sabnzbd/scripts/port_forward.sh >> /var/log/pia.log 2>&1

or


*/5 * * * * /usr/bin/sh /sabnzbd/scripts/port_forward.sh >> /var/log/pia.log 2>&1
either should be fine if the script has execute permissions. if its not then the second method should still work
 

denist

Contributor
Joined
Jan 28, 2013
Messages
188
Hey Joshua is it needed to update the transmission blacklist weekly ? as a script like the one below.

Code:
#!/bin/sh

export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin"

echo "Blocklist Update $(date +%Y-%m-%d-%H:%M:%S)"

transmission-remote --blocklist-update


and setup a crontab -e

Code:
@weekly /usr/bin/sh /sabnzbd/scripts/ubl.sh >> /var/log/blocklistupdate.log 2>&1


Is the script above OK for doing this.

Also can i run the py script in jail or is it better to run the py script in the Freenas GUI cron?

Thanks
 

denist

Contributor
Joined
Jan 28, 2013
Messages
188
Hi Joshua,

Tried you script and when i run sh port_forward.sh i get this error.

Code:
root@transmission_1:/usr/local/etc/pia_openvpn # sh port_forward.sh
: not foundd.sh:
: not foundd.sh:
: not foundd.sh:
Transmission Port Forward 2016-12-21-23:37:36
: not foundd.sh:
cut: bad delimiter
: not foundd.sh:
: not foundd.sh:
: not foundd.sh:


do you have any idea?
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Hi Joshua,

Tried you script and when i run sh port_forward.sh i get this error.

Code:
root@transmission_1:/usr/local/etc/pia_openvpn # sh port_forward.sh
: not foundd.sh:
: not foundd.sh:
: not foundd.sh:
Transmission Port Forward 2016-12-21-23:37:36
: not foundd.sh:
cut: bad delimiter
: not foundd.sh:
: not foundd.sh:
: not foundd.sh:


do you have any idea?
I just tested the script myself and am not getting the ": not foundd.sh:" errors. Maybe your file is in DOS format somehow (I got an issue like that and just created a new script pasting in the contents).
As for the cut error, I made a mistake and removed a space in that line. Please add it back like the original script version of the script you posted on this thread.
 

denist

Contributor
Joined
Jan 28, 2013
Messages
188
It's working fine using the bash at the moment no errors. Just port forward transmission for me.


Sent from my iPhone using Tapatalk
 

denist

Contributor
Joined
Jan 28, 2013
Messages
188
Im using it this way in crom
Code:
*/5 * * * * /usr/local/bin/bash /sabnzbd/scripts/port_forward.sh >> /var/log/pia.log 2>&1

and the original script without the space.
Code:
#!/usr/local/bin/bash
# Cronable port forwarding script for PIA/transmission running on
# FreeNAS
#
# Requires bash, jq (JSON parser) and curl
# pkg install -y jq bash curl
# Assumes tunnel is tun0 if different change below
#

# Your PrivateInternetAccess credentials
PIA_USER=username
PIA_PASS=password

# Export path for when you use this in cron
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin"

# echo date/time for logging
echo "Transmission Port Forward $(date +%Y-%m-%d-%H:%M:%S)"

get_new_port( ) {
  if ! [ -x $(curl)  ]; then
  echo "Curl not installed/not executable"
  exit 0
  fi
   
  # get the local tunnel ip
  local_ip=$(ifconfig tun0 | grep "inet " | cut -d\  -f2)
   
  #client_id seems to want random data
  client_id=$(head -n 100 /dev/urandom | md5 -r | tr -d " -")
   
  port=$(curl --silent --data "user=$PIA_USER&pass=$PIA_PASS&client_id=$client_id&local_ip=$local_ip" https://www.privateinternetaccess.com/vpninfo/port_forward_assignment | jq .port)
   
  if ! [[ $port =~ ^[0-9]+$ ]]; then
  echo "Garbled data: $port"
  exit 0
  fi
   
  transmission-remote -p $port
}

is_port_forwarded( ) {
  # -pt tests for open port.
  json=$(transmission-remote -pt)
   
  if [[ $json == "Port is open: No" ]]; then
  echo "Closed port detected"
  get_new_port
  elif [[ $json == "Port is open: Yes" ]]; then
  echo "Open port detected"
  exit 1

  fi
}

check_for_connectivity( ) {
  if nc -zw 1 google.com 80; then
  echo "VPN connection up."
  else
  echo "VPN connection down. Exiting."
	exit 0

  fi
}

check_for_connectivity
is_port_forwarded

exit 1


When the port is open already i get this message

Transmission Port Forward 2016-12-22-16:15:00
Connection to google.com 80 port [tcp/http] succeeded!
VPN connection up.
Open port detected

When the port is closed and VPN is up i get this message

Transmission Port Forward 2016-12-22-16:05:00
Connection to google.com 80 port [tcp/http] succeeded!
VPN connection up.
Closed port detected
curl: try 'curl --help' or 'curl --manual' for more information (this line here why does this come up?)
localhost:9091/transmission/rpc/ responded: "success"
Transmission Port Forward 2016-12-22-16:10:00
Connection to google.com 80 port [tcp/http] succeeded!

So far so good but the line above not sure why that comes up. Is there an error with the curl

Thanx Heaps for the blog guide and this also.
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
Im using it this way in crom
Code:
*/5 * * * * /usr/local/bin/bash /sabnzbd/scripts/port_forward.sh >> /var/log/pia.log 2>&1

and the original script without the space.
Code:
#!/usr/local/bin/bash
# Cronable port forwarding script for PIA/transmission running on
# FreeNAS
#
# Requires bash, jq (JSON parser) and curl
# pkg install -y jq bash curl
# Assumes tunnel is tun0 if different change below
#

# Your PrivateInternetAccess credentials
PIA_USER=username
PIA_PASS=password

# Export path for when you use this in cron
export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin"

# echo date/time for logging
echo "Transmission Port Forward $(date +%Y-%m-%d-%H:%M:%S)"

get_new_port( ) {
  if ! [ -x $(curl)  ]; then
  echo "Curl not installed/not executable"
  exit 0
  fi
  
  # get the local tunnel ip
  local_ip=$(ifconfig tun0 | grep "inet " | cut -d\  -f2)
  
  #client_id seems to want random data
  client_id=$(head -n 100 /dev/urandom | md5 -r | tr -d " -")
  
  port=$(curl --silent --data "user=$PIA_USER&pass=$PIA_PASS&client_id=$client_id&local_ip=$local_ip" https://www.privateinternetaccess.com/vpninfo/port_forward_assignment | jq .port)
  
  if ! [[ $port =~ ^[0-9]+$ ]]; then
  echo "Garbled data: $port"
  exit 0
  fi
  
  transmission-remote -p $port
}

is_port_forwarded( ) {
  # -pt tests for open port.
  json=$(transmission-remote -pt)
  
  if [[ $json == "Port is open: No" ]]; then
  echo "Closed port detected"
  get_new_port
  elif [[ $json == "Port is open: Yes" ]]; then
  echo "Open port detected"
  exit 1

  fi
}

check_for_connectivity( ) {
  if nc -zw 1 google.com 80; then
  echo "VPN connection up."
  else
  echo "VPN connection down. Exiting."
	exit 0

  fi
}

check_for_connectivity
is_port_forwarded

exit 1


When the port is open already i get this message

Transmission Port Forward 2016-12-22-16:15:00
Connection to google.com 80 port [tcp/http] succeeded!
VPN connection up.
Open port detected

When the port is closed and VPN is up i get this message

Transmission Port Forward 2016-12-22-16:05:00
Connection to google.com 80 port [tcp/http] succeeded!
VPN connection up.
Closed port detected
curl: try 'curl --help' or 'curl --manual' for more information (this line here why does this come up?)
localhost:9091/transmission/rpc/ responded: "success"
Transmission Port Forward 2016-12-22-16:10:00
Connection to google.com 80 port [tcp/http] succeeded!

So far so good but the line above not sure why that comes up. Is there an error with the curl

Thanx Heaps for the blog guide and this also.
what does that curl command give you if you run it in the command line? you should replace the variables appropriately
 

carleycr

Patron
Joined
May 2, 2014
Messages
233
That wouldn't remove sabnzbd itself, that command would remove the data-directory (config / database) that sabnzbd leaves behind. You would want to stop and remove the sabnzbd plugin first.

transmission is the same case, except its folder is /var/db/transmission
So I followed your instructions on removing and reinstalling Sab and Transmission into the jail and re-setup the plugins using your blog. I also took it a step further and re-installed sickrage, as it was having issues after my roommate switched out the router (had to do some network setup changes to get some things to work again). Anyway, I'm back up and running with the plugins, but now Sickrage gives me a crap ton of errors and won't let me re-add all the existing media. I'm getting the below errors over and over in the errors log.

2017-02-07 14:47:24 MAIN :: Connection error to getURL http://sickrage.github.io/sb_network_timezones/network_timezones.txt Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:47:24 MAIN :: Updating network timezones failed, this can happen from time to time. URL: http://sickrage.github.io/sb_network_timezones/network_timezones.txt
2017-02-07 14:46:23 MAIN :: Connection error to getURL http://sickrage.github.io/sb_network_timezones/network_timezones.txt Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:46:23 MAIN :: Updating network timezones failed, this can happen from time to time. URL: http://sickrage.github.io/sb_network_timezones/network_timezones.txt
2017-02-07 14:45:23 MAIN :: Connection error to getURL http://sickrage.github.io/sb_network_timezones/network_timezones.txt Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:45:23 MAIN :: Updating network timezones failed, this can happen from time to time. URL: http://sickrage.github.io/sb_network_timezones/network_timezones.txt
2017-02-07 14:44:22 MAIN :: Connection error to getURL http://sickrage.github.io/sb_network_timezones/network_timezones.txt Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:44:22 MAIN :: Updating network timezones failed, this can happen from time to time. URL: http://sickrage.github.io/sb_network_timezones/network_timezones.txt
2017-02-07 14:43:22 MAIN :: Connection error to getURL http://sickrage.github.io/sb_network_timezones/network_timezones.txt Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:43:22 MAIN :: Updating network timezones failed, this can happen from time to time. URL: http://sickrage.github.io/sb_network_timezones/network_timezones.txt
2017-02-07 14:43:00 Thread-56 :: Connection error to getURL https://newshosting.com/api?t=caps Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:43:00 Thread-56 :: Error getting xml for [https://newshosting.com/api?t=caps]
2017-02-07 14:43:00 Thread-18 :: Connection error to getURL https://nzbfinder.ws/api?apikey=fecf33ed669094e00778f5827681f9d8&t=caps Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:43:00 Thread-18 :: Error getting xml for [https://nzbfinder.ws/api?apikey=fecf33ed669094e00778f5827681f9d8&t=caps]
2017-02-07 14:43:00 Thread-35 :: Connection error to getURL https://nzbplanet.net/api?apikey=fbdf62f3075d86b131be31e183246874&t=caps Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:43:00 Thread-35 :: Error getting xml for [https://nzbplanet.net/api?apikey=fbdf62f3075d86b131be31e183246874&t=caps]
 

Joshua Parker Ruehlig

Hall of Famer
Joined
Dec 5, 2011
Messages
5,949
So I followed your instructions on removing and reinstalling Sab and Transmission into the jail and re-setup the plugins using your blog. I also took it a step further and re-installed sickrage, as it was having issues after my roommate switched out the router (had to do some network setup changes to get some things to work again). Anyway, I'm back up and running with the plugins, but now Sickrage gives me a crap ton of errors and won't let me re-add all the existing media. I'm getting the below errors over and over in the errors log.

2017-02-07 14:47:24 MAIN :: Connection error to getURL http://sickrage.github.io/sb_network_timezones/network_timezones.txt Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:47:24 MAIN :: Updating network timezones failed, this can happen from time to time. URL: http://sickrage.github.io/sb_network_timezones/network_timezones.txt
2017-02-07 14:46:23 MAIN :: Connection error to getURL http://sickrage.github.io/sb_network_timezones/network_timezones.txt Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:46:23 MAIN :: Updating network timezones failed, this can happen from time to time. URL: http://sickrage.github.io/sb_network_timezones/network_timezones.txt
2017-02-07 14:45:23 MAIN :: Connection error to getURL http://sickrage.github.io/sb_network_timezones/network_timezones.txt Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:45:23 MAIN :: Updating network timezones failed, this can happen from time to time. URL: http://sickrage.github.io/sb_network_timezones/network_timezones.txt
2017-02-07 14:44:22 MAIN :: Connection error to getURL http://sickrage.github.io/sb_network_timezones/network_timezones.txt Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:44:22 MAIN :: Updating network timezones failed, this can happen from time to time. URL: http://sickrage.github.io/sb_network_timezones/network_timezones.txt
2017-02-07 14:43:22 MAIN :: Connection error to getURL http://sickrage.github.io/sb_network_timezones/network_timezones.txt Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:43:22 MAIN :: Updating network timezones failed, this can happen from time to time. URL: http://sickrage.github.io/sb_network_timezones/network_timezones.txt
2017-02-07 14:43:00 Thread-56 :: Connection error to getURL https://newshosting.com/api?t=caps Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:43:00 Thread-56 :: Error getting xml for [https://newshosting.com/api?t=caps]
2017-02-07 14:43:00 Thread-18 :: Connection error to getURL https://nzbfinder.ws/api?apikey=fecf33ed669094e00778f5827681f9d8&t=caps Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:43:00 Thread-18 :: Error getting xml for [https://nzbfinder.ws/api?apikey=fecf33ed669094e00778f5827681f9d8&t=caps]
2017-02-07 14:43:00 Thread-35 :: Connection error to getURL https://nzbplanet.net/api?apikey=fbdf62f3075d86b131be31e183246874&t=caps Error: u"error ('Connection aborted.', gaierror(8, 'hostname nor servname provided, or not known'))"
2017-02-07 14:43:00 Thread-35 :: Error getting xml for [https://nzbplanet.net/api?apikey=fbdf62f3075d86b131be31e183246874&t=caps]
it sounds like you dont have DNS setup in your jail. I would check its /etc/resolv.conf and make sure you can successfully 'ping google.com'
 

carleycr

Patron
Joined
May 2, 2014
Messages
233
One other thing. Couchpotato will not download media. I click download next to the movie and
it sounds like you dont have DNS setup in your jail. I would check its /etc/resolv.conf and make sure you can successfully 'ping google.com'
Thanks Joshua. I was able to find something on the forums to copy over my global DNS settings to the jail and that seems to have fixed it. I'm almost all back up and running now. The last issue I'm running into is one i've had before, but i'm not sure how i fixed it. Attached screenshot. Thoughts?

I've tried running chmod command in jail on that directory with no luck. I'm also running Sab 1.2.0 [1be50eb] on the latest 9.10.2-U1 build.

Screen Shot 2017-02-07 at 5.26.21 PM.png
 
Status
Not open for further replies.
Top