From: Eric Bollengier Date: Fri, 29 May 2009 07:57:10 +0000 (+0000) Subject: ebl untabify X-Git-Tag: Release-3.0.2~193 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=288442f08ed1b9fbf14c4726fcf8f2c21756823b;p=bacula%2Fbacula ebl untabify git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8873 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/gui/bweb/lib/Bweb.pm b/gui/bweb/lib/Bweb.pm index a923410a03..4a4200a6a5 100644 --- a/gui/bweb/lib/Bweb.pm +++ b/gui/bweb/lib/Bweb.pm @@ -72,7 +72,7 @@ sub new { my ($class, %arg) = @_; my $self = bless { - name => undef, + name => undef, }, $class; map { $self->{lc($_)} = $arg{$_} } keys %arg ; @@ -85,11 +85,11 @@ sub debug my ($self, $what) = @_; if ($self->{debug}) { - if (ref $what) { - print "
" . Data::Dumper::Dumper($what) . "
"; - } else { - print "
$what
"; - } + if (ref $what) { + print "
" . Data::Dumper::Dumper($what) . "
"; + } else { + print "
$what
"; + } } } @@ -156,21 +156,21 @@ sub display my $dir = $self->{template_dir} || $template_dir; my $lang = $self->{lang} || 'en'; my $template = HTML::Template->new(filename => $tpl, - path =>["$dir/$lang", + path =>["$dir/$lang", "$dir/$lang/tpl", - $dir], - die_on_bad_params => 0, - case_sensitive => 0); + $dir], + die_on_bad_params => 0, + case_sensitive => 0); foreach my $var (qw/limit offset/) { - unless ($hash->{$var}) { - my $value = CGI::param($var) || ''; + unless ($hash->{$var}) { + my $value = CGI::param($var) || ''; - if ($value =~ /^(\d+)$/) { - $template->param($var, $1) ; - } - } + if ($value =~ /^(\d+)$/) { + $template->param($var, $1) ; + } + } } $template->param('thisurl', CGI::url(-relative => 1, -query=>1)); @@ -219,24 +219,24 @@ use CGI; =cut our %k_re = ( dbi => qr/^(dbi:(Pg|mysql):(?:\w+=[\w\d\.-]+;?)+)$/i, - user => qr/^([\w\d\.-]+)$/i, - password => qr/^(.*)$/, - fv_write_path => qr!^([/\w\d\.-]*)$!, - template_dir => qr!^([/\w\d\.-]+)$!, - debug => qr/^(on)?$/, - lang => qr/^(\w\w)?$/, - email_media => qr/^([\w\d\.-]+@[\d\w\.-]+)$/, - graph_font => qr!^([/\w\d\.-]+.ttf)?$!, - bconsole => qr!^(.+)?$!, - syslog_file => qr!^(.+)?$!, - log_dir => qr!^(.+)?$!, - wiki_url => qr!(.*)$!, - stat_job_table => qr!^(\w*)$!, - display_log_time => qr!^(on)?$!, - enable_security => qr/^(on)?$/, - enable_security_acl => qr/^(on)?$/, - default_age => qr/^((?:\d+(?:[ywdhms]\s*?)?)+)\s*$/, - ); + user => qr/^([\w\d\.-]+)$/i, + password => qr/^(.*)$/, + fv_write_path => qr!^([/\w\d\.-]*)$!, + template_dir => qr!^([/\w\d\.-]+)$!, + debug => qr/^(on)?$/, + lang => qr/^(\w\w)?$/, + email_media => qr/^([\w\d\.-]+@[\d\w\.-]+)$/, + graph_font => qr!^([/\w\d\.-]+.ttf)?$!, + bconsole => qr!^(.+)?$!, + syslog_file => qr!^(.+)?$!, + log_dir => qr!^(.+)?$!, + wiki_url => qr!(.*)$!, + stat_job_table => qr!^(\w*)$!, + display_log_time => qr!^(on)?$!, + enable_security => qr/^(on)?$/, + enable_security_acl => qr/^(on)?$/, + default_age => qr/^((?:\d+(?:[ywdhms]\s*?)?)+)\s*$/, + ); =head1 FUNCTION @@ -254,12 +254,12 @@ sub load unless (open(FP, $self->{config_file})) { - return $self->error("can't load config_file $self->{config_file} : $!"); + return $self->error("can't load config_file $self->{config_file} : $!"); } my $f=''; my $tmpbuffer; while(read FP,$tmpbuffer,4096) { - $f .= $tmpbuffer; + $f .= $tmpbuffer; } close(FP); @@ -270,16 +270,16 @@ sub load use strict; if ($f and $@) { - $self->load_old(); - $self->save(); - return $self->error("If you update from an old bweb install, your must reload this page and if it's fail again, you have to configure bweb again...") ; + $self->load_old(); + $self->save(); + return $self->error("If you update from an old bweb install, your must reload this page and if it's fail again, you have to configure bweb again...") ; } # set default values $self->{default_age} = '7d'; foreach my $k (keys %$VAR1) { - $self->{$k} = $VAR1->{$k}; + $self->{$k} = $VAR1->{$k}; } return 1; @@ -297,16 +297,16 @@ sub load_old unless (open(FP, $self->{config_file})) { - return $self->error("$self->{config_file} : $!"); + return $self->error("$self->{config_file} : $!"); } while (my $line = ) { - chomp($line); - my ($k, $v) = split(/\s*=\s*/, $line, 2); - if ($k_re{$k}) { - $self->{$k} = $v; - } + chomp($line); + my ($k, $v) = split(/\s*=\s*/, $line, 2); + if ($k_re{$k}) { + $self->{$k} = $v; + } } close(FP); @@ -324,17 +324,17 @@ sub save my ($self) = @_ ; if ($self->{ach_list}) { - # shortcut for display_begin - $self->{achs} = [ map {{ name => $_ }} - keys %{$self->{ach_list}} - ]; + # shortcut for display_begin + $self->{achs} = [ map {{ name => $_ }} + keys %{$self->{ach_list}} + ]; } unless (open(FP, ">$self->{config_file}")) { - return $self->error("$self->{config_file} : $!\n" . - "You must add this to your config file\n" - . Data::Dumper::Dumper($self)); + return $self->error("$self->{config_file} : $!\n" . + "You must add this to your config file\n" + . Data::Dumper::Dumper($self)); } print FP Data::Dumper::Dumper($self); @@ -375,21 +375,21 @@ sub modify foreach my $k (CGI::param()) { - next unless (exists $k_re{$k}) ; - my $val = CGI::param($k); - if ($val =~ $k_re{$k}) { - $self->{$k} = $1; - } else { - $self->{error} .= "bad parameter : $k = [$val]"; - } + next unless (exists $k_re{$k}) ; + my $val = CGI::param($k); + if ($val =~ $k_re{$k}) { + $self->{$k} = $1; + } else { + $self->{error} .= "bad parameter : $k = [$val]"; + } } $self->view(); - if ($self->{error}) { # an error as occured - $self->display($self, 'error.tpl'); + if ($self->{error}) { # an error as occured + $self->display($self, 'error.tpl'); } else { - $self->save(); + $self->save(); } } @@ -432,22 +432,22 @@ sub display_running_job my $status = $self->status($bweb->{info}); if ($jobid) { - if ($status->{$jobid}) { - $status = $status->{$jobid}; - $status->{last_jobbytes} = $infos->{jobbytes}; - $status->{last_jobfiles} = $infos->{jobfiles}; - $status->{corr_jobbytes} = $infos->{corr_jobbytes}; - $status->{corr_jobfiles} = $infos->{corr_jobfiles}; - $status->{jobbytes}=$status->{Bytes}; - $status->{jobbytes} =~ s![^\d]!!g; - $status->{jobfiles}=$status->{'Files Examined'}; - $status->{jobfiles} =~ s/,//g; - $bweb->display($status, "client_job_status.tpl"); - } + if ($status->{$jobid}) { + $status = $status->{$jobid}; + $status->{last_jobbytes} = $infos->{jobbytes}; + $status->{last_jobfiles} = $infos->{jobfiles}; + $status->{corr_jobbytes} = $infos->{corr_jobbytes}; + $status->{corr_jobfiles} = $infos->{corr_jobfiles}; + $status->{jobbytes}=$status->{Bytes}; + $status->{jobbytes} =~ s![^\d]!!g; + $status->{jobfiles}=$status->{'Files Examined'}; + $status->{jobfiles} =~ s/,//g; + $bweb->display($status, "client_job_status.tpl"); + } } else { - for my $id (keys %$status) { - $bweb->display($status->{$id}, "client_job_status.tpl"); - } + for my $id (keys %$status) { + $bweb->display($status->{$id}, "client_job_status.tpl"); + } } } @@ -473,13 +473,13 @@ sub display_running_job =head2 OUTPUT $VAR1 = { 105 => { - JobName => Full_plume.2006-06-06_17.22.23, - JobId => 105, - Files => 8,971, - Bytes => 194,484,132, - ... + JobName => Full_plume.2006-06-06_17.22.23, + JobId => 105, + Files => 8,971, + Bytes => 194,484,132, + ... }, - ... + ... }; =cut @@ -489,7 +489,7 @@ sub status my ($self, $conf) = @_ ; if (defined $self->{cur_jobs}) { - return $self->{cur_jobs} ; + return $self->{cur_jobs} ; } my $arg = {}; @@ -499,32 +499,32 @@ sub status my $jobid; for my $r (split(/\n/, $ret)) { - chomp($r); - $r =~ s/(^\s+|\s+$)//g; - if ($r =~ /JobId (\d+) Job (\S+)/) { - if ($jobid) { - $arg->{$jobid} = { @param, JobId => $jobid } ; - } + chomp($r); + $r =~ s/(^\s+|\s+$)//g; + if ($r =~ /JobId (\d+) Job (\S+)/) { + if ($jobid) { + $arg->{$jobid} = { @param, JobId => $jobid } ; + } - $jobid = $1; - @param = ( JobName => $2 ); + $jobid = $1; + @param = ( JobName => $2 ); - } elsif ($r =~ /=.+=/) { - push @param, split(/\s+|\s*=\s*/, $r) ; + } elsif ($r =~ /=.+=/) { + push @param, split(/\s+|\s*=\s*/, $r) ; - } elsif ($r =~ /=/) { # one per line - push @param, split(/\s*=\s*/, $r) ; + } elsif ($r =~ /=/) { # one per line + push @param, split(/\s*=\s*/, $r) ; - } elsif ($r =~ /:/) { # one per line - push @param, split(/\s*:\s*/, $r, 2) ; - } + } elsif ($r =~ /:/) { # one per line + push @param, split(/\s*:\s*/, $r, 2) ; + } } if ($jobid and @param) { - $arg->{$jobid} = { @param, - JobId => $jobid, - Client => $self->{name}, - } ; + $arg->{$jobid} = { @param, + JobId => $jobid, + Client => $self->{name}, + } ; } $self->{cur_jobs} = $arg ; @@ -565,20 +565,20 @@ sub new my ($class, %arg) = @_; my $self = bless { - name => '', # autochanger name - label => {}, # where are volume { label1 => 40, label2 => drive0 } - drive => [], # drive use [ 'media1', 'empty', ..] - slot => [], # slot use [ undef, 'empty', 'empty', ..] no slot 0 - io => [], # io slot number list [ 41, 42, 43...] - info => {slot => 0, # informations (slot, drive, io) - io => 0, - drive=> 0, - }, - mtxcmd => '/usr/sbin/mtx', - debug => 0, - device => '/dev/changer', - precmd => '', # ssh command - bweb => undef, # link to bacula web object (use for display) + name => '', # autochanger name + label => {}, # where are volume { label1 => 40, label2 => drive0 } + drive => [], # drive use [ 'media1', 'empty', ..] + slot => [], # slot use [ undef, 'empty', 'empty', ..] no slot 0 + io => [], # io slot number list [ 41, 42, 43...] + info => {slot => 0, # informations (slot, drive, io) + io => 0, + drive=> 0, + }, + mtxcmd => '/usr/sbin/mtx', + debug => 0, + device => '/dev/changer', + precmd => '', # ssh command + bweb => undef, # link to bacula web object (use for display) } ; map { $self->{lc($_)} = $arg{$_} } keys %arg ; @@ -630,41 +630,41 @@ sub status # Storage Element 7:Empty # Storage Element 2:Full :VolumeTag=000002 - if ($l =~ /Storage Element (\d+):(Empty|Full)(\s+:VolumeTag=([\w\d.-]+))?/){ - - if ($2 eq 'Empty') { - $self->set_empty_slot($1); - } else { - $self->set_slot($1, $4); - } - - } elsif ($l =~ /Data Transfer.+(\d+):(Full|Empty)(\s+.Storage Element (\d+) Loaded.(:VolumeTag = ([\w\d.-]+))?)?/) { - - if ($2 eq 'Empty') { - $self->set_empty_drive($1); - } else { - $self->set_drive($1, $4, $6); - } - - } elsif ($l =~ /Storage Element (\d+).+IMPORT\/EXPORT:(Empty|Full)( :VolumeTag=([\d\w.-]+))?/) - { - if ($2 eq 'Empty') { - $self->set_empty_io($1); - } else { - $self->set_io($1, $4); - } + if ($l =~ /Storage Element (\d+):(Empty|Full)(\s+:VolumeTag=([\w\d.-]+))?/){ + + if ($2 eq 'Empty') { + $self->set_empty_slot($1); + } else { + $self->set_slot($1, $4); + } + + } elsif ($l =~ /Data Transfer.+(\d+):(Full|Empty)(\s+.Storage Element (\d+) Loaded.(:VolumeTag = ([\w\d.-]+))?)?/) { + + if ($2 eq 'Empty') { + $self->set_empty_drive($1); + } else { + $self->set_drive($1, $4, $6); + } + + } elsif ($l =~ /Storage Element (\d+).+IMPORT\/EXPORT:(Empty|Full)( :VolumeTag=([\d\w.-]+))?/) + { + if ($2 eq 'Empty') { + $self->set_empty_io($1); + } else { + $self->set_io($1, $4); + } # Storage Changer /dev/changer:2 Drives, 30 Slots ( 1 Import/Export ) - } elsif ($l =~ /Storage Changer .+:(\d+) Drives, (\d+) Slots/) { - $self->{info}->{drive} = $1; - $self->{info}->{slot} = $2; - if ($l =~ /(\d+)\s+Import/) { - $self->{info}->{io} = $1 ; - } else { - $self->{info}->{io} = 0; - } - } + } elsif ($l =~ /Storage Changer .+:(\d+) Drives, (\d+) Slots/) { + $self->{info}->{drive} = $1; + $self->{info}->{slot} = $2; + if ($l =~ /(\d+)\s+Import/) { + $self->{info}->{io} = $1 ; + } else { + $self->{info}->{io} = 0; + } + } } $self->debug($self) ; @@ -676,7 +676,7 @@ sub is_slot_loaded # no barcodes if ($self->{slot}->[$slot] eq 'loaded') { - return 1; + return 1; } my $label = $self->{slot}->[$slot] ; @@ -694,14 +694,14 @@ sub unload my $out = `$self->{precmd} $self->{mtxcmd} -f $self->{device} unload $slot $drive 2>&1`; if ($? == 0) { - my $content = $self->get_slot($slot); - print "content = $content
$drive => $slot
"; - $self->set_empty_drive($drive); - $self->set_slot($slot, $content); - return 1; + my $content = $self->get_slot($slot); + print "content = $content
$drive => $slot
"; + $self->set_empty_drive($drive); + $self->set_slot($slot, $content); + return 1; } else { - $self->{error} = $out; - return 0; + $self->{error} = $out; + return 0; } } @@ -717,14 +717,14 @@ sub load my $out = `$self->{precmd} $self->{mtxcmd} -f $self->{device} load $slot $drive 2>&1`; if ($? == 0) { - my $content = $self->get_slot($slot); - print "content = $content
$slot => $drive
"; - $self->set_drive($drive, $slot, $content); - return 1; + my $content = $self->get_slot($slot); + print "content = $content
$slot => $drive
"; + $self->set_drive($drive, $slot, $content); + return 1; } else { - $self->{error} = $out; - print $out; - return 0; + $self->{error} = $out; + print $out; + return 0; } } @@ -733,11 +733,11 @@ sub is_media_loaded my ($self, $media) = @_; unless ($self->{label}->{$media}) { - return 0; + return 0; } if ($self->{label}->{$media} =~ /drive\d+/) { - return 1; + return 1; } return 0; @@ -756,7 +756,7 @@ sub set_io push @{ $self->{io} }, $slot; if ($tag) { - $self->{label}->{$tag} = $slot; + $self->{label}->{$tag} = $slot; } } @@ -767,7 +767,7 @@ sub set_empty_io push @{ $self->{io} }, $slot; unless ($self->{slot}->[$slot]) { # can be loaded (parse before) - $self->{slot}->[$slot] = 'empty'; + $self->{slot}->[$slot] = 'empty'; } } @@ -783,7 +783,7 @@ sub set_slot $self->{slot}->[$slot] = $tag || 'full'; if ($tag) { - $self->{label}->{$tag} = $slot; + $self->{label}->{$tag} = $slot; } } @@ -792,7 +792,7 @@ sub set_empty_slot my ($self, $slot) = @_; unless ($self->{slot}->[$slot]) { # can be loaded (parse before) - $self->{slot}->[$slot] = 'empty'; + $self->{slot}->[$slot] = 'empty'; } } @@ -811,7 +811,7 @@ sub set_drive $self->{slot}->[$slot] = $tag || 'loaded'; if ($tag) { - $self->{label}->{$tag} = "drive$drive"; + $self->{label}->{$tag} = "drive$drive"; } } @@ -821,20 +821,20 @@ sub slot_is_full # slot don't exists => full if (not defined $self->{slot}->[$slot]) { - return 0 ; + return 0 ; } if ($self->{slot}->[$slot] eq 'empty') { - return 0; + return 0; } - return 1; # vol, full, loaded + return 1; # vol, full, loaded } sub slot_get_first_free { my ($self) = @_; for (my $slot=1; $slot < $self->{info}->{slot}; $slot++) { - return $slot unless ($self->slot_is_full($slot)); + return $slot unless ($self->slot_is_full($slot)); } } @@ -843,7 +843,7 @@ sub io_get_first_free my ($self) = @_; foreach my $slot (@{ $self->{io} }) { - return $slot unless ($self->slot_is_full($slot)); + return $slot unless ($self->slot_is_full($slot)); } return 0; } @@ -867,28 +867,28 @@ sub send_to_io my ($self, $slot) = @_; unless ($self->slot_is_full($slot)) { - print "Autochanger $self->{name} slot $slot is empty
\n"; - return 1; # ok + print "Autochanger $self->{name} slot $slot is empty
\n"; + return 1; # ok } # first, eject it if ($self->is_slot_loaded($slot)) { - # bconsole->umount - # self->eject - print "Autochanger $self->{name} $slot is currently in use
\n"; - return 0; + # bconsole->umount + # self->eject + print "Autochanger $self->{name} $slot is currently in use
\n"; + return 0; } # autochanger must have I/O unless ($self->have_io()) { - print "Autochanger $self->{name} don't have I/O, you can take media yourself
\n"; - return 0; + print "Autochanger $self->{name} don't have I/O, you can take media yourself
\n"; + return 0; } my $dst = $self->io_get_first_free(); unless ($dst) { - print "Autochanger $self->{name} mailbox is full, you must empty I/O first
\n"; + print "Autochanger $self->{name} mailbox is full, you must empty I/O first
\n"; return 0; } @@ -899,18 +899,18 @@ sub transfer { my ($self, $src, $dst) = @_ ; if ($self->{debug}) { - print "
$self->{precmd} $self->{mtxcmd} -f $self->{device} transfer $src $dst
\n"; + print "
$self->{precmd} $self->{mtxcmd} -f $self->{device} transfer $src $dst
\n"; } my $out = `$self->{precmd} $self->{mtxcmd} -f $self->{device} transfer $src $dst 2>&1`; if ($? == 0) { - my $content = $self->get_slot($src); - $self->{slot}->[$src] = 'empty'; - $self->set_slot($dst, $content); - return 1; + my $content = $self->get_slot($src); + $self->{slot}->[$src] = 'empty'; + $self->set_slot($dst, $content); + return 1; } else { - $self->{error} = $out; - return 0; + $self->{error} = $out; + return 0; } } @@ -933,27 +933,27 @@ sub clear_io print "\n"; for my $slot (@{$self->{io}}) { - if ($self->is_slot_loaded($slot)) { - print "\n"; - next; - } - - if ($self->slot_is_full($slot)) - { - my $free = $self->slot_get_first_free() ; - print ""; - - if ($free) { - if ($self->transfer($slot, $free)) { - print "\n"; - } else { - print "\n"; - } - - } else { - $self->{error} = "\n"; - } - } + if ($self->is_slot_loaded($slot)) { + print "\n"; + next; + } + + if ($self->slot_is_full($slot)) + { + my $free = $self->slot_get_first_free() ; + print ""; + + if ($free) { + if ($self->transfer($slot, $free)) { + print "\n"; + } else { + print "\n"; + } + + } else { + $self->{error} = "\n"; + } + } } print "
Slot $slot is currently loaded
move slot $slot to $free :okokokSlot $slot is currently loaded
move slot $slot to $free :okokok
\n"; } @@ -995,49 +995,49 @@ WHERE Media.VolumeName IN ($media_list) for (my $slot=1; $slot <= $self->{info}->{slot} ; $slot++) { - if ($self->slot_is_full($slot)) { + if ($self->slot_is_full($slot)) { - my $vol = $self->{slot}->[$slot]; - if (defined $all->{$vol}) { # TODO : autochanger without barcodes + my $vol = $self->{slot}->[$slot]; + if (defined $all->{$vol}) { # TODO : autochanger without barcodes - my $bslot = $all->{$vol}->{slot} ; - my $inchanger = $all->{$vol}->{inchanger}; + my $bslot = $all->{$vol}->{slot} ; + my $inchanger = $all->{$vol}->{inchanger}; - # if bacula slot or inchanger flag is bad, we display a message - if ($bslot != $slot or !$inchanger) { - push @to_update, $slot; - } - - $all->{$vol}->{realslot} = $slot; + # if bacula slot or inchanger flag is bad, we display a message + if ($bslot != $slot or !$inchanger) { + push @to_update, $slot; + } + + $all->{$vol}->{realslot} = $slot; - push @{ $param }, $all->{$vol}; + push @{ $param }, $all->{$vol}; - } else { # empty or no label - push @{ $param }, {realslot => $slot, - volstatus => 'Unknown', - volumename => $self->{slot}->[$slot]} ; - } - } else { # empty - push @{ $param }, {realslot => $slot, volumename => 'empty'} ; - } + } else { # empty or no label + push @{ $param }, {realslot => $slot, + volstatus => 'Unknown', + volumename => $self->{slot}->[$slot]} ; + } + } else { # empty + push @{ $param }, {realslot => $slot, volumename => 'empty'} ; + } } my $i=0; my $drives = [] ; foreach my $d (@{ $self->{drive} }) { - $drives->[$i] = { index => $i, - load => $self->{drive}->[$i], - name => $self->{drive_name}->[$i], - }; - $i++; + $drives->[$i] = { index => $i, + load => $self->{drive}->[$i], + name => $self->{drive_name}->[$i], + }; + $i++; } $bweb->display({ Name => $self->{name}, - nb_drive => $self->{info}->{drive}, - nb_io => $self->{info}->{io}, - Drives => $drives, - Slots => $param, - Update => scalar(@to_update) }, - 'ach_content.tpl'); + nb_drive => $self->{info}->{drive}, + nb_io => $self->{info}->{io}, + Drives => $drives, + Slots => $param, + Update => scalar(@to_update) }, + 'ach_content.tpl'); } @@ -1083,19 +1083,19 @@ sub new # we compare the current schedule date with begin and end # in a float form ex: 20071212.1243 > 20070101 if ($self->{begin} and $self->{end}) { - ($self->{fbegin}, $self->{fend}) = ($self->{begin}, $self->{end}); - $self->{fbegin} =~ s/(-|:)//g; $self->{fbegin} =~ s/ /./; - $self->{fend} =~ s/(-|:)//g; $self->{fend} =~ s/ /./; + ($self->{fbegin}, $self->{fend}) = ($self->{begin}, $self->{end}); + $self->{fbegin} =~ s/(-|:)//g; $self->{fbegin} =~ s/ /./; + $self->{fend} =~ s/(-|:)//g; $self->{fend} =~ s/ /./; } bless($self,$class); if ($self->{bconsole}) { - my $sel = $self->{name}?"=\"$self->{name}\"":''; - my $b = $self->{bconsole}; - my $out = $b->send_cmd("show schedule$sel"); - $self->parse_scheds(split(/\r?\n/, $out)); - undef $self->{bconsole}; # useless now + my $sel = $self->{name}?"=\"$self->{name}\"":''; + my $b = $self->{bconsole}; + my $out = $b->send_cmd("show schedule$sel"); + $self->parse_scheds(split(/\r?\n/, $out)); + undef $self->{bconsole}; # useless now } return $self; @@ -1112,7 +1112,7 @@ sub add_sched $info->{event} = [ $self->get_events($info, $self->{format}) ]; foreach my $i (qw/hour mday month wday wom woy mins/) { - delete $info->{$i}; + delete $info->{$i}; } push @{$self->{schedules}->{$name}}, $info; @@ -1166,44 +1166,44 @@ sub parse_scheds my $elt; foreach my $ligne (@output) { - if ($ligne =~ /Schedule: name=(.+)/) { - if ($name and $elt) { - $elt->{level} = $run; - $self->add_sched($name, $elt); - $elt=undef; - } - $name = $1; - } - elsif ($ligne =~ /Run Level=(.+)/) { - if ($name and $elt) { - $elt->{level} = $run; - $self->add_sched($name, $elt); - $elt=undef; - } - $run = $1; - } - elsif ($ligne =~ /(hour|mday|month|mins)=(.+)/) { - # All theses lines have the same format - - my ($k,$v) = ($1,$2); - # we get all values (0 1 4 9) - $elt->{$k}=[split (/\s/,$v)]; - } - # we make a bitmap for this kind of data (0 0 1 0 0 0 1) for a quick access - elsif ($ligne =~ /(wday|wom|woy)=(.+)/) { - my ($k,$v) = ($1,$2); - foreach my $e (split (/\s/,$v)) { - $elt->{$k}->[$e]=1; - } - } - elsif ($ligne =~ /Pool: name=(.+?) PoolType/) { - $elt->{pool} = $1; - } + if ($ligne =~ /Schedule: name=(.+)/) { + if ($name and $elt) { + $elt->{level} = $run; + $self->add_sched($name, $elt); + $elt=undef; + } + $name = $1; + } + elsif ($ligne =~ /Run Level=(.+)/) { + if ($name and $elt) { + $elt->{level} = $run; + $self->add_sched($name, $elt); + $elt=undef; + } + $run = $1; + } + elsif ($ligne =~ /(hour|mday|month|mins)=(.+)/) { + # All theses lines have the same format + + my ($k,$v) = ($1,$2); + # we get all values (0 1 4 9) + $elt->{$k}=[split (/\s/,$v)]; + } + # we make a bitmap for this kind of data (0 0 1 0 0 0 1) for a quick access + elsif ($ligne =~ /(wday|wom|woy)=(.+)/) { + my ($k,$v) = ($1,$2); + foreach my $e (split (/\s/,$v)) { + $elt->{$k}->[$e]=1; + } + } + elsif ($ligne =~ /Pool: name=(.+?) PoolType/) { + $elt->{pool} = $1; + } } if ($name and $elt) { - $elt->{level} = $run; - $self->add_sched($name, $elt); + $elt->{level} = $run; + $self->add_sched($name, $elt); } } @@ -1217,44 +1217,44 @@ sub get_events my $year = $self->{year} || ((localtime)[5] + 1900); $format = $format || '%u-%02u-%02u %02u:%02u'; my @ret; - foreach my $m (@{$s->{month}}) # mois de l'annee + foreach my $m (@{$s->{month}}) # mois de l'annee { - foreach my $md (@{$s->{mday}}) # jour du mois - { -# print " m=$m md=$md\n"; - # we check if this day exists (31 fev) - next if (!check_date($year,$m,$md)); -# print " check_date ok\n"; - - my $w = ($md-1)/7; # we use the same thing than bacula - next if (! $s->{wom}->[$w]); -# print " wom ok\n"; - - # on recupere le jour de la semaine - my $wd = Day_of_Week($year,$m,$md); - - my ($w1,undef) = Week_of_Year($year,$m,$wd); - next if (! $s->{woy}->[$w1-1]); # bacula 0-51 -# print " woy ok\n"; - - $wd = 0 if ($wd == 7) ; # sunday is 0 on bacula - next if (! $s->{wday}->[$wd]); -# print " wday ok\n"; - - foreach my $h (@{$s->{hour}}) # hour of the day - { - foreach my $min (@{$s->{mins}}) # minute - { - if ($self->{fbegin}) { - no integer; - my $d = sprintf('%d%0.2d%0.2d.%0.2d%0.2d', - $year,$m,$md,$h,$min); - next if ($d < $self->{fbegin} or $d > $self->{fend}); - } - push @ret, sprintf($format, $year,$m,$md,$h,$min); - } - } - } + foreach my $md (@{$s->{mday}}) # jour du mois + { +# print " m=$m md=$md\n"; + # we check if this day exists (31 fev) + next if (!check_date($year,$m,$md)); +# print " check_date ok\n"; + + my $w = ($md-1)/7; # we use the same thing than bacula + next if (! $s->{wom}->[$w]); +# print " wom ok\n"; + + # on recupere le jour de la semaine + my $wd = Day_of_Week($year,$m,$md); + + my ($w1,undef) = Week_of_Year($year,$m,$wd); + next if (! $s->{woy}->[$w1-1]); # bacula 0-51 +# print " woy ok\n"; + + $wd = 0 if ($wd == 7) ; # sunday is 0 on bacula + next if (! $s->{wday}->[$wd]); +# print " wday ok\n"; + + foreach my $h (@{$s->{hour}}) # hour of the day + { + foreach my $min (@{$s->{mins}}) # minute + { + if ($self->{fbegin}) { + no integer; + my $d = sprintf('%d%0.2d%0.2d.%0.2d%0.2d', + $year,$m,$md,$h,$min); + next if ($d < $self->{fbegin} or $d > $self->{fend}); + } + push @ret, sprintf($format, $year,$m,$md,$h,$min); + } + } + } } return @ret; } @@ -1289,50 +1289,50 @@ our $cur_id=0; =cut our %sql_func = ( - Pg => { - UNIX_TIMESTAMP => '', - FROM_UNIXTIME => '', - TO_SEC => " interval '1 second' * ", - SEC_TO_INT => "SEC_TO_INT", - SEC_TO_TIME => '', - MATCH => " ~* ", - STARTTIME_SEC => " date_trunc('sec', Job.StartTime) ", - STARTTIME_DAY => " date_trunc('day', Job.StartTime) ", - STARTTIME_HOUR => " date_trunc('hour', Job.StartTime) ", - STARTTIME_MONTH => " date_trunc('month', Job.StartTime) ", - STARTTIME_WEEK => " date_trunc('week', Job.StartTime) ", - STARTTIME_PHOUR=> " date_part('hour', Job.StartTime) ", - STARTTIME_PDAY => " date_part('day', Job.StartTime) ", - STARTTIME_PMONTH => " date_part('month', Job.StartTime) ", - STARTTIME_PWEEK => " date_part('week', Job.StartTime) ", - DB_SIZE => " SELECT pg_database_size(current_database()) ", - CAT_POOL_TYPE => " MediaType || '_' || Pool.Name ", - CONCAT_SEP => "", - }, - mysql => { - UNIX_TIMESTAMP => 'UNIX_TIMESTAMP', - FROM_UNIXTIME => 'FROM_UNIXTIME', - SEC_TO_INT => '', - TO_SEC => '', - SEC_TO_TIME => 'SEC_TO_TIME', - MATCH => " REGEXP ", - STARTTIME_SEC => " DATE_FORMAT(Job.StartTime, '%Y-%m-%d %T') ", - STARTTIME_DAY => " DATE_FORMAT(Job.StartTime, '%Y-%m-%d') ", - STARTTIME_HOUR => " DATE_FORMAT(Job.StartTime, '%Y-%m-%d %H') ", - STARTTIME_MONTH => " DATE_FORMAT(Job.StartTime, '%Y-%m') ", - STARTTIME_WEEK => " DATE_FORMAT(Job.StartTime, '%Y-%v') ", - STARTTIME_PHOUR=> " DATE_FORMAT(Job.StartTime, '%H') ", - STARTTIME_PDAY => " DATE_FORMAT(Job.StartTime, '%d') ", - STARTTIME_PMONTH => " DATE_FORMAT(Job.StartTime, '%m') ", - STARTTIME_PWEEK => " DATE_FORMAT(Job.StartTime, '%v') ", - # with mysql < 5, you have to play with the ugly SHOW command - DB_SIZE => " SELECT 0 ", - # works only with mysql 5 - # DB_SIZE => " SELECT sum(DATA_LENGTH) FROM INFORMATION_SCHEMA.TABLES ", - CAT_POOL_TYPE => " CONCAT(MediaType,'_',Pool.Name) ", - CONCAT_SEP => " SEPARATOR '' ", - }, - ); + Pg => { + UNIX_TIMESTAMP => '', + FROM_UNIXTIME => '', + TO_SEC => " interval '1 second' * ", + SEC_TO_INT => "SEC_TO_INT", + SEC_TO_TIME => '', + MATCH => " ~* ", + STARTTIME_SEC => " date_trunc('sec', Job.StartTime) ", + STARTTIME_DAY => " date_trunc('day', Job.StartTime) ", + STARTTIME_HOUR => " date_trunc('hour', Job.StartTime) ", + STARTTIME_MONTH => " date_trunc('month', Job.StartTime) ", + STARTTIME_WEEK => " date_trunc('week', Job.StartTime) ", + STARTTIME_PHOUR=> " date_part('hour', Job.StartTime) ", + STARTTIME_PDAY => " date_part('day', Job.StartTime) ", + STARTTIME_PMONTH => " date_part('month', Job.StartTime) ", + STARTTIME_PWEEK => " date_part('week', Job.StartTime) ", + DB_SIZE => " SELECT pg_database_size(current_database()) ", + CAT_POOL_TYPE => " MediaType || '_' || Pool.Name ", + CONCAT_SEP => "", + }, + mysql => { + UNIX_TIMESTAMP => 'UNIX_TIMESTAMP', + FROM_UNIXTIME => 'FROM_UNIXTIME', + SEC_TO_INT => '', + TO_SEC => '', + SEC_TO_TIME => 'SEC_TO_TIME', + MATCH => " REGEXP ", + STARTTIME_SEC => " DATE_FORMAT(Job.StartTime, '%Y-%m-%d %T') ", + STARTTIME_DAY => " DATE_FORMAT(Job.StartTime, '%Y-%m-%d') ", + STARTTIME_HOUR => " DATE_FORMAT(Job.StartTime, '%Y-%m-%d %H') ", + STARTTIME_MONTH => " DATE_FORMAT(Job.StartTime, '%Y-%m') ", + STARTTIME_WEEK => " DATE_FORMAT(Job.StartTime, '%Y-%v') ", + STARTTIME_PHOUR=> " DATE_FORMAT(Job.StartTime, '%H') ", + STARTTIME_PDAY => " DATE_FORMAT(Job.StartTime, '%d') ", + STARTTIME_PMONTH => " DATE_FORMAT(Job.StartTime, '%m') ", + STARTTIME_PWEEK => " DATE_FORMAT(Job.StartTime, '%v') ", + # with mysql < 5, you have to play with the ugly SHOW command + DB_SIZE => " SELECT 0 ", + # works only with mysql 5 + # DB_SIZE => " SELECT sum(DATA_LENGTH) FROM INFORMATION_SCHEMA.TABLES ", + CAT_POOL_TYPE => " CONCAT(MediaType,'_',Pool.Name) ", + CONCAT_SEP => " SEPARATOR '' ", + }, + ); sub dbh_is_mysql { @@ -1369,9 +1369,9 @@ sub dbh_quote $self->connect_db(); if (wantarray) { - return map { $self->{dbh}->quote($_) } @what; + return map { $self->{dbh}->quote($_) } @what; } else { - return $self->{dbh}->quote($what[0]) ; + return $self->{dbh}->quote($what[0]) ; } } @@ -1405,9 +1405,9 @@ sub dbh_strcat { my ($self, @what) = @_; if ($self->dbh_is_mysql()) { - return 'CONCAT(' . join(',', @what) . ')' ; + return 'CONCAT(' . join(',', @what) . ')' ; } else { - return join(' || ', @what); + return join(' || ', @what); } } @@ -1426,8 +1426,8 @@ sub human_size my $i=0; my $format = '%i %s'; while ($val / 1024 > 1) { - $i++; - $val /= 1024; + $i++; + $val /= 1024; } $format = ($i>0)?'%0.1f %s':'%i %s'; return sprintf($format, $val, $unit[$i]); @@ -1458,23 +1458,23 @@ sub human_sec use integer; my $val = shift; - $val /= 60; # sec -> min + $val /= 60; # sec -> min if ($val / 60 <= 1) { - return "$val mins"; + return "$val mins"; } - $val /= 60; # min -> hour + $val /= 60; # min -> hour if ($val / 24 <= 1) { - return "$val hours"; + return "$val hours"; } - $val /= 24; # hour -> day + $val /= 24; # hour -> day if ($val / 365 < 2) { - return "$val days"; + return "$val days"; } - $val /= 365 ; # day -> year + $val /= 365 ; # day -> year return "$val years"; } @@ -1485,11 +1485,11 @@ sub human_enabled my $val = shift || 0; if ($val eq '1' or $val eq "yes") { - return "yes"; + return "yes"; } elsif ($val eq '2' or $val eq "archived") { - return "archived"; + return "archived"; } else { - return "no"; + return "no"; } } @@ -1499,11 +1499,11 @@ sub from_human_enabled my $val = shift || 0; if ($val eq '1' or $val eq "yes") { - return 1; + return 1; } elsif ($val eq '2' or $val eq "archived") { - return 2; + return 2; } else { - return 0; + return 0; } } @@ -1514,15 +1514,15 @@ sub from_human_sec my $val = shift; unless ($val =~ /^\s*(\d+)\s*(\w)\w*\s*$/) { - return 0; + return 0; } my %times = ( m => 60, - h => 60*60, - d => 60*60*24, - m => 60*60*24*31, - y => 60*60*24*365, - ); + h => 60*60, + d => 60*60*24, + m => 60*60*24*31, + y => 60*60*24*365, + ); my $mult = $times{$2} || 0; return $1 * $mult; @@ -1534,7 +1534,7 @@ sub get_stat_table my ($self) = @_; my $ret = $self->{info}->{stat_job_table} || 'JobHisto'; if ($ret !~ m/^job$/i) { - $ret = "(SELECT * FROM Job UNION SELECT * FROM $ret)"; + $ret = "(SELECT * FROM Job UNION SELECT * FROM $ret)"; } return $ret; } @@ -1545,20 +1545,20 @@ sub connect_db unless ($self->{dbh}) { - $self->{dbh} = DBI->connect($self->{info}->{dbi}, - $self->{info}->{user}, - $self->{info}->{password}); + $self->{dbh} = DBI->connect($self->{info}->{dbi}, + $self->{info}->{user}, + $self->{info}->{password}); - $self->error("Can't connect to your database:\n$DBI::errstr\n") - unless ($self->{dbh}); + $self->error("Can't connect to your database:\n$DBI::errstr\n") + unless ($self->{dbh}); - $self->{dbh}->{FetchHashKeyName} = 'NAME_lc'; + $self->{dbh}->{FetchHashKeyName} = 'NAME_lc'; - if ($self->dbh_is_mysql()) { - $self->{dbh}->do("SET group_concat_max_len=1000000"); - } else { - $self->{dbh}->do("SET datestyle TO 'ISO, YMD'"); - } + if ($self->dbh_is_mysql()) { + $self->{dbh}->do("SET group_concat_max_len=1000000"); + } else { + $self->{dbh}->do("SET datestyle TO 'ISO, YMD'"); + } } } @@ -1566,18 +1566,18 @@ sub new { my ($class, %arg) = @_; my $self = bless ({ - dbh => undef, # connect_db(); - info => { - dbi => '', # DBI:Pg:database=bacula;host=127.0.0.1 - user => 'bacula', - password => 'test', - }, + dbh => undef, # connect_db(); + info => { + dbi => '', # DBI:Pg:database=bacula;host=127.0.0.1 + user => 'bacula', + password => 'test', + }, },$class) ; map { $self->{lc($_)} = $arg{$_} } keys %arg ; if ($self->{info}->{dbi} =~ /DBI:(\w+):/i) { - $self->{sql} = $sql_func{$1}; + $self->{sql} = $sql_func{$1}; } $self->{loginname} = CGI::remote_user(); @@ -1592,7 +1592,7 @@ sub display_begin { my ($self) = @_; if ($self->{info}->{enable_security}) { - $self->get_roles(); # get lang + $self->get_roles(); # get lang } $self->display($self->{info}, "begin.tpl"); } @@ -1636,23 +1636,23 @@ GROUP by client_group_name"; sub display_clients { my ($self) = @_; - my $where=''; # by default + my $where=''; # by default my $arg = $self->get_form("client", "qre_client", - "jclient_groups", "qnotingroup"); + "jclient_groups", "qnotingroup"); if ($arg->{qre_client}) { - $where = "WHERE Name $self->{sql}->{MATCH} $arg->{qre_client} "; + $where = "WHERE Name $self->{sql}->{MATCH} $arg->{qre_client} "; } elsif ($arg->{client}) { - $where = "WHERE Name = '$arg->{client}' "; + $where = "WHERE Name = '$arg->{client}' "; } elsif ($arg->{jclient_groups}) { - # $filter could already contains client_group_member - $where = " + # $filter could already contains client_group_member + $where = " JOIN client_group_member USING (ClientId) JOIN client_group USING (client_group_id) WHERE client_group_name IN ($arg->{jclient_groups}) "; } elsif ($arg->{qnotingroup}) { - $where = " + $where = " WHERE NOT EXISTS (SELECT 1 FROM client_group_member WHERE Client.ClientId = client_group_member.ClientId @@ -1672,7 +1672,7 @@ $where ; my $all = $self->dbh_selectall_hashref($query, 'name') ; my $dsp = { ID => $cur_id++, - clients => [ values %$all] }; + clients => [ values %$all] }; $self->display($dsp, "client_list.tpl") ; } @@ -1685,11 +1685,11 @@ sub get_limit my $label = ''; if ($arg{since} and $arg{age}) { - my $now = "$self->{sql}->{UNIX_TIMESTAMP}(TIMESTAMP '$arg{since}')"; - $limit .= " + my $now = "$self->{sql}->{UNIX_TIMESTAMP}(TIMESTAMP '$arg{since}')"; + $limit .= " AND $self->{sql}->{UNIX_TIMESTAMP}(StartTime) > $now AND $self->{sql}->{UNIX_TIMESTAMP}(EndTime) < ($now + $self->{sql}->{TO_SEC}($arg{age}))"; - $label .= "since $arg{since} and during " . human_sec($arg{age}); + $label .= "since $arg{since} and during " . human_sec($arg{age}); } elsif ($arg{age}) { $limit .= @@ -1704,25 +1704,25 @@ sub get_limit } if ($arg{groupby}) { - $limit .= " GROUP BY $arg{groupby} "; + $limit .= " GROUP BY $arg{groupby} "; } if ($arg{order}) { - $limit .= " ORDER BY $arg{order} "; + $limit .= " ORDER BY $arg{order} "; } if ($arg{limit}) { - $limit .= " LIMIT $arg{limit} "; - $label .= " limited to $arg{limit}"; + $limit .= " LIMIT $arg{limit} "; + $label .= " limited to $arg{limit}"; } if ($arg{offset}) { - $limit .= " OFFSET $arg{offset} "; - $label .= " with $arg{offset} offset "; + $limit .= " OFFSET $arg{offset} "; + $label .= " with $arg{offset} offset "; } unless ($label) { - $label = 'no filter'; + $label = 'no filter'; } return ($limit, $label); @@ -1758,141 +1758,141 @@ sub get_form my %ret; my %opt_i = ( - limit => 100, - cost => 10, - offset => 0, + limit => 100, + cost => 10, + offset => 0, start => 0, - width => 640, - height => 480, - jobid => 0, - slot => 0, - drive => 0, - priority => 10, - age => $self->{info}->{default_age}, - days => 1, - maxvoljobs => 0, - maxvolbytes => 0, - maxvolfiles => 0, - filenameid => 0, - pathid => 0, - nb => 0, - ); - - my %opt_ss =( # string with space - job => 1, - storage => 1, - ); - my %opt_s = ( # default to '' - ach => 1, - status => 1, - volstatus => 1, + width => 640, + height => 480, + jobid => 0, + slot => 0, + drive => 0, + priority => 10, + age => $self->{info}->{default_age}, + days => 1, + maxvoljobs => 0, + maxvolbytes => 0, + maxvolfiles => 0, + filenameid => 0, + pathid => 0, + nb => 0, + ); + + my %opt_ss =( # string with space + job => 1, + storage => 1, + ); + my %opt_s = ( # default to '' + ach => 1, + status => 1, + volstatus => 1, inchanger => 1, client => 1, - level => 1, - pool => 1, - media => 1, + level => 1, + pool => 1, + media => 1, ach => 1, jobtype=> 1, - graph => 1, + graph => 1, gtype => 1, type => 1, - poolrecycle => 1, - replace => 1, - expired => 1, - enabled => 1, + poolrecycle => 1, + replace => 1, + expired => 1, + enabled => 1, username => 1, rolename => 1, - storage_cmd => 1, + storage_cmd => 1, + ); + my %opt_p = ( # option with path + fileset=> 1, + mtxcmd => 1, + precmd => 1, + device => 1, + where => 1, ); - my %opt_p = ( # option with path - fileset=> 1, - mtxcmd => 1, - precmd => 1, - device => 1, - where => 1, - ); my %opt_r = (regexwhere => 1); - my %opt_d = ( # option with date - voluseduration=> 1, - volretention => 1, - ); - my %opt_t = (when => 2, # option with time - begin => 1, # 1 hh:min are optionnal - end => 1, # 2 hh:min are required - ); + my %opt_d = ( # option with date + voluseduration=> 1, + volretention => 1, + ); + my %opt_t = (when => 2, # option with time + begin => 1, # 1 hh:min are optionnal + end => 1, # 2 hh:min are required + ); foreach my $i (@what) { - if (exists $opt_i{$i}) {# integer param - my $value = CGI::param($i) || $opt_i{$i} ; - if ($value =~ /^(\d+)$/) { - $ret{$i} = $1; - } elsif ($i eq 'age' && # can have unit - $value =~ /^(?:\d+(?:[ywdhms]\s*)?)+\s*$/) # 2y1h2m34s - { - $ret{$i} = human_sec_unit($value); - } - } elsif ($opt_s{$i}) { # simple string param - my $value = CGI::param($i) || ''; - if ($value =~ /^([\w\d\.-]+)$/) { - $ret{$i} = $1; - } - } elsif ($opt_ss{$i}) { # simple string param (with space) - my $value = CGI::param($i) || ''; - if ($value =~ /^([\w\d\.\-\s]+)$/) { - $ret{$i} = $1; - } - } elsif ($i =~ /^j(\w+)s$/) { # quote join args "'arg1', 'arg2'" - my @value = grep { ! /^\s*$/ } CGI::param($1) ; - if (@value) { - $ret{$i} = $self->dbh_join(@value) ; - } - - } elsif ($i =~ /^q(\w+[^s])$/) { # 'arg1' - my $value = CGI::param($1) ; - if ($value) { - $ret{$i} = $self->dbh_quote($value); - } - - } elsif ($i =~ /^q(\w+)s$/) { #[ 'arg1', 'arg2'] - $ret{$i} = [ map { { name => $self->dbh_quote($_) } } - grep { ! /^\s*$/ } CGI::param($1) ]; - } elsif (exists $opt_p{$i}) { - my $value = CGI::param($i) || ''; - if ($value =~ /^([\w\d\.\/\s:\@\-]+)$/) { - $ret{$i} = $1; - } - } elsif (exists $opt_r{$i}) { - my $value = CGI::param($i) || ''; - if ($value =~ /^([^'"']+)$/) { - $ret{$i} = $1; - } - } elsif (exists $opt_d{$i}) { - my $value = CGI::param($i) || ''; - if ($value =~ /^\s*(\d+\s+\w+)$/) { - $ret{$i} = $1; - } - } elsif (exists $opt_t{$i}) { # 1: hh:min optionnal, 2: hh:min required - my $when = CGI::param($i) || ''; - if ($when =~ /(\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?)/) { - if ($opt_t{$i} == 1 or defined $2) { - $ret{$i} = $1; - } - } - } + if (exists $opt_i{$i}) {# integer param + my $value = CGI::param($i) || $opt_i{$i} ; + if ($value =~ /^(\d+)$/) { + $ret{$i} = $1; + } elsif ($i eq 'age' && # can have unit + $value =~ /^(?:\d+(?:[ywdhms]\s*)?)+\s*$/) # 2y1h2m34s + { + $ret{$i} = human_sec_unit($value); + } + } elsif ($opt_s{$i}) { # simple string param + my $value = CGI::param($i) || ''; + if ($value =~ /^([\w\d\.-]+)$/) { + $ret{$i} = $1; + } + } elsif ($opt_ss{$i}) { # simple string param (with space) + my $value = CGI::param($i) || ''; + if ($value =~ /^([\w\d\.\-\s]+)$/) { + $ret{$i} = $1; + } + } elsif ($i =~ /^j(\w+)s$/) { # quote join args "'arg1', 'arg2'" + my @value = grep { ! /^\s*$/ } CGI::param($1) ; + if (@value) { + $ret{$i} = $self->dbh_join(@value) ; + } + + } elsif ($i =~ /^q(\w+[^s])$/) { # 'arg1' + my $value = CGI::param($1) ; + if ($value) { + $ret{$i} = $self->dbh_quote($value); + } + + } elsif ($i =~ /^q(\w+)s$/) { #[ 'arg1', 'arg2'] + $ret{$i} = [ map { { name => $self->dbh_quote($_) } } + grep { ! /^\s*$/ } CGI::param($1) ]; + } elsif (exists $opt_p{$i}) { + my $value = CGI::param($i) || ''; + if ($value =~ /^([\w\d\.\/\s:\@\-]+)$/) { + $ret{$i} = $1; + } + } elsif (exists $opt_r{$i}) { + my $value = CGI::param($i) || ''; + if ($value =~ /^([^'"']+)$/) { + $ret{$i} = $1; + } + } elsif (exists $opt_d{$i}) { + my $value = CGI::param($i) || ''; + if ($value =~ /^\s*(\d+\s+\w+)$/) { + $ret{$i} = $1; + } + } elsif (exists $opt_t{$i}) { # 1: hh:min optionnal, 2: hh:min required + my $when = CGI::param($i) || ''; + if ($when =~ /(\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?)/) { + if ($opt_t{$i} == 1 or defined $2) { + $ret{$i} = $1; + } + } + } } if ($what{storage_cmd}) { - if (!grep {/^\Q$ret{storage_cmd}\E$/} ('mount', 'umount', 'release','status')) { - delete $ret{storage_cmd}; - } + if (!grep {/^\Q$ret{storage_cmd}\E$/} ('mount', 'umount', 'release','status')) { + delete $ret{storage_cmd}; + } } if ($what{slots}) { - foreach my $s (CGI::param('slot')) { - if ($s =~ /^(\d+)$/) { - push @{$ret{slots}}, $s; - } - } + foreach my $s (CGI::param('slot')) { + if ($s =~ /^(\d+)$/) { + push @{$ret{slots}}, $s; + } + } } if ($what{since}) { @@ -1904,129 +1904,129 @@ sub get_form } if ($what{lang}) { - my $lang = CGI::param('lang') || 'en'; - if ($lang =~ /^(\w\w)$/) { - $ret{lang} = $1; - } + my $lang = CGI::param('lang') || 'en'; + if ($lang =~ /^(\w\w)$/) { + $ret{lang} = $1; + } } if ($what{db_clients}) { - my $filter=''; - if ($what{filter}) { - # get security filter only if asked - $filter = $self->get_client_filter(); - } + my $filter=''; + if ($what{filter}) { + # get security filter only if asked + $filter = $self->get_client_filter(); + } - my $query = " + my $query = " SELECT Client.Name as clientname FROM Client $filter "; - my $clients = $self->dbh_selectall_hashref($query, 'clientname'); - $ret{db_clients} = [sort {$a->{clientname} cmp $b->{clientname} } - values %$clients] ; + my $clients = $self->dbh_selectall_hashref($query, 'clientname'); + $ret{db_clients} = [sort {$a->{clientname} cmp $b->{clientname} } + values %$clients] ; } if ($what{db_client_groups}) { - my $filter=''; - if ($what{filter}) { - # get security filter only if asked - $filter = $self->get_client_group_filter(); - } + my $filter=''; + if ($what{filter}) { + # get security filter only if asked + $filter = $self->get_client_group_filter(); + } - my $query = " + my $query = " SELECT client_group_name AS name, comment AS comment FROM client_group $filter "; - my $grps = $self->dbh_selectall_hashref($query, 'name'); - $ret{db_client_groups} = [sort {$a->{name} cmp $b->{name} } - values %$grps] ; + my $grps = $self->dbh_selectall_hashref($query, 'name'); + $ret{db_client_groups} = [sort {$a->{name} cmp $b->{name} } + values %$grps] ; } if ($what{db_usernames}) { - my $query = " + my $query = " SELECT username, comment FROM bweb_user "; - my $users = $self->dbh_selectall_hashref($query, 'username'); - $ret{db_usernames} = [sort {$a->{username} cmp $b->{username} } - values %$users] ; + my $users = $self->dbh_selectall_hashref($query, 'username'); + $ret{db_usernames} = [sort {$a->{username} cmp $b->{username} } + values %$users] ; } if ($what{db_roles}) { - my $query = " + my $query = " SELECT rolename, comment FROM bweb_role "; - my $r = $self->dbh_selectall_hashref($query, 'rolename'); - $ret{db_roles} = [sort {$a->{rolename} cmp $b->{rolename} } - values %$r] ; + my $r = $self->dbh_selectall_hashref($query, 'rolename'); + $ret{db_roles} = [sort {$a->{rolename} cmp $b->{rolename} } + values %$r] ; } if ($what{db_mediatypes}) { - my $query = " + my $query = " SELECT MediaType as mediatype FROM MediaType "; - my $media = $self->dbh_selectall_hashref($query, 'mediatype'); - $ret{db_mediatypes} = [sort {$a->{mediatype} cmp $b->{mediatype} } - values %$media] ; + my $media = $self->dbh_selectall_hashref($query, 'mediatype'); + $ret{db_mediatypes} = [sort {$a->{mediatype} cmp $b->{mediatype} } + values %$media] ; } if ($what{db_locations}) { - my $query = " + my $query = " SELECT Location as location, Cost as cost FROM Location "; - my $loc = $self->dbh_selectall_hashref($query, 'location'); - $ret{db_locations} = [ sort { $a->{location} - cmp - $b->{location} - } values %$loc ]; + my $loc = $self->dbh_selectall_hashref($query, 'location'); + $ret{db_locations} = [ sort { $a->{location} + cmp + $b->{location} + } values %$loc ]; } if ($what{db_pools}) { - my $query = "SELECT Name as name FROM Pool"; + my $query = "SELECT Name as name FROM Pool"; - my $all = $self->dbh_selectall_hashref($query, 'name') ; - $ret{db_pools} = [ sort { $a->{name} cmp $b->{name} } values %$all ]; + my $all = $self->dbh_selectall_hashref($query, 'name') ; + $ret{db_pools} = [ sort { $a->{name} cmp $b->{name} } values %$all ]; } if ($what{db_filesets}) { - my $query = " + my $query = " SELECT FileSet.FileSet AS fileset FROM FileSet "; - my $filesets = $self->dbh_selectall_hashref($query, 'fileset'); + my $filesets = $self->dbh_selectall_hashref($query, 'fileset'); - $ret{db_filesets} = [sort {lc($a->{fileset}) cmp lc($b->{fileset}) } - values %$filesets] ; + $ret{db_filesets} = [sort {lc($a->{fileset}) cmp lc($b->{fileset}) } + values %$filesets] ; } if ($what{db_jobnames}) { - my $filter=''; - if ($what{filter}) { - $filter = " JOIN Client USING (ClientId) " . $self->get_client_filter(); - } - my $query = " + my $filter=''; + if ($what{filter}) { + $filter = " JOIN Client USING (ClientId) " . $self->get_client_filter(); + } + my $query = " SELECT DISTINCT Job.Name AS jobname FROM Job $filter "; - my $jobnames = $self->dbh_selectall_hashref($query, 'jobname'); + my $jobnames = $self->dbh_selectall_hashref($query, 'jobname'); - $ret{db_jobnames} = [sort {lc($a->{jobname}) cmp lc($b->{jobname}) } - values %$jobnames] ; + $ret{db_jobnames} = [sort {lc($a->{jobname}) cmp lc($b->{jobname}) } + values %$jobnames] ; } if ($what{db_devices}) { - my $query = " + my $query = " SELECT Device.Name AS name FROM Device "; - my $devices = $self->dbh_selectall_hashref($query, 'name'); + my $devices = $self->dbh_selectall_hashref($query, 'name'); - $ret{db_devices} = [sort {lc($a->{name}) cmp lc($b->{name}) } - values %$devices] ; + $ret{db_devices} = [sort {lc($a->{name}) cmp lc($b->{name}) } + values %$devices] ; } return \%ret; @@ -2038,24 +2038,24 @@ sub display_graph $self->can_do('r_view_stat'); my $fields = $self->get_form(qw/age level status clients filesets graph gtype type filter db_clients - limit db_filesets width height - qclients qfilesets qjobnames db_jobnames/); + limit db_filesets width height + qclients qfilesets qjobnames db_jobnames/); my $url = CGI::url(-full => 0, -base => 0, -query => 1); - $url =~ s/^.+?\?//; # http://path/to/bweb.pl?arg => arg + $url =~ s/^.+?\?//; # http://path/to/bweb.pl?arg => arg # this organisation is to keep user choice between 2 click # TODO : fileset and client selection doesn't work $self->display({ - url => $url, - %$fields, + url => $url, + %$fields, }, "graph.tpl"); if ($fields->{gtype} and $fields->{gtype} eq 'balloon') { - system("./bgraph.pl"); + system("./bgraph.pl"); } } @@ -2066,7 +2066,7 @@ sub get_selected_media_location my $media = $self->get_form('jmedias'); unless ($media->{jmedias}) { - return undef; + return undef; } my $query = " @@ -2091,19 +2091,19 @@ sub move_media my $media = $self->get_selected_media_location(); unless ($media) { - return ; + return ; } my $elt = $self->get_form('db_locations'); $self->display({ ID => $cur_id++, - enabled => human_enabled($in), - %$elt, # db_locations - media => [ + enabled => human_enabled($in), + %$elt, # db_locations + media => [ sort { $a->{volumename} cmp $b->{volumename} } values %$media - ], - }, - "move_media.tpl"); + ], + }, + "move_media.tpl"); } sub help_extern @@ -2123,11 +2123,11 @@ sub help_extern_compute my $number = CGI::param('limit') || '' ; unless ($number =~ /^(\d+)$/) { - return $self->error("Bad arg number : $number "); + return $self->error("Bad arg number : $number "); } my ($sql, undef) = $self->get_param('pools', - 'locations', 'mediatypes'); + 'locations', 'mediatypes'); my $query = " SELECT Media.VolumeName AS volumename, @@ -2155,7 +2155,7 @@ LIMIT $number my $all = $self->dbh_selectall_hashref($query, 'volumename') ; $self->display({ Media => [ values %$all ] }, - "help_extern_compute.tpl"); + "help_extern_compute.tpl"); } sub help_intern @@ -2174,14 +2174,14 @@ sub help_intern_compute my $number = CGI::param('limit') || '' ; unless ($number =~ /^(\d+)$/) { - return $self->error("Bad arg number : $number "); + return $self->error("Bad arg number : $number "); } my ($sql, undef) = $self->get_param('pools', 'locations', 'mediatypes'); if (CGI::param('expired')) { # we take only expired volumes or purged/recycle ones - $sql = " + $sql = " AND ( ( ($self->{sql}->{UNIX_TIMESTAMP}(Media.LastWritten) + $self->{sql}->{TO_SEC}(Media.VolRetention) @@ -2219,7 +2219,7 @@ LIMIT $number my $all = $self->dbh_selectall_hashref($query, 'volumename') ; $self->display({ Media => [ values %$all ] }, - "help_intern_compute.tpl"); + "help_intern_compute.tpl"); } @@ -2264,131 +2264,131 @@ sub get_param my $limit = ''; if ($elt{clients}) { - my @clients = grep { ! /^\s*$/ } CGI::param('client'); - if (@clients) { - $ret{clients} = \@clients; - my $str = $self->dbh_join(@clients); - $limit .= "AND Client.Name IN ($str) "; - } + my @clients = grep { ! /^\s*$/ } CGI::param('client'); + if (@clients) { + $ret{clients} = \@clients; + my $str = $self->dbh_join(@clients); + $limit .= "AND Client.Name IN ($str) "; + } } if ($elt{client_groups}) { - my @clients = grep { ! /^\s*$/ } CGI::param('client_group'); - if (@clients) { - $ret{client_groups} = \@clients; - my $str = $self->dbh_join(@clients); - $limit .= "AND client_group_name IN ($str) "; - } + my @clients = grep { ! /^\s*$/ } CGI::param('client_group'); + if (@clients) { + $ret{client_groups} = \@clients; + my $str = $self->dbh_join(@clients); + $limit .= "AND client_group_name IN ($str) "; + } } if ($elt{filesets}) { - my @filesets = grep { ! /^\s*$/ } CGI::param('fileset'); - if (@filesets) { - $ret{filesets} = \@filesets; - my $str = $self->dbh_join(@filesets); - $limit .= "AND FileSet.FileSet IN ($str) "; - } + my @filesets = grep { ! /^\s*$/ } CGI::param('fileset'); + if (@filesets) { + $ret{filesets} = \@filesets; + my $str = $self->dbh_join(@filesets); + $limit .= "AND FileSet.FileSet IN ($str) "; + } } if ($elt{mediatypes}) { - my @media = grep { ! /^\s*$/ } CGI::param('mediatype'); - if (@media) { - $ret{mediatypes} = \@media; - my $str = $self->dbh_join(@media); - $limit .= "AND Media.MediaType IN ($str) "; - } + my @media = grep { ! /^\s*$/ } CGI::param('mediatype'); + if (@media) { + $ret{mediatypes} = \@media; + my $str = $self->dbh_join(@media); + $limit .= "AND Media.MediaType IN ($str) "; + } } if ($elt{client}) { - my $client = CGI::param('client'); - if ($client) { - $ret{client} = $client; - $client = $self->dbh_quote($client); - $limit .= "AND Client.Name = $client "; - } + my $client = CGI::param('client'); + if ($client) { + $ret{client} = $client; + $client = $self->dbh_quote($client); + $limit .= "AND Client.Name = $client "; + } } if ($elt{level}) { - my $level = CGI::param('level') || ''; - if ($level =~ /^(\w)$/) { - $ret{level} = $1; - $limit .= "AND Job.Level = '$1' "; - } + my $level = CGI::param('level') || ''; + if ($level =~ /^(\w)$/) { + $ret{level} = $1; + $limit .= "AND Job.Level = '$1' "; + } } if ($elt{jobid}) { - my $jobid = CGI::param('jobid') || ''; + my $jobid = CGI::param('jobid') || ''; - if ($jobid =~ /^(\d+)$/) { - $ret{jobid} = $1; - $limit .= "AND Job.JobId = '$1' "; - } + if ($jobid =~ /^(\d+)$/) { + $ret{jobid} = $1; + $limit .= "AND Job.JobId = '$1' "; + } } if ($elt{status}) { - my $status = CGI::param('status') || ''; - if ($status =~ /^(\w)$/) { - $ret{status} = $1; - if ($1 eq 'f') { - $limit .= "AND Job.JobStatus IN ('E','e','f','A') "; - } elsif ($1 eq 'W') { - $limit .= "AND Job.JobStatus IN ('T', 'W') OR Job.JobErrors > 0 "; + my $status = CGI::param('status') || ''; + if ($status =~ /^(\w)$/) { + $ret{status} = $1; + if ($1 eq 'f') { + $limit .= "AND Job.JobStatus IN ('E','e','f','A') "; + } elsif ($1 eq 'W') { + $limit .= "AND Job.JobStatus IN ('T', 'W') OR Job.JobErrors > 0 "; } else { - $limit .= "AND Job.JobStatus = '$1' "; - } - } + $limit .= "AND Job.JobStatus = '$1' "; + } + } } if ($elt{volstatus}) { - my $status = CGI::param('volstatus') || ''; - if ($status =~ /^(\w+)$/) { - $ret{status} = $1; - $limit .= "AND Media.VolStatus = '$1' "; - } + my $status = CGI::param('volstatus') || ''; + if ($status =~ /^(\w+)$/) { + $ret{status} = $1; + $limit .= "AND Media.VolStatus = '$1' "; + } } if ($elt{locations}) { - my @location = grep { ! /^\s*$/ } CGI::param('location') ; - if (@location) { - $ret{locations} = \@location; - my $str = $self->dbh_join(@location); - $limit .= "AND Location.Location IN ($str) "; - } + my @location = grep { ! /^\s*$/ } CGI::param('location') ; + if (@location) { + $ret{locations} = \@location; + my $str = $self->dbh_join(@location); + $limit .= "AND Location.Location IN ($str) "; + } } if ($elt{pools}) { - my @pool = grep { ! /^\s*$/ } CGI::param('pool') ; - if (@pool) { - $ret{pools} = \@pool; - my $str = $self->dbh_join(@pool); - $limit .= "AND Pool.Name IN ($str) "; - } + my @pool = grep { ! /^\s*$/ } CGI::param('pool') ; + if (@pool) { + $ret{pools} = \@pool; + my $str = $self->dbh_join(@pool); + $limit .= "AND Pool.Name IN ($str) "; + } } if ($elt{location}) { - my $location = CGI::param('location') || ''; - if ($location) { - $ret{location} = $location; - $location = $self->dbh_quote($location); - $limit .= "AND Location.Location = $location "; - } + my $location = CGI::param('location') || ''; + if ($location) { + $ret{location} = $location; + $location = $self->dbh_quote($location); + $limit .= "AND Location.Location = $location "; + } } if ($elt{pool}) { - my $pool = CGI::param('pool') || ''; - if ($pool) { - $ret{pool} = $pool; - $pool = $self->dbh_quote($pool); - $limit .= "AND Pool.Name = $pool "; - } + my $pool = CGI::param('pool') || ''; + if ($pool) { + $ret{pool} = $pool; + $pool = $self->dbh_quote($pool); + $limit .= "AND Pool.Name = $pool "; + } } if ($elt{jobtype}) { - my $jobtype = CGI::param('jobtype') || ''; - if ($jobtype =~ /^(\w)$/) { - $ret{jobtype} = $1; - $limit .= "AND Job.Type = '$1' "; - } + my $jobtype = CGI::param('jobtype') || ''; + if ($jobtype =~ /^(\w)$/) { + $ret{jobtype} = $1; + $limit .= "AND Job.Type = '$1' "; + } } return ($limit, %ret); @@ -2409,16 +2409,16 @@ sub display_job my ($limit, $label) = $self->get_limit(%arg); my ($where, undef) = $self->get_param('clients', - 'client_groups', - 'level', - 'filesets', - 'jobtype', - 'pools', - 'jobid', - 'status'); + 'client_groups', + 'level', + 'filesets', + 'jobtype', + 'pools', + 'jobid', + 'status'); my $cgq=''; if (CGI::param('client_group')) { - $cgq .= " + $cgq .= " JOIN client_group_member USING (ClientId) JOIN client_group USING (client_group_id) "; @@ -2429,20 +2429,20 @@ JOIN client_group USING (client_group_id) SELECT Job.JobId AS jobid, Client.Name AS client, FileSet.FileSet AS fileset, - Job.Name AS jobname, + Job.Name AS jobname, Level AS level, StartTime AS starttime, EndTime AS endtime, Pool.Name AS poolname, JobFiles AS jobfiles, JobBytes AS jobbytes, - JobStatus AS jobstatus, + JobStatus AS jobstatus, Type AS jobtype, $self->{sql}->{SEC_TO_TIME}( $self->{sql}->{UNIX_TIMESTAMP}(EndTime) - $self->{sql}->{UNIX_TIMESTAMP}(StartTime)) AS duration, - JobErrors AS joberrors + JobErrors AS joberrors FROM Client $filter $cgq, Job LEFT JOIN Pool ON (Job.PoolId = Pool.PoolId) @@ -2456,14 +2456,14 @@ SELECT Job.JobId AS jobid, my $all = $self->dbh_selectall_hashref($query, 'jobid') ; $self->display({ Filter => $label, - ID => $cur_id++, - Jobs => - [ - sort { $a->{jobid} <=> $b->{jobid} } - values %$all - ], - }, - "display_job.tpl"); + ID => $cur_id++, + Jobs => + [ + sort { $a->{jobid} <=> $b->{jobid} } + values %$all + ], + }, + "display_job.tpl"); } # display job informations @@ -2480,14 +2480,14 @@ sub display_job_zoom my $query=" SELECT DISTINCT Job.JobId AS jobid, Client.Name AS client, - Job.Name AS jobname, + Job.Name AS jobname, FileSet.FileSet AS fileset, Level AS level, - Pool.Name AS poolname, + Pool.Name AS poolname, StartTime AS starttime, JobFiles AS jobfiles, JobBytes AS jobbytes, - JobStatus AS jobstatus, + JobStatus AS jobstatus, JobErrors AS joberrors, Type AS jobtype, $self->{sql}->{SEC_TO_TIME}( $self->{sql}->{UNIX_TIMESTAMP}(EndTime) @@ -2527,8 +2527,8 @@ sub display_job_group my ($limit, $label) = $self->get_limit(groupby => 'client_group_name', %arg); my ($where, undef) = $self->get_param('client_groups', - 'level', - 'pools'); + 'level', + 'pools'); my $filter = $self->get_client_group_filter(); my $query = " @@ -2585,20 +2585,20 @@ sub display_media my ($limit, $label) = $self->get_limit(%arg); my ($where, %elt) = $self->get_param('pools', - 'mediatypes', - 'volstatus', - 'locations'); + 'mediatypes', + 'volstatus', + 'locations'); my $arg = $self->get_form('jmedias', 'qre_media', 'expired'); if ($arg->{jmedias}) { - $where = "AND Media.VolumeName IN ($arg->{jmedias}) $where"; + $where = "AND Media.VolumeName IN ($arg->{jmedias}) $where"; } if ($arg->{qre_media}) { - $where = "AND Media.VolumeName $self->{sql}->{MATCH} $arg->{qre_media} $where"; + $where = "AND Media.VolumeName $self->{sql}->{MATCH} $arg->{qre_media} $where"; } if ($arg->{expired}) { - $where = " + $where = " AND VolStatus = 'Full' AND ( $self->{sql}->{UNIX_TIMESTAMP}(Media.LastWritten) + $self->{sql}->{TO_SEC}(Media.VolRetention) @@ -2636,11 +2636,11 @@ $limit my $all = $self->dbh_selectall_hashref($query, 'volumename') ; $self->display({ ID => $cur_id++, - Pool => $elt{pool}, - Location => $elt{location}, - Media => [ values %$all ], - }, - "display_media.tpl"); + Pool => $elt{pool}, + Location => $elt{location}, + Media => [ values %$all ], + }, + "display_media.tpl"); } sub display_allmedia @@ -2650,8 +2650,8 @@ sub display_allmedia my $pool = $self->get_form('db_pools'); foreach my $name (@{ $pool->{db_pools} }) { - CGI::param('pool', $name->{name}); - $self->display_media(); + CGI::param('pool', $name->{name}); + $self->display_media(); } } @@ -2662,7 +2662,7 @@ sub display_media_zoom my $media = $self->get_form('jmedias'); unless ($media->{jmedias}) { - return $self->error("Can't get media selection"); + return $self->error("Can't get media selection"); } my $query=" @@ -2699,16 +2699,16 @@ SELECT InChanger AS online, my $all = $self->dbh_selectall_hashref($query, 'volumename') ; foreach my $media (values %$all) { - my $mq = $self->dbh_quote($media->{volumename}); + my $mq = $self->dbh_quote($media->{volumename}); - $query = " + $query = " SELECT DISTINCT Job.JobId AS jobid, Job.Name AS name, Job.StartTime AS starttime, - Job.Type AS type, + Job.Type AS type, Job.Level AS level, Job.JobFiles AS files, - Job.JobBytes AS bytes, + Job.JobBytes AS bytes, Job.jobstatus AS status FROM Media,JobMedia,Job WHERE Media.VolumeName=$mq @@ -2716,9 +2716,9 @@ SELECT DISTINCT Job.JobId AS jobid, AND JobMedia.JobId=Job.JobId "; - my $jobs = $self->dbh_selectall_hashref($query, 'jobid') ; + my $jobs = $self->dbh_selectall_hashref($query, 'jobid') ; - $query = " + $query = " SELECT LocationLog.Date AS date, Location.Location AS location, LocationLog.Comment AS comment @@ -2727,16 +2727,16 @@ SELECT LocationLog.Date AS date, AND Media.VolumeName = $mq "; - my $logtxt = ''; - my $log = $self->dbh_selectall_arrayref($query) ; - if ($log) { - $logtxt = join("\n", map { ($_->[0] . ' ' . $_->[1] . ' ' . $_->[2])} @$log ) ; - } + my $logtxt = ''; + my $log = $self->dbh_selectall_arrayref($query) ; + if ($log) { + $logtxt = join("\n", map { ($_->[0] . ' ' . $_->[1] . ' ' . $_->[2])} @$log ) ; + } - $self->display({ jobs => [ values %$jobs ], - LocationLog => $logtxt, - %$media }, - "display_media_zoom.tpl"); + $self->display({ jobs => [ values %$jobs ], + LocationLog => $logtxt, + %$media }, + "display_media_zoom.tpl"); } } @@ -2747,7 +2747,7 @@ sub location_edit my $loc = $self->get_form('qlocation'); unless ($loc->{qlocation}) { - return $self->error("Can't get location"); + return $self->error("Can't get location"); } my $query = " @@ -2761,7 +2761,7 @@ WHERE Location.Location = $loc->{qlocation} my $row = $self->dbh_selectrow_hashref($query); $row->{enabled} = human_enabled($row->{enabled}); $self->display({ ID => $cur_id++, - %$row }, "location_edit.tpl") ; + %$row }, "location_edit.tpl") ; } sub location_save @@ -2771,13 +2771,13 @@ sub location_save my $arg = $self->get_form(qw/qlocation qnewlocation cost enabled/) ; unless ($arg->{qlocation}) { - return $self->error("Can't get location"); + return $self->error("Can't get location"); } unless ($arg->{qnewlocation}) { - return $self->error("Can't get new location name"); + return $self->error("Can't get new location name"); } unless ($arg->{cost}) { - return $self->error("Can't get new cost"); + return $self->error("Can't get new cost"); } my $enabled = from_human_enabled($arg->{enabled}); @@ -2802,7 +2802,7 @@ sub location_del my $arg = $self->get_form(qw/qlocation/) ; unless ($arg->{qlocation}) { - return $self->error("Can't get location"); + return $self->error("Can't get location"); } my $query = " @@ -2814,7 +2814,7 @@ WHERE Location = $arg->{qlocation} my $res = $self->dbh_selectrow_hashref($query); if ($res->{nb}) { - return $self->error("Sorry, the location must be empty"); + return $self->error("Sorry, the location must be empty"); } $query = " @@ -2834,11 +2834,11 @@ sub location_add my $arg = $self->get_form(qw/qlocation cost/) ; unless ($arg->{qlocation}) { - $self->display({}, "location_add.tpl"); - return 1; + $self->display({}, "location_add.tpl"); + return 1; } unless ($arg->{cost}) { - return $self->error("Can't get new cost"); + return $self->error("Can't get new cost"); } my $enabled = CGI::param('enabled') || ''; @@ -2872,8 +2872,8 @@ FROM Location my $location = $self->dbh_selectall_hashref($query, 'location'); $self->display({ ID => $cur_id++, - Locations => [ values %$location ] }, - "display_location.tpl"); + Locations => [ values %$location ] }, + "display_location.tpl"); } sub update_location @@ -2882,16 +2882,16 @@ sub update_location my $media = $self->get_selected_media_location(); unless ($media) { - return ; + return ; } my $arg = $self->get_form('db_locations', 'qnewlocation'); $self->display({ email => $self->{info}->{email_media}, - %$arg, + %$arg, media => [ values %$media ], - }, - "update_location.tpl"); + }, + "update_location.tpl"); } ########################################################### @@ -2902,7 +2902,7 @@ sub client_save my $arg = $self->get_form(qw/jclient_groups qclient/); unless ($arg->{qclient}) { - return $self->error("Can't get client name"); + return $self->error("Can't get client name"); } $self->can_do('r_group_mgnt'); @@ -2922,7 +2922,7 @@ DELETE FROM client_group_member $self->dbh_do($query); if ($arg->{jclient_groups}) { - $query = " + $query = " INSERT INTO client_group_member (client_group_id, ClientId) (SELECT client_group_id, (SELECT ClientId FROM Client $f1 @@ -2930,7 +2930,7 @@ DELETE FROM client_group_member FROM client_group $f2 WHERE client_group_name IN ($arg->{jclient_groups}) ) "; - $self->dbh_do($query); + $self->dbh_do($query); } $self->{dbh}->commit() or $self->error($self->{dbh}->errstr); @@ -2944,16 +2944,16 @@ sub groups_edit my $grp = $self->get_form(qw/qclient_group db_clients/); unless ($grp->{qclient_group}) { - $self->can_do('r_group_mgnt'); - $self->display({ ID => $cur_id++, - client_group => "''", - %$grp, - }, "groups_edit.tpl"); - return; + $self->can_do('r_group_mgnt'); + $self->display({ ID => $cur_id++, + client_group => "''", + %$grp, + }, "groups_edit.tpl"); + return; } unless ($self->cant_do('r_group_mgnt')) { - $self->can_do('r_view_group'); + $self->can_do('r_view_group'); } my $query = " @@ -2966,10 +2966,10 @@ WHERE client_group_name = $grp->{qclient_group} my $row = $self->dbh_selectall_hashref($query, "name"); $self->debug($row); $self->display({ ID => $cur_id++, - client_group => $grp->{qclient_group}, - %$grp, - client_group_member => [ values %$row]}, - "groups_edit.tpl"); + client_group => $grp->{qclient_group}, + %$grp, + client_group_member => [ values %$row]}, + "groups_edit.tpl"); } sub groups_save @@ -2983,16 +2983,16 @@ sub groups_save } if (!$arg->{qclient_group} and $arg->{qnewgroup}) { - my $query = " + my $query = " INSERT INTO client_group (client_group_name, comment) VALUES ($arg->{qnewgroup}, $arg->{qcomment}) "; - $self->dbh_do($query); - $arg->{qclient_group} = $arg->{qnewgroup}; + $self->dbh_do($query); + $arg->{qclient_group} = $arg->{qnewgroup}; } unless ($arg->{qclient_group}) { - return $self->error("Can't get groups"); + return $self->error("Can't get groups"); } $self->{dbh}->begin_work(); @@ -3007,7 +3007,7 @@ DELETE FROM client_group_member $self->dbh_do($query); if ($arg->{jclients}) { - $query = " + $query = " INSERT INTO client_group_member (ClientId, client_group_id) (SELECT ClientId, (SELECT client_group_id @@ -3016,16 +3016,16 @@ DELETE FROM client_group_member FROM Client WHERE Name IN ($arg->{jclients}) ) "; - $self->dbh_do($query); + $self->dbh_do($query); } if ($arg->{qclient_group} ne $arg->{qnewgroup}) { - $query = " + $query = " UPDATE client_group SET client_group_name = $arg->{qnewgroup}, comment = $arg->{qcomment} WHERE client_group_name = $arg->{qclient_group} "; - $self->dbh_do($query); + $self->dbh_do($query); } $self->{dbh}->commit() or $self->error($self->{dbh}->errstr); @@ -3041,7 +3041,7 @@ sub groups_del my $arg = $self->get_form(qw/qclient_group/); unless ($arg->{qclient_group}) { - return $self->error("Can't get groups"); + return $self->error("Can't get groups"); } $self->{dbh}->begin_work(); @@ -3074,20 +3074,20 @@ sub display_groups my $arg; if ($self->cant_do('r_group_mgnt')) { - $arg = $self->get_form(qw/db_client_groups filter/) ; + $arg = $self->get_form(qw/db_client_groups filter/) ; } else { - $arg = $self->get_form(qw/db_client_groups/) ; + $arg = $self->get_form(qw/db_client_groups/) ; } if ($self->{dbh}->errstr) { - return $self->error("Can't use groups with bweb, read INSTALL to enable them"); + return $self->error("Can't use groups with bweb, read INSTALL to enable them"); } $self->debug($arg); $self->display({ ID => $cur_id++, - %$arg}, - "display_groups.tpl"); + %$arg}, + "display_groups.tpl"); } ########################################################### @@ -3101,7 +3101,7 @@ sub get_roles if (!$self->{loginname}) { $self->error("Can't get your login name"); $self->display_end(); - exit 0; + exit 0; } # admin is a special user that can do everything if ($self->{loginname} eq 'admin') { @@ -3109,7 +3109,7 @@ sub get_roles } # already fill if (defined $self->{security}) { - return 1; + return 1; } $self->{security} = {}; my $u = $self->dbh_quote($self->{loginname}); @@ -3129,11 +3129,11 @@ sub get_roles exit 0; } foreach my $r (@$rows) { - $self->{security}->{$r->[1]}=1; + $self->{security}->{$r->[1]}=1; } $self->{security}->{use_acl} = $rows->[0]->[0]; if ($rows->[0]->[2] =~ /^(\w\w)$/) { - $self->{lang} = $1; + $self->{lang} = $1; } return 1; } @@ -3144,7 +3144,7 @@ sub can_view_client my $filter = $self->get_client_filter(); if (!$filter) { - return 1; + return 1; } my $cont = $self->dbh_selectrow_hashref(" SELECT 1 @@ -3167,18 +3167,18 @@ sub cant_do } # must be logged if (!$self->{loginname}) { - $self->{error} = "Can't do $action, your are not logged. " . - "Check security with your administrator"; + $self->{error} = "Can't do $action, your are not logged. " . + "Check security with your administrator"; return 1; } if (!$self->get_roles()) { - return 0; + return 0; } if (!$self->{security}->{$action}) { $self->{error} = - "$self->{loginname} sorry, but this action ($action) " . - "is not permited. " . - "Check security with your administrator"; + "$self->{loginname} sorry, but this action ($action) " . + "is not permited. " . + "Check security with your administrator"; return 1; } return 0; @@ -3201,15 +3201,15 @@ sub use_filter my ($self) = @_; if (!$self->{info}->{enable_security} or - !$self->{info}->{enable_security_acl}) + !$self->{info}->{enable_security_acl}) { - return 0 ; + return 0 ; } if ($self->get_roles()) { - return $self->{security}->{use_acl}; + return $self->{security}->{use_acl}; } else { - return 1; + return 1; } } @@ -3219,11 +3219,11 @@ sub get_client_filter my ($self, $login) = @_; my $u; if ($login) { - $u = $self->dbh_quote($login); + $u = $self->dbh_quote($login); } elsif ($self->use_filter()) { - $u = $self->dbh_quote($self->{loginname}); + $u = $self->dbh_quote($self->{loginname}); } else { - return ''; + return ''; } return " JOIN (SELECT ClientId FROM client_group_member @@ -3240,11 +3240,11 @@ sub get_client_group_filter my ($self, $login) = @_; my $u; if ($login) { - $u = $self->dbh_quote($login); + $u = $self->dbh_quote($login); } elsif ($self->use_filter()) { - $u = $self->dbh_quote($self->{loginname}); + $u = $self->dbh_quote($self->{loginname}); } else { - return ''; + return ''; } return " JOIN (SELECT client_group_id @@ -3353,7 +3353,7 @@ sub users_add # we don't quote username directly to check that it is conform my $arg = $self->get_form(qw/username qpasswd qcomment jrolenames qcreate - lang qcopy_username jclient_groups/) ; + lang qcopy_username jclient_groups/) ; if (not $arg->{qcreate}) { $arg = $self->get_form(qw/db_roles db_usernames db_client_groups/); @@ -3396,15 +3396,15 @@ sub users_add $self->grant($arg->{jrolenames}, $u); } - if ($arg->{jclient_groups}) { - $self->dbh_do(" + if ($arg->{jclient_groups}) { + $self->dbh_do(" INSERT INTO bweb_client_group_acl (client_group_id, userid) SELECT client_group_id, userid FROM client_group, bweb_user WHERE client_group_name IN ($arg->{jclient_groups}) AND username = $u "); - } + } } $self->{dbh}->commit(); @@ -3500,9 +3500,9 @@ sub get_media_max_size my $res = $self->selectrow_hashref($query); if ($res) { - return $res->{size}; + return $res->{size}; } else { - return 0; + return 0; } } @@ -3513,7 +3513,7 @@ sub update_media my $media = $self->get_form('qmedia'); unless ($media->{qmedia}) { - return $self->error("Can't get media"); + return $self->error("Can't get media"); } my $query = " @@ -3547,7 +3547,7 @@ WHERE Media.VolumeName = $media->{qmedia} my $elt = $self->get_form(qw/db_pools db_locations/); $self->display({ - %$elt, + %$elt, %$row, }, "update_media.tpl"); } @@ -3560,11 +3560,11 @@ sub save_location my $arg = $self->get_form('jmedias', 'qnewlocation') ; unless ($arg->{jmedias}) { - return $self->error("Can't get selected media"); + return $self->error("Can't get selected media"); } unless ($arg->{qnewlocation}) { - return $self->error("Can't get new location"); + return $self->error("Can't get new location"); } my $query = " @@ -3589,7 +3589,7 @@ sub location_change my $media = $self->get_selected_media_location(); unless ($media) { - return $self->error("Can't get media selection"); + return $self->error("Can't get media selection"); } my $newloc = CGI::param('newlocation'); @@ -3603,16 +3603,16 @@ sub location_change my $query; foreach my $vol (keys %$media) { - $query = " + $query = " INSERT INTO LocationLog (Date,Comment,MediaId,LocationId,NewEnabled,NewVolStatus) SELECT NOW(), $comm, Media.MediaId, Location.LocationId, $en, VolStatus FROM Media, Location WHERE Media.VolumeName = '$vol' AND Location.Location = '$media->{$vol}->{location}' "; - $self->dbh_do($query); - $self->debug($query); - $b->send_cmd("update volume=\"$vol\" enabled=$en"); + $self->dbh_do($query); + $self->debug($query); + $b->send_cmd("update volume=\"$vol\" enabled=$en"); } $b->close(); @@ -3621,12 +3621,12 @@ INSERT INTO LocationLog (Date,Comment,MediaId,LocationId,NewEnabled,NewVolStatus my $url = $q->url(-full => 1, -query=>1); $self->display({ email => $self->{info}->{email_media}, - url => $url, - newlocation => $newloc, - # [ { volumename => 'vol1' }, { volumename => 'vol2'},..] - media => [ values %$media ], - }, - "change_location.tpl"); + url => $url, + newlocation => $newloc, + # [ { volumename => 'vol1' }, { volumename => 'vol2'},..] + media => [ values %$media ], + }, + "change_location.tpl"); } @@ -3672,7 +3672,7 @@ sub _display_group_stats my $carg = $self->get_form(qw/qclient_group/); unless ($carg->{qclient_group}) { - return $self->error("Can't get group"); + return $self->error("Can't get group"); } my $jobt = $self->get_stat_table(); my ($limit, $label) = $self->get_limit(%arg); @@ -3724,14 +3724,14 @@ sub make_overview_tab my $events=[]; my $cur_name=''; for my $elt (@$ret) { - if ($cur_name and $cur_name ne $elt->[0]) { # order by name, num - push @items, { name => $cur_name, events => $events}; - $events = []; - } - $cur_name = $elt->[0]; - push @$events, - { num => $elt->[1], status => $elt->[2], - joberrors => $elt->[3], title => "$elt->[4] jobs"}; + if ($cur_name and $cur_name ne $elt->[0]) { # order by name, num + push @items, { name => $cur_name, events => $events}; + $events = []; + } + $cur_name = $elt->[0]; + push @$events, + { num => $elt->[1], status => $elt->[2], + joberrors => $elt->[3], title => "$elt->[4] jobs"}; } push @items, { name => $cur_name, events => $events}; return \@items; @@ -3742,10 +3742,10 @@ sub get_time_overview my ($self, $arg) = @_; # want since et age from get_form(); my $type = $arg->{type} || 'day'; if ($type =~ /^(day|week|hour|month)$/) { - $type = uc($1); + $type = uc($1); } else { - $arg->{type}='day'; - $type = 'DAY'; + $arg->{type}='day'; + $type = 'DAY'; } my $jobt = $self->get_stat_table(); my $stime1 = $self->{sql}->{"STARTTIME_P" . $type}; # get 1,2,3 @@ -3753,7 +3753,7 @@ sub get_time_overview my $stime2 = $self->{sql}->{"STARTTIME_" . $type}; # get 2007-01-03, 2007-01-23 my ($limit, $label) = $self->get_limit('since' => $arg->{since}, - 'age' => $arg->{age}); + 'age' => $arg->{age}); return ($stime1, $stime2, $limit, $label, $jobt); } @@ -3770,7 +3770,7 @@ sub display_overview_zoom my $arg = $self->get_form(qw/jclient_groups age since type level/); if (!$arg->{jclient_groups}) { - return $self->error("Can't get client_group selection"); + return $self->error("Can't get client_group selection"); } my ($filter2, undef) = $self->get_param(qw/level jobtype/); my ($stime1, $stime2, $limit, $label, $jobt) = $self->get_time_overview($arg); @@ -3781,7 +3781,7 @@ SELECT name, $stime1 AS num, JobStatus AS value, joberrors, nb_job FROM ( SELECT $stime2 AS date, - Client.Name AS name, + Client.Name AS name, MAX(severity) AS severity, COUNT(1) AS nb_job, SUM(JobErrors) AS joberrors @@ -3799,8 +3799,8 @@ FROM ( "; my $items = $self->make_overview_tab($q); $self->display({label => $label, - action => "job;since=$arg->{since};level=$arg->{level};type=$arg->{type};age=$arg->{age};client=", - items => $items}, "overview.tpl"); + action => "job;since=$arg->{since};level=$arg->{level};type=$arg->{type};age=$arg->{age};client=", + items => $items}, "overview.tpl"); } sub display_overview @@ -3821,7 +3821,7 @@ FROM ( client_group_name AS name, MAX(severity) AS severity, COUNT(1) AS nb_job, - SUM(JobErrors) AS joberrors + SUM(JobErrors) AS joberrors FROM $jobt AS Job JOIN client_group_member USING (ClientId) JOIN client_group USING (client_group_id) $filter3 @@ -3834,8 +3834,8 @@ FROM ( "; my $items = $self->make_overview_tab($q); $self->display({label=>$label, - action => "overview_zoom;since=$arg->{since};level=$arg->{level};type=$arg->{type};age=$arg->{age};client_group=", - items => $items}, "overview.tpl"); + action => "overview_zoom;since=$arg->{since};level=$arg->{level};type=$arg->{type};age=$arg->{age};client_group=", + items => $items}, "overview.tpl"); } @@ -3850,8 +3850,8 @@ sub display_pool my $arg = $self->get_form('jmediatypes', 'qmediatypes'); if ($arg->{jmediatypes}) { - $whereW = "WHERE MediaType IN ($arg->{jmediatypes}) "; - $whereA = "AND MediaType IN ($arg->{jmediatypes}) "; + $whereW = "WHERE MediaType IN ($arg->{jmediatypes}) "; + $whereA = "AND MediaType IN ($arg->{jmediatypes}) "; } # TODO : afficher les tailles et les dates @@ -3903,17 +3903,17 @@ GROUP BY Pool.Name; my $empty = $self->dbh_selectall_hashref($query, 'name'); foreach my $p (values %$all) { - if ($p->{volmax} > 0) { # mysql returns 0.0000 - # we remove Recycled/Purged media from pool usage - if (defined $empty->{$p->{name}}) { - $p->{voltotal} -= $empty->{$p->{name}}->{size}; - } - $p->{poolusage} = sprintf('%.2f', $p->{voltotal} * 100/ $p->{volmax}) ; - } else { - $p->{poolusage} = 0; - } - - $query = " + if ($p->{volmax} > 0) { # mysql returns 0.0000 + # we remove Recycled/Purged media from pool usage + if (defined $empty->{$p->{name}}) { + $p->{voltotal} -= $empty->{$p->{name}}->{size}; + } + $p->{poolusage} = sprintf('%.2f', $p->{voltotal} * 100/ $p->{volmax}) ; + } else { + $p->{poolusage} = 0; + } + + $query = " SELECT VolStatus AS volstatus, count(MediaId) AS nb FROM Media WHERE PoolId=$p->{poolid} @@ -3921,17 +3921,17 @@ GROUP BY Pool.Name; $whereA GROUP BY VolStatus "; - my $content = $self->dbh_selectall_hashref($query, 'volstatus'); - foreach my $t (values %$content) { - $p->{"nb_" . $t->{volstatus}} = $t->{nb} ; - } + my $content = $self->dbh_selectall_hashref($query, 'volstatus'); + foreach my $t (values %$content) { + $p->{"nb_" . $t->{volstatus}} = $t->{nb} ; + } } $self->debug($all); $self->display({ ID => $cur_id++, - MediaType => $arg->{qmediatypes}, # [ { name => type1 } , { name => type2 } ] - Pools => [ values %$all ]}, - "display_pool.tpl"); + MediaType => $arg->{qmediatypes}, # [ { name => type1 } , { name => type2 } ] + Pools => [ values %$all ]}, + "display_pool.tpl"); } # With this function, we get an estimation of next jobfiles/jobbytes count @@ -3944,20 +3944,20 @@ sub get_estimate_query my $query; if ($self->dbh_is_mysql()) { # mysql doesn't have statistics functions - $query = " + $query = " SELECT jobname AS jobname, 0.1 AS corr_jobbytes, AVG(jobbytes) AS jobbytes, COUNT(1) AS nb_jobbytes "; } else { - # postgresql have functions that permit to handle lineal regression - # in y=ax + b - # REGR_SLOPE(Y,X) = get x - # REGR_INTERCEPT(Y,X) = get b - # and we need y when x=now() - # CORR gives the correlation - # (TODO: display progress bar only if CORR > 0.8) - my $now = scalar(time); - $query = " + # postgresql have functions that permit to handle lineal regression + # in y=ax + b + # REGR_SLOPE(Y,X) = get x + # REGR_INTERCEPT(Y,X) = get b + # and we need y when x=now() + # CORR gives the correlation + # (TODO: display progress bar only if CORR > 0.8) + my $now = scalar(time); + $query = " SELECT temp.jobname AS jobname, CORR(jobbytes,jobtdate) AS corr_jobbytes, ($now*REGR_SLOPE(jobbytes,jobtdate) @@ -3973,7 +3973,7 @@ SELECT temp.jobname AS jobname, # +----------------- +------------------- my $filter2=''; if ($level eq 'D') { - $filter2 = " + $filter2 = " AND Job.StartTime > ( SELECT StartTime FROM Job @@ -4001,8 +4001,8 @@ FROM ( "; if ($mode eq 'jobfiles') { - $query =~ s/jobbytes/jobfiles/g; - $query =~ s/JobBytes/JobFiles/g; + $query =~ s/jobbytes/jobfiles/g; + $query =~ s/JobBytes/JobFiles/g; } return $query; } @@ -4029,33 +4029,33 @@ WHERE Job.JobId = $arg->{jobid} my $row = $self->dbh_selectrow_hashref($query); if ($row) { - $arg->{client} = $row->{name}; + $arg->{client} = $row->{name}; } else { - return $self->error("Can't get client"); + return $self->error("Can't get client"); } if ($row->{type} eq 'B') { - # for jobfiles, we use only last Full backup. status client= returns - # all files that have been checked - my $query1 = $self->get_estimate_query('jobfiles', $row->{jobname}, 'F'); - my $query2 = $self->get_estimate_query('jobbytes', - $row->{jobname}, $row->{level}); - - # LEFT JOIN because we always have a previous Full - $query = " + # for jobfiles, we use only last Full backup. status client= returns + # all files that have been checked + my $query1 = $self->get_estimate_query('jobfiles', $row->{jobname}, 'F'); + my $query2 = $self->get_estimate_query('jobbytes', + $row->{jobname}, $row->{level}); + + # LEFT JOIN because we always have a previous Full + $query = " SELECT corr_jobbytes, jobbytes, corr_jobfiles, jobfiles FROM ($query1) AS A LEFT JOIN ($query2) AS B USING (jobname) "; - $row = $self->dbh_selectrow_hashref($query); + $row = $self->dbh_selectrow_hashref($query); - if (!$row) { - $row->{jobbytes} = $row->{jobfiles} = 0; - } + if (!$row) { + $row->{jobbytes} = $row->{jobfiles} = 0; + } } my $cli = new Bweb::Client(name => $arg->{client}); $cli->display_running_job($self, $arg->{jobid}, $row); if ($arg->{jobid}) { - $self->get_job_log(); + $self->get_job_log(); } } @@ -4082,13 +4082,13 @@ $self->{sql}->{SEC_TO_TIME}( $self->{sql}->{UNIX_TIMESTAMP}(NOW()) FROM Job INNER JOIN Client USING (ClientId) $filter WHERE JobStatus IN ('C','R','B','e','D','F','S','m','M','s','j','c','d','t','p') -"; +"; my $all = $self->dbh_selectall_hashref($query, 'jobid') ; $self->display({ ID => $cur_id++, - display_action => $display_action, - Jobs => [ values %$all ]}, - "running_job.tpl") ; + display_action => $display_action, + Jobs => [ values %$all ]}, + "running_job.tpl") ; } sub display_group_stats @@ -4142,9 +4142,9 @@ SELECT client_group_name AS name, nb_byte, nb_file, nb_job, nb_err, nb_resto $self->debug($all); $self->display({ ID => $cur_id++, - label => $label, - Stats => [ values %$all ]}, - "display_stats.tpl") ; + label => $label, + Stats => [ values %$all ]}, + "display_stats.tpl") ; } # return the autochanger list to update @@ -4157,7 +4157,7 @@ sub eject_media my $arg = $self->get_form('jmedias'); unless ($arg->{jmedias}) { - return $self->error("Can't get media selection"); + return $self->error("Can't get media selection"); } my $query = " @@ -4174,21 +4174,21 @@ WHERE Media.VolumeName IN ($arg->{jmedias}) my $all = $self->dbh_selectall_hashref($query, 'volumename'); foreach my $vol (values %$all) { - my $a = $self->ach_get($vol->{location}); - next unless ($a) ; - $ret{$vol->{location}} = 1; - - unless ($a->{have_status}) { - $a->status(); - $a->{have_status} = 1; - } - # TODO: set enabled - print "eject $vol->{volumename} from $vol->{storage} : "; - if ($a->send_to_io($vol->{slot})) { - print "ok
"; - } else { - print "err
"; - } + my $a = $self->ach_get($vol->{location}); + next unless ($a) ; + $ret{$vol->{location}} = 1; + + unless ($a->{have_status}) { + $a->status(); + $a->{have_status} = 1; + } + # TODO: set enabled + print "eject $vol->{volumename} from $vol->{storage} : "; + if ($a->send_to_io($vol->{slot})) { + print "ok
"; + } else { + print "err
"; + } } return keys %ret; } @@ -4198,8 +4198,8 @@ sub move_email my ($self) = @_; my ($to, $subject, $content) = (CGI::param('email'), - CGI::param('subject'), - CGI::param('content')); + CGI::param('subject'), + CGI::param('content')); $to =~ s/[^\w\d\.\@<>,]//; $subject =~ s/[^\w\d\.\[\]]/ /; @@ -4233,18 +4233,18 @@ sub ach_get my ($self, $name) = @_; unless ($name) { - return $self->error("Can't get your autochanger name ach"); + return $self->error("Can't get your autochanger name ach"); } unless ($self->{info}->{ach_list}) { - return $self->error("Could not find any autochanger"); + return $self->error("Could not find any autochanger"); } my $a = $self->{info}->{ach_list}->{$name}; unless ($a) { - $self->error("Can't get your autochanger $name from your ach_list"); - return undef; + $self->error("Can't get your autochanger $name from your ach_list"); + return undef; } $a->{bweb} = $self; @@ -4272,17 +4272,17 @@ sub ach_edit my $arg = $self->get_form('ach'); if (!$arg->{ach} - or !$self->{info}->{ach_list} - or !$self->{info}->{ach_list}->{$arg->{ach}}) + or !$self->{info}->{ach_list} + or !$self->{info}->{ach_list}->{$arg->{ach}}) { - return $self->error("Can't get autochanger name"); + return $self->error("Can't get autochanger name"); } my $ach = $self->{info}->{ach_list}->{$arg->{ach}}; my $i=0; $ach->{drives} = - [ map { { name => $_, index => $i++ } } @{$ach->{drive_name}} ] ; + [ map { { name => $_, index => $i++ } } @{$ach->{drive_name}} ] ; my $b = $self->get_bconsole(); @@ -4304,10 +4304,10 @@ sub ach_del my $arg = $self->get_form('ach'); if (!$arg->{ach} - or !$self->{info}->{ach_list} - or !$self->{info}->{ach_list}->{$arg->{ach}}) + or !$self->{info}->{ach_list} + or !$self->{info}->{ach_list}->{$arg->{ach}}) { - return $self->error("Can't get autochanger name"); + return $self->error("Can't get autochanger name"); } delete $self->{info}->{ach_list}->{$arg->{ach}} ; @@ -4327,34 +4327,34 @@ sub ach_add my @storages = $b->list_storage() ; unless ($arg->{ach}) { - $arg->{devices} = [ map { { name => $_ } } @storages ]; - return $self->display($arg, "ach_add.tpl"); + $arg->{devices} = [ map { { name => $_ } } @storages ]; + return $self->display($arg, "ach_add.tpl"); } my @drives ; foreach my $drive (CGI::param('drives')) { - unless (grep(/^$drive$/,@storages)) { - return $self->error("Can't find $drive in storage list"); - } + unless (grep(/^$drive$/,@storages)) { + return $self->error("Can't find $drive in storage list"); + } - my $index = CGI::param("index_$drive"); - unless (defined $index and $index =~ /^(\d+)$/) { - return $self->error("Can't get $drive index"); - } + my $index = CGI::param("index_$drive"); + unless (defined $index and $index =~ /^(\d+)$/) { + return $self->error("Can't get $drive index"); + } - $drives[$index] = $drive; + $drives[$index] = $drive; } unless (@drives) { - return $self->error("Can't get drives from Autochanger"); + return $self->error("Can't get drives from Autochanger"); } my $a = new Bweb::Autochanger(name => $arg->{ach}, - precmd => $arg->{precmd}, - drive_name => \@drives, - device => $arg->{device}, - mtxcmd => $arg->{mtxcmd}); + precmd => $arg->{precmd}, + drive_name => \@drives, + device => $arg->{device}, + mtxcmd => $arg->{mtxcmd}); $self->ach_register($a) ; @@ -4369,15 +4369,15 @@ sub delete my $arg = $self->get_form('jobid'); if ($arg->{jobid}) { - my $b = $self->get_bconsole(); - my $ret = $b->send_cmd("delete jobid=\"$arg->{jobid}\""); + my $b = $self->get_bconsole(); + my $ret = $b->send_cmd("delete jobid=\"$arg->{jobid}\""); - $self->display({ - content => $ret, - title => "Delete a job ", - name => "delete jobid=$arg->{jobid}", + $self->display({ + content => $ret, + title => "Delete a job ", + name => "delete jobid=$arg->{jobid}", id => $cur_id++, - }, "command.tpl"); + }, "command.tpl"); } } @@ -4387,28 +4387,28 @@ sub do_update_media $self->can_do('r_media_mgnt'); my $arg = $self->get_form(qw/media volstatus inchanger pool - slot volretention voluseduration - maxvoljobs maxvolfiles maxvolbytes - qcomment poolrecycle enabled - /); + slot volretention voluseduration + maxvoljobs maxvolfiles maxvolbytes + qcomment poolrecycle enabled + /); unless ($arg->{media}) { - return $self->error("Can't find media selection"); + return $self->error("Can't find media selection"); } my $update = "update volume=$arg->{media} "; if ($arg->{volstatus}) { - $update .= " volstatus=$arg->{volstatus} "; + $update .= " volstatus=$arg->{volstatus} "; } if ($arg->{inchanger}) { - $update .= " inchanger=yes " ; - if ($arg->{slot}) { - $update .= " slot=$arg->{slot} "; - } + $update .= " inchanger=yes " ; + if ($arg->{slot}) { + $update .= " slot=$arg->{slot} "; + } } else { - $update .= " slot=0 inchanger=no "; + $update .= " slot=0 inchanger=no "; } if ($arg->{enabled}) { @@ -4416,41 +4416,41 @@ sub do_update_media } if ($arg->{pool}) { - $update .= " pool=$arg->{pool} " ; + $update .= " pool=$arg->{pool} " ; } if (defined $arg->{volretention}) { - $update .= " volretention=\"$arg->{volretention}\" " ; + $update .= " volretention=\"$arg->{volretention}\" " ; } if (defined $arg->{voluseduration}) { - $update .= " voluse=\"$arg->{voluseduration}\" " ; + $update .= " voluse=\"$arg->{voluseduration}\" " ; } if (defined $arg->{maxvoljobs}) { - $update .= " maxvoljobs=$arg->{maxvoljobs} " ; + $update .= " maxvoljobs=$arg->{maxvoljobs} " ; } if (defined $arg->{maxvolfiles}) { - $update .= " maxvolfiles=$arg->{maxvolfiles} " ; + $update .= " maxvolfiles=$arg->{maxvolfiles} " ; } if (defined $arg->{maxvolbytes}) { - $update .= " maxvolbytes=$arg->{maxvolbytes} " ; + $update .= " maxvolbytes=$arg->{maxvolbytes} " ; } if (defined $arg->{poolrecycle}) { - $update .= " recyclepool=\"$arg->{poolrecycle}\" " ; + $update .= " recyclepool=\"$arg->{poolrecycle}\" " ; } my $b = $self->get_bconsole(); $self->display({ - content => $b->send_cmd($update), - title => "Update a volume ", - name => $update, + content => $b->send_cmd($update), + title => "Update a volume ", + name => $update, id => $cur_id++, - }, "command.tpl"); + }, "command.tpl"); my @q; @@ -4458,11 +4458,11 @@ sub do_update_media my $loc = CGI::param('location') || ''; if ($loc) { - $loc = $self->dbh_quote($loc); # is checked by db - push @q, "LocationId=(SELECT LocationId FROM Location WHERE Location=$loc)"; + $loc = $self->dbh_quote($loc); # is checked by db + push @q, "LocationId=(SELECT LocationId FROM Location WHERE Location=$loc)"; } if (!$arg->{qcomment}) { - $arg->{qcomment} = "''"; + $arg->{qcomment} = "''"; } push @q, "Comment=$arg->{qcomment}"; @@ -4485,21 +4485,21 @@ sub update_slots my $ach = CGI::param('ach') ; $ach = $self->ach_get($ach); unless ($ach) { - return $self->error("Bad autochanger name"); + return $self->error("Bad autochanger name"); } $self->display({ - title => "Scanning autochanger content ", - name => "update slots", + title => "Scanning autochanger content ", + name => "update slots", notail => 1, id => $cur_id++, - }, "command.tpl"); + }, "command.tpl"); my $b = new Bconsole(pref => $self->{info},timeout => 60,log_stdout => 1); $b->update_slots($ach->{name}); $self->display({ nohead => 1, - }, "command.tpl"); + }, "command.tpl"); } sub get_job_log @@ -4509,7 +4509,7 @@ sub get_job_log my $arg = $self->get_form('jobid', 'limit', 'offset'); unless ($arg->{jobid}) { - return $self->error("Can't get jobid"); + return $self->error("Can't get jobid"); } if ($arg->{limit} == 100) { @@ -4527,20 +4527,20 @@ SELECT Job.Name as name, Client.Name as clientname my $row = $self->dbh_selectrow_hashref($query); unless ($row) { - return $self->error("Can't find $arg->{jobid} in catalog"); + return $self->error("Can't find $arg->{jobid} in catalog"); } # display only Error and Warning messages $filter = ''; if (CGI::param('error')) { - $filter = " AND LogText $self->{sql}->{MATCH} 'Error|Warning|ERR=' "; + $filter = " AND LogText $self->{sql}->{MATCH} 'Error|Warning|ERR=' "; } my $logtext; if (CGI::param('time') || $self->{info}->{display_log_time}) { - $logtext = $self->dbh_strcat('Time', " ' ' ", 'LogText'); + $logtext = $self->dbh_strcat('Time', " ' ' ", 'LogText'); } else { - $logtext = 'LogText'; + $logtext = 'LogText'; } $query = " @@ -4564,17 +4564,17 @@ SELECT count(1) AS nbline, my $log = $self->dbh_selectrow_hashref($query); unless ($log) { - return $self->error("Can't get log for jobid $arg->{jobid}"); + return $self->error("Can't get log for jobid $arg->{jobid}"); } $log->{logtxt} =~ s/\0//g; $self->display({ lines=> $log->{logtxt}, - nbline => $log->{nbline}, - jobid => $arg->{jobid}, - name => $row->{name}, - client => $row->{clientname}, - offset => $arg->{offset}, - limit => $arg->{limit}, - }, 'display_log.tpl'); + nbline => $log->{nbline}, + jobid => $arg->{jobid}, + name => $row->{name}, + client => $row->{clientname}, + offset => $arg->{offset}, + limit => $arg->{limit}, + }, 'display_log.tpl'); } sub cancel_future_job @@ -4622,8 +4622,8 @@ INSERT INTO $jobtable ) "); $self->display({ Filter => "Dummy record for $jname", - ID => 1, - Jobs => + ID => 1, + Jobs => [{ jobid => 0, client => $arg->{client}, jobname => $arg->{job}, @@ -4636,8 +4636,8 @@ INSERT INTO $jobtable joberrors => 0, jobstatus => 'A', }] - }, - "display_job.tpl"); + }, + "display_job.tpl"); } sub add_media @@ -4648,19 +4648,19 @@ sub add_media my $b = $self->get_bconsole(); if (!$arg->{storage} || !$arg->{pool} || not defined $arg->{nb} || !$arg->{media} || !$arg->{offset}) { - CGI::param(offset => 0); - $arg = $self->get_form('db_pools'); - $arg->{storage} = [ map { { name => $_ } }$b->list_storage()]; - $self->display($arg, 'add_media.tpl'); - return 1; + CGI::param(offset => 0); + $arg = $self->get_form('db_pools'); + $arg->{storage} = [ map { { name => $_ } }$b->list_storage()]; + $self->display($arg, 'add_media.tpl'); + return 1; } my $cmd; if ($arg->{nb} > 0) { - $arg->{offset} = $arg->{offset}?$arg->{offset}:1; - $cmd = "add pool=\"$arg->{pool}\" storage=\"$arg->{storage}\"\n$arg->{nb}\n$arg->{media}\n$arg->{offset}\n"; + $arg->{offset} = $arg->{offset}?$arg->{offset}:1; + $cmd = "add pool=\"$arg->{pool}\" storage=\"$arg->{storage}\"\n$arg->{nb}\n$arg->{media}\n$arg->{offset}\n"; } else { - $cmd = "add pool=\"$arg->{pool}\" storage=\"$arg->{storage}\"\n0\n$arg->{media}\n"; + $cmd = "add pool=\"$arg->{pool}\" storage=\"$arg->{storage}\"\n0\n$arg->{media}\n"; } $b->connect(); $b->send($cmd); @@ -4679,35 +4679,35 @@ sub label_barcodes my $arg = $self->get_form('ach', 'slots', 'drive', 'pool'); unless ($arg->{ach}) { - return $self->error("Can't find autochanger name"); + return $self->error("Can't find autochanger name"); } my $a = $self->ach_get($arg->{ach}); unless ($a) { - return $self->error("Can't find autochanger name in configuration"); + return $self->error("Can't find autochanger name in configuration"); } my $storage = $a->get_drive_name($arg->{drive}); unless ($storage) { - return $self->error("Can't get your drive name"); + return $self->error("Can't get your drive name"); } my $slots = ''; my $slots_sql = ''; my $t = 300 ; if ($arg->{slots}) { - $slots = join(",", @{ $arg->{slots} }); - $slots_sql = " AND Slot IN ($slots) "; - $t += 60*scalar( @{ $arg->{slots} }) ; + $slots = join(",", @{ $arg->{slots} }); + $slots_sql = " AND Slot IN ($slots) "; + $t += 60*scalar( @{ $arg->{slots} }) ; } my $pool = $arg->{pool} || 'Scratch'; my $b = new Bconsole(pref => $self->{info}, timeout => $t,log_stdout => 1); print "

This command can take long time, be patient...

"; print "
" ;
     $b->label_barcodes(storage => $storage,
-		       drive => $arg->{drive},
-		       pool  => $pool,
-		       slots => $slots) ;
+                       drive => $arg->{drive},
+                       pool  => $pool,
+                       slots => $slots) ;
     $b->close();
     print "
