Wifidog Gateway的iptables规则整理
最近在研究Wifi的Portal认证相关,研究了一下wifidog,整理了一下iptables规则。
本文章由 http://www.wifidog.pro/2015/02/04/wifidog-iptables.html 整理编辑,转载请注明出处
最近在研究Wifi的Portal认证相关,研究了一下wifidog,整理了一下iptables规则。
本文章由 http://www.wifidog.pro/2015/02/04/wifidog-iptables.html 整理编辑,转载请注明出处
#网关ID
GatewayID default
#外部网卡
ExternalInterface eth0
#无线网卡
GatewayInterface eth0
#无线IP
GatewayAddress 192.168.1.1
#路由状态HTML
HtmlMessageFile wifidog-msg.html
#验证服务器
#AuthServer {
# Hostname (Mandatory; Default: NONE)
# SSLAvailable (Optional; Default: no; Possible values: yes, no)
# SSLPort (Optional; Default: 443)
# HTTPPort (Optional; Default: 80)
# Path (Optional; Default: /wifidog/ Note: The path must be both prefixed and suffixed by /. Use a single / for server root.)
# LoginScriptPathFragment (Optional; Default: login/? Note: 未用户登录重定向地址.)
# PortalScriptPathFragment (Optional; Default: portal/? Note: 登录成功后重定向地址.)
# MsgScriptPathFragment (Optional; Default: gw_message.php? Note: 退出登录后重定向地址.)
# PingScriptPathFragment (Optional; Default: ping/? Note: 路由状态心跳地址.)
# AuthScriptPathFragment (Optional; Default: auth/? Note: 路由请求服务器验证地址 and 验证心跳地址(stage=counters).)
#}
AuthServer {
Hostname auth.com
#SSLAvailable yes
Path /
}
# 是否后台进程
# Daemon 1
#默认网关端口
# Default: 2060
GatewayPort 80
# HTTP进程名
# HTTPDName WiFiDog
# HTTP最大连接数
# Default: 10
# HTTPDMaxConn 10
# WEB页面加密码后显示名
# Default: WiFiDog
# HTTPDRealm WiFiDog
# WEB加验证
# HTTPDUserName admin
# HTTPDPassword secret
# 心跳间隔时间
# Default: 60
CheckInterval 60
# 心跳间隔次数 验证超时数等于 CheckInterval*ClientTimeout
ClientTimeout 2
# 信任的MAC地址,加入信任列表将不用登录可访问
#TrustedMACList 00:00:DE:AD:BE:AF,00:00:C0:1D:F0:0D
#其他防火墙设置
#全局
FirewallRuleSet global {
## To block SMTP out, as it's a tech support nightmare, and a legal liability
#FirewallRule block tcp port 25
## Use the following if you don't want clients to be able to access machines on
## the private LAN that gives internet access to wifidog. Note that this is not
## client isolation; The laptops will still be able to talk to one another, as
## well as to any machine bridged to the wifi of the router.
# FirewallRule block to 192.168.0.0/16
# FirewallRule block to 172.16.0.0/12
# FirewallRule block to 10.0.0.0/8
## This is an example ruleset for the Teliphone service.
#FirewallRule allow udp to 69.90.89.192/27
#FirewallRule allow udp to 69.90.85.0/27
#FirewallRule allow tcp port 80 to 69.90.89.205
}
# 新验证用户
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 to baidu.com
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
}
本文章由 http://www.wifidog.pro/2015/02/04/wifidog-conf.html 整理编辑,转载请注明出处
最近在做 wifidog 的广告功能,发现 wifidog 有很多不稳定的地方,急待改进和优化。于是自习研究了 wifidog 的工作流程,结合自己的需求,简化了认证过程,流程图如下:
正常 wifidog 认证流程10步以上,而6次是与服务器端的直接通信。其中重复向服务器发送数据的一项可以完全省略,这样精简了认证流程可以减少4次网络传输,使每个上网用户只需要一次请求即可认证上网。认证流程优化至6步且4步是在本地通信。
注意此种方案中token的产生要在wifidog和服务器端协调一致。其实就是通过算法代替了网络认证问题。
本文章由 http://www.wifidog.pro/2015/02/04/wifidog%E6%94%B9%E8%BF%9B.html 整理编辑,转载请注明出处
1.在package/ utils下创建wifidog_lib目录。在wifidog_lib目录下创建一个文件夹src和一个Makefile文件。Makefile文件编写内容如下:
include $(TOPDIR)/rules.mk
PKG_NAME:=wifidog_lib
PKG_VERSION:=20130917
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/wifidog_lib
SECTION:=utils
CATEGORY:=Utilities
DEPENDS:=+iptables-mod-extra +iptables-mod-ipopt +iptables-mod-nat-extra +libpthread
TITLE:=A wireless captive portal solution
endef
define Package/wifidog_lib/description
The Wifidog project is a complete and embeddable captive
portal solution for wireless community groups or individuals
who wish to open a free Hotspot while still preventing abuse
of their Internet connection.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Configure
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CC)" \
CFLAGS="$(TARGET_CFLAGS) -Wall" \
LDFLAGS="$(TARGET_LDFLAGS)"
endef
define Package/wifidog_lib/conffiles
/etc/wifidog.conf
endef
define Package/wifidog_lib/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/test_wifidog $(1)/usr/bin/
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_BUILD_DIR)/libwifidog.so* $(1)/usr/lib/
$(INSTALL_DIR) $(1)/etc
$(INSTALL_DATA) $(PKG_BUILD_DIR)/wifidog.conf $(1)/etc/
endef
$(eval $(call BuildPackage,wifidog_lib))
2.解压wifidog包进入src目录
Tar xzvf wifidog-20130917-440445db60b0c3aff528ea703a828b0567293387.tar.gz –C src
3.在src下创建Makefile文件,内容如下:
LIB_VERMAJOR = 0
LIB_VERMINOR = 1
LIB_FILENAME = libhttpd.so
LIBWIFIDOG_FILENAME = libwifidog.so
OBJEXT = o
CFLAGS += -Os -pipe -mno-branch-likely -mips32r2 -mtune=34kc -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -msoft-float
LIB_CFLAGS = $(CFLAGS) -shared -fPIC -DPIC
LIB_LDFLAGS = $(LDFLAGS) -Wl,-soname,$(LIB_FILENAME).$(LIB_VERMAJOR).$(LIB_VERMINOR)
LIBWIFIDOG_LDFLAGS = $(LDFLAGS) -Wl,-soname,$(LIBWIFIDOG_FILENAME).$(LIB_VERMAJOR).$(LIB_VERMINOR)
wifidog_OBJECTS = src/conf.$(OBJEXT) src/commandline.$(OBJEXT)\
src/debug.$(OBJEXT) src/fw_iptables.$(OBJEXT) src/firewall.$(OBJEXT) \
src/gateway.$(OBJEXT) src/centralserver.$(OBJEXT) src/http.$(OBJEXT) \
src/auth.$(OBJEXT) src/client_list.$(OBJEXT) src/util.$(OBJEXT) \
src/wdctl_thread.$(OBJEXT) src/ping_thread.$(OBJEXT) src/safe.$(OBJEXT) \
src/httpd_thread.$(OBJEXT) src/wifidogapi.$(OBJEXT)
wdctl_OBJECTS = src/wdctl.$(OBJEXT)
LIB_OBJ = libhttpd/protocol.o libhttpd/api.o libhttpd/version.o libhttpd/ip_acl.o
DEFS = -DHAVE_CONFIG_H
DEFAULT_INCLUDES = -I.-I..
sysconfdir = /etc
AM_CPPFLAGS += \
-I./libhttpd/ \
-DSYSCONFDIR='"$(sysconfdir)"'
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
wifidog_LDADD = libhttpd/$(LIB_FILENAME).$(LIB_VERMAJOR).$(LIB_VERMINOR)
LIBS = -lnsl -lpthread
all: Makefile libhttpd libwifidog test_wifidog
test_wifidog: src/test_wifidog.o libhttpd libwifidog
@rm -f test_wifidog
$(LINK) src/test_wifidog.o $(LIBWIFIDOG_FILENAME).$(LIB_VERMAJOR).$(LIB_VERMINOR) $(LIBS)
wdctl: $(wdctl_OBJECTS) libhttpd
@rm -f wdctl
$(LINK) $(wdctl_OBJECTS) $(wdctl_LDADD) $(LIBS)
wifidog_test: $(wifidog_OBJECTS) libhttpd
@rm -f wifidog_test
$(LINK) $(wifidog_OBJECTS) $(wifidog_LDADD) $(LIBS)
libhttpd:$(LIB_OBJ) ./libhttpd/httpd_priv.h ./libhttpd/httpd.h
$(CC) $(LIB_CFLAGS) $(LIB_LDFLAGS) $(LIB_OBJ) $(LIBS) \
-o libhttpd/$(LIB_FILENAME).$(LIB_VERMAJOR).$(LIB_VERMINOR)
libwifidog:$(wifidog_OBJECTS) $(wdctl_OBJECTS) $(LIB_OBJ) ./libhttpd/httpd_priv.h ./libhttpd/httpd.h
$(CC) $(LIB_CFLAGS) $(LIBWIFIDOG_LDFLAGS) $(LIB_OBJ) $(wifidog_OBJECTS) $(wdctl_OBJECTS) $(LIBS) \
-o $(LIBWIFIDOG_FILENAME).$(LIB_VERMAJOR).$(LIB_VERMINOR)
.c.o:
$(CC) $(DEFS) $(AM_CPPFLAGS) $(DEFAULT_INCLUDES) $(INCLUDES) $(CFLAGS) -MD -fPIC -DPIC -c -o $@ $<
clean:
rm -f $(LIB_FILENAME)*
本文章由 http://www.wifidog.pro/2015/02/03/wifidog%E7%BC%96%E8%AF%91-1.html 整理编辑,转载请注明出处