antiblock: Add AntiBlock package
authorKhachatryan Karen <[email protected]>
Tue, 7 Jan 2025 02:01:59 +0000 (05:01 +0300)
committerTianling Shen <[email protected]>
Fri, 17 Jan 2025 06:17:19 +0000 (14:17 +0800)
AntiBlock program proxies DNS requests.
The IP addresses of the specified domains are added to
the routing table for routing through the specified interface.

Signed-off-by: Khachatryan Karen <[email protected]>
net/antiblock/Makefile [new file with mode: 0644]
net/antiblock/files/etc/config/antiblock [new file with mode: 0644]
net/antiblock/files/etc/init.d/antiblock [new file with mode: 0644]
net/antiblock/test.sh [new file with mode: 0644]

diff --git a/net/antiblock/Makefile b/net/antiblock/Makefile
new file mode 100644 (file)
index 0000000..f8101fb
--- /dev/null
@@ -0,0 +1,48 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=antiblock
+PKG_VERSION:=2.0.0
+PKG_RELEASE:=1
+
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_URL:=https://github.com/karen07/antiblock
+PKG_SOURCE_VERSION:=v$(PKG_VERSION)
+PKG_MIRROR_HASH:=3ea495e825edb75bc0bec9010d4b0195442dbcc745fc4d3150ae41ca11e9dfc4
+
+PKG_MAINTAINER:=Khachatryan Karen <[email protected]>
+PKG_LICENSE:=GPL-3.0-or-later
+PKG_LICENSE_FILES:=LICENSE
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/cmake.mk
+
+define Package/antiblock
+  SECTION:=net
+  CATEGORY:=Network
+  DEPENDS:=+libcurl
+  TITLE:=AntiBlock
+  URL:=https://github.com/karen07/antiblock
+endef
+
+define Package/antiblock/description
+  AntiBlock program proxies DNS requests.
+  The IP addresses of the specified domains are added to
+  the routing table for routing through the specified interface.
+endef
+
+define Package/antiblock/conffiles
+/etc/config/antiblock
+endef
+
+define Package/antiblock/install
+       $(INSTALL_DIR) $(1)/usr/bin
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/antiblock $(1)/usr/bin/antiblock
+
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/etc/init.d/antiblock $(1)/etc/init.d/antiblock
+
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_CONF) ./files/etc/config/antiblock $(1)/etc/config/antiblock
+endef
+
+$(eval $(call BuildPackage,antiblock))
diff --git a/net/antiblock/files/etc/config/antiblock b/net/antiblock/files/etc/config/antiblock
new file mode 100644 (file)
index 0000000..cc31500
--- /dev/null
@@ -0,0 +1,14 @@
+
+#config antiblock 'config'
+       #option enabled '0'
+       #At least one parameters needs to be filled:
+               #option url 'https://antifilter.download/list/domains.lst'
+               #option file '/root/my_urls.txt'
+       #Required parameters:
+               #option listen '192.168.1.1:5053'
+               #option DNS '1.1.1.1:53'
+               #option VPN_name 'VPN'
+       #Optional parameters:
+               #option log '1'
+               #option stat '1'
+               #option output '/tmp/antiblock'
diff --git a/net/antiblock/files/etc/init.d/antiblock b/net/antiblock/files/etc/init.d/antiblock
new file mode 100644 (file)
index 0000000..85d29bf
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/sh /etc/rc.common
+
+USE_PROCD=1
+START=99
+
+CONF="antiblock"
+
+start_service() {
+       config_load "$CONF"
+
+       local _enabled
+       config_get_bool _enabled "config" "enabled" "0"
+       [ "${_enabled}" -eq "0" ] && return 1
+
+       echo "AntiBlock start"
+
+       local _url
+       local _file
+       local _listen
+       local _DNS
+       local _VPN_name
+       local _log
+       local _stat
+       local _output
+
+       config_get _url "config" "url"
+       config_get _file "config" "file"
+
+       config_get _listen "config" "listen"
+       config_get _DNS "config" "DNS"
+       config_get _VPN_name "config" "VPN_name"
+
+       config_get_bool _log "config" "log" "0"
+       config_get_bool _stat "config" "stat" "0"
+       config_get _output "config" "output"
+
+       procd_open_instance "$CONF"
+
+       procd_set_param command "/usr/bin/antiblock"
+       procd_set_param stdout 1
+       procd_set_param stderr 1
+
+       [ -n "${_url}" ] && procd_append_param command -url "${_url}"
+       [ -n "${_file}" ] && procd_append_param command -file "${_file}"
+
+       if [ -n "${_listen}" ]; then
+               local listen_IP="$(echo "${_listen}" | cut -d ':' -f1)"
+               local listen_port="$(echo "${_listen}" | cut -d ':' -f2)"
+               uci -q set dhcp.@dnsmasq[0].noresolv="1"
+               uci -q delete dhcp.@dnsmasq[0].server
+               uci -q add_list dhcp.@dnsmasq[0].server="$listen_IP#$listen_port"
+
+               procd_append_param command -listen "${_listen}"
+       fi
+       [ -n "${_DNS}" ] && procd_append_param command -DNS "${_DNS}"
+       if [ -n "${_VPN_name}" ]; then
+               local gateway="$(uci -q get network."${_VPN_name}".addresses | cut -d '/' -f1)"
+               procd_append_param command -gateway "$gateway"
+       fi
+
+       [ "${_log}" -ne "0" ] && procd_append_param command -log
+       [ "${_stat}" -ne "0" ] && procd_append_param command -stat
+       if [ -n "${_output}" ]; then
+               mkdir -p "${_output}"
+               procd_append_param command -output "${_output}"
+       fi
+
+       procd_close_instance
+
+       /etc/init.d/dnsmasq restart >/dev/null 2>&1
+}
+
+stop_service() {
+       echo "AntiBlock stop"
+
+       uci -q revert dhcp.@dnsmasq[0]
+
+       /etc/init.d/dnsmasq restart >/dev/null 2>&1
+}
+
+service_triggers() {
+       procd_add_reload_trigger "$CONF"
+}
diff --git a/net/antiblock/test.sh b/net/antiblock/test.sh
new file mode 100644 (file)
index 0000000..6c9cb66
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+antiblock | grep "AntiBlock started"