feat: event management and websocket for updates

This commit is contained in:
Andrew Rioux
2025-02-22 16:04:15 -05:00
parent 005048f1ce
commit faaa4d2d1a
48 changed files with 1409 additions and 204 deletions

View File

@@ -22,6 +22,8 @@ pub struct LinuxAdapter;
impl BeaconAdapter for LinuxAdapter {
type Error = LinuxAdapterError;
const OPERATING_SYSTEM: &'static str = "Linux";
fn interface_name_from_interface(interface: &BeaconInterface) -> Vec<u8> {
interface.name.clone()
}
@@ -88,4 +90,33 @@ impl BeaconAdapter for LinuxAdapter {
.collect(),
})
}
async fn get_username(&self) -> Result<String, error::BeaconError<Self::Error>> {
let passwd = tokio::fs::read_to_string("/etc/passwd").await?;
let uid = unsafe { libc::getuid() };
Ok(passwd
.split("\n")
.find_map(|row| -> Option<String> {
let mut entries = row.split(":");
let name = entries.next()?;
entries.next()?;
let euid = entries.next()?.parse::<u32>().ok()?;
if euid == uid {
Some(name.to_string())
} else {
None
}
})
.unwrap_or("(unknown)".to_string()))
}
async fn get_hostname(&self) -> Result<String, error::BeaconError<Self::Error>> {
Ok(tokio::fs::read_to_string("/etc/hostname")
.await?
.trim()
.to_string())
}
}