Skip to content

Commit

Permalink
Support upgrade feature file
Browse files Browse the repository at this point in the history
  • Loading branch information
destan19 committed Mar 4, 2021
1 parent 2489a51 commit 4483aab
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
27 changes: 27 additions & 0 deletions luci-app-oaf/luasrc/controller/appfilter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
62 changes: 61 additions & 1 deletion luci-app-oaf/luasrc/model/cbi/appfilter/appfilter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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="<strong>当前版本: </strong>"..version.."<br><strong>特征码个数:</strong> "..rule_count.."<br><strong> 下载地址:</strong><a href=\"https://destan19.github.io\">https://destan19.github.io</a>"
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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions luci-app-oaf/root/etc/uci-defaults/92_add_user_section
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

uci -q batch <<-EOF >/dev/null
set appfilter.user=user
appfilter.feature=feature
commit appfilter
EOF
exit 0
2 changes: 2 additions & 0 deletions open-app-filter/files/appfilter.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
config global global

config appfilter appfilter

config feature feature
1 change: 1 addition & 0 deletions open-app-filter/files/feature.cfg
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit 4483aab

Please sign in to comment.