5 Bweb - A Bacula web interface
6 Bacula® - The Network Backup Solution
8 Copyright (C) 2000-2010 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.
13 This program is Free Software; you can redistribute it and/or
14 modify it under the terms of version three of the GNU Affero General Public
15 License as published by the Free Software Foundation and included
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Affero General Public License for more details.
23 You should have received a copy of the GNU Affero General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 Bacula® is a registered trademark of Kern Sibbald.
29 The licensor of Bacula is the Free Software Foundation Europe
30 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
31 Switzerland, email:ftf@fsfeurope.org.
36 use GD qw/gdSmallFont/;
62 my ($class, %arg) = @_ ;
65 height => 800, # element height in px
66 width => 600, # element width in px
69 cbegin => 0, # compute begin
70 cend => 0, # compute end
72 begin => 0, # user start
75 cur_y => 0, # current y position
76 elt_h => 20, # elt height in px
84 map { $self->{$_} = $arg{$_} } keys %arg ;
87 $self->{begin} = parsedate($self->{begin});
90 $self->{end} = parsedate($self->{end});
102 my ($self, $title, $img) = @_ ;
108 <img src='$img' border=0 usemap='#testmap' alt=''>
115 my ($self, $label, $tips, $x1, $y1, $x2, $y2) = @_ ;
117 my $ret = sprintf("%.2f,%.2f,%.2f,%.2f,%.2f,%.2f",
118 $x1,$y1,$x1,$y2,$x2,$y2);
120 $_image_map .= "<area shape='polygon' coords='$ret' ".
121 "title='$tips' href='$self->{base_url}/$label'>\n" ;
127 my ($self, $what) = @_;
129 if ($self->{debug}) {
131 print STDERR Data::Dumper::Dumper($what);
133 print STDERR "$what\n";
138 use Time::ParseDate qw/parsedate/;
142 my ($self, %elt) = @_;
144 foreach my $d (@{$elt{data}}) {
146 if ($d->{begin} !~ /^\d+$/) { # date => second
147 $d->{begin} = parsedate($d->{begin});
150 if ($d->{end} !~ /^\d+$/) { # date => second
151 $d->{end} = parsedate($d->{end});
154 if ($self->{cbegin} == 0) {
155 $self->{cbegin} = $d->{begin};
156 $self->{cend} = $d->{end};
159 # calculate begin and end graph
160 if ($self->{cbegin} > $d->{begin}) {
161 $self->{cbegin}= $d->{begin};
163 if ($self->{cend} < $d->{end}) {
164 $self->{cend} = $d->{end};
170 push @{$self->{data}}, \%elt;
173 # si le label est identique, on reste sur la meme ligne
174 # sinon, on prend la ligne suivante
177 my ($self, $label) = @_;
179 unless ($self->{label_y}->{$label}) {
180 $self->{label_y}->{$label} = $self->{cur_y};
181 $self->{cur_y} += $self->{elt_h} + 5;
184 return $self->{label_y}->{$label} ;
189 my ($self, $label) = @_;
191 return 1 unless ($label);
193 unless ($self->{type}->{$label}) {
194 $self->{type}->{$label} = 1;
197 return $self->{type}->{$label} ;
202 my ($self, $elt, $y1) = @_;
205 my $y2 = $self->{height} - ($y1 + $self->{elt_h}) ;
206 $y1 = $self->{height} - $y1;
208 my $x1 = $self->{xmarge} + ($elt->{begin} - $self->{cbegin}) * $self->{width}/ $self->{period} ;
209 my $x2 = $self->{xmarge} + ($elt->{end} - $self->{cbegin}) * $self->{width}/ $self->{period} ;
211 my $color = $self->get_color($elt->{type});
213 $gd->rectangle($x1,$y1,
216 if (($x1 + 4) <= $x2) {
217 $gd->fill(($x1 + $x2)/2,
227 unless (defined $gd) {
228 my $height = $self->{height} ;
229 my $width = $self->{width} ;
231 $gd = new GD::Image($width+350,$height+200);
232 $white = $gd->colorAllocate(255,255,255);
234 push @color_tab, ($gd->colorAllocate(135,236,88),
235 $gd->colorAllocate( 255, 236, 139),
236 $gd->colorAllocate(255,95,95),
237 $gd->colorAllocate(255,149,0),
238 $gd->colorAllocate( 255, 174, 185),
239 $gd->colorAllocate( 179, 255, 58),
240 $gd->colorAllocate( 205, 133, 0),
241 $gd->colorAllocate(205, 133, 0 ),
242 $gd->colorAllocate(238, 238, 209),
245 $black = $gd->colorAllocate(0,0,0);
246 #$gd->transparent($white);
247 $gd->interlaced('true');
249 $gd->line($self->{xmarge},10, $self->{xmarge}, $height, $color_tab[1]);
250 $gd->line($self->{xmarge},$height, $width, $height, $black);
253 use POSIX qw/strftime/;
259 my $nb_elt = scalar(@{$self->{data}});
260 # (4 drive + nb job) * (size of elt)
261 $self->{height} = (4+$nb_elt) * ($self->{elt_h} + 5);
265 if ($self->{begin}) {
266 $self->{cbegin} = $self->{begin};
269 $self->{cend} = $self->{end};
272 $self->{period} = $self->{cend} - $self->{cbegin};
273 return if ($self->{period} < 1);
275 foreach my $elt (@{$self->{data}}) {
276 my $y1 = $self->get_y($elt->{label});
278 $gd->string(GD::Font->Small,
280 $self->{height} - $y1 - 12,
281 $elt->{label}, $black);
283 foreach my $d (@{$elt->{data}}) {
284 $self->draw_elt($d, $y1);
289 my $x1 = $i/10*$self->{width} + $self->{xmarge} ;
290 $gd->stringUp(GD::Font->Small,
292 $self->{height} + 100, # y
293 strftime('%D %H:%M', localtime($i/10*$self->{period}+$self->{cbegin})), $black);
296 $self->{height} + 100,
302 # affichage des legendes
304 my $y1=$self->{height} + 150;
306 for my $t (keys %{$self->{type}}) {
307 my $color = $self->get_color($t);
309 $gd->rectangle($x1 - 5,
311 $x1 + length($t)*10 - 5,
315 $gd->fill($x1, $y1, $color_tab[$color]);
317 $gd->string(GD::Font->Small,
322 $x1 += length($t)*10;
335 my $begin1 = "2006-10-03 09:59:34";
336 my $end1 = "2006-10-03 10:59:34";
338 my $begin2 = "2006-10-03 11:59:34";
339 my $end2 = "2006-10-03 13:59:34";
341 my $top = new GTime(debug => 1,
348 $top->add_job(label => "label",
369 $top->add_job(label => "label2",
391 #$top->draw_labels() ;
392 # make sure we are writing to a binary stream
395 # Convert the image to PNG and print it on standard output