/usr/share/perl5/ClamTk/App.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 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 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | # 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::App;
# use strict;
# use warnings;
$| = 1;
use Time::Piece;
use File::Basename 'basename';
use POSIX 'locale_h';
use Locale::gettext;
use Encode 'decode';
sub get_TK_version {
# Stick with %.2f format - 4.50 vice 4.5
return '5.20';
}
sub get_path {
my ( undef, $wanted ) = @_;
my $path;
# These are directories and files necessary for
# preferences, storing AV signatures, and more
# Images directory:
# This is a "global" setting which may need
# to be changed depending on distro, so it's first
$path->{ images } = '/usr/share/pixmaps/';
# Now, determine home directory
$path->{ directory } = $ENV{ HOME } || ( ( getpwuid $< )[ -2 ] );
# Default personal clamtk directory
$path->{ clamtk } = $path->{ directory } . '/.clamtk';
# Trash directory - main
$path->{ trash_dir } = $path->{ directory } . '/.local/share/Trash';
# Trash directory - where files are held
$path->{ trash_dir_files } = $path->{ trash_dir } . '/files';
# Trash directory - where associated files are held:
# e.g. trash.jpg.trashinfo
$path->{ trash_files_info } = $path->{ trash_dir } . '/info';
# For storing quarantined files
$path->{ viruses } = $path->{ clamtk } . '/viruses';
# Store history logs here
$path->{ history } = $path->{ clamtk } . '/history';
# Plain text file for preferences
$path->{ prefs } = $path->{ clamtk } . '/prefs';
# Plain text file for restoring quarantined files
$path->{ restore } = $path->{ clamtk } . '/restore';
# The db directory stores virus defs/freshclam-related stuff
$path->{ db } = $path->{ clamtk } . '/db';
# The submit directory stores file submission information
$path->{ submit } = $path->{ clamtk } . '/submit';
# Keeps track of previous VT submissions
$path->{ previous_submissions }
= $path->{ submit } . '/previous_submissions';
# Keeps track of previous VT submissions
$path->{ virustotal_links } = $path->{ submit } . '/virustotal_links';
# Default variables
$path->{ whitelist_dir }
= join( ';', $path->{ viruses }, '/sys', '/dev', '/proc;' );
# Most times freshclam is under /usr/bin
$path->{ freshclam }
= ( -e '/usr/bin/freshclam' ) ? '/usr/bin/freshclam'
: ( -e '/usr/local/bin/freshclam' ) ? '/usr/local/bin/freshclam'
: ( -e '/opt/local/bin/freshclam' ) ? '/opt/local/bin/freshclam'
: '';
# Use sigtool for db info
$path->{ sigtool }
= ( -e '/usr/bin/sigtool' ) ? '/usr/bin/sigtool'
: ( -e '/usr/local/bin/sigtool' ) ? '/usr/local/bin/sigtool'
: ( -e '/opt/local/bin/sigtool' ) ? '/opt/local/bin/sigtool'
: '';
# Most times clamscan is under /usr/bin
# We'll use clampath as the actual path
# and clamscan as clampath + scan options
$path->{ clampath }
= ( -e '/usr/bin/clamscan' ) ? '/usr/bin/clamscan'
: ( -e '/usr/local/bin/clamscan' ) ? '/usr/local/bin/clamscan'
: ( -e '/opt/local/bin/clamscan' ) ? '/opt/local/bin/clamscan'
: '';
$path->{ clamscan } = $path->{ clampath };
# The default ClamAV options:
# leave out the summary and warn on encrypted
$path->{ clamscan } .= ' --no-summary --block-encrypted ';
return ( $wanted eq 'all' ) ? $path : $path->{ $wanted };
}
sub get_daily_sigs_path {
# Returns path_of_daily.c?d
# There are (or have been) 3 formats:
# 1. The .cld files
# 2. The .cvd files
# 3. The {daily,main}.info directories
# As of 4.23, we're no longer looking for the .info dirs.
# The .cvd is the compressed database, while .cld is a
# previous .cvd/.cld with incremental updates.
# The problem is that you can end up with both a
# daily.cvd AND a daily.cld, and it's a crapshoot as to
# which one will show the most current date. So we'll return
# just the directory path, compare dates, and return
# the most current date.
# Path to the daily.c{l,v}d file(s)
my $DAILY_PATH;
# These are the typical directories where the sigs are found.
# Because CentOS is a little screwy, it will often contain two
# directories of definitions... The newer one is likely in
# /var/clamav, so check that first. Other distros will
# likely find the defs under /var/lib/clamav.
my @dirs = qw(
/var/clamav
/var/lib/clamav
/opt/local/share/clamav
/usr/share/clamav
/usr/local/share/clamav
/var/db/clamav
);
# If the user selected "manual", that directory needs
# to be checked first, so we'll jam that in with unshift.
my $user_set = 0;
my $update_method = ClamTk::Prefs->get_preference( 'Update' );
if ( $update_method eq 'single' ) {
$user_set = 1;
my $paths = ClamTk::App->get_path( 'db' );
unshift( @dirs, $paths );
}
# We'll search for the daily file then main;
# Check for daily's .cld before .cvd,
# but main's .cvd before .cld
my $dupe_db = ClamTk::Prefs->get_preference( 'DupeDB' );
for my $dir_list ( @dirs ) {
# Check for duplicate daily databases
if ( -e "$dir_list/daily.cld" && -e "$dir_list/daily.cvd" ) {
only_one( "$dir_list" )
if ( ( $dupe_db && $update_method eq 'single' )
or ( $dupe_db && $> == 0 ) );
}
if ( -e "$dir_list/daily.cld" ) {
$DAILY_PATH = "$dir_list/daily.cld";
} elsif ( -e "$dir_list/daily.cvd" ) {
$DAILY_PATH = "$dir_list/daily.cvd";
}
last if ( $DAILY_PATH );
# the user may have set single - may need to update db
last if ( $user_set );
}
return $DAILY_PATH;
}
sub get_main_sigs_path {
# Path to the main.c{l,v}d file(s)
my $MAIN_PATH;
# If the user selected "manual", that directory needs
# to be checked first, so we'll jam that in with unshift.
my $update_method = ClamTk::Prefs->get_preference( 'Update' );
my $user_set = 0;
my @dirs = qw(
/var/clamav
/var/lib/clamav
/opt/local/share/clamav
/usr/share/clamav
/usr/local/share/clamav
/var/db/clamav
);
# Check for duplicate main databases
my $dupe_db = ClamTk::Prefs->get_preference( 'DupeDB' );
for my $dir_list ( @dirs ) {
# Check for duplicate daily databases
if ( -e "$dir_list/main.cld" && "$dir_list/main.cvd" ) {
unlink( "$dir_list/main.cld" )
if ( ( $dupe_db && $update_method eq 'single' )
or ( $dupe_db && $> == 0 ) );
}
if ( -e "$dir_list/main.cvd" ) {
$MAIN_PATH = "$dir_list/main.cvd";
} elsif ( -e "$dir_list/main.cld" ) {
$MAIN_PATH = "$dir_list/main.cld";
}
last if ( $MAIN_PATH );
# the user may have set single - may need to update db
last if ( $user_set );
}
return $MAIN_PATH;
}
sub get_local_sig_version {
my $daily = get_daily_sigs_path();
my $sigtool = get_path( undef, 'sigtool' );
my $version = 0;
if ( -e $daily ) {
if ( open( my $CLD, '-|', "$sigtool -i $daily" ) ) {
while ( <$CLD> ) {
if ( /Version: (\d+)/ ) {
$version = $1;
}
}
}
}
return ( $version =~ /\d+/ ) ? $version : _( 'Unknown' );
}
sub only_one {
my ( $location ) = shift;
my $basename = basename( $location );
my ( $cld, $cvd ) = ( '01 Jan 1900' ) x 2;
my $sigtool = get_path( undef, 'sigtool' );
if ( open( my $CLD, '-|', "$sigtool -i $location/daily.cld" ) ) {
while ( <$CLD> ) {
if ( /Build time: (\d+\s\w+\s\d{4})/ ) {
$cld = $1;
last;
}
}
} else {
# shouldn't happen
$cld = '01 01 1970';
}
if ( open( my $CVD, '-|', "$sigtool -i $location/daily.cvd" ) ) {
while ( <$CVD> ) {
if ( /Build time: (\d+\s\w+\s\d{4})/ ) {
$cvd = $1;
last;
}
}
} else {
# shouldn't happen
$cvd = '01 01 1970';
}
my $cmp = comp_dates( $cld, $cvd );
# If cmp == -1, cvd is newer.
# If cmp == 1, cld is newer.
# If cmp == 0, they're the same.
if ( $cmp == -1 ) {
unlink( "$location/daily.cld" )
or warn "Cannot delete $location/daily.cld: $!\n";
} elsif ( $cmp == 1 ) {
unlink( "$location/daily.cvd" )
or warn "Cannot delete $location/daily.cvd: $!\n";
} elsif ( $cmp == 0 ) {
unlink( "$location/daily.cvd" )
or warn "Cannot delete $location/daily.cvd: $!\n";
}
return;
}
sub get_AV_version {
# simple 'clamscan -V'.
# We have to parse something like this:
# ClamAV 0.95.3/11220/Fri Jun 18 22:06:39 2010
# Worth keeping an eye on since it's changed in
# past without me noticing...
local $ENV{ 'PATH' } = '/bin:/usr/bin:/usr/local/bin';
delete @ENV{ 'IFS', 'CDPATH', 'ENV', 'BASH_ENV' };
my $paths = ClamTk::App->get_path( 'clampath' );
my $version = '';
if ( open( my $c, '-|', $paths, '-V' ) ) {
while ( <$c> ) {
chomp;
$version = $_;
}
}
$version =~ s/^\S+\s+([0-9\.]+).*/$1/;
return $version ? $version : '0.00';
}
sub get_sigtool_info {
# Should get requests for:
# count: add up daily/main sigs
# version: version count found in sigs
# date: show build time of sigs
my ( undef, $wanted ) = @_;
my $regex = '';
if ( $wanted eq 'date' ) {
# Build time: 16 Aug 2013
$regex = qr|Build time:\s(\d+\s\w+\s\d{4})|;
} elsif ( $wanted eq 'version' ) {
# Version: 17694
$regex = qr|Version:\s(\d+)|;
} elsif ( $wanted eq 'count' ) {
# Signatures: 1614500
$regex = qr|Signatures: (\d+)|;
}
my $result = '';
my $sigtool = get_path( undef, 'sigtool' );
my $daily_path = get_daily_sigs_path();
my $main_path = get_main_sigs_path();
my $found_wanted = 0;
if ( -e $daily_path ) {
if ( open( my $cld_db, '-|', "$sigtool -i $daily_path" ) ) {
while ( <$cld_db> ) {
if ( /$regex/ ) {
chomp;
$result = $1;
}
}
}
}
if ( $wanted eq 'count' ) {
if ( -e $main_path ) {
if ( open( my $main_db, '-|', "$sigtool -i $main_path" ) ) {
while ( <$main_db> ) {
if ( /$regex/ ) {
chomp;
$result += $1;
}
}
}
}
}
# If the date is wanted, we have to tweak the results
# first. Instead of getting translations for each 3 letter
# month abbreviation, it's easier to change it to digits
# and display it as $YEAR $MONTH $DAY (2013 08 01).
if ( $wanted eq 'date' && $result ) {
my ( $day, $month, $year ) = split( / /, $result );
my %months = (
'Jan' => '01',
'Feb' => '02',
'Mar' => '03',
'Apr' => '04',
'May' => '05',
'Jun' => '06',
'Jul' => '07',
'Aug' => '08',
'Sep' => '09',
'Oct' => 10,
'Nov' => 11,
'Dec' => 12,
);
$result = join( ' ', $year, $months{ $month }, $day );
}
return $result;
}
sub lastscan {
my $path = ClamTk::App->get_path( 'history' );
my @logs = glob "$path/*.log";
return _( 'Never' ) if ( !@logs );
my %orcs;
my @newer
= sort { ( $orcs{ $a } ||= -M $a ) <=> ( $orcs{ $b } ||= -M $b ) }
@logs;
# The newest "file" (actually a string/scalar)
# is a path like /home/foo/.clamtk/histories/01-01-Jan.log.
# We just want the basename of that.
my $chosen = basename( $newer[ 0 ] );
my ( $month, $day, $year ) = split( /-/, $chosen );
$year =~ s/(\d+)\.log/$1/;
return "$day $month $year";
}
sub comp_dates {
my ( $cld, $cvd ) = @_;
my %months = (
'Jan' => 1,
'Feb' => 2,
'Mar' => 3,
'Apr' => 4,
'May' => 5,
'Jun' => 6,
'Jul' => 7,
'Aug' => 8,
'Sep' => 9,
'Oct' => 10,
'Nov' => 11,
'Dec' => 12,
);
my ( $cld_day, $cld_mon, $cld_year ) = split( /\s/, $cld );
my ( $cvd_day, $cvd_mon, $cvd_year ) = split( /\s/, $cvd );
my $cld_zone = $cld_day . ' ' . $months{ $cld_mon } . ' ' . $cld_year;
my $cvd_zone = $cvd_day . ' ' . $months{ $cvd_mon } . ' ' . $cld_year;
my $date_format = '%d %m %Y';
$cld_zone = Time::Piece->strptime( $cld_zone, $date_format );
$cvd_zone = Time::Piece->strptime( $cvd_zone, $date_format );
my $cmp = ( $cld_zone ) <=> ( $cvd_zone );
# If cmp == -1, cvd is newer.
# If cmp == 1, cld is newer.
# If cmp == 0, they're the same.
return $cmp;
}
sub translate {
# This is a dummy routine, solely for the .desktop file
# and other spots...
my $a = _( 'Scan for threats...' );
$a = _( 'Advanced' );
$a = _( 'Scan a file' );
$a = _( 'Scan a directory' );
return $a;
}
sub _ {
# stupid gettext wrapper
return decode( 'utf8', gettext( $_[ 0 ] ) );
}
1;
|