/usr/share/perl5/ClamTk/Results.pm is in clamtk 4.45-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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | # ClamTk, copyright (C) 2004-2013 Dave M
#
# This file is part of ClamTk (http://clamtk.sourceforge.net).
#
# 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 strict;
# use warnings FATAL => 'all';
$| = 1;
use File::Basename 'basename', 'dirname';
use File::Copy 'move';
use Digest::MD5 'md5_hex';
use Encode;
use Gtk2::SimpleList;
use Glib 'TRUE', 'FALSE';
use Locale::gettext;
use POSIX 'locale_h';
use bytes;
binmode( STDIN, ':utf8' );
binmode( STDOUT, ':utf8' );
my $slist;
my $hover_label;
my $hash;
# We have to avoid parsing mail for now:
# http://clamtk.sourceforge.net/faq.html#inbox
my $maildirs = join( '|',
'.thunderbird', '.mozilla-thunderbird', 'evolution(?!/tmp)',
'Mail', 'kmail', "\.pst" );
sub display {
shift; # don't need package name
($hash) = @_;
my $popup = Gtk2::Dialog->new( gettext('Scanning Results'),
undef, 'destroy-with-parent' );
$popup->signal_connect( destroy => sub { $popup->destroy } );
$popup->set_default_size( 650, 250 );
$popup->set_title( gettext('Scanning Results') );
my ( $x, $y ) = ClamTk::GUI->window_coords();
$popup->move( $x, $y );
my $pbox = Gtk2::VBox->new();
$popup->get_content_area()->add($pbox);
$hover_label =
Gtk2::Label->new( gettext('Possible threats have been found.') );
$pbox->pack_start( $hover_label, FALSE, TRUE, 0 );
# This scrolled window holds the slist
my $scrolled_win = Gtk2::ScrolledWindow->new;
$pbox->pack_start( $scrolled_win, TRUE, TRUE, 0 );
$scrolled_win->set_shadow_type('etched_in');
$scrolled_win->set_policy( 'never', 'automatic' );
$slist = Gtk2::SimpleList->new(
gettext('File') => 'markup',
gettext('Status') => 'markup',
gettext('Action Taken') => 'markup',
);
$scrolled_win->add($slist);
$scrolled_win->grab_focus();
$slist->get_selection->set_mode('multiple');
$slist->set_rules_hint(TRUE);
$slist->set_headers_clickable(TRUE);
# No longer reorderable due to the way we
# push these onto the $slist->{data}.
# $slist->set_reorderable(TRUE);
map { $_->set_resizable(TRUE) } $slist->get_columns;
map { $_->set_sizing('fixed') } $slist->get_columns;
map { $_->set_expand(TRUE) } $slist->get_columns;
# Sorting the columns.
# Can't do it yet because it dorks up the sexy highlighting
# after quarantining or deleting a file.
#for ( 0 .. 2 ) {
# $slist->get_column($_)->set_sort_column_id($_);
#}
$slist->set(
hover_selection => TRUE,
hover_expand => TRUE
);
# Display the possible infections:
# for my $keys ( sort keys %$hash ) {
my $i = 0;
while ( $i <= scalar keys %$hash ) {
push @{ $slist->{data} },
[
$hash->{$i}->{name}, $hash->{$i}->{status},
$hash->{$i}->{action},
];
$i++;
Gtk2->main_iteration while ( Gtk2->events_pending );
last if ( $i == scalar keys %$hash );
}
# Left-click will clear the top label
$slist->signal_connect(
button_press_event => sub {
my ( $widget, $event ) = @_;
return FALSE unless $event->button == 1;
$hover_label->set_text('');
} );
# Right-click functionality. Also uses 'sub confirm'.
$slist->signal_connect(
button_press_event => sub {
my ( $widget, $event ) = @_;
return FALSE unless $event->button == 3;
my @sel = $slist->get_selected_indices;
my $deref = $sel[0];
defined $deref or return;
my $menu = Gtk2::Menu->new();
# Right-click 'quarantine' option
my $quar_pop =
Gtk2::ImageMenuItem->new( gettext('Quarantine this file') );
my $quar_image =
Gtk2::Image->new_from_stock( 'gtk-refresh', 'menu' );
$quar_pop->set_image($quar_image);
$quar_pop->signal_connect(
activate => sub {
for my $t (@sel) {
next if ( $hash->{$t}->{name} =~ m#$maildirs# );
next if ( -d $hash->{$t}->{name} );
main_confirm( $t, 'q' );
}
} );
$quar_pop->show();
$menu->append($quar_pop)
unless dirname( $hash->{$deref}->{name} )
=~ /^\/(proc|sys|dev)/;
# Right-click 'delete' option
my $delete_pop =
Gtk2::ImageMenuItem->new( gettext('Delete this file') );
my $del_image =
Gtk2::Image->new_from_stock( 'gtk-delete', 'menu' );
$delete_pop->set_image($del_image);
$delete_pop->signal_connect(
activate => sub {
for my $u (@sel) {
next if ( $hash->{$u}->{name} =~ m#$maildirs# );
next if ( -d $hash->{$u}->{name} );
main_confirm( $u, 'd' );
}
} );
$delete_pop->show();
$menu->append($delete_pop)
unless dirname( $hash->{$deref}->{name} )
=~ /^\/(proc|sys|dev)/;
# Right-click 'save-as' option.
# This is useful if the file is 'opened' (intercepted)
# as a $web_browser download
my $save_pop =
Gtk2::ImageMenuItem->new_from_stock( 'gtk-save-as', undef );
$save_pop->signal_connect(
activate => sub {
return if ( -d $slist->{data}[$deref][0] );
my $save_dialog = Gtk2::FileChooserDialog->new(
gettext('Save As...'), undef, 'save',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok',
);
$save_dialog->set_do_overwrite_confirmation(TRUE);
$save_dialog->set_default_response('ok');
if ( "ok" eq $save_dialog->run ) {
my $tmp = $save_dialog->get_filename;
$save_dialog->destroy();
move( $slist->{data}[$deref][0], $tmp )
or do {
show_message_dialog( $popup, 'error', 'close',
gettext('Could not save that file.') );
return FALSE;
};
$slist->{data}[$deref][2] = gettext('Moved');
main_confirm( $deref, 's' );
show_message_dialog( $popup, 'info', 'close',
gettext('File saved.') );
return FALSE;
} else {
$save_dialog->destroy();
}
} );
$save_pop->show();
$menu->append($save_pop);
# Right-click 'cancel' option
my $cancel_pop =
Gtk2::ImageMenuItem->new_from_stock( 'gtk-cancel', undef );
$cancel_pop->signal_connect( activate => sub { return; } );
$cancel_pop->show();
$menu->append($cancel_pop);
$menu->popup( undef, undef, undef, undef, $event->button,
$event->time );
return TRUE;
} );
my $bottombar = Gtk2::Toolbar->new;
$bottombar->set_style('both-horiz');
$pbox->pack_start( $bottombar, FALSE, FALSE, 0 );
my $quar_img = Gtk2::Image->new_from_stock( 'gtk-refresh', 'menu' );
my $quar_btn = Gtk2::ToolButton->new( $quar_img, gettext('Quarantine') );
$quar_btn->set_is_important(TRUE);
$bottombar->insert( $quar_btn, -1 );
$quar_btn->signal_connect(
clicked => sub {
my @sel = $slist->get_selected_indices;
for my $t (@sel) {
next if ( $hash->{$t}->{name} =~ m#$maildirs# );
next if ( -d $hash->{$t}->{name} );
main_confirm( $t, 'q' );
}
} );
my $del_close_btn = Gtk2::ToolButton->new_from_stock('gtk-delete');
$del_close_btn->set_is_important(TRUE);
$bottombar->insert( $del_close_btn, -1 );
$del_close_btn->signal_connect(
clicked => sub {
my @sel = $slist->get_selected_indices;
for my $u (@sel) {
next if ( $hash->{$u}->{name} =~ m#$maildirs# );
next if ( -d $hash->{$u}->{name} );
main_confirm( $u, 'd' );
}
} );
my $b_sep = Gtk2::SeparatorToolItem->new;
$b_sep->set_draw(FALSE);
$b_sep->set_expand(TRUE);
$bottombar->insert( $b_sep, -1 );
my $results_close_btn = Gtk2::ToolButton->new_from_stock('gtk-close');
$results_close_btn->set_is_important(TRUE);
$bottombar->insert( $results_close_btn, -1 );
$results_close_btn->signal_connect(
clicked => sub {
$popup->destroy;
} );
$popup->show_all();
$slist->columns_autosize;
}
sub main_confirm {
# This sub accepts both quarantine and delete options.
# The quarantine happens without prompting, but deleting
# always prompts the user.
# $number = row of selected file so we can reference it
# $do_this = quarantine, delete
my $number = shift;
my $do_this = shift;
#my $full_name = $slist->{data}[$number][0];
my $full_name = $hash->{$number}->{name};
my $md5sum = $hash->{$number}->{md5sum};
my $status = $slist->{data}[$number][1];
my $action = $slist->{data}[$number][2];
# do_this = quarantine (q), delete (d), or save (s).
# The #CCCCCC color gives a neat grayed-out look
# once the file is quarantined, deleted, or saved
if ( $do_this eq 'q' ) {
if ( not -e $full_name ) {
$hover_label->set_text(
sprintf gettext('File has been moved or deleted already.') );
main_slist_delete($number);
return;
}
if ( move_to_quarantine($number) ) {
$hover_label->set_text( gettext('File has been quarantined.') );
$slist->{data}[$number][2] =
sprintf gettext("<b>Quarantined</b>");
} else {
$hover_label->set_text(
gettext('File could not be quarantined.') );
return;
}
} elsif ( $do_this eq 'd' ) {
if ( not -e $full_name ) {
$hover_label->set_text(
gettext('File has been moved or deleted already.') );
main_slist_delete($number);
return;
}
my $confirm_message = gettext('Really delete this file?');
$confirm_message .= ' ' . '(' . basename($full_name) . ')';
my $confirm =
Gtk2::MessageDialog->new( undef, [qw(modal destroy-with-parent)],
'question', 'ok-cancel', $confirm_message );
if ( 'cancel' eq $confirm->run ) {
$confirm->destroy;
return;
} else {
$confirm->destroy;
if ( unlink($full_name) ) {
$hover_label->set_text( gettext('File has been deleted.') );
$slist->{data}[$number][2] =
sprintf gettext("<b>Deleted</b>");
} else {
$hover_label->set_text(
gettext('File could not be deleted.') );
return;
}
}
} elsif ( $do_this eq 's' ) {
my $new_action = gettext('Moved');
$slist->{data}[$number][0] =
"<span foreground='#CCCCCC'>$full_name</span>";
$slist->{data}[$number][1] =
"<span foreground='#CCCCCC'>$status</span>";
$slist->{data}[$number][2] =
"<span foreground='#CCCCCC'><b>$new_action</b></span>";
return;
}
main_slist_delete($number);
return;
}
sub main_slist_delete {
my $number = shift;
#my $full_name = $slist->{data}[$number][0];
my $full_name = $hash->{$number}->{name};
my $status = $slist->{data}[$number][1];
my $action = $slist->{data}[$number][2];
$slist->{data}[$number][0] =
"<span foreground='#CCCCCC'>$full_name</span>";
$slist->{data}[$number][1] = "<span foreground='#CCCCCC'>$status</span>";
$slist->{data}[$number][2] = "<span foreground='#CCCCCC'>$action</span>";
#$popup->queue_draw;
return;
}
sub move_to_quarantine {
# $number = row we're dealing with
my $number = shift;
# We need the basename, because we're
# dealing with the filename, not the full_path
#my $full_name = $slist->{data}[$number][0];
#my $basename = basename($slist->{data}[$number][0]);
my $full_name = $hash->{$number}->{name};
my $basename = basename($full_name);
# This is where threats go
my $paths = ClamTk::App->get_path('viruses');
# Ensure quarantine directory exists
if ( not -e $paths or not -d $paths ) {
show_message_dialog( undef, 'info', 'close',
gettext('Quarantine directory does not exist.') );
return;
}
# Get permissions
my $mode = ( stat($full_name) )[2];
my $perm = sprintf( "%03o", $mode & oct(7777) );
# Assign 600 permissions
chmod oct(600), $full_name;
move( $full_name, "$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. No need to check for failure.
unlink("$paths/$basename");
return;
};
# Update restore file by adding file, path and md5
my $ctx = do {
local $/ = undef;
open( my $F, '<', "$paths/$basename" ) or do {
warn "Could not open file for md5-ing: $!\n";
return;
};
binmode($F);
<$F>;
};
my $md5 = md5_hex($ctx);
ClamTk::Prefs->restore( $md5, 'add', $full_name, $perm );
if ( not -e $full_name ) {
return 1;
} else {
return -1;
}
}
sub show_message_dialog {
my ( $parent, $type, $button, $message ) = @_;
my $dialog;
$dialog =
Gtk2::MessageDialog->new_with_markup( $parent,
[qw(modal destroy-with-parent)],
$type, $button, $message );
$dialog->run;
$dialog->destroy;
return;
}
1;
|