function metaDataBuild($formField, $formType, $type, $critsUpdateData, $critsPage, $critsLogin, $_POST, $critsJSON, $desc=NULL){ if(isset($critsUpdateData[$formField])){ #echo "critsUpdateData[$formField] is set<br/><br/>"; foreach($critsUpdateData[$formField] as $key=>$val){ #Search crits for an existing event matching this ticket # $eventSearch = searchCRITs($type, $val, $critsPage, $critsLogin); echo "eventSearch:"; echo "<pre>"; print_r($eventSearch); echo "</pre>"; $eventJSON = json_decode($eventSearch[0],true); #If the event already exists, just set the critsJSON tags and move on. Otherwise, add the event. if(isset($eventJSON['objects'][0]['_id'])){ $critsJSON[$formField][$key]['id']=$eventJSON['objects'][0]['_id']; if($type=='event'){ $critsJSON[$formField][$key]['type']='Event'; } elseif($type=='ip'){ $critsJSON[$formField][$key]['type']='IP'; } elseif($type=='domain'){ $critsJSON[$formField][$key]['type']='Domain'; } } else{ #build a new event #$type='event'; #$desc='tauseragent'; #$critsJSON[$type]=dataBuild($type, $new_file_name=NULL, $_POST, $_FILES, $critsPage, $critsLogin); $critsJSON[$formField][$key]=dataBuild($formType, $val, $_POST, $_FILES=NULL, $critsPage, $critsLogin, $relationArray=NULL, $desc); /* echo "<pre>"; echo "critsJSON at $key: <br/>"; print_r($critsJSON); echo "formField: $formField <br/>"; echo "val: $val <br/>"; echo "desc: $desc <br/>"; echo "</pre>"; */ } }#end foreach loop } else{ #echo "critsUpdateData[$formField] is NOT set: "; #print_r($critsUpdateData); #echo "<br/><br/>"; } return $critsJSON; }
#Build Data for Sample if (!empty($type) && !empty($val)) { $critsJSON[$type] = dataBuild($type, $new_file_name = NULL, $_POST, $_FILES, $critsPage, $critsLogin); } elseif (!empty($type)) { echo "<h2>ERROR: No TLO type set</h2>"; #DEBUG } } } ##### Create new Event if one does not already exist #Check if an event already exists matching the ticket number #if the ticket number matches, add that id/data to $critsJSON['event']['id'] and $critsJSON['event']['type'] #if the ticket number does not match, build the data to create a new event and POST to the events API if (isset($_POST['ticket'])) { #Search crits for an existing event matching this ticket # $eventSearch = searchCRITs($type = 'event', $_POST['ticket'], $critsPage, $critsLogin); $eventJSON = json_decode($eventSearch[0], true); #If the event already exists, just set the critsJSON tags and move on. Otherwise, add the event. if (isset($eventJSON['objects'][0]['_id'])) { $critsJSON['event']['id'] = $eventJSON['objects'][0]['_id']; $critsJSON['event']['type'] = 'Event'; } else { #build a new event $type = 'event'; $critsJSON[$type] = dataBuild($type, $new_file_name = NULL, $_POST, $_FILES, $critsPage, $critsLogin); } } ##### RELATE ALL UPLOADED CONTENT TO EACH OTHER $relationArray = array(); $type = 'relationship'; #handling the fact that email uploading doesn't work properly
if(isset($eventJSON['objects'][0]['_id'])){ $critsJSON['event'][0]['id']=$eventJSON['objects'][0]['_id']; $critsJSON['event'][0]['type']='Event'; } else{ #build a new event (ticket) $type='event'; $critsJSON[$type][0]=dataBuild($type, $new_file_name=NULL, $_POST, $_FILES=NULL, $critsPage, $critsLogin); } #### Work in Progress - Adding Samples if not found #Search crits for an existing sample matching this MD5 $eventSearch = searchCRITs($type='sample', $_GET['idmd5'], $critsPage, $critsLogin); $eventJSON = json_decode($eventSearch[0],true); #If the sample already exists, just set the critsJSON tags and move on. Otherwise, add it. if(isset($eventJSON['objects'][0]['_id'])){ $critsJSON['sample'][0]['id']=$eventJSON['objects'][0]['_id']; $critsJSON['sample'][0]['type']='Sample'; } else{ #build a new event echo "<pre>"; print_r($fileArrays['vir'][0]); echo "</pre>"; $old_file_name=$fileArrays['vir'][0]; $type='sampleRetro'; $new_file_name=substr($fileArrays['vir'][0], 0, -4);