路由器上wifidog的设置
主要设置鉴权服务器主机名(域名或ip都可以)和加粗鉴权服务器路径
路由器会请求以下四个地址:
http://认证服务器/路径/login
http://认证服务器/路径/auth
http://认证服务器/路径/ping
http://认证服务器/路径/portal
http://认证服务器/路径/gw_message.php
所以我们需要每个请求建立一个文件夹下一个index.php
预备知识
客户端首次连接wifi,浏览器请求将被重定向到login并携带参数
login/?gw_address=路由器ip&gw_port=路由器wifidog的端口&gw_id=用户id&url=被重定向前用户浏览的地址
(2013版本的wifidog参数多了mac)
而login/index.php需要做的就是验证通过后再重定向到网关:
http://网关地址:网关端口/wifidog/auth?token=
之后wifidog会启动一个线程周期性报告用户状态:
/auth?stage=&ip=&mac=&token=&incoming=&outgoing=
/auth/index.php则需要返回是否让该用户继续上网,回复格式:Auth:状态码(0:拒绝, 1:验证通过)
验证成功后,路由器将请求/portal/?gw_id=%s
在/portal/index.php就可以写重定向到第一次请求的url参数或者重定向到自定义网址了
/ping/index.php的作用就是告诉路由器认证服务器还没有崩
/gw_message/index.php作用是当认证过程出现错误的时候,想用户显示错误信息
开工
我们将完成用户用账号密码方式认证
1.首先是重定向,在首次登陆时,用户访问的url会被重定向到如下的地址:
/login/index.php
<?php//获取url传递过来的参数parse_str($_SERVER['QUERY_STRING'], $parseUrl);//gw_address、gw_port、gw_id是必需参数,缺少不能认证成功.if( !array_key_exists('gw_address', $parseUrl) || !array_key_exists('gw_port', $parseUrl) || !array_key_exists('gw_id', $parseUrl)){ exit;}//如果提交了账号密码if(isset($_POST['name']) && isset($_POST['password'])){ $username = $_POST['name']; $password = $_POST['password']; $db = new mysqli('localhost', 'root', '', 'test'); if(mysqli_connect_errno()){ echo mysqli_connect_error(); die; } $db->query("set names 'utf8'"); $result = $db->query("SELECT * FROM user WHERE username='{$username}' AND password='{$password}'"); if($result && $result->num_rows != 0){ //数据库验证成功 $token = ''; $pattern="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ"; for($i=0;$i<32;$i++) $token .= $pattern[ rand(0,35) ]; //把token放到数据库,用于后续验证(auth/index.php) $time = time(); $sql = "UPDATE user SET token='{$token}',logintime='{$time}'"; $db->query($sql); $db->close(); //登陆成功,跳转到路由网管指定的页面. $url = "http://{$parseUrl['gw_address']}:{$parseUrl['gw_port']}/wifidog/auth?token={$token}"; header("Location: ".$url); }else{ //认证失败 //直接重定向本页 请求变成get $url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]; header("Location: ".$url); }}else{ //get请求 //一个简单的表单页面 $html = <<< EOD <html> <head> <title>portal login</title> </head> <body> <form action="#" method="post"> username:<input type="text" name="username" /> password:<input type="password" name="password" /> <input type="submit" value="submit" /> </form> </body> </html>EOD; echo $html;}
2.用户认证协议:
/auth/?stage=%s&ip=%s&mac=%s&token=%s&incoming=%s&outgoing=%s
参数解释:
stage: 认证阶段,就logoin和counters两种
token: login页面下发的token
incoming: 下载流量
outgoing: 上传流量
/auth/index.php
<?php//获取url传递过来的参数parse_str($_SERVER['QUERY_STRING'], $parseUrl);//需要多少参数用户可自己顶if( !array_key_exists('token', $parseUrl) ){ //拒绝 echo "Auth:0"; exit;}$db = new mysqli('localhost', 'root', '', 'test');$db->query("set names 'utf8'");$token = $parseUrl['token'];$sql = "SELECT * FROM user WHERE token='{$token}'";$result = $db->query($sql);if($result && $result->num_rows != 0){ //token匹配,验证通过 echo "Auth:1";}else{ echo "Auth:0";}
3.Ping协议
/ping/?gw_id=%s&sys_uptime=%lu&sys_memfree=%u&sys_load=%.2f&wifidog_uptime=%lu
wifidog会向认证服务器发送一些信息,来报告wifidog现在的情况,这些信息是通过Http协议发送的,如上的链接所示,参数大概如字面意思,没仔细研究过,而作为认证服务器,auth_server应回应一个"Pong"。
主要作用是路由确认认证服务器仍然存活,没有死机,另外一个功能是认证服务器可以收集路由的负载等的信息。路由器会定时访问这个脚本,脚本必须回复Pong,否则将认为认证服务器失效而出错。
/ping/index.php
<?phpecho "Pong";?>
4.认证成功后的跳转
portal/?gw_id=%s
在认证成功后,wifidog会将用户重定向至该页面。
/portal/index.php
<?php//认证前用户访问任意url,然后被重定向登录页面,session记录的是这个“任意url”.$url = $_SESSION["url"];//如果login参数url保存到session中//跳转到登陆前页面.header("Location: ".$url);
5.若验证失败,则会根据失败原因跳转至如下页面
gw_message.php?message=denied
gw_message.php?message=activate
gw_message.php?message=failed_validation
/gw_message.php
<?php $message = null; if(isset($_GET["message"])){ $message = $_GET["message"]; } echo $message;?>

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor
