├── LICENSE ├── Makefile ├── README.md ├── files ├── luci │ ├── controller │ │ └── koolproxy.lua │ ├── i18n │ │ └── koolproxy.zh-cn.po │ ├── model │ │ └── cbi │ │ │ ├── koolproxy-custom.lua │ │ │ └── koolproxy-general.lua │ └── view │ │ └── koolproxy │ │ ├── dynamiclist.htm │ │ └── kplist.htm └── root │ └── etc │ ├── config │ └── koolproxy │ ├── init.d │ └── koolproxy │ ├── koolproxy │ ├── firewall.include │ └── user.txt │ └── uci-defaults │ └── luci-koolproxy └── preview.png /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 chenhw2 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 chenhw2 3 | # 4 | # See /LICENSE for more information. 5 | # 6 | 7 | include $(TOPDIR)/rules.mk 8 | 9 | PKG_NAME:=luci-app-koolproxy 10 | PKG_VERSION:=0.2.5 11 | PKG_RELEASE:=3 12 | 13 | PKG_LICENSE:=MIT 14 | PKG_LICENSE_FILES:=LICENSE 15 | PKG_MAINTAINER:=chenhw2 16 | 17 | PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) 18 | 19 | include $(INCLUDE_DIR)/package.mk 20 | 21 | define Package/luci-app-koolproxy 22 | SECTION:=luci 23 | CATEGORY:=LuCI 24 | SUBMENU:=3. Applications 25 | TITLE:=LuCI Support for KoolProxy 26 | PKGARCH:=all 27 | DEPENDS:=+curl +ipset 28 | endef 29 | 30 | define Package/luci-app-koolproxy/description 31 | LuCI Support for KoolProxy. 32 | endef 33 | 34 | define Build/Prepare 35 | $(foreach po,$(wildcard ${CURDIR}/files/luci/i18n/*.po), \ 36 | po2lmo $(po) $(PKG_BUILD_DIR)/$(patsubst %.po,%.lmo,$(notdir $(po)));) 37 | endef 38 | 39 | define Build/Configure 40 | endef 41 | 42 | define Build/Compile 43 | endef 44 | 45 | define Package/luci-app-koolproxy/postinst 46 | #!/bin/sh 47 | if [ -z "$${IPKG_INSTROOT}" ]; then 48 | if [ -f /etc/uci-defaults/luci-koolproxy ]; then 49 | ( . /etc/uci-defaults/luci-koolproxy ) && \ 50 | rm -f /etc/uci-defaults/luci-koolproxy 51 | fi 52 | rm -rf /tmp/luci-indexcache /tmp/luci-modulecache 53 | fi 54 | exit 0 55 | endef 56 | 57 | define Package/luci-app-koolproxy/prerm 58 | /etc/init.d/koolproxy stop 59 | endef 60 | 61 | define Package/luci-app-koolproxy/conffiles 62 | /etc/config/koolproxy 63 | /etc/koolproxy/user.txt 64 | endef 65 | 66 | define Package/luci-app-koolproxy/install 67 | $(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n 68 | $(INSTALL_DATA) $(PKG_BUILD_DIR)/koolproxy.*.lmo $(1)/usr/lib/lua/luci/i18n/ 69 | $(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller 70 | $(INSTALL_DATA) ./files/luci/controller/*.lua $(1)/usr/lib/lua/luci/controller/ 71 | $(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi 72 | $(INSTALL_DATA) ./files/luci/model/cbi/*.lua $(1)/usr/lib/lua/luci/model/cbi/ 73 | $(INSTALL_DIR) $(1)/usr/lib/lua/luci/view/koolproxy 74 | $(INSTALL_DATA) ./files/luci/view/koolproxy/*.htm $(1)/usr/lib/lua/luci/view/koolproxy/ 75 | $(INSTALL_DIR) $(1)/etc/koolproxy 76 | $(INSTALL_DATA) ./files/root/etc/koolproxy/{firewall.include,user.txt} $(1)/etc/koolproxy/ 77 | $(INSTALL_DIR) $(1)/etc/config 78 | $(INSTALL_DATA) ./files/root/etc/config/koolproxy $(1)/etc/config/koolproxy 79 | $(INSTALL_DIR) $(1)/etc/init.d 80 | $(INSTALL_BIN) ./files/root/etc/init.d/koolproxy $(1)/etc/init.d/koolproxy 81 | $(INSTALL_DIR) $(1)/etc/uci-defaults 82 | $(INSTALL_BIN) ./files/root/etc/uci-defaults/luci-koolproxy $(1)/etc/uci-defaults/luci-koolproxy 83 | 84 | endef 85 | 86 | $(eval $(call BuildPackage,luci-app-koolproxy)) 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OpenWrt/LEDE LuCI for KoolProxy 2 | === 3 | Deprecated. 4 | 5 | 前言 6 | --- 7 | 感謝 [koolshare.cn][koolshare] 提供 ```KoolProxy```, 使用风险由用户自行承担 8 | 本程序运行需要联网下载最新的 ```KoolProxy``` 到内存中运行, 也正因此本程序大小可以忽略不计. 9 | 10 | 简介 11 | --- 12 | 13 | 本软件包是 KoolProxy 的 LuCI 控制界面, 14 | 15 | 软件包文件结构: 16 | ``` 17 | / 18 | ├── etc/ 19 | │   ├── config/ 20 | │   │   └── koolproxy // UCI 配置文件 21 | │   │── init.d/ 22 | │   │   └── koolproxy // init 脚本 23 | │ ├── koolproxy 24 | │ │   ├── firewall.include // firewall 脚本 25 | │   └── uci-defaults/ 26 | │      └── luci-koolproxy // uci-defaults 脚本 27 | └── usr/ 28 | └── lib/ 29 | └── lua/ 30 | └── luci/ // LuCI 部分 31 | ├── controller/ 32 | │ ├── koolproxy-custom.lua // LuCI 菜单配置:用户自定义规则 33 | │   └── koolproxy-general.lua // LuCI 菜单配置:基本设置 34 | ├── i18n/ // LuCI 语言文件目录 35 | │   └── koolproxy.zh-cn.lmo 36 | └── model/ 37 | └── cbi/ 38 | └── koolproxy.lua // LuCI 基本设置 39 | ``` 40 | 41 | 依赖 42 | --- 43 | 软件包的正常使用需要依赖 ```curl, dnsmasq-full, iptables, ipset``` 和 [dnsmasq-extra][openwrt-dnsmasq-extra]. 44 | 45 | 预览 46 | --- 47 | ![preview](https://github.com/chenhw2/luci-app-koolproxy/blob/master/preview.png) 48 | 49 | 配置 50 | --- 51 | 52 | 软件包的配置文件路径: `/etc/config/koolproxy` 53 | 此文件为 UCI 配置文件, 配置方式可参考 [Wiki -> Use-UCI-system][Use-UCI-system] 和 [OpenWrt Wiki][uci] 54 | 55 | 编译 56 | --- 57 | 58 | 从 OpenWrt 的 [SDK][openwrt-sdk] 编译 59 | ```bash 60 | # 解压下载好的 SDK 61 | tar xjf OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2 62 | cd OpenWrt-SDK-ar71xx-* 63 | # Clone 项目 64 | git clone https://github.com/chenhw2/luci-app-koolproxy.git package/feeds/luci-app-koolproxy 65 | # 编译 po2lmo (如果有po2lmo可跳过) 66 | pushd package/feeds/luci-app-koolproxy/tools/po2lmo 67 | make && sudo make install 68 | popd 69 | # 选择要编译的包 LuCI -> 3. Applications 70 | make menuconfig 71 | # 开始编译 72 | make package/feeds/luci-app-koolproxy/compile V=s 73 | ``` 74 | 75 | [openwrt-sdk]: https://wiki.openwrt.org/doc/howto/obtain.firmware.sdk 76 | [Use-UCI-system]: https://github.com/shadowsocks/luci-app-shadowsocks/wiki/Use-UCI-system 77 | [uci]: https://wiki.openwrt.org/doc/uci 78 | [openwrt-dnsmasq-extra]: https://github.com/chenhw2/openwrt-dnsmasq-extra 79 | [koolshare]: http://koolshare.cn/thread-64086-1-1.html 80 | -------------------------------------------------------------------------------- /files/luci/controller/koolproxy.lua: -------------------------------------------------------------------------------- 1 | -- Copyright (C) 2016 chenhw2 2 | -- Licensed to the public under the MIT License. 3 | 4 | module("luci.controller.koolproxy", package.seeall) 5 | 6 | function index() 7 | entry({"admin", "services", "koolproxy"}, 8 | alias("admin", "services", "koolproxy", "general"), 9 | _("KoolProxy"), 50) 10 | 11 | entry({"admin", "services", "koolproxy", "general"}, 12 | cbi("koolproxy-general"), _("General Settings"), 10).leaf = true 13 | 14 | entry({"admin", "services", "koolproxy", "custom"}, 15 | cbi("koolproxy-custom"), _("User Custom"), 20).leaf = true 16 | 17 | entry({"admin", "services", "koolproxy", "log"}, 18 | call("action_log"), _("System Log"), 30).leaf = true 19 | 20 | if luci.sys.call("command -v /etc/init.d/dnsmasq-extra >/dev/null") ~= 0 then 21 | return 22 | end 23 | 24 | entry({"admin", "services", "koolproxy", "kplist"}, 25 | call("action_kplist"), _("KP-List"), 15).leaf = true 26 | 27 | end 28 | 29 | function action_log() 30 | local fs = require "nixio.fs" 31 | local conffile = "/var/log/koolproxy_watchdog.log" 32 | local watchdog = fs.readfile(conffile) or "" 33 | luci.template.render("admin_status/syslog", {syslog=watchdog}) 34 | end 35 | 36 | function action_kplist() 37 | local fs = require "nixio.fs" 38 | local conffile = "/etc/dnsmasq-extra.d/koolproxy" 39 | local kplist = fs.readfile(conffile) or "" 40 | luci.template.render("/koolproxy/kplist", {kplist=kplist}) 41 | end 42 | -------------------------------------------------------------------------------- /files/luci/i18n/koolproxy.zh-cn.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "Content-Type: text/plain; charset=UTF-8\n" 3 | 4 | msgid "Enable" 5 | msgstr "启用" 6 | 7 | msgid "General Setting" 8 | msgstr "基本设置" 9 | 10 | msgid "ByPass LAN" 11 | msgstr "不去广告的内网主机" 12 | 13 | msgid "Version" 14 | msgstr "版本" 15 | 16 | msgid "Rules" 17 | msgstr "规则" 18 | 19 | msgid "User Custom" 20 | msgstr "用户自定义" 21 | 22 | msgid "Counts" 23 | msgstr "数量" 24 | 25 | msgid "ADBlock" 26 | msgstr "广告阻断" 27 | 28 | msgid "Extra arguments" 29 | msgstr "附加参数" 30 | 31 | msgid "None" 32 | msgstr "无" 33 | 34 | msgid "Proxy port numbers %s only" 35 | msgstr "仅代理 %s 端口" 36 | 37 | msgid "Passes additional arguments to iptables. Use with care!" 38 | msgstr "传递到iptables的额外参数。小心使用!" 39 | 40 | msgid "KP-List" 41 | msgstr "去广告域名列表" 42 | -------------------------------------------------------------------------------- /files/luci/model/cbi/koolproxy-custom.lua: -------------------------------------------------------------------------------- 1 | local fs = require "nixio.fs" 2 | local userrules = "/etc/koolproxy/user.txt" 3 | 4 | f = SimpleForm("User.txt", "%s %s" %{translate("User Custom"), translate("Rules")}) 5 | 6 | t = f:field(TextValue, "conf") 7 | t.rmempty = true 8 | t.rows = 30 9 | function t.cfgvalue() 10 | return fs.readfile(userrules) or "" 11 | end 12 | 13 | function f.handle(self, state, data) 14 | if state == FORM_VALID then 15 | if data.conf then 16 | fs.writefile(userrules, data.conf:gsub("\r\n", "\n")) 17 | luci.sys.call("/etc/init.d/koolproxy restart") 18 | end 19 | end 20 | return true 21 | end 22 | 23 | return f -------------------------------------------------------------------------------- /files/luci/model/cbi/koolproxy-general.lua: -------------------------------------------------------------------------------- 1 | -- Copyright (C) 2016 chenhw2 2 | -- Licensed to the public under the MIT License. 3 | 4 | local m, s, o 5 | 6 | if luci.sys.call("pgrep koolproxy >/dev/null") == 0 then 7 | m = Map("koolproxy", translate("KoolProxy"), "%s - %s" %{translate("KoolProxy"), translate("RUNNING")}) 8 | else 9 | m = Map("koolproxy", translate("KoolProxy"), "%s - %s" %{translate("KoolProxy"), translate("NOT RUNNING")}) 10 | end 11 | 12 | s = m:section(TypedSection, "general", translate("General Setting")) 13 | s.anonymous = true 14 | 15 | o = s:option(Flag, "enable", translate("Enable")) 16 | o.rmempty = false 17 | 18 | if luci.sys.call("command -v /var/run/koolproxy/kp >/dev/null") == 0 then 19 | o = s:option(DummyValue, "stat0", "%s %s" %{translate("KoolProxy"), translate("Version")}) 20 | o.value=string.format("[ %s ]", luci.sys.exec("/var/run/koolproxy/kp -v")) 21 | 22 | o = s:option(DummyValue, "stat1", "%s-%s %s" %{translate("KoolProxy"), translate("Rules"), translate("Version")}) 23 | o.value=string.format("%s", luci.sys.exec("head /var/run/koolproxy/data/rules/koolproxy.txt | sed -n '/]$/d; s/.*\\[/[/p'")) 24 | 25 | o = s:option(DummyValue, "stat2", "%s-%s %s" %{translate("KoolProxy"), translate("Rules"), translate("Counts")}) 26 | o.value=string.format("[ %s ]", luci.sys.exec("sed '/^!/d' /var/run/koolproxy/data/rules/koolproxy.txt | wc -l")) 27 | 28 | o = s:option(DummyValue, "stat3", "%s-%s %s" %{translate("User Custom"), translate("Rules"), translate("Counts")}) 29 | o.value=string.format("[ %s ]", luci.sys.exec("sed '/^!/d; /^[ \\t]*$/d' /var/run/koolproxy/data/rules/user.txt | wc -l")) 30 | 31 | o = s:option(DummyValue, "stat4", "%s-%s %s" %{translate("ADBlock"), translate("Hosts"), translate("Counts")}) 32 | o.value=string.format("[ %s ]", luci.sys.exec("wc -l /var/dnsmasq.d/adblock.conf | sed 's/ .*//g'")) 33 | 34 | end 35 | 36 | o = s:option(Value, "startup_delay", translate("Startup Delay")) 37 | o:value(0, translate("Not enabled")) 38 | for _, v in ipairs({5, 10, 15, 25, 40, 60, 120}) do 39 | o:value(v, translate("%u seconds") %{v}) 40 | end 41 | o.datatype = "uinteger" 42 | o.default = 0 43 | o.rmempty = false 44 | 45 | o = s:option(Value, "ipt_ext", translate("Extra arguments"), 46 | translate("Passes additional arguments to iptables. Use with care!")) 47 | o:value("", translate("None")) 48 | o:value("--dport 80:88", translatef("Proxy port numbers %s only", "80~88")) 49 | o:value("-m multiport --dports 80,88,8080", translatef("Proxy port numbers %s only", "80,88,8080")) 50 | 51 | o = s:option(DynamicList, "lan_bp_list", translate("ByPass LAN"), translate("e.g. aa:bb:cc:dd:ee:ff")) 52 | o.template = "koolproxy/dynamiclist" 53 | o:value("00:00:00:00:00:00", "%s (%s)" %{"00:00:00:00:00:00", "NULL"}) 54 | o.placeholder = "00:00:00:00:00:00" 55 | luci.sys.net.mac_hints(function(mac, name) 56 | o:value(mac, "%s (%s)" %{mac, name}) 57 | end) 58 | o.datatype = "macaddr" 59 | o.rmempty = false 60 | 61 | return m 62 | -------------------------------------------------------------------------------- /files/luci/view/koolproxy/dynamiclist.htm: -------------------------------------------------------------------------------- 1 | <%# 2 | Copyright (C) 2017 Jian Chang 3 | Licensed to the public under the GNU General Public License v3. 4 | -%> 5 | 6 | <%+cbi/valueheader%> 7 | 8 | <%- 9 | local values = self:formvalue(section) 10 | if not values then 11 | values = self:cfgvalue(section) or {self.default} 12 | end 13 | -%> 14 | 15 | > 16 | 69 | 70 | <%+cbi/valuefooter%> 71 | -------------------------------------------------------------------------------- /files/luci/view/koolproxy/kplist.htm: -------------------------------------------------------------------------------- 1 | <%+header%> 2 |
3 | 4 |
5 | <%+footer%> 6 | -------------------------------------------------------------------------------- /files/root/etc/config/koolproxy: -------------------------------------------------------------------------------- 1 | 2 | config general 3 | option enable 1 4 | option startup_delay '25' 5 | -------------------------------------------------------------------------------- /files/root/etc/init.d/koolproxy: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | 3 | START=99 4 | EXTRA_COMMANDS="rules watchdog" 5 | NAME=koolproxy 6 | 7 | CRON_FILE=/etc/crontabs/root 8 | 9 | curl_f="curl -ksSL" 10 | ipt_n="iptables -t nat" 11 | ipt_m="iptables -t mangle" 12 | 13 | uci_get_by_type() { 14 | local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null) 15 | echo ${ret:=$3} 16 | } 17 | 18 | uci_bool_by_type() { 19 | case "$(uci_get_by_type $1 $2)" in 20 | 1|on|true|yes|enabled) return 0;; 21 | esac 22 | return 1 23 | } 24 | 25 | detect_arch() { 26 | if [ -x /lib/ar71xx.sh -o -x /lib/functions/k2t.sh ]; then 27 | echo "mips" 28 | elif [ -x /lib/ramips.sh ]; then 29 | echo "mipsel" 30 | elif [ -x /lib/brcm2708.sh ]; then 31 | echo "arm" 32 | elif [ 0 -lt $(uname -m | grep -c 'x86_64') ]; then 33 | echo "x86_64" 34 | elif [ 0 -lt $(uname -m | grep -c 'armv7l') ]; then 35 | echo "arm" 36 | else 37 | echo "i386" 38 | fi 39 | } 40 | 41 | kill_all() { 42 | kill -9 $(pgrep -f $@) >/dev/null 2>&1 43 | } 44 | 45 | ipset_init() { 46 | ipset -! restore <<-EOF || return 1 47 | create kp_dst_bp hash:net hashsize 64 48 | create kp_src_bp hash:mac hashsize 64 49 | $(gen_special_purpose_ip | sed -e "s/^/add kp_dst_bp /") 50 | $(for lan in $(uci_get_by_type general lan_bp_list); do 51 | echo "add kp_src_bp $lan" 52 | done | grep -v '00:00:00:00:00:00') 53 | EOF 54 | return 0 55 | } 56 | 57 | gen_special_purpose_ip() { 58 | cat <<-EOF | grep -E "^([0-9]{1,3}\.){3}[0-9]{1,3}" 59 | 0.0.0.0/8 60 | 10.0.0.0/8 61 | 100.64.0.0/10 62 | 127.0.0.0/8 63 | 169.254.0.0/16 64 | 172.16.0.0/12 65 | 192.0.0.0/24 66 | 192.0.2.0/24 67 | 192.31.196.0/24 68 | 192.52.193.0/24 69 | 192.88.99.0/24 70 | 192.168.0.0/16 71 | 192.175.48.0/24 72 | 198.18.0.0/15 73 | 198.51.100.0/24 74 | 203.0.113.0/24 75 | 224.0.0.0/4 76 | 240.0.0.0/4 77 | 255.255.255.255 78 | EOF 79 | } 80 | 81 | delay_start() { 82 | (sleep $1 && start >/dev/null 2>&1) & 83 | } 84 | 85 | boot() { 86 | uci_bool_by_type general enable || return 0 87 | 88 | local delay=$(uci_get_by_type general start_delay 0) 89 | if [ "$delay" -gt 0 ]; then 90 | delay_start $delay 91 | else 92 | start 93 | fi 94 | return 0 95 | } 96 | 97 | start() { 98 | uci_bool_by_type general enable || return 0 99 | 100 | add_cron 101 | start_kp && rules 102 | } 103 | 104 | stop() { 105 | del_cron 106 | flush_rules 107 | kill_all /var/run/${NAME}/kp 108 | kill_all 'koolproxy.com/downloads' 109 | rm -rf /var/run/${NAME}/data 110 | 111 | # delete main program only if it is broken 112 | [ 5 -lt $(/var/run/${NAME}/kp -h 2>/dev/null | wc -l) ] || rm -rf /var/run/${NAME}/kp 113 | } 114 | 115 | restart(){ 116 | # force update by delete 117 | stop 118 | rm -rf /var/run/${NAME} 119 | start 120 | } 121 | 122 | start_kp() { 123 | mkdir -p /var/run/${NAME}/data/rules 124 | # koolproxy will download {kp.dat, koolproxy.txt, daily.txt} itself. 125 | ln -sf /etc/${NAME}/user.txt /var/run/${NAME}/data/rules/user.txt 126 | 127 | [ 5 -lt $(/var/run/${NAME}/kp -h 2>/dev/null | wc -l) ] || { 128 | $curl_f "https://koolproxy.com/downloads/$(detect_arch)" > /var/run/${NAME}/kp 129 | chmod +x /var/run/${NAME}/kp 130 | } 131 | 132 | /var/run/${NAME}/kp -d 133 | 134 | return $? 135 | } 136 | 137 | rules() { 138 | if !(pgrep -f /var/run/${NAME}/kp >/dev/null); then 139 | logger -st $NAME -p3 "${NAME} not running." 140 | return 1 141 | fi 142 | start_rules || flush_rules 143 | } 144 | 145 | start_rules() { 146 | flush_rules 147 | ipset_init 148 | 149 | $ipt_n -N KOOLPROXY 150 | $ipt_n -A KOOLPROXY -m set --match-set kp_src_bp src -j RETURN 151 | $ipt_n -A KOOLPROXY -m set --match-set kp_dst_bp dst -j RETURN 152 | $ipt_n -A KOOLPROXY -p tcp -j REDIRECT --to-port 3000 153 | 154 | # ipset create koolproxy hash:ip > /dev/null 2>&1 155 | ipt_ext=$(uci_get_by_type general ipt_ext '--dport 80') 156 | idx=$($ipt_n -L PREROUTING | tail -n +3 | sed -n -e '/^SSR*_SPEC/=') 157 | $ipt_n -I PREROUTING $((${idx} + 1)) -p tcp ${ipt_ext} -m set --match-set ${NAME} dst -j KOOLPROXY 158 | $ipt_m -I PREROUTING -p tcp ${ipt_ext} -m set --match-set ${NAME} dst -j RETURN 159 | } 160 | 161 | flush_rules() { 162 | $ipt_n -nL --line-numbers | sed -n 's/ .*koolproxy.*//p' | sort -r | while read idx; do $ipt_n -D PREROUTING $idx; done 163 | $ipt_m -nL --line-numbers | sed -n 's/ .*koolproxy.*//p' | sort -r | while read idx; do $ipt_m -D PREROUTING $idx; done 164 | $ipt_n -F KOOLPROXY > /dev/null 2>&1 165 | while $ipt_n -X KOOLPROXY > /dev/null 2>&1; do :; done 166 | for setname in $(ipset -n list | grep "kp_"); do 167 | ipset destroy $setname 2>/dev/null 168 | done 169 | } 170 | 171 | add_cron() { 172 | sed -i '/koolproxy_watchdog/d' $CRON_FILE 173 | echo '0 */3 * * * rm -f /var/log/koolproxy_watchdog.log 2>&1' >> $CRON_FILE 174 | echo '* * * * * /etc/init.d/koolproxy watchdog >> /var/log/koolproxy_watchdog.log 2>&1' >> $CRON_FILE 175 | echo '0 4 * * * /etc/init.d/koolproxy restart >> /var/log/koolproxy_watchdog.log 2>&1' >> $CRON_FILE 176 | /etc/init.d/cron restart 177 | } 178 | 179 | del_cron() { 180 | sed -i '/koolproxy_watchdog/d' $CRON_FILE 181 | /etc/init.d/cron restart 182 | } 183 | 184 | watchdog() { 185 | uci_bool_by_type general enable || { 186 | del_cron 187 | return 0 188 | } 189 | 190 | LOGTIME=$(date "+%Y-%m-%d %H:%M:%S") 191 | 192 | if [ "Z$(pgrep -f /var/run/${NAME}/kp)" = "Z" ]; then 193 | echo "[${LOGTIME}] Problem(0x01) decteted, restarting ${NAME}..." 194 | restart 195 | return $? 196 | fi 197 | 198 | # Check data: daily.txt koolproxy.txt kp.dat user.txt 199 | if [ $(ls -l /var/run/${NAME}/data/rules/ | wc -l) -lt 4 ]; then 200 | echo "[${LOGTIME}] Problem(0x02) decteted, restarting ${NAME}..." 201 | restart 202 | return $? 203 | fi 204 | 205 | for kp_data in $(ls /var/run/${NAME}/data/rules/ | grep -v user); do 206 | kp_data="/var/run/${NAME}/data/rules/${kp_data}" 207 | if [ ! -f "$kp_data" ] || [ $(ls -l "$kp_data" | awk '{print $5}') -lt 256 ]; then 208 | echo "[${LOGTIME}] Problem(0x04) decteted, restarting ${NAME}..." 209 | restart 210 | return $? 211 | fi 212 | done 213 | 214 | echo "[${LOGTIME}] ${NAME} No Problem." 215 | 216 | return 0 217 | } 218 | 219 | -------------------------------------------------------------------------------- /files/root/etc/koolproxy/firewall.include: -------------------------------------------------------------------------------- 1 | /etc/init.d/koolproxy rules 2 | -------------------------------------------------------------------------------- /files/root/etc/koolproxy/user.txt: -------------------------------------------------------------------------------- 1 | ! ******************************* koolproxy 自定义过滤语法简表 ******************************* 2 | ! ------------------------ 规则基于adblock规则,并进行了语法部分的扩展 ------------------------ 3 | ! ABP规则请参考https://adblockplus.org/zh_CN/filters,下面为大致摘要 4 | ! "!" 为行注释符,注释行以该符号起始作为一行注释语义,用于规则描述 5 | ! "@@" 为白名单符,白名单具有最高优先级,放行过滤的网站,例如:@@||taobao.com 6 | ! ------------------------------------------------------------------------------------------ 7 | ! "*" 为字符通配符,能够匹配0长度或任意长度的字符串,该通配符不能与正则语法混用。 8 | ! "^" 为分隔符,可以是除了字母、数字或者 _ - . % 之外的任何字符。 9 | ! "~" 为排除标识符,通配符能过滤大多数广告,但同时存在误杀, 可以通过排除标识符修正误杀链接。 10 | ! 注:通配符仅在 url 规则中支持,html 规则中不支持 11 | ! ------------------------------------------------------------------------------------------ 12 | ! "|" 为管线符号,来表示地址的最前端或最末端 13 | ! "||" 为子域通配符,方便匹配主域名下的所有子域 14 | ! 用法及例子如下:(以下等号表示等价于) 15 | ! ||xx.com/ad = http://xx.com/ad* || http://*.xx.com/ad* 16 | ! ||http://xx.com/ad = http://xx.com/ad* || http://*.xx.com/ad* 17 | ! ||https://xx.com/ad = https://xx.com/ad* || https://*.xx.com/ad* 18 | ! |xx.com/ad = http://xx.com/ad* 19 | ! |http://xx.com/ad = http://xx.com/ad* 20 | ! |https://xx.com/ad = https://xx.com/ad* 21 | ! ad = http://*ad* 22 | ! http://ad = http://*ad* 23 | ! https://ad = 不支持,需要指定域名,如下例 24 | ! https://xx.com/ad = |https://xx.com/ad = https://xx.com/ad* 25 | ! [同时可以表示两个以及两个以上的域名]如下例子 26 | ! https://xx.ad.com 和 https://xxx.xx.ad.com = ||https://ad.com (注意! 由于https的原因使用要非常谨慎,不可以大范围使用) 27 | ! ------------------------------------------------------------------------------------------ 28 | ! 兼容adblock规则的html规则语法,例如: 29 | ! fulldls.com,torrentzap.com##.tp_reccomend_banner 30 | ! 但是推荐写成以下标准写法: 31 | ! ||fulldls.com##.tp_reccomend_banner 32 | ! ||torrentzap.com##.tp_reccomend_banner 33 | ! 如果一个网站html规则有多条,可以合并为这样: 34 | ! ||torrentzap.com##.tp_reccomend_banner,.ad_top,[class="ad_right"]...... 35 | ! ------------------------------------------------------------------------------------------ 36 | ! 文本替换语法:$s@匹配内容@替换内容@ 37 | ! 文本替换例子:|http://cdn.pcbeta.js.inimc.com/data/cache/common.js?$s@old@new@ 38 | ! 重定向语法:$r@匹配内容@替换内容@ 39 | ! 重定向例子:|http://koolshare.cn$r@http://koolshare.cn/*@http://www.qq.com@ 40 | ! 注:文本替换语法及重定向语法中的匹配内容不仅支持通配符功能,而且额外支持以下功能 41 | ! 支持通配符 * 和 ? 表示单个字符 42 | ! 支持全正则匹配,/正则内容/ 表示应用正则匹配 43 | ! 正则替换:替换内容支持 $1 $2 这样的符号 44 | ! 普通替换:替换内容支持 * 这样的符号,表示把命中的内容复制到替换的内容。(类似 $1 $2,但是 * 号会自动计算数字) 45 | ! ------------------------------------------------------------------------------------------ 46 | ! 未来将逐步添加相关语法,兼容adblock puls的更多语法,敬请期待。 47 | ! ****************************************************************************************** 48 | -------------------------------------------------------------------------------- /files/root/etc/uci-defaults/luci-koolproxy: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | uci -q batch <<-EOF >/dev/null 4 | delete ucitrack.@koolproxy[-1] 5 | add ucitrack koolproxy 6 | set ucitrack.@koolproxy[-1].init=koolproxy 7 | commit ucitrack 8 | delete firewall.koolproxy 9 | set firewall.koolproxy=include 10 | set firewall.koolproxy.type=script 11 | set firewall.koolproxy.path=/etc/koolproxy/firewall.include 12 | set firewall.koolproxy.reload=1 13 | commit firewall 14 | EOF 15 | exit 0 16 | -------------------------------------------------------------------------------- /preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/honwen/luci-app-koolproxy/80236db94252d5153a2fbd3a74d4be0540580a7a/preview.png --------------------------------------------------------------------------------