From 5261ae2fa86ae090a2923b502646aa03c6a275a9 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 5 Nov 2009 15:27:43 +0000 Subject: First cut at kamailio ACF. Just status, listfiles, edit, startstop. --- Makefile | 44 +++++++++++++++++++++++++++++++++++++ README | 1 + config.mk | 10 +++++++++ kamailio-controller.lua | 22 +++++++++++++++++++ kamailio-edit-html.lsp | 1 + kamailio-listfiles-html.lsp | 28 ++++++++++++++++++++++++ kamailio-model.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++ kamailio-startstop-html.lsp | 1 + kamailio-status-html.lsp | 1 + kamailio.menu | 4 ++++ kamailio.roles | 3 +++ 11 files changed, 168 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100644 config.mk create mode 100644 kamailio-controller.lua create mode 120000 kamailio-edit-html.lsp create mode 100644 kamailio-listfiles-html.lsp create mode 100644 kamailio-model.lua create mode 120000 kamailio-startstop-html.lsp create mode 120000 kamailio-status-html.lsp create mode 100644 kamailio.menu create mode 100644 kamailio.roles diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..50d9b3d --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +APP_NAME=kamailio +PACKAGE=acf-$(APP_NAME) +VERSION=0.1.0 + +APP_DIST=\ + kamailio* \ + + +EXTRA_DIST=README Makefile config.mk + +DISTFILES=$(APP_DIST) $(EXTRA_DIST) + +TAR=tar + +P=$(PACKAGE)-$(VERSION) +tarball=$(P).tar.bz2 +install_dir=$(DESTDIR)/$(appdir)/$(APP_NAME) + +all: +clean: + rm -rf $(tarball) $(P) + +dist: $(tarball) + +install: + mkdir -p "$(install_dir)" + cp -a $(APP_DIST) "$(install_dir)" + +$(tarball): $(DISTFILES) + rm -rf $(P) + mkdir -p $(P) + cp -a $(DISTFILES) $(P) + $(TAR) -jcf $@ $(P) + rm -rf $(P) + +# target that creates a tar package, unpacks is and install from package +dist-install: $(tarball) + $(TAR) -jxf $(tarball) + $(MAKE) -C $(P) install DESTDIR=$(DESTDIR) + rm -rf $(P) + +include config.mk + +.PHONY: all clean dist install dist-install diff --git a/README b/README new file mode 100644 index 0000000..ec521f5 --- /dev/null +++ b/README @@ -0,0 +1 @@ +ACF for kamailio diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..45f4d21 --- /dev/null +++ b/config.mk @@ -0,0 +1,10 @@ +prefix=/usr +datadir=${prefix}/share +sysconfdir=${prefix}/etc +localstatedir=${prefix}/var +acfdir=${datadir}/acf +wwwdir=${acfdir}/www +cgibindir=${acfdir}/cgi-bin +appdir=${acfdir}/app +acflibdir=${acfdir}/lib +sessionsdir=${localstatedir}/lib/acf/sessions diff --git a/kamailio-controller.lua b/kamailio-controller.lua new file mode 100644 index 0000000..45a8fd7 --- /dev/null +++ b/kamailio-controller.lua @@ -0,0 +1,22 @@ +module(..., package.seeall) + +-- Load libraries +require("controllerfunctions") + +default_action = "status" + +function status(self) + return self.model.getstatus() +end + +function startstop(self) + return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.clientdata) +end + +function listfiles(self) + return self.model.list_files() +end + +function edit(self) + return controllerfunctions.handle_form(self, function() return self.model.get_filedetails(self.clientdata.filename) end, self.model.update_filedetails, self.clientdata, "Save", "Edit File", "File Saved") +end diff --git a/kamailio-edit-html.lsp b/kamailio-edit-html.lsp new file mode 120000 index 0000000..15b1930 --- /dev/null +++ b/kamailio-edit-html.lsp @@ -0,0 +1 @@ +../filedetails-html.lsp \ No newline at end of file diff --git a/kamailio-listfiles-html.lsp b/kamailio-listfiles-html.lsp new file mode 100644 index 0000000..0719f76 --- /dev/null +++ b/kamailio-listfiles-html.lsp @@ -0,0 +1,28 @@ +<% local view, viewlibrary, page_info, session = ... +require("viewfunctions") +%> + +<% displaycommandresults({"edit", "startstop"}, session) %> + +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("status") +end %> + +

Configuration

+ + + + + + + +<% + for k,v in ipairs( view.value ) do + io.write( "\n" ) + end +%> +
FileSizeLast Modified
" .. html.html_escape(v.filename) .. "" .. html.html_escape(v.size) .."" .. html.html_escape(v.mtime) .."
+ +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("startstop") +end %> diff --git a/kamailio-model.lua b/kamailio-model.lua new file mode 100644 index 0000000..4915787 --- /dev/null +++ b/kamailio-model.lua @@ -0,0 +1,53 @@ +module(..., package.seeall) + +-- Load libraries +require("modelfunctions") +require("fs") +require("validator") + +-- Set variables +local processname = "kamailio" +local packagename = "kamailio" +local baseurl = "/etc/kamailio" + +local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " + +-- ################################################################################ +-- LOCAL FUNCTIONS + +local is_valid_filename = function(filename) + local dirname = dirname(filename) + return validator.is_valid_filename(filename) and string.match(dirname, baseurl) and not string.match(dirname, "%.%.") +end + +-- ################################################################################ +-- PUBLIC FUNCTIONS + +function startstop_service(action) + return modelfunctions.startstop_service(processname, action) +end + +function getstatus() + return modelfunctions.getstatus(processname, packagename, "Kamailio Status") +end + +function get_filedetails(filename) + return modelfunctions.getfiledetails(filename, is_valid_filename) +end + +function update_filedetails(filedetails) + return modelfunctions.setfiledetails(filedetails, is_valid_filename) +end + +function list_files() + local retval = {} + for file in fs.find(null, baseurl) do + local details = fs.stat(file) + if details.type == "regular" then + details.filename = file + table.insert(retval, details) + end + end + table.sort(retval, function(a,b) return a.filename < b.filename end) + return cfe({ type="structure", value=retval, label="List of Kamailio files" }) +end diff --git a/kamailio-startstop-html.lsp b/kamailio-startstop-html.lsp new file mode 120000 index 0000000..0ea2627 --- /dev/null +++ b/kamailio-startstop-html.lsp @@ -0,0 +1 @@ +../startstop-html.lsp \ No newline at end of file diff --git a/kamailio-status-html.lsp b/kamailio-status-html.lsp new file mode 120000 index 0000000..b2f8480 --- /dev/null +++ b/kamailio-status-html.lsp @@ -0,0 +1 @@ +../status-html.lsp \ No newline at end of file diff --git a/kamailio.menu b/kamailio.menu new file mode 100644 index 0000000..f806819 --- /dev/null +++ b/kamailio.menu @@ -0,0 +1,4 @@ +# Prefix and controller are already known at this point +# Cat Group Tab Action +Applications 86Kamailio Status status +Applications 86Kamailio Expert listfiles diff --git a/kamailio.roles b/kamailio.roles new file mode 100644 index 0000000..b40dd8a --- /dev/null +++ b/kamailio.roles @@ -0,0 +1,3 @@ +USER=kamailio:status,kamailio:startstop +EXPERT=kamailio:listfiles,kamailio:edit +ADMIN=kamailio:status,kamailio:startstop,kamailio:listfiles,kamailio:edit -- cgit v1.2.3 From 7570528cc84eb88a606858bed7cba166074af92e Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 17 Nov 2009 17:52:35 +0000 Subject: Added ability to create/delete/update users (tested for postgres) --- kamailio-controller.lua | 16 +++++++ kamailio-createuser-html.lsp | 15 ++++++ kamailio-listusers-html.lsp | 43 +++++++++++++++++ kamailio-model.lua | 107 +++++++++++++++++++++++++++++++++++++++++++ kamailio-updateuser-html.lsp | 1 + kamailio.menu | 1 + kamailio.roles | 5 +- 7 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 kamailio-createuser-html.lsp create mode 100644 kamailio-listusers-html.lsp create mode 120000 kamailio-updateuser-html.lsp diff --git a/kamailio-controller.lua b/kamailio-controller.lua index 45a8fd7..a4bff67 100644 --- a/kamailio-controller.lua +++ b/kamailio-controller.lua @@ -20,3 +20,19 @@ end function edit(self) return controllerfunctions.handle_form(self, function() return self.model.get_filedetails(self.clientdata.filename) end, self.model.update_filedetails, self.clientdata, "Save", "Edit File", "File Saved") end + +function listusers(self) + return self.model.list_users() +end + +function createuser(self) + return controllerfunctions.handle_form(self, self.model.get_new_user, self.model.create_new_user, self.clientdata, "Create", "Create New User") +end + +function deleteuser(self) + return self:redirect_to_referrer(self.model.delete_user(self.clientdata.username)) +end + +function updateuser(self) + return controllerfunctions.handle_form(self, function() return self.model.get_user(self.clientdata.username) end, self.model.update_user, self.clientdata, "Update", "Update User") +end diff --git a/kamailio-createuser-html.lsp b/kamailio-createuser-html.lsp new file mode 100644 index 0000000..fb05750 --- /dev/null +++ b/kamailio-createuser-html.lsp @@ -0,0 +1,15 @@ +<% local form, viewlibrary, page_info = ... +require("viewfunctions") +%> + +

