changeset 6:c4ed473452d4

better https support
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 22 Jul 2019 05:37:46 -0400
parents b74139388033
children a04508136174
files conf/Init.luan src/nabble/model/FileUpload.java src/nabble/model/Init.java src/nabble/model/SiteGlobal.java
diffstat 4 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
diff -r b74139388033 -r c4ed473452d4 conf/Init.luan
--- a/conf/Init.luan	Sun Jul 07 17:15:31 2019 -0600
+++ b/conf/Init.luan	Mon Jul 22 05:37:46 2019 -0400
@@ -65,6 +65,8 @@
 
 --Init.monitor_emails = {}  -- list of emails
 
+--Init.ssl_dir = nil
+
 
 -- for serve_nabble.luan
 
diff -r b74139388033 -r c4ed473452d4 src/nabble/model/FileUpload.java
--- a/src/nabble/model/FileUpload.java	Sun Jul 07 17:15:31 2019 -0600
+++ b/src/nabble/model/FileUpload.java	Mon Jul 22 05:37:46 2019 -0400
@@ -569,7 +569,7 @@
 				String filename = HtmlTag.unquote(tag.getAttributeValue("src"));
 				if( filename==null )
 					continue;
-				String url = getPath(filename,src);
+				String url = getUrl(filename,src);
 				tag.setAttribute("src",HtmlTag.quote(url));
 				tag.setName("img");
 			}
@@ -604,10 +604,6 @@
 		return FileDownload.url(filename,src);
 	}
 
-	static String getPath(String filename,Message.Source src) {
-		return FileDownload.path(filename,src);
-	}
-
 	public static void saveImage(BufferedImage image, String fileName, Message.Source src)
 			throws ModelException
 	{
diff -r b74139388033 -r c4ed473452d4 src/nabble/model/Init.java
--- a/src/nabble/model/Init.java	Sun Jul 07 17:15:31 2019 -0600
+++ b/src/nabble/model/Init.java	Mon Jul 22 05:37:46 2019 -0400
@@ -8,6 +8,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.ServerSocket;
@@ -150,6 +151,11 @@
 		return obj!=null ? obj : defaultVal;
 	}
 
+	public static String scheme(String domain) {
+		String sslDir = (String)get("ssl_dir");
+		return sslDir!=null && new File(sslDir+domain).exists() ? "https" : "http";
+	}
+
 	public static final boolean hasDaemons = nabble.utils.Jetty.isJetty;
 
 	public static final String tempDir = (String)Init.get("home_dir")+"local/temp/"; // General purpose folder
diff -r b74139388033 -r c4ed473452d4 src/nabble/model/SiteGlobal.java
--- a/src/nabble/model/SiteGlobal.java	Sun Jul 07 17:15:31 2019 -0600
+++ b/src/nabble/model/SiteGlobal.java	Mon Jul 22 05:37:46 2019 -0400
@@ -139,8 +139,8 @@
 
 	public String getBaseUrl() {
 		if( baseUrl == null ) {
-			baseUrl = "http://" +
-				(customDomain != null ? customDomain : Jtp.getDefaultBaseUrl(siteKey.site()));
+			String domain = customDomain != null ? customDomain : Jtp.getDefaultBaseUrl(siteKey.site());
+			baseUrl = Init.scheme(domain) + "://" + domain;
 		}
 		return baseUrl;
 	}