summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/Makefile1
-rw-r--r--app/acf_cli-controller.lua21
-rw-r--r--lib/controllerfunctions.lua17
-rw-r--r--www/Makefile2
-rw-r--r--www/cgi-bin/cli52
5 files changed, 74 insertions, 19 deletions
diff --git a/app/Makefile b/app/Makefile
index 4616aac..ba4258a 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -19,6 +19,7 @@ APP_DIST= \
acf-util/password-status-html.lsp \
acf-util/password.menu \
acf_www-controller.lua\
+ acf_cli-controller.lua\
menuhints.menu\
template-html.lsp\
template-stream.lsp\
diff --git a/app/acf_cli-controller.lua b/app/acf_cli-controller.lua
index 60d9a9e..e3f160d 100644
--- a/app/acf_cli-controller.lua
+++ b/app/acf_cli-controller.lua
@@ -5,7 +5,6 @@ local parent_exception_handler
mvc = {}
mvc.on_load = function (self, parent)
-
-- Make sure we have some kind of sane defaults for libdir and sessiondir
self.conf.libdir = self.conf.libdir or ( self.conf.appdir .. "/lib/" )
self.conf.sessiondir = self.conf.sessiondir or "/tmp/"
@@ -29,16 +28,26 @@ end
view_resolver = function(self)
- return function (viewtable)
- print(viewtable)
- end
+ return function (viewtable)
+ print(session.serialize("result", viewtable))
+ end
end
+--[[ The parent exception handler is just fine
exception_handler = function (self, message )
- print(message)
+ print(session.serialize("exception", message))
+end
+--]]
+
+redirect = function (self, str, result)
+ return result
+end
+
+redirect_to_referrer = function(self, result)
+ return result
end
-- syslog something
-logit = function ( ... )
+logevent = function ( ... )
os.execute ( "logger \"" .. ... .. "\"" )
end
diff --git a/lib/controllerfunctions.lua b/lib/controllerfunctions.lua
index ef910d2..bccd847 100644
--- a/lib/controllerfunctions.lua
+++ b/lib/controllerfunctions.lua
@@ -20,6 +20,15 @@ function handle_clientdata(form, clientdata)
if value.type == "boolean" then
value.value = (clientdata[name] ~= nil)
elseif value.type == "multi" then
+ if clientdata[name] == nil then
+ -- for cli we use name[num] as the name
+ clientdata[name] = {}
+ for n,val in pairs(clientdata) do
+ if string.find(n, "^"..name.."%[%d+%]$") then
+ clientdata[name][tonumber(string.match(n, "%[(%d+)%]$"))] = val
+ end
+ end
+ end
-- FIXME this is because multi selects don't work in haserl
local oldtable = clientdata[name] or {}
-- Assume it's a sparse array, and remove blanks
@@ -33,9 +42,17 @@ function handle_clientdata(form, clientdata)
elseif value.type == "list" then
value.value = {}
if clientdata[name] and clientdata[name] ~= "" then
+ -- for www we use \r separated list
for ip in string.gmatch(clientdata[name].."\n", "%s*(%S[^\n]*%S)%s*\n") do
table.insert(value.value, ip)
end
+ else
+ -- for cli we use name[num] as the name
+ for n,val in pairs(clientdata) do
+ if string.find(n, "^"..name.."%[%d+%]$") then
+ value.value[tonumber(string.match(n, "%[(%d+)%]$"))] = val
+ end
+ end
end
else
value.value = clientdata[name] or value.value
diff --git a/www/Makefile b/www/Makefile
index ca885c0..75453c8 100644
--- a/www/Makefile
+++ b/www/Makefile
@@ -1,6 +1,7 @@
include ../config.mk
WWW_DIST=cgi-bin/acf\
+ cgi-bin/cli\
cgi-bin/mvc.lua\
index.html\
sample.html\
@@ -36,6 +37,7 @@ install:
cp "$$i" "$$dest";\
done
chmod +x $(install_dir)/cgi-bin/acf
+ chmod +x $(install_dir)/cgi-bin/cli
.PHONY: $(phony)
diff --git a/www/cgi-bin/cli b/www/cgi-bin/cli
index 85ad41e..9e8ce02 100644
--- a/www/cgi-bin/cli
+++ b/www/cgi-bin/cli
@@ -1,22 +1,48 @@
+#!/usr/bin/lua
+if #arg == 0 then
+ print([[ACF Client interface
+
+Usage: cli [action] [parameter]...
+
+Actions are of the form "prefix/controller/action"
+Parameters are of the form "parameter=value"
+ list and multi select parameters are of the form "parameter[1]=value"
+ boolean parameters are true if defined, false is undefined
+
+Example:
+cli acf-util/password/newuser password="test123" password_confirm="test123" roles[1]="ADMIN" userid="root" Create
+
+For forms, remember to pass in the "option" value as a parameter (see Create in example above).
+Output will be a serialized Lua table.
+ ]])
+ return
+end
+
+local PATH = package.path
+package.path = "/usr/share/acf/www/cgi-bin/?.lua;" .. package.path
require("mvc")
+package.path = PATH
+
-- this is to get around having to store
--- -- the config file in /etc/helloworld/helloworld.conf
+-- the config file in /etc/helloworld/helloworld.conf
ENV={}
ENV.HOME="."
FRAMEWORK=mvc:new()
FRAMEWORK:read_config("acf")
APP=FRAMEWORK:new("acf_cli")
+
+-- command line will have URI-type string defining prefix/controller/action
+-- (put into ENV.PATH_INFO)
+-- followed by parameters
+-- (put into APP.clientdata)
+ENV.PATH_INFO = arg[1]
APP.clientdata = {}
-local cmd={}
-for i = 2, #arg do
- a,v = string.match(arg[i], "([^=]-)=(.*)")
- if v then
- APP.clientdata[a] = v
- else
- cmd[#cmd + 1] = a
- end
+for i=2,#arg do
+ a,v = string.match(arg[i], "([^=]*)=(.*)")
+ if v then
+ APP.clientdata[a] = v
+ else
+ APP.clientdata[arg[i]] = true
+ end
end
-APP:dispatch("", cmd[1], cmd[2] or "")
-
--- vim: set filetype=lua :
-
+APP:dispatch()