<%= html.html_escape(form.label) %>

+<% + 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) +%> diff --git a/kamailio-listusers-html.lsp b/kamailio-listusers-html.lsp new file mode 100644 index 0000000..0c010c5 --- /dev/null +++ b/kamailio-listusers-html.lsp @@ -0,0 +1,43 @@ +<% local form, viewlibrary, page_info, session = ... %> +<% require("viewfunctions") %> + +<% displaycommandresults({"deleteuser", "updateuser"}, session) %> +<% displaycommandresults({"createuser"}, session, true) %> + +

<%= html.html_escape(form.label) %>

+
+ + + <% if session.permissions[page_info.controller].deleteuser or session.permissions[page_info.controller].updateuser then %> + + <% end %> + + + + +<% for i,user in ipairs(form.value) do %> + + <% if session.permissions[page_info.controller].deleteuser or session.permissions[page_info.controller].updateuser then %> + + <% end %> + + <% if session.permissions[page_info.controller].updateuser then %> + + <% else %> + + <% end %> + +<% end %> +
ActionUser NamePassword
+ <% if session.permissions[page_info.controller].updateuser then %> + <%= html.link{value = "updateuser?username=" .. user.username.."&redir="..page_info.orig_action, label="Update "} %> + <% end %> + <% if session.permissions[page_info.controller].deleteuser then %> + <%= html.link{value = "deleteuser?username=" .. user.username, label="Delete "} %> + <% end %> + <%= html.html_escape(user.username) %><%= html.html_escape(user.password) %>******
+
+ +<% if viewlibrary and viewlibrary.dispatch_component and session.permissions[page_info.controller].createuser then + viewlibrary.dispatch_component("createuser") +end %> diff --git a/kamailio-model.lua b/kamailio-model.lua index 4915787..e6262ba 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -20,6 +20,23 @@ local is_valid_filename = function(filename) return validator.is_valid_filename(filename) and string.match(dirname, baseurl) and not string.match(dirname, "%.%.") end +local function validate_user(user) + local success = true + if user.value.username.value == "" then + user.value.username.errtxt = "Cannot be empty" + success = false + end + if user.value.password.value == "" then + user.value.password.errtxt = "Cannot be empty" + success = false + end + if user.value.password.value ~= user.value.password_confirm.value then + user.value.password_confirm.errtxt = "Must match password" + success = false + end + return success, user +end + -- ################################################################################ -- PUBLIC FUNCTIONS @@ -51,3 +68,93 @@ function list_files() table.sort(retval, function(a,b) return a.filename < b.filename end) return cfe({ type="structure", value=retval, label="List of Kamailio files" }) end + +function list_users() + -- Database format: id | username | domain | password | email_address | ha1 | ha1b | rpid + local cmd = path .. "kamctl db show subscriber" + local f = io.popen(cmd) + -- These settings work for Postgres database + local skiplines = 2 + local delimiter = "%s*|%s*" + local results = {} + for line in f:lines() do + if skiplines > 0 then + skiplines = skiplines-1 + else + local words = format.string_to_table(line, delimiter) + if #words > 1 then + local temp = {username = words[2], + --domain = words[3], + password = words[4], + --email_address = words[5] + } + results[#results+1] = temp + end + end + end + f:close() + table.sort(results, function(a,b) return a.username < b.username end) + return cfe({type="list", value=results, label="Kamailio Users"}) +end + +function get_new_user() + local user = {} + user.username = cfe({label="User Name"}) + user.password = cfe({label="Password"}) + user.password_confirm = cfe({label="Password (confirm)"}) + --user.email_address = cfe({label="E-mail Address"}) + return cfe({type="group", value=user, label="Kamailio User"}) +end + +function create_new_user(user) + local success = validate_user(user) + if success then + local cmd = path .. "kamctl add "..format.escapespecialcharacters(user.value.username.value).." "..format.escapespecialcharacters(user.value.password.value) + --if user.value.email_address.value ~= "" then + -- cmd = cmd.." "..format.escapespecialcharacters(user.value.email_address.value) + --end + local f = io.popen(cmd) + user.descr = f:read("*a") + f:close() + else + user.errtxt = "Failed to create new user" + end + + return user +end + +function delete_user(username) + local cmd = path .. "kamctl rm "..format.escapespecialcharacters(username) + local f = io.popen(cmd) + local result = f:read("*a") + f:close() + return cfe({value=result, label="Delete User Result"}) +end + +function get_user(username) + local user = get_new_user() + user.value.username.value = username + user.value.username.errtxt = "Invalid user" + local users = list_users() + for i,u in ipairs(users.value) do + if u.username == username then + user.value.username.errtxt = nil + break + end + end + return user +end + +function update_user(user) + local success = validate_user(user) + if success then + local cmd = path .. "kamctl passwd "..format.escapespecialcharacters(user.value.username.value).." "..format.escapespecialcharacters(user.value.password.value) + local f = io.popen(cmd) + user.descr = f:read("*a") + f:close() + else + user.errtxt = "Failed to update user" + end + + return user +end diff --git a/kamailio-updateuser-html.lsp b/kamailio-updateuser-html.lsp new file mode 120000 index 0000000..cd878eb --- /dev/null +++ b/kamailio-updateuser-html.lsp @@ -0,0 +1 @@ +kamailio-createuser-html.lsp \ No newline at end of file diff --git a/kamailio.menu b/kamailio.menu index f806819..607387f 100644 --- a/kamailio.menu +++ b/kamailio.menu @@ -1,4 +1,5 @@ # Prefix and controller are already known at this point # Cat Group Tab Action Applications 86Kamailio Status status +Applications 86Kamailio Users listusers Applications 86Kamailio Expert listfiles diff --git a/kamailio.roles b/kamailio.roles index b40dd8a..111828b 100644 --- a/kamailio.roles +++ b/kamailio.roles @@ -1,3 +1,4 @@ -USER=kamailio:status,kamailio:startstop +USER=kamailio:status,kamailio:startstop,kamailio:listusers +EDITOR=kamailio:createuser,kamailio:updateuser,kamailio:deleteuser EXPERT=kamailio:listfiles,kamailio:edit -ADMIN=kamailio:status,kamailio:startstop,kamailio:listfiles,kamailio:edit +ADMIN=kamailio:status,kamailio:startstop,kamailio:listusers,kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listfiles,kamailio:edit -- cgit v1.2.3 From 5ad56e0611b0fb496fbb05f88e5f2057dd8ef0bd Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 18 Nov 2009 12:05:25 +0000 Subject: Added parsing of userlist for DBTEXT --- kamailio-model.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kamailio-model.lua b/kamailio-model.lua index e6262ba..53cb29a 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -3,6 +3,7 @@ module(..., package.seeall) -- Load libraries require("modelfunctions") require("fs") +require("format") require("validator") -- Set variables @@ -76,6 +77,12 @@ function list_users() -- These settings work for Postgres database local skiplines = 2 local delimiter = "%s*|%s*" + local dbengine = format.parse_ini_file(fs.read_file("/etc/kamailio/kamctlrc") or "", "", "DBENGINE") + if dbengine == "DBTEXT" then + skiplines = 0 + delimiter = "\'?%s*,%s*\'?" + end + local results = {} for line in f:lines() do if skiplines > 0 then -- cgit v1.2.3 From 31a844298953750a24ca9a67521676540e3154f2 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 27 Nov 2009 16:47:55 +0000 Subject: Bumped version to 0.1.1 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 50d9b3d..2711708 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=kamailio PACKAGE=acf-$(APP_NAME) -VERSION=0.1.0 +VERSION=0.1.1 APP_DIST=\ kamailio* \ -- cgit v1.2.3 From 999412d23770869658b978727b479764f5e0bf90 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 10 Dec 2009 15:43:08 +0000 Subject: UI fix, bumped to 0.1.2 --- Makefile | 2 +- kamailio-listfiles-html.lsp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 2711708..675fc24 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=kamailio PACKAGE=acf-$(APP_NAME) -VERSION=0.1.1 +VERSION=0.1.2 APP_DIST=\ kamailio* \ diff --git a/kamailio-listfiles-html.lsp b/kamailio-listfiles-html.lsp index 0719f76..caff231 100644 --- a/kamailio-listfiles-html.lsp +++ b/kamailio-listfiles-html.lsp @@ -9,7 +9,7 @@ require("viewfunctions") end %>

