I need to make the luci > network > wireless tab dissapear conditionally based on whether the user has installed a certain network card or not. This is necessary because UCI is unable to manage certain cards and I don't want the user messing up the config.
I am able to make my custom config tab appear conditionally, but making the standard wireless tab dissapear is tricky. I understand that the presence of /etc/config/wireless on the system causes that tab to appear. But I don't want to delete that from the system in case a compatible card is used. Below is a snippet from my current approach which is a part of the luasrc/controller/halow.lua file in my custom luci app package.
local usb_check = os.execute("lsusb | grep -q '<card ID>'")
if usb_check == 0 then
local nw = entry({"admin", "network", "wireless"}, nil, nil)
nw.target = nil
nw.title = nil
I've also tried this approach
local nw = luci.dispatcher.node("admin", "network", "wireless")
if nw then
nw.target = nil
nw.title = nil
nw.order = 100
But all that does is push it to the bottom of the network section.
is the choice made at runtime or during compilation ??
also you appear to be using the legacy luci ... i assume luci-compat ??
You may want to have a look at my old Luci-app-multi-user package to see how to hook into the menu displays and add conditions
from what i recall, you''l need to set the condition in the index.lua, then check for said condition in the dispatcher where the pages are rendered ... (added to the index list).
with a slight adjustment this should get it done ...
So this is a runtime thing. The idea being that once the device is in service a user can hot-swap wifi cards and behavior will change depending on the card installed. I was able to get this work in a sort of hacky way. I learned that it is the presence of /etc/config/wireless that makes the network > wireless tab appear. So, I wrote an init.d service that hides or reinserts /etc/config/wireless on boot.
#!/bin/sh /etc/rc.common
START=15 # Run early, before LuCI initializes
start() {
if lsusb | grep -q '<Card id>'; then
if [ -f /etc/config/wireless ]; then
mv /etc/config/wireless /etc/config/wireless.bak
fi
else
if [ -f /etc/config/wireless.bak ]; then
mv /etc/config/wireless.bak /etc/config/wireless
fi
fi
}