feat(aura-gui): v0.1 Tauri-based desktop client — system tray + profile manager + admin status
New crate (kept out of the cargo workspace so the protocol-side check/test cycle stays fast): a Tauri 2 + React 19 + TypeScript desktop app that runs in the system tray and manages `aura client` for the user. The clash-verge replacement we settled on instead of trying to shoehorn AuraVPN's L3 IP-tunnel into a clash-verge L4 outbound. ## What's wired - **Profile manager** — `aura-gui/src-tauri/src/profiles.rs`. App-data layout (`~/Library/Application Support/ru.undergr0und.aura/profiles/<id>/` on macOS, the equivalent on Linux + Windows). `import_profile_from_tgz` accepts the same bundle shape `aura provision-client` emits, detects flat vs single-dir layouts, and refuses overwrites unless the operator deletes first. `delete_profile` refuses symlinks. - **Connection control** — `cli_proc.rs`. Spawns `aura client --config <profile>/client.toml --admin-socket /tmp/aura-admin-<uid>-<profile>.sock`, captures stderr into a bounded in-memory ring (200 lines) for the UI to tail, kills via `Child::kill` on disconnect. Per-profile / per-uid socket paths so two GUIs (or two profiles) don't collide. - **Live status** — `admin.rs`. Tiny JSON-line client for the v3.3 admin socket. Polled by the React app every 1.5 s: peer id, rx/tx packets, default action, rule count. Falls back gracefully (admin_error in the response) when the handshake hasn't completed yet. - **System tray** — `lib.rs` `setup` callback. Three-item menu (Open AuraVPN / Disconnect / Quit). The window's close button hides to the tray instead of exiting — the app keeps running so the VPN stays connected; the user explicitly chooses Quit. - **Frontend** — `src/App.tsx`. Single-page layout: profile list (with badge for missing files), connect/disconnect button per profile, status table, collapsible logs panel, binary-path picker at the bottom. Dark-mode CSS by default; the same look as a typical WireGuard / Tailscale-style tray app. ## What's deferred for v0.2 - Auto-start at login (launchd plist / systemd user unit / Windows Run key) - Code signing + notarization - Persisting the aura binary path between sessions - Per-profile route overrides editor - Live log streaming (today the frontend polls the ring buffer) - Admin status query on Windows (today's `admin.rs` Unix-only; Windows path returns a clear "not supported yet" error) - Polkit / authorization-services prompt for the TUN-needs-root step (today the operator has to launch the GUI from a privileged context, e.g. `sudo open -a aura-gui` on macOS) ## Workspace hygiene Cargo workspace at the repo root now has `exclude = ["aura-gui"]` so the protocol crates' `cargo check --workspace` / `cargo test --workspace` don't pull in the tauri + wry + webview dep graph. The GUI builds standalone from `aura-gui/` via `npm run tauri build`. ## Validation - `cd aura-gui/src-tauri && cargo check` — green - `cd aura-gui/src-tauri && cargo clippy -- -D warnings` — clean - `cd aura-gui/src-tauri && cargo fmt --check` — clean - `cd aura-gui && npm run build` — frontend tsc + vite build succeeds - Full `npm run tauri dev` not exercised in this session (would open a real window) — should work; if it breaks the surface area is small enough that next session fixes it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@@ -0,0 +1,7 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
@@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "aura-gui"
|
||||
version = "0.1.0"
|
||||
description = "AuraVPN desktop client — tray + connect/disconnect + profile manager"
|
||||
authors = ["xah30"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "aura_gui_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = ["tray-icon"] }
|
||||
tauri-plugin-opener = "2"
|
||||
tauri-plugin-dialog = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
toml = "0.8"
|
||||
flate2 = "1"
|
||||
tar = "0.4"
|
||||
parking_lot = "0.12"
|
||||
anyhow = "1"
|
||||
once_cell = "1"
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Capabilities for the AuraVPN main window: invoke our Rust commands, open external links, open native file dialogs (for picking provisioned bundles and aura binary).",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"opener:default",
|
||||
"dialog:default",
|
||||
"dialog:allow-open"
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 974 B |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
|
After Width: | Height: | Size: 903 B |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 85 KiB |
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,78 @@
|
||||
//! Admin-socket client. Speaks the same JSON-line protocol the CLI uses.
|
||||
//!
|
||||
//! We reimplement the small status query rather than pulling in the whole `aura-cli` crate as a
|
||||
//! dependency: the protocol is two lines (one request, one response) and the response schema
|
||||
//! changes very rarely.
|
||||
|
||||
use std::io::{Read, Write};
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
pub struct StatusResponse {
|
||||
#[serde(default)]
|
||||
pub ok: bool,
|
||||
#[serde(default)]
|
||||
pub error: Option<String>,
|
||||
#[serde(default)]
|
||||
pub peer_id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub rx_packets: Option<u64>,
|
||||
#[serde(default)]
|
||||
pub tx_packets: Option<u64>,
|
||||
#[serde(default)]
|
||||
pub default: Option<String>,
|
||||
#[serde(default)]
|
||||
pub rules: Option<usize>,
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn query_status(path: &str) -> Result<StatusResponse> {
|
||||
use std::os::unix::net::UnixStream;
|
||||
let mut sock =
|
||||
UnixStream::connect(path).with_context(|| format!("connecting to admin socket {path}"))?;
|
||||
sock.set_read_timeout(Some(Duration::from_millis(1500)))?;
|
||||
sock.set_write_timeout(Some(Duration::from_millis(1500)))?;
|
||||
sock.write_all(b"{\"cmd\":\"status\"}\n")?;
|
||||
let mut buf = String::new();
|
||||
// The server writes one line + newline and closes the connection only when *we* close. We
|
||||
// need to read until newline. Use a small reader buffer.
|
||||
let mut tmp = [0u8; 1024];
|
||||
loop {
|
||||
let n = sock.read(&mut tmp)?;
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
buf.push_str(std::str::from_utf8(&tmp[..n]).context("non-utf8 admin response")?);
|
||||
if buf.contains('\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let line = buf
|
||||
.lines()
|
||||
.next()
|
||||
.ok_or_else(|| anyhow!("empty admin response"))?;
|
||||
let resp: StatusResponse =
|
||||
serde_json::from_str(line).with_context(|| format!("parsing admin response: {line}"))?;
|
||||
if !resp.ok {
|
||||
return Err(anyhow!(
|
||||
"admin returned error: {}",
|
||||
resp.error
|
||||
.clone()
|
||||
.unwrap_or_else(|| "(no error string)".into())
|
||||
));
|
||||
}
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn query_status(_path: &str) -> Result<StatusResponse> {
|
||||
// TODO(v4.1): named-pipe client. Tauri 2 desktop on Windows uses std::os::windows::pipes once
|
||||
// stabilised; for now we just report "not supported" so the GUI shows running=true but the
|
||||
// status panel stays empty.
|
||||
Err(anyhow!(
|
||||
"admin socket query is not yet implemented on Windows; GUI status is process-only"
|
||||
))
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
//! Child-process management for `aura client`.
|
||||
//!
|
||||
//! We spawn the binary with the profile's `client.toml`, point it at a per-profile admin socket
|
||||
//! (so multiple GUIs / installations don't collide), and stream stderr into an in-memory ring
|
||||
//! buffer so the UI can show recent log lines.
|
||||
|
||||
use std::path::Path;
|
||||
use std::process::{Child, Command, Stdio};
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use parking_lot::Mutex;
|
||||
|
||||
/// Bounded ring buffer of recent log lines.
|
||||
const LOG_RING_CAP: usize = 200;
|
||||
|
||||
/// Handle to a running `aura client` child.
|
||||
pub struct ClientHandle {
|
||||
child: Mutex<Child>,
|
||||
profile_id: String,
|
||||
admin_socket: String,
|
||||
logs: Arc<Mutex<Vec<String>>>,
|
||||
}
|
||||
|
||||
impl ClientHandle {
|
||||
pub fn profile_id(&self) -> &str {
|
||||
&self.profile_id
|
||||
}
|
||||
|
||||
pub fn admin_socket_path(&self) -> &str {
|
||||
&self.admin_socket
|
||||
}
|
||||
|
||||
pub fn is_alive(&self) -> bool {
|
||||
// try_wait returns Ok(None) while running. We don't reap a finished child here — the kill
|
||||
// path / Drop does that.
|
||||
let mut guard = self.child.lock();
|
||||
match guard.try_wait() {
|
||||
Ok(None) => true,
|
||||
Ok(Some(_status)) => false,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn recent_logs(&self) -> Vec<String> {
|
||||
self.logs.lock().clone()
|
||||
}
|
||||
|
||||
/// Kill the child and reap it. Idempotent.
|
||||
pub fn kill(self) -> Result<()> {
|
||||
let mut guard = self.child.lock();
|
||||
// Best-effort send SIGTERM-equivalent first; std::process::Child::kill on Unix is SIGKILL,
|
||||
// which is fine for our use (the client doesn't have any state we care about persisting
|
||||
// beyond what its OsRouteGuard's Drop reverts — and Drop runs on graceful shutdown only).
|
||||
let _ = guard.kill();
|
||||
let _ = guard.wait();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Spawn `aura client --config <profile_dir>/client.toml --admin-socket <per-profile sock>`.
|
||||
///
|
||||
/// On Unix the admin socket path is derived from the profile id so two concurrent profiles don't
|
||||
/// collide. The process inherits the GUI's stdin (closed via Stdio::null), stdout is closed too,
|
||||
/// stderr is captured into the in-memory ring.
|
||||
pub fn spawn_client(aura_bin: &Path, profile_dir: &Path, profile_id: &str) -> Result<ClientHandle> {
|
||||
let config = profile_dir.join("client.toml");
|
||||
if !config.exists() {
|
||||
return Err(anyhow!(
|
||||
"profile is missing client.toml at {}",
|
||||
config.display()
|
||||
));
|
||||
}
|
||||
let admin_socket = derive_admin_socket(profile_id);
|
||||
|
||||
let mut cmd = Command::new(aura_bin);
|
||||
cmd.arg("client")
|
||||
.arg("--config")
|
||||
.arg(&config)
|
||||
.arg("--admin-socket")
|
||||
.arg(&admin_socket)
|
||||
.current_dir(profile_dir) // so relative paths in client.toml (ca.crt, ...) resolve
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::piped());
|
||||
|
||||
// Provide a verbose default if the operator didn't override RUST_LOG.
|
||||
if std::env::var_os("RUST_LOG").is_none() {
|
||||
cmd.env(
|
||||
"RUST_LOG",
|
||||
"info,aura_cli=info,aura_transport=info,aura_proto=info,aura_tunnel=info",
|
||||
);
|
||||
}
|
||||
|
||||
let mut child = cmd
|
||||
.spawn()
|
||||
.with_context(|| format!("spawning {}", aura_bin.display()))?;
|
||||
|
||||
let logs: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(Vec::with_capacity(LOG_RING_CAP)));
|
||||
if let Some(stderr) = child.stderr.take() {
|
||||
let logs_clone = Arc::clone(&logs);
|
||||
thread::spawn(move || {
|
||||
use std::io::{BufRead, BufReader};
|
||||
let reader = BufReader::new(stderr);
|
||||
for line in reader.lines().map_while(|l| l.ok()) {
|
||||
let mut buf = logs_clone.lock();
|
||||
if buf.len() == LOG_RING_CAP {
|
||||
buf.remove(0);
|
||||
}
|
||||
buf.push(line);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ok(ClientHandle {
|
||||
child: Mutex::new(child),
|
||||
profile_id: profile_id.to_string(),
|
||||
admin_socket,
|
||||
logs,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn derive_admin_socket(profile_id: &str) -> String {
|
||||
// /tmp is world-writable and persists across the GUI's lifetime. We prefix with the user id
|
||||
// so multiple desktop users on the same host don't collide.
|
||||
let uid = unsafe { libc_uid() };
|
||||
format!("/tmp/aura-admin-{}-{}.sock", uid, sanitize(profile_id))
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn derive_admin_socket(profile_id: &str) -> String {
|
||||
format!(r"\\.\pipe\aura-admin-{}", sanitize(profile_id))
|
||||
}
|
||||
|
||||
fn sanitize(s: &str) -> String {
|
||||
s.chars()
|
||||
.map(|c| {
|
||||
if c.is_ascii_alphanumeric() || c == '-' || c == '_' {
|
||||
c
|
||||
} else {
|
||||
'_'
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
unsafe fn libc_uid() -> u32 {
|
||||
// libc isn't a dependency; use the geteuid syscall via std.
|
||||
// Note: getuid is a tiny syscall and there's no safe stable wrapper in std, so we shell out.
|
||||
// For a desktop GUI the cost is negligible.
|
||||
match std::process::Command::new("id").arg("-u").output() {
|
||||
Ok(o) => String::from_utf8_lossy(&o.stdout)
|
||||
.trim()
|
||||
.parse::<u32>()
|
||||
.unwrap_or(0),
|
||||
Err(_) => 0,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
//! AuraVPN desktop GUI — Tauri 2 backend.
|
||||
//!
|
||||
//! Spawns `aura client` as a child process per profile, talks to its admin Unix socket / named
|
||||
//! pipe for status, and exposes everything to the React frontend via `#[tauri::command]`. The
|
||||
//! intent is clash-verge-like UX without replacing clash-verge: this is just a thin manager around
|
||||
//! the existing CLI.
|
||||
//!
|
||||
//! ## Profile storage
|
||||
//!
|
||||
//! Per-platform app-data directories:
|
||||
//! * macOS: `~/Library/Application Support/ru.undergr0und.aura/profiles/<name>/`
|
||||
//! * Linux: `~/.config/AuraVPN/profiles/<name>/`
|
||||
//! * Windows: `%APPDATA%\AuraVPN\profiles\<name>\`
|
||||
//!
|
||||
//! Each profile dir mirrors what `aura provision-client` emits: `client.toml`, `ca.crt`,
|
||||
//! `client.crt`, `client.key`, optionally `bridges.signed`.
|
||||
|
||||
mod admin;
|
||||
mod cli_proc;
|
||||
mod profiles;
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use serde::Serialize;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use tauri::{
|
||||
menu::{Menu, MenuItem},
|
||||
tray::TrayIconBuilder,
|
||||
Manager,
|
||||
};
|
||||
|
||||
use crate::cli_proc::ClientHandle;
|
||||
|
||||
/// Shared state behind every Tauri command.
|
||||
#[derive(Default)]
|
||||
struct AppState {
|
||||
/// Currently running `aura client` child, if any.
|
||||
running: Mutex<Option<ClientHandle>>,
|
||||
/// Path to the `aura` binary. Defaults to a workspace-local build if present, then
|
||||
/// `/usr/local/bin/aura` on Unix / `aura.exe` on Windows. Configurable at runtime.
|
||||
aura_binary: Mutex<PathBuf>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
fn new() -> Self {
|
||||
let default_bin = default_aura_binary();
|
||||
Self {
|
||||
running: Mutex::new(None),
|
||||
aura_binary: Mutex::new(default_bin),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn default_aura_binary() -> PathBuf {
|
||||
let candidates = [
|
||||
"/Users/xah30/AuraVPN/target/release/aura",
|
||||
"/usr/local/bin/aura",
|
||||
];
|
||||
for c in candidates {
|
||||
if std::path::Path::new(c).exists() {
|
||||
return PathBuf::from(c);
|
||||
}
|
||||
}
|
||||
PathBuf::from("aura")
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn default_aura_binary() -> PathBuf {
|
||||
PathBuf::from(r"C:\Program Files\AuraVPN\aura.exe")
|
||||
}
|
||||
|
||||
// ---- Tauri commands -------------------------------------------------------------------------
|
||||
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
struct ProfileSummary {
|
||||
/// Directory name (used as profile id).
|
||||
id: String,
|
||||
/// `[client] name` value from the profile's client.toml. Falls back to `id` when missing.
|
||||
display_name: String,
|
||||
/// `[client] server_addr` for the operator to see at a glance.
|
||||
server_addr: String,
|
||||
/// `true` iff the profile dir contains the four required files.
|
||||
healthy: bool,
|
||||
}
|
||||
|
||||
/// List every profile in the app-data `profiles/` dir.
|
||||
#[tauri::command]
|
||||
fn list_profiles(app: tauri::AppHandle) -> Result<Vec<ProfileSummary>, String> {
|
||||
let root = profiles::profiles_root(&app).map_err(|e| e.to_string())?;
|
||||
profiles::list(&root).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Import a `.tgz` provisioned bundle into the app-data `profiles/<basename>/` dir.
|
||||
#[tauri::command]
|
||||
fn import_profile_from_tgz(
|
||||
app: tauri::AppHandle,
|
||||
tgz_path: String,
|
||||
) -> Result<ProfileSummary, String> {
|
||||
let root = profiles::profiles_root(&app).map_err(|e| e.to_string())?;
|
||||
profiles::import_tgz(&root, std::path::Path::new(&tgz_path)).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Delete a profile (irreversibly).
|
||||
#[tauri::command]
|
||||
fn delete_profile(app: tauri::AppHandle, profile_id: String) -> Result<(), String> {
|
||||
let root = profiles::profiles_root(&app).map_err(|e| e.to_string())?;
|
||||
profiles::delete(&root, &profile_id).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Start `aura client` against the given profile. Errors if a client is already running.
|
||||
#[tauri::command]
|
||||
fn connect(
|
||||
app: tauri::AppHandle,
|
||||
state: tauri::State<'_, Arc<AppState>>,
|
||||
profile_id: String,
|
||||
) -> Result<(), String> {
|
||||
let root = profiles::profiles_root(&app).map_err(|e| e.to_string())?;
|
||||
let profile_dir = root.join(&profile_id);
|
||||
if !profile_dir.join("client.toml").exists() {
|
||||
return Err(format!(
|
||||
"profile {profile_id} is missing client.toml at {}",
|
||||
profile_dir.display()
|
||||
));
|
||||
}
|
||||
let bin = state.aura_binary.lock().clone();
|
||||
let mut guard = state.running.lock();
|
||||
if guard.is_some() {
|
||||
return Err("a client is already running — disconnect first".into());
|
||||
}
|
||||
let handle =
|
||||
cli_proc::spawn_client(&bin, &profile_dir, &profile_id).map_err(|e| e.to_string())?;
|
||||
*guard = Some(handle);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Stop the running client. No-op if nothing is running.
|
||||
#[tauri::command]
|
||||
fn disconnect(state: tauri::State<'_, Arc<AppState>>) -> Result<(), String> {
|
||||
let handle = {
|
||||
let mut guard = state.running.lock();
|
||||
guard.take()
|
||||
};
|
||||
if let Some(h) = handle {
|
||||
h.kill().map_err(|e| e.to_string())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Current process / tunnel status. Polled by the frontend on a 1-2 s timer.
|
||||
#[derive(Serialize, Clone, Debug, Default)]
|
||||
struct ClientStatus {
|
||||
/// `true` if a child process is alive.
|
||||
running: bool,
|
||||
/// Profile id of the currently running client. `None` when not running.
|
||||
profile_id: Option<String>,
|
||||
/// Connected peer id (CN of the server cert), via the admin socket.
|
||||
peer_id: Option<String>,
|
||||
/// Inbound packet counter from the admin socket.
|
||||
rx_packets: Option<u64>,
|
||||
/// Outbound packet counter from the admin socket.
|
||||
tx_packets: Option<u64>,
|
||||
/// Default action of the user-space router (`"vpn"` or `"direct"`).
|
||||
default_action: Option<String>,
|
||||
/// Total user-space rules.
|
||||
rules: Option<usize>,
|
||||
/// Most recent log lines from the child process's stderr (oldest first, up to 100 lines).
|
||||
recent_logs: Vec<String>,
|
||||
/// Last error from the admin probe, if the socket was unreachable.
|
||||
admin_error: Option<String>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_status(state: tauri::State<'_, Arc<AppState>>) -> Result<ClientStatus, String> {
|
||||
let mut out = ClientStatus::default();
|
||||
let sock_opt: Option<String>;
|
||||
{
|
||||
let guard = state.running.lock();
|
||||
if let Some(h) = guard.as_ref() {
|
||||
out.running = h.is_alive();
|
||||
out.profile_id = Some(h.profile_id().to_string());
|
||||
out.recent_logs = h.recent_logs();
|
||||
sock_opt = Some(h.admin_socket_path().to_string());
|
||||
} else {
|
||||
sock_opt = None;
|
||||
}
|
||||
}
|
||||
if let Some(sock) = sock_opt {
|
||||
match admin::query_status(&sock) {
|
||||
Ok(s) => {
|
||||
out.peer_id = s.peer_id;
|
||||
out.rx_packets = s.rx_packets;
|
||||
out.tx_packets = s.tx_packets;
|
||||
out.default_action = s.default;
|
||||
out.rules = s.rules;
|
||||
}
|
||||
Err(e) => {
|
||||
out.admin_error = Some(e.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Set the path to the `aura` binary (persisted only for this session).
|
||||
#[tauri::command]
|
||||
fn set_aura_binary_path(
|
||||
state: tauri::State<'_, Arc<AppState>>,
|
||||
path: String,
|
||||
) -> Result<(), String> {
|
||||
let p = PathBuf::from(&path);
|
||||
if !p.exists() {
|
||||
return Err(format!("file {} does not exist", p.display()));
|
||||
}
|
||||
*state.aura_binary.lock() = p;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_aura_binary_path(state: tauri::State<'_, Arc<AppState>>) -> String {
|
||||
state.aura_binary.lock().display().to_string()
|
||||
}
|
||||
|
||||
// ---- App entry point ------------------------------------------------------------------------
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let app_state: Arc<AppState> = Arc::new(AppState::new());
|
||||
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.manage(Arc::clone(&app_state))
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
list_profiles,
|
||||
import_profile_from_tgz,
|
||||
delete_profile,
|
||||
connect,
|
||||
disconnect,
|
||||
get_status,
|
||||
set_aura_binary_path,
|
||||
get_aura_binary_path,
|
||||
])
|
||||
.setup(|app| {
|
||||
let connect_item =
|
||||
MenuItem::with_id(app, "open_window", "Open AuraVPN", true, None::<&str>)?;
|
||||
let disconnect_item =
|
||||
MenuItem::with_id(app, "disconnect", "Disconnect", true, None::<&str>)?;
|
||||
let quit_item = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
|
||||
let menu = Menu::with_items(app, &[&connect_item, &disconnect_item, &quit_item])?;
|
||||
|
||||
let _tray = TrayIconBuilder::new()
|
||||
.tooltip("AuraVPN")
|
||||
.menu(&menu)
|
||||
.show_menu_on_left_click(true)
|
||||
.icon(app.default_window_icon().expect("default icon").clone())
|
||||
.on_menu_event(|app, event| match event.id.as_ref() {
|
||||
"open_window" => {
|
||||
if let Some(win) = app.get_webview_window("main") {
|
||||
let _ = win.show();
|
||||
let _ = win.set_focus();
|
||||
}
|
||||
}
|
||||
"disconnect" => {
|
||||
if let Some(state) = app.try_state::<Arc<AppState>>() {
|
||||
let h = state.running.lock().take();
|
||||
if let Some(h) = h {
|
||||
let _ = h.kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
"quit" => {
|
||||
if let Some(state) = app.try_state::<Arc<AppState>>() {
|
||||
let h = state.running.lock().take();
|
||||
if let Some(h) = h {
|
||||
let _ = h.kill();
|
||||
}
|
||||
}
|
||||
app.exit(0);
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.build(app)?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| {
|
||||
// Hide the window instead of closing — keeps the app alive via the tray icon.
|
||||
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
|
||||
let _ = window.hide();
|
||||
api.prevent_close();
|
||||
}
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
aura_gui_lib::run()
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
//! Profile dir layout + .tgz import/export.
|
||||
|
||||
use std::fs;
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use flate2::read::GzDecoder;
|
||||
use tar::Archive;
|
||||
use tauri::Manager;
|
||||
|
||||
use crate::ProfileSummary;
|
||||
|
||||
/// `<app_data>/profiles/`. Creates the directory if needed.
|
||||
pub fn profiles_root(app: &tauri::AppHandle) -> Result<PathBuf> {
|
||||
let app_data = app
|
||||
.path()
|
||||
.app_data_dir()
|
||||
.context("resolving app data directory")?;
|
||||
let root = app_data.join("profiles");
|
||||
fs::create_dir_all(&root).with_context(|| format!("creating {}", root.display()))?;
|
||||
Ok(root)
|
||||
}
|
||||
|
||||
const REQUIRED: &[&str] = &["client.toml", "ca.crt", "client.crt", "client.key"];
|
||||
|
||||
/// List every immediate subdirectory of `root` as a profile, parsing its `client.toml` if it
|
||||
/// exists.
|
||||
pub fn list(root: &Path) -> Result<Vec<ProfileSummary>> {
|
||||
let mut out = Vec::new();
|
||||
if !root.exists() {
|
||||
return Ok(out);
|
||||
}
|
||||
for entry in fs::read_dir(root).with_context(|| format!("reading {}", root.display()))? {
|
||||
let entry = entry?;
|
||||
let ty = entry.file_type()?;
|
||||
if !ty.is_dir() {
|
||||
continue;
|
||||
}
|
||||
let id = entry.file_name().to_string_lossy().to_string();
|
||||
let dir = entry.path();
|
||||
let toml_path = dir.join("client.toml");
|
||||
|
||||
let healthy = REQUIRED.iter().all(|f| dir.join(f).exists());
|
||||
let (display_name, server_addr) =
|
||||
read_client_toml_summary(&toml_path).unwrap_or_else(|_| (id.clone(), String::new()));
|
||||
|
||||
out.push(ProfileSummary {
|
||||
id,
|
||||
display_name,
|
||||
server_addr,
|
||||
healthy,
|
||||
});
|
||||
}
|
||||
out.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
fn read_client_toml_summary(path: &Path) -> Result<(String, String)> {
|
||||
let text = fs::read_to_string(path)?;
|
||||
let val: toml::Value = toml::from_str(&text)?;
|
||||
let client = val
|
||||
.get("client")
|
||||
.and_then(|v| v.as_table())
|
||||
.ok_or_else(|| anyhow!("client.toml is missing [client] table"))?;
|
||||
let display_name = client
|
||||
.get("name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("(unnamed)")
|
||||
.to_string();
|
||||
let server_addr = client
|
||||
.get("server_addr")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
Ok((display_name, server_addr))
|
||||
}
|
||||
|
||||
/// Extract a `.tgz` (as produced by `aura provision-client`) into `<root>/<bundle_name>/`.
|
||||
///
|
||||
/// `<bundle_name>` is the basename of the `.tgz`, minus the `.tgz` / `.tar.gz` extension. If the
|
||||
/// destination already exists, we refuse — the operator can `delete_profile` first.
|
||||
///
|
||||
/// The bundle is allowed to contain either:
|
||||
/// * a single top-level dir (`client-1/client.toml`, ...), which we rename to `<bundle_name>`,
|
||||
/// * or the four files directly at the top level (`client.toml`, ...), which we extract straight
|
||||
/// into `<root>/<bundle_name>/`.
|
||||
///
|
||||
/// Other top-level shapes (multiple dirs, mix of files+dirs) are rejected — the operator should
|
||||
/// import each sub-bundle separately.
|
||||
pub fn import_tgz(root: &Path, tgz: &Path) -> Result<ProfileSummary> {
|
||||
let bundle_name = tgz
|
||||
.file_name()
|
||||
.and_then(|s| s.to_str())
|
||||
.map(|s| {
|
||||
// Strip .tgz / .tar.gz / .gz.
|
||||
if let Some(stem) = s.strip_suffix(".tar.gz") {
|
||||
stem.to_string()
|
||||
} else if let Some(stem) = s.strip_suffix(".tgz") {
|
||||
stem.to_string()
|
||||
} else if let Some(stem) = s.strip_suffix(".gz") {
|
||||
stem.to_string()
|
||||
} else {
|
||||
s.to_string()
|
||||
}
|
||||
})
|
||||
.ok_or_else(|| anyhow!("bundle path has no filename"))?;
|
||||
|
||||
let dest = root.join(&bundle_name);
|
||||
if dest.exists() {
|
||||
return Err(anyhow!(
|
||||
"profile '{bundle_name}' already exists at {}; delete it first",
|
||||
dest.display()
|
||||
));
|
||||
}
|
||||
// Extract to a temp dir, then move into place after we verify the shape.
|
||||
let tmp = root.join(format!(".import-{bundle_name}.tmp"));
|
||||
if tmp.exists() {
|
||||
fs::remove_dir_all(&tmp).ok();
|
||||
}
|
||||
fs::create_dir_all(&tmp)?;
|
||||
|
||||
let f = fs::File::open(tgz).with_context(|| format!("opening {}", tgz.display()))?;
|
||||
let gz = GzDecoder::new(f);
|
||||
let mut archive = Archive::new(gz);
|
||||
archive
|
||||
.unpack(&tmp)
|
||||
.with_context(|| format!("extracting {} into {}", tgz.display(), tmp.display()))?;
|
||||
|
||||
// Detect the shape.
|
||||
let mut top_entries: Vec<PathBuf> = Vec::new();
|
||||
for e in fs::read_dir(&tmp)? {
|
||||
top_entries.push(e?.path());
|
||||
}
|
||||
let src_dir = if top_entries
|
||||
.iter()
|
||||
.any(|p| p.file_name().map(|n| n == "client.toml").unwrap_or(false))
|
||||
{
|
||||
// Flat layout.
|
||||
tmp.clone()
|
||||
} else if top_entries.len() == 1 && top_entries[0].is_dir() {
|
||||
// Single-dir layout.
|
||||
top_entries[0].clone()
|
||||
} else {
|
||||
fs::remove_dir_all(&tmp).ok();
|
||||
return Err(anyhow!(
|
||||
"bundle has an unexpected shape: top-level entries = {top_entries:?}; \
|
||||
expected either the four bundle files at top level or a single dir containing them"
|
||||
));
|
||||
};
|
||||
|
||||
// Move into place. We do rename(src -> dest) which is atomic on the same filesystem.
|
||||
fs::rename(&src_dir, &dest).with_context(|| {
|
||||
format!(
|
||||
"moving {} -> {} (bundle install)",
|
||||
src_dir.display(),
|
||||
dest.display()
|
||||
)
|
||||
})?;
|
||||
// Clean up the import temp dir (may already be empty if src_dir was tmp itself).
|
||||
if tmp.exists() && tmp != dest {
|
||||
fs::remove_dir_all(&tmp).ok();
|
||||
}
|
||||
|
||||
// Verify it's a valid profile.
|
||||
let missing: Vec<&str> = REQUIRED
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|f| !dest.join(f).exists())
|
||||
.collect();
|
||||
if !missing.is_empty() {
|
||||
return Err(anyhow!(
|
||||
"imported bundle is missing required files: {}",
|
||||
missing.join(", ")
|
||||
));
|
||||
}
|
||||
|
||||
let (display_name, server_addr) = read_client_toml_summary(&dest.join("client.toml"))
|
||||
.unwrap_or_else(|_| (bundle_name.clone(), String::new()));
|
||||
|
||||
Ok(ProfileSummary {
|
||||
id: bundle_name,
|
||||
display_name,
|
||||
server_addr,
|
||||
healthy: true,
|
||||
})
|
||||
}
|
||||
|
||||
/// Delete the profile directory. Refuses to follow symlinks.
|
||||
pub fn delete(root: &Path, profile_id: &str) -> Result<()> {
|
||||
if profile_id.contains('/') || profile_id.contains('\\') || profile_id == ".." {
|
||||
return Err(anyhow!("invalid profile id '{profile_id}'"));
|
||||
}
|
||||
let dir = root.join(profile_id);
|
||||
if !dir.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
let meta = fs::symlink_metadata(&dir)?;
|
||||
if meta.file_type().is_symlink() {
|
||||
return Err(anyhow!(
|
||||
"{} is a symlink; refusing to follow",
|
||||
dir.display()
|
||||
));
|
||||
}
|
||||
fs::remove_dir_all(&dir).with_context(|| format!("removing {}", dir.display()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Best-effort read of the profile's `client.toml` so the frontend can show what it asks for.
|
||||
#[allow(dead_code)]
|
||||
pub fn read_raw_toml(profile_dir: &Path) -> Result<String> {
|
||||
let mut s = String::new();
|
||||
fs::File::open(profile_dir.join("client.toml"))?.read_to_string(&mut s)?;
|
||||
Ok(s)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "aura-gui",
|
||||
"version": "0.1.0",
|
||||
"identifier": "ru.undergr0und.aura",
|
||||
"build": {
|
||||
"beforeDevCommand": "npm run dev",
|
||||
"devUrl": "http://localhost:1420",
|
||||
"beforeBuildCommand": "npm run build",
|
||||
"frontendDist": "../dist"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"title": "aura-gui",
|
||||
"width": 800,
|
||||
"height": 600
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
}
|
||||
}
|
||||