changeset 1611:f67f972bd648

make postgres.luan optional
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 15 May 2021 17:24:07 -0600
parents 94ea190714dd
children 8852f34a646a
files src/luan/host/Util.luan src/luan/host/init.luan
diffstat 2 files changed, 7 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/host/Util.luan	Thu May 13 17:26:34 2021 -0600
+++ b/src/luan/host/Util.luan	Sat May 15 17:24:07 2021 -0600
@@ -3,6 +3,7 @@
 local do_file = Luan.do_file or error()
 local ipairs = Luan.ipairs or error()
 local stringify = Luan.stringify or error()
+local Package = require "luan:Package.luan"
 local Io = require "luan:Io.luan"
 local String = require "luan:String.luan"
 local lower = String.lower or error()
@@ -26,40 +27,17 @@
 	return do_file(Hosted.sites_dir..domain.."/info.luan").password or error()
 end
 
-local function basic_authentication(dir,password)
-	local sha1 = digest_message("SHA1",to_binary(password))
-	local encoded = base64_encode(sha1)
-	local file = Io.schemes.file(dir.."/password.nginx")
-	file.delete()
-	file.write_text("admin:{SHA}"..encoded.."\n")
-end
-
-local function digest_authentication(dir,password)
-	local s = "admin:Restricted:"..password
-	local md5 = digest_message("MD5",to_binary(s))
-	md5 = {bytes(md5,1,#md5)}
-	local encoded = ""
-	for _, n in ipairs(md5) do
-		encoded = encoded..format("%02x",n)
-	end
-	local file = Io.schemes.file(dir.."/password.nginx")
-	file.delete()
-	file.write_text("admin:Restricted:"..encoded.."\n")
-end
-
 function Util.set_password(domain,password)
 	local dir = Hosted.sites_dir..lower(domain)
 	local file = Io.schemes.file(dir.."/info.luan")
 	file.delete()
 	file.write_text("return "..stringify{password=password}.."\n")
-	digest_authentication(dir,password)
 end
 
-local fn = Luan.load_file("file:postgres.luan") or error()
-local pg_admin = fn()
+local pg_admin = Package.load("file:postgres.luan")
 
 function Util.set_postgres_password(domain,password)
-	if pg_admin == nil then
+	if pg_admin == false then
 		return
 	end
 	local db = database(pg_admin)
@@ -72,7 +50,7 @@
 end
 
 function Util.check_postgres_password(domain,password)
-	if pg_admin == nil then
+	if pg_admin == false then
 		return
 	end
 	local db = database(pg_admin)
--- a/src/luan/host/init.luan	Thu May 13 17:26:34 2021 -0600
+++ b/src/luan/host/init.luan	Sat May 15 17:24:07 2021 -0600
@@ -1,6 +1,7 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
 local do_file = Luan.do_file or error()
+local Package = require "luan:Package.luan"
 local String = require "luan:String.luan"
 local gsub = String.gsub or error()
 local Number = require "luan:Number.luan"
@@ -72,11 +73,10 @@
 local Logging = require "luan:logging/Logging.luan"
 local logger = Logging.logger "init"
 
-local fn = Luan.load_file("file:postgres.luan") or error()
-local pg = fn()
+local pg = Package.load("file:postgres.luan")
 
 function Hosted.postgres_spec()
-	if pg == nil then
+	if pg == false then
 		return nil
 	end
 	local spec = {