with help from AI I found a way to add the proper Power Off to main menu of Luci, and as well add it to the ADMIN PANEL from GL-Inet E750 main Control Panel, here it goes:
1) Adding âPower Offâ to the main LuCI menu
- SSH into your GL-E750
ssh [email protected]
- Create the LuCI controller
Paste everything at once:
cat > /usr/lib/lua/luci/controller/poweroff.lua << 'EOF'
module("luci.controller.poweroff", package.seeall)
function index()
-- Replace the old âMCU Controlâ with a direct âPower Offâ at admin/mcu
entry({"admin","mcu"}, call("action_poweroff"), _("Power Off"), 60).leaf = true
end
function action_poweroff()
-- Trigger MCU shutdown over UBus, then redirect to Status
os.execute("ubus call mcu cmd_json '{\"poweroff\":\"1\"}'")
luci.http.redirect(luci.dispatcher.build_url("admin","status"))
end
EOF
- Fix permissions and reload LuCI
chmod 644 /usr/lib/lua/luci/controller/poweroff.lua
/etc/init.d/uhttpd reload
- Now in LuCI youâll see Power Off alongside the main menus, and clicking it immediately shuts down the modem.
- Make it persist across firmware upgrades
a. Create an installer script:
cat > /usr/bin/install_poweroff << 'EOF'
#!/bin/sh
CONTROLLER="/usr/lib/lua/luci/controller/poweroff.lua"
# (Re)write the controller idempotently
cat << 'EOC' > "$CONTROLLER"
module("luci.controller.poweroff", package.seeall)
function index()
entry({"admin","mcu"}, call("action_poweroff"), _("Power Off"), 60).leaf = true
end
function action_poweroff()
os.execute("ubus call mcu cmd_json '{\"poweroff\":\"1\"}'")
luci.http.redirect(luci.dispatcher.build_url("admin","status"))
end
EOC
chmod 644 "$CONTROLLER"
EOF
chmod +x /usr/bin/install_poweroff
b. Edit /etc/rc.local
:
vi /etc/rc.local
Before the final exit 0
, add:
# reinstall Power Off button in LuCI
/usr/bin/install_poweroff
/etc/init.d/uhttpd reload
Save and exit (Esc
â :wq
â Enter).From now on, on every boot (including after a sysupgrade with âKeep configâ), your LuCI Power Off button will be recreated automatically.
2) Injecting âPower Offâ after Advanced Settings in the GL-iNet Admin Panel
- Locate the SPA HTML
On the GL-E750 itâs served from:
/www/gl_home.html
- Create the injection snippet
cat > /tmp/poweroff_snippet.js << 'EOF'
<script>
window.addEventListener('DOMContentLoaded', function(){
var obs = new MutationObserver(function(muts, ob){
// Seleciona todos os tĂtulos de item de menu
var titles = document.querySelectorAll('.el-menu-item > .menu-title');
titles.forEach(function(title){
if (title.textContent.trim() === 'Advanced Settings') {
var parentLi = title.closest('li.el-menu-item');
// cria novo <li> com a mesma classe e estilo
var newLi = document.createElement('li');
newLi.setAttribute('role','menuitem');
newLi.setAttribute('tabindex','-1');
newLi.className = 'el-menu-item';
newLi.style.paddingLeft = parentLi.style.paddingLeft;
// cria o <span><a>Power Off</a></span>
var span = document.createElement('span');
span.className = 'menu-title';
var a = document.createElement('a');
a.href = '/cgi-bin/luci/admin/mcu';
a.textContent = 'Power Off';
span.appendChild(a);
newLi.appendChild(span);
// insere logo apĂłs o Advanced Settings
parentLi.parentNode.insertBefore(newLi, parentLi.nextSibling);
ob.disconnect();
}
});
});
obs.observe(document.body, { childList: true, subtree: true });
});
</script>
EOF
- Inject it into the Admin Panel
cp /www/gl_home.html /www/gl_home.html.bak
sed -i '/<\/body>/r /tmp/poweroff_snippet.js' /www/gl_home.html
/etc/init.d/uhttpd reload
- Open the Admin Panel in incognito modeâyouâll see Power Off immediately below Advanced Settings in the System menu.
- Persist via
rc.local
Edit /etc/rc.local
again (with vi /etc/rc.local
) and before exit 0
paste:
# recreate Admin Panel Power Off snippet
cat > /tmp/poweroff_snippet.js << 'EOF'
<script>
window.addEventListener('DOMContentLoaded', function(){
var obs = new MutationObserver(function(muts, ob){
// Seleciona todos os tĂtulos de item de menu
var titles = document.querySelectorAll('.el-menu-item > .menu-title');
titles.forEach(function(title){
if (title.textContent.trim() === 'Advanced Settings') {
var parentLi = title.closest('li.el-menu-item');
// cria novo <li> com a mesma classe e estilo
var newLi = document.createElement('li');
newLi.setAttribute('role','menuitem');
newLi.setAttribute('tabindex','-1');
newLi.className = 'el-menu-item';
newLi.style.paddingLeft = parentLi.style.paddingLeft;
// cria o <span><a>Power Off</a></span>
var span = document.createElement('span');
span.className = 'menu-title';
var a = document.createElement('a');
a.href = '/cgi-bin/luci/admin/mcu';
a.textContent = 'Power Off';
span.appendChild(a);
newLi.appendChild(span);
// insere logo apĂłs o Advanced Settings
parentLi.parentNode.insertBefore(newLi, parentLi.nextSibling);
ob.disconnect();
}
});
});
obs.observe(document.body, { childList: true, subtree: true });
});
</script>
EOF
cp /www/gl_home.html /www/gl_home.html.bak 2>/dev/null
sed -i '/<\/body>/r /tmp/poweroff_snippet.js' /www/gl_home.html
/etc/init.d/uhttpd reload
Save & exit. Now every boot (and after any firmware upgrade that preserves /etc/rc.local
), your Admin Panel will automatically get the Power Off link re-injected.
In Summary
- LuCI:
- Create
/usr/lib/lua/luci/controller/poweroff.lua
- Installer at
/usr/bin/install_poweroff
- Call it from
/etc/rc.local
- GL-iNet Admin Panel:
- Inject a JS snippet into
/www/gl_home.html
- Automate via
/etc/rc.local
I hope it helps as it helped me. =)