xiangbo80 发表于 2015-9-20 20:18

微信扫一扫认证流程中AP部分的代码

module("luci.controller.sfcos", package.seeall)
function index()
page = entry({"sfcos"}, call("sfcos"))
page.dependent = false
page.leaf = true
end

function sfcos()
local user_ip = luci.sys.getenv("REMOTE_ADDR")/获取当前客户端IP
local leasefile = "/var/dhcp.leases"        /读取IP列表
local fd = io.open(leasefile, "r")   /根据客户端IP得到MAC地址
        if fd then
                while true do
                        local ln = fd:read("*l")
                        if not ln then
                                break
                        else
                                local ts, mac, ip, name, duid = ln:match("^(%d+) (%S+) (%S+) (%S+) (%S+)")
                                if ip == user_ip then
                                user_mac = mac
                                end
                        end
                end
                fd:close()
        end
local file = io.open("/tmp/"..user_mac, "r")   /302跳转发送到认证服务器,分两种情况:首次连接和二次连接.微信要求auth进行加密,不过不加密也可以传递
if file then
luci.http.redirect("http://xxx.xxx.xxx/?auth="..user_mac)
else
io.open("/tmp/"..user_mac, "w+")
luci.sys.exec("iptables -t mangle -A WiFiDog_br-lan_Trusted   -s "..user_ip.." -m mac --mac-source "..user_mac.." -j MARK --set-mark 0x2")   /将当前客户端加入到wifidog白名单
luci.http.redirect("http://xxx.xxx.xxx/?auth="..user_ip.."|"..user_mac)    /这是第一次连接
end
end我的路由器环境是: openwrt+lighttpd+wifidog,程序采用LUCI框架, AP部分的工作很简单,只要获取到微信认证的AUTH参数交给认证服务器处理,所以OPENWRT系统中只需要添加一个LUCI文件就可以了,记得把微信的黑名单请求http://10.1.0.6/redirect指向这个LUCI文件。刚学LUA,请高手不要见笑。

南路 发表于 2015-10-24 23:10

页: [1]
查看完整版本: 微信扫一扫认证流程中AP部分的代码