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
@@ -5,7 +5,7 @@ use std::borrow::Cow;
|
||||
|
||||
use gpui_kit::*;
|
||||
|
||||
gpui_kit::assets::icon_assets!(Extra, [Shield, Send, Package, Pin, PinOff, RefreshCw, Save, Trash, Plus, Copy, Download, Link, Gauge, Power, Video, FileUp, Route]);
|
||||
gpui_kit::assets::icon_assets!(Extra, [Shield, Send, Package, Pin, PinOff, RefreshCw, Save, Trash, Plus, Copy, Download, Link, Gauge, Power, Video, FileUp, Route, Lock]);
|
||||
|
||||
pub struct AppAssets;
|
||||
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
//! AmneziaWG: its profiles, system-wide VPNs (started and stopped here, their tunnel's log) or
|
||||
//! outbounds of the proxy; one added from an AmneziaVPN vpn:// link or a .conf, or removed.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use gpui_kit::assets::IconName;
|
||||
use gpui_kit::component::button::{Button, ButtonVariants as _};
|
||||
use gpui_kit::component::input::{Input, InputState, Textarea, TextareaState};
|
||||
use gpui_kit::component::notification::Notification;
|
||||
use gpui_kit::component::radio::RadioGroup;
|
||||
use gpui_kit::component::switch::Switch;
|
||||
use gpui_kit::component::tag::Tag;
|
||||
use gpui_kit::component::*;
|
||||
use gpui_kit::*;
|
||||
use ps_client::edits;
|
||||
use ps_ipc::Request;
|
||||
use serde_json::Value;
|
||||
|
||||
use super::widgets::{card, hint, page, state_tag};
|
||||
use crate::model::Model;
|
||||
|
||||
const KINDS: [(&str, &str); 3] = [("vpn", "System-wide VPN"), ("userspace", "Outbound (AmneziaWG)"), ("singBox", "Outbound (plain WireGuard)")];
|
||||
|
||||
pub struct AmneziaWgPage {
|
||||
model: Entity<Model>,
|
||||
name: Entity<InputState>,
|
||||
text: Entity<TextareaState>,
|
||||
kind: usize,
|
||||
list: Result<Value, String>,
|
||||
loaded_at: Option<Instant>,
|
||||
/// A profile's tunnel log, while shown.
|
||||
logs: BTreeMap<String, Result<Vec<String>, String>>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
impl AmneziaWgPage {
|
||||
pub fn new(model: Entity<Model>, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
let name = cx.new(|cx| InputState::new(window, cx).placeholder("home"));
|
||||
let text = cx.new(|cx| TextareaState::new(window, cx).rows(5).placeholder("vpn://… from AmneziaVPN, or a .conf: [Interface] …"));
|
||||
let subscriptions = vec![cx.observe(&model, |this, _, cx| {
|
||||
if this.loaded_at.is_none_or(|t| t.elapsed() > Duration::from_secs(3)) {
|
||||
this.load(cx);
|
||||
}
|
||||
})];
|
||||
let mut this = Self { model, name, text, kind: 0, list: Ok(Value::Null), loaded_at: None, logs: BTreeMap::new(), _subscriptions: subscriptions };
|
||||
this.load(cx);
|
||||
this
|
||||
}
|
||||
|
||||
fn load(&mut self, cx: &mut Context<Self>) {
|
||||
self.loaded_at = Some(Instant::now());
|
||||
let job = self.model.read(cx).bridge().call(Request::AwgList);
|
||||
cx.spawn(async move |this, cx| {
|
||||
let r = job.await;
|
||||
this.update(cx, |this, cx| {
|
||||
this.list = r.map_err(|e| format!("{e:#}"));
|
||||
cx.notify();
|
||||
})
|
||||
.ok();
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn set(&mut self, name: String, on: bool, cx: &mut Context<Self>) {
|
||||
let what = format!("{name}: {}", if on { "tunnel up" } else { "tunnel down" });
|
||||
let job = self.model.read(cx).bridge().call(Request::AwgSet { name, on });
|
||||
let model = self.model.clone();
|
||||
cx.spawn(async move |this, cx| {
|
||||
let r = job.await;
|
||||
model.update(cx, |m, cx| m.track(what, async move { r.map(drop) }, cx));
|
||||
this.update(cx, |this, cx| this.load(cx)).ok();
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn toggle_log(&mut self, name: String, cx: &mut Context<Self>) {
|
||||
if self.logs.remove(&name).is_some() {
|
||||
cx.notify();
|
||||
return;
|
||||
}
|
||||
let job = self.model.read(cx).bridge().call(Request::AwgLog { name: name.clone(), lines: 30 });
|
||||
cx.spawn(async move |this, cx| {
|
||||
let r = job.await.map(|v| v["lines"].as_array().into_iter().flatten().filter_map(Value::as_str).map(str::to_owned).collect()).map_err(|e| format!("{e:#}"));
|
||||
this.update(cx, |this, cx| {
|
||||
this.logs.insert(name, r);
|
||||
cx.notify();
|
||||
})
|
||||
.ok();
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn add(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let name = self.name.read(cx).value().trim().to_owned();
|
||||
let text = self.text.read(cx).value().to_string();
|
||||
let kind = KINDS[self.kind].0;
|
||||
// Checked here first, for a message at once.
|
||||
if let Err(e) = edits::add_awg_profile(&mut serde_json::json!({}), &name, &text, kind) {
|
||||
window.push_notification(Notification::error(format!("{e:#}")), cx);
|
||||
return;
|
||||
}
|
||||
self.name.update(cx, |s, cx| s.set_value("", window, cx));
|
||||
self.text.update(cx, |s, cx| s.set_value("", window, cx));
|
||||
let what = format!("AmneziaWG profile '{name}' added");
|
||||
self.model.update(cx, |m, cx| m.edit(what, move |c| edits::add_awg_profile(c, &name, &text, kind), cx));
|
||||
}
|
||||
|
||||
fn remove(&mut self, name: String, cx: &mut Context<Self>) {
|
||||
self.model.update(cx, |m, cx| m.edit(format!("AmneziaWG profile '{name}' removed"), move |c| edits::remove_awg_profile(c, &name), cx));
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for AmneziaWgPage {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let m = self.model.read(cx);
|
||||
let body = page("AmneziaWG", cx);
|
||||
if m.config().is_null() {
|
||||
return body.child(hint("Waiting for the service…", cx));
|
||||
}
|
||||
let on = m.config()["amneziaWg"]["enable"] == true;
|
||||
let model = self.model.clone();
|
||||
let enable = Switch::new("awg-enable").checked(on).on_change(move |on, _, cx| {
|
||||
let on = *on;
|
||||
model.update(cx, |m, cx| {
|
||||
m.edit(
|
||||
if on { "AmneziaWG is on" } else { "AmneziaWG is off" },
|
||||
move |c| {
|
||||
edits::set_path(c, &["amneziaWg", "enable"], on.into());
|
||||
Ok(())
|
||||
},
|
||||
cx,
|
||||
)
|
||||
})
|
||||
});
|
||||
let about = card("AmneziaWG", Some(enable.into_any_element()), cx).child(hint(
|
||||
"WireGuard with AmneziaVPN's obfuscation. A system-wide profile is a VPN of its own (a network adapter, its routes and DNS); with one peer that takes everything, it also blocks what would leave outside the tunnel. An outbound profile is one more exit for the proxy, with nothing else changed.",
|
||||
cx,
|
||||
));
|
||||
|
||||
let mut profiles = card("Profiles", Some(Button::new("awg-reload").small().icon(IconName::RefreshCw).on_click(cx.listener(|this, _, _, cx| this.load(cx))).into_any_element()), cx);
|
||||
match &self.list {
|
||||
Err(e) => profiles = profiles.child(div().text_sm().text_color(cx.theme().danger).child(e.clone())),
|
||||
Ok(l) => {
|
||||
let list = l["profiles"].as_array().cloned().unwrap_or_default();
|
||||
if list.is_empty() {
|
||||
profiles = profiles.child(hint("None yet: add one below.", cx));
|
||||
}
|
||||
for (i, p) in list.iter().enumerate() {
|
||||
let name = p["name"].as_str().unwrap_or("").to_owned();
|
||||
let vpn = p["kind"] == "vpn";
|
||||
let state = p["state"].as_str().unwrap_or("").to_owned();
|
||||
let kind = match p["kind"].as_str().unwrap_or("") {
|
||||
"vpn" => Tag::info().child("system VPN"),
|
||||
"userspace" => Tag::secondary().child("outbound"),
|
||||
_ => Tag::secondary().child("outbound (WireGuard)"),
|
||||
};
|
||||
let mut line = div()
|
||||
.h_flex()
|
||||
.gap_3()
|
||||
.items_center()
|
||||
.child(div().font_medium().child(name.clone()))
|
||||
.child(kind)
|
||||
.child(if state == "windows-only" { Tag::secondary().child("Windows only") } else { state_tag(&state) })
|
||||
.child(div().flex_1());
|
||||
if vpn {
|
||||
let (n1, n2) = (name.clone(), name.clone());
|
||||
let running = matches!(state.as_str(), "active" | "activating");
|
||||
line = line
|
||||
.child(Button::new(("awg-log", i)).small().ghost().label("Log").on_click(cx.listener(move |this, _, _, cx| this.toggle_log(n1.clone(), cx))))
|
||||
.child(
|
||||
Switch::new(("awg-on", i))
|
||||
.checked(running)
|
||||
.disabled(!on)
|
||||
.on_change(cx.listener(move |this, v: &bool, _, cx| this.set(n2.clone(), *v, cx))),
|
||||
);
|
||||
}
|
||||
let n3 = name.clone();
|
||||
line = line.child(Button::new(("awg-remove", i)).small().ghost().icon(IconName::Trash).on_click(cx.listener(move |this, _, _, cx| this.remove(n3.clone(), cx))));
|
||||
let mut row = div().v_flex().gap_2().py_2().border_t_1().border_color(cx.theme().border).child(line);
|
||||
match self.logs.get(&name) {
|
||||
Some(Ok(lines)) => {
|
||||
let text = if lines.is_empty() { "(no log yet)".to_owned() } else { lines.join("\n") };
|
||||
row = row.child(div().text_xs().font_family("monospace").text_color(cx.theme().muted_foreground).child(text));
|
||||
}
|
||||
Some(Err(e)) => row = row.child(hint(e.clone(), cx)),
|
||||
None => {}
|
||||
}
|
||||
profiles = profiles.child(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let kinds = RadioGroup::horizontal("awg-kind").children(KINDS.map(|(_, label)| label)).selected_index(Some(self.kind)).on_change(cx.listener(|this, ix: &usize, _, cx| {
|
||||
this.kind = *ix;
|
||||
cx.notify();
|
||||
}));
|
||||
let add = card("Add a profile", Some(Button::new("awg-add").small().primary().icon(IconName::Plus).label("Add").on_click(cx.listener(|this, _, window, cx| this.add(window, cx))).into_any_element()), cx)
|
||||
.child(div().v_flex().gap_1().child(div().text_sm().child("Name (also the adapter's)")).child(Input::new(&self.name)))
|
||||
.child(kinds)
|
||||
.child(Textarea::new(&self.text))
|
||||
.child(hint("The link or .conf stays in the service's configuration, which only you and administrators read. Starting at sign-in (autostart), the endpoint and the rest are in Settings, under amneziaWg.profiles.", cx));
|
||||
|
||||
body.child(about).child(profiles).child(add)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
//! The window: a sidebar of pages, the page shown, and what came of each change as a
|
||||
//! notification.
|
||||
|
||||
mod amneziawg;
|
||||
mod autoproxy;
|
||||
mod components;
|
||||
mod dpi;
|
||||
@@ -28,14 +29,25 @@ pub enum Page {
|
||||
Whitelist,
|
||||
Outbounds,
|
||||
AutoProxy,
|
||||
AmneziaWg,
|
||||
Logs,
|
||||
Settings,
|
||||
Components,
|
||||
}
|
||||
|
||||
impl Page {
|
||||
const ALL: [Page; 9] =
|
||||
[Page::Overview, Page::Dpi, Page::Telegram, Page::Whitelist, Page::Outbounds, Page::AutoProxy, Page::Logs, Page::Settings, Page::Components];
|
||||
const ALL: [Page; 10] = [
|
||||
Page::Overview,
|
||||
Page::Dpi,
|
||||
Page::Telegram,
|
||||
Page::Whitelist,
|
||||
Page::Outbounds,
|
||||
Page::AutoProxy,
|
||||
Page::AmneziaWg,
|
||||
Page::Logs,
|
||||
Page::Settings,
|
||||
Page::Components,
|
||||
];
|
||||
|
||||
fn title(self) -> &'static str {
|
||||
match self {
|
||||
@@ -45,6 +57,7 @@ impl Page {
|
||||
Page::Whitelist => "Whitelist bypass",
|
||||
Page::Outbounds => "Outbounds",
|
||||
Page::AutoProxy => "autoProxy",
|
||||
Page::AmneziaWg => "AmneziaWG",
|
||||
Page::Logs => "Logs",
|
||||
Page::Settings => "Settings",
|
||||
Page::Components => "Components",
|
||||
@@ -59,6 +72,7 @@ impl Page {
|
||||
Page::Whitelist => IconName::Video,
|
||||
Page::Outbounds => IconName::Globe,
|
||||
Page::AutoProxy => IconName::Route,
|
||||
Page::AmneziaWg => IconName::Lock,
|
||||
Page::Logs => IconName::SquareTerminal,
|
||||
Page::Settings => IconName::Settings,
|
||||
Page::Components => IconName::Package,
|
||||
@@ -75,6 +89,7 @@ pub struct AppView {
|
||||
/// Made when first shown.
|
||||
whitelist: Option<Entity<whitelist::WhitelistPage>>,
|
||||
autoproxy: Option<Entity<autoproxy::AutoProxyPage>>,
|
||||
amneziawg: Option<Entity<amneziawg::AmneziaWgPage>>,
|
||||
/// Made when first shown: following the logs starts then.
|
||||
logs: Option<Entity<logs::LogsPage>>,
|
||||
/// Made when first shown, as it loads the configuration into its editor then.
|
||||
@@ -98,7 +113,7 @@ impl AppView {
|
||||
let dpi = cx.new(|cx| dpi::DpiPage::new(model.clone(), window, cx));
|
||||
let telegram = cx.new(|cx| telegram::TelegramPage::new(model.clone(), window, cx));
|
||||
let outbounds = cx.new(|cx| outbounds::OutboundsPage::new(model.clone(), window, cx));
|
||||
Self { model, page: Page::Overview, dpi, telegram, outbounds, whitelist: None, autoproxy: None, logs: None, settings: None, components: None, _subscriptions: subscriptions }
|
||||
Self { model, page: Page::Overview, dpi, telegram, outbounds, whitelist: None, autoproxy: None, amneziawg: None, logs: None, settings: None, components: None, _subscriptions: subscriptions }
|
||||
}
|
||||
|
||||
fn sidebar(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
@@ -131,6 +146,10 @@ impl Render for AppView {
|
||||
self.whitelist.get_or_insert_with(|| cx.new(|cx| whitelist::WhitelistPage::new(model, window, cx))).clone().into_any_element()
|
||||
}
|
||||
Page::Outbounds => self.outbounds.clone().into_any_element(),
|
||||
Page::AmneziaWg => {
|
||||
let model = self.model.clone();
|
||||
self.amneziawg.get_or_insert_with(|| cx.new(|cx| amneziawg::AmneziaWgPage::new(model, window, cx))).clone().into_any_element()
|
||||
}
|
||||
Page::AutoProxy => {
|
||||
let model = self.model.clone();
|
||||
self.autoproxy.get_or_insert_with(|| cx.new(|cx| autoproxy::AutoProxyPage::new(model, window, cx))).clone().into_any_element()
|
||||
|
||||
Reference in new issue
Block a user