@@ -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 ) ]
4952enum 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