Merge pull request #157 from zeronet-conservancy/fix_optparse_tor

allow only passing port as tor_* parameters
This commit is contained in:
caryoscelus 2022-09-08 12:43:26 +00:00 committed by GitHub
commit 8c1513ee8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 7 deletions

View file

@ -16,7 +16,7 @@ class Config(object):
self.version = "0.7.7+" self.version = "0.7.7+"
self.user_agent = "conservancy" self.user_agent = "conservancy"
# DEPRECATED ; replace with git-generated commit # DEPRECATED ; replace with git-generated commit
self.rev = 5035 self.rev = 5036
self.argv = argv self.argv = argv
self.action = None self.action = None
self.test_parser = None self.test_parser = None
@ -754,6 +754,28 @@ class Config(object):
if file_logging: if file_logging:
self.initFileLogger() self.initFileLogger()
def tor_proxy_split(self):
if self.tor_proxy:
if ':' in config.tor_proxy:
ip, port = config.tor_proxy.rsplit(":", 1)
else:
ip = 'localhost'
port = config.tor_proxy
return ip, int(port)
else:
return 'localhost', 9050
def tor_controller_split(self):
if self.tor_controller:
if ':' in config.tor_controller:
ip, port = config.tor_controller.rsplit(":", 1)
else:
ip = 'localhost'
port = config.tor_controller
return ip, int(port)
else:
return 'localhost', 9051
class ErrorLogHandler(logging.StreamHandler): class ErrorLogHandler(logging.StreamHandler):
def __init__(self): def __init__(self):

View file

@ -51,11 +51,8 @@ class TorManager(object):
else: else:
self.fileserver_port = config.fileserver_port self.fileserver_port = config.fileserver_port
self.ip, self.port = config.tor_controller.rsplit(":", 1) self.ip, self.port = config.tor_controller_split()
self.port = int(self.port) self.proxy_ip, self.proxy_port = config.tor_proxy_split()
self.proxy_ip, self.proxy_port = config.tor_proxy.rsplit(":", 1)
self.proxy_port = int(self.proxy_port)
def start(self): def start(self):
self.log.debug("Starting (Tor: %s)" % config.tor) self.log.debug("Starting (Tor: %s)" % config.tor)

View file

@ -122,7 +122,7 @@ elif config.tor == "always":
logging.info("Patching sockets to tor socks proxy: %s" % config.tor_proxy) logging.info("Patching sockets to tor socks proxy: %s" % config.tor_proxy)
if config.fileserver_ip == "*": if config.fileserver_ip == "*":
config.fileserver_ip = '127.0.0.1' # Do not accept connections anywhere but localhost config.fileserver_ip = '127.0.0.1' # Do not accept connections anywhere but localhost
SocksProxy.monkeyPatch(*config.tor_proxy.split(":")) SocksProxy.monkeyPatch(*config.tor_proxy_split())
config.disable_udp = True config.disable_udp = True
elif config.bind: elif config.bind:
bind = config.bind bind = config.bind