Page 2 of 4

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: February 24th, 2009, 8:55 am
by sander
I think it would be useful if the SABnzbd service would tell on which machine-name it's running (for clarity and when there are more SAB instances on different machines), so I've patched that in the patch code. See code below and see screenshots.

Important parts:

from socket import gethostname
name = "SABnzbd on " + gethostname() ,

Code: Select all

####Start Zeroconf patch########################################################
    try:
        from sabnzbd.utils import pybonjour
    except OSError:
        logging.info('Zeroconf service could not be registered')
    else:


	from socket import gethostname

        def zeroconf_callback(sdRef, flags, errorCode, name, regtype, domain):
            if errorCode == pybonjour.kDNSServiceErr_NoError:
                logging.info('Registering Zeroconf service')

        zeroconf_sdRef = pybonjour.DNSServiceRegister(
            name = "SABnzbd on " + gethostname() ,
            regtype = '_http._tcp',
            port = int(cfg['misc']['port']),
            txtRecord = pybonjour.TXTRecord({'path': '/sabnzbd/'}),
            callBack = zeroconf_callback)

        pybonjour.DNSServiceProcessResult(zeroconf_sdRef)
####End Zeroconf patch##########################################################

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: February 26th, 2009, 5:14 am
by rAf
Good idea !
Thanks

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: June 1st, 2009, 2:47 am
by sander
I just found a zeroconf / bonjour  / avahi for Firefox:  http://andrew.tj.id.au/projects/bonjourfoxy/

I tested it on Ubuntu 9.04, and Firefox now sees the  zeroconf / bonjour  / avahi  'shares' / 'services' on my LAN.

Now let's hope the zeroconf feature itself gets into SABnzbd...

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: June 4th, 2009, 4:13 pm
by sander
Included is a screendump of my Firefox with the BonjourFoxy plugin, automagically seeing SABnzbd 0.4.11 patched with the bonjour patch and bonjour*.py copied into utils.

