Merge pull request #478 from qlwz/master

add luci-app-wifidog-ng from qlwz/master
This commit is contained in:
coolsnowwolf 2018-08-24 15:17:01 +08:00 committed by GitHub
commit f3fc4566fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 625 additions and 0 deletions

View File

@ -0,0 +1,12 @@
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI support for WifiDog-ng
LUCI_DEPENDS:=+luci-lib-json +wifidog-ng-openssl
PKG_VERSION:=1.0
PKG_RELEASE:=1
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -0,0 +1,27 @@
module("luci.controller.wifidog-ng", package.seeall)
local json = require "luci.json"
function index()
if not nixio.fs.access("/etc/config/wifidog-ng") then
return
end
local page
page = entry({"admin", "services", "wifidog-ng"}, cbi("wifidog-ng"), _("WifiDog-ng"))
page.dependent = true
entry({"admin", "services", "wifidog-ng", "getClientList"}, call("getClientList"))
end
function getClientList()
local result = {}
local running = luci.sys.call("pgrep wifidog-ng >/dev/null")==0
if running then
local term = luci.sys.exec("ubus call wifidog-ng term '{\"action\":\"show\"}'")
result = json.decode(term)
end
result["running"] = running
luci.http.prepare_content("application/json")
luci.http.write_json(result)
end

View File

