mirror of
https://github.com/kenzok8/small-package
synced 2025-09-20 19:11:30 +08:00
update-09.24
This commit is contained in:
18
luci-app-control-weburl/Makefile
Normal file
18
luci-app-control-weburl/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2016 Openwrt.org
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
LUCI_TITLE:=LuCI support for Weburl From Koolshare
|
||||
LUCI_DEPENDS:=+iptables-mod-filter +kmod-ipt-filter
|
||||
LUCI_PKGARCH:=all
|
||||
PKG_VERSION:=1.0
|
||||
PKG_RELEASE:=3-20190309
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
||||
|
||||
|
17
luci-app-control-weburl/luasrc/controller/weburl.lua
Normal file
17
luci-app-control-weburl/luasrc/controller/weburl.lua
Normal file
@ -0,0 +1,17 @@
|
||||
module("luci.controller.weburl", package.seeall)
|
||||
|
||||
function index()
|
||||
if not nixio.fs.access("/etc/config/weburl") then return end
|
||||
|
||||
entry({"admin", "control"}, firstchild(), "Control", 44).dependent = false
|
||||
entry({"admin", "control", "weburl"}, cbi("weburl"), _("网址过滤"), 12).dependent =
|
||||
true
|
||||
entry({"admin", "control", "weburl", "status"}, call("status")).leaf = true
|
||||
end
|
||||
|
||||
function status()
|
||||
local e = {}
|
||||
e.status = luci.sys.call("iptables -L FORWARD |grep WEBURL >/dev/null") == 0
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
36
luci-app-control-weburl/luasrc/model/cbi/weburl.lua
Normal file
36
luci-app-control-weburl/luasrc/model/cbi/weburl.lua
Normal file
@ -0,0 +1,36 @@
|
||||
local o = require "luci.sys"
|
||||
local a, t, e
|
||||
a = Map("weburl", translate("网址过滤"), translate(
|
||||
"在这里设置关键词过滤,可以是URL里任意字符,可以过滤如视频网站、QQ、迅雷、淘宝。。。"))
|
||||
a.template = "weburl/index"
|
||||
t = a:section(TypedSection, "basic", translate("Running Status"))
|
||||
t.anonymous = true
|
||||
e = t:option(DummyValue, "weburl_status", translate("当前状态"))
|
||||
e.template = "weburl/weburl"
|
||||
e.value = translate("Collecting data...")
|
||||
t = a:section(TypedSection, "basic", translate("基本设置"), translate(
|
||||
"一般来说普通过滤效果就很好了,强制过滤会使用更复杂的算法导致更高的CPU占用。"))
|
||||
t.anonymous = true
|
||||
e = t:option(Flag, "enable", translate("开启"))
|
||||
e.rmempty = false
|
||||
e = t:option(Flag, "algos", translate("强效过滤"))
|
||||
e.rmempty = false
|
||||
t = a:section(TypedSection, "macbind", translate("关键词设置"), translate(
|
||||
"黑名单MAC不设置为全客户端过滤,如设置只过滤指定的客户端。过滤时间可不设置。"))
|
||||
t.template = "cbi/tblsection"
|
||||
t.anonymous = true
|
||||
t.addremove = true
|
||||
e = t:option(Flag, "enable", translate("开启控制"))
|
||||
e.rmempty = false
|
||||
e = t:option(Value, "macaddr", translate("黑名单MAC"))
|
||||
e.rmempty = true
|
||||
o.net.mac_hints(function(t, a) e:value(t, "%s (%s)" % {t, a}) end)
|
||||
e = t:option(Value, "timeon", translate("开始过滤时间"))
|
||||
e.placeholder = "00:00"
|
||||
e.rmempty = true
|
||||
e = t:option(Value, "timeoff", translate("取消过滤时间"))
|
||||
e.placeholder = "23:59"
|
||||
e.rmempty = true
|
||||
e = t:option(Value, "keyword", translate("网址关键词"))
|
||||
e.rmempty = false
|
||||
return a
|
18
luci-app-control-weburl/luasrc/view/weburl/index.htm
Normal file
18
luci-app-control-weburl/luasrc/view/weburl/index.htm
Normal file
@ -0,0 +1,18 @@
|
||||
<%#
|
||||
Copyright 2016 Chen RuiWei <crwbak@gmail.com>
|
||||
Licensed to the public under the Apache License 2.0.
|
||||
-%>
|
||||
|
||||
<% include("cbi/map") %>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(2, '<%=luci.dispatcher.build_url("admin", "control", "weburl", "status")%>', null,
|
||||
function(x, result)
|
||||
{
|
||||
var status = document.getElementsByClassName('weburl_status')[0];
|
||||
status.setAttribute("style","font-weight:bold;");
|
||||
status.setAttribute("color",result.status ? "green":"red");
|
||||
status.innerHTML = result.status?'<%=translate("RUNNING")%>':'<%=translate("NOT RUNNING")%>';
|
||||
}
|
||||
)
|
||||
//]]>
|
||||
</script>
|
3
luci-app-control-weburl/luasrc/view/weburl/weburl.htm
Normal file
3
luci-app-control-weburl/luasrc/view/weburl/weburl.htm
Normal file
@ -0,0 +1,3 @@
|
||||
<%+cbi/valueheader%>
|
||||
<font class="weburl_status"><%=pcdata(self:cfgvalue(section) or self.default or "")%></font>
|
||||
<%+cbi/valuefooter%>
|
2
luci-app-control-weburl/po/zh-cn/weburl.po
Normal file
2
luci-app-control-weburl/po/zh-cn/weburl.po
Normal file
@ -0,0 +1,2 @@
|
||||
msgid "Control"
|
||||
msgstr "管控"
|
1
luci-app-control-weburl/po/zh_Hans
Symbolic link
1
luci-app-control-weburl/po/zh_Hans
Symbolic link
@ -0,0 +1 @@
|
||||
zh-cn
|
22
luci-app-control-weburl/root/etc/config/weburl
Normal file
22
luci-app-control-weburl/root/etc/config/weburl
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
config basic
|
||||
option enable '0'
|
||||
option algos '0'
|
||||
|
||||
config macbind
|
||||
option keyword 'qq.com'
|
||||
option enable '0'
|
||||
option macaddr '00:0C:29:C8:99:9E'
|
||||
|
||||
config macbind
|
||||
option keyword 'taobao.com'
|
||||
option enable '0'
|
||||
|
||||
config macbind
|
||||
option enable '0'
|
||||
option keyword 'youku.com'
|
||||
|
||||
config macbind
|
||||
option enable '0'
|
||||
option keyword 'www'
|
||||
|
88
luci-app-control-weburl/root/etc/init.d/weburl
Executable file
88
luci-app-control-weburl/root/etc/init.d/weburl
Executable file
@ -0,0 +1,88 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
#
|
||||
# Copyright (C) 2015 OpenWrt-dist
|
||||
# Copyright (C) 2016 fw867 <ffkykzs@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
START=99
|
||||
|
||||
CONFIG=weburl
|
||||
|
||||
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}
|
||||
}
|
||||
|
||||
is_true() {
|
||||
case $1 in
|
||||
1|on|true|yes|enabled) echo 0;;
|
||||
*) echo 1;;
|
||||
esac
|
||||
}
|
||||
|
||||
load_config() {
|
||||
ENABLED=$(uci_get_by_type basic enable)
|
||||
return $(is_true $ENABLED)
|
||||
}
|
||||
|
||||
get_algo_mode(){
|
||||
case "$1" in
|
||||
0)
|
||||
echo "bm"
|
||||
;;
|
||||
1)
|
||||
echo "kmp"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
add_rule(){
|
||||
algos=$(uci_get_by_type basic algos)
|
||||
for i in $(seq 0 100)
|
||||
do
|
||||
enable=$(uci_get_by_type macbind enable '' $i)
|
||||
macaddr=$(uci_get_by_type macbind macaddr '' $i)
|
||||
timeon=$(uci_get_by_type macbind timeon '' $i)
|
||||
timeoff=$(uci_get_by_type macbind timeoff '' $i)
|
||||
keyword=$(uci_get_by_type macbind keyword '' $i)
|
||||
if [ -z $enable ] || [ -z $keyword ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
if [ -z $timeon ] || [ -z $timeoff ]; then
|
||||
settime=""
|
||||
else
|
||||
settime="-m time --kerneltz --timestart $timeon --timestop $timeoff"
|
||||
fi
|
||||
|
||||
if [ "$enable" == "1" ]; then
|
||||
if [ -z $macaddr ]; then
|
||||
iptables -t filter -I WEBURL $settime -m string --string "$keyword" --algo $(get_algo_mode $algos) -j DROP
|
||||
else
|
||||
iptables -t filter -I WEBURL $settime -m mac --mac-source $macaddr -m string --string "$keyword" --algo $(get_algo_mode $algos) -j DROP
|
||||
unset "$macaddr"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
start(){
|
||||
! load_config && exit 0
|
||||
iptables -L FORWARD | grep -c WEBURL 2>/dev/null && [ $? -eq 0 ] && exit 0;
|
||||
iptables -t filter -N WEBURL
|
||||
iptables -t filter -I FORWARD -m comment --comment "Rule For Control" -j WEBURL
|
||||
add_rule
|
||||
}
|
||||
stop(){
|
||||
iptables -t filter -D FORWARD -m comment --comment "Rule For Control" -j WEBURL
|
||||
iptables -t filter -F WEBURL
|
||||
iptables -t filter -X WEBURL
|
||||
}
|
||||
|
11
luci-app-control-weburl/root/etc/uci-defaults/luci-app-control-weburl
Executable file
11
luci-app-control-weburl/root/etc/uci-defaults/luci-app-control-weburl
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@weburl[-1]
|
||||
add ucitrack weburl
|
||||
set ucitrack.@weburl[-1].init=weburl
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
rm -f /tmp/luci-indexcache
|
||||
exit 0
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-control-weburl": {
|
||||
"description": "Grant UCI access for luci-app-control-weburl",
|
||||
"read": {
|
||||
"uci": [ "weburl" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "weburl" ]
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user