MVC is a software design that separates the representation of data from the user's interactions with that data. This is the architecture that is used by the LuCI system
LuCI uses the existing UCI configuration files as a model. It uses its own configuration language called CBI to translate the UCI file into the HTML form (view) you see on most pages. It's controller's are a series of Lua scripts that can be found in the main LuCI directory.
LuCI's directory is contained at:
/usr/lib/lua/luci/
The default directories for resources on the Commotion router are as such:
RESOURCES: The directory for LuCI resources (images, js, css, and html assets) that are not theme specific
/www/luci-static/resources/
MEDIA: The LuCI resource directory for the current active theme
/www/luci-static/commotion/
'core' 'main': These are the basic settings for things like setting the default directories, turning on the network interface unit and setting the language.
'extern' 'flash_keep': The files to keep when sysupgrade is run with save-settings. See: https://forum.openwrt.org/viewtopic.php?id=23194 for more info on customization
'internal' 'languages': The abbreviations that represent the supported translations in LuCI translate.
'internal' 'sauth': Defines where sessions are stored and how long they last for logged in admin users.
'internal' 'ccache': LuCI module caching. See: 06-debugging module of this repo for an in depth overview.
'internal' 'themes': The current themes that LuCI knows about. You should not have to touch this.
CBI models are Lua files that describe the structure of a UCI vconfig file and the resulting HTML form to be evaluated by the CBI parser.
The main CBI parser is found in the luci directory.
/usr/lib/lua/luci/cbi.lua
CBI also uses a set of datatypes. These datatypes are Lua functions that dynamically validate user input on the client side using JavaScript.
/usr/lib/lua/luci/cbi/datatypes.lua
We will cover CBI in more depth in section 04-model-cbi of this module.
While much can be done simply using the CBI interface and properly implementing UCI into your OpenWRT programs, more complex functionality, or non-UCI compliant programs, will require that you write your own Lua scripts. LuCI has a robust set of Lua functions for interacting with OpenWRT routers.
API Documentation- http://luci.subsignal.org/api/luci/
Nixio is the "Networking and I/O library for Lua." Nixio is the low level Lua code that powers the LuCI API. If you are looking for Lua hooks for specific networking and I/O tasks that too far abstracted by the LuCI libraries, here is where you need to look.
API Documentation - http://luci.subsignal.org/api/nixio/ Source - http://luci.subsignal.org/trac/browser/luci/trunk/libs/nixio
To use the LuCI development environment you can simply run make luci
from the luci_tutorials folder to use the simple makefile I have written to automate the process. It will echo out the command to run once it is finished gathering the needed files.
If you are missing dependencies you can go to the online guide to get requirements:
http://luci.subsignal.org/trac/wiki/Documentation/DevelopmentEnvironmentHowTo
Note:
-l Used to load the module
-e Executes some Lua script
root@OpenWrt:~# lua -l luci.sys -e 'print(luci.sys.sysinfo())'
/etc/config/unitrack