diff --git a/luci-app-oaf/luasrc/controller/appfilter.lua b/luci-app-oaf/luasrc/controller/appfilter.lua index 7b1bdf0..93daabb 100755 --- a/luci-app-oaf/luasrc/controller/appfilter.lua +++ b/luci-app-oaf/luasrc/controller/appfilter.lua @@ -25,6 +25,9 @@ function index() page = entry({"admin", "network", "dev_visit_list"}, call("get_dev_visit_list"), nil) page.leaf = true + page = entry({"admin", "network", "feature_upgrade"}, call("handle_feature_upgrade"), nil) + page.leaf = true + page = entry({"admin", "network", "dev_visit_time"}, call("get_dev_visit_time"), nil) page.leaf = true page = entry({"admin", "network", "app_class_visit_time"}, call("get_app_class_visit_time"), nil) @@ -50,6 +53,30 @@ function get_hostname_by_mac(dst_mac) return "" end + +function handle_feature_upgrade() + local fs = require "nixio.fs" + local http = require "luci.http" + local image_tmp = "/tmp/feature.cfg" + + local fp + http.setfilehandler( + function(meta, chunk, eof) + + fp = io.open(image_tmp, "w") + + if fp and chunk then + fp:write(chunk) + end + if fp and eof then + fp:close() + end + end + ) + + +end + function get_app_name_by_id(appid) local class_fd = io.popen("find /tmp/appfilter/ -type f -name *.class |xargs cat |grep "..appid.."|awk '{print $2}'") if class_fd then diff --git a/luci-app-oaf/luasrc/model/cbi/appfilter/appfilter.lua b/luci-app-oaf/luasrc/model/cbi/appfilter/appfilter.lua index b7988fa..0977b9b 100755 --- a/luci-app-oaf/luasrc/model/cbi/appfilter/appfilter.lua +++ b/luci-app-oaf/luasrc/model/cbi/appfilter/appfilter.lua @@ -9,7 +9,8 @@ local dsp = require "luci.dispatcher" local uci = require "luci.model.uci" local lng = require "luci.i18n" local jsc = require "luci.jsonc" - +local http = luci.http +local SYS = require "luci.sys" local m, s m = Map("appfilter", @@ -20,7 +21,23 @@ s = m:section(TypedSection, "global", translate("Basic Settings")) s:option(Flag, "enable", translate("Enable App Filter"),translate("")) s.anonymous = true +local rule_count=0 +local version="" +if nixio.fs.access("/etc/appfilter/feature.cfg") then + rule_count=tonumber(SYS.exec("cat /etc/appfilter/feature.cfg | wc -l")) + version=SYS.exec("cat /etc/appfilter/feature.cfg |grep \"#version\" | awk '{print $2}'") +end +local display_str="当前版本: "..version.."
特征码个数: "..rule_count.."
下载地址:https://destan19.github.io" +s = m:section(TypedSection, "feature", translate("特征库更新"), display_str ) +fu = s:option(FileUpload, "") +fu.template = "cbi/other_upload" +s.anonymous = true + +um = s:option(DummyValue, "rule_data") +um.template = "cbi/other_dvalue" + +--um.value =rule_count .. " " .. translate("Records").. " "..version s = m:section(TypedSection, "appfilter", translate("App Filter Rules")) s.anonymous = true s.addremove = false @@ -146,6 +163,49 @@ for i=1,max,1 do end end m:section(SimpleSection).template = "admin_network/user_status" +local dir, fd +dir = "/tmp/upload/" +nixio.fs.mkdir(dir) +http.setfilehandler( + function(meta, chunk, eof) + if not fd then + if not meta then return end + if meta and chunk then fd = nixio.open(dir .. meta.file, "w") end + if not fd then + --um.value = translate("Create upload file error.") + return + end + end + if chunk and fd then + fd:write(chunk) + end + if eof and fd then + fd:close() + local fd2 = io.open("/tmp/upload/"..meta.file) + local line=fd2:read("*l"); + local ret=string.match(line, "#version") + if ret ~= nil then + local cmd="cp /tmp/upload/"..meta.file.." /etc/appfilter/feature.cfg"; + os.execute(cmd); + os.execute("rm /tmp/appfilter -fr"); + luci.sys.exec("/etc/init.d/appfilter restart &"); + um.value = translate("更新成功,请刷新页面!") + else + um.value = translate("更新失败,格式错误!") + end + end + + end +) + +if luci.http.formvalue("upload") then + local f = luci.http.formvalue("ulfile") + if #f <= 0 then + --um.value = translate("No specify upload file.") + end +elseif luci.http.formvalue("download") then + Download() +end return m diff --git a/luci-app-oaf/root/etc/uci-defaults/92_add_user_section b/luci-app-oaf/root/etc/uci-defaults/92_add_user_section index a584078..cea403f 100755 --- a/luci-app-oaf/root/etc/uci-defaults/92_add_user_section +++ b/luci-app-oaf/root/etc/uci-defaults/92_add_user_section @@ -2,6 +2,7 @@ uci -q batch <<-EOF >/dev/null set appfilter.user=user + appfilter.feature=feature commit appfilter EOF exit 0 diff --git a/open-app-filter/files/appfilter.config b/open-app-filter/files/appfilter.config index a63a65c..17fd458 100755 --- a/open-app-filter/files/appfilter.config +++ b/open-app-filter/files/appfilter.config @@ -1,3 +1,5 @@ config global global config appfilter appfilter + +config feature feature diff --git a/open-app-filter/files/feature.cfg b/open-app-filter/files/feature.cfg index 07a638a..6f3880f 100755 --- a/open-app-filter/files/feature.cfg +++ b/open-app-filter/files/feature.cfg @@ -1,3 +1,4 @@ +#version v21.3.4 #id name:[proto;sport;dport;host url;request;dict] #class chat 1001 QQ:[tcp;;;;;00:02|-1:03,tcp;;;;;02:02|-1:03,tcp;;14000;;;,tcp;;8080;;;00:ca|01:3c,tcp;;;;;00:00|01:00|02:00|03:15]