openwrt - Add column - Add page

1. Add a configuration page in the original column

1. The files in /usr/lib/lua/luci/controller/admin are the columns corresponding to the UI page .

If you need to add it in that column, open the corresponding lua file

For example, if I want to add a page in the system column, I open the system.lua file and add a line of code

entry({"admin", "system", "test"}, cbi("admin_system/test"), _("Test"), 60)

Note: 1. system means in the system column, and test is the page to be created

        2. cbi("admin_system/test") is to put the configuration file here later. In fact, it is to change the test.

        3. 60 means sorting. You can see that the following figure is in order, from small to large. If you want to put it in that position, write it according to the numbers before and after

Note, generally modify the files in the controller, then restart it, or delete luci-indexcache luci-modulecache/luci-sessions/ in the /tmp/ directory

Save it, restart the machine, and you can see that the test page has been added to the UI page

2. Create a new test file in /etc/config

config test
        option name '123'
        option url '123.com'

3. Create a new page test.lua under /usr/lib/lua/luci/model/cbi/admin_system.

Regarding the content in test.lua, you can refer to Openwrt: CBI of LuCI (2)_Jags' Blog-CSDN Blog , you can rewrite it according to your needs

local ipc = require "luci.ip"

m = Map("test", translate("Test1"))

s = m:section(TypedSection, "test", translate("Example Info"))
s.addremove = true
s.anonymous = true
s.template = "cbi/tblsection"

name = s:option(Value, "name", translate("Name"))
name.datatype = "string"
name.rmempty  = true

url = s:option(Value, "url", translate("Url"))
url.datatype = "hostname"
url.rmempty  = true

return m

 4. Refresh, the UI page also comes out

2. Add a new column and add a configuration page in the new column

In fact, it is similar to adding pages in the original column. Let’s look at the picture first. We know that each column corresponds to a lua file. To add a page in the original column, you only need to find the corresponding file and add a statement.

Then add a column, that is, create a new file.

1. Create a new busservice.lua file under /usr/lib/lua/luci/model/cbi/

(i.e. add a new column)

Edit the content in the busservice.lua file, you can refer to other files, for example

module("luci.controller.admin.busservice", package.seeall)

function index()
        entry({"admin", "busservice"}, alias("admin", "busservice", "busservice"), _("Busservice"), 35).index = true
        entry({"admin", "busservice", "access_restrictions"}, cbi("admin_busservice/access_restrictions"), _("Access Restrictions"), 10)

        entry({"admin", "busservice", "urlfiltering"}, cbi("admin_busservice/urlfiltering"), _("Urlfiltering"), 20)

end

Here I wrote two pages, access_restrictions and urlfiltering, you can rewrite according to your needs.

The column is newly created, restart the board, refresh the UI page and you can see it

2. Create a new configuration file

Here I wrote the access_restrictions page. In fact, I have already put the urlfiltering page on it, but changed the name.

The configuration file is under /etc/config/

vi /etc/config/access_restrictions
config access_restrictions
        option name '123'
        option ip '123.12.12.12'
        option protocol 'tcp'
        option starport '10'
        option endport '888'

The option inside can be rewritten according to your own needs

3. Create a new cbi page and create the admin_busservice directory under /usr/lib/lua/luci/model/cbi/

(Or change the name to your own, according to your own column name, refer to other files)

mkdir admin_busservice
cd admin_busservice
进入admin_busservice文件(这个就相当于是栏目),新建页面文件(此栏目里面的页面)

vi access_restrictions.lua
m = Map("access_restrictions", translate("Access_Restrictions"))

s = m:section(TypedSection, "access_restrictions",translate("Example Info"))
s.addremove = true
s.anonymous = true
s.template = "cbi/tblsection"

name = s:option(Value, "name", translate("Name"))
name.datatype = "string"
name.rmempty  = true

ip = s:option(Value, "ip", translate("IP address"))
ip.datatype = "ipaddr"
ip.rmempty  = true

ipc.neighbors({ }, function(n)
        if n.mac and n.dest and not n.dest:is6linklocal() then
                ip:value(n.dest:string(), "%s (%s)" %{ n.dest:string(), n.mac })
        end
end)

-- 下拉框
p = s:option(ListValue, "protocol", translate("Protocol"))
p:value("tcp","TCP")
p:value("udp","UDP")
p:value("tcp+udp","TCP+UDP")

sp = s:option(Value, "starport", translate("Star port"))
sp.datatype = "and(min(1),max(65534))"
sp.rmempty  = true

ep = s:option(Value, "endport", translate("End port"))
ep.datatype = "and(min(1),max(65535))"
ep.rmempty  = true

return m

Save, refresh the page, the content has come out.

 

Those who want to learn CBI are the content in the access_restrictions.lua file, click the link below. I think this one is not bad.

Openwrt: LuCI's CBI (2) - Jags' Blog - CSDN Blog

Ok, the above are the steps to create a new column and page on openwrt. If there is anything you don’t understand, just go to Baidu. Ask me. Maybe my knowledge is less than yours. I also record while studying. If there are any mistakes in the text, I hope God pointed out.

Guess you like

Origin blog.csdn.net/m0_60027682/article/details/126876256