Page 1 of 3

Adding SOCKS support for SAB

Posted: February 21st, 2010, 4:09 pm
by f00b4r
Hi All,

I've been using SAB for a few months now. I need to use a SOCKS proxy to connect to my NG provider (no way to get around that). Right now I'm using a SSH tunnel proxying.
I'm willing to implement SocksiPy (http://socksipy.sourceforge.net/) in SAB on my own, I would only need a few hints on how the code is working.

For example I'm wondering where is made the connection to the News server...

Thanks for your help !

(I'm not sure I posted in the right section... :))

Re: Adding SOCKS support for SAB

Posted: February 25th, 2010, 7:29 pm
by switch
Socket connections occur in newswrapper.py

Be aware there is also a wrapper for SSL connections, I'm not sure how nice the SocksiPy wrapper will play with the SSL wrapper.

If you need any more guidance I can usually be found on IRC http://sabnzbd.org/live-chat

Re: Adding SOCKS support for SAB

Posted: July 12th, 2010, 12:32 pm
by f00b4r
Woot, it works :) Even with SSL.
I will document my work and make it available here!

Thanks for your help switch!

Re: Adding SOCKS support for SAB

Posted: July 27th, 2010, 8:18 pm
by Jabroni
I would love to see socks supports on SabNZBd, so far Ive been using sockscap on a win32 setup to send the requests thru a socks servers, but I would love to see more a native solution so I can move sabnzbd to my linux server  :)

Care to share the code? Or have you tried talking to the projects admin to see if you can commit your source changes to their svn ?

Re: Adding SOCKS support for SAB

Posted: August 14th, 2010, 8:03 pm
by Jabroni
Ok I finally managed to get it working.. for anyone interested in adding a socks proxy for news server connection just do the following:

- Download and install the socksipy python package and install it
- Edit the /sabnzbd/newswrapper.py
Add a import socks (around line 15 where the other improts are)
Add self.sock.setproxy(socks.PROXY_TYPE_SOCKS5,"IP.OF.PROXY.SERVER",PORT_OF_SERVER) at line ~168  (after the self.sock = socks.socksocket(af,socktype,proto))

This will just add the socks support for nonssl connections, whoever previous poster said the wrapper worked for SSL connections too, so it would just required to set the ssl socket with the socks proxy parameters


Right now I have it hardcoded my proxy there, but it would be nice if we could have a config screen on sabnzbd for it :)

Thats for socks5, for other proxy options, check the socksipy README at http://socksipy.sourceforge.net/readme.txt

Re: Adding SOCKS support for SAB

Posted: August 15th, 2010, 7:48 am
by shypike
Well done! The true spirit of Open Source, indeed.
Do you want us to add this to the SABnzbd distribution?
If so, please contact the team at team at sabnzbd.org

Re: Adding SOCKS support for SAB

Posted: August 15th, 2010, 3:32 pm
by Jabroni
Whoops post didnt came out complete.. I had more instructiosn but guess my browser didnt post it correctly..

Let me edit my previous post..

Re: Adding SOCKS support for SAB

Posted: August 15th, 2010, 5:23 pm
by shypike
Looks like most work will go into the UI elements :(
We'll see if this can be added to an 0.6.x release.
Testing will be a bit awkward without an available proxy.
Thanks.

Re: Adding SOCKS support for SAB

Posted: August 26th, 2010, 1:38 pm
by f00b4r
Sorry, but I couldn't find time to document it just yet...
Indeed most of the changes take place in the UI, and a little in the parameters/config file too (less hardcoded parameters). My main problem was to understand the code, which should not be a problem for the devellopers team (I hope  ;D).

I currently have a working modified version for a specific usage: no news server settings available in the UI, ssl proxy only and UI settings available. I'd be really glad to see it on the SVN someday, please ask :)

I MAY be able to provide a proxy for testing, please PM me.

Re: Adding SOCKS support for SAB

Posted: August 26th, 2010, 7:07 pm
by crk
Hi @ll,
you are discussing a feature that is missing for months (years).
Months ago, I had the same idea with this sockisfier lib... so I gave it a try, nearly solved, failed and gave up...
Today it's nice to have activity in this topic.

My environment:
Debian Lenny on amd64 dual core
danted socks v 5
all the python stuff from apt repos

Additionally I'm running it on a Seagate Dockstar (ARM) [~ 20 euros].
6 watts power consumption :) :)

