]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/bweb.pl
ebl fix mtime display
[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     $bweb->can_do('r_configure');
88     $conf->view()
89
90 } elsif ($action eq 'edit_conf') {
91     $bweb->can_do('r_configure');
92     $conf->edit();
93
94 } elsif ($action eq 'apply_conf') {
95     $bweb->can_do('r_configure');
96     $conf->modify();
97
98 } elsif ($action eq 'user_del') {
99     $bweb->users_del();
100
101 } elsif ($action eq 'user_add') {
102     $bweb->users_add();
103
104 } elsif ($action eq 'user_edit') {
105     $bweb->display_user();
106
107 } elsif ($action eq 'user_save') {
108     $bweb->users_add();
109
110 } elsif ($action eq 'users') {
111     $bweb->display_users();
112
113 } elsif ($action eq 'client') { 
114     $bweb->display_clients();
115
116 } elsif ($action eq 'pool') {
117     $bweb->display_pool();
118
119 } elsif ($action eq 'location_edit') {
120     $bweb->location_edit();
121
122 } elsif ($action eq 'location_save') {
123     $bweb->location_save();
124
125 } elsif ($action eq 'location_add') {
126     $bweb->location_add();
127
128 } elsif ($action eq 'location_del') {
129     $bweb->location_del();
130
131 } elsif ($action eq 'cmd_storage') {
132     $bweb->cmd_storage();
133
134 } elsif ($action eq 'media') {
135     $bweb->can_do('r_view_media');
136
137     print "<div><table border='0'><tr><td valign='top'>\n";
138     my $fields = $bweb->get_form(qw/db_locations db_pools expired
139                                     qlocations qpools volstatus qre_media
140                                     limit  qmediatypes db_mediatypes/);
141     $bweb->display($fields, "display_form_media.tpl");
142
143     print "</td><td valign='top'>";
144     $bweb->display_media(offset => $arg->{offset},
145                          limit => $arg->{limit});
146     print "</td></tr></table></div>";
147
148 } elsif ($action eq 'allmedia') {
149     $bweb->display_allmedia();
150
151 } elsif ($action eq 'eject') {
152     $bweb->can_do('r_autochanger_mgnt');
153
154     my $arg = $bweb->get_form("ach");
155     my $a = $bweb->ach_get($arg->{ach});
156     
157     if ($a) {
158         $a->status();
159         foreach my $slot (CGI::param('slot')) {
160             print $a->{error} unless $a->send_to_io($slot);
161         }
162
163         foreach my $media (CGI::param('media')) {
164             my $slot = $a->get_media_slot($media);
165             print $a->{error} unless $a->send_to_io($slot);
166         }
167
168         $a->display_content();
169     }
170 } elsif ($action eq 'add_media') {
171     $bweb->add_media();
172
173 } elsif ($action eq 'eject_media') {
174     $bweb->eject_media();
175
176 } elsif ($action eq 'clear_io') {
177     $bweb->can_do('r_autochanger_mgnt');
178
179     my $arg = $bweb->get_form('ach');
180
181     my $a = $bweb->ach_get($arg->{ach});
182     if (defined $a) {
183         $a->status();
184         $a->clear_io();
185         $a->display_content();
186     }
187
188 } elsif ($action eq 'ach_edit') {
189     $bweb->ach_edit();
190
191 } elsif ($action eq 'ach_del') {
192     $bweb->ach_del();
193
194 } elsif ($action eq 'ach_view') {
195     $bweb->can_do('r_autochanger_mgnt');
196
197     # TODO : get autochanger name and create it
198     $bweb->connect_db();
199     my $arg = $bweb->get_form('ach');
200
201     my $a = $bweb->ach_get($arg->{ach});
202     if ($a) {
203         $a->status();
204         $a->display_content();
205     }
206
207 } elsif ($action eq 'ach_add') {
208     $bweb->ach_add();
209
210 } elsif ($action eq 'ach_load') {
211     $bweb->can_do('r_autochanger_mgnt');
212
213     my $arg = $bweb->get_form('ach', 'drive', 'slot');
214     
215     my $a = $bweb->ach_get($arg->{ach});
216
217     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
218     {
219         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
220         # TODO : use template here
221         print "<pre>\n";
222         $b->send_cmd("mount slot=$arg->{slot} drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
223         print "</pre>\n";
224     } else {
225         $bweb->error("Can't get drive, slot or ach");
226     }
227     
228 } elsif ($action eq 'ach_unload') {
229     $bweb->can_do('r_autochanger_mgnt');
230
231     my $arg = $bweb->get_form('drive', 'slot', 'ach');
232
233     my $a = $bweb->ach_get($arg->{ach});
234
235     if (defined $a and defined $arg->{drive} and defined $arg->{slot})
236     {
237         my $b = new Bconsole(pref => $conf, timeout => 300, log_stdout => 1) ;
238         # TODO : use template here
239         print "<pre>\n";
240         $b->send_cmd("umount drive=$arg->{drive} storage=\"" . $a->get_drive_name($arg->{drive}) . '"');
241         print "</pre>\n";
242
243     } else {
244         $bweb->error("Can't get drive, slot or ach");
245     }   
246 } elsif ($action eq 'intern_media') {
247     $bweb->help_intern();
248
249 } elsif ($action eq 'compute_intern_media') {
250     $bweb->help_intern_compute();
251
252 } elsif ($action eq 'extern_media') {
253     $bweb->help_extern();
254
255 } elsif ($action eq 'compute_extern_media') {
256     $bweb->help_extern_compute();
257
258 } elsif ($action eq 'extern') {
259     $bweb->can_do('r_media_mgnt');
260     $bweb->can_do('r_autochanger_mgnt');
261
262     print "<div style='float: left;'>";
263     my @achs = $bweb->eject_media();
264     for my $ach (@achs) {
265         CGI::param('ach', $ach);
266         $bweb->update_slots();
267     }
268     print "</div><div style='float: left;margin-left: 20px;'>";
269     $bweb->move_media('no');    # enabled = no
270     print "</div>";
271
272 } elsif ($action eq 'move_email') {
273     $bweb->move_email();
274
275 } elsif ($action eq 'change_location') {
276     $bweb->location_change();
277
278 } elsif ($action eq 'location') {
279     $bweb->location_display();
280
281 } elsif ($action eq 'about') {
282     $bweb->display($bweb, 'about.tpl');
283
284 } elsif ($action eq 'intern') {
285     $bweb->move_media('yes'); # TODO : remove that
286
287 } elsif ($action eq 'move_media') {
288     my $a = $bweb->get_form('enabled');
289     $bweb->move_media($a->{enabled}); 
290
291 } elsif ($action eq 'save_location') {
292     $bweb->save_location();
293
294 } elsif ($action eq 'update_location') {
295     $bweb->update_location();
296
297 } elsif ($action eq 'update_media') {
298     $bweb->update_media();
299
300 } elsif ($action eq 'do_update_media') {
301     $bweb->do_update_media();
302
303 } elsif ($action eq 'update_slots') {
304     $bweb->update_slots();
305
306 } elsif ($action eq 'graph') {
307     $bweb->display_graph();
308
309 } elsif ($action eq 'next_job') {
310     $bweb->director_show_sched();
311
312 } elsif ($action eq 'enable_job') {
313     $bweb->enable_disable_job(1);
314
315 } elsif ($action eq 'disable_job') {
316     $bweb->enable_disable_job(0);
317
318 } elsif ($action eq 'groups') {
319     $bweb->display_groups();
320
321 } elsif ($action eq 'groups_edit') {
322     $bweb->groups_edit();
323
324 } elsif ($action eq 'groups_save') {
325     $bweb->groups_save();
326
327 } elsif ($action eq 'groups_del') {
328     $bweb->groups_del();
329
330 } elsif ($action eq 'job') {
331     $bweb->can_do('r_view_job');
332     print "<div><table border='0'><tr><td valign='top'>\n";
333     my $fields = $bweb->get_form(qw/status level filter db_clients
334                                     db_filesets since
335                                     limit age offset qclients qfilesets
336                                     jobtype qpools db_pools
337                                     db_client_groups qclient_groups/); # drop this to hide 
338     if (!CGI::param('since')) {
339         $fields->{hide_since}=1 ;
340         delete $fields->{since};
341     }
342     $bweb->display($fields, "display_form_job.tpl");
343
344     print "</td><td valign='top'>";
345     $bweb->display_job(age => $fields->{age},  # last 7 days
346                        since => $fields->{since},
347                        offset => $fields->{offset},
348                        limit => $fields->{limit});
349     print "</td></tr></table></div>";
350 } elsif ($action eq 'job_group') {
351     $bweb->can_do('r_view_job');
352     print "<div><table border='0'><tr><td valign='top'>\n";
353     my $fields = $bweb->get_form(qw/limit level age filter 
354                                     db_client_groups qclient_groups/); # drop this to hide 
355
356     $fields->{hide_status} = 1;
357     $fields->{hide_type} = 1;
358     $fields->{hide_since}=1;
359     $fields->{action} = 'job_group';
360
361     $bweb->display($fields, "display_form_job.tpl");
362
363     print "</td><td valign='top'>";
364     $bweb->display_job_group(age => $arg->{age},  # last 7 days
365                              limit => $arg->{limit});
366     print "</td></tr></table></div>";
367 } elsif ($action eq 'client_stats') {
368
369     foreach my $client (CGI::param('client')) {
370         if ($client =~ m/$client_re/) {
371             $bweb->display_client_stats(clientname => $1,
372                                         age => $arg->{age});
373         }
374     }
375
376 } elsif ($action eq 'group_stats') {
377     $bweb->display_group_stats(age => $arg->{age});
378
379 } elsif ($action eq 'running') {
380     $bweb->display_running_jobs(1);
381
382 } elsif ($action eq 'dsp_cur_job') {
383     $bweb->display_running_job();
384
385 } elsif ($action eq 'update_from_pool') {
386     $bweb->can_do('r_media_mgnt');
387     my $elt = $bweb->get_form(qw/media pool/);
388     unless ($elt->{media} || $elt->{pool}) {
389         $bweb->error("Can't get media or pool param");
390     } else {
391         my $b = new Bconsole(pref => $conf) ;
392
393         $bweb->display({
394  content => $b->send_cmd("update volume=$elt->{media} fromPool=$elt->{pool}"),
395  title => "Update pool",
396  name => "update volume=$elt->{media} fromPool=$elt->{pool}",
397         }, "command.tpl");      
398     }
399     
400     $bweb->update_media();
401
402 } elsif ($action eq 'client_status') {
403     $bweb->can_do('r_client_status');
404     my $b;
405     foreach my $client (CGI::param('client')) {
406         if ($client =~ m/$client_re/) {
407             $client = $1;
408             $b = new Bconsole(pref => $conf) 
409                 unless ($b) ;
410
411             $bweb->display({
412                 content => $b->send_cmd("st client=$client"),
413                 title => "Client status",
414                 name => $client,
415             }, "command.tpl");
416             
417         } else {
418             $bweb->error("Can't get client selection");
419         }
420     }
421
422 } elsif ($action eq 'cancel_job') {
423     $bweb->cancel_job();
424
425 } elsif  ($action eq 'media_zoom') {
426     $bweb->display_media_zoom();
427
428 } elsif  ($action eq 'job_zoom') {
429     if ($arg->{jobid}) {
430         $bweb->display_job_zoom($arg->{jobid});
431         $bweb->get_job_log();
432     } 
433 } elsif ($action eq 'job_log') {
434     $bweb->get_job_log();
435
436 } elsif ($action eq 'prune') {
437     $bweb->prune();
438
439 } elsif ($action eq 'purge') {
440     $bweb->purge();
441
442 } elsif ($action eq 'run_job') {
443     $bweb->run_job();
444
445 } elsif ($action eq 'run_job_mod') {
446     $bweb->run_job_mod();
447
448 } elsif ($action eq 'run_job_now') {
449     $bweb->run_job_now();
450
451 } elsif ($action eq 'label_barcodes') {
452     $bweb->label_barcodes();
453
454 } elsif ($action eq 'delete') {
455     $bweb->delete();
456
457 } elsif ($action eq 'fileset_view') {
458     $bweb->fileset_view();
459
460 } elsif ($action eq 'next_job2') {
461     $bweb->display_next_job();
462
463 } elsif ($action eq 'missing') {
464     $bweb->display_missing_job();
465
466 } elsif ($action eq 'overview') {
467     $bweb->can_do('r_view_job');
468     print "<div><table border='0'><tr><td valign='top'>\n";
469     my $fields = $bweb->get_form(qw/level filter age jobtype since type
470                                     db_client_groups qclient_groups/); # drop this to hide 
471     $fields->{hide_status}=1;
472     $fields->{view_time_slice}=1;
473     $fields->{action}='overview';
474     $bweb->display($fields, "display_form_job.tpl");
475
476     print "</td><td valign='top'>";
477     $bweb->display_overview();
478     print "</td></tr></table></div>";
479
480 } elsif ($action eq 'overview_zoom') {
481     $bweb->can_do('r_view_job');
482     print "<div><table border='0'><tr><td valign='top'>\n";
483     my $fields = $bweb->get_form(qw/level filter age jobtype since type
484                                  db_client_groups qclient_groups/); # drop this to hide 
485     $fields->{hide_status}=1;
486     $fields->{view_time_slice}=1;
487     $fields->{action}='overview_zoom';
488     $bweb->display($fields, "display_form_job.tpl");
489     print "</td><td valign='top'>";
490     $bweb->display_overview_zoom();
491     print "</td></tr></table></div>";
492
493 } else {
494     $bweb->error("Sorry, this action doesn't exist");
495 }
496
497 $bweb->display_end();
498
499 $bweb->dbh_disconnect();
500
501 __END__
502
503 TODO :
504
505  o Affichage des medias qui ont besoin d'etre change
506  o Affichage des infos de query.sql
507
508  - Affichage des du TapeAlert sur le site
509  - Recuperation des erreurs SCSI de /var/log/kern.log