]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bweb/cgi/bweb.pl
ebl fix display_job_group, it works now !
[bacula/bacula] / gui / bweb / cgi / bweb.pl
index ee0b59af77a731e6febdea7c5d2711f112a94a53..b6d1e97dfa99c86cc2c279f736b6ce7d35e4ecf8 100755 (executable)
@@ -3,22 +3,34 @@ use strict ;
 
 =head1 LICENSE
 
-    Copyright (C) 2006 Eric Bollengier
-        All rights reserved.
+   Bweb - A Bacula web interface
+   Bacula® - The Network Backup Solution
 
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    any later version.
+   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
 
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
+   The main author of Bweb is Eric Bollengier.
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
+   Switzerland, email:ftf@fsfeurope.org.
 
 =head1 VERSION
 
@@ -31,7 +43,6 @@ use Bweb;
 use CGI;
 
 my $client_re = qr/^([\w\d\.-]+)$/;
-my $pool_re   = $client_re; 
 
 my $action = CGI::param('action') || 'begin';
 
@@ -43,7 +54,7 @@ if ($action eq 'restore') {
 }
 
 # loading config file
-my $conf = new Bweb::Config(config_file => '/etc/bweb/config');
+my $conf = new Bweb::Config(config_file => $Bweb::config_file);
 $conf->load();
 
 my $bweb = new Bweb(info => $conf);
@@ -59,25 +70,17 @@ my $arg = $bweb->get_form('jobid', 'limit', 'offset', 'age');
 $bweb->display_begin();
 
 # if no configuration, we send edit_conf
