]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/bconsole.pl
bweb: Update some GPL2 notice to AGPL
[bacula/bacula] / gui / 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-2010 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    This program is Free Software; you can redistribute it and/or
21    modify it under the terms of version three of the GNU Affero General Public
22    License as published by the Free Software Foundation and included
23    in the file LICENSE.
24
25    This program is distributed in the hope that it will be useful, but
26    WITHOUT ANY WARRANTY; without even the implied warranty of
27    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28    Affero General Public License for more details.
29
30    You should have received a copy of the GNU Affero General Public License
31    along with this program; if not, write to the Free Software
32    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
33    02110-1301, USA.
34
35    Bacula® is a registered trademark of Kern Sibbald.
36    The licensor of Bacula is the Free Software Foundation Europe
37    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
38    Switzerland, email:ftf@fsfeurope.org.
39
40 =cut
41
42 use Data::Dumper;
43 use CGI;
44 use POSIX qw/strftime/;
45 use File::Temp qw/tempfile/;
46
47 use Bweb;
48 use Bconsole;
49
50 my $conf = new Bweb::Config(config_file => $Bweb::config_file);
51 $conf->load();
52
53 my $bweb = new Bweb(info => $conf);
54 my $bconsole = new Bconsole(pref => $conf);
55 my $debug = $bweb->{debug};
56
57 my $opts = $bweb->get_form('timeout');
58 $bconsole->{timeout} = $opts->{timeout} || 40;
59
60 # on doit utiliser du POST
61 print CGI::header('text/plain');
62
63 my @action = CGI::param('action') ;
64 my %cmd = ( 'list_job'      => '.job', 
65             'list_client'   => '.client' ,
66             'list_storage'  => '.storage',
67             'list_fileset'  => '.fileset',
68            );
69
70
71 my $have_run=0;
72 for my $a (@action)
73 {
74     if (defined $cmd{$a})
75     {
76         my $out = $bconsole->send_cmd($cmd{$a});
77         $out =~ s/\r\n/;/g ;
78         print "$a=$out\n";
79
80     } elsif ($a eq 'run' and $have_run==0) {
81         $have_run=1;
82
83         my $arg = $bweb->get_form(qw/job client storage fileset regexwhere
84                                      where replace priority/);
85
86         my $bootstrap = CGI::param('bootstrap');
87         
88         if (!$bootstrap or !$arg->{job} or !$arg->{client}) {
89             print "ERROR: missing bootstrap or job or client\n";
90             exit 1;
91         }
92
93         my ($fh, $filename) = tempfile();
94         while (my $l = <$bootstrap>) {
95             $fh->print($l);
96         }
97         close($fh);
98         chmod(0644, $filename);
99         
100         my $jobid = $bconsole->run(job       => $arg->{job},
101                                    client    => $arg->{client},
102                                    storage   => $arg->{storage},
103                                    fileset   => $arg->{fileset},
104                                    where     => $arg->{where},
105                                    regexwhere => $arg->{regexwhere},
106 #                                  replace   => $arg->{replace},
107                                    priority  => $arg->{priority},
108                                    bootstrap => $filename);
109
110         print "run=$jobid\n";
111
112     } else {
113         print STDERR "unknow argument $a\n";
114     }
115 }
116
117 exit 0;