p2pool/xmrig: add address/path check before allowing [Start]

This commit is contained in:
hinto-janaiyo 2022-12-08 20:24:37 -05:00
parent a3802ef4f7
commit 6dbf0386c4
No known key found for this signature in database
GPG key ID: B1C5A64B80691E45
6 changed files with 68 additions and 40 deletions

38
Cargo.lock generated
View file

@ -488,9 +488,9 @@ dependencies = [
[[package]] [[package]]
name = "calloop" name = "calloop"
version = "0.10.3" version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bcf530afb40e45e14440701e5e996d7fd139e84a912a4d83a8d6a0fb3e58663" checksum = "19457a0da465234abd76134a5c2a910c14bd3c5558463e4396ab9a37a328e465"
dependencies = [ dependencies = [
"log", "log",
"nix 0.25.1", "nix 0.25.1",
@ -645,9 +645,9 @@ dependencies = [
[[package]] [[package]]
name = "config" name = "config"
version = "0.13.2" version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11f1667b8320afa80d69d8bbe40830df2c8a06003d86f73d8e003b2c48df416d" checksum = "d379af7f68bfc21714c6c7dea883544201741d2ce8274bb12fa54f89507f52a7"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"lazy_static", "lazy_static",
@ -1370,9 +1370,9 @@ dependencies = [
[[package]] [[package]]
name = "filetime" name = "filetime"
version = "0.2.18" version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b9663d381d07ae25dc88dbdf27df458faa83a9b25336bcac83d5e452b5fc9d3" checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
@ -2655,9 +2655,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]] [[package]]
name = "openssl" name = "openssl"
version = "0.10.43" version = "0.10.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "020433887e44c27ff16365eaa2d380547a94544ad509aff6eb5b6e3e0b27b376" checksum = "29d971fd5722fec23977260f6e81aa67d2f22cadbdc2aa049f1022d9a3be1566"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cfg-if", "cfg-if",
@ -2696,9 +2696,9 @@ dependencies = [
[[package]] [[package]]
name = "openssl-sys" name = "openssl-sys"
version = "0.9.78" version = "0.9.79"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07d5c8cb6e57b3a3612064d7b18b117912b4ce70955c2504d4b741c9e244b132" checksum = "5454462c0eced1e97f2ec09036abc8da362e66802f66fd20f86854d9d8cbcbc4"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"cc", "cc",
@ -3399,18 +3399,18 @@ checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.148" version = "1.0.149"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc" checksum = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.148" version = "1.0.149"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c" checksum = "b4eae9b04cbffdfd550eb462ed33bc6a1b68c935127d008b27444d08380f94e4"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -4025,9 +4025,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.22.0" version = "1.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"bytes", "bytes",
@ -4039,7 +4039,7 @@ dependencies = [
"signal-hook-registry", "signal-hook-registry",
"socket2", "socket2",
"tokio-macros", "tokio-macros",
"winapi", "windows-sys 0.42.0",
] ]
[[package]] [[package]]
@ -4667,9 +4667,9 @@ checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff"
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.15.0" version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]] [[package]]
name = "uncased" name = "uncased"

View file

@ -139,7 +139,8 @@ r#"Use advanced Gupax settings:
- Update button - Update button
- Basic toggles - Basic toggles
- P2Pool/XMRig binary path selector - P2Pool/XMRig binary path selector
- Gupax resolution sliders"#; - Gupax resolution sliders
- Gupax start-up tab selector"#;
pub const GUPAX_SELECT: &str = "Open a file explorer to select a file"; pub const GUPAX_SELECT: &str = "Open a file explorer to select a file";
pub const GUPAX_PATH_P2POOL: &str = "The location of the P2Pool binary: Both absolute and relative paths are accepted; A red [X] will appear if there is no file found at the given path"; pub const GUPAX_PATH_P2POOL: &str = "The location of the P2Pool binary: Both absolute and relative paths are accepted; A red [X] will appear if there is no file found at the given path";
pub const GUPAX_PATH_XMRIG: &str = "The location of the XMRig binary: Both absolute and relative paths are accepted; A red [X] will appear if there is no file found at the given path"; pub const GUPAX_PATH_XMRIG: &str = "The location of the XMRig binary: Both absolute and relative paths are accepted; A red [X] will appear if there is no file found at the given path";
@ -154,7 +155,7 @@ pub const P2POOL_AUTO_NODE: &str = "Automatically ping the community Monero node
pub const P2POOL_AUTO_SELECT: &str = "Automatically select the fastest community Monero node after pinging"; pub const P2POOL_AUTO_SELECT: &str = "Automatically select the fastest community Monero node after pinging";
pub const P2POOL_SELECT_FASTEST: &str = "Select the fastest community Monero node"; pub const P2POOL_SELECT_FASTEST: &str = "Select the fastest community Monero node";
pub const P2POOL_PING: &str = "Ping the built-in community Monero nodes"; pub const P2POOL_PING: &str = "Ping the built-in community Monero nodes";
pub const P2POOL_ADDRESS: &str = "You must use a primary Monero address to mine on P2Pool (starts with a 4). It is highly recommended to create a new wallet for P2Pool mining; wallet addresses are public on P2Pool!"; pub const P2POOL_ADDRESS: &str = "You must use a primary Monero address to mine on P2Pool (starts with a 4). It is highly recommended to create a new wallet since addresses are public on P2Pool!";
pub const P2POOL_ARGUMENTS: &str = "Start P2Pool with these arguments and override all below settings; If the [--data-api] & [--local-api] flag is not given, Gupax will append it to the arguments automatically so that the [Status] tab can work"; pub const P2POOL_ARGUMENTS: &str = "Start P2Pool with these arguments and override all below settings; If the [--data-api] & [--local-api] flag is not given, Gupax will append it to the arguments automatically so that the [Status] tab can work";
pub const P2POOL_SIMPLE: &str = pub const P2POOL_SIMPLE: &str =
r#"Use simple P2Pool settings: r#"Use simple P2Pool settings:
@ -162,6 +163,7 @@ r#"Use simple P2Pool settings:
- Default P2Pool settings + Mini"#; - Default P2Pool settings + Mini"#;
pub const P2POOL_ADVANCED: &str = pub const P2POOL_ADVANCED: &str =
r#"Use advanced P2Pool settings: r#"Use advanced P2Pool settings:
- Terminal input
- Overriding command arguments - Overriding command arguments
- Manual node list - Manual node list
- P2Pool Main/Mini selection - P2Pool Main/Mini selection
@ -171,6 +173,7 @@ pub const P2POOL_NAME: &str = "Add a unique name to identify this node; Only [A-
pub const P2POOL_NODE_IP: &str = "Specify the Monero Node IP to connect to with P2Pool; It must be a valid IPv4 address or a valid domain name; Max length = 255 characters"; pub const P2POOL_NODE_IP: &str = "Specify the Monero Node IP to connect to with P2Pool; It must be a valid IPv4 address or a valid domain name; Max length = 255 characters";
pub const P2POOL_RPC_PORT: &str = "Specify the RPC port of the Monero node; [1-65535]"; pub const P2POOL_RPC_PORT: &str = "Specify the RPC port of the Monero node; [1-65535]";
pub const P2POOL_ZMQ_PORT: &str = "Specify the ZMQ port of the Monero node; [1-65535]"; pub const P2POOL_ZMQ_PORT: &str = "Specify the ZMQ port of the Monero node; [1-65535]";
pub const P2POOL_PATH_NOT_EXE: &str = "P2Pool binary not found at the given path in the Gupax tab!";
// Node/Pool list // Node/Pool list
pub const LIST_ADD: &str = "Add the current values to the list"; pub const LIST_ADD: &str = "Add the current values to the list";
@ -186,6 +189,7 @@ r#"Use simple XMRig settings:
- HTTP API @ localhost:18088"#; - HTTP API @ localhost:18088"#;
pub const XMRIG_ADVANCED: &str = pub const XMRIG_ADVANCED: &str =
r#"Use advanced XMRig settings: r#"Use advanced XMRig settings:
- Terminal input
- Overriding config file - Overriding config file
- Custom payout address - Custom payout address
- CPU thread slider - CPU thread slider
@ -194,17 +198,18 @@ r#"Use advanced XMRig settings:
- Keepalive setting - Keepalive setting
- Custom HTTP API IP/Port"#; - Custom HTTP API IP/Port"#;
pub const XMRIG_ARGUMENTS: &str = "Start XMRig with these arguments and override all below settings; If the [http-api] options are not set, Gupax will append it to the arguments automatically so that the [Status] tab can work"; pub const XMRIG_ARGUMENTS: &str = "Start XMRig with these arguments and override all below settings; If the [http-api] options are not set, Gupax will append it to the arguments automatically so that the [Status] tab can work";
pub const XMRIG_ADDRESS: &str = "Specify which Monero address to send payouts to; Must be a valid primary address (starts with 4)"; pub const XMRIG_ADDRESS: &str = "Specify which Monero address to payout to. This does nothing if mining to P2Pool since the address being payed out to will be the one P2Pool started with. This doubles as a rig identifier for P2Pool and some pools.";
pub const XMRIG_NAME: &str = "Add a unique name to identify this pool; Only [A-Za-z0-9-_] and spaces allowed; Max length = 30 characters"; pub const XMRIG_NAME: &str = "Add a unique name to identify this pool; Only [A-Za-z0-9-_] and spaces allowed; Max length = 30 characters";
pub const XMRIG_IP: &str = "Specify the pool IP to connect to with XMRig; It must be a valid IPv4 address or a valid domain name; Max length = 255 characters"; pub const XMRIG_IP: &str = "Specify the pool IP to connect to with XMRig; It must be a valid IPv4 address or a valid domain name; Max length = 255 characters";
pub const XMRIG_PORT: &str = "Specify the port of the pool; [1-65535]"; pub const XMRIG_PORT: &str = "Specify the port of the pool; [1-65535]";
pub const XMRIG_RIG: &str = "Add an optional rig ID. This will be the name shown on the pool; Only [A-Za-z0-9-_] and spaces allowed; Max length = 30 characters"; pub const XMRIG_RIG: &str = "Add an optional rig ID. This will be the name shown on the pool; Only [A-Za-z0-9-_] and spaces allowed; Max length = 30 characters";
pub const XMRIG_PAUSE: &str = "THIS SETTING IS DISABLED IF SET TO [0]. Pause mining if user is active, resume after"; pub const XMRIG_PAUSE: &str = "THIS SETTING IS DISABLED IF SET TO [0]. Pause mining if user is active, resume after";
pub const XMRIG_API_IP: &str = "Specify which IP to bind to for XMRig's HTTP API"; pub const XMRIG_API_IP: &str = "Specify which IP to bind to for XMRig's HTTP API; If empty: [localhost/127.0.0.1]";
pub const XMRIG_API_PORT: &str = "Specify which port to bind to for XMRig's HTTP API"; pub const XMRIG_API_PORT: &str = "Specify which port to bind to for XMRig's HTTP API; If empty: [18088]";
pub const XMRIG_TLS: &str = "Enable SSL/TLS connections (needs pool support)"; pub const XMRIG_TLS: &str = "Enable SSL/TLS connections (needs pool support)";
pub const XMRIG_KEEPALIVE: &str = "Send keepalived packet to prevent timeout (needs pool support)"; pub const XMRIG_KEEPALIVE: &str = "Send keepalived packet to prevent timeout (needs pool support)";
pub const XMRIG_THREADS: &str = "Number of CPU threads to use for mining"; pub const XMRIG_THREADS: &str = "Number of CPU threads to use for mining";
pub const XMRIG_PATH_NOT_EXE: &str = "XMRig binary not found at the given path in the Gupax tab!";
// CLI argument messages // CLI argument messages
pub const ARG_HELP: &str = pub const ARG_HELP: &str =

View file

@ -159,15 +159,9 @@ impl Gupax {
if self.xmrig_path.is_empty() { if self.xmrig_path.is_empty() {
ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ").color(LIGHT_GRAY))); ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ").color(LIGHT_GRAY)));
} else { } else {
match crate::disk::into_absolute_path(self.xmrig_path.clone()) { match Self::path_is_exe(&self.xmrig_path) {
Ok(path) => { true => ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ✔").color(GREEN))),
if path.is_file() { false => ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ❌").color(RED))),
ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ✔").color(GREEN)))
} else {
ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ❌").color(RED)))
}
},
_ => ui.add_sized([text_edit, height], Label::new(RichText::new(" XMRig Binary Path ❌").color(RED))),
}; };
} }
ui.spacing_mut().text_edit_width = ui.available_width() - SPACE; ui.spacing_mut().text_edit_width = ui.available_width() - SPACE;
@ -246,6 +240,15 @@ impl Gupax {
})}); })});
} }
// Checks if a path is a valid path to an executable.
pub fn path_is_exe(path: &str) -> bool {
let path = path.to_string();
match crate::disk::into_absolute_path(path) {
Ok(path) => if path.is_file() { true } else { false },
_ => false,
}
}
fn spawn_file_window_thread(file_window: &Arc<Mutex<FileWindow>>, file_type: FileType) { fn spawn_file_window_thread(file_window: &Arc<Mutex<FileWindow>>, file_type: FileType) {
use FileType::*; use FileType::*;
let name = match file_type { let name = match file_type {

View file

@ -655,14 +655,15 @@ impl Helper {
} }
// Else, build the argument // Else, build the argument
} else { } else {
let api_ip = if state.api_ip == "localhost" { "127.0.0.1".to_string() } else { state.api_ip.to_string() }; // XMRig doesn't understand [localhost] let api_ip = if state.api_ip == "localhost" || state.api_ip.is_empty() { "127.0.0.1" } else { &state.api_ip }; // XMRig doesn't understand [localhost]
let url = format!("{}:{}", state.selected_ip, state.selected_port); // Combine IP:Port into one string let api_port = if state.selected_port.is_empty() { "18088" } else { &state.selected_port };
let url = format!("{}:{}", api_ip, api_port); // Combine IP:Port into one string
args.push("--user".to_string()); args.push(state.address.clone()); // Wallet args.push("--user".to_string()); args.push(state.address.clone()); // Wallet
args.push("--threads".to_string()); args.push(state.current_threads.to_string()); // Threads args.push("--threads".to_string()); args.push(state.current_threads.to_string()); // Threads
args.push("--rig-id".to_string()); args.push(state.selected_rig.to_string()); // Rig ID args.push("--rig-id".to_string()); args.push(state.selected_rig.to_string()); // Rig ID
args.push("--url".to_string()); args.push(url.clone()); // IP/Port args.push("--url".to_string()); args.push(url.clone()); // IP/Port
args.push("--http-host".to_string()); args.push(api_ip); // HTTP API IP args.push("--http-host".to_string()); args.push(api_ip.to_string()); // HTTP API IP
args.push("--http-port".to_string()); args.push(state.api_port.to_string()); // HTTP API Port args.push("--http-port".to_string()); args.push(api_port.to_string()); // HTTP API Port
args.push("--no-color".to_string()); // No color escape codes args.push("--no-color".to_string()); // No color escape codes
if state.tls { args.push("--tls".to_string()); } // TLS if state.tls { args.push("--tls".to_string()); } // TLS
if state.keepalive { args.push("--keepalive".to_string()); } // Keepalive if state.keepalive { args.push("--keepalive".to_string()); } // Keepalive

View file

@ -492,6 +492,11 @@ impl Regexes {
port: Regex::new(r#"^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$"#).unwrap(), port: Regex::new(r#"^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$"#).unwrap(),
} }
} }
// Check if a Monero address is correct.
pub fn addr_ok(&self, address: &str) -> bool {
address.len() == 95 && Regex::is_match(&self.address, &address) && !address.contains('0') && !address.contains('O') && !address.contains('l')
}
} }
//---------------------------------------------------------------------------------------------------- Init functions //---------------------------------------------------------------------------------------------------- Init functions
@ -1137,7 +1142,16 @@ impl eframe::App for App {
ui.add_sized([width, height], Button::new("")).on_hover_text("Restart P2Pool"); ui.add_sized([width, height], Button::new("")).on_hover_text("Restart P2Pool");
ui.add_sized([width, height], Button::new("")).on_hover_text("Stop P2Pool"); ui.add_sized([width, height], Button::new("")).on_hover_text("Stop P2Pool");
}); });
if ui.add_sized([width, height], Button::new("")).on_hover_text("Start P2Pool").clicked() { // Check if address is okay before allowing to start.
let mut text = String::new();
if !Regexes::addr_ok(&self.regex, &self.state.p2pool.address) {
ui.set_enabled(false);
text = P2POOL_ADDRESS.to_string();
} else if !Gupax::path_is_exe(&self.state.gupax.p2pool_path) {
ui.set_enabled(false);
text = P2POOL_PATH_NOT_EXE.to_string();
}
if ui.add_sized([width, height], Button::new("")).on_hover_text("Start P2Pool").on_disabled_hover_text(text).clicked() {
Helper::start_p2pool(&self.helper, &self.state.p2pool, &self.state.gupax.absolute_p2pool_path); Helper::start_p2pool(&self.helper, &self.state.p2pool, &self.state.gupax.absolute_p2pool_path);
} }
} }
@ -1178,7 +1192,12 @@ impl eframe::App for App {
ui.add_sized([width, height], Button::new("")).on_hover_text("Restart XMRig"); ui.add_sized([width, height], Button::new("")).on_hover_text("Restart XMRig");
ui.add_sized([width, height], Button::new("")).on_hover_text("Stop XMRig"); ui.add_sized([width, height], Button::new("")).on_hover_text("Stop XMRig");
}); });
if ui.add_sized([width, height], Button::new("")).on_hover_text("Start XMRig").clicked() { let mut text = String::new();
if !Gupax::path_is_exe(&self.state.gupax.xmrig_path) {
ui.set_enabled(false);
text = XMRIG_PATH_NOT_EXE.to_string();
}
if ui.add_sized([width, height], Button::new("")).on_hover_text("Start XMRig").on_disabled_hover_text(text).clicked() {
self.sudo.lock().unwrap().signal = ProcessSignal::Start; self.sudo.lock().unwrap().signal = ProcessSignal::Start;
self.error_state.ask_sudo(&self.sudo); self.error_state.ask_sudo(&self.sudo);
} }

View file

@ -93,7 +93,7 @@ impl P2pool {
if self.address.is_empty() { if self.address.is_empty() {
text = format!("Monero Address [{}/95] ", len); text = format!("Monero Address [{}/95] ", len);
color = Color32::LIGHT_GRAY; color = Color32::LIGHT_GRAY;
} else if self.address.len() == 95 && Regex::is_match(&regex.address, &self.address) && ! self.address.contains('0') && ! self.address.contains('O') && ! self.address.contains('l') { } else if Regexes::addr_ok(&regex, &self.address) {
text = format!("Monero Address [{}/95] ✔", len); text = format!("Monero Address [{}/95] ✔", len);
color = Color32::from_rgb(100, 230, 100); color = Color32::from_rgb(100, 230, 100);
} else { } else {