要在路由器上实现路由器的配置页面的开发
就是路由器,后标签贴的,管理路径 一般是 192.168.1.1 或192.168.0.1
要实现一套这样的小项目
项目内容很小,个人有兴趣,所以接了这任务
路由器 自带nginx lua支持
任何的web开发,只要有搞清楚的request,response,mvc结构,很容易上手。
前端引用 js/jquery.idTabs.min.js
后端示例代码
#!/usr/bin/env lua
local json = require "los.json"
local util = require "los.util"
--配置文件路径
wifiplacedatapath="/etc/testconfig.data"
--设置
local function set_placeinfo(data)
local str=""
util.exec(‘rm -rf ‘.. wifiplacedatapath)
for k,v in pairs(data) do
if k~="act" then
util.exec("echo ‘" .. k .. "|" .. v .. "‘ >> " .. wifiplacedatapath)
end
end
ngx.print(json.encode({status=0}))
end
--读取
function getplaceinfo()
local bw = io.open(wifiplacedatapath)
local wifidata={}
if bw then
local bwraw = bw:read("*a")
local tabs= split(bwraw,"\n")
for i=1,#tabs do
if tabs[i]~=nil and tabs[i]~=‘‘ then
local subtabs=split(tabs[i],"|")
wifidata[subtabs[1]]=subtabs[2]
end
end
end
return wifidata
end
local function get_placeinfo()
local wifidata=getplaceinfo()
ngx.print(json.encode(wifidata))
end
--路由
local function parser()
local args = ngx.req.get_uri_args()
if tostring(args.act) == "get" then
get_placeinfo()
elseif tostring(args.act) == "set" then
set_placeinfo(args)
end
end
parser()
local function split(str, delimiter)
if str==nil or str==‘‘ or delimiter==nil then
return nil
end
local result = {}
for match in (str..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end
原文:http://www.cnblogs.com/zihunqingxin/p/4578855.html