ubnt解决方案
查看: 877|回复: 1

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

[复制链接]

2

回帖

126

积分

48 小时

在线时间

上等兵

注册时间
2012-4-19
金币
114 个
威望
0 个
荣誉
0 个
累计签到:6 天
连续签到:0 天
[LV.20]漫游旅程
发表于 2015-9-20 20:18 |显示全部楼层
  1. module("luci.controller.sfcos", package.seeall)
  2. function index()
  3. page = entry({"sfcos"}, call("sfcos"))
  4. page.dependent = false
  5. page.leaf = true
  6. end

  7. function sfcos()
  8. local user_ip = luci.sys.getenv("REMOTE_ADDR")  /获取当前客户端IP
  9. local leasefile = "/var/dhcp.leases"        /读取IP列表
  10. local fd = io.open(leasefile, "r")   /根据客户端IP得到MAC地址
  11.         if fd then
  12.                 while true do
  13.                         local ln = fd:read("*l")
  14.                         if not ln then
  15.                                 break
  16.                         else
  17.                                 local ts, mac, ip, name, duid = ln:match("^(%d+) (%S+) (%S+) (%S+) (%S+)")
  18.                                 if ip == user_ip then
  19.                                 user_mac = mac
  20.                                 end
  21.                         end
  22.                 end
  23.                 fd:close()
  24.         end
  25. local file = io.open("/tmp/"..user_mac, "r")     /302跳转发送到认证服务器,分两种情况:首次连接和二次连接.微信要求auth进行加密,不过不加密也可以传递
  26. if file then
  27. luci.http.redirect("http://xxx.xxx.xxx/?auth="..user_mac)
  28. else
  29. io.open("/tmp/"..user_mac, "w+")
  30. 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白名单
  31. luci.http.redirect("http://xxx.xxx.xxx/?auth="..user_ip.."|"..user_mac)    /这是第一次连接
  32. end
  33. end
复制代码
我的路由器环境是: openwrt+lighttpd+wifidog  ,程序采用LUCI框架, AP部分的工作很简单,只要获取到微信认证的AUTH参数交给认证服务器处理,所以OPENWRT系统中只需要添加一个LUCI文件就可以了,记得把微信的黑名单请求http://10.1.0.6/redirect指向这个LUCI文件。刚学LUA,请高手不要见笑。
头像被屏蔽

270

回帖

612

积分

384 小时

在线时间

禁止发言

注册时间
2015-8-19
金币
293 个
威望
0 个
荣誉
0 个
累计签到:238 天
连续签到:0 天
[LV.365]无线熟人
发表于 2015-10-24 23:10 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册 微信登录

本版积分规则

Archiver | 手机版 | 无线门户 ( 粤ICP备11076993号|粤公网安备44010602008359号 ) |网站地图

GMT+8, 2026-6-5 08:22

返回顶部 返回列表