zoukankan      html  css  js  c++  java
  • OpenWrt Web 开发 LuCI框架 lua语言

    LuCI作为“FFLuCI”诞生于2008年3月份,目的是为OpenWrt固件从 Whiterussian 到 Kamikaze实现快速配置接口。Lua是一个小巧的脚本语言,很容易嵌入其它语言。轻量级 LUA语言的官方版本只包括一个精简的核心和最基本的库。这使得LUA体积小、启动速度快,从而适合嵌入在别的程序里。UCI是OpenWrt中为实现所有系统配置的一个统一接口,英文名Unified Configuration Interface,即统一配置接口。LuCI,即是这两个项目的合体,可以实现路由的网页配置界面。

    要在路由器上实现路由器的配置页面的开发

    就是路由器,后标签贴的,管理路径 一般是 192.168.1.1 或192.168.0.1

    要实现一套这样的小项目

    项目内容很小,个人有兴趣,所以接了这任务

    任何的web开发,只要有搞清楚的request,response,mvc结构,很容易上手。

    后端示例代码

    #!/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,"
    ")
             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
    

      

  • 相关阅读:
    Android笔记(六十六) android中的动画——XML文件定义属性动画
    Android笔记(六十五) android中的动画——属性动画(propertyanimation)
    python函数参数默认值及重要警告
    Python 列表
    Python数学运算入门把Python当作计算器
    Python 的非正式介绍
    python中为什么 if/while/def/class语句需要冒号?
    为什么Python在列表和元组的末尾允许使用逗号?
    现实世界中的 Python
    Python常见问题
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/4578855.html
Copyright © 2011-2022 走看看