Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79ecc100d3 |
@@ -122,35 +122,45 @@ fn summarize_log(log: &str) -> Vec<String> {
|
|||||||
|
|
||||||
/// VNish: unlock -> bearer -> the full miner log.
|
/// VNish: unlock -> bearer -> the full miner log.
|
||||||
fn fetch_vnish_log(ip: &str, pass: &str) -> Result<String, String> {
|
fn fetch_vnish_log(ip: &str, pass: &str) -> Result<String, String> {
|
||||||
let unlock = curl(&[
|
// The password goes in the POST body read from stdin (-d @-), never on argv,
|
||||||
"-s",
|
// and is JSON-encoded by serde so it is both un-leakable and correctly escaped
|
||||||
"--connect-timeout",
|
// (round 18 #12).
|
||||||
"5",
|
let body = serde_json::json!({ "pw": pass }).to_string();
|
||||||
"--max-time",
|
let unlock = curl(
|
||||||
"9",
|
&[
|
||||||
"-X",
|
"-s",
|
||||||
"POST",
|
"--connect-timeout",
|
||||||
"-H",
|
"5",
|
||||||
"Content-Type: application/json",
|
"--max-time",
|
||||||
"-d",
|
"9",
|
||||||
&format!("{{\"pw\":\"{pass}\"}}"),
|
"-X",
|
||||||
&format!("http://{ip}/api/v1/unlock"),
|
"POST",
|
||||||
])?;
|
"-H",
|
||||||
|
"Content-Type: application/json",
|
||||||
|
"-d",
|
||||||
|
"@-",
|
||||||
|
&format!("http://{ip}/api/v1/unlock"),
|
||||||
|
],
|
||||||
|
Some(body.as_bytes()),
|
||||||
|
)?;
|
||||||
let token = serde_json::from_str::<serde_json::Value>(&unlock)
|
let token = serde_json::from_str::<serde_json::Value>(&unlock)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|v| v.get("token").and_then(|t| t.as_str()).map(str::to_string))
|
.and_then(|v| v.get("token").and_then(|t| t.as_str()).map(str::to_string))
|
||||||
.filter(|t| !t.is_empty())
|
.filter(|t| !t.is_empty())
|
||||||
.ok_or_else(|| "VNish unlock rejected (check the VNish password in scan credentials)".to_string())?;
|
.ok_or_else(|| "VNish unlock rejected (check the VNish password in scan credentials)".to_string())?;
|
||||||
let log = curl(&[
|
let log = curl(
|
||||||
"-s",
|
&[
|
||||||
"--connect-timeout",
|
"-s",
|
||||||
"5",
|
"--connect-timeout",
|
||||||
"--max-time",
|
"5",
|
||||||
"12",
|
"--max-time",
|
||||||
"-H",
|
"12",
|
||||||
&format!("Authorization: Bearer {token}"),
|
"-H",
|
||||||
&format!("http://{ip}/api/v1/logs/miner"),
|
&format!("Authorization: Bearer {token}"),
|
||||||
])?;
|
&format!("http://{ip}/api/v1/logs/miner"),
|
||||||
|
],
|
||||||
|
None,
|
||||||
|
)?;
|
||||||
if log.trim().is_empty() {
|
if log.trim().is_empty() {
|
||||||
return Err("VNish returned an empty log".to_string());
|
return Err("VNish returned an empty log".to_string());
|
||||||
}
|
}
|
||||||
@@ -159,17 +169,23 @@ fn fetch_vnish_log(ip: &str, pass: &str) -> Result<String, String> {
|
|||||||
|
|
||||||
/// Stock Antminer web log (digest auth). Absent on older models (404).
|
/// Stock Antminer web log (digest auth). Absent on older models (404).
|
||||||
fn fetch_antminer_log(ip: &str, user: &str, pass: &str) -> Result<String, String> {
|
fn fetch_antminer_log(ip: &str, user: &str, pass: &str) -> Result<String, String> {
|
||||||
let body = curl(&[
|
// Credentials go through a curl config on stdin (-K -), never on argv, so they
|
||||||
"-s",
|
// can't be read from the process list (round 18 #12).
|
||||||
"--digest",
|
let config = format!("user = \"{}\"\n", curl_config_quote(&format!("{user}:{pass}")));
|
||||||
"-u",
|
let body = curl(
|
||||||
&format!("{user}:{pass}"),
|
&[
|
||||||
"--connect-timeout",
|
"-s",
|
||||||
"5",
|
"--digest",
|
||||||
"--max-time",
|
"--connect-timeout",
|
||||||
"12",
|
"5",
|
||||||
&format!("http://{ip}/cgi-bin/log.cgi"),
|
"--max-time",
|
||||||
])?;
|
"12",
|
||||||
|
"-K",
|
||||||
|
"-",
|
||||||
|
&format!("http://{ip}/cgi-bin/log.cgi"),
|
||||||
|
],
|
||||||
|
Some(config.as_bytes()),
|
||||||
|
)?;
|
||||||
if body.contains("404 - Not Found") || body.trim().is_empty() {
|
if body.contains("404 - Not Found") || body.trim().is_empty() {
|
||||||
return Err("this firmware does not expose a log over its web API".to_string());
|
return Err("this firmware does not expose a log over its web API".to_string());
|
||||||
}
|
}
|
||||||
@@ -186,13 +202,21 @@ fn fetch_whatsminer_errors(ip: &str) -> Result<String, String> {
|
|||||||
/// Run curl and return stdout, with a hard wall-clock cap. stdout is drained on a
|
/// Run curl and return stdout, with a hard wall-clock cap. stdout is drained on a
|
||||||
/// separate thread so a large log (hundreds of KB) never deadlocks on a full pipe
|
/// separate thread so a large log (hundreds of KB) never deadlocks on a full pipe
|
||||||
/// -- the reason a naive "wait then read" times out on the VNish log.
|
/// -- the reason a naive "wait then read" times out on the VNish log.
|
||||||
fn curl(args: &[&str]) -> Result<String, String> {
|
fn curl(args: &[&str], stdin_data: Option<&[u8]>) -> Result<String, String> {
|
||||||
use std::io::Read;
|
use std::io::{Read, Write};
|
||||||
let mut cmd = Command::new("curl");
|
let mut cmd = Command::new("curl");
|
||||||
cmd.args(args);
|
cmd.args(args);
|
||||||
cmd.stdout(std::process::Stdio::piped());
|
cmd.stdout(std::process::Stdio::piped());
|
||||||
cmd.stderr(std::process::Stdio::null());
|
cmd.stderr(std::process::Stdio::null());
|
||||||
|
if stdin_data.is_some() {
|
||||||
|
cmd.stdin(std::process::Stdio::piped());
|
||||||
|
}
|
||||||
let mut child = cmd.spawn().map_err(|e| format!("spawn curl: {e}"))?;
|
let mut child = cmd.spawn().map_err(|e| format!("spawn curl: {e}"))?;
|
||||||
|
if let Some(data) = stdin_data {
|
||||||
|
if let Some(mut si) = child.stdin.take() {
|
||||||
|
let _ = si.write_all(data);
|
||||||
|
} // dropping `si` closes the pipe so curl stops reading the config/body
|
||||||
|
}
|
||||||
let mut stdout = child.stdout.take().ok_or("no curl stdout")?;
|
let mut stdout = child.stdout.take().ok_or("no curl stdout")?;
|
||||||
let reader = std::thread::spawn(move || {
|
let reader = std::thread::spawn(move || {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
@@ -208,6 +232,7 @@ fn curl(args: &[&str]) -> Result<String, String> {
|
|||||||
None => {
|
None => {
|
||||||
if start.elapsed() >= timeout {
|
if start.elapsed() >= timeout {
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
|
let _ = child.wait(); // reap so we never leave a zombie (round 18 #12)
|
||||||
timed_out = true;
|
timed_out = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -222,6 +247,11 @@ fn curl(args: &[&str]) -> Result<String, String> {
|
|||||||
Ok(String::from_utf8_lossy(&buf).into_owned())
|
Ok(String::from_utf8_lossy(&buf).into_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Escape a value for a curl `--config` file (double-quoted string).
|
||||||
|
fn curl_config_quote(s: &str) -> String {
|
||||||
|
s.replace('\\', "\\\\").replace('"', "\\\"")
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -110,10 +110,13 @@ fn restore_one(t: &RestoreTarget, vnish_pass: &str, ssh_user: &str, ssh_pass: &s
|
|||||||
|
|
||||||
/// VNish: unlock -> bearer -> firmware/remove (self-restores + reboots ~3 s).
|
/// VNish: unlock -> bearer -> firmware/remove (self-restores + reboots ~3 s).
|
||||||
fn restore_vnish(ip: &str, pass: &str) -> (bool, String) {
|
fn restore_vnish(ip: &str, pass: &str) -> (bool, String) {
|
||||||
|
// serde-encode the body so a password with a quote/backslash can't break or
|
||||||
|
// inject into the JSON (round 18 #12).
|
||||||
|
let body = serde_json::json!({ "pw": pass }).to_string();
|
||||||
let unlock = match curl(&[
|
let unlock = match curl(&[
|
||||||
"-s", "--connect-timeout", "5", "--max-time", "9",
|
"-s", "--connect-timeout", "5", "--max-time", "9",
|
||||||
"-X", "POST", "-H", "Content-Type: application/json",
|
"-X", "POST", "-H", "Content-Type: application/json",
|
||||||
"-d", &format!("{{\"pw\":\"{pass}\"}}"),
|
"-d", &body,
|
||||||
&format!("http://{ip}/api/v1/unlock"),
|
&format!("http://{ip}/api/v1/unlock"),
|
||||||
]) {
|
]) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
@@ -155,7 +158,9 @@ fn restore_luxos(ip: &str) -> (bool, String) {
|
|||||||
let Some(session) = session.filter(|s| !s.is_empty()) else {
|
let Some(session) = session.filter(|s| !s.is_empty()) else {
|
||||||
return (false, format!("no SessionID in logon response: {}", logon.trim()));
|
return (false, format!("no SessionID in logon response: {}", logon.trim()));
|
||||||
};
|
};
|
||||||
let cmd = format!("{{\"command\":\"uninstallluxos\",\"parameter\":\"{session}\"}}");
|
// serde-encode so the miner-supplied SessionID can't break or inject into the
|
||||||
|
// JSON-RPC command (round 18 #12).
|
||||||
|
let cmd = serde_json::json!({ "command": "uninstallluxos", "parameter": session }).to_string();
|
||||||
match lux_rpc(ip, &cmd) {
|
match lux_rpc(ip, &cmd) {
|
||||||
// Code 350 "Uninstalling LuxOS"; the miner reboots + reverts in background.
|
// Code 350 "Uninstalling LuxOS"; the miner reboots + reverts in background.
|
||||||
Ok(resp) if resp.contains("350") || resp.to_lowercase().contains("uninstall") => {
|
Ok(resp) if resp.contains("350") || resp.to_lowercase().contains("uninstall") => {
|
||||||
|
|||||||
@@ -1229,12 +1229,16 @@ impl App {
|
|||||||
|
|
||||||
pub fn fill_rows(&mut self) {
|
pub fn fill_rows(&mut self) {
|
||||||
let Some(t) = self.table else { return };
|
let Some(t) = self.table else { return };
|
||||||
|
// Compute the shown columns once and reuse it everywhere below (with
|
||||||
|
// auto-hide-empty on, table_columns() scans every cell of every row, so it
|
||||||
|
// must not be called per section of this function -- round 18 #12).
|
||||||
|
let cols = self.table_columns();
|
||||||
// If the set of shown columns has changed since the widget was built (only
|
// If the set of shown columns has changed since the widget was built (only
|
||||||
// possible with auto-hide-empty on, when a scan makes a column non-empty),
|
// possible with auto-hide-empty on, when a scan makes a column non-empty),
|
||||||
// the widget's columns are stale: rendering now would misalign cells and
|
// the widget's columns are stale: rendering now would misalign cells and
|
||||||
// header clicks. Rebuild instead -- deferred, because rebuild_table
|
// header clicks. Rebuild instead -- deferred, because rebuild_table
|
||||||
// destroys this control (round 18 #12).
|
// destroys this control (round 18 #12).
|
||||||
if self.table_columns() != self.built_columns {
|
if cols != self.built_columns {
|
||||||
wx_rs::call_after(DEFER_TABLE);
|
wx_rs::call_after(DEFER_TABLE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1243,7 +1247,6 @@ impl App {
|
|||||||
let top = t.dvlc_get_top_row();
|
let top = t.dvlc_get_top_row();
|
||||||
t.dvlc_clear();
|
t.dvlc_clear();
|
||||||
self.view_idx = self.view.view(&self.rows);
|
self.view_idx = self.view.view(&self.rows);
|
||||||
let cols = self.table_columns();
|
|
||||||
for &ri in &self.view_idx {
|
for &ri in &self.view_idx {
|
||||||
let r = &self.rows[ri];
|
let r = &self.rows[ri];
|
||||||
let cells: Vec<String> = cols.iter().map(|c| c.cell(r)).collect();
|
let cells: Vec<String> = cols.iter().map(|c| c.cell(r)).collect();
|
||||||
|
|||||||
Reference in New Issue
Block a user