Skip to content

Commit

Permalink
✨ feat(req): 添加登录校园网功能,修复Linux背景问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CakeAL committed Oct 29, 2024
1 parent f9901f4 commit 140a47b
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 35 deletions.
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ declare module 'vue' {
NLoadingBarProvider: typeof import('naive-ui')['NLoadingBarProvider']
NMenu: typeof import('naive-ui')['NMenu']
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
NPopover: typeof import('naive-ui')['NPopover']
NProgress: typeof import('naive-ui')['NProgress']
NResult: typeof import('naive-ui')['NResult']
NScrollbar: typeof import('naive-ui')['NScrollbar']
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ustb-wifi-tools",
"private": true,
"version": "0.8.1",
"version": "0.8.2",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

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

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ustb-wifi-tools"
version = "0.8.1"
version = "0.8.2"
description = "A Tauri App that can be used to get information of the USTB Wifi"
authors = ["CakeAL"]
edition = "2021"
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,11 @@ pub async fn load_ammeter(
None => Err("获取用电量失败,可能是电表号错误".to_string()),
}
}

#[tauri::command]
pub async fn submit_login_ustb_wifi(user_name: String, password: String) -> Result<String, String> {
match login_ustb_wifi(&user_name, &password).await {
Ok(()) => Ok("登录成功".to_string()),
Err(e) => Err(e.to_string()),
}
}
22 changes: 21 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ pub fn run() {
load_monthly_login_log,
manually_check_update,
load_ammeter,
load_user_flow
load_user_flow,
submit_login_ustb_wifi
])
.setup(|app| {
#[cfg(not(target_os = "android"))]
Expand All @@ -65,8 +66,27 @@ pub fn run() {

#[cfg(not(target_os = "android"))]
fn background_init(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {

let win = app.get_webview_window("main").unwrap();

#[cfg(target_os = "linux")]
win.eval(r#"
document.body.style.backgroundColor = '#f0f0f0';
const themeMedia = window.matchMedia("(prefers-color-scheme: dark)");
if (themeMedia.matches) {
document.body.style.backgroundColor = '#222';
} else {
document.body.style.backgroundColor = '#f0f0f0';
}
themeMedia.addEventListener("change", (event) => {
if (event.matches) {
document.body.style.backgroundColor = '#222';
} else {
document.body.style.backgroundColor = '#f0f0f0';
}
});
"#)?;

#[cfg(target_os = "macos")]
window_vibrancy::apply_vibrancy(
&win,
Expand Down
44 changes: 37 additions & 7 deletions src-tauri/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use reqwest::{header::SET_COOKIE, Client};
use scraper::{Html, Selector};
use serde_json::Value;

use crate::entities::{AmmeterData, EveryLoginData, MacAddress, MonthPayInfo, MonthlyData, UserLoginLog};
use crate::entities::{
AmmeterData, EveryLoginData, MacAddress, MonthPayInfo, MonthlyData, UserLoginLog,
};

// Ciallo~(∠・ω< )⌒☆
pub async fn get_load_user_flow(account: &str, session_id: &str, via_vpn: bool) -> Result<Value> {
Expand Down Expand Up @@ -94,7 +96,8 @@ pub async fn simulate_login(account: &str, password: &str) -> Result<Option<Stri
.text()
.await?;
// dbg!(&response);
if response.contains("账号或密码出现错误!") || response.contains("登录密码不正确") {
if response.contains("账号或密码出现错误!") || response.contains("登录密码不正确")
{
return Ok(None); // 账号或密码出现错误!
}
Ok(Some(jsessionid.to_string()))
Expand Down Expand Up @@ -435,7 +438,7 @@ pub async fn get_user_login_log(
}
// dbg!(every_login_datas);
Ok(Some(UserLoginLog {
// 获取数据如果没有数据会在 unwrap 崩掉该 task,但是 WHO CARES?
// 获取数据如果没有数据会在 unwrap 崩掉该 task,但是 WHO CARES?
#[allow(clippy::get_first)]
ipv4_up: redtexts.get(0).unwrap().trim().parse()?,
ipv4_down: redtexts.get(1).unwrap().trim().parse()?,
Expand Down Expand Up @@ -553,7 +556,7 @@ pub async fn get_address() -> Result<Vec<String>> {
Ok(vec![v4_resp, v6_resp])
}

pub async fn get_ammeter(num: u32) -> Result<Option<i32>, Box<dyn std::error::Error>> {
pub async fn get_ammeter(num: u32) -> Result<Option<i32>> {
let response = Client::new()
.post("http://fspapp.ustb.edu.cn/app.GouDian/index.jsp?m=alipay&c=AliPay&a=getDbYe")
.header("Content-Type", "application/x-www-form-urlencoded")
Expand All @@ -562,11 +565,30 @@ pub async fn get_ammeter(num: u32) -> Result<Option<i32>, Box<dyn std::error::Er
.await?;
let res_text = response.text().await?;
let ammeter_data: AmmeterData = serde_json::from_str(&res_text)?;
let kwh = ammeter_data.service_key.parse::<i32>();
if ammeter_data.status_code != "200".to_string() || kwh.is_err() {
if let Ok(kwh) = ammeter_data.service_key.parse::<i32>() {
Ok(Some(kwh))
} else {
Ok(None)
}
}

pub async fn login_ustb_wifi(account: &str, password: &str) -> Result<()> {
let params = [
("user_account", account),
("user_password", password),
("wlan_ac_ip", "10.0.124.68"),
];
let response = Client::new()
.get("http://202.204.48.66:801/eportal/portal/login")
.query(&params)
.send()
.await?;
let text = response.text().await?;
dbg!(&text);
if text.contains("认证成功") {
Ok(())
} else {
Ok(Some(kwh.unwrap()))
Err(anyhow!("认证失败,可能是由于已经登陆,或者账密错误"))
}
}

Expand Down Expand Up @@ -654,4 +676,12 @@ mod tests {
let res = get_address().await;
dbg!(res.unwrap());
}

#[tokio::test]
async fn test_login_ustb_wifi() {
let account: &str = "1";
let password = "1";
let res = login_ustb_wifi(account, password).await;
println!("{:?}", res);
}
}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"productName": "ustb-wifi-tools",
"mainBinaryName": "ustb-wifi-tools",
"version": "0.8.1",
"version": "0.8.2",
"identifier": "ustb.wifi.tools",
"build": {
"beforeDevCommand": "pnpm dev",
Expand Down
6 changes: 3 additions & 3 deletions src/pages/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const show1 = ref(false);
<p>USTB-V6接入说明:http://cipp.ustb.edu.cn/app.IAManage/index.jsp?m=iamanage&c=Notice&a=noticeInfo&id=22</p>
<p>一个原来能看校园网出口出入流量的网站,现在已经打不开了:http://traffic.ustb.edu.cn/</p>
<h4>校园网 Radius 超时可能解决方法:</h4>
<p>0. 尝试手动打开http://login.ustb.edu.cn/登录</p>
<p>0. 点击本应用登录页的登录校园网功能,或尝试手动打开http://login.ustb.edu.cn/登录</p>
<p>1. 不要使用注销页直接登陆,首先忽略此网络(忘记),然后重开Wi-Fi,再进行登陆,会跳出登录页(虽然ip和注销页是一样的)</p>
<p>2. 关掉代理,再重新进行上述操作。</p>
<p>3. 重启电脑。</p>
Expand All @@ -66,7 +66,7 @@ const show1 = ref(false);
<p>4. 通过 pt 站下载大型软件(比如 Photoshop 等)</p>
<p>5. 自建/使用 ipv6 代理服务器</p>
<br/>
<p>当前 version = "0.8.1"</p>
<p>当前 version = "0.8.2"</p>
</n-space>
</n-card>
</div>
Expand All @@ -80,6 +80,6 @@ const show1 = ref(false);
}
.my-card {
background: rgba(255, 255, 255, 0.05);
background: rgba(255, 255, 255, 0.5);
}
</style>
65 changes: 46 additions & 19 deletions src/pages/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ const railStyle = ({
const manually_check_update = () => {
invoke("manually_check_update").catch((err) => pop_message.error(err));
};
const submit_login_ustb_wifi = () => {
invoke("submit_login_ustb_wifi", {
userName: user_name.value,
password: password.value,
})
.then((res) => pop_message.success(res as string))
.catch((err) => pop_message.error(err));
};
</script>

<template>
Expand All @@ -135,23 +144,27 @@ const manually_check_update = () => {
show-password-on="mousedown"
placeholder="密码"
round
style="margin-top: 5px;"
style="margin-top: 5px"
/>
<n-space>
<n-switch v-model:value="login_via_vpn" :rail-style="railStyle" class="my-switch">
<template #checked> 我不在校园网 </template>
<template #unchecked> 我在校园网 </template>
</n-switch>
<n-button
strong
secondary
type="primary"
@click="get_cookies"
:disabled="button_disabled"
class="my-button"
>
点我登陆获取 cookie⭐️
</n-button>
<n-switch
v-model:value="login_via_vpn"
:rail-style="railStyle"
class="my-switch"
>
<template #checked> 我不在校园网 </template>
<template #unchecked> 我在校园网 </template>
</n-switch>
<n-button
strong
secondary
type="primary"
@click="get_cookies"
:disabled="button_disabled"
class="my-button"
>
点我登陆校园网后台获取 cookie⭐️
</n-button>
</n-space>
<h3 v-if="button_disabled === true">登录中...</h3>
</div>
Expand All @@ -167,10 +180,24 @@ const manually_check_update = () => {
<p>
Windows: C:\Users\%UserName%\AppData\Roaming\ustb-wifi-tools\config.json
</p>
<p>
macOS: ~/Library/Application
Support/ustb-wifi-tools/config.json
</p>
<p>macOS: ~/Library/Application Support/ustb-wifi-tools/config.json</p>
<n-popover trigger="hover">
<template #trigger>
<n-button
strong
secondary
type="primary"
@click="submit_login_ustb_wifi"
:disabled="button_disabled"
class="my-button"
>
点我登陆校园网
</n-button>
</template>
<span
>当你被校园网登录“Radius认证超时!”搞烦了可以用,当然也可以直接用!</span
>
</n-popover>
<p>用来手动检查更新的按钮:</p>
<n-button tertiary type="info" @click="manually_check_update">
我是用来手动检查更新的按钮
Expand Down
2 changes: 1 addition & 1 deletion src/pages/OtherTools.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ const load_ammeter = async () => {
.my-card {
margin: 10px 5px;
width: calc(100vw - 300px);
background: rgba(255, 255, 255, 0.05);
background: rgba(255, 255, 255, 0.5);
}
</style>
1 change: 1 addition & 0 deletions src/pages/UnbindMacs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const unbind = async () => {
await invoke("do_unbind_macs", {
macs: macs,
}).catch((err) => pop_message.error(err));
setTimeout(load_mac_address, 100);
};
</script>

Expand Down

0 comments on commit 140a47b

Please sign in to comment.