windows: AmneziaWG as a system-wide VPN
Each profile without asOutbound is a tunnel service of its own, AmneziaWGTunnel$<interface>, as amneziawg-windows's client installs one: amneziawg-go on Wintun, its routes and DNS, and for one peer that takes everything its firewall blocking what would leave outside the tunnel. It runs awg-tunnel.exe, amneziawg-windows built from its pinned commit with a main of ours (its Run(), its log in a file) instead of its tunnel.dll, beside Wintun's signed DLL (tools/build-amneziawg.sh). The service writes each profile's .conf below its state root, registers the tunnel (unrestricted service SID, which its firewall exempts it by), starts the autostart ones with itself, and removes the tunnels of profiles gone, and all of them on uninstall. proxy-ctl awg list|on|off|log, and the app's AmneziaWG page: profiles (a system-wide one switched on and off, its log), one added from a vpn:// link or a .conf, or removed. tools/lib.sh: clone_commit, and fetch_pinned, which fetches in pieces a download that stalls (some networks cut TLS after about 16 KB, as wintun.net's here). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
95ec15e14a
commit
5cf3a237e6
30 files changed
+916
-12
No files matched your search
@@ -54,6 +54,11 @@ enum Cmd {
|
||||
#[command(subcommand)]
|
||||
verb: TgVerb,
|
||||
},
|
||||
/// AmneziaWG profiles: the system-wide ones started and stopped.
|
||||
Awg {
|
||||
#[command(subcommand)]
|
||||
verb: Option<AwgVerb>,
|
||||
},
|
||||
/// whitelist-bypass creators and joiners.
|
||||
Wl {
|
||||
#[command(subcommand)]
|
||||
@@ -72,6 +77,22 @@ enum TgVerb {
|
||||
Link,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum AwgVerb {
|
||||
/// Profiles and their state.
|
||||
List,
|
||||
/// Start a system-wide profile's tunnel.
|
||||
On { profile: String },
|
||||
/// Stop it.
|
||||
Off { profile: String },
|
||||
/// Its tunnel's log.
|
||||
Log {
|
||||
profile: String,
|
||||
#[arg(short = 'n', long, default_value_t = 50)]
|
||||
lines: usize,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum WlVerb {
|
||||
/// Creators and joiners, and their state.
|
||||
@@ -681,6 +702,51 @@ async fn zapret(ctl: &Ctl, verb: Option<ZapretVerb>) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn awg(ctl: &Ctl, verb: Option<AwgVerb>) -> Result<()> {
|
||||
match verb.unwrap_or(AwgVerb::List) {
|
||||
AwgVerb::List => {
|
||||
let r = ctl.call(Request::AwgList).await?;
|
||||
if ctl.json {
|
||||
ctl.print(&r);
|
||||
return Ok(());
|
||||
}
|
||||
let profiles = r["profiles"].as_array().cloned().unwrap_or_default();
|
||||
if profiles.is_empty() {
|
||||
println!("No AmneziaWG profiles configured.");
|
||||
return Ok(());
|
||||
}
|
||||
if r["enabled"] != true {
|
||||
println!("AmneziaWG is off (amneziaWg.enable).");
|
||||
}
|
||||
println!(" {:<24} {:<12} {:<12} INTERFACE", "PROFILE", "KIND", "STATUS");
|
||||
for p in profiles {
|
||||
let kind = match p["kind"].as_str().unwrap_or("") {
|
||||
"vpn" => "system VPN",
|
||||
"userspace" => "outbound",
|
||||
"singBox" => "outbound (WG)",
|
||||
k => k,
|
||||
};
|
||||
println!(" {:<24} {:<12} {:<12} {}", p["name"].as_str().unwrap_or(""), kind, p["state"].as_str().unwrap_or(""), p["interface"].as_str().unwrap_or("-"));
|
||||
}
|
||||
}
|
||||
AwgVerb::On { profile } => {
|
||||
let r = ctl.call(Request::AwgSet { name: profile.clone(), on: true }).await?;
|
||||
println!("{profile}: {}", r["state"].as_str().unwrap_or("?"));
|
||||
}
|
||||
AwgVerb::Off { profile } => {
|
||||
let r = ctl.call(Request::AwgSet { name: profile.clone(), on: false }).await?;
|
||||
println!("{profile}: {}", r["state"].as_str().unwrap_or("?"));
|
||||
}
|
||||
AwgVerb::Log { profile, lines } => {
|
||||
let r = ctl.call(Request::AwgLog { name: profile, lines }).await?;
|
||||
for l in r["lines"].as_array().into_iter().flatten().filter_map(Value::as_str) {
|
||||
println!("{l}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A login for the DION and Bitrix creators, which log in on their own from it.
|
||||
fn password_login(platform: &str, name: &str) -> Result<String> {
|
||||
let fields: &[&str] = match platform {
|
||||
@@ -834,6 +900,7 @@ async fn real_main() -> Result<()> {
|
||||
Cmd::Zapret { verb } => zapret(&ctl, verb).await?,
|
||||
Cmd::Components { verb } => components(&ctl, verb).await?,
|
||||
Cmd::Wl { verb } => wl(&ctl, verb).await?,
|
||||
Cmd::Awg { verb } => awg(&ctl, verb).await?,
|
||||
Cmd::Tg { verb: TgVerb::Link } => {
|
||||
let r = ctl.call(Request::TgLinks).await?;
|
||||
for l in r["links"].as_array().into_iter().flatten().filter_map(Value::as_str) {
|
||||
|
||||
Reference in new issue
Block a user