Mercurial Hosting > luan
view src/luan/host/Util.luan @ 1802:ca98dee04e08 default tip
add Parsers.json_null
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 21 Apr 2024 21:25:15 -0600 |
parents | 5c676385284b |
children |
line wrap: on
line source
local Luan = require "luan:Luan.luan" local error = Luan.error local do_file = Luan.do_file or error() local ipairs = Luan.ipairs or error() local stringify = Luan.stringify or error() local Package = require "luan:Package.luan" local Io = require "luan:Io.luan" local String = require "luan:String.luan" local lower = String.lower or error() local format = String.format or error() local to_binary = String.to_binary or error() local Binary = require "luan:Binary.luan" local bytes = Binary.byte or error() local base64_encode = Binary.base64_encode or error() local Hosted = require "luan:host/Hosted.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" local Util = {} function Util.read_password(domain) domain = lower(domain) return do_file(Hosted.sites_dir..domain.."/info.luan").password or error() end function Util.set_password(domain,password) local dir = Hosted.sites_dir..lower(domain) local file = Io.schemes.file(dir.."/info.luan") file.delete() file.write_text("return "..stringify{password=password}.."\n") end require "java" local WebHandler = require "java:luan.host.WebHandler" local pg_admin = WebHandler.config.postgres function Util.set_postgres_password(domain,password) if pg_admin == nil then return end local db = database(pg_admin) local exists = db.query("select rolname from pg_roles where rolname=?",domain).results() ~= nil; --logger.info("exists "..exists) if exists then db.update( [[alter role "]]..domain..[[" with encrypted password ']]..password..[[']] ) end db.close() end function Util.check_postgres_password(domain,password) if pg_admin == nil then return end local db = database(pg_admin) local exists = db.query("select rolname from pg_roles where rolname=?",domain).results() ~= nil; db.close() if exists then db = database{ class = "org.postgresql.Driver" url = "jdbc:postgresql://localhost:5432/"..domain user = domain password = password } db.close() end end return Util