diff --git a/.gitmodules b/.gitmodules index 4fcbc24..93a7107 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "rust/crates/libnfqws/zapret"] path = rust/crates/libnfqws/zapret url = https://github.com/bol-van/zapret.git +[submodule "rust/crates/iptables"] + path = rust/crates/iptables + url = https://github.com/yaa110/rust-iptables diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 1ee230c..06b4a2a 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -905,7 +905,6 @@ dependencies = [ "libnfqws", "log", "nix", - "once_cell", "pretty_env_logger", "regex", "rust-ini", diff --git a/rust/crates/iptables b/rust/crates/iptables new file mode 160000 index 0000000..e0e1f5d --- /dev/null +++ b/rust/crates/iptables @@ -0,0 +1 @@ +Subproject commit e0e1f5dcc02023dbd162940af1b2f5159677dbd7 diff --git a/rust/crates/zaprett/Cargo.toml b/rust/crates/zaprett/Cargo.toml index e91f660..2cc5b63 100644 --- a/rust/crates/zaprett/Cargo.toml +++ b/rust/crates/zaprett/Cargo.toml @@ -14,7 +14,6 @@ serde = { workspace = true } serde_json = { workspace = true } sysctl ={ workspace = true } tokio = { workspace = true } -once_cell = { workspace = true } libnfqws = { path = "../libnfqws" } daemonize = { workspace = true } pretty_env_logger = { workspace = true } diff --git a/rust/crates/zaprett/src/main.rs b/rust/crates/zaprett/src/main.rs index dbafbe3..f387c37 100644 --- a/rust/crates/zaprett/src/main.rs +++ b/rust/crates/zaprett/src/main.rs @@ -302,14 +302,22 @@ fn get_autostart() { } fn service_status() -> bool { - unimplemented!(); - // match all_processes() { - // Ok(iter) => iter - // .filter_map(|rp| rp.ok()) - // .filter_map(|p| p.stat().ok()) - // .any(|st| st.comm == "zaprett"), - // Err(_) => false, - // } + let pid_str = match fs::read_to_string(MODULE_PATH.join("tmp/pid.lock")) { + Ok(s) => s, + Err(_) => return false, + }; + let pid = match pid_str.trim().parse::() { + Ok(p) => p, + Err(_) => return false, + }; + return true + /*match all_processes() { + Ok(iter) => iter + .filter_map(|rp| rp.ok()) + .filter_map(|p| p.stat().ok()) + .any(|st| st.pid == pid), + Err(_) => false, + }*/ } fn module_version() { diff --git a/rust/remove_os_check.patch b/rust/remove_os_check.patch new file mode 100644 index 0000000..b34a2af --- /dev/null +++ b/rust/remove_os_check.patch @@ -0,0 +1,19 @@ +diff --git a/crates/iptables/src/lib.rs b/crates/iptables/src/lib.rs +index 4a4d6dc..e7d15fc 100644 +--- a/src/lib.rs ++++ b/src/lib.rs +@@ -92,14 +92,6 @@ pub struct IPTables { + pub is_numeric: bool, + } + +-/// Returns `None` because iptables only works on linux +-#[cfg(not(target_os = "linux"))] +-pub fn new(is_ipv6: bool) -> Result> { +- Err(error_from_str("iptables only works on Linux")) +-} +- +-/// Creates a new `IPTables` Result with the command of 'iptables' if `is_ipv6` is `false`, otherwise the command is 'ip6tables'. +-#[cfg(target_os = "linux")] + pub fn new(is_ipv6: bool) -> Result> { + let cmd = if is_ipv6 { "ip6tables" } else { "iptables" }; +