9684047874667451e47229f16b5c9eab60286850
braney
Sat Apr 11 12:15:39 2015 -0700
change mirror redirect to be opt-in.
diff --git src/hg/lib/web.c src/hg/lib/web.c
index fd5a2fc..9f3bd44 100644
--- src/hg/lib/web.c
+++ src/hg/lib/web.c
@@ -221,62 +221,30 @@
{
puts("
");
}
puts("" "\n"
"" "\n" );
}
/* Put up the hot links bar. */
char *menuStr = menuBar(theCart, db);
if(menuStr)
{
puts(menuStr);
}
-if (endsWith(scriptName, "hgGateway") && geoMirrorEnabled())
- {
- // Show an opt-out alert if user is on a host to which user has been automatically redirected (just once, right after they have been redirected)
- char *source = cgiOptionalString("source");
- char *redirect = cgiOptionalString("redirect");
- if (source != NULL && redirect != NULL && sameString(redirect, "auto"))
- {
- char *domain = cgiServerName();
- char *port = cgiServerPort();
- // We don't bother maintaining stuff in request URI, because it may contain items like hgsid and other host specific values
- int newUriSize = 2048;
- char *newUri = needMem(newUriSize);
- safef(newUri, newUriSize, "http%s://%s:%s/cgi-bin/hgGateway?redirect=manual&source=%s",
- cgiServerHttpsIsOn() ? "s" : "", source, port, domain);
-
- printf("
"
- ""
- " "
- " You've been redirected to your nearest mirror - %s"
- "[x]"
- " "
- " "
- " "
- " |
\n"
- , domain, newUri, source );
- }
- }
-
if(!skipSectionHeader)
/* this HTML must be in calling code if skipSectionHeader is TRUE */
{
webFirstSection(textOutBuf);
};
webPushErrHandlers();
/* set the flag */
webHeadAlreadyOutputed = TRUE;
} /* static void webStartWrapperDetailedInternal() */
void webStartWrapperDetailedArgs(struct cart *theCart, char *db,
char *headerText, char *format, va_list args, boolean withHttpHeader,
boolean withLogo, boolean skipSectionHeader, boolean withHtmlHeader)
/* output a CGI and HTML header with the given title in printf format */
{
@@ -1439,15 +1407,78 @@
}
// Don't overwrite any previously set defaults
if(!contextSpecificHelpLink && link)
contextSpecificHelpLink = link;
if(!contextSpecificHelpLabel && label)
contextSpecificHelpLabel = label;
}
if(contextSpecificHelpLink)
{
char buf[1024];
safef(buf, sizeof(buf), "%s", contextSpecificHelpLink, contextSpecificHelpLabel);
menuStr = replaceChars(menuStr, "", buf);
}
return menuStr;
}
+
+void checkForGeoMirrorRedirect(struct cart *cart)
+// Implement Geo/IP based redirection.
+{
+char *thisNodeStr = geoMirrorNode();
+if (thisNodeStr) // if geo-mirroring is enabled
+ {
+ char *redirectCookie = findCookieData("redirect");
+ char *redirect = cgiOptionalString("redirect");
+
+ // if we're not already redirected
+ if (redirect == NULL && redirectCookie == NULL)
+ {
+ int thisNode = sqlUnsigned(thisNodeStr);
+ struct sqlConnection *centralConn = hConnectCentral();
+ char *ipStr = cgiRemoteAddr();
+ int node = defaultNode(centralConn, ipStr);
+
+ // if our node is not the node that's closest.
+ if (thisNode != node)
+ {
+ char *geoSuffix = cfgOptionDefault("browser.geoSuffix","");
+ char query[1056];
+ sqlSafef(query, sizeof query, "select domain from gbNode%s where node = %d", geoSuffix, node);
+ char *newDomain = sqlQuickString(centralConn, query);
+ char *oldDomain = cgiServerName();
+ char *port = cgiServerPort();
+ char *uri = cgiRequestUri();
+ char *sep = strchr(uri, '?') ? "&" : "?";
+ int newUriSize = strlen(uri) + 1024;
+ char *newUri = needMem(newUriSize);
+ char *oldUri = needMem(newUriSize);
+ safef(oldUri, newUriSize, "http%s://%s:%s%s%sredirect=manual&source=%s",
+ cgiServerHttpsIsOn() ? "s" : "", oldDomain, port, uri, sep, oldDomain);
+ safef(newUri, newUriSize, "http%s://%s:%s%s%sredirect=manual&source=%s",
+ cgiServerHttpsIsOn() ? "s" : "", newDomain, port, uri, sep, oldDomain);
+ struct dyString *dy = dyStringNew(256);
+
+ cartCheckForCustomTracks(cart, dy);
+ printf(""
+ ""
+ " "
+ " You might want to navigate to your nearest mirror - %s"
+ "[x]"
+ " "
+ " "
+ "- Take me to %s"
+ "What is this?"
+ "
",
+ newDomain, newUri, newDomain);
+
+ printf("- Let me stay here %s"
+ "
"
+ " "
+ " |
\n",
+ oldUri, oldDomain );
+ printf("%s\n", dy->string);
+ exit(0);
+ }
+ hDisconnectCentral(¢ralConn);
+ }
+ }
+}