mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-17 21:03:30 +00:00
luci-app-adbyby-plus: less debug logs
This commit is contained in:
parent
97700ac6f6
commit
5e271e43e3
@ -1,167 +1,209 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
local NXFS = require "nixio.fs"
|
||||
local SYS = require "luci.sys"
|
||||
local HTTP = require "luci.http"
|
||||
local DISP = require "luci.dispatcher"
|
||||
START=99
|
||||
STOP=10
|
||||
|
||||
local DL = SYS.exec("head -1 /tmp/adbyby/data/lazy.txt | awk -F' ' '{print $3,$4}'") or ""
|
||||
local DV = SYS.exec("head -1 /tmp/adbyby/data/video.txt | awk -F' ' '{print $3,$4}'") or ""
|
||||
local NR = SYS.exec("grep -v '^!' /usr/share/adbyby/data/rules.txt | wc -l")
|
||||
local NU = SYS.exec("cat /usr/share/adbyby/data/user.txt | wc -l")
|
||||
local UD = NXFS.readfile("/tmp/adbyby.updated") or "1970-01-01 00:00:00"
|
||||
local ND = SYS.exec("cat /usr/share/adbyby/dnsmasq.adblock | wc -l")
|
||||
EXTRA_COMMANDS="add_rule del_rule reload_rule"
|
||||
PROG_PATH=/usr/share/adbyby
|
||||
DATA_PATH=$PROG_PATH/data
|
||||
WAN_FILE=/var/etc/dnsmasq-adbyby.d/03-adbyby-ipset.conf
|
||||
CRON_FILE=/etc/crontabs/root
|
||||
CONFIG=adbyby
|
||||
ipt_n="iptables -t nat"
|
||||
|
||||
m = Map("adbyby")
|
||||
m.title = translate("Adbyby Plus +")
|
||||
m.description = translate("Adbyby Plus + can filter all kinds of banners, popups, video ads, and prevent tracking, privacy theft and a variety of malicious websites<br /><font color=\"red\">Plus + version combination mode can operation with Adblock Plus Host,filtering ads without losing bandwidth</font>")
|
||||
|
||||
m:section(SimpleSection).template = "adbyby/adbyby_status"
|
||||
get_config()
|
||||
{
|
||||
config_get_bool enable $1 enable
|
||||
config_get_bool cron_mode $1 cron_mode
|
||||
config_get wan_mode $1 wan_mode
|
||||
config_get_bool block_ios $1 block_ios 0
|
||||
config_get_bool mem_mode $1 mem_mode 1
|
||||
}
|
||||
|
||||
s = m:section(TypedSection, "adbyby")
|
||||
s.anonymous = true
|
||||
add_rules()
|
||||
{
|
||||
rm -f $DATA_PATH/user.bin
|
||||
grep -v ^! $PROG_PATH/rules.txt > $DATA_PATH/user.txt
|
||||
cp $PROG_PATH/rules.txt $DATA_PATH/rules.txt
|
||||
}
|
||||
|
||||
s:tab("basic", translate("Base Setting"))
|
||||
|
||||
o = s:taboption("basic", Flag, "enable")
|
||||
o.title = translate("Enable")
|
||||
o.default = 0
|
||||
o.rmempty = false
|
||||
add_cron()
|
||||
{
|
||||
if [ $cron_mode -eq 1 ]; then
|
||||
sed -i '/adblock.sh/d' $CRON_FILE
|
||||
echo '0 6 * * * /usr/share/adbyby/adblock.sh > /tmp/adupdate.log 2>&1' >> $CRON_FILE
|
||||
crontab $CRON_FILE
|
||||
fi
|
||||
}
|
||||
|
||||
o = s:taboption("basic", ListValue, "wan_mode")
|
||||
o.title = translate("Running Mode")
|
||||
o:value("0", translate("Global Mode(The slowest, the best effects)"))
|
||||
o:value("1", translate("Plus + Mode(Filter domain name list and blacklist website.Recommended)"))
|
||||
o:value("2", translate("No filter Mode (Must set in Client Filter Mode Settings manually)"))
|
||||
o.default = 1
|
||||
o.rmempty = false
|
||||
del_cron()
|
||||
{
|
||||
sed -i '/adblock.sh/d' $CRON_FILE
|
||||
/etc/init.d/cron restart
|
||||
}
|
||||
|
||||
o = s:taboption("basic", Button, "restart")
|
||||
o.title = translate("Adbyby and Rule state")
|
||||
o.inputtitle = translate("Restart Adbyby")
|
||||
o.description = string.format("<strong>Last Update Checked:</strong> %s<br /><strong>Lazy Rule:</strong>%s <br /><strong>Video Rule:</strong>%s", UD, DL, DV)
|
||||
o.inputstyle = "reload"
|
||||
o.write = function()
|
||||
SYS.call("rm -rf /tmp/adbyby.updated && /usr/share/adbyby/admem.sh > /tmp/adupdate.log 2>&1 &")
|
||||
SYS.call("sleep 5")
|
||||
HTTP.redirect(DISP.build_url("admin", "services", "adbyby"))
|
||||
end
|
||||
ip_rule()
|
||||
{
|
||||
|
||||
s:tab("advanced", translate("Advance Setting"))
|
||||
ipset -N adbyby_esc hash:ip
|
||||
$ipt_n -A ADBYBY -m set --match-set adbyby_esc dst -j RETURN
|
||||
|
||||
for i in $(seq 0 100)
|
||||
do
|
||||
local ip=$(uci_get_by_type acl_rule ipaddr '' $i)
|
||||
local mode=$(uci_get_by_type acl_rule filter_mode '' $i)
|
||||
case "$mode" in
|
||||
disable)
|
||||
$ipt_n -A ADBYBY -s $ip -j RETURN
|
||||
;;
|
||||
global)
|
||||
$ipt_n -A ADBYBY -s $ip -p tcp -j REDIRECT --to-ports 8118
|
||||
$ipt_n -A ADBYBY -s $ip -j RETURN
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
|
||||
case $wan_mode in
|
||||
0)
|
||||
;;
|
||||
1)
|
||||
ipset -N adbyby_wan hash:ip
|
||||
$ipt_n -A ADBYBY -m set ! --match-set adbyby_wan dst -j RETURN
|
||||
;;
|
||||
2)
|
||||
$ipt_n -I ADBYBY -j RETURN
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "create blockip hash:net family inet hashsize 1024 maxelem 65536" > /tmp/blockip.ipset
|
||||
awk '!/^$/&&!/^#/{printf("add blockip %s'" "'\n",$0)}' /usr/share/adbyby/blockip.conf >> /tmp/blockip.ipset
|
||||
ipset -! restore < /tmp/blockip.ipset 2>/dev/null
|
||||
iptables -I FORWARD -m set --match-set blockip dst -j DROP
|
||||
iptables -I OUTPUT -m set --match-set blockip dst -j DROP
|
||||
}
|
||||
|
||||
o = s:taboption("advanced", Flag, "cron_mode")
|
||||
o.title = translate("Update the rule at 6 a.m. every morning and restart adbyby")
|
||||
o.default = 0
|
||||
o.rmempty = false
|
||||
o.description = translate(string.format("<strong><font color=blue>Adblock Plus Host List:</font></strong> %s Lines<br /><br />", ND))
|
||||
add_dns()
|
||||
{
|
||||
mkdir -p /var/etc/dnsmasq-adbyby.d
|
||||
mkdir -p /tmp/dnsmasq.d
|
||||
awk '!/^$/&&!/^#/{printf("ipset=/%s/'"adbyby_esc"'\n",$0)}' $PROG_PATH/adesc.conf > /var/etc/dnsmasq-adbyby.d/06-dnsmasq.esc
|
||||
awk '!/^$/&&!/^#/{printf("address=/%s/'"0.0.0.0"'\n",$0)}' $PROG_PATH/adblack.conf > /var/etc/dnsmasq-adbyby.d/07-dnsmasq.black
|
||||
cat > /tmp/dnsmasq.d/dnsmasq-adbyby.conf <<EOF
|
||||
conf-dir=/var/etc/dnsmasq-adbyby.d
|
||||
EOF
|
||||
|
||||
local var=1
|
||||
if [ $wan_mode -eq 1 ]; then
|
||||
awk '!/^$/&&!/^#/{printf("ipset=/%s/'"adbyby_wan"'\n",$0)}' $PROG_PATH/adhost.conf > $WAN_FILE
|
||||
if ls /var/etc/dnsmasq-adbyby.d/* >/dev/null 2>&1; then
|
||||
mkdir -p /tmp/dnsmasq.d
|
||||
cp /usr/share/adbyby/dnsmasq.adblock /var/etc/dnsmasq-adbyby.d/04-dnsmasq.adblock
|
||||
cp /usr/share/adbyby/dnsmasq.ads /var/etc/dnsmasq-adbyby.d/05-dnsmasq.ads
|
||||
fi
|
||||
fi
|
||||
|
||||
sed -i '/mesu.apple.com/d' /etc/dnsmasq.conf && [ $block_ios -eq 1 ] && echo 'address=/mesu.apple.com/0.0.0.0' >> /etc/dnsmasq.conf
|
||||
}
|
||||
|
||||
updatead = s:taboption("advanced", Button, "updatead", translate("Manually force update<br />Adblock Plus Host List"), translate("Note: It needs to download and convert the rules. The background process may takes 60-120 seconds to run. <br / > After completed it would automatically refresh, please do not duplicate click!"))
|
||||
updatead.inputtitle = translate("Manually force update")
|
||||
updatead.inputstyle = "apply"
|
||||
updatead.write = function()
|
||||
SYS.call("nohup sh /usr/share/adbyby/adblock.sh > /tmp/adupdate.log 2>&1 &")
|
||||
end
|
||||
del_dns()
|
||||
{
|
||||
rm -f /tmp/dnsmasq.d/dnsmasq-adbyby.conf
|
||||
rm -f /var/etc/dnsmasq-adbyby.d/*
|
||||
rm -f /tmp/adbyby_host.conf
|
||||
}
|
||||
|
||||
o = s:taboption("advanced", Flag, "block_ios")
|
||||
o.title = translate("Block Apple iOS OTA update")
|
||||
o.default = 0
|
||||
o.rmempty = false
|
||||
|
||||
s:tab("help", translate("Plus+ Domain List"))
|
||||
add_rule()
|
||||
{
|
||||
$ipt_n -N ADBYBY
|
||||
$ipt_n -A ADBYBY -d 0.0.0.0/8 -j RETURN
|
||||
$ipt_n -A ADBYBY -d 10.0.0.0/8 -j RETURN
|
||||
$ipt_n -A ADBYBY -d 127.0.0.0/8 -j RETURN
|
||||
$ipt_n -A ADBYBY -d 169.254.0.0/16 -j RETURN
|
||||
$ipt_n -A ADBYBY -d 172.16.0.0/12 -j RETURN
|
||||
$ipt_n -A ADBYBY -d 192.168.0.0/16 -j RETURN
|
||||
$ipt_n -A ADBYBY -d 224.0.0.0/4 -j RETURN
|
||||
$ipt_n -A ADBYBY -d 240.0.0.0/4 -j RETURN
|
||||
ip_rule
|
||||
$ipt_n -A ADBYBY -p tcp -j REDIRECT --to-ports 8118
|
||||
$ipt_n -I PREROUTING -p tcp --dport 80 -j ADBYBY
|
||||
}
|
||||
|
||||
local conf = "/usr/share/adbyby/adhost.conf"
|
||||
o = s:taboption("help", TextValue, "conf")
|
||||
o.description = translate("(!)Note that you should fill to the domain name ONLY. For example, http://www.baidu.com only needs to write to baidu.com. One line for each")
|
||||
o.rows = 13
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section)
|
||||
return NXFS.readfile(conf) or ""
|
||||
end
|
||||
o.write = function(self, section, value)
|
||||
NXFS.writefile(conf, value:gsub("\r\n", "\n"))
|
||||
--SYS.call("/etc/init.d/adbyby restart")
|
||||
end
|
||||
del_rule()
|
||||
{
|
||||
$ipt_n -D PREROUTING -p tcp --dport 80 -j ADBYBY 2>/dev/null
|
||||
$ipt_n -F ADBYBY 2>/dev/null
|
||||
$ipt_n -X ADBYBY 2>/dev/null
|
||||
iptables -D FORWARD -m set --match-set blockip dst -j DROP 2>/dev/null
|
||||
iptables -D OUTPUT -m set --match-set blockip dst -j DROP 2>/dev/null
|
||||
ipset -F adbyby_esc 2>/dev/null
|
||||
ipset -X adbyby_esc 2>/dev/null
|
||||
ipset -F adbyby_wan 2>/dev/null
|
||||
ipset -X adbyby_wan 2>/dev/null
|
||||
ipset -F blockip 2>/dev/null
|
||||
ipset -X blockip 2>/dev/null
|
||||
}
|
||||
|
||||
s:tab("esc", translate("Bypass Domain List"))
|
||||
reload_rule()
|
||||
{
|
||||
config_load adbyby
|
||||
config_foreach get_config adbyby
|
||||
del_rule
|
||||
iptables-save | grep ADBYBY >/dev/null || \
|
||||
add_rule
|
||||
}
|
||||
|
||||
local escconf = "/usr/share/adbyby/adesc.conf"
|
||||
o = s:taboption("esc", TextValue, "escconf")
|
||||
o.description = translate("(!)Will Never filter these Domain")
|
||||
o.rows = 13
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section)
|
||||
return NXFS.readfile(escconf) or ""
|
||||
end
|
||||
o.write = function(self, section, value)
|
||||
NXFS.writefile(escconf, value:gsub("\r\n", "\n"))
|
||||
--SYS.call("/etc/init.d/adbyby restart")
|
||||
end
|
||||
start()
|
||||
{
|
||||
config_load adbyby
|
||||
config_foreach get_config adbyby
|
||||
[ $enable -eq 0 ] && exit 0
|
||||
add_cron
|
||||
[ ! -d "/tmp/adbyby/data" ] && cp -a /usr/share/adbyby /tmp/ && rm -f /tmp/adbyby.updated
|
||||
/usr/share/adbyby/admem.sh &>/dev/null &
|
||||
add_rules
|
||||
/tmp/adbyby/adbyby &>/dev/null &
|
||||
add_dns
|
||||
iptables-save | grep ADBYBY >/dev/null || \
|
||||
add_rule
|
||||
/etc/init.d/dnsmasq reload
|
||||
}
|
||||
|
||||
s:tab("black", translate("Black Domain List"))
|
||||
stop()
|
||||
{
|
||||
config_load adbyby
|
||||
config_foreach get_config adbyby
|
||||
del_rule
|
||||
del_cron
|
||||
del_dns
|
||||
kill -9 $(ps | grep 'admem.sh' | grep -v grep | awk '{print $1}') >/dev/null 2>&1
|
||||
kill -9 $(ps | grep '/tmp/adbyby/adbyby' | grep -v grep | awk '{print $1}') >/dev/null 2>&1
|
||||
/etc/init.d/dnsmasq reload
|
||||
}
|
||||
|
||||
local blackconf = "/usr/share/adbyby/adblack.conf"
|
||||
o = s:taboption("black", TextValue, "blackconf")
|
||||
o.description = translate("(!)Will Always block these Domain")
|
||||
o.rows = 13
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section)
|
||||
return NXFS.readfile(blackconf) or ""
|
||||
end
|
||||
o.write = function(self, section, value)
|
||||
NXFS.writefile(blackconf, value:gsub("\r\n", "\n"))
|
||||
--SYS.call("/etc/init.d/adbyby restart")
|
||||
end
|
||||
boot()
|
||||
{
|
||||
mkdir -p /tmp/adbyby && cp -a /usr/share/adbyby /tmp/
|
||||
start
|
||||
}
|
||||
|
||||
s:tab("block", translate("Black IP List"))
|
||||
|
||||
local blockconf = "/usr/share/adbyby/blockip.conf"
|
||||
o = s:taboption("block", TextValue, "blockconf")
|
||||
o.description = translate("(!)Will Always block these IP")
|
||||
o.rows = 13
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section)
|
||||
return NXFS.readfile(blockconf) or " "
|
||||
end
|
||||
o.write = function(self, section, value)
|
||||
NXFS.writefile(blockconf, value:gsub("\r\n", "\n"))
|
||||
--SYS.call("/etc/init.d/adbyby restart")
|
||||
end
|
||||
uci_get_by_name() {
|
||||
local ret=$(uci get $CONFIG.$1.$2 2>/dev/null)
|
||||
echo ${ret:=$3}
|
||||
}
|
||||
|
||||
s:tab("user", translate("User-defined Rule"))
|
||||
uci_get_by_type() {
|
||||
local index=0
|
||||
if [ -n $4 ]; then
|
||||
|
||||
index=$4
|
||||
fi
|
||||
local ret=$(uci get $CONFIG.@$1[$index].$2 2>/dev/null)
|
||||
echo ${ret:=$3}
|
||||
}
|
||||
|
||||
local file = "/usr/share/adbyby/rules.txt"
|
||||
o = s:taboption("user", TextValue, "rules")
|
||||
o.description = translate("Each line of the beginning exclamation mark is considered an annotation.")
|
||||
o.rows = 13
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section)
|
||||
return NXFS.readfile(file) or ""
|
||||
end
|
||||
o.write = function(self, section, value)
|
||||
NXFS.writefile(file, value:gsub("\r\n", "\n"))
|
||||
end
|
||||
|
||||
t=m:section(TypedSection,"acl_rule",translate("<strong>Client Filter Mode Settings</strong>"),
|
||||
translate("Filter mode settings can be set to specific LAN clients ( <font color=blue> No filter , Global filter </font> ) . Does not need to be set by default."))
|
||||
t.template="cbi/tblsection"
|
||||
t.sortable=true
|
||||
t.anonymous=true
|
||||
t.addremove=true
|
||||
|
||||
e=t:option(Value,"ipaddr",translate("IP Address"))
|
||||
e.width="40%"
|
||||
e.datatype="ip4addr"
|
||||
e.placeholder="0.0.0.0/0"
|
||||
luci.ip.neighbors({ family = 4 }, function(entry)
|
||||
if entry.reachable then
|
||||
e:value(entry.dest:string())
|
||||
end
|
||||
end)
|
||||
|
||||
e=t:option(ListValue,"filter_mode",translate("Filter Mode"))
|
||||
e.width="40%"
|
||||
e.default="disable"
|
||||
e.rmempty=false
|
||||
e:value("disable",translate("No filter"))
|
||||
e:value("global",translate("Global filter"))
|
||||
|
||||
return m
|
||||
|
Loading…
Reference in New Issue
Block a user