Initial project structure cleanup

This commit is contained in:
litoral05
2026-05-08 16:57:55 +01:00
commit 8075104243
59 changed files with 22335 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
#[tauri::command]
pub async fn read_text_file(
path: String,
) -> Result<String, String> {
std::fs::read_to_string(&path)
.map_err(|error| {
format!(
"failed to read {}: {}",
path, error,
)
})
}
+4
View File
@@ -0,0 +1,4 @@
pub mod files;
pub mod network;
pub mod router;
pub mod ssh;
+13
View File
@@ -0,0 +1,13 @@
#[tauri::command]
pub async fn ping_host(
ip: String,
) -> Result<bool, String> {
if ip.trim().is_empty() {
return Err(
"ip address cannot be empty"
.to_string(),
);
}
Ok(true)
}
+125
View File
@@ -0,0 +1,125 @@
use std::{
thread,
time::Duration,
};
fn delay() {
thread::sleep(Duration::from_millis(350));
}
#[tauri::command]
pub async fn detect_router(
ip: String,
) -> Result<bool, String> {
delay();
if ip.trim().is_empty() {
return Err(
"router IP is required".into(),
);
}
Ok(true)
}
#[tauri::command]
pub async fn upload_firmware(
ip: String,
firmware_path: String,
) -> Result<String, String> {
delay();
Ok(format!(
"uploaded {} to {}:/tmp/firmware.bin",
firmware_path, ip,
))
}
#[tauri::command]
pub async fn flash_router(
ip: String,
remote_firmware_path: String,
) -> Result<String, String> {
delay();
Ok(format!(
"sysupgrade started on {} with {}",
ip, remote_firmware_path,
))
}
#[tauri::command]
pub async fn wait_for_ssh(
ip: String,
) -> Result<bool, String> {
for _ in 0..3 {
delay();
}
if ip == "198.51.100.1"
|| ip == "192.168.1.1"
{
Ok(true)
} else {
Err(format!(
"SSH timeout waiting for {}",
ip,
))
}
}
#[tauri::command]
pub async fn upload_provisioning_bundle(
ip: String,
env_content: String,
script_content: String,
) -> Result<String, String> {
delay();
Ok(format!(
"uploaded router.env ({} bytes) and provision.sh ({} bytes) to {}",
env_content.len(),
script_content.len(),
ip,
))
}
#[tauri::command]
pub async fn run_provisioning(
ip: String,
) -> Result<String, String> {
delay();
Ok(format!(
"provision.sh completed on {}; fw4/nftables, wg0, DNAT, LuCI over WireGuard configured",
ip,
))
}
#[tauri::command]
pub async fn capture_wireguard_public_key(
_ip: String,
) -> Result<String, String> {
delay();
Ok(
"MOCK_ROUTER_WIREGUARD_PUBLIC_KEY_BASE64="
.into(),
)
}
#[tauri::command]
pub async fn verify_router(
ip: String,
) -> Result<bool, String> {
delay();
if ip == "198.51.100.1" {
Ok(true)
} else {
Err(
"router verification failed"
.into(),
)
}
}
+16
View File
@@ -0,0 +1,16 @@
#[tauri::command]
pub async fn remove_known_host(
ip: String,
) -> Result<String, String> {
if ip.trim().is_empty() {
return Err(
"ip address cannot be empty"
.into(),
);
}
Ok(format!(
"removed stale known_hosts entry for {}",
ip,
))
}
+39
View File
@@ -0,0 +1,39 @@
mod commands;
use commands::{
files::read_text_file,
network::ping_host,
router::{
capture_wireguard_public_key,
detect_router,
flash_router,
run_provisioning,
upload_firmware,
upload_provisioning_bundle,
verify_router,
wait_for_ssh,
},
ssh::remove_known_host,
};
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_fs::init())
.invoke_handler(tauri::generate_handler![
read_text_file,
ping_host,
remove_known_host,
detect_router,
upload_firmware,
flash_router,
wait_for_ssh,
upload_provisioning_bundle,
run_provisioning,
capture_wireguard_public_key,
verify_router,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
+1
View File
@@ -0,0 +1 @@
fn main() { lr_openwrt_tool_lib::run() }