Beispiel #1
0
def launch_a_browser(url, force=False):
    """ Launch a browser pointing to the URL """
    if not force and not cfg.autobrowser() or sabnzbd.DAEMON:
        return

    if '::1' in url and '[::1]' not in url:
        # Get around idiosyncrasy in Python runtime
        url = url.replace('::1', '[::1]')

    if cfg.enable_https() and not cfg.https_port.get_int():
        # Must use https, because http is not available
        url = url.replace('http:', 'https:')

    if 'localhost' in url and not cfg.ipv6_hosting():
        url = url.replace('localhost', '127.0.0.1')
    logging.info("Launching browser with %s", url)
    try:
        if url and not url.startswith('http'):
            url = 'file:///%s' % url
        if webbrowser:
            webbrowser.open(url, 2, 1)
        else:
            logging.info(
                'Not showing panic message in webbrowser, no support found')
    except:
        logging.warning(T('Cannot launch the browser, probably not found'))
        logging.info("Traceback: ", exc_info=True)
Beispiel #2
0
    def two(self, **kwargs):
        """ Accept server and show internal web server page """
        # Save server details
        if kwargs:
            kwargs['enable'] = 1
            sabnzbd.interface.handle_server(kwargs)

        # Create web server page
        info = self.info.copy()
        info['num'] = '» %s' % T('Step Two')
        info['number'] = 2
        info['T'] = Ttemplate

        host = cfg.cherryhost()
        info['host'] = host
        # Allow special operation if host is not one of the defaults
        if host not in ('localhost','0.0.0.0'):
            info['custom_host'] = True
        else:
            info['custom_host'] = False

        info['have_ssl'] = bool(sabnzbd.newswrapper.HAVE_SSL)
        info['enable_https'] = cfg.enable_https()
        info['autobrowser'] = cfg.autobrowser()
        info['web_user'] = cfg.username()
        info['web_pass'] = cfg.password()

        template = Template(file=os.path.join(self.__web_dir, 'two.html'),
                            searchList=[info], compilerSettings=sabnzbd.interface.DIRECTIVES)
        return template.respond()
Beispiel #3
0
    def two(self, **kwargs):
        """ Accept server and show internal web server page """
        # Save server details
        if kwargs:
            kwargs['enable'] = 1
            sabnzbd.interface.handle_server(kwargs)

        # Create web server page
        info = self.info.copy()
        info['num'] = '» %s' % T('Step Two')
        info['number'] = 2
        info['T'] = Ttemplate

        host = cfg.cherryhost()
        info['host'] = host
        # Allow special operation if host is not one of the defaults
        if host not in ('localhost', '0.0.0.0'):
            info['custom_host'] = True
        else:
            info['custom_host'] = False

        info['have_ssl'] = bool(sabnzbd.newswrapper.HAVE_SSL)
        info['enable_https'] = cfg.enable_https()
        info['autobrowser'] = cfg.autobrowser()
        info['web_user'] = cfg.username()
        info['web_pass'] = cfg.password()

        template = Template(file=os.path.join(self.__web_dir, 'two.html'),
                            searchList=[info],
                            compilerSettings=sabnzbd.interface.DIRECTIVES)
        return template.respond()
Beispiel #4
0
def launch_a_browser(url, force=False):
    """ Launch a browser pointing to the URL """
    if not force and not cfg.autobrowser() or sabnzbd.DAEMON:
        return

    if "::1" in url and "[::1]" not in url:
        # Get around idiosyncrasy in Python runtime
        url = url.replace("::1", "[::1]")

    if cfg.enable_https() and not cfg.https_port.get_int():
        # Must use https, because http is not available
        url = url.replace("http:", "https:")

    if "localhost" in url and not cfg.ipv6_hosting():
        url = url.replace("localhost", "127.0.0.1")
    logging.info("Launching browser with %s", url)
    try:
        if url and not url.startswith("http"):
            url = "file:///%s" % url
        if webbrowser:
            webbrowser.open(url, 2, 1)
        else:
            logging.info("Not showing panic message in webbrowser, no support found")
    except:
        logging.warning(T("Cannot launch the browser, probably not found"))
        logging.info("Traceback: ", exc_info=True)
