Skip to content

Commit 4745c8b

Browse files
committed
some more websocket-related improvements
1 parent ef07658 commit 4745c8b

6 files changed

Lines changed: 24 additions & 7 deletions

File tree

application/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ async fn main() {
458458

459459
tracing::info!(
460460
"ssh server listening on {} (app@{}, {}ms)",
461-
address.to_string().cyan(),
461+
address.to_string(),
462462
wings_rs::VERSION,
463463
state.start_time.elapsed().as_millis()
464464
);
@@ -503,7 +503,7 @@ async fn main() {
503503
.context("failed to load SSL certificate and key")
504504
.unwrap();
505505

506-
tracing::info!("https listening on {}", address.to_string().cyan(),);
506+
tracing::info!("https listening on {}", address.to_string());
507507

508508
match axum_server::bind_rustls(address, config)
509509
.serve(router.into_make_service_with_connect_info::<SocketAddr>())
@@ -521,7 +521,7 @@ async fn main() {
521521
}
522522
}
523523
} else {
524-
tracing::info!("http listening on {}", address.to_string().cyan(),);
524+
tracing::info!("http listening on {}", address.to_string());
525525

526526
match axum::serve(
527527
match tokio::net::TcpListener::bind(address).await {
@@ -557,7 +557,7 @@ async fn main() {
557557
{
558558
let socket_path = &state.config.api.host;
559559

560-
tracing::info!("http server listening on {}", socket_path.cyan(),);
560+
tracing::info!("http server listening on {}", socket_path);
561561

562562
let router = router.layer(axum::middleware::from_fn(
563563
|mut req: Request, next: Next| async move {

application/src/server/permissions.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ pub struct UserPermissionsMap {
8787
impl Default for UserPermissionsMap {
8888
fn default() -> Self {
8989
let map = Arc::new(Mutex::new(HashMap::new()));
90-
9190
let (tx, rx) = tokio::sync::broadcast::channel(32);
9291

9392
Self {
@@ -175,6 +174,13 @@ impl UserPermissionsMap {
175174
),
176175
);
177176
}
177+
178+
pub async fn clear_permissions(&self) {
179+
for user_uuid in self.map.lock().await.keys().copied().collect::<Vec<_>>() {
180+
self.map.lock().await.remove(&user_uuid);
181+
self.removal_sender.send(user_uuid).ok();
182+
}
183+
}
178184
}
179185

180186
impl Drop for UserPermissionsMap {

application/src/server/transfer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ impl OutgoingServerTransfer {
725725
["completed".into()].into(),
726726
))
727727
.ok();
728+
server.user_permissions.clear_permissions().await;
728729
});
729730
}));
730731

application/src/server/websocket/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub async fn handle_ws(
3333
let user_ip = state.config.find_ip(&headers, connect_info);
3434

3535
ws.on_upgrade(move |socket| async move {
36-
let (sender, mut reciever) = socket.split();
36+
let (sender, mut receiver) = socket.split();
3737
let sender = Arc::new(Mutex::new(sender));
3838
let socket_jwt = Arc::new(RwLock::new(None));
3939

@@ -69,7 +69,7 @@ pub async fn handle_ws(
6969
websocket_handler.close("permission revoked").await;
7070
break;
7171
}
72-
data = reciever.next() => match data {
72+
data = receiver.next() => match data {
7373
Some(Ok(data)) => data,
7474
Some(Err(err)) => {
7575
tracing::debug!(

application/src/server/websocket/message_handler.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ pub async fn handle_message(
6262
))
6363
.await;
6464
}
65+
WebsocketEvent::SendStatus => {
66+
websocket_handler
67+
.send_message(WebsocketMessage::new(
68+
WebsocketEvent::ServerStatus,
69+
[server.state.get_state().to_str().into()].into(),
70+
))
71+
.await;
72+
}
6573
WebsocketEvent::SendServerLogs => {
6674
if server.state.get_state() != crate::server::state::ServerState::Offline
6775
|| state.config.api.send_offline_server_logs

application/src/server/websocket/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pub enum WebsocketEvent {
5858
SendCommand,
5959
#[serde(rename = "send stats")]
6060
SendStats,
61+
#[serde(rename = "send status")]
62+
SendStatus,
6163
#[serde(rename = "daemon error")]
6264
Error,
6365
#[serde(rename = "jwt error")]

0 commit comments

Comments
 (0)