Skip to content
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
36 changes: 19 additions & 17 deletions crates/defguard_core/src/enterprise/db/models/snat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,40 @@ impl UserSnatBinding {
}

impl UserSnatBinding<Id> {
pub async fn find_binding<'e, E>(
pub(crate) async fn find_binding<'e, E>(
executor: E,
location_id: Id,
user_id: Id,
) -> Result<Self, UserSnatBindingError>
where
E: PgExecutor<'e>,
{
let binding = query_as!(Self,
"SELECT id, user_id, location_id, \"public_ip\" \"public_ip: IpAddr\" FROM user_snat_binding WHERE location_id = $1 AND user_id = $2",
location_id, user_id
).fetch_one(executor).await?;
let binding = query_as!(
Self,
"SELECT id, user_id, location_id, \"public_ip\" \"public_ip: IpAddr\" \
FROM user_snat_binding WHERE location_id = $1 AND user_id = $2",
location_id,
user_id
)
.fetch_one(executor)
.await?;

Ok(binding)
}

pub async fn all_for_location<'e, E>(
executor: E,
location_id: Id,
) -> Result<Vec<Self>, sqlx::Error>
pub async fn all_for_location<'e, E>(executor: E, location_id: Id) -> sqlx::Result<Vec<Self>>
where
E: PgExecutor<'e>,
{
let bindings = query_as!(Self,
"SELECT id, user_id, location_id, \"public_ip\" \"public_ip: IpAddr\" FROM user_snat_binding WHERE location_id = $1",
location_id
).fetch_all(executor).await?;
let bindings = query_as!(
Self,
"SELECT id, user_id, location_id, \"public_ip\" \"public_ip: IpAddr\" \
FROM user_snat_binding WHERE location_id = $1",
location_id
)
.fetch_all(executor)
.await?;

Ok(bindings)
}

pub fn update_ip(&mut self, new_public_ip: IpAddr) {
self.public_ip = new_public_ip;
}
}
3 changes: 1 addition & 2 deletions crates/defguard_core/src/enterprise/snat/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ pub async fn modify_snat_binding(
// clone state before modifications
let before = snat_binding.clone();

// update public IP
snat_binding.update_ip(data.public_ip);
snat_binding.public_ip = data.public_ip;
snat_binding.save(&appstate.pool).await?;

// emit event
Expand Down
9 changes: 6 additions & 3 deletions crates/defguard_gateway_manager/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ use std::{
};

use chrono::DateTime;
#[cfg(not(test))]
use defguard_common::db::models::Settings;
use defguard_common::{
VERSION,
db::{
Id,
models::{WireguardNetwork, gateway::Gateway, wireguard::DEFAULT_WIREGUARD_MTU},
models::{Settings, WireguardNetwork, gateway::Gateway, wireguard::DEFAULT_WIREGUARD_MTU},
},
messages::peer_stats_update::PeerStatsUpdate,
};
Expand Down Expand Up @@ -168,6 +166,11 @@ impl GatewayHandler {
/// Send gateway disconnected notification.
/// Sends notification only if last notification time is bigger than specified in config.
async fn send_disconnect_notification(&self) {
let settings = Settings::get_current_settings();
if !settings.gateway_disconnect_notifications_enabled {
return;
}

debug!("Sending gateway disconnect email notification");
let name = self.gateway.name.clone();
let pool = self.pool.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ const AssignmentForm = ({
<ModalControls
submitProps={{
text: m.controls_submit(),
disabled: isSubmitting,
disabled: isSubmitting || locationData.locations.length === 0,
onClick: () => form.handleSubmit(),
}}
cancelProps={{
Expand Down
Loading