summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2014-11-03 20:14:20 +0000
committerTed Trask <ttrask01@yahoo.com>2014-11-03 20:14:20 +0000
commit89d58217d2bddcad1aa43b8f993fec2c7e8193f0 (patch)
tree17c4222005d7787cab0c63a9fa14b828d3fdc936
parent837cb215ed10119d8bd7c48e0df1da3493ae4b0f (diff)
downloadacf-postgresql-89d58217d2bddcad1aa43b8f993fec2c7e8193f0.tar.bz2
acf-postgresql-89d58217d2bddcad1aa43b8f993fec2c7e8193f0.tar.xz
Add ability to view/modify databases using acf-db-lib
-rw-r--r--Makefile3
-rw-r--r--postgresql-controller.lua6
-rw-r--r--postgresql-model.lua42
-rw-r--r--postgresql.menu1
-rw-r--r--postgresql.roles2
5 files changed, 52 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 3b78cf7..b9c77a1 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/postgresql-controller.lua b/postgresql-controller.lua
index 2a61370..2b375e8 100644
--- a/postgresql-controller.lua
+++ b/postgresql-controller.lua
@@ -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
diff --git a/postgresql-model.lua b/postgresql-model.lua
index efb86d4..8a27ac4 100644
--- a/postgresql-model.lua
+++ b/postgresql-model.lua
@@ -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
diff --git a/postgresql.menu b/postgresql.menu
index 7ac0234..a968cdd 100644
--- a/postgresql.menu
+++ b/postgresql.menu
@@ -1,4 +1,5 @@
#CAT GROUP/DESC TAB ACTION
Applications 25Postgresql Status status
Applications 25Postgresql Expert listfiles
+Applications 25Postgresql Databases listdatabases
Applications 25Postgresql Logfile logfile
diff --git a/postgresql.roles b/postgresql.roles
index 8e3f58e..e2f16cb 100644
--- a/postgresql.roles
+++ b/postgresql.roles
@@ -1,3 +1,3 @@
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