Difference between revisions of "ACF Libraries"

From Alpine Linux
Jump to: navigation, search
(controllerfunctions.lua: Added handle_clientdata note)
(Update to latest libraries - removed split, join, getopts, daemoncontrol, procps, ...)
Line 8: Line 8:
 
==[[apk.lua]]==
 
==[[apk.lua]]==
 
Functions to load/unload apk packages
 
Functions to load/unload apk packages
* get_all_packages
+
* repository
* get_loaded_packages
+
* get_all
* get_available_packages
+
* get_loaded
* delete_package
+
* get_available
* install_package
+
* delete
 +
* install
 +
* is_installed
  
==[[authenticator-plaintext.lua]]==
+
==[[authenticator.lua]]==
 
Authentication module
 
Authentication module
 
* authenticate
 
* authenticate
Line 20: Line 22:
 
* get_userinfo_roles
 
* get_userinfo_roles
 
* list_users
 
* list_users
* list_roles
 
* change_setting
 
 
* change_settings
 
* change_settings
 
* new_settings
 
* new_settings
 
* delete_user
 
* delete_user
 +
* list_userfields
 +
* read_userfield
 +
* delete_userfield
 +
* write_userentry
 +
* read_userentry
 +
* delete_userentry
 +
* list_rolefields
 +
* read_rolefield
 +
* delete_rolefield
 +
* write_roleentry
 +
* read_roleentry
 +
* delete_roleentry
  
==[[cfe.lua]]==
+
==[[authenticator-plaintext.lua]]==
cfe helper function
+
Authentication sub-module for plaintext database
* cfe
+
* list_fields
 +
* read_field
 +
* delete_field
 +
* write_entry
 +
* read_entry
 +
* delete_entry
  
 
==[[controllerfunctions.lua]]==
 
==[[controllerfunctions.lua]]==
 
Controller helper functions
 
Controller helper functions
 +
* handle_clientdata
 
* handle_form
 
* handle_form
 
* handle_startstop
 
* handle_startstop
* handle_clientdata
 
 
==[[daemoncontrol.lua]]==
 
Service start/stop/restart function
 
* daemoncontrol
 
  
 
==[[date.lua]]==
 
==[[date.lua]]==
Line 61: Line 74:
 
***Days of Week
 
***Days of Week
 
***Months of the Year
 
***Months of the Year
 
== [[fs.lua]] ==
 
Used for various filesystem specific 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
 
*write_file - replace contents of a file
 
*write_line_file - appends lines to a file
 
*find - Give a path and a filename and search for it
 
*md5sum_file - give a hash, md5sum of a file
 
  
 
== [[format.lua]] ==
 
== [[format.lua]] ==
Used to format table,string,input,output ...
+
Used to format tables and strings
 
*dostounix - converts dos line endings to unix
 
*dostounix - converts dos line endings to unix
*remove_blanks_comments - takes out the blank and commented lines
+
*parse_lines - takes out the blank and commented lines
 +
*parse_linesandwords
 +
*parse_configfile
 
*search_replace - will go through a file or table and search and replace
 
*search_replace - will go through a file or table and search and replace
 
*search_for_lines - will go through a file and return a table with matches
 
*search_for_lines - will go through a file and return a table with matches
 
*cap_begin_word - will capitalize beginning of words
 
*cap_begin_word - will capitalize beginning of words
*ipairs_to_string
+
*string_to_table - takes a delimited string and turns it into a table
*table_to_string - formally the join.lua takes a table and makes into a string with delimiter
 
*string_to_table - formally split.lua. takes a delimited string and turns it into a table
 
 
*md5sum_string
 
*md5sum_string
 +
*expand_bash_syntax_vars
 +
*replace_line
 +
*insert_line
 +
*get_line
 +
*opts_to_table
 +
*table_to_opts
 +
*update_configfile2
 +
*parse_configfile2
 +
*get_section
 +
*set_section
  
 
== [[fs.lua]] ==
 
