修改/etc/wifidog.conf, 只需要修改文件的前半部分, 其他都保持默認
GatewayID default GatewayInterface br-lan GatewayAddress 192.168.1.1 AuthServer { Hostname auth.mydomain.com SSLAvailable no HTTPPort 80 Path /wifidog/ LoginScriptPathFragment login.php? PortalScriptPathFragment portal.php? MsgScriptPathFragment message.php? PingScriptPathFragment ping.php? AuthScriptPathFragment auth.php? }
其中
GatewayAddress wifidog所在路由的網關IP
Hostname: 提供驗證服務的服務器
SSLAvailable, HTTPPort, Path 分別是驗證服務對應的 是否可用https, 訪問端口, 路徑. 路徑必須前后帶'/'(如果是根目錄則只有'/')
LoginScriptPathFragment 和上面的Path聯合后得到的登錄頁地址
PortalScriptPathFragment 驗證成功后的頁面地址
MsgScriptPathFragment 消息頁地址
PingScriptPathFragment 必須返回 Pong --- 注意大小寫一致
AuthScriptPathFragment 返回 Auth: 1 或 Auth: 0 代表驗證通過/不通過
使用以下命令在前台啟用wifidog, 可以看到詳細的日志輸出
wifidog -f
用戶的訪問順序:
1. wifidog啟動后, 會主動訪問驗證服務器
GET /wifidog/ping.php?gw_id=default&sys_uptime=11865&sys_memfree=70304&sys_load=0.77&wifidog_uptime=242 HTTP/1.0" 200 5 "-" "WiFiDog 1.3.0"
2. 用戶連接wifi后, 會被引導至登錄頁
GET /wifidog/login.php?gw_address=192.168.1.1&gw_port=2060&gw_id=default&ip=192.168.1.110&mac=10:0b:a9:a6:bb:ac&url=http%3A%2F%2Fwww.bt.net%2Fframes.do HTTP/1.1
3. 用戶登錄成功后, 會返回wifidog的驗證頁, 其域名, 端口來自於前面的參數, 而/wifidog/auth?token= 這個是固定的
http://192.168.1.1:2060/wifidog/auth?token=128273kisdud71oidj12
4. wifidog會拿token去驗證服務器驗證
GET /wifidog/auth.php?stage=login&ip=192.168.1.110&mac=10:0b:a9:a6:bb:ac&token=1484935173&incoming=0&outgoing=0&gw_id=default HTTP/1.0" 200 8 "-" "WiFiDog 1.3.0"
5. 驗證通過后, 用戶瀏覽器再跳往 PortalScriptPathFragment 指定的地址
6. wifidog會定時去驗證服務器驗證訪問有效性
GET /wifidog/auth.php?stage=counters&ip=192.168.1.110&mac=10:0b:a9:a6:bb:ac&token=1484935173&incoming=65954&outgoing=37750&gw_id=default HTTP/1.0" 200 8 "-" "WiFiDog 1.3.0"
一個登錄頁的例子
<html> <head> <title>Login with Your Account</title> </head> <body> <h2>Login</h2> <?php if (isset($_POST['user_name']) && isset($_POST['password'])) { $user_name = $_POST['user_name']; $password = $_POST['password']; if ($user_name == 'milton' && $password == '123123') { $location = 'Location: http://' . $_POST['gw_address'] . ':' . $_POST['gw_port'] .'/wifidog/auth?token='.time(); echo $location; header($location); } else { echo '<h1>Incorrect login.</h1><br>'; } } ?> <form action="login.php" method="post"> Username:<input type="text" name="user_name"/><br> Password:<input type="password" name="password"/><br> <?php echo '<input type="hidden" name="gw_address" value="'. $_GET['gw_address'] . '"><br>'; echo '<input type="hidden" name="gw_port" value="'. $_GET['gw_port'] . '">'; ?> <input type="submit"> <pre> <?php var_dump($_GET);?> </pre> </body> </html>