Don't permit common invalid REPORT_HOST values
This commit is contained in:
parent
af67536598
commit
5f56689e9c
@ -9,6 +9,7 @@
|
||||
|
||||
|
||||
from collections import namedtuple
|
||||
from ipaddress import ip_address
|
||||
from os import environ
|
||||
|
||||
from lib.coins import Coin
|
||||
@ -68,8 +69,10 @@ class Env(LoggedClass):
|
||||
self.irc_nick = self.default('IRC_NICK', None)
|
||||
|
||||
# Identities
|
||||
report_host = self.default('REPORT_HOST', self.host)
|
||||
self.check_report_host(report_host)
|
||||
main_identity = NetIdentity(
|
||||
self.default('REPORT_HOST', self.host),
|
||||
report_host,
|
||||
self.integer('REPORT_TCP_PORT', self.tcp_port) or None,
|
||||
self.integer('REPORT_SSL_PORT', self.ssl_port) or None,
|
||||
''
|
||||
@ -114,6 +117,16 @@ class Env(LoggedClass):
|
||||
raise self.Error('cannot convert envvar {} value {} to an integer'
|
||||
.format(envvar, value))
|
||||
|
||||
def check_report_host(self, host):
|
||||
try:
|
||||
ip = ip_address(host)
|
||||
except ValueError:
|
||||
bad = not bool(host)
|
||||
else:
|
||||
bad = ip.is_multicast or ip.is_unspecified
|
||||
if bad:
|
||||
raise self.Error('{} is not a valid REPORT_HOST'.format(host))
|
||||
|
||||
def obsolete(self, envvars):
|
||||
bad = [envvar for envvar in envvars if environ.get(envvar)]
|
||||
if bad:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user