Port the toolkit GUI to Windows (wxMSW, cross-built with mingw-w64)
Build: the wx-rs build script chose the platform with cfg!(), which in a build script describes the build host, so a Linux-to-Windows build took the GTK path. It now reads CARGO_CFG_TARGET_*, and Windows/GNU builds through wx-config exactly like GTK, against a static wxMSW from scripts/build-wx-windows.sh. The C++ runtime is linked statically, so the .exe imports only Windows system DLLs. crates/alkane-gui/build.rs embeds an application manifest (Common Controls v6, per-monitor DPI v2, UTF-8 code page, Windows 10/11), the icon and version info. Bridge on wxMSW (patches 0007/0008): - the upstream frame's invisible "OSX key events" child sat above the UI on MSW and swallowed every click and key; it is no longer created there - light/dark is chosen before the first window (wxMSW ignores it later) and follows the Windows app mode, with dark grid rules for the data view - the generic wxDataViewCtrl gets mouse input in its inner main window, so drag-select and the per-cell / per-icon tooltips bind there (GTK keeps its native GtkTreeView paths; the icon hit-test is shared) - sizes cross the Rust/C++ boundary in DIPs (identity on GTK), so columns, icons, KPI cards and the status bar scale at 125-200 % - vector shapes go through GDI+ (anti-aliased like Cairo on GTK); selected rows use the themed list-view text colour like the native renderer - the frame never opens larger than the monitor work area; title-bar icon from the executable; upstream menu insert no longer reads UTF-8 as UTF-16 App: OS differences live in alkane_core::platform (settings in %APPDATA%\alkane-toolkit, owner-only secret files, NUL, console-less helper processes). SSH password logins use SSH_ASKPASS with the toolkit itself as the helper on every platform, replacing sshpass, which Windows lacks. Release builds are GUI-subsystem; headless modes attach to the parent console. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -77,11 +77,11 @@ pub fn probe_access(ip: &str, make: &str, user: &str, pass: &str) -> Result<Opti
|
||||
return Ok(probe_whatsminer_access(ip, &candidates));
|
||||
}
|
||||
let url = format!("http://{ip}{}", endpoint(make));
|
||||
let mut cmd = Command::new("curl");
|
||||
let mut cmd = alkane_core::platform::quiet_command("curl");
|
||||
cmd.args([
|
||||
"-s",
|
||||
"-o",
|
||||
"/dev/null",
|
||||
alkane_core::platform::NULL_DEVICE,
|
||||
"-w",
|
||||
"%{http_code}",
|
||||
"--digest",
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
//! Non-interactive SSH password logins without `sshpass`.
|
||||
//!
|
||||
//! OpenSSH (Linux, and the `ssh.exe` built into Windows 10/11) asks the
|
||||
//! program named by `SSH_ASKPASS` for a password when `SSH_ASKPASS_REQUIRE=force`
|
||||
//! (OpenSSH 8.4+). The toolkit names its own executable: when ssh runs it with
|
||||
//! [`ROLE_ENV`] set, `main()` calls [`serve_if_askpass`] first thing, which
|
||||
//! prints the password from [`SECRET_ENV`] and exits before any GUI starts.
|
||||
//!
|
||||
//! This replaces `sshpass`, which Windows does not have, with one mechanism for
|
||||
//! every platform. Like `sshpass -e` the password travels in the child's
|
||||
//! environment, never on a command line where the process list would show it.
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
/// Set (to "1") in the environment of an ssh child whose askpass helper is us.
|
||||
pub const ROLE_ENV: &str = "ALKANE_SSH_ASKPASS";
|
||||
/// The password the askpass helper hands back to ssh.
|
||||
pub const SECRET_ENV: &str = "ALKANE_SSH_SECRET";
|
||||
|
||||
/// If this process is ssh's askpass helper, answer the prompt and return the
|
||||
/// exit code to use; otherwise `None` and the app starts normally.
|
||||
pub fn serve_if_askpass() -> Option<i32> {
|
||||
std::env::var_os(ROLE_ENV)?;
|
||||
let prompt = std::env::args_os().nth(1).unwrap_or_default();
|
||||
Some(answer(&prompt, std::env::var_os(SECRET_ENV).as_deref()))
|
||||
}
|
||||
|
||||
/// Print the secret for a password prompt. Anything else ssh might ask through
|
||||
/// askpass (a host-key "yes/no" confirmation, a passphrase for a key we never
|
||||
/// configured) is refused, so a changed prompt can never be answered with the
|
||||
/// password by accident.
|
||||
fn answer(prompt: &OsStr, secret: Option<&OsStr>) -> i32 {
|
||||
let Some(secret) = secret else { return 1 };
|
||||
if !is_password_prompt(&prompt.to_string_lossy()) {
|
||||
return 1;
|
||||
}
|
||||
use std::io::Write;
|
||||
let mut out = std::io::stdout().lock();
|
||||
if out
|
||||
.write_all(secret.to_string_lossy().as_bytes())
|
||||
.and_then(|_| out.write_all(b"\n"))
|
||||
.and_then(|_| out.flush())
|
||||
.is_err()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
fn is_password_prompt(prompt: &str) -> bool {
|
||||
let p = prompt.to_ascii_lowercase();
|
||||
p.contains("password") && !p.contains("yes/no")
|
||||
}
|
||||
|
||||
/// Configure an `ssh` command to log in with `password` and never block on a
|
||||
/// terminal prompt. ssh tries password (and keyboard-interactive) auth once;
|
||||
/// a wrong password fails fast with "Permission denied" instead of hanging.
|
||||
pub fn ssh_with_password(cmd: &mut Command, password: &str) -> Result<(), String> {
|
||||
let exe = std::env::current_exe().map_err(|e| format!("locate askpass helper: {e}"))?;
|
||||
cmd.env("SSH_ASKPASS", exe)
|
||||
.env("SSH_ASKPASS_REQUIRE", "force")
|
||||
.env(ROLE_ENV, "1")
|
||||
.env(SECRET_ENV, password)
|
||||
.stdin(Stdio::null());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ssh `-o` options that go with [`ssh_with_password`].
|
||||
pub const PASSWORD_AUTH_OPTIONS: [&str; 4] = [
|
||||
"-o",
|
||||
"PreferredAuthentications=password,keyboard-interactive",
|
||||
"-o",
|
||||
"NumberOfPasswordPrompts=1",
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn only_password_prompts_are_answered() {
|
||||
assert!(is_password_prompt("root@10.0.0.1's password: "));
|
||||
assert!(is_password_prompt("Password:"));
|
||||
assert!(!is_password_prompt(
|
||||
"Are you sure you want to continue connecting (yes/no/[fingerprint])?"
|
||||
));
|
||||
assert!(!is_password_prompt(
|
||||
"Enter passphrase for key '/x/id_ed25519':"
|
||||
));
|
||||
assert_eq!(
|
||||
answer(OsStr::new("Password:"), None),
|
||||
1,
|
||||
"no secret -> refuse"
|
||||
);
|
||||
assert_eq!(
|
||||
answer(OsStr::new("Continue (yes/no)?"), Some(OsStr::new("pw"))),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ssh_command_gets_askpass_environment() {
|
||||
let mut cmd = Command::new("ssh");
|
||||
ssh_with_password(&mut cmd, "hunter2").unwrap();
|
||||
let env: std::collections::HashMap<_, _> = cmd
|
||||
.get_envs()
|
||||
.map(|(k, v)| (k.to_owned(), v.map(|v| v.to_owned())))
|
||||
.collect();
|
||||
assert_eq!(
|
||||
env[OsStr::new("SSH_ASKPASS_REQUIRE")].as_deref(),
|
||||
Some(OsStr::new("force"))
|
||||
);
|
||||
assert_eq!(
|
||||
env[OsStr::new(SECRET_ENV)].as_deref(),
|
||||
Some(OsStr::new("hunter2"))
|
||||
);
|
||||
assert!(env[OsStr::new("SSH_ASKPASS")].is_some());
|
||||
// The password is never an argument.
|
||||
assert!(cmd.get_args().all(|a| a != "hunter2"));
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,7 @@ fn load_creds() -> Option<(String, String)> {
|
||||
) {
|
||||
return Some((u, pw));
|
||||
}
|
||||
let home = std::env::var("HOME").ok()?;
|
||||
let p = std::path::PathBuf::from(home).join(".config/alkane-toolkit/scan-credentials.txt");
|
||||
let p = alkane_core::platform::config_path("scan-credentials.txt");
|
||||
let s = std::fs::read_to_string(p).ok()?;
|
||||
let mut l = s.lines();
|
||||
let u = l.next()?.to_string();
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
//! firmware registry, so `scan`'s callers never have to think about it.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
||||
|
||||
use alkane_core::platform::write_private;
|
||||
|
||||
use asic_rs::core::traits::miner::MinerAuth;
|
||||
use asic_rs::MinerFactory;
|
||||
@@ -40,20 +40,9 @@ fn save_creds_file(file: &str, user: &str, pass: &str) -> std::io::Result<()> {
|
||||
if let Some(dir) = p.parent() {
|
||||
std::fs::create_dir_all(dir)?;
|
||||
}
|
||||
// Open (and create) with mode 0600 up front so a freshly created file is
|
||||
// never world/group-readable, even for the instant before the write. For a
|
||||
// pre-existing file the create mode is ignored, so also tighten it to 0600
|
||||
// while it is still empty (post-truncate, pre-write) -- the plaintext is
|
||||
// never on disk under a looser mode.
|
||||
let mut f = std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.mode(0o600)
|
||||
.open(&p)?;
|
||||
f.set_permissions(std::fs::Permissions::from_mode(0o600))?;
|
||||
f.write_all(format!("{user}\n{pass}\n").as_bytes())?;
|
||||
Ok(())
|
||||
// Owner-only from creation on (0600 on Unix, re-tightened if the file
|
||||
// already existed): the plaintext is never on disk under a looser mode.
|
||||
write_private(&p, format!("{user}\n{pass}\n").as_bytes())
|
||||
}
|
||||
|
||||
fn clear_creds_file(file: &str) -> std::io::Result<()> {
|
||||
@@ -164,20 +153,14 @@ pub fn save_firmware_credentials(map: &HashMap<String, (String, String)>) -> std
|
||||
if let Some(dir) = p.parent() {
|
||||
std::fs::create_dir_all(dir)?;
|
||||
}
|
||||
let mut f = std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.mode(0o600)
|
||||
.open(&p)?;
|
||||
f.set_permissions(std::fs::Permissions::from_mode(0o600))?;
|
||||
let mut names: Vec<&String> = map.keys().collect();
|
||||
names.sort();
|
||||
let mut body = String::new();
|
||||
for name in names {
|
||||
let (user, pass) = &map[name];
|
||||
f.write_all(format!("{name}\t{user}\t{pass}\n").as_bytes())?;
|
||||
body.push_str(&format!("{name}\t{user}\t{pass}\n"));
|
||||
}
|
||||
Ok(())
|
||||
write_private(&p, body.as_bytes())
|
||||
}
|
||||
|
||||
/// Remove the per-firmware overrides file, if any. Not an error if none exists.
|
||||
@@ -218,6 +201,20 @@ pub fn configured_factory() -> MinerFactory {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Unix: the file is mode 0600. Windows relies on the profile directory's
|
||||
/// owner-only ACL (see `alkane_core::platform::write_private`), so only
|
||||
/// existence is checked there.
|
||||
fn assert_owner_only(path: &std::path::Path, why: &str) {
|
||||
let meta = std::fs::metadata(path).unwrap();
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
assert_eq!(meta.permissions().mode() & 0o777, 0o600, "{why}");
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
assert!(meta.is_file(), "{why}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn credentials_round_trip_and_file_perms() {
|
||||
// config_path() reads $HOME; point it at a private temp dir. HOME is
|
||||
@@ -226,11 +223,12 @@ mod tests {
|
||||
let _home = crate::model::HOME_TEST_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
let prev = std::env::var_os("HOME");
|
||||
let root_var = alkane_core::platform::CONFIG_ROOT_VAR;
|
||||
let prev = std::env::var_os(root_var);
|
||||
let dir = std::env::temp_dir().join(format!("alkane-cred-test-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
std::env::set_var("HOME", &dir);
|
||||
std::env::set_var(root_var, &dir);
|
||||
|
||||
assert_eq!(load_credentials(), None, "no file -> None");
|
||||
|
||||
@@ -240,11 +238,9 @@ mod tests {
|
||||
Some(("admin".to_string(), "hunter2".to_string()))
|
||||
);
|
||||
|
||||
let meta = std::fs::metadata(config_path(CREDENTIALS_FILE)).unwrap();
|
||||
assert_eq!(
|
||||
meta.permissions().mode() & 0o777,
|
||||
0o600,
|
||||
"credentials file must be 0600"
|
||||
assert_owner_only(
|
||||
&config_path(CREDENTIALS_FILE),
|
||||
"credentials file must be 0600",
|
||||
);
|
||||
|
||||
// configured_factory() must construct in both branches without panicking:
|
||||
@@ -255,13 +251,15 @@ mod tests {
|
||||
// 0600 by save_credentials (the create-mode is ignored for an existing
|
||||
// file, so the explicit set_permissions is what protects it).
|
||||
let path = config_path(CREDENTIALS_FILE);
|
||||
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o644)).unwrap();
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o644)).unwrap();
|
||||
}
|
||||
save_credentials("admin2", "s3cr3t").unwrap();
|
||||
let meta = std::fs::metadata(&path).unwrap();
|
||||
assert_eq!(
|
||||
meta.permissions().mode() & 0o777,
|
||||
0o600,
|
||||
"save over a pre-existing 0644 file must re-tighten to 0600"
|
||||
assert_owner_only(
|
||||
&path,
|
||||
"save over a pre-existing 0644 file must re-tighten to 0600",
|
||||
);
|
||||
assert_eq!(
|
||||
load_credentials(),
|
||||
@@ -290,11 +288,7 @@ mod tests {
|
||||
save_firmware_credentials(&fw).unwrap();
|
||||
// 0600, and it round-trips (an empty username survives the tab format).
|
||||
let fwpath = config_path(FIRMWARE_CREDENTIALS_FILE);
|
||||
assert_eq!(
|
||||
std::fs::metadata(&fwpath).unwrap().permissions().mode() & 0o777,
|
||||
0o600,
|
||||
"per-firmware creds file must be 0600"
|
||||
);
|
||||
assert_owner_only(&fwpath, "per-firmware creds file must be 0600");
|
||||
let back = load_firmware_credentials();
|
||||
assert_eq!(
|
||||
back.get("WhatsMiner Stock"),
|
||||
@@ -322,8 +316,8 @@ mod tests {
|
||||
clear_firmware_credentials().unwrap(); // idempotent
|
||||
|
||||
match prev {
|
||||
Some(v) => std::env::set_var("HOME", v),
|
||||
None => std::env::remove_var("HOME"),
|
||||
Some(v) => std::env::set_var(root_var, v),
|
||||
None => std::env::remove_var(root_var),
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
@@ -71,10 +71,7 @@ static CURRENT: AtomicU8 = AtomicU8::new(0);
|
||||
const LANG_FILE: &str = "language.txt";
|
||||
|
||||
fn config_path() -> PathBuf {
|
||||
let home = std::env::var("HOME").unwrap_or_else(|_| ".".into());
|
||||
PathBuf::from(home)
|
||||
.join(".config/alkane-toolkit")
|
||||
.join(LANG_FILE)
|
||||
alkane_core::platform::config_path(LANG_FILE)
|
||||
}
|
||||
|
||||
/// Load the saved language into the global (call once at startup).
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
//! alkane-toolkit: primary view (docs/UI-SPEC.md).
|
||||
//! Pure-Rust wxWidgets app on the vendored, patched wx-rs.
|
||||
|
||||
// A GUI application on Windows: no console window opens behind it. The
|
||||
// headless modes below re-attach to the console they were started from.
|
||||
#![cfg_attr(windows, windows_subsystem = "windows")]
|
||||
|
||||
mod access_probe;
|
||||
mod askpass;
|
||||
mod credentials;
|
||||
mod export;
|
||||
mod fixtures;
|
||||
@@ -17,6 +22,15 @@ mod scan;
|
||||
mod ui;
|
||||
|
||||
fn main() {
|
||||
// ssh runs this executable as its askpass helper for password logins
|
||||
// (askpass.rs); answer and exit before anything else starts.
|
||||
if let Some(code) = askpass::serve_if_askpass() {
|
||||
std::process::exit(code);
|
||||
}
|
||||
if headless_mode() {
|
||||
attach_parent_console();
|
||||
}
|
||||
|
||||
// Headless workflow self-test: render the bench-fleet fixtures through the
|
||||
// real widgets and check the table + KPIs against the expected hardware
|
||||
// output. Run under a virtual display (see scripts/ui-selftest.sh).
|
||||
@@ -60,10 +74,10 @@ fn main() {
|
||||
// Load the saved UI language before any strings are built (round 15 #13).
|
||||
i18n::init();
|
||||
|
||||
// Bootstrap the wx app + main frame (upstream bridge).
|
||||
// Bootstrap the wx app + main frame (upstream bridge). This also picks the
|
||||
// light/dark appearance (system, or ALKANE_APPEARANCE=light|dark) before the
|
||||
// frame exists, which wxMSW requires.
|
||||
wx_rs::init_app("alkane-toolkit", 1280, 800);
|
||||
// Follow the system light/dark appearance.
|
||||
wx_rs::set_appearance_system();
|
||||
|
||||
// Build the UI-SPEC primary view into the frame.
|
||||
let frame = wx_rs::Widget::main_frame();
|
||||
@@ -92,3 +106,37 @@ fn run_selftest() -> i32 {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
/// True when the process runs one of the headless check modes instead of the GUI.
|
||||
fn headless_mode() -> bool {
|
||||
["ALKANE_SELFTEST", "ALKANE_ACCESS_PROBE", "ALKANE_LOG_SCAN"]
|
||||
.iter()
|
||||
.any(|v| std::env::var_os(v).is_some())
|
||||
}
|
||||
|
||||
/// A Windows GUI-subsystem process has no console, so output from the headless
|
||||
/// modes would vanish when they are run from a terminal. Attach to the parent's
|
||||
/// console in that case. Redirected output (pipes, files, CI) already has valid
|
||||
/// standard handles and is left alone.
|
||||
#[cfg(windows)]
|
||||
fn attach_parent_console() {
|
||||
type Handle = *mut core::ffi::c_void;
|
||||
const STD_OUTPUT_HANDLE: u32 = -11i32 as u32;
|
||||
const ATTACH_PARENT_PROCESS: u32 = u32::MAX;
|
||||
#[link(name = "kernel32")]
|
||||
extern "system" {
|
||||
fn GetStdHandle(which: u32) -> Handle;
|
||||
fn AttachConsole(process_id: u32) -> i32;
|
||||
}
|
||||
// SAFETY: plain Win32 calls with constant arguments; failure (no parent
|
||||
// console, already attached) is harmless and leaves the process unchanged.
|
||||
unsafe {
|
||||
let out = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if out.is_null() || out as isize == -1 {
|
||||
AttachConsole(ATTACH_PARENT_PROCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn attach_parent_console() {}
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
const CONFIG_DIR: &str = ".config/alkane-toolkit";
|
||||
|
||||
/// Which pool field a "+" menu belongs to.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum PoolField {
|
||||
@@ -72,8 +70,7 @@ pub const POOL_STRATUMS: &[(&str, &str)] = &[
|
||||
];
|
||||
|
||||
fn config_path(file: &str) -> PathBuf {
|
||||
let home = std::env::var("HOME").unwrap_or_else(|_| ".".into());
|
||||
PathBuf::from(home).join(CONFIG_DIR).join(file)
|
||||
alkane_core::platform::config_path(file)
|
||||
}
|
||||
|
||||
/// The user's saved values for `field`, in save order (most recent last).
|
||||
@@ -106,28 +103,9 @@ pub fn save_all(field: PoolField, values: &[String]) -> std::io::Result<usize> {
|
||||
Ok(out.len())
|
||||
}
|
||||
|
||||
/// Write `data` to `path` with owner-only (0600) permissions from creation on
|
||||
/// Unix, so a secret is never momentarily world-readable between write and chmod.
|
||||
/// `mode()` only takes effect when the file is created, so an already-existing
|
||||
/// file is also re-tightened; elsewhere this is a plain write.
|
||||
/// Saved pool values can carry worker passwords, so they are written owner-only.
|
||||
fn write_private(path: &std::path::Path, data: &[u8]) -> std::io::Result<()> {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::io::Write;
|
||||
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
||||
let mut f = std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.mode(0o600)
|
||||
.open(path)?;
|
||||
let _ = std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600));
|
||||
f.write_all(data)
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
std::fs::write(path, data)
|
||||
}
|
||||
alkane_core::platform::write_private(path, data)
|
||||
}
|
||||
|
||||
/// Trim every value, then drop empties, values equal to a built-in preset, and
|
||||
|
||||
@@ -249,21 +249,24 @@ fn restore_braiins(ip: &str, user: &str, pass: &str) -> (bool, String) {
|
||||
);
|
||||
}
|
||||
let target = format!("{user}@{ip}");
|
||||
// sshpass reads the password from $SSHPASS (-e) rather than argv (-p), so it
|
||||
// never shows up in the process list (round 18 #12). Host-key checking is
|
||||
// deliberately disabled: these are LAN miners whose SSH host key changes on
|
||||
// every reflash, so pinning it would break the very revert this performs.
|
||||
// BatchMode stops any interactive prompt from hanging out the 60 s cap.
|
||||
let mut cmd = Command::new("sshpass");
|
||||
cmd.env("SSHPASS", pass);
|
||||
cmd.arg("-e").arg("ssh");
|
||||
// The password reaches ssh through the toolkit's own askpass helper (its
|
||||
// environment, never argv, so it stays out of the process list; round 18
|
||||
// #12), which works the same with Linux OpenSSH and Windows' ssh.exe. One
|
||||
// password attempt and no terminal: a bad password fails fast instead of
|
||||
// hanging out the 60 s cap. Host-key checking is deliberately disabled: these
|
||||
// are LAN miners whose SSH host key changes on every reflash, so pinning it
|
||||
// would break the very revert this performs.
|
||||
let mut cmd = alkane_core::platform::quiet_command("ssh");
|
||||
if let Err(e) = crate::askpass::ssh_with_password(&mut cmd, pass) {
|
||||
return (false, e);
|
||||
}
|
||||
let known_hosts = format!("UserKnownHostsFile={}", alkane_core::platform::NULL_DEVICE);
|
||||
cmd.args(crate::askpass::PASSWORD_AUTH_OPTIONS);
|
||||
cmd.args([
|
||||
"-o",
|
||||
"StrictHostKeyChecking=no",
|
||||
"-o",
|
||||
"UserKnownHostsFile=/dev/null",
|
||||
"-o",
|
||||
"BatchMode=yes",
|
||||
&known_hosts,
|
||||
"-o",
|
||||
"ConnectTimeout=8",
|
||||
&target,
|
||||
@@ -375,7 +378,7 @@ struct CmdOutput {
|
||||
/// timed out (a black-holed host); otherwise returns stdout even on a non-zero
|
||||
/// exit (curl prints useful bodies/status on failures).
|
||||
fn curl(args: &[&str], stdin_data: Option<&[u8]>) -> Result<String, String> {
|
||||
let mut cmd = Command::new("curl");
|
||||
let mut cmd = alkane_core::platform::quiet_command("curl");
|
||||
cmd.args(args);
|
||||
let out = run_with_timeout(cmd, Duration::from_secs(15), stdin_data)?;
|
||||
if out.timed_out && out.stdout.is_empty() {
|
||||
|
||||
@@ -40,7 +40,6 @@ pub enum ScanMsg {
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
pub const CONFIG_DIR: &str = ".config/alkane-toolkit";
|
||||
pub const RANGES_FILE: &str = "scan-ranges.txt";
|
||||
pub const AUTO_FILE: &str = "auto-rescan-secs.txt";
|
||||
pub const SCAN_TIMEOUT_FILE: &str = "scan-timeout-secs.txt";
|
||||
@@ -128,9 +127,10 @@ pub fn save_scan_timeout(secs: u64) -> std::io::Result<()> {
|
||||
std::fs::write(p, secs.max(1).to_string())
|
||||
}
|
||||
|
||||
/// `file` inside the per-user settings directory (`~/.config/alkane-toolkit`,
|
||||
/// or `%APPDATA%\alkane-toolkit` on Windows; see `alkane_core::platform`).
|
||||
pub fn config_path(file: &str) -> PathBuf {
|
||||
let home = std::env::var("HOME").unwrap_or_else(|_| ".".into());
|
||||
PathBuf::from(home).join(CONFIG_DIR).join(file)
|
||||
alkane_core::platform::config_path(file)
|
||||
}
|
||||
|
||||
pub fn load_ranges() -> Vec<String> {
|
||||
@@ -2368,17 +2368,18 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn auto_secs_round_trip_and_defaults() {
|
||||
// config_path() reads $HOME; point it at a private temp dir. HOME is
|
||||
// process-global, so serialise against other HOME-mutating tests and
|
||||
// restore HOME afterward (round 18 #12).
|
||||
// config_path() reads the platform's config root ($HOME, or %APPDATA%
|
||||
// on Windows); point it at a private temp dir. It is process-global, so
|
||||
// serialise against other such tests and restore it afterward (round 18 #12).
|
||||
let _home = crate::model::HOME_TEST_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
let prev = std::env::var_os("HOME");
|
||||
let root_var = alkane_core::platform::CONFIG_ROOT_VAR;
|
||||
let prev = std::env::var_os(root_var);
|
||||
let dir = std::env::temp_dir().join(format!("alkane-test-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
std::env::set_var("HOME", &dir);
|
||||
std::env::set_var(root_var, &dir);
|
||||
|
||||
assert_eq!(
|
||||
load_auto_secs(),
|
||||
@@ -2393,8 +2394,8 @@ mod tests {
|
||||
assert_eq!(load_auto_secs(), 42, "whitespace tolerated");
|
||||
|
||||
match prev {
|
||||
Some(v) => std::env::set_var("HOME", v),
|
||||
None => std::env::remove_var("HOME"),
|
||||
Some(v) => std::env::set_var(root_var, v),
|
||||
None => std::env::remove_var(root_var),
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user