]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bweb/cgi/bweb.pl
ebl use $CONF_DIR instead of /etc/bacula
[bacula/bacula] / gui / bweb / cgi / bweb.pl
index b1cddc23e4092ed84aa89b123412d2255cb3435a..d4a8cf573afa7bd24a97a1d8f9f9d312294e2c12 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);
@@ -58,21 +69,18 @@ my $arg = $bweb->get_form('jobid', 'limit', 'offset', 'age');
 
 $bweb->display_begin();
 
+# if no configuration, we send edit_conf
+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' 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') {
@@ -99,58 +107,106 @@ 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') {
+    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();
+    print "</td></tr></table></div>";
 
 } elsif ($action eq 'medias') {
     $bweb->display_medias();
 
 } elsif ($action eq 'eject') {
-    my $a = Bweb::Autochanger::get('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('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('L80', $bweb);
-    $a->status();
-    $a->display_content();
+    my $arg = $bweb->get_form('ach');
 
-} elsif ($action eq 'ach_load') {
-    my $arg = $bweb->get_form('drive', 'slot');
-    my $a = Bweb::Autochanger::get('L80', $bweb);
-    $a->status();
-    $a->load($arg->{drive}, $arg->{slot}) ;
+    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 $a and defined $arg->{drive} and defined $arg->{slot})
+    {
+       my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
+       # TODO : use template here
+       print "<pre>\n";
+       $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");
+    }
+    
 } elsif ($action eq 'ach_unload') {
-    my $arg = $bweb->get_form('drive', 'slot');
-    my $a = Bweb::Autochanger::get('L80', $bweb);
-    $a->status();
-    $a->unload($arg->{drive}, $arg->{slot}) ;
-   
+    my $arg = $bweb->get_form('drive', 'slot', 'ach');
+
+    my $a = $bweb->ach_get($arg->{ach});
+
+    if (defined $a and defined $arg->{drive} and defined $arg->{slot})
+    {
+       my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
+       # TODO : use template here
+       print "<pre>\n";
+       $b->send_cmd("umount drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
+       print "</pre>\n";
+
+    } else {
+       $bweb->error("Can't get drive, slot or ach");
+    }   
 } elsif ($action eq 'intern_media') {
     $bweb->help_intern();
 
@@ -164,9 +220,12 @@ if ($action eq 'begin') {          # main display
     $bweb->help_extern_compute();
 
 } elsif ($action eq 'extern') {
-    print "TODO : Eject ", join(",", CGI::param('media'));
+    $bweb->eject_media();
     $bweb->move_media();
 
+} elsif ($action eq 'move_email') {
+    $bweb->move_email();
+
 } elsif ($action eq 'change_location') {
     $bweb->change_location();
 
@@ -211,17 +270,17 @@ if ($action eq 'begin') {         # main display
 
 } 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/);
     $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 'client_stats') {
 
     foreach my $client (CGI::param('client')) {
@@ -231,8 +290,6 @@ if ($action eq 'begin') {           # main display
        }
     }
 
-  
-
 } elsif ($action eq 'running') {
     $bweb->display_running_jobs(1);
 
@@ -309,6 +366,9 @@ 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");
 }
@@ -343,14 +403,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