Skip to content

Commit

Permalink
Support bypass mode
Browse files Browse the repository at this point in the history
  • Loading branch information
destan19 committed Aug 17, 2022
1 parent 48298e6 commit ef0ed9a
Show file tree
Hide file tree
Showing 22 changed files with 584 additions and 168 deletions.
2 changes: 1 addition & 1 deletion luci-app-oaf/luasrc/controller/appfilter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function index()
_("用户列表"), 21).leaf=true

entry({"admin", "services", "appfilter", "base_setting"},
cbi("appfilter/base_setting"), _("应用过滤规则"), 22).leaf=true
cbi("appfilter/base_setting"), _("基本设置"), 22).leaf=true

entry({"admin", "services", "appfilter", "user_setting"},
cbi("appfilter/user_setting"), _("生效用户"), 23).leaf=true
Expand Down
7 changes: 6 additions & 1 deletion luci-app-oaf/luasrc/model/cbi/appfilter/base_setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ local SYS = require "luci.sys"
local m, s

m = Map("appfilter", translate("App Filter"), translate(
"目前不支持旁路模式,请先关闭所有加速(acc)、广告过滤、多拨等可能冲突的模块"))
"请先关闭所有加速(acc)、广告过滤、多拨等可能冲突的模块"))

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.default=0
o:value(0,"主路由模式")
o:value(1,"旁路由模式")

local rule_count = 0
local version = ""

Expand Down
27 changes: 20 additions & 7 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,15 @@ local m, s

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

s = m:section(TypedSection, "time", translate("Time Setting"))
s = m:section(TypedSection, "time", translate("Time Setting"),translate("时间2为选填,开始和结束时间需要同时设置,结束时间要大于开始时间"))
s.anonymous = true
hv = s:option(Value, "start_time", translate("Start Time"))
hv.default = "00:00"
hv.optional = false
hv = s:option(Value, "end_time", translate("End Time"))
hv.default = "23:59"
hv.optional = false


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

days = s:option(MultiValue, "days", "", translate(""))
days.widget = "checkbox"
days.size = 10
Expand All @@ -33,4 +34,16 @@ 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.optional = false
hv = s:option(Value, "end_time", translate("End Time1"))
hv.optional = false

hv = s:option(Value, "start_time2", translate("Start Time2"))
hv.optional = false
hv = s:option(Value, "end_time2", translate("End Time2"))
hv.optional = false



return m
15 changes: 11 additions & 4 deletions luci-app-oaf/po/zh-cn/oaf.po
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,18 @@ msgstr "更新特征库失败,格式错误!"
msgid "Select feature file:"
msgstr "选择本地特征库文件:"

msgid "Start Time"
msgstr "开始时间"
msgid "Start Time1"
msgstr "开始时间1"

msgid "End Time"
msgstr "结束时间"
msgid "End Time1"
msgstr "结束时间1"


msgid "Start Time2"
msgstr "开始时间2"

msgid "End Time2"
msgstr "结束时间2"

msgid "App Name"
msgstr "App名称"
Expand Down
2 changes: 0 additions & 2 deletions luci-app-oaf/root/etc/uci-defaults/91_luci-oaf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ EOF

# remove LuCI cache
rm -rf /tmp/luci-indexcache /tmp/luci-modulecache

exit 0
8 changes: 8 additions & 0 deletions luci-app-oaf/root/etc/uci-defaults/92_oaf_time
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

uci -q batch <<-EOF >/dev/null
set appfilter.time.time_mode="0"
set appfilter.time.start_time2=""
set appfilter.time.end_time2=""
commit appfilter
EOF
22 changes: 17 additions & 5 deletions oaf/src/af_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,22 @@ af_client_info_t *find_af_client(unsigned char *mac)
{
if (0 == memcmp(node->mac, mac, 6))
{
node->update_jiffies = jiffies;
return node;
}
}
return NULL;
}
}

af_client_info_t *find_and_add_af_client(unsigned char *mac)
{
af_client_info_t *nfc;
nfc = find_af_client(mac);
if (!nfc){
nfc = nf_client_add(mac);
}
return nfc;
}