== [[fs.lua]] ==
File system functions
+
Used for various filesystem specific functions
*is_dir
+
*is_dir - test if the path is a directory
*is_file
+
*is_file - test if the path is a file
*is_link
+
*is_link - test if the path is a link
*read_file
+
*create_file
*read_file_as_array
+
*read_file / read_file_as_array - will read a file as a string / array
*write_file
+
*write_file - replace contents of a file
*write_line_file
+
*write_line_file - appends lines to a file
*md5sum_file
+
*md5sum_file - give a hash, md5sum of a file
*md5sum_string
+
*find - Give a path and a search string and iterate over matching files
*find
 
 
*stat
 
*stat
 
== [[getopts.lua]] ==
 
Functions to parse config files
 
*opts_to_table
 
*table_to_opts
 
*setoptsinfile
 
*getoptsfromfile
 
  
 
== [[html.lua]] ==
 
== [[html.lua]] ==
Line 111: Line 115:
 
*cookie.unset
 
*cookie.unset
 
*html_escape - will escape html encoded strings
 
*html_escape - will escape html encoded strings
*nv_pair - returns name value pairings as string
 
 
*entity
 
*entity
 
*link
 
*link
Line 128: Line 131:
 
**form.start
 
**form.start
 
**form.stop
 
**form.stop
 
== [[ipcalc.lua]] ==
 
*iptoint
 
*nettoint
 
*same_subnet
 
  
 
== menubuilder.lua ==
 
== menubuilder.lua ==
Line 143: Line 141:
 
*getstatus
 
*getstatus
 
*getfiledetails
 
*getfiledetails
 +
*setfiledetails
 
*validateselect
 
*validateselect
 
*validatemulti
 
*validatemulti
 
== 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:'''<br>
 
* 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:'''
 
<pre>
 
#!/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())
 
</pre>
 
  
 
== [[processinfo.lua]] ==
 
== [[processinfo.lua]] ==
 
*package_version
 
*package_version
 
*process_botsequence
 
*process_botsequence
 
+
*daemoncontrol
== procps.lua ==
+
*pidof - find the process ID of a running program
=== 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
 
  
 
== [[roles.lua]] ==
 
== [[roles.lua]] ==
Line 213: Line 155:
 
*get_controllers
 
*get_controllers
 
*get_controllers_func
 
*get_controllers_func
 +
*get_controllers_view
 
*list_default_roles
 
*list_default_roles
 
*list_roles
 
*list_roles
Line 248: Line 191:
  
 
== [[viewfunctions.lua]] ==
 
== [[viewfunctions.lua]] ==
displayinfo
+
displayinfo - obsolete
displaymanagement
+
displaymanagement - obsolete
 
*displayitem
 
*displayitem
 
*displayformitem
 
*displayformitem
 
*displayform
 
*displayform
 
*displaycommandresults
 
*displaycommandresults
 
