diff --git a/src/main.rs b/src/main.rs index 3cc34fc..1147bd7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,11 +34,11 @@ fn ipad(args: &Args) -> Result<(), Box> { ("filter[group]", ""), ("filter[search]", "iPad"), ]; - let header = ("Cookie", args.session_cookie.to_owned()); + let header = ("Cookie", &args.session_cookie); let client = reqwest::blocking::Client::new(); let resp = client .get(format!("https://{}/iserv/admin/hosts", args.hostname)) - .header(header.0, header.to_owned().1) + .header(header.0, header.1) .query(¶ms) .send()?; let status = &resp.status(); @@ -65,10 +65,10 @@ No new host: skipping (Retry in 5s) } let host_id = squeeze(json_part, "data-host-id=\"", "\""); let device_name = squeeze(json_part, "", ""); - print_banner!("1/7 Found host\nHost id: {}\nDevice name: {}\nReceived response status: {:?}", host_id, device_name, status); + print_banner!("1/8 Found host\nHost id: {}\nDevice name: {}\nReceived response status: {:?}", host_id, device_name, status); let dest = format!("https://{}/iserv/admin/host/edit/{}", args.hostname, &host_id); - let resp = client.get(&dest).header(header.0, header.to_owned().1).send()?; + let resp = client.get(&dest).header(header.0, header.1).send()?; //TODO Check for non 200 response let status = &resp.status(); if !status.is_success() && *status != 300 { @@ -101,38 +101,40 @@ No new host: skipping (Retry in 5s) ("host[actions][submit]", ""), ("host[_token]", form_token), ]; - print_banner!("2/7 Received current host properties\nReceived response status: {:?}", status); + print_banner!("2/8 Received current host properties\nReceived response status: {:?}", status); + let resp = client .post(&dest) - .header(header.0, header.to_owned().1) + .header(header.0, header.1) .form(&form_data) .send()?; let status = &resp.status(); let plain = &resp.text()?; form_ip = squeeze_html_form(plain, "name=\"host[ip]\"", "value=\"", "\""); form_data[3] = ("host[ip]", form_ip); - print_banner!("3/7 Received recommended ip: {}\nReceived response status: {:?}", form_ip, status); + print_banner!("3/8 Received recommended ip: {}\nReceived response status: {:?}", form_ip, status); + let resp = client .post(&dest) - .header(header.0, header.to_owned().1) + .header(header.0, header.1) .form(&form_data) .send()?; let status = &resp.status(); - print_banner!("4/7 Sucessfully updated host\nReceived response status: {:?}", status); + print_banner!("4/8 Sucessfully updated host\nReceived response status: {:?}", status); + if args.target_compilation.is_none() { return Ok(()) } let resp = client .get(format!("https://{}/iserv/admin/mdm/ios/compilation/edit/{}", args.hostname, args.target_compilation.unwrap())) - .header(header.0, header.to_owned().1) + .header(header.0, header.1) .send()?; //TODO Check for non 200 response let status = &resp.status(); let plain = &resp.text()?; - print_banner!("5/7 Received MDM compilation\nReceived response status: {:?}", status); - - //let csrf_token = squeeze_html_form(plain, "name=\"ioscompilation[_token]\"", "value=\"", "\""); + print_banner!("5/8 Received MDM compilation\nReceived response status: {:?}", status); + let mut form_data = Vec::from([ ( "ioscompilation[name]", @@ -143,16 +145,19 @@ No new host: skipping (Retry in 5s) squeeze_html_form(plain, "name=\"ioscompilation[description]\"", "value=\"", "\"") ), ].map(|(a, b)| (Cow::Borrowed(a), Cow::Borrowed(b)))); - + // push apps (