summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kamailio-controller.lua16
-rw-r--r--kamailio-listtables-html.lsp13
-rw-r--r--kamailio-model.lua140
-rw-r--r--[l---------]kamailio-updatetableentry-html.lsp15
-rw-r--r--[l---------]kamailio-updateuser-html.lsp16
5 files changed, 196 insertions, 4 deletions
diff --git a/kamailio-controller.lua b/kamailio-controller.lua
index 8cd66ac..7a98ae3 100644
--- a/kamailio-controller.lua
+++ b/kamailio-controller.lua
@@ -42,7 +42,13 @@ function listtables(self)
end
function viewtable(self)
- return self.model.list_table_entries(self.clientdata.table)
+ local req_table
+ if self.clientdata.schema then
+ req_table = self.clientdata.schema.."."..self.clientdata.table
+ else
+ req_table = self.clientdata.table
+ end
+ return self.model.list_table_entries(req_table)
end
function deletetableentry(self)
@@ -54,7 +60,13 @@ function updatetableentry(self)
end
function createtableentry(self)
- return controllerfunctions.handle_form(self, function() return self.model.get_table_entry(self.clientdata.table) end, self.model.create_table_entry, self.clientdata, "Create", "Create New Table Entry", "Entry created")
+ local req_table
+ if self.clientdata.schema then
+ req_table = self.clientdata.schema.."."..self.clientdata.table
+ else
+ req_table = self.clientdata.table
+ end
+ return controllerfunctions.handle_form(self, function() return self.model.get_table_entry(req_table) end, self.model.create_table_entry, self.clientdata, "Create", "Create New Table Entry", "Entry created")
end
function createdatabase(self)
diff --git a/kamailio-listtables-html.lsp b/kamailio-listtables-html.lsp
index 49aebc2..f8bdd33 100644
--- a/kamailio-listtables-html.lsp
+++ b/kamailio-listtables-html.lsp
@@ -5,12 +5,25 @@
<H1><%= html.html_escape(form.label) %></H1>
<DL>
+<<<<<<< HEAD
+<% for i,v in ipairs(form.value) do %>
+ <li>
+ <% if viewlibrary.check_permission("viewtable") then %>
+ <% if v.schema ~= "public" then %>
+ <%= html.link{value = "viewtable?table=" .. v.table .. "&schema=" .. v.schema, label="("..v.schema..") "..v.table} %>
+ <% else %>
+ <%= html.link{value = "viewtable?table=" .. v.table, label=v.table} %>
+ <% end %>
+ <% else %>
+ <%= html.html_escape("("..v.schema..") "..v.table) %>
+=======
<% for i,table in ipairs(form.value) do %>
<li>
<% if viewlibrary.check_permission("viewtable") then %>
<%= html.link{value = "viewtable?table=" .. table, label=table} %>
<% else %>
<%= html.html_escape(table) %>
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
<% end %>
<% end %>
<% if #form.value == 0 and viewlibrary.check_permission("createdatabase") then %>
diff --git a/kamailio-model.lua b/kamailio-model.lua
index c121dd1..bee2cb8 100644
--- a/kamailio-model.lua
+++ b/kamailio-model.lua
@@ -103,9 +103,15 @@ end
local listtables = function()
local result = {}
if DBENGINE == "PGSQL" then
+<<<<<<< HEAD
+ local tab = getselectresponse("SELECT tablename, schemaname FROM pg_tables WHERE tablename !~* 'pg_*' ORDER BY schemaname, tablename ASC")
+ for i,t in ipairs(tab) do
+ result[#result+1] = {schema=t.schemaname, table=t.tablename}
+=======
local tab = getselectresponse("SELECT tablename FROM pg_tables WHERE tablename !~* 'pg_*' ORDER BY tablename ASC")
for i,t in ipairs(tab) do
result[#result+1] = t.tablename
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
end
else
-- untested
@@ -114,10 +120,23 @@ local listtables = function()
return result
end
+<<<<<<< HEAD
+local listcolumns = function(table, schema)
+ local result = {}
+ if DBENGINE == "PGSQL" then
+ local col
+ if schema then
+ col = getselectresponse("SELECT column_name AS field FROM information_schema.columns WHERE table_schema='"..schema.."' AND table_name='"..table.."' ORDER BY ordinal_position")
+ else
+ col = getselectresponse("SELECT column_name AS field FROM information_schema.columns WHERE table_name='"..table.."' ORDER BY ordinal_position")
+ end
+
+=======
local listcolumns = function(table)
local result = {}
if DBENGINE == "PGSQL" then
local col = getselectresponse("SELECT a.attname AS field FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '"..table.."' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid ORDER BY a.attnum")
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
for i,c in ipairs(col) do
result[#result+1] = c.field
end
@@ -313,9 +332,22 @@ function list_tables()
return cfe({ type="list", value=retval, label="List of Database Tables", errtxt=errtxt })
end
+<<<<<<< HEAD
+function list_table_entries(req_table)
+ local retval = {}
+ -- split up the schema from the table
+ local schema, table
+ schema, table = string.match(req_table, "(.+)%.(.+)")
+ -- if there's no schema with it then grab the req_table value
+ if not schema then
+ table = req_table
+ end
+ retval.table = cfe({ value=req_table or "", label="Table" })
+=======
function list_table_entries(table)
local retval = {}
retval.table = cfe({ value=table or "", label="Table" })
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
retval.fields = cfe({ type="list", value={}, label="List of Table Fields" })
retval.entries = cfe({ type="structure", value={}, label="List of Database Entries" })
local errtxt
@@ -326,11 +358,24 @@ function list_table_entries(table)
retval.table.errtxt = "Table does not exist"
errtxt = "Table does not exist"
for i,t in ipairs(tables) do
+<<<<<<< HEAD
+ if t.table == table then
+ retval.table.errtxt = nil
+ errtxt = nil
+ -- if there's a schema, include it in the select statement
+ if schema then
+ retval.entries.value = getselectresponse("SELECT * FROM "..schema.."."..table) or {}
+ else
+ retval.entries.value = getselectresponse("SELECT * FROM "..table) or {}
+ end
+ retval.fields.value = listcolumns(table, schema) or {}
+=======
if t == table then
retval.table.errtxt = nil
errtxt = nil
retval.entries.value = getselectresponse("SELECT * FROM "..table.." ORDER BY id ASC") or {}
retval.fields.value = listcolumns(table) or {}
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
end
end
if connected then databasedisconnect() end
@@ -338,6 +383,23 @@ function list_table_entries(table)
if not res and err then
errtxt = err
end
+<<<<<<< HEAD
+ return cfe({ type="group", value=retval, label="Database Table Entries", errtxt=errtxt })
+end
+
+function get_table_entry(req_table, id)
+ local retval = {}
+ -- split up the schema from the table
+ local schema, table
+ schema, table = string.match(req_table, "(.+)%.(.+)")
+ -- if there's no schema with it then grab the req_table value
+ if not schema then
+ table = req_table
+ end
+ retval.table = cfe({ value=req_table or "", label="Table", errtxt="Table does not exist", seq=0 })
+ local errtxt = "Table does not exist"
+ if req_table and req_table ~= "" then
+=======
return cfe({ type="group", value=retval, label="Database Table Entries", errtxt=errtxt })
end
@@ -347,23 +409,41 @@ function get_table_entry(table, id)
retval.table = cfe({ value=table or "", label="Table", errtxt="Table does not exist", seq=0 })
local errtxt = "Table does not exist"
if table and table ~= "" then
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
local res, err = pcall(function()
local connected = databaseconnect()
local tables = listtables()
for i,t in ipairs(tables) do
+<<<<<<< HEAD
+ if t.table == table then
+=======
if t == table then
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
retval.table.errtxt = nil
errtxt = nil
break
end
end
if not errtxt then
+<<<<<<< HEAD
+ local fields = listcolumns(table, schema)
+=======
local fields = listcolumns(table)
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
for i,f in ipairs(fields) do
retval[f] = cfe({ label=f, seq=i })
end
if id and id ~= "" then
+<<<<<<< HEAD
+ local entry
+ if schema then
+ entry = getselectresponse("SELECT * FROM "..schema.."."..table.." WHERE id='"..escape(id).."'")
+ else
+ entry = getselectresponse("SELECT * FROM "..table.." WHERE id='"..escape(id).."'")
+ end
+=======
local entry = getselectresponse("SELECT * FROM "..table.." WHERE id='"..escape(id).."'")
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
if entry and #entry > 0 then
for n,v in pairs(entry[1]) do
if retval[n] then retval[n].value = v end
@@ -406,10 +486,22 @@ function update_table_entry(entry, create)
local res, err = pcall(function()
local connected = databaseconnect()
local tables = listtables()
+<<<<<<< HEAD
+ local schema, tablename
+ schema, tablename = string.match(entry.value.table.value, "(.+)%.(.+)")
+ success = false
+ if not schema then
+ tablename = entry.value.table.value
+ end
+ entry.value.table.errtxt = "Table does not exist"
+ for i,t in ipairs(tables) do
+ if t.table == tablename then
+=======
success = false
entry.value.table.errtxt = "Table does not exist"
for i,t in ipairs(tables) do
if t == entry.value.table.value then
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
success = true
entry.value.table.errtxt = nil
break
@@ -428,6 +520,21 @@ function update_table_entry(entry, create)
local values = {}
for n,v in pairs(entry.value) do
if n ~= "table" and n ~= "id" then
+<<<<<<< HEAD
+ --- !!! HACK !!! ---
+ --- Fix for DISTributary Phone System Tool: ASHP
+ ---
+ --- Need to allow for insertion of NULL rather than
+ --- simply '' so that integers and booleans can be
+ --- added with empty values.
+ ---- ----------- ---
+ if n == "role_id" or n == "seq" then
+ if v.value == "" then
+ v.value = "0"
+ end
+ end
+=======
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
names[#names+1] = n
values[#values+1] = escape(v.value)
end
@@ -456,10 +563,24 @@ function update_table_entry(entry, create)
return entry
end
+<<<<<<< HEAD
+function delete_table_entry(req_table, id)
+ local result = ""
+ local errtxt
+ -- split up the schema from the table
+ local schema, table
+ schema, table = string.match(req_table, "(.+)%.(.+)")
+ -- if there's no schema with it then grab the req_table value
+ if not schema then
+ table = req_table
+ end
+ if not req_table or req_table == "" then
+=======
function delete_table_entry(table, id)
local result = ""
local errtxt
if not table or table == "" then
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
errtxt = "Invalid table"
elseif not id or id == "" then
errtxt = "Invalid entry"
@@ -469,13 +590,26 @@ function delete_table_entry(table, id)
errtxt = "Invalid table"
local tables = listtables()
for i,t in ipairs(tables) do
+<<<<<<< HEAD
+ if t.table == table then
+=======
if t == table then
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
errtxt = nil
break
end
end
if not errtxt then
+<<<<<<< HEAD
+ local sql
+ if schema then
+ sql = "DELETE FROM "..schema.."."..table.." WHERE id='"..escape(id).."'"
+ else
+ sql = "DELETE FROM "..table.." WHERE id='"..escape(id).."'"
+ end
+=======
local sql = "DELETE FROM "..table.." WHERE id='"..escape(id).."'"
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
runsqlcommand(sql)
result = "Entry Deleted"
end
@@ -506,9 +640,15 @@ function search_database(id, value, comparison)
local connected = databaseconnect()
local tables = listtables() or {}
for i,t in ipairs(tables) do
+<<<<<<< HEAD
+ local columns = listcolumns(t.table) or {}
+ for i,c in ipairs(columns) do
+ retval.id.option[#retval.id.option + 1] = t.table.."."..c
+=======
local columns = listcolumns(t) or {}
for i,c in ipairs(columns) do
retval.id.option[#retval.id.option + 1] = t.."."..c
+>>>>>>> e19ee215667692e70cb4788dca4151e23aa73b96
end
end
-- Get the rows from the DB
diff --git a/kamailio-updatetableentry-html.lsp b/kamailio-updatetableentry-html.lsp
index ee06465..14ffd0a 120000..100644
--- a/kamailio-updatetableentry-html.lsp
+++ b/kamailio-updatetableentry-html.lsp
@@ -1 +1,14 @@
-kamailio-createtableentry-html.lsp \ No newline at end of file
+<% local form, viewlibrary, page_info = ...
+require("viewfunctions")
+%>
+
+<H1><%= html.html_escape(form.label) %></H1>
+<%
+ form.value.table.readonly = true
+ if page_info.action == "updatetableentry" and form.value.id then
+ form.value.id.readonly = true
+ elseif form.value.id then
+ form.value.id.type = "hidden"
+ end
+ displayform(form, nil, nil, page_info, 2)
+%>
diff --git a/kamailio-updateuser-html.lsp b/kamailio-updateuser-html.lsp
index cd878eb..fb05750 120000..100644
--- a/kamailio-updateuser-html.lsp
+++ b/kamailio-updateuser-html.lsp
@@ -1 +1,15 @@
-kamailio-createuser-html.lsp \ No newline at end of file
+<% local form, viewlibrary, page_info = ...
+require("viewfunctions")
+%>
+
+<H1><%= html.html_escape(form.label) %></H1>
+<%
+ form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action
+ form.value.password.type = "password"
+ form.value.password_confirm.type = "password"
+ if page_info.action == "updateuser" then
+ form.value.username.readonly = true
+ end
+ local order = {"username", "password", "password_confirm", "email_address"}
+ displayform(form, order)
+%>