-unless ($bweb->{info}->{dbi}) {
+if ($action ne 'apply_conf' and !$bweb->{info}->{dbi}) {
     $action = 'edit_conf';
 }
 
 if ($action eq 'begin') {              # main display
-    print "<table border='0'><td valign='top' width='100%'>\n";
+    print "<div style='left=0;'><table border='0'><tr><td valign='top' width='100%'>\n";
     $bweb->display_general(age => $arg->{age});
     $bweb->display_running_jobs(0);
     print "</td><td valign='top'>";
-    print "
-<div class='titlediv'>
-  <h1 class='newstitle'> Statistics (last 48 hours)</h1>
-</div>
-<div class='bodydiv'>
-<a href='?action=job;age=172800;jobtype=B'>
-<img src='bgraph.pl?age=172800;width=450;height=250;graph=job_size;limit=100;action=graph;legend=off' alt='Nothing to display'>
-</a>
-</div>";
-    print "</td></table>";
+    $bweb->display({}, "stats.tpl");
+    print "</td></tr></table></div>";
     $bweb->display_job(limit => 10); 
 
 } elsif ($action eq 'view_conf') {
@@ -104,57 +107,86 @@ if ($action eq 'begin') {         # main display
 } elsif ($action eq 'location_add') {
     $bweb->location_add();
 
-#} elsif ($action eq 'del_location') {
-#    $bweb->del_location();
-#
+} elsif ($action eq 'location_del') {
+    $bweb->location_del();
+
 } elsif ($action eq 'media') {
-    $bweb->display_media();
+    print "<div><table border='0'><tr><td valign='top'>\n";
+    my $fields = $bweb->get_form(qw/db_locations db_pools
+                                   qlocations qpools volstatus qre_media
+                                   limit  qmediatypes db_mediatypes/);
+    $bweb->display($fields, "display_form_media.tpl");
+
+    print "</td><td valign='top'>";
+    $bweb->display_media(offset => $arg->{offset},
+                        limit => $arg->{limit});
+    print "</td></tr></table></div>";
 
 } elsif ($action eq 'medias') {
     $bweb->display_medias();
 
 } elsif ($action eq 'eject') {
-    my $a = Bweb::Autochanger::get('S1_L80', $bweb);
+    my $arg = $bweb->get_form("ach");
+    my $a = $bweb->ach_get($arg->{ach});
+    
+    if ($a) {
+       $a->status();
+       foreach my $slot (CGI::param('slot')) {
+           print $a->{error} unless $a->send_to_io($slot);
+       }
 
-    $a->status();
-    foreach my $slot (CGI::param('slot')) {
-       print $a->{error} unless $a->send_to_io($slot);
-    }
+       foreach my $media (CGI::param('media')) {
+           my $slot = $a->get_media_slot($media);
+           print $a->{error} unless $a->send_to_io($slot);
+       }
 
-    foreach my $media (CGI::param('media')) {
-       my $slot = $a->get_media_slot($media);
-       print $a->{error} unless $a->send_to_io($slot);
+       $a->display_content();
     }
 
-    $a->display_content();
-
 } elsif ($action eq 'eject_media') {
     $bweb->eject_media();
 
 } elsif ($action eq 'clear_io') {
-    my $a = Bweb::Autochanger::get('S1_L80', $bweb);
-    $a->status();
-    $a->clear_io();
-    $a->display_content();
-   
+    my $arg = $bweb->get_form('ach');
+
+    my $a = $bweb->ach_get($arg->{ach});
+    if (defined $a) {
+       $a->status();
+       $a->clear_io();
+       $a->display_content();
+    }
+
+} elsif ($action eq 'ach_edit') {
+    $bweb->ach_edit();
+
+} elsif ($action eq 'ach_del') {
+    $bweb->ach_del();
+
 } elsif ($action eq 'ach_view') {
     # TODO : get autochanger name and create it
     $bweb->connect_db();
-    my $a = Bweb::Autochanger::get('S1_L80', $bweb);
-    $a->status();
-    $a->display_content();
+    my $arg = $bweb->get_form('ach');
+
+    my $a = $bweb->ach_get($arg->{ach});
+    if ($a) {
+       $a->status();
+       $a->display_content();
+    }
+
+} elsif ($action eq 'ach_add') {
+    $bweb->ach_add();
 
 } elsif ($action eq 'ach_load') {
     my $arg = $bweb->get_form('ach', 'drive', 'slot');
+    
+    my $a = $bweb->ach_get($arg->{ach});
 
-    if (defined $arg->{ach} and defined $arg->{drive} and defined $arg->{slot})
+    if (defined $a and defined $arg->{drive} and defined $arg->{slot})
     {
-       my $a = Bweb::Autochanger::get('S1_L80', $bweb);
        my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
        # TODO : use template here
        print "<pre>\n";
-       $b->send_cmd_with_drive("mount slot=$arg->{slot} storage=\"" . $a->get_drive_name($arg->{drive}) . '"',
-                               $arg->{drive});
+       $b->send_cmd("mount slot=$arg->{slot} drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
        print "</pre>\n";
     } else {
        $bweb->error("Can't get drive, slot or ach");
@@ -163,15 +195,14 @@ if ($action eq 'begin') {         # main display
 } elsif ($action eq 'ach_unload') {
     my $arg = $bweb->get_form('drive', 'slot', 'ach');
 
-    if (defined $arg->{ach} and defined $arg->{drive} and defined $arg->{slot})
+    my $a = $bweb->ach_get($arg->{ach});
+
+    if (defined $a and defined $arg->{drive} and defined $arg->{slot})
     {
-       my $a = Bweb::Autochanger::get('S1_L80', $bweb);
        my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
        # TODO : use template here
        print "<pre>\n";
-       $b->send_cmd_with_drive("umount storage=\"" . $a->get_drive_name($arg->{drive}) . '"',
-                               $arg->{drive});
-
+       $b->send_cmd("umount drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
        print "</pre>\n";
 
     } else {
@@ -190,14 +221,24 @@ if ($action eq 'begin') {         # main display
     $bweb->help_extern_compute();
 
 } elsif ($action eq 'extern') {
-    print "TODO : Eject ", join(",", CGI::param('media'));
+    print "<div style='float: left;'>";
+    my @achs = $bweb->eject_media();
+    for my $ach (@achs) {
+        CGI::param('ach', $ach);
+       $bweb->update_slots();
+    }
+    print "</div><div style='float: left;margin-left: 20px;'>";
     $bweb->move_media();
+    print "</div>";
+
+} elsif ($action eq 'move_email') {
+    $bweb->move_email();
 
 } elsif ($action eq 'change_location') {
-    $bweb->change_location();
+    $bweb->location_change();
 
 } elsif ($action eq 'location') {
-    $bweb->display_location();
+    $bweb->location_display();
 
 } elsif ($action eq 'about') {
     $bweb->display($bweb, 'about.tpl');
@@ -235,19 +276,52 @@ if ($action eq 'begin') {         # main display
 } elsif ($action eq 'disable_job') {
     $bweb->enable_disable_job(0);
 
+} elsif ($action eq 'groups') {
+    $bweb->display_groups();
+
+} elsif ($action eq 'groups_edit') {
+    $bweb->groups_edit();
+
+} elsif ($action eq 'groups_save') {
+    $bweb->groups_save();
+
+} elsif ($action eq 'groups_add') {
+    $bweb->groups_add();
+
+} elsif ($action eq 'groups_del') {
+    $bweb->groups_del();
+
 } elsif ($action eq 'job') {
 
-    print "<table border='0'><td valign='top'>\n";
+    print "<div><table border='0'><tr><td valign='top'>\n";
     my $fields = $bweb->get_form(qw/status level db_clients db_filesets
                                    limit age offset qclients qfilesets
-                                   jobtype/);
+                                   jobtype qpools db_pools
+                                   db_client_groups qclient_groups/); # drop this to hide 
+
     $bweb->display($fields, "display_form_job.tpl");
 
     print "</td><td valign='top'>";
     $bweb->display_job(age => $arg->{age},  # last 7 days
                       offset => $arg->{offset},
                       limit => $arg->{limit});
-    print "</td></table>";
+    print "</td></tr></table></div>";
+} elsif ($action eq 'job_group') {
+
+    print "<div><table border='0'><tr><td valign='top'>\n";
+    my $fields = $bweb->get_form(qw/limit level age 
+                                    db_client_groups qclient_groups/); # drop this to hide 
+
+    $fields->{hide_status} = 1;
+    $fields->{hide_type} = 1;
+    $fields->{action} = 'job_group';
+
+    $bweb->display($fields, "display_form_job.tpl");
+
+    print "</td><td valign='top'>";
+    $bweb->display_job_group(age => $arg->{age},  # last 7 days
+                            limit => $arg->{limit});
+    print "</td></tr></table></div>";
 } elsif ($action eq 'client_stats') {
 
     foreach my $client (CGI::param('client')) {
@@ -257,7 +331,9 @@ if ($action eq 'begin') {           # main display
        }
     }
 
-  
+} elsif ($action eq 'group_stats') {
+
+    $bweb->display_group_stats(age => $arg->{age});
 
 } elsif ($action eq 'running') {
     $bweb->display_running_jobs(1);
@@ -335,12 +411,16 @@ if ($action eq 'begin') {         # main display
 } elsif ($action eq 'delete') {
     $bweb->delete();
 
+} elsif ($action eq 'fileset_view') {
+    $bweb->fileset_view();
+
 } else {
     $bweb->error("Sorry, this action don't exist");
 }
 
 $bweb->display_end();
 
+$bweb->dbh_disconnect();
 
 __END__
 
@@ -369,14 +449,4 @@ TODO :
  o update d'un volume
  o update d'un pool
 
- - Configuration des autochanger a la main dans un hash dumper
-
- {
-   L10 => {
-     name => 'L10',
-     drive_name => ['SDLT-1', 'STLD-2'],
-     login => 'bacula',
-     host  => 'storehost',
-     device => '/dev/changer',
-   },
- }
+ o Configuration des autochanger a la main dans un hash dumper