OpenAppFilter: sync with upstream source

This commit is contained in:
CN_SZTL 2020-06-20 18:12:25 +08:00
parent 1be68f5d62
commit e2063a2798
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
6 changed files with 88 additions and 21 deletions

View File

@ -24,10 +24,8 @@ function get_hostname_by_mac(dst_mac)
break
end
local ts, mac, ip, name, duid = ln:match("^(%d+) (%S+) (%S+) (%S+) (%S+)")
print(ln)
if dst_mac == mac then
print("match mac", mac, "hostname=", name);
fd:close()
fd:close()
return name
end
end

View File

@ -1,16 +1,3 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id$
]]--
local ds = require "luci.dispatcher"
@ -81,6 +68,57 @@ if class_fd then
end
class_fd:close()
end
s=m:section(TypedSection,"user",translate("Select users"))
s.anonymous = true
users = s:option(MultiValue, "users", "", translate("Select at least one user, otherwise it will take effect for all users"))
users.widget="checkbox"
function get_hostname_by_mac(dst_mac)
leasefile="/tmp/dhcp.leases"
local fd = io.open(leasefile, "r")
if not fd then return end
while true do
local ln = fd:read("*l")
if not ln then
break
end
local ts, mac, ip, name, duid = ln:match("^(%d+) (%S+) (%S+) (%S+) (%S+)")
print(ln)
if dst_mac == mac then
fd:close()
return name
end
end
fd:close()
return nil
end
users.widget="checkbox"
--users.widget="select"
users.size=1
local fd = io.open("/proc/net/arp", "r")
if not fd then return end
while true do
local line = fd:read("*l")
if not line then
break
end
if not line:match("Ip*") then
local ip, hw_type, flags, mac, mask, device = line:match("(%S+) %s+ (%S+) %s+ (%S+) %s+ (%S+) %s+ (%S+) %s+ (%S+)")
if device:match("lan") then
local hostname=get_hostname_by_mac(mac)
if not hostname then
users:value(mac, mac);
else
users:value(mac, hostname);
end
end
end
end
m:section(SimpleSection).template = "admin_network/user_status"

View File

@ -41,8 +41,13 @@ msgstr "基本设置"
msgid "App Filter Rules"
msgstr "应用过滤规则"
msgid "Select at least one user, otherwise it will take effect for all users"
msgstr "至少选择一个用户,否则对所有用户生效"
msgid "Select users"
msgstr "选择用户"
msgid "Enable App Filter"
msgstr "开启应用过滤"

View File

@ -0,0 +1,7 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
set appfilter.user=user
commit appfilter
EOF
exit 0

View File

@ -3,12 +3,12 @@ include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=oaf
PKG_VERSION:=3.0
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_SOURCE_URL:=https://github.com/destan19/OpenAppFilter.git
PKG_SOURCE_PROTO:=git
PKG_SOURCE_DATE:=2020-05-26
PKG_SOURCE_VERSION:=bba08ecedaf97bd4bbb991e32b89eb81ad017da6
PKG_SOURCE_DATE:=2020-06-15
PKG_SOURCE_VERSION:=08f07db43d7dd424cb763f50ed7437d35449af7c
include $(INCLUDE_DIR)/package.mk

View File

@ -64,6 +64,25 @@ load_rule()
config_apply "$json_str"
json_cleanup
}
load_mac_list()
{
json_init
config_load appfilter
json_add_int "op" 4
json_add_object "data"
json_add_array "mac_list"
config_get appid_list "user" "users"
echo "appid list=$appid_list"
for appid in $appid_list:
do
echo "appid=$appid"
json_add_string "" $appid
done
json_str=`json_dump`
config_apply "$json_str"
echo "json str=$json_str"
json_cleanup
}
clean_rule
load_rule
load_mac_list