佐须之男 发布的文章

OpenWrt wifidog 实现收费提醒效果

需求场景

有一个免认证的 Wifi SSID,比如叫:OpenWrt,附近的同学可以随便连上这个 SSID,没有缴过费的同学不管访问什么地址,都会被跳转到收费提醒页面,而缴过费的同学就可以开心上网了。

解决办法

从需求上来说,这是一个非常标准的 WifiDog 效果,如果未来有很复杂的需求,可以直接通过 WifiDog 来实现跳转,然后再通过 AuthPuppy 来实现账户管理,不过想在 OpenWrt 上同时部署 WifiDog 与 AuthPuppy 也不是一件很容易的事情。

因此我们准备考虑直接通过 iptables 来实现这个需求,未来如果有复杂的扩展需求,也不影响扩展到 WifiDog 来实现。

实现流程

通过 SSH 登录到 OpenWrt,打开 /etc/config/uhttpd,在文件的最顶部增加以下配置

config uhttpd 'portal'
list listen_http '0.0.0.0:11990'
option home '/www/portal'
option error_page '/index.html'

然后在 /www/portal 下新建一个名为 index.html 的静态文件,文件内容可以如下

<html>
<head>
  <meta http-equiv="cache-control" content="no-cache">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Wifi</title>
</head>
<body>
  Email: xxxx@xxx.com
</bodu>
</html>

之后再打开 /etc/firewall.user 文件,在末尾添加如下配置:

iptables -t nat -A prerouting_lan_rule -p tcp -m tcp --dport 80 -m mark ! --mark 8 -j REDIRECT --to-ports 11990
iptables -t filter -A forwarding_lan_rule -m mark ! --mark 8 -j REJECT

保存后执行 /etc/init.d/firewall restart 重新载入 iptables 的配置
然后再执行 /etc/init.d/uhttpd restart 重新载入 uhttpd 的配置

然后用手机连接这个无线网络,你就会发现总是弹出这个提示页面了

用户授权

当有用户缴费了之后,向他要到他的MAC地址,同样打开 /etc/firewall.user 文件,比如这个用户有 2 个设备,MAC 地址分别是 00:00:00:00:BB:AA 与 00:00:00:00:BB:BB 则添加以下 2 条 规则,以后这 2 个设备就可以随便上网了!

iptables -t mangle -A fwmark -m mac --mac-source 00:00:00:00:BB:AA -j MARK --set-mark 8
iptables -t mangle -A fwmark -m mac --mac-source 00:00:00:00:BB:BB -j MARK --set-mark 8

添加后同样需要执行 /etc/init.d/firewall restart 以使配置生效

注意事项

如果通过以太网口访问 OpenWrt luci 管理界面也是那个收费提示,只需要把该机器的 MAC 地址同样授权一样即可

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

OpenWrt WifiDog + wiwiz 安装配置

wifidog

WifiDog是路由器的一种上网认证功能,如果开启此功能,所有通过路由器上网的设备都会跳转到指定的界面,需要通过某种方式认证才可以上网,这种认证方式的优势在于安全性高,不容易被破解验证。

WifiDog安装
登录到 OpenWrt luci 后台,打开 System / Software,然后查找 wifidog
NewImage1.png

再点击 Available packages (wifidog),选择安装
NewImage2.png

NewImage.png

WifiDog 安装后,还需要到 System / Startup 使用 WifiDog 服务自动启动
NewImage4.png

然后还要到 Network /Firewall 里,把 lan => wan 的默认 Forward 规则改为 reject
NewImage3.png

wiwiz 账号申请

Wifidog 使用时需要配合认证系统来使用,你可以部署一个 AuthPuppy,不过如果为了测试方便,可以直接申请一个 wiwiz 的账号。Wiwiz是一个有线/无线网络热点管理系统,利用它你可以为你的热点创建一个强制门户/强制认证页面(captive portal)。

申请好账号之后,需要在 Wiwiz 里创建一个热点,这个时候将得到你的 HotSpot ID,把这个 ID 记录下来,等下 WifiDog 配置的时候要用到。

WifiDog配置

使用 SSH 登录到你的 OpenWrt 上,编辑 /etc/wifidog.conf 文件,在文件末尾增加以下配置:

GatewayID 14BBB888BBB
AuthServer {
    Hostname cp.wiwiz.com
    Path /as/s/
}

最后直接重新启动一下路由器,然后用你的终端通过你的路由器访问互联网,就会弹出 Wiwiz 的认证页面

本文章由 http://www.wifidog.pro/2015/04/08/wifidog-openwrt-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 整理编辑,转载请注明出处