foreach ($critsJSON as $key => $val) { if (isset($val['id'])) { /* echo "<br/>critsJSON:</br>"; #DEBUG echo "<pre>"; #DEBUG print_r($critsJSON); #DEBUG echo "</pre>"; #DEBUG */ $relationArray['TLO1type'] = $val['type']; $relationArray['TLO1id'] = $val['id']; foreach ($critsJSON as $key2 => $val2) { if ($key2 != $key) { $relationArray['TLO2type'] = $val2['type']; $relationArray['TLO2id'] = $val2['id']; if (isset($val2['id'])) { $relationJSON[$key][$key2] = dataBuild($type, $new_file_name = NULL, $_POST, $_FILES, $critsPage, $critsLogin, $relationArray); } } } unset($critsJSON[$key]); } } #set all the CRITs variables to prep them for relation ($sampleCRITs, $ipCRITs, $domainCRITs, $pcapCRITs, etc...) #if $sampleCRITs is not already set, that means it wasn't found in the db -- #upload it to CRITs, and save the response (id, type, msg, url, etc) as an array in $sampleCRITs #likewise for all the other fields submitted #Once all the $xxxCRITs variables are populated above, and the ticket #'s have all been updated, relate all the objects to eachother # relationships.relationship:"Related_to" # relationships.rel_reason:"Related via ticket XXXX" #Upload files that aren't in CRITs to the CRITs DB #Relate all files (new or old)
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; }