From 6e1f4fada9dea43ea0d4f39d23094b6eb84c92f4 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Tue, 17 Jul 2018 02:09:14 +0200 Subject: [PATCH] Rev3537, Allow to add peers to site with get request --- src/Config.py | 2 +- src/Ui/UiRequest.py | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/Config.py b/src/Config.py index 687e91c7..b60d5f95 100644 --- a/src/Config.py +++ b/src/Config.py @@ -10,7 +10,7 @@ class Config(object): def __init__(self, argv): self.version = "0.6.3" - self.rev = 3535 + self.rev = 3537 self.argv = argv self.action = None self.pending_changes = {} diff --git a/src/Ui/UiRequest.py b/src/Ui/UiRequest.py index 9807e602..eb6e800c 100644 --- a/src/Ui/UiRequest.py +++ b/src/Ui/UiRequest.py @@ -332,6 +332,21 @@ class UiRequest(object): else: return "/" + address + def processQueryString(self, site, query_string): + match = re.search("zeronet_peers=(.*?)(&|$)", query_string) + if match: + query_string = query_string.replace(match.group(0), "") + num_added = 0 + for peer in match.group(1).split(","): + if not re.match(".*?:[0-9]+$", peer): + continue + ip, port = peer.split(":") + if site.addPeer(ip, int(port), source="query_string"): + num_added += 1 + site.log.debug("%s peers added by query string" % num_added) + + return query_string + def renderWrapper(self, site, path, inner_path, title, extra_headers, show_loadingscreen=None): file_inner_path = inner_path if not file_inner_path: @@ -360,13 +375,15 @@ class UiRequest(object): postmessage_nonce_security = "false" wrapper_nonce = self.getWrapperNonce() + inner_query_string = self.processQueryString(site, self.env.get("QUERY_STRING", "")) - if self.env.get("QUERY_STRING"): - query_string = "?%s&wrapper_nonce=%s" % (self.env["QUERY_STRING"], wrapper_nonce) + if inner_query_string: + inner_query_string = "?%s&wrapper_nonce=%s" % (inner_query_string, wrapper_nonce) elif "?" in inner_path: - query_string = "&wrapper_nonce=%s" % wrapper_nonce + inner_query_string = "&wrapper_nonce=%s" % wrapper_nonce else: - query_string = "?wrapper_nonce=%s" % wrapper_nonce + inner_query_string = "?wrapper_nonce=%s" % wrapper_nonce + if self.isProxyRequest(): # Its a remote proxy request if self.env["REMOTE_ADDR"] == "127.0.0.1": # Local client, the server address also should be 127.0.0.1 @@ -409,7 +426,7 @@ class UiRequest(object): title=cgi.escape(title, True), body_style=body_style, meta_tags=meta_tags, - query_string=re.escape(query_string), + query_string=re.escape(inner_query_string), wrapper_key=site.settings["wrapper_key"], ajax_key=site.settings["ajax_key"], wrapper_nonce=wrapper_nonce,