分类 wifidog分析 下的文章

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”作为回应。
具体php实现代码如下

public function auth()
    {
        //响应客户端的定时认证,可在此处做各种统计、计费等等
        /*
            wifidog 会通过这个接口传递连接客户端的信息,然后根据返回,对客户端做开通、断开等处理,具体返回值可以看wifidog的文档
        wifidog主要提交如下参数
        1.ip
        2. mac
        3. token(login页面下发的token)
        4.incoming 下载流量
        5.outgoing 上传流量
        6.stage  认证阶段,就两种 login 和 counters
        */


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

            //做一个简单的流量判断验证,下载流量超值时,返回下线通知,否则保持在线
            if(!empty($_GET['incoming']) and $_GET['incoming'] > 10000000)
            {
                echo "Auth: 0";
            }else{
                echo "Auth: 1\n";
            }
        }
        else
            echo "Auth: 0"; //其他情况都返回拒绝


        /*
            返回值:主要有这两种就够了
        0 - 拒绝
        1 - 放行

        官方文档如下
        0 - AUTH_DENIED - User firewall users are deleted and the user removed.
        6 - AUTH_VALIDATION_FAILED - User email validation timeout has occured and user/firewall is deleted(用户邮件验证超时,防火墙关闭该用户)
        1 - AUTH_ALLOWED - User was valid, add firewall rules if not present
        5 - AUTH_VALIDATION - Permit user access to email to get validation email under default rules (用户邮件验证时,向用户开放email)
        -1 - AUTH_ERROR - An error occurred during the validation process
        */
    }
    public function portal()
    {
        /*
         wifidog 带过来的参数 如下
        1. gw_id
        */
        //重定到指定网站 或者 显示splash广告页面
        redirect('http://www.baidu.com', 'location', 302);

    }
    public function ping()
    {
        //url请求 "gw_id=$gw_id&sys_uptime=$sys_uptime&sys_memfree=$sys_memfree&sys_load=$sys_load&wifidog_uptime=$wifidog_uptime";
        //log_message($this->config->item('MY_log_threshold'), __CLASS__.':'.__FUNCTION__.':'.debug_printarray($_GET));

        //判断各种参数是否为空
        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']) ) )
        {
            echo '{"error":"2"}';
            return;
        }
        //添加心跳日志处理功能
        /*
            此处可获取 wififog提供的 如下参数
        1.gw_id  来自wifidog 配置文件中,用来区分不同的路由设备
        2.sys_uptime 路由器的系统启动时间
        3.sys_memfree 系统内存使用百分比
        4.wifidog_uptime wifidog持续运行时间(这个数据经常会有问题)
        */

        //返回值
        echo 'Pong';
    }
    /**
     * wifidog 的gw_message 接口,信息提示页面
     */
    function gw_message()
    {
        if (isset($_REQUEST["message"])) {
            switch ($_REQUEST["message"]) {
                case 'failed_validation':
                    //auth的stage为login时,被服务器返回AUTH_VALIDATION_FAILED时,来到该处处理
                    //认证失败,请重新认证
                    break;
                case 'denied':
                    //auth的stage为login时,被服务器返回AUTH_DENIED时,来到该处处理
                    //认证被拒
                    break;
                case 'activate':
                    //auth的stage为login时,被服务器返回AUTH_VALIDATION时,来到该处处理
                    //待激活
                    break;
                default:
                    break;
            }
        }else{
            //不回显任何信息
        }
    }

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

wifidog安装Oauth login for Google and Facebook on OpenWrt routers

Oauth for OpenWrt routers aims to support authentication via OAuth services (Google, Facebook...) and run on the same box with WifiDog. It is using Luci and provides an alternative to single Auth Server for WifiDog. There is no need to setup a separated machine for authentication.

How does it work?

When a new guest uses Wifi from a router to go to the Internet, he/she will be presented a login page where he/she can use his Facebook or Google accounts to log in order to have permission of using our Wifi to access the Internet. When the session of using the Internet is over, a page with a message informing that the user is unauthenticated is displayed, and he/she is withdrawn the Internet access permission. This means he/she must be login again to have the permission.

System requirements