Configuration

- +
@@ -21,7 +21,7 @@ end %> io.write( "\n" ) end %> -
File Size
" .. html.html_escape(v.filename) .. "" .. html.html_escape(v.size) .."" .. html.html_escape(v.mtime) .."
+ <% if viewlibrary and viewlibrary.dispatch_component then viewlibrary.dispatch_component("startstop") -- cgit v1.2.3 From 25204ba6ee44fdbd9288f3953ca63dcbb81b2167 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 1 Jan 2010 16:42:00 +0000 Subject: Use viewlibrary.check_permission from acf-core-0.9.0, dirname function is no longer in acf-core-0.9.0 --- kamailio-listusers-html.lsp | 12 ++++++------ kamailio-model.lua | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/kamailio-listusers-html.lsp b/kamailio-listusers-html.lsp index 0c010c5..5994b79 100644 --- a/kamailio-listusers-html.lsp +++ b/kamailio-listusers-html.lsp @@ -8,7 +8,7 @@
- <% if session.permissions[page_info.controller].deleteuser or session.permissions[page_info.controller].updateuser then %> + <% if viewlibrary.check_permission("deleteuser") or viewlibrary.check_permission("updateuser") then %> <% end %> @@ -17,18 +17,18 @@ <% for i,user in ipairs(form.value) do %> - <% if session.permissions[page_info.controller].deleteuser or session.permissions[page_info.controller].updateuser then %> + <% if viewlibrary.check_permission("deleteuser") or viewlibrary.check_permission("updateuser") then %> <% end %> - <% if session.permissions[page_info.controller].updateuser then %> + <% if viewlibrary.check_permission("updateuser") then %> <% else %> @@ -38,6 +38,6 @@
ActionUser Name
- <% if session.permissions[page_info.controller].updateuser then %> + <% if viewlibrary.check_permission("updateuser") then %> <%= html.link{value = "updateuser?username=" .. user.username.."&redir="..page_info.orig_action, label="Update "} %> <% end %> - <% if session.permissions[page_info.controller].deleteuser then %> + <% if viewlibrary.check_permission("deleteuser") then %> <%= html.link{value = "deleteuser?username=" .. user.username, label="Delete "} %> <% end %> <%= html.html_escape(user.username) %><%= html.html_escape(user.password) %>******
-<% if viewlibrary and viewlibrary.dispatch_component and session.permissions[page_info.controller].createuser then +<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createuser") then viewlibrary.dispatch_component("createuser") end %> diff --git a/kamailio-model.lua b/kamailio-model.lua index 53cb29a..8d4ec97 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -1,6 +1,7 @@ module(..., package.seeall) -- Load libraries +require("posix") require("modelfunctions") require("fs") require("format") @@ -17,7 +18,7 @@ local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin -- LOCAL FUNCTIONS local is_valid_filename = function(filename) - local dirname = dirname(filename) + local dirname = posix.dirname(filename) return validator.is_valid_filename(filename) and string.match(dirname, baseurl) and not string.match(dirname, "%.%.") end -- cgit v1.2.3 From 0b38e3b87b7dad7b6f76ac8857b85120ae256a7a Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 1 Jan 2010 16:42:30 +0000 Subject: Bumped version to 0.2.0 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 675fc24..0ac2e18 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=kamailio PACKAGE=acf-$(APP_NAME) -VERSION=0.1.2 +VERSION=0.2.0 APP_DIST=\ kamailio* \ -- cgit v1.2.3 From 7737dbd5def8fe3f38553e6e5c91bfc389fcae64 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 8 Jan 2011 19:54:34 +0000 Subject: Added actions for listing and editing database tables. Relys on kamctlrc. --- kamailio-controller.lua | 21 +++ kamailio-createtableentry-html.lsp | 14 ++ kamailio-listtables-html.lsp | 14 ++ kamailio-model.lua | 338 ++++++++++++++++++++++++++++++++++--- kamailio-updatetableentry-html.lsp | 1 + kamailio-viewtable-html.lsp | 48 ++++++ kamailio.menu | 1 + kamailio.roles | 4 +- 8 files changed, 418 insertions(+), 23 deletions(-) create mode 100644 kamailio-createtableentry-html.lsp create mode 100644 kamailio-listtables-html.lsp create mode 120000 kamailio-updatetableentry-html.lsp create mode 100644 kamailio-viewtable-html.lsp diff --git a/kamailio-controller.lua b/kamailio-controller.lua index a4bff67..69d3d1d 100644 --- a/kamailio-controller.lua +++ b/kamailio-controller.lua @@ -36,3 +36,24 @@ end function updateuser(self) return controllerfunctions.handle_form(self, function() return self.model.get_user(self.clientdata.username) end, self.model.update_user, self.clientdata, "Update", "Update User") end + +function listtables(self) + return self.model.list_tables() +end + +function viewtable(self) + return self.model.list_table_entries(self.clientdata.table) +end + +function deletetableentry(self) + return self:redirect_to_referrer(self.model.delete_table_entry(self.clientdata.table, self.clientdata.id)) +end + +function updatetableentry(self) + return controllerfunctions.handle_form(self, function() return self.model.get_table_entry(self.clientdata.table, self.clientdata.id) end, self.model.update_table_entry, self.clientdata, "Update", "Update Table Entry", "Entry updated") +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") +end + diff --git a/kamailio-createtableentry-html.lsp b/kamailio-createtableentry-html.lsp new file mode 100644 index 0000000..b0dabfa --- /dev/null +++ b/kamailio-createtableentry-html.lsp @@ -0,0 +1,14 @@ +<% local form, viewlibrary, page_info = ... +require("viewfunctions") +%> + +

