diff --git a/.sqlx/query-5acdf80bf0c44933e3d74e2c86f56f89123c84fc2351ca92ab1e17525c1097ef.json b/.sqlx/query-16802280f46083a640c0f084479e4aee1d1b2098133ff953c1188346c7cb252e.json similarity index 65% rename from .sqlx/query-5acdf80bf0c44933e3d74e2c86f56f89123c84fc2351ca92ab1e17525c1097ef.json rename to .sqlx/query-16802280f46083a640c0f084479e4aee1d1b2098133ff953c1188346c7cb252e.json index b52e770941..67293eca96 100644 --- a/.sqlx/query-5acdf80bf0c44933e3d74e2c86f56f89123c84fc2351ca92ab1e17525c1097ef.json +++ b/.sqlx/query-16802280f46083a640c0f084479e4aee1d1b2098133ff953c1188346c7cb252e.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "UPDATE \"gateway\" SET \"network_id\" = $2,\"url\" = $3,\"hostname\" = $4,\"connected_at\" = $5,\"disconnected_at\" = $6,\"has_certificate\" = $7,\"certificate_expiry\" = $8 WHERE id = $1", + "query": "UPDATE \"gateway\" SET \"network_id\" = $2,\"url\" = $3,\"hostname\" = $4,\"connected_at\" = $5,\"disconnected_at\" = $6,\"has_certificate\" = $7,\"certificate_expiry\" = $8,\"version\" = $9 WHERE id = $1", "describe": { "columns": [], "parameters": { @@ -12,10 +12,11 @@ "Timestamp", "Timestamp", "Bool", - "Timestamp" + "Timestamp", + "Text" ] }, "nullable": [] }, - "hash": "5acdf80bf0c44933e3d74e2c86f56f89123c84fc2351ca92ab1e17525c1097ef" + "hash": "16802280f46083a640c0f084479e4aee1d1b2098133ff953c1188346c7cb252e" } diff --git a/.sqlx/query-ee66d9ce46f283c78402efcd27385327ebeecbefa97c0af2273f7147dab098be.json b/.sqlx/query-2ce4e93d1b2c0fd0c8783e9b574ebdcb7ef45d2f40b8c785353b2cb51c9ee3e8.json similarity index 79% rename from .sqlx/query-ee66d9ce46f283c78402efcd27385327ebeecbefa97c0af2273f7147dab098be.json rename to .sqlx/query-2ce4e93d1b2c0fd0c8783e9b574ebdcb7ef45d2f40b8c785353b2cb51c9ee3e8.json index 5f78596bc5..9c785ac3e0 100644 --- a/.sqlx/query-ee66d9ce46f283c78402efcd27385327ebeecbefa97c0af2273f7147dab098be.json +++ b/.sqlx/query-2ce4e93d1b2c0fd0c8783e9b574ebdcb7ef45d2f40b8c785353b2cb51c9ee3e8.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id, \"name\",\"address\",\"port\",\"public_address\",\"connected_at\",\"disconnected_at\",\"has_certificate\",\"certificate_expiry\" FROM \"proxy\" WHERE id = $1", + "query": "SELECT id, \"name\",\"address\",\"port\",\"public_address\",\"connected_at\",\"disconnected_at\",\"version\",\"has_certificate\",\"certificate_expiry\" FROM \"proxy\" WHERE id = $1", "describe": { "columns": [ { @@ -40,11 +40,16 @@ }, { "ordinal": 7, + "name": "version", + "type_info": "Text" + }, + { + "ordinal": 8, "name": "has_certificate", "type_info": "Bool" }, { - "ordinal": 8, + "ordinal": 9, "name": "certificate_expiry", "type_info": "Timestamp" } @@ -62,9 +67,10 @@ false, true, true, + true, false, true ] }, - "hash": "ee66d9ce46f283c78402efcd27385327ebeecbefa97c0af2273f7147dab098be" + "hash": "2ce4e93d1b2c0fd0c8783e9b574ebdcb7ef45d2f40b8c785353b2cb51c9ee3e8" } diff --git a/.sqlx/query-b48534fac2ea138d617f3653168c692e787fd1187d3dd2b8c128134c3d83cf92.json b/.sqlx/query-4d03f4506afc44d5467c9e7a1f04daff875a766935e93b53df8bbf2be28421a9.json similarity index 80% rename from .sqlx/query-b48534fac2ea138d617f3653168c692e787fd1187d3dd2b8c128134c3d83cf92.json rename to .sqlx/query-4d03f4506afc44d5467c9e7a1f04daff875a766935e93b53df8bbf2be28421a9.json index 15e64e3afb..a62f6fc534 100644 --- a/.sqlx/query-b48534fac2ea138d617f3653168c692e787fd1187d3dd2b8c128134c3d83cf92.json +++ b/.sqlx/query-4d03f4506afc44d5467c9e7a1f04daff875a766935e93b53df8bbf2be28421a9.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id, \"name\",\"address\",\"port\",\"public_address\",\"connected_at\",\"disconnected_at\",\"has_certificate\",\"certificate_expiry\" FROM \"proxy\"", + "query": "SELECT id, \"name\",\"address\",\"port\",\"public_address\",\"connected_at\",\"disconnected_at\",\"version\",\"has_certificate\",\"certificate_expiry\" FROM \"proxy\"", "describe": { "columns": [ { @@ -40,11 +40,16 @@ }, { "ordinal": 7, + "name": "version", + "type_info": "Text" + }, + { + "ordinal": 8, "name": "has_certificate", "type_info": "Bool" }, { - "ordinal": 8, + "ordinal": 9, "name": "certificate_expiry", "type_info": "Timestamp" } @@ -60,9 +65,10 @@ false, true, true, + true, false, true ] }, - "hash": "b48534fac2ea138d617f3653168c692e787fd1187d3dd2b8c128134c3d83cf92" + "hash": "4d03f4506afc44d5467c9e7a1f04daff875a766935e93b53df8bbf2be28421a9" } diff --git a/.sqlx/query-cef21a0fb292e51a461fc1bc44ec967087f477add7724e08b45ca60baabd2705.json b/.sqlx/query-5117dfaead4847c2432f4354ee7caf1a9fd548f64e067ef2d8ec9b1f1d3ea8fb.json similarity index 64% rename from .sqlx/query-cef21a0fb292e51a461fc1bc44ec967087f477add7724e08b45ca60baabd2705.json rename to .sqlx/query-5117dfaead4847c2432f4354ee7caf1a9fd548f64e067ef2d8ec9b1f1d3ea8fb.json index e3f41ec873..145f25c369 100644 --- a/.sqlx/query-cef21a0fb292e51a461fc1bc44ec967087f477add7724e08b45ca60baabd2705.json +++ b/.sqlx/query-5117dfaead4847c2432f4354ee7caf1a9fd548f64e067ef2d8ec9b1f1d3ea8fb.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "INSERT INTO \"proxy\" (\"name\",\"address\",\"port\",\"public_address\",\"connected_at\",\"disconnected_at\",\"has_certificate\",\"certificate_expiry\") VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING id", + "query": "INSERT INTO \"proxy\" (\"name\",\"address\",\"port\",\"public_address\",\"connected_at\",\"disconnected_at\",\"version\",\"has_certificate\",\"certificate_expiry\") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9) RETURNING id", "describe": { "columns": [ { @@ -17,6 +17,7 @@ "Text", "Timestamp", "Timestamp", + "Text", "Bool", "Timestamp" ] @@ -25,5 +26,5 @@ false ] }, - "hash": "cef21a0fb292e51a461fc1bc44ec967087f477add7724e08b45ca60baabd2705" + "hash": "5117dfaead4847c2432f4354ee7caf1a9fd548f64e067ef2d8ec9b1f1d3ea8fb" } diff --git a/.sqlx/query-9c70a4374828099fa19032f4394ce3d23b6d3b80d820d022502916dd8adc0262.json b/.sqlx/query-671c3ef062fa5c901d26adb86c75b7ccad57d9cc9caa41502cbe85c6eafb087e.json similarity index 83% rename from .sqlx/query-9c70a4374828099fa19032f4394ce3d23b6d3b80d820d022502916dd8adc0262.json rename to .sqlx/query-671c3ef062fa5c901d26adb86c75b7ccad57d9cc9caa41502cbe85c6eafb087e.json index ed24b8d62a..f673e531f4 100644 --- a/.sqlx/query-9c70a4374828099fa19032f4394ce3d23b6d3b80d820d022502916dd8adc0262.json +++ b/.sqlx/query-671c3ef062fa5c901d26adb86c75b7ccad57d9cc9caa41502cbe85c6eafb087e.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id, \"network_id\",\"url\",\"hostname\",\"connected_at\",\"disconnected_at\",\"has_certificate\",\"certificate_expiry\" FROM \"gateway\" WHERE id = $1", + "query": "SELECT id, \"network_id\",\"url\",\"hostname\",\"connected_at\",\"disconnected_at\",\"has_certificate\",\"certificate_expiry\",\"version\" FROM \"gateway\" WHERE id = $1", "describe": { "columns": [ { @@ -42,6 +42,11 @@ "ordinal": 7, "name": "certificate_expiry", "type_info": "Timestamp" + }, + { + "ordinal": 8, + "name": "version", + "type_info": "Text" } ], "parameters": { @@ -57,8 +62,9 @@ true, true, false, + true, true ] }, - "hash": "9c70a4374828099fa19032f4394ce3d23b6d3b80d820d022502916dd8adc0262" + "hash": "671c3ef062fa5c901d26adb86c75b7ccad57d9cc9caa41502cbe85c6eafb087e" } diff --git a/.sqlx/query-a0818064c80739debc8a8788dfa8c23bff66bc40eafba7400a7d7db49ab36e2e.json b/.sqlx/query-9655c2e6a8f749fe1ea966dcdc0ea2080a4c27137278b2fb761d3b279b69f9db.json similarity index 83% rename from .sqlx/query-a0818064c80739debc8a8788dfa8c23bff66bc40eafba7400a7d7db49ab36e2e.json rename to .sqlx/query-9655c2e6a8f749fe1ea966dcdc0ea2080a4c27137278b2fb761d3b279b69f9db.json index c321d2e9e7..53deb53137 100644 --- a/.sqlx/query-a0818064c80739debc8a8788dfa8c23bff66bc40eafba7400a7d7db49ab36e2e.json +++ b/.sqlx/query-9655c2e6a8f749fe1ea966dcdc0ea2080a4c27137278b2fb761d3b279b69f9db.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id, \"network_id\",\"url\",\"hostname\",\"connected_at\",\"disconnected_at\",\"has_certificate\",\"certificate_expiry\" FROM \"gateway\"", + "query": "SELECT id, \"network_id\",\"url\",\"hostname\",\"connected_at\",\"disconnected_at\",\"has_certificate\",\"certificate_expiry\",\"version\" FROM \"gateway\"", "describe": { "columns": [ { @@ -42,6 +42,11 @@ "ordinal": 7, "name": "certificate_expiry", "type_info": "Timestamp" + }, + { + "ordinal": 8, + "name": "version", + "type_info": "Text" } ], "parameters": { @@ -55,8 +60,9 @@ true, true, false, + true, true ] }, - "hash": "a0818064c80739debc8a8788dfa8c23bff66bc40eafba7400a7d7db49ab36e2e" + "hash": "9655c2e6a8f749fe1ea966dcdc0ea2080a4c27137278b2fb761d3b279b69f9db" } diff --git a/.sqlx/query-a41787c8c8307414165ab23ef96d82a34d3bfa4364cbe9b8368e71445bc20877.json b/.sqlx/query-a41787c8c8307414165ab23ef96d82a34d3bfa4364cbe9b8368e71445bc20877.json index c6ce1e21b0..2408b9888f 100644 --- a/.sqlx/query-a41787c8c8307414165ab23ef96d82a34d3bfa4364cbe9b8368e71445bc20877.json +++ b/.sqlx/query-a41787c8c8307414165ab23ef96d82a34d3bfa4364cbe9b8368e71445bc20877.json @@ -47,6 +47,11 @@ "ordinal": 8, "name": "certificate_expiry", "type_info": "Timestamp" + }, + { + "ordinal": 9, + "name": "version", + "type_info": "Text" } ], "parameters": { @@ -64,6 +69,7 @@ true, true, false, + true, true ] }, diff --git a/.sqlx/query-95cc72beeb57a84ed791fcc6873b1033ff78a115ae0a3f4882c28b3becb3d0a5.json b/.sqlx/query-cd6c70e9b46c5cdce053d6f0772612388c1e322dbc7ce93d92251b3a82caabef.json similarity index 70% rename from .sqlx/query-95cc72beeb57a84ed791fcc6873b1033ff78a115ae0a3f4882c28b3becb3d0a5.json rename to .sqlx/query-cd6c70e9b46c5cdce053d6f0772612388c1e322dbc7ce93d92251b3a82caabef.json index b45febc008..cb69aae3b7 100644 --- a/.sqlx/query-95cc72beeb57a84ed791fcc6873b1033ff78a115ae0a3f4882c28b3becb3d0a5.json +++ b/.sqlx/query-cd6c70e9b46c5cdce053d6f0772612388c1e322dbc7ce93d92251b3a82caabef.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "INSERT INTO \"gateway\" (\"network_id\",\"url\",\"hostname\",\"connected_at\",\"disconnected_at\",\"has_certificate\",\"certificate_expiry\") VALUES ($1,$2,$3,$4,$5,$6,$7) RETURNING id", + "query": "INSERT INTO \"gateway\" (\"network_id\",\"url\",\"hostname\",\"connected_at\",\"disconnected_at\",\"has_certificate\",\"certificate_expiry\",\"version\") VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING id", "describe": { "columns": [ { @@ -17,12 +17,13 @@ "Timestamp", "Timestamp", "Bool", - "Timestamp" + "Timestamp", + "Text" ] }, "nullable": [ false ] }, - "hash": "95cc72beeb57a84ed791fcc6873b1033ff78a115ae0a3f4882c28b3becb3d0a5" + "hash": "cd6c70e9b46c5cdce053d6f0772612388c1e322dbc7ce93d92251b3a82caabef" } diff --git a/.sqlx/query-d10c9a7b0b391aeb8b4869f6bddf997807b66e0b532da747b146513c34e15c5c.json b/.sqlx/query-d10c9a7b0b391aeb8b4869f6bddf997807b66e0b532da747b146513c34e15c5c.json index 6b597e4488..f007870a8d 100644 --- a/.sqlx/query-d10c9a7b0b391aeb8b4869f6bddf997807b66e0b532da747b146513c34e15c5c.json +++ b/.sqlx/query-d10c9a7b0b391aeb8b4869f6bddf997807b66e0b532da747b146513c34e15c5c.json @@ -42,6 +42,11 @@ "ordinal": 7, "name": "certificate_expiry", "type_info": "Timestamp" + }, + { + "ordinal": 8, + "name": "version", + "type_info": "Text" } ], "parameters": { @@ -57,6 +62,7 @@ true, true, false, + true, true ] }, diff --git a/.sqlx/query-d890aeacd36cbc31d5042a66cf8724f23803f5a9d400d81f39d8d6eacadb7565.json b/.sqlx/query-ebb3c3e89e4d1469d6e54ae6ba4c284b051bd034a869e38581a0db0c613037ab.json similarity index 67% rename from .sqlx/query-d890aeacd36cbc31d5042a66cf8724f23803f5a9d400d81f39d8d6eacadb7565.json rename to .sqlx/query-ebb3c3e89e4d1469d6e54ae6ba4c284b051bd034a869e38581a0db0c613037ab.json index 475daea818..6cbaef5106 100644 --- a/.sqlx/query-d890aeacd36cbc31d5042a66cf8724f23803f5a9d400d81f39d8d6eacadb7565.json +++ b/.sqlx/query-ebb3c3e89e4d1469d6e54ae6ba4c284b051bd034a869e38581a0db0c613037ab.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "UPDATE \"proxy\" SET \"name\" = $2,\"address\" = $3,\"port\" = $4,\"public_address\" = $5,\"connected_at\" = $6,\"disconnected_at\" = $7,\"has_certificate\" = $8,\"certificate_expiry\" = $9 WHERE id = $1", + "query": "UPDATE \"proxy\" SET \"name\" = $2,\"address\" = $3,\"port\" = $4,\"public_address\" = $5,\"connected_at\" = $6,\"disconnected_at\" = $7,\"version\" = $8,\"has_certificate\" = $9,\"certificate_expiry\" = $10 WHERE id = $1", "describe": { "columns": [], "parameters": { @@ -12,11 +12,12 @@ "Text", "Timestamp", "Timestamp", + "Text", "Bool", "Timestamp" ] }, "nullable": [] }, - "hash": "d890aeacd36cbc31d5042a66cf8724f23803f5a9d400d81f39d8d6eacadb7565" + "hash": "ebb3c3e89e4d1469d6e54ae6ba4c284b051bd034a869e38581a0db0c613037ab" } diff --git a/crates/defguard_common/src/db/models/gateway.rs b/crates/defguard_common/src/db/models/gateway.rs index f7f25189d7..ccd7edfce4 100644 --- a/crates/defguard_common/src/db/models/gateway.rs +++ b/crates/defguard_common/src/db/models/gateway.rs @@ -17,6 +17,7 @@ pub struct Gateway { pub disconnected_at: Option, pub has_certificate: bool, pub certificate_expiry: Option, + pub version: Option, } impl Gateway { @@ -43,6 +44,7 @@ impl Gateway { disconnected_at: None, has_certificate: false, certificate_expiry: None, + version: None, } } } diff --git a/crates/defguard_common/src/db/models/proxy.rs b/crates/defguard_common/src/db/models/proxy.rs index ed79f2639f..0df6d59331 100644 --- a/crates/defguard_common/src/db/models/proxy.rs +++ b/crates/defguard_common/src/db/models/proxy.rs @@ -13,6 +13,7 @@ pub struct Proxy { pub public_address: String, pub connected_at: Option, pub disconnected_at: Option, + pub version: Option, pub has_certificate: bool, pub certificate_expiry: Option, } @@ -29,6 +30,7 @@ impl Proxy { disconnected_at: None, has_certificate: false, certificate_expiry: None, + version: None, } } } diff --git a/crates/defguard_core/src/grpc/gateway/handler.rs b/crates/defguard_core/src/grpc/gateway/handler.rs index 99f355c8ca..fec303fa1c 100644 --- a/crates/defguard_core/src/grpc/gateway/handler.rs +++ b/crates/defguard_core/src/grpc/gateway/handler.rs @@ -398,6 +398,14 @@ impl GatewayHandler { }; info!("Connected to Defguard Gateway {uri}"); + let maybe_info = defguard_version::ComponentInfo::from_metadata(response.metadata()); + let (version, _info) = defguard_version::get_tracing_variables(&maybe_info); + + if let Some(mut gateway) = Gateway::find_by_id(&self.pool, self.gateway.id).await? { + gateway.version = Some(version.to_string()); + gateway.save(&self.pool).await?; + } + let mut resp_stream = response.into_inner(); let mut config_sent = false; diff --git a/crates/defguard_core/src/handlers/mail.rs b/crates/defguard_core/src/handlers/mail.rs index 7f78913bec..922d1642c4 100644 --- a/crates/defguard_core/src/handlers/mail.rs +++ b/crates/defguard_core/src/handlers/mail.rs @@ -130,9 +130,42 @@ pub async fn send_support_data( "User {} sending support mail to {SUPPORT_EMAIL_ADDRESS}", session.user.username ); + + let proxies = defguard_common::db::models::proxy::Proxy::all(&appstate.pool).await?; + let gateways = defguard_common::db::models::gateway::Gateway::all(&appstate.pool).await?; + + let components_info = json!({ + "proxies": proxies.iter().map(|p| json!({ + "id": p.id, + "name": p.name, + "version": p.version.as_deref().unwrap_or("unknown"), + "address": p.address, + "connected_at": p.connected_at + })).collect::>(), + "gateways": gateways.iter().map(|g| json!({ + "id": g.id, + "network_id": g.network_id, + "version": g.version.as_deref().unwrap_or("unknown"), + "url": g.url, + "has_certificate": g.has_certificate, + "hostname": g.hostname, + "connected_at": g.connected_at, + })).collect::>(), + }); + + let components_json = + serde_json::to_string(&components_info).unwrap_or("JSON formatting error".to_string()); + + let components = Attachment { + filename: format!("defguard-components-{}.json", Utc::now()), + content: components_json.into(), + content_type: ContentType::TEXT_PLAIN, + }; + let config = dump_config(&appstate.pool).await; let config = - serde_json::to_string_pretty(&config).unwrap_or("Json formatting error".to_string()); + serde_json::to_string_pretty(&config).unwrap_or("JSON formatting error".to_string()); + let config = Attachment { filename: format!("defguard-support-data-{}.json", Utc::now()), content: config.into(), @@ -149,10 +182,11 @@ pub async fn send_support_data( to: SUPPORT_EMAIL_ADDRESS.to_string(), subject: SUPPORT_EMAIL_SUBJECT.to_string(), content: support_data_mail()?, - attachments: vec![config, logs], + attachments: vec![components, config, logs], result_tx: Some(tx), }; let (to, subject) = (mail.to.clone(), mail.subject.clone()); + match appstate.mail_tx.send(mail) { Ok(()) => match rx.recv().await { Some(Ok(_)) => { diff --git a/crates/defguard_core/src/support.rs b/crates/defguard_core/src/support.rs index f9d0a99d77..0b710cdd12 100644 --- a/crates/defguard_core/src/support.rs +++ b/crates/defguard_core/src/support.rs @@ -52,6 +52,39 @@ pub async fn dump_config(db: &PgPool) -> Value { }; let users_diagnostic_data = unwrap_json(User::all_without_sensitive_data(db).await); + let proxies = match defguard_common::db::models::proxy::Proxy::::all(db).await { + Ok(proxies) => json!( + proxies + .iter() + .map(|p| json!({ + "id": p.id, + "name": p.name, + "version": p.version.as_deref().unwrap_or("unknown"), + "address": p.address, + "connected_at": p.connected_at + })) + .collect::>() + ), + Err(err) => json!({"error": err.to_string()}), + }; + + let gateways = match defguard_common::db::models::gateway::Gateway::::all(db).await { + Ok(gateways) => json!( + gateways + .iter() + .map(|g| json!({ + "id": g.id, + "network_id": g.network_id, + "version": g.version.as_deref().unwrap_or("unknown"), + "url": g.url, + "hostname": g.hostname, + "connected_at": g.connected_at, + })) + .collect::>() + ), + Err(err) => json!({"error": err.to_string()}), + }; + json!({ "settings": settings, "networks": networks, @@ -59,5 +92,7 @@ pub async fn dump_config(db: &PgPool) -> Value { "devices": devices, "users": users_diagnostic_data, "config": server_config(), + "proxies": proxies, + "gateways": gateways, }) } diff --git a/crates/defguard_proxy_manager/src/lib.rs b/crates/defguard_proxy_manager/src/lib.rs index ddb680e1dd..13547b1ca3 100644 --- a/crates/defguard_proxy_manager/src/lib.rs +++ b/crates/defguard_proxy_manager/src/lib.rs @@ -48,7 +48,7 @@ use openidconnect::{AuthorizationCode, Nonce, Scope, core::CoreAuthenticationFlo use reqwest::Url; use secrecy::ExposeSecret; use semver::Version; -use sqlx::PgPool; +use sqlx::{PgPool, types::chrono::Utc}; use thiserror::Error; use tokio::{ select, @@ -192,6 +192,7 @@ impl ProxyManager { // Currently we can't shutdown this proxy since it was started via CLI arguments (no ID in DB) // This should be removed when we do a proper import of old proxies Arc::new(Mutex::new(None)), + None, ); proxies.push(proxy); } @@ -300,6 +301,7 @@ struct ProxyServer { /// Proxy server gRPC URL url: Url, shutdown_signal: Arc>>, + proxy_id: Option, } impl ProxyServer { @@ -310,6 +312,7 @@ impl ProxyServer { remote_mfa_responses: Arc>>>, sessions: Arc>>, shutdown_signal: Arc>>, + proxy_id: Option, ) -> Self { // Instantiate gRPC servers. let services = ProxyServices::new(&pool, tx, remote_mfa_responses, sessions); @@ -319,6 +322,7 @@ impl ProxyServer { services, url, shutdown_signal, + proxy_id, } } @@ -331,6 +335,7 @@ impl ProxyServer { shutdown_signal: Arc>>, ) -> Result { let url = Url::from_str(&format!("http://{}:{}", proxy.address, proxy.port))?; + let proxy_id = proxy.id; Ok(Self::new( pool, url, @@ -338,6 +343,7 @@ impl ProxyServer { remote_mfa_responses, sessions, shutdown_signal, + Some(proxy_id), )) } @@ -418,6 +424,21 @@ impl ProxyServer { let (version, info) = get_tracing_variables(&maybe_info); let proxy_is_supported = is_proxy_version_supported(Some(&version)); + if let Some(proxy_id) = self.proxy_id { + if let Some(mut proxy) = Proxy::find_by_id(&self.pool, proxy_id).await? { + proxy.version = Some(version.to_string()); + proxy.connected_at = Some(Utc::now().naive_utc()); + proxy.save(&self.pool).await?; + } else { + warn!("Couldn't find proxy by id, URL: {} ", self.url); + } + } else { + warn!( + "Couldn't obtain proxy id, check if proxy exists in database. URL: {}", + self.url + ); + } + let span = tracing::info_span!("proxy_bidi", component = %DefguardComponent::Proxy, version = version.to_string(), info); let _guard = span.enter(); diff --git a/migrations/20260121122631_[2.0.0]_Add_component_versions.down.sql b/migrations/20260121122631_[2.0.0]_Add_component_versions.down.sql new file mode 100644 index 0000000000..d45223bf16 --- /dev/null +++ b/migrations/20260121122631_[2.0.0]_Add_component_versions.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE proxy DROP COLUMN version; +ALTER TABLE gateway DROP COLUMN version; diff --git a/migrations/20260121122631_[2.0.0]_Add_component_versions.up.sql b/migrations/20260121122631_[2.0.0]_Add_component_versions.up.sql new file mode 100644 index 0000000000..461804fd0f --- /dev/null +++ b/migrations/20260121122631_[2.0.0]_Add_component_versions.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE proxy ADD COLUMN version TEXT; +ALTER TABLE gateway ADD COLUMN version TEXT; diff --git a/proto b/proto index 0b982922c4..d01bfabe4e 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 0b982922c4dab3304a8cb01aed1d8cee806600b7 +Subproject commit d01bfabe4e4f7f419de3682020e708f5861530da