windows: the service, its API and proxy-ctl
ps-ipc: line-delimited JSON over a named pipe whose ACL admits SYSTEM, Administrators and (with userControl) the interactive user; the caller is identified by impersonation, never by what it claims. A Unix socket stands in off Windows. ps-service (proxy-suite-service.exe): a Windows service, or --console. Keeps the configuration with revisions, runtime state and generated secrets; renders, checks with sing-box check before replacing what runs, and supervises the backends (restart with backoff, start limit, logs in a ring and a file, a Job Object on Windows). Enforces scopes, admin-only edits and secret redaction that round-trips. Fetches subscriptions and rule sets through the proxy or directly with upstream's redirect rules, on timers. ps-ctl (proxy-ctl.exe): status, restart, logs [-f], config get/set/ validate, and proxy on/off, outbounds, pin, mode, subs, rules, rulesets, tun and config. An end-to-end test runs it all offline: a sing-box Shadowsocks server, the service, proxy-ctl adding the outbound, a page fetched through the local proxy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
918cdc9a75
commit
41c8ed4406
25 files changed
+5411
-7
No files matched your search
@@ -158,11 +158,14 @@ impl Default for AutoProxy {
|
||||
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
||||
pub struct SingBoxOptions {
|
||||
pub clash_api_port: u16,
|
||||
/// Windows only: the loopback listener `proxy-ctl proxy outbounds test` reaches each
|
||||
/// outbound through. Upstream fixes it at 18537.
|
||||
pub test_port: u16,
|
||||
}
|
||||
|
||||
impl Default for SingBoxOptions {
|
||||
fn default() -> Self {
|
||||
Self { clash_api_port: 9090 }
|
||||
Self { clash_api_port: 9090, test_port: 18537 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -565,7 +565,9 @@ fn ports(cfg: &Config, v: &mut Issues) {
|
||||
if p.backend.runs_sing_box() {
|
||||
claim(p.sing_box.clash_api_port, "proxy.singBox.clashApiPort".into(), v);
|
||||
}
|
||||
claim(derived::ports::OUTBOUND_TEST, "the outbound test listener".into(), v);
|
||||
if p.backend.runs_sing_box() {
|
||||
claim(p.sing_box.test_port, "proxy.singBox.testPort".into(), v);
|
||||
}
|
||||
}
|
||||
if cfg.tor.enable {
|
||||
claim(cfg.tor.socks_port, "tor.socksPort".into(), v);
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
//! Time spans as the options write them: systemd's ("1d", "6h", "1h 30min") and Go's
|
||||
//! ("3m", "15s", "1m30s", "500ms").
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
/// A span such as "1d", "6h 30m", "1m30s" or "500ms". A bare number is seconds.
|
||||
pub fn parse(text: &str) -> Option<Duration> {
|
||||
let text = text.trim();
|
||||
if text.is_empty() {
|
||||
return None;
|
||||
}
|
||||
if let Ok(secs) = text.parse::<f64>() {
|
||||
return (secs >= 0.0).then(|| Duration::from_secs_f64(secs));
|
||||
}
|
||||
let mut total = 0f64;
|
||||
let mut rest = text;
|
||||
while !rest.is_empty() {
|
||||
rest = rest.trim_start();
|
||||
let num_len = rest.find(|c: char| !(c.is_ascii_digit() || c == '.')).unwrap_or(rest.len());
|
||||
if num_len == 0 {
|
||||
return None;
|
||||
}
|
||||
let value: f64 = rest[..num_len].parse().ok()?;
|
||||
rest = &rest[num_len..];
|
||||
let unit_len = rest.find(|c: char| !c.is_ascii_alphabetic()).unwrap_or(rest.len());
|
||||
let unit = &rest[..unit_len];
|
||||
rest = &rest[unit_len..];
|
||||
let factor = match unit {
|
||||
"ns" => 1e-9,
|
||||
"us" | "µs" => 1e-6,
|
||||
"ms" | "msec" => 1e-3,
|
||||
"s" | "sec" | "second" | "seconds" | "" => 1.0,
|
||||
"m" | "min" | "minute" | "minutes" => 60.0,
|
||||
"h" | "hr" | "hour" | "hours" => 3600.0,
|
||||
"d" | "day" | "days" => 86400.0,
|
||||
"w" | "week" | "weeks" => 604800.0,
|
||||
_ => return None,
|
||||
};
|
||||
total += value * factor;
|
||||
}
|
||||
Some(Duration::from_secs_f64(total))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn both_spellings_read() {
|
||||
assert_eq!(parse("1d"), Some(Duration::from_secs(86400)));
|
||||
assert_eq!(parse("6h 30min"), Some(Duration::from_secs(6 * 3600 + 1800)));
|
||||
assert_eq!(parse("1m30s"), Some(Duration::from_secs(90)));
|
||||
assert_eq!(parse("500ms"), Some(Duration::from_millis(500)));
|
||||
assert_eq!(parse("45"), Some(Duration::from_secs(45)));
|
||||
assert_eq!(parse("soon"), None);
|
||||
assert_eq!(parse("3x"), None);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
pub mod config;
|
||||
pub mod derived;
|
||||
pub mod duration;
|
||||
pub mod links;
|
||||
pub mod render;
|
||||
pub mod wg;
|
||||
@@ -104,7 +104,7 @@ pub(super) fn config(input: &Input, asm: &Assembly, warnings: &mut Vec<String>)
|
||||
inbounds.push(mixed);
|
||||
// The test listener `proxy-ctl proxy outbounds test` dials each outbound through, by the
|
||||
// Clash API's switching of its selector.
|
||||
let mut test_in = json!({ "type": "mixed", "tag": "proxy-suite-test-in", "listen": "127.0.0.1", "listen_port": ports::OUTBOUND_TEST });
|
||||
let mut test_in = json!({ "type": "mixed", "tag": "proxy-suite-test-in", "listen": "127.0.0.1", "listen_port": p.sing_box.test_port });
|
||||
if let Some(users) = &users {
|
||||
test_in["users"] = users.clone();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user