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.
37 use GD qw/gdSmallFont/;
63 my ($class, %arg) = @_ ;
66 height => 800, # element height in px
67 width => 600, # element width in px
70 cbegin => 0, # compute begin
71 cend => 0, # compute end
73 begin => 0, # user start
76 cur_y => 0, # current y position
77 elt_h => 20, # elt height in px
85 map { $self->{$_} = $arg{$_} } keys %arg ;
88 $self->{begin} = parsedate($self->{begin});
91 $self->{end} = parsedate($self->{end});
103 my ($self, $title, $img) = @_ ;
109 <img src='$img' border=0 usemap='#testmap' alt=''>
116 my ($self, $label, $tips, $x1, $y1, $x2, $y2) = @_ ;
118 my $ret = sprintf("%.2f,%.2f,%.2f,%.2f,%.2f,%.2f",
119 $x1,$y1,$x1,$y2,$x2,$y2);
121 $_image_map .= "<area shape='polygon' coords='$ret' ".
122 "title='$tips' href='$self->{base_url}/$label'>\n" ;
128 my ($self, $what) = @_;
130 if ($self->{debug}) {
132 print STDERR Data::Dumper::Dumper($what);
134 print STDERR "$what\n";
139 use Time::ParseDate qw/parsedate/;
143 my ($self, %elt) = @_;
145 foreach my $d (@{$elt{data}}) {
147 if ($d->{begin} !~ /^\d+$/) { # date => second
148 $d->{begin} = parsedate($d->{begin});
151 if ($d->{end} !~ /^\d+$/) { # date => second
152 $d->{end} = parsedate($d->{end});
155 if ($self->{cbegin} == 0) {
156 $self->{cbegin} = $d->{begin};
157 $self->{cend} = $d->{end};
160 # calculate begin and end graph
161 if ($self->{cbegin} > $d->{begin}) {
162 $self->{cbegin}= $d->{begin};
164 if ($self->{cend} < $d->{end}) {
165 $self->{cend} = $d->{end};
171 push @{$self->{data}}, \%elt;
174 # si le label est identique, on reste sur la meme ligne
175 # sinon, on prend la ligne suivante
178 my ($self, $label) = @_;
180 unless ($self->{label_y}->{$label}) {
181 $self->{label_y}->{$label} = $self->{cur_y};
182 $self->{cur_y} += $self->{elt_h} + 5;
185 return $self->{label_y}->{$label} ;
190 my ($self, $label) = @_;
192 return 1 unless ($label);
194 unless ($self->{type}->{$label}) {
195 $self->{type}->{$label} = 1;
198 return $self->{type}->{$label} ;
203 my ($self, $elt, $y1) = @_;
206 my $y2 = $self->{height} - ($y1 + $self->{elt_h}) ;
207 $y1 = $self->{height} - $y1;
209 my $x1 = $self->{xmarge} + ($elt->{begin} - $self->{cbegin}) * $self->{width}/ $self->{period} ;
210 my $x2 = $self->{xmarge} + ($elt->{end} - $self->{cbegin}) * $self->{width}/ $self->{period} ;
212 my $color = $self->get_color($elt->{type});
214 $gd->rectangle($x1,$y1,
217 if (($x1 + 4) <= $x2) {
218 $gd->fill(($x1 + $x2)/2,
228 unless (defined $gd) {
229 my $height = $self->{height} ;
230 my $width = $self->{width} ;
232 $gd = new GD::Image($width+350,$height+200);
233 $white = $gd->colorAllocate(255,255,255);
235 push @color_tab, ($gd->colorAllocate(135,236,88),
236 $gd->colorAllocate( 255, 236, 139),
237 $gd->colorAllocate(255,95,95),
238 $gd->colorAllocate(255,149,0),
239 $gd->colorAllocate( 255, 174, 185),
240 $gd->colorAllocate( 179, 255, 58),
241 $gd->colorAllocate( 205, 133, 0),
242 $gd->colorAllocate(205, 133, 0 ),
243 $gd->colorAllocate(238, 238, 209),
246 $black = $gd->colorAllocate(0,0,0);
247 #$gd->transparent($white);
248 $gd->interlaced('true');
250 $gd->line($self->{xmarge},10, $self->{xmarge}, $height, $color_tab[1]);
251 $gd->line($self->{xmarge},$height, $width, $height, $black);
254 use POSIX qw/strftime/;
260 my $nb_elt = scalar(@{$self->{data}});
261 # (4 drive + nb job) * (size of elt)
262 $self->{height} = (4+$nb_elt) * ($self->{elt_h} + 5);
266 if ($self->{begin}) {
267 $self->{cbegin} = $self->{begin};
270 $self->{cend} = $self->{end};
273 $self->{period} = $self->{cend} - $self->{cbegin};
274 return if ($self->{period < 1);
276 foreach my $elt (@{$self->{data}}) {
277 my $y1 = $self->get_y($elt->{label});
279 $gd->string(GD::Font->Small,
281 $self->{height} - $y1 - 12,
282 $elt->{label}, $black);
284 foreach my $d (@{$elt->{data}}) {
285 $self->draw_elt($d, $y1);
290 my $x1 = $i/10*$self->{width} + $self->{xmarge} ;
291 $gd->stringUp(GD::Font->Small,
293 $self->{height} + 100, # y
294 strftime('%D %H:%M', localtime($i/10*$self->{period}+$self->{cbegin})), $black);
297 $self->{height} + 100,
303 # affichage des legendes
305 my $y1=$self->{height} + 150;
307 for my $t (keys %{$self->{type}}) {
308 my $color = $self->get_color($t);
310 $gd->rectangle($x1 - 5,
312 $x1 + length($t)*10 - 5,
316 $gd->fill($x1, $y1, $color_tab[$color]);
318 $gd->string(GD::Font->Small,
323 $x1 += length($t)*10;
336 my $begin1 = "2006-10-03 09:59:34";
337 my $end1 = "2006-10-03 10:59:34";
339 my $begin2 = "2006-10-03 11:59:34";
340 my $end2 = "2006-10-03 13:59:34";
342 my $top = new GTime(debug => 1,
349 $top->add_job(label => "label",
370 $top->add_job(label => "label2",
392 #$top->draw_labels() ;
393 # make sure we are writing to a binary stream
396 # Convert the image to PNG and print it on standard output