11 Commits

Author SHA1 Message Date
egor-white
cf98c42995 Update workflow.yml 2025-11-03 22:30:52 +03:00
CherretGit
942578b5c5 optimize release binary 2025-11-03 23:47:45 +07:00
egor-white
6215a36eb6 Update customize.sh 2025-11-03 18:00:42 +03:00
CherretGit
5e64628d7f Update workflow.yml 2025-11-03 21:43:02 +07:00
CherretGit
8b0945352a Update workflow_without_post.yml 2025-11-03 21:41:47 +07:00
CherretGit
ca65e0c6f1 remove iptables crate, fix service_status 2025-11-03 21:16:14 +07:00
egor-white
234e9e5824 Merge pull request #7 from sqlerrorthing/refactor/rust/autostart
refactor: autostart
2025-11-03 16:28:23 +03:00
egor-white
aedf249712 Merge branch 'main' into refactor/rust/autostart 2025-11-03 16:28:13 +03:00
egor-white
526bf7ded2 Merge pull request #6 from sqlerrorthing/fix/right-library
fix: right library functions
2025-11-03 16:26:06 +03:00
sqlerrorthing
2c8721e42b right library api 2025-11-03 05:42:28 +08:00
sqlerrorthing
d59340a5c9 refactor autostart 2025-11-03 05:35:33 +08:00
11 changed files with 116 additions and 98 deletions

View File

