/usr/share/doc/integrit/examples/viewreport is in integrit 4.1-1.1+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | #! /usr/bin/perl -w
# integrit - file integrity verification system
# Copyright (C) 2006 Ed L. Cashin
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# $Header: /cvsroot/integrit/integrit/examples/viewreport,v 1.14 2006/04/07 09:41:13 wavexx Exp $
# extensions based on a patch from
# Volker Apelt <va@org.chemie.uni-frankfurt.de>
# added to version 1.6 of this file.
use strict;
use XML::Grove;
use XML::Grove::Builder;
use XML::Parser::PerlSAX;
use Tk;
if ("debug" eq "yup") {
use Data::Dumper;
}
&go;
sub go {
&show_excuses;
push @ARGV, "-" if ! @ARGV; # default to stdin
foreach my $fname (@ARGV) {
&show_report($fname);
}
}
sub show_excuses {
print STDERR <<"MY_BOLOGNA_HAS_A_FIRST_NAME";
viewreport - an example of a GUI viewer for the XML reports that integrit
generates.
I'm not too much of a GUI programmer, so I'm sure you can do better!
MY_BOLOGNA_HAS_A_FIRST_NAME
# ' # for emacs (in case single quote in here doc are odd)
}
sub show_report {
die "Error: parameter missing" if @_ < 1;
my ($fname) = @_;
#--------------use perl for XML parsing
my $xml = &slirp_file($fname);
my $gbuilder = new XML::Grove::Builder;
my $parser = new XML::Parser::PerlSAX('Handler' => $gbuilder);
my $doc = $parser->parse('Source' => {
'String' => $xml,
});
die "Error: unable to parse XML" unless $doc;
my $report = &get_report($doc);
# print new Data::Dumper([ $report ])->Dump and die; # debug
#--------------use Perl/Tk for the GUI
my $mw = new MainWindow(-title => "demo integrit report viewer");
my $date = localtime($report->{'Attributes'}{'date'});
$mw->Label(-text => "report from $date")->pack;
$mw->Button(-text => 'Quit', -command => [ $mw => 'destroy' ])->pack;
my $box = $mw->Listbox(-relief => 'sunken',
-width => -1, # Shrink to fit
-height => 5,
-setgrid => 1);
$box->bind('<Double-1>' => sub { &show_info($_[0], $report); });
&insert_elements($box, $report);
my $scroll = $mw->Scrollbar(-command => ['yview', $box]);
$box->configure(-yscrollcommand => ['set', $scroll]);
$box->pack(-side => 'left', -fill => 'both', -expand => 1);
$scroll->pack(-side => 'right', -fill => 'y');
MainLoop();
}
#--------------show more info for a given report line
sub show_info {
die "Error: missing parameter" if @_ < 2;
my ($mw, $report) = @_;
my $target = $mw->get('active');
foreach my $elem (@{ $report->{'Contents'} }) {
my $name = $elem->{'Name'};
my $elem_data = &elem_data($elem);
next unless $name;
if (($name eq "change")
&& ($target =~ m/^change/)) {
my $type = $elem->{'Attributes'}{'type'};
my $filename = $elem->{'Attributes'}{'file'};
my $tag = "$name ($type): $filename";
if ($tag eq $target) {
&display_change($mw, $elem);
}
} elsif (($name eq "options")
&& ($target eq "options")) {
&display_options($mw, $elem);
} elsif ($target eq "$name: $elem_data"){
&display_misc($mw, $elem);
}
}
}
#-----------------show changed data
sub display_change {
die "Error: missing parameter" if @_ < 2;
my ($mw, $elem) = @_;
my $type = $elem->{'Attributes'}{'type'}; # e.g. stat, SHA-1
my $filename = $elem->{'Attributes'}{'file'};
my ($old, $new) = ("(unknown)", "(unknown)");
my $change = $elem->{'Contents'}[0];
# $type .= ": " . $change->{'Name'};
my $changew = $mw->Toplevel(-title => "viewreport: change"); # new window
$changew->Label(-text => "file: $filename")->pack;
$changew->Label(-text => "type of change: $type")->pack;
foreach my $change (@{ $elem->{'Contents'} }) {
if ($type eq "stat") {
my $statkind = $change->{'Name'}; # e.g., mtime, atime
my $postprocess = &postprocessor_for_statchange($statkind);
$changew->Label(-text => "stat change: $statkind")->pack;
foreach my $stat (@{ $change->{'Contents'} }) {
my $name = $stat->{'Name'};
if (($name eq "old") || ($name eq "new")) {
my $val = $postprocess->(&elem_data($stat));
$changew->Label(-text => "$name: $val")->pack;
}
}
} else {
my $name = $change->{'Name'};
if (($name eq "old") || ($name eq "new")) {
my $val = &elem_data($change);
$changew->Label(-text => "$name: $val")->pack;
}
}
}
$changew->Button(-text => "Dismiss",
-command => [ $changew => 'destroy' ])->pack;
}
sub display_options {
die "Error: missing parameter" if @_ < 2;
my ($mw, $elem) = @_;
#-----------new window
my $optionsw = $mw->Toplevel(-title => "viewreport: options");
foreach my $thang (@{ $elem->{'Contents'} }) {
my $name = $thang->{'Name'};
next unless $name;
my $val = &elem_data($thang);
$optionsw->Label(-text => "$name: $val")->pack;
}
$optionsw->Button(-text => "Dismiss",
-command => [ $optionsw => 'destroy' ])->pack;
}
sub display_misc {
die "Error: missing parameter" if @_ < 2;
my ($mw, $elem) = @_;
my $name = $elem->{'Name'};
return unless $name;
#-----------new window
my $miscw = $mw->Toplevel(-title => "viewreport: misc");
my $val = &elem_data($elem);
$miscw->Label(-text => "$name: $val")->pack if $val =~ /\S/;
$miscw->Button(-text => "Dismiss",
-command => [ $miscw => 'destroy' ])->pack;
}
sub get_report {
die "Error: missing parameter" if @_ < 1;
my ($doc) = @_;
my $report;
foreach my $elem (@{ $doc->{'Contents'} }) {
if ($elem->{'Name'} eq "report") {
$report = $elem;
}
}
die "no report found" unless $report;
return $report;
}
sub insert_elements {
die "Error: missing parameter" if @_ < 2;
my ($box, $report) = @_;
foreach my $elem (@{ $report->{'Contents'} }) {
my $name = $elem->{'Name'};
next unless $name;
if ($name eq "change") {
my $type = $elem->{'Attributes'}{'type'};
my $filename = $elem->{'Attributes'}{'file'};
$box->insert('end', "$name ($type): $filename");
} elsif ($name eq "options") {
$box->insert('end', $name);
} else {
$box->insert('end', "$name: " . &elem_data($elem));
}
}
}
sub elem_data {
die "Error: missing parameter" if @_ < 1;
my ($thang) = @_;
my $contents = $thang->{'Contents'} or return "(no data)";
foreach my $elem (@$contents) {
next unless $elem->{'Data'};
return $elem->{'Data'};
}
return "(no data)";
}
sub slirp_file {
die "Error: missing parameter" if @_ < 1;
my ($self, $filename) = @_; # disgard self param
if (! ref $self) {
#--------assume it's not an OO method if there's no
# reference in the first param.
$filename = $self;
}
open SLIRPFILE, $filename
or die "Error: could not open $filename for reading";
local $/ = undef;
my $file_contents = <SLIRPFILE>;
close SLIRPFILE;
return $file_contents;
}
####### element post processors
# turn raw element data into readable text
sub postprocessor_for_statchange {
die "Error: missing parameter" if @_ < 1;
my ($statchange) = @_;
if ($statchange =~ m/_time$/) {
return \&post_processor_time2localtime;
} elsif ( $statchange eq 'gid' ){
return \&post_processor_gid;
} elsif ( $statchange eq 'uid' ){
return \&post_processor_uid;
}
return \&post_processor_noop;
}
sub post_processor_noop {
return $_[0];
}
sub post_processor_time2localtime {
my $time = shift; # time in unix seconds since ....
return localtime($time);
}
sub post_processor_gid {
my $gid = shift; # numeric gid
if( $gid !~ /^\d+/ ){
return "$gid";
}
my $name = getgrgid($gid); # must be scalar!
if( ! defined $name ){
return "(unknown)$gid";
}
return $name;
}
sub post_processor_uid {
my $uid = shift; # numeric gid
if( $uid !~ /^\d+/ ){
return "$uid";
}
my $name = getpwuid($uid); # must be scalar!
if( ! defined $name ){
return "(unknown)$uid";
}
return $name;
}
####### end element post processors
|