Following the previous two articles: OpenWrt Luci Web Manager Add New menu and OpenWrt Luci Web Manager Add new menu (ii)
This extension is to implement a login interface, and the login interface to parse the input content into a configuration file
Step One:
To modify the /usr/lib/lua/luci/model/cbi/admin_myapp/Cbi_tab.lua file:
--Copyright fulinux <[email protected]>--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 O f the form ") S.addremove = falses.anonymous = Trueenable = S:option (Flag," Enable ", Translate (" Enable ")) name = S:option (Val UE, "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-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
Step Two:Modify the/etc/config/login configuration file (the file formerly known as Cbi_file) with the following contents:
Config login option username ' fulinux ' option enable ' option domain ' option ifname ' option Password "
Step Three:Add the/etc/init.d/login script file with the following content:
#!/bin/sh/etc/rc.commonstart=14run_copyconfig () { Local enable Config_get_bool enable enable if [$ Enable]; Then local username local password local domain local ifname config_get username $ username Config_get Password $ password config_get domain domain config_get ifname $ 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}
Works Show:1. Web interface:
2. configuration file:
3. Generated configuration file:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
OpenWrt Luci Web Manager Add a new menu (iii)