上等兵
- 注册时间
- 2012-4-19
- 金币
- 114 个
- 威望
- 0 个
- 荣誉
- 0 个
累计签到:6 天 连续签到:0 天 [LV.20]漫游旅程
|
- 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,请高手不要见笑。
|
|