(Broken state) Added example TOML

- Add example TOML
- Fix formatting for print_banner()
This commit is contained in:
Kevin Dorner 2022-03-22 00:19:33 +01:00
parent a37e9e1d69
commit 2bdeef98c1
2 changed files with 16 additions and 9 deletions

7
src/config.toml Normal file
View File

@ -0,0 +1,7 @@
hostname = "mein-iserv.de"
session-cookie = "markus"
[target]
ip = 10.0.0.0
room = 23
compilation = 2

View File

@ -4,21 +4,21 @@ use clap::Parser;
#[clap(author, version, about, long_about = None)] #[clap(author, version, about, long_about = None)]
struct Args { struct Args {
#[clap(short, long)] #[clap(short, long)]
hostname: String, hostname: Option<String>,
//example: "IServSAT=mvuvFvCZSlpvuwhk0mmNwF1NKEQypM4d; IServSession=xEPqyJO1a5nsVd34HEpbPqQGMMQKapvw; nav-show-additional-modules=true; PHPSESSID=mchbrl11epjnnp851q0i4rt8rc" //example: "IServSAT=mvuvFvCZSlpvuwhk0mmNwF1NKEQypM4d; IServSession=xEPqyJO1a5nsVd34HEpbPqQGMMQKapvw; nav-show-additional-modules=true; PHPSESSID=mchbrl11epjnnp851q0i4rt8rc"
#[clap(short, long)] #[clap(short, long)]
session_cookie: String, session_cookie: Option<String>,
#[clap(long)] #[clap(long)]
target_ip: String, target_ip: Option<String>,
#[clap(long)] #[clap(long)]
target_room: u16, target_room: Option<u16>,
#[clap(long)] #[clap(long)]
target_compilation: Option<u16>, target_compilation: Option<u16>,
} }
macro_rules! print_banner { macro_rules! print_banner {
($f: expr, $($arg: expr),*) => { ($f: expr, $($arg: expr),*) => {
println!(concat!("-----------------------------------\n", $f, "\n-----------------------------------"), $($arg),*) println!(concat!("----------------------------------------\n", $f, "\n----------------------------------------"), $($arg),*)
}; };
} }
@ -37,7 +37,7 @@ fn ipad(args: &Args) -> Result<(), Box<dyn std::error::Error>> {
let header = ("Cookie", &args.session_cookie); let header = ("Cookie", &args.session_cookie);
let client = reqwest::blocking::Client::new(); let client = reqwest::blocking::Client::new();
let resp = client let resp = client
.get(format!("https://{}/iserv/admin/hosts", args.hostname)) .get(format!("https://{}/iserv/admin/hosts", args.hostname.unwrap()))
.header(header.0, header.1) .header(header.0, header.1)
.query(&params) .query(&params)
.send()?; .send()?;
@ -55,9 +55,9 @@ fn ipad(args: &Args) -> Result<(), Box<dyn std::error::Error>> {
// skip rest of loop when no entry appeared // skip rest of loop when no entry appeared
if json_part == "null" { if json_part == "null" {
println!( println!(
"################################### "########################################
No new host: skipping (Retry in 5s) No new host: skipping (Retry in 5s)
################################### ########################################
"); ");
//sleep for 5 seconds //sleep for 5 seconds
std::thread::sleep(std::time::Duration::from_secs(5)); std::thread::sleep(std::time::Duration::from_secs(5));
@ -76,7 +76,7 @@ No new host: skipping (Retry in 5s)
return Ok(()) return Ok(())
} }
let plain = &resp.text()?; let plain = &resp.text()?;
let mut form_ip: &str = &args.target_ip; //default let mut form_ip: &str = &args.target_ip;
let form_name = squeeze_html_form(plain, "name=\"host[name]\"", "value=\"", "\""); let form_name = squeeze_html_form(plain, "name=\"host[name]\"", "value=\"", "\"");
let form_tags = squeeze_html_form(plain, "name=\"host[tags][]\"", "value=\"", "\""); let form_tags = squeeze_html_form(plain, "name=\"host[tags][]\"", "value=\"", "\"");
let form_mac = squeeze_html_form(plain, "name=\"host[mac]\"", "value=\"", "\""); let form_mac = squeeze_html_form(plain, "name=\"host[mac]\"", "value=\"", "\"");