From 0c55e877abe85f31652e513c2eecf14d2402f297 Mon Sep 17 00:00:00 2001 From: Robert Olejnik Date: Tue, 20 Aug 2024 12:50:47 +0200 Subject: [PATCH 1/3] Update README.md --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1bd1e628..449ac3d9 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,15 @@ Built packages are available after in `src-tauri/target/release/bundle`. Remove `default-run` line from `[package]` section in `Cargo.toml` to build the project. +# Built and sponsored by + +

+ build by teonite +

+ +# Legal +WireGuard® is [registered trademarks](https://www.wireguard.com/trademark-policy/) of Jason A. Donenfeld. + # Known issues ## Failed to bundle project @@ -71,7 +80,3 @@ The app launches but the window is blank. Set the `WEBKIT_DISABLE_DMABUF_RENDERE ``` WEBKIT_DISABLE_DMABUF_RENDERER=1 defguard-client ``` - -# Legal - - - *defguard is not an official WireGuard project, and WireGuard is a registered trademark of Jason A. Donenfeld.* From 6a453cf7c6fe986850a50e8108bc18d164b55e16 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Fri, 11 Oct 2024 11:52:31 +0200 Subject: [PATCH 2/3] move pre/post command functionality to client (#331) * move command functionality to client * fix builds * fix linter * update workflow --- .github/workflows/lint.yaml | 2 +- .github/workflows/release.yaml | 85 ++++++++++++++++++---------------- .github/workflows/test.yml | 18 +++---- src-tauri/Cargo.lock | 16 +++++-- src-tauri/src/commands.rs | 18 +++++-- src-tauri/src/service/mod.rs | 24 +--------- src-tauri/src/utils.rs | 37 ++++++++++++--- 7 files changed, 112 insertions(+), 88 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index bf9cdebc..9fe337fd 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -13,7 +13,7 @@ on: jobs: lint-web: - runs-on: self-hosted + runs-on: [self-hosted, Linux, X64] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2b33a885..60ccb6db 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,4 +1,4 @@ -name: "Build app & create release" +name: 'Build app and create release' on: push: tags: @@ -18,9 +18,9 @@ jobs: ref: master fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: - go-version: '1.20' + go-version: '1.22' - name: Build wireguard-go binary run: make env: @@ -56,10 +56,22 @@ jobs: runs-on: - self-hosted - Linux + - ${{ matrix.architecture }} + strategy: + fail-fast: false + matrix: + architecture: [ARM64, X64] + include: + - architecture: ARM64 + deb_arch: arm64 + binary_arch: aarch64 + - architecture: X64 + deb_arch: amd64 + binary_arch: x86_64 steps: - uses: actions/checkout@v4 with: - submodules: "recursive" + submodules: 'recursive' - name: Write release version run: | VERSION=$(echo ${GITHUB_REF_NAME#v} | cut -d '-' -f1) @@ -67,10 +79,10 @@ jobs: echo "VERSION=$VERSION" >> $GITHUB_ENV - uses: actions/setup-node@v3 with: - node-version: "20" + node-version: '20' - uses: pnpm/action-setup@v2 with: - version: 8 + version: 9 run_install: false - name: Get pnpm store directory shell: bash @@ -83,13 +95,13 @@ jobs: key: ${{ runner.os }}-pnpm-build-store-${{ hashFiles('**/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm-build-store- - - name: Install deps + - name: Install Node dependencies run: pnpm install --frozen-lockfile - uses: dtolnay/rust-toolchain@stable - - name: install linux deps + - name: Install Linux dependencies run: | sudo apt-get update - sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libssl-dev unzip + sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libssl-dev unzip protobuf-compiler libprotobuf-dev - name: Build packages uses: tauri-apps/tauri-action@v0 env: @@ -100,53 +112,44 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.create-release.outputs.upload_url }} - asset_path: src-tauri/target/release/bundle/deb/defguard-client_${{ env.VERSION }}_amd64.deb - asset_name: defguard-client_${{ env.VERSION }}_amd64.deb - asset_content_type: application/octet-stream - - name: Upload AppImage - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.create-release.outputs.upload_url }} - asset_path: src-tauri/target/release/bundle/appimage/defguard-client_${{ env.VERSION }}_amd64.AppImage - asset_name: defguard-client_${{ env.VERSION }}_amd64.AppImage + asset_path: src-tauri/target/release/bundle/deb/defguard-client_${{ env.VERSION }}_${{ matrix.deb_arch }}.deb + asset_name: defguard-client_${{ env.VERSION }}_${{ matrix.deb_arch }}.deb asset_content_type: application/octet-stream - name: Rename client binary - run: mv src-tauri/target/release/defguard-client defguard-client-linux-x86_64-${{ github.ref_name }} + run: mv src-tauri/target/release/defguard-client defguard-client-linux-${{ matrix.binary_arch }}-${{ github.ref_name }} - name: Tar client binary uses: a7ul/tar-action@v1.1.0 with: command: c files: | - defguard-client-linux-x86_64-${{ github.ref_name }} - outPath: defguard-client-linux-x86_64-${{ github.ref_name }}.tar.gz + defguard-client-linux-${{ matrix.binary_arch }}-${{ github.ref_name }} + outPath: defguard-client-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz - name: Upload client archive uses: actions/upload-release-asset@v1.0.2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.create-release.outputs.upload_url }} - asset_path: defguard-client-linux-x86_64-${{ github.ref_name }}.tar.gz - asset_name: defguard-client-linux-x86_64-${{ github.ref_name }}.tar.gz + asset_path: defguard-client-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz + asset_name: defguard-client-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz asset_content_type: application/octet-stream - name: Rename daemon binary - run: mv src-tauri/target/release/defguard-service defguard-service-linux-x86_64-${{ github.ref_name }} + run: mv src-tauri/target/release/defguard-service defguard-service-linux-${{ matrix.binary_arch }}-${{ github.ref_name }} - name: Tar daemon binary uses: a7ul/tar-action@v1.1.0 with: command: c files: | - defguard-service-linux-x86_64-${{ github.ref_name }} - outPath: defguard-service-linux-x86_64-${{ github.ref_name }}.tar.gz + defguard-service-linux-${{ matrix.binary_arch }}-${{ github.ref_name }} + outPath: defguard-service-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz - name: Upload daemon archive uses: actions/upload-release-asset@v1.0.2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.create-release.outputs.upload_url }} - asset_path: defguard-service-linux-x86_64-${{ github.ref_name }}.tar.gz - asset_name: defguard-service-linux-x86_64-${{ github.ref_name }}.tar.gz + asset_path: defguard-service-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz + asset_name: defguard-service-linux-${{ matrix.binary_arch }}-${{ github.ref_name }}.tar.gz asset_content_type: application/octet-stream build-macos: needs: @@ -162,7 +165,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - submodules: "recursive" + submodules: 'recursive' - name: Write release version run: | VERSION=$(echo ${GITHUB_REF_NAME#v} | cut -d '-' -f1) @@ -170,10 +173,10 @@ jobs: echo "VERSION=$VERSION" >> $GITHUB_ENV - uses: actions/setup-node@v3 with: - node-version: "20" + node-version: '20' - uses: pnpm/action-setup@v2 with: - version: 8 + version: 9 run_install: false - name: Get pnpm store directory shell: bash @@ -203,12 +206,12 @@ jobs: uses: tauri-apps/tauri-action@v0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - APPLE_SIGNING_IDENTITY: "Developer ID Application: TEONITE (6WD6W6WQNV)" + APPLE_SIGNING_IDENTITY: 'Developer ID Application: TEONITE (6WD6W6WQNV)' APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }} APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }} - APPLE_ID: "admin@teonite.com" + APPLE_ID: 'admin@teonite.com' APPLE_PASSWORD: ${{ secrets.NOTARYTOOL_APP_SPECIFIC_PASSWORD }} - APPLE_TEAM_ID: "6WD6W6WQNV" + APPLE_TEAM_ID: '6WD6W6WQNV' with: args: --target ${{ matrix.target }} -v - name: Build installation package @@ -240,7 +243,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - submodules: "recursive" + submodules: 'recursive' - name: Write release version run: | $env:VERSION=echo ($env:GITHUB_REF_NAME.Substring(1) -Split "-")[0] @@ -248,10 +251,10 @@ jobs: echo "VERSION=$env:VERSION" >> $env:GITHUB_ENV - uses: actions/setup-node@v3 with: - node-version: "20" + node-version: '20' - uses: pnpm/action-setup@v2 with: - version: 8 + version: 9 run_install: false - name: Get pnpm store directory shell: bash @@ -299,6 +302,7 @@ jobs: runs-on: - self-hosted - Linux + - X64 steps: - name: Write release version run: | @@ -323,7 +327,7 @@ jobs: - sign-burn-engine runs-on: windows-latest steps: - - name: Download unsigned bundle & signed burn-engine + - name: Download unsigned bundle and signed burn-engine uses: actions/download-artifact@v4 with: name: unsigned-bundle-and-signed-burnengine @@ -346,6 +350,7 @@ jobs: runs-on: - self-hosted - Linux + - X64 steps: - name: Write release version run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6191064b..990ad968 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,41 +6,41 @@ on: - main - dev paths-ignore: - - "*.md" - - "LICENSE" + - '*.md' + - 'LICENSE' pull_request: branches: - main - dev paths-ignore: - - "*.md" - - "LICENSE" + - '*.md' + - 'LICENSE' env: CARGO_TERM_COLOR: always jobs: test: - runs-on: [self-hosted, Linux] - container: rust:1.74 + runs-on: [self-hosted, Linux, X64] + container: rust:1 defaults: run: working-directory: ./src-tauri steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: recursive - name: Debug run: echo ${{ github.ref_name }} - name: Cache uses: Swatinem/rust-cache@v2 - - name: install linux deps + - name: Install required packages run: | apt-get update apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libssl-dev unzip - - name: install protobuf compiler + - name: Install protobuf compiler run: | PB_REL='https://github.com/protocolbuffers/protobuf/releases' PB_VERSION='3.20.0' && curl -LO $PB_REL/download/v$PB_VERSION/protoc-$PB_VERSION-linux-x86_64.zip diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 4c479140..6ee9594d 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3181,6 +3181,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.45" @@ -5496,13 +5502,14 @@ dependencies = [ [[package]] name = "time" -version = "0.3.31" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa 1.0.10", "libc", + "num-conv", "num_threads", "powerfmt", "serde", @@ -5518,10 +5525,11 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index d0fbe9d9..4218f1bf 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -10,8 +10,8 @@ use crate::{ service::{log_watcher::stop_log_watcher_task, proto::RemoveInterfaceRequest}, tray::configure_tray_icon, utils::{ - disconnect_interface, get_location_interface_details, get_tunnel_interface_details, - handle_connection_for_location, handle_connection_for_tunnel, + disconnect_interface, execute_command, get_location_interface_details, + get_tunnel_interface_details, handle_connection_for_location, handle_connection_for_tunnel, }, wg_config::parse_wireguard_config, CommonConnection, CommonConnectionInfo, CommonLocationStats, ConnectionType, @@ -752,10 +752,15 @@ pub async fn delete_tunnel(tunnel_id: i64, handle: AppHandle) -> Result<(), Erro app_state.find_and_remove_connection(tunnel_id, &ConnectionType::Tunnel) { debug!("Found active connection for tunnel({tunnel_id}), closing...",); + if let Some(pre_down) = &tunnel.pre_down { + debug!("Executing specified PreDown command: {pre_down}"); + let _ = execute_command(pre_down); + info!("Executed specified PreDown command: {pre_down}"); + } let request = RemoveInterfaceRequest { interface_name: connection.interface_name.clone(), - pre_down: tunnel.pre_down.clone(), - post_down: tunnel.post_up.clone(), + pre_down: None, + post_down: None, }; client .remove_interface(request) @@ -768,6 +773,11 @@ pub async fn delete_tunnel(tunnel_id: i64, handle: AppHandle) -> Result<(), Erro error!("{msg}"); Error::InternalError(msg) })?; + if let Some(post_down) = &tunnel.post_down { + debug!("Executing specified PostDown command: {post_down}"); + let _ = execute_command(post_down); + info!("Executed specified PostDown command: {post_down}"); + } info!("Connection closed and interface removed"); } tunnel.delete(pool).await?; diff --git a/src-tauri/src/service/mod.rs b/src-tauri/src/service/mod.rs index ccac5624..179e56ac 100644 --- a/src-tauri/src/service/mod.rs +++ b/src-tauri/src/service/mod.rs @@ -28,7 +28,7 @@ use tonic::{ use tracing::{debug, error, info, info_span, Instrument}; use self::config::Config; -use crate::utils::{execute_command, IS_MACOS}; +use crate::utils::IS_MACOS; use proto::{ desktop_daemon_service_server::{DesktopDaemonService, DesktopDaemonServiceServer}, @@ -93,12 +93,6 @@ impl DesktopDaemonService for DaemonService { // setup WireGuard API let wgapi = setup_wgapi(ifname.clone())?; - if let Some(pre_up) = request.pre_up { - debug!("Executing specified PreUp command: {pre_up}"); - let _ = execute_command(&pre_up); - info!("Executed specified PreUp command: {pre_up}"); - } - #[cfg(not(windows))] { // create new interface @@ -152,11 +146,6 @@ impl DesktopDaemonService for DaemonService { })?; } } - if let Some(post_up) = request.post_up { - debug!("Executing specified PostUp command: {post_up}"); - let _ = execute_command(&post_up); - info!("Executed specified PostUp command: {post_up}"); - } Ok(Response::new(())) } @@ -171,23 +160,12 @@ impl DesktopDaemonService for DaemonService { info!("Removing interface {ifname}"); // setup WireGuard API let wgapi = setup_wgapi(ifname.clone())?; - if let Some(pre_down) = request.pre_down { - debug!("Executing specified PreDown command: {pre_down}"); - let _ = execute_command(&pre_down); - info!("Executed specified PreDown command: {pre_down}"); - } // remove interface wgapi.remove_interface().map_err(|err| { let msg = format!("Failed to remove WireGuard interface {ifname}: {err}"); error!("{msg}"); Status::new(Code::Internal, msg) })?; - if let Some(post_down) = request.post_down { - debug!("Executing specified PostDown command: {post_down}"); - let _ = execute_command(&post_down); - info!("Executed specified PostDown command: {post_down}"); - } - Ok(Response::new(())) } diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index de8baa88..7a45bf09 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -360,14 +360,24 @@ pub async fn setup_interface_tunnel( config: Some(interface_config.clone().into()), allowed_ips, dns: tunnel.dns.clone(), - pre_up: tunnel.pre_up.clone(), - post_up: tunnel.post_up.clone(), + pre_up: None, + post_up: None, }; + if let Some(pre_up) = &tunnel.pre_up { + debug!("Executing specified PreUp command: {pre_up}"); + let _ = execute_command(pre_up); + info!("Executed specified PreUp command: {pre_up}"); + } if let Err(error) = client.create_interface(request).await { let msg = format!("Failed to create interface: {error}"); error!("{msg}"); Err(Error::InternalError(msg)) } else { + if let Some(post_up) = &tunnel.post_up { + debug!("Executing specified PreUp command: {post_up}"); + let _ = execute_command(post_up); + info!("Executed specified PreUp command: {post_up}"); + } info!("Created interface {}", interface_config.name); debug!("Created interface with config: {interface_config:?}"); Ok(()) @@ -664,13 +674,16 @@ pub fn execute_command(command: &str) -> Result<(), Error> { let stdout = String::from_utf8_lossy(&output.stdout); let stderr = String::from_utf8_lossy(&output.stderr); - info!("Command executed successfully. Stdout:\n{}", stdout); + info!( + "Command {command} executed successfully. Stdout: {}", + stdout + ); if !stderr.is_empty() { - error!("Stderr:\n{stderr}"); + error!("Command produced the following output on stderr: {stderr}"); } } else { let stderr = String::from_utf8_lossy(&output.stderr); - error!("Error executing command. Stderr:\n{stderr}"); + error!("Error while executing command: {command}. Stderr: {stderr}"); } } Ok(()) @@ -713,14 +726,24 @@ pub async fn disconnect_interface( { let request = RemoveInterfaceRequest { interface_name: interface_name.clone(), - pre_down: tunnel.pre_down, - post_down: tunnel.post_down, + pre_down: None, + post_down: None, }; + if let Some(pre_down) = tunnel.pre_down { + debug!("Executing specified PreDown command: {pre_down}"); + let _ = execute_command(&pre_down); + info!("Executed specified PreDown command: {pre_down}"); + } if let Err(error) = client.remove_interface(request).await { let msg = format!("Failed to remove interface: {error}"); error!("{msg}"); return Err(Error::InternalError(msg)); } + if let Some(post_down) = tunnel.post_down { + debug!("Executing specified PostDown command: {post_down}"); + let _ = execute_command(&post_down); + info!("Executed specified PostDown command: {post_down}"); + } let mut connection: TunnelConnection = active_connection.into(); connection.save(&state.get_pool()).await?; trace!("Saved connection: {connection:#?}"); From ac7eaa03563724361407d5418d260bc18f00b4c3 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:32:15 +0200 Subject: [PATCH 3/3] change version to 0.4.1 --- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 6 ++---- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index d3df6782..044f1969 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "defguard-client", "private": false, - "version": "0.4.0", + "version": "0.4.1", "type": "module", "scripts": { "dev": "npm-run-all --parallel vite typesafe-i18n", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 6ee9594d..b2d0c45c 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1185,7 +1185,7 @@ checksum = "7046468a81e6a002061c01e6a7c83139daf91b11c30e66795b13217c2d885c8b" [[package]] name = "defguard-client" -version = "0.4.0" +version = "0.4.1" dependencies = [ "anyhow", "base64 0.22.1", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index cf0bb534..0a443b49 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "defguard-client" -version = "0.4.0" +version = "0.4.1" description = "Defguard desktop client" license = "" homepage = "https://github.com/DefGuard/client" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 65258773..95b746ed 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "defguard-client", - "version": "0.4.0" + "version": "0.4.1" }, "tauri": { "systemTray": { @@ -68,9 +68,7 @@ "providerShortName": null, "signingIdentity": null }, - "resources": [ - "resources/*" - ], + "resources": ["resources/*"], "shortDescription": "", "targets": ["deb", "app", "appimage"], "windows": {