Beispiel #5
0
def launch_a_browser(url, force=False):
    """ Launch a browser pointing to the URL """
    if not force and not cfg.autobrowser() or sabnzbd.DAEMON:
        return

    if '::1' in url and '[::1]' not in url:
        # Get around idiosyncrasy in Python runtime
        url = url.replace('::1', '[::1]')

    if cfg.enable_https() and not cfg.https_port.get_int():
        # Must use https, because http is not available
        url = url.replace('http:', 'https:')

    if 'localhost' in url and not cfg.ipv6_hosting():
        url = url.replace('localhost', '127.0.0.1')
    logging.info("Launching browser with %s", url)
    try:
        if url and not url.startswith('http'):
            url = 'file:///%s' % url
        if webbrowser:
            webbrowser.open(url, 2, 1)
        else:
            logging.info('Not showing panic message in webbrowser, no support found')
    except:
        logging.warning(T('Cannot launch the browser, probably not found'))
        logging.info("Traceback: ", exc_info=True)
Beispiel #6
0
def set_bonjour(host=None, port=None):
    """ Publish host/port combo through Bonjour """
    global _HOST_PORT, _BONJOUR_OBJECT

    if not _HAVE_BONJOUR or not cfg.enable_bonjour():
        logging.info('No Bonjour/ZeroConfig support installed')
        return

    if host is None and port is None:
        host, port = _HOST_PORT
    else:
        _HOST_PORT = (host, port)

    scope = pybonjour.kDNSServiceInterfaceIndexAny
    zhost = None
    domain = None

    if match_str(host, ('localhost', '127.0.', '::1')):
        logging.info('Bonjour/ZeroConfig does not support "localhost"')
        # All implementations fail to implement "localhost" properly
        # A false address is published even when scope==kDNSServiceInterfaceIndexLocalOnly
        return

    name = hostname()
    if '.local' in name:
        suffix = ''
    else:
        suffix = '.local'

    logging.debug('Try to publish in Bonjour as "%s" (%s:%s)', name, host,
                  port)
    try:
        refObject = pybonjour.DNSServiceRegister(
            interfaceIndex=scope,
            name='SABnzbd on %s:%s' % (name, port),
            regtype='_http._tcp',
            domain=domain,
            host=zhost,
            port=int(port),
            txtRecord=pybonjour.TXTRecord({
                'path': cfg.url_base(),
                'https': cfg.enable_https()
            }),
            callBack=_zeroconf_callback)
    except sabnzbd.utils.pybonjour.BonjourError as e:
        _BONJOUR_OBJECT = None
        logging.debug('Failed to start Bonjour service: %s', str(e))
    except:
        _BONJOUR_OBJECT = None
        logging.debug(
            'Failed to start Bonjour service due to non-pybonjour related problem',
            exc_info=True)
    else:
        Thread(target=_bonjour_server, args=(refObject, ))
        _BONJOUR_OBJECT = refObject
        logging.debug('Successfully started Bonjour service')
Beispiel #7
0
def set_bonjour(host=None, port=None):
    """ Publish host/port combo through Bonjour """
    global _HOST_PORT, _BONJOUR_OBJECT

    if not _HAVE_BONJOUR or not cfg.enable_broadcast():
        logging.info("No bonjour/zeroconf support installed")
        return

    if host is None and port is None:
        host, port = _HOST_PORT
    else:
        _HOST_PORT = (host, port)

    scope = pybonjour.kDNSServiceInterfaceIndexAny
    zhost = None
    domain = None

    if is_localhost(host):
        logging.info("Cannot setup bonjour/zeroconf for localhost (%s)", host)
        # All implementations fail to implement "localhost" properly
        # A false address is published even when scope==kDNSServiceInterfaceIndexLocalOnly
        return

    name = socket.gethostname()
    logging.debug('Try to publish in Bonjour as "%s" (%s:%s)', name, host,
                  port)
    try:
        refObject = pybonjour.DNSServiceRegister(
            interfaceIndex=scope,
            name="SABnzbd on %s:%s" % (name, port),
            regtype="_http._tcp",
            domain=domain,
            host=zhost,
            port=int(port),
            txtRecord=pybonjour.TXTRecord({
                "path": cfg.url_base(),
                "https": cfg.enable_https()
            }),
            callBack=_zeroconf_callback,
        )
    except sabnzbd.utils.pybonjour.BonjourError as e:
        _BONJOUR_OBJECT = None
        logging.debug("Failed to start Bonjour service: %s", str(e))
    except:
        _BONJOUR_OBJECT = None
        logging.debug(
            "Failed to start Bonjour service due to non-pybonjour related problem",
            exc_info=True)
    else:
        Thread(target=_bonjour_server, args=(refObject, ))
        _BONJOUR_OBJECT = refObject
        logging.debug("Successfully started Bonjour service")
