4 |
use strict; |
use strict; |
5 |
use BackupPC::CGI::Lib qw(:all); |
use BackupPC::CGI::Lib qw(:all); |
6 |
use BackupPC::Attrib qw(:all); |
use BackupPC::Attrib qw(:all); |
|
use Data::Dumper; |
|
7 |
use DBI; |
use DBI; |
8 |
|
|
9 |
sub getUnits() { |
sub getUnits() { |
24 |
} |
} |
25 |
|
|
26 |
sub getWhere($) { |
sub getWhere($) { |
27 |
my ($param) = @_; |
my ($param) = @_; |
28 |
my $retSQL = ""; |
my @conditions; |
|
my @conditions = (); |
|
|
my $cond; |
|
29 |
|
|
30 |
|
sub mk_iso_date($$) { |
31 |
|
my ($name,$suffix) = @_; |
|
|
|
|
if ( defined( $param->{'search_backup_day_from'} ) && $param->{'search_backup_day_from'} ne "") { |
|
|
push( @conditions, |
|
|
' strftime("%d", datetime(backups.date, "unixepoch","localtime")) >= "' |
|
|
. $param->{'search_backup_day_from'} ."\""); |
|
|
} |
|
|
if ( defined( $param->{'search_backup_day_to'} ) && $param->{'search_backup_day_to'} ne "") { |
|
|
push( @conditions, |
|
|
' strftime("%d", datetime(backups.date, "unixepoch","localtime")) <= "' |
|
|
. $param->{'search_backup_day_from'} ."\""); |
|
|
} |
|
|
if ( defined( $param->{'search_backup_month_from'} ) && $param->{'search_backup_month_from'} ne "") { |
|
|
push( @conditions, |
|
|
' strftime("%m", datetime(backups.date, "unixepoch","localtime")) >= "' |
|
|
. $param->{'search_backup_month_from'} ."\""); |
|
|
} |
|
|
if ( defined( $param->{'search_backup_month_to'} ) && $param->{'search_backup_month_to'} ne "") { |
|
|
push( @conditions, |
|
|
' strftime("%m", datetime(backups.date, "unixepoch","localtime")) <= "' |
|
|
. $param->{'search_backup_month_to'} ."\""); |
|
|
} |
|
|
if ( defined( $param->{'search_backup_year_from'} ) && $param->{'search_backup_year_from'} ne "") { |
|
|
push( @conditions, |
|
|
' strftime("%Y", datetime(backups.date, "unixepoch","localtime")) >= "' |
|
|
. $param->{'search_backup_year_from'} ."\""); |
|
|
} |
|
|
if ( defined( $param->{'search_backup_year_to'} ) && $param->{'search_backup_year_to'} ne "") { |
|
|
push( @conditions, |
|
|
' strftime("%Y", datetime(backups.date, "unixepoch","localtime")) <= "' |
|
|
. $param->{'search_backup_year_to'} ."\""); |
|
|
} |
|
32 |
|
|
33 |
if ( defined( $param->{'search_day_from'} ) && $param->{'search_day_from'} ne "" ) { |
my $yyyy = $param->{ $name . '_year_' . $suffix} || return; |
34 |
push( @conditions, |
my $mm .= $param->{ $name . '_month_' . $suffix} || |
35 |
' strftime("%d", datetime(files.date, "unixepoch","localtime")) >= "' |
( $suffix eq 'from' ? 1 : 12); |
36 |
. $param->{'search_day_from'} ."\""); |
my $dd .= $param->{ $name . '_day_' . $suffix} || |
37 |
} |
( $suffix eq 'from' ? 1 : 31); |
38 |
if ( defined( $param->{'search_month_from'} ) && $param->{'search_month_from'} ne "") { |
return sprintf("%04d-%02d-%02d", $yyyy, $mm, $dd); |
39 |
push( @conditions, |
} |
|
' strftime("%m", datetime(files.date, "unixepoch","localtime")) >= "' |
|
|
. $param->{'search_month_from'} ."\""); |
|
|
} |
|
|
if ( defined( $param->{'search_year_from'} ) && $param->{'search_year_from'} ne "") { |
|
|
push( @conditions, |
|
|
' strftime("%Y", datetime(files.date, "unixepoch","localtime")) >= "' |
|
|
. $param->{'search_year_from'} ."\""); |
|
|
} |
|
|
if ( defined( $param->{'search_day_to'} ) && $param->{'search_day_to'} ne "" ) { |
|
|
push( @conditions, |
|
|
' strftime("%d", datetime(files.date, "unixepoch","localtime")) <= "' |
|
|
. $param->{'search_day_to'} ."\""); |
|
|
} |
|
|
if ( defined( $param->{'search_month_to'} ) && $param->{'search_month_to'} ne "" ) { |
|
|
push( @conditions, |
|
|
' strftime("%m", datetime(files.date, "unixepoch","localtime")) <= "' |
|
|
. $param->{'search_month_to'} ."\"" ); |
|
|
} |
|
|
if ( defined( $param->{'search_year_to'} )&& $param->{'search_year_to'} ne "" ) { |
|
|
push( @conditions, |
|
|
' strftime("%Y", datetime(files.date, "unixepoch","localtime")) <= "' |
|
|
. $param->{'search_year_to'} ."\""); |
|
|
} |
|
40 |
|
|
41 |
if ( defined( $param->{'search_host'} ) && $param->{'search_host'} ne "") { |
my $backup_from = mk_iso_date('search_backup', 'from'); |
42 |
push( @conditions, ' backups.hostID = ' . $param->{'search_host'} ); |
push @conditions, qq{ date(backups.date, 'unixepoch','localtime') >= '$backup_from' } if ($backup_from); |
43 |
} |
my $backup_to = mk_iso_date('search_backup', 'to'); |
44 |
|
push @conditions, qq{ date(backups.date, 'unixepoch','localtime') <= '$backup_to' } if ($backup_to); |
45 |
|
|
46 |
|
my $files_from = mk_iso_date('search', 'from'); |
47 |
|
push @conditions, qq{ date(files.date, 'unixepoch','localtime') >= '$files_from' } if ($files_from); |
48 |
|
my $files_to = mk_iso_date('search', 'to'); |
49 |
|
push @conditions, qq{ date(files.date, 'unixepoch','localtime') <= '$files_to' } if ($files_to); |
50 |
|
|
51 |
if ( defined ($param->{'search_filename'}) && $param->{'search_filename'} ne "") { |
print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:",join(" | ",@conditions); |
|
push (@conditions, " files.name LIKE '".$param->{'search_filename'}."%'"); |
|
|
} |
|
52 |
|
|
53 |
$retSQL = ""; |
push( @conditions, ' backups.hostID = ' . $param->{'search_host'} ) if ($param->{'search_host'}); |
|
foreach $cond(@conditions) |
|
|
{ |
|
|
if ($retSQL ne "") |
|
|
{ |
|
|
$retSQL .= " AND "; |
|
|
} |
|
|
$retSQL .= $cond; |
|
|
} |
|
54 |
|
|
55 |
|
push (@conditions, " upper(files.name) LIKE upper('%".$param->{'search_filename'}."%')") if ($param->{'search_filename'}); |
56 |
return $retSQL; |
|
57 |
|
return ( |
58 |
|
join(" and ", @conditions), |
59 |
|
$files_from, $files_to, |
60 |
|
$backup_from, $backup_to |
61 |
|
); |
62 |
} |
} |
63 |
|
|
64 |
|
|
65 |
sub getFiles($$) |
sub getFiles($$) |
66 |
{ |
{ |
67 |
my ($where, $offset) = @_; |
my ($where, $offset) = @_; |
86 |
FROM files |
FROM files |
87 |
INNER JOIN shares ON files.shareID=shares.ID |
INNER JOIN shares ON files.shareID=shares.ID |
88 |
INNER JOIN hosts ON hosts.ID = shares.hostID |
INNER JOIN hosts ON hosts.ID = shares.hostID |
89 |
|
INNER JOIN backups ON backups.num = files.backupNum and backups.hostID = hosts.ID |
90 |
LEFT JOIN dvds ON dvds.ID = files.dvdid |
LEFT JOIN dvds ON dvds.ID = files.dvdid |
91 |
}; |
}; |
92 |
|
|
278 |
$retHTML .= qq{ |
$retHTML .= qq{ |
279 |
<table style="fview" width="100%"> |
<table style="fview" width="100%"> |
280 |
<tr> |
<tr> |
281 |
<td class="tableheader">Host</td> |
<td class="tableheader">Share</td> |
|
<td class="tableheader">Type</td> |
|
282 |
<td class="tableheader">Name</td> |
<td class="tableheader">Name</td> |
283 |
<td class="tableheader">backup no.</td> |
<td class="tableheader">Type</td> |
284 |
<td class="tableheader">size</td> |
<td class="tableheader">#</td> |
285 |
<td class="tableheader">date</td> |
<td class="tableheader">Size</td> |
286 |
|
<td class="tableheader">Date</td> |
287 |
<td class="tableheader">Media</td> |
<td class="tableheader">Media</td> |
288 |
</tr> |
</tr> |
289 |
}; |
}; |
296 |
return $html; |
return $html; |
297 |
} |
} |
298 |
|
|
299 |
foreach $file (@files) { |
sub restore_link($$$$$$) { |
300 |
my $ftype = "file"; |
my $type = shift; |
301 |
$ftype = "dir" if ($file->{'type'} == BPC_FTYPE_DIR); |
my $action = 'RestoreFile'; |
302 |
|
$action = 'browse' if (lc($type) eq 'dir'); |
303 |
|
return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_); |
304 |
|
} |
305 |
|
|
306 |
|
foreach $file (@files) { |
307 |
|
my $typeStr = BackupPC::Attrib::fileType2Text(undef, $file->{'type'}); |
308 |
$retHTML .= "<tr>"; |
$retHTML .= "<tr>"; |
309 |
|
|
310 |
foreach my $v (( |
foreach my $v (( |
311 |
$file->{'hname'}, |
$file->{'sharename'}, |
312 |
$ftype, |
qq{<img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" align="center"> } . hilite_html( $file->{'fpath'}, $hilite ), |
313 |
hilite_html( $file->{'fpath'}, $hilite ), |
$typeStr, |
314 |
$file->{'backupno'}, |
restore_link( $typeStr, $file->{'hname'}, $file->{'backupno'}, $file->{'sname'}, $file->{'fpath'}, $file->{'backupno'} ), |
315 |
$file->{'size'}, |
$file->{'size'}, |
316 |
$file->{'date'}, |
$file->{'date'}, |
317 |
$file->{'dvd'} |
$file->{'dvd'} |