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}; |
19 |
|
if ($index_path) { |
20 |
|
$index_path = $TopDir . '/' . $index_path; |
21 |
|
$index_path =~ s#//#/#g; |
22 |
|
} |
23 |
|
|
24 |
my $dbh; |
my $dbh; |
25 |
|
|
26 |
sub get_dbh { |
sub get_dbh { |
32 |
my @ret; |
my @ret; |
33 |
|
|
34 |
my $dbh = get_dbh(); |
my $dbh = get_dbh(); |
35 |
my $sth = $dbh->prepare(qq{ SELECT id, share FROM shares ORDER BY share} ); |
my $sth = $dbh->prepare(qq{ |
36 |
|
SELECT |
37 |
|
shares.id as id, |
38 |
|
hosts.name || ':' || shares.name as share |
39 |
|
FROM shares |
40 |
|
JOIN hosts on hostid = hosts.id |
41 |
|
ORDER BY share |
42 |
|
} ); |
43 |
$sth->execute(); |
$sth->execute(); |
44 |
push @ret, { 'id' => '', 'share' => '-'}; # dummy any |
push @ret, { 'id' => '', 'share' => '-'}; # dummy any |
45 |
|
|
51 |
|
|
52 |
sub epoch_to_iso { |
sub epoch_to_iso { |
53 |
my $t = shift || return; |
my $t = shift || return; |
54 |
my $iso = BackupPC::Lib::timeStamp($t); |
my $iso = BackupPC::Lib::timeStamp(undef, $t); |
55 |
$iso =~ s/\s/ /g; |
$iso =~ s/\s/ /g; |
56 |
return $iso; |
return $iso; |
57 |
} |
} |
113 |
files.id AS fid, |
files.id AS fid, |
114 |
hosts.name AS hname, |
hosts.name AS hname, |
115 |
shares.name AS sname, |
shares.name AS sname, |
116 |
shares.share AS sharename, |
-- shares.share AS sharename, |
117 |
files.backupNum AS backupNum, |
files.backupnum AS backupnum, |
118 |
files.name AS filename, |
-- files.name AS filename, |
119 |
files.path AS filepath, |
files.path AS filepath, |
120 |
files.date AS date, |
files.date AS date, |
121 |
files.type AS filetype, |
files.type AS type, |
122 |
files.size AS size, |
files.size AS size, |
123 |
-- dvds.name AS dvd |
-- dvds.name AS dvd |
124 |
null AS dvd |
null AS dvd |
128 |
FROM files |
FROM files |
129 |
INNER JOIN shares ON files.shareID=shares.ID |
INNER JOIN shares ON files.shareID=shares.ID |
130 |
INNER JOIN hosts ON hosts.ID = shares.hostID |
INNER JOIN hosts ON hosts.ID = shares.hostID |
131 |
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 |
132 |
}; |
}; |
133 |
|
|
134 |
my $sql_dvd_from = qq{ |
my $sql_dvd_from = qq{ |
167 |
my @ret; |
my @ret; |
168 |
|
|
169 |
while (my $row = $sth->fetchrow_hashref()) { |
while (my $row = $sth->fetchrow_hashref()) { |
170 |
push(@ret, { |
push @ret, $row; |
|
'hname' => $row->{'hname'}, |
|
|
'sname' => $row->{'sname'}, |
|
|
'sharename' => $row->{'sharename'}, |
|
|
'backupno' => $row->{'backupnum'}, |
|
|
'fname' => $row->{'filename'}, |
|
|
'fpath' => $row->{'filepath'}, |
|
|
'networkpath' => $row->{'networkpath'}, |
|
|
'date' => $row->{'date'}, |
|
|
'type' => $row->{'filetype'}, |
|
|
'size' => $row->{'size'}, |
|
|
'id' => $row->{'fid'}, |
|
|
'dvd' => $row->{'dvd'} |
|
|
}); |
|
171 |
} |
} |
172 |
|
|
173 |
$sth->finish(); |
$sth->finish(); |
174 |
return ($results, \@ret); |
return ($results, \@ret); |
175 |
} |
} |
176 |
|
|
177 |
|
sub getFilesHyperEstraier($$) { |
178 |
|
my ($param, $offset) = @_; |
179 |
|
|
180 |
|
die "no index_path?" unless ($index_path); |
181 |
|
|
182 |
|
use HyperEstraier; |
183 |
|
|
184 |
|
# open the database |
185 |
|
my $db = HyperEstraier::Database->new(); |
186 |
|
$db->open($index_path, $HyperEstraier::ESTDBREADER); |
187 |
|
|
188 |
|
# create a search condition object |
189 |
|
my $cond = HyperEstraier::Condition->new(); |
190 |
|
|
191 |
|
my $q = $param->{'search_filename'}; |
192 |
|
my $shareid = $param->{'search_share'}; |
193 |
|
|
194 |
|
if ($q) { |
195 |
|
$q =~ s/(.)/$1 /g; |
196 |
|
|
197 |
|
# set the search phrase to the search condition object |
198 |
|
$cond->set_phrase($q); |
199 |
|
|
200 |
|
my ($backup_from, $backup_to, $files_from, $files_to) = dates_from_form($param); |
201 |
|
|
202 |
|
$cond->add_attr("backup_date NUMGE $backup_from") if ($backup_from); |
203 |
|
$cond->add_attr("backup_date NUMLE $backup_to") if ($backup_to); |
204 |
|
|
205 |
|
$cond->add_attr("date NUMGE $files_from") if ($files_from); |
206 |
|
$cond->add_attr("date NUMLE $files_to") if ($files_to); |
207 |
|
|
208 |
|
$cond->add_attr("shareid NUMEQ $shareid") if ($shareid); |
209 |
|
} |
210 |
|
|
211 |
|
$offset ||= 0; |
212 |
|
$offset = ($offset * $on_page); |
213 |
|
|
214 |
|
# $cond->set_max( $offset + $on_page ); |
215 |
|
$cond->set_options( $HyperEstraier::Condition::SURE ); |
216 |
|
$cond->set_order( 'date NUMA' ); |
217 |
|
|
218 |
|
# get the result of search |
219 |
|
my $result = $db->search($cond, 0); |
220 |
|
$result->get(0); |
221 |
|
|
222 |
|
my @res; |
223 |
|
my $hits = $result->size; |
224 |
|
|
225 |
|
# for each document in result |
226 |
|
for my $i ($offset .. $result->size-1) { |
227 |
|
my $id = $result->get($i); |
228 |
|
my $doc = $db->get_doc($id, 0); |
229 |
|
|
230 |
|
my $row; |
231 |
|
foreach my $c (qw/fid hname sname backupnum fiilename filepath date type size/) { |
232 |
|
$row->{$c} = $doc->attr($c); |
233 |
|
} |
234 |
|
push @res, $row; |
235 |
|
} |
236 |
|
|
237 |
|
return ($hits, \@res); |
238 |
|
} |
239 |
|
|
240 |
sub getBackupsNotBurned() { |
sub getBackupsNotBurned() { |
241 |
|
|
242 |
my $dbh = get_dbh(); |
my $dbh = get_dbh(); |
244 |
SELECT |
SELECT |
245 |
backups.hostID AS hostid, |
backups.hostID AS hostid, |
246 |
min(hosts.name) AS host, |
min(hosts.name) AS host, |
247 |
backups.num AS backupno, |
backups.num AS backupnum, |
248 |
min(backups.type) AS type, |
min(backups.type) AS type, |
249 |
min(backups.date) AS date, |
min(backups.date) AS date, |
250 |
min(backups.size) AS size |
min(backups.size) AS size |
251 |
FROM files |
FROM files |
252 |
INNER JOIN shares ON files.shareID=shares.ID |
INNER JOIN shares ON files.shareID=shares.ID |
253 |
INNER JOIN hosts ON hosts.ID = shares.hostID |
INNER JOIN hosts ON hosts.ID = shares.hostID |
254 |
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 |
255 |
WHERE |
WHERE |
256 |
files.dvdid IS NULL |
files.dvdid IS NULL |
257 |
GROUP BY |
GROUP BY |
339 |
$retHTML .= "<tr>"; |
$retHTML .= "<tr>"; |
340 |
if ($addForm) { |
if ($addForm) { |
341 |
$retHTML .= '<td class="fview"><input type="checkbox" name="fcb' . |
$retHTML .= '<td class="fview"><input type="checkbox" name="fcb' . |
342 |
$backup->{'hostid'}.'_'.$backup->{'backupno'} . |
$backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
343 |
'" value="' . $backup->{'hostid'}.'_'.$backup->{'backupno'} . |
'" value="' . $backup->{'hostid'}.'_'.$backup->{'backupnum'} . |
344 |
'"></td>'; |
'"></td>'; |
345 |
} |
} |
346 |
|
|
347 |
$retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' . |
$retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' . |
348 |
'<td class="fviewborder">' . $backup->{'backupno'} . '</td>' . |
'<td class="fviewborder">' . $backup->{'backupnum'} . '</td>' . |
349 |
'<td class="fviewborder">' . $backup->{'type'} . '</td>' . |
'<td class="fviewborder">' . $backup->{'type'} . '</td>' . |
350 |
'<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '</td>' . |
'<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '</td>' . |
351 |
'<td class="fviewborder">' . $backup->{'age'} . '</td>' . |
'<td class="fviewborder">' . $backup->{'age'} . '</td>' . |
362 |
return $retHTML; |
return $retHTML; |
363 |
} |
} |
364 |
|
|
365 |
sub displayGrid($$) { |
sub displayGrid($) { |
366 |
my ($param, $addForm) = @_; |
my ($param) = @_; |
367 |
|
|
368 |
my $offset = $param->{'offset'}; |
my $offset = $param->{'offset'}; |
369 |
my $hilite = $param->{'search_filename'}; |
my $hilite = $param->{'search_filename'}; |
372 |
|
|
373 |
my $start_t = time(); |
my $start_t = time(); |
374 |
|
|
375 |
my ($results, $files) = getFiles($param, $offset); |
my ($results, $files); |
376 |
|
if ($param->{'use_hest'}) { |
377 |
|
($results, $files) = getFilesHyperEstraier($param, $offset); |
378 |
|
} else { |
379 |
|
($results, $files) = getFiles($param, $offset); |
380 |
|
} |
381 |
|
|
382 |
my $dur_t = time() - $start_t; |
my $dur_t = time() - $start_t; |
383 |
my $dur = sprintf("%0.4fs", $dur_t); |
my $dur = sprintf("%0.4fs", $dur_t); |
396 |
} |
} |
397 |
|
|
398 |
|
|
|
if ($addForm) { |
|
|
$retHTML .= qq{<form name="forma" method="GET" action="$MyURL">}; |
|
|
$retHTML.= qq{<input type="hidden" value="search" name="action">}; |
|
|
$retHTML .= qq{<input type="hidden" value="results" name="search_results">}; |
|
|
} |
|
|
|
|
|
|
|
399 |
$retHTML .= qq{ |
$retHTML .= qq{ |
400 |
<div> |
<div> |
401 |
Found <b>$results files</b> showing <b>$from - $to</b> (took $dur) |
Found <b>$results files</b> showing <b>$from - $to</b> (took $dur) |
431 |
$retHTML .= qq{<tr class="fviewborder">}; |
$retHTML .= qq{<tr class="fviewborder">}; |
432 |
|
|
433 |
$retHTML .= |
$retHTML .= |
434 |
qq{<td class="fviewborder" align="right">} . $file->{'sharename'} . qq{</td>} . |
qq{<td class="fviewborder" align="right">} . $file->{'hname'} . ':' . $file->{'sname'} . qq{</td>} . |
435 |
qq{<td class="fviewborder"><img src="$Conf{CgiImageDirURL}/icon-$typeStr.gif" alt="$typeStr" align="middle"> } . hilite_html( $file->{'fpath'}, $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>} . |
436 |
qq{<td class="fviewborder" align="center">} . restore_link( $typeStr, ${EscURI( $file->{'hname'} )}, $file->{'backupno'}, ${EscURI( $file->{'sname'})}, ${EscURI( $file->{'fpath'} )}, $file->{'backupno'} ) . 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>} . |
437 |
qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} . |
qq{<td class="fviewborder" align="right">} . $file->{'size'} . qq{</td>} . |
438 |
qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} . |
qq{<td class="fviewborder">} . epoch_to_iso( $file->{'date'} ) . qq{</td>} . |
439 |
qq{<td class="fviewborder">} . $file->{'dvd'} . qq{</td>}; |
qq{<td class="fviewborder">} . $file->{'dvd'} . qq{</td>}; |
500 |
|
|
501 |
$retHTML .= "</div>"; |
$retHTML .= "</div>"; |
502 |
|
|
|
$retHTML .= "</form>" if ($addForm); |
|
|
|
|
503 |
return $retHTML; |
return $retHTML; |
504 |
} |
} |
505 |
|
|