Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

antiblock: add new package #25694

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=""
1715173329 marked this conversation as resolved.
Show resolved Hide resolved
stat=""
url=""
file=""
output=""
DNS=""
listen=""
VPN_name=""

config_load antiblock
config_foreach antiblock_walk_add antiblock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are only interested in in the first or last section, then you do not need config_foreach. But I would look up how to do that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to have access via @, I'll look for it.


procd_open_instance

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

if [[ "$log" != "" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace these kind of contructs with if [ -n "$log" ]; then. it is less specific shell code. But it is not important.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, [ -n ... ] is better

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This writes all changes to all configuration files to the flash on every start of the application.
Please don't do that. :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, right, that needs to be fixed)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	uci -q set dhcp.$id.noresolv="1"
	uci -q delete dhcp.$id.server
	uci -q add_list dhcp.$id.server="$listen_IP#$listen_port"

This line is needed to apply the dhcp changes. I want to change to uci commit dhcp. Or will the changes apply themselves?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to store/commit the setting if you modify the dhcp settings and restart dnsmasq afterwards anyway.

But in general it is not a good idea to modify and save other programs configuration files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or [ -n "$(uci -q changes dhcp)" ] && uci commit dhcp

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in general it is not a good idea to modify and save other programs configuration files.

I agree, especially it could break existing user configurations. It simply removes the server but never restored.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen that other services also modify configurations, for example https-dns-proxy. I took it as an example. For my program to work, it is necessary to redirect DNS traffic to it. I will fix the recovery of deleted parameters.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I write what I think. It is no law :)


/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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove that line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll correct it, as discussed above.


/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"
Loading