== [[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
 
 
 
== split.lua <span style="color:red">put in format.lua</span>==
 
== join.lua <span style="color:red">put in format.lua</span>==
 

Revision as of 17:40, 30 September 2008

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


apk.lua

Functions to load/unload apk packages

  • repository
  • get_all
  • get_loaded
  • get_available
  • delete
  • install
  • is_installed

authenticator.lua

Authentication module

  • authenticate
  • get_userinfo
  • get_userinfo_roles
  • list_users
  • change_settings
  • new_settings
  • delete_user
  • list_userfields
  • read_userfield
  • delete_userfield
  • write_userentry
  • read_userentry
  • delete_userentry
  • list_rolefields
  • read_rolefield
  • delete_rolefield
  • write_roleentry
  • read_roleentry
  • delete_roleentry

authenticator-plaintext.lua

Authentication sub-module for plaintext database

  • list_fields
  • read_field
  • delete_field
  • write_entry
  • read_entry
  • delete_entry

controllerfunctions.lua

Controller helper functions

  • handle_clientdata
  • handle_form
  • handle_startstop

date.lua

Date and time functions To be used with os.time() and os.date()

  • date_to_seconds - Takes a date table and converts it to seconds from 1970
  • seconds_to_date - Takes table of seconds values and converts to a date sorted smallest to largest
  • string_to_table
  • date_diff - Takes two values of seconds and gives back the difference
  • num_month_name - Month number to name of month
  • num_month_name_abr - Month number to abr of month
  • name_month_num - Month name to number
  • abr_month_num - Month abbreviation to number
  • num_dow_name - Day of Week number to name
  • num_dow_name_abr - Day of week number to abbreviation
  • name_dow_num - Day of Week full name to number
  • abr_dow_num - Day of week abbreviation to number
  • what_tz - Checks to see what timezone the box is set to; /etc/TZ
  • change_tz - Changes the timezone
    • Tables are included with this information
      • Timezones
      • Days of Week
      • Months of the Year

format.lua

Used to format tables and strings

  • dostounix - converts dos line endings to unix
  • parse_lines - takes out the blank and commented lines
  • parse_linesandwords
  • parse_configfile
  • search_replace - will go through a file or table and search and replace
  • search_for_lines - will go through a file and return a table with matches
  • cap_begin_word - will capitalize beginning of words
  • string_to_table - takes a delimited string and turns it into a table
  • md5sum_string
  • expand_bash_syntax_vars
  • replace_line
  • insert_line
  • get_line
  • opts_to_table
  • table_to_opts
  • update_configfile2
  • parse_configfile2
  • get_section
  • set_section

fs.lua

Used for various filesystem specific functions

  • is_dir - test if the path is a directory
  • is_file - test if the path is a file
  • is_link - test if the path is a link
  • create_file
  • read_file / read_file_as_array - will read a file as a string / array
  • write_file - replace contents of a file
  • write_line_file - appends lines to a file
  • md5sum_file - give a hash, md5sum of a file
  • find - Give a path and a search string and iterate over matching files
  • stat

html.lua

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

  • cookie.set -creates a cookie to be used with ACF
  • cookie.unset
  • html_escape - will escape html encoded strings
  • entity
  • link
  • cfe_unpack - returns the whole of a cfe as a string. Great for troubleshooting.
  • Form setup functions - also are the "types" of cfe. See ACF_core_principles
    • form.text
    • form.longtext
    • form.password
    • form.hidden
    • form.submit
    • form.action
    • form.file
    • form.image
    • form.select
    • form.checkbox
    • form.start
    • form.stop

menubuilder.lua

Written by nangel for ACF

  • get_menuitems

modelfunctions.lua

  • getenabled
  • startstop_service
  • getstatus
  • getfiledetails
  • setfiledetails
  • validateselect
  • validatemulti

processinfo.lua

  • package_version
  • process_botsequence
  • daemoncontrol
  • pidof - find the process ID of a running program

roles.lua

  • list_controllers
  • get_controllers
  • get_controllers_func
  • get_controllers_view
  • list_default_roles
  • list_roles
  • list_all_roles
  • get_roles_perm
  • get_role_perm
  • delete_role
  • set_role_perm

session.lua

Written by nangel for ACF.

  • random_hash - will create a bash64-like hash from /dev/urandom
  • hash_ip_addr - create 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 and serialize
  • save_session - save the session table
  • load_session - load a saved session table
  • unlink_session - delete a saved session table
  • record_event - record an invalid login attempt
  • count_events - check if there are too many invalid attempts
  • expired_events - delete the expired invalid attempts and saved sessions

validator.lua

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

  • is_string
  • is_boolean
  • is_number
  • is_ipv4 - test if this is a valid ipv4 address
  • is_partial_ipv4
  • 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
  • is_valid_filename

viewfunctions.lua

displayinfo - obsolete displaymanagement - obsolete

  • displayitem
  • displayformitem
  • displayform
  • displaycommandresults