I am trying to sort this output by the severity. I tired several different options, but It doesn't seem to work.
$xmlVuln = file_get_contents("xml/$file.xml");
$counter = 0;
function TOC($record){
global $counter;
if ($record["SEVERITY"] <= 1) return;
$counter++;
print '<tr>';
print '<td style="width: 125px;">';
if ($record["SEVERITY"] == 4) {
print '<div class="critical small">';
print 'Critical';
print '</div>';
}
if ($record["SEVERITY"] == 3) {
print '<div class="high small">';
print 'High';
print '</div>';
}
if ($record["SEVERITY"] == 2) {
print '<div class="medium small">';
print 'Medium';
print '</div>';
}
if ($record["SEVERITY"] == 1) {
print '<div class="low small">';
print 'Low';
print '</div>';
}
if ($record["SEVERITY"] == 0) {
print '<div class="informational small">';
print 'informational';
print '</div>';
}
print '</td>';
print '<td>';
print '<a href="#';
print $counter;
print '" target="_self">';
print_r($record["NAME"]);
print '</a>';
print '</td>';
print '<td>';
print $record["VULNERABILITYID"];
print '</td>';
print '</tr>';
}
MagicParser_parse("string://".$xmlVuln,"TOC","xml|SCAN/ISSUES/ISSUE/");
Hi crusnac,
The best thing to do in this situation is to parse the XML into a global array, and then sort using PHP's usort() function. After that, re-loop through the records using foreach() and process as per your original record handler function... Consider the following example:
$xmlVuln = file_get_contents("xml/$file.xml");
function TOC($record){
global $records;
if ($record["SEVERITY"] <= 1) return;
$records[] = $record;
}
MagicParser_parse("string://".$xmlVuln,"TOC","xml|SCAN/ISSUES/ISSUE/");
function cmp($a, $b)
{
if ($a["SEVERITY"] == $b["SEVERITY"]) {
return 0;
}
return ($a["SEVERITY"] < $b["SEVERITY"]) ? -1 : 1;
}
function TOC2($record)
{
print '<tr>';
print '<td style="width: 125px;">';
if ($record["SEVERITY"] == 4) {
print '<div class="critical small">';
print 'Critical';
print '</div>';
}
if ($record["SEVERITY"] == 3) {
print '<div class="high small">';
print 'High';
print '</div>';
}
if ($record["SEVERITY"] == 2) {
print '<div class="medium small">';
print 'Medium';
print '</div>';
}
if ($record["SEVERITY"] == 1) {
print '<div class="low small">';
print 'Low';
print '</div>';
}
if ($record["SEVERITY"] == 0) {
print '<div class="informational small">';
print 'informational';
print '</div>';
}
print '</td>';
print '<td>';
print '<a href="#';
print $counter;
print '" target="_self">';
print_r($record["NAME"]);
print '</a>';
print '</td>';
print '<td>';
print $record["VULNERABILITYID"];
print '</td>';
print '</tr>';
}
print "<table>";
foreach($record as $record)
{
TOC2($record);
}
print "</table>";
Hope this helps!
Cheers,
David
--
MagicParser.com