first commit
This commit is contained in:
224
src/util/mod.rs
Normal file
224
src/util/mod.rs
Normal file
@@ -0,0 +1,224 @@
|
||||
use std::env::consts::OS;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn get_cache_dir() -> String {
|
||||
#[allow(unused)]
|
||||
let mut cache_dir = String::new();
|
||||
let cur_user = whoami::username();
|
||||
|
||||
match OS {
|
||||
"linux" => {
|
||||
if cur_user.eq_ignore_ascii_case("root") {
|
||||
let _ = fs::create_dir_all(Path::new("/root/.config/watchman/config/"));
|
||||
"/root/.config/watchman/".to_string()
|
||||
} else {
|
||||
let create_dir = format!("/home/{}/.config/watchman/config/", cur_user);
|
||||
let _ = fs::create_dir_all(Path::new(create_dir.as_str()));
|
||||
format!("/home/{}/.config/watchman/", cur_user)
|
||||
}
|
||||
}
|
||||
"macos" => {
|
||||
// /var/root/Library/Caches/com.helloimalemur.watchman/
|
||||
if cur_user.eq_ignore_ascii_case("root") {
|
||||
let _ = fs::create_dir_all(Path::new("/var/root/Library/Caches/com.helloimalemur.watchman/config/"));
|
||||
"/var/root/Library/Caches/com.helloimalemur.watchman/".to_string()
|
||||
} else {
|
||||
let create_dir = format!("/Users/{}/Library/Caches/com.helloimalemur.watchman/config/", cur_user);
|
||||
let _ = fs::create_dir_all(Path::new(create_dir.as_str()));
|
||||
format!("/Users/{}/Library/Caches/com.helloimalemur.watchman/", cur_user)
|
||||
}
|
||||
}
|
||||
"windows" => {
|
||||
// Prefer LOCALAPPDATA for cache
|
||||
if let Ok(local_appdata) = std::env::var("LOCALAPPDATA") {
|
||||
let base = format!("{}\\Watchman\\", local_appdata);
|
||||
let _ = fs::create_dir_all(Path::new(format!("{}config\\", base).as_str()));
|
||||
base
|
||||
} else {
|
||||
let base = format!("C:\\Users\\{}\\AppData\\Local\\Watchman\\", cur_user);
|
||||
let _ = fs::create_dir_all(Path::new(format!("{}config\\", base).as_str()));
|
||||
base
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// Fallback to current directory for unknown OS
|
||||
let _ = fs::create_dir_all(Path::new("./config/"));
|
||||
"./".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn get_config_dir() -> String {
|
||||
#[allow(unused)]
|
||||
let mut cache_dir = String::new();
|
||||
let cur_user = whoami::username();
|
||||
|
||||
match OS {
|
||||
"linux" => {
|
||||
if cur_user.eq_ignore_ascii_case("root") {
|
||||
let _ = fs::create_dir_all(Path::new("/root/.config/watchman/config/"));
|
||||
"/root/.config/watchman/".to_string()
|
||||
} else {
|
||||
let create_dir = format!("/home/{}/.config/watchman/config/", cur_user);
|
||||
let _ = fs::create_dir_all(Path::new(create_dir.as_str()));
|
||||
format!("/home/{}/.config/watchman/", cur_user)
|
||||
}
|
||||
}
|
||||
"macos" => {
|
||||
// /var/root/Library/Application\ Support/com.helloimalemur.watchman/
|
||||
if cur_user.eq_ignore_ascii_case("root") {
|
||||
let _ = fs::create_dir_all(Path::new("/var/root/Library/Application\\ Support/com.helloimalemur.watchman/config/"));
|
||||
"/var/root/Library/Application\\ Support/com.helloimalemur.watchman/".to_string()
|
||||
} else {
|
||||
let create_dir = format!("/Users/{}/Library/Application\\ Support/com.helloimalemur.watchman/config/", cur_user);
|
||||
let _ = fs::create_dir_all(Path::new(create_dir.as_str()));
|
||||
format!("/Users/{}/Library/Application\\ Support/com.helloimalemur.watchman/", cur_user)
|
||||
}
|
||||
}
|
||||
"windows" => {
|
||||
// Prefer APPDATA (Roaming) for config
|
||||
if let Ok(appdata) = std::env::var("APPDATA") {
|
||||
let base = format!("{}\\Watchman\\", appdata);
|
||||
let _ = fs::create_dir_all(Path::new(format!("{}config\\", base).as_str()));
|
||||
base
|
||||
} else {
|
||||
let base = format!("C:\\Users\\{}\\AppData\\Roaming\\Watchman\\", cur_user);
|
||||
let _ = fs::create_dir_all(Path::new(format!("{}config\\", base).as_str()));
|
||||
base
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// Fallback to current directory for unknown OS
|
||||
let _ = fs::create_dir_all(Path::new("./config/"));
|
||||
"./".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_default_blacklist<T: ToString>(path: T) {
|
||||
let _ = fs::write(path.to_string(), default_blacklist());
|
||||
}
|
||||
|
||||
fn default_blacklist() -> &'static str {
|
||||
r#"
|
||||
/etc/mtab
|
||||
/etc/cups
|
||||
"#
|
||||
}
|
||||
|
||||
pub fn write_default_config<T: ToString>(path: T, webhook: String) {
|
||||
if fs::write(
|
||||
path.to_string(),
|
||||
default_config().replace("https://discord.com/api/webhooks/", webhook.as_str()),
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
println!(
|
||||
"{}\n ~~~~~~~ UNABLE TO LOCATE CONFIG FILE - DEFAULT CONFIG CREATED ~~~~~~~",
|
||||
default_config().replace("https://discord.com/api/webhooks/", webhook.as_str())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn default_config() -> &'static str {
|
||||
match OS {
|
||||
"linux" => {
|
||||
r#"
|
||||
## General settings
|
||||
tick_delay_seconds = "5"
|
||||
fs_tick_delay_seconds = "300"
|
||||
|
||||
### File System Integrity
|
||||
fs_mon_path_variable = true
|
||||
fs_mon_enabled = "true"
|
||||
fs_mon_dir = ["/etc", "/bin", "$PATH"]
|
||||
fs_mon_hash_type = "blake3"
|
||||
|
||||
### USB Monitor
|
||||
usb_mon_enabled = "true"
|
||||
reboot_on_increase_of_usb_devices = "false"
|
||||
notify_on_increase_of_usb_devices = "false"
|
||||
unmount_crypt_on_increase_of_usb_devices = "true"
|
||||
|
||||
### Burn File Monitor
|
||||
burn_file_mon_enabled = "false"
|
||||
unmount_crypt_on_file_burn = "true"
|
||||
ssh_check_burn_host = "hostname"
|
||||
ssh_check_burn_user = "root"
|
||||
ssh_check_burn_key = "/home/user/.ssh/id_rsa"
|
||||
ssh_check_burn_path = "/root/.config/burn"
|
||||
ssh_check_burn_check_interval = "30"
|
||||
burn_path_1 = "/root/test/"
|
||||
|
||||
### Network Monitor
|
||||
net_mon_enabled = "false"
|
||||
|
||||
### Client Discovery & Scan
|
||||
client_scan_enabled = "false"
|
||||
client_discovery_method = "arp" # arp | ping
|
||||
client_scan_exclusions = ["127.0.0.1", "localhost"]
|
||||
scan_on_add = "true"
|
||||
nmap_path = "nmap"
|
||||
nmap_profile = "-sV -T4"
|
||||
findings_critical_ports = ["23", "2323", "3389", "5900"]
|
||||
notify_on_findings = "false"
|
||||
action_on_findings = "none" # none | reboot
|
||||
|
||||
######## Notification settings
|
||||
discord_webhook_url = "https://discord.com/api/webhooks/"
|
||||
discord_webhook_avatar_name = "Lazarus"
|
||||
"#
|
||||
}
|
||||
|
||||
"macos" => {
|
||||
r#"
|
||||
## General settings
|
||||
tick_delay_seconds = "5"
|
||||
fs_tick_delay_seconds = "300"
|
||||
|
||||
### File System Integrity
|
||||
fs_mon_path_variable = true
|
||||
fs_mon_enabled = "true"
|
||||
fs_mon_dir = ["/etc", "/bin", "$PATH"]
|
||||
fs_mon_hash_type = "blake3"
|
||||
|
||||
### USB Monitor
|
||||
usb_mon_enabled = "true"
|
||||
reboot_on_increase_of_usb_devices = "false"
|
||||
notify_on_increase_of_usb_devices = "true"
|
||||
unmount_crypt_on_increase_of_usb_devices = "true"
|
||||
|
||||
### Burn File Monitor
|
||||
burn_file_mon_enabled = "false"
|
||||
unmount_crypt_on_file_burn = "true"
|
||||
ssh_check_burn_host = "hostname"
|
||||
ssh_check_burn_user = "root"
|
||||
ssh_check_burn_key = "/User/user/.ssh/id_rsa"
|
||||
ssh_check_burn_path = "/var/root/.config/burn"
|
||||
ssh_check_burn_check_interval = "30"
|
||||
burn_path_1 = "/var/root/test/"
|
||||
|
||||
### Network Monitor
|
||||
net_mon_enabled = "false"
|
||||
|
||||
### Client Discovery & Scan
|
||||
client_scan_enabled = "false"
|
||||
client_discovery_method = "arp" # arp | ping
|
||||
client_scan_exclusions = ["127.0.0.1", "localhost"]
|
||||
scan_on_add = "true"
|
||||
nmap_path = "nmap"
|
||||
nmap_profile = "-sV -T4"
|
||||
findings_critical_ports = ["23", "2323", "3389", "5900"]
|
||||
notify_on_findings = "true"
|
||||
action_on_findings = "none" # none | reboot
|
||||
|
||||
######## Notification settings
|
||||
discord_webhook_url = "https://discord.com/api/webhooks/"
|
||||
discord_webhook_avatar_name = "Lazarus"
|
||||
"#
|
||||
}
|
||||
_ => {
|
||||
panic!("Unsupported OS: {}", OS);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user