Wifidog路由接口文档

维基教科书,自由的教学读本

WIFIDOG路由接口文档

概述[编辑]

wifidog是搭建无线热点认证系统的解决方案之一,他比nocat更适合互联网营销思路。目前支持openwrt系统,他实现了路由器和认证服务器的数据交互,在路由器方是用C语言代码,通过wifidog程序和linux iptables防火墙实现接入用户的认证跳转和控制,在认证服务器方是通过php实现用户的认证流程和管理。
优点:有开源代码,可以很方便的搭建认证系统。
缺点:通过iptables方式实现,性能比较差,整体拉低了路由器的数据包处理速度,协议比较繁琐,对认证服务器的造成性能损耗比较大,在安全方面都是明文传输,有一定的安全隐患。

认证流程图:[编辑]

网关心跳协议[编辑]

Wifidog将ping协议作为心跳机制向认证服务器发送当前状态信息。实现认证服务器和每个节点的状态双向健康监测的机制。

请求信息格式:[编辑]

http://auth_sever/ping/?
gw_id=%s
sys_uptime=%lu
sys_memfree=%u
sys_load=%.2f
wifidog_uptime=%lu

而请求封包的封包header如下

Headers
HTTP/1.0\r\n" 
"User-Agent: WiFiDog %s\r\n" 
"Host: %s\r\n" 
"\r\n",

User-Agent 会因为你的设定而改变

回复格式:[编辑]

Pong

例子:[编辑]

GET /ping/?gw_id=001217DA42D2&sys_uptime=742725&sys_memfree=2604&sys_load=0.03&wifidog_uptime=3861 HTTP/1.0
User-Agent: WiFiDog 1.1.3_beta6
Host: auth.ilesansfil.org

用户状态心跳协议[编辑]

请求格式:[编辑]

auth_server:/auth/index.php?
stage=
ip=
mac=
token=
incoming=
outgoing=

注意:[编辑]

ip, mac, token为用户的基本信息,incoming, outgoing为用户的连接计数信息。

stage=counter|login|logout,分别表示:已认证、新认证用户、超时需要删除的用户。

回复格式:[编辑]

Auth: 状态码

(注意中间冒号和状态码之间有个空格)

状态码:[编辑]

0 - AUTH_DENIED - 用戶已被刪除
6 - AUTH_VALIDATION_FAILED - Email驗證超時,用戶被刪除
1 - AUTH_ALLOWED - 合法用戶,若防火牆無記錄則新增
5 - AUTH_VALIDATION - 允許用戶接上信箱完成認證
-1 - AUTH_ERROR - 驗證失敗

例子:[编辑]

GET /auth/?stage=counters&ip=7.0.0.107&mac=00:40:05:5F:44:43&token=4f473ae3ddc5c1c2165f7a0973c57a98&incoming=6031353&outgoing=827770 HTTP/1.0
User-Agent: WiFiDog 1.1.3_beta6
Host: auth.ilesansfil.org

跳转协议[编辑]

客户端网页会在以下几种情况被跳转。

第一次连上[编辑]

刚连上,用户会被重导向到以下URL进行验证

  • login/?gw_address=%s&gw_port=%d&gw_id=%s&url=%s

例子[编辑]

https://auth.ilesansfil.org/login/?gw_id=0016B6DA9AE0&gw_address=7.0.0.1&gw_port=2060

首次验证后[编辑]

一旦第一次验证进行后,用户会因以下状况被跳转到不同地方。

若服务器回应 AUTH_DENIED: Note that you will normally never see that one in the standard auth server. The client won't be redirected back to the gateway.

  • gw_message.php?message=denied

若服务器回应 AUTH_VALIDATION:

  • gw_message.php?message=activate

若服务器回应 AUTH_ALLOWED: This is the portal redirect

  • portal/?gw_id=%s

若服务器回应 AUTH_VALIDATION_FAILED: Note that you will normally never see that one in the standard auth server. The client won't be redirected back to the gateway.

  • gw_message.php?message=failed_validation

Browser redirects by the auth server[编辑]

Upon successfull login, the client will be redirected to the gateway.  http://" . $gw_address . ":" . $gw_port . "/wifidog/auth?token=" . $token

Example URL  http://7.0.0.1:2060/wifidog/auth?token=4f473ae3ddc5c1c2165f7a0973c57a98

注册协议[编辑]

请求格式:[编辑]

http://gw_ip/wifidog/auth? token=

例子:[编辑]

GETwifidog/auth?token=12312412124 User-Agent:iphone Host:路由器ip 注册请求成功,以307的方式跳转平台的portal/?gw_id=