summaryrefslogtreecommitdiffstats
path: root/gnats-model.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2009-07-10 10:35:21 +0000
committerTed Trask <ttrask01@yahoo.com>2009-07-10 10:35:21 +0000
commit6b961ce2c357c605a9643af00ce2ccd658bf3f7a (patch)
tree860b187112547870d042769677f4de66c25ea810 /gnats-model.lua
parenta013e49aab5d4292662f85d1a6794823dcc2ff49 (diff)
downloadacf-gnats-master.tar.bz2
acf-gnats-master.tar.xz
Incomplete rewrite of gnats to make it generic ACFHEADmaster
The previous version is obsolete, pointing only to dev.alpinelinux.org server, which is no longer in use Rewrite started, but still incomplete
Diffstat (limited to 'gnats-model.lua')
-rw-r--r--gnats-model.lua110
1 files changed, 99 insertions, 11 deletions
diff --git a/gnats-model.lua b/gnats-model.lua
index c273fbc..d6650af 100644
--- a/gnats-model.lua
+++ b/gnats-model.lua
@@ -1,6 +1,7 @@
module(..., package.seeall)
-- Load libraries
+require("modelfunctions")
require("fs")
require("date")
require("format")
@@ -9,11 +10,14 @@ require("validator")
require("processinfo")
-- Set variables
-local configfile = ""
+local configfile = "/etc/gnats/databases"
local processname = "gnats"
local packagename = "gnats"
local baseurl = "/etc/gnats" --No trailing /
+local databaseurl = "/var/lib/gnats/"
local gnatsopts = " -H dev.alpinelinux.org "
+local gnatspath = "/usr/libexec/gnats/"
+gnatsopts = " -H 10.1.59.82 "
-- constants
local SECT_HEADER = 1
local SECT_SFIELDS = 2
@@ -115,7 +119,7 @@ end
local function get_array(name)
local a = {}
- local f = assert(io.popen("/usr/bin/query-pr "..gnatsopts.." --valid-values " .. format.escapespecialcharacters(name)))
+ local f = assert(io.popen("/usr/bin/query-pr "..format.escapespecialcharacters(gnatsopts).." --valid-values " .. format.escapespecialcharacters(name)))
for line in f:lines() do
table.insert(a, line)
end
@@ -124,7 +128,7 @@ local function get_array(name)
end
local function get_various_info()
- local f = assert(io.popen("/usr/bin/query-pr "..gnatsopts.." -x -q | wc -l"))
+ local f = assert(io.popen("/usr/bin/query-pr "..format.escapespecialcharacters(gnatsopts).." -x -q | wc -l"))
local count = f:read("*l")
f:close()
return count
@@ -142,7 +146,7 @@ end
-- generate an array of select options
function list_responsible()
local a = {}
- local f = assert(io.popen("/usr/bin/query-pr "..gnatsopts.." --list-responsible "))
+ local f = assert(io.popen("/usr/bin/query-pr "..format.escapespecialcharacters(gnatsopts).." --list-responsible "))
for line in f:lines() do
table.insert(a, string.match(line,"^(.-):.*$"))
end
@@ -170,7 +174,7 @@ function summary()
end
end
- local f = assert(io.popen("query-pr "..gnatsopts.. format.escapespecialcharacters(search_opts)))
+ local f = assert(io.popen("query-pr "..format.escapespecialcharacters(gnatsopts)..format.escapespecialcharacters(search_opts)))
i = 0
for line in f:lines() do
@@ -277,8 +281,8 @@ end
--]=]
-- read pr to header, sfields and mfields
function read_pr(self, id)
- local cmd = "query-pr -F "..gnatsopts.." "..tostring(id)
- local f = assert(io.popen(format.escapespecialcharacters(cmd)))
+ local cmd = "query-pr -F "..format.escapespecialcharacters(gnatsopts).." "..format.escapespecialcharacters(id)
+ local f = assert(io.popen(cmd))
local line
local section = SECT_HEADER
@@ -313,6 +317,89 @@ end
function getstatus()
local status = {}
+
+ local value, errtxt = processinfo.package_version(packagename)
+ status.version = cfe({
+ label="Program version",
+ value=value,
+ errtxt=errtxt,
+ name=packagename
+ })
+
+ return cfe({ type="group", value=status, label="GNATS Status" })
+-- return modelfunctions.getstatus(processname, packagename, "GNATS Status")
+end
+--[[
+function startstop_service(action)
+ return modelfunctions.startstop_service(processname, action)
+end
+--]]
+function list_databases()
+ local databases = {}
+ local dbs = format.parse_lines(fs.read_file(configfile) or "")
+ for i,db in ipairs(dbs) do
+ temp = {}
+ temp.name, temp.description, temp.directory = string.match(db, "([^:]+):([^:]+):([^:]+)")
+ databases[#databases+1] = temp
+ end
+ return cfe({ type="structure", value=databases, label="GNATS Databases" })
+end
+
+function list_database_files(database)
+ local files = {}
+ local dbs = list_databases()
+ for i,db in ipairs(dbs.value) do
+ if db.name == database then
+ if fs.is_dir(db.directory) and validator.is_valid_filename(string.gsub(db.directory, "/+$", ""), databaseurl) then
+ files = fs.find_files_as_array("[^.].*", db.directory.."/gnats-adm") or {}
+ end
+ break
+ end
+ end
+
+ return cfe({ type="list", value=files, label="GNATS Files", database=database })
+end
+
+local function validate_database_filename(filename)
+ -- We're allowed to edit files in /var/lib/gnats/xxx/gnats-adm/
+ if fs.is_file(filename) and string.match(filename, "^"..format.escapemagiccharacters(databaseurl).."[^/]+/gnats%-adm/[^/]+$") then
+ return true
+ end
+ return false
+end
+
+function read_database_file(filename)
+ return modelfunctions.getfiledetails(filename, validate_database_filename)
+end
+
+function update_database_file(filecontents)
+ return modelfunctions.setfiledetails(filecontents, validate_database_filename)
+end
+
+function list_config_files()
+ local files = fs.find_files_as_array("[^.].*", baseurl) or {}
+
+ return cfe({ type="list", value=files, label="GNATS Files" })
+end
+
+local function validate_config_filename(filename)
+ -- We're allowed to edit files in /etc/gnats/ and below
+ if fs.is_file(filename) and string.match(filename, "^"..format.escapemagiccharacters(baseurl)) and not string.match(filename, "%.%.") then
+ return true
+ end
+ return false
+end
+
+function read_config_file(filename)
+ return modelfunctions.getfiledetails(filename, validate_config_filename)
+end
+
+function update_config_file(filecontents)
+ return modelfunctions.setfiledetails(filecontents, validate_config_filename)
+end
+
+function getreport()
+ local status = {}
local config = getconfig()
local value, errtxt = processinfo.package_version(packagename)
status.version = cfe({ name = "version",
@@ -353,7 +440,7 @@ end
function get_logfile ()
local file = {}
- local cmdtxt = "cat /var/log/messages | grep " .. format.escapespecialcharacters(processname)
+ local cmdtxt = "cat /var/log/messages | grep " .. processname
local cmd, error = io.popen(cmdtxt ,r)
local cmdoutput = cmd:read("*a")
cmd:close()
@@ -438,6 +525,7 @@ function get_filedetails(self,path)
return true, file
end
+
function update_filecontent (self, modifications,path)
if not (fs.is_file(path)) then
return false, "Not a filename"
@@ -465,7 +553,7 @@ function sendbug (self, message)
end
local cmdtxt = "/usr/bin/which sendmail"
- local cmd, error = io.popen(cmdtxt ,r)
+ local cmd, error = io.popen(cmdtxt)
local cmdoutput = cmd:read("*a")
cmd:close()
if not (cmdoutput) then
@@ -476,11 +564,11 @@ function sendbug (self, message)
fs.write_file(mailtxt, table.concat(message , "\n"))
local cmdtxt = "/usr/sbin/sendmail -oi -t < " .. format.escapespecialcharacters(mailtxt) .. " 2>&1"
- local cmd, error = io.popen(cmdtxt ,r)
+ local cmd, error = io.popen(cmdtxt)
local cmdoutput = cmd:read("*a")
cmd:close()
- local cmd, error = io.popen("/bin/rm -f " .. format.escapespecialcharacters(mailtxt) ,r)
+ local cmd, error = io.popen("/bin/rm -f " .. format.escapespecialcharacters(mailtxt))
cmd:close()
if (#cmdoutput > 0) then