af_client_info_t *find_af_client_by_ip(unsigned int ip)
{
Expand All @@ -128,7 +138,7 @@ af_client_info_t *find_af_client_by_ip(unsigned int ip)
return NULL;
}

static af_client_info_t *
af_client_info_t *
nf_client_add(unsigned char *mac)
{
af_client_info_t *node;
Expand All @@ -154,6 +164,9 @@ nf_client_add(unsigned char *mac)
return node;
}




void check_client_expire(void)
{
af_client_info_t *node;
Expand Down Expand Up @@ -243,8 +256,6 @@ int __af_visit_info_report(af_client_info_t *node)
{
if (node->visit_info[i].app_id == 0)
continue;
if (node->visit_info[i].total_num < 3)
continue;
count++;
visit_obj = cJSON_CreateObject();
cJSON_AddNumberToObject(visit_obj, "appid", node->visit_info[i].app_id);
Expand Down Expand Up @@ -373,6 +384,7 @@ static u_int32_t af_client_hook(unsigned int hook,
if (nfc && nfc->ip != iph->saddr)
{
AF_DEBUG("update node " MAC_FMT " ip %pI4--->%pI4\n", MAC_ARRAY(nfc->mac), &nfc->ip, &iph->saddr);
nfc->update_jiffies = jiffies;
nfc->ip = iph->saddr;
}
AF_CLIENT_UNLOCK_W();
Expand Down
3 changes: 3 additions & 0 deletions oaf/src/af_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ int af_client_init(void);

void af_client_exit(void);
af_client_info_t *find_af_client_by_ip(unsigned int ip);
af_client_info_t *find_af_client(unsigned char *mac);

void check_client_expire(void);

void af_visit_info_report(void);

void af_client_list_reset_report_num(void);
af_client_info_t *nf_client_add(unsigned char *mac);
af_client_info_t *find_and_add_af_client(unsigned char *mac);

#endif
11 changes: 9 additions & 2 deletions oaf/src/af_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include <linux/seq_file.h>
#include <linux/list.h>
#include <linux/sysctl.h>

#include "app_filter.h"
#include "af_log.h"
int af_log_lvl = 1;
int af_test_mode = 0;
// todo: rename af_log.c
int g_oaf_enable __read_mostly = 0;

int af_work_mode = AF_MODE_GATEWAY;
/*
cat /proc/sys/oaf/debug
*/
Expand All @@ -36,6 +36,13 @@ static struct ctl_table oaf_table[] = {
.mode = 0666,
.proc_handler = proc_dointvec,
},
{
.procname = "work_mode",
.data = &af_work_mode,
.maxlen = sizeof(int),
.mode = 0666,
.proc_handler = proc_dointvec,
},
{
}
};
Expand Down
1 change: 1 addition & 0 deletions oaf/src/af_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __AF_DEBUG_H__
extern int af_log_lvl;
extern int af_test_mode;
extern int af_work_mode;
#define LOG(level, fmt, ...) do { \
if ((level) <= af_log_lvl) { \
printk(fmt, ##__VA_ARGS__); \
Expand Down
21 changes: 21 additions & 0 deletions oaf/src/af_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ u_int32_t af_get_timestamp_sec(void)
#endif

}
char *k_trim(char *s)
{
char *start, *last, *bk;
int len;

start = s;
while (isspace(*start))
start++;

bk = last = s + strlen(s) - 1;
while (last > start && isspace(*last))
last--;

if ((s != start) || (bk != last))
{
len = last - start + 1;
strncpy(s, start, len);
s[len] = '\0';
}
return s;
}

int check_local_network_ip(unsigned int ip)
{
Expand Down
2 changes: 2 additions & 0 deletions oaf/src/af_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define AF_UTILS_H
u_int32_t af_get_timestamp_sec(void);

char *k_trim(char *s);

int check_local_network_ip(unsigned int ip);

void dump_str(char *name, unsigned char *p, int len);
Expand Down
Loading

0 comments on commit ef0ed9a

Please sign in to comment.