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=