Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vpn: Add WireGuard configuration file support #678

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions cosmic-settings/src/pages/networking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod vpn;
pub mod wifi;
pub mod wired;

use std::{ffi::OsStr, io, process::ExitStatus, sync::Arc};
use std::{ffi::OsStr, process::Stdio, sync::Arc};

use anyhow::Context;
use cosmic::{widget, Apply, Command, Element};
Expand Down Expand Up @@ -354,29 +354,33 @@ impl Page {
}
}

async fn nm_add_vpn_file<P: AsRef<OsStr>>(type_: &str, path: P) -> io::Result<ExitStatus> {
async fn nm_add_vpn_file<P: AsRef<OsStr>>(type_: &str, path: P) -> Result<(), String> {
tokio::process::Command::new("nmcli")
.args(["connection", "import", "type", type_, "file"])
.arg(path)
.status()
.stderr(Stdio::piped())
.output()
.await
.apply(crate::utils::map_stderr_output)
}

async fn nm_add_wired() -> io::Result<ExitStatus> {
async fn nm_add_wired() -> Result<(), String> {
nm_connection_editor(&["--type=802-3-ethernet", "-c"]).await
}

async fn nm_add_wifi() -> io::Result<ExitStatus> {
async fn nm_add_wifi() -> Result<(), String> {
nm_connection_editor(&["--type=802-11-wireless", "-c"]).await
}

async fn nm_edit_connection(uuid: &str) -> io::Result<ExitStatus> {
async fn nm_edit_connection(uuid: &str) -> Result<(), String> {
nm_connection_editor(&[&["--edit=", uuid].concat()]).await
}

async fn nm_connection_editor(args: &[&str]) -> io::Result<ExitStatus> {
async fn nm_connection_editor(args: &[&str]) -> Result<(), String> {
tokio::process::Command::new(NM_CONNECTION_EDITOR)
.args(args)
.status()
.stderr(Stdio::piped())
.output()
.await
.apply(crate::utils::map_stderr_output)
}
Loading
Loading