I'd be glad to have a working newswrapper.py including proxy authentification with ssl support.

sabnzbd - great work guys. I will spend spent some bucks for the project.
Usenet is getting cheaper, so there is more money for nice tools :)
//edit: :)

Re: Adding SOCKS support for SAB

Posted: August 27th, 2010, 6:33 am
by shypike
I do have code for this, based on Jabroni's suggestions.
However, I have no possibility to test it.

Re: Adding SOCKS support for SAB

Posted: August 27th, 2010, 8:28 am
by crk
Guys, amazing news!
I'm testing with dante proxy server (SOCKS5 & auth).
After having short conversation with jabroni and f00b4r... I wasn't able to stop thinking about the problem.
Especially in my case the connection was not working, because I always used proxy authentification for testing.
Thus, jabronis solution didn't work for me.
Finally I traced the scripts and the libraries...

AMAZING NEWS:
found a bug in socksipy lib!! (last version in 2006...)
That was the reason why I was not able to use socket proxy with authentification and so every connection failed.

The bug is in socks.py line 190
replace

Code: Select all

self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.proxy[5])) + self.__proxy[5])
with

Code: Select all

self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5])
Now the connection is working for me.
This is just for users that can't wait to sockisfy their sabnzbd  with working proxy authentification :)
I'm now going to write a short howto after testing issues with ssl connections.

Re: Adding SOCKS support for SAB

Posted: August 27th, 2010, 9:28 am
by crk
Howto add SOCKS support to SABnzbd+

For this short howto I'm using the latest version.

1. Download and install the socksipy python package and install it (http://socksipy.sourceforge.net/ or repository debian "apt-get install python-socksipy" ). Make sure that the lib is put in the python shared folder.

2. Fix the authentification bug in socksipy. This is needed if you are going to use socks proxy with authentification.
In case of installation via repository just search for the socks.py (find / -name "socks.py")

socks.py line 190
replace

Code: Select all

self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.proxy[5])) + self.__proxy[5])
with

Code: Select all

self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.__proxy[5])) + self.__proxy[5])
3. Edit /sabnzbd/newswrapper.py

where: line 166 after the else branch
desc: change the object from socket to socks and the method from socket to socksipys socksocket which receives the same arguments
todo:
replace

Code: Select all

self.sock = socket.socket(af, socktype, proto)
with

Code: Select all

self.sock = socks.socksocket(af, socktype, proto)
where: Underneath last insert
desc: Setup proxy connection for object "sock". This one is for authentification with socks5. To use socks4, http and socks4a please read the manual.
todo:
insert

Code: Select all

self.sock.setproxy(socks.PROXY_TYPE_SOCKS5,"IP_OR_DOMAIN",PORT,True,"USERNAME","PASSWORD")
Or - if authentification is not needed, just take:

Code: Select all

self.sock.setproxy(socks.PROXY_TYPE_SOCKS5,"IP_OR_DOMAIN",PORT)
where: import section (line 20-30)
desc: Make the script use socksipy.
todo:
Add new line, for example after line 20

Code: Select all

import socks
That's it. Now you can connect to server. You can check servers in server setup.
Currently, f00b4r is working on a SSL connection implementation. Time will tell .. weekend will bring :)

Re: Adding SOCKS support for SAB

Posted: September 1st, 2010, 12:21 pm
by bullox
I'm trying to get socks support on my OSX version of SABnzbd, but I'm having a problem:
I don't know if I'm wrong at all, but I can't seem to find the newswrapper.py file in OSX. I've tried show package contents on SABnzbd+ and searched all its folders but no results, also nothing in application support in Library.
I'm guessing this stuff is in a different folder from which SABnzbd sources it? Where do I find this file?

Thanks

Re: Adding SOCKS support for SAB

Posted: September 1st, 2010, 2:54 pm
by shypike
If you want to patch SABnzbd yourself, you're in for an adventure.
It's rather complicated and described here: http://wiki.sabnzbd.org/howto-osx-src