mirror of
https://github.com/egor-white/zaprett.git
synced 2026-03-22 00:18:13 +05:00
add nfqws2 launching, config field for service type, remove unused import in nfqws2's build.rs
This commit is contained in:
@@ -10,10 +10,14 @@ echo "Make build dirs"
|
||||
mkdir -p zaprett/system/bin
|
||||
mkdir -p zaprett/zaprett/bin
|
||||
mkdir -p zaprett/zaprett/lists/include
|
||||
mkdir -p zaprett/zaprett/lists/exclude
|
||||
mkdir -p zaprett/zaprett/strategies/nfqws2/libs
|
||||
mkdir -p zaprett-hosts/system/bin
|
||||
mkdir -p zaprett-hosts/system/etc
|
||||
mkdir -p zaprett-hosts/zaprett/bin
|
||||
mkdir -p zaprett-hosts/zaprett/lists/include
|
||||
mkdir -p zaprett-hosts/zaprett/lists/exclude
|
||||
mkdir -p zaprett/zaprett/strategies/nfqws2/libs
|
||||
mkdir -p out lists
|
||||
|
||||
echo "Copy files to dirs"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
macro_rules! rel_manifest_path {
|
||||
($name:ident, $path:expr) => {
|
||||
|
||||
@@ -10,17 +10,36 @@ pub enum ListType {
|
||||
Blacklist,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ServiceType {
|
||||
#[default]
|
||||
Nfqws,
|
||||
Nfqws2,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ApplistType {
|
||||
#[default]
|
||||
None,
|
||||
Blacklist,
|
||||
Whitelist,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Getters)]
|
||||
#[getset(get = "pub")]
|
||||
#[serde(default)]
|
||||
pub struct Config {
|
||||
service_type: ServiceType,
|
||||
active_lists: Vec<String>,
|
||||
active_ipsets: Vec<String>,
|
||||
active_exclude_lists: Vec<String>,
|
||||
active_exclude_ipsets: Vec<String>,
|
||||
list_type: ListType,
|
||||
strategy: String,
|
||||
app_list: String,
|
||||
strategy_nfqws2: String,
|
||||
app_list: ApplistType,
|
||||
whitelist: Vec<String>,
|
||||
blacklist: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ pub static MODULE_PATH: LazyLock<&Path> =
|
||||
pub static ZAPRETT_DIR_PATH: LazyLock<&Path> =
|
||||
LazyLock::new(|| Path::new("/storage/emulated/0/zaprett"));
|
||||
|
||||
pub static ZAPRETT_LIBS_PATH: LazyLock<&Path> =
|
||||
LazyLock::new(|| Path::new("/storage/emulated/0/zaprett/strategies/nfwqs2/libs"));
|
||||
|
||||
pub static DEFAULT_STRATEGY_NFQWS: &str = "
|
||||
--filter-tcp=80 --dpi-desync=fake,split2 --dpi-desync-autottl=2 --dpi-desync-fooling=md5sig,badsum $hostlist --new
|
||||
--filter-tcp=443 $hostlist --dpi-desync=fake,split2 --dpi-desync-repeats=6 --dpi-desync-fooling=md5sig,badsum --dpi-desync-fake-tls=${zaprettdir}/bin/tls_clienthello_www_google_com.bin --new
|
||||
@@ -33,6 +36,10 @@ pub static DEFAULT_STRATEGY_NFQWS: &str = "
|
||||
--filter-udp=443 --dpi-desync=fake --dpi-desync-repeats=6 $hostlist
|
||||
";
|
||||
|
||||
pub static DEFAULT_STRATEGY_NFQWS2: &str = "
|
||||
/// я всё ещё жду стратегию под nfqws2
|
||||
";
|
||||
|
||||
async fn module_version() -> anyhow::Result<String> {
|
||||
let prop = spawn_blocking(|| Ini::load_from_file(MODULE_PATH.join("module.prop")))
|
||||
.await??;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::config::Config;
|
||||
use crate::config::{Config, ServiceType};
|
||||
use crate::daemon::daemonize_nfqws;
|
||||
use crate::daemon::daemonize_nfqws2;
|
||||
use crate::iptables_rust::{clear_iptables_rules, setup_iptables_rules};
|
||||
use crate::{DEFAULT_STRATEGY_NFQWS, MODULE_PATH, ZAPRETT_DIR_PATH};
|
||||
use crate::{DEFAULT_STRATEGY_NFQWS, DEFAULT_STRATEGY_NFQWS2, MODULE_PATH, ZAPRETT_DIR_PATH, ZAPRETT_LIBS_PATH};
|
||||
use anyhow::bail;
|
||||
use log::info;
|
||||
use nix::sys::signal::{Signal, kill};
|
||||
@@ -53,10 +54,21 @@ pub async fn start_service() -> anyhow::Result<()> {
|
||||
|
||||
let config: Config = serde_json::from_str(&config_contents)?;
|
||||
|
||||
let start = fs::read_to_string(config.strategy())
|
||||
.await
|
||||
.map(Cow::Owned)
|
||||
.unwrap_or(Cow::Borrowed(DEFAULT_STRATEGY_NFQWS));
|
||||
let start: Cow<str> = if config.service_type() == &ServiceType::Nfqws {
|
||||
fs::read_to_string(config.strategy())
|
||||
.await
|
||||
.map(Cow::Owned)
|
||||
.unwrap_or(Cow::Borrowed(DEFAULT_STRATEGY_NFQWS))
|
||||
}
|
||||
else if config.service_type() == &ServiceType::Nfqws2 {
|
||||
fs::read_to_string(config.strategy_nfqws2())
|
||||
.await
|
||||
.map(Cow::Owned)
|
||||
.unwrap_or(Cow::Borrowed(DEFAULT_STRATEGY_NFQWS2))
|
||||
}
|
||||
else {
|
||||
bail!("Broken config file!");
|
||||
};
|
||||
|
||||
let regex_hostlist = Regex::new(r"\$(?:hostlist|\{hostlist})")?;
|
||||
let regex_ipsets = Regex::new(r"\$(?:ipset|\{ipset})")?;
|
||||
@@ -75,12 +87,25 @@ pub async fn start_service() -> anyhow::Result<()> {
|
||||
.replace_all(&strat_modified, ZAPRETT_DIR_PATH.to_str().unwrap())
|
||||
.into_owned();
|
||||
|
||||
strat_modified = regex_libsdir
|
||||
.replace_all(&strat_modified, ZAPRETT_LIBS_PATH.to_str().unwrap())
|
||||
.into_owned();
|
||||
|
||||
let ctl = Ctl::new("net.netfilter.nf_conntrack_tcp_be_liberal")?;
|
||||
ctl.set_value(CtlValue::String("1".into()))?;
|
||||
|
||||
setup_iptables_rules().expect("setup iptables rules");
|
||||
|
||||
daemonize_nfqws(&strat_modified).await;
|
||||
if config.service_type() == &ServiceType::Nfqws {
|
||||
daemonize_nfqws(&strat_modified).await;
|
||||
}
|
||||
else if config.service_type() == &ServiceType::Nfqws2 {
|
||||
daemonize_nfqws2(&strat_modified).await;
|
||||
}
|
||||
else {
|
||||
bail!("Broken config file!");
|
||||
}
|
||||
|
||||
println!("zaprett service started!");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user