[luci] Custom buttons and functions

Jo-Philipp Wich xm at subsignal.org
Fri Sep 25 13:12:29 CEST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi.

> I am trying to create a page that includes the following elements:
> 
> a) A button that points to a URL outside the router, but with part of the
> URL parameters set by uci variables (set in a /etc/configfile

You can do that by wrapping the cbi action into a call action on the
controller side, like this:

local page = entry({"admin", "foo", "bar"}, call("myhandler"), ...)
function myhandler(self)
  if luci.http.formvalue("some_value") then
    luci.http.redirect("http://some.url/" ..
      luci.http.formvalue("some_value"))
  else
    self.model = "some/cbi/model"
    return _cbi(self)
  end
end

> b) A button that allows to start a daemon or stop it. Button should toggle
> Start/Stop depending on the status of the programme

See the following url for an example:
http://luci.subsignal.org/trac/changeset/5257/luci/trunk/applications/luci-openvpn/luasrc

> c) A button that triggers a shell script programme when pressed. However,
> depending on a configuration option stored in one of the /etc/config files
> the button should either show, ready for action, or show a text in lieu of
> the button, indicating the function is not available.

This is best done in the cbi model like this:
local uci = require "luci.model.uci".cursor_state()

if uci:get("some_config", "some_section", "available") == "1" then
  s:option(Button, ...)
else
  s:option(DummyValue, ...)
end


Regards,
JoW
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkq8pZkACgkQdputYINPTPOBmACfeoOEQNca10CDZwGeop7E5amZ
84IAoJewMSQgmLH6ExxhjtVyM7JGVWiE
=Kwhp
-----END PGP SIGNATURE-----


More information about the luci mailing list