1 Commits
async ... 1.0.2

Author SHA1 Message Date
c699bf1849 Format Rust code using rustfmt 2023-07-03 12:54:56 +00:00
3 changed files with 50 additions and 47 deletions

3
Cargo.lock generated
View File

@ -1043,7 +1043,7 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]]
name = "rexec"
version = "1.0.3"
version = "1.0.2"
dependencies = [
"brace-expand",
"clap 4.3.4",
@ -1056,7 +1056,6 @@ dependencies = [
"log",
"massh",
"regex",
"tokio",
"whoami",
]

View File

@ -1,6 +1,6 @@
[package]
name = "rexec"
version = "1.0.3"
version = "1.0.2"
edition = "2021"
description = "Parallel SSH executor"
repository = "https://github.com/house-of-vanity/rexec"
@ -12,7 +12,6 @@ authors = ["AB <gh@hexor.ru>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1", features = ["full"] }
dns-lookup = "2.0.2"
log = "0.4.0"
env_logger = "0.10.0"

View File

@ -77,41 +77,48 @@ fn read_known_hosts() -> Vec<Host> {
result
}
fn expand_range(start: i32, end: i32) -> Vec<String> {
(start..=end).map(|i| i.to_string()).collect()
}
fn expand_list(list: &str) -> Vec<String> {
list.split(',').map(|s| s.to_string()).collect()
}
fn expand_string(s: &str) -> Vec<Host> {
fn expand_string(string: String) -> Vec<Host> {
let mut result: Vec<String> = Vec::new();
let mut _result: Vec<String> = Vec::new();
let mut hosts: Vec<Host> = Vec::new();
let mut result = vec![s.to_string()];
while let Some(r) = result.iter().find(|s| s.contains('[')) {
let r = r.clone();
let start = r.find('[').unwrap();
let end = r.find(']').unwrap();
let colon = r.find(':').unwrap();
let low = r[start+1..colon].parse::<i32>().unwrap();
let high = r[colon+1..end].parse::<i32>().unwrap();
result.retain(|s| s != &r);
for val in expand_range(low, high) {
let new_str = format!("{}{}{}", &r[..start], val, &r[end+1..]);
result.push(new_str);
if let Some(open_bracket_index) = string.find('[') {
if let Some(close_bracket_index) = string.find(']') {
let prefix = &string[..open_bracket_index];
let range = &string[open_bracket_index + 1..close_bracket_index];
let postfix = &string[close_bracket_index + 1..];
let parts: Vec<&str> = range.split(':').collect();
if parts.len() == 2 {
if let Ok(start) = parts[0].parse::<u32>() {
if let Ok(end) = parts[1].parse::<u32>() {
for num in start..=end {
_result.push(format!("{}{}{}", prefix, num, postfix));
}
}
}
}
}
} else {
_result.push(String::from(string));
}
while let Some(r) = result.iter().find(|s| s.contains('{')) {
let r = r.clone();
let start = r.find('{').unwrap();
let end = r.find('}').unwrap();
let list = &r[start+1..end];
result.retain(|s| s != &r);
for val in expand_list(list) {
let new_str = format!("{}{}{}", &r[..start], val, &r[end+1..]);
result.push(new_str);
for string in _result {
if let Some(open_brace_index) = string.find('{') {
if let Some(close_brace_index) = string.find('}') {
let prefix = &string[..open_brace_index];
let list = &string[open_brace_index + 1..close_brace_index];
let postfix = &string[close_brace_index + 1..];
let items: Vec<&str> = list.split(',').collect();
for item in items {
result.push(format!("{}{}{}", prefix, item, postfix));
}
}
} else {
result.push(String::from(string));
}
}
@ -124,8 +131,7 @@ fn expand_string(s: &str) -> Vec<Host> {
hosts
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
fn main() {
env_logger::Builder::from_env(Env::default().default_filter_or("info"))
.format_timestamp(None)
.format_target(false)
@ -150,7 +156,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.collect()
} else {
info!("Using string expansion to build server list.");
expand_string(&args.expression)
expand_string(args.expression)
};
// Dedup hosts from known_hosts file
@ -242,5 +248,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} else {
warn!("Stopped");
}
Ok(())
}