From 4f43349dee7006312acf69b3f8dca6f8021386e4 Mon Sep 17 00:00:00 2001 From: Zwooosh Date: Tue, 13 May 2014 11:58:27 +0200 Subject: [PATCH] Don't add portnumber when restarting with reverse proxy enabled --- SickBeard.py | 9 ++++---- .../interfaces/default/restart_bare.tmpl | 3 +++ gui/slick/js/restart.js | 23 ++++++++++++------- sickbeard/webserve.py | 6 +++-- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/SickBeard.py b/SickBeard.py index c892458f..aa01b655 100755 --- a/SickBeard.py +++ b/SickBeard.py @@ -55,7 +55,7 @@ from sickbeard import db from sickbeard.tv import TVShow from sickbeard import logger from sickbeard.version import SICKBEARD_VERSION -from sickbeard.databases.mainDB import MIN_DB_VERSION +from sickbeard.databases.mainDB import MIN_DB_VERSION from sickbeard.databases.mainDB import MAX_DB_VERSION from sickbeard.webserveInit import initWebServer @@ -263,15 +263,15 @@ def main(): sickbeard.CFG = ConfigObj(sickbeard.CONFIG_FILE) - CUR_DB_VERSION = db.DBConnection().checkDBVersion() + CUR_DB_VERSION = db.DBConnection().checkDBVersion() if CUR_DB_VERSION > 0: if CUR_DB_VERSION < MIN_DB_VERSION: raise SystemExit("Your database version (" + str(db.DBConnection().checkDBVersion()) + ") is too old to migrate from with this version of Sick Beard (" + str(MIN_DB_VERSION) + ").\n" + \ "Upgrade using a previous version of SB first, or start with no database file to begin fresh.") if CUR_DB_VERSION > MAX_DB_VERSION: raise SystemExit("Your database version (" + str(db.DBConnection().checkDBVersion()) + ") has been incremented past what this version of Sick Beard supports (" + str(MAX_DB_VERSION) + ").\n" + \ - "If you have used other forks of SB, your database may be unusable due to their modifications.") - + "If you have used other forks of SB, your database may be unusable due to their modifications.") + # Initialize the config and our threads sickbeard.initialize(consoleLogging=consoleLogging) @@ -314,6 +314,7 @@ def main(): 'username': sickbeard.WEB_USERNAME, 'password': sickbeard.WEB_PASSWORD, 'enable_https': sickbeard.ENABLE_HTTPS, + 'handle_reverse_proxy': sickbeard.HANDLE_REVERSE_PROXY, 'https_cert': sickbeard.HTTPS_CERT, 'https_key': sickbeard.HTTPS_KEY, }) diff --git a/gui/slick/interfaces/default/restart_bare.tmpl b/gui/slick/interfaces/default/restart_bare.tmpl index 70de6fca..d5a79076 100644 --- a/gui/slick/interfaces/default/restart_bare.tmpl +++ b/gui/slick/interfaces/default/restart_bare.tmpl @@ -4,14 +4,17 @@ #set curSBHost = $sbHost #set curSBHttpPort = $sbHttpPort #set curSBHttpsEnabled = $sbHttpsEnabled + #set curSBHandleReverseProxy = $sbHandleReverseProxy #except NameMapper.NotFound: #set curSBHost = "localhost" #set curSBHttpPort = $sickbeard.WEB_PORT #set curSBHttpsEnabled = "False" + #set curSBHandleReverseProxy = "False" #end try sbRoot = "$sbRoot"; sbHttpPort = "$curSBHttpPort"; sbHttpsEnabled = "$curSBHttpsEnabled"; +sbHandleReverseProxy = "$curSBHandleReverseProxy"; sbHost = "$curSBHost"; //--> diff --git a/gui/slick/js/restart.js b/gui/slick/js/restart.js index 572e4c3f..b98b0a8d 100644 --- a/gui/slick/js/restart.js +++ b/gui/slick/js/restart.js @@ -1,7 +1,14 @@ -if (sbHttpsEnabled != "False" && sbHttpsEnabled != 0) - var sb_base_url = 'https://'+sbHost+':'+sbHttpPort+sbRoot; +if (sbHandleReverseProxy != "False" && sbHandleReverseProxy != 0) + // Don't add the port to the url if using reverse proxy + if (sbHttpsEnabled != "False" && sbHttpsEnabled != 0) + var sb_base_url = 'https://'+sbHost+sbRoot; + else + var sb_base_url = 'http://'+sbHost+sbRoot; else - var sb_base_url = 'http://'+sbHost+':'+sbHttpPort+sbRoot; + if (sbHttpsEnabled != "False" && sbHttpsEnabled != 0) + var sb_base_url = 'https://'+sbHost+':'+sbHttpPort+sbRoot; + else + var sb_base_url = 'http://'+sbHost+':'+sbHttpPort+sbRoot; var base_url = window.location.protocol+'//'+window.location.host+sbRoot; var is_alive_url = sbRoot+'/home/is_alive'; @@ -12,7 +19,7 @@ var num_restart_waits = 0; function is_alive() { timeout_id = 0; $.get(is_alive_url, function(data) { - + // if it's still initalizing then just wait and try again if (data.msg == 'nope') { $('#shut_down_loading').hide(); @@ -36,11 +43,11 @@ function is_alive() { }, 'jsonp'); } -$(document).ready(function() -{ +$(document).ready(function() +{ is_alive(); - + $(document).ajaxError(function(e, jqxhr, settings, exception) { num_restart_waits += 1; @@ -49,7 +56,7 @@ $(document).ready(function() $('#restart_message').show(); is_alive_url = sb_base_url+'/home/is_alive'; - // if https is enabled or you are currently on https and the port or protocol changed just wait 5 seconds then redirect. + // if https is enabled or you are currently on https and the port or protocol changed just wait 5 seconds then redirect. // This is because the ajax will fail if the cert is untrusted or the the http ajax requst from https will fail because of mixed content error. if ((sbHttpsEnabled != "False" && sbHttpsEnabled != 0) || window.location.protocol == "https:") { if (base_url != sb_base_url) { diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 4ca85c3a..5ce75cdb 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -95,6 +95,8 @@ class PageTemplate(Template): self.sbHttpPort = sickbeard.WEB_PORT self.sbHttpsPort = sickbeard.WEB_PORT self.sbHttpsEnabled = sickbeard.ENABLE_HTTPS + self.sbHandleReverseProxy = sickbeard.HANDLE_REVERSE_PROXY + if cherrypy.request.headers['Host'][0] == '[': self.sbHost = re.match("^\[.*\]", cherrypy.request.headers['Host'], re.X | re.M | re.S).group(0) else: @@ -941,7 +943,7 @@ class ConfigGeneral: sickbeard.SUBTITLES_DEFAULT = config.checkbox_to_value(subtitles) sickbeard.save_config() - + @cherrypy.expose def generateKey(self): """ Return a new randomized API_KEY @@ -1596,7 +1598,7 @@ class ConfigProviders: sickbeard.KAT_TRUSTED = config.checkbox_to_value(kat_trusted) sickbeard.KAT_RATIO = config.to_int(kat_ratio) sickbeard.KAT_VERIFIED = config.checkbox_to_value(kat_verified) - + sickbeard.PUBLICHD_RATIO = publichd_ratio sickbeard.TORRENTDAY_USERNAME = torrentday_username.strip()