分类 wifidog服务器 下的文章

asp.net MVC 使用wifidog 协议实现wifi认证

在网上看到的很多实现的wifidog 协议一般都是PHP 的,了解一下PHP 但是比较喜欢.net ,所以实现了简单的一个进行登录认证的功能

(好多协议中的功能目前没有实现)

  1. 开发环境(vs2010 )

  2. 路由(支持wifidog协议的 ddwrt )

  3. 环境的配置

    主要是进行路由的配置

    截图如下:
    1.jpg

2.jpg

注意红圈的部分这个我按照php 的配置

asp.net MVC 的配置如下:

端口 9999 authserver path /login/

  1. MVC 项目布局:
    3.jpg

loginController.cs 代码如下:

public class loginController : Controller
{
//
// GET: /login/

public ActionResult login()
{
string demo = Request.QueryString.ToString();
ViewData["demo"]=demo;
ViewData["gw_address"] = Request.QueryString["gw_address"];
ViewData["gw_port"] = Request.QueryString["gw_port"];
ViewData["gw_id"] = Request.QueryString["gw_id"];
//ViewData["url"]=Request.QueryString["url"];
string url = Request.QueryString["url"];
// string url = "www.cnblogs.com";

ViewData["url"] = url;
Response.Write("Auth:1");
return View();
}

public ActionResult index()
{
return View();
}

public ActionResult auth()
{
// result data = new result();

Response.Write("Auth:1");
return View();


}
public ActionResult MyLogin()
{

return View();
}
}

代码写的比较乱,但是还是比较简单的。

login view 的代码如下:

<%
Label1.Text = ViewData["demo"].ToString() + "<br/>" ;

if (ViewData["url"] == null)
{

}
else
{
string a = ViewData["gw_address"].ToString();
string p = ViewData["gw_port"].ToString();
string token = Guid.NewGuid().ToString();
string url=ViewData["url"].ToString();
string demo = "http://" + a + ":" + p + "/wifidog/auth?token=" + token + "url=" + url;

ViewData["authurl"] = demo;
Application["authurl"] = demo;
}

%>

dalong demo app
</h2>
<p>


<h1>
登陆页面
</h1>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</p>

[ <%: Html.ActionLink("进入", "MyLogin", "login")%> ]

Mylogin view 的代码如下:

<%

string tepdemo = "Auth: 1";
byte[] data = System.Text.Encoding.Default.GetBytes(tepdemo);
char[] list = System.Text.Encoding.Default.GetChars(data);
Response.Write(list, 0, list.Length);
Response.Redirect(Application["authurl"].ToString());
%>
  1. 手机端的测试效果:
    4.jpg

window phone 连接wifi 的显示界面

点击进入如下效果:
5.png

连接成功标志:

打开网页:
6.png

其中对于认证最重要的是按照协议返回的数据:

比如我通过返回的数据:

Auth: 1

拒绝为: Auth: 0

以上只是简单的测试,实际应用需要很多的东西。

本文章由 http://www.wifidog.pro/2015/02/06/asp-wifidog.html整理编辑,转载请注明出处

Wifidog鉴权服务器wifidog-auth的搭建

原来已经配置好的apache2、python、trac系统
在/etc/apache2/sites-enabled下增加的新的配置文件(域名和对应的目录)

sudo /etc/init.d/apache2 restart

这是可以用新域名访问对应目录下index.php了,但无法执行php代码只能下载该文件

sudo apt-get install php5
sudo apt-get install libapache2-mod-php5 # 安装遇到麻烦
sudo apt-get install postgresql
sudo apt-get install php5-cgi php5-common php5-pgsql php-pear php5-xmlrpc php5-curl language-pack-en-base subversion
sudo pear install XML_RPC
wget http://sourceforge.net/projects/phlickr/files/Phlickr-0.2.5.tgz
sudo pear install Phlickr-0.2.5.tgz
sudo apt-get install openssh-server
sudo apt-get install postfix
选择"internet site with smart host",然后配置

svn checkout https:// dev.wifidog.org/svn/trunk/wifidog-auth #放到/var/www目录下

