mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-06-29 21:52:06 -07:00
WIFI changes to support moxee. May need to rebase as delivering refactoring under other PR.
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#!/bin/sh
|
||||
# Pushes all client-mode files to the Orbic device via ADB.
|
||||
# Dev tool: pushes WiFi client-mode files to a device via ADB.
|
||||
# For production installs, use the installer instead: ./installer moxee --admin-password X
|
||||
#
|
||||
# Usage: ./setup-device.sh [orbic|moxee]
|
||||
# If no device specified, auto-detects via ADB uid (root=Moxee, shell=Orbic).
|
||||
# Run from the rayhunter repo root.
|
||||
set -e
|
||||
|
||||
@@ -11,14 +15,38 @@ if ! adb devices | grep -q device$; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Pushing scripts..."
|
||||
adb shell "mkdir -p /data/rayhunter/scripts /data/rayhunter/bin"
|
||||
adb push "$SCRIPT_DIR/wifi-client.sh" /data/rayhunter/scripts/wifi-client.sh
|
||||
DEVICE="$1"
|
||||
if [ -z "$DEVICE" ]; then
|
||||
ADB_UID=$(adb shell id -u | tr -d '\r')
|
||||
if [ "$ADB_UID" = "0" ]; then
|
||||
DEVICE="moxee"
|
||||
else
|
||||
DEVICE="orbic"
|
||||
fi
|
||||
echo "Auto-detected device: $DEVICE (uid=$ADB_UID)"
|
||||
fi
|
||||
|
||||
case "$DEVICE" in
|
||||
moxee)
|
||||
DEST="/cache/rayhunter"
|
||||
;;
|
||||
orbic)
|
||||
DEST="/data/rayhunter"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown device: $DEVICE (expected 'orbic' or 'moxee')" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Pushing scripts to $DEST/scripts/..."
|
||||
adb shell "mkdir -p $DEST/scripts $DEST/bin"
|
||||
adb push "$SCRIPT_DIR/wifi-client.sh" "$DEST/scripts/wifi-client.sh"
|
||||
|
||||
if [ -f "$WPA_DIR/wpa_supplicant" ]; then
|
||||
echo "Pushing wpa_supplicant binaries..."
|
||||
adb push "$WPA_DIR/wpa_supplicant" /data/rayhunter/bin/wpa_supplicant
|
||||
adb push "$WPA_DIR/wpa_cli" /data/rayhunter/bin/wpa_cli
|
||||
echo "Pushing wpa_supplicant binaries to $DEST/bin/..."
|
||||
adb push "$WPA_DIR/wpa_supplicant" "$DEST/bin/wpa_supplicant"
|
||||
adb push "$WPA_DIR/wpa_cli" "$DEST/bin/wpa_cli"
|
||||
else
|
||||
echo "wpa_supplicant binaries not found at $WPA_DIR"
|
||||
echo "Build them first: see tools/build-wpa-supplicant/Dockerfile"
|
||||
@@ -26,5 +54,5 @@ else
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Files pushed. Set WiFi credentials via the web UI or installer,"
|
||||
echo "Files pushed to $DEST. Set WiFi credentials via the web UI or installer,"
|
||||
echo "then reboot. WiFi client starts automatically on boot."
|
||||
|
||||
@@ -9,8 +9,17 @@ LOG="/tmp/wifi-client.log"
|
||||
exec > "$LOG" 2>&1
|
||||
|
||||
CRED_FILE="/data/rayhunter/wifi-creds.conf"
|
||||
WPA_BIN="/data/rayhunter/bin/wpa_supplicant"
|
||||
WPA_CONF="/tmp/wpa_sta.conf"
|
||||
|
||||
# Auto-detect wpa_supplicant location (Moxee uses /cache, Orbic uses /data)
|
||||
if [ -x "/cache/rayhunter/bin/wpa_supplicant" ]; then
|
||||
WPA_BIN="/cache/rayhunter/bin/wpa_supplicant"
|
||||
elif [ -x "/data/rayhunter/bin/wpa_supplicant" ]; then
|
||||
WPA_BIN="/data/rayhunter/bin/wpa_supplicant"
|
||||
else
|
||||
echo "wpa_supplicant not found in /cache/rayhunter/bin or /data/rayhunter/bin"
|
||||
exit 1
|
||||
fi
|
||||
WPA_PID="/tmp/wpa_sta.pid"
|
||||
DHCP_PID="/tmp/udhcpc_wlan1.pid"
|
||||
IFACE="wlan1"
|
||||
@@ -109,7 +118,7 @@ WPAEOF
|
||||
iptables -I INPUT -i "$IFACE" -j ACCEPT
|
||||
iptables -I FORWARD -i "$IFACE" -j ACCEPT
|
||||
|
||||
# Block stock Orbic daemons from phoning home (dmclient, upgrade, etc.)
|
||||
# Block stock daemons from phoning home (dmclient, upgrade, etc.)
|
||||
# Allow only: replies to incoming connections, DHCP renewal, DNS, and HTTPS
|
||||
# (needed for ntfy notifications).
|
||||
iptables -A OUTPUT -o "$IFACE" -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||
@@ -134,7 +143,7 @@ WPAEOF
|
||||
ip route show
|
||||
|
||||
echo "Internet test:"
|
||||
wget -q -O /dev/null http://detectportal.firefox.com/success.txt && echo "OK" || echo "FAILED"
|
||||
wget -q -O /dev/null https://detectportal.firefox.com/success.txt && echo "OK" || echo "FAILED"
|
||||
}
|
||||
|
||||
status() {
|
||||
|
||||
+1
-1
@@ -240,7 +240,7 @@ async fn run_with_config(
|
||||
info!("Starting UI");
|
||||
|
||||
let update_ui = match &config.device {
|
||||
Device::Orbic => display::orbic::update_ui,
|
||||
Device::Orbic | Device::Moxee => display::orbic::update_ui,
|
||||
Device::Tplink => display::tplink::update_ui,
|
||||
Device::Tmobile => display::tmobile::update_ui,
|
||||
Device::Wingtech => display::wingtech::update_ui,
|
||||
|
||||
@@ -11,7 +11,9 @@ use crate::RAYHUNTER_DAEMON_INIT;
|
||||
use crate::connection::{TelnetConnection, install_config, install_wifi_creds, setup_data_directory};
|
||||
use crate::orbic_auth::{LoginInfo, LoginRequest, LoginResponse, encode_password};
|
||||
use crate::output::{eprintln, print, println};
|
||||
use crate::util::{interactive_shell, telnet_send_command, telnet_send_file};
|
||||
use crate::util::{
|
||||
interactive_shell, telnet_send_command, telnet_send_command_with_output, telnet_send_file,
|
||||
};
|
||||
|
||||
// Some kajeet devices have password protected telnetd on port 23, so we use port 24 just in case
|
||||
const TELNET_PORT: u16 = 24;
|
||||
@@ -198,6 +200,31 @@ async fn wait_for_telnet(admin_ip: &str) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn check_disk_space(addr: SocketAddr, binary_size: usize) -> Result<()> {
|
||||
let df_output = telnet_send_command_with_output(
|
||||
addr,
|
||||
"df /data | tail -1 | awk '{print $4}'",
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
let available_kb: usize = df_output
|
||||
.lines()
|
||||
.find(|l| l.trim().chars().all(|c| c.is_ascii_digit()) && !l.trim().is_empty())
|
||||
.and_then(|l| l.trim().parse().ok())
|
||||
.unwrap_or(0);
|
||||
let needed_kb = binary_size / 1024 + 1024; // binary + 1 MB headroom for config/logs
|
||||
if available_kb < needed_kb {
|
||||
bail!(
|
||||
"Not enough space on /data: need ~{} KB but only {} KB available.\n\
|
||||
The firmware-devel binary is too large for this device.\n\
|
||||
Build with the firmware profile: cargo build-daemon-firmware",
|
||||
needed_kb,
|
||||
available_kb
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn setup_rayhunter(
|
||||
admin_ip: &str,
|
||||
reset_config: bool,
|
||||
@@ -220,9 +247,20 @@ async fn setup_rayhunter(
|
||||
)
|
||||
.await?;
|
||||
|
||||
check_disk_space(addr, rayhunter_daemon_bin.len()).await?;
|
||||
|
||||
let mut conn = TelnetConnection::new(addr, false);
|
||||
setup_data_directory(&mut conn, data_dir).await?;
|
||||
|
||||
// Ensure bin and scripts directories exist under the data dir (via symlink)
|
||||
telnet_send_command(
|
||||
addr,
|
||||
"mkdir -p /data/rayhunter/scripts /data/rayhunter/bin",
|
||||
"exit code 0",
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
telnet_send_file(
|
||||
addr,
|
||||
"/data/rayhunter/rayhunter-daemon",
|
||||
@@ -244,7 +282,13 @@ async fn setup_rayhunter(
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
telnet_send_file(addr, "/data/rayhunter/bin/wpa_cli", wpa_cli_bin, false).await?;
|
||||
telnet_send_file(
|
||||
addr,
|
||||
"/data/rayhunter/bin/wpa_cli",
|
||||
wpa_cli_bin,
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
||||
install_config(&mut conn, "orbic", reset_config).await?;
|
||||
install_wifi_creds(&mut conn, wifi_ssid, wifi_password).await?;
|
||||
|
||||
@@ -40,4 +40,5 @@ pub enum Device {
|
||||
Wingtech,
|
||||
Pinephone,
|
||||
Uz801,
|
||||
Moxee,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user