Skip to content

Commit

Permalink
Merge pull request #67 from luccioman/mixedcontent
Browse files Browse the repository at this point in the history
Fixed HTTPS  mixed content warnings and errors
  • Loading branch information
reger24 committed Aug 19, 2016
2 parents 91ab8a5 + f84e584 commit 28a608c
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 43 deletions.
6 changes: 3 additions & 3 deletions htroot/ConfigPortal.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h3>
</pre></fieldset>
This would look like:
<iframe name="target"
src="http://#[myPreviewAddress]#/index.html?display=2&amp;resource=local&amp;focus=0"
src="#[myPreviewProtocol]#://#[myPreviewAddress]#/index.html?display=2&amp;resource=local&amp;focus=0"
width="100%"
height="410"
frameborder="0"
Expand All @@ -169,7 +169,7 @@ <h3>
</pre></fieldset>
This would look like:
<iframe name="target2"
src="http://#[myPreviewAddress]#/yacysearch.html?display=2&amp;resource=local&amp;focus=0"
src="#[myPreviewProtocol]#://#[myPreviewAddress]#/yacysearch.html?display=2&amp;resource=local&amp;focus=0"
width="100%"
height="180"
frameborder="0"
Expand All @@ -193,7 +193,7 @@ <h3>
</pre></fieldset>
This would look like:
<iframe name="target3"
src="http://#[myPreviewAddress]#/yacyinteractive.html?display=2&amp;focus=0"
src="#[myPreviewProtocol]#://#[myPreviewAddress]#/yacyinteractive.html?display=2&amp;focus=0"
width="100%"
height="180"
frameborder="0"
Expand Down
23 changes: 18 additions & 5 deletions htroot/ConfigPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
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;
Expand Down Expand Up @@ -224,19 +226,30 @@ public static serverObjects respond(final RequestHeader header, final serverObje
prop.put("target_selected_special_searchresult", "searchresult".equals(target_special) ? 1 : 0);
prop.put("target_special_pattern", sb.getConfig(SwitchboardConstants.SEARCH_TARGET_SPECIAL_PATTERN, ""));

/* Addresse used in code template */
/* 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());
if (myaddress == null) {
myaddress = "localhost:" + sb.getLocalPort();
}
prop.put("myaddress", myaddress);

/* Adress used to display iframe preview : no need to use public adress when coming from local */
String myPreviewAddress = myaddress;
if(header.accessFromLocalhost()) {
myPreviewAddress = "localhost:" + sb.getLocalPort();
/* 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);
return prop;
}

Expand Down
24 changes: 12 additions & 12 deletions htroot/compare_yacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ public class compare_yacy {
searchengines.put("YaCy (local)", "yacysearch.html?display=2&resource=local&query=");
//searchengines.put("google.com", "https://www.google.com/#q=");
searchengines.put("startpage.com", "https://startpage.com/do/search?cat=web&query=");
searchengines.put("bing.com", "http://www.bing.com/search?q=");
searchengines.put("metager.de", "http://www.metager.de/meta/cgi-bin/meta.ger1?eingabe=");
searchengines.put("metager2.de (web)", "http://www.metager2.de/search.php?ses=web&q=");
searchengines.put("metager2.de (international)", "http://www.metager2.de/search.php?ses=international&q=");
searchengines.put("yahoo.com", "http://search.yahoo.com/search?p=");
//searchengines.put("romso.de", "http://romso.de/?q="); // no serach service 2016-01-02
searchengines.put("Wikipedia English", "http://en.wikipedia.org/wiki/");
searchengines.put("Wikipedia Deutsch", "http://de.wikipedia.org/wiki/");
searchengines.put("Sciencenet", "http://sciencenet.fzk.de:8080/yacysearch.html?verify=true&resource=global&nav=all&display=2&meanCount=5&query=");
searchengines.put("bing.com", "https://www.bing.com/search?q=");
searchengines.put("metager.de", "https://www.metager.de/meta/cgi-bin/meta.ger1?eingabe=");
searchengines.put("metager2.de (web)", "https://www.metager2.de/search.php?ses=web&q=");
searchengines.put("metager2.de (international)", "https://www.metager2.de/search.php?ses=international&q=");
//searchengines.put("yahoo.com", "https://search.yahoo.com/search?p="); // no search service in iframe 2016-08-17 : "Load denied by X-Frame-Options: does not permit cross-origin framing."
//searchengines.put("romso.de", "http://romso.de/?q="); // no search service 2016-01-02
searchengines.put("Wikipedia English", "https://en.wikipedia.org/wiki/");
searchengines.put("Wikipedia Deutsch", "https://de.wikipedia.org/wiki/");
//searchengines.put("Sciencenet", "http://sciencenet.fzk.de:8080/yacysearch.html?verify=true&resource=global&nav=all&display=2&meanCount=5&query="); // no search service 2016-08-17
//searchengines.put("dbpedia", "http://dbpedia.neofonie.de/browse/~:"); // no search service 2016-01-02
searchengines.put("wolfram alpha", "http://www.wolframalpha.com/input/?i=");
searchengines.put("OAIster@OCLC", "http://oaister.worldcat.org/search?q=");
searchengines.put("oai.yacy.net", "http://oai.yacy.net/yacysearch.html?verify=true&resource=local&nav=all&display=2&meanCount=5&query=");
searchengines.put("wolfram alpha", "https://www.wolframalpha.com/input/?i=");
searchengines.put("OAIster@OCLC", "https://oaister.worldcat.org/search?q=");
//searchengines.put("oai.yacy.net", "http://oai.yacy.net/yacysearch.html?verify=true&resource=local&nav=all&display=2&meanCount=5&query="); // no search service 2016-08-17
}

public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
Expand Down
87 changes: 64 additions & 23 deletions source/net/yacy/yacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,22 @@
import java.nio.channels.FileLock;
import java.util.Properties;
import java.util.concurrent.Semaphore;

import com.google.common.io.Files;

import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.federate.yacy.CacheStrategy;
import net.yacy.cora.order.Digest;
import net.yacy.cora.protocol.ClientIdentification;
import net.yacy.cora.protocol.ConnectionInfo;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.protocol.TimeoutRequest;
import net.yacy.cora.protocol.http.HTTPClient;
import net.yacy.cora.sorting.Array;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.crawler.retrieval.Response;
import net.yacy.document.Document;
import net.yacy.gui.YaCyApp;
import net.yacy.gui.framework.Browser;
import net.yacy.http.Jetty9HttpServerImpl;
Expand All @@ -54,17 +63,11 @@
import net.yacy.kelondro.util.Formatter;
import net.yacy.kelondro.util.MemoryControl;
import net.yacy.kelondro.util.OS;
import net.yacy.peers.Seed;
import net.yacy.peers.operation.yacyBuildProperties;
import net.yacy.peers.operation.yacyRelease;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
import com.google.common.io.Files;
import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.federate.yacy.CacheStrategy;
import net.yacy.cora.order.Digest;
import net.yacy.cora.protocol.ConnectionInfo;
import net.yacy.crawler.retrieval.Response;
import net.yacy.peers.Seed;
import net.yacy.server.serverSwitch;
import net.yacy.utils.translation.TranslatorXliff;

Expand Down Expand Up @@ -265,22 +268,7 @@ private static void startup(final File dataHome, final File appHome, final long
//final File htTemplatePath = new File(homePath, sb.getConfig("htTemplatePath","htdocs"));

// copy the donate iframe (better to copy this once here instead of doing this in an actual iframe in the search result)
final File wwwEnvPath = new File(htDocsPath, "env");
mkdirIfNeseccary(wwwEnvPath);
final String iframesource = sb.getConfig("donation.iframesource", "");
final String iframetarget = sb.getConfig("donation.iframetarget", "");
final File iframefile = new File(htDocsPath, iframetarget);
if (!iframefile.exists()) new Thread() {
@Override
public void run() {
final ClientIdentification.Agent agent = ClientIdentification.getAgent(ClientIdentification.yacyInternetCrawlerAgentName);
Response response;
try {
response = sb.loader == null ? null : sb.loader.load(sb.loader.request(new DigestURL(iframesource), false, true), CacheStrategy.NOCACHE, Integer.MAX_VALUE, null, agent);
if (response != null) FileUtils.copy(response.getContent(), iframefile);
} catch (Throwable e) {}
}
}.start();
importDonationIFrame(sb, htDocsPath);

// create default notifier picture
File notifierFile = new File(htDocsPath, "notifier.gif");
Expand Down Expand Up @@ -421,6 +409,59 @@ public void run() {
} catch (final Exception e) {} // was once stopped by de.anomic.net.ftpc$sm.checkExit(ftpc.java:1790)
}

/**
* Concurrently import the donation iframe content to serve it directly from this peer.
* @param switchBoard the SwitchBoard instance. Must not be null.
* @param htDocsDirectory the custom htdocs directory. Must not be null.
*/
private static void importDonationIFrame(final Switchboard switchBoard, final File htDocsDirectory) {
final File wwwEnvPath = new File(htDocsDirectory, "env");
mkdirIfNeseccary(wwwEnvPath);
final String iframesource = switchBoard.getConfig("donation.iframesource", "");
final String iframetarget = switchBoard.getConfig("donation.iframetarget", "");
final File iframefile = new File(htDocsDirectory, iframetarget);
if (!iframefile.exists()) new Thread() {
@Override
public void run() {
final ClientIdentification.Agent agent = ClientIdentification.getAgent(ClientIdentification.yacyInternetCrawlerAgentName);
Response documentResponse;
try {
/* Load the donation html frame content */
documentResponse = switchBoard.loader == null ? null : switchBoard.loader.load(switchBoard.loader.request(new DigestURL(iframesource), false, true), CacheStrategy.NOCACHE, Integer.MAX_VALUE, null, agent);
if (documentResponse != null) {
Document[] documents = documentResponse.parse();
if(documents != null && documents.length > 0 && documents[0] != null) {
Document donateDocument = documents[0];
String donateDocContent = new String(documentResponse.getContent(), donateDocument.getCharset());
/* Load image resources contained in the page */
if(donateDocument.getImages() != null) {
for(DigestURL imgURL : donateDocument.getImages().keySet()) {
try {
Response response = switchBoard.loader.load(switchBoard.loader.request(imgURL, false, true), CacheStrategy.NOCACHE, Integer.MAX_VALUE, null, agent);
if (response != null) {
String imgFileName = imgURL.getFileName();
/* Store each image in the same directory as the iframe target file */
FileUtils.copy(response.getContent(), new File(iframefile.getParentFile(), imgFileName));

/* Transform the original image URL to a relative one */
donateDocContent = donateDocContent.replace(imgURL.getURL().toString(), imgFileName);
}
} catch(IOException e) {
/* Failing to load one image should not stop the whole task */
ConcurrentLog.warn("STARTUP", "Donation frame retrieval : could not get an image resource.", e);
}
}
}
FileUtils.copy(donateDocContent.getBytes(donateDocument.getCharset()), iframefile);
}
}
} catch (Exception e) {
ConcurrentLog.warn("STARTUP", "Could not retrieve donation frame content.", e);
}
}
}.start();
}

/**
* @param f
*/
Expand Down

0 comments on commit 28a608c

Please sign in to comment.