#!/usr/bin/perl # view_annotations.pl, distributed as part of Snortsnarf v021111.1 # Author: James Hoagland, Silicon Defense (hoagland@SiliconDefense.com) # copyright (c) 2000 by Silicon Defense (http://www.silicondefense.com/) # Released under GNU General Public License, see the COPYING file included # with the distribution or http://www.silicondefense.com/software/snortsnarf/ # for details. # view_annotations.pl is a CGI script to retrieve the annotations for a # certain type and key from the annotation base given and to present a form # to add new entries. # Please send complaints, kudos, and especially improvements and bugfixes to # hoagland@SiliconDefense.com. As described in GNU General Public License, no # warranty is expressed for this program. use CGI; use XML::Parser; # get parameters of the invocation $input= new CGI; foreach (@ARGV) { # simulate field input if running on command line $input->param(split('=',$_,2)); } $source_file= $input->param('file'); $search_type= $input->param('type'); $search_key= $input->param('key'); # print out headers print $input->header(-header => 'text/html',-expires => '+0d'); # create a tree representing the XML in the given file -e $source_file || die "annotation file $source_file does not exist"; $xml= new XML::Parser(Style => 'Tree'); $tree= $xml->parsefile($source_file); $tree->[0] eq "ANNOTATION-BASE" || die "invalid XML file ($source_file); expected root element to be ANNOTATION-BASE"; @content= @{$tree->[1]}; shift @content; while (@content) { $tagname=shift(@content); $content=shift(@content); next unless $tagname eq 'ANNOTATIONS'; ($type,$key,@annlist)= &get_anns_info($content); last if $type eq $search_type && $key eq $search_key; @annlist=(); # in case this is the last iteration of the loop } # @annlist now contains a list of the annotation subtrees found print <<">>";
| Subject | Author | Date | Annotation |
| $subject | $author | $date | $note |
Use your browser's back command to return to the previous page.
Generated by $0 from $source_file >> sub get_anns_info { my($anns)= shift; my @content= @{$anns}; shift @content; my($tagname,$content,$type,$key,@annlist); $type= $key= undef; @annlist=(); while (@content) { $tagname=shift(@content); my @info= @{shift(@content)}; if ($tagname eq 'TYPE') { $type= $info[2]; } elsif ($tagname eq 'KEY') { $key= $info[2]; } elsif ($tagname eq 'ANNOTATION') { shift(@info); push(@annlist,\@info); } else { next; } } return ($type,$key,@annlist); } sub get_ann_info { my($ann)= shift; my @content= @{$ann}; #shift @content; my($tagname,$content,$author,$date,$subject,$note); $author= $date= $subject= $note= ''; while (@content) { $tagname=shift(@content); my $content= shift(@content); $content= $content->[2]; if ($tagname eq 'AUTHOR') { $author= $content; } elsif ($tagname eq 'DATE') { $date= $content; } elsif ($tagname eq 'SUBJECT') { $subject= $content; } elsif ($tagname eq 'NOTE') { $note= $content; } else { next; } } return ($author,$date,$subject,$note); } 1; # $Id: view_annotations.pl,v 1.6 2000/06/14 18:39:47 jim Exp $