summaryrefslogtreecommitdiffstats
path: root/www
diff options
context:
space:
mode:
Diffstat (limited to 'www')
-rw-r--r--www/Makefile4
-rwxr-xr-xwww/cgi-bin/acf2
-rwxr-xr-xwww/cgi-bin/cli53
-rwxr-xr-xwww/cgi-bin/mvc.lua357
-rw-r--r--www/sample.html117
5 files changed, 1 insertions, 532 deletions
diff --git a/www/Makefile b/www/Makefile
index 5bc108c..71e6c62 100644
--- a/www/Makefile
+++ b/www/Makefile
@@ -1,10 +1,7 @@
include ../config.mk
WWW_DIST=cgi-bin/acf\
- cgi-bin/cli\
- cgi-bin/mvc.lua\
index.html\
- sample.html\
EXTRA_DIST=Makefile
DISTFILES=$(WWW_DIST) $(EXTRA_DIST)
@@ -36,6 +33,5 @@ install:
cp "$$i" "$$dest";\
done
chmod 755 $(install_dir)/cgi-bin/acf
- chmod 700 $(install_dir)/cgi-bin/cli
.PHONY: $(phony)
diff --git a/www/cgi-bin/acf b/www/cgi-bin/acf
index d866de9..7f6592d 100755
--- a/www/cgi-bin/acf
+++ b/www/cgi-bin/acf
@@ -1,6 +1,6 @@
#!/usr/bin/haserl --shell=lua --upload-limit=256
<%
-require("mvc")
+mvc = require("acf.mvc")
-- create a new container
FRAMEWORK=mvc:new()
diff --git a/www/cgi-bin/cli b/www/cgi-bin/cli
deleted file mode 100755
index 437a211..0000000
--- a/www/cgi-bin/cli
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/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
-
-require("posix")
-local PATH = package.path
-local p = posix.dirname(arg[0])
-if p:sub(1,1) ~= "/" then p = posix.getcwd().."/"..p end
-package.path = p.."/?.lua;" .. package.path
-require("mvc")
-package.path = PATH
-
--- this is to get around having to store
--- 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 = {}
-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()
-APP:destroy()
-FRAMEWORK:destroy()
diff --git a/www/cgi-bin/mvc.lua b/www/cgi-bin/mvc.lua
deleted file mode 100755
index 41aa9db..0000000
--- a/www/cgi-bin/mvc.lua
+++ /dev/null
@@ -1,357 +0,0 @@
---[[ Basic MVC framework
- Written for Alpine Configuration Framework (ACF)
- see www.alpinelinux.org for more information
- Copyright (C) 2007 Nathan Angelacos
- Licensed under the terms of GPL2
- ]]--
-module(..., package.seeall)
-
-require("posix")
-
-mvc = {}
-
--- the constructor
---[[ Builds a new MVC object. If "module" is given, then tries to load
- self.conf.appdir .. module "-controller.lua" in c.worker and
- self.conf.appdir .. module "-model.lua" in c.model
-
- The returned .conf table is guaranteed to have the following
- appdir - where the application lives
- confdir - where the configuration file is
- sessiondir - where session data and other temporary stuff goes
- appname - the name of the application
- ]]
-
-new = function (self, modname)
- local model_loaded = true
- local worker_loaded = true
- local c = {}
- c.worker = {}
- c.model = {}
-
- -- make defaults if the parent doesn't have them
- if self.conf == nil then
- c.conf = { appdir = "", confdir = "",
- tempdir = "", appname = "" }
- end
-
- -- If no clientdata, then clientdata is a null table
- if self.clientdata == nil then
- c.clientdata = {}
- end
-
- -- If we don't have an application name, use the modname
- if (self.conf == nil ) or (self.conf.appname == nil) then
- c.conf.appname = modname
- end
-
- -- load the module code here
- if (modname) then
- c.worker = self:soft_require( modname .. "-controller")
- if c.worker == nil then
- c.worker = {}
- worker_loaded = false
- end
- c.model = self:soft_require( modname .. "-model" )
- if c.model == nil then
- c.model = {}
- model_loaded = false
- end
- end
-
- -- The magic that makes all the metatables point in the correct
- -- direction. c.model -> c.worker -> parent -> parent.worker ->
- -- grandparent -> grandparent -> worker (and so on)
-
- -- The model looks in worker for missing
- setmetatable (c.model, c.model )
- c.model.__index = c.worker
-
- -- the worker looks in the parent table for missing
- setmetatable (c.worker, c.worker)
- c.worker.__index = self
-
- -- the table looks in the worker for missing
- setmetatable (c, c)
- c.__index = c.worker
-
- -- ensure an "mvc" table exists, even if empty
- if (type(rawget(c.worker, "mvc")) ~= "table") then
- c.worker.mvc = {}
- end
-
- setmetatable (c.worker.mvc, c.worker.mvc)
- -- If creating a new parent container, then
- -- we are the top of the chain.
- if (modname) then
- c.worker.mvc.__index = self.worker.mvc
- else
- c.worker.mvc.__index = self.mvc
- end
-
- -- run the worker on_load code
- if type(rawget(c.worker.mvc, "on_load")) == "function" then
- c.worker.mvc.on_load(c, self)
- c.worker.mvc.on_load = nil
- end
-
- -- save the new self on the SELF stack
- if not SELF then SELF = {} end
- SELF[#SELF + 1] = c
-
- return c, worker_loaded, model_loaded
-end
-
-destroy = function (self)
- if type(rawget(self.worker.mvc, "on_unload")) == "function" then
- self.worker.mvc.on_unload(self)
- self.worker.mvc.on_unload = nil
- end
-
- -- remove the self from the SELF stack (should be at the end, but just in case)
- if SELF then
- for i,s in ipairs(SELF) do
- if s == self then
- table.remove(SELF, i)
- break
- end
- end
- end
-
- -- remove packages from package.loaded
- if self["_NAME"] then package.loaded[self["_NAME"]] = nil end
- if self.model and self.model["_NAME"] then package.loaded[self.model["_NAME"]] = nil end
-end
-
--- This is a sample front controller/dispatch.
-dispatch = function (self, userprefix, userctlr, useraction)
- local controller = nil
- local success, err = xpcall ( function ()
-
- if userprefix == nil then
- self.conf.prefix, self.conf.controller, self.conf.action =
- parse_path_info(ENV["PATH_INFO"])
- else
- self.conf.prefix = userprefix
- self.conf.controller = userctlr or ""
- self.conf.action = useraction or ""
- end
-
- -- If they didn't provide a controller, and a default was specified
- -- use it
- if self.conf.controller == "" and self.conf.default_controller then
- self.conf.controller = self.conf.default_controller
- self.conf.prefix = self.conf.default_prefix or "/"
- end
-
- local worker_loaded
- controller, worker_loaded = self:new(self.conf.prefix .. self.conf.controller)
-
- if not worker_loaded then
- self.conf.type = "dispatch"
- error(self.conf)
- end
-
- if controller.conf.action == "" then
- controller.conf.action = rawget(controller.worker, "default_action") or ""
- end
-
- local action = controller.conf.action
-
- -- Because of the inheritance, normally the
- -- controller.worker.action will flow up, so that all children have
- -- actions of all parents. We use rawget to make sure that only
- -- controller defined actions are used on dispatch
- -- If the action is missing, raise an error
- if ( type(rawget(controller.worker, action)) ~= "function") then
- self.conf.type = "dispatch"
- error (self.conf)
- end
-
- -- run the (first found) pre_exec code, starting at the controller
- -- and moving up the parents
- if type(controller.worker.mvc.pre_exec) == "function" then
- controller.worker.mvc.pre_exec ( controller )
- end
-
- -- run the action
- local viewtable = controller.worker[action](controller)
-
- -- run the post_exec code
- if type(controller.worker.mvc.post_exec) == "function" then
- controller.worker.mvc.post_exec ( controller )
- end
-
- local viewfunc = controller:view_resolver()
-
- -- we're done with the controller, destroy it
- controller:destroy()
- controller = nil
-
- viewfunc (viewtable)
- end,
- self:soft_traceback(message)
- )
-
- if not success then
- local handler
- if controller then
- handler = controller.worker or controller
- if handler then handler:exception_handler(err) end
- controller:destroy()
- controller = nil
- end
- if nil == handler then
- handler = self.worker or mvc
- handler:exception_handler(err)
- end
- end
-end
-
--- Tries to see if name exists in the self.conf.appdir, and if so, it loads it.
--- otherwise, returns nil, but no error
-soft_require = function (self, name )
- local filename, file
- for p in string.gmatch(self.conf.appdir, "[^,]+") do
- filename = p .. name .. ".lua"
- file = io.open(filename)
- if file then
- file:close()
- local PATH=package.path
- -- FIXME - this should really try to open the lua file,
- -- and if it doesnt exist silently fail.
- -- This version allows things from /usr/local/lua/5.1 to
- -- be loaded
- package.path = p .. "/?.lua;" .. package.path
- local t
- if posix.dirname(name) == "." then
- t = require(posix.basename(name))
- else
- t = require(posix.basename(posix.dirname(name)).."."..posix.basename(name))
- end
- package.path = PATH
- return t
- end
- end
- return nil
-end
-
--- look in various places for a config file, and store it in self.conf
-read_config = function( self, appname )
- appname = appname or self.conf.appname
- self.conf.appname = self.conf.appname or appname
-
- local confs = { (ENV["HOME"] or ENV["PWD"] or "") .. "/." ..
- appname .. "/" .. appname .. ".conf",
- ( ENV["HOME"] or ENV["PWD"] or "") .. "/" ..
- appname .. ".conf",
- ENV["ROOT"] or "" .. "/etc/" .. appname .. "/" ..
- appname .. ".conf",
- ENV["ROOT"] or "" .. "/etc/" .. appname .. ".conf"
- }
- for i, filename in ipairs (confs) do
- local file = io.open (filename)
- if (file) then
- self.conf.confdir = posix.dirname(filename) .. "/"
- self.conf.conffile = filename
- for line in file:lines() do
- key, value = string.match(line, "^%s*([^[=%s#]*)%s*=%s*(.*)")
- if key then
- self.conf[key] = value
- end
- end
- file:close()
- break
- end
- end
-
- if (#self.conf.confdir) then -- check for an appname-hooks.lua file
- self.conf.app_hooks = {}
- setmetatable (self.conf.app_hooks, {__index = _G})
-
- -- loadfile loads into the global environment
- -- so we set env 0, not env 1
- setfenv (0, self.conf.app_hooks)
- local f = loadfile(self.conf.confdir .. "/" .. appname.. "-hooks.lua")
- if (f) then f() end
- setfenv (0, _G)
- -- setmetatable (self.conf.app_hooks, {})
- end
-
-end
-
--- parse a "URI" like string into a prefix, controller and action
--- return them (or blank strings)
-parse_path_info = function( str )
- str = str or ""
- local words = {}
- str = string.gsub(str, "/+$", "")
- for x=1,3 do
- words[#words+1] = string.match(str, "[^/]+$")
- str = string.gsub(str, "/+[^/]*$", "")
- end
- prefix = "/"..(words[#words] or "").."/"
- if prefix == "//" then prefix = "/" end
- controller = words[#words-1] or ""
- action = words[#words-2] or ""
-
- return prefix, controller, action
-end
-
--- The view resolver of last resort.
-view_resolver = function(self)
- return function()
- if ENV["REQUEST_METHOD"] then
- io.write ("Content-type: text/plain\n\n")
- end
- io.write ("Your controller and application did not specify a view resolver.\n")
- io.write ("The MVC framework has no view available. sorry.\n")
- return
- end
-end
-
--- Generates a debug.traceback if called with no arguments
-soft_traceback = function (self, message )
- if message then
- return message
- else
- return debug.traceback
- end
-end
-
--- The exception hander of last resort
-exception_handler = function (self, message )
- if ENV["REQUEST_METHOD"] then
- print ("Content-Type: text/plain\n\n")
- end
- print ("The following unhandled application error occured:\n\n")
-
- if (type(message) == "table" ) then
- if (message.type == "dispatch") then
- print ('controller: "' .. message.controller .. '" does not have a "' ..
- message.action .. '" action.')
- else
- print ("An error of type: '" .. (tostring(message.type) or "nil") .. "' was raised." )
- end
- else
- print (tostring(message))
- end
-end
-
--- create a Configuration Framework Entity (cfe)
--- returns a table with at least "value", "type", and "label"
-cfe = function ( optiontable )
- optiontable = optiontable or {}
- me = { value="",
- type="text",
- label="" }
- for key,value in pairs(optiontable) do
- me[key] = value
- end
- return me
-end
-_G.cfe = cfe
-
-logevent = function ( ... )
- os.execute ( "logger \"ACF: " .. (... or "") .. "\"" )
-end
diff --git a/www/sample.html b/www/sample.html
deleted file mode 100644
index e4c9e14..0000000
--- a/www/sample.html
+++ /dev/null
@@ -1,117 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//ddD HTML 4.01 Transitional//EN">
-<html lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-<title>Alpine</title>
-<link rel="stylesheet" type="text/css" href="snow/snow.css">
-</head>
-
-
-<body>
-<div id=header>
- <a href="#Content" class="hide">[Skip to main content]</a>
- <h1 class="logo">AlpineLinux</h1>
- <div class="leader">[ this is h-leader div text <a href="#Content">Goto content</a>]</div>
- <p>This is plain old Head div text</p>
-</div>
-
-<div id="main">
- <div id="nav">
- <ul><li>Networking
- <ul><a href=""><li>Interfaces</li></a>
- <a href=""><li>Firewall</li></a>
- <a href=""><li>BGP</li></a>
- <a href=""><li>DHCP Server</li></a>
- <a href=""><li>Ipsec VPN</li></a>
- </ul></li>
- <li>Applications
- <ul><li><a href="">Web Proxy</a></li>
- <li><a href="">Content Filter</a></li>
- <li><a href="">Fetchmail</a></li>
- <li><a href="">Certificate Authority</a></li>
- </ul></li>
- <li>System
- <ul><li><a href="">Backup</a></li>
- <li><a href="">Package Management</a></li>
- <li><a href="">General Health</a></li>
- <li><a href="">System Logs</a></li>
- <li><a href="">SNMP</a></li>
- </ul></li>
- </ul>
- </div>
-
- <div class="postnav">
- <h2>Networking : Interfaces</h2>
- <p>[ welcome ] > [ login ] > [ bgp ] > [ firewall ] > [ content filter ] > [ interfaces ]</p>
- </div>
- <a name="Content"></a>
- <div id="subnav">
- <a href="">Nav 1</a>
- <strong class=selected>Nav 2</strong>
- <a href="">Nav 3</a>
- </div>
-
- <div id="content">
-
-
-
- <p>
-This is plain old content
-</p>
-
-
-<h1>Errors</h1>
-<p class="error">This is error text. As if you didn't know that. Just check the errors below.</p>
-<p class="hide">This is some plain content level hide text</p>
-<p>This is a page with a <a href="foo">link</a> in it.</p>
-
-<h1>Networking - Status</h1>
-<p>This is the networking page. This is a very long paragraph in that page, talking about
-all the good things on this page. This is not the real page, its just a standin page for
-the page you want. Evenutally, you'll see the page you want. But not quite yet.</p>
-
-<h2>Status</h2>
-<p>The service is running</p>
-<form>
-<dl>
-<dt>bozo</dt>
-<dd><input class=error type=text value="Baz" name=bozo size=3>This is error text</dd>
-
-<dt>foo</dt><dd>
-<input type=text value="foo" name=foo size=40>
-</dd>
-
-<dt>Command</dt>
-<dd>
-<input type=submit value="Start" name="cmd">
-<input type=submit value="Stop" name="cmd">
-<input type=submit value="Restart" name="cmd">
-</dd>
-
-<dt>Textbox</dt>
-<dd><textarea cols=80 rows=10 name="textbox">fooo</textarea>
-</dd>
-
-
-<dt>A Tag with no form element</dt>
-<dd>This is just some text</dd>
-
-</dl>
-</form>
-
-<h2>Configure</h2>
-<p>Bring Service Down</p>
-<p>Bring Service Up</p>
-</div>
-</div>
-
-<div id=c-trailer>This is c-trailer</div>
-
-<div id="footer">
- <div id="f-leader">F leader</div>
- <p>Made with care by webconf</p>
- <div id="f-nav">F nav</div>
- <div id="f-trailer">F trailer</div>
-</div>
-</body>
-</html>