现在修改文件/var/www/wifidog-auth/wifidog/classes/Dependency.php,否则智能安装会失败
$sudo vim /var/www/wifidog-auth/wifidog/classes/Dependency.php
将第122行改为:'website' => "http://www.smarty.net/" 
将第123行改为:'installSourceUrl' => http://www.smarty.net/files/Smarty-2.6.26.tar.gz

$sudo vim /var/www/wifidog-auth/wifidog/config.php
将define('DEFAULT_LANG', 'fr_CA');改为define('DEFAULT_LANG', 'en_US');

本文章由 http://www.wifidog.pro/2015/02/06/wifidog-auth.html 整理编辑,转载请注明出处

WifiDog 认证协议研究之 Auth Server

认证流程如下图:
wifidog-flow-2009.png

认证流程详解:
1.Login登录(参照 login/index.php)
服务器验证后,Redirect to GW,携带 token
http://$_REQUEST[gw_address]:$_REQUEST[gw_port]/wifidog/auth?token=$token
2.Validation of ID
服务器返回 Status
Auth: 1
Messages: | 认证信息(如错误之类的消息)
common.php中有如下定义:
/* Constant shared with the gateway

  • NEVER edit these, as they mush match the C code of the gateway */
    define('ACCOUNT_STATUS_ERROR', -1);
    define('ACCOUNT_STATUS_DENIED', 0);
    define('ACCOUNT_STATUS_ALLOWED', 1);
    define('ACCOUNT_STATUS_VALIDATION', 5);
    define('ACCOUNT_STATUS_VALIDATION_FAILED', 6);
    define('ACCOUNT_STATUS_LOCKED', 254);

auth.h中也有相应定义:

/** 
 * @brief Authentication codes returned by auth server. 
 * 
 * Authentication result codes returned by auth_server_request() corresponding 
 * to result code from the central server itself. 
 */  
typedef enum {  
    AUTH_ERROR = -1, /**< An error occured during the validation process*/  
    AUTH_DENIED = 0, /**< Client was denied by the auth server */  
    AUTH_ALLOWED = 1, /**< Client was granted access by the auth server */  
    AUTH_VALIDATION = 5, /**< A misnomer.  Client is in 15 min probation to validate his new account */  
    AUTH_VALIDATION_FAILED = 6, /**< Client had X minutes to validate account by email and didn't = too late */  
    AUTH_LOCKED = 254 /**< Account has been locked */  
} t_authcode; 

本文章由 http://www.wifidog.pro/2015/01/29/wifidog-authserver.html 整理编辑,转载请注明出处

wifidog 认证 php

1.首先简单说说wifidog认证的过程

客户端首次连接到wifi后,浏览器请求将会被重定向到:

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

验证通过后,客户端被重定向到网关,url格式如下:

http://网关地址:网关端口/wifidog/auth?token=

wifidong会启动一个线程周期性地报告每一个用户的状态信息,并通过如下地址发送给认证

服务器:

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

认证服务器根据该状态信息决定是否允许该用户继续连接,并回复网关,回复格式为:Auth:状态码,

如:Auth:1

常用状态码:

0:AUTH_DENIED,表示拒绝

1:AUTH_ALLOWED,验证通过

验证通过后,将重定向到如下地址:

portal/?gw_id=%s

wifidog的ping协议

wifidog通过ping协议将当前状态信息发送给认证服务器,发送地址为:

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

认证服务器须返回一个“Pong”作为回应。

2.具体php实现代码如下

