]> 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 6c653dcf2e2a67b299fa707f7d23470f340cb6e0..24c2b60a88cc2ffbb5a9c90878c3faa7b332ee9d 100644 (file)
@@ -2043,7 +2043,7 @@ sub get_param
 sub display_job
 {
     my ($self, %arg) = @_ ;
-    $self->can_do('r_view_job');
+    return if $self->cant_do('r_view_job');
 
     $arg{order} = ' Job.JobId DESC ';
 
@@ -2454,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);
@@ -2540,7 +2540,11 @@ sub groups_edit
     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 = "
@@ -2565,10 +2569,20 @@ sub groups_save
     $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 = "
@@ -2642,29 +2656,6 @@ DELETE FROM client_group
     $self->display_groups();
 }
 
-
-sub groups_add
-{
-    my ($self) = @_;
-    $self->can_do('r_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) = @_;
@@ -2724,33 +2715,42 @@ sub get_roles
     return 1;
 }
 
-# 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 cant_do
 {
     my ($self, $action) = @_;
     # is security enabled in configuration ?
     if (not $self->{info}->{enable_security}) {
-        return 1;
+        return 0
     }
     # admin is a special user that can do everything
     if ($self->{loginname} eq 'admin') {
-        return 1;
+        return 0;
     }
     # 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);
+       $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");
+        $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);
+        exit 0;
     }
     return 1;
 }
@@ -2937,8 +2937,8 @@ sub users_add
      SET passwd=$arg->{qpasswd}, comment=$arg->{qcomment}, 
          use_acl=$arg->{use_acl}
    WHERE username = $u") 
-     and (! $self->dbh_is_mysql() )
-     ) or
+#     and (! $self->dbh_is_mysql() )
+     ) and
     $self->dbh_do("
   INSERT INTO bweb_user (username, passwd, use_acl, comment) 
         VALUES ($u, $arg->{qpasswd}, $arg->{use_acl}, $arg->{qcomment})");
@@ -3186,7 +3186,7 @@ INSERT LocationLog (Date, Comment, MediaId, LocationId, NewVolStatus)
 sub display_client_stats
 {
     my ($self, %arg) = @_ ;
-    $self->can_do('r_view_stats');
+    $self->can_do('r_view_stat');
 
     my $client = $self->dbh_quote($arg{clientname});
     # get security filter
@@ -3350,7 +3350,7 @@ GROUP BY VolStatus
 sub display_running_job
 {
     my ($self) = @_;
-    $self->can_do('r_view_running_job');
+    return if $self->cant_do('r_view_running_job');
 
     my $arg = $self->get_form('client', 'jobid');
 
@@ -3386,7 +3386,7 @@ WHERE Job.JobId = $arg->{jobid}
 sub display_running_jobs
 {
     my ($self, $display_action) = @_;
-    $self->can_do('r_view_running_job');
+    return if $self->cant_do('r_view_running_job');
 
     # get security filter
     my $filter = $self->get_client_filter();