Write wifidog settings on the authentication server router using php
Main settingsAuthentication server host name(Both the domain name and ip address can be used) andPath of the authentication server
The router requests the following addresses:
Http: // authentication server/path/login
Http: // authentication server/path/auth
Http: // authentication server/path/ping
Http: // authentication server/path/portal
Http: // authentication server/path/gw_message.php
Therefore, we need to create the next index. php folder for each request.
Prerequisites
When the client connects to wifi for the first time, the browser request will be redirected to login with parameters
Login /? Gw_address = vroip ip & gw_port = vrowwifidog Port & gw_id = user ID & url = address browsed by the user before being redirected
(In version 2013, the wifidog parameter is mac-less)
What login/index. php needs to do is to redirect to the gateway after the verification is passed:
Http: // gateway address: Gateway port/wifidog/auth? Token =
Then, wifidog starts a thread to periodically report the user status:
/Auth? Stage = & ip = & mac = & token = & incoming = & outgoing =
/Auth/index. php then needs to return whether to allow the user to continue accessing the Internet. reply format: Auth: Status Code (0: Rejected, 1: verified)
After the verification is successful, the router will request/portal /? Gw_id = % s
In/portal/index. php, you can write the url parameter redirected to the first request or redirect to the custom url.
/Ping/index. php indicates that the router authentication server has not crashed.
/Gw_message/index. php is used to display the error message when an error occurs during authentication.
Commencement
We will complete user account and password authentication
1. first, redirection. during the first login, the url accessed by the user will be redirected to the following address:
/Login/index. php
Query ("set names 'utf8 '"); $ result = $ db-> query ("SELECT * FROM user WHERE username = '{$ username}' AND password = '{$ password }'"); if ($ result & $ result-> num_rows! = 0) {// database verification succeeded $ token = ''; $ pattern =" 1234567890 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ "; for ($ I = 0; $ I <32; $ I ++) $ token. = $ pattern [rand ()]; // place the token to the database for subsequent verification (auth/index. php) $ time = time (); $ SQL = "UPDATE user SET token = '{$ token}', logintime = '{$ time }'"; $ db-> query ($ SQL); $ db-> close (); // log on to the page specified by route manager. $ url = "http: // {$ parseUrl ['gw _ address'] }:{ $ parseUrl ['gw _ port']}/wifidog/ Auth? Token = {$ token} "; header (" Location :". $ url);} else {// authentication failed // redirect requests on this page to get $ url = 'http ://'. $ _ SERVER ['server _ name']. $ _ SERVER ["REQUEST_URI"]; header ("Location :". $ url) ;}} else {// get request // A simple form page $ html = <EOD Portal login EOD; echo $ html ;}
2. user authentication protocol:
/Auth /? Stage = % s & ip = % s & mac = % s & token = % s & incoming = % s & outgoing = % s
Parameter description:
Stage: indicates the authentication stage, which is logoin and counters.
Token: the token issued by the login page.
Incoming: Download Traffic
Outgoing: upload traffic
/Auth/index. php
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 match, verification by echo "Auth: 1";} else {echo "Auth: 0 ";}
3. Ping protocol
/Ping /? Gw_id = % s & sys_uptime = % lu & sys_memfree = % u & sys_load = %. 2f & wifidog_uptime = % lu
The wifidog sends some information to the authentication server to report the current situation of the wifidog. The information is sent through the Http protocol. as shown in the above link, the parameter is probably literal, I have not studied it carefully. as an authentication server, auth_server should respond to a "Pong ".
The main function is to verify that the authentication server is still alive and does not crash. Another function is that the authentication server can collect routing load and other information. The vro periodically accesses this script. the script must reply to Pong. Otherwise, the authentication server becomes invalid and an error occurs.
/Ping/index. php
4. redirect after successful authentication
Portal /? Gw_id = % s
After successful authentication, wifidog redirects the user to this page.
/Portal/index. php
5. if verification fails, the following page is displayed based on the cause of failure:
Gw_message.php? Message = denied
Gw_message.php? Message = activate
Gw_message.php? Message = failed_validation
/Gw_message.php