lua网桥和路由模式数据的设置

以下是自行写的lua网桥和路由模式数据的设置。警供参考:

module("luci.controller.wizard", package.seeall)

function index()
entry({"admin", "services","wizard"}, call("action"), "设置向导", 6)
entry({"admin", "services","wizard","commit"}, call("commit"))
entry({"admin", "services","wizard1"}, call("action_first"), "设置向导下一步", 6)
entry({"admin", "services","wizard1","commit_first"}, call("commit_first"))
entry({"admin", "services","wizard1.1"}, call("action_first_first"), "设置向导下一步", 6)
entry({"admin", "services","wizard1.1","commit_first_first"}, call("commit_first_first"))
entry({"admin", "services","wizard1.2"}, call("action_first_second"), "设置向导下一步", 6)
entry({"admin", "services","wizard1.2","commit_first_second"}, call("commit_first_second"))
entry({"admin", "services","wizard2"}, call("action_second"), "设置向导再下一步", 6)
entry({"admin", "services","wizard2","commit_second"}, call("commit_second"))
entry({"admin", "services","wizard3"}, call("action_last"), "设置向导最后一步", 6)
entry({"admin", "services","wizard3","commit_last"}, call("commit_last"))
end
--设置设置向导页面
function action()
luci.template.render("admin_setting/wizard")
end
 --设置向导基本设置
 function commit()
 end
--设置设置向导下一步页面
function action_first()
luci.template.render("admin_setting/wizard1")
end
 --设置向导下一步基本设置
 function commit_first()
 end
--设置设置向导下一步页面
function action_first_first()
luci.template.render("admin_setting/wizard1.1")
end
 --设置向导下一步基本设置
 function commit_first_first()
 end
--设置设置向导下一步页面
function action_first_second()
luci.template.render("admin_setting/wizard1.2")
end
 --设置向导下一步基本设置
 function commit_first_second()
 end
--设置设置向导页面
function action_second()
luci.template.render("admin_setting/wizard2")
end
 --设置向导基本设置
 function commit_second()
 end
--设置向导最后一步页面
function action_last()
luci.template.render("admin_setting/wizard3")
end
 --设置向导最后一步基本设置
 function commit_last()
  local uci  = require "luci.model.uci".cursor()
  local json = require "cjson"
  local pppoe = luci.http.formvalue("pppoe")
  local dhcp_client = luci.http.formvalue("dhcp_client")
  local static = luci.http.formvalue("static")
  local lan = luci.http.formvalue("lan")
  local dhcp = luci.http.formvalue("dhcp")
  local bridge = luci.http.formvalue("bridge")
  local mode = luci.http.formvalue("mode")
-- luci.http.prepare_content("application/json")
-- luci.http.write_json(dhcp_client)
--网桥和路由模式的判断
if mode=="route" then
--路由模式
--pppoe拨号
if pppoe ~= "undefined" then
local pppoe = json.decode(pppoe)
uci:set("network","wan1","interface")
uci:set("network","wan1","ifname",pppoe["ifname"])
uci:set("network","wan1","proto",pppoe['proto'])
uci:set("network","wan1","username",pppoe['username'])
uci:set("network","wan1","password",pppoe['password'])
end
--dhcp客户端设置
if dhcp_client ~= "undefined" then
local dhcp_client = json.decode(dhcp_client)
end
--ip静态
if static ~= "undefined" then
local static = json.decode(static)
end
--lan口设置
if lan ~= "undefined" then
local lan = json.decode(lan)
uci:set("network","lan1","interface")
uci:set("network","lan1","ifname",lan["ifname"])
uci:set("network","lan1","type",lan["type"])
uci:set("network","lan1","mode",lan["mode"])
uci:set("network","lan1","proto",lan['proto'])
uci:set("network","lan1","ipaddr",lan['ipaddr'])
uci:set("network","lan1","netmask",lan['netmask'])
end
--dhcp服务端设置
if dhcp ~= "undefined" then
local dhcp = json.decode(dhcp)
uci:set("dhcp","lan1","dhcp")
uci:set("dhcp","lan1","interface",dhcp["interface"])
uci:set("dhcp","lan1","start",dhcp["start"])
uci:set("dhcp","lan1","limit",dhcp["limit"])
uci:set("dhcp","lan1","leasetime",dhcp['leasetime'])
uci:set("dhcp","lan1","force",dhcp['force'])
uci:delete("dhcp","lan1","ignore")
end
uci:delete("network","lan1","gateway")
uci:delete("network","lan1","dns")
else
--网桥模式
if bridge ~= "undefined" then
local bridge = json.decode(bridge)
uci:set("network","lan1","interface")
uci:set("network","lan1","ifname",bridge["ifname"])
uci:set("network","lan1","proto",bridge["proto"])
uci:set("network","lan1","mode",bridge["mode"])
uci:set("network","lan1","ipaddr",bridge['ipaddr'])
uci:set("network","lan1","netmask",bridge['netmask'])
uci:set("network","lan1","gateway",bridge['gateway'])
uci:set("network","lan1","dns",bridge['dns'])
uci:set("dhcp","lan1","dhcp")
uci:set("dhcp","lan1","ignore",bridge['ignore'])
uci:delete("dhcp","lan1","force")
uci:delete("network","wan1")
end
end
  uci:commit("network")
  uci:commit("dhcp")
 end

猜你喜欢

转载自blog.csdn.net/qq_35396905/article/details/80856455