Beispiel #8
0
def launch_a_browser(url, force=False):
    """Launch a browser pointing to the URL
    """
    if not force and not cfg.autobrowser() or sabnzbd.DAEMON:
        return

    if cfg.enable_https() and not cfg.https_port.get_int():
        # Must use https, because http is not available
        url = url.replace('http:', 'https:')

    logging.info("Lauching browser with %s", url)
    try:
        webbrowser.open(url, 2, 1)
    except:
        logging.warning(Ta('Cannot launch the browser, probably not found'))
        logging.info("Traceback: ", exc_info = True)
Beispiel #9
0
def set_bonjour(host=None, port=None):
    """ Publish host/port combo through Bonjour """
    global _HOST_PORT, _BONJOUR_OBJECT

    if not _HAVE_BONJOUR or not cfg.enable_bonjour():
        logging.info('No Bonjour/ZeroConfig support installed')
        return

    if host is None and port is None:
        host, port = _HOST_PORT
    else:
        _HOST_PORT = (host, port)

    scope = pybonjour.kDNSServiceInterfaceIndexAny
    zhost = None
    domain = None

    if match_str(host, ('localhost', '127.0.', '::1')):
        logging.info('Bonjour/ZeroConfig does not support "localhost"')
        # All implementations fail to implement "localhost" properly
        # A false address is published even when scope==kDNSServiceInterfaceIndexLocalOnly
        return

    name = hostname()
    logging.debug('Try to publish in Bonjour as "%s" (%s:%s)', name, host, port)
    try:
        refObject = pybonjour.DNSServiceRegister(
            interfaceIndex=scope,
            name='SABnzbd on %s:%s' % (name, port),
            regtype='_http._tcp',
            domain=domain,
            host=zhost,
            port=int(port),
            txtRecord=pybonjour.TXTRecord({'path': cfg.url_base(),
                                           'https': cfg.enable_https()}),
            callBack=_zeroconf_callback)
    except sabnzbd.utils.pybonjour.BonjourError as e:
        _BONJOUR_OBJECT = None
        logging.debug('Failed to start Bonjour service: %s', str(e))
    except:
        _BONJOUR_OBJECT = None
        logging.debug('Failed to start Bonjour service due to non-pybonjour related problem', exc_info=True)
    else:
        Thread(target=_bonjour_server, args=(refObject,))
        _BONJOUR_OBJECT = refObject
        logging.debug('Successfully started Bonjour service')
Beispiel #10
0
def launch_a_browser(url, force=False):
    """Launch a browser pointing to the URL
    """
    if not force and not cfg.autobrowser() or sabnzbd.DAEMON:
        return

    if "::1" in url and not "[::1]" in url:
        # Get around ideosyncrasy in Python runtime
        url = url.replace("::1", "[::1]")

    if cfg.enable_https() and not cfg.https_port.get_int():
        # Must use https, because http is not available
        url = url.replace("http:", "https:")

    logging.info("Lauching browser with %s", url)
    try:
        if url and not url.startswith("http"):
            url = "file:///%s" % url
        webbrowser.open(url, 2, 1)
    except:
        logging.warning(Ta("Cannot launch the browser, probably not found"))
        logging.info("Traceback: ", exc_info=True)
