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