windows: what is not on Windows yet is said, for as long as it holds
The configuration accepted the kill switch, AmneziaWG, WARP, Tor, the SSH tunnel, whitelist-bypass, serving inbounds, autoProxy, the xray backend, zapret's hostlistRules, z2k and zapret2's extended detection, and the service silently did nothing with them: a kill switch turned on looked like protection that was not there. The validator now warns for each, and for TUN with zapret together; the status carries the configuration's warnings as well as the rendering's, so the app's overview and proxy-ctl status show them until they no longer hold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c0b089dea8
commit
88c8b88a49
2 files changed
+63
-3
No files matched your search
@@ -5,7 +5,7 @@ use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{Backend, Config, GroupStrategy, Selection, ZapretEngine};
|
||||
use super::{Backend, Config, GroupStrategy, Selection, StrategySource, ZapretEngine};
|
||||
use crate::derived::{self, BUILTIN_TAGS};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -85,11 +85,52 @@ pub fn validate(cfg: &Config) -> Vec<Issue> {
|
||||
per_app(cfg, &mut v);
|
||||
inbounds(cfg, &mut v);
|
||||
ports(cfg, &mut v);
|
||||
not_ported(cfg, &mut v);
|
||||
let mut issues = v.0;
|
||||
issues.sort_by_key(|i| i.severity != Severity::Error);
|
||||
issues
|
||||
}
|
||||
|
||||
/// What upstream runs and this port does not yet: said, never taken silently. (The kill switch
|
||||
/// above all: on, it would otherwise look like protection that is not there.)
|
||||
fn not_ported(cfg: &Config, v: &mut Issues) {
|
||||
const IGNORED: &str = "is not on Windows yet: this release ignores it";
|
||||
if cfg.kill_switch.enable {
|
||||
v.warn("killSwitch.enable", "the kill switch is not on Windows yet: nothing blocks traffic that bypasses the tunnel");
|
||||
}
|
||||
for (on, path, what) in [
|
||||
(cfg.amnezia_wg.enable, "amneziaWg.enable", "AmneziaWG"),
|
||||
(cfg.warp.enable, "warp.enable", "WARP"),
|
||||
(cfg.tor.enable, "tor.enable", "Tor"),
|
||||
(cfg.ssh_proxy.enable, "sshProxy.enable", "The SSH tunnel"),
|
||||
(cfg.whitelist_bypass.enable, "whitelistBypass.enable", "whitelist-bypass"),
|
||||
(cfg.inbounds.enable, "inbounds.enable", "Serving inbounds"),
|
||||
(cfg.proxy.auto_proxy.enable, "proxy.autoProxy.enable", "autoProxy"),
|
||||
] {
|
||||
if on {
|
||||
v.warn(path, format!("{what} {IGNORED}"));
|
||||
}
|
||||
}
|
||||
if cfg.proxy.enable && cfg.proxy.backend == Backend::Xray {
|
||||
v.warn("proxy.backend", "the xray backend is not on Windows yet: the proxy does not start with it (sing-box or hybrid do)");
|
||||
}
|
||||
let z = &cfg.zapret;
|
||||
if z.enable && z.engine == ZapretEngine::DiscordYoutube && !z.discord_youtube.hostlist_rules.is_empty() {
|
||||
v.warn("zapret.zapret-discord-youtube.hostlistRules", "hostlistRules are not on Windows yet: the preset applies to every site");
|
||||
}
|
||||
if z.enable && z.engine == ZapretEngine::Zapret2 {
|
||||
if z.zapret2.strategy_source == StrategySource::Z2k && z.zapret2.profiles.is_none() {
|
||||
v.warn("zapret.zapret2.strategySource", "z2k's strategies are not on Windows yet: zapret2 does not start with them (nfqws2-keenetic's, or your own profiles, do)");
|
||||
}
|
||||
if z.zapret2.auto_hostlist.extended_detection {
|
||||
v.warn("zapret.zapret2.autoHostlist.extendedDetection", "the extended detection is not on Windows yet: nfqws2's own learning is used");
|
||||
}
|
||||
}
|
||||
if z.enable && cfg.proxy.tun.enable {
|
||||
v.warn("proxy.tun.enable", "TUN and zapret together: zapret's packets are not kept off the TUN on Windows yet; use one or the other");
|
||||
}
|
||||
}
|
||||
|
||||
fn proxy(cfg: &Config, v: &mut Issues) {
|
||||
let p = &cfg.proxy;
|
||||
let sing_box = p.backend.runs_sing_box();
|
||||
@@ -678,6 +719,21 @@ mod tests {
|
||||
assert_eq!(errors(&Config::default()), Vec::<String>::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn what_is_not_ported_is_said() {
|
||||
let quiet: Vec<String> = validate(&Config::default()).into_iter().filter(|i| i.message.contains("not on Windows yet")).map(|i| i.path).collect();
|
||||
assert!(quiet.is_empty(), "{quiet:?}");
|
||||
let mut cfg = Config::default();
|
||||
cfg.kill_switch.enable = true;
|
||||
cfg.tor.enable = true;
|
||||
cfg.zapret.enable = true;
|
||||
cfg.proxy.tun.enable = true;
|
||||
let paths: Vec<String> = validate(&cfg).into_iter().filter(|i| i.severity == Severity::Warning && i.message.contains("Windows yet")).map(|i| i.path).collect();
|
||||
for want in ["killSwitch.enable", "tor.enable", "proxy.tun.enable"] {
|
||||
assert!(paths.iter().any(|p| p == want), "{want} not in {paths:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outbound_tags_are_unique_and_not_builtin() {
|
||||
let mut cfg = Config::default();
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::sync::Arc;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use ps_core::config::{Backend, Config, RuleSetFormat};
|
||||
use ps_core::config::{Backend, Config, RuleSetFormat, Severity, validate};
|
||||
use ps_core::render::{self, Env, Input, Rendered};
|
||||
use serde_json::{Value, json};
|
||||
use sha2::{Digest, Sha256};
|
||||
@@ -297,6 +297,10 @@ impl Service {
|
||||
|
||||
pub fn status(&self) -> Value {
|
||||
let cfg = self.cfg();
|
||||
// The rendering's warnings, and the configuration's own (what is not on Windows yet
|
||||
// among them): said for as long as they hold, not only when it is saved.
|
||||
let mut warnings: Vec<String> = self.last.as_ref().map(|r| r.warnings.clone()).unwrap_or_default();
|
||||
warnings.extend(validate(cfg).into_iter().filter(|i| i.severity == Severity::Warning).map(|i| format!("{}: {}", i.path, i.message)));
|
||||
let units: Vec<Value> = self.sup.status().into_iter().map(|u| serde_json::to_value(u).unwrap()).collect();
|
||||
let socks = self.sup.state_of(SOCKS_UNIT);
|
||||
json!({
|
||||
@@ -323,7 +327,7 @@ impl Service {
|
||||
"state": self.sup.state_of(crate::tg::UNIT).as_str(),
|
||||
"listener": format!("{}:{}", cfg.tg_ws_proxy.listener.address, cfg.tg_ws_proxy.listener.port),
|
||||
},
|
||||
"warnings": self.last.as_ref().map(|r| r.warnings.clone()).unwrap_or_default(),
|
||||
"warnings": warnings,
|
||||
"error": self.last_error,
|
||||
"revision": self.store.revision,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user