From 11426bd1807c16382a9b00b491296a043e5a6e64 Mon Sep 17 00:00:00 2001 From: derry Date: Tue, 29 Nov 2022 22:38:53 +0800 Subject: [PATCH] Delete invalid file and log --- oaf/src/app_filter.c | 2 - open-app-filter/Makefile | 4 - open-app-filter/files/appfilter.init | 3 +- open-app-filter/files/appfilter.lua | 262 --------------------------- open-app-filter/files/appfilter.sh | 88 --------- open-app-filter/files/gen_class.sh | 1 - open-app-filter/files/oaf_rule | 27 +-- 7 files changed, 9 insertions(+), 378 deletions(-) delete mode 100755 open-app-filter/files/appfilter.lua delete mode 100755 open-app-filter/files/appfilter.sh diff --git a/oaf/src/app_filter.c b/oaf/src/app_filter.c index e71abb69..70671db0 100755 --- a/oaf/src/app_filter.c +++ b/oaf/src/app_filter.c @@ -1204,10 +1204,8 @@ int netlink_oaf_init(void) static int __init app_filter_init(void) { - printk("appfilter version:" AF_VERSION "\n"); if (0 != load_feature_config()) { - printk("load feature failed\n"); return -1; } diff --git a/open-app-filter/Makefile b/open-app-filter/Makefile index a431b42b..bb8900ce 100755 --- a/open-app-filter/Makefile +++ b/open-app-filter/Makefile @@ -6,10 +6,7 @@ PKG_VERSION:=5.0.2 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) - - include $(INCLUDE_DIR)/package.mk -#include $(INCLUDE_DIR)/kernel.mk define Package/appfilter SECTION:=Derry Apps @@ -42,7 +39,6 @@ endef define Package/appfilter/install - echo "install" $(INSTALL_DIR) $(1)/usr/bin $(1)/etc/init.d $(INSTALL_DIR) $(1)/etc/appfilter $(INSTALL_DIR) $(1)/etc/config diff --git a/open-app-filter/files/appfilter.init b/open-app-filter/files/appfilter.init index 61003cfd..7d458fc5 100755 --- a/open-app-filter/files/appfilter.init +++ b/open-app-filter/files/appfilter.init @@ -19,13 +19,12 @@ stop_service(){ start_service(){ local update - #lang=`uci get luci.main.lang` rm $FEATURE_FILE update=`uci get appfilter.feature.update` if [ x"1" == x"$update" ];then ln -s /etc/appfilter/feature.cfg $FEATURE_FILE else - uci get luci.languages.zh_cn >/dev/null + uci get luci.languages.zh_cn >/dev/null 2>&1 if [ $? -eq 0 ];then test -f $FEATURE_FILE && rm $FEATURE_FILE ln -s /etc/appfilter/feature_cn.cfg $FEATURE_FILE diff --git a/open-app-filter/files/appfilter.lua b/open-app-filter/files/appfilter.lua deleted file mode 100755 index 8cea8966..00000000 --- a/open-app-filter/files/appfilter.lua +++ /dev/null @@ -1,262 +0,0 @@ -#!/usr/bin/lua - -local libubus = require "ubus" -local uloop = require "uloop" - -local UBUS_STATUS_OK = 0 -local UBUS_STATUS_INVALID_COMMAND = 1 -local UBUS_STATUS_INVALID_ARGUMENT = 2 -local UBUS_STATUS_METHOD_NOT_FOUND = 3 -local UBUS_STATUS_NOT_FOUND = 4 -local UBUS_STATUS_NO_DATA = 5 -local UBUS_STATUS_PERMISSION_DENIED = 6 -local UBUS_STATUS_TIMEOUT = 7 -local UBUS_STATUS_NOT_SUPPORTED = 8 -local UBUS_STATUS_UNKNOWN_ERROR = 9 -local UBUS_STATUS_CONNECTION_FAILED = 10 -local UBUS_STATUS_ALREADY_EXISTS = 11 - -local cfg_file = "/etc/appfilter/feature.cfg" - -local cfg = {} -local class = {} -local ubus - -cfg.__index = cfg -class.__index = class -function cfg:init(file) - local f = io.open(file, "r") - local t = {} - local t2 = {} - if f then - for line in f:lines() do - table.insert(t, line) - local tt = line:match("#class (%S+)") - if tt then - table.insert(t2, tt) - end - end - setmetatable(t, self) - setmetatable(t2, self) - return t,t2 - end - return nil -end - -function cfg:lookup(o) - if not o then return UBUS_STATUS_INVALID_ARGUMENT end - local tab = self - for _, v in ipairs(tab) do - if v:match(o) then - if v:match("#class") then - local tt = {} - local t2 = {} - local found - for _, t in ipairs(tab) do - repeat - if t:match(o) then - found = true - table.insert(tt, t) - break - end - - if t:match("#class") then - found = false - table.insert(t2, t) - break - end - - if found then - table.insert(tt, t) - else - table.insert(t2, t) - end - until true - end - setmetatable(tt, self) - setmetatable(t2, self) - return tt, t2 - else - return v - end - end - end - return nil -end - -function cfg:lookup_class(m) - if not m then return UBUS_STATUS_INVALID_ARGUMENT end - local t1, t2 = self:lookup(m) - if type(t1) ~= "table" then return nil end - return t1, t2 -end - -function cfg:add_class(m) - if not m then return UBUS_STATUS_INVALID_ARGUMENT end - local f = io.open(cfg_file, "r+") - local tab = self - if f then - io.output(f) - for _, v in ipairs(tab) do - io.write(v) - io.write("\n") - end - io.write("#class "..m) - f:flush() - f:close() - return UBUS_STATUS_OK - else - return UBUS_STATUS_NOT_FOUND - end -end - -function cfg:add_app(m, name, proto, sport, dport, url, request, dict) - if not name then return UBUS_STATUS_INVALID_ARGUMENT end - local id - local offset - local f = io.open(cfg_file, "r+") - io.output(f) - local t1,t2 = self:lookup_class(m) - if t1[#t1] == nil or "" then - offset = 0 - id = math.modf(string.match(t1[#t1-1], "(%d+) %S+:") +1) - else - offset = 1 - id = math.modf(string.match(t1[#t1], "(%d+) %S+:") +1) - end - - local str = string.format("%d %s:[%s;%s;%s;%s;%s;%s]", id, name, proto, sport or "", dport or "", url or "", request or "", dict or "") - table.insert(t1, #t1+offset, str) - if f then - for _, v in ipairs(t2) do - if v then - io.write(v) - io.write("\n") - end - end - for _, v in ipairs(t1) do - if v then - io.write(v) - io.write("\n") - end - end - f:flush() - f:close() - end - return id -end - -function cfg:del_app(id, name) - local t = self - local f = io.open(cfg_file, "r+") - local ret - if id then - for i, v in ipairs(t) do - if v:match(id) then - table.remove(t, i) - ret = i - end - end - - end - - if name then - for i, v in ipairs(t) do - if v:match(name) then - table.remove(t, i) - ret = i - end - end - end - - if f then - io.output(f) - for _, v in ipairs(t) do - io.write(v) - io.write("\n") - end - f:flush() - f:close() - end - return ret -end - -local methods = { - ["appfilter"] = { - add_class = { - function(req, msg) - if not msg.class then return UBUS_STATUS_INVALID_ARGUMENT end - local t = cfg:init(cfg_file) - local ret - if t:lookup_class(msg.class) then return ubus.reply(req, {ret = UBUS_STATUS_ALREADY_EXISTS}) end - ret = t:add_class(msg.class) - ubus.reply(req, {msg = ret}) - end, {class = libubus.STRING} - }, - add_app = { - function (req, msg) - if not msg.class then return UBUS_STATUS_INVALID_ARGUMENT end - if not msg.name then return UBUS_STATUS_INVALID_ARGUMENT end - if not msg.proto then return UBUS_STATUS_INVALID_ARGUMENT end - local t = cfg:init(cfg_file) - local ret - if t:lookup(msg.name) then return ubus.reply(req, {ret = UBUS_STATUS_ALREADY_EXISTS}) end - ret = t:add_app(msg.class, msg.name, msg.proto, msg.sport, msg.dport, msg.url, msg.request, msg.dict) - ubus.reply(req, {ret = ret}) - end,{class = libubus.STRING, name = libubus.STRING, proto = libubus.STRING, sport = libubus.INT32, dport = libubus.INT32, url = libubus.STRING, request = libubus.STRING, dict = libubus.STRING} - }, - del_app = { - function(req, msg) - local t = cfg:init(cfg_file) - local ret = t:del_app(msg.id, msg.name) - ubus.reply(req, {ret = ret}) - end,{id = libubus.INT32, name = libubus.STRING} - }, - list_class = { - function (req, msg) - local _, c = cfg:init(cfg_file) - ubus.reply(req, {result = c}) - end,{} - }, - list_app = { - function (req, msg) - if not msg.class then return UBUS_STATUS_INVALID_ARGUMENT end - local t = cfg:init(cfg_file) - local ret = {} - for i, v in ipairs(t:lookup_class(msg.class)) do - if not v:match("#class") then - local id, name = v:match("(%d+) (%S+):%[") - ret[i-1] = {id = id, name = name} - end - end - ubus.reply(req, {result = ret}) - end,{class = libubus.STRING} - } - } -} - -function ubus_init() - local conn = libubus.connect() - if not conn then - error("Failed to connect to ubus") - end - - conn:add(methods) - - return { - call = function(object, method, params) - return conn:call(object, method, params or {}) - end, - reply = function(req, msg) - conn:reply(req, msg) - end - } -end - -local function main() - uloop.init() - ubus = ubus_init() - uloop.run() -end - -main() \ No newline at end of file diff --git a/open-app-filter/files/appfilter.sh b/open-app-filter/files/appfilter.sh deleted file mode 100755 index b096c9f1..00000000 --- a/open-app-filter/files/appfilter.sh +++ /dev/null @@ -1,88 +0,0 @@ -. /usr/share/libubox/jshn.sh -. /lib/functions.sh - -config_apply() -{ - test -z "$1" && return 1 - - if [ -e "/dev/appfilter" ];then - echo "config json str=$1" - echo "$1" >/dev/appfilter - fi -} - -clean_rule() -{ - json_init - echo "clean appfilter rule..." - - json_add_int "op" 3 - json_add_object "data" - json_str=`json_dump` - - config_apply "$json_str" - - json_cleanup -} - -load_rule() -{ - json_init - - config_load appfilter - config_get enable "global" enable - echo "enable = $enable" - if [ x"$enable" != x"1" ];then - echo "appfilter is disabled" - echo 0 >/proc/sys/oaf/enable>/dev/null - return 0 - else - insmod oaf >/dev/null - echo 1 >/proc/sys/oaf/enable - fi - echo "appfilter is enabled" - json_add_int "op" 1 - - json_add_object "data" - json_add_array "apps" - - for file in `ls /tmp/appfilter/*.class` - do - class_name=`echo "$file" | awk -F/ '{print $4}'| awk -F. '{print $1}'` - config_get appid_list "appfilter" "${class_name}apps" - echo "appid_list=$appid_list" - - if ! test -z "$appid_list";then - for appid in $appid_list: - do - json_add_int "" $appid - done - fi - done - - json_str=`json_dump` - 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 diff --git a/open-app-filter/files/gen_class.sh b/open-app-filter/files/gen_class.sh index b173fcb5..72840553 100755 --- a/open-app-filter/files/gen_class.sh +++ b/open-app-filter/files/gen_class.sh @@ -27,6 +27,5 @@ do test -z "$cur_class" && continue appid=`echo "$line" |awk '{print $1}'` appname=`echo "$line" | awk '{print $2}' | awk -F: '{print $1}'` - echo "appid = $appid, appname=$appname" echo "$appid $appname" >> $cur_class_file done < $f_file diff --git a/open-app-filter/files/oaf_rule b/open-app-filter/files/oaf_rule index 0aa57d3c..fde45c16 100755 --- a/open-app-filter/files/oaf_rule +++ b/open-app-filter/files/oaf_rule @@ -5,9 +5,7 @@ config_apply() { test -z "$1" && return 1 - if [ -e "/dev/appfilter" ];then - echo "config json str=$1" echo "$1" >/dev/appfilter fi } @@ -15,14 +13,10 @@ config_apply() clean_rule() { json_init - echo "clean appfilter rule..." - json_add_int "op" 3 json_add_object "data" json_str=`json_dump` - config_apply "$json_str" - json_cleanup } @@ -32,18 +26,17 @@ load_rule() json_add_int "op" 1 json_add_object "data" json_add_array "apps" - for file in `ls /tmp/appfilter/*.class` do - class_name=`echo "$file" | awk -F/ '{print $4}'| awk -F. '{print $1}'` - config_get appid_list "appfilter" "${class_name}apps" + class_name=`echo "$file" | awk -F/ '{print $4}'| awk -F. '{print $1}'` + config_get appid_list "appfilter" "${class_name}apps" - if ! test -z "$appid_list";then - for appid in $appid_list: - do - json_add_int "" $appid - done - fi + if ! test -z "$appid_list";then + for appid in $appid_list: + do + json_add_int "" $appid + done + fi done json_str=`json_dump` @@ -59,7 +52,6 @@ load_mac_list() json_add_object "data" json_add_array "mac_list" config_get mac_list "user" "users" - echo "mac list=$mac_list" if [ x"$mac_list" != x"" ];then for mac in $mac_list: do @@ -79,16 +71,13 @@ reload_rule(){ } reload_base_config(){ - local old_work_mode config_load appfilter config_get work_mode "global" "work_mode" - echo "work mode=$work_mode" echo "$work_mode" >/proc/sys/oaf/work_mode } case $1 in "reload") - echo "reload appfilter rule..." reload_base_config reload_rule ;;