Skip to content

Commit

Permalink
Adapt to new auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Jan 20, 2025
1 parent 36e720a commit b56daef
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 140 deletions.
71 changes: 4 additions & 67 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ mac_address2 = "2"
rustls = { version = "0.23", default-features = false }
rustls-platform-verifier = "0.5"


serde = "1"
serde_json = "1"
serde_with = "3"

core-foundation = "0.9"
system-configuration = "0.6"

windows = "0.59"
windows = "0.58"
winresource = "0.1"
12 changes: 6 additions & 6 deletions tunet-helper/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,17 @@ pub struct Auth4Uri;
impl AuthConnectUri for Auth4Uri {
#[inline]
fn log_uri() -> &'static str {
"https://auth4.tsinghua.edu.cn/cgi-bin/srun_portal"
"https://tauth4.tsinghua.edu.cn/cgi-bin/srun_portal"
}

#[inline]
fn challenge_uri() -> &'static str {
"https://auth4.tsinghua.edu.cn/cgi-bin/get_challenge"
"https://tauth4.tsinghua.edu.cn/cgi-bin/get_challenge"
}

#[inline]
fn flux_uri() -> &'static str {
"https://auth4.tsinghua.edu.cn/rad_user_info.php"
"https://tauth4.tsinghua.edu.cn/cgi-bin/rad_user_info"
}
}

Expand All @@ -200,17 +200,17 @@ pub struct Auth6Uri;
impl AuthConnectUri for Auth6Uri {
#[inline]
fn log_uri() -> &'static str {
"https://auth6.tsinghua.edu.cn/cgi-bin/srun_portal"
"https://tauth6.tsinghua.edu.cn/cgi-bin/srun_portal"
}

#[inline]
fn challenge_uri() -> &'static str {
"https://auth6.tsinghua.edu.cn/cgi-bin/get_challenge"
"https://tauth6.tsinghua.edu.cn/cgi-bin/get_challenge"
}

#[inline]
fn flux_uri() -> &'static str {
"https://auth6.tsinghua.edu.cn/rad_user_info.php"
"https://tauth6.tsinghua.edu.cn/cgi-bin/rad_user_info"
}
}

Expand Down
13 changes: 1 addition & 12 deletions tunet-helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ pub use chrono::{
pub use cyper::Client as HttpClient;

mod auth;
mod net;
pub mod suggest;
pub mod usereg;

pub use auth::{Auth4Connect, Auth6Connect};
pub use net::NetConnect;

#[derive(Debug, Error)]
pub enum NetHelperError {
Expand Down Expand Up @@ -162,17 +160,14 @@ impl std::str::FromStr for NetFlux {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NetState {
Unknown,
Net,
Auth4,
Auth6,
}

impl std::str::FromStr for NetState {
type Err = NetHelperError;
fn from_str(s: &str) -> NetHelperResult<Self> {
if s.eq_ignore_ascii_case("net") {
Ok(NetState::Net)
} else if s.eq_ignore_ascii_case("auth4") {
if s.eq_ignore_ascii_case("auth4") {
Ok(NetState::Auth4)
} else if s.eq_ignore_ascii_case("auth6") {
Ok(NetState::Auth6)
Expand All @@ -190,31 +185,27 @@ pub trait TUNetHelper: Send + Sync {

#[derive(Clone)]
pub enum TUNetConnect {
Net(NetConnect),
Auth4(Auth4Connect),
Auth6(Auth6Connect),
}

impl TUNetHelper for TUNetConnect {
async fn login(&self, u: &str, p: &str) -> NetHelperResult<String> {
match self {
Self::Net(inner) => TUNetHelper::login(inner, u, p).await,
Self::Auth4(inner) => TUNetHelper::login(inner, u, p).await,
Self::Auth6(inner) => TUNetHelper::login(inner, u, p).await,
}
}

async fn logout(&self, u: &str) -> NetHelperResult<String> {
match self {
TUNetConnect::Net(inner) => TUNetHelper::logout(inner, u).await,
TUNetConnect::Auth4(inner) => TUNetHelper::logout(inner, u).await,
TUNetConnect::Auth6(inner) => TUNetHelper::logout(inner, u).await,
}
}

async fn flux(&self) -> NetHelperResult<NetFlux> {
match self {
TUNetConnect::Net(inner) => TUNetHelper::flux(inner).await,
TUNetConnect::Auth4(inner) => TUNetHelper::flux(inner).await,
TUNetConnect::Auth6(inner) => TUNetHelper::flux(inner).await,
}
Expand All @@ -224,7 +215,6 @@ impl TUNetHelper for TUNetConnect {
impl TUNetConnect {
pub fn new(s: NetState, client: HttpClient) -> NetHelperResult<TUNetConnect> {
match s {
NetState::Net => Ok(Self::Net(net::NetConnect::new(client))),
NetState::Auth4 => Ok(Self::Auth4(auth::AuthConnect::new(client))),
NetState::Auth6 => Ok(Self::Auth6(auth::AuthConnect::new(client))),
_ => Err(NetHelperError::InvalidHost),
Expand Down Expand Up @@ -296,7 +286,6 @@ mod impl_dart {
fn into_dart(self) -> DartCObject {
match self {
NetState::Unknown => 0,
NetState::Net => 1,
NetState::Auth4 => 2,
NetState::Auth6 => 3,
}
Expand Down
47 changes: 0 additions & 47 deletions tunet-helper/src/net.rs

This file was deleted.

6 changes: 2 additions & 4 deletions tunet-helper/src/suggest/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ async fn can_connect(client: &HttpClient, uri: &str) -> bool {
}

pub async fn suggest(client: &HttpClient) -> NetState {
if can_connect(client, "https://auth4.tsinghua.edu.cn").await {
if can_connect(client, "https://tauth4.tsinghua.edu.cn").await {
NetState::Auth4
} else if can_connect(client, "https://net.tsinghua.edu.cn").await {
NetState::Net
} else if can_connect(client, "https://auth6.tsinghua.edu.cn").await {
} else if can_connect(client, "https://tauth6.tsinghua.edu.cn").await {
NetState::Auth6
} else {
NetState::Unknown
Expand Down
3 changes: 1 addition & 2 deletions tunet-helper/src/suggest/ssid_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ static SUGGEST_SSID_MAP: LazyLock<BTreeMap<&'static str, NetState>> = LazyLock::
("Tsinghua-5G", NetState::Auth4),
("Tsinghua-IPv4", NetState::Auth4),
("Tsinghua-IPv6", NetState::Auth6),
("Tsinghua-Secure", NetState::Net),
("Wifi.郑裕彤讲堂", NetState::Net),
("Tsinghua-Secure", NetState::Auth4),
])
});

Expand Down

0 comments on commit b56daef

Please sign in to comment.