From 94b72df94e56a1d4daf7c9e9536a93ba94956cb6 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Mon, 2 May 2016 08:52:10 +0300 Subject: [PATCH 1/2] Add support for set service listen on defined address - new option - listen_host It is needed if we want hide service behind nginx/proxy. And set it listen on localhost. --- denyhosts-server.conf.example | 7 +++++++ denyhosts_server/config.py | 4 ++++ denyhosts_server/main.py | 10 +++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/denyhosts-server.conf.example b/denyhosts-server.conf.example index 66ab442..4a78c11 100644 --- a/denyhosts-server.conf.example +++ b/denyhosts-server.conf.example @@ -43,6 +43,9 @@ # denyhosts clients per sync. Default: 50 #max_reported_crackers: 50 +# TCP addr to listen on. Default: empty (all) +#listen_host: + # TCP port to listen on. Default: 9911 #listen_port: 9911 @@ -110,6 +113,10 @@ # Default: yes #resolve_hostnames: yes +# TCP addr to serve statistics. Can be the same a the listen_host in the +# [sync] section. Default: empty (all) +#listen_host: + # TCP port to serve statistics. Can be the same a the listen_port in the # [sync] section. Default: 9911 #listen_port: 9911 diff --git a/denyhosts_server/config.py b/denyhosts_server/config.py index 4695e75..7b89ecc 100644 --- a/denyhosts_server/config.py +++ b/denyhosts_server/config.py @@ -55,6 +55,7 @@ def read_config(filename): global max_reported_crackers global logfile global loglevel + global xmlrpc_listen_host global xmlrpc_listen_port global legacy_server global legacy_frequency @@ -62,6 +63,7 @@ def read_config(filename): global enable_debug_methods global stats_frequency global stats_resolve_hostnames + global stats_listen_host global stats_listen_port global static_dir, graph_dir, template_dir @@ -103,6 +105,7 @@ def read_config(filename): legacy_expiry_days = _getfloat(_config, "maintenance", "legacy_expiry_days", 30) max_reported_crackers = _getint(_config, "sync", "max_reported_crackers", 50) + xmlrpc_listen_host = _get(_config, "sync", "listen_host", "") xmlrpc_listen_port = _getint(_config, "sync", "listen_port", 9911) enable_debug_methods = _getboolean(_config, "sync", "enable_debug_methods", False) legacy_server = _get(_config, "sync", "legacy_server", None) @@ -130,4 +133,5 @@ def read_config(filename): graph_dir = _get(_config, "stats", "graph_dir", os.path.join(static_dir, "graph")) template_dir = _get(_config, "stats", "template_dir", os.path.join(package_dir, "template")) stats_resolve_hostnames = _getboolean(_config, "stats", "resolve_hostnames", True) + stats_listen_host = _get(_config, "stats", "listen_host", "") stats_listen_port = _getint(_config, "stats", "listen_port", 9911) diff --git a/denyhosts_server/main.py b/denyhosts_server/main.py index a1d5d4d..3cce711 100644 --- a/denyhosts_server/main.py +++ b/denyhosts_server/main.py @@ -165,15 +165,15 @@ def start_listening(): # /static/graphs web_static.putChild('graphs', web_graphs) - logging.info("Start listening on port {}".format(config.xmlrpc_listen_port)) + logging.info("Start listening on host:port {}:{}".format(config.xmlrpc_listen_host, config.xmlrpc_listen_port)) _xmlrpc_site = server.Site(xmlrpc_root) - _xmlrpc_listener = reactor.listenTCP(config.xmlrpc_listen_port, _xmlrpc_site) + _xmlrpc_listener = reactor.listenTCP(config.xmlrpc_listen_port, _xmlrpc_site, interface=config.xmlrpc_listen_host) - if config.stats_listen_port == config.xmlrpc_listen_port: + if config.stats_listen_port == config.xmlrpc_listen_port and config.xmlrpc_listen_host == config.stats_listen_host: _stats_listener = None else: - logging.info("Start serving statistics on port {}".format(config.stats_listen_port)) - _stats_listener = reactor.listenTCP(config.stats_listen_port, server.Site(stats_root)) + logging.info("Start serving statistics on host:port {}:{}".format(config.stats_listen_host, config.stats_listen_port)) + _stats_listener = reactor.listenTCP(config.stats_listen_port, server.Site(stats_root), interface=config.stats_listen_host) maintenance_job = None legacy_sync_job = None From 9c1ff3355a1a3c061053be9c6f497bb9fea79478 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Tue, 3 May 2016 10:02:01 +0300 Subject: [PATCH 2/2] Change option name listen_host to listen_address as suggested --- denyhosts-server.conf.example | 6 +++--- denyhosts_server/config.py | 8 ++++---- denyhosts_server/main.py | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/denyhosts-server.conf.example b/denyhosts-server.conf.example index 4a78c11..985d3ab 100644 --- a/denyhosts-server.conf.example +++ b/denyhosts-server.conf.example @@ -44,7 +44,7 @@ #max_reported_crackers: 50 # TCP addr to listen on. Default: empty (all) -#listen_host: +#listen_address: # TCP port to listen on. Default: 9911 #listen_port: 9911 @@ -113,9 +113,9 @@ # Default: yes #resolve_hostnames: yes -# TCP addr to serve statistics. Can be the same a the listen_host in the +# TCP addr to serve statistics. Can be the same a the listen_address in the # [sync] section. Default: empty (all) -#listen_host: +#listen_address: # TCP port to serve statistics. Can be the same a the listen_port in the # [sync] section. Default: 9911 diff --git a/denyhosts_server/config.py b/denyhosts_server/config.py index 7b89ecc..bce8d65 100644 --- a/denyhosts_server/config.py +++ b/denyhosts_server/config.py @@ -55,7 +55,7 @@ def read_config(filename): global max_reported_crackers global logfile global loglevel - global xmlrpc_listen_host + global xmlrpc_listen_address global xmlrpc_listen_port global legacy_server global legacy_frequency @@ -63,7 +63,7 @@ def read_config(filename): global enable_debug_methods global stats_frequency global stats_resolve_hostnames - global stats_listen_host + global stats_listen_address global stats_listen_port global static_dir, graph_dir, template_dir @@ -105,7 +105,7 @@ def read_config(filename): legacy_expiry_days = _getfloat(_config, "maintenance", "legacy_expiry_days", 30) max_reported_crackers = _getint(_config, "sync", "max_reported_crackers", 50) - xmlrpc_listen_host = _get(_config, "sync", "listen_host", "") + xmlrpc_listen_address = _get(_config, "sync", "listen_address", "") xmlrpc_listen_port = _getint(_config, "sync", "listen_port", 9911) enable_debug_methods = _getboolean(_config, "sync", "enable_debug_methods", False) legacy_server = _get(_config, "sync", "legacy_server", None) @@ -133,5 +133,5 @@ def read_config(filename): graph_dir = _get(_config, "stats", "graph_dir", os.path.join(static_dir, "graph")) template_dir = _get(_config, "stats", "template_dir", os.path.join(package_dir, "template")) stats_resolve_hostnames = _getboolean(_config, "stats", "resolve_hostnames", True) - stats_listen_host = _get(_config, "stats", "listen_host", "") + stats_listen_address = _get(_config, "stats", "listen_address", "") stats_listen_port = _getint(_config, "stats", "listen_port", 9911) diff --git a/denyhosts_server/main.py b/denyhosts_server/main.py index 3cce711..15909aa 100644 --- a/denyhosts_server/main.py +++ b/denyhosts_server/main.py @@ -165,15 +165,15 @@ def start_listening(): # /static/graphs web_static.putChild('graphs', web_graphs) - logging.info("Start listening on host:port {}:{}".format(config.xmlrpc_listen_host, config.xmlrpc_listen_port)) + logging.info("Start listening on host:port {}:{}".format(config.xmlrpc_listen_address, config.xmlrpc_listen_port)) _xmlrpc_site = server.Site(xmlrpc_root) - _xmlrpc_listener = reactor.listenTCP(config.xmlrpc_listen_port, _xmlrpc_site, interface=config.xmlrpc_listen_host) + _xmlrpc_listener = reactor.listenTCP(config.xmlrpc_listen_port, _xmlrpc_site, interface=config.xmlrpc_listen_address) - if config.stats_listen_port == config.xmlrpc_listen_port and config.xmlrpc_listen_host == config.stats_listen_host: + if config.stats_listen_port == config.xmlrpc_listen_port and config.xmlrpc_listen_address == config.stats_listen_address: _stats_listener = None else: - logging.info("Start serving statistics on host:port {}:{}".format(config.stats_listen_host, config.stats_listen_port)) - _stats_listener = reactor.listenTCP(config.stats_listen_port, server.Site(stats_root), interface=config.stats_listen_host) + logging.info("Start serving statistics on host:port {}:{}".format(config.stats_listen_address, config.stats_listen_port)) + _stats_listener = reactor.listenTCP(config.stats_listen_port, server.Site(stats_root), interface=config.stats_listen_address) maintenance_job = None legacy_sync_job = None