comparison src/luan/host/Util.luan @ 1382:9604579c1c9b

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 29 Jul 2019 09:50:14 -0600
parents 8d95711f6615
children f5368cd8c056
comparison
equal deleted inserted replaced
1381:8d7a39ca2c0c 1382:9604579c1c9b
24 end 24 end
25 25
26 local function basic_authentication(dir,password) 26 local function basic_authentication(dir,password)
27 local sha1 = MessageDigest.getInstance("SHA1").digest(password.getBytes()) 27 local sha1 = MessageDigest.getInstance("SHA1").digest(password.getBytes())
28 local encoded = Base64.getEncoder().encodeToString(sha1) 28 local encoded = Base64.getEncoder().encodeToString(sha1)
29 Io.schemes.file(dir.."/password.nginx").write_text( %> 29 local file = Io.schemes.file(dir.."/password.nginx")
30 file.delete()
31 file.write_text( %>
30 admin:{SHA}<%=encoded%> 32 admin:{SHA}<%=encoded%>
31 <% ) 33 <% )
32 end 34 end
33 35
34 local function digest_authentication(dir,password) 36 local function digest_authentication(dir,password)
37 md5 = {bytes(md5,1,#md5)} 39 md5 = {bytes(md5,1,#md5)}
38 local encoded = "" 40 local encoded = ""
39 for _, n in ipairs(md5) do 41 for _, n in ipairs(md5) do
40 encoded = encoded..format("%02x",n) 42 encoded = encoded..format("%02x",n)
41 end 43 end
42 Io.schemes.file(dir.."/password.nginx").write_text( %> 44 local file = Io.schemes.file(dir.."/password.nginx")
45 file.delete()
46 file.write_text( %>
43 admin:Restricted:<%=encoded%> 47 admin:Restricted:<%=encoded%>
44 <% ) 48 <% )
45 end 49 end
46 50
47 function Util.write_password(domain,password) 51 function Util.write_password(domain,password)
48 local dir = Hosting.sites_dir..lower(domain) 52 local dir = Hosting.sites_dir..lower(domain)
49 Io.schemes.file(dir.."/info.luan").write_text( %> 53 local file = Io.schemes.file(dir.."/info.luan")
54 file.delete()
55 file.write_text( %>
50 return <%= stringify{password=password} %> 56 return <%= stringify{password=password} %>
51 <% ) 57 <% )
52 digest_authentication(dir,password) 58 digest_authentication(dir,password)
53 end 59 end
54 60