d81a994fc5b713f0bafc32923e44d29c872c720b
angie
  Fri Jul 29 16:18:55 2016 -0700
Added a new hg.conf setting, login.https, so that mirror sites can turn off https for hgLogin if they don't support https (they really should).  refs #17778 note-7

diff --git src/hg/lib/wikiLink.c src/hg/lib/wikiLink.c
index dce10b3..0ce09ab 100644
--- src/hg/lib/wikiLink.c
+++ src/hg/lib/wikiLink.c
@@ -28,30 +28,45 @@
 return FALSE;
 #endif
 }
 
 char *wikiLinkHost()
 /* Return the wiki host specified in hg.conf, or NULL.  Allocd here. 
  * Returns hostname from http request if hg.conf entry is HTTPHOSTNAME.
  * */
 {
 char *wikiHost = cfgOption(CFG_WIKI_HOST);
 if ((wikiHost!=NULL) && sameString(wikiHost, "HTTPHOST"))
     wikiHost = hHttpHost();
 return cloneString(wikiHost);
 }
 
+boolean loginUseHttps()
+/* Return TRUE unless https is disabled in hg.conf. */
+{
+return cfgOptionBooleanDefault(CFG_LOGIN_USE_HTTPS, TRUE);
+}
+
+static char *loginUrl()
+/* Return the URL for the login host. */
+{
+char buf[2048];
+safef(buf, sizeof(buf), "http%s://%s/cgi-bin/hgLogin",
+      loginUseHttps() ? "s" : "", wikiLinkHost());
+return cloneString(buf);
+}
+
 boolean wikiLinkEnabled()
 /* Return TRUE if all wiki.* parameters are defined in hg.conf . */
 {
 return ((cfgOption(CFG_WIKI_HOST) != NULL) &&
 	(cfgOption(CFG_WIKI_USER_NAME_COOKIE) != NULL) &&
 	(cfgOption(CFG_WIKI_LOGGED_IN_COOKIE) != NULL));
 }
 
 static char *wikiLinkUserNameCookie()
 /* Return the cookie name specified in hg.conf as the wiki user name cookie. */
 {
 return cfgOption(CFG_WIKI_USER_NAME_COOKIE);
 }
 
 static char *wikiLinkLoggedInCookie()
@@ -90,32 +105,32 @@
 return cgiEncode(retBuf);
 }
 
 
 
 char *wikiLinkUserLoginUrlReturning(char *hgsid, char *returnUrl)
 /* Return the URL for the wiki user login page. */
 {
 char buf[2048];
 if (loginSystemEnabled())
     {
     if (! wikiLinkEnabled())
         errAbort("wikiLinkUserLoginUrl called when login system is not enabled "
            "(specified in hg.conf).");
     safef(buf, sizeof(buf),
-        "https://%s/cgi-bin/hgLogin?hgLogin.do.displayLoginPage=1&returnto=%s",
-        wikiLinkHost(), returnUrl);
+        "%s?hgLogin.do.displayLoginPage=1&returnto=%s",
+        loginUrl(), returnUrl);
     } 
 else 
     {
     if (! wikiLinkEnabled())
         errAbort("wikiLinkUserLoginUrl called when wiki is not enabled (specified "
             "in hg.conf).");
     safef(buf, sizeof(buf),
         "http://%s/index.php?title=Special:UserloginUCSC&returnto=%s",
         wikiLinkHost(), returnUrl);
     }   
 return(cloneString(buf));
 }
 
 char *wikiLinkUserLoginUrl(char *hgsid)
 /* Return the URL for the wiki user login page with return going to hgSessions. */
@@ -124,32 +139,32 @@
 char *result = wikiLinkUserLoginUrlReturning(hgsid, retUrl);
 freez(&retUrl);
 return result;
 }
 
 char *wikiLinkUserLogoutUrlReturning(char *hgsid, char *returnUrl)
 /* Return the URL for the wiki user logout page. */
 {
 char buf[2048];
 if (loginSystemEnabled())
     {
     if (! wikiLinkEnabled())
         errAbort("wikiLinkUserLogoutUrl called when login system is not enabled "
             "(specified in hg.conf).");
     safef(buf, sizeof(buf),
-        "https://%s/cgi-bin/hgLogin?hgLogin.do.displayLogout=1&returnto=%s",
-        wikiLinkHost(), returnUrl);
+        "%s?hgLogin.do.displayLogout=1&returnto=%s",
+        loginUrl(), returnUrl);
     } 
 else
     {
     if (! wikiLinkEnabled())
         errAbort("wikiLinkUserLogoutUrl called when wiki is not enable (specified "
             "in hg.conf).");
     safef(buf, sizeof(buf),
         "http://%s/index.php?title=Special:UserlogoutUCSC&returnto=%s",
          wikiLinkHost(), returnUrl);
     }
 return(cloneString(buf));
 }
 
 char *wikiLinkUserLogoutUrl(char *hgsid)
 /* Return the URL for the wiki user logout page that returns to hgSessions. */
@@ -160,59 +175,59 @@
 return result;
 }
 
 char *wikiLinkUserSignupUrl(char *hgsid)
 /* Return the URL for the user signup  page. */
 {
 char buf[2048];
 char *retEnc = encodedHgSessionReturnUrl(hgsid);
 
 if (loginSystemEnabled())
     {
     if (! wikiLinkEnabled())
         errAbort("wikiLinkUserSignupUrl called when login system is not enabled "
             "(specified in hg.conf).");
     safef(buf, sizeof(buf),
-        "https://%s/cgi-bin/hgLogin?hgLogin.do.signupPage=1&returnto=%s",
-        wikiLinkHost(), retEnc);
+        "%s?hgLogin.do.signupPage=1&returnto=%s",
+        loginUrl(), retEnc);
     }
 else
     {
     if (! wikiLinkEnabled())
         errAbort("wikiLinkUserLogoutUrl called when wiki is not enable (specified "
             "in hg.conf).");
     safef(buf, sizeof(buf),
         "http://%s/index.php?title=Special:UserlogoutUCSC&returnto=%s",
          wikiLinkHost(), retEnc);
     }
 freez(&retEnc);
 return(cloneString(buf));
 }
 
 char *wikiLinkChangePasswordUrl(char *hgsid)
 /* Return the URL for the user change password page. */
 {
 char buf[2048];
 char *retEnc = encodedHgSessionReturnUrl(hgsid);
 
 if (loginSystemEnabled())
     {
     if (! wikiLinkEnabled())
         errAbort("wikiLinkChangePasswordUrl called when login system is not enabled "
             "(specified in hg.conf).");
     safef(buf, sizeof(buf),
-        "https://%s/cgi-bin/hgLogin?hgLogin.do.changePasswordPage=1&returnto=%s",
-        wikiLinkHost(), retEnc);
+        "%s?hgLogin.do.changePasswordPage=1&returnto=%s",
+        loginUrl(), retEnc);
     }
 else
     {
     if (! wikiLinkEnabled())
         errAbort("wikiLinkUserLogoutUrl called when wiki is not enable (specified "
             "in hg.conf).");
     safef(buf, sizeof(buf),
         "http://%s/index.php?title=Special:UserlogoutUCSC&returnto=%s",
          wikiLinkHost(), retEnc);
     }
 freez(&retEnc);
 return(cloneString(buf));
 }