From 5247d01cd48ed20589bfe3bf02135cd80992b941 Mon Sep 17 00:00:00 2001 From: reger Date: Sun, 14 Sep 2014 23:26:22 +0200 Subject: [PATCH] implement a forward to remote peer link in P2P Network list Most links in Network.html are only available with transparent proxy = on, which is switched off by default, to make the provided links useable in default setup a small forward servlet added (goto_p.java), which takes the peer hash as parameter and forwards to current public ip (optional with path= parameter). The servlet is protected ( _p ending) to assure forwarding works only for authorized YaCy users. --- htroot/Network.html | 6 ++-- htroot/goto_p.html | 10 ++++++ htroot/goto_p.java | 74 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 htroot/goto_p.html create mode 100644 htroot/goto_p.java diff --git a/htroot/Network.html b/htroot/Network.html index 14ccc3fd9..2fecf9105 100644 --- a/htroot/Network.html +++ b/htroot/Network.html @@ -136,14 +136,14 @@ document.getElementById("apilink").setAttribute("href", "Network.xml?" + window. m  p  - w  - b  + w  + b  #(updatedProfile)#::Profile updated#(/updatedProfile)# #(updatedWiki)#::Wiki updated#(/updatedWiki)# #(updatedBlog)#::Blog updated#(/updatedBlog)# #(isCrawling)#::Crawl#(/isCrawling)# - #[shortname]##(ssl)#::https supported#(/ssl)# + #[shortname]##(ssl)#::https supported#(/ssl)# #(type)##(direct)#Junior passive::Junior direct::Junior offline#(/direct)#::#(direct)#senior passive::Senior direct::Senior offline#(/direct)#::#(direct)#Principal passive::Principal active::Principal offline#(/direct)##(/type)##(acceptcrawl)#no crawl::crawl possible::crawl possible#(/acceptcrawl)##(dhtreceive)#no DHT receive::DHT receive enabled::DHT receive enabled#(/dhtreceive)##(nodestate)#no node candidate::node candidate#(/nodestate)# #[version]# diff --git a/htroot/goto_p.html b/htroot/goto_p.html new file mode 100644 index 000000000..a33639aa2 --- /dev/null +++ b/htroot/goto_p.html @@ -0,0 +1,10 @@ + + + + forwarding + + +

forward to remote peer

+

Error: #[msg]#

+ + diff --git a/htroot/goto_p.java b/htroot/goto_p.java new file mode 100644 index 000000000..387665ac4 --- /dev/null +++ b/htroot/goto_p.java @@ -0,0 +1,74 @@ +// goto_p.java +// ----------------------- +// part of YaCy +// (C) by Michael Peter Christen; mc@yacy.net +// first published on http://yacy.net +// +// $LastChangedDate$ +// $LastChangedRevision$ +// $LastChangedBy$ +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +// You must compile this file with +// javac -classpath .:../Classes goto_p.java +// if the shell's current path is HTROOT + +import net.yacy.cora.protocol.RequestHeader; +import net.yacy.peers.Seed; +import net.yacy.search.Switchboard; +import net.yacy.server.serverObjects; +import net.yacy.server.serverSwitch; + +/** + * forwards caller/browser to remote peer + */ +public class goto_p { + + /** + * url parameter + * + * hash= of remote peer + * path= path part to forward to + */ + public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { + final Switchboard sb = (Switchboard) env; + final serverObjects prop = new serverObjects(); + + String hash = null; + if (post != null) { + hash = post.get("hash", null); // get peers hash + } + + if (hash != null) { + Seed seed = sb.peers.getConnected(hash); + + if (seed != null) { + String peersUrl = seed.getPublicAddress(); + if (peersUrl != null) { + String path = post.get("path", "/"); + if (!path.startsWith("/")) path = "/" + path; + prop.put(serverObjects.ACTION_LOCATION, "http://" + peersUrl + path); // redirect command + } + } else { + prop.put("msg", "peer not available"); + } + + } else { + prop.put("msg", "parameter missing"); + } + return prop; + } +}