/usr/share/perl5/ClamTk/Results.pm is in clamtk 5.20-1.
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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | # ClamTk, copyright (C) 2004-2015 Dave M
#
# This file is part of ClamTk (http://code.google.com/p/clamtk/).
#
# ClamTk is free software; you can redistribute it and/or modify it
# under the terms of either:
#
# a) the GNU General Public License as published by the Free Software
# Foundation; either version 1, or (at your option) any later version, or
#
# b) the "Artistic License".
package ClamTk::Results;
use Glib 'TRUE', 'FALSE';
# use strict;
# use warnings;
$| = 1;
use POSIX 'locale_h';
use File::Basename 'basename';
use Locale::gettext;
use File::Copy 'move';
use Digest::SHA 'sha256_hex';
use Encode 'decode';
my $liststore;
my $dialog;
binmode( STDIN, ':utf8' );
binmode( STDOUT, ':utf8' );
sub show_window {
my ( $pkg_name, $hash, $parent ) = @_;
$dialog = Gtk2::Dialog->new( _( 'Results' ), $parent,
'destroy-with-parent', );
$dialog->set_size_request( 600, 200 );
my $sbox = Gtk2::VBox->new( FALSE, 0 );
# This scrolled window holds the slist
my $sw = Gtk2::ScrolledWindow->new;
$sbox->pack_start( $sw, TRUE, TRUE, 0 );
$dialog->get_content_area->add( $sbox );
$sw->set_shadow_type( 'etched_in' );
$sw->set_policy( 'never', 'automatic' );
use constant FILE => 0;
use constant STATUS => 1;
use constant ACTION_TAKEN => 2;
#<<<
$liststore = Gtk2::ListStore->new(
# FILE
'Glib::String',
# STATUS
'Glib::String',
# ACTION_TAKEN
'Glib::String',
);
my $tree = Gtk2::TreeView->new_with_model( $liststore );
$tree->set_rules_hint( TRUE );
$sw->add( $tree );
my $renderer = Gtk2::CellRendererText->new;
my $column
= Gtk2::TreeViewColumn->new_with_attributes(
_( 'File' ),
$renderer,
markup => FILE,
);
$column->set_sort_column_id( FILE );
$column->set_resizable( TRUE );
$column->set_sizing( 'fixed' );
$column->set_expand( TRUE );
$tree->append_column( $column );
$column = Gtk2::TreeViewColumn->new_with_attributes(
_( 'Status' ),
$renderer,
markup => STATUS,
);
$column->set_sort_column_id( STATUS );
$column->set_resizable( TRUE );
$column->set_sizing( 'fixed' );
$column->set_expand( TRUE );
$tree->append_column( $column );
$column = Gtk2::TreeViewColumn->new_with_attributes(
_( 'Action Taken' ),
$renderer,
markup => ACTION_TAKEN,
);
$column->set_sort_column_id( ACTION_TAKEN );
$column->set_resizable( TRUE );
$column->set_sizing( 'fixed' );
$column->set_expand( TRUE );
$tree->append_column( $column );
#<<<
my $i = 0;
while ( $i <= scalar keys %$hash ) {
# print 'name = ', $hash->{ $i }->{ name }, "\n";
my $iter = $liststore->append;
$liststore->set(
$iter,
0, decode( 'utf8', $hash->{ $i }->{ name }),
1, $hash->{ $i }->{ status },
2, $hash->{ $i }->{ action },
);
$i++;
last if ( $i >= scalar keys %$hash );
}
#>>>
my $hbox = Gtk2::Toolbar->new;
$hbox->set_style( 'both-horiz' );
$sbox->pack_start( $hbox, FALSE, FALSE, 5 );
my $image = Gtk2::Image->new_from_stock( 'gtk-refresh', 'menu' );
my $button = Gtk2::ToolButton->new( $image, _( 'Quarantine' ) );
$button->set_is_important( TRUE );
$hbox->insert( $button, -1 );
$button->signal_connect( clicked => \&action, $tree );
$image = Gtk2::Image->new_from_stock( 'gtk-delete', 'menu' );
$button = Gtk2::ToolButton->new( $image, _( 'Delete' ) );
$button->set_is_important( TRUE );
$hbox->insert( $button, -1 );
$button->signal_connect( clicked => \&action, $tree );
# Testing to see if we can add Analysis button.
# See ClamTk::Analysis->button_test for more
if ( ClamTk::Analysis->button_test ) {
$image = Gtk2::Image->new_from_stock( 'gtk-find', 'menu' );
$button = Gtk2::ToolButton->new( $image, _( 'Analysis' ) );
$button->set_is_important( TRUE );
$hbox->insert( $button, -1 );
$button->signal_connect( clicked => \&action, $tree );
}
my $sep = Gtk2::SeparatorToolItem->new;
$sep->set_draw( FALSE );
$sep->set_expand( TRUE );
$hbox->insert( $sep, -1 );
$image = Gtk2::Image->new_from_stock( 'gtk-close', 'menu' );
$button = Gtk2::ToolButton->new( $image, _( 'Close' ) );
$button->signal_connect(
clicked => sub {
$dialog->destroy;
}
);
$button->set_is_important( TRUE );
$hbox->insert( $button, -1 );
$sbox->show_all;
$dialog->run;
$dialog->destroy;
}
sub action {
my ( $button, $view ) = @_;
my $selected = $view->get_selection;
my ( $model, $iter ) = $selected->get_selected;
return unless $iter;
# These look like
# first_col_value = >/home/foo/mime.cache<
# second_col_value = >PUA.Win.Exploit.CVE_2012_0110<
my $first_col_value = $model->get_value( $iter, FILE );
my $second_col_value = $model->get_value( $iter, STATUS );
my $third_col_value = $model->get_value( $iter, ACTION_TAKEN );
# Don't mess with inboxes and empty values (!)
my $maildirs = get_maildirs();
if ( $first_col_value =~ /$maildirs/ || !-e $first_col_value ) {
color_out( $model, $iter );
return TRUE;
}
# Don't quarantine or delete PUAs outside of home directory
if ( $second_col_value =~ /^PUA/ ) {
if ( $first_col_value !~ m#^/home/# ) {
color_out( $model, $iter );
return TRUE;
}
}
# Return 1 or TRUE for successfully deleting
# or quarantining so we can "color_out" that row
# and change its status column
if ( $button->get_label eq _( 'Quarantine' ) ) {
my $ret = quarantine( $first_col_value );
if ( $ret ) {
color_out( $model, $iter, _( 'Quarantined' ) );
return TRUE;
} else {
return FALSE;
}
} elsif ( $button->get_label eq _( 'Delete' ) ) {
my $ret = delete_file( $first_col_value );
if ( $ret ) {
color_out( $model, $iter, _( 'Deleted' ) );
return TRUE;
}
return FALSE;
} elsif ( $button->get_label eq _( 'Analysis' ) ) {
ClamTk::Analysis->show_window( $first_col_value, $dialog );
return TRUE;
} else {
warn 'unable to ' . $button->get_label . " file >$first_col_value<\n";
}
return TRUE;
}
sub quarantine {
my ( $file ) = shift;
my $basename = basename( $file );
# This is where threats go
my $paths = ClamTk::App->get_path( 'viruses' );
if ( !-e $paths or !-d $paths ) {
warn "Unable to quarantine >$file<; no quarantine directory\n";
return FALSE;
}
# Get permissions
my $mode = ( stat( $file ) )[ 2 ];
my $perm = sprintf( "%03o", $mode & oct( 7777 ) );
# Update restore file by adding file, path and md5
ClamTk::Quarantine->add_hash( $file, $perm );
# Assign 600 permissions
chmod oct( 600 ), $file;
move( $file, "$paths/$basename" ) or do {
# When a 'mv' fails, it still probably did a 'cp'...
# 'mv' copies the file first, then unlinks the source.
# d'oh... so just to make sure, unlink the intended target
# and THEN return.
unlink( "$paths/$basename" )
or warn "unable to delete tmp file $paths/$basename\n: $!\n";
return FALSE;
};
}
sub delete_file {
my $file = shift;
my $basename = basename( $file );
# This is where threats go
my $paths = ClamTk::App->get_path( 'viruses' );
my $question
= sprintf( _( 'Really delete this file (%s) ?' ), $basename );
my $message
= Gtk2::MessageDialog->new( undef,
[ qw| modal destroy-with-parent | ],
'question', 'ok-cancel', $question, );
if ( 'ok' eq $message->run ) {
$message->destroy;
} else {
$message->destroy;
return FALSE;
}
unlink( $file ) or do {
warn "unable to delete >$file<: $!\n";
return FALSE;
};
# If it's in the trash, remove its associated information file
my $trash_info_path = ClamTk::App->get_path( 'trash_files_info' );
my $trash_info_file = $trash_info_path . '/' . $basename . '.trashinfo';
if ( $file =~ m#Trash# ) {
if ( -e $trash_info_file ) {
unlink( $trash_info_file )
or warn "Unable to delete trashinfo file for $file: $!\n";
}
}
return TRUE;
}
sub color_out {
# We optionally take a value to set the third
# column to (e.g., Quarantined, Deleted)
my ( $store, $iter, $third_value_change ) = @_;
if ( !$third_value_change ) {
$third_value_change = ' - ';
}
my $first_col_value
= "<span foreground = '#CCCCCC'>"
. $store->get_value( $iter, FILE )
. " </span>";
my $second_col_value
= "<span foreground='#CCCCCC'>"
. $store->get_value( $iter, STATUS )
. "</span > ";
my $third_col_value = "<span foreground = '#CCCCCC'>"
#. $store->get_value( $iter, ACTION_TAKEN )
. $third_value_change . "</span>";
#<<<
$store->set(
$iter,
0, $first_col_value,
1, $second_col_value,
2, $third_col_value,
);
#>>>
}
sub get_maildirs {
return join(
'|',
'.thunderbird', '.mozilla-thunderbird', 'evolution(?!/ tmp
) ',
' Mail ', ' kmail ', "\.pst"
);
}
sub get_hash {
my $file = shift;
my $slurp = do {
local $/ = undef;
open( my $f, ' < ', $file ) or do {
warn "unable to open >$file<: $!\n";
return;
};
binmode( $f );
<$f>;
};
return sha256_hex( $slurp );
}
1;
|