This commit is contained in:
Miraty 2024-02-14 23:03:41 +01:00
commit 50f72e1e07
5 changed files with 96 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

20
Cargo.toml Normal file
View 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
View file

@ -0,0 +1 @@
hard_tabs = true

3
sn-client.toml Normal file
View 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
View 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());
}