Mercurial Hosting > luan
comparison src/luan/host/Util.luan @ 1396:a5f61890ad84
add check_postgres_password
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 10 Sep 2019 13:41:22 -0600 |
parents | 8fe777ba5045 |
children | 1979cff9aad2 |
comparison
equal
deleted
inserted
replaced
1395:9dfff82dfc59 | 1396:a5f61890ad84 |
---|---|
52 local dir = Hosting.sites_dir..lower(domain) | 52 local dir = Hosting.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 | 58 |
58 -- postgres | 59 local fn = Luan.load_file("file:postgres.luan") or error() |
59 local fn = Luan.load_file("file:postgres.luan") or error() | 60 local pg_admin = fn() |
60 local pg = fn() | 61 |
61 if pg == nil then | 62 function Util.set_postgres_password(domain,password) |
63 if pg_admin == nil then | |
62 return | 64 return |
63 end | 65 end |
64 local db = database(pg) | 66 local db = database(pg_admin) |
65 local exists = db.query("select rolname from pg_roles where rolname=?",domain)() ~= nil; | 67 local exists = db.query("select rolname from pg_roles where rolname=?",domain)() ~= nil; |
66 --logger.info("exists "..exists) | 68 --logger.info("exists "..exists) |
67 if exists then | 69 if exists then |
68 db.update( [[alter role "]]..domain..[[" with encrypted password ']]..password..[[']] ) | 70 db.update( [[alter role "]]..domain..[[" with encrypted password ']]..password..[[']] ) |
69 end | 71 end |
70 db.close() | 72 db.close() |
71 end | 73 end |
72 | 74 |
75 function Util.check_postgres_password(domain,password) | |
76 if pg_admin == nil then | |
77 return | |
78 end | |
79 local db = database{ | |
80 class = "org.postgresql.Driver" | |
81 url = "jdbc:postgresql://localhost:5432/"..domain | |
82 user = domain | |
83 password = password | |
84 } | |
85 db.close() | |
86 end | |
87 | |
73 return Util | 88 return Util |