<%= html.html_escape(form.label) %>

+<% + form.value.table.type = "hidden" + 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-listtables-html.lsp b/kamailio-listtables-html.lsp new file mode 100644 index 0000000..6a117e4 --- /dev/null +++ b/kamailio-listtables-html.lsp @@ -0,0 +1,14 @@ +<% local form, viewlibrary, page_info, session = ... %> +<% require("viewfunctions") %> + +

<%= html.html_escape(form.label) %>

+
+<% for i,table in ipairs(form.value) do %> +
  • + <% if viewlibrary.check_permission("viewtable") then %> + <%= html.link{value = "viewtable?table=" .. table, label=table} %> + <% else %> + <%= html.html_escape(table) %> + <% end %> +<% end %> +
  • diff --git a/kamailio-model.lua b/kamailio-model.lua index 8d4ec97..63be94a 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -11,8 +11,120 @@ require("validator") local processname = "kamailio" local packagename = "kamailio" local baseurl = "/etc/kamailio" +local kamctlrc_file = "/etc/kamailio/kamctlrc" local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " +local env +local con +local DBENGINE + +-- ################################################################################ +-- DATABASE FUNCTIONS + +local function assert (v, m) + if not v then + m = m or "Assertion failed!" + error(m, 0) + end + return v, m +end + +-- Escape special characters in sql statements +local escape = function(sql) + sql = sql or "" + sql = string.gsub(sql, "'", "''") + return string.gsub(sql, "\\", "\\\\") +end + +local databaseconnect = function() + if not con then + -- parse the kamctlrc file + local config = format.parse_ini_file(fs.read_file(kamctlrc_file), "") or {} + if not config.DBENGINE then + error("Database engine not specified, please setup one in the config script "..kamctlrc_file) + end + + -- create environment object + if config.DBENGINE == "MYSQL" or config.DBENGINE == "mysql" or config.DBENGINE == "MySQL" then + error("MYSQL database not supported") + elseif config.DBENGINE == "PGSQL" or config.DBENGINE == "pgsql" or config.DBENGINE == "postgres" or config.DBENGINE == "postgresql" or config.DBENGINE == "POSTGRESQL" then + require("luasql.postgres") + env = assert (luasql.postgres()) + DBENGINE = "PGSQL" + elseif config.DBENGINE == "ORACLE" or config.DBENGINE == "oracle" or config.DBENGINE == "Oracle" then + error("ORACLE database not supported") + elseif config.DBENGINE == "DBTEXT" or config.DBENGINE == "dbtext" or config.DBENGINE == "textdb" then + error("DBTEXT database not supported") + elseif config.DBENGINE == "DB_BERKELEY" or config.DBENGINE == "db_berkeley" or config.DBENGINE == "BERKELEY" or config.DBENGINE == "berkeley" then + error("BERKELEY database not supported") + else + error("Unknown database engine "..config.DBENGINE) + end + + -- connect to data source + con = assert(env:connect(config.DBNAME or "", config.DBRWUSER or "", config.DBRWPW or "")) + return true + end + return false +end + +local databasedisconnect = function() + if env then + env:close() + env = nil + end + if con then + con:close() + con = nil + end +end + +local runsqlcommand = function(sql) +logevent(sql) + assert(con:execute(sql)) +end + +local getselectresponse = function(sql) + local retval = {} +logevent(sql) + local cur = assert (con:execute(sql)) + local row = cur:fetch ({}, "a") + while row do + local tmp = {} + for name,val in pairs(row) do + tmp[name] = val + end + retval[#retval + 1] = tmp + row = cur:fetch (row, "a") + end + cur:close() + return retval +end + +local listtables = function() + local result = {} + if DBENGINE == "PGSQL" then + 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 + end + else + -- untested + result = con:tables() + end + return result +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") + for i,c in ipairs(col) do + result[#result+1] = c.field + end + end + return result +end -- ################################################################################ -- LOCAL FUNCTIONS @@ -71,36 +183,47 @@ function list_files() return cfe({ type="structure", value=retval, label="List of Kamailio files" }) end -function list_users() - -- Database format: id | username | domain | password | email_address | ha1 | ha1b | rpid - local cmd = path .. "kamctl db show subscriber" +local function parse_db_show(table) + local cmd = path .. "kamctl db show "..(table or "") local f = io.popen(cmd) - -- These settings work for Postgres database - local skiplines = 2 - local delimiter = "%s*|%s*" - local dbengine = format.parse_ini_file(fs.read_file("/etc/kamailio/kamctlrc") or "", "", "DBENGINE") - if dbengine == "DBTEXT" then - skiplines = 0 - delimiter = "\'?%s*,%s*\'?" - end - + -- These settings work for Postgres and DBTEXT database + local delimiter = "\'?%s*[,|]%s*\'?" local results = {} + local errtxt for line in f:lines() do - if skiplines > 0 then - skiplines = skiplines-1 + if #results == 0 and string.match(line, "^ERROR:") then + errtxt = line + results = nil + break + end + if string.match(line, "^[+-]+$") then + results = {} else local words = format.string_to_table(line, delimiter) - if #words > 1 then - local temp = {username = words[2], - --domain = words[3], - password = words[4], - --email_address = words[5] - } - results[#results+1] = temp + if words and #words > 0 then + results[#results+1] = words end end end f:close() + return results, errtxt +end + +function list_users() + -- Database format: id | username | domain | password | email_address | ha1 | ha1b | rpid + local results = {} + local r, errtxt + r, errtxt = parse_db_show("subscriber") + for i,words in ipairs(r or {}) do + if #words > 1 then + local temp = {username = words[2], + --domain = words[3], + password = words[4], + --email_address = words[5] + } + results[#results+1] = temp + end + end table.sort(results, function(a,b) return a.username < b.username end) return cfe({type="list", value=results, label="Kamailio Users"}) end @@ -166,3 +289,176 @@ function update_user(user) return user end + +function list_tables() + local retval = {} + local errtxt + -- Get the devices from the DB + local res, err = pcall(function() + local connected = databaseconnect() + retval = listtables() + if connected then databasedisconnect() end + end) + if not res and err then + errtxt = err + end + + return cfe({ type="list", value=retval, label="List of Database Tables", errtxt=errtxt }) +end + +function list_table_entries(table) + local retval = {} + retval.table = cfe({ value=table or "", label="Table" }) + retval.fields = cfe({ type="list", value={}, label="List of Table Fields" }) + retval.entries = cfe({ type="structure", value={}, label="List of Database Entries" }) + local errtxt + -- Get the devices from the DB + local res, err = pcall(function() + local connected = databaseconnect() + retval.entries.value = getselectresponse("SELECT * FROM "..table.." ORDER BY id ASC") or {} + retval.fields.value = listcolumns(table) or {} + if connected then databasedisconnect() end + end) + if not res and err then + errtxt = err + end + + return cfe({ type="group", value=retval, label="Database Table Entries", errtxt=errtxt }) +end + +function get_table_entry(table, id) + local retval = {} + retval.table = cfe({ value=table or "", label="Table", errtxt="Table does not exist" }) + local errtxt = "Table does not exist" + if table and table ~= "" then + local res, err = pcall(function() + local connected = databaseconnect() + local tables = listtables() + for i,t in ipairs(tables) do + if t == table then + retval.table.errtxt = nil + errtxt = nil + break + end + end + if not errtxt then + local fields = listcolumns(table) + for i,f in ipairs(fields) do + retval[f] = cfe({ label=f, seq=i }) + end + if id and id ~= "" then + local entry = getselectresponse("SELECT * FROM "..table.." WHERE id='"..escape(id).."'") + if entry and #entry > 0 then + for n,v in pairs(entry[1]) do + if retval[n] then retval[n].value = v end + end + end + end + end + if connected then databasedisconnect() end + end) + if not res and err then + errtxt = err + end + end + + return cfe({ type="group", value=retval, label="Database Table Entry", errtxt=errtxt }) +end + +function create_table_entry(entry) + return update_table_entry(entry, true) +end + +function update_table_entry(entry, create) + local success = true + local errtxt + -- Validate the settings + -- relying on get_table_entry to do the validation of table + if entry.value.table.value == "" or entry.value.table.errtxt then + success = false + entry.value.table.errtxt = "Table does not exist" + end + if not create then + if not entry.value.id then + success = false + elseif not entry.value.id.value or entry.value.id.value == "" then + success = false + entry.value.id.errtxt = "Invalid id" + end + end + if success then + local res, err = pcall(function() + local connected = databaseconnect() + if success and not create then + local sql = "SELECT * FROM "..entry.value.table.value.." WHERE id='"..escape(entry.value.id.value).."'" + local tmp = getselectresponse(sql) + if not tmp or #tmp == 0 then + success = false + errtxt = "Entry does not exist" + end + end + if success then + local names = {} + local values = {} + for n,v in pairs(entry.value) do + if n ~= "table" and n ~= "id" then + names[#names+1] = n + values[#values+1] = escape(v.value) + end + end + if create then + sql = "INSERT INTO "..entry.value.table.value.." ("..table.concat(names, ", ")..") VALUES('"..table.concat(values, "', '").."')" + else + sql = "UPDATE "..entry.value.table.value.." SET ("..table.concat(names, ", ")..") = ('"..table.concat(values, "', '").."') WHERE id='"..escape(entry.value.id.value).."'" + end + runsqlcommand(sql) + end + if connected then databasedisconnect() end + end) + if not res and err then + success = false + errtxt = err + end + end + if not success then + if create then + entry.errtxt = errtxt or "Failed to create entry" + else + entry.errtxt = errtxt or "Failed to save entry" + end + end + return entry +end + +function delete_table_entry(table, id) + local result = "" + local errtxt + if not table or table == "" then + errtxt = "Invalid table" + elseif not id or id == "" then + errtxt = "Invalid entry" + else + local res, err = pcall(function() + local connected = databaseconnect() + errtxt = "Invalid table" + local tables = listtables() + for i,t in ipairs(tables) do + if t == table then + errtxt = nil + break + end + end + if not errtxt then + local sql = "DELETE FROM "..table.." WHERE id='"..escape(id).."'" + runsqlcommand(sql) + result = "Entry Deleted" + end + if connected then databasedisconnect() end + end) + if not res and err then + errtxt = err + end + end + + return cfe({ value=result, errtxt=errtxt, label="Delete Entry Result" }) +end diff --git a/kamailio-updatetableentry-html.lsp b/kamailio-updatetableentry-html.lsp new file mode 120000 index 0000000..ee06465 --- /dev/null +++ b/kamailio-updatetableentry-html.lsp @@ -0,0 +1 @@ +kamailio-createtableentry-html.lsp \ No newline at end of file diff --git a/kamailio-viewtable-html.lsp b/kamailio-viewtable-html.lsp new file mode 100644 index 0000000..7d0aa41 --- /dev/null +++ b/kamailio-viewtable-html.lsp @@ -0,0 +1,48 @@ +<% local form, viewlibrary, page_info, session = ... %> +<% require("viewfunctions") %> + +<% displaycommandresults({"deletetableentry", "updatetableentry"}, session) %> +<% displaycommandresults({"createtableentry"}, session, true) %> + +

    <%= html.html_escape(form.label) %> - <%= html.html_escape(form.value.table.value) %>

    +
    + + + <% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %> + + <% end %> + <% for i,f in ipairs(form.value.fields.value) do %> + + <% end %> + + +<% for i,tableentry in ipairs(form.value.entries.value) do %> + + <% if viewlibrary.check_permission("deletetableentry") or viewlibrary.check_permission("updatetableentry") then %> + + <% end %> + <% for i,f in ipairs(form.value.fields.value) do %> + + <% end %> + +<% end %> +
    Action<%= html.html_escape(f) %>
    + <% if viewlibrary.check_permission("updatetableentry") then %> +
    + + + +
    + <% end %> + <% if viewlibrary.check_permission("deletetableentry") then %> +
    + + +
    + <% end %> +
    <%= html.html_escape(tableentry[f]) %>
    +
    + +<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createtableentry") then + viewlibrary.dispatch_component("createtableentry", {table=form.value.table.value}) +end %> diff --git a/kamailio.menu b/kamailio.menu index 607387f..4a9a3e5 100644 --- a/kamailio.menu +++ b/kamailio.menu @@ -2,4 +2,5 @@ # Cat Group Tab Action Applications 86Kamailio Status status Applications 86Kamailio Users listusers +Applications 86Kamailio Database listtables Applications 86Kamailio Expert listfiles diff --git a/kamailio.roles b/kamailio.roles index 111828b..15add79 100644 --- a/kamailio.roles +++ b/kamailio.roles @@ -1,4 +1,4 @@ USER=kamailio:status,kamailio:startstop,kamailio:listusers -EDITOR=kamailio:createuser,kamailio:updateuser,kamailio:deleteuser +EDITOR=kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry EXPERT=kamailio:listfiles,kamailio:edit -ADMIN=kamailio:status,kamailio:startstop,kamailio:listusers,kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listfiles,kamailio:edit +ADMIN=kamailio:status,kamailio:startstop,kamailio:listusers,kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listfiles,kamailio:edit,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry -- cgit v1.2.3 From 802b8d7fe548afad99235db73b9c7ffea64c011b Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 8 Jan 2011 20:30:37 +0000 Subject: Added createdatabase action. --- kamailio-controller.lua | 3 +++ kamailio-listtables-html.lsp | 9 +++++++++ kamailio-model.lua | 7 +++++++ kamailio.roles | 4 ++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/kamailio-controller.lua b/kamailio-controller.lua index 69d3d1d..9352aac 100644 --- a/kamailio-controller.lua +++ b/kamailio-controller.lua @@ -57,3 +57,6 @@ 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") end +function createdatabase(self) + return self:redirect_to_referrer(self.model.create_database()) +end diff --git a/kamailio-listtables-html.lsp b/kamailio-listtables-html.lsp index 6a117e4..49aebc2 100644 --- a/kamailio-listtables-html.lsp +++ b/kamailio-listtables-html.lsp @@ -1,6 +1,8 @@ <% local form, viewlibrary, page_info, session = ... %> <% require("viewfunctions") %> +<% displaycommandresults({"createdatabase"}, session) %> +

    <%= html.html_escape(form.label) %>

    <% for i,table in ipairs(form.value) do %> @@ -11,4 +13,11 @@ <%= html.html_escape(table) %> <% end %> <% end %> +<% if #form.value == 0 and viewlibrary.check_permission("createdatabase") then %> +
    Create Database
    +
    "> +
    + + +<% end %>
    diff --git a/kamailio-model.lua b/kamailio-model.lua index 63be94a..3ace9b2 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -462,3 +462,10 @@ function delete_table_entry(table, id) return cfe({ value=result, errtxt=errtxt, label="Delete Entry Result" }) end + +function create_database() + local cmd = path.."echo -e 'y\ny\n' | "..path.."kamdbctl create 2>&1" + local f = io.popen(cmd) + local result = f:read("*a") + return cfe({ value=result, label="Create database result" }) +end diff --git a/kamailio.roles b/kamailio.roles index 15add79..c425a7b 100644 --- a/kamailio.roles +++ b/kamailio.roles @@ -1,4 +1,4 @@ USER=kamailio:status,kamailio:startstop,kamailio:listusers EDITOR=kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry -EXPERT=kamailio:listfiles,kamailio:edit -ADMIN=kamailio:status,kamailio:startstop,kamailio:listusers,kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listfiles,kamailio:edit,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry +EXPERT=kamailio:listfiles,kamailio:edit,kamailio:createdatabase +ADMIN=kamailio:status,kamailio:startstop,kamailio:listusers,kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listfiles,kamailio:edit,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry,kamailio:createdatabase -- cgit v1.2.3 From 893341b533d71e11f7842883f78b61d2ff19aaba Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 8 Jan 2011 20:36:18 +0000 Subject: Display table name when editing entry --- kamailio-createtableentry-html.lsp | 2 +- kamailio-model.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kamailio-createtableentry-html.lsp b/kamailio-createtableentry-html.lsp index b0dabfa..14ffd0a 100644 --- a/kamailio-createtableentry-html.lsp +++ b/kamailio-createtableentry-html.lsp @@ -4,7 +4,7 @@ require("viewfunctions")

    <%= html.html_escape(form.label) %>

    <% - form.value.table.type = "hidden" + 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 diff --git a/kamailio-model.lua b/kamailio-model.lua index 3ace9b2..5ee381c 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -328,7 +328,7 @@ end function get_table_entry(table, id) local retval = {} - retval.table = cfe({ value=table or "", label="Table", errtxt="Table does not exist" }) + 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 local res, err = pcall(function() -- cgit v1.2.3 From 4086a663fbe9a0830ccf619d1f07c0a6cf15b4c8 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 8 Jan 2011 20:44:54 +0000 Subject: Bumped version to 0.3.0 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0ac2e18..5ab34dd 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=kamailio PACKAGE=acf-$(APP_NAME) -VERSION=0.2.0 +VERSION=0.3.0 APP_DIST=\ kamailio* \ -- cgit v1.2.3 From bc6748e33836019dff67723d67226a6ffdc83019 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 31 Jan 2011 15:45:09 +0000 Subject: Use specified host and port when opening DB connection --- kamailio-model.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio-model.lua b/kamailio-model.lua index 5ee381c..9c24346 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -62,7 +62,7 @@ local databaseconnect = function() end -- connect to data source - con = assert(env:connect(config.DBNAME or "", config.DBRWUSER or "", config.DBRWPW or "")) + con = assert(env:connect(config.DBNAME or "", config.DBRWUSER or "", config.DBRWPW or "", config.DBHOST, config.DBPORT)) return true end return false -- cgit v1.2.3 From 8ceb7e4eb46a498d4d63005dd02b32af012dc4d1 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 31 Jan 2011 15:45:29 +0000 Subject: Bumped version to 0.3.1 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5ab34dd..c41b38b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=kamailio PACKAGE=acf-$(APP_NAME) -VERSION=0.3.0 +VERSION=0.3.1 APP_DIST=\ kamailio* \ -- cgit v1.2.3 From 31f68d1ea1390017773e691cccd0e6f9cc1fd0a7 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 23 Feb 2011 14:24:20 +0000 Subject: Added searchdatabase action --- kamailio-controller.lua | 4 ++++ kamailio-model.lua | 33 +++++++++++++++++++++++++++++++++ kamailio-searchdatabase-html.lsp | 28 ++++++++++++++++++++++++++++ kamailio-viewtable-html.lsp | 5 ++++- kamailio.menu | 1 + kamailio.roles | 4 ++-- 6 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 kamailio-searchdatabase-html.lsp diff --git a/kamailio-controller.lua b/kamailio-controller.lua index 9352aac..ff16c50 100644 --- a/kamailio-controller.lua +++ b/kamailio-controller.lua @@ -60,3 +60,7 @@ end function createdatabase(self) return self:redirect_to_referrer(self.model.create_database()) end + +searchdatabase = function( self ) + return self.model.search_database(self.clientdata.id, self.clientdata.value, self.clientdata.comparison) +end diff --git a/kamailio-model.lua b/kamailio-model.lua index 9c24346..7937ea8 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -469,3 +469,36 @@ function create_database() local result = f:read("*a") return cfe({ value=result, label="Create database result" }) end + +function search_database(id, value, comparison) + local errtxt + retval = {} + retval.id = cfe({type="select", value=id or "", label="Table.Column", option={}, seq=1}) + retval.comparison = cfe({type="select", value=comparison or "=", label="Comparison", option={"=", "!=", "~", "!~", "~*", "!*~"}, seq=2}) + retval.value = cfe({label="Value", value=value or "", descr="Value or SQL regular expression", seq=3}) + local res, err = pcall(function() + local connected = databaseconnect() + local tables = listtables() or {} + for i,t in ipairs(tables) do + local columns = listcolumns(t) or {} + for i,c in ipairs(columns) do + retval.id.option[#retval.id.option + 1] = t.."."..c + end + end + -- Get the rows from the DB + if id and modelfunctions.validateselect(retval.id) and modelfunctions.validateselect(retval.comparison) then + retval.result = cfe({type="structure", value={}, label="List of Rows", seq=4 }) + local table, column = string.match(id, "^([^.]*)%.(.*)") + if table then + local sql = "SELECT * FROM "..table.." WHERE "..column..comparison.."'"..value.."'" + retval.result.value = getselectresponse(sql) + end + end + if connected then databasedisconnect() end + end) + if not res and err then + errtxt = err + end + return cfe({type="group", value=retval, label="Database Search", errtxt=errtxt}) +end + diff --git a/kamailio-searchdatabase-html.lsp b/kamailio-searchdatabase-html.lsp new file mode 100644 index 0000000..87f0a9d --- /dev/null +++ b/kamailio-searchdatabase-html.lsp @@ -0,0 +1,28 @@ +<% local form, viewlibrary, page_info = ... +require("viewfunctions") +%> + +<% if form.value.result then + local func = haserl.loadfile(page_info.viewfile:gsub("searchdatabase", "viewtable")) + local table, column = string.match(form.value.id.value, "^([^.]*)%.(.*)") + form.value.table = cfe({ value=table }) + form.value.fields = cfe({ value={} }) + for i,o in ipairs(form.value.id.option) do + local t,c = string.match(o, "^([^.]*)%.(.*)") + if t == table then + form.value.fields.value[#form.value.fields.value + 1] = c + end + end + form.value.entries = form.value.result + func(form, viewlibrary, page_info, session) + form.value.entries = nil + form.value.table = nil + form.value.fields = nil +end %> + +

    <%= html.html_escape(form.label) %>

    +<% + form.value.result = nil + form.option = "Search" + displayform(form, nil, nil, page_info, 2) +%> diff --git a/kamailio-viewtable-html.lsp b/kamailio-viewtable-html.lsp index 7d0aa41..f0c5ff9 100644 --- a/kamailio-viewtable-html.lsp +++ b/kamailio-viewtable-html.lsp @@ -41,8 +41,11 @@ <% end %> +<% if #form.value.entries.value == 0 then %> +

    No entries found

    +<% end %> -<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createtableentry") then +<% if page_info.action == "viewtable" and viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createtableentry") then viewlibrary.dispatch_component("createtableentry", {table=form.value.table.value}) end %> diff --git a/kamailio.menu b/kamailio.menu index 4a9a3e5..9d51be7 100644 --- a/kamailio.menu +++ b/kamailio.menu @@ -3,4 +3,5 @@ Applications 86Kamailio Status status Applications 86Kamailio Users listusers Applications 86Kamailio Database listtables +Applications 86Kamailio Search_Database searchdatabase Applications 86Kamailio Expert listfiles diff --git a/kamailio.roles b/kamailio.roles index c425a7b..be6e771 100644 --- a/kamailio.roles +++ b/kamailio.roles @@ -1,4 +1,4 @@ USER=kamailio:status,kamailio:startstop,kamailio:listusers -EDITOR=kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry +EDITOR=kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry,kamailio:searchdatabase EXPERT=kamailio:listfiles,kamailio:edit,kamailio:createdatabase -ADMIN=kamailio:status,kamailio:startstop,kamailio:listusers,kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listfiles,kamailio:edit,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry,kamailio:createdatabase +ADMIN=kamailio:status,kamailio:startstop,kamailio:listusers,kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listfiles,kamailio:edit,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry,kamailio:createdatabase,kamailio:searchdatabase -- cgit v1.2.3 From 206148ed3cf2942c2d1eebe7f051391a65c411d7 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 23 Feb 2011 14:28:44 +0000 Subject: Bumped version to 0.3.2 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c41b38b..5cb6925 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=kamailio PACKAGE=acf-$(APP_NAME) -VERSION=0.3.1 +VERSION=0.3.2 APP_DIST=\ kamailio* \ -- cgit v1.2.3 From c13362bf0143eb9a2a49d4070e8b0b78b12a39b9 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 30 Mar 2011 14:49:22 +0000 Subject: Modified for acf-core-0.13.0 --- kamailio-listfiles-html.lsp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kamailio-listfiles-html.lsp b/kamailio-listfiles-html.lsp index caff231..93a00fc 100644 --- a/kamailio-listfiles-html.lsp +++ b/kamailio-listfiles-html.lsp @@ -2,7 +2,7 @@ require("viewfunctions") %> -<% displaycommandresults({"edit", "startstop"}, session) %> +<% displaycommandresults({"edit"}, session) %> <% if viewlibrary and viewlibrary.dispatch_component then viewlibrary.dispatch_component("status") @@ -22,7 +22,3 @@ end %> end %> - -<% if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("startstop") -end %> -- cgit v1.2.3 From 6815f423917d9c43592961acd1fc8c6cc65b30f6 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 30 Mar 2011 14:49:40 +0000 Subject: Bumped version to 0.4.0 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5cb6925..7be0299 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=kamailio PACKAGE=acf-$(APP_NAME) -VERSION=0.3.2 +VERSION=0.4.0 APP_DIST=\ kamailio* \ -- cgit v1.2.3 From 712b8caff7f279896b378afe23b3b4b0b173011b Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 7 Jun 2011 13:46:49 +0000 Subject: Added table validation to list_table_entries and update_table_entry --- kamailio-model.lua | 23 +++++++++++++++++++++-- kamailio-viewtable-html.lsp | 3 +++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/kamailio-model.lua b/kamailio-model.lua index 7937ea8..896a50f 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -315,8 +315,17 @@ function list_table_entries(table) -- Get the devices from the DB local res, err = pcall(function() local connected = databaseconnect() - retval.entries.value = getselectresponse("SELECT * FROM "..table.." ORDER BY id ASC") or {} - retval.fields.value = listcolumns(table) or {} + local tables = listtables() + retval.table.errtxt = "Table does not exist" + errtxt = "Table does not exist" + for i,t in ipairs(tables) do + 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 {} + end + end if connected then databasedisconnect() end end) if not res and err then @@ -389,6 +398,16 @@ function update_table_entry(entry, create) if success then local res, err = pcall(function() local connected = databaseconnect() + local tables = listtables() + success = false + entry.value.table.errtxt = "Table does not exist" + for i,t in ipairs(tables) do + if t == entry.value.table.value then + success = true + entry.value.table.errtxt = nil + break + end + end if success and not create then local sql = "SELECT * FROM "..entry.value.table.value.." WHERE id='"..escape(entry.value.id.value).."'" local tmp = getselectresponse(sql) diff --git a/kamailio-viewtable-html.lsp b/kamailio-viewtable-html.lsp index f0c5ff9..28d4e13 100644 --- a/kamailio-viewtable-html.lsp +++ b/kamailio-viewtable-html.lsp @@ -41,6 +41,9 @@ <% end %> +<% if form.errtxt then %> +

    <%= html.html_escape(form.errtxt) %>

    +<% end %> <% if #form.value.entries.value == 0 then %>

    No entries found

    <% end %> -- cgit v1.2.3 From 7cfb462745a39f0620ff2bc68d82a7a184bcc61b Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 7 Jun 2011 13:48:49 +0000 Subject: Bumped version to 0.4.1 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7be0299..3bae1fb 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=kamailio PACKAGE=acf-$(APP_NAME) -VERSION=0.4.0 +VERSION=0.4.1 APP_DIST=\ kamailio* \ -- cgit v1.2.3 From acfcabcf7191a311011a77d9a3bddd183c5ff933 Mon Sep 17 00:00:00 2001 From: skel Date: Mon, 11 Jul 2011 16:08:18 -0400 Subject: Implemented Reload Dial Plan command. --- kamailio-controller.lua | 5 +++++ kamailio-model.lua | 8 ++++++++ kamailio-status-html.lsp | 44 +++++++++++++++++++++++++++++++++++++++++++- kamailio.roles | 8 ++++---- 4 files changed, 60 insertions(+), 5 deletions(-) mode change 120000 => 100644 kamailio-status-html.lsp diff --git a/kamailio-controller.lua b/kamailio-controller.lua index ff16c50..8cd66ac 100644 --- a/kamailio-controller.lua +++ b/kamailio-controller.lua @@ -61,6 +61,11 @@ function createdatabase(self) return self:redirect_to_referrer(self.model.create_database()) end +function reloadplan(self) + return self:redirect_to_referrer(self.model.reloadplan()) +end + + searchdatabase = function( self ) return self.model.search_database(self.clientdata.id, self.clientdata.value, self.clientdata.comparison) end diff --git a/kamailio-model.lua b/kamailio-model.lua index 896a50f..311fa7c 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -170,6 +170,14 @@ function update_filedetails(filedetails) return modelfunctions.setfiledetails(filedetails, is_valid_filename) end +function reloadplan() + local cmd = path .. " sercmd mi_dg dp_reload" + local f = io.popen(cmd) + local result = f:read("*a") + f:close() + return cfe({value=result, label="Reloading Dial Plan Result"}) +end + function list_files() local retval = {} for file in fs.find(null, baseurl) do diff --git a/kamailio-status-html.lsp b/kamailio-status-html.lsp deleted file mode 120000 index b2f8480..0000000 --- a/kamailio-status-html.lsp +++ /dev/null @@ -1 +0,0 @@ -../status-html.lsp \ No newline at end of file diff --git a/kamailio-status-html.lsp b/kamailio-status-html.lsp new file mode 100644 index 0000000..dd26d27 --- /dev/null +++ b/kamailio-status-html.lsp @@ -0,0 +1,43 @@ +<% local data, viewlibrary, page_info, session = ... +require("viewfunctions") +%> + +<% displaycommandresults({"install","edit"}, session) %> +<% displaycommandresults({"startstop"}, session) %> +<% displaycommandresults({"reloadplan"}, session) %> + +

    System Info

    +
    +<% +displayitem(data.value.status) + +displayitem(data.value.version) +if data.value.version and data.value.version.errtxt and viewlibrary.check_permission("apk-tools/apk/install") then +%> +
    Install package
    +
    +
    +<% +end + +displayitem(data.value.autostart) +if not (data.value.version and data.value.version.errtxt) and data.value.autostart and data.value.autostart.errtxt and viewlibrary.check_permission("alpine-baselayout/rc/edit") then +%> +
    Enable autostart
    +
    +
    +<% end %> +
    + +<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("startstop") then + viewlibrary.dispatch_component("startstop") +end %> + +<% if viewlibrary.check_permission("reloadplan") then %> +

    Reload Dial Plan

    +
    +
    Reload dial plan into memory
    +
    +
    +
    +<% end %> diff --git a/kamailio.roles b/kamailio.roles index be6e771..c5f2ba3 100644 --- a/kamailio.roles +++ b/kamailio.roles @@ -1,4 +1,4 @@ -USER=kamailio:status,kamailio:startstop,kamailio:listusers -EDITOR=kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry,kamailio:searchdatabase -EXPERT=kamailio:listfiles,kamailio:edit,kamailio:createdatabase -ADMIN=kamailio:status,kamailio:startstop,kamailio:listusers,kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listfiles,kamailio:edit,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry,kamailio:createdatabase,kamailio:searchdatabase +USER=kamailio:status,kamailio:startstop,kamailio:listusers,kamailio:reloadplan +EDITOR=kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry,kamailio:searchdatabase,kamailio:reloadplan +EXPERT=kamailio:listfiles,kamailio:edit,kamailio:createdatabase,kamailio:reloadplan +ADMIN=kamailio:status,kamailio:startstop,kamailio:listusers,kamailio:createuser,kamailio:updateuser,kamailio:deleteuser,kamailio:listfiles,kamailio:edit,kamailio:listtables,kamailio:viewtable,kamailio:deletetableentry,kamailio:updatetableentry,kamailio:createtableentry,kamailio:createdatabase,kamailio:searchdatabase,kamailio:reloadplan -- cgit v1.2.3 From 792809f70a96c1c17fe170c1d2aa0b162da122cc Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 13 Jul 2011 20:19:19 +0000 Subject: Fixed bug with package install and autostart forms not working --- kamailio-status-html.lsp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kamailio-status-html.lsp b/kamailio-status-html.lsp index dd26d27..9a8bce3 100644 --- a/kamailio-status-html.lsp +++ b/kamailio-status-html.lsp @@ -15,7 +15,8 @@ displayitem(data.value.version) if data.value.version and data.value.version.errtxt and viewlibrary.check_permission("apk-tools/apk/install") then %>
    Install package
    -
    +
    " method="POST"> +
    <% end @@ -24,7 +25,9 @@ displayitem(data.value.autostart) if not (data.value.version and data.value.version.errtxt) and data.value.autostart and data.value.autostart.errtxt and viewlibrary.check_permission("alpine-baselayout/rc/edit") then %>
    Enable autostart
    -
    +
    " method="POST"> + +
    <% end %> -- cgit v1.2.3 From 729b143227d16ab58b4f69b06dec5f98c52df0d4 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 14 Jul 2011 18:17:57 +0000 Subject: Bumped version to 0.4.2 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3bae1fb..3332530 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=kamailio PACKAGE=acf-$(APP_NAME) -VERSION=0.4.1 +VERSION=0.4.2 APP_DIST=\ kamailio* \ -- cgit v1.2.3 From fe5c65f65a356a31f3f196845eec20df3eca976b Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 3 Jan 2012 16:14:33 +0000 Subject: Fixed escape function to not escape \ --- kamailio-model.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kamailio-model.lua b/kamailio-model.lua index 311fa7c..c121dd1 100644 --- a/kamailio-model.lua +++ b/kamailio-model.lua @@ -32,8 +32,7 @@ end -- Escape special characters in sql statements local escape = function(sql) sql = sql or "" - sql = string.gsub(sql, "'", "''") - return string.gsub(sql, "\\", "\\\\") + return string.gsub(sql, "'", "''") end local databaseconnect = function() -- cgit v1.2.3 From e19ee215667692e70cb4788dca4151e23aa73b96 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 27 Jan 2012 19:57:22 +0000 Subject: Bumped version to 0.4.3 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3332530..80e34f1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ APP_NAME=kamailio PACKAGE=acf-$(APP_NAME) -VERSION=0.4.2 +VERSION=0.4.3 APP_DIST=\ kamailio* \ -- cgit v1.2.3