在wifidog的login参数中加入客户端MAC地址
用户在连接到需要认证的wifi上之后,会被wifidog 的login 协议重定向到:
http://auth_server/login/?gw_id=xxx&gw_address=xxx&gw_port=xxx&url=xxx
如果我们想添加一个mac 地址,该如何实现?
添加网关的MAC地址直接可以改成:
http://auth_server/login/?gw_id=xxx&gw_address=xxx&gw_mac=xxx&gw_port=xxx&url=xxx
网关的MAC 地址获取很简单用ioctl 就可以实现,这里不细说,另一种办法是直接在配置页面把网关MAC 配置进wifidog.conf,给全局变量config 添加一个字段成员即可,也很简单。
那么添加当前客户端的MAC 地址又该如何实现?
在http.c 文件里找到
/* Re-direct them to auth server */
char *urlFragment;
safe_asprintf(&urlFragment, "%sgw_address=%s&gw_port=%d&gw_id=%s&url=%s",
auth_server->authserv_login_script_path_fragment,
config->gw_address,
config->gw_port,
config->gw_id,
url);
debug(LOG_INFO, "Captured %s requesting [%s] and re-directing them to login page", r->clientAddr, url);
http_send_redirect_to_auth(r, urlFragment, "Redirect to login page");
free(urlFragment);
lighttpd 已经帮我们拿到了r->clientAddr,这个其实就是当前客户端的IP 地址,然后我们通过读取arp 表/proc/net/arp 来查找r->clientAddr 对应的MAC,不过wifidog 已经有现成的函数arp_get直接得到MAC 地址,所以我们直接将上述代码修改成:
/* Re-direct them to auth server */
char *urlFragment;
char *client_mac = arp_get(r->clientAddr);
if(client_mac == NULL)
return;
safe_asprintf(&urlFragment, "%sgw_address=%s&gw_port=%d&client_mac=%s&gw_id=%s&url=%s",
auth_server->authserv_login_script_path_fragment,
config->gw_address,
config->gw_port,
config->gw_id,
url);
debug(LOG_INFO, "Captured %s requesting [%s] and re-directing them to login page", r->clientAddr, url);
http_send_redirect_to_auth(r, urlFragment, "Redirect to login page");
free(urlFragment);
本文章由 http://www.wifidog.pro/2015/03/04/wifidog-login%E6%B7%BB%E5%8A%A0%E5%AE%A2%E6%88%B7%E7%AB%AFmac%E5%9C%B0%E5%9D%80.html 整理编辑,转载请注明出处