From d57d82f4398995389c390f344ee093027ff08d6b Mon Sep 17 00:00:00 2001 From: shortcutme Date: Thu, 16 Feb 2017 20:56:07 +0100 Subject: [PATCH] Rev1913, Support local address other than 127.0.0.1 --- src/Config.py | 9 ++++++++- src/Connection/Connection.py | 4 ++-- src/Connection/ConnectionServer.py | 2 +- src/File/FileRequest.py | 4 ++-- src/main.py | 8 +++++--- src/util/SocksProxy.py | 4 ++-- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Config.py b/src/Config.py index 3bf5b6c8..bc16b108 100644 --- a/src/Config.py +++ b/src/Config.py @@ -10,7 +10,7 @@ class Config(object): def __init__(self, argv): self.version = "0.5.2" - self.rev = 1909 + self.rev = 1913 self.argv = argv self.action = None self.config_file = "zeronet.conf" @@ -85,6 +85,8 @@ class Config(object): data_dir = "data" log_dir = "log" + ip_local = ["127.0.0.1"] + # Main action = self.subparsers.add_parser("main", help='Start UiServer and FileServer (default)') @@ -184,6 +186,8 @@ class Config(object): self.parser.add_argument('--fileserver_ip', help='FileServer bind address', default="*", metavar='ip') self.parser.add_argument('--fileserver_port', help='FileServer bind port', default=15441, type=int, metavar='port') + self.parser.add_argument('--ip_local', help='My local ips', default=ip_local, type=int, metavar='ip', nargs='*') + self.parser.add_argument('--disable_udp', help='Disable UDP connections', action='store_true') self.parser.add_argument('--proxy', help='Socks proxy address', metavar='ip:port') self.parser.add_argument('--ip_external', help='Set reported external ip (tested on start if None)', metavar='ip') @@ -284,6 +288,9 @@ class Config(object): self.parseCommandline(argv, silent) # Parse argv self.setAttributes() + if self.fileserver_ip != "*" and self.fileserver_ip not in self.ip_local: + self.ip_local.append(self.fileserver_ip) + if silent: # Restore original functions if self.parser.exited and self.action == "main": # Argument parsing halted, don't start ZeroNet with main action self.action = None diff --git a/src/Connection/Connection.py b/src/Connection/Connection.py index 7f171fd6..23fdf03c 100644 --- a/src/Connection/Connection.py +++ b/src/Connection/Connection.py @@ -116,7 +116,7 @@ class Connection(object): def handleIncomingConnection(self, sock): self.log("Incoming connection...") self.type = "in" - if self.ip != "127.0.0.1": # Clearnet: Check implicit SSL + if self.ip not in config.ip_local: # Clearnet: Check implicit SSL try: if sock.recv(1, gevent.socket.MSG_PEEK) == "\x16": self.log("Crypt in connection using implicit SSL") @@ -176,7 +176,7 @@ class Connection(object): else: crypt_supported = CryptConnection.manager.crypt_supported # No peer id for onion connections - if self.ip.endswith(".onion") or self.ip == "127.0.0.1": + if self.ip.endswith(".onion") or self.ip in config.ip_local: peer_id = "" else: peer_id = self.server.peer_id diff --git a/src/Connection/ConnectionServer.py b/src/Connection/ConnectionServer.py index c55b125f..fad9260b 100644 --- a/src/Connection/ConnectionServer.py +++ b/src/Connection/ConnectionServer.py @@ -29,7 +29,7 @@ class ConnectionServer: self.tor_manager = None self.connections = [] # Connections - self.whitelist = ("127.0.0.1",) # No flood protection on this ips + self.whitelist = config.ip_local # No flood protection on this ips self.ip_incoming = {} # Incoming connections from ip in the last minute to avoid connection flood self.broken_ssl_peer_ids = {} # Peerids of broken ssl connections self.ips = {} # Connection by ip diff --git a/src/File/FileRequest.py b/src/File/FileRequest.py index 761c1e3b..0ad03b77 100644 --- a/src/File/FileRequest.py +++ b/src/File/FileRequest.py @@ -408,7 +408,7 @@ class FileRequest(object): self.response({"ok": "Updated"}) def actionSiteReload(self, params): - if self.connection.ip != "127.0.0.1" and self.connection.ip != config.ip_external: + if self.connection.ip not in config.ip_local and self.connection.ip != config.ip_external: self.response({"error": "Only local host allowed"}) site = self.sites.get(params["site"]) @@ -419,7 +419,7 @@ class FileRequest(object): self.response({"ok": "Reloaded"}) def actionSitePublish(self, params): - if self.connection.ip != "127.0.0.1" and self.connection.ip != config.ip_external: + if self.connection.ip not in config.ip_local and self.connection.ip != config.ip_external: self.response({"error": "Only local host allowed"}) site = self.sites.get(params["site"]) diff --git a/src/main.py b/src/main.py index 5f894271..e43e627f 100644 --- a/src/main.py +++ b/src/main.py @@ -116,13 +116,15 @@ if config.proxy: from util import SocksProxy import urllib2 logging.info("Patching sockets to socks proxy: %s" % config.proxy) - config.fileserver_ip = '127.0.0.1' # Do not accept connections anywhere but localhost + if config.fileserver_ip == "*": + config.fileserver_ip = '127.0.0.1' # Do not accept connections anywhere but localhost SocksProxy.monkeyPatch(*config.proxy.split(":")) elif config.tor == "always": from util import SocksProxy import urllib2 logging.info("Patching sockets to tor socks proxy: %s" % config.tor_proxy) - config.fileserver_ip = '127.0.0.1' # Do not accept connections anywhere but localhost + if config.fileserver_ip == "*": + config.fileserver_ip = '127.0.0.1' # Do not accept connections anywhere but localhost SocksProxy.monkeyPatch(*config.tor_proxy.split(":")) config.disable_udp = True # -- Actions -- @@ -366,7 +368,7 @@ class Actions(object): else: # Already running, notify local client on new content logging.info("Sending siteReload") - my_peer = Peer("127.0.0.1", config.fileserver_port) + my_peer = Peer(config.fileserver_ip, config.fileserver_port) logging.info(my_peer.request("siteReload", {"site": site.address, "inner_path": inner_path})) logging.info("Sending sitePublish") logging.info(my_peer.request("sitePublish", {"site": site.address, "inner_path": inner_path, "diffs": diffs})) diff --git a/src/util/SocksProxy.py b/src/util/SocksProxy.py index 7a99e2aa..4c357134 100644 --- a/src/util/SocksProxy.py +++ b/src/util/SocksProxy.py @@ -1,10 +1,10 @@ import socket from lib.PySocks import socks - +from Config import config def create_connection(address, timeout=None, source_address=None): - if address == "127.0.0.1": + if address in config.ip_local: sock = socket.socket_noproxy(socket.AF_INET, socket.SOCK_STREAM) sock.connect(address) else: