added report signature and fixed client_version in server
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -422,6 +422,15 @@ version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
|
||||
|
||||
[[package]]
|
||||
name = "enable-ansi-support"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea7457668b3da8a4b702f3d79e131aa3e81cd7e81cc95fb2d54fce9f182ecc77"
|
||||
dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.35"
|
||||
@@ -1872,6 +1881,7 @@ dependencies = [
|
||||
"colored",
|
||||
"cpal",
|
||||
"display-info",
|
||||
"enable-ansi-support",
|
||||
"mac_address",
|
||||
"num_cpus",
|
||||
"reqwest",
|
||||
|
||||
@@ -9,6 +9,7 @@ clap = { version = "4.6.0", features = ["cargo", "derive"] }
|
||||
colored = "3.1.1"
|
||||
cpal = { version = "0.17.3", optional = true }
|
||||
display-info = { version = "0.5.9", optional = true }
|
||||
enable-ansi-support = "0.3.1"
|
||||
mac_address = "1.1.8"
|
||||
num_cpus = "1.17.0"
|
||||
reqwest = { version = "0.13.2", features = ["blocking", "json"] }
|
||||
|
||||
@@ -46,6 +46,8 @@ pub struct FullReport {
|
||||
pub timestamp: String,
|
||||
pub slimes: Option<HashMap<String, Vec<String>>>,
|
||||
pub benchmark: Option<BenchmarkReport>,
|
||||
pub client_version: String,
|
||||
pub signature: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -70,14 +72,19 @@ async fn submit(
|
||||
let raw_json = serde_json::to_string(&payload)
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
||||
|
||||
sqlx::query("INSERT INTO reports (mac_address, score, timestamp, data) VALUES (?, ?, ?, ?)")
|
||||
.bind(payload.mac_address)
|
||||
.bind(score as i64)
|
||||
.bind(payload.timestamp)
|
||||
.bind(raw_json)
|
||||
.execute(&state.db)
|
||||
.await
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
||||
sqlx::query(
|
||||
"INSERT INTO reports (mac_address, score, timestamp, client_version, signature, data)
|
||||
VALUES (?, ?, ?, ?, ?, ?)",
|
||||
)
|
||||
.bind(&payload.mac_address)
|
||||
.bind(score as i64)
|
||||
.bind(&payload.timestamp)
|
||||
.bind(&payload.client_version)
|
||||
.bind(&payload.signature)
|
||||
.bind(raw_json)
|
||||
.execute(&state.db)
|
||||
.await
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
||||
|
||||
Ok(StatusCode::CREATED)
|
||||
}
|
||||
@@ -142,6 +149,8 @@ async fn main() -> anyhow::Result<()> {
|
||||
mac_address TEXT NOT NULL,
|
||||
score INTEGER NOT NULL,
|
||||
timestamp TEXT NOT NULL,
|
||||
client_version TEXT NOT NULL,
|
||||
signature TEXT,
|
||||
data TEXT NOT NULL
|
||||
);",
|
||||
)
|
||||
|
||||
26
src/main.rs
26
src/main.rs
@@ -58,6 +58,7 @@ struct FullReport {
|
||||
slimes: Option<HashMap<String, Vec<String>>>,
|
||||
benchmark: Option<BenchmarkReport>,
|
||||
client_version: String,
|
||||
signature: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -69,6 +70,9 @@ struct BenchmarkReport {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(windows)]
|
||||
let _ = enable_ansi_support::enable_ansi_support();
|
||||
|
||||
let cli = Cli::parse();
|
||||
let mut report = FullReport {
|
||||
mac_address: get_mac_address()
|
||||
@@ -80,6 +84,7 @@ fn main() {
|
||||
slimes: None,
|
||||
benchmark: None,
|
||||
client_version: crate_version!().to_string(),
|
||||
signature: String::new(),
|
||||
};
|
||||
|
||||
vprintln!(
|
||||
@@ -152,18 +157,33 @@ fn main() {
|
||||
}
|
||||
|
||||
if !cli.offline {
|
||||
let json_payload = serde_json::to_string_pretty(&report).unwrap();
|
||||
vprintln!(cli.verbose, "Generated JSON report: {:?}", &json_payload);
|
||||
|
||||
println!();
|
||||
if !confirm_upload() {
|
||||
return;
|
||||
}
|
||||
|
||||
report.signature = sign_upload();
|
||||
|
||||
let json_payload = serde_json::to_string_pretty(&report).unwrap();
|
||||
vprintln!(cli.verbose, "Generated JSON report: {:?}", &json_payload);
|
||||
|
||||
send_to_server(&cli.server_url, &report);
|
||||
}
|
||||
}
|
||||
|
||||
fn sign_upload() -> String {
|
||||
print!("Please sign your report, it should allow to identify it (or leave empty): ");
|
||||
io::stdout().flush().unwrap();
|
||||
|
||||
let mut input = String::new();
|
||||
io::stdin()
|
||||
.read_line(&mut input)
|
||||
.expect("Failed to read line");
|
||||
let input = input.trim().to_string();
|
||||
|
||||
input
|
||||
}
|
||||
|
||||
fn confirm_upload() -> bool {
|
||||
print!("Send data to leaderboard server? [Y/n] ");
|
||||
io::stdout().flush().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user