BTW: the bonjour service should only be announced if the Listen Host is 0.0.0.0 (and not if it's limited to localhost).

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: June 16th, 2009, 3:20 pm
by sander
I've patched the bonjour patch to make it work in SAB 0.5.0 Alpha4:

- log if succesfully imported
- port is filled with the value of 'cherryport'; the old way resulted in an error
- inserted "Bonjour" in the comment lines
- put it right after starting up the cherrypy server (maybe that's not new)

After copying pybonjour.py to SABnzbd-0.5.0Alpha4/sabnzbd/utils/pybonjour.py everything is OK; SABnzbd is seen by BonjourFoxy.

Tested on Ubuntu 9.04

Still to be done: before announcing the service, the patch should check whether the listening host is filled with 0.0.0.0 or [::] and thus really listening on the LAN interface.

Please give feedback.

Code: Select all

    # Wait for server to become ready
    cherrypy.engine.wait(cherrypy.process.wspbus.states.STARTED)


####Start Bonjour Zeroconf patch########################################################

    try:
        from sabnzbd.utils import pybonjour
        logging.info('Zeroconf service succesfully imported')

    except OSError:
        logging.info('Zeroconf service could not be registered')
    else:


	from socket import gethostname

        def zeroconf_callback(sdRef, flags, errorCode, name, regtype, domain):
            if errorCode == pybonjour.kDNSServiceErr_NoError:
                logging.info('Registering Zeroconf service')

        zeroconf_sdRef = pybonjour.DNSServiceRegister(
            name = "SABnzbd on " + gethostname() ,
            regtype = '_http._tcp',
# error           port = int(cfg['misc']['port']),
# OK            port = int(8080),
            port = int(cherryport),
            txtRecord = pybonjour.TXTRecord({'path': '/sabnzbd/'}),
            callBack = zeroconf_callback)

        pybonjour.DNSServiceProcessResult(zeroconf_sdRef)

####End Bonjour Zeroconf patch##########################################################


    if enable_https and https_port:
        launch_a_browser("https://%s:%s/sabnzbd" % (browserhost, https_port))
    else:
        launch_a_browser("http://%s:%s/sabnzbd" % (browserhost, cherryport))



Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: June 16th, 2009, 3:51 pm
by sander
I've now implemented the check for "listening on LAN'. See patch and resulting logging below

To be done (I guess): first check for "listening on LAN", and after that starting the "import pybonjour"

Feedback very welcome.

Code: Select all

    # Wait for server to become ready
    cherrypy.engine.wait(cherrypy.process.wspbus.states.STARTED)


####Start Bonjour Zeroconf patch########################################################

    try:
        from sabnzbd.utils import pybonjour
        logging.info('Zeroconf service succesfully imported')

    except OSError:
        logging.info('Zeroconf service could not be registered')
    else:

        logging.info('cherryhost is ' + cherryhost)
        if cherryhost == '0.0.0.0' or cherryhost in ('::','[::]'):
		logging.info('SABnzbd is configured to listen on LAN interface, so start Bonjour Zeroconf')

		from socket import gethostname
	
	        def zeroconf_callback(sdRef, flags, errorCode, name, regtype, domain):
	            if errorCode == pybonjour.kDNSServiceErr_NoError:
	                logging.info('Registering Zeroconf service')

	        zeroconf_sdRef = pybonjour.DNSServiceRegister(
	            name = "SABnzbd on " + gethostname() ,
	            regtype = '_http._tcp',
# error      	    port = int(cfg['misc']['port']),
# OK           	    port = int(8080),
	            port = int(cherryport),
	            txtRecord = pybonjour.TXTRecord({'path': '/sabnzbd/'}),
	            callBack = zeroconf_callback)

	        pybonjour.DNSServiceProcessResult(zeroconf_sdRef)
	else:
		logging.info('SABnzbd is not configured to listen on a LAN interface, so not starting Bonjour Zeroconf')

####End Bonjour Zeroconf patch##########################################################


    if enable_https and https_port:
        launch_a_browser("https://%s:%s/sabnzbd" % (browserhost, https_port))
    else:
        launch_a_browser("http://%s:%s/sabnzbd" % (browserhost, cherryport))

Output with host=[::] (or 0.0.0.0)

Code: Select all

2009-06-16 20:40:07,475::INFO::[_cplogging:55] [16/Jun/2009:20:40:07] ENGINE Bus STARTED
2009-06-16 20:40:07,499::INFO::[SABnzbd:1119] Zeroconf service succesfully imported
2009-06-16 20:40:07,499::INFO::[SABnzbd:1125] cherryhost is ::
2009-06-16 20:40:07,500::INFO::[SABnzbd:1127] SABnzbd is configured to listen on LAN interface, so start Bonjour Zeroconf
2009-06-16 20:40:07,507::INFO::[misc:425] Lauching browser with http://localhost:8080/sabnzbd
Output with host=localhost:

Code: Select all


2009-06-16 20:41:03,155::INFO::[_cplogging:55] [16/Jun/2009:20:41:03] ENGINE Bus STARTED
2009-06-16 20:41:03,190::INFO::[SABnzbd:1119] Zeroconf service succesfully imported
2009-06-16 20:41:03,191::INFO::[SABnzbd:1125] cherryhost is localhost
2009-06-16 20:41:03,191::INFO::[SABnzbd:1146] SABnzbd is not configured to listen on a LAN interface, so not starting Bonjour Zeroconf
2009-06-16 20:41:03,192::INFO::[misc:425] Lauching browser with http://localhost:8080/sabnzbd


Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: June 29th, 2009, 5:25 am
by rAf
Thanks for sharing, very useful.

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: June 29th, 2009, 6:32 am
by sander
rAf wrote: Thanks for sharing, very useful.
Thanks! Does it work on your OS X?

How can I get this code into the source of SAB so that others can benefit from it?

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: June 29th, 2009, 7:29 am
by rAf
Not tested your last patch with 0.5.0 but the previous one with 0.4.x worked.
I'll try to test the new one. I'll have to discuss with the team to integrate this patch in trunk.

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: June 29th, 2009, 8:39 am
by sander
FYI: I've now put the bonjour-patch after the launch_a_browser call; that way the browser startup & user don't have to wait for the bonjour registering.

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: June 29th, 2009, 12:14 pm
by rAf
Could you put a link of a tar.gz or zip of your source code including the patch ?
I'll simply want to build an OSX binary to test.

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: June 29th, 2009, 2:09 pm
by sander
rAf wrote: Could you put a link of a tar.gz or zip of your source code including the patch ?
I'll simply want to build an OSX binary to test.
I've uploaded a 2 MB zip here: http://drop.io/imrtzin

Hopefully this method works.

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: July 8th, 2009, 11:18 am
by rAf
Sorry for the delay.
I've tested and it's working on OSX.
I only have an issue, don't know if it's a network config problem...
In safari, I see "SABnzbd on mbp.private.lan" on Bonjour bookmarks, but when i click on it, the url opened is http://mbp.local.:8080/sabnzbd and it don't work...

Theses url work on my browser : http://mbp.private.lan:8080 and http://mbp:8080.

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: July 9th, 2009, 12:57 am
by sander
rAf wrote: Sorry for the delay.
I've tested and it's working on OSX.
I only have an issue, don't know if it's a network config problem...
In safari, I see "SABnzbd on mbp.private.lan" on Bonjour bookmarks, but when i click on it, the url opened is http://mbp.local.:8080/sabnzbd and it don't work...
So clicking on it does NOT work? :-(

"SABnzbd on mbp.private.lan" contains just a name generated by "gethostname()". I introduced that name as a help for identification by an user. The system will not use it.

The URL http://mbp.local.:8080/sabnzbd that's tried, is exactly what I would expect: .local. , as .local. is the top level domain for zeroconf stuff, with the SAB specifics filled out. So if that does not work, I'm surprised.

Question: can you "ping mbp.local."? Please include the dot at the end



FYI: http://en.wikipedia.org/wiki/.local says
If a computer running Mac OS X is not assigned a domain name by the DNS server, it will identify itself as hostname.local. The host name can be set in the Sharing Preference Pane.

rAf wrote: Theses url work on my browser : http://mbp.private.lan:8080 and http://mbp:8080.
AFAIK those are not zeroconf names.

Re: Zeroconf (Bonjour/Avahi) support for HTTP

Posted: May 17th, 2011, 12:07 pm
by fkmtc
Hi all,

I was wondering the status of that "Bonjour" support SABnzbd+... I would love to have that feature in SABnzbd+ !!

I'm the developer of SABMobile and would make very good use of that "auto discovering" of sab :)

Thanks,
Jérôme