diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/debugs.lua | 51 | ||||
-rw-r--r-- | lib/ipcalc.lua | 55 | ||||
-rw-r--r-- | lib/privsep.lua | 75 | ||||
-rw-r--r-- | lib/web_elements.lua | 156 |
4 files changed, 0 insertions, 337 deletions
diff --git a/lib/debugs.lua b/lib/debugs.lua deleted file mode 100644 index 32eec7c..0000000 --- a/lib/debugs.lua +++ /dev/null @@ -1,51 +0,0 @@ ---Show various debug information - -module(..., package.seeall) - -require("session") ---local cnt = 0 - -function serialize ( view, cnt ) - if type(view) == "string" then - io.write(" ><span2 style='color:black'>") - io.write(string.format("%q", view)) - io.write("</span2><") - elseif type(view) == "number" then - io.write(" ><span2 style='color:black'>") - io.write(view) - io.write("</span2><") - elseif type(view) == "table" then - cnt = cnt + 1 --- io.write("<BR>") - for k,v in pairs(view) do - io.write("<br>") - io.write(string.rep("{ ",cnt), "<B>", k, "</B>") - serialize(v, cnt) - end --- io.write("}\n") - else - error("Cannot serialize a " .. type(view)) - end -end - -function variables ( view ) - io.write [[ - <span style='color:#D2691E;font-family:courier;'> - <h2>DEBUG INFO: THIS VIEW CONTAINS THE FOLLOWING VARIABLES/TABLES</h2> - ------------ START DEBUG INFORMATION ------------<BR>]] - serialize(view,0) - io.write( "<BR><BR>------------ END DEBUG INFORMATION ------------</span>") - return -end - - --- from http://lua-users.org/wiki/MakingLuaLikePhp -function print_r (t, indent) -- alt version, abuse to http://richard.warburton.it - local indent=indent or '' - for key,value in pairs(t) do - io.write(indent,'[',tostring(key),']') - if type(value)=="table" then io.write(':\n') print_r(value,indent..'\t') - else io.write(' = ',tostring(value),'\n') end - end -end - diff --git a/lib/ipcalc.lua b/lib/ipcalc.lua deleted file mode 100644 index fb05561..0000000 --- a/lib/ipcalc.lua +++ /dev/null @@ -1,55 +0,0 @@ - -module (..., package.seeall) -require("bit") - -function iptoint(str) - -- TODO: support "a.", "a.b.", "a.b.c." - local a,b,c,d = string.match(str, "(%d+).(%d+).(%d+).(%d+)") - if a and b and c and d then - return bit.lshift(a, 24) + bit.lshift(b, 16) + bit.lshift(c, 8) + d - end - return nil -end - -function nettoint(net, mask) - if mask == nil then - mask = string.match(net, "/(.*)") - if mask == nil then - -- no mask provied at all - return iptoint(net) - end - net = string.gsub(net, "/.*", "") - end - - local n = tonumber(mask) - if n == nil then - -- mask is a.b.c.d style - return iptoint(net), iptoint(mask) - end - - -- mask is /24 style - if n > 32 then - return nil - end - return iptoint(net), bit.band(bit.lshift(0xfffffffff, 32 - n), 0xffffffff) -end - - --- same_subnet - check if address is in net/mask --- synopsis: --- same_subnet(addr, net[/mask][, mask]) --- example: --- same_subnet("10.0.0.1", "10.0.0.0/24") --- same_subnet("10.0.0.1", "10.0.0.0", "24") --- same_subnet("10.0.0.1", "10.0.0.0/255.255.255.0") --- same_subnet("10.0.0.1", "10.0.0.0", "255.255.255.0") - -function same_subnet(addr, net, mask) - local a = iptoint(addr) - local n, m = nettoint(net, mask) - if a and n and m then - return bit.band(a, m) == bit.band(n, m) - end - return false -end - diff --git a/lib/privsep.lua b/lib/privsep.lua deleted file mode 100644 index d2edcb7..0000000 --- a/lib/privsep.lua +++ /dev/null @@ -1,75 +0,0 @@ - -module(..., package.seeall) - -require("json") -require("posix") - -local rpc = {} - --- private privileged rpc server ------------------------------------ -local function rpcserver(r, w) - for line in r:lines() do - local handle = json.decode(line) - if type(rpc[handle.func]) == "function" then - response = rpc[handle.func](unpack(handle.data)) - else - response = nil - end - w:write(json.encode(response).."\n") - w:flush() - end -end - - --- public func ---------------------------------------------------- -function drop_privs(user, group, privileged_funcs) - local k, v - local wrapper = {} - - -- communication pipes - local cr, pw = posix.pipe() - local pr, cw = posix.pipe() - - -- create wrapper table - for k,v in pairs(privileged_funcs or {}) do - if type(v) == "function" then - rpc[k] = v - wrapper[k] = function(...) - local handle = {} - handle.func = k - handle.data = {...} - cw:write(json.encode(handle).."\n") - cw:flush() - return (json.decode(cr:read("*line"))) - end - end - end - - pid = posix.fork() - if pid == nil then - cr:close() - cw:close() - pr:close() - cw:close() - return nil - end - - if pid == 0 then - -- child runs with privs - cr:close() - cw:close() - rpcserver(pr, pw) - pw:close() - pr:close() - os.exit() - end - - -- lets drop privs - if posix.setpid("g", group) and posix.setpid("u", user) then - return wrapper - else - posix.kill(pid) - return nil - end -end - diff --git a/lib/web_elements.lua b/lib/web_elements.lua deleted file mode 100644 index e676205..0000000 --- a/lib/web_elements.lua +++ /dev/null @@ -1,156 +0,0 @@ ---[[ - middle level functions for the webconf view templates. Part of - acf - - Copyright (C) 2006 N. Angelacos Licensed under terms of GPL2 -]]-- - -module ( ..., package.seeall ) - -require ("html") - --- This is the main function that walks a table formatted for a template --- (This is the magic in generic) -function render_table ( element, level) - local level = level or 1 - - if (type(element) ~= "table" ) then - return nil - end - - for k,v in pairs (element) do - if ( v.type ~= nil ) then - if ( v.type == "group" ) then - print ( html.entity ( ( "h" .. tostring(level) ), v.label, v.class, v.id ) ) - print ( html.entity ( "p" , v.text, v.class ) ) - render_table ( v.value, level + 1 ) - elseif ( v.type == "label" ) then - print ( html.entity ( "h" .. level , v.value, v.class, v.id ) ) - if ( v.text ~= nil ) then - print ( html.entity ( "p", v.text, v.class )) - end - elseif ( v.type == "html" ) then - print (v.value) - elseif ( v.type == "log" ) then - print("<pre>") - if type(v.lines) == "function" then - for line in v.lines do - print(line) - end - elseif v.lines then - print(v.lines) - end - print("</pre>") - elseif ( v.type == "link" ) then - print (html.link ( v ) ) - elseif ( v.type == "form" ) then - print ( html.form.start ( v ) ) - print ("<dl>") - render_table ( v.value, level + 1 ) - print ("</dl>") - print ( html.form.stop () ) - elseif type(html.form[v.type]) ~= "nil" then - if v.type == "hidden" then - v.noitem = true - end - if not v.noitem then - print ( string.format ("<dt>%s</dt><dd>", ( v.label or "" ))) - end - print ( html.form[v.type] ( v ) ) - if not v.noitem then - print ("</dd>") - end - end - end - end -end - - --- This function prints the main menu, with the given prefix/controller "selected" --- returns the group, category, subcat that is selected -function render_mainmenu ( menu, prefix, controller, action ) - -- prefix+controller defines which menu is "selected" - local megroup = nil - local mecat = nil - local mesubcat = nil - local liston = nil - local group = "" - local cat = "" - - -- find the current group/cat/subcat - for i=1,table.maxn(menu) do - if (menu[i].prefix == prefix) and ( menu[i].controller == controller ) then - megroup = menu[i].group - mecat = menu[i].cat - if ( menu[i].action == action ) then - mesubcat = menu[i].subcat - elseif ( menu[i].action == "*" ) and ( mesubcat == nil ) then - mesubcat = menu[i].subcat - end - end - end - - -- render the mainmenu - local thisgroup = "" - local thiscat = "" - for i=1,table.maxn(menu),1 do - if menu[i].group ~= thisgroup then - thisgroup = menu[i].group - if ( liston ) then io.write ("</ul>") end - print ( html.entity ( "h3", menu[i].group ) ) - io.write("<ul>") - liston = true - thicat = nil - end - if menu[i].cat ~= thiscat then - thiscat = menu[i].cat - if (thiscat == mecat ) then - print ( html.entity ("li", html.html_escape(thiscat), nil, "selected")) - else - print (html.link ( { value= ENV.SCRIPT_NAME .. menu[i].uri , - label = html.entity ("li", html.html_escape(thiscat)) } ) ) - end - end - end - io.write ("</ul>") - return megroup, mecat, mesubcat -end - - - --- This function prints the tabs for the submenu, with the given submenu "selected" -function render_submenu ( menu, group, cat, subcat ) - cat = cat or "" - group = group or "" - local this_subcat = nil - local foo = group .. " > " .. cat - if (foo ~= " > " ) then - print ( html.entity ( "h2", html.html_escape( group .. " > " .. cat ) )) - end - - - -- print (string.format ("%s - %s - %s", group, cat , (subcat or ""))) - - io.write ("<ul>") - for i=1, table.maxn(menu),1 do - if ( group == menu[i].group ) and ( cat == menu[i].cat ) then - -- If a subcat was not selected, make the first one the default - if ( subcat == nil ) then - subcat = menu[i].subcat - end - - if ( menu[i].subcat ~= this_subcat ) then - this_subcat = menu[i].subcat - if ( menu[i].subcat == subcat ) then - print ( html.entity ("li", menu[i].subcat, nil, "selected")) - else - io.write ("<li>") - io.write ( html.link ( { value= ENV.SCRIPT_NAME .. menu[i].uri , - label =menu[i].subcat } ) ) - print ("</li>") - end - end - end - end - io.write ("</ul>") -end |