生活随笔
收集整理的這篇文章主要介紹了
Openwrt中luci配置页面cbi小记
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
先看看network的配置文件:
[html] view plaincopy
config?interface?'loopback'??????????option?ifname?'lo'??????????option?proto?'static'??????????option?ipaddr?'127.0.0.1'??????????option?netmask?'255.0.0.0'????config?interface?'lan'??????????option?ifname?'eth0?eth1'??????????option?type?'bridge'??????????option?proto?'static'??????????option?ipaddr?'192.168.1.10'??????????option?netmask?'255.255.255.0'????config?switch??????????option?name?'eth0'??????????option?reset?'1'??????????option?enable_vlan?'1'????config?switch_vlan??????????option?device?'eth0'??????????option?vlan?'1'??????????option?ports?'0?1?2?3?4'?? 首先綁定/etc/config下的一個(gè)配置文件,比方network:
[html] view plaincopy
m?=?Map("network")?? 然后綁定network以下的一個(gè)部分,比方config interface 'lan' :
[html] view plaincopy
n?=?m:section(NamedSection,?"lan",?translate("接口配置"))??n.anonymous?=?true??n.addremove?=?false?--不添加移除的button??這里使用的是名字匹配。還有類型匹配。加如要config?switch?這個(gè)時(shí)候我們能夠使用?:?? [html] view plaincopy
n?=?m:section(TypedSection,?"switch",translate("xx"))?? 假如上面的lan使用TypedSection interface的話? ,是能夠同一時(shí)候匹配 config interface loopback 里面的字段的。
這個(gè)時(shí)候我們已經(jīng)綁定了lanport的字段 ,就能夠開始對里面的ipaddr,netmask等進(jìn)行改動 :
[html] view plaincopy
ip?=?n:option(Value,"ipaddr",translate("IP地址")?? 這個(gè)時(shí)候就會有一個(gè)IP地址 :???????????????????????????? 。這種對話框,里面填寫就可以,假設(shè)須要加入提示,能夠這樣:
[html] view plaincopy
ip?=?n:option(Value,"ipaddr","IP地址","改動IP地址”)?? 這個(gè)時(shí)候下方就會顯示一句提示。改動IP地址。
當(dāng)中的Value還有幾種別的屬性,比方Listvalue,下拉選擇框,假如說我要選擇netmask,給幾個(gè)選項(xiàng),下拉選擇:
[html] view plaincopy
mask?=?s:option(ListValue,"netmask",translate("子網(wǎng)掩碼"))??mask.override_values?=?true??mask:value("255.255.255.0",translate("255.255.255.0"))??mask:value("xxx.xxx.xxx.x",translate("xxxxxx"))????????????? 這個(gè)時(shí)候就會出現(xiàn)一個(gè)子網(wǎng)掩碼的下拉框供選擇。詳細(xì)更復(fù)雜的功能能夠參考官方文檔
Value另一個(gè)屬性就勾選框,Flag,用法類似,介紹一點(diǎn)最簡單的使用 :
[html] view plaincopy
encryption?=?s:option(Flag,"encryption",translate("............"))????????????????????????????????????????????encryption.default?=?encryption.enabled?????????????????????????????????????encryption.enabled?=?"wpa-psk2"?????????????????????????????????????????????encryption.disabled?=?"none"??? 這個(gè)是選擇加不加密的,一般這個(gè)時(shí)候我們選擇以后要出現(xiàn)一個(gè)key的password框。這個(gè)時(shí)候就要用到depends()這個(gè)函數(shù)了,比方:
[html] view plaincopy
key?=?s:option(Value,"key",translate("Password"))????????????????????????????????????????????????????????????key:depends({encryption="wpa-psk2"})??? 這里結(jié)合上面的勾選。假如勾選,就會出現(xiàn)一個(gè)password框,也能夠和下拉框配合一起使用
最后通過改動帳號password來介紹幾個(gè)參數(shù) :
[html] view plaincopy
username?=?s:option(Value,"username",".........")?????????????????????????????????????????????????????????????username.rmempty?=?false?--不同意為空????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????password?=?s:option(Value,"password",".........")????????????????????????????????????????????????????????????password.password=true???--加密,也就是*號顯示,往往后面會帶一個(gè)button,能夠即時(shí)顯示密碼?????????????????????????????????????????password.rmempt?=false??? 臨時(shí)就這么多。以后再慢慢補(bǔ)充,近期在寫機(jī)器人。掛在irc上面,結(jié)合曾經(jīng)寫的一些查詢類程序。能夠?qū)崿F(xiàn)非常多功能嘿嘿,上班沒事的時(shí)候?qū)憣?br />
對了 ,改動完了記得rm -rf /tmp/luci-*來更新緩存,不然看不到變化的,還有瀏覽器刪掉又一次輸入地址!
新增button簡單應(yīng)用
button = modex:option(Button, "modename", "橋接模式")
button.inputtitle = translate("切換")
button.inputstyle = "apply"
function button.write(self, section, value)
??? AbstractValue.write(self, section, value)
??? luci.sys.call("uci set network.lan.ifname=\"eth0.1 eth0.2\" ;uci del network.wan")
??? --self.inputtitle = translate("路由模式")
??? return
end
DDummyValue 靜態(tài)文本
depends在非常多情況下不安常理出牌,還有待研究
轉(zhuǎn)載于:https://www.cnblogs.com/yangykaifa/p/7117775.html
總結(jié)
以上是生活随笔為你收集整理的Openwrt中luci配置页面cbi小记的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。