Compare commits
No commits in common. "4fca7d669645b318303796dc76b3f26c2485d9fa" and "92dcfc2592676d981296885675524858c5fcab3b" have entirely different histories.
4fca7d6696
...
92dcfc2592
2 changed files with 39 additions and 98 deletions
|
|
@ -54,7 +54,7 @@ use ratatui::{
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use crate::diags::{DiagGroup, Type as DiagType, get_diag_type, parse_bitlocker, parse_chkdsk};
|
use crate::diags::{DiagGroup, Type as DiagType, get_diag_type, parse_chkdsk};
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
// TUI
|
// TUI
|
||||||
|
|
@ -445,13 +445,9 @@ impl App {
|
||||||
if let Ok(mut diag_groups) = self.diag_groups.lock() {
|
if let Ok(mut diag_groups) = self.diag_groups.lock() {
|
||||||
if let Some(current_group) = diag_groups.last_mut() {
|
if let Some(current_group) = diag_groups.last_mut() {
|
||||||
match current_group.diag_type {
|
match current_group.diag_type {
|
||||||
DiagType::Bitlocker => {
|
|
||||||
if let Some(task_result) = &task.result {
|
|
||||||
parse_bitlocker(current_group, task_result.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DiagType::CheckDisk => {
|
DiagType::CheckDisk => {
|
||||||
if let Some(task_result) = &task.result {
|
if let Some(task_result) = &task.result {
|
||||||
|
//
|
||||||
parse_chkdsk(current_group, task_result.clone());
|
parse_chkdsk(current_group, task_result.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,21 +21,11 @@ use regex::Regex;
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
pub struct RegexList {
|
pub struct RegexList {
|
||||||
bitlocker_locked: OnceLock<Regex>,
|
|
||||||
bitlocker_off: OnceLock<Regex>,
|
|
||||||
carriage_returns: OnceLock<Regex>,
|
carriage_returns: OnceLock<Regex>,
|
||||||
chkdsk_splits: OnceLock<Regex>,
|
chkdsk_splits: OnceLock<Regex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RegexList {
|
impl RegexList {
|
||||||
fn bitlocker_locked(&self) -> &Regex {
|
|
||||||
self.bitlocker_locked
|
|
||||||
.get_or_init(|| Regex::new(r"Lock Status:\s+Locked").unwrap())
|
|
||||||
}
|
|
||||||
fn bitlocker_off(&self) -> &Regex {
|
|
||||||
self.bitlocker_off
|
|
||||||
.get_or_init(|| Regex::new(r"Protection Status:\s+Protection Off").unwrap())
|
|
||||||
}
|
|
||||||
fn carriage_returns(&self) -> &Regex {
|
fn carriage_returns(&self) -> &Regex {
|
||||||
self.carriage_returns
|
self.carriage_returns
|
||||||
.get_or_init(|| Regex::new(r"^.*\r").unwrap())
|
.get_or_init(|| Regex::new(r"^.*\r").unwrap())
|
||||||
|
|
@ -52,8 +42,6 @@ impl RegexList {
|
||||||
}
|
}
|
||||||
|
|
||||||
static REGEXES: RegexList = RegexList {
|
static REGEXES: RegexList = RegexList {
|
||||||
bitlocker_locked: OnceLock::new(),
|
|
||||||
bitlocker_off: OnceLock::new(),
|
|
||||||
carriage_returns: OnceLock::new(),
|
carriage_returns: OnceLock::new(),
|
||||||
chkdsk_splits: OnceLock::new(),
|
chkdsk_splits: OnceLock::new(),
|
||||||
};
|
};
|
||||||
|
|
@ -142,73 +130,6 @@ pub fn get_diag_type(label: &str) -> Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_bitlocker(diag_group: &mut DiagGroup, task_result: TaskResult) {
|
|
||||||
if !cfg!(windows) {
|
|
||||||
sleep(Duration::from_millis(500));
|
|
||||||
return ();
|
|
||||||
}
|
|
||||||
let re_bitlocker_locked = REGEXES.bitlocker_locked();
|
|
||||||
let re_bitlocker_off = REGEXES.bitlocker_off();
|
|
||||||
match task_result {
|
|
||||||
TaskResult::Error(err) => {
|
|
||||||
diag_group.passed = false;
|
|
||||||
diag_group.result = String::from("Error");
|
|
||||||
diag_group.logs.push(Log {
|
|
||||||
label: String::from("Bitlocker"),
|
|
||||||
summary: vec![DVLine {
|
|
||||||
line_parts: vec![String::from("Bitlocker: "), String::from("Error")],
|
|
||||||
line_colors: vec![Color::Reset, Color::Red],
|
|
||||||
}],
|
|
||||||
raw: err,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
TaskResult::Output(stdout, stderr, _) => {
|
|
||||||
let output_text = if stderr.is_empty() {
|
|
||||||
stdout.clone()
|
|
||||||
} else {
|
|
||||||
format!("{stdout}\n\n-------\n\n{stderr}")
|
|
||||||
};
|
|
||||||
let result: String;
|
|
||||||
let set_result_text = !output_text.contains("All Key Protectors");
|
|
||||||
|
|
||||||
if re_bitlocker_off.is_match(&output_text) {
|
|
||||||
diag_group.passed &= true;
|
|
||||||
result = String::from("OK");
|
|
||||||
diag_group.logs.push(Log {
|
|
||||||
label: String::from("Bitlocker"),
|
|
||||||
summary: vec![DVLine {
|
|
||||||
line_parts: vec![String::from("Bitlocker: "), String::from("OFF")],
|
|
||||||
line_colors: vec![Color::Reset, Color::Green],
|
|
||||||
}],
|
|
||||||
raw: output_text,
|
|
||||||
});
|
|
||||||
} else if re_bitlocker_locked.is_match(&output_text) {
|
|
||||||
diag_group.passed = false;
|
|
||||||
result = String::from("Locked");
|
|
||||||
diag_group.logs.push(Log {
|
|
||||||
label: String::from("Bitlocker"),
|
|
||||||
summary: vec![DVLine {
|
|
||||||
line_parts: vec![String::from("Bitlocker: "), String::from("Locked")],
|
|
||||||
line_colors: vec![Color::Reset, Color::Red],
|
|
||||||
}],
|
|
||||||
raw: output_text,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
diag_group.passed &= true;
|
|
||||||
result = String::from("Unknown");
|
|
||||||
diag_group.logs.push(Log {
|
|
||||||
label: String::from("Bitlocker"),
|
|
||||||
summary: Vec::new(),
|
|
||||||
raw: output_text,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if set_result_text {
|
|
||||||
diag_group.result = result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse_chkdsk(diag_group: &mut DiagGroup, task_result: TaskResult) {
|
pub fn parse_chkdsk(diag_group: &mut DiagGroup, task_result: TaskResult) {
|
||||||
if !cfg!(windows) {
|
if !cfg!(windows) {
|
||||||
sleep(Duration::from_millis(500));
|
sleep(Duration::from_millis(500));
|
||||||
|
|
@ -228,15 +149,22 @@ pub fn parse_chkdsk(diag_group: &mut DiagGroup, task_result: TaskResult) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
TaskResult::Output(stdout, stderr, _) => {
|
TaskResult::Output(stdout, stderr, _) => {
|
||||||
|
let re_carriage_returns = REGEXES.carriage_returns();
|
||||||
let re_chkdsk_splits = REGEXES.chkdsk_splits();
|
let re_chkdsk_splits = REGEXES.chkdsk_splits();
|
||||||
let output_text = if stderr.is_empty() {
|
let output_text = if stderr.is_empty() {
|
||||||
stdout.clone()
|
stdout.clone()
|
||||||
} else {
|
} else {
|
||||||
format!("{stdout}\n\n-------\n\n{stderr}")
|
format!("{stdout}\n\n-------\n\n{stderr}")
|
||||||
};
|
};
|
||||||
let output_text = remove_carriage_returns(&output_text);
|
let parsed_lines: Vec<String> = output_text
|
||||||
|
.split("\r\n")
|
||||||
|
.filter_map(|line| {
|
||||||
|
let line = re_carriage_returns.replace_all(line, "").trim().to_string();
|
||||||
|
if line.is_empty() { None } else { Some(line) }
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
let parsed_output = re_chkdsk_splits
|
let parsed_output = re_chkdsk_splits
|
||||||
.replace_all(output_text.as_str(), "\n $1")
|
.replace_all(parsed_lines.join("\n").as_str(), "\n $1")
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
if parsed_output.contains("Windows has scanned the file system and found no problems.")
|
if parsed_output.contains("Windows has scanned the file system and found no problems.")
|
||||||
|
|
@ -265,16 +193,33 @@ pub fn parse_chkdsk(diag_group: &mut DiagGroup, task_result: TaskResult) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn remove_carriage_returns(text: &str) -> String {
|
// let mut summary = Vec::new();
|
||||||
let re_carriage_returns = REGEXES.carriage_returns();
|
// let raw = if stderr.is_empty() {
|
||||||
let parsed_lines: Vec<String> = text
|
// stdout.to_string()
|
||||||
.split("\r\n")
|
// } else {
|
||||||
.filter_map(|line| {
|
// format!("{stdout}\n\n --stderr-- \n\n{stderr}")
|
||||||
let line = re_carriage_returns.replace_all(line, "").trim().to_string();
|
// };
|
||||||
if line.is_empty() { None } else { Some(line) }
|
// // TODO: Implement actual logic for result
|
||||||
})
|
// Log {
|
||||||
.collect();
|
// label: String::from("CHKDSK"),
|
||||||
parsed_lines.join("\n")
|
// raw,
|
||||||
|
// summary,
|
||||||
|
// }
|
||||||
|
// // Split lines
|
||||||
|
// let lines: Vec<_> = output.split("\r\n").collect();
|
||||||
|
//
|
||||||
|
// // Omit progress lines and unhelpful messages
|
||||||
|
// lines
|
||||||
|
// .into_iter()
|
||||||
|
// .filter(|line| {
|
||||||
|
// !(line.contains("\r")
|
||||||
|
// || line.contains("Class not registered")
|
||||||
|
// || line.contains("/F parameter")
|
||||||
|
// || line.contains("Running CHKDSK")
|
||||||
|
// || line.contains("Total duration:")
|
||||||
|
// || line.contains("Failed to transfer logged messages"))
|
||||||
|
// })
|
||||||
|
// .collect::<Vec<_>>()
|
||||||
|
// .join("\n")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue