delete_Target($delete_tgt); header("Location: index.php"); } elseif ($delete_findings) { $db->delete_Target_Findings($delete_tgt_findings); $findings_deleted = true; } elseif ($sec_tgt > 0) { $tgt_id = filter_input(INPUT_POST, 'tgt', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); $db->merge_Target($ste_id, $tgt_id, $sec_tgt); } $required = "* "; $task_status = $db->get_Task_Statuses(); $gen_os = $db->get_Software("cpe:/o:generic:generic:-"); if (is_array($gen_os) && count($gen_os) && isset($gen_os[0]) && is_a($gen_os[0], 'software')) { $gen_os = $gen_os[0]; } // Update or insert new target if ($action == 'insert') { $params = array( 'cat' => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1)), 'ste' => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1)), "Classification" => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array('regexp' => "/U|FOUO|S/")), "DeviceName" => FILTER_SANITIZE_STRING, "osSoftware" => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1)), "location" => FILTER_SANITIZE_STRING, "automated_taskStatus" => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1, 'max_range' => 5)), "manual_taskStatus" => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1, 'max_range' => 5)), "dataGathering_taskStatus" => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1, 'max_range' => 5)), "fp_CAT1_taskStatus" => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1, 'max_range' => 5)), "applicableChecklists" => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY), "suspend_pp" => array('filter' => FILTER_VALIDATE_BOOLEAN, 'flags' => FILTER_NULL_ON_FAILURE), "targetNotes" => FILTER_SANITIZE_STRING ); $vals = filter_input_array(INPUT_POST, $params); $tgt = new target($vals['DeviceName']); $tgt->set_STE_ID($vals['ste']); $tgt->set_Auto_Status_ID($vals['automated_taskStatus']); $tgt->set_Man_Status_ID($vals['manual_taskStatus']); $tgt->set_Data_Status_ID($vals['dataGathering_taskStatus']); $tgt->set_FP_Cat1_Status_ID($vals['fp_CAT1_taskStatus']); $tgt->set_Location($vals['location']); $tgt->classification = $vals['Classification']; $tgt->set_Notes(trim($vals['targetNotes'])); $tgt->set_PP_Suspended((boolean) $vals['suspend_pp']); if ($vals['cat'] && is_numeric($vals['cat'])) { $tgt->set_Cat_ID($vals['cat']); } if (is_array($vals['applicableChecklists']) && count($vals['applicableChecklists'])) { foreach ($vals['applicableChecklists'] as $chk_id) { $chk = $db->get_Checklist($chk_id); if (is_array($chk) && count($chk) && isset($chk[0]) && is_a($chk[0], 'checklist')) { $tgt->checklists[$chk_id] = $chk[0]; } } } else { foreach ($tgt->checklists as $key => $chk) { unset($tgt->checklists[$key]); } } if ($vals['osSoftware'] > 0) { $os = $db->get_Software($vals['osSoftware']); if (is_array($os) && count($os) && isset($os[0]) && is_a($os[0], 'software')) { $tgt->set_OS_ID($os[0]->get_ID()); $tgt->set_OS_String($os[0]->get_Shortened_SW_String()); } } $ret = $db->save_Target($tgt); if (!$ret) { print 'Error Saving Target'; } header('Location: /ste/index.php'); } elseif ($action == 'update') { $params = array( "Classification" => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array('regexp' => "/U|FOUO|S/")), "DeviceName" => FILTER_SANITIZE_STRING, 'ste' => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1)), "tgt" => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1)), "osSoftware" => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1)), "location" => FILTER_SANITIZE_STRING, "automated_taskStatus" => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1, 'max_range' => 5)), "manual_taskStatus" => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1, 'max_range' => 5)), "dataGathering_taskStatus" => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1, 'max_range' => 5)), "fp_CAT1_taskStatus" => array('filter' => FILTER_VALIDATE_INT, 'options' => array('min_range' => 1, 'max_range' => 5)), "applicableChecklists" => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY), "installedSoftware" => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY), "suspend_pp" => array('filter' => FILTER_VALIDATE_BOOLEAN, 'flags' => FILTER_NULL_ON_FAILURE), "targetNotes" => FILTER_SANITIZE_STRING, "missingPatches" => FILTER_SANITIZE_STRING, "netstatConnections" => FILTER_SANITIZE_STRING, "login" => FILTER_SANITIZE_STRING, "new" => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY), "ip" => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY), "hostname" => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY), "name" => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY), "fqdn" => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY), "description" => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY) ); $vals = filter_input_array(INPUT_POST, $params); $tgt = $db->get_Target_Details($vals['ste'], $vals['tgt']); if (is_array($tgt) && count($tgt) && isset($tgt[0]) && is_a($tgt[0], 'target')) { $tgt = $tgt[0]; } else { die(nl2br(print_r($tgt, true))); } $tgt->set_ID($vals['tgt']); $tgt->set_Name($vals['DeviceName']); $tgt->set_STE_ID($vals['ste']); $tgt->set_Auto_Status_ID($vals['automated_taskStatus']); $tgt->set_Man_Status_ID($vals['manual_taskStatus']); $tgt->set_Data_Status_ID($vals['dataGathering_taskStatus']); $tgt->set_FP_Cat1_Status_ID($vals['fp_CAT1_taskStatus']); $tgt->set_Location($vals['location']); $tgt->classification = $vals['Classification']; $tgt->set_Notes(trim($vals['targetNotes'])); $tgt->set_Netstat_Connections(trim($vals['netstatConnections'])); $tgt->set_Missing_Patches(trim($vals['missingPatches'])); $tgt->set_Login($vals['login']); $tgt->set_PP_Suspended((boolean) $vals['suspend_pp']); if ($vals['osSoftware'] > 0) { $os = $db->get_Software($vals['osSoftware']); if (is_array($os) && count($os) && isset($os[0]) && is_a($os[0], 'software')) { $tgt->set_OS_ID($os[0]->get_ID()); $tgt->set_OS_String($os[0]->get_Shortened_SW_String()); } } if (is_array($vals['applicableChecklists']) && count($vals['applicableChecklists'])) { $tgt->checklists = array(); foreach ($vals['applicableChecklists'] as $chk_id) { $chk = $db->get_Checklist($chk_id); if (is_array($chk) && count($chk) && isset($chk[0]) && is_a($chk[0], 'checklist')) { $tgt->checklists[$chk_id] = $chk[0]; } } } else { foreach ($tgt->checklists as $key => $chk) { unset($tgt->checklists[$key]); } } if (is_array($vals['installedSoftware']) && count($vals['installedSoftware'])) { $tgt->software = array(); foreach ($vals['installedSoftware'] as $sw_id) { $sw = $db->get_Software($sw_id); if (is_array($sw) && count($sw) && isset($sw[0]) && is_a($sw[0], 'software')) { $tgt->software[$sw_id] = $sw[0]; } } } else { foreach ($tgt->software as $key => $chk) { unset($tgt->software[$key]); } } if (is_array($vals['ip']) && count($vals['ip'])) { foreach ($vals['ip'] as $id => $ip) { $ipv4 = null; $ipv6 = null; if (preg_match("/:/", $ip)) { $ipv6 = $ip; } else { $ipv4 = $ip; } if (strtolower($ip) == 'delete') { foreach ($tgt->interfaces as $idx => $int) { if ($int->get_ID() == $id) { Sagacity_Error::err_handler("Deleting target ({$tgt->get_ID()}) interface (ID: {$int->get_ID()} IP: $ip)"); unset($tgt->interfaces["{$idx}"]); break; } } $db->delete_Interface($id); } else { if (isset($tgt->interfaces["$ip"])) { $int = $tgt->interfaces["$ip"]; $int->set_Name($vals['name'][$id]); $int->set_IPv4($ipv4); $int->set_IPv6($ipv6); $int->set_Description($vals['description'][$id]); $int->set_Hostname($vals['hostname'][$id]); $int->set_FQDN($vals['fqdn'][$id]); } else { $int = new interfaces(null, $tgt->get_ID(), $vals['name'][$id], $ipv4, $ipv6, $vals['hostname'][$id], $vals['fqdn'][$id], $vals['description'][$id]); } $tgt->interfaces["$ip"] = $int; } } } $ret = $db->save_Target($tgt); header("Location: /ste/"); } elseif ($action == 'data_collection') { include_once 'import.inc'; $import = new import(); $import->import_Host_Data_Collection(); } // If there is 'tgt' in the querystring if ($tgt_id && $ste_id) { $tgt = $db->get_Target_Details($ste_id, $tgt_id)[0]; $ste = $db->get_STE($tgt->get_STE_ID())[0]; } else { $tgt = null; $checklists = array(); } $title_prefix = ($tgt_id ? "Edit " . $tgt->get_Name() : "Add Target"); include_once 'header.inc'; ?>