]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bweb/lib/Bweb.pm
ebl Add role checks for media
[bacula/bacula] / gui / bweb / lib / Bweb.pm
index 42aa705cb019eee89faae148b48c529dd44f007c..24c2b60a88cc2ffbb5a9c90878c3faa7b332ee9d 100644 (file)
@@ -218,6 +218,7 @@ our %k_re = ( dbi      => qr/^(dbi:(Pg|mysql):(?:\w+=[\w\d\.-]+;?)+)$/i,
              stat_job_table => qr!^(\w*)$!,
              display_log_time => qr!^(on)?$!,
              enable_security => qr/^(on)?$/,
+             enable_security_acl => qr/^(on)?$/,
              );
 
 =head1 FUNCTION
@@ -348,8 +349,9 @@ sub modify
     $self->{error} = '';
     # we need to reset checkbox first
     $self->{debug} = 0;
-    $self->{enable_security} = 0;
     $self->{display_log_time} = 0;
+    $self->{enable_security} = 0;
+    $self->{enable_security_acl} = 0;
 
     foreach my $k (CGI::param())
     {
@@ -1056,6 +1058,7 @@ our %sql_func = (
              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',
@@ -1076,9 +1079,16 @@ our %sql_func = (
              # 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
+{
+    my ($self) = @_;
+    return $self->{info}->{dbi} =~ /dbi:mysql/i;
+}
+
 sub dbh_disconnect
 {
     my ($self) = @_;
@@ -1143,7 +1153,7 @@ sub dbh_selectrow_hashref
 sub dbh_strcat
 {
     my ($self, @what) = @_;
-    if ($self->{conf}->{connection_string} =~ /dbi:mysql/i) {
+    if ($self->dbh_is_mysql()) {
        return 'CONCAT(' . join(',', @what) . ')' ;
     } else {
        return join(' || ', @what);
@@ -1204,15 +1214,29 @@ sub human_enabled
 {
     my $val = shift || 0;
 
-    if ($val == 1 or $val eq "yes") {
+    if ($val eq '1' or $val eq "yes") {
        return "yes";
-    } elsif ($val == 2 or $val eq "archived") {
+    } elsif ($val eq '2' or $val eq "archived") {
        return "archived";
     } else {
        return  "no";
     }
 }
 
+# display Enabled
+sub from_human_enabled
+{
+    my $val = shift || 0;
+
+    if ($val == 1 or $val eq "yes") {
+       return 1;
+    } elsif ($val == 2 or $val eq "archived") {
+       return 2;
+    } else {
+       return  0;
+    }
+}
+
 # get Day, Hour, Year
 sub from_human_sec
 {
@@ -1240,6 +1264,7 @@ sub connect_db
     my ($self) = @_;
 
     unless ($self->{dbh}) {
+
        $self->{dbh} = DBI->connect($self->{info}->{dbi}, 
                                    $self->{info}->{user},
                                    $self->{info}->{password});
@@ -1249,7 +1274,9 @@ sub connect_db
 
        $self->{dbh}->{FetchHashKeyName} = 'NAME_lc';
 
-       if ($self->{info}->{dbi} =~ /^dbi:Pg/i) {
+       if ($self->dbh_is_mysql()) {
+           $self->{dbh}->do("SET group_concat_max_len=1000000");
+       } else {
            $self->{dbh}->do("SET datestyle TO 'ISO, YMD'");
        }
     }
@@ -2016,6 +2043,7 @@ sub get_param
 sub display_job
 {
     my ($self, %arg) = @_ ;
+    return if $self->cant_do('r_view_job');
 
     $arg{order} = ' Job.JobId DESC ';
 
@@ -2081,6 +2109,7 @@ SELECT  Job.JobId       AS jobid,
 sub display_job_zoom
 {
     my ($self, $jobid) = @_ ;
+    $self->can_do('r_view_job');
 
     $jobid = $self->dbh_quote($jobid);
 
@@ -2130,6 +2159,7 @@ WHERE Job.JobId = $jobid
 sub display_job_group
 {
     my ($self, %arg) = @_;
+    $self->can_do('r_view_job');
 
     my ($limit, $label) = $self->get_limit(groupby => 'client_group_name',  %arg);
 
@@ -2349,7 +2379,7 @@ SELECT LocationLog.Date    AS date,
 sub location_edit
 {
     my ($self) = @_ ;
-    $self->can_do('location_mgnt');
+    $self->can_do('r_location_mgnt');
 
     my $loc = $self->get_form('qlocation');
     unless ($loc->{qlocation}) {
@@ -2365,7 +2395,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") ;
 }
@@ -2373,9 +2403,9 @@ WHERE Location.Location = $loc->{qlocation}
 sub location_save
 {
     my ($self) = @_ ;
-    $self->can_do('location_mgnt');
+    $self->can_do('r_location_mgnt');
 
-    my $arg = $self->get_form(qw/qlocation qnewlocation cost/) ;
+    my $arg = $self->get_form(qw/qlocation qnewlocation cost enabled/) ;
     unless ($arg->{qlocation}) {
        return $self->error("Can't get location");
     }    
@@ -2386,8 +2416,7 @@ sub location_save
        return $self->error("Can't get new cost");
     }
 
-    my $enabled = CGI::param('enabled') || '';
-    $enabled = $enabled?1:0;
+    my $enabled = from_human_enabled($arg->{enabled});
 
     my $query = "
 UPDATE Location SET Cost     = $arg->{cost}, 
@@ -2404,7 +2433,7 @@ WHERE Location.Location = $arg->{qlocation}
 sub location_del
 {
     my ($self) = @_ ;
-    $self->can_do('location_mgnt');
+    $self->can_do('r_location_mgnt');
 
     my $arg = $self->get_form(qw/qlocation/) ;
 
@@ -2425,7 +2454,7 @@ WHERE Location = $arg->{qlocation}
     }
 
     $query = "
-DELETE FROM Location WHERE Location = $arg->{qlocation} LIMIT 1
+DELETE FROM Location WHERE Location = $arg->{qlocation}
 ";
 
     $self->dbh_do($query);
@@ -2436,7 +2465,7 @@ DELETE FROM Location WHERE Location = $arg->{qlocation} LIMIT 1
 sub location_add
 {
     my ($self) = @_ ;
-    $self->can_do('location_mgnt');
+    $self->can_do('r_location_mgnt');
 
     my $arg = $self->get_form(qw/qlocation cost/) ;
 
@@ -2506,12 +2535,16 @@ sub update_location
 sub groups_edit
 {
     my ($self) = @_;
-    $self->can_do('group_mgnt');
+    $self->can_do('r_group_mgnt');
 
     my $grp = $self->get_form(qw/qclient_group db_clients/);
 
     unless ($grp->{qclient_group}) {
-       return $self->error("Can't get group");
+       $self->display({ ID => $cur_id++,
+                        client_group => "''",
+                        %$grp,
+                    }, "groups_edit.tpl");
+       return;
     }
 
     my $query = "
@@ -2533,13 +2566,23 @@ WHERE client_group_name = $grp->{qclient_group}
 sub groups_save
 {
     my ($self) = @_;
-    $self->can_do('group_mgnt');
+    $self->can_do('r_group_mgnt');
 
     my $arg = $self->get_form(qw/qclient_group jclients qnewgroup/);
+
+    if (!$arg->{qclient_group} and $arg->{qnewgroup}) {
+       my $query = "
+INSERT INTO client_group (client_group_name) 
+VALUES ($arg->{qnewgroup})
+";
+       $self->dbh_do($query);
+       $arg->{qclient_group} = $arg->{qnewgroup};
+    }
+
     unless ($arg->{qclient_group}) {
        return $self->error("Can't get groups");
     }
-    
+
     $self->{dbh}->begin_work();
 
     my $query = "
@@ -2580,7 +2623,7 @@ UPDATE client_group
 sub groups_del
 {
     my ($self) = @_;
-    $self->can_do('group_mgnt');
+    $self->can_do('r_group_mgnt');
 
     my $arg = $self->get_form(qw/qclient_group/);
 
@@ -2613,29 +2656,6 @@ DELETE FROM client_group
     $self->display_groups();
 }
 
-
-sub groups_add
-{
-    my ($self) = @_;
-    $self->can_do('group_mgnt');
-
-    my $arg = $self->get_form(qw/qclient_group/) ;
-
-    unless ($arg->{qclient_group}) {
-       $self->display({}, "groups_add.tpl");
-       return 1;
-    }
-
-    my $query = "
-INSERT INTO client_group (client_group_name) 
-VALUES ($arg->{qclient_group})
-";
-
-    $self->dbh_do($query);
-
-    $self->display_groups();
-}
-
 sub display_groups
 {
     my ($self) = @_;
@@ -2655,12 +2675,9 @@ sub display_groups
 
 ###########################################################
 
-# TODO: avoir un mode qui coupe le programme avec une page d'erreur
-# we can also get all security and fill {security} hash
-sub can_do
+sub get_roles
 {
-    my ($self, $action) = @_;
-    # is security enabled in configuration ?
+    my ($self) = @_;
     if (not $self->{info}->{enable_security}) {
         return 1;
     }
@@ -2668,73 +2685,132 @@ sub can_do
     if ($self->{loginname} eq 'admin') {
         return 1;
     }
-    # must be logged
     if (!$self->{loginname}) {
-        $self->error("Can't do $action, your are not logged. " .
-                     "Check security with your administrator");
-        $self->display_end();
-        exit (0);
+       return 0;
     }
-    # already checked
-    if ($self->{security}->{$action}) {
-        return 1;
+    # already fill
+    if (defined $self->{security}) {
+       return 1;
     }
-    my ($u, $r) = ($self->dbh_quote($self->{loginname}),
-                   $self->dbh_quote($action));
+    $self->{security} = {};
+    my $u = $self->dbh_quote($self->{loginname});
+           
     my $query = "
- SELECT 1, username, rolename
+ SELECT use_acl, rolename
   FROM bweb_user 
        JOIN bweb_role_member USING (userid)
        JOIN bweb_role USING (roleid)
  WHERE username = $u
-   AND rolename = $r
 ";
-
-    my $row = $self->dbh_selectrow_hashref($query);
+    my $rows = $self->dbh_selectall_arrayref($query);
     # do cache with this role   
-    if (!$row) {
-        $self->error("$u sorry, but this action ($action) is not permited. " .
-                     "Check security with your administrator");
+    if (!$rows) {
+        return 0;
+    }
+    foreach my $r (@$rows) {
+       $self->{security}->{$r->[1]}=1;
+    }
+
+    $self->{security}->{use_acl} = $rows->[0]->[0];
+    return 1;
+}
+
+sub cant_do
+{
+    my ($self, $action) = @_;
+    # is security enabled in configuration ?
+    if (not $self->{info}->{enable_security}) {
+        return 0
+    }
+    # admin is a special user that can do everything
+    if ($self->{loginname} eq 'admin') {
+        return 0;
+    }
+    # must be logged
+    if (!$self->{loginname}) {
+       $self->{error} = "Can't do $action, your are not logged. " .
+           "Check security with your administrator";
+        return 1;
+    }
+    $self->get_roles();
+    if (!$self->{security}->{$action}) {
+        $self->{error} =
+           "$self->{loginname} sorry, but this action ($action) " .
+           "is not permited. " .
+           "Check security with your administrator";
+        return 1;
+    }
+    return 0;
+}
+
+# make like an assert (program die)
+sub can_do
+{
+    my ($self, $action) = @_;
+    if ($self->cant_do($action)) {
+        $self->error($self->{error});
         $self->display_end();
-        exit (0);
-    } 
-    $self->{security}->{$row->{rolename}} = 1;    
+        exit 0;
+    }
     return 1;
 }
 
+sub use_filter
+{
+    my ($self) = @_;
+
+    if (!$self->{info}->{enable_security} or 
+       !$self->{info}->{enable_security_acl})
+    {
+       return 0 ;
+    }
+    
+    if ($self->get_roles()) {
+       return $self->{security}->{use_acl};
+    } else {
+       return 0;
+    }
+}
+
 # JOIN Client USING (ClientId) " . $b->get_client_filter() . "
 sub get_client_filter
 {
-    my ($self) = @_;
-    if ($self->{info}->{enable_security}) {
-       my $u = $self->dbh_quote($self->{loginname});
-       return "
+    my ($self, $login) = @_;
+    my $u;
+    if ($login) {
+       $u = $self->dbh_quote($login);
+    } elsif ($self->use_filter()) {
+       $u = $self->dbh_quote($self->{loginname});
+    } else {
+       return '';
+    }
+    return "
  JOIN (SELECT ClientId FROM client_group_member
    JOIN client_group USING (client_group_id) 
    JOIN bweb_client_group_acl USING (client_group_id) 
    JOIN bweb_user USING (userid)
    WHERE bweb_user.username = $u 
  ) AS filter USING (ClientId)";
-    } else {
-       return '';
-    }
 }
 
 #JOIN client_group USING (client_group_id)" . $b->get_client_group_filter()
 sub get_client_group_filter
 {
-    my ($self) = @_;
-    if ($self->{info}->{enable_security}) {
-       my $u = $self->dbh_quote($self->{loginname});
-       return "
+    my ($self, $login) = @_;
+    my $u;
+    if ($login) {
+       $u = $self->dbh_quote($login);
+    } elsif ($self->use_filter()) {
+       $u = $self->dbh_quote($self->{loginname});
+    } else {
+       return '';
+    }
+    return "
  JOIN (SELECT client_group_id 
          FROM bweb_client_group_acl
          JOIN bweb_user USING (userid)
    WHERE bweb_user.username = $u 
  ) AS filter USING (client_group_id)";
-    } else {
-       return '';
-    }
 }
 
 # role and username have to be quoted before
@@ -2742,7 +2818,7 @@ sub get_client_group_filter
 sub revoke
 {
     my ($self, $role, $username) = @_;
-    $self->can_do("user_mgnt");
+    $self->can_do("r_user_mgnt");
     
     my $nb = $self->dbh_do("
  DELETE FROM bweb_role_member 
@@ -2758,7 +2834,7 @@ sub revoke
 sub grant
 {
     my ($self, $role, $username) = @_;
-    $self->can_do("user_mgnt");
+    $self->can_do("r_user_mgnt");
 
     my $nb = $self->dbh_do("
    INSERT INTO bweb_role_member (roleid, userid)
@@ -2774,7 +2850,7 @@ sub grant
 sub grant_like
 {
     my ($self, $copy, $user) = @_;
-    $self->can_do("user_mgnt");
+    $self->can_do("r_user_mgnt");
 
     my $nb = $self->dbh_do("
   INSERT INTO bweb_role_member (roleid, userid) 
@@ -2790,7 +2866,7 @@ sub grant_like
 sub revoke_all
 {
     my ($self, $username) = @_;
-    $self->can_do("user_mgnt");
+    $self->can_do("r_user_mgnt");
 
     $self->dbh_do("
    DELETE FROM bweb_role_member
@@ -2810,7 +2886,7 @@ DELETE FROM bweb_client_group_acl
 sub users_del
 {
     my ($self) = @_;
-    $self->can_do("user_mgnt");
+    $self->can_do("r_user_mgnt");
 
     my $arg = $self->get_form(qw/jusernames/);
 
@@ -2832,7 +2908,7 @@ DELETE FROM bweb_user WHERE username IN ($arg->{jusernames})");
 sub users_add
 {
     my ($self) = @_;
-    $self->can_do("user_mgnt");
+    $self->can_do("r_user_mgnt");
 
     # we don't quote username directly to check that it is conform
     my $arg = $self->get_form(qw/username qpasswd qcomment jrolenames qcreate qcopy_username jclient_groups/) ;
@@ -2844,6 +2920,8 @@ sub users_add
     }
 
     my $u = $self->dbh_quote($arg->{username});
+    
+    $arg->{use_acl}=(CGI::param('use_acl')?'true':'false');
 
     if (!$arg->{qpasswd}) {
         $arg->{qpasswd} = "''";
@@ -2853,13 +2931,17 @@ sub users_add
     }
 
     # will fail if user already exists
+    # UPDATE with mysql dbi does not return if update is ok
+    ($self->dbh_do("
+  UPDATE bweb_user 
+     SET passwd=$arg->{qpasswd}, comment=$arg->{qcomment}, 
+         use_acl=$arg->{use_acl}
+   WHERE username = $u") 
+#     and (! $self->dbh_is_mysql() )
+     ) and
     $self->dbh_do("
-  UPDATE bweb_user SET passwd=$arg->{qpasswd}, comment=$arg->{qcomment}
-   WHERE username = $u")
-        or
-    $self->dbh_do("
-  INSERT INTO bweb_user (username, passwd, comment) 
-        VALUES ($u, $arg->{qpasswd}, $arg->{qcomment})");
+  INSERT INTO bweb_user (username, passwd, use_acl, comment) 
+        VALUES ($u, $arg->{qpasswd}, $arg->{use_acl}, $arg->{qcomment})");
 
     $self->{dbh}->begin_work();
     {
@@ -2871,14 +2953,15 @@ sub users_add
             $self->grant($arg->{jrolenames}, $u);
         }
 
-       $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();
 
@@ -2889,7 +2972,7 @@ INSERT INTO bweb_client_group_acl (client_group_id, userid)
 sub display_users
 {
     my ($self) = @_;
-    $self->can_do("user_mgnt");
+    $self->can_do("r_user_mgnt");
 
     my $arg = $self->get_form(qw/db_usernames/) ;
 
@@ -2905,22 +2988,24 @@ sub display_users
 sub display_user
 {
     my ($self) = @_;
-    $self->can_do("user_mgnt");
+    $self->can_do("r_user_mgnt");
 
     my $arg = $self->get_form('username');
     my $user = $self->dbh_quote($arg->{username});
 
     my $userp = $self->dbh_selectrow_hashref("
-   SELECT username, passwd, comment
+   SELECT username, passwd, comment, use_acl
      FROM bweb_user
     WHERE username = $user
 ");
-
     if (!$userp) {
         return $self->error("Can't find $user in catalog");
     }
-    $arg = $self->get_form(qw/db_usernames db_client_groups/);
-    my $arg2 = $self->get_form(qw/filter db_client_groups/);
+    my $filter = $self->get_client_group_filter($arg->{username});
+    my $scg = $self->dbh_selectall_hashref("
+ SELECT client_group_name AS name 
+   FROM client_group $filter
+", 'name');
 
 #  rolename  | userid
 #------------+--------
@@ -2937,13 +3022,16 @@ SELECT rolename, temp.userid
 ORDER BY rolename
 ", 'rolename');
 
+    $arg = $self->get_form(qw/db_usernames db_client_groups/);    
+
     $self->display({
         db_usernames => $arg->{db_usernames},
         username => $userp->{username},
         comment => $userp->{comment},
         passwd => $userp->{passwd},
+       use_acl => $userp->{use_acl},
        db_client_groups => $arg->{db_client_groups},
-       client_group => $arg2->{db_client_groups},
+       client_group => [ values %$scg ],
         db_roles => [ values %$role], 
     }, "display_user.tpl");
 }
@@ -3019,7 +3107,7 @@ WHERE Media.VolumeName = $media->{qmedia}
 sub save_location
 {
     my ($self) = @_ ;
-    $self->can_do('media_mgnt');
+    $self->can_do('r_media_mgnt');
 
     my $arg = $self->get_form('jmedias', 'qnewlocation') ;
 
@@ -3049,7 +3137,7 @@ sub save_location
 sub location_change
 {
     my ($self) = @_ ;
-    $self->can_do('media_mgnt');
+    $self->can_do('r_media_mgnt');
 
     my $media = $self->get_selected_media_location();
     unless ($media) {
@@ -3098,6 +3186,7 @@ INSERT LocationLog (Date, Comment, MediaId, LocationId, NewVolStatus)
 sub display_client_stats
 {
     my ($self, %arg) = @_ ;
+    $self->can_do('r_view_stat');
 
     my $client = $self->dbh_quote($arg{clientname});
     # get security filter
@@ -3261,6 +3350,7 @@ GROUP BY VolStatus
 sub display_running_job
 {
     my ($self) = @_;
+    return if $self->cant_do('r_view_running_job');
 
     my $arg = $self->get_form('client', 'jobid');
 
@@ -3296,6 +3386,8 @@ WHERE Job.JobId = $arg->{jobid}
 sub display_running_jobs
 {
     my ($self, $display_action) = @_;
+    return if $self->cant_do('r_view_running_job');
+
     # get security filter
     my $filter = $self->get_client_filter();
 
@@ -3327,7 +3419,7 @@ WHERE
 sub eject_media
 {
     my ($self) = @_;
-    $self->can_do('media_mgnt');
+    $self->can_do('r_media_mgnt');
 
     my %ret; 
     my $arg = $self->get_form('jmedias');
@@ -3432,7 +3524,7 @@ sub ach_get
 sub ach_register
 {
     my ($self, $ach) = @_;
-    $self->can_do('configure');
+    $self->can_do('r_configure');
 
     $self->{info}->{ach_list}->{$ach->{name}} = $ach;
 
@@ -3444,7 +3536,7 @@ sub ach_register
 sub ach_edit
 {
     my ($self) = @_;
-    $self->can_do('configure');
+    $self->can_do('r_configure');
 
     my $arg = $self->get_form('ach');
     if (!$arg->{ach} 
@@ -3475,7 +3567,7 @@ sub ach_edit
 sub ach_del
 {
     my ($self) = @_;
-    $self->can_do('configure');
+    $self->can_do('r_configure');
 
     my $arg = $self->get_form('ach');
 
@@ -3495,7 +3587,7 @@ sub ach_del
 sub ach_add
 {
     my ($self) = @_;
-    $self->can_do('configure');
+    $self->can_do('r_configure');
 
     my $arg = $self->get_form('ach', 'mtxcmd', 'device', 'precmd');
 
@@ -3540,7 +3632,7 @@ sub ach_add
 sub delete
 {
     my ($self) = @_;
-    $self->can_do('delete_job');
+    $self->can_do('r_delete_job');
 
     my $arg = $self->get_form('jobid');
 
@@ -3559,7 +3651,7 @@ sub delete
 sub do_update_media
 {
     my ($self) = @_ ;
-    $self->can_do('media_mgnt');
+    $self->can_do('r_media_mgnt');
 
     my $arg = $self->get_form(qw/media volstatus inchanger pool
                                 slot volretention voluseduration 
@@ -3654,7 +3746,7 @@ UPDATE Media
 sub update_slots
 {
     my ($self) = @_;
-    $self->can_do('autochanger_mgnt');
+    $self->can_do('r_autochanger_mgnt');
 
     my $ach = CGI::param('ach') ;
     $ach = $self->ach_get($ach);
@@ -3671,6 +3763,7 @@ sub update_slots
 sub get_job_log
 {
     my ($self) = @_;
+    $self->can_do('r_view_log');
 
     my $arg = $self->get_form('jobid', 'limit', 'offset');
     unless ($arg->{jobid}) {
@@ -3680,17 +3773,8 @@ sub get_job_log
     if ($arg->{limit} == 100) {
         $arg->{limit} = 1000;
     }
-
-    my $t = CGI::param('time') || $self->{info}->{display_log_time} || '';
-
-    # display only Error and Warning messages
-    my $filter = '';
-    if (CGI::param('error')) {
-       $filter = " AND LogText $self->{sql}->{MATCH} 'Error|Warning' ";
-    }
-
     # get security filter
-    $filter .= $self->get_client_filter();
+    my $filter = $self->get_client_filter();
 
     my $query = "
 SELECT Job.Name as name, Client.Name as clientname
@@ -3704,33 +3788,45 @@ SELECT Job.Name as name, Client.Name as clientname
        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' ";
+    }
+
+    my $logtext;
+    if (CGI::param('time') || $self->{info}->{display_log_time}) {
+       $logtext = $self->dbh_strcat('Time', " ' ' ", 'LogText');
+    } else {
+       $logtext = 'LogText';
+    }
+
     $query = "
-SELECT Time AS time, LogText AS log 
-  FROM  Log 
- WHERE ( Log.JobId = $arg->{jobid} 
-    OR (Log.JobId = 0 AND Time >= (SELECT StartTime FROM Job WHERE JobId=$arg->{jobid}) 
-                      AND Time <= (SELECT COALESCE(EndTime,NOW()) FROM Job WHERE JobId=$arg->{jobid})
-       )
-       ) $filter
+SELECT count(1) AS nbline, JobId AS jobid, 
+       GROUP_CONCAT($logtext $self->{sql}->{CONCAT_SEP}) AS logtxt
+  FROM  (
+    SELECT JobId, Time, LogText
+    FROM Log 
+   WHERE ( Log.JobId = $arg->{jobid} 
+      OR (Log.JobId = 0 
+          AND Time >= (SELECT StartTime FROM Job WHERE JobId=$arg->{jobid}) 
+          AND Time <= (SELECT COALESCE(EndTime,NOW()) FROM Job WHERE JobId=$arg->{jobid})
+       ) ) $filter
  ORDER BY LogId
  LIMIT $arg->{limit}
  OFFSET $arg->{offset}
+ ) AS temp
+ GROUP BY JobId
+
 ";
 
-    my $log = $self->dbh_selectall_arrayref($query);
+    my $log = $self->dbh_selectrow_hashref($query);
     unless ($log) {
        return $self->error("Can't get log for jobid $arg->{jobid}");
     }
 
-    my $logtxt;
-    if ($t) {
-       # log contains \n
-       $logtxt = join("", map { ($_->[0] . ' ' . $_->[1]) } @$log ) ; 
-    } else {
-       $logtxt = join("", map { $_->[1] } @$log ) ; 
-    }
-    
-    $self->display({ lines=> $logtxt,
+    $self->display({ lines=> $log->{logtxt},
+                    nbline => $log->{nbline},
                     jobid => $arg->{jobid},
                     name  => $row->{name},
                     client => $row->{clientname},
@@ -3742,7 +3838,7 @@ SELECT Time AS time, LogText AS log
 sub label_barcodes
 {
     my ($self) = @_ ;
-    $self->can_do('autochanger_mgnt');
+    $self->can_do('r_autochanger_mgnt');
 
     my $arg = $self->get_form('ach', 'slots', 'drive');
 
@@ -3794,7 +3890,7 @@ sub label_barcodes
 sub purge
 {
     my ($self) = @_;
-    $self->can_do('purge');
+    $self->can_do('r_purge');
 
     my @volume = CGI::param('media');
 
@@ -3817,7 +3913,7 @@ sub purge
 sub prune
 {
     my ($self) = @_;
-    $self->can_do('prune');
+    $self->can_do('r_prune');
 
     my @volume = CGI::param('media');
     unless (@volume) {
@@ -3839,7 +3935,7 @@ sub prune
 sub cancel_job
 {
     my ($self) = @_;
-    $self->can_do('cancel_job');
+    $self->can_do('r_cancel_job');
 
     my $arg = $self->get_form('jobid');
     unless ($arg->{jobid}) {
@@ -3890,7 +3986,7 @@ sub director_show_sched
 sub enable_disable_job
 {
     my ($self, $what) = @_ ;
-    $self->can_do('run_job');
+    $self->can_do('r_run_job');
 
     my $name = CGI::param('job') || '';
     unless ($name =~ /^[\w\d\.\-\s]+$/) {
@@ -3922,7 +4018,7 @@ sub get_bconsole
 sub run_job_select
 {
     my ($self) = @_;
-    $self->can_do('run_job');
+    $self->can_do('r_run_job');
 
     my $b = $self->get_bconsole();
 
@@ -3959,7 +4055,7 @@ sub run_parse_job
 sub run_job_mod
 {
     my ($self) = @_;
-    $self->can_do('run_job');
+    $self->can_do('r_run_job');
 
     my $b = $self->get_bconsole();
     
@@ -3992,7 +4088,7 @@ sub run_job_mod
 sub run_job
 {
     my ($self) = @_;
-    $self->can_do('run_job');
+    $self->can_do('r_run_job');
 
     my $b = $self->get_bconsole();
     
@@ -4006,7 +4102,7 @@ sub run_job
 sub run_job_now
 {
     my ($self) = @_;
-    $self->can_do('run_job');
+    $self->can_do('r_run_job');
 
     my $b = $self->get_bconsole();