Difference between revisions of "ACF Libraries"

From Alpine Linux
Jump to: navigation, search
(ACF Libraries <span style="color:red">(Using Lua Posix. Most will go away)</span>)
Line 1: Line 1:
= ACF Libraries <span style="color:red">(Using Lua Posix. Most will go away)</span>=
+
= ACF Libraries =
 
Because of using lua, a very small language, the need arises to build everything from scratch. This can lead to some confusion, apprehension, or just feeling overwhelmed. Here is documentation on what we have now in the form of libraries and common functions. We hope to build some more and use this information to get the juices flowing in regard to ACF.  
 
Because of using lua, a very small language, the need arises to build everything from scratch. This can lead to some confusion, apprehension, or just feeling overwhelmed. Here is documentation on what we have now in the form of libraries and common functions. We hope to build some more and use this information to get the juices flowing in regard to ACF.  
  
 
Some of these are lua libs or ones written for ACF.
 
Some of these are lua libs or ones written for ACF.
 
+
We are also using as a standard the lposix library which is documented here [[LPOSIX]]
  
  

Revision as of 15:40, 22 November 2007

ACF Libraries

Because of using lua, a very small language, the need arises to build everything from scratch. This can lead to some confusion, apprehension, or just feeling overwhelmed. Here is documentation on what we have now in the form of libraries and common functions. We hope to build some more and use this information to get the juices flowing in regard to ACF.

Some of these are lua libs or ones written for ACF. We are also using as a standard the lposix library which is documented here LPOSIX


fs.lua

Used for various filespecific functions

  • is_dir - test if the a directory
  • is_file - test if is a file
  • is_link - test if file is a link
  • read_file / read_file_as_array - will read a file as a string / array
  • dostounix - converts dos line endings to unix
  • remove_blanks_comments - takes out the blank and commented lines
  • write_file - replace contents of a file
  • wrie_line_file - appends lines to a file
  • find - Give a path and a filename and search for it

html.lua

Functions used by web_elements.lua. Written by nangel for ACF.

  • cookie.set -creates a cookie to be used with ACF
  • html_escape - will escape html encoded strings
  • nv_pair - returns name value pairings as string
  • entity
  • link
  • Form setup functions
    • form.text
    • form.longtext
    • form.passwd
    • form.hidden
    • form.submit
    • form.action
    • form.file
    • form.image
    • form.select
    • form.checkbox
    • form.start
    • form.stop

join.lua (not working)

INPUT:
This library required the following inputs/parameters.

  • Delimiter
    • Could be one or more chars.
  • Array
    • Data which is to be joined into a string.

OUTPUT:
This library deliverers the following output/parameters.

  • String
    • Could be something like "Word, Word, Word, Word"

CODING EXAMPLE:

-- Set variable/Call for this library
ourlib = require("join")
-- Create a array of data (Not sure if the next row is correct)
arraytojoin = "Bird", "Fish", "Cow", "Hammer"
-- Process the data (note the delimiter)
liboutput = ourlib(";", arraytojoin)

'liboutput' would contain:

Bird;Fish;Cow;Hammer

log_view.lua

menubuilder.lua

Written by nangel for ACF

pidof.lua

pidof

find the process ID of a running program

pidof.pidof(program)

INPUT

  • program

OUTPUT returns the PID's of running program or nil if there are none.

CODING EXAMPLE

require "pidof"
if pidof.pidof("mini_httpd") ~= nil then
  print("mini_httpd is running")
else
  print("mini_httpd is not running")
end

privsep.lua

drop_privs

Drop privileges while allowing a few functions still have root permissions.

privsep.drop_privs(user, group, functable)

Depends on posix and json.

INPUT:

  • user
  • group
  • functable
    • a table of functions that will run as root

OUTPUT: returns a table identical to functable, except the funcs are wrapped and runs in a separate process with root permissions.

CODING EXAMPLE:

#!/usr/bin/env lua

require "posix" 
require "privsep"

-- register those as privileged funcs 
a = {}
function a.getuid()
        return posix.getpid().euid
end

-- main ---------------------------------------------------------
priv = privsep.drop_privs("nobody", "nogroup", a)
if priv == nil then
        error("failed to drop privileges")
end

print("current uid:", posix.getpid().euid)
print("privileged uid:", priv.getuid())


service_controller.lua

This is comprised of many local functions. Will just go through the exported ones.

create_services_controller

service_model.lua

Has many functions inside the one below.

create_service_model

INPUT

  • cfglist
  • loglist
  • servlist
  • notepath

OUPUT

  • Returns a me table:
    • Looks like it contains information about the service.
      • Processes running
      • If there is an /etc/init.d/ script
      • Where is the programs config file
      • Where does it log to

session.lua

Written by nangel for ACF.

  • random_hash - will create a bash64 like hash from /dev/urandom
  • hash_ip_address -a hash encoded ip address
  • ip_addr_from_hash -take the hash encoded ip and give me the ip
  • serialize -go through a table or set of tables
  • save_session -save the session table

split.lua

INPUT:
This library required the following inputs/parameters.

  • Delimiter
    • Could be one or more chars.
  • String or line from a file: bobo~foo~bar~baz~1
    • Data is to be split into a table

OUTPUT:
This library deliverers the following output/parameters.

  • Table
    • { 1 = "bobo", 2 = "foo", 3 = "bar", 4 = "baz", 5 = 1}

CODING EXAMPLE:

-- Set variable/Call for this library
strsplit = require("split")
-- Grab the line from a file or input it into the funtcion
line = "bobo~foo~bar~baz~1"
-- Process the data (note the delimiter)
t = ourlib("~", line)
't' would contain: 
{ 1 = "bobo", 2 = "foo", 3 = "bar", 4 = "baz", 5 = 1}
for a,b in ipairs(t) do print(a,b) end
1 bobo
2 foo
3 bar
4 baz
5 1

validator.lua

This contains multiple different functions that each will validate input in there own way.

  • is_ipv4 - test if this is a valid ipv4 address
  • is_mac - test to see if this is a valid mac address
  • is_integer - is the number and int
  • is_integer_in_range - is the int in the range of numbers
  • is_port - the the number in the ip port range

web_elements.lua

Written by nangel for ACF.

  • render_table -walks through a table rendered for a template
  • render_mainmenu - will render the side menu
  • render_submenu - will render all the sub menu items