Page 2 of 2

Re: remote address redirects to https://localhost:9012/sabnz

Posted: September 3rd, 2012, 5:41 pm
by rolo
I have the same issue. Did anyone find a solution?

EDIT:
Found it!
In the settings, change the host address of 0.0.0.0 to the local IP of the host, i.e. 192.168.x.xx
Works like a charm :D

Re: remote address redirects to https://localhost:9012/sabnz

Posted: July 7th, 2014, 2:57 pm
by sander
FWIW: I ran into this problem again, so I did some more research:

With a wrong sub-URL, things go wrong: redirection to localhost. Example:

Code: Select all

sander@flappie:~$ curl http://192.168.1.101:8080/doesnotexist

<html>
    <head>
      <script type="text/javascript">
      <!--
      location.href = "http://localhost:8080/sabnzbd"
      //-->
      </script>
    </head>
    <body><br/></body>
</html>
                                                                                                                                                                                                                                                                                                                                sander@flappie:~$
The redirect (?) to localhost is not good. I searched the code, and it's in sabnzbd/panic.py

Code: Select all

def error_page_404(status, message, traceback, version):
    """ Custom handler for 404 error, redirect to main page """
    import cherrypy
    return r'''
<html>
    <head>
      <script type="text/javascript">
      <!--
      location.href = "%s"
      //-->
      </script>
    </head>
    <body><br/></body>
</html>
''' % cherrypy.wsgiserver.REDIRECT_URL
So far I found this in the code:

Code: Select all

$ grep -ir error_page.404 *
sabnzbd/panic.py:def error_page_404(status, message, traceback, version):
SABnzbd.py:                            'error_page.404': sabnzbd.panic.error_page_404

Code: Select all

$ grep -ir REDIRECT_URL *
cherrypy/wsgiserver/__init__.py:REDIRECT_URL = None  # Application can write it's HTTP-->HTTPS redirection URL here
cherrypy/wsgiserver/__init__.py:                if REDIRECT_URL:
cherrypy/wsgiserver/__init__.py:                    req.simple_response("301 Moved Permanently", REDIRECT_URL)
sabnzbd/panic.py:''' % cherrypy.wsgiserver.REDIRECT_URL
SABnzbd.py:    cherrypy.wsgiserver.REDIRECT_URL = browser_url
The corresponding code in SABnzbd.py is:

Code: Select all

    if enable_https:
        browser_url = "https://%s:%s/sabnzbd" % (browserhost, cherryport)
    else:
        browser_url = "http://%s:%s/sabnzbd" % (browserhost, cherryport)
    cherrypy.wsgiserver.REDIRECT_URL = browser_url
cherrypy.wsgiserver.REDIRECT_URL is: http://localhost:8080/sabnzbd

... and that's wrong; it should redirect to the FQDN that is used in the request itself, which can only be found at the moment the request is sent by the client. Not in the early startup phase of SABnzbd.

TBC

Re: remote address redirects to https://localhost:9012/sabnz

Posted: July 7th, 2014, 3:09 pm
by sander
Solved: Thanks to http://stackoverflow.com/questions/6941 ... 53#6941653, in panic.py I changed the last lines of code to:

Code: Select all

def error_page_404(status, message, traceback, version):
    """ Custom handler for 404 error, redirect to main page """
    import cherrypy
    return r'''
<html>
    <head>
      <script type="text/javascript">
      <!--
      var full = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '') + '/sabnzbd/' ;
      location.href = full
      //-->
      </script>
    </head>
    <body><br/></body>
</html>
'''
and that works! :)

http://192.168.1.111:8080/isnotthere now redirects to the correct URL http://192.168.1.111:8080/sabnzbd/

I don't know if the code in SABnzbd.py is still needed

Code: Select all

sander@flappie:~/git/sabnzbd$ grep -irn browser_url *
sabnzbd/sabtray.py:104:        launch_a_browser(sabnzbd.BROWSER_URL, True)
Binary file sabnzbd/__init__.pyo matches
sabnzbd/__init__.py:125:BROWSER_URL = None
sabnzbd/osxmenu.py:671:        launch_a_browser(sabnzbd.BROWSER_URL, True)
SABnzbd.py:1511:        browser_url = "https://%s:%s/sabnzbd" % (browserhost, cherryport)
SABnzbd.py:1513:        browser_url = "http://%s:%s/sabnzbd" % (browserhost, cherryport)
SABnzbd.py:1514:    cherrypy.wsgiserver.REDIRECT_URL = browser_url
SABnzbd.py:1516:    sabnzbd.BROWSER_URL = browser_url
SABnzbd.py:1518:        launch_a_browser(browser_url)
SABnzbd.py:1609:                if sabnzbd.cfg.web_watchdog() and not is_sabnzbd_running('%s/api?tickleme=1' % sabnzbd.BROWSER_URL, 120):
sander@flappie:~/git/sabnzbd$
It seems the line "cherrypy.wsgiserver.REDIRECT_URL = browser_url" might not be needed anymore. I'll test with that.

Re: remote address redirects to https://localhost:9012/sabnz

Posted: July 7th, 2014, 4:16 pm
by sander
It works, so pull request sent: https://github.com/sabnzbd/sabnzbd/pull/168