Rev1913, Support local address other than 127.0.0.1

This commit is contained in:
shortcutme 2017-02-16 20:56:07 +01:00
parent 39734dfadb
commit d57d82f439
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
6 changed files with 20 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"])

View File

@ -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}))

View File

@ -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: