Skip to content

Commit

Permalink
antiblock: Add AntiBlock package
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
karen07 committed Jan 11, 2025
1 parent 99a4a0f commit 9dffa8b
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 0 deletions.
47 changes: 47 additions & 0 deletions net/antiblock/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=antiblock
PKG_VERSION:=1.0.0
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/karen07/antiblock
PKG_SOURCE_VERSION:=bd8e4ae4fe066833d63574bad0d6e1989f6e98f0
PKG_MIRROR_HASH:=d0411f62785c4636b760729ab269e21bba12e4c10b315ac8f7cf48f68475b796

PKG_MAINTAINER:=Khachatryan Karen <[email protected]>
PKG_LICENSE:=GPL-3.0-or-later

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))
10 changes: 10 additions & 0 deletions net/antiblock/files/etc/config/antiblock
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#config antiblock
#option url 'https://antifilter.download/list/domains.lst'
#option file '/root/my_urls.txt'
#option DNS '1.1.1.1:53'
#option listen '192.168.1.1:5053'
#option VPN_name 'VPN'
#option output '/tmp/antiblock'
#option log '1'
#option stat '1'
124 changes: 124 additions & 0 deletions net/antiblock/files/etc/init.d/antiblock
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/sh /etc/rc.common

START=99
USE_PROCD=1

start_service() {
echo "AntiBlock start"

local log="$(uci -q get antiblock.@antiblock[0].log)"
local stat="$(uci -q get antiblock.@antiblock[0].stat)"
local url="$(uci -q get antiblock.@antiblock[0].url)"
local file="$(uci -q get antiblock.@antiblock[0].file)"
local output="$(uci -q get antiblock.@antiblock[0].output)"
local DNS="$(uci -q get antiblock.@antiblock[0].DNS)"
local listen="$(uci -q get antiblock.@antiblock[0].listen)"
local VPN_name="$(uci -q get antiblock.@antiblock[0].VPN_name)"

procd_open_instance

procd_set_param command "/usr/bin/antiblock"
procd_set_param stdout 1

if [ -n "$log" ]; then
procd_append_param command -log
fi
if [ -n "$stat" ]; then
procd_append_param command -stat
fi
if [ -n "$url" ]; then
procd_append_param command -url "$url"
fi
if [ -n "$file" ]; then
procd_append_param command -file "$file"
fi
if [ -n "$output" ]; then
mkdir -p "$output"
procd_append_param command -output "$output"
fi
if [ -n "$DNS" ]; then
procd_append_param command -DNS "$DNS"
fi
if [ -n "$listen" ]; then
local forward="$(uci -q get antiblock.@dhcp_backup[0].forward)"

if [ -z "$forward" ]; then
local listen_IP="$(echo $listen | cut -d ':' -f1)"
local listen_port="$(echo $listen | cut -d ':' -f2)"

local dhcp_noresolv="$(uci -q get dhcp.@dnsmasq[0].noresolv)"
local dhcp_server="$(uci -q get dhcp.@dnsmasq[0].server)"

uci -q add antiblock dhcp_backup >/dev/null 2>&1

if [ -n "$dhcp_noresolv" ]; then
uci -q set antiblock.@dhcp_backup[0].noresolv="$dhcp_noresolv"
fi
if [ -n "$dhcp_server" ]; then
uci -q set antiblock.@dhcp_backup[0].server="$dhcp_server"
fi

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"

uci -q set antiblock.@dhcp_backup[0].forward="1"
fi

procd_append_param command -listen "$listen"
fi
if [ -n "$VPN_name" ]; then
local gateway="$(uci -q get network.$VPN_name.addresses | cut -d '/' -f1)"
procd_append_param command -gateway "$gateway"
fi

procd_close_instance

uci -q commit antiblock.@dhcp_backup[0]
uci -q commit dhcp.@dnsmasq[0]

/etc/init.d/dnsmasq restart >/dev/null 2>&1
}

stop_service() {
echo "AntiBlock stop"

local forward="$(uci -q get antiblock.@dhcp_backup[0].forward)"

if [ -n "$forward" ]; then
uci -q delete dhcp.@dnsmasq[0].noresolv
uci -q delete dhcp.@dnsmasq[0].server

local dhcp_noresolv_backup="$(uci -q get antiblock.@dhcp_backup[0].noresolv)"
local dhcp_server_backup="$(uci -q get antiblock.@dhcp_backup[0].server)"

if [ -n "$dhcp_noresolv_backup" ]; then
uci -q set dhcp.@dnsmasq[0].noresolv="$dhcp_noresolv_backup"
fi
if [ -n "$dhcp_server_backup" ]; then
for i in $(echo $dhcp_server_backup | tr " " "\n"); do
uci -q add_list dhcp.@dnsmasq[0].server="$i"
done
fi

uci -q delete antiblock.@dhcp_backup[0]
fi

local VPN_name="$(uci -q get antiblock.@antiblock[0].VPN_name)"

if [ -n "$VPN_name" ]; then
local ips="$(ip r | grep "dev $VPN_name" | grep via | cut -d' ' -f 1)"
for i in $ips; do
ip r del $i >/dev/null 2>&1
done
fi

uci -q commit antiblock.@dhcp_backup[0]
uci -q commit dhcp.@dnsmasq[0]

/etc/init.d/dnsmasq restart >/dev/null 2>&1
}

service_triggers() {
procd_add_reload_trigger "antiblock"
}
3 changes: 3 additions & 0 deletions net/antiblock/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

antiblock | grep "Antiblock started"

0 comments on commit 9dffa8b

Please sign in to comment.