]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/bweb/cgi/bweb.pl
6b3dd7d10a60902a3124b4da6fd3baa0bbfcdc88
[bacula/bacula] / gui / bweb / bweb / cgi / bweb.pl
1 #!/usr/bin/perl -w
2 use strict ;
3
4 =head1 LICENSE
5
6    Bweb - A Bacula web interface
7    Bacula® - The Network Backup Solution
8
9    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
10
11    The main author of Bweb is Eric Bollengier.
12    The main author of Bacula is Kern Sibbald, with contributions from
13    many others, a complete list can be found in the file AUTHORS.
14
15    This program is Free Software; you can redistribute it and/or
16    modify it under the terms of version two of the GNU General Public
17    License as published by the Free Software Foundation plus additions
18    that are listed in the file LICENSE.
19
20    This program is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23    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., 51 Franklin Street, Fifth Floor, Boston, MA
28    02110-1301, USA.
29
30    Bacula® is a registered trademark of John Walker.
31    The licensor of Bacula is the Free Software Foundation Europe
32    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
33    Switzerland, email:ftf@fsfeurope.org.
34
35 =head1 VERSION
36
37     $Id$
38
39 =cut
40
41 use Data::Dumper;
42 use Bweb;
43 use CGI;
44
45 my $client_re = qr/^([\w\d\.-]+)$/;
46
47 my $action = CGI::param('action') || 'begin';
48
49 if ($action eq 'restore') {
50     print CGI::header('text/brestore'); # specialy to run brestore.pl
51
52 } else {
53     print CGI::header('text/html');
54 }
55
56 # loading config file
57 my $conf = new Bweb::Config(config_file => $Bweb::config_file);
58 $conf->load();
59
60 my $bweb = new Bweb(info => $conf);
61
62 # just send data with text/brestore content
63 if ($action eq 'restore') {
64     $bweb->restore();
65     exit 0;
66 }
67
68 my $arg = $bweb->get_form('jobid', 'limit', 'offset', 'age');
69
70 $bweb->display_begin();
71
72 # if no configuration, we send edit_conf
73 if ($action ne 'apply_conf' and !$bweb->{info}->{dbi}) {
74     $action = 'edit_conf';
75 }
76
77 if ($action eq 'begin') {               # main display
78     print "<div style='left=0;'><table border='0'><tr><td valign='top' width='100%'>\n";
79     $bweb->display_general(age => $arg->{age});
80     $bweb->display_running_jobs(0);
81     print "</td><td valign='top'>";
82     $bweb->display({}, "stats.tpl");
83     print "</td></tr></table></div>";
84     $bweb->display_job(limit => 10); 
85
86 } elsif ($action eq 'view_conf') {
87     $conf->view()
88
89 } elsif ($action eq 'edit_conf') {
90     $conf->edit();
91
92 } elsif ($action eq 'apply_conf') {
93     $conf->modify();
94
95 } elsif ($action eq 'client') { 
96     $bweb->display_clients();
97
98 } elsif ($action eq 'pool') {
99     $bweb->display_pool();
100
101 } elsif ($action eq 'location_edit') {
102     $bweb->location_edit();
103
104 } elsif ($action eq 'location_save') {
105     $bweb->location_save();
106
107 } elsif ($action eq 'location_add') {
108     $bweb->location_add();
109
110 } elsif ($action eq 'location_del') {
111     $bweb->location_del();
112
113 } elsif ($action eq 'media') {
114     print "<div><table border='0'><tr><td valign='top'>\n";
115     my $fields = $bweb->get_form(qw/db_locations db_pools
116                                     qlocations qpools volstatus qre_media
117                                     limit  qmediatypes db_mediatypes/);
118     $bweb->display($fields, "display_form_media.tpl");
119
120     print "</td><td valign='top'>";
121     $bweb->display_media();
122     print "</td></tr></table></div>";
123
124 } elsif ($action eq 'medias') {
125     $bweb->display_medias();
126
127 } elsif ($action eq 'eject') {
128     my $arg = $bweb->get_form("ach");
129     my $a = $bweb->ach_get($arg->{ach});
130     
131     if ($a) {
132         $a->status();
133         foreach my $slot (CGI::param('slot')) {
134             print $a->{error} unless $a->send_to_io($slot);
135         }
136
137         foreach my $media (CGI::param('media')) {
138             my $slot = $a->get_media_slot($media);
139             print $a->{error} unless $a->send_to_io($slot);
140         }
141
142         $a->display_content();
143     }
144
145 } elsif ($action eq 'eject_media') {
146     $bweb->eject_media();
147
148 } elsif ($action eq 'clear_io') {
149     my $arg = $bweb->get_form('ach');
150
151     my $a = $bweb->ach_get($arg->{ach});
152     if (defined $a) {
153         $a->status();
154         $a->clear_io();
155         $a->display_content();
156     }
157
158 } elsif ($action eq 'ach_edit') {
159     $bweb->ach_edit();
160
161 } elsif ($action eq 'ach_del') {
162     $bweb->ach_del();
163
164 } elsif ($action eq 'ach_view') {
165     # TODO : get autochanger name and create it
166     $bweb->connect_db();
167     my $arg = $bweb->get_form('ach');
168
169     my $a = $bweb->ach_get($arg->{ach});
170     if ($a) {
171         $a->status();
172         $a->display_content();
173     }
174
175 } elsif ($action eq 'ach_add') {
176     $bweb->ach_add();
177
178 } elsif ($action eq 'ach_load') {
179     my $arg = $bweb->get_form('ach', 'drive', 'slot');
180     
181     my $a = $bweb->ach_get($arg->{ach});
182
183     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
184     {
185         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
186         # TODO : use template here
187         print "<pre>\n";
188         $b->send_cmd("mount slot=$arg->{slot} drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
189         print "</pre>\n";
190     } else {
191         $bweb->error("Can't get drive, slot or ach");
192     }
193     
194 } elsif ($action eq 'ach_unload') {
195     my $arg = $bweb->get_form('drive', 'slot', 'ach');
196
197     my $a = $bweb->ach_get($arg->{ach});
198
199     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
200     {
201         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
202         # TODO : use template here
203         print "<pre>\n";
204         $b->send_cmd("umount drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
205         print "</pre>\n";
206
207     } else {
208         $bweb->error("Can't get drive, slot or ach");
209     }   
210 } elsif ($action eq 'intern_media') {
211     $bweb->help_intern();
212
213 } elsif ($action eq 'compute_intern_media') {
214     $bweb->help_intern_compute();
215
216 } elsif ($action eq 'extern_media') {
217     $bweb->help_extern();
218
219 } elsif ($action eq 'compute_extern_media') {
220     $bweb->help_extern_compute();
221
222 } elsif ($action eq 'extern') {
223     print "<div style='float: left;'>";
224     my @achs = $bweb->eject_media();
225     for my $ach (@achs) {
226         CGI::param('ach', $ach);
227         $bweb->update_slots();
228     }
229     print "</div><div style='float: left;margin-left: 20px;'>";
230     $bweb->move_media();
231     print "</div>";
232
233 } elsif ($action eq 'move_email') {
234     $bweb->move_email();
235
236 } elsif ($action eq 'change_location') {
237     $bweb->change_location();
238
239 } elsif ($action eq 'location') {
240     $bweb->display_location();
241
242 } elsif ($action eq 'about') {
243     $bweb->display($bweb, 'about.tpl');
244
245 } elsif ($action eq 'intern') {
246     $bweb->move_media(); # TODO : remove that
247
248 } elsif ($action eq 'move_media') {
249     $bweb->move_media(); 
250
251 } elsif ($action eq 'save_location') {
252     $bweb->save_location();
253
254 } elsif ($action eq 'update_location') {
255     $bweb->update_location();
256
257 } elsif ($action eq 'update_media') {
258     $bweb->update_media();
259
260 } elsif ($action eq 'do_update_media') {
261     $bweb->do_update_media();
262
263 } elsif ($action eq 'update_slots') {
264     $bweb->update_slots();
265
266 } elsif ($action eq 'graph') {
267     $bweb->display_graph();
268
269 } elsif ($action eq 'next_job') {
270     $bweb->director_show_sched();
271
272 } elsif ($action eq 'enable_job') {
273     $bweb->enable_disable_job(1);
274
275 } elsif ($action eq 'disable_job') {
276     $bweb->enable_disable_job(0);
277
278 } elsif ($action eq 'job') {
279
280     print "<div><table border='0'><tr><td valign='top'>\n";
281     my $fields = $bweb->get_form(qw/status level db_clients db_filesets
282                                     limit age offset qclients qfilesets
283                                     jobtype qpools db_pools/);
284     $bweb->display($fields, "display_form_job.tpl");
285
286     print "</td><td valign='top'>";
287     $bweb->display_job(age => $arg->{age},  # last 7 days
288                        offset => $arg->{offset},
289                        limit => $arg->{limit});
290     print "</td></tr></table></div>";
291 } elsif ($action eq 'client_stats') {
292
293     foreach my $client (CGI::param('client')) {
294         if ($client =~ m/$client_re/) {
295             $bweb->display_client_stats(clientname => $1,
296                                         age => $arg->{age});
297         }
298     }
299
300 } elsif ($action eq 'running') {
301     $bweb->display_running_jobs(1);
302
303 } elsif ($action eq 'dsp_cur_job') {
304     $bweb->display_running_job();
305
306 } elsif ($action eq 'update_from_pool') {
307     my $elt = $bweb->get_form(qw/media pool/);
308     unless ($elt->{media} || $elt->{pool}) {
309         $bweb->error("Can't get media or pool param");
310     } else {
311         my $b = new Bconsole(pref => $conf) ;
312
313         $bweb->display({
314  content => $b->send_cmd("update volume=$elt->{media} fromPool=$elt->{pool}"),
315  title => "Update pool",
316  name => "update volume=$elt->{media} fromPool=$elt->{pool}",
317         }, "command.tpl");      
318     }
319     
320     $bweb->update_media();
321
322 } elsif ($action eq 'client_status') {
323     my $b;
324     foreach my $client (CGI::param('client')) {
325         if ($client =~ m/$client_re/) {
326             $client = $1;
327             $b = new Bconsole(pref => $conf) 
328                 unless ($b) ;
329
330             $bweb->display({
331                 content => $b->send_cmd("st client=$client"),
332                 title => "Client status",
333                 name => $client,
334             }, "command.tpl");
335             
336         } else {
337             $bweb->error("Can't get client selection");
338         }
339     }
340
341 } elsif ($action eq 'cancel_job') {
342     $bweb->cancel_job();
343
344 } elsif  ($action eq 'media_zoom') {
345     $bweb->display_media_zoom();
346
347 } elsif  ($action eq 'job_zoom') {
348     if ($arg->{jobid}) {
349         $bweb->display_job_zoom($arg->{jobid});
350         $bweb->get_job_log();
351     } 
352 } elsif ($action eq 'job_log') {
353     $bweb->get_job_log();
354
355 } elsif ($action eq 'prune') {
356     $bweb->prune();
357
358 } elsif ($action eq 'purge') {
359     $bweb->purge();
360
361 } elsif ($action eq 'run_job') {
362     $bweb->run_job();
363
364 } elsif ($action eq 'run_job_mod') {
365     $bweb->run_job_mod();
366
367 } elsif ($action eq 'run_job_now') {
368     $bweb->run_job_now();
369
370 } elsif ($action eq 'label_barcodes') {
371     $bweb->label_barcodes();
372
373 } elsif ($action eq 'delete') {
374     $bweb->delete();
375
376 } elsif ($action eq 'fileset_view') {
377     $bweb->fileset_view();
378
379 } else {
380     $bweb->error("Sorry, this action don't exist");
381 }
382
383 $bweb->display_end();
384
385
386 __END__
387
388 TODO :
389
390  o Affichage des job en cours, termines
391  o Affichage du detail d'un job (status client)
392  o Acces aux log d'une sauvegarde
393  o Cancel d'un job
394  o Lancement d'un job
395
396  o Affichage des medias (pool, cf bacweb)
397  o Affichage de la liste des cartouches
398  o Affichage d'un autochangeur
399  o Mise a jour des slots
400  o Label barcodes
401  o Affichage des medias qui ont besoin d'etre change
402
403  o Affichage des stats sur les dernieres sauvegardes (cf bacula-web)
404  o Affichage des stats sur un type de job
405  o Affichage des infos de query.sql
406
407  - Affichage des du TapeAlert sur le site
408  - Recuperation des erreurs SCSI de /var/log/kern.log
409
410  o update d'un volume
411  o update d'un pool
412
413  o Configuration des autochanger a la main dans un hash dumper