diff --git a/.gitignore b/.gitignore index 77910f7a75..b31db22919 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ result/ .aider* .env .zellij_layout.kdl +docker-compose-dev.yaml diff --git a/.sqlx/query-e35609fb11b592660bbe1ae5951de81314b320428a49960a6efafd73ff8fd721.json b/.sqlx/query-e35609fb11b592660bbe1ae5951de81314b320428a49960a6efafd73ff8fd721.json new file mode 100644 index 0000000000..c66c4f6d1c --- /dev/null +++ b/.sqlx/query-e35609fb11b592660bbe1ae5951de81314b320428a49960a6efafd73ff8fd721.json @@ -0,0 +1,26 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id, name AS display FROM wireguard_network ORDER BY id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "display", + "type_info": "Text" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false + ] + }, + "hash": "e35609fb11b592660bbe1ae5951de81314b320428a49960a6efafd73ff8fd721" +} diff --git a/crates/defguard_core/src/handlers/mod.rs b/crates/defguard_core/src/handlers/mod.rs index 2d5e1f4850..067c876832 100644 --- a/crates/defguard_core/src/handlers/mod.rs +++ b/crates/defguard_core/src/handlers/mod.rs @@ -42,6 +42,7 @@ pub mod openid_clients; pub mod openid_flow; pub(crate) mod pagination; pub mod proxy; +pub mod resource_display; pub mod session_info; pub mod settings; pub(crate) mod ssh_authorized_keys; diff --git a/crates/defguard_core/src/handlers/resource_display.rs b/crates/defguard_core/src/handlers/resource_display.rs new file mode 100644 index 0000000000..edc23acd25 --- /dev/null +++ b/crates/defguard_core/src/handlers/resource_display.rs @@ -0,0 +1,25 @@ +use axum::{Extension, http::StatusCode}; +use serde::Serialize; + +use super::{ApiResponse, ApiResult}; +use crate::auth::AdminRole; + +#[derive(Serialize, Debug)] +pub struct ResourceDisplay { + pub id: i64, + pub display: String, +} + +pub async fn get_locations_display( + _admin: AdminRole, + Extension(pool): Extension, +) -> ApiResult { + let resources = sqlx::query_as!( + ResourceDisplay, + "SELECT id, name AS display FROM wireguard_network ORDER BY id" + ) + .fetch_all(&pool) + .await?; + + Ok(ApiResponse::json(resources, StatusCode::OK)) +} diff --git a/crates/defguard_core/src/lib.rs b/crates/defguard_core/src/lib.rs index 362366d7d7..6113302eb9 100644 --- a/crates/defguard_core/src/lib.rs +++ b/crates/defguard_core/src/lib.rs @@ -141,6 +141,7 @@ use crate::{ userinfo, }, proxy::{delete_proxy, proxy_details, proxy_list, update_proxy}, + resource_display::get_locations_display, settings::{ get_settings, get_settings_essentials, patch_settings, set_default_branding, test_ldap_settings, update_settings, @@ -533,6 +534,7 @@ pub fn build_webapp( post(start_network_device_setup_for_device), ) .route("/network", post(create_network).get(list_networks)) + .route("/network/display", get(get_locations_display)) .route("/network/import", post(import_network)) .route("/network/stats", get(locations_overview_stats)) .route("/network/gateways", get(all_gateways_status)) diff --git a/crates/defguard_setup/src/migration.rs b/crates/defguard_setup/src/migration.rs index 4b452f6df0..44f5c80bb7 100644 --- a/crates/defguard_setup/src/migration.rs +++ b/crates/defguard_setup/src/migration.rs @@ -20,7 +20,8 @@ use defguard_core::{ mfa_enable, recovery_code, request_email_mfa_code, totp_code, totp_enable, totp_secret, webauthn_end, webauthn_finish, webauthn_init, webauthn_start, }, - component_setup::setup_proxy_tls_stream, + component_setup::{setup_gateway_tls_stream, setup_proxy_tls_stream}, + resource_display::get_locations_display, session_info::get_session_info, settings::{get_settings, get_settings_essentials, patch_settings}, wireguard::list_networks, @@ -121,6 +122,11 @@ pub fn build_migration_webapp( .route("/auth/email/verify", post(email_mfa_code)) .route("/auth/recovery", post(recovery_code)) .route("/network", get(list_networks)) + .route("/network/display", get(get_locations_display)) + .route( + "/network/{network_id}/gateways/setup", + get(setup_gateway_tls_stream), + ) .nest( "/migration", Router::new() diff --git a/crates/defguard_setup/src/setup_server.rs b/crates/defguard_setup/src/setup_server.rs index c8d1240f23..97eee0d54b 100644 --- a/crates/defguard_setup/src/setup_server.rs +++ b/crates/defguard_setup/src/setup_server.rs @@ -13,7 +13,10 @@ use defguard_common::VERSION; use defguard_core::{ auth::failed_login::FailedLoginMap, handle_404, - handlers::{component_setup::setup_proxy_tls_stream, settings::get_settings_essentials}, + handlers::{ + component_setup::setup_proxy_tls_stream, resource_display::get_locations_display, + settings::get_settings_essentials, + }, health_check, }; use defguard_web_ui::{index, svg, web_asset}; @@ -45,6 +48,7 @@ pub fn build_setup_webapp(pool: PgPool, version: Version, setup_shutdown_tx: Sen .route("/health", get(health_check)) .route("/settings_essentials", get(get_settings_essentials)) .route("/session-info", get(get_session_info)) + .route("/network/display", get(get_locations_display)) .route("/wizard", get(get_wizard_state)) .route("/proxy/setup/stream", get(setup_proxy_tls_stream)) .nest( diff --git a/docker-compose.yaml b/docker-compose.yaml index 8cf2fd08f1..96034653cd 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -26,7 +26,7 @@ services: - db gateway: - image: ghcr.io/defguard/gateway:latest + image: ghcr.io/defguard/gateway environment: DEFGUARD_GRPC_URL: http://core:50055 DEFGUARD_STATS_PERIOD: 60 @@ -35,6 +35,7 @@ services: ports: # WireGuard endpoint - "50051:50051/udp" + - "50066:50066" depends_on: - core cap_add: @@ -50,6 +51,11 @@ services: - ./.volumes/db:/var/lib/postgresql/data ports: - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U defguard"] + interval: 3s + timeout: 5s + retries: 5 device: build: diff --git a/web/src/pages/AddLocationPage/steps/AddLocationAccessStep.tsx b/web/src/pages/AddLocationPage/steps/AddLocationAccessStep.tsx index 7f0bcff779..6707b5290a 100644 --- a/web/src/pages/AddLocationPage/steps/AddLocationAccessStep.tsx +++ b/web/src/pages/AddLocationPage/steps/AddLocationAccessStep.tsx @@ -2,11 +2,11 @@ import { useQuery } from '@tanstack/react-query'; import { useCallback, useMemo, useState } from 'react'; import { m } from '../../../paraglide/messages'; import api from '../../../shared/api/api'; +import { Controls } from '../../../shared/components/Controls/Controls'; import { SelectionSection } from '../../../shared/components/SelectionSection/SelectionSection'; import type { SelectionOption } from '../../../shared/components/SelectionSection/type'; import { WizardCard } from '../../../shared/components/wizard/WizardCard/WizardCard'; import { Button } from '../../../shared/defguard-ui/components/Button/Button'; -import { ModalControls } from '../../../shared/defguard-ui/components/ModalControls/ModalControls'; import { AddLocationPageStep } from '../types'; import { useAddLocationStore } from '../useAddLocationStore'; @@ -44,18 +44,7 @@ export const AddLocationAccessStep = () => { selection={selected} onChange={setSelected} /> - { - saveChanges(selected); - useAddLocationStore.setState({ - activeStep: AddLocationPageStep.Firewall, - }); - }, - }} - > +