Skip to content

Commit

Permalink
1.Internationalization of app rules 2.Change feature format, Support …
Browse files Browse the repository at this point in the history
…for custom categories
  • Loading branch information
destan19 committed Nov 29, 2022
1 parent dc918b3 commit fd21eb3
Show file tree
Hide file tree
Showing 19 changed files with 494 additions and 117 deletions.
Empty file modified LICENSE
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions luci-app-oaf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ include $(TOPDIR)/rules.mk

LUCI_TITLE:=Open App Filter Module
LUCI_PKGARCH:=all
LUCI_DEPENDS:=+appfilter +kmod-oaf
LUCI_DEPENDS:=+appfilter +kmod-oaf +luci-compat
PKG_NAME:=luci-app-oaf
PKG_VERSION:=5.0
PKG_VERSION:=5.0.2
PKG_RELEASE:=1
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature
12 changes: 6 additions & 6 deletions luci-app-oaf/luasrc/controller/appfilter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ function index()
local page
entry({"admin", "services", "appfilter"},
alias("admin", "services", "appfilter", "user_list"),
_("应用过滤"), 20).dependent = true
_("App Filter"), 20).dependent = true

entry({"admin", "services", "appfilter", "user_list"},
arcombine(cbi("appfilter/user_list",{hideapplybtn=true, hidesavebtn=true, hideresetbtn=true}),
cbi("appfilter/dev_status", {hideapplybtn=true, hidesavebtn=true, hideresetbtn=true})),
_("用户列表"), 21).leaf=true
_("User List"), 21).leaf=true

entry({"admin", "services", "appfilter", "base_setting"},
cbi("appfilter/base_setting"), _("基本设置"), 22).leaf=true
cbi("appfilter/base_setting"), _("Basic Settings"), 22).leaf=true

entry({"admin", "services", "appfilter", "user_setting"},
cbi("appfilter/user_setting"), _("生效用户"), 23).leaf=true
cbi("appfilter/user_setting"), _("Effective User"), 23).leaf=true

entry({"admin", "services", "appfilter", "time_setting"},
cbi("appfilter/time_setting"), _("生效时间"), 24).leaf=true
cbi("appfilter/time_setting"), _("Effective Time"), 24).leaf=true

entry({"admin", "services", "appfilter", "feature"},
cbi("appfilter/feature", {hideapplybtn=true, hidesavebtn=true, hideresetbtn=true}), _("特征库升级"), 25).leaf=true
cbi("appfilter/feature", {hideapplybtn=true, hidesavebtn=true, hideresetbtn=true}), _("App Feature"), 25).leaf=true

page = entry({"admin", "network", "user_status"}, call("user_status"), nil)
page.leaf = true
Expand Down
37 changes: 30 additions & 7 deletions luci-app-oaf/luasrc/model/cbi/appfilter/base_setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,59 @@ local SYS = require "luci.sys"
local m, s

m = Map("appfilter", translate("App Filter"), translate(
"请先关闭所有加速(acc)、广告过滤、多拨等可能冲突的模块"))
"Please close the modules that may conflict, such as acceleration, ad filtering, and multi-dial"))

s = m:section(TypedSection, "global", translate("Basic Settings"))
s:option(Flag, "enable", translate("Enable App Filter"), translate(""))
s.anonymous = true

o=s:option(ListValue, "work_mode", translate("工作模式"),translate("请正确选择模式,一般经过了WAN口转发则为主路由,建议切换模式后重启设备"))
o=s:option(ListValue, "work_mode", translate("Work Mode"),translate(""))
o.default=0
o:value(0,"主路由模式")
o:value(1,"旁路由模式")
o:value(0, translate("Gateway Mode"))
o:value(1,translate("Bypass Mode"))

local rule_count = 0
local version = ""

s = m:section(TypedSection, "appfilter", translate("App Filter Rules"))
s = m:section(TypedSection, "appfilter", translate("App Filter Rules"),
translate("If there is no app you want, you can add the app by updating the app feature file"))
s.anonymous = true
s.addremove = false

function get_class_i18n_name(class_name)
local fd = io.open("/tmp/app_class.txt", "r")
if not fd then return end
while true do
local ln = fd:read("*l")
if not ln then
break
end
local id, name1, name2 = ln:match("^(%d+) (%S+) (%S+)")
if class_name == name1 then
fd:close()
return name2
end
end
fd:close()
return nil
end
local class_fd = io.popen("find /tmp/appfilter/ -type f -name '*.class'")
if class_fd then
while true do
local apps
local class
local i18n_name
local path = class_fd:read("*l")
if not path then
break
end

class = path:match("([^/]+)%.class$")
s:tab(class, translate(class))
i18n_name=get_class_i18n_name(class)
if nil ~= i18n_name then
s:tab(class, i18n_name)
else
s:tab(class, class)
end
apps = s:taboption(class, MultiValue, class .. "apps", translate(""))
apps.rmempty = true
apps.widget = "checkbox"
Expand Down
35 changes: 26 additions & 9 deletions luci-app-oaf/luasrc/model/cbi/appfilter/feature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@ local SYS = require "luci.sys"
local m, s

m = Map("appfilter", translate(""),
translate("特征库用于描述app特征,app过滤效果和个数依赖特征库"))
translate("The feature library is used to describe app features, app filtering effect and number-dependent feature library"))

