windows: the service names zapret's presets and tg-ws-proxy's links
- zapret-presets: the presets of the installed zapret release and the one configured; proxy-ctl zapret presets. - tg-links: tg-ws-proxy's tg:// links (dd, and ee with a fake-TLS domain), as it prints them; they carry its secret, so the secrets scope. proxy-ctl tg link. No more reading them out of its log. - tools/dev-service.sh: the service on Linux with a demo outbound, for working on the app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4ae30dac3c
commit
63aede0dc1
5 files changed
+136
-1
No files matched your search
@@ -133,7 +133,7 @@ fn scope_of(req: &Request) -> Option<Scope> {
|
||||
Request::Pin { .. } | Request::Mode { .. } | Request::RuleSetsUpdate => Some(Scope::Routing),
|
||||
Request::Disable { .. } | Request::SubsUpdate { .. } | Request::Test { .. } => Some(Scope::Outbounds),
|
||||
// Backend logs name the sites visited (at info), and errors may quote what was dialled.
|
||||
Request::RenderedConfig | Request::Logs { .. } => Some(Scope::Secrets),
|
||||
Request::RenderedConfig | Request::Logs { .. } | Request::TgLinks => Some(Scope::Secrets),
|
||||
Request::Restart { .. } | Request::Start { .. } | Request::Stop { .. } => Some(Scope::Services),
|
||||
_ => None,
|
||||
}
|
||||
@@ -454,6 +454,27 @@ pub async fn handle(req: Request, peer: &Peer, shared: &Shared) -> Response {
|
||||
Response::ok(json!(list))
|
||||
}
|
||||
|
||||
Request::ZapretPresets => {
|
||||
let s = shared.lock().await;
|
||||
let bats: Vec<String> = std::fs::read_dir(s.paths().bin().join("zapret"))
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|e| e.ok()?.file_name().into_string().ok())
|
||||
.collect();
|
||||
Response::ok(json!({
|
||||
"presets": ps_core::zapret::presets(&bats),
|
||||
"current": s.cfg().zapret.discord_youtube.config_name,
|
||||
}))
|
||||
}
|
||||
|
||||
Request::TgLinks => {
|
||||
let s = shared.lock().await;
|
||||
match crate::tg::secret(s.cfg(), s.paths()) {
|
||||
Ok(secret) => Response::ok(json!({ "links": crate::tg::links(s.cfg(), &secret) })),
|
||||
Err(e) => Response::err(format!("tg-ws-proxy's secret: {e:#}")),
|
||||
}
|
||||
}
|
||||
|
||||
Request::ComponentsInstall { names } => {
|
||||
// Programs the service runs as SYSTEM: an administrator's call, whatever the scopes.
|
||||
if !peer.admin {
|
||||
|
||||
@@ -52,6 +52,26 @@ pub fn args(cfg: &Config, secret: &str) -> Vec<String> {
|
||||
a
|
||||
}
|
||||
|
||||
/// The links tg-ws-proxy prints for itself: `dd` with the secret, and `ee` with the fake-TLS
|
||||
/// domain after it when one is set. A wildcard listener is named by this machine's address.
|
||||
pub fn links(cfg: &Config, secret: &str) -> Vec<String> {
|
||||
let t = &cfg.tg_ws_proxy;
|
||||
let host = match t.listener.address.as_str() {
|
||||
"0.0.0.0" => std::net::UdpSocket::bind("0.0.0.0:0")
|
||||
.and_then(|s| s.connect("8.8.8.8:80").and_then(|()| s.local_addr()))
|
||||
.map(|a| a.ip().to_string())
|
||||
.unwrap_or_else(|_| "127.0.0.1".into()),
|
||||
h => h.to_owned(),
|
||||
};
|
||||
let base = format!("tg://proxy?server={host}&port={}&secret=", t.listener.port);
|
||||
let mut out = vec![format!("{base}dd{secret}")];
|
||||
if let Some(domain) = t.fake_tls_domain.as_deref().filter(|d| !d.is_empty()) {
|
||||
let hex: String = domain.bytes().map(|b| format!("{b:02x}")).collect();
|
||||
out.push(format!("{base}ee{secret}{hex}"));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The secret: given, or read from `secretFile`, or one generated once and kept.
|
||||
pub fn secret(cfg: &Config, paths: &Paths) -> Result<String> {
|
||||
let t = &cfg.tg_ws_proxy;
|
||||
@@ -89,6 +109,15 @@ pub fn unit(cfg: &Config, paths: &Paths, python: PathBuf) -> Result<UnitSpec> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn links_are_tg_ws_proxys() {
|
||||
let mut cfg = Config::default();
|
||||
cfg.tg_ws_proxy.listener.port = 1443;
|
||||
assert_eq!(links(&cfg, "ab"), ["tg://proxy?server=127.0.0.1&port=1443&secret=ddab"]);
|
||||
cfg.tg_ws_proxy.fake_tls_domain = Some("x.io".into());
|
||||
assert_eq!(links(&cfg, "ab")[1], "tg://proxy?server=127.0.0.1&port=1443&secret=eeab782e696f");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upstreams_flags() {
|
||||
let mut cfg = Config::default();
|
||||
|
||||
Reference in new issue
Block a user