15 |
my $dsn = $Conf{SearchDSN}; |
my $dsn = $Conf{SearchDSN}; |
16 |
my $db_user = $Conf{SearchUser} || ''; |
my $db_user = $Conf{SearchUser} || ''; |
17 |
|
|
18 |
my $index_path = $Conf{HyperEstraierIndex}; |
my $hest_index_path = $Conf{HyperEstraierIndex}; |
|
if ($index_path) { |
|
|
$index_path = $TopDir . '/' . $index_path; |
|
|
$index_path =~ s#//#/#g; |
|
|
} |
|
19 |
|
|
20 |
my $dbh; |
my $dbh; |
21 |
|
|
171 |
return ($results, \@ret); |
return ($results, \@ret); |
172 |
} |
} |
173 |
|
|
174 |
|
sub getHyperEstraier_url($) { |
175 |
|
my ($use_hest) = @_; |
176 |
|
|
177 |
|
return unless $use_hest; |
178 |
|
|
179 |
|
use HyperEstraier; |
180 |
|
my ($index_path, $index_node_url); |
181 |
|
|
182 |
|
if ($use_hest =~ m#^http://#) { |
183 |
|
$index_node_url = $use_hest; |
184 |
|
} else { |
185 |
|
$index_path = $TopDir . '/' . $index_path; |
186 |
|
$index_path =~ s#//#/#g; |
187 |
|
} |
188 |
|
return ($index_path, $index_node_url); |
189 |
|
} |
190 |
|
|
191 |
sub getFilesHyperEstraier($) { |
sub getFilesHyperEstraier($) { |
192 |
my ($param) = @_; |
my ($param) = @_; |
193 |
|
|
194 |
my $offset = $param->{'offset'} || 0; |
my $offset = $param->{'offset'} || 0; |
195 |
$offset *= $on_page; |
$offset *= $on_page; |
196 |
|
|
197 |
die "no index_path?" unless ($index_path); |
die "no index_path?" unless ($hest_index_path); |
198 |
|
|
199 |
use HyperEstraier; |
use HyperEstraier; |
200 |
|
|
201 |
|
my ($index_path, $index_node_url) = getHyperEstraier_url($hest_index_path); |
202 |
|
|
203 |
# open the database |
# open the database |
204 |
my $db = HyperEstraier::Database->new(); |
my $db; |
205 |
$db->open($index_path, $HyperEstraier::ESTDBREADER); |
if ($index_path) { |
206 |
|
$db = HyperEstraier::Database->new(); |
207 |
|
$db->open($index_path, $HyperEstraier::ESTDBREADER); |
208 |
|
} elsif ($index_node_url) { |
209 |
|
$db ||= HyperEstraier::Node->new($index_node_url); |
210 |
|
$db->set_auth('admin', 'admin'); |
211 |
|
} else { |
212 |
|
die "BUG: unimplemented"; |
213 |
|
} |
214 |
|
|
215 |
# create a search condition object |
# create a search condition object |
216 |
my $cond = HyperEstraier::Condition->new(); |
my $cond = HyperEstraier::Condition->new(); |
218 |
my $q = $param->{'search_filename'}; |
my $q = $param->{'search_filename'}; |
219 |
my $shareid = $param->{'search_share'}; |
my $shareid = $param->{'search_share'}; |
220 |
|
|
221 |
if ($q) { |
if (length($q) > 0) { |
222 |
$q =~ s/(.)/$1 /g; |
# exact match |
223 |
|
$cond->add_attr("filepath ISTRINC $q"); |
224 |
|
|
225 |
|
$q =~ s/(.)/$1 /g; |
226 |
# set the search phrase to the search condition object |
# set the search phrase to the search condition object |
227 |
$cond->set_phrase($q); |
$cond->set_phrase($q); |
228 |
} |
} |
242 |
$cond->set_order( 'date NUMA' ); |
$cond->set_order( 'date NUMA' ); |
243 |
|
|
244 |
# get the result of search |
# get the result of search |
|
my $result = $db->search($cond, 0); |
|
|
|
|
245 |
my @res; |
my @res; |
246 |
my $hits = $result->size; |
my ($result, $hits); |
247 |
|
|
248 |
|
if ($index_path) { |
249 |
|
$result = $db->search($cond, 0); |
250 |
|
$hits = $result->size; |
251 |
|
} elsif ($index_node_url) { |
252 |
|
$result = $db->search($cond, 0); |
253 |
|
$hits = $result->doc_num; |
254 |
|
} else { |
255 |
|
die "BUG: unimplemented"; |
256 |
|
} |
257 |
|
|
258 |
# for each document in result |
# for each document in result |
259 |
for my $i ($offset .. ($offset + $on_page - 1)) { |
for my $i ($offset .. ($offset + $on_page - 1)) { |
260 |
last if ($i >= $hits); |
last if ($i >= $hits); |
261 |
|
|
262 |
my $id = $result->get($i); |
my $doc; |
263 |
my $doc = $db->get_doc($id, 0); |
if ($index_path) { |
264 |
|
my $id = $result->get($i); |
265 |
|
$doc = $db->get_doc($id, 0); |
266 |
|
} elsif ($index_node_url) { |
267 |
|
$doc = $result->get_doc($i); |
268 |
|
} else { |
269 |
|
die "BUG: unimplemented"; |
270 |
|
} |
271 |
|
|
272 |
my $row; |
my $row; |
273 |
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/) { |
279 |
return ($hits, \@res); |
return ($hits, \@res); |
280 |
} |
} |
281 |
|
|
282 |
|
sub getGzipName($$$) |
283 |
|
{ |
284 |
|
my ($host, $share, $backupnum) = @_; |
285 |
|
my $ret = $Conf{GzipSchema}; |
286 |
|
|
287 |
|
$share =~ s/\//_/g; |
288 |
|
$ret =~ s/\\h/$host/ge; |
289 |
|
$ret =~ s/\\s/$share/ge; |
290 |
|
$ret =~ s/\\n/$backupnum/ge; |
291 |
|
|
292 |
|
return $ret; |
293 |
|
|
294 |
|
} |
295 |
|
|
296 |
sub getBackupsNotBurned() { |
sub getBackupsNotBurned() { |
297 |
|
|
298 |
my $dbh = get_dbh(); |
my $dbh = get_dbh(); |
299 |
my $sql = q{ |
|
300 |
SELECT |
my $sql = q{ |
301 |
backups.hostID AS hostid, |
SELECT |
302 |
min(hosts.name) AS host, |
backups.hostID AS hostID, |
303 |
backups.num AS backupnum, |
hosts.name AS host, |
304 |
min(backups.type) AS type, |
shares.name AS share, |
305 |
min(backups.date) AS date, |
backups.id AS backupnum, |
306 |
min(backups.size) AS size |
backups.type AS type, |
307 |
FROM files |
backups.date AS date, |
308 |
INNER JOIN shares ON files.shareID=shares.ID |
backups.size AS size |
309 |
INNER JOIN hosts ON hosts.ID = shares.hostID |
FROM backups |
310 |
INNER JOIN backups ON backups.num = files.backupnum and backups.hostID = hosts.ID AND backups.shareID = shares.ID |
INNER JOIN shares ON backups.shareID=shares.ID |
311 |
GROUP BY |
INNER JOIN hosts ON backups.hostID = hosts.ID |
312 |
backups.hostID, backups.num |
LEFT OUTER JOIN archive_backup ON archive_backup.backup_id = backups.id AND archive_backup.backup_id IS NULL |
313 |
ORDER BY min(backups.date) |
WHERE backups.size > 0 |
314 |
|
GROUP BY |
315 |
|
backups.hostID, |
316 |
|
hosts.name, |
317 |
|
shares.name, |
318 |
|
backups.num, |
319 |
|
backups.shareid, |
320 |
|
backups.id, |
321 |
|
backups.type, |
322 |
|
backups.date, |
323 |
|
backups.size |
324 |
|
ORDER BY backups.date |
325 |
}; |
}; |
326 |
my $sth = $dbh->prepare( $sql ); |
my $sth = $dbh->prepare( $sql ); |
327 |
my @ret; |
my @ret; |
330 |
while ( my $row = $sth->fetchrow_hashref() ) { |
while ( my $row = $sth->fetchrow_hashref() ) { |
331 |
$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) ); |
$row->{'age'} = sprintf("%0.1f", ( (time() - $row->{'date'}) / 86400 ) ); |
332 |
$row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024); |
$row->{'size'} = sprintf("%0.2f", $row->{'size'} / 1024 / 1024); |
333 |
|
my (undef,undef,undef,undef,undef,undef,undef,$fs_size,undef,undef,undef,undef,undef) = |
334 |
|
stat( $Conf{InstallDir}.'/'.$Conf{GzipTempDir}.'/'. |
335 |
|
getGzipName($row->{'host'}, $row->{share}, $row->{'backupnum'})); |
336 |
|
$row->{'fs_size'} = $fs_size; |
337 |
push @ret, $row; |
push @ret, $row; |
338 |
} |
} |
339 |
|
|
340 |
return @ret; |
return @ret; |
341 |
} |
} |
342 |
|
|
343 |
sub displayBackupsGrid() |
sub displayBackupsGrid() { |
344 |
{ |
|
345 |
my $retHTML = ""; |
my $retHTML .= q{ |
346 |
my $addForm = 1; |
<form id="forma" method="POST" action=}; |
347 |
|
$retHTML .= "\"".$MyURL."\""; |
348 |
if ($addForm) { |
$retHTML .= q{?action=burn> |
349 |
|
}; |
350 |
|
|
351 |
$retHTML .= <<EOF3; |
$retHTML .= <<EOF3; |
352 |
<script language="javascript" type="text/javascript"> |
<script language="javascript" type="text/javascript"> |
353 |
<!-- |
<!-- |
354 |
|
|
355 |
function checkAll(location) |
var debug_div = null; |
356 |
{ |
|
357 |
for (var i=0;i<document.forma.elements.length;i++) |
function debug(msg) { |
358 |
{ |
// return; // Disable debugging |
359 |
var e = document.forma.elements[i]; |
|
360 |
if ((e.checked || !e.checked) && e.name != \'all\') { |
if (! debug_div) debug_div = document.getElementById('debug'); |
361 |
if (eval("document.forma."+location+".checked")) { |
|
362 |
e.checked = true; |
// this will create debug div if it doesn't exist. |
363 |
} else { |
if (! debug_div) { |
364 |
e.checked = false; |
debug_div = document.createElement('div'); |
365 |
} |
if (document.body) document.body.appendChild(debug_div); |
366 |
} |
else debug_div = null; |
367 |
} |
} |
368 |
} |
if (debug_div) { |
369 |
//--> |
debug_div.appendChild(document.createTextNode(msg)); |
370 |
</script> |
debug_div.appendChild(document.createElement("br")); |
|
EOF3 |
|
|
$retHTML .= q{<form name="forma" method="GET" action="}."$MyURL"."?action=burn\""; |
|
|
$retHTML.= q{<input type="hidden" value="burn" name="action">}; |
|
|
$retHTML .= q{<input type="hidden" value="results" name="search_results">}; |
|
371 |
} |
} |
372 |
$retHTML .= qq{ |
} |
373 |
<table style="fview" border="1" cellspacing="0" cellpadding="3"> |
|
|
<tr class="tableheader"> |
|
|
}; |
|
374 |
|
|
375 |
if ($addForm) { |
var element_id_cache = Array(); |
376 |
$retHTML .= "<td class=\"tableheader\"><input type=\"checkbox\" name=\"allFiles\" onClick=\"checkAll('allFiles');\"></td>"; |
|
377 |
|
function element_id(name,element) { |
378 |
|
if (! element_id_cache[name]) { |
379 |
|
element_id_cache[name] = self.document.getElementById(name); |
380 |
} |
} |
381 |
$retHTML .= qq{ |
return element_id_cache[name]; |
382 |
<td align="center">Host</td> |
} |
|
<td align="center">Backup no</td> |
|
|
<td align="center">Type</td> |
|
|
<td align="center">date</td> |
|
|
<td align="center">age/days</td> |
|
|
<td align="center">size/MB</td> |
|
|
</tr> |
|
|
}; |
|
383 |
|
|
384 |
my @backups = getBackupsNotBurned(); |
function checkAll(location) { |
385 |
my $backup; |
var len = element_id('forma').elements.length; |
386 |
|
var check_all = element_id('allFiles'); |
387 |
|
|
388 |
|
for (var i = 0; i < len; i++) { |
389 |
|
|
390 |
|
var e = element_id('forma').elements[i]; |
391 |
|
if ((e.checked || !e.checked) && e.name != \'all\') { |
392 |
|
if (check_all.checked) { |
393 |
|
e.checked = true; |
394 |
|
} else { |
395 |
|
e.checked = false; |
396 |
|
} |
397 |
|
} |
398 |
|
} |
399 |
|
|
400 |
if ($addForm) { |
sumiraj(); |
401 |
$retHTML .= qq{ |
} |
402 |
<tr><td colspan=7 style="tableheader"> |
|
403 |
<input type="submit" value="Burn selected backups on medium" name="submitBurner"> |
function sumiraj(e) { |
404 |
</td></tr> |
var suma = parseInt(element_id('forma').totalsize.value) || 0; |
405 |
}; |
var len = element_id('forma').elements.length; |
406 |
|
if (e) { |
407 |
|
var size = parseInt( element_id("fss" + e.name.substr(3)).value ); |
408 |
|
if (e.checked) { |
409 |
|
suma += size; |
410 |
|
} else { |
411 |
|
suma -= size; |
412 |
|
} |
413 |
|
} else { |
414 |
|
suma = 0; |
415 |
|
for (var i = 0; i < len; i++) { |
416 |
|
var e = element_id('forma').elements[i]; |
417 |
|
if (e.name != \'all\' && e.checked && e.name.substr(0,3) == 'fcb') { |
418 |
|
var el = element_id("fss" + e.name.substr(3)); |
419 |
|
if (el && el.value) suma += parseInt(el.value) || 0; |
420 |
|
} |
421 |
|
} |
422 |
} |
} |
423 |
|
element_id('forma').totalsize.value = suma; |
424 |
|
debug('total size: '+suma); |
425 |
|
return suma; |
426 |
|
} |
427 |
|
|
428 |
|
if (!self.body) self.body = new Object(); |
429 |
|
self.onload = self.document.onload = self.body.onload = function() { |
430 |
|
sumiraj(); |
431 |
|
} |
432 |
|
|
433 |
|
//--> |
434 |
|
</script> |
435 |
|
<div id="debug" style="position: absolute; top: 0; right: 0; width: 10em; border: 1px #ff0000 solid; background-color: #ffe0e0; -moz-opacity: 0.7;"> |
436 |
|
Total size: |
437 |
|
<input type="text" name="totalsize" size="8"> |
438 |
|
<br/> |
439 |
|
Note: |
440 |
|
<textarea name="note" cols="10" rows="5"> |
441 |
|
</textarea> |
442 |
|
<br/> |
443 |
|
<input type="submit" value="Burn selected backups" name="submitBurner"> |
444 |
|
</div> |
445 |
|
EOF3 |
446 |
|
$retHTML .= q{ |
447 |
|
<input type="hidden" value="burn" name="action"> |
448 |
|
<input type="hidden" value="results" name="search_results"> |
449 |
|
<table style="fview" border="0" cellspacing="0" cellpadding="2"> |
450 |
|
<tr class="tableheader"> |
451 |
|
<td class="tableheader"> |
452 |
|
<input type="checkbox" name="allFiles" id="allFiles" onClick="checkAll('allFiles');"> |
453 |
|
</td> |
454 |
|
<td align="center">Share</td> |
455 |
|
<td align="center">Backup no</td> |
456 |
|
<td align="center">Type</td> |
457 |
|
<td align="center">date</td> |
458 |
|
<td align="center">age/days</td> |
459 |
|
<td align="center">size/MB</td> |
460 |
|
<td align="center">gzip size</td> |
461 |
|
</tr> |
462 |
|
|
463 |
|
}; |
464 |
|
|
465 |
|
my @color = (' bgcolor="#e0e0e0"', ''); |
466 |
|
|
467 |
|
my $i = 0; |
468 |
|
my $host = ''; |
469 |
|
|
470 |
foreach $backup(@backups) { |
foreach my $backup ( getBackupsNotBurned() ) { |
471 |
|
|
472 |
|
if ($host ne $backup->{'host'}) { |
473 |
|
$i++; |
474 |
|
$host = $backup->{'host'}; |
475 |
|
} |
476 |
my $ftype = ""; |
my $ftype = ""; |
|
|
|
|
$retHTML .= "<tr>"; |
|
|
if ($addForm) { |
|
|
$retHTML .= '<td class="fview"><input type="checkbox" name="fcb' . |
|
|
$backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
|
|
'" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
|
|
'"></td>'; |
|
|
} |
|
|
|
|
|
$retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' . |
|
|
'<td class="fviewborder">' . $backup->{'backupnum'} . '</td>' . |
|
|
'<td class="fviewborder">' . $backup->{'type'} . '</td>' . |
|
|
'<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '</td>' . |
|
|
'<td class="fviewborder">' . $backup->{'age'} . '</td>' . |
|
|
'<td class="fviewborder">' . $backup->{'size'} . '</td>' . |
|
|
'</tr>'; |
|
|
} |
|
477 |
|
|
478 |
$retHTML .= "</table>"; |
$retHTML .= |
479 |
|
'<tr' . $color[$i %2 ] . '> |
480 |
|
<td class="fview">'; |
481 |
|
# FIXME |
482 |
|
#$backup->{'fs_size'} = int($backup->{'size'} * 1024); |
483 |
|
if (($backup->{'fs_size'} || 0) > 0) { |
484 |
|
$retHTML .= ' |
485 |
|
<input type="checkbox" name="fcb' . |
486 |
|
$backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
487 |
|
'" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
488 |
|
'" onClick="sumiraj(this);">'; |
489 |
|
} |
490 |
|
$retHTML .= |
491 |
|
'</td>' . |
492 |
|
'<td align="right">' . $backup->{'host'} . ':' . $backup->{'share'} . '</td>' . |
493 |
|
'<td align="center">' . $backup->{'backupnum'} . '</td>' . |
494 |
|
'<td align="center">' . $backup->{'type'} . '</td>' . |
495 |
|
'<td align="center">' . epoch_to_iso( $backup->{'date'} ) . '</td>' . |
496 |
|
'<td align="center">' . $backup->{'age'} . '</td>' . |
497 |
|
'<td align="right">' . $backup->{'size'} . '</td>' . |
498 |
|
'<td align="right">' . $backup->{'fs_size'} . |
499 |
|
'<input type="hidden" iD="fss'.$backup->{'hostid'}.'_'.$backup->{'backupnum'} . '" value="'. $backup->{'fs_size'} .'"></td>' . |
500 |
|
|
501 |
if ($addForm) { |
"</tr>\n"; |
|
$retHTML .= "</form>"; |
|
502 |
} |
} |
503 |
|
|
504 |
|
$retHTML .= "</table>"; |
505 |
|
$retHTML .= "</form>"; |
506 |
|
|
507 |
return $retHTML; |
return $retHTML; |
508 |
} |
} |
518 |
my $start_t = time(); |
my $start_t = time(); |
519 |
|
|
520 |
my ($results, $files); |
my ($results, $files); |
521 |
if ($param->{'use_hest'}) { |
if ($param->{'use_hest'} && length($hilite) > 0) { |
522 |
($results, $files) = getFilesHyperEstraier($param); |
($results, $files) = getFilesHyperEstraier($param); |
523 |
} else { |
} else { |
524 |
($results, $files) = getFiles($param); |
($results, $files) = getFiles($param); |
580 |
my $typeStr = BackupPC::Attrib::fileType2Text(undef, $file->{'type'}); |
my $typeStr = BackupPC::Attrib::fileType2Text(undef, $file->{'type'}); |
581 |
$retHTML .= qq{<tr class="fviewborder">}; |
$retHTML .= qq{<tr class="fviewborder">}; |
582 |
|
|
583 |
$retHTML .= qq{<td>$i</td>}; |
$retHTML .= qq{<td class="fviewborder">$i</td>}; |
584 |
|
|
585 |
$retHTML .= |
$retHTML .= |
586 |
qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} . |
qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} . |