"; @@ -4731,19 +4731,19 @@ sub purge my @volume = CGI::param('media'); unless (@volume) { - return $self->error("Can't get media selection"); + return $self->error("Can't get media selection"); } my $b = new Bconsole(pref => $self->{info}, timeout => 60); foreach my $v (@volume) { - $self->display({ - content => $b->purge_volume($v), - title => "Purge media", - name => "purge volume=$v", + $self->display({ + content => $b->purge_volume($v), + title => "Purge media", + name => "purge volume=$v", id => $cur_id++, - }, "command.tpl"); - } + }, "command.tpl"); + } $b->close(); } @@ -4754,18 +4754,18 @@ sub prune my @volume = CGI::param('media'); unless (@volume) { - return $self->error("Can't get media selection"); + return $self->error("Can't get media selection"); } my $b = new Bconsole(pref => $self->{info}, timeout => 60); foreach my $v (@volume) { - $self->display({ - content => $b->prune_volume($v), - title => "Prune volume", - name => "prune volume=$v", + $self->display({ + content => $b->prune_volume($v), + title => "Prune volume", + name => "prune volume=$v", id => $cur_id++, - }, "command.tpl"); + }, "command.tpl"); } $b->close(); } @@ -4777,16 +4777,16 @@ sub cancel_job my $arg = $self->get_form('jobid'); unless ($arg->{jobid}) { - return $self->error("Can't get jobid"); + return $self->error("Can't get jobid"); } my $b = $self->get_bconsole(); $self->display({ - content => $b->cancel($arg->{jobid}), - title => "Cancel job", - name => "cancel jobid=$arg->{jobid}", + content => $b->cancel($arg->{jobid}), + title => "Cancel job", + name => "cancel jobid=$arg->{jobid}", id => $cur_id++, - }, "command.tpl"); + }, "command.tpl"); } sub fileset_view @@ -4797,13 +4797,13 @@ sub fileset_view my $arg = $self->get_form('fileset'); if ($arg->{fileset}) { - my $b = $self->get_bconsole(); - my $ret = $b->get_fileset($arg->{fileset}); - $self->display({ fileset => $arg->{fileset}, - %$ret, - }, "fileset_view.tpl"); + my $b = $self->get_bconsole(); + my $ret = $b->get_fileset($arg->{fileset}); + $self->display({ fileset => $arg->{fileset}, + %$ret, + }, "fileset_view.tpl"); } else { - $self->error("Can't get fileset name"); + $self->error("Can't get fileset name"); } } @@ -4817,8 +4817,8 @@ sub director_show_sched my $ret = $b->director_get_sched( $arg->{days} ); $self->display({ - id => $cur_id++, - list => $ret, + id => $cur_id++, + list => $ret, }, "scheduled_job.tpl"); } @@ -4829,24 +4829,24 @@ sub enable_disable_job my $arg = $self->get_form('job'); if (!$arg->{job}) { - return $self->error("Can't find job name"); + return $self->error("Can't find job name"); } my $b = $self->get_bconsole(); my $cmd; if ($what) { - $cmd = "enable"; + $cmd = "enable"; } else { - $cmd = "disable"; + $cmd = "disable"; } $self->display({ - content => $b->send_cmd("$cmd job=\"$arg->{job}\""), - title => "$cmd $arg->{job}", - name => "$cmd job=\"$arg->{job}\"", + content => $b->send_cmd("$cmd job=\"$arg->{job}\""), + title => "$cmd $arg->{job}", + name => "$cmd job=\"$arg->{job}\"", id => $cur_id++, - }, "command.tpl"); + }, "command.tpl"); } sub get_bconsole @@ -4863,18 +4863,18 @@ sub cmd_storage my $b = $self->get_bconsole(); if ($arg->{storage} and $arg->{storage_cmd}) { - my $cmd = "$arg->{storage_cmd} storage=\"$arg->{storage}\" drive=$arg->{drive}"; - my $ret = $b->send_cmd($cmd); - - $self->display({ - content => $ret, - title => "Storage ", - name => $cmd, - id => $cur_id++, - }, "command.tpl"); + my $cmd = "$arg->{storage_cmd} storage=\"$arg->{storage}\" drive=$arg->{drive}"; + my $ret = $b->send_cmd($cmd); + + $self->display({ + content => $ret, + title => "Storage ", + name => $cmd, + id => $cur_id++, + }, "command.tpl"); } else { - my $storages= [ map { { name => $_ } } $b->list_storage()]; - $self->display({ storage => $storages}, "cmd_storage.tpl"); + my $storages= [ map { { name => $_ } } $b->list_storage()]; + $self->display({ storage => $storages}, "cmd_storage.tpl"); } } @@ -4898,20 +4898,20 @@ sub run_parse_job $self->debug($ouput); foreach my $l (split(/\r?\n/, $ouput)) { $self->debug($l); - if ($l =~ /(\w+): name=([\w\d\.\s-]+?)(\s+\w+=.+)?$/) { - $arg{$1} = $2; - $l = $3 - if ($3) ; - } - - if (my @l = $l =~ /(\w+)=([\w\d*]+)/g) { - %arg = (%arg, @l); - } + if ($l =~ /(\w+): name=([\w\d\.\s-]+?)(\s+\w+=.+)?$/) { + $arg{$1} = $2; + $l = $3 + if ($3) ; + } + + if (my @l = $l =~ /(\w+)=([\w\d*]+)/g) { + %arg = (%arg, @l); + } } my %lowcase ; foreach my $k (keys %arg) { - $lowcase{lc($k)} = $arg{$k} ; + $lowcase{lc($k)} = $arg{$k} ; } $self->debug(\%lowcase); return \%lowcase; @@ -4934,15 +4934,15 @@ sub run_job_mod my $attr = $self->run_parse_job($info); if (!$arg->{pool} and $arg->{media}) { - my $r = $self->dbh_selectrow_hashref(" + my $r = $self->dbh_selectrow_hashref(" SELECT Pool.Name AS name FROM Media JOIN Pool USING (PoolId) WHERE Media.VolumeName = '$arg->{media}' AND Pool.Name != 'Scratch' "); - if ($r) { - $arg->{pool} = $r->{name}; - } + if ($r) { + $arg->{pool} = $r->{name}; + } } my %job_opt = (%$attr, %$arg); @@ -4955,12 +4955,12 @@ SELECT Pool.Name AS name my $storages= [ map { { name => $_ } }$b->list_storage()]; $self->display({ - jobs => $jobs, - pools => $pools, - clients => $clients, - filesets => $filesets, - storages => $storages, - %job_opt, + jobs => $jobs, + pools => $pools, + clients => $clients, + filesets => $filesets, + storages => $storages, + %job_opt, }, "run_job_mod.tpl"); } @@ -4974,7 +4974,7 @@ sub run_job my $jobs = [ map {{ name => $_ }} $b->list_job() ]; $self->display({ - jobs => $jobs, + jobs => $jobs, }, "run_job.tpl"); } @@ -4994,14 +4994,14 @@ sub run_job_now } my $jobid = $b->run(job => $arg->{job}, - client => $arg->{client}, - priority => $arg->{priority}, - level => $arg->{level}, - storage => $arg->{storage}, - pool => $arg->{pool}, - fileset => $arg->{fileset}, - when => $arg->{when}, - ); + client => $arg->{client}, + priority => $arg->{priority}, + level => $arg->{level}, + storage => $arg->{storage}, + pool => $arg->{pool}, + fileset => $arg->{fileset}, + when => $arg->{when}, + ); print $b->{error}; @@ -5014,7 +5014,7 @@ sub display_next_job my $arg = $self->get_form(qw/job begin end/); if (!$arg->{job}) { - return $self->error("Can't get job name"); + return $self->error("Can't get job name"); } my $b = $self->get_bconsole(); @@ -5023,21 +5023,21 @@ sub display_next_job my $attr = $self->run_parse_job($job); if (!$attr->{schedule}) { - return $self->error("Can't get $arg->{job} schedule"); + return $self->error("Can't get $arg->{job} schedule"); } my $jpool=$attr->{pool} || ''; my $sched = new Bweb::Sched(bconsole => $b, name => $attr->{schedule}, - begin => $arg->{begin}, end => $arg->{end}); + begin => $arg->{begin}, end => $arg->{end}); my $ss = $sched->get_scheds($attr->{schedule}); my @ret; foreach my $s (@$ss) { - my $level = $sched->get_level($s); - my $pool = $sched->get_pool($s) || $jpool; - my $evt = $sched->get_event($s); - push @ret, map { "$_ : $pool ($level)\n" } @$evt; + my $level = $sched->get_level($s); + my $pool = $sched->get_pool($s) || $jpool; + my $evt = $sched->get_event($s); + push @ret, map { "$_ : $pool ($level)\n" } @$evt; } print "$arg->{job}:
", sort @ret, "

"; @@ -5050,11 +5050,11 @@ sub get_higher_level { my ($self, $level) = @_; if ($level eq 'F') { - return "'F'"; + return "'F'"; } elsif ($level eq 'D') { - return "'F', 'D'"; + return "'F', 'D'"; } elsif ($level eq 'I') { - return "'F', 'D', 'I'"; + return "'F', 'D', 'I'"; } return "''"; } @@ -5070,17 +5070,17 @@ sub check_job my @ret; foreach my $s (@$sch) { - my $pool; - if ($type eq 'B') { # we take the pool only for backup job - $pool = $sched->get_pool($s) || $job_pool; - } - my $level = $sched->get_level($s); - my ($l) = ($level =~ m/^(.)/); # we keep the first letter - $l = $self->get_higher_level($l); - my $evts = $sched->get_event($s); - my $end = $sched->{end}; # this backup must have start before the next one - foreach my $evt (reverse @$evts) { - my $all = $self->dbh_selectrow_hashref(" + my $pool; + if ($type eq 'B') { # we take the pool only for backup job + $pool = $sched->get_pool($s) || $job_pool; + } + my $level = $sched->get_level($s); + my ($l) = ($level =~ m/^(.)/); # we keep the first letter + $l = $self->get_higher_level($l); + my $evts = $sched->get_event($s); + my $end = $sched->{end}; # this backup must have start before the next one + foreach my $evt (reverse @$evts) { + my $all = $self->dbh_selectrow_hashref(" SELECT 1 FROM Job JOIN Client USING (ClientId) LEFT JOIN Pool USING (PoolId) @@ -5093,17 +5093,17 @@ sub check_job " . ($pool?" AND Pool.Name = '$pool' ":'') . " AND Client.Name = '$client' LIMIT 1 -"); - if ($all) { -# print "ok $job "; - } else { - push @{$self->{tmp}}, {date => $evt, level => $level, - type => 'Backup', name => $job, - pool => $pool, volume => $pool, - client => $client}; - } - $end = $evt; - } +"); + if ($all) { +# print "ok $job "; + } else { + push @{$self->{tmp}}, {date => $evt, level => $level, + type => 'Backup', name => $job, + pool => $pool, volume => $pool, + client => $client}; + } + $end = $evt; + } } } @@ -5113,37 +5113,37 @@ sub display_missing_job my $arg = $self->get_form(qw/begin end age/); if (!$arg->{begin}) { # TODO: change this - $arg->{begin} = strftime('%F %T', localtime(time - $arg->{age})); + $arg->{begin} = strftime('%F %T', localtime(time - $arg->{age})); } if (!$arg->{end}) { - $arg->{end} = strftime('%F %T', localtime(time)); + $arg->{end} = strftime('%F %T', localtime(time)); } - $self->{tmp} = []; # check_job use this for result + $self->{tmp} = []; # check_job use this for result my $bconsole = $self->get_bconsole(); my $sched = new Bweb::Sched(bconsole => $bconsole, - begin => $arg->{begin}, - end => $arg->{end}); + begin => $arg->{begin}, + end => $arg->{end}); my $job = $bconsole->send_cmd("show job"); my ($jname, $jsched, $jclient, $jpool, $jtype); foreach my $j (split(/\r?\n/, $job)) { - if ($j =~ /Job: name=([\w\d\-]+?) JobType=(\d+)/i) { - if ($jname and $jsched) { - $self->check_job($sched, $jsched, $jname, - $jpool, $jclient, $jtype); - } - $jname = $1; - $jtype = chr($2); - $jclient = $jpool = $jsched = undef; - } elsif ($j =~ /Client: name=(.+?) address=/i) { - $jclient = $1; - } elsif ($j =~ /Pool: name=([\w\d\-]+) PoolType=/i) { - $jpool = $1; - } elsif ($j =~ /Schedule: name=([\w\d\-]+)/i) { - $jsched = $1; - } + if ($j =~ /Job: name=([\w\d\-]+?) JobType=(\d+)/i) { + if ($jname and $jsched) { + $self->check_job($sched, $jsched, $jname, + $jpool, $jclient, $jtype); + } + $jname = $1; + $jtype = chr($2); + $jclient = $jpool = $jsched = undef; + } elsif ($j =~ /Client: name=(.+?) address=/i) { + $jclient = $1; + } elsif ($j =~ /Pool: name=([\w\d\-]+) PoolType=/i) { + $jpool = $1; + } elsif ($j =~ /Schedule: name=([\w\d\-]+)/i) { + $jsched = $1; + } } $self->display({ id => $cur_id++,