Alpine Configuration Framework Design
Alpine Configuration Framework
The Alpine Configuration Framework (ACF) is a mvc-style application for configuring an Alpine device. The primary focus is for a web interface - ACF's main goal is to be a light-weight MVC "webmin".
Why Haserl + Lua
Other competitors in the arena were Webmin, Ruby on Rails, PHP with templates.
A full webmin (Perl), RoR or PHP implementation each require several MB of installed code, and can have very slow startup times, especially when used in "cgi" mode. After evaluating many options, we found that Lua has the following advantages:
- It is small (typically ~200KB of compiled code)
- It compiles and runs much faster than PHP, Perl or Ruby
- It provides a "normal" scripting language with features similar to PHP, perl, java, awk, etc.
Haserl + Lua provides a 'good enough' toolset to build a full-featured web application.
Why ACF is MVC
The MVC design pattern is used to separate presentation information from control logic. By MVC we mean:
- Model - code that reads / writes a config file, starts / stops daemons, or does other work modifying the router.
- View - code that formats data for output
- Controller - code that glues the two together
Note the lack of words like: HTML, XML, OO, AJAX, etc. The purpose of ACF's MVC is simply to separate the configuration logic from the presentation of the output.
The flow of a single transaction is:
start -> execute requested function in controller, optionally reading/writing a file using functions in the model -> execute the view to format the output -> end
Every transaction follows this pattern. For ACF developers, the focus should be on getting a model that does a proper job of abstracting the config file into useable entities and then building a controller that presents useable "actions" based on the model. The presentation layer should be last on the priority list.
For good background information on what ACF attempts to do, please see Terence Parr's paper "Enforcing Strict Model-View Separation in Template Engines" at http://www.cs.usfcs.edu or the local copy of the pdf.
The easiest way to start ACF is to run the setup-webconf script (renamed to setup-acf in Alpine beta 4 and later). This script will install mini-httpd, create a certificate, and start mini-httpd in HTTPS mode. WARNING - This will give anyone on the network access to your machine. The script will also install the two packages that are necessary for basic ACF: acf-core and acf-alpine-baselayout. To view ACF, simply browse to your machine (https://<hostname>/).
Alternately, you can manually install ACF and your web server. Once again, the two critical ACF packages are acf-core and acf-alpine-baselayout. The ACF packages will install to /usr/share/acf. You can configure your web server to give access to /usr/share/acf/www and run cgi scripts from /usr/share/acf/www/cgi-bin, and you should be able to view ACF.
If you would like to play with other ACF packages, we recommend you install the acf-apk-tools package. This package will allow you to install / delete other packages using ACF. You can then load any other acf-* packages you are interested in.
In alpine 1.8, the system includes two default users: alpine and foo. 'alpine' is given ADMIN rights and 'foo' is given USER rights. The default password for both users is test123. Replace the default users as soon as possible. In alpine 1.9, you will be prompted to create an initial user the first time you try to log in. (As of 1.9.1, the initial user is already created and is the root account for the system.)
ACF Developer's Guides
- mvc.lua reference - mvc.lua is the core of ACF
- mvc.lua example - build a simple (command-line) application
- acf www-controller reference - ACF www application functions
- acf www-controller example - webify the above examples
- ACF how to write - Step by step howto for writing acfs
- ACF core principles - Things that are standard across the application
- LPOSIX - Documentation for the Lua Posix functions
- ACF Libraries - Document the libraries and common functions
- Writing ACF Views - Guide for writing a view
- Writing ACF Controllers - Guide for writing a controller
- Writing ACF Models - Guide for writing a model
ACF has support for multiple skins.
Only a few skins are available. Feel free to contribute in programming css-stylesheets for ACF.
First download ACF using git or installing available acf's using apk_add.
Easiest is if you download latest Alpine ISO, boot a box on that and then run 'setup-alpine' and 'setup-webconf -a' (renamed to setup-acf in Alpine beta 4 and later)that way you get a running environment fast and easy!
Some example skins are available
Make a new skin-folder
Create a css file called as the folder.
Now you can start editing your myskin.css.
If you have ACF running on a computer, you can browse to this ACF-page and switch to your new skin (called myskin) and see the results of your changes.
Pack your myskin-folder, containing your css-file (and images, if there is any).
Send this patch to firstname.lastname@example.org (Note: Don't forget to subscribe before sending your patch)
Look at ACF packages to see available ACF modules and their status.