mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 23:24:35 +01:00
Update proxy to handle traffic
This commit is contained in:
@@ -3,11 +3,11 @@ root = true
|
|||||||
[*]
|
[*]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
end_of_line = crlf
|
end_of_line = crlf
|
||||||
indent_size = 4
|
indent_size = 2
|
||||||
indent_style = space
|
indent_style = space
|
||||||
insert_final_newline = false
|
insert_final_newline = false
|
||||||
max_line_length = 120
|
max_line_length = 120
|
||||||
tab_width = 4
|
tab_width = 2
|
||||||
trim_trailing_whitespace = false
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
[*.rs]
|
[*.rs]
|
||||||
|
|||||||
11
src-tauri/Cargo.lock
generated
11
src-tauri/Cargo.lock
generated
@@ -671,6 +671,7 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"tauri",
|
"tauri",
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
|
"tokio",
|
||||||
"tokio-rustls",
|
"tokio-rustls",
|
||||||
"tokio-tungstenite",
|
"tokio-tungstenite",
|
||||||
"tracing",
|
"tracing",
|
||||||
@@ -3302,6 +3303,15 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signal-hook-registry"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "siphasher"
|
name = "siphasher"
|
||||||
version = "0.3.10"
|
version = "0.3.10"
|
||||||
@@ -3877,6 +3887,7 @@ dependencies = [
|
|||||||
"num_cpus",
|
"num_cpus",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"signal-hook-registry",
|
||||||
"socket2",
|
"socket2",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ tauri-build = { version = "1.0.0-rc.8", features = [] }
|
|||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tauri = { version = "1.0.0-rc.9", features = ["api-all"] }
|
tauri = { version = "1.0.0-rc.9", features = ["api-all"] }
|
||||||
|
|
||||||
# zip library
|
# ZIP-archive library.
|
||||||
zip-extract = "0.1.1"
|
zip-extract = "0.1.1"
|
||||||
|
|
||||||
# For creating a "global" downloads list
|
# For creating a "global" downloads list.
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
|
||||||
# Access to the Windows Registry.
|
# Access to the Windows Registry.
|
||||||
@@ -38,6 +38,7 @@ hudsucker = "0.17.2"
|
|||||||
tracing = "0.1.21"
|
tracing = "0.1.21"
|
||||||
tokio-rustls = "0.23.0"
|
tokio-rustls = "0.23.0"
|
||||||
tokio-tungstenite = "0.17.0"
|
tokio-tungstenite = "0.17.0"
|
||||||
|
tokio = { version = "1.18.2", features = ["signal"] }
|
||||||
rustls-pemfile = "1.0.0"
|
rustls-pemfile = "1.0.0"
|
||||||
reqwest = { version = "0.11.3", features = ["stream"] }
|
reqwest = { version = "0.11.3", features = ["stream"] }
|
||||||
futures-util = "0.3.14"
|
futures-util = "0.3.14"
|
||||||
|
|||||||
22
src-tauri/resources/cert.crt
Normal file
22
src-tauri/resources/cert.crt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIDkzCCAnugAwIBAgIJAMdLw5xpuf6yMA0GCSqGSIb3DQEBCwUAMGYxHTAbBgNV
|
||||||
|
BAMMFEh1ZHN1Y2tlciBJbmR1c3RyaWVzMR0wGwYDVQQKDBRIdWRzdWNrZXIgSW5k
|
||||||
|
dXN0cmllczELMAkGA1U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1
|
||||||
|
XR72llJbbExYbTzaEV3uw7sJsuwldMC/QL+oWm/Jnwc2WfLTl3HjLOaK9r/smF/E
|
||||||
|
RtYk5yo7J6pMALrIP7SPHpFooez5JHn2ucP42HcUwOXmrDIOUt6gJQ4w8DBE46Bo
|
||||||
|
oMKSHK2k0g==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -4,6 +4,7 @@ windows_subsystem = "windows"
|
|||||||
)]
|
)]
|
||||||
|
|
||||||
use open;
|
use open;
|
||||||
|
use tokio::sync::oneshot::Sender;
|
||||||
use structs::{APIQuery};
|
use structs::{APIQuery};
|
||||||
|
|
||||||
mod file_helpers;
|
mod file_helpers;
|
||||||
@@ -40,15 +41,18 @@ async fn connect(port: u16) {
|
|||||||
// Log message to console.
|
// Log message to console.
|
||||||
println!("Connecting to proxy...");
|
println!("Connecting to proxy...");
|
||||||
|
|
||||||
// Create and start a proxy.
|
|
||||||
proxy::create_proxy(port).await;
|
|
||||||
|
|
||||||
// Change proxy settings.
|
// Change proxy settings.
|
||||||
proxy::connect_to_proxy(port);
|
proxy::connect_to_proxy(port);
|
||||||
|
|
||||||
|
// Create and start a proxy.
|
||||||
|
proxy::create_proxy(port).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn disconnect() {
|
fn disconnect() {
|
||||||
|
// Log message to console.
|
||||||
|
println!("Disconnecting from proxy...");
|
||||||
|
|
||||||
// Change proxy settings.
|
// Change proxy settings.
|
||||||
proxy::disconnect_from_proxy();
|
proxy::disconnect_from_proxy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
* https://github.com/omjadas/hudsucker/blob/main/examples/log.rs
|
* https://github.com/omjadas/hudsucker/blob/main/examples/log.rs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use std::borrow::Borrow;
|
||||||
use hudsucker::{
|
use hudsucker::{
|
||||||
async_trait::async_trait,
|
async_trait::async_trait,
|
||||||
certificate_authority::RcgenAuthority,
|
certificate_authority::RcgenAuthority,
|
||||||
@@ -14,12 +15,12 @@ use std::net::SocketAddr;
|
|||||||
use registry::{Hive, Data, Security};
|
use registry::{Hive, Data, Security};
|
||||||
|
|
||||||
use rustls_pemfile as pemfile;
|
use rustls_pemfile as pemfile;
|
||||||
|
use tauri::http::Uri;
|
||||||
|
use tokio::sync::oneshot::Sender;
|
||||||
|
|
||||||
/**
|
async unsafe fn shutdown_signal() {
|
||||||
* Application shutdown handler.
|
tokio::signal::ctrl_c().await
|
||||||
*/
|
.expect("Failed to install CTRL+C signal handler");
|
||||||
async fn shutdown_signal() {
|
|
||||||
disconnect_from_proxy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -31,8 +32,29 @@ impl HttpHandler for ProxyHandler {
|
|||||||
_context: &HttpContext,
|
_context: &HttpContext,
|
||||||
request: Request<Body>
|
request: Request<Body>
|
||||||
) -> RequestOrResponse {
|
) -> RequestOrResponse {
|
||||||
println!("{:?}", request.uri().path());
|
// Get request parts.
|
||||||
RequestOrResponse::Request(request)
|
let (parts, body) = request.into_parts();
|
||||||
|
|
||||||
|
// Parse request URI.
|
||||||
|
let mut uri = parts.uri.clone();
|
||||||
|
let path = uri.to_string();
|
||||||
|
|
||||||
|
// Check URI against constraints.
|
||||||
|
if path.contains("hoyoverse.com") || path.contains("mihoyo.com") || path.contains("yuanshen.com") {
|
||||||
|
let mut new_uri = String::new();
|
||||||
|
new_uri.push_str("127.0.0.1");
|
||||||
|
new_uri.push_str(uri.path());
|
||||||
|
|
||||||
|
uri = Uri::from_static(new_uri.as_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
let builder = Request::builder()
|
||||||
|
.method(&parts.method)
|
||||||
|
.uri(&uri)
|
||||||
|
.version(parts.version);
|
||||||
|
let modified = builder.body(body).unwrap();
|
||||||
|
|
||||||
|
RequestOrResponse::Request(modified)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_response(&mut self,
|
async fn handle_response(&mut self,
|
||||||
@@ -74,9 +96,10 @@ pub(crate) async fn create_proxy(proxy_port: u16) {
|
|||||||
.with_http_handler(ProxyHandler)
|
.with_http_handler(ProxyHandler)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Create the proxy & listen for errors.
|
// Start the proxy.
|
||||||
proxy.start(shutdown_signal()).await
|
unsafe {
|
||||||
.expect("Failed to start proxy");
|
tokio::spawn(proxy.start(shutdown_signal()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,4 +132,6 @@ pub(crate) fn disconnect_from_proxy() {
|
|||||||
// Set registry values.
|
// Set registry values.
|
||||||
settings.set_value("ProxyEnable", &Data::U32(0)).unwrap();
|
settings.set_value("ProxyEnable", &Data::U32(0)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("Disconnected from proxy.");
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ import React from 'react'
|
|||||||
import {invoke} from '@tauri-apps/api/tauri'
|
import {invoke} from '@tauri-apps/api/tauri'
|
||||||
|
|
||||||
async function startProxy() {
|
async function startProxy() {
|
||||||
await invoke('connect')
|
await invoke('connect', { port: 2222 })
|
||||||
}
|
}
|
||||||
|
|
||||||
async function stopProxy() {
|
async function stopProxy() {
|
||||||
|
|||||||
Reference in New Issue
Block a user