Mercurial Hosting > luan
comparison src/luan/host/Util.luan @ 1418:732b5de211fc
add Hosted.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 18 Oct 2019 22:29:46 -0600 |
parents | db57d562c4bd |
children | 60f6741f000a |
comparison
equal
deleted
inserted
replaced
1417:c7f9dd062eda | 1418:732b5de211fc |
---|---|
7 local String = require "luan:String.luan" | 7 local String = require "luan:String.luan" |
8 local lower = String.lower or error() | 8 local lower = String.lower or error() |
9 local format = String.format or error() | 9 local format = String.format or error() |
10 local Binary = require "luan:Binary.luan" | 10 local Binary = require "luan:Binary.luan" |
11 local bytes = Binary.byte or error() | 11 local bytes = Binary.byte or error() |
12 local Hosting = require "luan:host/Hosting.luan" | 12 local Hosted = require "luan:host/Hosted.luan" |
13 local Sql = require "luan:sql/Sql.luan" | 13 local Sql = require "luan:sql/Sql.luan" |
14 local database = Sql.database or error() | 14 local database = Sql.database or error() |
15 local Logging = require "luan:logging/Logging.luan" | 15 local Logging = require "luan:logging/Logging.luan" |
16 local logger = Logging.logger "Util" | 16 local logger = Logging.logger "Util" |
17 | 17 |
22 | 22 |
23 local Util = {} | 23 local Util = {} |
24 | 24 |
25 function Util.read_password(domain) | 25 function Util.read_password(domain) |
26 domain = lower(domain) | 26 domain = lower(domain) |
27 return do_file(Hosting.sites_dir..domain.."/info.luan").password or error() | 27 return do_file(Hosted.sites_dir..domain.."/info.luan").password or error() |
28 end | 28 end |
29 | 29 |
30 local function basic_authentication(dir,password) | 30 local function basic_authentication(dir,password) |
31 local sha1 = MessageDigest.getInstance("SHA1").digest(password.getBytes()) | 31 local sha1 = MessageDigest.getInstance("SHA1").digest(password.getBytes()) |
32 local encoded = Base64.getEncoder().encodeToString(sha1) | 32 local encoded = Base64.getEncoder().encodeToString(sha1) |
47 file.delete() | 47 file.delete() |
48 file.write_text("admin:Restricted:"..encoded.."\n") | 48 file.write_text("admin:Restricted:"..encoded.."\n") |
49 end | 49 end |
50 | 50 |
51 function Util.set_password(domain,password) | 51 function Util.set_password(domain,password) |
52 local dir = Hosting.sites_dir..lower(domain) | 52 local dir = Hosted.sites_dir..lower(domain) |
53 local file = Io.schemes.file(dir.."/info.luan") | 53 local file = Io.schemes.file(dir.."/info.luan") |
54 file.delete() | 54 file.delete() |
55 file.write_text("return "..stringify{password=password}.."\n") | 55 file.write_text("return "..stringify{password=password}.."\n") |
56 digest_authentication(dir,password) | 56 digest_authentication(dir,password) |
57 end | 57 end |