Pretty big refactor - Only the last step is broken
This commit is contained in:
parent
a6f4357ded
commit
0059bcd91b
73
src/main.rs
73
src/main.rs
|
@ -18,7 +18,7 @@ struct Args {
|
|||
target_room: u16,
|
||||
|
||||
#[clap(long)]
|
||||
target_compilation: u16,
|
||||
target_compilation: Option<u16>,
|
||||
|
||||
}
|
||||
|
||||
|
@ -141,9 +141,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
println!("Received response status: {:?}", status);
|
||||
println!("-----------------------------------");
|
||||
|
||||
if args.target_compilation.is_none() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let resp = client
|
||||
.get(format!("https://{}/iserv/admin/mdm/ios/compilation/edit/1", args.hostname))
|
||||
.get(format!("https://{}/iserv/admin/mdm/ios/compilation/edit/{}", args.hostname, args.target_compilation.unwrap()))
|
||||
.header(header.0, header.to_owned().1)
|
||||
.send()?;
|
||||
//TODO Check for non 200 response
|
||||
|
@ -156,6 +159,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
println!("Received response status: {:?}", status);
|
||||
println!("-----------------------------------");
|
||||
|
||||
let csrf_token = squeeze_html_form(plain, "name=\"ioscompilation[_token]\"", "value=\"", "\"");
|
||||
|
||||
let mut form_data = Vec::from([
|
||||
(
|
||||
|
@ -180,37 +184,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let plain_inner_devices = squeeze_html_form(plain, "name=\"ioscompilation[devices][]\"", ">", "</select>");
|
||||
form_data.append(&mut squeeze_loop(plain_inner_devices, "<option value=\"", "\"", " selected=\"selected\"", 3, "ioscompilation[devices][]"));
|
||||
|
||||
/*
|
||||
let re =
|
||||
regex::Regex::new(r#"<option value="(\d+)" selected="selected">(iPad-\w+)</option>"#)
|
||||
.unwrap();
|
||||
form_data.extend(
|
||||
re.captures_iter(plain)
|
||||
.map(|cap| ("ioscompilation[devices][]".into(), cap[1].to_owned().into())),
|
||||
); */
|
||||
|
||||
// push new device
|
||||
let mdm_new_ipad_id = squeeze_right(plain_inner_devices, "<option value=\"", &format!("\">{}", form_name));
|
||||
if plain_inner_devices.contains(form_name) {
|
||||
form_data.push(("ioscompilation[devices][]".into(), squeeze_right(plain_inner_devices, "<option value=\"", &format!("\">{}", form_name)).into()));
|
||||
form_data.push(("ioscompilation[devices][]".into(), mdm_new_ipad_id.into()));
|
||||
} else {
|
||||
eprintln!("Device not found in compilation edit.")
|
||||
}
|
||||
|
||||
/*
|
||||
let re = regex::Regex::new(&format!(
|
||||
"<option value=\"(\\d+)\">({})</option>",
|
||||
form_name
|
||||
))
|
||||
.unwrap();
|
||||
let mut iter = re
|
||||
.captures_iter(plain)
|
||||
.map(|cap| ("ioscompilation[devices][]".into(), cap[1].to_owned().into()));
|
||||
form_data.push(iter.next().expect("Device not found in compilation edit"));
|
||||
if iter.next().is_none() {
|
||||
eprintln!("Expected single device match, found multiple");
|
||||
eprintln!("Perhaps the item already was added to the compilation");
|
||||
};*/
|
||||
|
||||
// push submit action
|
||||
form_data.push(("ioscompilation[actions][submit]".into(), "".into()));
|
||||
|
||||
|
@ -218,20 +199,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let form_token = squeeze_html_form(plain, "name=\"ioscompilation[_token]\"", "value=\"", "\"");
|
||||
form_data.push(("ioscompilation[_token]".into(), form_token.into()));
|
||||
|
||||
println!("{:#?}", form_data);
|
||||
|
||||
//remove me
|
||||
//std::fs::write("plain.out", &plain).unwrap();
|
||||
continue;
|
||||
|
||||
let resp = client
|
||||
.post(format!("https://{}/iserv/admin/mdm/ios/compilation/edit/1", args.hostname))
|
||||
.post(format!("https://{}/iserv/admin/mdm/ios/compilation/edit/{}", args.hostname, args.target_compilation.unwrap()))
|
||||
.header(header.0, header.to_owned().1)
|
||||
.form(&form_data)
|
||||
.send()?;
|
||||
|
||||
let status = &resp.status();
|
||||
//let plain = &resp.text()?;
|
||||
let plain = &resp.text()?;
|
||||
std::fs::write("device-add.out.html", plain).unwrap();
|
||||
|
||||
println!("-----------------------------------");
|
||||
println!("6/7 Added device to MDM Compilation");
|
||||
println!("Received response status: {:?}", status);
|
||||
|
@ -239,36 +216,30 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
|
||||
let form_data = [
|
||||
("iserv_crud_multi_select[actions][apply-all-changes]", ""),
|
||||
("iserv_crud_multi_select[grouped_actions]", ""),
|
||||
// seems to work with and without token :o (but without it throws a csrf error) // example token: rqB8um_Y6sJ1hCFMeVlg9r3L0v__tH3GS5KcV4Lj_ug
|
||||
("iserv_crud_multi_select[_token]", ""),
|
||||
("iserv_crud_multi_select[confirm]", "apply-changes"),
|
||||
("iserv_crud_multi_select[multi][]", mdm_new_ipad_id),
|
||||
("iserv_crud_multi_select[topReplacementActions][apply-changes]", ""),
|
||||
//("iserv_crud_multi_select[_token]", csrf_token),
|
||||
// seems to work with and without token :o (but without it iserv throws a csrf error) // example token: rqB8um_Y6sJ1hCFMeVlg9r3L0v__tH3GS5KcV4Lj_ug
|
||||
];
|
||||
|
||||
let resp = client
|
||||
.post(format!("https://{}/iserv/admin/mdm/ios/device/batch/confirm", args.hostname))
|
||||
.post(format!("https://{}/iserv/admin/mdm/ios/device/batch", args.hostname))
|
||||
.header(header.0, header.to_owned().1)
|
||||
.form(&form_data)
|
||||
.send()?;
|
||||
|
||||
let status = &resp.status();
|
||||
//let plain = &resp.text()?;
|
||||
let plain = &resp.text()?;
|
||||
std::fs::write("confirm.out.html", plain).unwrap();
|
||||
|
||||
//println!("{}", plain);
|
||||
|
||||
|
||||
/*{
|
||||
"iserv_crud_multi_select[actions][apply-all-changes]": "",
|
||||
"iserv_crud_multi_select[grouped_actions]": "",
|
||||
"iserv_crud_multi_select[_token]": "rqB8um_Y6sJ1hCFMeVlg9r3L0v__tH3GS5KcV4Lj_ug"
|
||||
}*/
|
||||
|
||||
println!("-----------------------------------");
|
||||
println!("7/7 Confirmed actions");
|
||||
println!("7/7 Confirmed device actions");
|
||||
println!("Received response status: {:?}", status);
|
||||
println!("-----------------------------------");
|
||||
}
|
||||
Ok(())
|
||||
//Ok(())
|
||||
}
|
||||
|
||||
// helper functions
|
||||
|
|
Loading…
Reference in New Issue