From 1a4ba51dec9184bedf828f39885e5cc00cd516a1 Mon Sep 17 00:00:00 2001 From: Sander Date: Sat, 2 Jan 2021 16:49:55 +0100 Subject: [PATCH] SSDP logging and interval_timer (#1734) * SSDP: also log the User-Agent * SSDP: also log the User-Agent * SSDP: also log the User-Agent * SSDP: ssdp_broadcast_interval in seconds, configurable via GUI -> Specials * SSDP: ssdp_broadcast_interval as optional parater to the SSDP class * SSDP: less is more: start_ssdp(*args, **kwargs): * SSDP: less is more: start_ssdp(*args, **kwargs): * SSDP: handle if no User-Agent specified * SSDP: small change Co-authored-by: Safihre --- SABnzbd.py | 1 + sabnzbd/cfg.py | 2 ++ sabnzbd/interface.py | 9 +++++++-- sabnzbd/utils/ssdp.py | 9 +++++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/SABnzbd.py b/SABnzbd.py index 8e99c7b..73b64aa 100755 --- a/SABnzbd.py +++ b/SABnzbd.py @@ -1510,6 +1510,7 @@ def main(): "SABnzbd Team", "https://sabnzbd.org/", "SABnzbd %s" % sabnzbd.__version__, + ssdp_broadcast_interval=sabnzbd.cfg.ssdp_broadcast_interval(), ) # Have to keep this running, otherwise logging will terminate diff --git a/sabnzbd/cfg.py b/sabnzbd/cfg.py index 3aa3de9..be34c2d 100644 --- a/sabnzbd/cfg.py +++ b/sabnzbd/cfg.py @@ -298,6 +298,8 @@ url_base = OptionStr("misc", "url_base", "/sabnzbd", validation=validate_strip_r host_whitelist = OptionList("misc", "host_whitelist", validation=all_lowercase) max_url_retries = OptionNumber("misc", "max_url_retries", 10, 1) downloader_sleep_time = OptionNumber("misc", "downloader_sleep_time", 10, 0) +ssdp_broadcast_interval = OptionNumber("misc", "ssdp_broadcast_interval", 15, 1, 600) + ############################################################################## # Config - Notifications diff --git a/sabnzbd/interface.py b/sabnzbd/interface.py index 9c06628..95c88eb 100644 --- a/sabnzbd/interface.py +++ b/sabnzbd/interface.py @@ -471,8 +471,12 @@ class MainPage: @secured_expose def description_xml(self, **kwargs): - """ Keep web crawlers out """ - logging.debug("description.xml was requested by %s", cherrypy.request.remote.ip) + """ Provide the description.xml which was broadcast via SSDP """ + logging.debug( + "description.xml was requested from %s by %s", + cherrypy.request.remote.ip, + cherrypy.request.headers.get("User-Agent", "??"), + ) cherrypy.response.headers["Content-Type"] = "application/xml" return utob(sabnzbd.utils.ssdp.server_ssdp_xml()) @@ -1347,6 +1351,7 @@ SPECIAL_VALUE_LIST = ( "ipv6_servers", "selftest_host", "rating_host", + "ssdp_broadcast_interval", ) SPECIAL_LIST_LIST = ("rss_odd_titles", "quick_check_ext_ignore", "host_whitelist") diff --git a/sabnzbd/utils/ssdp.py b/sabnzbd/utils/ssdp.py index 04dd832..d7d8c16 100644 --- a/sabnzbd/utils/ssdp.py +++ b/sabnzbd/utils/ssdp.py @@ -44,7 +44,7 @@ from typing import Optional class SSDP(Thread): - def __init__(self, host, server_name, url, description, manufacturer, manufacturer_url, model): + def __init__(self, host, server_name, url, description, manufacturer, manufacturer_url, model, **kwargs): self.__host = host # Note: this is the LAN IP address! self.__server_name = server_name self.__url = url @@ -52,6 +52,7 @@ class SSDP(Thread): self.__manufacturer = manufacturer self.__manufacturer_url = manufacturer_url self.__model = model + self.__ssdp_broadcast_interval = kwargs.get("ssdp_broadcast_interval", 15) # optional, default 15 seconds self.__myhostname = socket.gethostname() # a steady uuid: stays the same as long as hostname and ip address stay the same: @@ -122,7 +123,7 @@ OPT: "http://schemas.upnp.org/upnp/1/0/"; ns=01 except: # probably no network pass - time.sleep(5) + time.sleep(self.__ssdp_broadcast_interval) def serve_xml(self): """Returns an XML-structure based on the information being @@ -139,9 +140,9 @@ __SSDP: Optional[SSDP] = None # Wrapper functions to be called by program -def start_ssdp(host, server_name, url, description, manufacturer, manufacturer_url, model): +def start_ssdp(*args, **kwargs): global __SSDP - __SSDP = SSDP(host, server_name, url, description, manufacturer, manufacturer_url, model) + __SSDP = SSDP(*args, **kwargs) __SSDP.start()