]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/bweb.pl
ebl add media limit offset option
[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(offset => $arg->{offset},
122                          limit => $arg->{limit});
123     print "</td></tr></table></div>";
124
125 } elsif ($action eq 'medias') {
126     $bweb->display_medias();
127
128 } elsif ($action eq 'eject') {
129     my $arg = $bweb->get_form("ach");
130     my $a = $bweb->ach_get($arg->{ach});
131     
132     if ($a) {
133         $a->status();
134         foreach my $slot (CGI::param('slot')) {
135             print $a->{error} unless $a->send_to_io($slot);
136         }
137
138         foreach my $media (CGI::param('media')) {
139             my $slot = $a->get_media_slot($media);
140             print $a->{error} unless $a->send_to_io($slot);
141         }
142
143         $a->display_content();
144     }
145
146 } elsif ($action eq 'eject_media') {
147     $bweb->eject_media();
148
149 } elsif ($action eq 'clear_io') {
150     my $arg = $bweb->get_form('ach');
151
152     my $a = $bweb->ach_get($arg->{ach});
153     if (defined $a) {
154         $a->status();
155         $a->clear_io();
156         $a->display_content();
157     }
158
159 } elsif ($action eq 'ach_edit') {
160     $bweb->ach_edit();
161
162 } elsif ($action eq 'ach_del') {
163     $bweb->ach_del();
164
165 } elsif ($action eq 'ach_view') {
166     # TODO : get autochanger name and create it
167     $bweb->connect_db();
168     my $arg = $bweb->get_form('ach');
169
170     my $a = $bweb->ach_get($arg->{ach});
171     if ($a) {
172         $a->status();
173         $a->display_content();
174     }
175
176 } elsif ($action eq 'ach_add') {
177     $bweb->ach_add();
178
179 } elsif ($action eq 'ach_load') {
180     my $arg = $bweb->get_form('ach', 'drive', 'slot');
181     
182     my $a = $bweb->ach_get($arg->{ach});
183
184     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
185     {
186         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
187         # TODO : use template here
188         print "<pre>\n";
189         $b->send_cmd("mount slot=$arg->{slot} drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
190         print "</pre>\n";
191     } else {
192         $bweb->error("Can't get drive, slot or ach");
193     }
194     
195 } elsif ($action eq 'ach_unload') {
196     my $arg = $bweb->get_form('drive', 'slot', 'ach');
197
198     my $a = $bweb->ach_get($arg->{ach});
199
200     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
201     {
202         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
203         # TODO : use template here
204         print "<pre>\n";
205         $b->send_cmd("umount drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
206         print "</pre>\n";
207
208     } else {
209         $bweb->error("Can't get drive, slot or ach");
210     }   
211 } elsif ($action eq 'intern_media') {
212     $bweb->help_intern();
213
214 } elsif ($action eq 'compute_intern_media') {
215     $bweb->help_intern_compute();
216
217 } elsif ($action eq 'extern_media') {
218     $bweb->help_extern();
219
220 } elsif ($action eq 'compute_extern_media') {
221     $bweb->help_extern_compute();
222
223 } elsif ($action eq 'extern') {
224     print "<div style='float: left;'>";
225     my @achs = $bweb->eject_media();
226     for my $ach (@achs) {
227         CGI::param('ach', $ach);
228         $bweb->update_slots();
229     }
230     print "</div><div style='float: left;margin-left: 20px;'>";
231     $bweb->move_media();
232     print "</div>";
233
234 } elsif ($action eq 'move_email') {
235     $bweb->move_email();
236
237 } elsif ($action eq 'change_location') {
238     $bweb->change_location();
239
240 } elsif ($action eq 'location') {
241     $bweb->display_location();
242
243 } elsif ($action eq 'about') {
244     $bweb->display($bweb, 'about.tpl');
245
246 } elsif ($action eq 'intern') {
247     $bweb->move_media(); # TODO : remove that
248
249 } elsif ($action eq 'move_media') {
250     $bweb->move_media(); 
251
252 } elsif ($action eq 'save_location') {
253     $bweb->save_location();
254
255 } elsif ($action eq 'update_location') {
256     $bweb->update_location();
257
258 } elsif ($action eq 'update_media') {
259     $bweb->update_media();
260
261 } elsif ($action eq 'do_update_media') {
262     $bweb->do_update_media();
263
264 } elsif ($action eq 'update_slots') {
265     $bweb->update_slots();
266
267 } elsif ($action eq 'graph') {
268     $bweb->display_graph();
269
270 } elsif ($action eq 'next_job') {
271     $bweb->director_show_sched();
272
273 } elsif ($action eq 'enable_job') {
274     $bweb->enable_disable_job(1);
275
276 } elsif ($action eq 'disable_job') {
277     $bweb->enable_disable_job(0);
278
279 } elsif ($action eq 'job') {
280
281     print "<div><table border='0'><tr><td valign='top'>\n";
282     my $fields = $bweb->get_form(qw/status level db_clients db_filesets
283                                     limit age offset qclients qfilesets
284                                     jobtype qpools db_pools/);
285     $bweb->display($fields, "display_form_job.tpl");
286
287     print "</td><td valign='top'>";
288     $bweb->display_job(age => $arg->{age},  # last 7 days
289                        offset => $arg->{offset},
290                        limit => $arg->{limit});
291     print "</td></tr></table></div>";
292 } elsif ($action eq 'client_stats') {
293
294     foreach my $client (CGI::param('client')) {
295         if ($client =~ m/$client_re/) {
296             $bweb->display_client_stats(clientname => $1,
297                                         age => $arg->{age});
298         }
299     }
300
301 } elsif ($action eq 'running') {
302     $bweb->display_running_jobs(1);
303
304 } elsif ($action eq 'dsp_cur_job') {
305     $bweb->display_running_job();
306
307 } elsif ($action eq 'update_from_pool') {
308     my $elt = $bweb->get_form(qw/media pool/);
309     unless ($elt->{media} || $elt->{pool}) {
310         $bweb->error("Can't get media or pool param");
311     } else {
312         my $b = new Bconsole(pref => $conf) ;
313
314         $bweb->display({
315  content => $b->send_cmd("update volume=$elt->{media} fromPool=$elt->{pool}"),
316  title => "Update pool",
317  name => "update volume=$elt->{media} fromPool=$elt->{pool}",
318         }, "command.tpl");      
319     }
320     
321     $bweb->update_media();
322
323 } elsif ($action eq 'client_status') {
324     my $b;
325     foreach my $client (CGI::param('client')) {
326         if ($client =~ m/$client_re/) {
327             $client = $1;
328             $b = new Bconsole(pref => $conf) 
329                 unless ($b) ;
330
331             $bweb->display({
332                 content => $b->send_cmd("st client=$client"),
333                 title => "Client status",
334                 name => $client,
335             }, "command.tpl");
336             
337         } else {
338             $bweb->error("Can't get client selection");
339         }
340     }
341
342 } elsif ($action eq 'cancel_job') {
343     $bweb->cancel_job();
344
345 } elsif  ($action eq 'media_zoom') {
346     $bweb->display_media_zoom();
347
348 } elsif  ($action eq 'job_zoom') {
349     if ($arg->{jobid}) {
350         $bweb->display_job_zoom($arg->{jobid});
351         $bweb->get_job_log();
352     } 
353 } elsif ($action eq 'job_log') {
354     $bweb->get_job_log();
355
356 } elsif ($action eq 'prune') {
357     $bweb->prune();
358
359 } elsif ($action eq 'purge') {
360     $bweb->purge();
361
362 } elsif ($action eq 'run_job') {
363     $bweb->run_job();
364
365 } elsif ($action eq 'run_job_mod') {
366     $bweb->run_job_mod();
367
368 } elsif ($action eq 'run_job_now') {
369     $bweb->run_job_now();
370
371 } elsif ($action eq 'label_barcodes') {
372     $bweb->label_barcodes();
373
374 } elsif ($action eq 'delete') {
375     $bweb->delete();
376
377 } elsif ($action eq 'fileset_view') {
378     $bweb->fileset_view();
379
380 } else {
381     $bweb->error("Sorry, this action don't exist");
382 }
383
384 $bweb->display_end();
385
386 $bweb->dbh_disconnect();
387
388 __END__
389
390 TODO :
391
392  o Affichage des job en cours, termines
393  o Affichage du detail d'un job (status client)
394  o Acces aux log d'une sauvegarde
395  o Cancel d'un job
396  o Lancement d'un job
397
398  o Affichage des medias (pool, cf bacweb)
399  o Affichage de la liste des cartouches
400  o Affichage d'un autochangeur
401  o Mise a jour des slots
402  o Label barcodes
403  o Affichage des medias qui ont besoin d'etre change
404
405  o Affichage des stats sur les dernieres sauvegardes (cf bacula-web)
406  o Affichage des stats sur un type de job
407  o Affichage des infos de query.sql
408
409  - Affichage des du TapeAlert sur le site
410  - Recuperation des erreurs SCSI de /var/log/kern.log
411
412  o update d'un volume
413  o update d'un pool
414
415  o Configuration des autochanger a la main dans un hash dumper