working version before responsiveness updates

This commit is contained in:
litoral05
2026-05-12 10:40:02 +01:00
parent abaa2aa137
commit 7c04ea5b2e
10 changed files with 1209 additions and 123 deletions
@@ -0,0 +1,154 @@
#!/bin/sh
set -eu
echo "======================================"
echo " UDP2RAW WireGuard Client Setup"
echo "======================================"
VPS_HOST="146.59.230.190"
UDP2RAW_REMOTE_PORT="444"
LOCAL_WG_PORT="4999"
UDP2RAW_PASSWORD="test123"
RAW_MODE="faketcp"
WG_MTU="1240"
INIT_SCRIPT="/etc/init.d/udp2raw-wg"
echo ""
echo "[1/10] Checking udp2raw binary..."
if ! command -v udp2raw >/dev/null 2>&1; then
echo "ERROR: udp2raw binary is missing"
exit 10
fi
echo "udp2raw binary found:"
command -v udp2raw
echo ""
echo "[2/10] Stopping existing service if present..."
if [ -f "$INIT_SCRIPT" ]; then
/etc/init.d/udp2raw-wg stop || true
fi
pkill -f "/usr/bin/udp2raw" || true
sleep 1
echo ""
echo "[3/10] Writing init.d service..."
cat > "$INIT_SCRIPT" <<EOF
#!/bin/sh /etc/rc.common
START=95
STOP=10
USE_PROCD=1
start_service() {
procd_open_instance
procd_set_param command \\
/usr/bin/udp2raw \\
-c \\
-l 127.0.0.1:${LOCAL_WG_PORT} \\
-r ${VPS_HOST}:${UDP2RAW_REMOTE_PORT} \\
--raw-mode ${RAW_MODE} \\
-k ${UDP2RAW_PASSWORD}
procd_set_param respawn
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
EOF
chmod +x "$INIT_SCRIPT"
echo ""
echo "[4/10] Enabling service..."
/etc/init.d/udp2raw-wg enable
echo ""
echo "[5/10] Starting service..."
/etc/init.d/udp2raw-wg restart
sleep 3
echo ""
echo "[6/10] Updating WireGuard endpoint and MTU..."
if ! uci show network.wgserver >/dev/null 2>&1; then
echo "ERROR: WireGuard peer section network.wgserver was not found"
exit 30
fi
if ! uci show network.wg0 >/dev/null 2>&1; then
echo "ERROR: WireGuard interface section network.wg0 was not found"
exit 31
fi
uci set network.wgserver.endpoint_host='127.0.0.1'
uci set network.wgserver.endpoint_port="${LOCAL_WG_PORT}"
uci set network.wg0.mtu="${WG_MTU}"
uci commit network
echo ""
echo "[7/10] Restarting WireGuard interface..."
ifdown wg0 || true
sleep 2
ifup wg0 || true
sleep 5
echo ""
echo "[8/10] Checking udp2raw process..."
if pgrep -af "^/usr/bin/udp2raw" >/dev/null 2>&1; then
echo "udp2raw process running:"
pgrep -af "^/usr/bin/udp2raw"
else
echo "ERROR: udp2raw process not running"
exit 20
fi
echo ""
echo "[9/10] Checking local listener..."
if netstat -ln 2>/dev/null | grep -q "127.0.0.1:${LOCAL_WG_PORT}"; then
echo "Local listener active on 127.0.0.1:${LOCAL_WG_PORT}"
else
echo "WARNING: Could not confirm local listener"
fi
echo ""
echo "[10/10] Testing connectivity..."
ping -c 2 -W 2 "${VPS_HOST}" || true
echo ""
echo "WireGuard endpoint:"
uci get network.wgserver.endpoint_host
uci get network.wgserver.endpoint_port
echo ""
echo "WireGuard MTU:"
uci get network.wg0.mtu || true
echo ""
echo "WireGuard status:"
wg show wg0 || true
echo ""
echo "======================================"
echo " UDP2RAW setup completed successfully"
echo "======================================"
Binary file not shown.
+254
View File
@@ -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
View File
@@ -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");
}
}