[luci] How does LuCI hook into the back-end?

Kunal Punjabi kpunjabi at ubicom.com
Thu Jul 9 08:55:58 CEST 2009


Hi everyone,

We are trying to port OpenWRT to our platform and need to modify some of
the default LuCI functionality. Please forgive me if this post appears
to sound "beginner"-ish, but I don't understand LuCi yet in its
entirety, hence I need some help from the community. Some background - I
am an embedded C developer and familiar with the MVC design pattern in a
web-based environment. By the way I already did some groundwork and read
through some of the documentation, specifically this page

http://luci.freifunk-halle.net/Documentation/ModulesHowTo#Showmetheway.2
8Thedispatchingprocess.29

in trying to understand how the dispatcher, and the MVC framework is
designed in LuCI.

 

I have 2 questions:

By default OpenWRT (which uses LuCI) has a system->Mount Points page,
where one can mount devices from.

 

 

Question 1

Adding an entry to the "Mount Points" section of this page (as shown
below in the screenshot) and then pressing "Save and Apply" causes the
USB device to get mounted.

There is a "hook" that ties the press of "Save and apply" to the "mount"
command in the back-end. Where is this hook exactly? Something is
transferring control over to the "mount" command.

The reason I ask is because we need to do the opposite (i.e. unmount)
when the 'x' button next to a mount point entry is clicked on the UI.
The entry gets removed from the UI, but our console shows that the
device is still mounted. I want to add code to unmount the device when
the entry is deleted, so I need to know the appropriate place to insert
that "hook".

 

For example,

luci-0.8.6/modules/admin-full/luasrc/controller/admin/system.lua
contains a dispatcher for the 

 

------------------------------------------------------------------------
-------------------------------

module("luci.controller.admin.system", package.seeall)

 

function index()

        luci.i18n.loadc("admin-core")

        local i18n = luci.i18n.translate

 

        entry({"admin", "system"}, alias("admin", "system", "system"),
i18n("system"), 30).index = true

        entry({"admin", "system", "system"}, cbi("admin_system/system"),
i18n("system"), 1)

        entry({"admin", "system", "packages"}, call("action_packages"),
i18n("a_s_packages"), 10)

        entry({"admin", "system", "packages", "ipkg"},
form("admin_system/ipkg"))

        entry({"admin", "system", "passwd"},
form("admin_system/passwd"), i18n("a_s_changepw"), 20)

        entry({"admin", "system", "sshkeys"},
form("admin_system/sshkeys"), i18n("a_s_sshkeys"), 30)

        entry({"admin", "system", "processes"},
form("admin_system/processes"), i18n("process_head"), 45)

        entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"),
i18n("a_s_fstab"), 50)

 

        if luci.fs.isdirectory("/sys/class/leds") then

--              entry({"admin", "system", "leds"},
cbi("admin_system/leds"), i18n("leds", "LEDs"), 60)

        end

 

        entry({"admin", "system", "backup"}, call("action_backup"),
i18n("a_s_backup"), 70)

        entry({"admin", "system", "upgrade"}, call("action_upgrade"),
i18n("a_s_flash"), 80)

        entry({"admin", "system", "reboot"}, call("action_reboot"),
i18n("reboot"), 90)

end

------------------------------------------------------------------------
-------------------------------

 

 

 

 

Question 2

There seems to be a bug here: a) Unchecking the "enable" box under
"Mount Points" (see screenshot of the Mount Points page, attached) and
pressing "Save and Apply" does NOT pass validation and I see

Required option "fstab. at mount[1].enabled" has no value

 

So, given that this checkbox seems pretty useless, I tried to remove the
enable checkbox for each mount entry. For doing this, I applied the
following patch:

 

------------------------------------------------------------------------
-------------------------------

---
luci-0.8.6/modules/admin-full/luasrc/model/cbi/admin_system/fstab.lua.or
ig  2009-07-08 16:57:50.000000000 -0700

+++
luci-0.8.6/modules/admin-full/luasrc/model/cbi/admin_system/fstab.lua
2009-07-08 16:58:27.000000000 -0700

@@ -61,7 +61,6 @@

 mount.addremove = true

 mount.template = "cbi/tblsection"

 

-mount:option(Flag, "enabled", translate("enable"))

 dev = mount:option(Value, "device", translate("device"),
translate("a_s_fstab_device1"))

 for i, d in ipairs(devices) do

        dev:value(d, size[d] and "%s (%s MB)" % {d, size[d]})

------------------------------------------------------------------------
-------------------------------

 

However what this does is remove the checkbox, but the "back end"
(validation code) still expects this value to be set? I want to disable
this validation.

The documentation states that the validation comes in the form:

function dns:validate(value) -- Now, that's nifty, eh?

    return value:match("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+") -- Returns nil
if it doesn't match otherwise returns match

end

 

However, I couldn't find any such validation function in 

luci-0.8.6/modules/admin-full 

Viewing the source of the page revealed that the javascript validation
is coming from a function called cbi_d_update(this.id), which is in

luci-0.8.6/libs/cbi/

 

               <input class="cbi-input-checkbox"
onclick="cbi_d_update(this.id)" onchange="cbi_d_update(this.id)"
type="checkbox" id="cbid.fstab.cfg023ae5.enabled"
name="cbid.fstab.cfg023ae5.enabled" value="1" />

 

 

 

 

 

Screnshot 2 (after removing the "enable" check box. Validation is
failing, I probably need to either disable validation or set enabled=1
always)

 

 

 

 

 

Kunal

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.subsignal.org/pipermail/luci/attachments/20090708/d30b52c7/attachment-0001.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 355523 bytes
Desc: image004.png
Url : http://lists.subsignal.org/pipermail/luci/attachments/20090708/d30b52c7/attachment-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 82581 bytes
Desc: image001.jpg
Url : http://lists.subsignal.org/pipermail/luci/attachments/20090708/d30b52c7/attachment-0001.jpeg 


More information about the luci mailing list