Skip to content

Commit

Permalink
much things for new version 20241012
Browse files Browse the repository at this point in the history
  • Loading branch information
twoone-3 committed Oct 12, 2024
1 parent cf69c58 commit 4668d47
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*.zip
cache/
30 changes: 2 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,8 @@

关注我们的频道以获取最新消息,或者加入我们的群组进行讨论!

# 用法
- 使用前需在设置里关闭 `私人/专用dns`,在 Magisk/KernelSU 刷入后即可使用,本模块默认后台管理地址为 http://127.0.0.1:3000 ,默认用户名/密码root
- 如果你从来没有接触过 AdGuardHome,你可以在这里找到[官方文档](https://github.com/AdguardTeam/AdGuardHome),或者也可以看看这篇教程[AdGuard Home 中文指南](https://www.timochan.cn/posts/jc/adguard_home_configuration_guide)

# 特性
- DNS 服务器选用腾讯和阿里的公共 DNS,你也可以在 AdGuardHome 的 DNS 设置里更改来满足你的需求
- 仅内置[秋风广告规则](https://github.com/TG-Twilight/AWAvenue-Ads-Rule),精准,轻量,少误杀
- 在 Magisk/KernelSU 中可以通过模块开关实时启动/关闭模块,当然你也可以在shell中模拟模块开关
```shell
touch /data/adb/modules/AdguardHome/disable
```
- 可修改位于 `/data/adb/agh/scripts/config.sh` 的配置文件来调整配置
- 在更新模块时,用户可自行选择是否保留原来的配置文件,即使你选择不保留,也会自动备份原来的配置文件到 `/data/adb/agh/backup` 目录下

# FAQ
> Q: 为什么模块无法屏蔽全部广告?
> A: 模块通过转发 53 端口的 DNS 请求来实现广告屏蔽,因此无法屏蔽通过 HTTPS 传输的广告,以及与正常内容同域名的广告,如 知乎,Youtube 等,好在大部分广告还是优先使用 53 端口的 DNS 请求。
> Q: 模块可以与其它代理模块/软件一起使用吗?
> A: 可以,一般的代理app可以直接兼容(这里推荐使用[FlClash](https://github.com/chen08209/FlClash)),且 AdGuardHome 的 DNS 查询会经过 VPN,其它代理模块看情况使用,可关闭自动 iptables 规则当作普通 DNS 使用
> Q: 为什么不接入 KernelSU 的 WebUI?
> A: 由于 KernelSU 的 WebUI 在无法显示确认弹窗,导致 AdGuardHome 管理端一些功能无法使用,因此暂时不接入

# 教程
- 用法教程及常见问题解答请前往 [Wiki](https://github.com/twoone-3/AdGuardHomeForMagisk/wiki) 查看

# 鸣谢
- [AdguardHome_magisk](https://github.com/410154425/AdGuardHome_magisk)
Expand Down
34 changes: 5 additions & 29 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,16 @@ English | [简体中文](README.md)

A Magisk/KernelSU module to block ads by redirecting and filtering DNS requests.

! [Static Badge](https://img.shields.io/badge/arm--64-support-blue)
! [Static Badge](https://img.shields.io/badge/arm--v7-support-blue) !
! [GitHub all releases](https://img.shields.io/github/downloads/twoone-3/AdguardHome/total)
![Static Badge](https://img.shields.io/badge/arm--64-support-blue)
![Static Badge](https://img.shields.io/badge/arm--v7-support-blue) !
![GitHub all releases](https://img.shields.io/github/downloads/twoone-3/AdguardHome/total)
[![](https://img.shields.io/badge/Telegram-Join%20Channel-blue?logo=telegram)](https://t.me/adguardhome_for_magisk_release)
[![](https://img.shields.io/badge/Telegram-Join%20Group-blue?logo=telegram)](https://t.me/+mdZL11mJjxhkYjdl)

Follow our channel for the latest news, or join our group for discussion!

# Usage
- Before using, turn off `Private/Custom DNS` in the settings, flash it in Magisk/KernelSU, and you can use it after installation. The default background management address is http://127.0.0.1:3000, and the default username/password is root.
- If you have never used AdGuardHome before, you can find the [official documentation](https://github.com/AdguardTeam/AdGuardHome) here, or you can also take a look at this tutorial [AdGuard Home 中文指南](https://www.timochan.cn/posts/jc/adguard_home_configuration_guide)

# Features
- The DNS server uses Tencent and Alibaba's public DNS, you can also change it in the DNS settings of AdGuardHome to meet your needs.
- Only built-in [Autumn Breeze Ad Rule](https://github.com/TG-Twilight/AWAvenue-Ads-Rule), accurate, lightweight, and low false positives.
- In Magisk/KernelSU, you can start/stop the module in real-time using the module switch, or you can simulate the module switch in the shell.
```shell
touch /data/adb/modules/AdguardHome/disable
```
- You can modify the configuration file located in `/data/adb/agh/scripts/config.sh` to adjust the configuration.
- When updating the module, users can choose whether to keep the original configuration file, even if you choose not to keep it, the original configuration file will be automatically backed up to the `/data/adb/agh/backup` directory.

# FAQ
> Q: Why can't the module block all ads?
> A: The module blocks ads by forwarding DNS requests on port 53, so it cannot block ads transmitted over HTTPS or ads on the same domain as normal content, such as Zhihu, Youtube, etc., but fortunately, most ads still prefer to use DNS requests on port 53.
> Q: Can the module be used with other proxy modules/software?
> A: Yes, general proxy apps can be directly compatible (here we recommend using [FlClash](https://github.com/chen08209/FlClash)), and AdGuardHome's DNS queries will pass through the VPN, other proxy modules can be used as needed, and the automatic iptables rules can be turned off for normal DNS use.
> Q: Why not integrate with KernelSU's WebUI?
> A: Because KernelSU's WebUI cannot display confirmation pop-ups, some functions of AdGuardHome's management end cannot be used, so it is not integrated for the time being.
# Tutorial
- For usage tutorials and FAQs, please visit [Wiki](https://github.com/twoone-3/AdGuardHomeForMagisk/wiki) for more information.

# Acknowledgments
- [AdguardHome_magisk](https://github.com/410154425/AdGuardHome_magisk)
Expand Down
20 changes: 14 additions & 6 deletions agh_service.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
#!/system/bin/sh

AGH_DIR="/data/adb/agh"
SCRIPT_DIR="$AGH_DIR/scripts"
MOD_PATH="/data/adb/modules/AdGuardHome"

(
exec >$AGH_DIR/agh.log 2>&1
while [ "$(getprop init.svc.bootanim)" != "stopped" ]; do
echo "Waiting for system to finish booting..." >>/data/adb/agh/agh.log
sleep 8
done
AGH_DIR="/data/adb/agh"
SCRIPT_DIR="$AGH_DIR/scripts"

if [ ! -f "/data/adb/modules/AdGuardHome/disable" ]; then
$SCRIPT_DIR/service.sh start >>$AGH_DIR/agh.log 2>&1 &&
$SCRIPT_DIR/iptables.sh enable >>$AGH_DIR/agh.log 2>&1
if [ ! -f "$MOD_PATH/disable" ]; then
$SCRIPT_DIR/service.sh start
if [ ! -f "$MOD_PATH/disable_iptable" ]; then
$SCRIPT_DIR/iptables.sh enable
sed -i "s/description=\[.*\]/description=\[😎AdGuardHome is running and 🔗iptables is enabled\]/" "$MOD_PATH/module.prop"
else
sed -i "s/description=\[.*\]/description=\[😎AdGuardHome is running but ⛓️‍💥iptables is disabled\]/" "$MOD_PATH/module.prop"
fi
fi

inotifyd $SCRIPT_DIR/inotify.sh /data/adb/modules/AdGuardHome:d,n >/dev/null 2>&1 &
inotifyd $SCRIPT_DIR/inotify.sh $MOD_PATH:d,n >/dev/null 2>&1 &
) &
8 changes: 5 additions & 3 deletions bin/AdGuardHome.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dns:
- 223.5.5.5
- 119.29.29.29
fallback_dns: []
upstream_mode: parallel
upstream_mode: load_balance
fastest_timeout: 1s
allowed_clients: []
disallowed_clients: []
Expand Down Expand Up @@ -130,6 +130,7 @@ filtering:
enabled: false
bing: true
duckduckgo: true
ecosia: true
google: true
pixabay: true
yandex: true
Expand All @@ -138,12 +139,13 @@ filtering:
parental_block_host: family-block.dns.adguard.com
safebrowsing_block_host: standard-block.dns.adguard.com
rewrites: []
safe_fs_patterns: []
safebrowsing_cache_size: 1048576
safesearch_cache_size: 1048576
parental_cache_size: 1048576
cache_time: 30
filters_update_interval: 168
blocked_response_ttl: 30
blocked_response_ttl: 10
filtering_enabled: true
parental_enabled: false
safebrowsing_enabled: false
Expand All @@ -169,4 +171,4 @@ os:
group: ""
user: ""
rlimit_nofile: 0
schema_version: 28
schema_version: 29
Binary file removed bin/AdGuardHome_arm64
Binary file not shown.
Binary file removed bin/AdGuardHome_armv7
Binary file not shown.
13 changes: 5 additions & 8 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# ChangeLog
- 修复manual选项不生效的问题
- fix manual option not work
- 更改了模块更新安装时的备份方式
- change the backup method when updating the module
- 更新了 README.md
- update README.md
- 更改了默认DNS查询方式为parallel,提高了查询速度
- change the default DNS query method to parallel, improve the query speed
- 新增模块描述动态显示模块状态功能
- 新增 [Wiki](https://github.com/twoone-3/AdGuardHomeForMagisk/wiki) 页面
- 更新 `AdGuardHome` 到 v0.107.53
- 更新 `AdGuardHome.yaml` 版本
- 删除 `config.sh` 中的 manual 配置项,转而改用创建 `disable_iptable` 文件
28 changes: 26 additions & 2 deletions customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ if [ -d "$AGH_DIR" ]; then
rm "$pid_file"
sleep 1
fi
ui_print "- 发现旧版模块,是否保留原来的配置文件?"
ui_print "- Found old version, do you want to keep the old configuration?"
ui_print "- 发现旧版模块,是否保留原来的配置文件?(若不保留则自动备份)"
ui_print "- Found old version, do you want to keep the old configuration? (If not, it will be automatically backed up)"
ui_print "- (音量上键 = 是, 音量下键 = 否)"
ui_print "- (Volume Up = Yes, Volume Down = No)"
key_click=""
Expand Down Expand Up @@ -69,6 +69,30 @@ else
unzip -o "$ZIPFILE" "bin/*" -d $AGH_DIR
fi

ui_print "- 是否需要禁用用于转发 DNS 请求的 iptables 规则?"
ui_print "- Do you want to disable iptables rules for forwarding DNS requests?"
ui_print "- (音量上键 = 是, 音量下键 = 否)"
ui_print "- (Volume Up = Yes, Volume Down = No)"
key_click=""
while [ "$key_click" = "" ]; do
key_click="$(getevent -qlc 1 | awk '{ print $3 }' | grep 'KEY_')"
sleep 0.2
done
case "$key_click" in
"KEY_VOLUMEUP")
ui_print "- 创建 disable_iptable 文件..."
ui_print "- Creating disable_iptable file..."
touch "$MODPATH/disable_iptable"
;;
*)
if [ -f "$MODPATH/disable_iptable" ]; then
ui_print "- 删除 disable_iptable 文件..."
ui_print "- Deleting disable_iptable file..."
rm "$MODPATH/disable_iptable"
fi
;;
esac

ui_print "- 正在设置权限..."
ui_print "- Setting permissions..."
chmod +x "$BIN_DIR/AdGuardHome"
Expand Down
6 changes: 3 additions & 3 deletions module.prop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id=AdGuardHome
name=AdGuardHome for Magisk
version=20241007
versionCode=22
version=20241012
versionCode=23
author=twoone3
description=Filter ads at the DNS level
description=[😐AdGuardHome is stopped and ⛓️‍💥iptables is disabled] Filter ads at the DNS level
updateJson=https://raw.githubusercontent.com/twoone-3/AdGuardHomeForMagisk/main/version.json
91 changes: 91 additions & 0 deletions pack.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# 定义下载 URL 和路径变量
$CacheDir = "$PSScriptRoot\cache"
$UrlWitchCachePath = @{
"https://github.com/AdguardTeam/AdGuardHome/releases/latest/download/AdGuardHome_linux_arm64.tar.gz" = "$CacheDir\AdGuardHome_linux_arm64.tar.gz"
"https://github.com/AdguardTeam/AdGuardHome/releases/latest/download/AdGuardHome_linux_armv7.tar.gz" = "$CacheDir\AdGuardHome_linux_armv7.tar.gz"
}

# 创建缓存目录
if (-Not (Test-Path -Path $CacheDir)) {
Write-Host "Creating cache directory..."
New-Item -Path $CacheDir -ItemType Directory
}

# 下载文件,有缓存时不再下载
Write-Host "Downloading AdGuardHome..."
foreach ($url in $UrlWitchCachePath.Keys) {
$CachePath = $UrlWitchCachePath[$url]
if (-Not (Test-Path -Path $CachePath)) {
Write-Host "Downloading $url..."
Invoke-WebRequest -Uri $url -OutFile $CachePath
if ($?) {
Write-Host "Download completed successfully."
}
else {
Write-Host "Download failed. Exiting..."
exit 1
}
}
else {
Write-Host "File already exists in cache. Skipping download."
}
}

# 使用 tar 解压文件
Write-Host "Extracting AdGuardHome..."
foreach ($url in $UrlWitchCachePath.Keys) {
$CachePath = $UrlWitchCachePath[$url]
if ($CachePath -match 'AdGuardHome_linux_(arm64|armv7)\.tar\.gz$') {
$ExtractDir = "./cache/" + $matches[1]
}
else {
throw "Invalid file path: $CachePath"
}
if (-Not (Test-Path -Path $ExtractDir)) {
New-Item -Path $ExtractDir -ItemType Directory
Write-Host "Extracting $CachePath..."
tar -xzf $CachePath -C $ExtractDir
if ($?) {
Write-Host "Extraction completed successfully."
}
else {
Write-Host "Extraction failed"
exit 1
}
}
}

# 给项目打包,使用 7-Zip 压缩 zip
Write-Host "Packing AdGuardHome..."
$7z = "C:\Program Files\7-Zip\7z.exe"
$OutputPathArm64 = "$CacheDir\AdGuardHomeForMagisk_arm64.zip"
$OutputPathArmv7 = "$CacheDir\AdGuardHomeForMagisk_armv7.zip"
if (Test-Path -Path $OutputPathArm64) {
Remove-Item -Path $OutputPathArm64
}
if (Test-Path -Path $OutputPathArmv7) {
Remove-Item -Path $OutputPathArmv7
}
# pack arm64
& $7z a -tzip $OutputPathArm64 ".\*.sh"
& $7z a -tzip $OutputPathArm64 ".\module.prop"
& $7z a -tzip $OutputPathArm64 ".\META-INF"
& $7z a -tzip $OutputPathArm64 ".\scripts"
& $7z a -tzip $OutputPathArm64 ".\bin\data"
& $7z rn $OutputPathArm64 "data" "bin\data"
& $7z a -tzip $OutputPathArm64 ".\bin\AdGuardHome.yaml"
& $7z rn $OutputPathArm64 "AdGuardHome.yaml" "bin\AdGuardHome.yaml"
& $7z a -tzip $OutputPathArm64 ".\cache\arm64\AdGuardHome\AdGuardHome"
& $7z rn $OutputPathArm64 "AdGuardHome" "bin\AdGuardHome"
# pack armv7
& $7z a -tzip $OutputPathArmv7 ".\*.sh"
& $7z a -tzip $OutputPathArmv7 ".\module.prop"
& $7z a -tzip $OutputPathArmv7 ".\META-INF"
& $7z a -tzip $OutputPathArmv7 ".\scripts"
& $7z a -tzip $OutputPathArmv7 ".\bin\data"
& $7z rn $OutputPathArmv7 "data" "bin\data"
& $7z a -tzip $OutputPathArmv7 ".\bin\AdGuardHome.yaml"
& $7z rn $OutputPathArmv7 "AdGuardHome.yaml" "bin\AdGuardHome.yaml"
& $7z a -tzip $OutputPathArmv7 ".\cache\armv7\AdGuardHome\AdGuardHome"
& $7z rn $OutputPathArmv7 "AdGuardHome" "bin\AdGuardHome"
Write-Host "Packing completed successfully."
5 changes: 0 additions & 5 deletions scripts/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ if ! command -v busybox &> /dev/null; then
export PATH="/data/adb/magisk:/data/adb/ksu/bin:/data/adb/ap/bin:$PATH:/system/bin"
fi

# 手动模式,默认关闭,开启后iptables.sh将跳过运行,如果你要在开机状态下修改本项,请先在Magisk/KernelSU关闭模块以确保预期的行为
# true: 开启
# false: 关闭
manual=false

# 是否开启 ipv6 DNS 查询,建议关闭
# true: 开启
# false: 关闭
Expand Down
33 changes: 29 additions & 4 deletions scripts/inotify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,38 @@ monitor_file="$3"

AGH_DIR="/data/adb/agh"
SCRIPT_DIR="$AGH_DIR/scripts"
MOD_PATH="/data/adb/modules/AdGuardHome"

exec >>$AGH_DIR/agh.log 2>&1

if [ "${monitor_file}" = "disable" ]; then
if [ "${events}" = "d" ]; then
$SCRIPT_DIR/service.sh start >>$AGH_DIR/agh.log 2>&1 &&
$SCRIPT_DIR/iptables.sh enable >>$AGH_DIR/agh.log 2>&1
$SCRIPT_DIR/service.sh start
if [ ! -f "/data/adb/modules/AdGuardHome/disable_iptable" ]; then
$SCRIPT_DIR/iptables.sh enable
sed -i "s/description=\[.*\]/description=\[😎AdGuardHome is running and 🔗iptables is enabled\]/" "$MOD_PATH/module.prop"
else
sed -i "s/description=\[.*\]/description=\[😎AdGuardHome is running but ⛓️‍💥iptables is disabled\]/" "$MOD_PATH/module.prop"
fi
elif [ "${events}" = "n" ]; then
if [ -f "/data/adb/modules/AdGuardHome/disable_iptable" ]; then
$SCRIPT_DIR/iptables.sh disable
fi
$SCRIPT_DIR/service.sh stop
sed -i "s/description=\[.*\]/description=\[😐AdGuardHome is stopped and ⛓️‍💥iptables is disabled\]/" "$MOD_PATH/module.prop"
fi
fi

if [ "${monitor_file}" = "disable_iptable" ]; then
if [ "${events}" = "d" ]; then
if [ ! -f "/data/adb/modules/AdGuardHome/disable" ]; then
$SCRIPT_DIR/iptables.sh enable
sed -i "s/description=\[.*\]/description=\[😎AdGuardHome is running and 🔗iptables is enabled\]/" "$MOD_PATH/module.prop"
fi
elif [ "${events}" = "n" ]; then
$SCRIPT_DIR/iptables.sh disable >>$AGH_DIR/agh.log 2>&1 &&
$SCRIPT_DIR/service.sh stop >>$AGH_DIR/agh.log 2>&1
if [ ! -f "/data/adb/modules/AdGuardHome/disable" ]; then
$SCRIPT_DIR/iptables.sh disable
sed -i "s/description=\[.*\]/description=\[😎AdGuardHome is running but ⛓️‍💥iptables is disabled\]/" "$MOD_PATH/module.prop"
fi
fi
fi
4 changes: 0 additions & 4 deletions scripts/iptables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ disable_ipv6() {
# sysctl -w net.ipv6.conf.wlan0.disable_ipv6=1
}

if [ "$manual" = true ]; then
exit 0
fi

case "$1" in
enable)
enable_iptables
Expand Down
Loading

0 comments on commit 4668d47

Please sign in to comment.