Mercurial Hosting > luan
changeset 1394:8fe777ba5045
change postgres password
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 08 Sep 2019 22:13:08 -0600 |
parents | cc0dbca576dc |
children | 9dfff82dfc59 |
files | src/luan/host/Util.luan src/luan/host/init.luan src/luan/host/main.luan |
diffstat | 3 files changed, 23 insertions(+), 5 deletions(-) [+] |
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
--- a/src/luan/host/init.luan Fri Sep 06 05:09:56 2019 -0600 +++ b/src/luan/host/init.luan Sun Sep 08 22:13:08 2019 -0600 @@ -89,7 +89,7 @@ } local db = database(pg) local exists = db.query("select datname from pg_database where datname=?",domain)() ~= nil; - logger.info("exists "..exists) + --logger.info("exists "..exists) if not exists then db.update( [[create user "]]..spec.user..[[" with encrypted password ']]..spec.password..[[']] ) db.update( [[create database "]]..domain..[[" owner "]]..spec.user..[["]] )
--- a/src/luan/host/main.luan Fri Sep 06 05:09:56 2019 -0600 +++ b/src/luan/host/main.luan Sun Sep 08 22:13:08 2019 -0600 @@ -17,7 +17,7 @@ local WebHandler = Hosting.WebHandler or error() local Util = require "classpath:luan/host/Util.luan" local read_password = Util.read_password or error() -local write_password = Util.write_password or error() +local set_password = Util.set_password or error() local sites_dir = Io.schemes.file(Hosting.sites_dir) @@ -104,7 +104,7 @@ local dir = sites_dir.child(domain) dir.exists() and error "already exists" dir.mkdir() - write_password(domain,password) + set_password(domain,password) dir = dir.child("site") dir.mkdir() return { name = dir.name(), path = dir.to_string(), children = {} } @@ -179,7 +179,7 @@ function fns.change_password(domain,old_password,new_password) local site_dir = get_dir(domain,old_password) site_dir or error "domain not found" - write_password(domain,new_password) + set_password(domain,new_password) WebHandler.removeHandler(domain) WebHandler.loadHandler(domain) end