diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Makefile | 3 | ||||
| -rw-r--r-- | lib/log_view.lua | 56 | ||||
| -rw-r--r-- | lib/service_controller.lua | 189 | ||||
| -rw-r--r-- | lib/service_model.lua | 115 | 
4 files changed, 0 insertions, 363 deletions
| diff --git a/lib/Makefile b/lib/Makefile index 5fa957c..9c726ae 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -3,12 +3,9 @@ include ../config.mk  LIB_DIST=fs.lua\  	html.lua\  	join.lua\ -	log_view.lua\  	menubuilder.lua\  	pidof.lua\  	privsep.lua\ -	service_controller.lua\ -	service_model.lua\  	session.lua\  	split.lua\  	validator.lua\ diff --git a/lib/log_view.lua b/lib/log_view.lua deleted file mode 100644 index f32400e..0000000 --- a/lib/log_view.lua +++ /dev/null @@ -1,56 +0,0 @@ -require ("web_elements")  - -local function fwrite(fmt, ...) -	return io.write(string.format(fmt, ...)) -end - -local function footer(time) -	fwrite("<div id=\"footer\">\n<p>This request was processed in approximately %d seconds</p>\n</div>",time) -end - -header = [[ -content-type: text/html -    -<!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 log view</title> -<link rel="stylesheet" type="text/css" href="/static/webconf.css" /> -<meta http-equiv='Cache-Control' content='no-cache' /> -<Meta http-equiv='Pragma' content='no-cache' /> -</head>]] - ---  - -print(header) -print("<body>\n<div id=\"head\">") - -fwrite("<h1>%s</h1>",cf.hostinfo.alpine_hostname) - -fwrite("<p><em>%s</em></p>",cf.hostinfo.alpine_release) - -print("</div>") - -print ('<div id="mainmenu">') -local group, cat, subcat =  -		web_elements.render_mainmenu ( menu, cf.prefix, cf.controller, cf.action ) -print([[ -</div> - -<div id="submenu">]]) -web_elements.render_submenu ( menu, group, cat, subcat ) -print([[</div> - -<div id="content"> -<p>]]) --- get the wc and view tables --- walk the tree -web_elements.render_table ( view ) -print("</p>\n</div>") - -print(footer(cf.time)) -print("</body></html>") - --- /* vim: set filetype=lua : */ diff --git a/lib/service_controller.lua b/lib/service_controller.lua deleted file mode 100644 index 09595a4..0000000 --- a/lib/service_controller.lua +++ /dev/null @@ -1,189 +0,0 @@ -local function build_status(model, name) -    return { -	type = "form", -	method = "post", -	action = cf.uri .. "/chrun", -	value = { -	    { -		type = "formtext", -		name = "status", -		label = "Status: <B>" .. name .. "</B>", -		value = model.status(name) -	    }, -	    { -		type = "hidden", -		name = "service", -		value = name -	    }, -	    { -		type = "submit", -		name = "cmd", -		label = "Running controls", -		value = { "Start", "Stop", "Restart" } -	    }, -	} -    } -end - -local function build_note(model, name) -    return { -	type = "form", -	method = "post", -	action = cf.uri .. "/note_set", -	value = { -	    { -		type = "textarea", -		name = "note", -		label = "Notes", -		cols = 80, -		rows = 8, -		value = model.get_note(name) -	    }, -	    { -		type = "submit", -		label = "Command", -		value = "Save" -	    } -	} -    } -end - -local function mkerr(str) -    return { -	{ -	    type = "formtext", -	    class = "error", -	    value = str -	} -    } -end - -local function mkresult(str) -    return { -	{ -	    type = "formtext", -	    value = str -	} -    } -end - -local function chrun(model, name, ucmd) -    local cmd = string.lower(ucmd) -    --TODO chect that name is in get_service_names() -    if cmd ~= "start" and cmd ~= "stop" and cmd ~= "restart" then -	return mkerr("unknown command") -    end -    return mkresult(model.initd(name, cmd)) -end - -local function build_log_file(model, name) -    return { -	type = "group", -	label = name, -	text = "FILE " .. model.get_log_names()[name].path, -	value = { -	    { -		type = "log", -		lines = model.get_log_producer(name) -	    } -	} -    } -end - -local function build_edit_file(model, name) -    return { -	type = "form", -	method = "post", -	action = cf.uri .. "/cfg_set", -	value = { -	    { -		type = "textarea", -		name = "cfg", -		label = name, -		cols = 80, -		rows = 12, -		value = model.get_cfg(name) -	    }, -	    { -		type = "hidden", -		name = "name", -		value = name -	    }, -	    { -		type = "submit", -		label = "Command", -		value = "Save" -	    } -	} -    } - -end - -local function build_cfg(model) -    local ret = {} -    for name, whatever in pairs(model.get_cfg_names()) do -	table.insert(ret, build_edit_file(model, name)) -    end -    return ret -end - -local function set_cfg(model) -    for name, whatever in pairs(model.get_cfg_names()) do -	if name == FORM.name then -	    model.set_cfg(name, FORM.cfg) -	    return -	end -    end  -    return mkerr("unknown config") -end - -local function build_log(model) -    local ret = {} -    for name, whatever in pairs(model.get_log_names()) do -	table.insert(ret, build_log_file(model, name)) -    end -    return ret  -end - -local function build_service(model) -    local ret = {} -    for name, whatever in pairs(model.get_service_names()) do -	table.insert(ret, build_status(model, name)) -    end -    table.insert(ret, build_note(model)) -    return ret -end - -function create_service_controller() - -    local me = {} - -    me.service = build_service -    me.default = me.service -    me.cfg = build_cfg -    me.log = build_log - -    function me.chrun(model) -	return chrun(model, FORM.service, FORM.cmd) -    end - -    function me.note_set(model) -	local ret = model.set_note(FORM.note) -	if ret then -	    return ret -	end -	return me.service(model) -    end - - -    function me.cfg_set(model) -	set_cfg(model) -	return me.cfg(model) -    end - -    return me - -end - --- /* vim: set filetype=lua shiftwidth=4: */ - diff --git a/lib/service_model.lua b/lib/service_model.lua deleted file mode 100644 index 3f81794..0000000 --- a/lib/service_model.lua +++ /dev/null @@ -1,115 +0,0 @@ -require("fs") - -function create_service_model(cfglist, loglist, servlist, notepath) - -	local me = {} - -	local function get_any_pid(pname) -		for e in posix.files("/proc") do -			if e == string.match(e, "^%d*$") then -				for line in io.lines("/proc/" .. e .. "/status") do -					tag, val = string.match(line, "^([^:]*):%s*(%S*)$"); -					if tag == "Name" then -						if val == pname then return e end -						break -					end -				end -			end -		end -	end - -	local function get_cfg_path(name) -		if not cfglist or not cfglist[name] then -			return -		end -		return cfglist[name].path -	end - -	local function get_log_path(name) -		if not loglist or not loglist[name] then -			return -		end -		return loglist[name].path -	end - -	--[[ Public Functions go here ]]-- - -	function me.status(name) -		if not servlist or not servlist[name] then -			return "unknown service" -		end -		local cmdname = servlist[name].cmdname -		if get_any_pid(cmdname) == nil then -			return "seems to be stopped" -		else -			return "seems to be running" -		end -	end - -	function me.initd(name, action) -		if not servlist or not servlist[name] then -			return "unknown service" -		end -		local p = io.popen("/etc/init.d/" -			.. servlist[name].initdname .. " " .. action, "r") -		local ret = p:read("*a") -		p:close() -		return ret -	end - -	function me.get_note() -		if not notepath or not fs.is_file(notepath) then return "" end -		return fs.read_file(notepath) -	end - -	function me.set_note(value) -		if notepath == nil then return end -		fs.write_file(notepath, value) -	end - -	function me.get_cfg_names() -		return cfglist     -	end - -	function me.get_log_names() -		return loglist     -	end - -	function me.get_service_names() -		return servlist -	end - -	function me.get_cfg(name) -		local path = get_cfg_path(name) -		if not path or not fs.is_file(path) then -			return "" -		end -		return fs.read_file(path) -	end - -	function me.set_cfg(name, value) -		local path = get_cfg_path(name) -		if path then -			fs.write_file(path, value) -		end -	end - --- 	local function wrap_single(x) --- 		return function(state, prev) --- 			if not prev then --- 				return x --- 			end --- 		end --- 	end - -	function me.get_log_producer(name) -		local path = get_log_path(name) -		if not path or not fs.is_file(path) then -			return "cannot access " .. path -		end -		return io.lines(path) -	end - -	return me - -end | 
