Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- a/src/luan/host/Util.luan Fri Sep 06 05:09:56 2019 -0600 +++ b/src/luan/host/Util.luan Sun Sep 08 22:13:08 2019 -0600 @@ -10,6 +10,10 @@ local Binary = require "luan:Binary.luan" local bytes = Binary.byte or error() local Hosting = require "luan:host/Hosting.luan" +local Sql = require "luan:sql/Sql.luan" +local database = Sql.database or error() +local Logging = require "luan:logging/Logging.luan" +local logger = Logging.logger "Util" require "java" local Base64 = require "java:java.util.Base64" @@ -44,12 +48,26 @@ file.write_text("admin:Restricted:"..encoded.."\n") end -function Util.write_password(domain,password) +function Util.set_password(domain,password) local dir = Hosting.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) + + -- postgres + local fn = Luan.load_file("file:postgres.luan") or error() + local pg = fn() + if pg == nil then + return + end + local db = database(pg) + local exists = db.query("select rolname from pg_roles where rolname=?",domain)() ~= nil; + --logger.info("exists "..exists) + if exists then + db.update( [[alter role "]]..domain..[[" with encrypted password ']]..password..[[']] ) + end + db.close() end return Util