Browse Source

Fix using multiple hostnames with config General/Interface/"Allowed browser hostnames"

Add config General/Interface/"Allow IP use for connections". The option is enabled by default and does not change existing behaviour to allow a browser to connect to an instance using server IP address.
Change add WrongHostWebHandler to handle a bad hostname request with a 404 response.
Fix Shazbat torrent provider backlog issue.
tags/release_0.20.12^2
JackDandy 5 years ago
parent
commit
27e8679cfc
  1. 10
      CHANGES.md
  2. 10
      gui/slick/interfaces/default/config_general.tmpl
  3. 5
      sickbeard/__init__.py
  4. 10
      sickbeard/helpers.py
  5. 4
      sickbeard/providers/shazbat.py
  6. 13
      sickbeard/webserve.py
  7. 4
      sickbeard/webserveInit.py

10
CHANGES.md

@ -1,4 +1,12 @@
### 0.20.11 (2019-11-30 02:45:00 UTC)
### 0.20.12 (2019-12-09 16:30:00 UTC)
* Fix using multiple hostnames with config General/Interface/"Allowed browser hostnames"
* Add config General/Interface/"Allow IP use for connections"
* Change add WrongHostWebHandler to handle a bad hostname request with a 404 response
* Fix Shazbat torrent provider backlog issue
### 0.20.11 (2019-11-30 02:45:00 UTC)
* Remove redundant tvdb_api v1
* Change update Emby api

10
gui/slick/interfaces/default/config_general.tmpl

@ -605,6 +605,16 @@
</div>
<div class="field-pair">
<label for="allow_anyip">
<span class="component-title">Allow IP use for connections</span>
<span class="component-desc">
<input type="checkbox" name="allow_anyip""#echo ('', $checked)[$sg_var('ALLOW_ANYIP')]#>
<p>disable to only accept "Allowed browser hostnames" for connections</p>
</span>
</label>
</div>
<div class="field-pair">
<label for="allowed_hosts">
<span class="component-title">Allowed browser hostnames</span>
<span class="component-desc">

5
sickbeard/__init__.py

@ -138,6 +138,7 @@ WEB_IPV64 = 0
HANDLE_REVERSE_PROXY = False
SEND_SECURITY_HEADERS = True
ALLOWED_HOSTS = None
ALLOW_ANYIP = True
PROXY_SETTING = None
PROXY_INDEXERS = True
@ -621,7 +622,7 @@ def init_stage_1(console_logging):
DATE_PRESET, TIME_PRESET, TIME_PRESET_W_SECONDS, TIMEZONE_DISPLAY, \
WEB_USERNAME, WEB_PASSWORD, CALENDAR_UNPROTECTED, USE_API, API_KEY, WEB_PORT, WEB_LOG, \
ENABLE_HTTPS, HTTPS_CERT, HTTPS_KEY, WEB_IPV6, WEB_IPV64, HANDLE_REVERSE_PROXY, \
SEND_SECURITY_HEADERS, ALLOWED_HOSTS
SEND_SECURITY_HEADERS, ALLOWED_HOSTS, ALLOW_ANYIP
# Gen Config/Advanced
global BRANCH, CUR_COMMIT_BRANCH, GIT_REMOTE, CUR_COMMIT_HASH, GIT_PATH, CPU_PRESET, ANON_REDIRECT, \
ENCRYPTION_VERSION, PROXY_SETTING, PROXY_INDEXERS, FILE_LOGGING_PRESET
@ -826,6 +827,7 @@ def init_stage_1(console_logging):
HANDLE_REVERSE_PROXY = bool(check_setting_int(CFG, 'General', 'handle_reverse_proxy', 0))
SEND_SECURITY_HEADERS = bool(check_setting_int(CFG, 'General', 'send_security_headers', 1))
ALLOWED_HOSTS = check_setting_str(CFG, 'General', 'allowed_hosts', '')
ALLOW_ANYIP = bool(check_setting_int(CFG, 'General', 'allow_anyip', 1))
ROOT_DIRS = check_setting_str(CFG, 'General', 'root_dirs', '')
if not re.match(r'\d+\|[^|]+(?:\|[^|]+)*', ROOT_DIRS):
@ -1676,6 +1678,7 @@ def save_config():
new_config['General']['handle_reverse_proxy'] = int(HANDLE_REVERSE_PROXY)
new_config['General']['send_security_headers'] = int(SEND_SECURITY_HEADERS)
new_config['General']['allowed_hosts'] = ALLOWED_HOSTS
new_config['General']['allow_anyip'] = int(ALLOW_ANYIP)
new_config['General']['use_nzbs'] = int(USE_NZBS)
new_config['General']['use_torrents'] = int(USE_TORRENTS)
new_config['General']['nzb_method'] = NZB_METHOD

