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 # Si c'est un fichier selectionne, afficher ses attributs
42 # ajouter le base_fic et base_url dans les options bweb
48 use Digest::MD5 qw(md5_hex);
49 use File::Basename qw/basename dirname/;
51 my $conf = new Bweb::Config(config_file => '/etc/bweb/config');
53 my $bweb = new Bweb(info => $conf);
56 my $arg = $bweb->get_form('where', 'jobid');
57 my $where = $arg->{where};
58 my $jobid = $arg->{jobid};
59 my $jobid_url = "jobid=$jobid";
62 my $batch = CGI::param("mode") || '';
64 my $md5_rep = md5_hex("$where:$jobid") ;
65 my $base_url = '/bweb/fv' ;
66 my $base_fich = $conf->{fv_write_path};
68 die "Can't get where" unless ($where and $jobid);
70 if ($batch eq 'batch') {
71 my $root = fv_get_root_pathid($where);
73 fv_compute_size($jobid, $root);
79 print CGI::header('text/html');
80 $bweb->display_begin();
81 $bweb->display_job_zoom($jobid);
83 if (-f "$base_fich/$md5_rep.png" and -f "$base_fich/$md5_rep.tpl")
85 $bweb->display({}, "$base_fich/$md5_rep.tpl");
90 my $attribs = fv_get_file_attribute($jobid, $where);
91 if ($attribs->{found}) {
92 $bweb->display($attribs, 'fv_file_attribs.tpl');
97 if ($where !~ m!/$!) {
98 $where = $where . "/" ;
101 my $root = fv_get_root_pathid($where);
103 $bweb->error("Can't find $where in catalog");
104 $bweb->display_end();
108 my $total = fv_compute_size($jobid, $root);
110 my $url_action = "bfileview.pl?opt_level=$opt_level" ;
111 my $top = new CCircle(
113 base_url => "$url_action;$jobid_url;where=$where",
116 fv_display_rep($top, $total, $root, $opt_level) ;
118 $top->draw_labels() ;
119 $top->set_title(Bweb::human_size($total)) ;
121 open(OUT, ">$base_fich/$md5_rep.png") or die "$base_fich/$md5_rep.png $!";
122 # make sure we are writing to a binary stream
124 # Convert the image to PNG and print it on standard output
125 print OUT $CCircle::gd->png;
128 open(OUT, ">$base_fich/$md5_rep.tpl") or die "$base_fich/$md5_rep.tpl $!";
130 <form action='$url_action' method='get'>
132 <input title='jobids' type='hidden' name='jobid' value='$jobid'>
133 <input title='repertoire' type='text' name='where' value='$where'/>
134 <input type='submit' size='256' name='go' value='go'/>
140 print OUT $top->get_imagemap($where, "$base_url/$md5_rep.png") ;
143 $bweb->display({}, "$base_fich/$md5_rep.tpl");
144 $bweb->display_end();
148 my ($ccircle, $max, $rep, $level) = @_ ;
149 return if ($max < 1);
152 my $dirs = fv_list_dirs($jobid, $rep); # 0: pathid, 1: pathname
154 foreach my $dir (@{$dirs})
156 my $size = fv_compute_size($jobid, $dir->[0]);
159 my $chld = $ccircle->add_part($size * 100 / $max,
160 basename($dir->[1]) . '/',
163 . Bweb::human_size($size)
166 if ($chld and $level > 0) {
167 fv_display_rep($chld, $size, $dir->[0], $level - 1) ;
172 my $files = fv_get_big_files($jobid, $rep, 3*100/$max, $max_file/($level+1));
173 foreach my $f (@{$files}) {
174 $ccircle->add_part($f->[1] * 100 / $max,
176 $f->[0] . "\n" . Bweb::human_size($f->[1]));
181 $ccircle->add_part(($max - $sum) * 100 / $max,
183 "other\n" . Bweb::human_size($max - $sum));
186 $ccircle->finalize() ;
191 my ($jobid, $rep) = @_;
193 my $size = fv_get_size($jobid, $rep);
198 $size = fv_get_files_size($jobid, $rep);
200 my $dirs = fv_list_dirs($jobid, $rep);
201 foreach my $dir (@{$dirs}) {
202 $size += fv_compute_size($jobid, $dir->[0]);
205 fv_update_size($jobid, $rep, $size);
211 my ($jobid, $rep) = @_;
213 my $ret = $bweb->dbh_selectall_arrayref("
216 SELECT Path FROM Path WHERE PathId = P.PathId
218 SELECT Path FROM brestore_missing_path WHERE PathId = P.PathId
222 FROM brestore_pathvisibility
223 INNER JOIN brestore_pathhierarchy USING (PathId)
232 sub fv_get_file_attribute
234 my ($jobid, $full_name) = @_;
236 my $filename = $bweb->dbh_quote(basename($full_name));
237 my $path = $bweb->dbh_quote(dirname($full_name) . "/");
239 my $attr = $bweb->dbh_selectrow_hashref("
241 base64_decode_lstat(8, lstat) AS size
242 FROM File INNER JOIN Filename USING (FilenameId)
243 INNER JOIN Path USING (PathId)
244 WHERE Name = $filename
249 $attr->{filename} = $full_name;
250 $attr->{size} = Bweb::human_size($attr->{size});
256 my ($jobid, $rep) = @_;
258 my $ret = $bweb->dbh_selectrow_hashref("
260 FROM brestore_pathvisibility
268 sub fv_get_files_size
270 my ($jobid, $rep) = @_;
272 my $ret = $bweb->dbh_selectrow_hashref("
273 SELECT sum(base64_decode_lstat(8,lstat)) AS size
284 my ($jobid, $rep, $min, $limit) = @_;
286 my $ret = $bweb->dbh_selectall_arrayref("
289 SELECT FilenameId,base64_decode_lstat(8,lstat) AS size
293 ) AS S INNER JOIN Filename USING (FilenameId)
304 my ($jobid, $rep, $size) = @_;
306 my $nb = $bweb->dbh_do("
307 UPDATE brestore_pathvisibility SET Size = $size
315 sub fv_get_root_pathid
318 $path = $bweb->dbh_quote($path);
319 my $ret = $bweb->dbh_selectrow_hashref("
320 SELECT PathId FROM Path WHERE Path = $path
322 SELECT PathId FROM brestore_missing_path WHERE PATH = $path
324 return $ret->{pathid};
329 CREATE OR REPLACE FUNCTION base64_decode_lstat(int4, varchar) RETURNS int8 AS $$
336 size := split_part($2, ' ', $1);
337 b64 := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
339 FOR i IN 1..length(size) LOOP
340 val := val + (strpos(b64, substr(size, i, 1))-1) * (64^(length(size)-i));
344 $$ language 'plpgsql';
346 ALTER TABLE brestore_pathvisibility ADD Size int8;