mirror of
https://github.com/egor-white/zaprett.git
synced 2026-03-22 00:18:13 +05:00
Compare commits
5 Commits
2b17b53a0a
...
15b15f4932
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15b15f4932 | ||
|
|
c050ee22b8 | ||
|
|
6c979bdeea | ||
|
|
05105fd0dc | ||
|
|
a2da8496a1 |
@@ -19,14 +19,17 @@ target_include_directories(nfqws PRIVATE
|
||||
target_compile_definitions(nfqws PRIVATE main=nfqws_main)
|
||||
target_compile_options(nfqws PRIVATE -w)
|
||||
|
||||
find_library(LOG_LIB log)
|
||||
target_link_libraries(nfqws PRIVATE ${LOG_LIB})
|
||||
if(ANDROID)
|
||||
find_library(LOG_LIB log)
|
||||
target_link_libraries(nfqws PRIVATE ${LOG_LIB})
|
||||
endif()
|
||||
|
||||
target_link_libraries(nfqws PRIVATE
|
||||
$ENV{NETFILTER_LIBS}/lib/libnetfilter_queue.a
|
||||
$ENV{NETFILTER_LIBS}/lib/libnfnetlink.a
|
||||
$ENV{NETFILTER_LIBS}/lib/libmnl.a
|
||||
z
|
||||
netfilter_queue
|
||||
nfnetlink
|
||||
mnl
|
||||
unwind
|
||||
)
|
||||
|
||||
install(TARGETS nfqws
|
||||
|
||||
@@ -17,16 +17,18 @@ target_include_directories(nfqws2 PRIVATE
|
||||
target_compile_definitions(nfqws2 PRIVATE main=nfqws2_main)
|
||||
target_compile_options(nfqws2 PRIVATE -w)
|
||||
|
||||
find_library(LOG_LIB log)
|
||||
target_link_libraries(nfqws2 PRIVATE ${LOG_LIB})
|
||||
if(ANDROID)
|
||||
find_library(LOG_LIB log)
|
||||
target_link_libraries(nfqws2 PRIVATE ${LOG_LIB})
|
||||
endif()
|
||||
|
||||
target_link_libraries(nfqws2 PRIVATE
|
||||
z
|
||||
netfilter_queue
|
||||
nfnetlink
|
||||
mnl
|
||||
unwind
|
||||
$ENV{NETFILTER_LIBS}/lib/libnetfilter_queue.a
|
||||
$ENV{NETFILTER_LIBS}/lib/libnfnetlink.a
|
||||
$ENV{NETFILTER_LIBS}/lib/libmnl.a
|
||||
$ENV{LUAJIT_LIBS}/lib/libluajit-5.1.a
|
||||
z
|
||||
unwind
|
||||
)
|
||||
|
||||
install(TARGETS nfqws2
|
||||
|
||||
@@ -137,10 +137,15 @@ fn run_nfqws(args_str: &str) -> anyhow::Result<()> {
|
||||
.map(|arg| CString::new(arg).unwrap())
|
||||
.collect();
|
||||
|
||||
let mut ptrs: Vec<*const c_char> = c_args.iter().map(|arg| arg.as_ptr()).collect();
|
||||
let mut ptrs: Vec<*mut c_char> = c_args
|
||||
.iter()
|
||||
.map(|arg| arg.as_ptr() as *mut c_char)
|
||||
.collect();
|
||||
|
||||
ptrs.push(std::ptr::null_mut());
|
||||
|
||||
unsafe {
|
||||
nfqws_main(c_args.len() as libc::c_int, ptrs.as_mut_ptr() as *mut _);
|
||||
nfqws_main(c_args.len() as libc::c_int, ptrs.as_mut_ptr());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -165,10 +170,15 @@ fn run_nfqws2(args_str: &str) -> anyhow::Result<()> {
|
||||
.map(|arg| CString::new(arg).unwrap())
|
||||
.collect();
|
||||
|
||||
let mut ptrs: Vec<*const c_char> = c_args.iter().map(|arg| arg.as_ptr()).collect();
|
||||
let mut ptrs: Vec<*mut c_char> = c_args
|
||||
.iter()
|
||||
.map(|arg| arg.as_ptr() as *mut c_char)
|
||||
.collect();
|
||||
|
||||
ptrs.push(std::ptr::null_mut());
|
||||
|
||||
unsafe {
|
||||
nfqws2_main(c_args.len() as libc::c_int, ptrs.as_mut_ptr() as *mut _);
|
||||
nfqws2_main(c_args.len() as libc::c_int, ptrs.as_mut_ptr());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -33,9 +33,10 @@ pub async fn start_service() -> anyhow::Result<()> {
|
||||
let tmp_dir = MODULE_PATH.join("tmp");
|
||||
if tmp_dir.exists() {
|
||||
fs::remove_dir_all(&tmp_dir).await?;
|
||||
fs::create_dir_all(&tmp_dir).await?;
|
||||
}
|
||||
|
||||
fs::create_dir_all(&tmp_dir).await?;
|
||||
|
||||
let config_path = ZAPRETT_DIR_PATH.join("config.json");
|
||||
let mut config_contents = String::new();
|
||||
|
||||
@@ -78,6 +79,7 @@ pub async fn start_service() -> anyhow::Result<()> {
|
||||
let regex_ipsets = Regex::new(r"\$(?:ipsets|\{ipsets})")?;
|
||||
let regex_zaprettdir = Regex::new(r"\$(?:zaprettdir|\{zaprettdir})")?;
|
||||
let regex_libsdir = Regex::new(r"\$(?:libsdir|\{libsdir})")?;
|
||||
let regex_bindir = Regex::new(r"\$\{bin:([^}]+)\}")?;
|
||||
let (hosts, ipsets) = config.list_type().merge(&config).await?;
|
||||
let hostlists: HashMap<String, Manifest> =
|
||||
get_all_manifests(&ZAPRETT_DIR_PATH.join("manifests/lists/include"))
|
||||
@@ -103,10 +105,17 @@ pub async fn start_service() -> anyhow::Result<()> {
|
||||
.into_iter()
|
||||
.map(|m| (m.id().clone(), m))
|
||||
.collect();
|
||||
let strat_modified = prepare_manifests(&start, ®ex_hostlist, &hostlists, &tmp_dir)?;
|
||||
let strat_modified = prepare_manifests(&strat_modified, ®ex_hostlist_exclude, &hostlists_exclude, &tmp_dir)?;
|
||||
let strat_modified = prepare_manifests(&strat_modified, ®ex_ipset, &ipset, &tmp_dir)?;
|
||||
let strat_modified = prepare_manifests(&strat_modified, ®ex_ipset_exclude, &ipset_exclude, &tmp_dir)?;
|
||||
let bins: HashMap<String, Manifest> =
|
||||
get_all_manifests(&ZAPRETT_DIR_PATH.join("manifests/bin"))
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|m| (m.id().clone(), m))
|
||||
.collect();
|
||||
let strat_modified = prepare_manifests(&start, ®ex_hostlist, &hostlists, &tmp_dir, "txt")?;
|
||||
let strat_modified = prepare_manifests(&strat_modified, ®ex_hostlist_exclude, &hostlists_exclude, &tmp_dir, "txt")?;
|
||||
let strat_modified = prepare_manifests(&strat_modified, ®ex_ipset, &ipset, &tmp_dir, "txt")?;
|
||||
let strat_modified = prepare_manifests(&strat_modified, ®ex_ipset_exclude, &ipset_exclude, &tmp_dir, "txt")?;
|
||||
let strat_modified = prepare_manifests(&strat_modified, ®ex_bindir, &bins, &tmp_dir, "bin")?;
|
||||
let strat_modified = regex_hostlists.replace_all(&strat_modified, &hosts);
|
||||
let strat_modified = regex_ipsets.replace_all(&strat_modified, &ipsets);
|
||||
let strat_modified =
|
||||
|
||||
@@ -3,7 +3,7 @@ use regex::Regex;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn prepare_manifests(input: &str, regex: &Regex, manifests: &HashMap<String, Manifest>, tmp_dir: &Path) -> anyhow::Result<String> {
|
||||
pub fn prepare_manifests(input: &str, regex: &Regex, manifests: &HashMap<String, Manifest>, tmp_dir: &Path, ext: &str) -> anyhow::Result<String> {
|
||||
let required: HashSet<String> = regex.captures_iter(input).map(|c| c[1].to_string()).collect();
|
||||
let mut paths: HashMap<String, PathBuf> = HashMap::new();
|
||||
for id in &required {
|
||||
@@ -11,7 +11,8 @@ pub fn prepare_manifests(input: &str, regex: &Regex, manifests: &HashMap<String,
|
||||
.get(id)
|
||||
.ok_or_else(|| anyhow::anyhow!("Manifest not found: {}", id))?;
|
||||
let path = Path::new(manifest.file());
|
||||
let dst = tmp_dir.join(format!("{}.txt", id));
|
||||
let mut dst = tmp_dir.join(id);
|
||||
dst.set_extension(ext);
|
||||
std::fs::copy(path, &dst)?;
|
||||
paths.insert(id.clone(), dst);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user