]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/bweb/cgi/bconsole.pl
ebl Release 2.0.2 on sf
[bacula/bacula] / gui / bweb / bweb / cgi / bconsole.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 =head1 NAME
5
6     bconsole.pl - Interface between brestore and bweb to use bconsole.
7
8     You can also use Bconsole.pm and install bconsole on your workstation.
9
10 =head1 LICENSE
11
12    Bweb - A Bacula web interface
13    Bacula® - The Network Backup Solution
14
15    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
16
17    The main author of Bweb is Eric Bollengier.
18    The main author of Bacula is Kern Sibbald, with contributions from
19    many others, a complete list can be found in the file AUTHORS.
20
21    This program is Free Software; you can redistribute it and/or
22    modify it under the terms of version two of the GNU General Public
23    License as published by the Free Software Foundation plus additions
24    that are listed in the file LICENSE.
25
26    This program is distributed in the hope that it will be useful, but
27    WITHOUT ANY WARRANTY; without even the implied warranty of
28    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29    General Public License for more details.
30
31    You should have received a copy of the GNU General Public License
32    along with this program; if not, write to the Free Software
33    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34    02110-1301, USA.
35
36    Bacula® is a registered trademark of John Walker.
37    The licensor of Bacula is the Free Software Foundation Europe
38    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
39    Switzerland, email:ftf@fsfeurope.org.
40
41 =head1 VERSION
42
43     $Id$
44
45 =cut
46
47 use Data::Dumper;
48 use CGI;
49 use POSIX qw/strftime/;
50 use File::Temp qw/tempfile/;
51
52 use Bweb;
53 use Bconsole;
54
55 my $conf = new Bweb::Config(config_file => $Bweb::config_file);
56 $conf->load();
57
58 my $bweb = new Bweb(info => $conf);
59 my $bconsole = new Bconsole(pref => $conf);
60 my $debug = $bweb->{debug};
61
62 my $opts = $bweb->get_form('timeout');
63 $bconsole->{timeout} = $opts->{timeout} || 40;
64
65 # on doit utiliser du POST
66 print CGI::header('text/plain');
67
68 my @action = CGI::param('action') ;
69 my %cmd = ( 'list_job'      => '.job', 
70             'list_client'   => '.client' ,
71             'list_storage'  => '.storage',
72             'list_fileset'  => '.fileset',
73            );
74
75
76 my $have_run=0;
77 for my $a (@action)
78 {
79     if (defined $cmd{$a})
80     {
81         my $out = $bconsole->send_cmd($cmd{$a});
82         $out =~ s/\r\n/;/g ;
83         print "$a=$out\n";
84
85     } elsif ($a eq 'run' and $have_run==0) {
86         $have_run=1;
87
88         my $arg = $bweb->get_form(qw/job client storage fileset 
89                                      where replace priority/);
90
91         my $bootstrap = CGI::param('bootstrap');
92         
93         if (!$bootstrap or !$arg->{job} or !$arg->{client}) {
94             print "ERROR: missing bootstrap or job or client\n";
95             exit 1;
96         }
97
98         my ($fh, $filename) = tempfile();
99         while (my $l = <$bootstrap>) {
100             $fh->print($l);
101         }
102         close($fh);
103         chmod(0644, $filename);
104         
105         my $jobid = $bconsole->run(job       => $arg->{job},
106                                    client    => $arg->{client},
107                                    storage   => $arg->{storage},
108                                    fileset   => $arg->{fileset},
109                                    where     => $arg->{where},
110                                    replace   => $arg->{replace},
111                                    priority  => $arg->{priority},
112                                    bootstrap => $filename);
113
114         print "run=$jobid\n";
115
116     } else {
117         print STDERR "unknow argument $a\n";
118     }
119 }
120
121 exit 0;