5 Bweb - A Bacula web interface
6 Bacula® - The Network Backup Solution
8 Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
10 The main author of Bweb is Eric Bollengier.
11 The main author of Bacula is Kern Sibbald, with contributions from
12 many others, a complete list can be found in the file AUTHORS.
14 This program is Free Software; you can redistribute it and/or
15 modify it under the terms of version two of the GNU General Public
16 License as published by the Free Software Foundation plus additions
17 that are listed in the file LICENSE.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 Bacula® is a registered trademark of John Walker.
30 The licensor of Bacula is the Free Software Foundation Europe
31 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
32 Switzerland, email:ftf@fsfeurope.org.
41 use POSIX qw/strftime/;
44 use Digest::MD5 qw(md5_hex);
45 use File::Basename qw/basename dirname/;
47 my $conf = new Bweb::Config(config_file => $Bweb::config_file);
49 my $bweb = new Bweb(info => $conf);
52 my $arg = $bweb->get_form('where', 'jobid', 'pathid', 'filenameid');
53 my $where = $arg->{where} || '/';
54 my $jobid = $arg->{jobid};
55 my $pathid = $arg->{pathid};
56 my $fnid = $arg->{filenameid};
57 my $jobid_url = "jobid=$jobid";
60 my $batch = CGI::param("mode") || '';
62 my $md5_rep = md5_hex("$where:$jobid") ;
63 my $base_url = '/bweb/fv' ;
64 my $base_fich = $conf->{fv_write_path};
66 if ($jobid and $batch eq 'batch') {
67 my $root = fv_get_root_pathid($where);
69 fv_compute_size($jobid, $root);
75 print CGI::header('text/html');
76 $bweb->display_begin();
77 $bweb->display_job_zoom($jobid);
80 $bweb->error("Can't get where or jobid");
84 unless ($base_fich and -w $base_fich) {
85 $bweb->error("fv_write_path ($base_fich) is not writable." .
86 " See Bweb configuration.");
90 if (-f "$base_fich/$md5_rep.png" and -f "$base_fich/$md5_rep.tpl")
92 $bweb->display({}, "$base_fich/$md5_rep.tpl");
98 # if it's a file, display it
99 if ($fnid and $pathid)
101 my $attribs = fv_get_file_attribute_from_id($jobid, $pathid, $fnid);
102 if ($attribs->{found}) {
103 $bweb->display($attribs, 'fv_file_attribs.tpl');
104 $bweb->display_end();
110 my $attribs = fv_get_file_attribute($jobid, $where);
111 if ($attribs->{found}) {
112 $bweb->display($attribs, 'fv_file_attribs.tpl');
113 $bweb->display_end();
122 $where = fv_get_root_path($pathid);
125 if ($where !~ m!/$!) {
126 $where = $where . "/" ;
129 $root = fv_get_root_pathid($where);
133 $bweb->error("Can't find $where in catalog");
134 $bweb->display_end();
138 my $total = fv_compute_size($jobid, $root);
140 my $url_action = "bfileview.pl?opt_level=$opt_level" ;
141 my $top = new CCircle(
143 base_url => "$url_action;pathid=$root;$jobid_url;where=$where",
146 fv_display_rep($top, $total, $root, $opt_level) ;
148 $top->draw_labels() ;
149 $top->set_title(Bweb::human_size($total)) ;
151 open(OUT, ">$base_fich/$md5_rep.png") or die "$base_fich/$md5_rep.png $!";
152 # make sure we are writing to a binary stream
154 # Convert the image to PNG and print it on standard output
155 print OUT $CCircle::gd->png;
158 open(OUT, ">$base_fich/$md5_rep.tpl") or die "$base_fich/$md5_rep.tpl $!";
160 <form action='$url_action' method='get'>
162 <input title='jobids' type='hidden' name='jobid' value='$jobid'>
163 <input title='repertoire' type='text' name='where' value='$where'/>
164 <input type='submit' size='256' name='go' value='go'/>
170 print OUT $top->get_imagemap($where, "$base_url/$md5_rep.png") ;
173 $bweb->display({}, "$base_fich/$md5_rep.tpl");
174 $bweb->display_end();
178 my ($ccircle, $max, $rep, $level) = @_ ;
179 return if ($max < 1);
182 my $dirs = fv_list_dirs($jobid, $rep); # 0: pathid, 1: pathname
184 foreach my $dir (@{$dirs})
186 my $size = fv_compute_size($jobid, $dir->[0]);
189 my $per = $size * 100 / $max;
190 # can't use pathname when using utf or accent
192 $ccircle->{base_url} =~ s/pathid=\d+;/pathid=$dir->[0];/;
194 my $chld = $ccircle->add_part($per,
195 basename($dir->[1]) . '/',
197 . sprintf(' %.0f%% ', $per)
198 . Bweb::human_size($size)
201 if ($chld && $level > 0) {
202 fv_display_rep($chld, $size, $dir->[0], $level - 1) ;
206 # 0: filenameid, 1: filename, 2: size
207 my $files = fv_get_big_files($jobid, $rep, 3*100/$max, $max_file/($level+1));
208 foreach my $f (@{$files}) {
209 $ccircle->{base_url} =~ s/pathid=\d+;(filenameid=\d+;)?/pathid=$rep;filenameid=$f->[0];/;
210 $ccircle->add_part($f->[2] * 100 / $max,
212 $f->[1] . "\n" . Bweb::human_size($f->[2]));
217 $ccircle->add_part(($max - $sum) * 100 / $max,
219 "other\n" . Bweb::human_size($max - $sum));
222 $ccircle->finalize() ;
227 my ($jobid, $rep) = @_;
229 my $size = fv_get_size($jobid, $rep);
234 $size = fv_get_files_size($jobid, $rep);
236 my $dirs = fv_list_dirs($jobid, $rep);
237 foreach my $dir (@{$dirs}) {
238 $size += fv_compute_size($jobid, $dir->[0]);
241 fv_update_size($jobid, $rep, $size);
247 my ($jobid, $rep) = @_;
249 my $ret = $bweb->dbh_selectall_arrayref("
251 ( SELECT Path FROM Path WHERE PathId = P.PathId) AS Path
254 FROM brestore_pathvisibility
255 INNER JOIN brestore_pathhierarchy USING (PathId)
264 sub fv_get_file_attribute
266 my ($jobid, $full_name) = @_;
268 my $filename = $bweb->dbh_quote(basename($full_name));
269 my $path = $bweb->dbh_quote(dirname($full_name) . "/");
271 my $attr = $bweb->dbh_selectrow_hashref("
274 base64_decode_lstat(8, LStat) AS size,
275 base64_decode_lstat(11, LStat) AS atime,
276 base64_decode_lstat(12, LStat) AS mtime,
277 base64_decode_lstat(13, LStat) AS ctime
279 FROM File INNER JOIN Filename USING (FilenameId)
280 INNER JOIN Path USING (PathId)
281 WHERE Name = $filename
286 $attr->{filename} = $full_name;
287 $attr->{size} = Bweb::human_size($attr->{size});
288 foreach my $d (qw/atime ctime mtime/) {
289 $attr->{$d} = strftime('%F %H:%M', localtime($attr->{$d}));
295 sub fv_get_file_attribute_from_id
297 my ($jobid, $pathid, $filenameid) = @_;
299 my $attr = $bweb->dbh_selectrow_hashref("
302 base64_decode_lstat(8, LStat) AS size,
303 base64_decode_lstat(11, LStat) AS atime,
304 base64_decode_lstat(12, LStat) AS mtime,
305 base64_decode_lstat(13, LStat) AS ctime,
306 Path.Path || Filename.Name AS filename
308 FROM File INNER JOIN Filename USING (FilenameId)
309 INNER JOIN Path USING (PathId)
310 WHERE FilenameId = $filenameid
315 $attr->{size} = Bweb::human_size($attr->{size});
316 foreach my $d (qw/atime ctime mtime/) {
317 $attr->{$d} = strftime('%F %H:%M', localtime($attr->{$d}));
324 my ($jobid, $rep) = @_;
326 my $ret = $bweb->dbh_selectrow_hashref("
328 FROM brestore_pathvisibility
336 sub fv_get_files_size
338 my ($jobid, $rep) = @_;
340 my $ret = $bweb->dbh_selectrow_hashref("
341 SELECT sum(base64_decode_lstat(8,LStat)) AS size
352 my ($jobid, $rep, $min, $limit) = @_;
354 my $ret = $bweb->dbh_selectall_arrayref("
355 SELECT Name AS name, size, FilenameId AS filenameid
357 SELECT FilenameId,base64_decode_lstat(8,LStat) AS size
361 ) AS S INNER JOIN Filename USING (FilenameId)
372 my ($jobid, $rep, $size) = @_;
374 my $nb = $bweb->dbh_do("
375 UPDATE brestore_pathvisibility SET Size = $size
383 sub fv_get_root_pathid
386 $path = $bweb->dbh_quote($path);
387 my $ret = $bweb->dbh_selectrow_hashref("SELECT PathId FROM Path WHERE Path = $path");
388 return $ret->{pathid};
394 my $ret = $bweb->dbh_selectrow_hashref("SELECT Path FROM Path WHERE PathId = $pathid");
401 CREATE OR REPLACE FUNCTION base64_decode_lstat(int4, varchar) RETURNS int8 AS $$
408 size := split_part($2, ' ', $1);
409 b64 := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
411 FOR i IN 1..length(size) LOOP
412 val := val + (strpos(b64, substr(size, i, 1))-1) * (64^(length(size)-i));
416 $$ language 'plpgsql';
418 ALTER TABLE brestore_pathvisibility ADD Size int8;
422 ALTER TABLE brestore_pathvisibility ADD Files int4;