The followings are all you need to successfully deploy Oauth for OpenWrt:

  • OpenWrt firmware.
  • LuCi package.
  • Wifidog package.
  • Standard wget package.
  • Oauth for OpenWrt package.

a. Install Wifidog package:

  • Connect with your router via SSH.
  • Use this command to install Wifidog: opkg install wifidog.

Note: if you can not install wifidog, let's first use this command: “opkg update”, and then install it again.

b. Modify Wifidog's configuration file:

The configuration file of Wifidog is in /etc/wifidog.conf.

  • Use this command to access the file: vi /etc/wifidog.conf.
  • There are some parameters that you need to alter, according to your
    system: + ExternalInterface. + GatewayInterface. + GatewayAddress
    (your router) + AuthServer (your router) + GatewayPort.

c. Install Oauth for OpenWrt package:

We provide an ipk package to easily install via opkg.

You can also build your own from source (https://github.com/hongquan/Oauth for OpenWrt):

  • Copy the source folder to openwrt/package (source tree).
  • Rename Makefile_build_standalone to Makefile (replace the old
    Makefile).
  • Rename "dist" folder to "root" Choose the luci-app-Oauth for OpenWrt
    in"make menuconfig".
  • Run "make package/luci-app-Oauth for OpenWrt/compile V=99" to build.

After finishing the whole things above, let's do some more steps following to make Oauth for OpenWrt works:

  • In Terminal, connect to your router via SSH.
  • Run wifidog via this command: “/etc/init.d/wifidog start” (or
    “wifidog -d 7 -f” to see log information)
  • On your web browser, access your router via its IP address. After
    logging in, select tab “Network/Oauth for OpenWrt/Status”. Then,
    press “Apply” button.

Oauth for OpenWrt is now ready to work.

Configure Oauth for OpenWrt

We have created some nice stuffs for you to make Oauth for OpenWrt work as you like. First of all, you need to access the admin page of router by typing the your router address. There are some options that you can choose to bend the Oauth for OpenWrt with your needs.

本文章由 http://www.wifidog.pro/2015/04/07/wifidog%E5%AE%89%E8%A3%85%E6%8E%88%E6%9D%83.html 整理编辑,转载请注明出处

wifidog认证实现OpenWRT强制认证的WIFI热点

首先安装wifidog到OpenWRT的路由器:

  opkg update

  opkg install wifidog

wifidog依赖下面这些模块:

iptables-mod-extra

iptables-mod-ipopt

kmod-ipt-nat

iptables-mod-nat-extra

libpthread

由于trunk的固件更新会比较频繁,会导致直接opkg install wifidog安装不了,如果你凑巧又没有备份与固件对应的Packages的话,就需要到http://downloads.openwrt.org/snapshots/trunk升级固件,然后再安装wifidog。

如果你的路由器不是openwrt官方支持的版本的话,那就需要自己编译固件。make menuconfig后,在Network–>Captive Portals中选择wifidog.

安装完成后,

/etc/init.d/wifidog enable
/etc/init.d/wifidog start

这时会抛出一个错误,因为我们还没有设置AuthServer的信息。关于安装wifidog更多的信息可以参考:http://wiki.openwrt.org/doc/howto/wireless.hotspot.wifidog

下面安装Auth Server,按照官方的说法:
AuthPuppy is the next generation authentication server for Wifidog networks.
源文档 http://www.authpuppy.org/
不过貌似这wifidog和Authpuppy都已经N久没更新了。。。

AuthPutty是需要安装apache2, php5和MySQL。详细介绍在这里:http://www.authpuppy.org/doc/Getting_Started (Windows版点这里)。

安装成功后,访问AuthPuppy会要求设置一些数据库信息,全部设置完成后能看到首页:
wifidog2.jpg

当然了,我们还需要设置管理员的账号。

进入Manage plugins,Install apAuthLocalUserPlugin,记得要enable这个插件。

然后,点击Manage Nodes,把默认节点的status改成deployed。这个GW(Gateway) ID default后面配置wifidog.conf的时候需要使用。
wifidog4.png

到这里,AuthPuppy就基本配置完毕了。

下面回到路由器,编辑wifidog.conf,一般情况下,我们之后配置ExternalInterface,GatewayInterface和AuthServer这三项就可以,其他默认。下面是我的配置:

GatewayIDdefault           #注意这个ID必须跟AuthPuppy的GW ID一致

# Parameter: ExternalInterface

# Default: NONE

# Optional

#

# Set this to the external interface (the one going out to the Inernet or your larger LAN).

# Typically vlan1 for OpenWrt, and eth0 or ppp0 otherwise,

# Normally autodetected

ExternalInterface eth0      #路由器外网的物理接口



# Parameter: GatewayInterface

# Default: NONE

# Mandatory

#

# Set this to the internal interface (typically your wifi interface).

# Typically br-lan for OpenWrt, and eth1, wlan0, ath0, etc. otherwise

GatewayInterface wlan0      #路由器内网的物理接口

AuthServer {

    Hostname 192.170.1.104

    SSLAvailable no

    Path /

}



CheckInterval 60

ClientTimeout 5

FirewallRuleSet global {

}

FirewallRuleSet validating-users {

    FirewallRule allow to 0.0.0.0/0

}

FirewallRuleSet known-users {

    FirewallRule allow to 0.0.0.0/0

}

FirewallRuleSet unknown-users {

    FirewallRule allow udp port 53

    FirewallRule allow tcp port 53

    FirewallRule allow udp port 67

    FirewallRule allow tcp port 67

}

FirewallRuleSet locked-users {

    FirewallRule block to 0.0.0.0/0

}

注意这个Interface是物理接口。

root@OpenWrt:~# cat /etc/config/network

config interface ‘loopback’

        option ifname ‘lo’

        option proto ‘static’

        option ipaddr ‘127.0.0.1’

        option netmask ‘255.0.0.0’

config globals ‘globals’

        option ula_prefix ‘fd09:fd03:490d::/48′

config interface ‘lan’

        option proto ‘static’

        option ipaddr ‘192.168.1.1’

        option netmask ‘255.255.255.0’

        option ip6assign ’60’

        option _orig_ifname ‘eth0′

        option _orig_bridge ‘false’

config interface ‘WAN’

        option proto ‘dhcp’

        option _orig_ifname ‘gretap0′

        option _orig_bridge ‘false’

        option ifname ‘eth0′

本文章由 http://www.wifidog.pro/2015/04/07/wifidog%E8%AE%A4%E8%AF%81wifi%E7%83%AD%E7%82%B9.html 整理编辑,转载请注明出处

wifidog认证无线认证管理

在网上了解到,许多实现无线或者有线Web验证的方案都用到 WiFi无线热点管理系统
目前比较主流的有:ros wiwiz 海蜘蛛这几个。ROS全称RouterOS软路由,最强大,但是比较复杂,海蜘蛛很容易,但效果一般般,WiWiZ实现一般,效果比较好,目前大部分研究的是wiwiz.为什么选择Wiwiz?并不是因为多人选我们就根从,而是因为它适合我们。

Wiwiz是一个开发式的系统,、装配置灵活,可以安装到路由器或者本地计算机、虚拟机都可以。通过Wiwiz Web控制面板创建并定制自己的热点。包括认证方式、是否付费及费率、认证页面的外观样式、颜色、图片以及服务条款都可以进行定制。为用户有偿提供网络服务。

Wiwiz系统,全称Wiwiz HotSpot Builder,一个WiFi无线热点管理系统,也可用于有线,
创建强制门户/认证页面。
Wiwiz HotSpot Builder的组成:
1、Wiwiz Web控制面板
2、客户端-Wiwiz HotSpot Builder Utility
部署了Wiwiz系统的计算机、路由器或者无线路由器充当WIFI网中的Internet网关。
可以实现Web认证。市面上创建商用Wifi热点的做法一般都是用强制网络门户系统(Captive Portal)/热点管理系统
来实现的。他们的原理都类似,需要一个防火墙/网关系统,一个用于认证管理和控制的后台系统。
常见的技术解决方案有NoCat、Wifidog、Chillispot等。有一些整套的解决方案,FON、Wiwiz、
ile sans fil、Sputnik、FreeSpot,这些要money的哦。wifidog 是免费开源的解决方案,只是性能不是很好,用于一般环境是足够的。

本文章由http://www.wifidog.pro/2015/04/07/wifidog%E8%AE%A4%E8%AF%81-5.html 整理编辑,转载请注明出处