working version before responsiveness updates
This commit is contained in:
@@ -714,3 +714,257 @@ pub async fn upload_provisioning_bundle(
|
||||
|
||||
Ok(format!("uploaded provision.sh and router.env to {}", ip))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn upload_udp2raw_setup_script(ip: String, password: String) -> Result<String, String> {
|
||||
if ip.trim().is_empty() {
|
||||
return Err("router IP is required".into());
|
||||
}
|
||||
|
||||
let local_script_path = "resources/udp2raw/setup_udp2raw.sh";
|
||||
let remote_script_path = "/tmp/setup_udp2raw.sh";
|
||||
|
||||
if password.trim().is_empty() {
|
||||
let target = format!("root@{}:{}", ip, remote_script_path);
|
||||
|
||||
let output = Command::new("scp")
|
||||
.args([
|
||||
"-O",
|
||||
"-o",
|
||||
"BatchMode=yes",
|
||||
"-o",
|
||||
"ConnectTimeout=10",
|
||||
"-o",
|
||||
"StrictHostKeyChecking=no",
|
||||
"-o",
|
||||
"UserKnownHostsFile=NUL",
|
||||
local_script_path,
|
||||
&target,
|
||||
])
|
||||
.output()
|
||||
.map_err(|error| format!("failed to run scp for setup_udp2raw.sh: {}", error))?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(
|
||||
format!(
|
||||
"failed to upload setup_udp2raw.sh:\n{}\n{}",
|
||||
String::from_utf8_lossy(&output.stderr),
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
run_system_ssh(&ip, "chmod +x /tmp/setup_udp2raw.sh")?;
|
||||
|
||||
return Ok(format!("uploaded setup_udp2raw.sh to {}", ip));
|
||||
}
|
||||
|
||||
let session = open_router_session(&ip, &password)?;
|
||||
|
||||
scp_file_from_disk(&session, local_script_path, remote_script_path, 0o755)?;
|
||||
|
||||
run_ssh_command(&session, "chmod +x /tmp/setup_udp2raw.sh")?;
|
||||
|
||||
Ok(format!("uploaded setup_udp2raw.sh to {}", ip))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn run_udp2raw_setup(ip: String, password: String) -> Result<String, String> {
|
||||
if ip.trim().is_empty() {
|
||||
return Err("router IP is required".into());
|
||||
}
|
||||
|
||||
let command = "sh /tmp/setup_udp2raw.sh";
|
||||
|
||||
if password.trim().is_empty() {
|
||||
return run_system_ssh(&ip, command);
|
||||
}
|
||||
|
||||
let session = open_router_session(&ip, &password)?;
|
||||
|
||||
run_ssh_command(&session, command)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn check_udp2raw_router_status(ip: String, password: String) -> Result<String, String> {
|
||||
if ip.trim().is_empty() {
|
||||
return Err("router IP is required".into());
|
||||
}
|
||||
|
||||
let command =
|
||||
r#"
|
||||
echo "== udp2raw binary =="
|
||||
if command -v udp2raw >/dev/null 2>&1; then
|
||||
command -v udp2raw
|
||||
else
|
||||
echo "missing"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "== init script =="
|
||||
if [ -x /etc/init.d/udp2raw-wg ]; then
|
||||
echo "present"
|
||||
else
|
||||
echo "missing"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "== process =="
|
||||
if pgrep -af "^/usr/bin/udp2raw" >/dev/null 2>&1; then
|
||||
pgrep -af "^/usr/bin/udp2raw"
|
||||
else
|
||||
echo "not running"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "== service status =="
|
||||
if [ -x /etc/init.d/udp2raw-wg ]; then
|
||||
/etc/init.d/udp2raw-wg status || true
|
||||
else
|
||||
echo "service unavailable"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "== WireGuard configured endpoint =="
|
||||
uci get network.wgserver.endpoint_host 2>/dev/null || true
|
||||
uci get network.wgserver.endpoint_port 2>/dev/null || true
|
||||
|
||||
echo ""
|
||||
echo "== local listener =="
|
||||
netstat -ln 2>/dev/null | grep -E '127.0.0.1:4999|:4999' || echo "listener not confirmed"
|
||||
|
||||
echo ""
|
||||
echo "== WireGuard runtime endpoint =="
|
||||
wg show wg0 2>/dev/null | grep -A8 '^peer:' || echo "wg0 unavailable"
|
||||
"#;
|
||||
|
||||
if password.trim().is_empty() {
|
||||
return run_system_ssh(&ip, command);
|
||||
}
|
||||
|
||||
let session = open_router_session(&ip, &password)?;
|
||||
|
||||
run_ssh_command(&session, command)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn test_udp2raw_tunnel(ip: String, password: String) -> Result<String, String> {
|
||||
if ip.trim().is_empty() {
|
||||
return Err("router IP is required".into());
|
||||
}
|
||||
|
||||
let command = r#"
|
||||
echo "== udp2raw process =="
|
||||
if pgrep -af "^/usr/bin/udp2raw" >/dev/null 2>&1; then
|
||||
pgrep -af "^/usr/bin/udp2raw"
|
||||
else
|
||||
echo "ERROR: udp2raw is not running"
|
||||
exit 20
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "== WireGuard configured endpoint =="
|
||||
uci get network.wgserver.endpoint_host 2>/dev/null || true
|
||||
uci get network.wgserver.endpoint_port 2>/dev/null || true
|
||||
|
||||
echo ""
|
||||
echo "== local listener =="
|
||||
netstat -ln 2>/dev/null | grep -E '127.0.0.1:4999|:4999' || echo "WARNING: listener not confirmed"
|
||||
|
||||
echo ""
|
||||
echo "== ping VPS public IP =="
|
||||
ping -c 2 -W 2 146.59.230.190 || true
|
||||
|
||||
echo ""
|
||||
echo "== WireGuard status =="
|
||||
wg show wg0 2>/dev/null || echo "wg0 not available"
|
||||
|
||||
echo ""
|
||||
echo "== route check =="
|
||||
ip route || true
|
||||
|
||||
echo ""
|
||||
echo "UDP2RAW tunnel test completed"
|
||||
"#;
|
||||
|
||||
if password.trim().is_empty() {
|
||||
return run_system_ssh(&ip, command);
|
||||
}
|
||||
|
||||
let mut last_error = String::new();
|
||||
|
||||
for attempt in 1..=5 {
|
||||
match open_router_session(&ip, &password) {
|
||||
Ok(session) => {
|
||||
return run_ssh_command(&session, command);
|
||||
}
|
||||
Err(error) => {
|
||||
last_error = format!(
|
||||
"SSH attempt {}/5 failed: {}",
|
||||
attempt,
|
||||
error
|
||||
);
|
||||
|
||||
thread::sleep(Duration::from_secs(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err(last_error)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn upload_udp2raw_binary(ip: String, password: String) -> Result<String, String> {
|
||||
if ip.trim().is_empty() {
|
||||
return Err("router IP is required".into());
|
||||
}
|
||||
|
||||
let local_binary_path = "resources/udp2raw/udp2raw";
|
||||
let remote_binary_path = "/usr/bin/udp2raw";
|
||||
|
||||
if password.trim().is_empty() {
|
||||
let target = format!("root@{}:{}", ip, remote_binary_path);
|
||||
|
||||
let output = Command::new("scp")
|
||||
.args([
|
||||
"-O",
|
||||
"-o",
|
||||
"BatchMode=yes",
|
||||
"-o",
|
||||
"ConnectTimeout=10",
|
||||
"-o",
|
||||
"StrictHostKeyChecking=no",
|
||||
"-o",
|
||||
"UserKnownHostsFile=NUL",
|
||||
local_binary_path,
|
||||
&target,
|
||||
])
|
||||
.output()
|
||||
.map_err(|error| { format!("failed to run scp for udp2raw binary: {}", error) })?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(
|
||||
format!(
|
||||
"failed to upload udp2raw binary:\n{}\n{}",
|
||||
String::from_utf8_lossy(&output.stderr),
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
run_system_ssh(
|
||||
&ip,
|
||||
"chmod +x /usr/bin/udp2raw && /usr/bin/udp2raw --help >/dev/null 2>&1 || true"
|
||||
)?;
|
||||
|
||||
return Ok("uploaded udp2raw binary to /usr/bin/udp2raw".into());
|
||||
}
|
||||
|
||||
let session = open_router_session(&ip, &password)?;
|
||||
|
||||
scp_file_from_disk(&session, local_binary_path, remote_binary_path, 0o755)?;
|
||||
|
||||
run_ssh_command(&session, "chmod +x /usr/bin/udp2raw && ls -l /usr/bin/udp2raw")?;
|
||||
|
||||
Ok("uploaded udp2raw binary to /usr/bin/udp2raw".into())
|
||||
}
|
||||
|
||||
+36
-27
@@ -15,39 +15,48 @@ use commands::{
|
||||
reconnect_router_after_flash,
|
||||
verify_router,
|
||||
wait_for_ssh,
|
||||
check_router_after_flash
|
||||
},
|
||||
ssh::{
|
||||
inspect_router_with_password,
|
||||
probe_router_ssh,
|
||||
remove_known_host,
|
||||
check_router_after_flash,
|
||||
upload_udp2raw_setup_script,
|
||||
run_udp2raw_setup,
|
||||
test_udp2raw_tunnel,
|
||||
check_udp2raw_router_status,
|
||||
upload_udp2raw_binary
|
||||
},
|
||||
ssh::{ inspect_router_with_password, probe_router_ssh, remove_known_host },
|
||||
};
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
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,
|
||||
probe_router_ssh,
|
||||
inspect_router_with_password,
|
||||
detect_router,
|
||||
upload_firmware,
|
||||
upload_firmware_to_router,
|
||||
flash_router,
|
||||
flash_router_sysupgrade,
|
||||
reconnect_router_after_flash,
|
||||
wait_for_ssh,
|
||||
upload_provisioning_bundle,
|
||||
run_provisioning,
|
||||
capture_wireguard_public_key,
|
||||
verify_router,
|
||||
check_router_after_flash
|
||||
])
|
||||
.invoke_handler(
|
||||
tauri::generate_handler![
|
||||
read_text_file,
|
||||
ping_host,
|
||||
remove_known_host,
|
||||
probe_router_ssh,
|
||||
inspect_router_with_password,
|
||||
detect_router,
|
||||
upload_firmware,
|
||||
upload_firmware_to_router,
|
||||
flash_router,
|
||||
flash_router_sysupgrade,
|
||||
reconnect_router_after_flash,
|
||||
wait_for_ssh,
|
||||
upload_provisioning_bundle,
|
||||
run_provisioning,
|
||||
capture_wireguard_public_key,
|
||||
verify_router,
|
||||
check_router_after_flash,
|
||||
upload_udp2raw_setup_script,
|
||||
run_udp2raw_setup,
|
||||
test_udp2raw_tunnel,
|
||||
check_udp2raw_router_status,
|
||||
upload_udp2raw_binary
|
||||
]
|
||||
)
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user