init
This commit is contained in:
commit
50f72e1e07
5 changed files with 96 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
20
Cargo.toml
Normal file
20
Cargo.toml
Normal file
|
@ -0,0 +1,20 @@
|
|||
[package]
|
||||
name = "sn-client"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
reqwest = {version = "0.11.24", default-features = false, features = [
|
||||
"blocking",
|
||||
"rustls-tls",
|
||||
"cookies",
|
||||
"socks",
|
||||
]}
|
||||
toml = "0.8.10"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "z"
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
||||
strip = true
|
1
rustfmt.toml
Normal file
1
rustfmt.toml
Normal file
|
@ -0,0 +1 @@
|
|||
hard_tabs = true
|
3
sn-client.toml
Normal file
3
sn-client.toml
Normal file
|
@ -0,0 +1,3 @@
|
|||
url = "https://niver.niv.re:443/"
|
||||
proxy = "socks5h://127.0.0.1:9050"
|
||||
language = "fr"
|
71
src/main.rs
Normal file
71
src/main.rs
Normal file
|
@ -0,0 +1,71 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
let value = std::fs::read_to_string("sn-client.toml")
|
||||
.expect("Unable to read configuration file \"sn-client.toml\".")
|
||||
.parse::<toml::Table>()
|
||||
.unwrap();
|
||||
|
||||
let installation = value["url"].as_str().unwrap();
|
||||
let language = match value.contains_key("language") {
|
||||
false => "en",
|
||||
true => match value["language"].as_str().unwrap() {
|
||||
"en" => "en",
|
||||
"fr" => "fr",
|
||||
_ => panic!("Unsupported language."),
|
||||
},
|
||||
};
|
||||
let mut client_builder = reqwest::blocking::Client::builder();
|
||||
if value.contains_key("proxy") {
|
||||
client_builder =
|
||||
client_builder.proxy(reqwest::Proxy::all(value["proxy"].as_str().unwrap()).unwrap())
|
||||
}
|
||||
let client = client_builder
|
||||
.cookie_store(true)
|
||||
.http1_only()
|
||||
.https_only(true)
|
||||
.min_tls_version(reqwest::tls::Version::TLS_1_3)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
request(
|
||||
"auth/login",
|
||||
HashMap::from([
|
||||
("username", "User"),
|
||||
("password", "Password"),
|
||||
]),
|
||||
&client,
|
||||
&installation,
|
||||
&language,
|
||||
);
|
||||
|
||||
request(
|
||||
"auth/password",
|
||||
HashMap::from([
|
||||
("current-password", "Password"),
|
||||
("new-password", "Password"),
|
||||
]),
|
||||
&client,
|
||||
&installation,
|
||||
&language,
|
||||
);
|
||||
}
|
||||
|
||||
fn request(
|
||||
path: &str,
|
||||
args: HashMap<&str, &str>,
|
||||
client: &reqwest::blocking::Client,
|
||||
installation: &str,
|
||||
language: &str,
|
||||
) {
|
||||
let res = client
|
||||
.post(installation.to_owned() + path)
|
||||
.header("Sec-Fetch-Site", "none")
|
||||
.header("Accept-Language", language)
|
||||
.form(&args)
|
||||
.send()
|
||||
.unwrap();
|
||||
|
||||
println!("{:#?}", res);
|
||||
println!("{:#?}", res.text());
|
||||
}
|
Loading…
Add table
Reference in a new issue