From 97cc03ef6abffbdb70a927fff16c9e84c4245a03 Mon Sep 17 00:00:00 2001 From: reger Date: Fri, 20 Nov 2015 01:49:56 +0100 Subject: [PATCH] start using a template for urlproxy header It is included as iframe /proxmsg/urlproxyheader.html to allow full servlet functionallity and flexibility to display some index/meta data in future. --- htroot/proxymsg/urlproxyheader.html | 10 ++++ htroot/proxymsg/urlproxyheader.java | 49 +++++++++++++++++++ .../yacy/http/servlets/UrlProxyServlet.java | 19 ++++--- 3 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 htroot/proxymsg/urlproxyheader.html create mode 100644 htroot/proxymsg/urlproxyheader.java diff --git a/htroot/proxymsg/urlproxyheader.html b/htroot/proxymsg/urlproxyheader.html new file mode 100644 index 000000000..5f53ef526 --- /dev/null +++ b/htroot/proxymsg/urlproxyheader.html @@ -0,0 +1,10 @@ + + + +
+
+ #(httpsAlertMsg)#::   - (Warning: secure target viewed over normal http)#(/httpsAlertMsg)# +
+
+ + diff --git a/htroot/proxymsg/urlproxyheader.java b/htroot/proxymsg/urlproxyheader.java new file mode 100644 index 000000000..2e102a878 --- /dev/null +++ b/htroot/proxymsg/urlproxyheader.java @@ -0,0 +1,49 @@ + +import net.yacy.cora.protocol.RequestHeader; +import net.yacy.search.Switchboard; +import net.yacy.server.serverObjects; +import net.yacy.server.serverSwitch; + + +/** + * Servlet to be included as header (via iframe) on top of a page viewed via urlproxyservlet + */ +public class urlproxyheader { + + public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader requestHeader, @SuppressWarnings("unused") final serverObjects post, @SuppressWarnings("unused") final serverSwitch env) { + final serverObjects prop = new serverObjects(); + final Switchboard sb = (Switchboard) env; + + final String proxyurlstr = post.get("url",""); // the url of remote page currently viewed + prop.put("proxyurl", proxyurlstr); + + if (proxyurlstr.startsWith("https")) { + prop.put("httpsAlertMsg", "1"); + } else { + prop.put("httpsAlertMsg", "0"); + } + + // TODO: get some index data to display + /* + if (post.containsKey("hash")) { + try { + String hashstr = post.get("hash"); + final SolrDocument idxdoc = sb.index.fulltext().getDefaultEmbeddedConnector().getDocumentById(hashstr); + if (idxdoc != null) { + String keywords = (String) idxdoc.getFieldValue(CollectionSchema.keywords.getSolrFieldName()); + if (keywords != null && !keywords.isEmpty()) { + keytxt += keywords; + } + Collection cols = idxdoc.getFieldValues(CollectionSchema.collection_sxt.getSolrFieldName()); + if (cols != null && !cols.isEmpty()) { + for (Object sx : cols) { + coltxt += sx.toString(); + } + } + }catch (IOException ex) { } + } + */ + return prop; + } + +} diff --git a/source/net/yacy/http/servlets/UrlProxyServlet.java b/source/net/yacy/http/servlets/UrlProxyServlet.java index ad4c8cd17..034c02232 100644 --- a/source/net/yacy/http/servlets/UrlProxyServlet.java +++ b/source/net/yacy/http/servlets/UrlProxyServlet.java @@ -252,13 +252,20 @@ public class UrlProxyServlet extends ProxyServlet implements Servlet { } // 8 - add interaction elements (e.g. proxy exit button to switch back to original url) - // TODO: use a template file for if (_stopProxyText != null) { - String httpsAllertMsg = ""; - if (proxyurl.getProtocol().equalsIgnoreCase("https") && !request.getScheme().equalsIgnoreCase("https")) httpsAllertMsg = "   - (Warning: secure target viewed over normal http)"; - bde.prepend("
" - + "
" + _stopProxyText + " " - + httpsAllertMsg + "
"); + + String httpsAlertMsg = ""; + if (proxyurl.getProtocol().equalsIgnoreCase("https") && !request.getScheme().equalsIgnoreCase("https")) httpsAlertMsg = "   - (Warning: secure target viewed over normal http)"; + + // use a template file, to allow full servlet functionallity header as iframe included + String hdrtemplate = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/proxymsg/urlproxyheader.html?url=" + proxyurl.toString(); + hdrtemplate = ""; + bde.prepend(hdrtemplate); // put as 1st element in body } // 9 - deliver to client