mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
Fixed /News.html and /Wiki.html pages in Search Portal mode (issue #87).
Also fixes theses pages rendering when the peer is not online. Re-factored code in common with /opensearchdescription.xml and ConfigPortal.html.
This commit is contained in:
parent
8fe28a83f2
commit
2da5f339f8
|
@ -149,7 +149,7 @@
|
|||
</pre></fieldset>
|
||||
This would look like:
|
||||
<iframe name="target"
|
||||
src="#[myPreviewProtocol]#://#[myPreviewAddress]#/index.html?display=2&resource=local&focus=0"
|
||||
src="#[myPreviewContext]#/index.html?display=2&resource=local&focus=0"
|
||||
width="100%"
|
||||
height="410"
|
||||
frameborder="0"
|
||||
|
@ -172,7 +172,7 @@
|
|||
</pre></fieldset>
|
||||
This would look like:
|
||||
<iframe name="target2"
|
||||
src="#[myPreviewProtocol]#://#[myPreviewAddress]#/yacysearch.html?display=2&resource=local&focus=0"
|
||||
src="#[myPreviewContext]#/yacysearch.html?display=2&resource=local&focus=0"
|
||||
width="100%"
|
||||
height="180"
|
||||
frameborder="0"
|
||||
|
@ -196,7 +196,7 @@
|
|||
</pre></fieldset>
|
||||
This would look like:
|
||||
<iframe name="target3"
|
||||
src="#[myPreviewProtocol]#://#[myPreviewAddress]#/yacyinteractive.html?display=2&focus=0"
|
||||
src="#[myPreviewContext]#/yacyinteractive.html?display=2&focus=0"
|
||||
width="100%"
|
||||
height="180"
|
||||
frameborder="0"
|
||||
|
|
|
@ -33,11 +33,10 @@ import java.net.MalformedURLException;
|
|||
import java.util.Properties;
|
||||
|
||||
import net.yacy.cora.document.id.DigestURL;
|
||||
import net.yacy.cora.protocol.Domains;
|
||||
import net.yacy.cora.protocol.HeaderFramework;
|
||||
import net.yacy.cora.protocol.RequestHeader;
|
||||
import net.yacy.cora.util.ConcurrentLog;
|
||||
import net.yacy.data.WorkTables;
|
||||
import net.yacy.http.servlets.YaCyDefaultServlet;
|
||||
import net.yacy.search.Switchboard;
|
||||
import net.yacy.search.SwitchboardConstants;
|
||||
import net.yacy.server.serverObjects;
|
||||
|
@ -230,29 +229,13 @@ public class ConfigPortal {
|
|||
prop.put("target_special_pattern", sb.getConfig(SwitchboardConstants.SEARCH_TARGET_SPECIAL_PATTERN, ""));
|
||||
|
||||
/* Address used in code template */
|
||||
String myaddress = (sb.peers == null) || sb.peers.mySeed() == null || sb.peers.mySeed().getIP() == null ? null : sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP());
|
||||
String myaddress = (sb.peers == null) || sb.peers.mySeed() == null || sb.peers.mySeed().getIPs().isEmpty() ? null : sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIPs().iterator().next());
|
||||
if (myaddress == null) {
|
||||
myaddress = "localhost:" + sb.getLocalPort();
|
||||
}
|
||||
prop.put("myaddress", myaddress);
|
||||
|
||||
/* Address used to generate the preview frames : let's use the adress and port as requested. (Same behavior as opensearchdescription.java) */
|
||||
String myPreviewAddress = header.get(HeaderFramework.HOST); // returns host:port (if not default http/https ports)
|
||||
String myPreviewProtocol = "http";
|
||||
if (myPreviewAddress == null) {
|
||||
myPreviewAddress = Domains.LOCALHOST + ":" + sb.getConfig("port", "8090");
|
||||
} else {
|
||||
final String sslport = ":" + sb.getConfig("port.ssl", "8443");
|
||||
if (myPreviewAddress.endsWith(sslport)) { // connection on ssl port, use https protocol
|
||||
myPreviewProtocol = "https";
|
||||
}
|
||||
}
|
||||
/* YaCyDefaultServelt should have filled this custom header, making sure we know here wether original request is http or https
|
||||
* (when default ports (80 and 443) are used, there is no way to distinguish the two schemes relying only on the Host header) */
|
||||
myPreviewProtocol = header.get(HeaderFramework.X_YACY_REQUEST_SCHEME, myPreviewProtocol);
|
||||
|
||||
prop.put("myPreviewAddress", myPreviewAddress);
|
||||
prop.put("myPreviewProtocol", myPreviewProtocol);
|
||||
prop.put("myPreviewContext", YaCyDefaultServlet.getContext(header, sb));
|
||||
return prop;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,14 @@
|
|||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.yacy.cora.date.GenericFormatter;
|
||||
import net.yacy.cora.protocol.HeaderFramework;
|
||||
import net.yacy.cora.protocol.RequestHeader;
|
||||
import net.yacy.cora.util.ConcurrentLog;
|
||||
import net.yacy.http.servlets.YaCyDefaultServlet;
|
||||
import net.yacy.peers.NewsDB;
|
||||
import net.yacy.peers.NewsPool;
|
||||
import net.yacy.peers.Seed;
|
||||
|
@ -157,11 +159,29 @@ public class News {
|
|||
title = record.attribute("title", "");
|
||||
description = record.attribute("url", "");
|
||||
} else if (category.equals(NewsPool.CATEGORY_WIKI_UPDATE)) {
|
||||
link = (seed == null)? "" : "http://" + seed.getPublicAddress(seed.getIP()) + "/Wiki.html?page=" + record.attribute("page", "");
|
||||
if(seed == null) {
|
||||
link = "";
|
||||
} else {
|
||||
Set<String> ips = seed.getIPs();
|
||||
if(!ips.isEmpty()) {
|
||||
link = "http://" + seed.getPublicAddress(ips.iterator().next()) + "/Wiki.html?page=" + record.attribute("page", "");
|
||||
} else {
|
||||
link = "";
|
||||
}
|
||||
}
|
||||
title = record.attribute("author", "Anonymous") + ": " + record.attribute("page", "");
|
||||
description = "Wiki Update: " + record.attribute("description", "");
|
||||
} else if (category.equals(NewsPool.CATEGORY_BLOG_ADD)) {
|
||||
link = (seed == null)? "" : "http://" + seed.getPublicAddress(seed.getIP()) + "/Blog.html?page=" + record.attribute("page", "");
|
||||
if(seed == null) {
|
||||
link = "";
|
||||
} else {
|
||||
Set<String> ips = seed.getIPs();
|
||||
if(!ips.isEmpty()) {
|
||||
link = "http://" + seed.getPublicAddress(ips.iterator().next()) + "/Blog.html?page=" + record.attribute("page", "");
|
||||
} else {
|
||||
link = "";
|
||||
}
|
||||
}
|
||||
title = record.attribute("author", "Anonymous") + ": " + record.attribute("page", "");
|
||||
description = "Blog Entry: " + record.attribute("subject", "");
|
||||
} else {
|
||||
|
@ -179,8 +199,8 @@ public class News {
|
|||
}
|
||||
}
|
||||
|
||||
// adding the peer address
|
||||
prop.put("address", sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP()));
|
||||
// add the peer web context (used by News.rss)
|
||||
prop.put("context", YaCyDefaultServlet.getContext(header, sb));
|
||||
|
||||
// return rewrite properties
|
||||
return prop;
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<rss version="2.0">
|
||||
<channel>
|
||||
<title><![CDATA[YaCy '#[clientname]#': #(page)#News Overview::Incoming News::Processed News::Outgoing News::Published News#(/page)#]]></title>
|
||||
<link>http://#[address]#/News.html?page=#[page]#</link>
|
||||
<link>#[context]#/News.html?page=#[page]#</link>
|
||||
<image>
|
||||
<url>http://#[address]#/env/grafics/YaCyLogo_60ppi.png</url>
|
||||
<url>#[context]#/env/grafics/YaCyLogo_60ppi.png</url>
|
||||
<title>YaCy</title>
|
||||
<link>http://#[address]#/</link>
|
||||
<link>#[context]#/</link>
|
||||
</image>
|
||||
#(table)#<!-- News Overview -->
|
||||
::<!-- News Tables -->
|
||||
|
|
|
@ -37,6 +37,7 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.yacy.cora.document.encoding.UTF8;
|
||||
import net.yacy.cora.protocol.Domains;
|
||||
|
@ -128,6 +129,18 @@ public class Wiki {
|
|||
prop.put(serverObjects.ACTION_LOCATION, prop.get(serverObjects.ACTION_LOCATION));
|
||||
}
|
||||
|
||||
String hostAndPort = null;
|
||||
Set<String> ips = null;
|
||||
if(sb.peers.mySeed() != null) {
|
||||
ips = sb.peers.mySeed().getIPs();
|
||||
}
|
||||
if(ips != null && !ips.isEmpty()) {
|
||||
hostAndPort = sb.peers.mySeed().getPublicAddress(ips.iterator().next());
|
||||
}
|
||||
if (hostAndPort == null) {
|
||||
hostAndPort = Domains.LOCALHOST + ":" + sb.getLocalPort();
|
||||
}
|
||||
|
||||
if (post != null && post.containsKey("edit")) {
|
||||
if ((access.equals("admin") && (!sb.verifyAuthentication(header)))) {
|
||||
// check access right for admin
|
||||
|
@ -147,7 +160,8 @@ public class Wiki {
|
|||
prop.putHTML("mode_pagename", pagename);
|
||||
prop.putHTML("mode_author", author);
|
||||
prop.put("mode_date", dateString(new Date()));
|
||||
prop.putWiki(sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP()), "mode_page", post.get("content", ""));
|
||||
// Note : it would be better to not only pass the peer host and port but also the protocol (http or https)
|
||||
prop.putWiki(hostAndPort, "mode_page", post.get("content", ""));
|
||||
prop.putHTML("mode_page-code", post.get("content", ""));
|
||||
}
|
||||
//end contrib of [MN]
|
||||
|
@ -237,7 +251,7 @@ public class Wiki {
|
|||
prop.putHTML("mode_versioning_pagename", pagename);
|
||||
prop.putHTML("mode_versioning_author", oentry.author());
|
||||
prop.put("mode_versioning_date", dateString(oentry.date()));
|
||||
prop.putWiki(sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP()), "mode_versioning_page", oentry.page());
|
||||
prop.putWiki(hostAndPort, "mode_versioning_page", oentry.page());
|
||||
prop.putHTML("mode_versioning_page-code", UTF8.String(oentry.page()));
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
|
@ -252,7 +266,7 @@ public class Wiki {
|
|||
prop.putHTML("mode_pagename", pagename);
|
||||
prop.putHTML("mode_author", page.author());
|
||||
prop.put("mode_date", dateString(page.date()));
|
||||
prop.putWiki(sb.peers.mySeed().getPublicAddress(sb.peers.mySeed().getIP()), "mode_page", page.page());
|
||||
prop.putWiki(hostAndPort, "mode_page", page.page());
|
||||
|
||||
prop.put("controls", "0");
|
||||
prop.putHTML("controls_pagename", pagename);
|
||||
|
|
|
@ -24,9 +24,8 @@
|
|||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import net.yacy.cora.protocol.Domains;
|
||||
import net.yacy.cora.protocol.HeaderFramework;
|
||||
import net.yacy.cora.protocol.RequestHeader;
|
||||
import net.yacy.http.servlets.YaCyDefaultServlet;
|
||||
import net.yacy.search.Switchboard;
|
||||
import net.yacy.search.SwitchboardConstants;
|
||||
import net.yacy.server.serverObjects;
|
||||
|
@ -40,26 +39,12 @@ public class opensearchdescription {
|
|||
String promoteSearchPageGreeting = env.getConfig(SwitchboardConstants.GREETING, "");
|
||||
if (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) promoteSearchPageGreeting = env.getConfig("network.unit.description", "");
|
||||
|
||||
String thisaddress = header.get(HeaderFramework.HOST); // returns host:port (if not default http/https ports)
|
||||
String thisprotocol = "http";
|
||||
if (thisaddress == null) {
|
||||
thisaddress = Domains.LOCALHOST + ":" + sb.getConfig("port", "8090");
|
||||
} else {
|
||||
final String sslport = ":" + sb.getConfig("port.ssl", "8443");
|
||||
if (thisaddress.endsWith(sslport)) { // connection on ssl port, use https protocol
|
||||
thisprotocol = "https";
|
||||
}
|
||||
}
|
||||
/* YaCyDefaultServelt should have filled this custom header, making sure we know here wether original request is http or https
|
||||
* (when default ports (80 and 443) are used, there is no way to distinguish the two schemes relying only on the Host header) */
|
||||
thisprotocol = header.get(HeaderFramework.X_YACY_REQUEST_SCHEME, thisprotocol);
|
||||
final String thisContext = YaCyDefaultServlet.getContext(header, sb);
|
||||
|
||||
final serverObjects prop = new serverObjects();
|
||||
prop.put("compareyacy", post != null && post.getBoolean("compare_yacy") ? 1 : 0);
|
||||
prop.putXML("thisaddress", thisaddress);
|
||||
prop.putXML("compareyacy_thisaddress", thisaddress);
|
||||
prop.putXML("thisprotocol", thisprotocol);
|
||||
prop.putXML("compareyacy_thisprotocol", thisprotocol);
|
||||
prop.putXML("thisContext", thisContext);
|
||||
prop.putXML("compareyacy_thisContext", thisContext);
|
||||
prop.putXML("SearchPageGreeting", promoteSearchPageGreeting);
|
||||
prop.putXML("clientname", sb.peers.mySeed().getName());
|
||||
prop.putXML("compareyacy_search_left", post == null ? compare_yacy.defaultsearchL : post.get("left", compare_yacy.defaultsearchL));
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
xmlns:suggestions="http://www.opensearch.org/specifications/opensearch/extensions/suggestions/1.1">
|
||||
<ShortName>#(compareyacy)#::Compare #(/compareyacy)#YaCy '#[clientname]#'</ShortName>
|
||||
<LongName>YaCy.net - #[SearchPageGreeting]#</LongName>
|
||||
<Image type="image/gif">#[thisprotocol]#://#[thisaddress]#/env/grafics/yacy.png</Image>
|
||||
<Image type="image/gif">#[thisContext]#/env/grafics/yacy.png</Image>
|
||||
<Image width="16" height="16">data:image/x-icon;base64,AAABAAEAEBAAAAAAGABoAwAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD////////Chiu+fBm+fRq+fRq+fRq+fRq+fRq8ehXMmk////////////////////////////++exjUqGfZsnjYsXbYsXbYsXbZsnjTp2W+fBr///////////////////////////+9exfs2r/69/L58+z58+z58+z59e/z59bChSn///////////////////////////+9fBnnz638+fX69O369e748un38Ob59O3Ll0fVrGz////////////////////////Jk0HJlUjXuYrWt4jVtYPr28T58+r59OzPn1fPnlX////////////////////////Rolu8eRXCiTPEjTvCijbNnlj169359e7Zs3vLlkf////////////////////////UqmrAgSLt3MP27eH1693169327+T59Ozo0rG/gB////////////////////////////+/gCDv4Mn48+v38Of59Oz58+v48+vr2b2+fRv///////////////////////////+9ehXr17n58+z48ejo0bDp07T48+zx49DBhCj///////////////////////////+/fhzjyJ/59Oz59OzQoVvNmU759Oz58+vKlUbXrnH////////////////////////LlkfUqmn59Oz48+vZtHzNm1D48+v59OzPoFjOnlX////////////////////////OnVPOnFL59e348+vq1rnEiC7u38j69vDXsHTIkT3////////////////////////UqWjIkD327+T58+3s2bzAgSLp07T79/Pmzqq+fBn///////////////////////////+/fx7v4Mr7+PTx5NDHkD3kyqP8+vjs2r+9exf///////////////////////////++fBjQoFnVq2zTp2bGjTjJk0LWrW7SpWC+exf////////////////////////////Nm1C6dQy7eBG8eBK9exe8ehS7dxC6dQzLlkj////////////AH///wB8x+sAf///AD/+PwA///8AP///AD///4A9PU+APoz/gB///4AdxvOAHoz/gB3368AfjU/AHT1PwB/+P
|
||||
</Image>
|
||||
<Language>en-us</Language>
|
||||
|
@ -13,19 +13,19 @@
|
|||
<AdultContent>true</AdultContent>
|
||||
<Description>YaCy is an open-source GPL-licensed software that can be used for stand-alone search engine installations or as a client for a multi-user P2P-based web indexing cluster. This is the access to peer '#[clientname]#'.</Description>
|
||||
#(compareyacy)#
|
||||
<Url type="text/html" method="GET" template="#[thisprotocol]#://#[thisaddress]#/yacysearch.html?query={searchTerms}&startRecord={startIndex?}&maximumRecords={count?}&nav=all&resource=global" />
|
||||
<Url type="application/rss+xml" method="GET" template="#[thisprotocol]#://#[thisaddress]#/yacysearch.rss?nav=&query={searchTerms}&startRecord={startIndex?}&maximumRecords={count?}&nav=all&resource=global" />
|
||||
<Url type="application/atom+xml" method="GET" template="#[thisprotocol]#://#[thisaddress]#/yacysearch.atom?query={searchTerms}&startRecord={startIndex?}&maximumRecords={count?}&resource=global" />
|
||||
<Url type="text/html" method="GET" template="#[thisContext]#/yacysearch.html?query={searchTerms}&startRecord={startIndex?}&maximumRecords={count?}&nav=all&resource=global" />
|
||||
<Url type="application/rss+xml" method="GET" template="#[thisContext]#/yacysearch.rss?nav=&query={searchTerms}&startRecord={startIndex?}&maximumRecords={count?}&nav=all&resource=global" />
|
||||
<Url type="application/atom+xml" method="GET" template="#[thisContext]#/yacysearch.atom?query={searchTerms}&startRecord={startIndex?}&maximumRecords={count?}&resource=global" />
|
||||
::
|
||||
<Url type="text/html" method="GET" template="#[thisprotocol]#://#[thisaddress]#/compare_yacy.html?query={searchTerms}&left=#[search_left]#&right=#[search_right]#&display=2" />
|
||||
<Url type="text/html" method="GET" template="#[thisContext]#/compare_yacy.html?query={searchTerms}&left=#[search_left]#&right=#[search_right]#&display=2" />
|
||||
#(/compareyacy)#
|
||||
<Url type="application/x-suggestions+json" template="#[thisprotocol]#://#[thisaddress]#/suggest.json?query={searchTerms}"/>
|
||||
<Url type="application/x-suggestions+xml" template="#[thisprotocol]#://#[thisaddress]#/suggest.xml?query={searchTerms}"/>
|
||||
<Url type="application/x-suggestions+json" template="#[thisContext]#/suggest.json?query={searchTerms}"/>
|
||||
<Url type="application/x-suggestions+xml" template="#[thisContext]#/suggest.xml?query={searchTerms}"/>
|
||||
<!-- syntax according to http://www.loc.gov/standards/sru/. Set verify=true to get snippets in the search results -->
|
||||
<Developer>See https://github.com/orgs/yacy/teams/yacy_developers</Developer>
|
||||
<Query role="example" searchTerms="yacy+free+software" />
|
||||
<Tags>YaCy Free Software Open Source P2P Peer-to-Peer Uncensored Distributed Web Search Engine</Tags>
|
||||
<Contact>See #[thisprotocol]#://#[thisaddress]#/ViewProfile.html?hash=localhash</Contact>
|
||||
<Contact>See #[thisContext]#/ViewProfile.html?hash=localhash</Contact>
|
||||
<Attribution>http://yacy.net YaCy Software &copy; 2004-2014 by Michael Christen et al., YaCy.net; Content: ask peer owner</Attribution>
|
||||
<SyndicationRight>open</SyndicationRight>
|
||||
</OpenSearchDescription>
|
||||
|
|
|
@ -62,6 +62,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import net.yacy.cora.date.GenericFormatter;
|
||||
import net.yacy.cora.document.analysis.Classification;
|
||||
import net.yacy.cora.order.Base64Order;
|
||||
import net.yacy.cora.protocol.Domains;
|
||||
import net.yacy.cora.protocol.HeaderFramework;
|
||||
import net.yacy.cora.protocol.RequestHeader;
|
||||
import net.yacy.cora.util.ByteBuffer;
|
||||
|
@ -693,6 +694,46 @@ public class YaCyDefaultServlet extends HttpServlet {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL base for this peer, determined from request header when present. Use this when absolute URL rendering is required,
|
||||
* otherwise relative URLs should be preferred.
|
||||
* @param header request header.
|
||||
* @param sb Switchboard instance.
|
||||
* @return the application context (URL request base) from request header or default configuration. This is
|
||||
* either http://hostname:port or https://hostname:sslport
|
||||
*/
|
||||
public static String getContext(final RequestHeader header, final Switchboard sb) {
|
||||
String hostAndPort = null;
|
||||
if(header != null) {
|
||||
hostAndPort = header.get(HeaderFramework.HOST);
|
||||
}
|
||||
String protocol = "http";
|
||||
if (hostAndPort == null) {
|
||||
if(sb != null) {
|
||||
hostAndPort = Domains.LOCALHOST + ":" + sb.getConfigInt("port", 8090);
|
||||
} else {
|
||||
hostAndPort = Domains.LOCALHOST + ":8090";
|
||||
}
|
||||
} else {
|
||||
final String sslport;
|
||||
if(sb != null) {
|
||||
sslport = ":" + sb.getConfigInt("port.ssl", 8443);
|
||||
} else {
|
||||
sslport = ":8443";
|
||||
}
|
||||
if (hostAndPort.endsWith(sslport)) { // connection on ssl port, use https protocol
|
||||
protocol = "https";
|
||||
}
|
||||
}
|
||||
/* YaCyDefaultServelt should have filled this custom header, making sure we know here whether original request is http or https
|
||||
* (when default ports (80 and 443) are used, there is no way to distinguish the two schemes relying only on the Host header) */
|
||||
protocol = header.get(HeaderFramework.X_YACY_REQUEST_SCHEME, protocol);
|
||||
|
||||
/* Note : this implementation lets the responsibility to any eventual Reverse Proxy to eventually rewrite the rendered absolute URL */
|
||||
|
||||
return protocol + "://" + hostAndPort;
|
||||
}
|
||||
|
||||
protected RequestHeader generateLegacyRequestHeader(HttpServletRequest request, String target, String targetExt) {
|
||||
RequestHeader legacyRequestHeader = convertHeaderFromJetty(request);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user