<pre code_snippet_id="335795" snippet_file_name="blog_20140509_1_6007550" name="code">public function auth()  
    {  
    <span style="white-space:pre">  </span>//响应客户端的定时认证,可在此处做各种统计、<a title="计费" href="index.php?c=search&amp;key=%E8%AE%A1%E8%B4%B9" target="_blank">计费</a>等等  
    <span style="white-space:pre">  </span>/*  
    <span style="white-space:pre">      </span>wifidog 会通过这个接口传递连接客户端的信息,然后根据返回,对客户端做<a title="开通" href="index.php?c=search&amp;key=%E5%BC%80%E9%80%9A" target="_blank">开通</a>、断开等处理,具体返回值可以看wifidog的文档  
    <span style="white-space:pre">  </span>wifidog主要提交如下参数  
    <span style="white-space:pre">  </span>1.ip  
    <span style="white-space:pre">  </span>2. mac  
    <span style="white-space:pre">  </span>3. token(login页面<a title="下发" href="index.php?c=search&amp;key=%E4%B8%8B%E5%8F%91" target="_blank">下发</a>的token)  
    <span style="white-space:pre">  </span>4.incoming 下载流量  
    <span style="white-space:pre">  </span>5.outgoing 上传流量  
    <span style="white-space:pre">  </span>6.stage  认证阶段,就两种 login 和 counters  
    <span style="white-space:pre">  </span>*/  


    <span style="white-space:pre">  </span>$stage = $_GET['stage'] == 'counters'?'counters':'login';  
    <span style="white-space:pre">  </span>if($stage == 'login')  
    <span style="white-space:pre">  </span>{  
    <span style="white-space:pre">      </span>//XXXX跳过login 阶段的处理XXXX不能随便跳过的  
    <span style="white-space:pre">      </span>//默认返回 允许  
    <span style="white-space:pre">      </span>echo "Auth: 1";  
    <span style="white-space:pre">  </span>}  
    <span style="white-space:pre">  </span>else if($stage == 'counters')  
    <span style="white-space:pre">  </span>{  

    <span style="white-space:pre">      </span>//做一个简单的流量判断验证,下载流量超值时,返回<a title="下线" href="index.php?c=search&amp;key=%E4%B8%8B%E7%BA%BF" target="_blank">下线</a>通知,否则保持在线  
    <span style="white-space:pre">      </span>if(!empty($_GET['incoming']) and $_GET['incoming'] &gt; 10000000)  
    <span style="white-space:pre">      </span>{  
    <span style="white-space:pre">          </span>echo "Auth: 0";  
    <span style="white-space:pre">      </span>}else{  
    <span style="white-space:pre">          </span>echo "Auth: 1\n";  
    <span style="white-space:pre">      </span>}  
    <span style="white-space:pre">  </span>}  
    <span style="white-space:pre">  </span>else  
    <span style="white-space:pre">      </span>echo "Auth: 0"; //其他情况都返回拒绝  
    <span style="white-space:pre">      </span>  
    <span style="white-space:pre">      </span> <span style="white-space:pre">  </span>  
    <span style="white-space:pre">  </span>/*  
    <span style="white-space:pre">      </span>返回值:主要有这两种就够了  
    <span style="white-space:pre">  </span>0 - 拒绝  
    <span style="white-space:pre">  </span>1 - <a title="放行" href="index.php?c=search&amp;key=%E6%94%BE%E8%A1%8C" target="_blank">放行</a>  

    <span style="white-space:pre">  </span>官方文档如下  
    <span style="white-space:pre">  </span>0 - AUTH_DENIED - User firewall users are deleted and the user removed.  
    <span style="white-space:pre">  </span>6 - AUTH_VALIDATION_FAILED - User email validation timeout has occured and user/firewall is deleted(用户邮件验证超时,防火墙关闭该用户)  
    <span style="white-space:pre">  </span>1 - AUTH_ALLOWED - User was valid, add firewall rules if not present  
    <span style="white-space:pre">  </span>5 - AUTH_VALIDATION - Permit user access to email to get validation email under default rules (用户邮件验证时,向用户开放email)  
    <span style="white-space:pre">  </span>-1 - AUTH_ERROR - An error occurred during the validation process  
    <span style="white-space:pre">  </span>*/  
    }  
    public function portal()  
    {  
    <span style="white-space:pre">  </span>/*  
    <span style="white-space:pre">  </span> wifidog 带过来的参数 如下  
    <span style="white-space:pre">  </span>1. gw_id  
    <span style="white-space:pre">  </span>*/  
    <span style="white-space:pre">  </span>//重定到指定网站 或者 显示splash广告页面  
    <span style="white-space:pre">  </span>redirect('http://www.baidu.com', 'location', 302);  
    <span style="white-space:pre">      </span>  
    }  
    public function ping()  
    {  
    <span style="white-space:pre">  </span>//url请求 "gw_id=$gw_id&amp;sys_uptime=$sys_uptime&amp;sys_memfree=$sys_memfree&amp;sys_load=$sys_load&amp;wifidog_uptime=$wifidog_uptime";  
    <span style="white-space:pre">  </span>//log_message($this-&gt;config-&gt;item('MY_log_threshold'), __CLASS__.':'.__FUNCTION__.':'.debug_printarray($_GET));  

    <span style="white-space:pre">  </span>//判断各种参数是否为空  
    <span style="white-space:pre">  </span>if( !(isset($_GET['gw_id']) and isset($_GET['sys_uptime']) and isset($_GET['sys_memfree']) and isset($_GET['sys_load']) and isset($_GET['wifidog_uptime']) ) )  
    <span style="white-space:pre">  </span>{  
    <span style="white-space:pre">      </span>echo '{"error":"2"}';  
    <span style="white-space:pre">      </span>return;  
    <span style="white-space:pre">  </span>}  
    <span style="white-space:pre">  </span>//添加<a title="心跳" href="index.php?c=search&amp;key=%E5%BF%83%E8%B7%B3" target="_blank">心跳</a>日志处理功能  
    <span style="white-space:pre">  </span>/*  
    <span style="white-space:pre">      </span>此处可获取 wififog提供的 如下参数  
    <span style="white-space:pre">  </span>1.gw_id  来自wifidog 配置文件中,用来区分不同的路由设备  
    <span style="white-space:pre">  </span>2.sys_uptime 路由器的系统启动时间  
    <span style="white-space:pre">  </span>3.sys_memfree 系统内存使用百分比  
    <span style="white-space:pre">  </span>4.wifidog_uptime wifidog持续运行时间(这个数据经常会有问题)  
    <span style="white-space:pre">  </span>*/  

    <span style="white-space:pre">  </span>//返回值  
    <span style="white-space:pre">  </span>echo 'Pong';  
    }  
    /**  
     * wifidog 的gw_message 接口,信息提示页面  
     */  
    function gw_message()  
    {  
    <span style="white-space:pre">  </span>if (isset($_REQUEST["message"])) {  
    <span style="white-space:pre">      </span>switch ($_REQUEST["message"]) {  
    <span style="white-space:pre">          </span>case 'failed_validation':  
    <span style="white-space:pre">              </span>//auth的stage为login时,被服务器返回AUTH_VALIDATION_FAILED时,<a title="来到" href="index.php?c=search&amp;key=%E6%9D%A5%E5%88%B0" target="_blank">来到</a><a title="该处" href="index.php?c=search&amp;key=%E8%AF%A5%E5%A4%84" target="_blank">该处</a>处理  
    <span style="white-space:pre">              </span>//认证失败,请重新认证  
    <span style="white-space:pre">              </span>break;  
    <span style="white-space:pre">          </span>case 'denied':  
    <span style="white-space:pre">              </span>//auth的stage为login时,被服务器返回AUTH_DENIED时,来到该处处理  
    <span style="white-space:pre">              </span>//认证被拒  
    <span style="white-space:pre">              </span>break;  
    <span style="white-space:pre">          </span>case 'activate':  
    <span style="white-space:pre">              </span>//auth的stage为login时,被服务器返回AUTH_VALIDATION时,来到该处处理  
    <span style="white-space:pre">              </span>//待激活  
    <span style="white-space:pre">              </span>break;  
    <span style="white-space:pre">          </span>default:  
    <span style="white-space:pre">              </span>break;  
    <span style="white-space:pre">      </span>}  
    <span style="white-space:pre">  </span>}else{  
    <span style="white-space:pre">      </span>//不回显任何信息  
    <span style="white-space:pre">  </span>}  
    }</pre>  
</p>  

本文章由 http://www.wifidog.pro/2015/01/28/wifidog-php-1.html 整理编辑,转载请注明出处