继前面两篇:OpenWrt的luci web管理器添加新菜单 和 OpenWrt的luci web管理器添加新菜单(二)
此次的扩展内容是实现一个登录界面,并且将登录界面中输入的内容解析到一个配置文件中
修改/usr/lib/lua/luci/model/cbi/admin_myapp/cbi_tab.lua文件:
-- Copyright 2008 fulinux <fulinux@sina.com> -- Licensed to the public under the Apache License 2.0. m = Map("login", translate("Login client"), translate("Please fill out the form below")) s = m:section(TypedSection, "login", "Part login of the form") s.addremove = false s.anonymous = true enable = s:option(Flag, "enable", translate("Enable")) name = s:option(Value, "username", translate("Username")) pass = s:option(Value, "password", translate("Password")) pass.password = true domain = s:option(Value, "domain", "Interfaces"); ifname = s:option(ListValue, "ifname", translate("Domain")) for k, v in ipairs(luci.sys.net.devices()) do if v ~= "lo" then ifname:value(v) end end s.optional=false; s.rmempty = false; local apply = luci.http.formvalue("cbi.apply") if apply then luci.sys.exec("/etc/init.d/login start") end return m
config login option username ‘fulinux‘ option enable ‘‘ option domain ‘‘ option ifname ‘‘ option password ‘‘
#!/bin/sh /etc/rc.common START=14 run_copyconfig() { local enable config_get_bool enable $1 enable if [ $enable ]; then local username local password local domain local ifname config_get username $1 username config_get password $1 password config_get domain $1 domain config_get ifname $1 ifname echo $username > /var/run/testfile.conf echo $password >> /var/run/testfile.conf echo $domain >> /var/run/testfile.conf echo $ifname >> /var/run/testfile.conf echo "testfile has started." fi } start() { config_load login config_foreach run_copyconfig login }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/fulinus/article/details/48996445