62 |
sub mk_epoch_date($$) { |
sub mk_epoch_date($$) { |
63 |
my ($name,$suffix) = @_; |
my ($name,$suffix) = @_; |
64 |
|
|
65 |
my $yyyy = $param->{ $name . '_year_' . $suffix} || return; |
my $yyyy = $param->{ $name . '_year_' . $suffix} || return undef; |
66 |
my $mm .= $param->{ $name . '_month_' . $suffix} || |
my $mm .= $param->{ $name . '_month_' . $suffix} || |
67 |
( $suffix eq 'from' ? 1 : 12); |
( $suffix eq 'from' ? 1 : 12); |
68 |
my $dd .= $param->{ $name . '_day_' . $suffix} || |
my $dd .= $param->{ $name . '_day_' . $suffix} || |
69 |
( $suffix eq 'from' ? 1 : 31); |
( $suffix eq 'from' ? 1 : 31); |
70 |
|
|
71 |
|
$yyyy =~ s/\D//g; |
72 |
|
$mm =~ s/\D//g; |
73 |
|
$dd =~ s/\D//g; |
74 |
|
|
75 |
my $dt = new DateTime( |
my $dt = new DateTime( |
76 |
year => $yyyy, |
year => $yyyy, |
77 |
month => $mm, |
month => $mm, |
78 |
day => $dd |
day => $dd |
79 |
); |
); |
80 |
|
print STDERR "mk_epoch_date($name,$suffix) [$yyyy-$mm-$dd] = " . $dt->ymd . " " . $dt->hms . "\n"; |
81 |
return $dt->epoch || 'NULL'; |
return $dt->epoch || 'NULL'; |
82 |
} |
} |
83 |
|
|
84 |
return ( |
my @ret = ( |
85 |
mk_epoch_date('search_backup', 'from'), |
mk_epoch_date('search_backup', 'from'), |
86 |
mk_epoch_date('search_backup', 'to'), |
mk_epoch_date('search_backup', 'to'), |
87 |
mk_epoch_date('search', 'from'), |
mk_epoch_date('search', 'from'), |
88 |
mk_epoch_date('search', 'to'), |
mk_epoch_date('search', 'to'), |
89 |
); |
); |
90 |
|
|
91 |
|
return @ret; |
92 |
|
|
93 |
} |
} |
94 |
|
|
95 |
|
|
113 |
} |
} |
114 |
|
|
115 |
|
|
116 |
sub getFiles($$) { |
sub getFiles($) { |
117 |
my ($param, $offset) = @_; |
my ($param) = @_; |
118 |
|
|
119 |
|
my $offset = $param->{'offset'} || 0; |
120 |
|
$offset *= $on_page; |
121 |
|
|
122 |
my $dbh = get_dbh(); |
my $dbh = get_dbh(); |
123 |
|
|
125 |
files.id AS fid, |
files.id AS fid, |
126 |
hosts.name AS hname, |
hosts.name AS hname, |
127 |
shares.name AS sname, |
shares.name AS sname, |
|
-- shares.share AS sharename, |
|
128 |
files.backupnum AS backupnum, |
files.backupnum AS backupnum, |
|
-- files.name AS filename, |
|
129 |
files.path AS filepath, |
files.path AS filepath, |
130 |
files.date AS date, |
files.date AS date, |
131 |
files.type AS type, |
files.type AS type, |
132 |
files.size AS size, |
files.size AS size |
|
-- dvds.name AS dvd |
|
|
null AS dvd |
|
133 |
}; |
}; |
134 |
|
|
135 |
my $sql_from = qq{ |
my $sql_from = qq{ |
136 |
FROM files |
FROM files |
137 |
INNER JOIN shares ON files.shareID=shares.ID |
INNER JOIN shares ON files.shareID=shares.ID |
138 |
INNER JOIN hosts ON hosts.ID = shares.hostID |
INNER JOIN hosts ON hosts.ID = shares.hostID |
139 |
INNER JOIN backups ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = shares.ID |
INNER JOIN backups ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = files.shareID |
|
}; |
|
|
|
|
|
my $sql_dvd_from = qq{ |
|
|
-- LEFT JOIN dvds ON dvds.ID = files.dvdid |
|
140 |
}; |
}; |
141 |
|
|
142 |
my $sql_where; |
my $sql_where; |
150 |
}; |
}; |
151 |
|
|
152 |
my $sql_count = qq{ select count(files.id) $sql_from $sql_where }; |
my $sql_count = qq{ select count(files.id) $sql_from $sql_where }; |
153 |
my $sql_results = qq{ select $sql_cols $sql_from $sql_dvd_from $sql_where $sql_order }; |
my $sql_results = qq{ select $sql_cols $sql_from $sql_where $sql_order }; |
|
|
|
|
$offset ||= 0; |
|
|
$offset = ($offset * $on_page); |
|
154 |
|
|
155 |
my $sth = $dbh->prepare($sql_count); |
my $sth = $dbh->prepare($sql_count); |
156 |
$sth->execute(); |
$sth->execute(); |
175 |
return ($results, \@ret); |
return ($results, \@ret); |
176 |
} |
} |
177 |
|
|
178 |
sub getFilesHyperEstraier($$) { |
sub getHyperEstraier_url($) { |
179 |
my ($param, $offset) = @_; |
my ($use_hest) = @_; |
180 |
|
|
181 |
|
return unless $use_hest; |
182 |
|
|
183 |
|
use HyperEstraier; |
184 |
|
my ($index_path, $index_node_url); |
185 |
|
|
186 |
|
if ($use_hest =~ m#^http://#) { |
187 |
|
$index_node_url = $use_hest; |
188 |
|
} else { |
189 |
|
$index_path = $TopDir . '/' . $index_path; |
190 |
|
$index_path =~ s#//#/#g; |
191 |
|
} |
192 |
|
return ($index_path, $index_node_url); |
193 |
|
} |
194 |
|
|
195 |
|
sub getFilesHyperEstraier($) { |
196 |
|
my ($param) = @_; |
197 |
|
|
198 |
|
my $offset = $param->{'offset'} || 0; |
199 |
|
$offset *= $on_page; |
200 |
|
|
201 |
die "no index_path?" unless ($index_path); |
die "no index_path?" unless ($index_path); |
202 |
|
|
203 |
use HyperEstraier; |
use HyperEstraier; |
204 |
|
|
205 |
|
my ($index_path, $index_node_url) = getHyperEstraier_url($index_path); |
206 |
|
|
207 |
# open the database |
# open the database |
208 |
my $db = HyperEstraier::Database->new(); |
my $db; |
209 |
$db->open($index_path, $HyperEstraier::ESTDBREADER); |
if ($index_path) { |
210 |
|
$db = HyperEstraier::Database->new(); |
211 |
|
$db->open($index_path, $HyperEstraier::ESTDBREADER); |
212 |
|
} elsif ($index_node_url) { |
213 |
|
$db ||= HyperEstraier::Node->new($index_node_url); |
214 |
|
$db->set_auth('admin', 'admin'); |
215 |
|
} else { |
216 |
|
die "BUG: unimplemented"; |
217 |
|
} |
218 |
|
|
219 |
# create a search condition object |
# create a search condition object |
220 |
my $cond = HyperEstraier::Condition->new(); |
my $cond = HyperEstraier::Condition->new(); |
222 |
my $q = $param->{'search_filename'}; |
my $q = $param->{'search_filename'}; |
223 |
my $shareid = $param->{'search_share'}; |
my $shareid = $param->{'search_share'}; |
224 |
|
|
225 |
if ($q) { |
if (length($q) > 0) { |
226 |
$q =~ s/(.)/$1 /g; |
# exact match |
227 |
|
$cond->add_attr("filepath ISTRINC $q"); |
228 |
|
|
229 |
|
$q =~ s/(.)/$1 /g; |
230 |
# set the search phrase to the search condition object |
# set the search phrase to the search condition object |
231 |
$cond->set_phrase($q); |
$cond->set_phrase($q); |
232 |
|
} |
233 |
|
|
234 |
my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param); |
my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param); |
|
|
|
|
$cond->add_attr("backup_date NUMGE $backup_from") if ($backup_from); |
|
|
$cond->add_attr("backup_date NUMLE $backup_to") if ($backup_to); |
|
235 |
|
|
236 |
$cond->add_attr("date NUMGE $files_from") if ($files_from); |
$cond->add_attr("backup_date NUMGE $backup_from") if ($backup_from); |
237 |
$cond->add_attr("date NUMLE $files_to") if ($files_to); |
$cond->add_attr("backup_date NUMLE $backup_to") if ($backup_to); |
238 |
|
|
239 |
$cond->add_attr("shareid NUMEQ $shareid") if ($shareid); |
$cond->add_attr("date NUMGE $files_from") if ($files_from); |
240 |
} |
$cond->add_attr("date NUMLE $files_to") if ($files_to); |
241 |
|
|
242 |
$offset ||= 0; |
$cond->add_attr("shareid NUMEQ $shareid") if ($shareid); |
|
$offset = ($offset * $on_page); |
|
243 |
|
|
244 |
# $cond->set_max( $offset + $on_page ); |
# $cond->set_max( $offset + $on_page ); |
245 |
$cond->set_options( $HyperEstraier::Condition::SURE ); |
$cond->set_options( $HyperEstraier::Condition::SURE ); |
246 |
$cond->set_order( 'date NUMA' ); |
$cond->set_order( 'date NUMA' ); |
247 |
|
|
248 |
# get the result of search |
# get the result of search |
|
my $result = $db->search($cond, 0); |
|
|
$result->get(0); |
|
|
|
|
249 |
my @res; |
my @res; |
250 |
my $hits = $result->size; |
my ($result, $hits); |
251 |
|
|
252 |
|
if ($index_path) { |
253 |
|
$result = $db->search($cond, 0); |
254 |
|
$hits = $result->size; |
255 |
|
} elsif ($index_node_url) { |
256 |
|
$result = $db->search($cond, 0); |
257 |
|
$hits = $result->doc_num; |
258 |
|
} else { |
259 |
|
die "BUG: unimplemented"; |
260 |
|
} |
261 |
|
|
262 |
# for each document in result |
# for each document in result |
263 |
for my $i ($offset .. $result->size-1) { |
for my $i ($offset .. ($offset + $on_page - 1)) { |
264 |
my $id = $result->get($i); |
last if ($i >= $hits); |
265 |
my $doc = $db->get_doc($id, 0); |
|
266 |
|
my $doc; |
267 |
|
if ($index_path) { |
268 |
|
my $id = $result->get($i); |
269 |
|
$doc = $db->get_doc($id, 0); |
270 |
|
} elsif ($index_node_url) { |
271 |
|
$doc = $result->get_doc($i); |
272 |
|
} else { |
273 |
|
die "BUG: unimplemented"; |
274 |
|
} |
275 |
|
|
276 |
my $row; |
my $row; |
277 |
foreach my $c (qw/fid hname sname backupnum fiilename filepath date type size/) { |
foreach my $c (qw/fid hname sname backupnum fiilename filepath date type size/) { |
283 |
return ($hits, \@res); |
return ($hits, \@res); |
284 |
} |
} |
285 |
|
|
286 |
|
sub getGzipName($$$) |
287 |
|
{ |
288 |
|
my ($host, $share, $backupnum) = @_; |
289 |
|
my $ret = $Conf{GzipSchema}; |
290 |
|
|
291 |
|
$share =~ s/\//_/g; |
292 |
|
$ret =~ s/\\h/$host/ge; |
293 |
|
$ret =~ s/\\s/$share/ge; |
294 |
|
$ret =~ s/\\n/$backupnum/ge; |
295 |
|
|
296 |
|
return $ret; |
297 |
|
|
298 |
|
} |
299 |
|
|
300 |
sub getBackupsNotBurned() { |
sub getBackupsNotBurned() { |
301 |
|
|
302 |
my $dbh = get_dbh(); |
my $dbh = get_dbh(); |
304 |
SELECT |
SELECT |
305 |
backups.hostID AS hostid, |
backups.hostID AS hostid, |
306 |
min(hosts.name) AS host, |
min(hosts.name) AS host, |
307 |
|
min(shares.name) AS share, |
308 |
backups.num AS backupnum, |
backups.num AS backupnum, |
309 |
min(backups.type) AS type, |
min(backups.type) AS type, |
310 |
min(backups.date) AS date, |
min(backups.date) AS date, |
313 |
INNER JOIN shares ON files.shareID=shares.ID |
INNER JOIN shares ON files.shareID=shares.ID |
314 |
INNER JOIN hosts ON hosts.ID = shares.hostID |
INNER JOIN hosts ON hosts.ID = shares.hostID |
315 |
INNER JOIN backups ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = shares.ID |
INNER JOIN backups ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = shares.ID |
|
WHERE |
|
|
files.dvdid IS NULL |
|
316 |
GROUP BY |
GROUP BY |
317 |
backups.hostID, backups.num |
backups.hostID, backups.num, backups.shareid |
318 |
ORDER BY min(backups.date) |
ORDER BY min(backups.date) |
319 |
}; |
}; |
320 |
my $sth = $dbh->prepare( $sql ); |
my $sth = $dbh->prepare( $sql ); |
324 |
while ( my $row = $sth->fetchrow_hashref() ) { |
while ( my $row = $sth->fetchrow_hashref() ) { |
325 |
$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) ); |
$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) ); |
326 |
$row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024); |
$row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024); |
327 |
|
my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) = |
328 |
|
stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'. |
329 |
|
getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'})); |
330 |
|
$row->{'fs_size'} = $fs_size; |
331 |
push @ret, $row; |
push @ret, $row; |
332 |
} |
} |
333 |
|
|
337 |
sub displayBackupsGrid() |
sub displayBackupsGrid() |
338 |
{ |
{ |
339 |
my $retHTML = ""; |
my $retHTML = ""; |
|
my $addForm = 1; |
|
340 |
|
|
341 |
if ($addForm) { |
$retHTML .= <<EOF3; |
|
|
|
|
$retHTML .= <<EOF3; |
|
342 |
<script language="javascript" type="text/javascript"> |
<script language="javascript" type="text/javascript"> |
343 |
<!-- |
<!-- |
344 |
|
|
359 |
//--> |
//--> |
360 |
</script> |
</script> |
361 |
EOF3 |
EOF3 |
362 |
$retHTML .= q{<form name="forma" method="GET" action="}."$MyURL"."?action=burn\""; |
$retHTML .= q{ |
363 |
$retHTML.= q{<input type="hidden" value="burn" name="action">}; |
<form name="forma" method="GET" action="$MyURL?action=burn"> |
364 |
$retHTML .= q{<input type="hidden" value="results" name="search_results">}; |
<input type="hidden" value="burn" name="action"> |
365 |
} |
<input type="hidden" value="results" name="search_results"> |
366 |
$retHTML .= qq{ |
<table style="fview" border="0" cellspacing="0" cellpadding="2"> |
|
<table style="fview" border="1" cellspacing="0" cellpadding="3"> |
|
367 |
<tr class="tableheader"> |
<tr class="tableheader"> |
368 |
}; |
<td class="tableheader"> |
369 |
|
<input type="checkbox" name="allFiles" onClick="checkAll('allFiles');"> |
370 |
if ($addForm) { |
</td> |
371 |
$retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>"; |
<td align="center">Share</td> |
|
} |
|
|
$retHTML .= qq{ |
|
|
<td align="center">Host</td> |
|
372 |
<td align="center">Backup no</td> |
<td align="center">Backup no</td> |
373 |
<td align="center">Type</td> |
<td align="center">Type</td> |
374 |
<td align="center">date</td> |
<td align="center">date</td> |
375 |
<td align="center">age/days</td> |
<td align="center">age/days</td> |
376 |
<td align="center">size/MB</td> |
<td align="center">size/MB</td> |
377 |
|
<td align="center">gzip size</td> |
378 |
</tr> |
</tr> |
379 |
|
|
380 |
|
<tr><td colspan=7 style="tableheader"> |
381 |
|
<input type="submit" value="Burn selected backups on medium" name="submitBurner"> |
382 |
|
</td></tr> |
383 |
}; |
}; |
384 |
|
|
385 |
my @backups = getBackupsNotBurned(); |
my @color = (' bgcolor="#e0e0e0"', ''); |
|
my $backup; |
|
386 |
|
|
387 |
if ($addForm) { |
my $i = 0; |
388 |
$retHTML .= qq{ |
my $host = ''; |
|
<tr><td colspan=7 style="tableheader"> |
|
|
<input type="submit" value="Burn selected backups on medium" name="submitBurner"> |
|
|
</td></tr> |
|
|
}; |
|
|
} |
|
389 |
|
|
390 |
foreach $backup(@backups) { |
foreach my $backup ( getBackupsNotBurned() ) { |
391 |
|
|
392 |
|
if ($host ne $backup->{'host'}) { |
393 |
|
$i++; |
394 |
|
$host = $backup->{'host'}; |
395 |
|
} |
396 |
my $ftype = ""; |
my $ftype = ""; |
397 |
|
|
398 |
$retHTML .= "<tr>"; |
$retHTML .= "<tr" . $color[$i %2 ] . ">"; |
399 |
if ($addForm) { |
$retHTML .= '<td class="fview"><input type="checkbox" name="fcb' . |
|
$retHTML .= '<td class="fview"><input type="checkbox" name="fcb' . |
|
400 |
$backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
$backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
401 |
'" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
'" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
402 |
'"></td>'; |
'"></td>'; |
|
} |
|
403 |
|
|
404 |
$retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' . |
$retHTML .= |
405 |
'<td class="fviewborder">' . $backup->{'backupnum'} . '</td>' . |
'<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' . |
406 |
'<td class="fviewborder">' . $backup->{'type'} . '</td>' . |
'<td align="center">' . $backup->{'backupnum'} . '</td>' . |
407 |
'<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '</td>' . |
'<td align="center">' . $backup->{'type'} . '</td>' . |
408 |
'<td class="fviewborder">' . $backup->{'age'} . '</td>' . |
'<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' . |
409 |
'<td class="fviewborder">' . $backup->{'size'} . '</td>' . |
'<td align="center">' . $backup->{'age'} . '</td>' . |
410 |
'</tr>'; |
'<td align="right">' . $backup->{'size'} . '</td>' . |
411 |
} |
'<td align="right">' . $backup->{'fs_size'} .'</td>' . |
412 |
|
"</tr>\n"; |
413 |
|
|
|
$retHTML .= "</table>"; |
|
414 |
|
|
|
if ($addForm) { |
|
|
$retHTML .= "</form>"; |
|
415 |
} |
} |
416 |
|
|
417 |
|
$retHTML .= "</table>"; |
418 |
|
$retHTML .= "</form>"; |
419 |
|
|
420 |
return $retHTML; |
return $retHTML; |
421 |
} |
} |
431 |
my $start_t = time(); |
my $start_t = time(); |
432 |
|
|
433 |
my ($results, $files); |
my ($results, $files); |
434 |
if ($param->{'use_hest'}) { |
if ($param->{'use_hest'} && length($hilite) > 0) { |
435 |
($results, $files) = getFilesHyperEstraier($param, $offset); |
($results, $files) = getFilesHyperEstraier($param); |
436 |
} else { |
} else { |
437 |
($results, $files) = getFiles($param, $offset); |
($results, $files) = getFiles($param); |
438 |
} |
} |
439 |
|
|
440 |
my $dur_t = time() - $start_t; |
my $dur_t = time() - $start_t; |
460 |
</div> |
</div> |
461 |
<table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0"> |
<table style="fview" width="100%" border="0" cellpadding="2" cellspacing="0"> |
462 |
<tr class="fviewheader"> |
<tr class="fviewheader"> |
463 |
|
<td></td> |
464 |
<td align="center">Share</td> |
<td align="center">Share</td> |
465 |
<td align="center">Type and Name</td> |
<td align="center">Type and Name</td> |
466 |
<td align="center">#</td> |
<td align="center">#</td> |
485 |
return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_); |
return sprintf(qq{<a href="?action=%s&host=%s&num=%d&share=%s&dir=%s">%s</a>}, $action, @_); |
486 |
} |
} |
487 |
|
|
488 |
|
my $i = $offset * $on_page; |
489 |
|
|
490 |
foreach $file (@{ $files }) { |
foreach $file (@{ $files }) { |
491 |
|
$i++; |
492 |
|
|
493 |
my $typeStr = BackupPC::Attrib::fileType2Text(undef, $file->{'type'}); |
my $typeStr = BackupPC::Attrib::fileType2Text(undef, $file->{'type'}); |
494 |
$retHTML .= qq{<tr class="fviewborder">}; |
$retHTML .= qq{<tr class="fviewborder">}; |
495 |
|
|
496 |
|
$retHTML .= qq{<td class="fviewborder">$i</td>}; |
497 |
|
|
498 |
$retHTML .= |
$retHTML .= |
499 |
qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} . |
qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} . |
500 |
qq{<td class="fviewborder"><img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" alt="$typeStr" align="middle"> } . hilite_html( $file->{'filepath'}, $hilite ) . qq{</td>} . |
qq{<td class="fviewborder"><img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" alt="$typeStr" align="middle"> } . hilite_html( $file->{'filepath'}, $hilite ) . qq{</td>} . |
501 |
qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupnum'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'filepath'} )}, $file->{'backupnum'} ) . qq{</td>} . |
qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupnum'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'filepath'} )}, $file->{'backupnum'} ) . qq{</td>} . |
502 |
qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} . |
qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} . |
503 |
qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} . |
qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} . |
504 |
qq{<td class="fviewborder">} . $file->{'dvd'} . qq{</td>}; |
qq{<td class="fviewborder">} . '?' . qq{</td>}; |
505 |
|
|
506 |
$retHTML .= "</tr>"; |
$retHTML .= "</tr>"; |
507 |
} |
} |