diff src/luan/host/Util.luan @ 1611:f67f972bd648

make postgres.luan optional
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 15 May 2021 17:24:07 -0600
parents 04615093b19d
children cf9dfead83a3
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)