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 9, 2025
1 parent 99a4a0f commit 33f35b1
Show file tree
Hide file tree
Showing 4 changed files with 164 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'
104 changes: 104 additions & 0 deletions net/antiblock/files/etc/init.d/antiblock
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/sh /etc/rc.common

START=99
USE_PROCD=1

dnsmasq_walk_add() {
local id=$1
local listen_IP=$(echo $listen | cut -d ':' -f1)
local listen_port=$(echo $listen | cut -d ':' -f2)

uci -q set dhcp.$id.noresolv="1"
uci -q delete dhcp.$id.server
uci -q add_list dhcp.$id.server="$listen_IP#$listen_port"
}
dnsmasq_walk_del() {
local id=$1

uci -q delete dhcp.$id.noresolv
uci -q delete dhcp.$id.server
}

antiblock_walk_add() {
local id=$1

config_get log "$id" log
config_get stat "$id" stat
config_get url "$id" url
config_get file "$id" file
config_get output "$id" output
config_get DNS "$id" DNS
config_get listen "$id" listen
config_get VPN_name "$id" VPN_name
}

start_service() {
echo "AntiBlock start"

log=""
stat=""
url=""
file=""
output=""
DNS=""
listen=""
VPN_name=""

config_load antiblock
config_foreach antiblock_walk_add antiblock

procd_open_instance

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

if [[ "$log" != "" ]]; then
procd_append_param command -log
fi
if [[ "$stat" != "" ]]; then
procd_append_param command -stat
fi
if [[ "$url" != "" ]]; then
procd_append_param command -url "$url"
fi
if [[ "$file" != "" ]]; then
procd_append_param command -file "$file"
fi
if [[ "$output" != "" ]]; then
mkdir -p $output
procd_append_param command -output $output
fi
if [[ "$DNS" != "" ]]; then
procd_append_param command -DNS "$DNS"
fi
if [[ "$listen" != "" ]]; then
config_load dhcp
config_foreach dnsmasq_walk_add dnsmasq
procd_append_param command -listen "$listen"
fi
if [[ "$VPN_name" != "" ]]; then
gateway=$(uci get network.$VPN_name.addresses | cut -d '/' -f1)
procd_append_param command -gateway "$gateway"
fi

procd_close_instance

uci commit

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

stop_service() {
echo "AntiBlock stop"

config_load dhcp
config_foreach dnsmasq_walk_del dnsmasq

uci commit

/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 33f35b1

Please sign in to comment.