diff --git a/net/antiblock/Makefile b/net/antiblock/Makefile new file mode 100644 index 0000000000000..f9bbfaa69c34c --- /dev/null +++ b/net/antiblock/Makefile @@ -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 +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)) diff --git a/net/antiblock/files/etc/config/antiblock b/net/antiblock/files/etc/config/antiblock new file mode 100644 index 0000000000000..33bec68916e09 --- /dev/null +++ b/net/antiblock/files/etc/config/antiblock @@ -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' diff --git a/net/antiblock/files/etc/init.d/antiblock b/net/antiblock/files/etc/init.d/antiblock new file mode 100644 index 0000000000000..b2b60e3c03a44 --- /dev/null +++ b/net/antiblock/files/etc/init.d/antiblock @@ -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" +} diff --git a/net/antiblock/test.sh b/net/antiblock/test.sh new file mode 100644 index 0000000000000..a2f467fa0891a --- /dev/null +++ b/net/antiblock/test.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +antiblock | grep "Antiblock started"