mirror of
https://github.com/egor-white/zaprett.git
synced 2025-12-10 21:40:12 +05:00
fix shitcode
This commit is contained in:
@@ -8,8 +8,7 @@ use nix::sys::signal::{Signal, kill};
|
|||||||
use nix::unistd::{Pid, Uid};
|
use nix::unistd::{Pid, Uid};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::path::Path;
|
use sysctl::{Ctl, CtlValue, Sysctl};
|
||||||
use sysctl::Sysctl;
|
|
||||||
use sysinfo::{Pid as SysPid, System};
|
use sysinfo::{Pid as SysPid, System};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
@@ -62,8 +61,8 @@ pub async fn start_service() -> anyhow::Result<()> {
|
|||||||
.replace_all(&strat_modified, ZAPRETT_DIR_PATH.to_str().unwrap())
|
.replace_all(&strat_modified, ZAPRETT_DIR_PATH.to_str().unwrap())
|
||||||
.into_owned();
|
.into_owned();
|
||||||
|
|
||||||
let ctl = sysctl::Ctl::new("net.netfilter.nf_conntrack_tcp_be_liberal")?;
|
let ctl = Ctl::new("net.netfilter.nf_conntrack_tcp_be_liberal")?;
|
||||||
ctl.set_value(sysctl::CtlValue::String("1".into()))?;
|
ctl.set_value(CtlValue::String("1".into()))?;
|
||||||
|
|
||||||
setup_iptables_rules().expect("setup iptables rules");
|
setup_iptables_rules().expect("setup iptables rules");
|
||||||
|
|
||||||
@@ -106,19 +105,17 @@ pub async fn service_status() -> anyhow::Result<bool> {
|
|||||||
bail!("Running not from root, exiting");
|
bail!("Running not from root, exiting");
|
||||||
};
|
};
|
||||||
|
|
||||||
let pid_i32 = match fs::read_to_string(Path::new(*MODULE_PATH).join("tmp/pid.lock")).await {
|
let Ok(Some(pid)) = fs::read_to_string(MODULE_PATH.join("/tmp/pid.lock"))
|
||||||
Ok(s) => match s.trim().parse::<i32>() {
|
.await
|
||||||
Ok(pid) => pid,
|
.map(|s| s.trim().parse::<usize>().ok())
|
||||||
Err(_) => return Ok(false),
|
else {
|
||||||
},
|
bail!("failed to get pid");
|
||||||
Err(_) => return Ok(false),
|
|
||||||
};
|
};
|
||||||
let pid = SysPid::from(pid_i32 as usize);
|
|
||||||
let system = System::new_all();
|
let is_zaprett = System::new_all()
|
||||||
if let Some(process) = system.process(pid) {
|
.process(SysPid::from(pid))
|
||||||
if process.name() == "zaprett" {
|
.map(|process| process.name() == "zaprett")
|
||||||
return Ok(true);
|
.unwrap_or(false);
|
||||||
}
|
|
||||||
}
|
Ok(is_zaprett)
|
||||||
Ok(false)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user