Mercurial Hosting > luan
comparison src/luan/host/Util.luan @ 1394:8fe777ba5045
change postgres password
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 08 Sep 2019 22:13:08 -0600 |
parents | f5368cd8c056 |
children | a5f61890ad84 |
comparison
equal
deleted
inserted
replaced
1393:cc0dbca576dc | 1394:8fe777ba5045 |
---|---|
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 Hosting = require "luan:host/Hosting.luan" |
13 local Sql = require "luan:sql/Sql.luan" | |
14 local database = Sql.database or error() | |
15 local Logging = require "luan:logging/Logging.luan" | |
16 local logger = Logging.logger "Util" | |
13 | 17 |
14 require "java" | 18 require "java" |
15 local Base64 = require "java:java.util.Base64" | 19 local Base64 = require "java:java.util.Base64" |
16 local MessageDigest = require "java:java.security.MessageDigest" | 20 local MessageDigest = require "java:java.security.MessageDigest" |
17 | 21 |
42 local file = Io.schemes.file(dir.."/password.nginx") | 46 local file = Io.schemes.file(dir.."/password.nginx") |
43 file.delete() | 47 file.delete() |
44 file.write_text("admin:Restricted:"..encoded.."\n") | 48 file.write_text("admin:Restricted:"..encoded.."\n") |
45 end | 49 end |
46 | 50 |
47 function Util.write_password(domain,password) | 51 function Util.set_password(domain,password) |
48 local dir = Hosting.sites_dir..lower(domain) | 52 local dir = Hosting.sites_dir..lower(domain) |
49 local file = Io.schemes.file(dir.."/info.luan") | 53 local file = Io.schemes.file(dir.."/info.luan") |
50 file.delete() | 54 file.delete() |
51 file.write_text("return "..stringify{password=password}.."\n") | 55 file.write_text("return "..stringify{password=password}.."\n") |
52 digest_authentication(dir,password) | 56 digest_authentication(dir,password) |
57 | |
58 -- postgres | |
59 local fn = Luan.load_file("file:postgres.luan") or error() | |
60 local pg = fn() | |
61 if pg == nil then | |
62 return | |
63 end | |
64 local db = database(pg) | |
65 local exists = db.query("select rolname from pg_roles where rolname=?",domain)() ~= nil; | |
66 --logger.info("exists "..exists) | |
67 if exists then | |
68 db.update( [[alter role "]]..domain..[[" with encrypted password ']]..password..[[']] ) | |
69 end | |
70 db.close() | |
53 end | 71 end |
54 | 72 |
55 return Util | 73 return Util |