@ -0,0 +1,132 @@
local ipc = require "luci.ip"
local sys = require "luci.sys"
local opkg = require "luci.model.ipkg"
local packageName = "wifidog-ng"
local m, s
if opkg.status(packageName)[packageName] then
return Map(packageName, translate("WifiDog-ng"), translate('<b style="color:red">WifiDog-ng is not installed..</b>'))
end
m = Map("wifidog-ng", translate("WifiDog-ng"), translate("<a target=\"_blank\" href=\"https://github.com/zhaojh329/wifidog-ng\">WifiDog-ng</a> It is a very efficient solution for wireless hotspot authentication."))
m:section(SimpleSection).template = "wifidog-ng/wifidog-ng_status"
s = m:section(TypedSection, "gateway", translate("Client Settings"))
s.anonymous = true
s.addremove = false
s:tab("general", translate("General Settings"))
s:tab("advanced", translate("Advanced Settings"))
-- Client Settings
Enabled = s:taboption("general", Flag, "enabled", translate("Enabled"),translate(""))
Enabled.rmempty = false
Enabled.default = "1"
DhcpHostWhite = s:taboption("general", Flag, "dhcp_host_white", translate("Enabled Trusted DHCP MAC"),translate("Does not support 1.5.6 and below"))
DhcpHostWhite.rmempty = false
DhcpHostWhite.default = "1"
Id = s:taboption("general",Value, "id", translate("Gateway ID"), translate("The mac address of the default GatewayInterface"))
Id.placeholder = luci.util.exec("ifconfig br-lan| grep HWaddr | awk -F \" \" '{print $5}' | awk '$1~//{print;exit}' | sed 's/://g'")
GatewayInterface = s:taboption("general", Value, "ifname", translate("Gateway Interface"), translate("Set this to the internal IP address of the gateway, default 'br-lan'"))
GatewayInterface.default = "br-lan"
for _, e in ipairs(sys.net.devices()) do
if e ~= "lo" then GatewayInterface:value(e) end
end
Port = s:taboption("advanced", Value, "port", translate("Gateway Port"), translate("Listen HTTP on this port"))
Port.datatype = "port"
SSLPort = s:taboption("advanced", Value, "ssl_port", translate("Gateway SSLPort"), translate("Listen HTTPS on this port"))
SSLPort.datatype = "port"
s:taboption("advanced", Value, "ssid", translate("WeChat SSID"), translate("WeChat Use this ssid"))
CheckInterval = s:taboption("advanced", Value, "checkinterval", translate("Check Interval"), translate("How many seconds should we wait between timeout checks."))
CheckInterval.datatype = "uinteger"
CheckInterval.default = "30"
ClientTimeout = s:taboption("advanced", Value, "client_timeout", translate("Client Timeout"), translate("Set this to the desired of number of CheckInterval of inactivity before a client is logged out. The timeout will be INTERVAL * TIMEOUT"))
ClientTimeout.datatype = "uinteger"
ClientTimeout.default = "5"
TemppassTime = s:taboption("advanced", Value, "temppass_time", translate("Temppass Time"), translate("Allow users to pass in a number of seconds"))
TemppassTime.datatype = "uinteger"
TemppassTime.default = "30"
-- Server Settings
s = m:section(TypedSection, "authserver", translate("Server Settings"))
s.anonymous = true
s.addremove = false
s:tab("general", translate("General Settings"))
s:tab("advanced", translate("Advanced Settings"))
s:taboption("general", Value, "host", translate("AuthServer Hostname"), translate("AuthServer Hostname Or IP"))
Path = s:taboption("general", Value, "path", translate("AuthServer Path"), translate("The path must be both prefixed and suffixed by /. Use a single / for server root."))
Path.default = "/wifidog/"
ServerPort = s:taboption("general", Value, "port", translate("AuthServer Port"), translate(""))
ServerPort.datatype = "port"
ServerSSL = s:taboption("general", Flag, "ssl", translate("SSL Available"),translate("Use SSL"))
ServerSSL.rmempty = false
ServerSSL.default = "0"
LoginPath = s:taboption("advanced", Value, "login_path", translate("Login ScriptPath"), translate("This is the script the user will be sent to for login."))
LoginPath.default = "login"
PortalPath = s:taboption("advanced", Value, "portal_path", translate("Portal ScriptPath"), translate("This is the script the user will be sent to after a successfull login."))
PortalPath.default = "portal"
MsgPath = s:taboption("advanced", Value, "msg_path", translate("Msg ScriptPath"), translate("This is the script the user will be sent to upon error to read a readable message."))
MsgPath.default = "gw_message.php"
PingPath = s:taboption("advanced", Value, "ping_path", translate("Ping ScriptPath"), translate("This is the script the user will be sent to check server."))
PingPath.default = "ping"
AuthPath = s:taboption("advanced", Value, "auth_path", translate("Auth ScriptPath"), translate("This is the script the user will be sent to check auth."))
AuthPath.default = "auth"
-- Trusted MAC List
s = m:section(TypedSection,"whitelist_mac",translate("Trusted MAC List"), translate("MAC addresses who are allowed to pass through without authentication."))
s.template = "cbi/tblsection"
s.anonymous = true
s.addremove = true
e = s:option(Value, "name", translate("Hostname"))
mac = s:option(Value, "mac", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
mac.datatype = "list(macaddr)"
mac.rmempty = true
function mac.cfgvalue(self, section)
local val = Value.cfgvalue(self, section)
return ipc.checkmac(val) or val
end
sys.net.host_hints(function(m, v4, v6, name)
if m and v4 then
mac:value(m, "%s (%s)" %{ m, name or v4 })
end
end)
-- Trusted Domain List
s = m:section(TypedSection,"whitelist_domain",translate("Trusted Domain List"),translate(""))
s.template = "cbi/tblsection"
s.anonymous = true
s.addremove = true
s:option(Value,"domain",translate("Domain Or IP"))
m:section(SimpleSection).template = "wifidog-ng/client_list"
return m

View File

@ -0,0 +1,77 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(10, '<%=luci.dispatcher.build_url("admin", "services", "wifidog-ng", "getClientList")%>', null,
function(x, st) {
var tb = document.getElementById('client-list');
var sa = document.getElementById('wifidog-ng-status');
if (st && sa) {
if (st.running) {
sa.innerHTML = '<em><b><font color=green>WifiDog-ng <%:RUNNING%></font></b></em>';
} else {
sa.innerHTML = '<em><b><font color=red>WifiDog-ng <%:NOT RUNNING%></font></b></em>';
}
}
if (tb) {
/* clear all rows */
while (tb.firstElementChild !== tb.lastElementChild) {
tb.removeChild(tb.lastElementChild);
}
if (st && st.terminals) {
for (var i = 0; i < st.terminals.length; i++) {
var client = st.terminals[i];
var timestr;
if (client.timeout !== false) {
timestr = '<em><%:expired%></em>';
} else {
timestr = String.format('%t', client.uptime);
}
tb.appendChild(E('<div class="tr cbi-rowstyle-%d">'.format((i % 2) + 1), [
E('<div class="td">', client.ip || '?'),
E('<div class="td">', client.ip),
E('<div class="td">', client.mac),
E('<div class="td">', bandwidth_Label(client.outgoing)),
E('<div class="td">', bandwidth_Label(client.incoming)),
E('<div class="td">', timestr)
]));
}
}
if (tb.firstElementChild === tb.lastElementChild) {
tb.appendChild(E('<div class="tr"><div class="td"><em><br /><%:No Authenticated Client%></em></div></div>'));
}
}
});
function bandwidth_Label(bytes) {
var uby = '<%:KB%>';
var kby = (bytes / 1024);
if (kby >= 1024) {
uby = '<%:MB%>';
kby = (kby / 1024);
}
return String.format("%f %s", kby.toFixed(2), uby);
}
//]]></script>
<fieldset class="cbi-section">
<legend><%:Authenticated Client%></legend>
<div class="table" id="client-list">
<div class="tr">
<div class="th"><%:Hostname%></div>
<div class="th"><%:IPv4-Address%></div>
<div class="th"><%:MAC-Address%></div>
<div class="th"><%:TX%></div>
<div class="th"><%:RX%></div>
<div class="th"><%:Uptime%></div>
</div>
<div class="tr">
<div class="td"><em><br /><%:Collecting data...%></em></div>
</div>
</div>
</fieldset>

View File

@ -0,0 +1,6 @@
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<p id="wifidog-ng-status">
<em><%:Collecting data...%></em>
</p>
</fieldset>

View File

@ -0,0 +1,132 @@
msgid "<a target=\"_blank\" href=\"https://github.com/zhaojh329/wifidog-ng\">WifiDog-ng</a> It is a very efficient solution for wireless hotspot authentication."
msgstr "<a target=\"_blank\" href=\"https://github.com/zhaojh329/wifidog-ng\">WifiDog-ng</a> 是一个非常高效的无线热点认证解决方案。"
msgid "Client Settings"
msgstr "程序设置"
msgid "Enabled Trusted DHCP MAC"
msgstr "启用DHCP中的MAC免验证"
msgid "Does not support 1.5.6 and below"
msgstr "不支持1.5.6及以下版本"
msgid "Gateway ID"
msgstr "设备 ID"
msgid "The mac address of the default GatewayInterface"
msgstr "默认为设备MAC地址"
msgid "Gateway Interface"
msgstr "内网接口"
msgid "Set this to the internal IP address of the gateway, default 'br-lan'"
msgstr "指定开启portal认证的网络接口默认'br-lan'"
msgid "Gateway Port"
msgstr "HTTP监听的端口"
msgid "Listen HTTP on this port"
msgstr "HTTP监听此接口"
msgid "Gateway SSLPort""
msgstr "HTTPS监听的端口"
msgid "Listen HTTPS on this port"
msgstr "HTTPS监听此接口"
msgid "WeChat SSID"
msgstr "微信SSID"
msgid "WeChat Use this ssid"
msgstr "微信认证时使用"
msgid "Check Interval"
msgstr "检查时间周期(秒)"
msgid "How many seconds should we wait between timeout checks."
msgstr "作为心跳间隔,以及流量统计间隔"
msgid "Client Timeout"
msgstr "客户端超时下线时间(秒)"
msgid "Set this to the desired of number of CheckInterval of inactivity before a client is logged out. The timeout will be INTERVAL * TIMEOUT"
msgstr "超时下线时间INTERVAL * TIMEOUT"
msgid "Temppass Time"
msgstr "临时放行时间(秒)"
msgid "Allow users to pass in a number of seconds"
msgstr "允许用户在规定时间内允许访问"
msgid "Server Setting"
msgstr "服务器设置"
msgid "AuthServer Hostname"
msgstr "授权服务器地址(支持域名)"
msgid "AuthServer Hostname Or IP"
msgstr "认证服务器地址, 可填写域名或IP"
msgid "AuthServer Path"
msgstr "服务器路径"
msgid "The path must be both prefixed and suffixed by /. Use a single / for server root."
msgstr "服务端WEB目录必须以'/'结尾,列'/wifidog/'"
msgid "AuthServer Port"
msgstr "认证服务器端口"
msgid "SSL Available"
msgstr "开启SSL"
msgid "Use SSL"
msgstr "使用SSL"
msgid "Login ScriptPath"
msgstr "登录接口url路径段"
msgid "This is the script the user will be sent to for login."
msgstr "登录连接"
msgid "Portal ScriptPath"
msgstr "认证成功接口url路径段"
msgid "This is the script the user will be sent to after a successfull login."
msgstr "认证成功连接"
msgid "Msg ScriptPath"
msgstr "错误信息接口url路径段"
msgid "This is the script the user will be sent to upon error to read a readable message."
msgstr "错误信息连接"
msgid "Ping ScriptPath"
msgstr "Ping接口url路径段"
msgid "This is the script the user will be sent to check server."
msgstr "Ping连接"
msgid "Auth ScriptPath"
msgstr "授权验证接口url路径段"
msgid "This is the script the user will be sent to check auth."
msgstr "授权连接"
msgid "Trusted MAC List"
msgstr "免授权的MAC"
msgid "MAC addresses who are allowed to pass through without authentication."
msgstr "允许在未经身份验证的情况下通过的MAC地址"
msgid "Trusted Domain List"
msgstr "免授权的域名"
msgid "Domain Or IP"
msgstr "域名或者IP"
msgid "Authenticated Client"
msgstr "已授权的客户端"
msgid "No Authenticated Client"
msgstr "没有已经授权的客户端"

View File

@ -0,0 +1,26 @@
config gateway
option enabled 0
option dhcp_host_white 1
option ifname 'br-lan'
option port 2060
option ssl_port 8443
option checkinterval 30
option client_timeout 5
option temppass_time 30
config authserver
option host 'authserver.com'
option port 80
option ssl 0
option path '/wifidog/'
option login_path 'login'
option portal_path 'portal'
option msg_path 'gw_message.php'
option ping_path 'ping'
option auth_path 'auth'
config popularserver
list server www.baidu.com
list server www.qq.com

View File

@ -0,0 +1,60 @@
#!/bin/sh /etc/rc.common
#
#
START=99
STOP=10
BIN=/usr/bin/wifidog-ng
parse_whitelist_mac() {
local cfg="$1"
local mac
uci_validate_section wifidog-ng whitelist "${1}" \
'mac:macaddr'
[ $? -ne 0 ] && {
echo "validation whitelist_mac failed" >&2
exit 1
}
}
parse_whitelist_domain() {
local cfg="$1"
local domain
uci_validate_section wifidog-ng whitelist "${1}" \
'domain:host'
[ $? -ne 0 ] && {
echo "validation whitelist_domain failed" >&2
exit 1
}
}
get_config() {
config_get_bool vt_enabled $1 enabled 0
}
start() {
config_load wifidog-ng
config_foreach get_config gateway
if [ "$vt_enabled" = 0 ]; then
echo "WARNING: WifiDog-ng is disabled."
exit 0
fi
#config_foreach parse_whitelist_mac whitelist_mac
#config_foreach parse_whitelist_domain whitelist_domain
modprobe wifidog-ng
$BIN & >/dev/null &
}
stop() {
rmmod wifidog-ng
killall -9 wifidog-ng 2>/dev/null
}

View File

@ -0,0 +1,22 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@wifidog-ng[-1]
add ucitrack wifidog-ng
set ucitrack.@wifidog-ng[-1].init=wifidog-ng
commit ucitrack
EOF
chmod +x /etc/init.d/wifidog-ng
/etc/init.d/wifidog-ng stop
yes|cp /tmp/wifidog-ng.init /etc/init.d/wifidog-ng
chmod +x /etc/init.d/wifidog-ng
/etc/init.d/wifidog-ng enable
/etc/init.d/wifidog-ng start
rm -f /tmp/luci-indexcache
exit 0

View File

@ -0,0 +1,60 @@
#!/bin/sh /etc/rc.common
#
#
START=99
STOP=10
BIN=/usr/bin/wifidog-ng
parse_whitelist_mac() {
local cfg="$1"
local mac
uci_validate_section wifidog-ng whitelist "${1}" \
'mac:macaddr'
[ $? -ne 0 ] && {
echo "validation whitelist_mac failed" >&2
exit 1
}
}
parse_whitelist_domain() {
local cfg="$1"
local domain
uci_validate_section wifidog-ng whitelist "${1}" \
'domain:host'
[ $? -ne 0 ] && {
echo "validation whitelist_domain failed" >&2
exit 1
}
}
get_config() {
config_get_bool vt_enabled $1 enabled 0
}
start() {
config_load wifidog-ng
config_foreach get_config gateway
if [ "$vt_enabled" = 0 ]; then
echo "WARNING: WifiDog-ng is disabled."
exit 0
fi
#config_foreach parse_whitelist_mac whitelist_mac
#config_foreach parse_whitelist_domain whitelist_domain
modprobe wifidog-ng
$BIN & >/dev/null &
}
stop() {
rmmod wifidog-ng
killall -9 wifidog-ng 2>/dev/null
}

View File

@ -0,0 +1,71 @@
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=95
BIN=/usr/bin/wifidog-ng
parse_whitelist_mac() {
local cfg="$1"
local mac
uci_validate_section wifidog-ng whitelist "${1}" \
'mac:macaddr'
[ $? -ne 0 ] && {
echo "validation whitelist_mac failed" >&2
exit 1
}
}
parse_whitelist_domain() {
local cfg="$1"
local domain
uci_validate_section wifidog-ng whitelist "${1}" \
'domain:host'
[ $? -ne 0 ] && {
echo "validation whitelist_domain failed" >&2
exit 1
}
}
get_config() {
config_get_bool vt_enabled $1 enabled 0
}
start_service() {
stop_service()
config_load wifidog-ng
config_foreach get_config gateway
if [ "$vt_enabled" = 0 ]; then
echo "WARNING: WifiDog-ng is disabled."
exit 0
fi
config_foreach parse_whitelist_mac whitelist_mac
config_foreach parse_whitelist_domain whitelist_domain
modprobe wifidog-ng
procd_open_instance
procd_set_param command $BIN
procd_set_param respawn
procd_close_instance
}
stop_service() {
rmmod wifidog-ng
killall -9 wifidog-ng 2>/dev/null
}
service_triggers() {
procd_add_reload_trigger "wifidog-ng"
}
reload_service() {
start_service()
}