Beispiel #11
0
    def get_access_info(self):
        ''' Build up a list of url's that sabnzbd can be accessed from '''
        # Access_url is used to provide the user a link to sabnzbd depending on the host
        access_uri = 'localhost'
        cherryhost = cfg.cherryhost()

        if cherryhost == '0.0.0.0':
            import socket
            host = socket.gethostname()
            socks = [host]
            # Grab a list of all ips for the hostname
            try:
                addresses = socket.getaddrinfo(host, None)
            except:
                addresses = []
            for addr in addresses:
                address = addr[4][0]
                # Filter out ipv6 addresses (should not be allowed)
                if ':' not in address and address not in socks:
                    socks.append(address)
            if cherrypy.request.headers.has_key('host'):
                host = cherrypy.request.headers['host']
                host = host.rsplit(':')[0]
                access_uri = host
                socks.insert(0, host)
            else:
                socks.insert(0, 'localhost')

        elif cherryhost == '::':
            import socket
            host = socket.gethostname()
            socks = [host]
            # Grab a list of all ips for the hostname
            addresses = socket.getaddrinfo(host, None)
            for addr in addresses:
                address = addr[4][0]
                # Only ipv6 addresses will work
                if ':' in address:
                    address = '[%s]' % address
                    if address not in socks:
                        socks.append(address)
            if cherrypy.request.headers.has_key('host'):
                host = cherrypy.request.headers['host']
                host = host.rsplit(':')[0]
                access_uri = host
                socks.insert(0, host)
            else:
                socks.insert(0, 'localhost')

        elif not cherryhost:
            import socket
            socks = [socket.gethostname()]
            access_uri = socket.gethostname()
        else:
            socks = [cherryhost]
            access_uri = cherryhost

        urls = []
        for sock in socks:
            if sock:
                if cfg.enable_https():
                    url = 'https://%s:%s/sabnzbd/' % (sock, cfg.https_port())
                else:
                    url = 'http://%s:%s/sabnzbd/' % (sock, cfg.cherryport())

                urls.append(url)

        if cfg.enable_https():
            access_url = 'https://%s:%s/sabnzbd/' % (access_uri, cfg.https_port())
        else:
            access_url = 'http://%s:%s/sabnzbd/' % (access_uri, cfg.cherryport())

        return access_url, urls
Beispiel #12
0
    def get_access_info(self):
        ''' Build up a list of url's that sabnzbd can be accessed from '''
        # Access_url is used to provide the user a link to sabnzbd depending on the host
        access_uri = 'localhost'
        cherryhost = cfg.cherryhost()

        if cherryhost == '0.0.0.0':
            import socket
            host = socket.gethostname()
            socks = [host]
            # Grab a list of all ips for the hostname
            try:
                addresses = socket.getaddrinfo(host, None)
            except:
                addresses = []
            for addr in addresses:
                address = addr[4][0]
                # Filter out ipv6 addresses (should not be allowed)
                if ':' not in address and address not in socks:
                    socks.append(address)
            if cherrypy.request.headers.has_key('host'):
                host = cherrypy.request.headers['host']
                host = host.rsplit(':')[0]
                access_uri = host
                socks.insert(0, host)
            else:
                socks.insert(0, 'localhost')

        elif cherryhost == '::':
            import socket
            host = socket.gethostname()
            socks = [host]
            # Grab a list of all ips for the hostname
            addresses = socket.getaddrinfo(host, None)
            for addr in addresses:
                address = addr[4][0]
                # Only ipv6 addresses will work
                if ':' in address:
                    address = '[%s]' % address
                    if address not in socks:
                        socks.append(address)
            if cherrypy.request.headers.has_key('host'):
                host = cherrypy.request.headers['host']
                host = host.rsplit(':')[0]
                access_uri = host
                socks.insert(0, host)
            else:
                socks.insert(0, 'localhost')

        elif not cherryhost:
            import socket
            socks = [socket.gethostname()]
            access_uri = socket.gethostname()
        else:
            socks = [cherryhost]
            access_uri = cherryhost

        urls = []
        for sock in socks:
            if sock:
                if cfg.enable_https():
                    url = 'https://%s:%s/sabnzbd/' % (sock, cfg.https_port())
                else:
                    url = 'http://%s:%s/sabnzbd/' % (sock, cfg.cherryport())

                urls.append(url)

        if cfg.enable_https():
            access_url = 'https://%s:%s/sabnzbd/' % (access_uri,
                                                     cfg.https_port())
        else:
            access_url = 'http://%s:%s/sabnzbd/' % (access_uri,
                                                    cfg.cherryport())

        return access_url, urls