]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/bweb.pl
ebl use $CONF_DIR instead of /etc/bacula
[bacula/bacula] / gui / 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     $bweb->eject_media();
224     $bweb->move_media();
225
226 } elsif ($action eq 'move_email') {
227     $bweb->move_email();
228
229 } elsif ($action eq 'change_location') {
230     $bweb->change_location();
231
232 } elsif ($action eq 'location') {
233     $bweb->display_location();
234
235 } elsif ($action eq 'about') {
236     $bweb->display($bweb, 'about.tpl');
237
238 } elsif ($action eq 'intern') {
239     $bweb->move_media(); # TODO : remove that
240
241 } elsif ($action eq 'move_media') {
242     $bweb->move_media(); 
243
244 } elsif ($action eq 'save_location') {
245     $bweb->save_location();
246
247 } elsif ($action eq 'update_location') {
248     $bweb->update_location();
249
250 } elsif ($action eq 'update_media') {
251     $bweb->update_media();
252
253 } elsif ($action eq 'do_update_media') {
254     $bweb->do_update_media();
255
256 } elsif ($action eq 'update_slots') {
257     $bweb->update_slots();
258
259 } elsif ($action eq 'graph') {
260     $bweb->display_graph();
261
262 } elsif ($action eq 'next_job') {
263     $bweb->director_show_sched();
264
265 } elsif ($action eq 'enable_job') {
266     $bweb->enable_disable_job(1);
267
268 } elsif ($action eq 'disable_job') {
269     $bweb->enable_disable_job(0);
270
271 } elsif ($action eq 'job') {
272
273     print "<div><table border='0'><tr><td valign='top'>\n";
274     my $fields = $bweb->get_form(qw/status level db_clients db_filesets
275                                     limit age offset qclients qfilesets
276                                     jobtype qpools db_pools/);
277     $bweb->display($fields, "display_form_job.tpl");
278
279     print "</td><td valign='top'>";
280     $bweb->display_job(age => $arg->{age},  # last 7 days
281                        offset => $arg->{offset},
282                        limit => $arg->{limit});
283     print "</td></tr></table></div>";
284 } elsif ($action eq 'client_stats') {
285
286     foreach my $client (CGI::param('client')) {
287         if ($client =~ m/$client_re/) {
288             $bweb->display_client_stats(clientname => $1,
289                                         age => $arg->{age});
290         }
291     }
292
293 } elsif ($action eq 'running') {
294     $bweb->display_running_jobs(1);
295
296 } elsif ($action eq 'dsp_cur_job') {
297     $bweb->display_running_job();
298
299 } elsif ($action eq 'update_from_pool') {
300     my $elt = $bweb->get_form(qw/media pool/);
301     unless ($elt->{media} || $elt->{pool}) {
302         $bweb->error("Can't get media or pool param");
303     } else {
304         my $b = new Bconsole(pref => $conf) ;
305
306         $bweb->display({
307  content => $b->send_cmd("update volume=$elt->{media} fromPool=$elt->{pool}"),
308  title => "Update pool",
309  name => "update volume=$elt->{media} fromPool=$elt->{pool}",
310         }, "command.tpl");      
311     }
312     
313     $bweb->update_media();
314
315 } elsif ($action eq 'client_status') {
316     my $b;
317     foreach my $client (CGI::param('client')) {
318         if ($client =~ m/$client_re/) {
319             $client = $1;
320             $b = new Bconsole(pref => $conf) 
321                 unless ($b) ;
322
323             $bweb->display({
324                 content => $b->send_cmd("st client=$client"),
325                 title => "Client status",
326                 name => $client,
327             }, "command.tpl");
328             
329         } else {
330             $bweb->error("Can't get client selection");
331         }
332     }
333
334 } elsif ($action eq 'cancel_job') {
335     $bweb->cancel_job();
336
337 } elsif  ($action eq 'media_zoom') {
338     $bweb->display_media_zoom();
339
340 } elsif  ($action eq 'job_zoom') {
341     if ($arg->{jobid}) {
342         $bweb->display_job_zoom($arg->{jobid});
343         $bweb->get_job_log();
344     } 
345 } elsif ($action eq 'job_log') {
346     $bweb->get_job_log();
347
348 } elsif ($action eq 'prune') {
349     $bweb->prune();
350
351 } elsif ($action eq 'purge') {
352     $bweb->purge();
353
354 } elsif ($action eq 'run_job') {
355     $bweb->run_job();
356
357 } elsif ($action eq 'run_job_mod') {
358     $bweb->run_job_mod();
359
360 } elsif ($action eq 'run_job_now') {
361     $bweb->run_job_now();
362
363 } elsif ($action eq 'label_barcodes') {
364     $bweb->label_barcodes();
365
366 } elsif ($action eq 'delete') {
367     $bweb->delete();
368
369 } elsif ($action eq 'fileset_view') {
370     $bweb->fileset_view();
371
372 } else {
373     $bweb->error("Sorry, this action don't exist");
374 }
375
376 $bweb->display_end();
377
378
379 __END__
380
381 TODO :
382
383  o Affichage des job en cours, termines
384  o Affichage du detail d'un job (status client)
385  o Acces aux log d'une sauvegarde
386  o Cancel d'un job
387  o Lancement d'un job
388
389  o Affichage des medias (pool, cf bacweb)
390  o Affichage de la liste des cartouches
391  o Affichage d'un autochangeur
392  o Mise a jour des slots
393  o Label barcodes
394  o Affichage des medias qui ont besoin d'etre change
395
396  o Affichage des stats sur les dernieres sauvegardes (cf bacula-web)
397  o Affichage des stats sur un type de job
398  o Affichage des infos de query.sql
399
400  - Affichage des du TapeAlert sur le site
401  - Recuperation des erreurs SCSI de /var/log/kern.log
402
403  o update d'un volume
404  o update d'un pool
405
406  o Configuration des autochanger a la main dans un hash dumper