]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bweb/lib/Bweb.pm
ebl fix javascript
[bacula/bacula] / gui / bweb / lib / Bweb.pm
index e62f749f7f60cf527bf3820840647793bba6c28e..d04a8b9e23e845db155fee31f53eeca1b12914f6 100644 (file)
@@ -53,7 +53,6 @@ package Bweb::Gui;
 use HTML::Template;
 our $template_dir='/usr/share/bweb/tpl';
 
-
 =head1 FUNCTION
 
     new - creation a of new Bweb object
@@ -208,6 +207,7 @@ use CGI;
 our %k_re = ( dbi      => qr/^(dbi:(Pg|mysql):(?:\w+=[\w\d\.-]+;?)+)$/i,
              user     => qr/^([\w\d\.-]+)$/i,
              password => qr/^(.*)$/i,
+             fv_write_path => qr!^([/\w\d\.-]*)$!,
              template_dir => qr!^([/\w\d\.-]+)$!,
              debug    => qr/^(on)?$/,
              email_media => qr/^([\w\d\.-]+@[\d\w\.-]+)$/,
@@ -233,7 +233,7 @@ sub load
 
     unless (open(FP, $self->{config_file}))
     {
-       return $self->error("$self->{config_file} : $!");
+       return $self->error("can't load config_file $self->{config_file} : $!");
     }
     my $f=''; my $tmpbuffer;
     while(read FP,$tmpbuffer,4096)
@@ -1018,6 +1018,8 @@ use base q/Bweb::Gui/;
 use DBI;
 use POSIX qw/strftime/;
 
+our $config_file='/etc/bacula/bweb.conf';
+
 our $cur_id=0;
 
 =head1 VARIABLE
@@ -1182,7 +1184,7 @@ sub connect_db
                                    $self->{info}->{user},
                                    $self->{info}->{password});
 
-       print "Can't connect to your database, see error log\n"
+       $self->error("Can't connect to your database:\n$DBI::errstr\n")
            unless ($self->{dbh});
 
        $self->{dbh}->{FetchHashKeyName} = 'NAME_lc';
@@ -1436,6 +1438,13 @@ sub get_form
        }
     }
 
+    if ($what{when}) {
+       my $when = CGI::param('when') || '';
+       if ($when =~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})$/) {
+           $ret{when} = $1;
+       }
+    }
+
     if ($what{db_clients}) {
        my $query = "
 SELECT Client.Name as clientname
@@ -1833,7 +1842,7 @@ sub get_param
 
     if ($elt{volstatus}) {
        my $status = CGI::param('volstatus') || '';
-       if ($status =~ /^(\w)$/) {
+       if ($status =~ /^(\w+)$/) {
            $ret{status} = $1;
            $limit .= "AND Media.VolStatus = '$1' ";            
        }
@@ -1903,6 +1912,7 @@ sub display_job
                                          'level',
                                          'filesets',
                                          'jobtype',
+                                         'pools',
                                          'jobid',
                                          'status');
 
@@ -2858,28 +2868,23 @@ sub do_update_media
        $update .= " pool=$arg->{pool} " ;
     }
 
-    $arg->{volretention} ||= 0 ; 
-    if ($arg->{volretention}) {
+    if (defined $arg->{volretention}) {
        $update .= " volretention=\"$arg->{volretention}\" " ;
     }
 
-    $arg->{voluseduration} ||= 0 ; 
-    if ($arg->{voluseduration}) {
+    if (defined $arg->{voluseduration}) {
        $update .= " voluse=\"$arg->{voluseduration}\" " ;
     }
 
-    $arg->{maxvoljobs} ||= 0;
-    if ($arg->{maxvoljobs}) {
+    if (defined $arg->{maxvoljobs}) {
        $update .= " maxvoljobs=$arg->{maxvoljobs} " ;
     }
     
-    $arg->{maxvolfiles} ||= 0;
-    if ($arg->{maxvolfiles}) {
+    if (defined $arg->{maxvolfiles}) {
        $update .= " maxvolfiles=$arg->{maxvolfiles} " ;
     }    
 
-    $arg->{maxvolbytes} ||= 0;
-    if ($arg->{maxvolbytes}) {
+    if (defined $arg->{maxvolbytes}) {
        $update .= " maxvolbytes=$arg->{maxvolbytes} " ;
     }    
 
@@ -2999,6 +3004,16 @@ sub label_barcodes
        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");
+    } 
+
+    my $storage = $a->get_drive_name($arg->{drive});
+    unless ($storage) {
+       return $self->error("Can't get your drive name");
+    }
+
     my $slots = '';
     my $t = 300 ;
     if ($arg->{slots}) {
@@ -3009,12 +3024,27 @@ sub label_barcodes
     my $b = new Bconsole(pref => $self->{info}, timeout => $t,log_stdout => 1);
     print "<h1>This command can take long time, be patient...</h1>";
     print "<pre>" ;
-    $b->label_barcodes(storage => $arg->{ach},
+    $b->label_barcodes(storage => $storage,
                       drive => $arg->{drive},
                       pool  => 'Scratch',
                       slots => $slots) ;
     $b->close();
     print "</pre>";
+
+    $self->dbh_do("
+  UPDATE Media 
+       SET LocationId =   (SELECT LocationId 
+                             FROM Location 
+                            WHERE Location = '$arg->{ach}'),
+
+           RecyclePoolId = PoolId
+
+     WHERE Media.PoolId = (SELECT PoolId 
+                             FROM Pool
+                            WHERE Name = 'Scratch')
+       AND (LocationId = 0 OR LocationId IS NULL)
+");
+
 }
 
 sub purge
@@ -3219,7 +3249,7 @@ sub run_job_now
     
     # TODO: check input (don't use pool, level)
 
-    my $arg = $self->get_form('pool', 'level', 'client', 'priority');
+    my $arg = $self->get_form('pool', 'level', 'client', 'priority', 'when');
     my $job = CGI::param('job') || '';
     my $storage = CGI::param('storage') || '';
 
@@ -3229,6 +3259,7 @@ sub run_job_now
                        level => $arg->{level},
                        storage => $storage,
                        pool => $arg->{pool},
+                       when => $arg->{when},
                        );
 
     print $jobid, $b->{error};