900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > Openwrt中luci配置页面cbi小记

Openwrt中luci配置页面cbi小记

时间:2021-01-09 06:46:57

相关推荐

Openwrt中luci配置页面cbi小记

先看看network的配置文件:

[html]view plaincopy configinterface'loopback'optionifname'lo'optionproto'static'optionipaddr'127.0.0.1'optionnetmask'255.0.0.0'configinterface'lan'optionifname'eth0eth1'optiontype'bridge'optionproto'static'optionipaddr'192.168.1.10'optionnetmask'255.255.255.0'configswitchoptionname'eth0'optionreset'1'optionenable_vlan'1'configswitch_vlanoptiondevice'eth0'optionvlan'1'optionports'01234'

首先绑定/etc/config下的一个配置文件,比方network:

[html]view plaincopy m=Map("network") 然后绑定network以下的一个部分,比方config interface 'lan' :[html]view plaincopy n=m:section(NamedSection,"lan",translate("接口配置"))n.anonymous=truen.addremove=false--不添加移除的button这里使用的是名字匹配。还有类型匹配。加如要configswitch这个时候我们能够使用:[html]view plaincopy n=m:section(TypedSection,"switch",translate("xx")) 假如上面的lan使用TypedSection interface的话 ,是能够同一时候匹配 config interface loopback 里面的字段的。

这个时候我们已经绑定了lanport的字段 ,就能够開始对里面的ipaddr,netmask等进行改动 :

[html]view plaincopy ip=n:option(Value,"ipaddr",translate("IP地址") 这个时候就会有一个IP地址 : 。这种对话框,里面填写就可以,假设须要加入提示,能够这样:[html]view plaincopy ip=n:option(Value,"ipaddr","IP地址","改动IP地址”) 这个时候下方就会显示一句提示。改动IP地址。

当中的Value还有几种别的属性,比方Listvalue,下拉选择框,假如说我要选择netmask,给几个选项,下拉选择:

[html]view plaincopy mask=s:option(ListValue,"netmask",translate("子网掩码"))mask.override_values=truemask:value("255.255.255.0",translate("255.255.255.0"))mask:value("xxx.xxx.xxx.x",translate("xxxxxx")) 这个时候就会出现一个子网掩码的下拉框供选择。详细更复杂的功能能够參考官方文档

Value另一个属性就勾选框,Flag,用法类似,介绍一点最简单的使用 :

[html]view plaincopy encryption=s:option(Flag,"encryption",translate("............"))encryption.default=encryption.enabledencryption.enabled="wpa-psk2"encryption.disabled="none" 这个是选择加不加密的,一般这个时候我们选择以后要出现一个key的password框。这个时候就要用到depends()这个函数了,比方:[html]view plaincopy key=s:option(Value,"key",translate("Password"))key:depends({encryption="wpa-psk2"}) 这里结合上面的勾选。假如勾选,就会出现一个password框,也能够和下拉框配合一起使用

最后通过改动帐号password来介绍几个參数 :

[html]view plaincopy username=s:option(Value,"username",".........")username.rmempty=false--不同意为空password=s:option(Value,"password",".........")password.password=true--加密,也就是*号显示,往往后面会带一个button,能够即时显示密码password.rmempt=false

临时就这么多。以后再慢慢补充,近期在写机器人。挂在irc上面,结合曾经写的一些查询类程序。能够实现非常多功能嘿嘿,上班没事的时候写写

对了 ,改动完了记得rm -rf /tmp/luci-*来更新缓存,不然看不到变化的,还有浏览器删掉又一次输入地址!

新增button简单应用

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 静态文本

depends在非常多情况下不安常理出牌,还有待研究

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。