|
|
@@ -71,6 +71,7 @@ static ROTATION_RELAY_SERVER: AtomicUsize = AtomicUsize::new(0);
|
|
71
|
71
|
type RelayServers = Vec<String>;
|
|
72
|
72
|
const CHECK_RELAY_TIMEOUT: u64 = 3_000;
|
|
73
|
73
|
static ALWAYS_USE_RELAY: AtomicBool = AtomicBool::new(false);
|
|
|
74
|
+static MUST_LOGIN: AtomicBool = AtomicBool::new(false);
|
|
74
|
75
|
|
|
75
|
76
|
#[derive(Clone)]
|
|
76
|
77
|
struct Inner {
|
|
|
@@ -175,6 +176,25 @@ impl RendezvousServer {
|
|
175
|
176
|
"N"
|
|
176
|
177
|
}
|
|
177
|
178
|
);
|
|
|
179
|
+
|
|
|
180
|
+ let must_login = get_arg("must-login");
|
|
|
181
|
+ log::debug!("must_login={}", must_login);
|
|
|
182
|
+ if must_login.to_uppercase() == "Y" ||
|
|
|
183
|
+ (must_login == "" && std::env::var("MUST_LOGIN")
|
|
|
184
|
+ .unwrap_or_default()
|
|
|
185
|
+ .to_uppercase()
|
|
|
186
|
+ == "Y") {
|
|
|
187
|
+ MUST_LOGIN.store(true, Ordering::SeqCst);
|
|
|
188
|
+ }
|
|
|
189
|
+
|
|
|
190
|
+ log::info!(
|
|
|
191
|
+ "MUST_LOGIN={}",
|
|
|
192
|
+ if MUST_LOGIN.load(Ordering::SeqCst) {
|
|
|
193
|
+ "Y"
|
|
|
194
|
+ } else {
|
|
|
195
|
+ "N"
|
|
|
196
|
+ }
|
|
|
197
|
+ );
|
|
178
|
198
|
if test_addr.to_lowercase() != "no" {
|
|
179
|
199
|
let test_addr = if test_addr.is_empty() {
|
|
180
|
200
|
listener.local_addr()?
|
|
|
@@ -756,6 +776,15 @@ impl RendezvousServer {
|
|
756
|
776
|
});
|
|
757
|
777
|
return Ok((msg_out, None));
|
|
758
|
778
|
}
|
|
|
779
|
+ // Todo check token by jwt
|
|
|
780
|
+ if ph.token.is_empty() && MUST_LOGIN.load(Ordering::SeqCst) {
|
|
|
781
|
+ let mut msg_out = RendezvousMessage::new();
|
|
|
782
|
+ msg_out.set_punch_hole_response(PunchHoleResponse {
|
|
|
783
|
+ other_failure: String::from("Connection failed, please login first"),
|
|
|
784
|
+ ..Default::default()
|
|
|
785
|
+ });
|
|
|
786
|
+ return Ok((msg_out, None));
|
|
|
787
|
+ }
|
|
759
|
788
|
let id = ph.id;
|
|
760
|
789
|
// punch hole request from A, relay to B,
|
|
761
|
790
|
// check if in same intranet first,
|
|
|
@@ -988,13 +1017,14 @@ impl RendezvousServer {
|
|
988
|
1017
|
match fds.next() {
|
|
989
|
1018
|
Some("h") => {
|
|
990
|
1019
|
res = format!(
|
|
991
|
|
- "{}\n{}\n{}\n{}\n{}\n{}\n",
|
|
|
1020
|
+ "{}\n{}\n{}\n{}\n{}\n{}\n{}\n",
|
|
992
|
1021
|
"relay-servers(rs) <separated by ,>",
|
|
993
|
1022
|
"reload-geo(rg)",
|
|
994
|
1023
|
"ip-blocker(ib) [<ip>|<number>] [-]",
|
|
995
|
1024
|
"ip-changes(ic) [<id>|<number>] [-]",
|
|
996
|
|
- "always-use-relay(aur)",
|
|
997
|
|
- "test-geo(tg) <ip1> <ip2>"
|
|
|
1025
|
+ "always-use-relay(aur) [Y|N]",
|
|
|
1026
|
+ "test-geo(tg) <ip1> <ip2>",
|
|
|
1027
|
+ "must-login(ml) [Y|N]",
|
|
998
|
1028
|
)
|
|
999
|
1029
|
}
|
|
1000
|
1030
|
Some("relay-servers" | "rs") => {
|
|
|
@@ -1121,6 +1151,21 @@ impl RendezvousServer {
|
|
1121
|
1151
|
}
|
|
1122
|
1152
|
}
|
|
1123
|
1153
|
}
|
|
|
1154
|
+ Some("must-login" | "ml") => {
|
|
|
1155
|
+ if let Some(rs) = fds.next() {
|
|
|
1156
|
+ if rs.to_uppercase() == "Y" {
|
|
|
1157
|
+ MUST_LOGIN.store(true, Ordering::SeqCst);
|
|
|
1158
|
+ } else {
|
|
|
1159
|
+ MUST_LOGIN.store(false, Ordering::SeqCst);
|
|
|
1160
|
+ }
|
|
|
1161
|
+ } else {
|
|
|
1162
|
+ let _ = writeln!(
|
|
|
1163
|
+ res,
|
|
|
1164
|
+ "MUST_LOGIN: {:?}",
|
|
|
1165
|
+ MUST_LOGIN.load(Ordering::SeqCst)
|
|
|
1166
|
+ );
|
|
|
1167
|
+ }
|
|
|
1168
|
+ }
|
|
1124
|
1169
|
_ => {}
|
|
1125
|
1170
|
}
|
|
1126
|
1171
|
res
|