summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gnats-controller.lua26
l---------gnats-editconfigfile-html.lsp1
l---------gnats-editdatabasefile-html.lsp1
-rw-r--r--gnats-listconfigfiles-html.lsp25
-rw-r--r--gnats-listdatabasefiles-html.lsp25
-rw-r--r--gnats-listdatabases-html.lsp39
-rw-r--r--gnats-model.lua110
l---------[-rw-r--r--]gnats-status-html.lsp26
-rw-r--r--gnats.menu3
-rw-r--r--gnats.roles5
10 files changed, 219 insertions, 42 deletions
diff --git a/gnats-controller.lua b/gnats-controller.lua
index 7668866..c82ccdc 100644
--- a/gnats-controller.lua
+++ b/gnats-controller.lua
@@ -1,6 +1,7 @@
module(..., package.seeall)
-- Load libraries
+require("controllerfunctions")
require("format")
-- Set variables
@@ -100,13 +101,32 @@ local descr = {
-- ################################################################################
-- PUBLIC FUNCTIONS
-default_action = "query"
+default_action = "status"
function status(self)
- return { status=self.model.getstatus() }
+ return self.model.getstatus()
+end
+
+function listdatabases(self)
+ return self.model.list_databases()
+end
+
+function listdatabasefiles(self)
+ return self.model.list_database_files(self.clientdata.database)
+end
+
+function editdatabsefile(self)
+ return controllerfunctions.handle_form(self, function() return self.model.read_database_file(self.clientdata.filename) end, self.model.update_database_file, self.clientdata, "Save", "Edit File", "File Saved")
+end
+
+function listconfigfiles(self)
+ return self.model.list_config_files()
+end
+
+function editconfigfile(self)
+ return controllerfunctions.handle_form(self, function() return self.model.read_config_file(self.clientdata.filename) end, self.model.update_config_file, self.clientdata, "Save", "Edit File", "File Saved")
end
----[[
function expert(self)
local url = self.conf.script .. self.conf.prefix .. self.conf.controller
diff --git a/gnats-editconfigfile-html.lsp b/gnats-editconfigfile-html.lsp
new file mode 120000
index 0000000..15b1930
--- /dev/null
+++ b/gnats-editconfigfile-html.lsp
@@ -0,0 +1 @@
+../filedetails-html.lsp \ No newline at end of file
diff --git a/gnats-editdatabasefile-html.lsp b/gnats-editdatabasefile-html.lsp
new file mode 120000
index 0000000..15b1930
--- /dev/null
+++ b/gnats-editdatabasefile-html.lsp
@@ -0,0 +1 @@
+../filedetails-html.lsp \ No newline at end of file
diff --git a/gnats-listconfigfiles-html.lsp b/gnats-listconfigfiles-html.lsp
new file mode 100644
index 0000000..e56ad06
--- /dev/null
+++ b/gnats-listconfigfiles-html.lsp
@@ -0,0 +1,25 @@
+<% local view, viewlibrary, page_info, session = ...
+require("viewfunctions")
+%>
+
+<% displaycommandresults({"editconfigfile"}, session) %>
+
+<H1>Config Files</H1>
+<DL>
+<TABLE>
+ <TR style="background:#eee;font-weight:bold;">
+ <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Action</TD>
+ <TD style="white-space:nowrap;text-align:left;" class="header">File</TD>
+ </TR>
+<% for i,file in ipairs(view.value) do %>
+ <TR>
+ <TD style="padding-right:20px;white-space:nowrap;">
+ <% if session.permissions.gnats.editconfigfile then %>
+ <%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/editconfigfile?filename="..file.."&redir="..page_info.orig_action, label="Edit "} %>
+ <% end %>
+ </TD>
+ <TD style="white-space:nowrap;"><%= html.html_escape(file) %></TD>
+ </TR>
+<% end %>
+</TABLE>
+</DL>
diff --git a/gnats-listdatabasefiles-html.lsp b/gnats-listdatabasefiles-html.lsp
new file mode 100644
index 0000000..35ffa9c
--- /dev/null
+++ b/gnats-listdatabasefiles-html.lsp
@@ -0,0 +1,25 @@
+<% local view, viewlibrary, page_info, session = ...
+require("viewfunctions")
+%>
+
+<% displaycommandresults({"editdatabasefile"}, session) %>
+
+<H1><%= html.html_escape(view.database) %> Database Files</H1>
+<DL>
+<TABLE>
+ <TR style="background:#eee;font-weight:bold;">
+ <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Action</TD>
+ <TD style="white-space:nowrap;text-align:left;" class="header">File</TD>
+ </TR>
+<% for i,file in ipairs(view.value) do %>
+ <TR>
+ <TD style="padding-right:20px;white-space:nowrap;">
+ <% if session.permissions.gnats.editdatabasefile then %>
+ <%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/editdatabasefile?filename="..file.."&redir="..page_info.orig_action.."?database="..view.database, label="Edit "} %>
+ <% end %>
+ </TD>
+ <TD style="white-space:nowrap;"><%= html.html_escape(file) %></TD>
+ </TR>
+<% end %>
+</TABLE>
+</DL>
diff --git a/gnats-listdatabases-html.lsp b/gnats-listdatabases-html.lsp
new file mode 100644
index 0000000..a2e0db6
--- /dev/null
+++ b/gnats-listdatabases-html.lsp
@@ -0,0 +1,39 @@
+<% local view, viewlibrary, page_info, session = ...
+require("viewfunctions")
+%>
+
+<% displaycommandresults({"deletedatabase"}, session) %>
+<% displaycommandresults({"createdatabase"}, session, true) %>
+
+<H1>Databases</H1>
+<DL>
+<TABLE>
+ <TR style="background:#eee;font-weight:bold;">
+ <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Action</TD>
+ <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Database</TD>
+ <TD style="white-space:nowrap;text-align:left;" class="header">Description</TD>
+ </TR>
+<% for i,db in ipairs(view.value) do %>
+ <TR>
+ <TD style="padding-right:20px;white-space:nowrap;">
+ <% if session.permissions.gnats.listdatabasefiles then %>
+ <%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/listdatabasefiles?database="..db.name, label="Edit "} %>
+ <% end %>
+ <% if session.permissions.gnats.deletedatabase then %>
+ <%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/deletedatabase?name="..db.name, label="Delete "} %>
+ <% end %>
+ </TD>
+ <TD style="padding-right:20px;white-space:nowrap;"><%= html.html_escape(db.name) %></TD>
+ <TD style="white-space:nowrap;"><%= html.html_escape(db.description) %></TD>
+ </TR>
+<% end %>
+</TABLE>
+</DL>
+
+<% if viewlibrary and viewlibrary.dispatch_component and session.permissions.gnats.createdatabase then
+ local createform = viewlibrary.dispatch_component("createdatabase", nil, true) %>
+<H2><%= html.html_escape(createform.label) %></H2>
+<%
+ createform.action = page_info.script .. page_info.prefix .. page_info.controller .. "/createdatabase"
+ displayform(createform)
+end %>
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
diff --git a/gnats-status-html.lsp b/gnats-status-html.lsp
index 6635952..b2f8480 100644..120000
--- a/gnats-status-html.lsp
+++ b/gnats-status-html.lsp
@@ -1,25 +1 @@
-<% local form = ...
-require("viewfunctions")
-%>
-<%
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
-%>
-
-<H1>SYSTEM INFO</H1>
-<DL>
-<%
-local myform = form.status
-local tags = { "status", "version", }
-displayinfo(myform,tags,"viewonly")
-%>
-<%
-local myform = form.status
-local tags = { "numbugs", }
-displayinfo(myform,tags,"viewonly")
-%>
-</DL>
-
+../status-html.lsp \ No newline at end of file
diff --git a/gnats.menu b/gnats.menu
index 5caaba6..b88b511 100644
--- a/gnats.menu
+++ b/gnats.menu
@@ -5,5 +5,6 @@ Applications 98GNATS_bugreport Report_a_BUG report
#Applications 98GNATS_bugreport Statuslist summary
#Applications 98GNATS_bugreport QueryResult queryresult
#Applications 98GNATS_bugreport Edit_PR queryeditpr
-Applications 98GNATS_bugreport Configuration expert
+Applications 98GNATS_bugreport Config listdatabases
+Applications 98GNATS_bugreport Expert listconfigfiles
diff --git a/gnats.roles b/gnats.roles
index c7fc599..53e40df 100644
--- a/gnats.roles
+++ b/gnats.roles
@@ -1,4 +1,5 @@
-GUEST=gnats:query,gnats:queryresult,gnats:summary,gnats:report,gnats:reportsuccess
+GUEST=gnats:status,gnats:query,gnats:queryresult,gnats:summary,gnats:report,gnats:reportsuccess
+EDITOR=gnats:status,gnats:listdatabases,gnats:listdatabasefiles,gnats:editdatabasefile,gnats:listconfigfiles,gnats:editconfigfile
EXPERT=gnats:expert,gnats:edit,gnats:queryeditpr,gnats:editpr
-ADMIN=gnats:status,gnats:query,gnats:queryresult,gnats:summary,gnats:report,gnats:reportsuccess,gnats:expert,gnats:edit,gnats:queryeditpr,gnats:editpr
+ADMIN=gnats:status,gnats:query,gnats:queryresult,gnats:summary,gnats:report,gnats:reportsuccess,gnats:listdatabases,gnats:listdatabasefiles,gnats:editdatabasefile,gnats:listconfigfiles,gnats:editconfigfile,gnats:expert,gnats:edit,gnats:queryeditpr,gnats:editpr