Luci tutorial or introduction?

When I press the gui REBOOT button, it seems to call this JS

function reboot(button) {
		(new XHR()).post('/cgi-bin/luci/admin/system/reboot/call', { token: 'xyzz' }, check);
	}

Similarly doing a gui reset to defaults calls /cgi-bin/luci/admin/system/flashops/reset

On the filesystem I find the single file /www/cgi-bin/luci which seems to somehow dispatch generically.

Where are these functions on the router? Is the a good writeup on how luci gui actions translate into cgi code running on the router? Or maybe a tutorial somewhere?

Does this help? https://github.com/openwrt/luci/wiki/Documentation

Mmmmmm Interesting.

So let me map out what I know.

https://github.com/openwrt/luci/wiki/ModulesHowTo#show-me-the-way-the-dispatching-process tells me that the cgi link I mentioned, /cgi-bin/luci/admin/system/flashops/reset, will be accessible if somebody has called the lua function entry( ... "flashops" ... )

Greping within the router finds me the function I want
/usr/lib/lua/luci# grep -r flashops * | grep entry
controller/admin/system.lua: entry({"admin", "system", "flashops"}, call("action_flashops"), _("Backup / Flash Firmware"), 70)
controller/admin/system.lua: entry({"admin", "system", "flashops", "reset"}, post("action_reset"))
controller/admin/system.lua: entry({"admin", "system", "flashops", "backup"}, post("action_backup"))
controller/admin/system.lua: entry({"admin", "system", "flashops", "backupfiles"}, form("admin_system/backupfiles"))
controller/admin/system.lua: entry({"admin", "system", "flashops", "restore"}, call("action_restore"))
controller/admin/system.lua: entry({"admin", "system", "flashops", "sysupgrade"}, call("action_sysupgrade"))

1 Like

What do you actually want to do?

The action_reset function is pretty clearly foundable:
https://github.com/openwrt/luci/search?q=action_reset&unscoped_q=action_reset

Direct link to the function (actual reset on line 269):

And reboot:
admin / system and then "action_reboot" function:

which leads to sys.lua and the actual "reboot" functionality:

2 Likes

I actually wanted to understand the linkage between luci buttons (and other gui elements) and the code which is run for them. At this point it is just learning, and trying to understand some behaviour I see.

At some point learning about the details involves actually looking into the details - the good news, the source is open, for everyone to see and change.

1 Like