feat: event management and websocket for updates
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user