[luci] sqlite connection to luci

Seamus Tuohy s2e at opentechinstitute.org
Tue Jun 4 14:50:30 CEST 2013


On 06/04/2013 06:02 AM, Pau wrote:
> I'm not a LUCI expert either but I'll try to help you.
> 
> 1) LUCI and OpenWRT are using UCI system [1] as database to store the
> information. I think you can use it for your own pourposes.

Since it took me a while to learn the in's and out's of LuCI's UCI
systems here is a quick primer.

More specifically, you should check out the built in functions here:
http://luci.subsignal.org/api/luci/modules/luci.model.uci.html

When using these functions I recommend using them as such:

First set the uci cursor object to a variable.
local uci = luci.model.uci.cursor()

Then use uci: to call the functions. Here is a little snippet that I
pulled from some some code to show you how to 'get' the 'disabled' value
from the uci file 'wireless' under the section device (that's defined
elsewhere).

disabled = uci:get('wireless', device, 'disabled')

I then see if the result return a value and delete it if it does. Many
of the control functions like delete will also return a boolean value if
they succeed, which I capture here. Finally I both save and commit the
values. Saving will not fully apply the values to the file, so you must
commit the file as well.

if disabled then
    disabledTrue = uci:delete('wireless', device, 'disabled')
    uci:save('wireless')
    uci:commit('wireless')
end

If you want to track the file and have other functions run based upon
its modification I suggest looking into ucitrack. But, that is a whole
other e-mail's worth of content.

I would go into /etc/config/. to explore some of the uci files there and
play with the uci command line tool to explore if uci is the right
format for your data. There are other ways to build in database support
using the LuCI interface, you just have to code your reads and writes to
them.

s2e

> 
> 2) Check /usr/lib/lua/luci/controller files to understand how it works.
> There are a couple of how-tos in the Luci web page [2]
> 
> 3) I'm not sure of that but as far I understand it does not (it only
> provides a single "stok").
> 
> Cheers
> 
> [1] http://wiki.openwrt.org/doc/uci
> [2] http://luci.subsignal.org/trac/wiki/Documentation
> 
> --
> ./p4u
> 
> 
> On Mon, Jun 3, 2013 at 4:14 PM, Deepak Agasibagil <deepak at relysys.co.in>wrote:
> 
>> Hello,
>>        I am newbie to this community.
>> I have router with OpenWrt running on it and  i am able to access router
>> through LUCI interface.
>>
>> Please guide me on below things
>>
>> 1) How to associate LuCI with a database.( I didn't found any document on
>> this in luci homesite).
>>      My intention is to provide form on 'view' when a user fills form and
>> hit submit button, the data should be stored in database
>>     and later i can query the database to retrieve the data stored and
>> represent on web page.
>>
>> 2) How to run lua code or functions inside a 'Controller' in LuCI.
>>
>> 3) And the last one is that, Does LuCI framework supports multiple user
>> login?
>>
>> Thanks,
>> Deepak
>>
>> _______________________________________________
>> luci mailing list
>> luci at lists.subsignal.org
>> https://lists.subsignal.org/mailman/listinfo/luci
>>
>>
> 
> 
> 
> _______________________________________________
> luci mailing list
> luci at lists.subsignal.org
> https://lists.subsignal.org/mailman/listinfo/luci
> 



More information about the luci mailing list