继前面三篇篇:OpenWrt的luci web管理器添加新菜单 、 OpenWrt的luci web管理器添加新菜单(二)和 OpenWrt的luci web管理器添加新菜单(三)
本文将记录如何实现按键重启路由的功能
步骤一:
在/usr/lib/lua/luci/controller/admin/new_tab.lua 文件中加入如下内容:
entry({"admin", "new_tab", "reboot"}, cbi("admin_myapp/reboot"), _("Reboot"), 4)
步骤二:
添加/usr/lib/lua/luci/model/cbi/admin_myapp/reboot.lua文件:
-- Copyright 2008 fulinux <fulinux@sina.com>
-- Licensed to the public under the Apache License 2.0.
m = Map("button", translate("Reboot"), translate("reboot system"))
s = m:section(TypedSection, "reboot", "Part reboot of the form")
s.addremove = false
s.anonymous = true
button = s:option(Button, "_button", "Reboot")
button.inputtitle = translate("Reboot")
button.inputstyle = "apply"
function button.write(self, section, value)
s:option(DummyValue, "Reboot", "reboot...")
luci.sys.call("reboot")
end
s.optional=false;
s.rmempty = false;
return m
步骤三:
添加/etc/config/button文件:
config reboot