Show guidelines on UI on how to setup network hook
This commit is contained in:
29
virtweb_backend/src/nat/nat_hook.rs
Normal file
29
virtweb_backend/src/nat/nat_hook.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::constants;
|
||||
use std::path::Path;
|
||||
|
||||
/// Check out whether NAT hook has been installed or not
|
||||
pub fn is_installed() -> anyhow::Result<bool> {
|
||||
let hook_file = Path::new(constants::NAT_HOOK_PATH);
|
||||
|
||||
if !hook_file.exists() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
let exe = std::env::current_exe()?;
|
||||
let hook_content = std::fs::read_to_string(hook_file)?;
|
||||
|
||||
Ok(hook_content.contains(exe.to_string_lossy().as_ref()))
|
||||
}
|
||||
|
||||
/// Get nat hook expected content
|
||||
pub fn hook_content() -> anyhow::Result<String> {
|
||||
let exe = std::env::current_exe()?;
|
||||
|
||||
Ok(format!(
|
||||
"#!/bin/bash\n\
|
||||
{} --storage {} --network-name \"$1\" --operation \"$2\" --sub-operation \"$3\"",
|
||||
exe.to_string_lossy(),
|
||||
AppConfig::get().storage
|
||||
))
|
||||
}
|
Reference in New Issue
Block a user