10
sickbeard/helpers.py

@ -1393,10 +1393,14 @@ def maybe_plural(number=1):
def re_valid_hostname(with_allowed=True):
this_host = socket.gethostname()
return re.compile(r'(?i)(%slocalhost|.*\.local|%s%s)$' % (
return re.compile(r'(?i)(%slocalhost|.*\.local%s%s)$' % (
(with_allowed
and '%s|' % (sickbeard.ALLOWED_HOSTS and re.escape(sickbeard.ALLOWED_HOSTS).replace(',', '|') or '.*')
or ''), bool(this_host) and ('%s|' % this_host) or '', valid_ipaddr_expr()))
and '%s|' % (sickbeard.ALLOWED_HOSTS
and '|'.join(re.escape(x.strip()) for x in sickbeard.ALLOWED_HOSTS.split(','))
or '.*')
or ''),
bool(this_host) and ('|%s' % this_host) or '',
sickbeard.ALLOW_ANYIP and ('|%s' % valid_ipaddr_expr()) or ''))
def valid_ipaddr_expr():

4
sickbeard/providers/shazbat.py

@ -98,9 +98,9 @@ class ShazbatProvider(generic.TorrentProvider):
raise generic.HaltParseException
with BS4Parser(html) as tbl:
tbl_rows = tbl.tbody.find_all('tr') or tbl.table.find_all('tr') or []
tbl_rows = tbl.tbody and tbl.tbody.find_all('tr') or tbl.table and tbl.table.find_all('tr')
if 2 > len(tbl_rows):
if 2 > len(tbl_rows or []):
raise generic.HaltParseException
head = None

13
sickbeard/webserve.py

@ -628,6 +628,16 @@ class IsAliveHandler(BaseHandler):
self.write(results)
class WrongHostWebHandler(BaseHandler):
def __init__(self, *arg, **kwargs):
super(BaseHandler, self).__init__(*arg, **kwargs)
self.lock = threading.Lock()
@gen.coroutine
def prepare(self):
self.send_error(404)
class LoadingWebHandler(BaseHandler):
def __init__(self, *arg, **kwargs):
super(BaseHandler, self).__init__(*arg, **kwargs)
@ -5919,7 +5929,7 @@ class ConfigGeneral(Config):
trash_remove_show=None, trash_rotate_logs=None, update_frequency=None, launch_browser=None, web_username=None,
use_api=None, api_key=None, indexer_default=None, timezone_display=None, cpu_preset=None, file_logging_preset=None,
web_password=None, version_notify=None, enable_https=None, https_cert=None, https_key=None,
handle_reverse_proxy=None, send_security_headers=None, allowed_hosts=None,
handle_reverse_proxy=None, send_security_headers=None, allowed_hosts=None, allow_anyip=None,
home_search_focus=None, display_freespace=None, sort_article=None, auto_update=None, notify_on_update=None,
proxy_setting=None, proxy_indexers=None, anon_redirect=None, git_path=None, git_remote=None, calendar_unprotected=None,
fuzzy_dating=None, trim_zero=None, date_preset=None, date_preset_na=None, time_preset=None,
@ -6021,6 +6031,7 @@ class ConfigGeneral(Config):
config.clean_hosts(allowed_hosts).split(',')))
if not hosts or self.request.host_name in hosts:
sickbeard.ALLOWED_HOSTS = hosts
sickbeard.ALLOW_ANYIP = config.checkbox_to_value(allow_anyip)
# Advanced
sickbeard.GIT_REMOTE = git_remote

4
sickbeard/webserveInit.py

@ -127,6 +127,8 @@ class WebServer(threading.Thread):
(r'%s(/?.*)' % self.options['web_root'], webserve.LoadingWebHandler),
])
self.app.add_handlers(r'.*', [(r'.*', webserve.WrongHostWebHandler)])
def _add_default_rules(self):
# webui login/logout handlers
self.app.add_handlers(self.re_host_pattern, [
@ -195,6 +197,8 @@ class WebServer(threading.Thread):
(r'%s(/?.*)' % self.options['web_root'], webserve.MainHandler),
])
self.app.add_handlers(r'.*', [(r'.*', webserve.WrongHostWebHandler)])
def run(self):
protocol, ssl_options = (('http', None),
('https', {'certfile': self.https_cert, 'keyfile': self.https_key}))[self.enable_https]

Loading…
Cancel
Save