|
@@ -3,13 +3,15 @@
|
|
|
|
|
|
|
|
use crate::actors::StationMsg;
|
|
use crate::actors::StationMsg;
|
|
|
use crate::json::JsonVal;
|
|
use crate::json::JsonVal;
|
|
|
|
|
+use crate::lib;
|
|
|
use crate::results::now_ms;
|
|
use crate::results::now_ms;
|
|
|
use std::fs;
|
|
use std::fs;
|
|
|
use std::io::ErrorKind;
|
|
use std::io::ErrorKind;
|
|
|
use std::net::{SocketAddr, TcpStream, UdpSocket};
|
|
use std::net::{SocketAddr, TcpStream, UdpSocket};
|
|
|
use std::path::{Path, PathBuf};
|
|
use std::path::{Path, PathBuf};
|
|
|
use std::process::Command;
|
|
use std::process::Command;
|
|
|
-use std::sync::Arc;
|
|
|
|
|
|
|
+use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
|
+use std::sync::{mpsc, Arc};
|
|
|
use std::thread;
|
|
use std::thread;
|
|
|
use std::time::Duration;
|
|
use std::time::Duration;
|
|
|
|
|
|
|
@@ -535,11 +537,92 @@ pub fn apply_pxe_configuration(
|
|
|
Ok(build_pxe_snapshot(pxe_state))
|
|
Ok(build_pxe_snapshot(pxe_state))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// Decode UTF-16LE (MemTest86 118.efi default `FF FE`), UTF-16BE (`FE FF`), UTF-8 BOM, or UTF-8 HTML payloads.
|
|
|
|
|
+pub fn decode_html_report_bytes(raw: &[u8]) -> String {
|
|
|
|
|
+ if raw.len() >= 2 && raw[0] == 0xFF && raw[1] == 0xFE {
|
|
|
|
|
+ let mut units = Vec::with_capacity((raw.len() - 2) / 2);
|
|
|
|
|
+ for chunk in raw[2..].chunks_exact(2) {
|
|
|
|
|
+ units.push(u16::from_le_bytes([chunk[0], chunk[1]]));
|
|
|
|
|
+ }
|
|
|
|
|
+ return String::from_utf16_lossy(&units);
|
|
|
|
|
+ }
|
|
|
|
|
+ if raw.len() >= 2 && raw[0] == 0xFE && raw[1] == 0xFF {
|
|
|
|
|
+ let mut units = Vec::with_capacity((raw.len() - 2) / 2);
|
|
|
|
|
+ for chunk in raw[2..].chunks_exact(2) {
|
|
|
|
|
+ units.push(u16::from_be_bytes([chunk[0], chunk[1]]));
|
|
|
|
|
+ }
|
|
|
|
|
+ return String::from_utf16_lossy(&units);
|
|
|
|
|
+ }
|
|
|
|
|
+ if raw.len() >= 3 && raw[0] == 0xEF && raw[1] == 0xBB && raw[2] == 0xBF {
|
|
|
|
|
+ return String::from_utf8_lossy(&raw[3..]).into_owned();
|
|
|
|
|
+ }
|
|
|
|
|
+ let sample_len = raw.len().min(256);
|
|
|
|
|
+ if sample_len >= 8 {
|
|
|
|
|
+ let odd_zeros = raw[..sample_len]
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .skip(1)
|
|
|
|
|
+ .step_by(2)
|
|
|
|
|
+ .filter(|&&b| b == 0)
|
|
|
|
|
+ .count();
|
|
|
|
|
+ let even_zeros = raw[..sample_len]
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .step_by(2)
|
|
|
|
|
+ .filter(|&&b| b == 0)
|
|
|
|
|
+ .count();
|
|
|
|
|
+ if odd_zeros * 3 > sample_len && even_zeros * 10 < sample_len {
|
|
|
|
|
+ let mut units = Vec::with_capacity(raw.len() / 2);
|
|
|
|
|
+ for chunk in raw.chunks_exact(2) {
|
|
|
|
|
+ units.push(u16::from_le_bytes([chunk[0], chunk[1]]));
|
|
|
|
|
+ }
|
|
|
|
|
+ return String::from_utf16_lossy(&units);
|
|
|
|
|
+ }
|
|
|
|
|
+ if even_zeros * 3 > sample_len && odd_zeros * 10 < sample_len {
|
|
|
|
|
+ let mut units = Vec::with_capacity(raw.len() / 2);
|
|
|
|
|
+ for chunk in raw.chunks_exact(2) {
|
|
|
|
|
+ units.push(u16::from_be_bytes([chunk[0], chunk[1]]));
|
|
|
|
|
+ }
|
|
|
|
|
+ return String::from_utf16_lossy(&units);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ String::from_utf8_lossy(raw).into_owned()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+pub fn looks_like_html_payload(lower_name: &str, raw: &[u8]) -> bool {
|
|
|
|
|
+ if lower_name.ends_with(".html") || lower_name.ends_with(".htm") {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ let prefix_len = raw.len().min(2048);
|
|
|
|
|
+ let head = decode_html_report_bytes(&raw[..prefix_len]).to_ascii_lowercase();
|
|
|
|
|
+ head.contains("<html") || head.contains("<!doctype html")
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+fn strip_html_block_tag(src: &str, open_tag: &str, close_tag: &str) -> String {
|
|
|
|
|
+ let lower = src.to_ascii_lowercase();
|
|
|
|
|
+ let mut out = String::with_capacity(src.len());
|
|
|
|
|
+ let mut pos = 0usize;
|
|
|
|
|
+ while let Some(rel_start) = lower[pos..].find(open_tag) {
|
|
|
|
|
+ let abs_start = pos + rel_start;
|
|
|
|
|
+ out.push_str(&src[pos..abs_start]);
|
|
|
|
|
+ if let Some(rel_end) = lower[abs_start..].find(close_tag) {
|
|
|
|
|
+ pos = abs_start + rel_end + close_tag.len();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ pos = src.len();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if pos < src.len() {
|
|
|
|
|
+ out.push_str(&src[pos..]);
|
|
|
|
|
+ }
|
|
|
|
|
+ out
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
fn strip_html_tags_to_text(html: &str) -> String {
|
|
fn strip_html_tags_to_text(html: &str) -> String {
|
|
|
- let mut raw_clean = String::with_capacity(html.len());
|
|
|
|
|
|
|
+ let no_style = strip_html_block_tag(html, "<style", "</style>");
|
|
|
|
|
+ let no_script = strip_html_block_tag(&no_style, "<script", "</script>");
|
|
|
|
|
+ let mut raw_clean = String::with_capacity(no_script.len());
|
|
|
let mut in_tag = false;
|
|
let mut in_tag = false;
|
|
|
let mut prev_space = false;
|
|
let mut prev_space = false;
|
|
|
- for ch in html.chars() {
|
|
|
|
|
|
|
+ for ch in no_script.chars() {
|
|
|
if ch == '<' {
|
|
if ch == '<' {
|
|
|
in_tag = true;
|
|
in_tag = true;
|
|
|
if !prev_space {
|
|
if !prev_space {
|
|
@@ -605,32 +688,134 @@ fn extract_token_after_labels(orig_txt: &str, lower_txt: &str, labels: &[&str])
|
|
|
String::new()
|
|
String::new()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+fn parse_n_ch_slot_coords(line: &str) -> (Option<i64>, Option<i64>, Option<i64>) {
|
|
|
|
|
+ let bytes = line.as_bytes();
|
|
|
|
|
+ for i in 0..bytes.len() {
|
|
|
|
|
+ if (bytes[i] == b'N' || bytes[i] == b'n')
|
|
|
|
|
+ && i + 4 < bytes.len()
|
|
|
|
|
+ && (bytes[i + 1] == b'0' || bytes[i + 1] == b'1')
|
|
|
|
|
+ && bytes[i + 2] == b'-'
|
|
|
|
|
+ && bytes[i + 3].is_ascii_digit()
|
|
|
|
|
+ {
|
|
|
|
|
+ let cpu = (bytes[i + 1] - b'0') as i64;
|
|
|
|
|
+ let rest = &line[i + 3..];
|
|
|
|
|
+ let mut parts = rest.split('-');
|
|
|
|
|
+ if let (Some(ch_s), Some(sl_s)) = (parts.next(), parts.next()) {
|
|
|
|
|
+ let ch_digits: String = ch_s.chars().take_while(|c| c.is_ascii_digit()).collect();
|
|
|
|
|
+ let sl_digits: String = sl_s.chars().take_while(|c| c.is_ascii_digit()).collect();
|
|
|
|
|
+ if let Ok(ch) = ch_digits.parse::<i64>() {
|
|
|
|
|
+ if (0..=11).contains(&ch) {
|
|
|
|
|
+ let sl = sl_digits.parse::<i64>().ok().filter(|v| (0..=1).contains(v));
|
|
|
|
|
+ return (Some(cpu), Some(ch), sl);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ let upper = line.to_ascii_uppercase();
|
|
|
|
|
+ for cpu in 0..=1i64 {
|
|
|
|
|
+ for (ch_idx, ch_ltr) in ('A'..='L').enumerate() {
|
|
|
|
|
+ let tag = format!("CPU{}_DIMM_{}", cpu, ch_ltr);
|
|
|
|
|
+ if upper.contains(&tag) {
|
|
|
|
|
+ return (Some(cpu), Some(ch_idx as i64), Some(0));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ (None, None, None)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+fn parse_mt86_html_error_rows(body_src: &str) -> Vec<JsonVal> {
|
|
|
|
|
+ let mut out = Vec::new();
|
|
|
|
|
+ let lower = body_src.to_ascii_lowercase();
|
|
|
|
|
+ let mut pos = 0usize;
|
|
|
|
|
+ while let Some(rel_tr) = lower[pos..].find("<tr") {
|
|
|
|
|
+ let abs_tr = pos + rel_tr;
|
|
|
|
|
+ let end_tr = lower[abs_tr..]
|
|
|
|
|
+ .find("</tr>")
|
|
|
|
|
+ .map(|e| abs_tr + e + 5)
|
|
|
|
|
+ .unwrap_or(body_src.len());
|
|
|
|
|
+ let row_html = &body_src[abs_tr..end_tr];
|
|
|
|
|
+ let row_lower = &lower[abs_tr..end_tr];
|
|
|
|
|
+ let row_txt = strip_html_tags_to_text(row_html);
|
|
|
|
|
+ let row_txt_lower = row_txt.to_ascii_lowercase();
|
|
|
|
|
+ let is_err_detail = row_txt_lower.contains("[ecc errors]")
|
|
|
|
|
+ || row_txt_lower.contains("[mem error")
|
|
|
|
|
+ || row_txt_lower.contains("[data error]")
|
|
|
|
|
+ || row_txt_lower.contains("channel-slot:")
|
|
|
|
|
+ || row_txt_lower.contains("channel/slot:")
|
|
|
|
|
+ || (row_lower.contains("class=\"fail\"") && row_txt_lower.contains("dimm"));
|
|
|
|
|
+ if is_err_detail && !row_txt.is_empty() && out.len() < 100 {
|
|
|
|
|
+ let (cpu, ch, dimm) = parse_n_ch_slot_coords(&row_txt);
|
|
|
|
|
+ let mut addr_str = String::new();
|
|
|
|
|
+ if let Some(ap) = row_txt_lower.find("address:") {
|
|
|
|
|
+ let raw_tok = row_txt[ap + 8..]
|
|
|
|
|
+ .trim_start()
|
|
|
|
|
+ .split(|c: char| c == ',' || c.is_whitespace())
|
|
|
|
|
+ .next()
|
|
|
|
|
+ .unwrap_or("")
|
|
|
|
|
+ .trim_start_matches("0x")
|
|
|
|
|
+ .trim_start_matches("0X");
|
|
|
|
|
+ if !raw_tok.is_empty() && raw_tok.chars().all(|c| c.is_ascii_hexdigit()) {
|
|
|
|
|
+ addr_str = format!("0x{}", raw_tok.to_ascii_uppercase());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ let mut entry = JsonVal::obj();
|
|
|
|
|
+ entry.set("message", JsonVal::Str(row_txt));
|
|
|
|
|
+ if let Some(c) = cpu {
|
|
|
|
|
+ entry.set("cpu", JsonVal::Num(c as f64));
|
|
|
|
|
+ }
|
|
|
|
|
+ if let Some(channel) = ch {
|
|
|
|
|
+ entry.set("channel", JsonVal::Num(channel as f64));
|
|
|
|
|
+ }
|
|
|
|
|
+ if let Some(dm) = dimm {
|
|
|
|
|
+ entry.set("dimm", JsonVal::Num(dm as f64));
|
|
|
|
|
+ }
|
|
|
|
|
+ if !addr_str.is_empty() {
|
|
|
|
|
+ entry.set("address", JsonVal::Str(addr_str));
|
|
|
|
|
+ }
|
|
|
|
|
+ out.push(entry);
|
|
|
|
|
+ }
|
|
|
|
|
+ pos = end_tr;
|
|
|
|
|
+ }
|
|
|
|
|
+ out
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
pub fn parse_mt86_html_report(filename: &str, html: &str) -> JsonVal {
|
|
pub fn parse_mt86_html_report(filename: &str, html: &str) -> JsonVal {
|
|
|
- let clean_txt = strip_html_tags_to_text(html);
|
|
|
|
|
let lower_html = html.to_ascii_lowercase();
|
|
let lower_html = html.to_ascii_lowercase();
|
|
|
|
|
+ let body_start = lower_html.find("<body").unwrap_or(0);
|
|
|
|
|
+ let body_src = &html[body_start..];
|
|
|
|
|
+ let body_lower = &lower_html[body_start..];
|
|
|
|
|
+ let clean_txt = strip_html_tags_to_text(body_src);
|
|
|
let lower_txt = clean_txt.to_ascii_lowercase();
|
|
let lower_txt = clean_txt.to_ascii_lowercase();
|
|
|
|
|
|
|
|
- let errors = extract_i64_after_labels(
|
|
|
|
|
|
|
+ let ecc_correctable = extract_i64_after_labels(&lower_txt, &["ecc correctable errors"]);
|
|
|
|
|
+ let ecc_uncorrectable = extract_i64_after_labels(&lower_txt, &["ecc uncorrectable errors"]);
|
|
|
|
|
+ let total_errors = extract_i64_after_labels(
|
|
|
&lower_txt,
|
|
&lower_txt,
|
|
|
- &["total errors", "error count", "errors:", "errors"],
|
|
|
|
|
|
|
+ &["total errors", "error count", "errors:"],
|
|
|
)
|
|
)
|
|
|
.unwrap_or_else(|| {
|
|
.unwrap_or_else(|| {
|
|
|
- // Fallback: "<N> errors"
|
|
|
|
|
let words: Vec<&str> = lower_txt.split_whitespace().collect();
|
|
let words: Vec<&str> = lower_txt.split_whitespace().collect();
|
|
|
for w in words.windows(2) {
|
|
for w in words.windows(2) {
|
|
|
- if w[1].starts_with("error") {
|
|
|
|
|
- if let Ok(n) = w[0].trim_matches(|c: char| !c.is_ascii_digit()).parse::<i64>() {
|
|
|
|
|
|
|
+ if w[1].starts_with("error") && w[0].chars().all(|c| c.is_ascii_digit()) {
|
|
|
|
|
+ if let Ok(n) = w[0].parse::<i64>() {
|
|
|
return n;
|
|
return n;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
0
|
|
0
|
|
|
});
|
|
});
|
|
|
|
|
+ let error_details = parse_mt86_html_error_rows(body_src);
|
|
|
|
|
+ let ecc_sum = ecc_correctable.unwrap_or(0).saturating_add(ecc_uncorrectable.unwrap_or(0));
|
|
|
|
|
+ let mut errors = total_errors.max(ecc_sum);
|
|
|
|
|
+ if errors == 0 && !error_details.is_empty() {
|
|
|
|
|
+ errors = error_details.len() as i64;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
let tests_passed = extract_token_after_labels(
|
|
let tests_passed = extract_token_after_labels(
|
|
|
&clean_txt,
|
|
&clean_txt,
|
|
|
&lower_txt,
|
|
&lower_txt,
|
|
|
- &["tests passed", "tests completed"],
|
|
|
|
|
|
|
+ &["# tests passed", "tests passed", "tests completed"],
|
|
|
);
|
|
);
|
|
|
let elapsed = extract_token_after_labels(
|
|
let elapsed = extract_token_after_labels(
|
|
|
&clean_txt,
|
|
&clean_txt,
|
|
@@ -638,21 +823,26 @@ pub fn parse_mt86_html_report(filename: &str, html: &str) -> JsonVal {
|
|
|
&["elapsed time", "test time", "elapsed"],
|
|
&["elapsed time", "test time", "elapsed"],
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- let has_fail_marker = lower_html.contains("failstamp")
|
|
|
|
|
|
|
+ let has_incomplete_pass = lower_txt.contains("incomplete pass");
|
|
|
|
|
+ let has_fail_marker = body_lower.contains("class=\"failstamp\"")
|
|
|
|
|
+ || body_lower.contains("class=\"fail\"")
|
|
|
|| lower_txt.contains("result: fail")
|
|
|| lower_txt.contains("result: fail")
|
|
|
|| lower_txt.contains("result fail")
|
|
|| lower_txt.contains("result fail")
|
|
|
- || lower_txt.contains("result: incomplete")
|
|
|
|
|
|| lower_txt.contains("test result fail")
|
|
|| lower_txt.contains("test result fail")
|
|
|
|| lower_txt.contains("test result: fail")
|
|
|| lower_txt.contains("test result: fail")
|
|
|
- || lower_txt.contains("incomplete")
|
|
|
|
|
- || errors > 0;
|
|
|
|
|
|
|
+ || lower_txt.contains("incomplete fail")
|
|
|
|
|
+ || (lower_txt.contains("result: incomplete") && !has_incomplete_pass)
|
|
|
|
|
+ || errors > 0
|
|
|
|
|
+ || !error_details.is_empty();
|
|
|
let has_pass_marker = !has_fail_marker
|
|
let has_pass_marker = !has_fail_marker
|
|
|
- && (lower_html.contains("passstamp")
|
|
|
|
|
|
|
+ && (body_lower.contains("class=\"passstamp\"")
|
|
|
|
|
+ || body_lower.contains("class=\"pass\"")
|
|
|
|| lower_txt.contains("result: pass")
|
|
|| lower_txt.contains("result: pass")
|
|
|
|| lower_txt.contains("result pass")
|
|
|| lower_txt.contains("result pass")
|
|
|
|| lower_txt.contains("test result pass")
|
|
|| lower_txt.contains("test result pass")
|
|
|
|| lower_txt.contains("test result: pass")
|
|
|| lower_txt.contains("test result: pass")
|
|
|
|| lower_txt.contains("pass complete")
|
|
|| lower_txt.contains("pass complete")
|
|
|
|
|
+ || has_incomplete_pass
|
|
|
|| lower_txt.contains("0 errors")
|
|
|| lower_txt.contains("0 errors")
|
|
|
|| lower_txt.contains("total errors 0"));
|
|
|| lower_txt.contains("total errors 0"));
|
|
|
|
|
|
|
@@ -668,6 +858,15 @@ pub fn parse_mt86_html_report(filename: &str, html: &str) -> JsonVal {
|
|
|
obj.set("filename", JsonVal::Str(filename.to_string()));
|
|
obj.set("filename", JsonVal::Str(filename.to_string()));
|
|
|
obj.set("verdict", JsonVal::Str(verdict.to_string()));
|
|
obj.set("verdict", JsonVal::Str(verdict.to_string()));
|
|
|
obj.set("errors", JsonVal::Num(errors as f64));
|
|
obj.set("errors", JsonVal::Num(errors as f64));
|
|
|
|
|
+ if let Some(c) = ecc_correctable {
|
|
|
|
|
+ obj.set("ecc_correctable_errors", JsonVal::Num(c as f64));
|
|
|
|
|
+ }
|
|
|
|
|
+ if let Some(u) = ecc_uncorrectable {
|
|
|
|
|
+ obj.set("ecc_uncorrectable_errors", JsonVal::Num(u as f64));
|
|
|
|
|
+ }
|
|
|
|
|
+ if !error_details.is_empty() {
|
|
|
|
|
+ obj.set("error_details", JsonVal::Arr(error_details));
|
|
|
|
|
+ }
|
|
|
if !tests_passed.is_empty() {
|
|
if !tests_passed.is_empty() {
|
|
|
obj.set("tests_passed", JsonVal::Str(tests_passed));
|
|
obj.set("tests_passed", JsonVal::Str(tests_passed));
|
|
|
}
|
|
}
|
|
@@ -1050,17 +1249,11 @@ fn handle_tftp_wrq(
|
|
|
let _ = fs::rename(&tmp_path, &dest_path);
|
|
let _ = fs::rename(&tmp_path, &dest_path);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let looks_like_html = lower_name.ends_with(".html")
|
|
|
|
|
- || lower_name.ends_with(".htm")
|
|
|
|
|
- || payload
|
|
|
|
|
- .windows(5)
|
|
|
|
|
- .take(512)
|
|
|
|
|
- .any(|w| w.eq_ignore_ascii_case(b"<html"));
|
|
|
|
|
- if !looks_like_html {
|
|
|
|
|
|
|
+ if !looks_like_html_payload(&lower_name, &payload) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let html_str = String::from_utf8_lossy(&payload).to_string();
|
|
|
|
|
|
|
+ let html_str = decode_html_report_bytes(&payload);
|
|
|
let report = parse_mt86_html_report(&clean_name, &html_str);
|
|
let report = parse_mt86_html_report(&clean_name, &html_str);
|
|
|
|
|
|
|
|
if let Ok(mut pxe_st) = hub.pxe_state.write() {
|
|
if let Ok(mut pxe_st) = hub.pxe_state.write() {
|
|
@@ -1117,12 +1310,122 @@ fn handle_tftp_wrq(
|
|
|
full_path: full_path_str.clone(),
|
|
full_path: full_path_str.clone(),
|
|
|
force: true,
|
|
force: true,
|
|
|
});
|
|
});
|
|
|
|
|
+ if handle.event_fd >= 0 {
|
|
|
|
|
+ unsafe {
|
|
|
|
|
+ lib::stl_eventfd_notify(handle.event_fd);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
hub.refresh_and_broadcast_qt_state();
|
|
hub.refresh_and_broadcast_qt_state();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// Non-blocking worker that pulls newly created MemTest86-Report-*.html from 192.168.2.63:/opt/pxe-server/tftp/
|
|
|
|
|
+/// when a station finishes MT and did not receive a direct TFTP WRQ upload on this host.
|
|
|
|
|
+pub fn sync_remote_pxe_report_async(
|
|
|
|
|
+ pxe_host: String,
|
|
|
|
|
+ pxe_tftp_dir: PathBuf,
|
|
|
|
|
+ min_unix_ms: i64,
|
|
|
|
|
+ sid: String,
|
|
|
|
|
+ actor_tx: mpsc::Sender<StationMsg>,
|
|
|
|
|
+ ev_fd: i32,
|
|
|
|
|
+ inflight: Arc<AtomicBool>,
|
|
|
|
|
+) {
|
|
|
|
|
+ let _ = thread::Builder::new()
|
|
|
|
|
+ .name(format!("stl-pxe-rpt-{}", sid))
|
|
|
|
|
+ .spawn(move || {
|
|
|
|
|
+ let mut sent_report = false;
|
|
|
|
|
+ if !pxe_host.trim().is_empty() && probe_pxe_ssh(&pxe_host, 300) {
|
|
|
|
|
+ let min_epoch = ((min_unix_ms.saturating_sub(90_000)) / 1000).max(0);
|
|
|
|
|
+ for attempt in 0..2 {
|
|
|
|
|
+ let remote_cmd = "ls -1t /opt/pxe-server/tftp/MemTest86-Report-*.html /srv/tftp/MemTest86-Report-*.html 2>/dev/null | head -n 1 | while read f; do [ -n \"$f\" ] && stat -c '%Y|%s|%n' \"$f\"; done";
|
|
|
|
|
+ if let Ok(out) = Command::new("sshpass")
|
|
|
|
|
+ .env("SSHPASS", "123456")
|
|
|
|
|
+ .args([
|
|
|
|
|
+ "-e",
|
|
|
|
|
+ "ssh",
|
|
|
|
|
+ "-o",
|
|
|
|
|
+ "LogLevel=ERROR",
|
|
|
|
|
+ "-o",
|
|
|
|
|
+ "StrictHostKeyChecking=no",
|
|
|
|
|
+ "-o",
|
|
|
|
|
+ "UserKnownHostsFile=/dev/null",
|
|
|
|
|
+ "-o",
|
|
|
|
|
+ "ConnectTimeout=2",
|
|
|
|
|
+ &format!("xjkj@{}", pxe_host.trim()),
|
|
|
|
|
+ remote_cmd,
|
|
|
|
|
+ ])
|
|
|
|
|
+ .output()
|
|
|
|
|
+ {
|
|
|
|
|
+ if out.status.success() {
|
|
|
|
|
+ let line = String::from_utf8_lossy(&out.stdout).trim().to_string();
|
|
|
|
|
+ let mut parts = line.splitn(3, '|');
|
|
|
|
|
+ if let (Some(ts_s), Some(_sz_s), Some(remote_path)) =
|
|
|
|
|
+ (parts.next(), parts.next(), parts.next())
|
|
|
|
|
+ {
|
|
|
|
|
+ let r_epoch = ts_s.trim().parse::<i64>().unwrap_or(0);
|
|
|
|
|
+ let rp = remote_path.trim();
|
|
|
|
|
+ if r_epoch >= min_epoch && !rp.is_empty() {
|
|
|
|
|
+ let _ = fs::create_dir_all(&pxe_tftp_dir);
|
|
|
|
|
+ let fname = Path::new(rp)
|
|
|
|
|
+ .file_name()
|
|
|
|
|
+ .and_then(|s| s.to_str())
|
|
|
|
|
+ .unwrap_or("MemTest86-Report.html")
|
|
|
|
|
+ .to_string();
|
|
|
|
|
+ let dest_path = pxe_tftp_dir.join(&fname);
|
|
|
|
|
+ let scp_ok = Command::new("sshpass")
|
|
|
|
|
+ .env("SSHPASS", "123456")
|
|
|
|
|
+ .args([
|
|
|
|
|
+ "-e",
|
|
|
|
|
+ "scp",
|
|
|
|
|
+ "-o",
|
|
|
|
|
+ "LogLevel=ERROR",
|
|
|
|
|
+ "-o",
|
|
|
|
|
+ "StrictHostKeyChecking=no",
|
|
|
|
|
+ "-o",
|
|
|
|
|
+ "UserKnownHostsFile=/dev/null",
|
|
|
|
|
+ "-o",
|
|
|
|
|
+ "ConnectTimeout=2",
|
|
|
|
|
+ &format!("xjkj@{}:{}", pxe_host.trim(), rp),
|
|
|
|
|
+ &dest_path.to_string_lossy(),
|
|
|
|
|
+ ])
|
|
|
|
|
+ .status()
|
|
|
|
|
+ .map(|s| s.success())
|
|
|
|
|
+ .unwrap_or(false);
|
|
|
|
|
+ if scp_ok && dest_path.is_file() {
|
|
|
|
|
+ if let Ok(raw_bytes) = fs::read(&dest_path) {
|
|
|
|
|
+ let html_str = decode_html_report_bytes(&raw_bytes);
|
|
|
|
|
+ let mut report = parse_mt86_html_report(&fname, &html_str);
|
|
|
|
|
+ report.set("source_host", JsonVal::Str(pxe_host.clone()));
|
|
|
|
|
+ let _ = actor_tx.send(StationMsg::MtReportUploaded {
|
|
|
|
|
+ report,
|
|
|
|
|
+ full_path: dest_path.to_string_lossy().to_string(),
|
|
|
|
|
+ force: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ sent_report = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if attempt == 0 {
|
|
|
|
|
+ thread::sleep(Duration::from_millis(650));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ let _ = actor_tx.send(StationMsg::MtReportSyncDone { fetched: sent_report });
|
|
|
|
|
+ inflight.store(false, Ordering::Release);
|
|
|
|
|
+ if ev_fd >= 0 {
|
|
|
|
|
+ unsafe {
|
|
|
|
|
+ lib::stl_eventfd_notify(ev_fd);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
pub fn spawn_tftp_server(listen_addr: &str, hub: Arc<crate::api::AppHub>) -> Option<SocketAddr> {
|
|
pub fn spawn_tftp_server(listen_addr: &str, hub: Arc<crate::api::AppHub>) -> Option<SocketAddr> {
|
|
|
let trimmed = listen_addr.trim();
|
|
let trimmed = listen_addr.trim();
|
|
|
if trimmed.is_empty() || trimmed.eq_ignore_ascii_case("disabled") {
|
|
if trimmed.is_empty() || trimmed.eq_ignore_ascii_case("disabled") {
|