]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/bconsole.pl
ebl fix missing where argument
[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     Copyright (C) 2006 Eric Bollengier
13         All rights reserved.
14
15     This program is free software; you can redistribute it and/or modify
16     it under the terms of the GNU General Public License as published by
17     the Free Software Foundation; either version 2 of the License, or
18     any later version.
19
20     This program is distributed in the hope that it will be useful,
21     but WITHOUT ANY WARRANTY; without even the implied warranty of
22     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     GNU General Public License for more details.
24
25     You should have received a copy of the GNU General Public License
26     along with this program; if not, write to the Free Software
27     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
29 =head1 VERSION
30
31     $Id$
32
33 =cut
34
35 use Data::Dumper;
36 use CGI;
37 use POSIX qw/strftime/;
38 use File::Temp qw/tempfile/;
39
40 use Bweb;
41 use Bconsole;
42
43 my $conf = new Bweb::Config(config_file => '/etc/bweb/config');
44 $conf->load();
45
46 my $bweb = new Bweb(info => $conf);
47 my $bconsole = new Bconsole(pref => $conf);
48 my $debug = $bweb->{debug};
49
50 my $opts = $bweb->get_form('timeout');
51 $bconsole->{timeout} = $opts->{timeout} || 40;
52
53 # on doit utiliser du POST
54 print CGI::header('text/plain');
55
56 my @action = CGI::param('action') ;
57 my %cmd = ( 'list_job'      => '.job', 
58             'list_client'   => '.client' ,
59             'list_storage'  => '.storage',
60             'list_fileset'  => '.fileset',
61            );
62
63
64 my $have_run=0;
65 for my $a (@action)
66 {
67     if (defined $cmd{$a})
68     {
69         my $out = $bconsole->send_cmd($cmd{$a});
70         $out =~ s/\r\n/;/g ;
71         print "$a=$out\n";
72
73     } elsif ($a eq 'run' and $have_run==0) {
74         $have_run=1;
75
76         my $arg = $bweb->get_form(qw/job client storage fileset 
77                                      where replace priority/);
78
79         my $bootstrap = CGI::param('bootstrap');
80         
81         if (!$bootstrap or !$arg->{job} or !$arg->{client}) {
82             print "ERROR: missing bootstrap or job or client\n";
83             exit 1;
84         }
85
86         my ($fh, $filename) = tempfile();
87         while (my $l = <$bootstrap>) {
88             $fh->print($l);
89         }
90         close($fh);
91         chmod(0644, $filename);
92         
93         my $jobid = $bconsole->run(job       => $arg->{job},
94                                    client    => $arg->{client},
95                                    storage   => $arg->{storage},
96                                    fileset   => $arg->{fileset},
97                                    where     => $arg->{where},
98                                    replace   => $arg->{replace},
99                                    priority  => $arg->{priority},
100                                    bootstrap => $filename);
101
102         print "run=$jobid\n";
103
104     } else {
105         print STDERR "unknow argument $a\n";
106     }
107 }
108
109 exit 0;