Commit 89d58217 authored by Ted Trask's avatar Ted Trask

Add ability to view/modify databases using acf-db-lib

parent 837cb215
......@@ -25,6 +25,9 @@ dist: $(tarball)
install:
mkdir -p "$(install_dir)"
cp -a $(APP_DIST) "$(install_dir)"
for i in $$(ls -1 $(DESTDIR)/$(acflibdir)/db-*.lsp); do\
ln -sf $$i $(install_dir)/$$(echo "$$(basename $$i)" | sed "s/db/$(APP_NAME)/");\
done
$(tarball): $(DISTFILES)
rm -rf $(P)
......
......@@ -28,4 +28,10 @@ function mymodule.expert(self)
return self.handle_form(self, function() return self.model.getfiledetails(self.clientdata.filename) end, self.model.updatefiledetails, self.clientdata, "Save", "Edit Postgresql File", "File Saved")
end
-- Use acf-db to allow editing of the database
dbcontrollerfunctions = require("dbcontrollerfunctions")
for n,f in pairs(dbcontrollerfunctions) do
mymodule[n] = f
end
return mymodule
......@@ -4,9 +4,12 @@ local mymodule = {}
modelfunctions = require("modelfunctions")
fs = require("acf.fs")
format = require("acf.format")
db = require("acf.db")
dbmodelfunctions = require("dbmodelfunctions")
-- Set variables
local confdfile = "/etc/conf.d/postgresql"
local conffile = "postgresql.conf"
local processname = "postgresql"
local packagename = "postgresql"
......@@ -14,6 +17,7 @@ local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
local datadirectory
local filelist
local confcontent
function mymodule.set_processname(p)
processname = p
......@@ -25,12 +29,42 @@ end
local determinefilelist = function()
if not filelist then
datadirectory = format.get_ini_entry(fs.read_file(confdfile) or "", "", "PGDATA")
datadirectory = datadirectory or format.get_ini_entry(fs.read_file(confdfile) or "", "", "PGDATA")
filelist = fs.find_files_as_array(".*%.conf", datadirectory)
end
return filelist
end
local getconfvalue = function(param)
datadirectory = datadirectory or format.get_ini_entry(fs.read_file(confdfile) or "", "", "PGDATA")
confcontent = confcontent or fs.read_file(datadirectory.."/"..conffile) or ""
conftable = conftable or format.parse_configfile(confcontent)
local val
if conftable then
val = conftable[param]
end
if val then
-- Remove starting '=', if present
val = string.match(val, "[ =]*(.*)")
-- Remove "'"
val = string.match(val, "[^']+")
end
return val
end
local determineconnection = function()
-- Determine the connection parameters from the config files
local listen_addresses = getconfvalue("listen_addresses")
if listen_addresses == "" or listen_addresses == "*" or listen_addresses == "localhost" then
listen_addresses = ""
elseif string.find(listen_addresses, "'") then
listen_addresses = string.match(listen_addresses, "[^']+")
end
local port = getconfvalue("port")
if not port then port = "5432" end
return db.create(db.engine.postgresql, nil, nil, nil, listen_addresses, port)
end
-- ################################################################################
-- PUBLIC FUNCTIONS
......@@ -71,4 +105,10 @@ function mymodule.updatefiledetails(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, determinefilelist())
end
for n,f in pairs(dbmodelfunctions) do
mymodule[n] = function(...)
return f(determineconnection, ...)
end
end
return mymodule
#CAT GROUP/DESC TAB ACTION
Applications 25Postgresql Status status
Applications 25Postgresql Expert listfiles
Applications 25Postgresql Databases listdatabases
Applications 25Postgresql Logfile logfile
USER=postgresql:status,postgresql:logfile,postgresql:details,postgresql:startstop
EXPERT=postgresql:listfiles,postgresql:expert
ADMIN=postgresql:status,postgresql:logfile,postgresql:details,postgresql:startstop,postgresql:listfiles,postgresql:expert
ADMIN=postgresql:status,postgresql:logfile,postgresql:details,postgresql:startstop,postgresql:listfiles,postgresql:expert,postgresql:listdatabases,postgresql:listtables,postgresql:viewtable,postgresql:deletetableentry,postgresql:updatetableentry,postgresql:createtableentry
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment