Skip to content

Commit

Permalink
Remove automatic upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Loudbooks committed Jul 26, 2024
1 parent 7edd54d commit 4390864
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 75 deletions.
105 changes: 105 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ whoami = "1.5.1"
machine-info = "1.0.6"
ureq = { version = "2.9.6", default-features = false, features = ["native-tls"] }
native-tls = "0.2.11"
open = "5.3.0"
chrono = "0.4.38"

[profile.release]
strip = true
opt-level = "z"
lto = true
codegen-units = 1
codegen-units = 1
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div align="center">
<h1>ReportBook</h1>
<p></p>Simplistic automated diagnostic tool</p>
<p></p>Simplistic automated diagnostic tool for Windows and macOS

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Loudbooks/ReportBook/rust.yml?style=for-the-badge)
</div>

ReportBook is a process used to diagnose a variety of possible issues on your device. Output is uploaded to [PasteBook](https://pastebook.dev), to be deleted entirely after 24 hours. You can find an example [here](https://pastebook.dev/pastes/millie-shadow-bard-milkchocolate?inspect).
ReportBook is a process used to diagnose a variety of possible issues on your device. Output is shown in a plain text file. You can find an example [here](https://pastebook.dev/pastes/millie-shadow-bard-milkchocolate?inspect).

This program was designed with the intention of being used by software support teams, but is available to anyone who wishes to use it. Source code can be viewed on [GitHub](https://github.com/Loudbooks/ReportBook) should you be interested in how it works.

Expand Down
3 changes: 1 addition & 2 deletions src/datagatherers/processes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn gather_processes(sys: &System) -> Vec<Process> {
let username = whoami::username();
let mut processes: Vec<Process> = Vec::new();

for (pid, process) in sys.processes() {
for (_pid, process) in sys.processes() {
match process.cwd() {
None => {}
Some(_) => {
Expand Down Expand Up @@ -37,7 +37,6 @@ pub fn gather_processes(sys: &System) -> Vec<Process> {
};

let process = Process {
pid: *pid,
name: process.name().to_string(),
path,
memory: process.memory() as f64,
Expand Down
39 changes: 39 additions & 0 deletions src/file_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::fs;

pub struct FileHandler {
pub lines: Vec<String>,
}

impl FileHandler {
pub fn new() -> Self {
Self {
lines: Vec::new(),
}
}

pub fn add_line(&mut self, line: String) {
self.lines.push(line);
}

pub fn submit(&self) {
if cfg!(target_os = "windows") {
self.submit_windows();
} else {
self.submit_unix();
}
}

fn submit_windows(&self) {
let path = "C:\\Temp\\ReportBook.txt";
fs::write(path, self.lines.join("\n").as_bytes()).expect("Failed to create tempfile");

open::that(path).expect("Failed to open file");
}

fn submit_unix(&self) {
let path = "/tmp/ReportBook.txt";
fs::write(path, self.lines.join("\n").as_bytes()).expect("Failed to create tempfile");

open::that(path).expect("Failed to open file");
}
}
44 changes: 0 additions & 44 deletions src/httphandler.rs

This file was deleted.

40 changes: 18 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::process::prettify_memory;
use std::io::stdin;

use machine_info::Machine;
use std::io::{stdin, stdout, Write};
use sysinfo::System;

use crate::process::prettify_memory;

mod app;
mod datagatherers;
mod httphandler;
mod file_handler;
mod process;

fn main() {
Expand All @@ -16,14 +18,14 @@ The intention of this process is to gather information on hardware and software
Rest assured, identifiable information including your name and your address will be omitted from the resulting report.
Reports will be uploaded to a pastebin, to expire after nine hours.
Reports will be opened in your default text editor once completed.
"#;

println!("{}", intro);
wait_for_enter("continue");

let mut http_handler =
httphandler::HttpHandler::new("https://pastebook.dev/upload".to_string());
file_handler::FileHandler::new();

let mut sys = System::new_all();
sys.refresh_all();
Expand All @@ -39,6 +41,7 @@ Reports will be uploaded to a pastebin, to expire after nine hours.
let gpus = machine.system_info().graphics;
let username = whoami::username();
let is_alphanumeric_username = username.chars().all(char::is_alphanumeric);
let log_creation = chrono::Utc::now().format("%Y-%m-%d %H:%M").to_string();

let os_name = format!(
"{}, {}",
Expand Down Expand Up @@ -160,7 +163,14 @@ Reports will be uploaded to a pastebin, to expire after nine hours.
let spaces = INFORMATION_SPACES - id.len();
format!("{}{}{}", id, " ".repeat(spaces), value)
};

let log_creation_str = {
let id = "Log Creation: ";

let spaces = INFORMATION_SPACES - id.len();
format!("{}{}{}", id, " ".repeat(spaces), log_creation)
};

http_handler.add_line(os_name_str.to_string());
http_handler.add_line(total_memory_str);
if total_swap > 0 {
Expand All @@ -176,6 +186,8 @@ Reports will be uploaded to a pastebin, to expire after nine hours.
http_handler.add_line(gpu);
}
http_handler.add_line(alphanumeric_username);
http_handler.add_line(log_creation_str);

http_handler.add_line("".to_string());

let processes = datagatherers::processes::gather_processes(&sys);
Expand Down Expand Up @@ -231,27 +243,11 @@ Reports will be uploaded to a pastebin, to expire after nine hours.
}
}

print!("Enter your username: ");
let username = user_input();

http_handler.submit(username.as_str());
http_handler.submit();

wait_for_enter("exit")
}

fn user_input() -> String {
let mut input = String::new();

stdout().flush().expect("Failed to flush");
stdin()
.read_line(&mut input)
.expect("Did not enter a correct string");

input = input.trim().to_string();

input
}

fn wait_for_enter(message: &str) {
println!("Press enter to {}.", message);
let _ = stdin().read_line(&mut String::new());
Expand Down
Loading

0 comments on commit 4390864

Please sign in to comment.