OpenWrt的luci web管理器添加新菜单(三)

来源:互联网 发布:淘宝最近总是查侵权 编辑:程序博客网 时间:2024/06/05 16:11

继前面两篇: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 = falses.anonymous = trueenable = s:option(Flag, "enable", translate("Enable"))name = s:option(Value, "username", translate("Username"))pass = s:option(Value, "password", translate("Password"))pass.password = truedomain = 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)        endends.optional=false;s.rmempty = false;local apply = luci.http.formvalue("cbi.apply")if apply then        luci.sys.exec("/etc/init.d/login start")endreturn m

步骤二:

修改/etc/config/login配置文件(文件原名是cbi_file),内容如下:
config login        option username 'fulinux'        option enable ''        option domain ''        option ifname ''        option password ''

步骤三:

添加/etc/init.d/login脚本文件,内容如下:
#!/bin/sh /etc/rc.commonSTART=14run_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}

作品展示:

1、Web界面:



2、配置文件:



3、生成的配置文件:



0 0
原创粉丝点击