Rev1913, Support local address other than 127.0.0.1
This commit is contained in:
parent
39734dfadb
commit
d57d82f439
6 changed files with 20 additions and 11 deletions
|
@ -10,7 +10,7 @@ class Config(object):
|
||||||
|
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
self.version = "0.5.2"
|
self.version = "0.5.2"
|
||||||
self.rev = 1909
|
self.rev = 1913
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
self.action = None
|
self.action = None
|
||||||
self.config_file = "zeronet.conf"
|
self.config_file = "zeronet.conf"
|
||||||
|
@ -85,6 +85,8 @@ class Config(object):
|
||||||
data_dir = "data"
|
data_dir = "data"
|
||||||
log_dir = "log"
|
log_dir = "log"
|
||||||
|
|
||||||
|
ip_local = ["127.0.0.1"]
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
action = self.subparsers.add_parser("main", help='Start UiServer and FileServer (default)')
|
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_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('--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('--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('--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')
|
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.parseCommandline(argv, silent) # Parse argv
|
||||||
self.setAttributes()
|
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 silent: # Restore original functions
|
||||||
if self.parser.exited and self.action == "main": # Argument parsing halted, don't start ZeroNet with main action
|
if self.parser.exited and self.action == "main": # Argument parsing halted, don't start ZeroNet with main action
|
||||||
self.action = None
|
self.action = None
|
||||||
|
|
|
@ -116,7 +116,7 @@ class Connection(object):
|
||||||
def handleIncomingConnection(self, sock):
|
def handleIncomingConnection(self, sock):
|
||||||
self.log("Incoming connection...")
|
self.log("Incoming connection...")
|
||||||
self.type = "in"
|
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:
|
try:
|
||||||
if sock.recv(1, gevent.socket.MSG_PEEK) == "\x16":
|
if sock.recv(1, gevent.socket.MSG_PEEK) == "\x16":
|
||||||
self.log("Crypt in connection using implicit SSL")
|
self.log("Crypt in connection using implicit SSL")
|
||||||
|
@ -176,7 +176,7 @@ class Connection(object):
|
||||||
else:
|
else:
|
||||||
crypt_supported = CryptConnection.manager.crypt_supported
|
crypt_supported = CryptConnection.manager.crypt_supported
|
||||||
# No peer id for onion connections
|
# 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 = ""
|
peer_id = ""
|
||||||
else:
|
else:
|
||||||
peer_id = self.server.peer_id
|
peer_id = self.server.peer_id
|
||||||
|
|
|
@ -29,7 +29,7 @@ class ConnectionServer:
|
||||||
self.tor_manager = None
|
self.tor_manager = None
|
||||||
|
|
||||||
self.connections = [] # Connections
|
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.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.broken_ssl_peer_ids = {} # Peerids of broken ssl connections
|
||||||
self.ips = {} # Connection by ip
|
self.ips = {} # Connection by ip
|
||||||
|
|
|
@ -408,7 +408,7 @@ class FileRequest(object):
|
||||||
self.response({"ok": "Updated"})
|
self.response({"ok": "Updated"})
|
||||||
|
|
||||||
def actionSiteReload(self, params):
|
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"})
|
self.response({"error": "Only local host allowed"})
|
||||||
|
|
||||||
site = self.sites.get(params["site"])
|
site = self.sites.get(params["site"])
|
||||||
|
@ -419,7 +419,7 @@ class FileRequest(object):
|
||||||
self.response({"ok": "Reloaded"})
|
self.response({"ok": "Reloaded"})
|
||||||
|
|
||||||
def actionSitePublish(self, params):
|
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"})
|
self.response({"error": "Only local host allowed"})
|
||||||
|
|
||||||
site = self.sites.get(params["site"])
|
site = self.sites.get(params["site"])
|
||||||
|
|
|
@ -116,13 +116,15 @@ if config.proxy:
|
||||||
from util import SocksProxy
|
from util import SocksProxy
|
||||||
import urllib2
|
import urllib2
|
||||||
logging.info("Patching sockets to socks proxy: %s" % config.proxy)
|
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(":"))
|
SocksProxy.monkeyPatch(*config.proxy.split(":"))
|
||||||
elif config.tor == "always":
|
elif config.tor == "always":
|
||||||
from util import SocksProxy
|
from util import SocksProxy
|
||||||
import urllib2
|
import urllib2
|
||||||
logging.info("Patching sockets to tor socks proxy: %s" % config.tor_proxy)
|
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(":"))
|
SocksProxy.monkeyPatch(*config.tor_proxy.split(":"))
|
||||||
config.disable_udp = True
|
config.disable_udp = True
|
||||||
# -- Actions --
|
# -- Actions --
|
||||||
|
@ -366,7 +368,7 @@ class Actions(object):
|
||||||
else:
|
else:
|
||||||
# Already running, notify local client on new content
|
# Already running, notify local client on new content
|
||||||
logging.info("Sending siteReload")
|
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(my_peer.request("siteReload", {"site": site.address, "inner_path": inner_path}))
|
||||||
logging.info("Sending sitePublish")
|
logging.info("Sending sitePublish")
|
||||||
logging.info(my_peer.request("sitePublish", {"site": site.address, "inner_path": inner_path, "diffs": diffs}))
|
logging.info(my_peer.request("sitePublish", {"site": site.address, "inner_path": inner_path, "diffs": diffs}))
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from lib.PySocks import socks
|
from lib.PySocks import socks
|
||||||
|
from Config import config
|
||||||
|
|
||||||
def create_connection(address, timeout=None, source_address=None):
|
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 = socket.socket_noproxy(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect(address)
|
sock.connect(address)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue