Skip to content

Commit 9990d75

Browse files
committed
Merge branch 'tcpserver-master-build' of github.com:sctg-development/sctgdesk-server into tcpserver-master-build
2 parents 6912fc9 + 925e217 commit 9990d75

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ sctgdesk-api-server = { git = "https://github.com/sctg-development/sctgdesk-api-
6161
rocket = { version = "0.5", features = ["json", "secrets"] }
6262
num_cpus = "1.16"
6363

64+
reqwest = { version = "0.12", default-features = false, features = ["json","rustls-tls"] }
65+
6466
[build-dependencies]
6567
hbb_common = { path = "libs/hbb_common" }
6668

src/rendezvous_server.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ use std::{
4545
time::Instant,
4646
};
4747

48+
use reqwest::Client;
49+
use serde_json::json;
50+
4851
#[derive(Clone, Debug)]
4952
enum Data {
5053
Msg(Box<RendezvousMessage>, SocketAddr),
@@ -815,17 +818,39 @@ impl RendezvousServer {
815818
}
816819
// For limiting abuse, only allow logged in users to punch hole
817820
// if LOGGED_IN_ONLY=Y is set in env or --logged-in-only is passed
818-
if ph.token.is_empty() && std::env::var("LOGGED_IN_ONLY")
821+
if std::env::var("LOGGED_IN_ONLY")
819822
.unwrap_or_default()
820823
.to_uppercase()
821824
== "Y"
822825
{
823826
let mut msg_out = RendezvousMessage::new();
824-
msg_out.set_punch_hole_response(PunchHoleResponse {
825-
other_failure: String::from("The connection is not allowed. You have not logged in."),
826-
..Default::default()
827-
});
828-
return Ok((msg_out, None));
827+
if !ph.token.is_empty() {
828+
let api_server = std::env::var("API_SERVER").unwrap_or_else(|_| "http://127.0.0.1:21114".to_string());
829+
let api_url = api_server + "/api/currentUser";
830+
let client = Client::new();
831+
let res = client.post(&api_url)
832+
.bearer_auth(ph.token)
833+
.json(&json!({ "id": ph.id, "uuid": "uuid" }))
834+
.send()
835+
.await?;
836+
if res.status().is_success() {
837+
let response_body: serde_json::Value = res.json().await?;
838+
log::debug!("Username: {}", response_body["name"]);
839+
} else {
840+
log::debug!("Error: {}", res.status());
841+
msg_out.set_punch_hole_response(PunchHoleResponse {
842+
other_failure: String::from("The connection is not allowed. Your session expired."),
843+
..Default::default()
844+
});
845+
return Ok((msg_out, None));
846+
}
847+
} else {
848+
msg_out.set_punch_hole_response(PunchHoleResponse {
849+
other_failure: String::from("The connection is not allowed. You have not logged in."),
850+
..Default::default()
851+
});
852+
return Ok((msg_out, None));
853+
}
829854
}
830855
let id = ph.id;
831856
// punch hole request from A, relay to B,

0 commit comments

Comments
 (0)