local rule_count = 0
local version = ""
local format = ""
if nixio.fs.access("/tmp/feature.cfg") then
rule_count = tonumber(SYS.exec("cat /tmp/feature.cfg | wc -l"))
version = SYS.exec("cat /tmp/feature.cfg |grep \"#version\" | awk '{print $2}'")
end
format=SYS.exec("uci get appfilter.feature.format")
if format == "" then
format="v2.0"
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("Update feature"), display_str)
local display_str = "<strong>"..translate("Current version")..": </strong>" .. version ..
"<br><strong>"..translate("Feature format")..":</strong> " ..format ..
"<br><strong>"..translate("App number")..":</strong> " ..rule_count ..
"<br><strong>"..translate("Feature download")..":</strong><a href=\"http://www.openappfilter.com\" target=\"_blank\">www.openappfilter.com</a>"
s = m:section(TypedSection, "feature", translate("App Feature"), display_str)

fu = s:option(FileUpload, "")
fu.template = "cbi/oaf_upload"
Expand All @@ -38,6 +44,8 @@ local dir, fd
dir = "/tmp/upload/"
nixio.fs.mkdir(dir)
http.setfilehandler(function(meta, chunk, eof)
local feature_file = "/etc/appfilter/feature.cfg"
local f_format="v1.0"
if not fd then
if not meta then
return
Expand All @@ -55,16 +63,25 @@ http.setfilehandler(function(meta, chunk, eof)
if eof and fd then
fd:close()
local fd2 = io.open("/tmp/upload/" .. meta.file)
local line = fd2:read("*l");
local version_line = fd2:read("*l");
local format_line = fd2:read("*l");
fd2:close()
local ret = string.match(line, "#version")
local feature_file = "/etc/appfilter/feature.cfg"
local ret = string.match(version_line, "#version")
if ret ~= nil then
if string.match(format_line, "#format") then
f_format = SYS.exec("echo '"..format_line.."'|awk '{print $2}'")
end
if not string.match(f_format, format) then
um.value = translate("Failed to update feature file, format error"..",feature format:"..f_format)
os.execute("rm /tmp/upload/* -fr");
return
end
local cmd = "cp /tmp/upload/" .. meta.file .. " " .. feature_file;
os.execute(cmd);
os.execute("chmod 666 " .. feature_file);
os.execute("rm /tmp/appfilter -fr");
luci.sys.exec("/etc/init.d/appfilter restart &");
os.execute("uci set appfilter.feature.update=1");
luci.sys.exec("/etc/init.d/appfilter restart");
um.value = translate("Update the feature file successfully, please refresh the page")
else
um.value = translate("Failed to update feature file, format error")
Expand Down
10 changes: 5 additions & 5 deletions luci-app-oaf/luasrc/model/cbi/appfilter/time_setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ local m, s

m = Map("appfilter", translate(""), translate(""))

s = m:section(TypedSection, "time", translate("Time Setting"),translate("时间2为选填,开始和结束时间需要同时设置,结束时间要大于开始时间"))
s = m:section(TypedSection, "time", translate("Time Setting"),translate("The second time is optional, the end time must be greater than the start time"))
s.anonymous = true


o=s:option(ListValue, "time_mode", translate("时间匹配模式:"),translate(""))
o=s:option(ListValue, "time_mode", translate("Time Mode"),translate(""))
o.default=0
o:value(0,"时间范围内规则生效")
o:value(1,"时间范围外规则生效")
o:value(0,translate("Blacklist mode"))
o:value(1,translate("Whitelist mode"))

days = s:option(MultiValue, "days", "", translate(""))
days.widget = "checkbox"
Expand All @@ -34,7 +34,7 @@ days:value("4", translate("Thur"));
days:value("5", translate("Fri"));
days:value("6", translate("Sat"));

hv = s:option(Value, "start_time", translate("Start Time1"),translate("格式xx:xx,下同"))
hv = s:option(Value, "start_time", translate("Start Time1"),translate("xx:xx"))
hv.optional = false
hv = s:option(Value, "end_time", translate("End Time1"))
hv.optional = false
Expand Down
62 changes: 62 additions & 0 deletions luci-app-oaf/po/zh-cn/oaf.po
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,66 @@ msgstr "分"
msgid "Enable App Filter"
msgstr "开启应用过滤"

msgid "App Feature"
msgstr "应用特征库"

msgid "Effective User"
msgstr "生效用户"

msgid "Effective Time"
msgstr "生效时间"

msgid "Basic Settings"
msgstr "基本设置"

msgid "Please close the modules that may conflict, such as acceleration, ad filtering, and multi-dial"
msgstr "请先关闭加速、广告过滤、多拨等可能冲突的模块"


msgid "Work Mode"
msgstr "工作模式"

msgid "Gateway Mode"
msgstr "网关模式"

msgid "Bypass Mode"
msgstr "旁路模式"

msgid "Bypass Mode"
msgstr "旁路模式"

msgid "Current version"
msgstr "当前版本"

msgid "Current version"
msgstr "当前版本"

msgid "App number"
msgstr "App个数"

msgid "Feature download"
msgstr "特征库下载"

msgid "The second time is optional, the end time must be greater than the start time"
msgstr "时间2为选填,结束时间要大于开始时间"

msgid "Time Mode"
msgstr "时间匹配模式"

msgid "Blacklist mode"
msgstr "黑名单模式"

msgid "Whitelist mode"
msgstr "白名单模式"

msgid "The feature library is used to describe app features, app filtering effect and number-dependent feature library"
msgstr "特征库用于描述app特征,app过滤效果和个数依赖特征库"

msgid "User List"
msgstr "用户列表"

msgid "If there is no app you want, you can add the app by updating the app feature file"
msgstr "如果没有你想要的APP,可以通过升级特征库增加APP"

msgid "Feature format"
msgstr "特征码格式"
Loading

0 comments on commit fd21eb3

Please sign in to comment.