@@ -96,9 +96,6 @@ jobs:
updateJson=https://raw.githubusercontent.com/egor-white/zaprett/refs/heads/main/update-hosts.json
EOF
- name: Tree files
run: |
tree zaprett/ zaprett-hosts/ zaprett-tv/
- name: Create archives
run: |
cd zaprett && zip -r ../zaprett.zip ./* && cd ..
@@ -125,8 +122,6 @@ jobs:
name: zaprett
path: out/*
- name: Update changelog
if: ${{ inputs.create_release == 'true' }}
run: echo "${{ inputs.release_changes }}" > changelog.md
@@ -150,20 +145,12 @@ jobs:
"changelog": "https://raw.githubusercontent.com/${{ github.repository }}/refs/heads/main/changelog.md"
}
EOF
cat > update-tv.json <<EOF
{
"version": "${{ inputs.version }}",
"versionCode": ${{ inputs.version_code }},
"zipUrl": "https://github.com/${{ github.repository }}/releases/download/${{ inputs.tag }}/zaprett-tv.zip",
"changelog": "https://raw.githubusercontent.com/${{ github.repository }}/refs/heads/main/changelog.md"
}
EOF
- name: Commit jsons and changelog
if: ${{ inputs.create_release == 'true' }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update update's.json and changelog"
file_pattern: "update.json update_hosts.json changelog.md"
file_pattern: "update.json update-hosts.json changelog.md"
- name: Send bot post
env:
MESSAGE_TEXT: |

View File

@@ -97,9 +97,6 @@ jobs:
updateJson=https://raw.githubusercontent.com/egor-white/zaprett/refs/heads/main/update-hosts.json
EOF
- name: Tree files
run: |
tree zaprett/ zaprett-hosts/ zaprett-tv/
- name: Create archives
run: |
cd zaprett && zip -r ../zaprett.zip ./* && cd ..
@@ -126,8 +123,6 @@ jobs:
name: zaprett
path: out/*
- name: Update changelog
if: ${{ inputs.create_release == 'true' }}
run: echo "${{ inputs.release_changes }}" > changelog.md

16
rust/Cargo.lock generated
View File

@@ -327,15 +327,6 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424"
[[package]]
name = "iptables"
version = "0.6.0"
source = "git+https://github.com/egor-white/rust-iptables-android.git?branch=add-android#15e43378308c766919e029ef315ee1681990c78f"
dependencies = [
"lazy_static",
"regex",
]
[[package]]
name = "is-terminal"
version = "0.4.17"
@@ -368,12 +359,6 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.177"
@@ -1126,7 +1111,6 @@ dependencies = [
"clap",
"daemonize",
"getset",
"iptables",
"libc",
"libnfqws",
"log",

View File

@@ -22,6 +22,11 @@ daemonize = "0.5.0"
log = "0.4.28"
pretty_env_logger = "0.5.0"
nix = { version = "0.30.1", features = ["signal"] }
iptables = { git = "https://github.com/egor-white/rust-iptables-android.git", branch = "add-android" }
getset = "0.1.6"
sysinfo = "0.37.2"
[profile.release]
panic = "abort"
opt-level = "z"
lto = true
strip = true

View File

@@ -19,6 +19,5 @@ daemonize = { workspace = true }
pretty_env_logger = { workspace = true }
log = { workspace = true }
nix = { workspace = true, features = ["user"] }
iptables = { workspace = true }
getset = { workspace = true }
sysinfo = { workspace = true }

View File

@@ -1,6 +1,6 @@
use tokio::fs::File;
use tokio::fs;
use crate::MODULE_PATH;
use tokio::fs;
use tokio::fs::File;
pub async fn set_autostart(autostart: bool) -> Result<(), anyhow::Error> {
let autostart_path = MODULE_PATH.join("autostart");

View File

@@ -59,8 +59,8 @@ impl Command {
}
}
Command::GetAutostart => get_autostart(),
Command::ModuleVersion => module_version(),
Command::BinaryVersion => bin_version(),
Command::ModuleVersion => println!("{}", module_version().await?),
Command::BinaryVersion => println!("{}", bin_version()),
}
Ok(())

View File

@@ -1,51 +1,88 @@
use std::error;
use std::process::Command;
pub fn setup_iptables_rules() -> Result<(), Box<dyn error::Error>> {
let ipt = iptables::new(false)?;
Command::new("iptables")
.arg("-t")
.arg("mangle")
.arg("-I")
.arg("POSTROUTING")
.arg("-j")
.arg("NFQUEUE")
.arg("--queue-num")
.arg("200")
.arg("--queue-bypass")
.status()
.expect("failed to add iptables rules");
ipt.insert(
"mangle",
"POSTROUTING",
"-j NFQUEUE --queue-num 200 --queue-bypass",
1,
)?;
Command::new("iptables")
.arg("-t")
.arg("mangle")
.arg("-I")
.arg("PREROUTING")
.arg("-j")
.arg("NFQUEUE")
.arg("--queue-num")
.arg("200")
.arg("--queue-bypass")
.status()
.expect("failed to add iptables rules");
ipt.insert(
"mangle",
"PREROUTING",
"-j NFQUEUE --queue-num 200 --queue-bypass",
1,
)?;
ipt.append(
"filter",
"FORWARD",
"-j NFQUEUE --queue-num 200 --queue-bypass",
)?;
Command::new("iptables")
.arg("-t")
.arg("filter")
.arg("-A")
.arg("FORWARD")
.arg("-j")
.arg("NFQUEUE")
.arg("--queue-num")
.arg("200")
.arg("--queue-bypass")
.status()
.expect("failed to add iptables rules");
Ok(())
}
pub fn clear_iptables_rules() -> Result<(), Box<dyn error::Error>> {
let ipt = iptables::new(false)?;
Command::new("iptables")
.arg("-t")
.arg("mangle")
.arg("-D")
.arg("POSTROUTING")
.arg("-j")
.arg("NFQUEUE")
.arg("--queue-num")
.arg("200")
.arg("--queue-bypass")
.status()
.expect("failed to remove iptables rules");
ipt.delete(
"mangle",
"POSTROUTING",
"-j NFQUEUE --queue-num 200 --queue-bypass",
)?;
Command::new("iptables")
.arg("-t")
.arg("mangle")
.arg("-D")
.arg("PREROUTING")
.arg("-j")
.arg("NFQUEUE")
.arg("--queue-num")
.arg("200")
.arg("--queue-bypass")
.status()
.expect("failed to remove iptables rules");
ipt.delete(
"mangle",
"PREROUTING",
"-j NFQUEUE --queue-num 200 --queue-bypass",
)?;
ipt.delete(
"filter",
"FORWARD",
"-j NFQUEUE --queue-num 200 --queue-bypass",
)?;
Command::new("iptables")
.arg("-t")
.arg("filter")
.arg("-D")
.arg("FORWARD")
.arg("-j")
.arg("NFQUEUE")
.arg("--queue-num")
.arg("200")
.arg("--queue-bypass")
.status()
.expect("failed to remove iptables rules");
Ok(())
}

View File

@@ -12,10 +12,14 @@ use std::ffi::CString;
use std::os::raw::c_char;
use std::path::Path;
use std::sync::LazyLock;
use anyhow::bail;
use tokio::fs::File;
use tokio::io::{copy, AsyncWriteExt};
use tokio::task::spawn_blocking;
pub static MODULE_PATH: LazyLock<&Path> =
LazyLock::new(|| Path::new("/data/adb/modules/zaprett"));
pub static MODULE_PATH: LazyLock<&Path> = LazyLock::new(|| Path::new("/data/adb/modules/zaprett"));
pub static ZAPRETT_DIR_PATH: LazyLock<&Path> =
LazyLock::new(|| Path::new("/storage/emulated/0/zaprett"));
@@ -28,17 +32,21 @@ pub static DEFAULT_START: &str = "
--filter-udp=443 --dpi-desync=fake --dpi-desync-repeats=6 $hostlist
";
fn module_version() {
if let Ok(prop) = Ini::load_from_file(MODULE_PATH.join("module.prop"))
&& let Some(props) = prop.section::<String>(None)
async fn module_version() -> anyhow::Result<String> {
let prop = spawn_blocking(|| Ini::load_from_file(MODULE_PATH.join("module.prop")))
.await??;
if let Some(props) = prop.section::<String>(None)
&& let Some(version) = props.get("version")
{
println!("{version}");
return Ok(version.into());
}
bail!("Failed to get version, prop not found")
}
fn bin_version() {
println!("{}", env!("ZAPRET_VERSION"));
fn bin_version() -> &'static str {
env!("ZAPRET_VERSION")
}
pub async fn merge_files(

View File

@@ -13,6 +13,7 @@ use sysinfo::{Pid as SysPid, System};
use tokio::fs;
use tokio::fs::File;
use tokio::io::AsyncReadExt;
use std::path::Path;
pub async fn start_service() -> anyhow::Result<()> {
if !Uid::effective().is_root() {
@@ -106,17 +107,19 @@ pub async fn service_status() -> anyhow::Result<bool> {
bail!("Running not from root, exiting");
};
let Ok(Some(pid)) = fs::read_to_string(MODULE_PATH.join("/tmp/pid.lock"))
.await
.map(|s| s.trim().parse::<usize>().ok())
else {
bail!("failed to get pid");
let pid_i32 = match fs::read_to_string(Path::new(*MODULE_PATH).join("tmp/pid.lock")).await {
Ok(s) => match s.trim().parse::<i32>() {
Ok(pid) => pid,
Err(_) => return Ok(false),
},
Err(_) => return Ok(false),
};
let is_zaprett = System::new_all()
.process(SysPid::from(pid))
.map(|process| process.name() == "zaprett")
.unwrap_or(false);
Ok(is_zaprett)
let pid = SysPid::from(pid_i32 as usize);
let system = System::new_all();
if let Some(process) = system.process(pid) {
if process.name() == "zaprett" {
return Ok(true);
}
}
Ok(false)
}

View File

@@ -21,7 +21,7 @@ ui_print "Filling configuration file if not exist..."
if [ ! -f "/sdcard/zaprett/config.json" ]; then
cat > /sdcard/zaprett/config.json << EOL
{
"active_lists": ["/sdcard/zaprett/lists/include/list-youtube.txt", "/sdcard/zaprett/lists/include/list-youtube.txt"],
"active_lists": ["/sdcard/zaprett/lists/include/list-youtube.txt", "/sdcard/zaprett/lists/include/list-discord.txt"],
"active_ipsets": [],
"active_exclude_lists": [],
"active_exclude_ipsets": [],
@@ -31,7 +31,7 @@ if [ ! -f "/sdcard/zaprett/config.json" ]; then
"whitelist": [],
"blacklist": []
}
EOL
EOL
fi
ui_print "Copying lists and binaries to /sdcard/zaprett..."